1 /* 2 3 eboard - chess client 4 http://www.bergo.eng.br/eboard 5 https://github.com/fbergo/eboard 6 Copyright (C) 2000-2016 Felipe Bergo 7 fbergo/at/gmail/dot/com 8 9 This program is free software; you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation; either version 2 of the License, or 12 (at your option) any later version. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 23 */ 24 25 // don't #include this, #include protocol.h instead 26 27 #ifndef PROTO_FICS_H 28 #define PROTO_FICS_H 1 29 30 #include <gtk/gtk.h> 31 #include "stl.h" 32 #include "position.h" 33 34 class FicsProtocol : public Protocol { 35 public: 36 FicsProtocol(); 37 virtual ~FicsProtocol(); 38 39 void receiveString(char *netstring); 40 void sendMove(int x1,int y1,int x2,int y2,int prom); 41 void sendDrop(piece p,int x,int y); 42 void finalize(); 43 int hasAuthenticationPrompts(); 44 45 void resign(); 46 void draw(); 47 void adjourn(); 48 void abort(); 49 50 void discardGame(int gameid); 51 void queryGameList(GameListConsumer *glc); 52 void queryAdList(GameListConsumer *glc); 53 void observe(int gameid); 54 void answerAd(int adid); 55 56 void exaForward(int n); 57 void exaBackward(int n); 58 59 void refreshSeeks(bool create); 60 61 vector<string *> * getPlayerActions(); 62 vector<string *> * getGameActions(); 63 64 void callPlayerAction(char *player, string *action); 65 void callGameAction(int gameid, string *action); 66 67 private: 68 void createGame(ExtPatternMatcher &pm); 69 void createExaminedGame(int gameid,char *whitep,char *blackp); 70 void createScratchPos(int gameid,char *whitep,char *blackp); 71 void addGame(ExtPatternMatcher &pm); 72 void removeGame(ExtPatternMatcher &pm); 73 void innerRemoveGame(int gameid); 74 void parseStyle12(char *data); 75 void gameOver(ExtPatternMatcher &pm, GameResult result); 76 void updateGame(ExtPatternMatcher &pm); 77 void attachHouseStock(ExtPatternMatcher &pm, bool OnlyForBughouse); 78 79 void clearMoveBuffer(); 80 void retrieve1(ExtPatternMatcher &pm); 81 void retrieve2(ExtPatternMatcher &pm); 82 void retrievef(); 83 void retrieveMoves(ExtPatternMatcher &pm); 84 85 void sendGameListEntry(); 86 void sendAdListEntry(char *pat); 87 void sendInitialization(); 88 89 char *knowRating(char *player); 90 void clearRatingBuffer(); 91 92 void ensureSeekGraph(); 93 void seekAdd(ExtPatternMatcher &pm); 94 void seekRemove(ExtPatternMatcher &pm); 95 96 void doPlayerAction(char *player, int id); 97 void doGameAction(int gameid, int id); 98 99 void prepareBugPane(); 100 101 void updateVar(ProtocolVar pv); 102 103 bool doAllOb1(); 104 void doAllOb2(); 105 106 friend gboolean fics_allob(gpointer data); 107 108 /* private parsing state and parsing methods */ 109 110 bool AuthGone; 111 bool InitSent; 112 bool LecBotSpecial; 113 bool LastWasStyle12; 114 bool LastWasPrompt; 115 bool UseMsecs; 116 117 bool RetrievingGameList; 118 bool RetrievingAdList; 119 int RetrievingMoves; 120 int PendingStatus; 121 122 int LastChannel; 123 int LastColor; 124 125 /* all parser* methods return true if all parsing has been done, 126 false if something must still be done. 127 (and I'm trying to avoid any false returns, making it all 128 functional-programming-happy) 129 */ 130 131 bool parser1(char *T); /* prompt removal */ 132 bool parser2(char *T); /* early login */ 133 bool parser3(char *T); /* game events */ 134 bool parser4(char *T); /* list retrieval */ 135 bool parser5(char *T); /* server/game events */ 136 bool parser6(char *T); /* game termination */ 137 bool parser7(char *T); /* bughouse and other oddities */ 138 bool parser8(char *T); /* chat */ 139 140 bool doOutput(char *msg, int channel, bool personal, int msgcolor); 141 142 PatternBinder Binder; 143 144 PatternMatcher WelcomeMessage; 145 PatternMatcher UserName; 146 147 ExtPatternMatcher Login; 148 ExtPatternMatcher Password; 149 ExtPatternMatcher Prompt; 150 151 ExtPatternMatcher CreateGame; 152 ExtPatternMatcher CreateGame0; 153 ExtPatternMatcher ContinueGame; 154 ExtPatternMatcher BeginObserve; 155 ExtPatternMatcher EndObserve; 156 ExtPatternMatcher NotObserve; 157 ExtPatternMatcher EndExamine; 158 159 ExtPatternMatcher GameStatus; 160 ExtPatternMatcher ExaGameStatus; 161 ExtPatternMatcher GameListEntry; 162 ExtPatternMatcher EndOfGameList; 163 164 ExtPatternMatcher AdListEntry; 165 ExtPatternMatcher EndOfAdList; 166 167 ExtPatternMatcher Style12; 168 ExtPatternMatcher Style12House; 169 ExtPatternMatcher Style12BadHouse; 170 171 ExtPatternMatcher WhiteWon; 172 ExtPatternMatcher BlackWon; 173 ExtPatternMatcher Drawn; 174 ExtPatternMatcher Interrupted; 175 ExtPatternMatcher DrawOffer; 176 177 ExtPatternMatcher PrivateTell; 178 ExtPatternMatcher News; 179 180 ExtPatternMatcher MovesHeader; 181 ExtPatternMatcher MovesHeader2; 182 ExtPatternMatcher MovesHeader3; 183 ExtPatternMatcher MovesHeader4; 184 ExtPatternMatcher MovesBody; 185 ExtPatternMatcher MovesBody2; 186 ExtPatternMatcher MovesEnd; 187 188 ExtPatternMatcher Kibitz; 189 ExtPatternMatcher Whisper; 190 ExtPatternMatcher Say; 191 ExtPatternMatcher Say2; 192 ExtPatternMatcher Shout; 193 ExtPatternMatcher cShout; 194 ExtPatternMatcher It; 195 ExtPatternMatcher ChannelTell; 196 ExtPatternMatcher Seek; 197 ExtPatternMatcher Notify; 198 ExtPatternMatcher Challenge; 199 200 ExtPatternMatcher LectureBotXTell; 201 ExtPatternMatcher LectureBotXTellContinued; 202 203 ExtPatternMatcher PTell; 204 ExtPatternMatcher GotPartnerGame; 205 206 ExtPatternMatcher ObsInfoLine; 207 ExtPatternMatcher MsSet; 208 209 // seek graph 210 ExtPatternMatcher SgClear; 211 ExtPatternMatcher SgAdd; 212 ExtPatternMatcher SgAdd2; 213 ExtPatternMatcher SgRemove; 214 ExtPatternMatcher SgRemove2; 215 216 ExtPatternMatcher AllObNone; 217 ExtPatternMatcher AllObFirstLine; 218 ExtPatternMatcher AllObMidLine; 219 int AllObState; 220 char AllObAcc[1024]; 221 222 char nick[64]; 223 piece style12table[256]; 224 225 list<Position> MoveBuf; 226 deque<int> MoveRetrievals; 227 deque<int> AllObReqs; 228 vector<string *> PActions, GActions; 229 Position WildStartPos; 230 231 GameListConsumer *lastGLC, *lastALC; 232 233 // 2-position circular buffer to keep rating parsing state 234 char xxplayer[2][64]; 235 char xxrating[2][64]; 236 int xxnext, xxwhen; 237 238 int PartnerGame; 239 int LinesReceived; 240 bool UserPlayingWithWhite; /* for won/lost sound event tracking */ 241 }; 242 243 gboolean fics_allob(gpointer data); 244 245 #endif 246