home · contact · privacy
Client: Send no arguments for commands where the server expects none.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 10 Jul 2014 04:38:14 +0000 (06:38 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 10 Jul 2014 04:38:14 +0000 (06:38 +0200)
TODO
src/client/command_db.h
src/client/control.c

diff --git a/TODO b/TODO
index b909b04fb74280aef274705b22a1f913807b79e3..5123c14d80878e6c522ad79d57dd1958da190bf1 100644 (file)
--- a/TODO
+++ b/TODO
@@ -9,6 +9,8 @@ BOTH SERVER/CLIENT:
 - make server and client communicate by specific world state info requests 
   in server/out, replacing server/worldstate
 
+- beautify form of command arguments (strings instead of numbers for directions)
+
 SERVER:
 
 - consider
@@ -24,5 +26,3 @@ CLIENT:
 - enable toggling of window borders
 
 - make log scrollable
-
-- send zero-argument player commands without argument
index 09273d145274830ea2d6871168ece26c6a114f64..93acce9d228df5a0f2d39c4ce7b0bea54727974b 100644 (file)
@@ -17,7 +17,7 @@ struct Command
     char * dsc_short; /* short name of command to be used internally */
     char * dsc_long; /* long description of command to be shown to the user */
     char * server_msg; /* optionally start string of message to send to server*/
-    char arg; /* defines server message suffix by player_control() convention */
+    char arg; /* defines server message suffix by try_server_commands() rules */
 };
 
 struct CommandDB
index 02e4fed2360bf8fda263b7b4f54ef0b1eda7733d..7ff99f3e75d39f538c6ede99b63431a178e850a3 100644 (file)
@@ -42,7 +42,8 @@ static uint8_t try_client_commands(struct Command * command);
 
 /* Try out "command" as one for server messaging; sending is .server_msg,
  * followed by either a string representing "command"'s .arg, or, if .arg is
- * 'i', world.player_inventory_select. Return 1 on success, 0 on failure.
+ * 'i', world.player_inventory_select, or, if .arg is '0', nothing. Return 1 on
+ * success, 0 on failure.
  */
 static uint8_t try_server_commands(struct Command * command);
 
@@ -162,17 +163,24 @@ static uint8_t try_server_commands(struct Command * command)
     if (command->server_msg)
     {
         uint8_t arg = (uint8_t) command->arg;
-        if ('i' == arg)
+        if ('0' == arg)
         {
-            arg = world.player_inventory_select;
+            send(command->server_msg);
+        }
+        else
+        {
+            if ('i' == arg)
+            {
+                arg = world.player_inventory_select;
+            }
+            uint8_t command_size = strlen(command->server_msg);
+            uint8_t arg_size = 3;
+            char * msg = try_malloc(command_size + 1 + arg_size + 1, f_name);
+            int test = sprintf(msg, "%s %d", command->server_msg, arg);
+            exit_trouble(test < 0, f_name, "sprintf()");
+            send(msg);
+            free(msg);
         }
-        uint8_t command_size = strlen(command->server_msg);
-        uint8_t arg_size = 3;
-        char * msg = try_malloc(command_size + 1 + arg_size + 1, f_name);
-        int test = sprintf(msg, "%s %d", command->server_msg, arg);
-        exit_trouble(test < 0, f_name, "sprintf()");
-        send(msg);
-        free(msg);
         return 1;
     }
     return 0;