home · contact · privacy
Server: meta command STACK to list item stack below player in out file.
authorChristian Heller <c.heller@plomlompom.de>
Tue, 28 Oct 2014 22:50:25 +0000 (23:50 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 28 Oct 2014 22:50:25 +0000 (23:50 +0100)
SERVER_COMMANDS
TODO
src/server/run.c
src/server/run.h

index a39cf7242d15fae0df3e79e6d1f1f021652bf474..6d011c7e83d0b41fbc8e50214e9f72bbdcaaee24 100644 (file)
@@ -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 a5eb09432b8f8b604ace9f715fc6f9a1e9196343..2b78587e389c2dbe1e44e199a21908748d6780a8 100644 (file)
--- 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:
index 334fe410fcf9200713725ee2f8adcc81b22f2c53..808be55398a3a03e7f1d69d67c104d3850ebaffd 100644 (file)
@@ -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 <stddef.h> /* NULL */
 #include <stdint.h> /* 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)
index 7436cb7429982054d42f60ba9dcbe2dd907f8df7..85c1339d8703b196922e1d94f4245c2bcb6d4ffc 100644 (file)
@@ -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();