-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbflib_network.h
278 lines (240 loc) · 8.34 KB
/
bflib_network.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
/******************************************************************************/
// Bullfrog Engine Emulation Library - for use to remake classic games like
// Syndicate Wars, Magic Carpet or Dungeon Keeper.
/******************************************************************************/
/** @file bflib_network.h
* Header file for bflib_network.c.
* @par Purpose:
* Network support routines.
* @par Comment:
* Just a header file - #defines, typedefs, function prototypes etc.
* @author Tomasz Lis
* @date 11 Apr 2009 - 13 May 2009
* @par Copying and copyrights:
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
/******************************************************************************/
#ifndef BFLIB_NETWRK_H
#define BFLIB_NETWRK_H
#include <basetyps.h>
#include "bflib_basics.h"
#include "globals.h"
#ifdef __cplusplus
extern "C" {
#endif
/******************************************************************************/
#define CLIENT_TABLE_LEN 32
/******************************************************************************/
#pragma pack(1)
// New Declarations Here ======================================================
#define MAX_N_USERS 4
#define MAX_N_PEERS (MAX_N_USERS - 1)
#define SERVER_ID 0
typedef int NetUserId;
enum NetDropReason
{
NETDROP_MANUAL, //via drop_user()
NETDROP_ERROR //connection error
};
typedef TbBool (*NetNewUserCallback)(NetUserId * assigned_id);
typedef void (*NetDropCallback)(NetUserId id, enum NetDropReason reason);
struct NetSP //new version
{
/**
* Inits this service provider.
* @return Lb_FAIL or Lb_OK
*/
TbError (*init)(NetDropCallback drop_callback);
/**
* Closes down all activities and cleans up this service provider.
*/
void (*exit)(void);
/**
* Sets this service provider up as a host for a new network game.
* @param session String representing the network game to be hosted.
* This could be a hostname:port pair for TCP for instance.
* @param options
* @return Lb_FAIL or Lb_OK
*/
TbError (*host)(const char * session, void * options); //leaving void * for now, analyze meaning later
/**
* Sets this service provider as a client for an existing network game.
* @param session String representing the network game to be hosted.
* This could be a hostname:port pair for TCP for instance.
* @param options
* @return Lb_FAIL or Lb_OK
*/
TbError (*join)(const char * session, void * options);
/**
* Checks for new connections.
* @param new_user Call back if a new user has connected.
*/
void (*update)(NetNewUserCallback new_user);
/**
* Sends a message buffer to a certain user.
* @param destination Destination user.
* @param buffer
* @param size Must be > 0
*/
void (*sendmsg_single)(NetUserId destination, const char * buffer, size_t size);
/**
* Sends a message buffer to all remote users.
* @param buffer
* @param size Must be > 0
*/
void (*sendmsg_all)(const char * buffer, size_t size);
/**
* Asks if a message has finished reception and get be read through readmsg.
* May block under some circumstances but shouldn't unless it can be presumed
* a whole message is on the way.
* TODO NET this definition is due to how SDL Net handles sockets.. see if it can
* be improved - ideally this function shouldn't block at all
* @param source The source user.
* @param timeout If non-zero, this method will wait this number of milliseconds
* for a message to arrive before returning.
* @return The size of the message waiting if there is a message, otherwise 0.
*/
size_t (*msgready)(NetUserId source, unsigned timeout);
/**
* Completely reads a message. Blocks until entire message has been read.
* Will not block if msgready has returned > 0.
* @param source The source user.
* @param buffer
* @param max_size The maximum size of the message to be received.
* @return The actual size of the message received, <= max_size. If 0, an
* error occurred.
*/
size_t (*readmsg)(NetUserId source, char * buffer, size_t max_size);
/**
* Disconnects a user.
* @param id User to be dropped.
*/
void (*drop_user)(NetUserId id);
};
extern const struct NetSP tcpSP;
// New Declarations End Here ==================================================
struct TbNetworkSessionNameEntry;
typedef long (*Net_Callback_Func)(void);
enum TbNetworkService {
NS_Serial,
NS_Modem,
NS_IPX,
NS_TCP_IP,
};
struct ClientDataEntry {
unsigned long plyrid;
unsigned long isactive;
unsigned long field_8;
char name[32];
};
struct ConfigInfo { // sizeof = 130
char numfield_0;
unsigned char numfield_1[8];
char numfield_9;
char str_atz[20];
char str_atdt[20];
char str_ath[20];
char str_ats[20];
char str_join[20];
char str_u2[20];
};
struct TbModemDev { // sizeof = 180
unsigned long field_0;
unsigned long field_4;
char field_8[80];
char field_58[80];
unsigned long field_A8;
Net_Callback_Func field_AC;
Net_Callback_Func field_B0;
};
struct ModemResponse {
unsigned char field_0[8];
unsigned char field_8[8];
unsigned char field_10[8];
unsigned char field_18[8];
unsigned char field_20[8];
unsigned char field_28[8];
unsigned char field_30[8];
unsigned char field_38[8];
};
struct TbNetworkPlayerInfo {
char name[32];
long active;
};
struct TbNetworkCallbackData {
char svc_name[12];
char plyr_name[20];
char field_20[32];
};
struct TbNetworkPlayerName {
char name[20];
};
struct TbNetworkPlayerNameEntry {
unsigned char id;
unsigned long islocal;
unsigned long ishost;
unsigned long field_9;
char name[19];
unsigned char field_20[20];
unsigned char field_34[4];
};
//TODO: find out what this struct really is, and how long is it
struct SystemUserMsg {
unsigned char type;
struct ClientDataEntry client_data_table[CLIENT_TABLE_LEN];
};
struct UnidirectionalDataMessage {
unsigned long field_0;
unsigned long field_4;
unsigned long field_8;
unsigned long field_C;
unsigned long field_10;
unsigned char field_14[492];
unsigned char field_200[12];
};
struct UnidirectionalRTSMessage {
unsigned long field_0;
unsigned long field_4;
unsigned long field_8;
unsigned long field_C;
unsigned long field_10;
};
/** Structure for storing network service configuration. Used to pass information about configuration into LbNetwork_Init().
*/
struct ServiceInitData {
long field_0;
long numfield_4;
long field_8;
long field_C;
char *str_phone;
char *str_dial;
char *str_hang;
char *str_answr;
};
/******************************************************************************/
DLLIMPORT extern int _DK_network_initialized;
#define network_initialized _DK_network_initialized
#pragma pack()
/******************************************************************************/
void LbNetwork_InitSessionsFromCmdLine(const char * str);
TbError LbNetwork_Init(unsigned long srvcindex, unsigned long maxplayrs, void *exchng_buf, unsigned long exchng_size, struct TbNetworkPlayerInfo *locplayr, struct ServiceInitData *init_data);
TbError LbNetwork_Join(struct TbNetworkSessionNameEntry *nsname, char *playr_name, unsigned long *playr_num, void *optns);
TbError LbNetwork_Create(char *nsname_str, char *plyr_name, unsigned long *plyr_num, void *optns);
TbError LbNetwork_Exchange(void *buf);
TbBool LbNetwork_Resync(void * buf, size_t len);
void LbNetwork_ChangeExchangeTimeout(unsigned long tmout);
TbError LbNetwork_ChangeExchangeBuffer(void *buf, unsigned long a2);
void LbNetwork_EnableLag(TbBool lag); //new addition to enable/disable scheduled lag mode
TbError LbNetwork_EnableNewPlayers(TbBool allow);
TbError LbNetwork_EnumerateServices(TbNetworkCallbackFunc callback, void *a2);
TbError LbNetwork_EnumeratePlayers(struct TbNetworkSessionNameEntry *sesn, TbNetworkCallbackFunc callback, void *a2);
TbError LbNetwork_EnumerateSessions(TbNetworkCallbackFunc callback, void *ptr);
TbError LbNetwork_Stop(void);
/******************************************************************************/
#ifdef __cplusplus
}
#endif
#endif