Compare commits
No commits in common. "main" and "0.5.5" have entirely different histories.
9 changed files with 91 additions and 165 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -4,5 +4,4 @@
|
||||||
/inv.txt
|
/inv.txt
|
||||||
/inv_users.txt
|
/inv_users.txt
|
||||||
/polls.txt
|
/polls.txt
|
||||||
/elem.tar.gz
|
/elem.tar.gz
|
||||||
/combos.txt
|
|
14
README.md
14
README.md
|
@ -1,14 +1,14 @@
|
||||||
# Elemental on Command Line
|
# Elemental on Command Line
|
||||||
This is an elemental combination game written in C, with optional multi-player support.
|
This is an elemental combination game written in C, with optional multi-player support.
|
||||||
|
|
||||||
## Clients
|
|
||||||
- [PenguinMod client](https://studio.penguinmod.com/?fps=200&clones=Infinity&offscreen&size=850x480#7218964246) for playing the game online with a fancy interface
|
|
||||||
- [Discord client](https://discord.gg/DKZTWyWH3B) for playing the game publicly with other Discord members
|
|
||||||
- [Web client](https://elem.dervland.net/) for a demo of the multiplayer version
|
|
||||||
- [Original client](https://git.dervland.net/elemental/elemental-on-terminal/releases) for developers, administrators, and command line fans
|
|
||||||
|
|
||||||
## Single-player
|
## Single-player
|
||||||
A single-player example pack is provided as an example in ``bin/combos.txt``. This can be customized by the user, although internal limitations require the combination string to be in alphabetical order.
|
A single-player example pack is provided as an example in ``bin/combos.txt``. This can be customized by the user, although internal limitations require the combination string to be in alphabetical order.
|
||||||
|
|
||||||
## Multi-player
|
## Multi-player
|
||||||
To set up multi-player mode, use the guide with the [Web proxy](https://git.dervland.net/elemental/elemental-to-web).
|
To set up multi-player mode, create a directory ``../elem_data``. Also, create separate directories for each user that plays.
|
||||||
|
|
||||||
|
The game can now be played with the following syntax, inside your user directory:
|
||||||
|
```sh
|
||||||
|
cd ../your_user_dir
|
||||||
|
../elemental-command-line/bin/elem your_username
|
||||||
|
```
|
|
@ -1,11 +1,10 @@
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include <time.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include "loader.h"
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
// huge cleanup operation soon
|
// huge cleanup operation soon
|
||||||
|
@ -81,7 +80,7 @@ int inv_handler(const void *key, size_t size, uintptr_t val, void *usr) {
|
||||||
if (val2[strlen(val2) - 1] == '\n') {
|
if (val2[strlen(val2) - 1] == '\n') {
|
||||||
printf("- user:%s suggested %s", key3, val2);
|
printf("- user:%s suggested %s", key3, val2);
|
||||||
} else {
|
} else {
|
||||||
printf("- user:%s suggested %s\n", key3, val2);
|
printf("- user:%s suggested %s\n", key3, val2);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(key3);
|
free(key3);
|
||||||
|
@ -104,52 +103,34 @@ int inv_handler(const void *key, size_t size, uintptr_t val, void *usr) {
|
||||||
int polls_handler(const void *key, size_t size, uintptr_t val, void *usr) {
|
int polls_handler(const void *key, size_t size, uintptr_t val, void *usr) {
|
||||||
struct verifier *verified = (struct verifier *)usr;
|
struct verifier *verified = (struct verifier *)usr;
|
||||||
|
|
||||||
char *val2 = (char *)val;
|
if (((char *)val)[strlen(((char *)val)) - 1] == '\n') {
|
||||||
char *val3 = malloc(strlen(val2) + 1);
|
((char *)val)[strlen(((char *)val)) - 1] = '\0';
|
||||||
strcpy(val3, val2);
|
|
||||||
|
|
||||||
if (val3[strlen(val3) - 1] == '\n') {
|
|
||||||
val3[strlen(val3) - 1] = '\0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp(verified->name, key, strlen(verified->name)) == 0 &&
|
if (strncmp(verified->name, key, strlen(verified->name)) == 0 &&
|
||||||
strcmp(verified->sugg, val3) == 0) {
|
strcmp(verified->sugg, (char *)val) == 0)
|
||||||
free(val3);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
free(val3);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int success_handler(const void *key, size_t size, uintptr_t val, void *usr) {
|
int success_handler(const void *key, size_t size, uintptr_t val, void *usr) {
|
||||||
struct succ *verified = (struct succ *)usr;
|
struct succ *verified = (struct succ *)usr;
|
||||||
|
|
||||||
char *val2 = (char *)val;
|
if ((char *)val != verified->sugg) {
|
||||||
char *val3 = malloc(strlen(val2) + 1);
|
//((char *)val)[strlen(((char *)val)) - 1] = '\0';
|
||||||
strcpy(val3, val2);
|
|
||||||
|
|
||||||
if (val3[strlen(val3) - 1] == '\n') {
|
|
||||||
val3[strlen(val3) - 1] = '\0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(verified->sugg, val3) == 0) {
|
if (strcmp(verified->sugg, (char *)val) == 0) {
|
||||||
verified->points[0]++;
|
verified->points[0]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(val3);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *handle_pages(char *command, char *invs) {
|
char *handle_pages(char *command, char *invs) {
|
||||||
char *data;
|
|
||||||
char *data2;
|
|
||||||
if (strncmp(command, invs, strlen(invs)) == 0) {
|
if (strncmp(command, invs, strlen(invs)) == 0) {
|
||||||
data = &command[strlen(invs)];
|
return &command[strlen(invs)];
|
||||||
data2 = malloc(strlen(data) + 1);
|
|
||||||
memcpy(data2,data,strlen(data) + 1);
|
|
||||||
return data2;
|
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -165,8 +146,8 @@ int handle_pages_int(char *command, char *invs) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int suggest_command(char *command, char *command_re, hashmap *polls, hashmap *combos, char *name,
|
int suggest_command(char *command, char *command_re, hashmap *polls,
|
||||||
int was_combination) {
|
char *name) {
|
||||||
|
|
||||||
char *page = handle_pages(command, "/suggest ");
|
char *page = handle_pages(command, "/suggest ");
|
||||||
|
|
||||||
|
@ -183,22 +164,11 @@ int suggest_command(char *command, char *command_re, hashmap *polls, hashmap *co
|
||||||
char *val = calloc(MAX_BUF_LENGTH, sizeof(char));
|
char *val = calloc(MAX_BUF_LENGTH, sizeof(char));
|
||||||
sprintf(val, "%s;%s", page, command_re);
|
sprintf(val, "%s;%s", page, command_re);
|
||||||
|
|
||||||
srand(time(NULL));
|
|
||||||
|
|
||||||
char *key = calloc(MAX_BUF_LENGTH, sizeof(char));
|
char *key = calloc(MAX_BUF_LENGTH, sizeof(char));
|
||||||
sprintf(key, "%s_%i", name, (int)rand());
|
sprintf(key, "%s_%i", name, (int)rand());
|
||||||
|
|
||||||
int point_thing = 0;
|
|
||||||
|
|
||||||
struct succ succer = {.sugg = val, .points = &point_thing};
|
|
||||||
hashmap_iterate(polls, success_handler, (void *)&succer);
|
|
||||||
|
|
||||||
if (was_combination == 2 && point_thing == 0) {
|
|
||||||
printf("You cannot create unique polls with elements you do not have.\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct verifier verified = {.name = name, .sugg = val};
|
struct verifier verified = {.name = name, .sugg = val};
|
||||||
|
|
||||||
if (hashmap_iterate(polls, polls_handler, (void *)&verified) == -1) {
|
if (hashmap_iterate(polls, polls_handler, (void *)&verified) == -1) {
|
||||||
printf("You already suggested this!\n");
|
printf("You already suggested this!\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -206,15 +176,22 @@ int suggest_command(char *command, char *command_re, hashmap *polls, hashmap *co
|
||||||
|
|
||||||
hashmap_set(polls, key, strlen(key), (uintptr_t)val, 1);
|
hashmap_set(polls, key, strlen(key), (uintptr_t)val, 1);
|
||||||
|
|
||||||
point_thing++;
|
int point_thing = 0;
|
||||||
|
|
||||||
|
struct succ succer = {.sugg = val, .points = &point_thing};
|
||||||
|
hashmap_iterate(polls, success_handler, (void *)&succer);
|
||||||
|
|
||||||
if (point_thing == UPVOTE_IN) {
|
if (point_thing == UPVOTE_IN) {
|
||||||
|
|
||||||
printf("Poll was added into the game!\n");
|
printf("Poll was added into the game!\n");
|
||||||
FILE *fptr;
|
FILE *fptr;
|
||||||
|
|
||||||
hashmap_set(combos, command_re, strlen(command_re), (uintptr_t)page, 0);
|
fptr = fopen("../elem_data/" combo_file, "a");
|
||||||
|
if (fptr == NULL)
|
||||||
write_elements(combos, "../elem_data/" COMBO_FILE, 0);
|
return 1;
|
||||||
|
fwrite(val, sizeof(char), strlen(val), fptr);
|
||||||
|
fwrite("\n", sizeof(char), 1, fptr);
|
||||||
|
fclose(fptr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +201,14 @@ int suggest_command(char *command, char *command_re, hashmap *polls, hashmap *co
|
||||||
|
|
||||||
FILE *fptr;
|
FILE *fptr;
|
||||||
|
|
||||||
write_elements(polls, "../elem_data/" POLL_FILE, 3);
|
fptr = fopen("../elem_data/" poll_file, "a");
|
||||||
|
if (fptr == NULL)
|
||||||
|
return 1;
|
||||||
|
fwrite(key, sizeof(char), strlen(key), fptr);
|
||||||
|
fwrite(";", sizeof(char), 1, fptr);
|
||||||
|
fwrite(val, sizeof(char), strlen(val), fptr);
|
||||||
|
fwrite("\n", sizeof(char), 1, fptr);
|
||||||
|
fclose(fptr);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -254,7 +238,7 @@ int polls_command(char *command, hashmap *polls, hashmap *cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int path_command(char *command, hashmap *elements_rev, hashmap *already_done,
|
int path_command(char *command, hashmap *elements_rev, hashmap *already_done,
|
||||||
int top, hashmap *inv) {
|
int top, hashmap* inv) {
|
||||||
char *page2;
|
char *page2;
|
||||||
if (top) {
|
if (top) {
|
||||||
page2 = handle_pages(command, "/path ");
|
page2 = handle_pages(command, "/path ");
|
||||||
|
@ -266,7 +250,7 @@ int path_command(char *command, hashmap *elements_rev, hashmap *already_done,
|
||||||
|
|
||||||
char *page = malloc(strlen(page2) + 1);
|
char *page = malloc(strlen(page2) + 1);
|
||||||
strcpy(page, page2);
|
strcpy(page, page2);
|
||||||
if (page[strlen(page) - 1] == '\n') {
|
if (page[strlen(page) - 1] == '\n') {
|
||||||
page[strlen(page) - 1] = '\0';
|
page[strlen(page) - 1] = '\0';
|
||||||
}
|
}
|
||||||
if (strlen(page) == 0) {
|
if (strlen(page) == 0) {
|
||||||
|
@ -279,6 +263,7 @@ int path_command(char *command, hashmap *elements_rev, hashmap *already_done,
|
||||||
already_done = hashmap_create();
|
already_done = hashmap_create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uintptr_t result;
|
uintptr_t result;
|
||||||
hashmap_get(inv, page, strlen(page), &result);
|
hashmap_get(inv, page, strlen(page), &result);
|
||||||
|
|
||||||
|
@ -288,7 +273,7 @@ int path_command(char *command, hashmap *elements_rev, hashmap *already_done,
|
||||||
}
|
}
|
||||||
|
|
||||||
hashmap_get(already_done, page, strlen(page), &result);
|
hashmap_get(already_done, page, strlen(page), &result);
|
||||||
|
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -302,7 +287,7 @@ int path_command(char *command, hashmap *elements_rev, hashmap *already_done,
|
||||||
|
|
||||||
// todo: refactor;
|
// todo: refactor;
|
||||||
char *tmp = (char *)result, *tmp2 = 0;
|
char *tmp = (char *)result, *tmp2 = 0;
|
||||||
if (tmp[strlen(tmp) - 1] == '\n') {
|
if (tmp[strlen(tmp)-1] == '\n') {
|
||||||
tmp[strlen(tmp) - 1] = '\0';
|
tmp[strlen(tmp) - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,7 +298,7 @@ int path_command(char *command, hashmap *elements_rev, hashmap *already_done,
|
||||||
if (tmp2[0] == ';') {
|
if (tmp2[0] == ';') {
|
||||||
tmp2++;
|
tmp2++;
|
||||||
}
|
}
|
||||||
tmp = strstr(tmp2, ";");
|
tmp = strstr(tmp2, ";");
|
||||||
if (tmp == 0) {
|
if (tmp == 0) {
|
||||||
tmp = &tmp2[strlen(tmp2)];
|
tmp = &tmp2[strlen(tmp2)];
|
||||||
}
|
}
|
||||||
|
@ -334,8 +319,8 @@ int path_command(char *command, hashmap *elements_rev, hashmap *already_done,
|
||||||
free(tmp23);
|
free(tmp23);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("<- %s\n-> %s\n", (char *)result, (char *)page);
|
printf("<- %s\n-> %s\n", (char*) result, (char *)page);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
int get_command(char *command, char *command_re, char **sort_tmp);
|
int get_command(char *command, char *command_re, char **sort_tmp);
|
||||||
int slash_command(char *command, hashmap *inv);
|
int slash_command(char *command, hashmap *inv);
|
||||||
int suggest_command(char *command, char *command_re, hashmap *polls,
|
int suggest_command(char *command, char *command_re, hashmap *polls,
|
||||||
hashmap *combos, char *name, int was_combination);
|
char *name);
|
||||||
int help_command(char *command);
|
int help_command(char *command);
|
||||||
int polls_command(char *command, hashmap *polls, hashmap *cmd);
|
int polls_command(char *command, hashmap *polls, hashmap *cmd);
|
||||||
int path_command(char *command, hashmap *elements_rev, hashmap *already_done,
|
int path_command(char *command, hashmap *elements_rev, hashmap *already_done,
|
||||||
|
|
63
src/loader.c
63
src/loader.c
|
@ -6,58 +6,7 @@
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
struct write_struct {
|
int load_elements(hashmap *m, char *table, int use_inv) {
|
||||||
FILE *fptr;
|
|
||||||
int mode;
|
|
||||||
};
|
|
||||||
|
|
||||||
int entry_handler(const void *key, size_t size, uintptr_t val, void *usr) {
|
|
||||||
struct write_struct *usr2 = (struct write_struct *)usr;
|
|
||||||
|
|
||||||
char *val2 = (char *)val;
|
|
||||||
char *key2 = (char *)key;
|
|
||||||
|
|
||||||
if (usr2->mode == 0) {
|
|
||||||
fwrite(val2, sizeof(char), strlen(val2), usr2->fptr);
|
|
||||||
fwrite(";", sizeof(char), 1, usr2->fptr);
|
|
||||||
fwrite(key2, sizeof(char), strlen(key2), usr2->fptr);
|
|
||||||
if (key2[strlen(key2) - 1] != '\n') {
|
|
||||||
fwrite("\n", sizeof(char), 1, usr2->fptr);
|
|
||||||
}
|
|
||||||
} else if (usr2->mode == 1) {
|
|
||||||
fwrite(key2, sizeof(char), strlen(key2), usr2->fptr);
|
|
||||||
if (key2[strlen(key2) - 1] != '\n') {
|
|
||||||
fwrite("\n", sizeof(char), 1, usr2->fptr);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fwrite(key2, sizeof(char), strlen(key2), usr2->fptr);
|
|
||||||
fwrite(";", sizeof(char), 1, usr2->fptr);
|
|
||||||
fwrite(val2, sizeof(char), strlen(val2), usr2->fptr);
|
|
||||||
if (val2[strlen(val2) - 1] != '\n') {
|
|
||||||
fwrite("\n", sizeof(char), 1, usr2->fptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void write_elements(hashmap *m, char *table, int mode) {
|
|
||||||
FILE *fptr;
|
|
||||||
|
|
||||||
fptr = fopen(table, "w");
|
|
||||||
|
|
||||||
if (fptr == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
struct write_struct writer = {.fptr = fptr, .mode = mode};
|
|
||||||
|
|
||||||
hashmap_iterate(m, entry_handler, (void *)&writer);
|
|
||||||
//fwrite("\n", sizeof(char), 1, fptr);
|
|
||||||
|
|
||||||
fclose(fptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
int load_elements(hashmap *m, char *table, int mode) {
|
|
||||||
FILE *fptr;
|
FILE *fptr;
|
||||||
|
|
||||||
fptr = fopen(table, "r");
|
fptr = fopen(table, "r");
|
||||||
|
@ -70,8 +19,6 @@ int load_elements(hashmap *m, char *table, int mode) {
|
||||||
|
|
||||||
int did_something = 0;
|
int did_something = 0;
|
||||||
|
|
||||||
int lines_get = 0;
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
str2 = calloc(MAX_FILE_SIZE, sizeof(char));
|
str2 = calloc(MAX_FILE_SIZE, sizeof(char));
|
||||||
if (!fgets(str2, MAX_FILE_SIZE, fptr)) {
|
if (!fgets(str2, MAX_FILE_SIZE, fptr)) {
|
||||||
|
@ -79,15 +26,13 @@ int load_elements(hashmap *m, char *table, int mode) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
lines_get++;
|
|
||||||
|
|
||||||
str = calloc(strlen(str2) + 1, sizeof(char));
|
str = calloc(strlen(str2) + 1, sizeof(char));
|
||||||
strcpy(str, str2);
|
strcpy(str, str2);
|
||||||
free(str2);
|
free(str2);
|
||||||
|
|
||||||
did_something = 1;
|
did_something = 1;
|
||||||
|
|
||||||
if (mode == 1) {
|
if (use_inv == 1) {
|
||||||
hashmap_set(m, str, strlen(str) - 1, (uintptr_t)1, 0);
|
hashmap_set(m, str, strlen(str) - 1, (uintptr_t)1, 0);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -99,7 +44,7 @@ int load_elements(hashmap *m, char *table, int mode) {
|
||||||
char *combo = calloc(strlen(combo_o) + 1, sizeof(char));
|
char *combo = calloc(strlen(combo_o) + 1, sizeof(char));
|
||||||
strcpy(combo, combo_o);
|
strcpy(combo, combo_o);
|
||||||
|
|
||||||
if (mode == 3) {
|
if (use_inv == 3) {
|
||||||
uintptr_t result;
|
uintptr_t result;
|
||||||
hashmap_get(m, str, strlen(str) - 1, &result);
|
hashmap_get(m, str, strlen(str) - 1, &result);
|
||||||
|
|
||||||
|
@ -109,7 +54,7 @@ int load_elements(hashmap *m, char *table, int mode) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == 2 || mode == 3) {
|
if (use_inv == 2 || use_inv == 3) {
|
||||||
hashmap_set(m, str, strlen(str) - 1, (uintptr_t)combo, 1);
|
hashmap_set(m, str, strlen(str) - 1, (uintptr_t)combo, 1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
int load_elements(hashmap *m, char *table, int mode);
|
int load_elements(hashmap *m, char *table, int use_inv);
|
||||||
void write_elements(hashmap *m, char *table, int mode);
|
|
62
src/main.c
62
src/main.c
|
@ -1,6 +1,5 @@
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
#include "loader.h"
|
#include "loader.h"
|
||||||
#include "map.h"
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -13,24 +12,24 @@
|
||||||
|
|
||||||
void init_tables(hashmap *elements, hashmap *inv, hashmap *polls,
|
void init_tables(hashmap *elements, hashmap *inv, hashmap *polls,
|
||||||
hashmap *elements_rev, int do_inv) {
|
hashmap *elements_rev, int do_inv) {
|
||||||
load_elements(elements, "../elem_data/" COMBO_FILE, 0);
|
load_elements(elements, "../elem_data/" combo_file, 0);
|
||||||
load_elements(elements, COMBO_FILE, 0) ||
|
load_elements(elements, combo_file, 0) ||
|
||||||
load_elements(elements, "bin/" COMBO_FILE, 0);
|
load_elements(elements, "bin/" combo_file, 0);
|
||||||
|
|
||||||
load_elements(elements_rev, "../elem_data/" COMBO_FILE, 3);
|
load_elements(elements_rev, "../elem_data/" combo_file, 3);
|
||||||
load_elements(elements_rev, COMBO_FILE, 3) ||
|
load_elements(elements_rev, combo_file, 3) ||
|
||||||
load_elements(elements_rev, "bin/" COMBO_FILE, 3);
|
load_elements(elements_rev, "bin/" combo_file, 3);
|
||||||
|
|
||||||
load_elements(polls, "../elem_data/" POLL_FILE, 3);
|
load_elements(polls, "../elem_data/" poll_file, 2);
|
||||||
|
|
||||||
if (!do_inv)
|
if (!do_inv)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
load_elements(inv, "../elem_data/" INV_BASE_FILE, 1) ||
|
load_elements(inv, "../elem_data/" inv_base_file, 1) ||
|
||||||
load_elements(inv, INV_BASE_FILE, 1) ||
|
load_elements(inv, inv_base_file, 1) ||
|
||||||
load_elements(inv, "bin/" INV_BASE_FILE, 1);
|
load_elements(inv, "bin/" inv_base_file, 1);
|
||||||
|
|
||||||
load_elements(inv, INV_FILE, 1);
|
load_elements(inv, inv_file, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
@ -51,7 +50,7 @@ int main(int argc, char *argv[]) {
|
||||||
char *command_re = calloc(MAX_BUF_LENGTH, sizeof(char));
|
char *command_re = calloc(MAX_BUF_LENGTH, sizeof(char));
|
||||||
char **sort_tmp = calloc(MAX_COMBO_LENGTH, sizeof(char **));
|
char **sort_tmp = calloc(MAX_COMBO_LENGTH, sizeof(char **));
|
||||||
|
|
||||||
int was_combination = 0;
|
int wasCombination = 0;
|
||||||
|
|
||||||
init_tables(elements, inv, polls, elements_rev, 1);
|
init_tables(elements, inv, polls, elements_rev, 1);
|
||||||
|
|
||||||
|
@ -81,18 +80,15 @@ int main(int argc, char *argv[]) {
|
||||||
command[i] = tolower(command[i]);
|
command[i] = tolower(command[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (was_combination &&
|
if (wasCombination && suggest_command(command, command_re, polls, name)) {
|
||||||
suggest_command(command, command_re, polls, elements, name, was_combination)) {
|
wasCombination = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
was_combination = 0;
|
wasCombination = 0;
|
||||||
if (help_command(command))
|
if (help_command(command))
|
||||||
continue;
|
continue;
|
||||||
if (polls_command(command, polls, elements)) {
|
if (polls_command(command, polls, elements))
|
||||||
hashmap_free(polls);
|
continue;
|
||||||
polls = hashmap_create();
|
|
||||||
init_tables(elements, inv, polls, elements_rev, 0);
|
|
||||||
}
|
|
||||||
if (slash_command(command, inv))
|
if (slash_command(command, inv))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -115,6 +111,9 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (failed)
|
||||||
|
continue;
|
||||||
|
|
||||||
uintptr_t result;
|
uintptr_t result;
|
||||||
hashmap_get(elements, command_re, strlen(command_re), &result);
|
hashmap_get(elements, command_re, strlen(command_re), &result);
|
||||||
|
|
||||||
|
@ -124,21 +123,12 @@ int main(int argc, char *argv[]) {
|
||||||
hashmap_get(elements, command_re, strlen(command_re), &result);
|
hashmap_get(elements, command_re, strlen(command_re), &result);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == 0 && failed) {
|
|
||||||
was_combination = 2;
|
|
||||||
printf("Use /suggest to upvote a pre-existing combination.\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
was_combination = 1;
|
wasCombination = 1;
|
||||||
printf("You didn't make anything; use /suggest to suggest an element.\n");
|
printf("You didn't make anything; use /suggest to suggest an element.\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (failed)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
char *res_str = (char *)result;
|
char *res_str = (char *)result;
|
||||||
|
|
||||||
uintptr_t result2;
|
uintptr_t result2;
|
||||||
|
@ -152,7 +142,15 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
hashmap_set(inv, res_str, strlen(res_str), (uintptr_t)1, 0);
|
hashmap_set(inv, res_str, strlen(res_str), (uintptr_t)1, 0);
|
||||||
printf("You made %s!\n", res_str);
|
printf("You made %s!\n", res_str);
|
||||||
write_elements(inv, INV_FILE, 1);
|
|
||||||
|
FILE *fptr;
|
||||||
|
|
||||||
|
fptr = fopen(inv_file, "a");
|
||||||
|
if (fptr == NULL)
|
||||||
|
continue;
|
||||||
|
fwrite(res_str, sizeof(char), strlen(res_str), fptr);
|
||||||
|
fwrite("\n", sizeof(char), 1, fptr);
|
||||||
|
fclose(fptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// free(command);
|
// free(command);
|
||||||
|
|
12
src/main.h
12
src/main.h
|
@ -1,9 +1,9 @@
|
||||||
#define INV_FILE "inv.txt"
|
#define inv_file "inv.txt"
|
||||||
#define INV_BASE_FILE "inv_base.txt"
|
#define inv_base_file "inv_base.txt"
|
||||||
#define COMBO_FILE "combos.txt"
|
#define combo_file "combos.txt"
|
||||||
#define POLL_FILE "polls.txt"
|
#define poll_file "polls.txt"
|
||||||
#define POLLS_LOCK_FILE "polls_lock.txt"
|
#define polls_lock_file "polls_lock.txt"
|
||||||
#define LB_FILE "lb.txt"
|
#define lb_file "lb.txt"
|
||||||
|
|
||||||
#define MAX_BUF_LENGTH 1024
|
#define MAX_BUF_LENGTH 1024
|
||||||
#define MAX_COMBO_LENGTH 1024
|
#define MAX_COMBO_LENGTH 1024
|
||||||
|
|
4
wrap.sh
4
wrap.sh
|
@ -1,6 +1,6 @@
|
||||||
make
|
make
|
||||||
CC=x86_64-w64-mingw32-gcc BIN=bin/elem.exe make
|
CC=x86_64-w64-mingw32-gcc BIN=bin/elem.exe make
|
||||||
CC=i686-w64-mingw32-gcc BIN=bin/elem_32.exe make
|
CC=i686-w64-mingw32-gcc BIN=bin/elem_32.exe make
|
||||||
strip --strip-all bin/elem
|
|
||||||
rm elem.tar.gz
|
rm elem.tar.gz
|
||||||
tar -cvf elem.tar.gz bin
|
tar -cvf elem.tar.gz bin
|
||||||
|
strip --strip-all bin/elem
|
Loading…
Reference in a new issue