X-Git-Url: http://git.shiar.net/netris.git/blobdiff_plain/788e0359aa0a3c6eec0238b828ee7d24c83e7a0c..ddbae5789635a63fcf36a84056f9df4bc8b6adaa:/client.c diff --git a/client.c b/client.c index 0974c22..6110445 100644 --- a/client.c +++ b/client.c @@ -21,6 +21,7 @@ #include "netris.h" #include +#include #include #include #include @@ -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,25 @@ void OneGame(void) 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; } } @@ -404,42 +426,34 @@ 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;