From: Christian Heller <c.heller@plomlompom.de>
Date: Thu, 10 Jul 2014 04:38:14 +0000 (+0200)
Subject: Client: Send no arguments for commands where the server expects none.
X-Git-Tag: tce~710
X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/static/%7B%7B%20web_path%20%7D%7D/decks/templates?a=commitdiff_plain;h=d2707c20a501a2c99af20c7e20f7c1a374bfe6aa;p=plomrogue

Client: Send no arguments for commands where the server expects none.
---

diff --git a/TODO b/TODO
index b909b04..5123c14 100644
--- 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
diff --git a/src/client/command_db.h b/src/client/command_db.h
index 09273d1..93acce9 100644
--- a/src/client/command_db.h
+++ b/src/client/command_db.h
@@ -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
diff --git a/src/client/control.c b/src/client/control.c
index 02e4fed..7ff99f3 100644
--- a/src/client/control.c
+++ b/src/client/control.c
@@ -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;