Let mamer take colors into account for pairing
[capablanca.git] / lasker-2.2.3 / bots / mamer / Mamer.hh
1 //--------------------------------------------------------------------------
2 // Mamer.hh - Class header for the Mamer class
3 //
4 // Matthew E. Moses & Michael A. Long
5 //
6 // $Revision: 1.11 $
7 // $Date: 1998/09/10 19:58:41 $
8 //
9 // $Author: mlong $
10 // $Locker:  $
11 //
12 // $Log: Mamer.hh,v $
13 // Revision 1.11  1998/09/10 19:58:41  mlong
14 // lots of little bug fixes and a few new features.
15 //
16 // Revision 1.10  1998/06/18 18:41:52  mlong
17 // prepairing for yet another move.
18 //
19 // Revision 1.9  1998/04/29 15:24:07  mlong
20 // prepairing for the move to daimi
21 // new sorting routine.
22 //
23 // Revision 1.8  1998/04/18 18:46:31  mlong
24 // fixed delete bug and
25 // added delete tourney function
26 //
27 // Revision 1.5  1997/05/15 18:29:12  chess
28 //  added pending and TourneyPlayers support
29 // added HandleGetPlayerInfo & HandleGetGameInfo
30 //
31 // Revision 1.4  1997/04/13 03:21:32  chess
32 // TellUser and ParseParams added
33 //
34 // Revision 1.3  1997/03/21 15:31:49  moses
35 // added some defines to support the solaris sun compile
36 //
37 // Revision 1.2  1996/10/01 20:14:43  moses
38 // Changes to support the new command list,
39 // to correctly have the commands, I had to derive this class from the
40 // CommandEntry class
41 //
42 // Revision 1.1  1996/09/30  20:52:48  moses
43 // Initial revision
44 //
45 //--------------------------------------------------------------------------
46
47 #ifndef _MAMER_
48 #define _MAMER_
49
50 #include <fstream>
51 #include <iostream>
52
53 using namespace std;
54
55 extern "C" {
56 #include <sys/param.h>
57 #include <sys/types.h>
58 #include <sys/time.h>
59
60 #include <ctype.h>
61 #include <errno.h>
62 #include <math.h>
63 #include <signal.h>
64 #include <stdio.h>
65 #include <stdlib.h>
66 #include <string.h>
67 #include <strings.h>
68 #include <sys/signal.h>
69 #include <sys/stat.h>
70
71 #include <sys/socket.h>
72 #include <netinet/in.h>
73 #include <netdb.h>
74 #include <arpa/inet.h>
75
76 #include <time.h>
77 #include <unistd.h>
78 #include <stdarg.h>
79 }
80
81 #ifdef SUN
82 #define INADDR_NONE -1
83 #endif
84
85 #include "config.h"
86 #include "link.hh"
87 #include "linklist.hh"
88 #include "User.hh"
89 #include "Tourney.hh"
90 #include "Command.hh"
91 #include "CommandEntry.hh"
92 #include "Player.hh"
93 #include "Game.hh"
94 #include "Storage.hh"
95 #include "types.h"
96
97 extern char *optarg;
98 extern int optind;
99
100 #define TRUE 1
101 #define FALSE 0
102
103 //#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
104 //#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
105
106 class Mamer : public CommandEntry {
107  public:
108
109   Mamer();
110   ~Mamer();
111   
112   int Initialize(int argc, char **argv);
113   char *s_and_r(char *, char *, char *);
114   int OpenServerConnection(void);
115   void ListenLoop(void);
116   void Shutdown(void);
117   int GivePlace(int, Tourney *);
118   void AnnounceTourneyEnd(Tourney *);
119   void savePlayerData(Tourney *);
120   
121   void DumpConfiguration(void);
122   
123   int XServerCom(char *, ...);
124   void TellUser(reasons, char *);
125   void TellUser(Command *, char *);
126   void TellUser(reasons, char *, char *);
127   void TellUser(reasons, char *, int);
128   void TellUser(reasons, char *, char *, int);
129   void TellUser(reasons, char *, char *, char *);
130   void TellUser(reasons, char *, char *, char *, int);
131
132 #define MAX_WORD_SIZE 1024
133 #define MAX_LINE_SIZE 1024
134
135   int UserIsLoaded(char *);
136   int ParseParams(Command *, char *);
137   int isWhiteSpace(int);
138   char *getWord(char *);
139   char *eatWord(char *);
140   char *eatWhite(char *);
141   char *eatTailWhite(char *);
142   char *nextWord(char *);
143   char *stolower(char *);
144
145   int GenerateTourneyNumber(void);
146
147   Tourney *FindTourney(int);
148   User    *FindUser(char *);
149   Command *FindCommand(char *, char *);
150
151 private:
152   void Usage(void);
153   void LoadConfigurationFile(void);
154   void BuildCommandList(void);
155   void CheckUser(char *);
156   void AdjustManagerList(int, char *);
157   
158   int HandleQtell(char *);
159   int HandleTell(char *);
160   int HandleChannel(char *);
161   int HandleConnect(char *);
162   int HandleDisconnect(char *);
163   int HandleGame(char *);
164   int HandleGameInfo(char *);
165   int HandlePlayerInfo(char *);
166   
167   void NextRound();
168
169   Player  *FindPending(char *);
170   
171 public:
172   char configFilename[MAXPATHLEN];
173   
174   char hostname[256];
175   int  portNumber;
176   int  channelNumber;
177   char username[80];
178   char password[80];
179   
180   int serverSocket;
181   
182   int  debugLevel;
183
184   char logFilename[MAXPATHLEN];  
185   char dataFilePath[MAXPATHLEN];
186   char homeFilePath[MAXPATHLEN];
187   char userFilePath[MAXPATHLEN];
188   char helpFilePath[MAXPATHLEN];
189   
190   short loggedInFlag;
191   
192   long countOfTourneysSinceRestart;
193   
194   TourneyParameters tourneyParams;
195   
196   LinkList<Tourney> tourneyList;
197   LinkList<Player>  pendingList;
198   LinkList<User>    userList;
199   LinkList<Command> commandList;
200   LinkList<Storage> storageList;
201 };
202
203 #endif