home · contact · privacy
Server: Execute THINGS_HERE command only on existing worlds.
[plomrogue] / src / server / run.c
index a1bf343b57599b9c66b384caf2351ce66273180f..d88d583041b3f5007686d42a1ac02a383ee9d549 100644 (file)
 #include <stddef.h> /* NULL */
 #include <stdint.h> /* uint8_t, uint16_t, uint32_t, int16_t */
 #include <stdio.h> /* FILE, printf(), fflush() */
-#include <stdlib.h> /* free() */
+#include <stdlib.h> /* atoi(), free() */
 #include <string.h> /* strlen(), strcmp(), strncmp(), strdup() */
 #include <time.h> /* time_t, time() */
 #include <unistd.h> /* access() */
 #include "../common/parse_file.h" /* set_err_line_options(), token_from_line(),
-                                   * err_line(), err_line_inc(), parse_val()
+                                   * err_line(), err_line_inc(), parse_val(),
+                                   * parestest_int()
                                    */
 #include "../common/readwrite.h" /* try_fopen(), try_fcose(), try_fwrite(),
                                   * try_fgets(), textfile_width(), try_fputc(),
@@ -207,23 +208,31 @@ static uint8_t parse_command_meta(char * tok0)
         send_to_outfile("PONG\n", 1);
         return 1;
     }
-    if (!strcmp("STACK", tok0))
+    if (!strcmp("THINGS_HERE", tok0))
     {
-        send_to_outfile("THINGS_BELOW_PLAYER START\n", 1);
-        struct Thing * player = get_player();
-        struct Thing * t;
-        for (t = world.things; t; t = t->next)
+        char * tok1 = token_from_line(NULL);
+        char * tok2 = token_from_line(NULL);
+        if (tok1&&tok2 && !parsetest_int(tok1, '8')&&!parsetest_int(tok2, '8'))
         {
-            if (   t->pos.y == player->pos.y && t->pos.x == player->pos.x
-                && t != player)
+            if (!world.exists)
             {
-                struct ThingType * tt = get_thing_type(t->type);
-                send_to_outfile(tt->name, 0);
-                send_to_outfile("\n", 1);
+                err_line(1, "Command only works on existing worlds.");
+                return 0;
             }
+            send_to_outfile("THINGS_HERE START\n", 1);
+            struct Thing * t;
+            for (t = world.things; t; t = t->next)
+            {
+                if (t->pos.y == atoi(tok1) && t->pos.x == atoi(tok2))
+                {
+                    struct ThingType * tt = get_thing_type(t->type);
+                    send_to_outfile(tt->name, 0);
+                    send_to_outfile("\n", 1);
+                }
+            }
+            send_to_outfile("THINGS_HERE END\n", 1);
+            return 1;
         }
-        send_to_outfile("THINGS_BELOW_PLAYER END\n", 1);
-        return 1;
     }
     return 0;
 }
@@ -407,7 +416,7 @@ extern uint8_t obey_msg(char * msg, uint8_t obey_state)
         }
         else if (!world.replay)
         {
-            err_line(1, "Unknown command/argument or bad number of tokens.");
+            err_line(1, "Invalid command/argument or bad number of tokens.");
         }
     }
     free(msg_copy);