From: Christian Heller Date: Tue, 28 Oct 2014 22:50:25 +0000 (+0100) Subject: Server: meta command STACK to list item stack below player in out file. X-Git-Tag: tce~620 X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/%7B%7Bprefix%7D%7D/%7B%7Btodo.date%7D%7D?a=commitdiff_plain;h=a9377a5125c28779f812f859564d4f4d0b744e89;p=plomrogue Server: meta command STACK to list item stack below player in out file. --- diff --git a/SERVER_COMMANDS b/SERVER_COMMANDS index a39cf72..6d011c7 100644 --- a/SERVER_COMMANDS +++ b/SERVER_COMMANDS @@ -51,6 +51,10 @@ Write "PONG" line to ./server/out file. QUIT Shut down server. +STACK +Write line-by-line list of items the player stands on into ./server/out file, +enclosed by two lines "THINGS_BELOW_PLAYER START" and "THINGS_BELOW_PLAYER END". + Player commands --------------- diff --git a/TODO b/TODO index a5eb094..2b78587 100644 --- a/TODO +++ b/TODO @@ -11,6 +11,9 @@ BOTH SERVER/CLIENT: CLIENT: +- split Available keys window in two (Global keys (maybe drop that, replace it + by F6 window), Active window's keys) + - re-work unnecessary complex command / keybinding / server message mapping BUILD PROCESS: diff --git a/src/server/run.c b/src/server/run.c index 334fe41..808be55 100644 --- a/src/server/run.c +++ b/src/server/run.c @@ -5,7 +5,7 @@ * see the file NOTICE in the root directory of the PlomRogue source package. */ -#define _POSIX_C_SOURCE 200809L +#define _POSIX_C_SOURCE 200809L /* strdup() */ #include "run.h" #include /* NULL */ #include /* uint8_t, uint16_t, uint32_t, int16_t */ @@ -28,9 +28,9 @@ #include "god_commands.h" /* parse_god_command_(1|2|3)arg() */ #include "hardcoded_strings.h" /* s */ #include "io.h" /* io_round(), save_world() */ -#include "things.h" /* Thing, get_thing_action_id_by_name(), get_player(), - * try_thing_proliferation() - */ +#include "things.h" /* Thing, ThingType, get_thing_action_id_by_name(), + * get_player(), try_thing_proliferation() + */ #include "world.h" /* world */ @@ -71,6 +71,12 @@ static uint8_t thing_in_whitelist(uint8_t id, int16_t * whitelist); */ static void turn_over(); +/* Append "answer" to server output file, with instant fflush(). */ +static void answer_query(char * answer); + +/* Try to read "msg" as meta command, act accordingly; on success, free it. */ +static uint8_t meta_commands(char * msg); + static uint8_t set_char_by_string_comparison(char * string, char * comparand, @@ -289,6 +295,51 @@ static void turn_over() +static void answer_query(char * answer) +{ + try_fwrite(answer, strlen(answer), 1, world.file_out, __func__); + fflush(world.file_out); +} + + + +static uint8_t meta_commands(char * msg) +{ + if (!strcmp("QUIT", msg)) + { + free(msg); + return 2; + } + if (!strcmp("PING", msg)) + { + free(msg); + answer_query("PONG\n"); + return 1; + } + if (!strcmp("STACK", msg)) + { + free(msg); + answer_query("THINGS_BELOW_PLAYER START\n"); + struct Thing * player = get_player(); + struct Thing * t; + for (t = world.things; t; t = t->next) + { + if ( t->pos.y == player->pos.y && t->pos.x == player->pos.x + && t != player) + { + struct ThingType * tt = get_thing_type(t->type); + answer_query(tt->name); + answer_query("\n"); + } + } + answer_query("THINGS_BELOW_PLAYER END\n"); + return 1; + } + return 0; +} + + + extern void record(char * msg, uint8_t force) { static FILE * file_tmp = NULL; @@ -375,17 +426,13 @@ extern uint8_t io_loop() { exit_trouble(-1 == printf("Input: %s\n", msg), __func__, "printf"); } - if (!strcmp("QUIT", msg)) - { - free(msg); - return 1; - } - if (!strcmp("PING", msg)) + uint8_t test = meta_commands(msg); + if (test) { - free(msg); - char * pong = "PONG\n"; - try_fwrite(pong, strlen(pong), 1, world.file_out, __func__); - fflush(world.file_out); + if (2 == test) + { + return 1; + } continue; } if (world.replay) diff --git a/src/server/run.h b/src/server/run.h index 7436cb7..85c1339 100644 --- a/src/server/run.h +++ b/src/server/run.h @@ -27,12 +27,11 @@ extern void record(char * msg, uint8_t force); */ extern void obey_msg(char * msg, uint8_t do_record, uint8_t do_verbose); -/* Loop for receiving commands via io_round() and acting on them. Exits with 1 +/* Loop for receiving commands via io_round(), and acting on them. Exits with 1 * on "QUIT" command. In replay mode, exits with 0 on each non-"QUIT" command. - * Writes a "PONG" line to server output file on "PING" command. In play mode, - * processes further incomming commands via obey_msg(). Compares the first line - * of the server out file with world.server_test to ensure that the current - * server process has not been superseded by a new one. + * In play mode, processes incomming god and player commands via obey_msg(). + * Compares the first line of the server out file with world.server_test to + * ensure that the current server process has not been superseded by a new one. */ extern uint8_t io_loop();