Compare commits

...

9 commits
0.5.4 ... main

5 changed files with 68 additions and 44 deletions

View file

@ -1,14 +1,14 @@
# Elemental on Command Line
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
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
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
```
To set up multi-player mode, use the guide with the [Web proxy](https://git.dervland.net/elemental/elemental-to-web).

View file

@ -80,7 +80,7 @@ int inv_handler(const void *key, size_t size, uintptr_t val, void *usr) {
if (val2[strlen(val2) - 1] == '\n') {
printf("- user:%s suggested %s", key3, val2);
} else {
printf("- user:%s suggested %s\n", key3, val2);
printf("- user:%s suggested %s\n", key3, val2);
}
free(key3);
@ -103,28 +103,41 @@ 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) {
struct verifier *verified = (struct verifier *)usr;
if (((char *)val)[strlen(((char *)val)) - 1] == '\n') {
((char *)val)[strlen(((char *)val)) - 1] = '\0';
char *val2 = (char *)val;
char *val3 = malloc(strlen(val2) + 1);
strcpy(val3, val2);
if (val3[strlen(val3) - 1] == '\n') {
val3[strlen(val3) - 1] = '\0';
}
if (strncmp(verified->name, key, strlen(verified->name)) == 0 &&
strcmp(verified->sugg, (char *)val) == 0)
strcmp(verified->sugg, val3) == 0) {
free(val3);
return -1;
}
free(val3);
return 0;
}
int success_handler(const void *key, size_t size, uintptr_t val, void *usr) {
struct succ *verified = (struct succ *)usr;
if ((char *)val != verified->sugg) {
//((char *)val)[strlen(((char *)val)) - 1] = '\0';
char *val2 = (char *)val;
char *val3 = malloc(strlen(val2) + 1);
strcpy(val3, val2);
if (val3[strlen(val3) - 1] == '\n') {
val3[strlen(val3) - 1] = '\0';
}
if (strcmp(verified->sugg, (char *)val) == 0) {
if (strcmp(verified->sugg, val3) == 0) {
verified->points[0]++;
}
free(val3);
return 0;
}
@ -146,8 +159,8 @@ int handle_pages_int(char *command, char *invs) {
}
}
int suggest_command(char *command, char *command_re, hashmap *polls,
char *name) {
int suggest_command(char *command, char *command_re, hashmap *polls, char *name,
int was_combination) {
char *page = handle_pages(command, "/suggest ");
@ -167,8 +180,17 @@ int suggest_command(char *command, char *command_re, hashmap *polls,
char *key = calloc(MAX_BUF_LENGTH, sizeof(char));
sprintf(key, "%s_%i", name, (int)rand());
struct verifier verified = {.name = name, .sugg = val};
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};
if (hashmap_iterate(polls, polls_handler, (void *)&verified) == -1) {
printf("You already suggested this!\n");
return 1;
@ -176,13 +198,9 @@ int suggest_command(char *command, char *command_re, hashmap *polls,
hashmap_set(polls, key, strlen(key), (uintptr_t)val, 1);
int point_thing = 0;
struct succ succer = {.sugg = val, .points = &point_thing};
hashmap_iterate(polls, success_handler, (void *)&succer);
point_thing++;
if (point_thing == UPVOTE_IN) {
printf("Poll was added into the game!\n");
FILE *fptr;
@ -238,7 +256,7 @@ int polls_command(char *command, hashmap *polls, hashmap *cmd) {
}
int path_command(char *command, hashmap *elements_rev, hashmap *already_done,
int top, hashmap* inv) {
int top, hashmap *inv) {
char *page2;
if (top) {
page2 = handle_pages(command, "/path ");
@ -250,7 +268,7 @@ int path_command(char *command, hashmap *elements_rev, hashmap *already_done,
char *page = malloc(strlen(page2) + 1);
strcpy(page, page2);
if (page[strlen(page) - 1] == '\n') {
if (page[strlen(page) - 1] == '\n') {
page[strlen(page) - 1] = '\0';
}
if (strlen(page) == 0) {
@ -263,7 +281,6 @@ int path_command(char *command, hashmap *elements_rev, hashmap *already_done,
already_done = hashmap_create();
}
uintptr_t result;
hashmap_get(inv, page, strlen(page), &result);
@ -273,7 +290,7 @@ int path_command(char *command, hashmap *elements_rev, hashmap *already_done,
}
hashmap_get(already_done, page, strlen(page), &result);
if (result != 0) {
return 1;
}
@ -287,7 +304,7 @@ int path_command(char *command, hashmap *elements_rev, hashmap *already_done,
// todo: refactor;
char *tmp = (char *)result, *tmp2 = 0;
if (tmp[strlen(tmp)-1] == '\n') {
if (tmp[strlen(tmp) - 1] == '\n') {
tmp[strlen(tmp) - 1] = '\0';
}
@ -298,7 +315,7 @@ int path_command(char *command, hashmap *elements_rev, hashmap *already_done,
if (tmp2[0] == ';') {
tmp2++;
}
tmp = strstr(tmp2, ";");
tmp = strstr(tmp2, ";");
if (tmp == 0) {
tmp = &tmp2[strlen(tmp2)];
}
@ -319,8 +336,8 @@ int path_command(char *command, hashmap *elements_rev, hashmap *already_done,
free(tmp23);
}
printf("<- %s\n-> %s\n", (char*) result, (char *)page);
printf("<- %s\n-> %s\n", (char *)result, (char *)page);
return 1;
}

View file

@ -2,7 +2,7 @@
int get_command(char *command, char *command_re, char **sort_tmp);
int slash_command(char *command, hashmap *inv);
int suggest_command(char *command, char *command_re, hashmap *polls,
char *name);
char *name, int was_combination);
int help_command(char *command);
int polls_command(char *command, hashmap *polls, hashmap *cmd);
int path_command(char *command, hashmap *elements_rev, hashmap *already_done,

View file

@ -20,7 +20,7 @@ void init_tables(hashmap *elements, hashmap *inv, hashmap *polls,
load_elements(elements_rev, combo_file, 3) ||
load_elements(elements_rev, "bin/" combo_file, 3);
load_elements(polls, "../elem_data/" poll_file, 2);
load_elements(polls, "../elem_data/" poll_file, 3);
if (!do_inv)
return;
@ -50,7 +50,7 @@ int main(int argc, char *argv[]) {
char *command_re = calloc(MAX_BUF_LENGTH, sizeof(char));
char **sort_tmp = calloc(MAX_COMBO_LENGTH, sizeof(char **));
int wasCombination = 0;
int was_combination = 0;
init_tables(elements, inv, polls, elements_rev, 1);
@ -80,11 +80,11 @@ int main(int argc, char *argv[]) {
command[i] = tolower(command[i]);
}
if (wasCombination && suggest_command(command, command_re, polls, name)) {
wasCombination = 0;
if (was_combination &&
suggest_command(command, command_re, polls, name, was_combination)) {
continue;
}
wasCombination = 0;
was_combination = 0;
if (help_command(command))
continue;
if (polls_command(command, polls, elements))
@ -111,9 +111,6 @@ int main(int argc, char *argv[]) {
}
}
if (failed)
continue;
uintptr_t result;
hashmap_get(elements, command_re, strlen(command_re), &result);
@ -123,12 +120,21 @@ int main(int argc, char *argv[]) {
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) {
wasCombination = 1;
was_combination = 1;
printf("You didn't make anything; use /suggest to suggest an element.\n");
continue;
}
if (failed)
continue;
char *res_str = (char *)result;
uintptr_t result2;

View file

@ -1,5 +1,6 @@
make
CC=x86_64-w64-mingw32-gcc BIN=./bin/elem.exe make
CC=i686-w64-mingw32-gcc BIN=./bin/elem_32.exe make
rm ./elem.tar.gz
tar -cvf ./elem.tar.gz bin
CC=x86_64-w64-mingw32-gcc BIN=bin/elem.exe make
CC=i686-w64-mingw32-gcc BIN=bin/elem_32.exe make
strip --strip-all bin/elem
rm elem.tar.gz
tar -cvf elem.tar.gz bin