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 #ifndef GLOBAL_H 26 #define GLOBAL_H 1 27 28 #include <gtk/gtk.h> 29 #include "eboard.h" 30 #include "text.h" 31 #include "network.h" 32 #include "protocol.h" 33 #include "position.h" 34 #include "chess.h" 35 #include "sound.h" 36 #include "seekgraph.h" 37 #include "history.h" 38 #include "bugpane.h" 39 #include "clock.h" 40 #include "stl.h" 41 42 class Board; 43 class OutputPane; 44 class TextSet; 45 class NetConnection; 46 class Status; 47 class Protocol; 48 class ChessGame; 49 class Notebook; 50 class QuickBar; 51 class QButton; 52 class SeekGraph; 53 class SoundSlave; 54 class StringCollection; 55 class BugPane; 56 class PieceSet; 57 class VectorPieces; 58 59 class HostBookmark { 60 public: 61 HostBookmark(); 62 int operator==(HostBookmark *hbm); 63 char host[128]; 64 int port; 65 char protocol[64]; 66 }; 67 68 class EngineBookmark { 69 public: 70 int operator==(EngineBookmark *ebm); 71 void read(tstring &t); 72 73 string caption; 74 string directory; 75 string cmdline; 76 int humanwhite; 77 TimeControl timecontrol; 78 int maxply; 79 int think; 80 int proto; 81 variant mode; 82 83 }; 84 85 class ZombieHunter { 86 public: 87 ZombieHunter(); 88 ~ZombieHunter(); 89 void add(int pid, SigChildHandler *sigh); 90 91 private: 92 void handleSigChild(); 93 friend void zh_sigchild_handler(int sig); 94 95 vector<int> pids; 96 vector<SigChildHandler *> handlers; 97 }; 98 99 void zh_sigchild_handler(int sig); 100 101 class IcsChannel { 102 public: 103 IcsChannel(char *s); // s like "49\tmamer tourneys\n" 104 string name; 105 int number; 106 }; 107 108 class ChannelSplitter : public SigChildHandler 109 { 110 public: ~ChannelSplitter()111 virtual ~ChannelSplitter() {} 112 void appendToChannel(int ch,char *msg,int color,Importance im=IM_NORMAL); 113 virtual Notebook * getNotebook()=0; 114 115 void removeRemovablePage(int n); 116 void getChannels(char *ipaddr); 117 void channelPageUp(int ch); 118 void channelPageDown(int ch); 119 120 void ZombieNotification(int pid); 121 void updateFont(); 122 123 protected: 124 void updateChannelScrollBacks(); 125 126 private: 127 void ensurePane(int ch); 128 void createPane(int ch); 129 130 void parseChannelList(); 131 const char * getChannelTitle(int n); 132 vector<Text *> panes; 133 vector<int> numbers; 134 string chlist; 135 vector<IcsChannel> channels; 136 }; 137 138 class TerminalColor { 139 public: 140 TerminalColor(); 141 void read(tstring &t); 142 143 int TextDefault; 144 int TextBright; 145 int PrivateTell; 146 int NewsNotify; 147 int Mamer; 148 int KibitzWhisper; 149 int Shouts; 150 int Seeks; 151 int ChannelTell; 152 int Engine; 153 int Background; 154 }; 155 156 class WindowGeometry { 157 public: 158 WindowGeometry(int a,int b,int c,int d); 159 WindowGeometry(); 160 161 void read(tstring &t); 162 void print(); 163 164 void retrieve(GtkWidget *w); 165 bool isNull(); 166 void setNull(); 167 int X,Y,W,H; 168 }; 169 170 class Desktop { 171 public: 172 173 Desktop(); 174 void clear(); 175 176 void read(tstring &t); 177 void readConsole(tstring &t); 178 void writeConsoles(ostream &s, const char *key); 179 180 void addConsole(DetachedConsole *dc); 181 void spawnConsoles(TextSet *ts); 182 183 184 WindowGeometry wMain, wGames, wLocal, wAds; 185 int PanePosition; 186 187 private: 188 vector<WindowGeometry *> consoles; 189 vector<string *> cfilters; 190 }; 191 192 class Environment { 193 public: 194 Environment(); 195 196 string Home; 197 string User; 198 string Config; 199 }; 200 201 class Global : public ChannelSplitter 202 { 203 public: 204 Global(); ~Global()205 virtual ~Global() {} 206 207 ChessGame * getGame(int num); 208 void removeBoard(Board *b); 209 int nextFreeGameId(int base); 210 void repaintAllBoards(); 211 212 void appendGame(ChessGame *cg,bool RenumberDupes=true); 213 void prependGame(ChessGame *cg,bool RenumberDupes=true); 214 void deleteGame(ChessGame *cg); 215 216 void statOS(); 217 void ensureDirectories(); 218 void readRC(); 219 void writeRC(); 220 221 void addHostBookmark(HostBookmark *hbm); 222 void addEngineBookmark(EngineBookmark *ebm); 223 224 void WrappedMainIteration(); 225 void WrappedMainQuit(); 226 void LogAppend(const char *msg); 227 void debug(const char *klass,const char *method,const char *data=0); 228 229 void dumpGames(); 230 void dumpBoards(); 231 void dumpPanes(); 232 233 void gatherConsoleState(); 234 235 void addAgent(NetConnection *ag); 236 void removeAgent(NetConnection *ag); 237 void agentBroadcast(char *z); 238 int receiveAgentLine(char *dest,int limit); 239 240 bool effectiveLegalityChecking(); 241 242 /* issue sound events */ 243 void opponentMoved(); 244 void drawOffered(); 245 void privatelyTold(); 246 void challenged(); 247 void timeRunningOut(); 248 void gameWon(); 249 void gameLost(); 250 void gameStarted(); 251 void gameFinished(); 252 void moveMade(); 253 254 void flushSound(); 255 void setPasswordMode(int pm); 256 // void clearSoundStack(); 257 258 void updateScrollBacks(); 259 void dropQuickbarButtons(); 260 261 bool hasSoundFile(string &p); 262 263 Notebook * getNotebook(); 264 265 void setPieceSet(string &filename,bool chgPieces,bool chgSquares); 266 void respawnPieceSet(); 267 void addPieceClient(PieceChangeListener *pcl); 268 void removePieceClient(PieceChangeListener *pcl); 269 270 const char * filter(const char *s); 271 272 // free with free() as usual 273 static void * safeMalloc(int nbytes); 274 275 list<ChessGame *> GameList; 276 list<ChessGame *>::iterator GLi; 277 list<Board *> BoardList; 278 list<Board *>::iterator BLi; 279 list<int> TheOffspring; 280 281 list<NetConnection *> Agents; 282 list<DetachedConsole *> Consoles; 283 list<PieceChangeListener *> PieceClients; 284 285 VectorPieces vpieces; 286 PieceSet *pieceset; 287 288 InputHandler *input; 289 OutputPane *output; 290 NetConnection *network; 291 Status *status; 292 Protocol *protocol; 293 ConnectionHandler *chandler; 294 PieceProvider *promotion; 295 Notebook *ebook; 296 SeekGraph2 *skgraph2; 297 History *inputhistory; 298 BookmarkListener *bmlistener; 299 UpdateInterface *qbcontainer; 300 QuickBar *quickbar; 301 GtkWidget *killbox; 302 GtkWidget *lowernotebook; 303 GtkWidget *mainpaned; 304 GtkWidget *toplevelwidget; 305 BugPane *bugpane; 306 IONotificationInterface *iowatcher; 307 308 StringCollection annotator; 309 ZombieHunter zombies; 310 311 int SelfInputColor; 312 int PasswordMode; 313 314 int LastScratch; 315 316 int HilightLastMove; 317 int AnimateMoves; 318 int Premove; 319 320 int TabPos; // 0=R 1=L 2=T 3=B 321 322 char ClockFont[96]; 323 char PlayerFont[96]; 324 char InfoFont[96]; 325 char ConsoleFont[96]; 326 char SeekFont[96]; 327 328 int PlainSquares; 329 int LightSqColor; 330 int DarkSqColor; 331 332 int ShowTimestamp; 333 int ShowRating; 334 int ScrollBack; 335 int FicsAutoLogin; 336 int IcsSeekGraph; 337 int HideSeeks; 338 int BeepWhenOppMoves; 339 int EnableSounds; 340 int UseVectorPieces; 341 int CheckLegality; 342 int SpecialChars; // 0=none 1=truncate 2=underscore 3=soft translate (a^) 343 int MsecThreshold; 344 int MsecDigits; 345 346 int SplitChannels; 347 int ChannelsToConsoleToo; 348 int DrawHouseStock; 349 350 int AppendPlayed; 351 int AppendObserved; 352 char AppendFile[128]; 353 354 int PopupSecondaryGames; 355 int SmartDiscard; 356 357 int ShowCoordinates; 358 int ShowQuickbar; 359 int RetrieveChannelNames; 360 bool PopupHelp; 361 int LowTimeWarningLimit; 362 int SmootherAnimation; 363 int IcsAllObPlayed; 364 int IcsAllObObserved; 365 366 char P2PName[64]; 367 368 TerminalColor Colors; 369 Desktop Desk; 370 371 // 0=opponent moved, 1=draw offer 2=pvt tell 3=challenged 372 // 4=time running out 373 // 5=won game 6=lost game 7=game started 374 // 8=game over (observed) 375 // 9=moved (observed) 376 SoundEvent sndevents[N_SOUND_EVENTS]; 377 378 int CommLog; 379 int DebugLog; 380 int PauseLog; 381 382 int Quitting; 383 384 list<HostBookmark *> HostHistory; 385 list<EngineBookmark *> EnginePresets; 386 387 vector<string> SoundFiles; 388 vector<QButton *> QuickbarButtons; 389 390 const char * Version; 391 char SystemType[64]; 392 char argv0[512]; 393 394 Environment env; 395 396 string ConsoleReply; 397 398 private: 399 int createDir(char *z); 400 void renumberGame(ChessGame *cg,int id); 401 void clearDupes(ChessGame *cg); 402 403 void playOther(int i); 404 405 void unicodeNormalize(string &dest, gunichar src); 406 407 int MainLevel; 408 int QuitPending; 409 410 vector<const char *> RCKeys; 411 stack<int> SoundStack; 412 }; 413 414 #ifndef GLOBAL_CC 415 extern Global global; 416 #endif 417 418 #endif 419