73f38a2ef8f97404f7f3a536426b31c431ed661a
[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.h>
51 #include <iostream.h>
52
53 extern "C" {
54 #include <sys/param.h>
55 #include <sys/types.h>
56 #include <sys/time.h>
57
58 #include <ctype.h>
59 #include <errno.h>
60 #include <math.h>
61 #include <signal.h>
62 #include <stdio.h>
63 #include <stdlib.h>
64 #include <string.h>
65 #include <strings.h>
66 #include <sys/signal.h>
67 #include <sys/stat.h>
68
69 #include <sys/socket.h>
70 #include <netinet/in.h>
71 #include <netdb.h>
72 #include <arpa/inet.h>
73
74 #include <time.h>
75 #include <unistd.h>
76 #include <stdarg.h>
77 }
78
79 #ifdef SUN
80 #define INADDR_NONE -1
81 #endif
82
83 #include "config.h"
84 #include "link.hh"
85 #include "linklist.hh"
86 #include "User.hh"
87 #include "Tourney.hh"
88 #include "Command.hh"
89 #include "CommandEntry.hh"
90 #include "Player.hh"
91 #include "Game.hh"
92 #include "Storage.hh"
93 #include "types.h"
94
95 extern char *optarg;
96 extern int optind;
97
98 #define TRUE 1
99 #define FALSE 0
100
101 //#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
102 //#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
103
104 class Mamer : public CommandEntry {
105  public:
106
107   Mamer();
108   ~Mamer();
109   
110   int Initialize(int argc, char **argv);
111   char *s_and_r(char *, char *, char *);
112   int OpenServerConnection(void);
113   void ListenLoop(void);
114   void Shutdown(void);
115   int GivePlace(int, Tourney *);
116   void AnnounceTourneyEnd(Tourney *);
117   void savePlayerData(Tourney *);
118   
119   void DumpConfiguration(void);
120   
121   int XServerCom(char *, ...);
122   void TellUser(reasons, char *);
123   void TellUser(Command *, char *);
124   void TellUser(reasons, char *, char *);
125   void TellUser(reasons, char *, int);
126   void TellUser(reasons, char *, char *, int);
127   void TellUser(reasons, char *, char *, char *);
128   void TellUser(reasons, char *, char *, char *, int);
129
130 #define MAX_WORD_SIZE 1024
131 #define MAX_LINE_SIZE 1024
132
133   int UserIsLoaded(char *);
134   int ParseParams(Command *, char *);
135   int isWhiteSpace(int);
136   char *getWord(char *);
137   char *eatWord(char *);
138   char *eatWhite(char *);
139   char *eatTailWhite(char *);
140   char *nextWord(char *);
141   char *stolower(char *);
142
143   int GenerateTourneyNumber(void);
144
145   Tourney *FindTourney(int);
146   User    *FindUser(char *);
147   Command *FindCommand(char *, char *);
148
149 private:
150   void Usage(void);
151   void LoadConfigurationFile(void);
152   void BuildCommandList(void);
153   void CheckUser(char *);
154   void AdjustManagerList(int, char *);
155   
156   int HandleQtell(char *);
157   int HandleTell(char *);
158   int HandleChannel(char *);
159   int HandleConnect(char *);
160   int HandleDisconnect(char *);
161   int HandleGame(char *);
162   int HandleGameInfo(char *);
163   int HandlePlayerInfo(char *);
164   
165   void NextRound();
166
167   Player  *FindPending(char *);
168   
169 public:
170   char configFilename[MAXPATHLEN];
171   
172   char hostname[256];
173   int  portNumber;
174   int  channelNumber;
175   char username[80];
176   char password[80];
177   
178   int serverSocket;
179   
180   int  debugLevel;
181
182   char logFilename[MAXPATHLEN];  
183   char dataFilePath[MAXPATHLEN];
184   char homeFilePath[MAXPATHLEN];
185   char userFilePath[MAXPATHLEN];
186   char helpFilePath[MAXPATHLEN];
187   
188   short loggedInFlag;
189   
190   long countOfTourneysSinceRestart;
191   
192   TourneyParameters tourneyParams;
193   
194   LinkList<Tourney> tourneyList;
195   LinkList<Player>  pendingList;
196   LinkList<User>    userList;
197   LinkList<Command> commandList;
198   LinkList<Storage> storageList;
199 };
200
201 #endif