typed messages with leading slash are interpreted as command
authorMischa POSLAWSKY <netris@shiar.org>
Sun, 4 Mar 2007 12:31:27 +0000 (13:31 +0100)
committerMischa POSLAWSKY <netris@shiar.org>
Sun, 4 Mar 2007 12:31:27 +0000 (13:31 +0100)
client.c

index a1e284d39475f5e9d282120ccf1dc1a05487db3d..1b48a8e100ba87599d33b84b42de7ca0c7888210 100644 (file)
--- a/client.c
+++ b/client.c
@@ -64,6 +64,12 @@ _Sets Sets = {7, 0, 1, 1, 1};
 
 static char keyTable[KT_numKeys+1];
 
+enum {
+       CT_MAX
+};
+static char *cmds[] = {
+};
+
 static char *hostStr;
 static int paused = 0;
 static char lastadd;
@@ -297,7 +303,7 @@ void CheckClears(int scr)
                Players[scr].score.score += Game.gravity
                        ? linevaluesq[linesCleared - 1] : linevalues[linesCleared - 1];
                Players[scr].score.lines += linesCleared;
-               Players[scr].score.adds += linesCleared - (linesCleared < 4);
+               Players[scr].score.adds += linesCleared - (linesCleared < 4); //XXX match handicap
                if (scr == me) {
                        if (game == GT_classicTwo) {
                                SendPacket(scr, NP_clear, 0, NULL);
@@ -328,6 +334,45 @@ void OneGame(void)
        int chatMode = 0;
        char chatText[MSG_WIDTH] = "\0";
 
+       void handle_cmd(char cmd, char *arg)
+       {
+               switch (cmd) {
+               }
+       }
+
+       void handle_cmdstr(char *cmd)
+       {
+               char tag[17], value[81];
+               char *cmdend;
+               int i;
+
+               if ((cmdend = strchr(cmd, ' '))) {
+                       *cmdend = 0;
+               } else {
+                       cmdend = cmd + strlen(cmd); // whole string
+               }
+               for (i = 0; i < CT_MAX; i++){
+                       if (!strcasecmp(cmds[i], cmd)) {
+                               return handle_cmd(i, cmdend + 1);
+                       }
+               }
+               Message("Unknown command /%s", cmd);
+       }
+
+       void handle_str(char *str)
+       {
+               if (chatText[0] == '/') {
+                               handle_cmdstr(chatText + 1);
+                               return;
+               }
+
+               Message("<\\%d%s\\7> %s",
+                       Players[me].team > 7 ? 7 : Players[me].team,
+                       Players[me].name, chatText);
+               if (game == GT_classicTwo)
+                       SendPacket(me, NP_msg, strlen(chatText) + 1, chatText);
+       }
+
        void GameKey(char key)
        {
                char *p;
@@ -337,11 +382,7 @@ void OneGame(void)
                                // enter text
                                chatMode = 0;
                                if (chatText[0]) {
-                                       Message("<\\%d%s\\7> %s",
-                                               Players[me].team > 7 ? 7 : Players[me].team,
-                                               Players[me].name, chatText);
-                                       if (game == GT_classicTwo)
-                                               SendPacket(me, NP_msg, strlen(chatText) + 1, chatText);
+                                       handle_str(chatText);
                                        memset(chatText, 0, sizeof(chatText));
                                } //say it
                                else Messagetype(27, -1, NULL); //escape