home · contact · privacy
Client: Send no arguments for commands where the server expects none.
[plomrogue] / src / client / control.c
index f97f5bdcffe0b8a8e0a4ef2f70e5792af4dd5d93..7ff99f3e75d39f538c6ede99b63431a178e850a3 100644 (file)
@@ -5,7 +5,7 @@
 #include <stdlib.h> /* free() */
 #include <stdio.h> /* sprintf() */
 #include <string.h> /* strlen() */
-#include "../common/rexit.h" /* exit_err() */
+#include "../common/rexit.h" /* exit_err(), exit_trouble() */
 #include "../common/try_malloc.h" /* try_malloc() */
 #include "interface_conf.h" /* reload_interface_conf(), save_interface_conf() */
 #include "io.h" /* send() */
@@ -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,16 +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);
-        sprintf(msg, "%s %d", command->server_msg, arg);
-        send(msg);
-        free(msg);
         return 1;
     }
     return 0;