check for game in pause command itself
[netris.git] / client.c
index 1b48a8e100ba87599d33b84b42de7ca0c7888210..47916fc27cdf9d5a14259da20115c496fe7e5fa0 100644 (file)
--- a/client.c
+++ b/client.c
@@ -21,6 +21,7 @@
 #include "netris.h"
 
 #include <stdlib.h>
+#include <stdbool.h>
 #include <ctype.h>
 #include <string.h>
 #include <sys/types.h>
@@ -65,9 +66,11 @@ _Sets Sets = {7, 0, 1, 1, 1};
 static char keyTable[KT_numKeys+1];
 
 enum {
+       CT_quit, CT_pause,
        CT_MAX
 };
 static char *cmds[] = {
+       "quit", "pause"
 };
 
 static char *hostStr;
@@ -337,6 +340,26 @@ void OneGame(void)
        void handle_cmd(char cmd, char *arg)
        {
                switch (cmd) {
+               case CT_quit:
+                       ShowPause(me);
+                       refresh();
+                       gameStatus = 0;
+                       return;
+               case CT_pause:
+                       if (Players[me].alive <= 0) return;
+                       Players[me].flags ^= SCF_paused;
+                       if (Game.started > 1)
+                               Message(Players[me].flags & SCF_paused
+                                       ? "You paused the game" : "You unpaused the game");
+                       else
+                               Message(Players[me].flags & SCF_paused
+                                       ? "You are not ready" : "You are ready");
+                       checkPaused();
+                       if (game == GT_classicTwo)
+                               SendPacket(me, NP_pause, 0, NULL);
+                       ShowPause(me);
+                       changed = 1;
+                       return;
                }
        }
 
@@ -362,8 +385,11 @@ void OneGame(void)
        void handle_str(char *str)
        {
                if (chatText[0] == '/') {
+                       if (chatText[1] != '/') {
                                handle_cmdstr(chatText + 1);
                                return;
+                       }
+                       memmove(chatText, chatText + 1, strlen(chatText));
                }
 
                Message("<\\%d%s\\7> %s",
@@ -401,45 +427,36 @@ void OneGame(void)
                if (!(p = strchr(keyTable, tolower(key)))) return;
                key = p - keyTable;
 
-               // global actions (always possible, even if not playing)
+       bool handle_key(char key)
+       {
                switch (key) {
                case KT_redraw:
                        clear();
                        InitFields();
 //                     ScheduleFullRedraw();
                        refresh();
-                       return;
+                       return 1;
                case KT_say:
                        chatMode = 1;
                        Messagetype(key, strlen(chatText) - 1, chatText);
-                       return;
+                       return 1;
                case KT_quit:
-                       ShowPause(me);
-                       refresh();
-                       gameStatus = 0;
-                       return;
+                       handle_cmd(CT_quit, NULL);
+                       return 1;
+               default:
+                       return 0;
                }
+       }
+               // global actions (always possible, even if not playing)
+               if (handle_key(key)) return;
 
-               if (Players[me].alive <= 0) return;
                // actions available while in game
                switch (key) {
                case KT_pause:
-                       Players[me].flags ^= SCF_paused;
-                       if (Game.started > 1)
-                               Message(Players[me].flags & SCF_paused
-                                       ? "You paused the game" : "You unpaused the game");
-                       else
-                               Message(Players[me].flags & SCF_paused
-                                       ? "You are not ready" : "You are ready");
-                       checkPaused();
-                       if (game == GT_classicTwo)
-                               SendPacket(me, NP_pause, 0, NULL);
-                       ShowPause(me);
-                       changed = 1;
-                       return;
+                       return handle_cmd(CT_pause, NULL);
                }
 
-               if (paused) return;
+               if (Players[me].alive <= 0 || paused) return;
                // actions only available while actually playing
                switch (key) {
                case KT_left: