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