missing features (notable on Tetris DS)
[netris.git] / client.c
index 67d6f8df9faa51f2a5d3ca55b4bc29a0f76b980f..9c228d857d4a756c4944689ca7b7fd420be88a51 100644 (file)
--- a/client.c
+++ b/client.c
@@ -64,6 +64,14 @@ _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;
 static int paused = 0;
 static char lastadd;
@@ -105,18 +113,34 @@ void MapKeys(char *newKeys)
                exit(1);
 }
 
-void WriteConf(void)
+void Usage(void)
 {
-       FILE *file_out;
-
-       file_out = fopen(CONFIG_FILE, "w");
-       if (file_out == NULL)
-               die("Error writing config file");
-
-       fprintf(file_out, "### NETRIS %s Config file ###\n\n", version_string);
-
-       fclose(file_out);
-       fprintf(stderr, "Wrote new game configuration to %s\n", CONFIG_FILE);
+       Header();
+       fprintf(stderr,
+               "Usage: netris <options>\n"
+               "\n"
+               "  -h, --help\t\tPrint this usage information\n"
+               "  -H, --info\t\tShow distribution and warranty information\n"
+               "  -R, --rules\t\tShow game rules\n"
+               "\n"
+               "  -S, --slowterm\tDisable inverse/bold/color for slow terminals\n"
+               "  -a, --ascii\t\tUse ascii characters\n"
+               "  -C, --color=0\t\tDisable color\n"
+               "\n"
+               "  -c, --connect <host>\tInitiate connection\n"
+               "  -p, --port <port>\tSet port number (default is %d)\n"
+               "\n"
+               "  -t, --team <team>\tJoin a team (don't receive lines from your teammates)\n"
+               "  -l, --level <lvl>\tBegin at a higher level (can be used as handicap)\n"
+               "  -k, --keys <keys>\tRemap keys (default is \"%s\" for cursors)\n"
+               "  -d, --dropmode\tDrops go into drop mode\n"
+               "  -D, --instadrop\tInstant drop\n"
+               "\n"
+               "  -r, --robot <cmd>\tExecute program to control the game instead of keyboard\n"
+               "  -F, --fair-robot\tUse fair robot interface\n"
+               "\n",
+               DEFAULT_PORT, DEFAULT_KEYS
+       );
 }
 
 void HandleOption(char tag, char *value)
@@ -281,7 +305,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);
@@ -312,6 +336,67 @@ void OneGame(void)
        int chatMode = 0;
        char chatText[MSG_WIDTH] = "\0";
 
+       void handle_cmd(char cmd, char *arg)
+       {
+               switch (cmd) {
+               case CT_quit:
+                       ShowPause(me);
+                       refresh();
+                       gameStatus = 0;
+                       return;
+               case CT_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;
+               }
+       }
+
+       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] == '/') {
+                       if (chatText[1] != '/') {
+                               handle_cmdstr(chatText + 1);
+                               return;
+                       }
+                       memmove(chatText, chatText + 1, strlen(chatText));
+               }
+
+               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;
@@ -321,11 +406,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
@@ -357,29 +438,14 @@ void OneGame(void)
                        Messagetype(key, strlen(chatText) - 1, chatText);
                        return;
                case KT_quit:
-                       ShowPause(me);
-                       refresh();
-                       gameStatus = 0;
-                       return;
+                       return handle_cmd(CT_quit, NULL);
                }
 
                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;