-
Notifications
You must be signed in to change notification settings - Fork 10
/
server.h
382 lines (312 loc) · 6.6 KB
/
server.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/*
* server.h
* XBolo
*
* Created by Robert Chrzanowski on 4/27/09.
* Copyright 2009 Robert Chrzanowski. All rights reserved.
*
*/
#ifndef __SERVER__
#define __SERVER__
#include "bolo.h"
#include "tracker.h"
#include "buf.h"
#include "errchk.h"
#include <stdint.h>
#define TRACKERUPDATESECONDS (60)
struct Server {
int setup;
int running;
/* tracker */
struct {
char *hostname;
int sock;
struct sockaddr_in addr;
char hostplayername[MAXNAME];
char mapname[TRKMAPNAMELEN];
uint16_t port;
void (*callback)(int status);
struct Buf recvbuf;
struct Buf sendbuf;
} tracker;
/* sockets */
int listensock;
int dgramsock;
int mainpipe[2];
int threadpipe[2];
/* server mutex */
pthread_mutex_t mutex;
/* chain detonation */
struct ListNode chains[CHAINTICKS + 1];
/* flood fill */
struct ListNode floods[FLOODTICKS + 1];
/* game info */
int gametype;
int timelimit;
int hiddenmines;
int passreq;
char pass[MAXPASS];
int pauseonplayerexit;
int allowjoin;
int pause;
/* used in domination games */
int basecontrol;
/* number of elapsed ticks */
uint32_t ticks;
union {
struct Domination domination;
} game;
int terrain[WIDTH][WIDTH];
int npills;
struct Pill pills[MAXPILLS];
int nbases;
struct Base bases[MAXBASES];
int nstarts;
struct Start starts[MAX_STARTS];
/* tree growing */
int growx;
int growy;
int growbestof;
/* joining player data */
struct {
int cntlsock;
struct sockaddr_in addr;
int disconnect;
struct Buf recvbuf;
struct Buf sendbuf;
} joiningplayer;
/* player info */
struct {
/* connection variables */
int used;
int cntlsock;
struct sockaddr_in addr;
struct sockaddr_in dgramaddr;
char name[MAXNAME];
char host[MAXHOST];
uint32_t seq;
uint32_t lastupdate;
uint16_t alliance;
Vec2f tank;
struct Buf recvbuf;
struct Buf sendbuf;
} players[MAXPLAYERS];
/* banned players list */
struct ListNode bannedplayers;
} ;
/* Server Messages */
struct SRHangUp {
uint8_t type;
} ;
struct SRSendMesg {
uint8_t type;
uint8_t player;
uint8_t to;
/* null terminated string */
} __attribute__((__packed__));
struct SRDamage {
uint8_t type;
uint8_t player;
uint8_t x;
uint8_t y;
uint8_t terrain;
} __attribute__((__packed__));
struct SRGrabTrees {
uint8_t type;
uint8_t x;
uint8_t y;
} __attribute__((__packed__));
struct SRBuild {
uint8_t type;
uint8_t x;
uint8_t y;
uint8_t terrain;
} __attribute__((__packed__));
struct SRGrow {
uint8_t type;
uint8_t x;
uint8_t y;
} __attribute__((__packed__));
struct SRFlood {
uint8_t type;
uint8_t x;
uint8_t y;
} __attribute__((__packed__));
struct SRPlaceMine {
uint8_t type;
uint8_t player;
uint8_t x;
uint8_t y;
} __attribute__((__packed__));
struct SRDropMine {
uint8_t type;
uint8_t player;
uint8_t x;
uint8_t y;
} __attribute__((__packed__));
struct SRDropBoat {
uint8_t type;
uint8_t x;
uint8_t y;
} __attribute__((__packed__));
struct SRPlayerJoin {
uint8_t type;
uint8_t player;
char name[MAXNAME];
char host[MAXHOST];
} __attribute__((__packed__));
struct SRPlayerRejoin {
uint8_t type;
uint8_t player;
char host[MAXHOST];
} __attribute__((__packed__));
struct SRPlayerExit {
uint8_t type;
uint8_t player;
} __attribute__((__packed__));
struct SRPlayerDisc {
uint8_t type;
uint8_t player;
} __attribute__((__packed__));
struct SRPlayerKick {
uint8_t type;
uint8_t player;
} __attribute__((__packed__));
struct SRPlayerBan {
uint8_t type;
uint8_t player;
} __attribute__((__packed__));
struct SRRepairPill {
uint8_t type;
uint8_t pill;
uint8_t armour;
} __attribute__((__packed__));
struct SRCoolPill {
uint8_t type;
uint8_t pill;
} __attribute__((__packed__));
struct SRCapturePill {
uint8_t type;
uint8_t pill;
uint8_t owner;
} __attribute__((__packed__));
struct SRBuildPill {
uint8_t type;
uint8_t pill;
uint8_t x;
uint8_t y;
uint8_t armour;
} __attribute__((__packed__));
struct SRDropPill {
uint8_t type;
uint8_t pill;
uint8_t x;
uint8_t y;
} __attribute__((__packed__));
struct SRReplenishBase {
uint8_t type;
uint8_t base;
} __attribute__((__packed__));
struct SRCaptureBase {
uint8_t type;
uint8_t base;
uint8_t owner;
} __attribute__((__packed__));
struct SRRefuel {
uint8_t type;
uint8_t base;
uint8_t armour;
uint8_t shells;
uint8_t mines;
} __attribute__((__packed__));
struct SRGrabBoat {
uint8_t type;
uint8_t player;
uint8_t x;
uint8_t y;
} __attribute__((__packed__));
struct SRMineAck {
uint8_t type;
uint8_t success;
} __attribute__((__packed__));
struct SRBuilderAck {
uint8_t type;
uint8_t mines;
uint8_t trees;
uint8_t pill;
} __attribute__((__packed__));
struct SRSmallBoom {
uint8_t type;
uint8_t player;
uint8_t x;
uint8_t y;
} __attribute__((__packed__));
struct SRSuperBoom {
uint8_t type;
uint8_t player;
uint8_t x;
uint8_t y;
} __attribute__((__packed__));
struct SRHitTank {
uint8_t type;
uint8_t player;
uint32_t dir;
} __attribute__((__packed__));
struct SRSetAlliance {
uint8_t type;
uint8_t player;
uint16_t alliance;
} __attribute__((__packed__));
struct SRTimeLimit {
uint8_t type;
uint16_t timeremaining;
} __attribute__((__packed__));
struct SRBaseControl {
uint8_t type;
uint16_t timeleft;
} __attribute__((__packed__));
struct SRPause {
uint8_t type;
uint8_t pause;
} __attribute__((__packed__));
/* structure for banned player list */
struct BannedPlayer {
char name[MAXNAME];
struct in_addr sin_addr;
} ;
/**********************/
/* external variables */
/**********************/
extern struct Server server;
/*******************/
/* server routines */
/*******************/
int initserver();
int setupserver(
int initiallypaused, const void *buf, size_t nbytes, uint16_t port,
const char password[], int timelimit, int hiddenmines, int pauseonplayerexit,
int gametype, const void *gamedata
);
int startserverthread();
int startserverthreadwithtracker(
const char trackerhostname[], uint16_t port, const char hostplayername[],
const char mapname[], void (*callback)(int status)
);
int stopserver();
int lockserver();
int unlockserver();
int togglejoinserver();
int kickplayer(int player);
int banplayer(int player);
int unbanplayer(int player);
int tiletoterrain(int tile);
int pauseresumeserver();
int getservertcpport();
int getserverudpport();
/* lock server first before calling these */
int getallowjoinserver();
void setallowjoinserver(int allowjoin);
int getpauseserver();
void pauseserver();
void resumeserver();
#endif /* __SERVER__ */