* 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 <stddef.h> /* NULL */
#include <stdint.h> /* uint8_t, uint16_t, uint32_t, int16_t */
#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 */
*/
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,
+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;
{
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)
*/
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();