Debian Codegraph @

src/bnetd/connection.h

raw symbols SCIP
1 /*
2 * Copyright (C) 1998,1999,2000,2001 Ross Combs ([email protected])
3 * Copyright (C) 2000,2001 Marco Ziech ([email protected])
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19 #ifndef INCLUDED_CONNECTION_TYPES
20 #define INCLUDED_CONNECTION_TYPES
21
22 #ifdef CONNECTION_INTERNAL_ACCESS
23
24 #include <ctime>
25
26 #ifdef JUST_NEED_TYPES
27 # include "game.h"
28 # include "channel.h"
29 # include "account.h"
30 # include "quota.h"
31 # include "character.h"
32 # include "versioncheck.h"
33 # include "anongame.h"
34 # include "anongame_wol.h"
35 # include "realm.h"
36 # include "common/queue.h"
37 # include "common/tag.h"
38 # include "common/elist.h"
39 # include "common/packet.h"
40 # include "common/rcm.h"
41 #else
42 # define JUST_NEED_TYPES
43 # include "game.h"
44 # include "channel.h"
45 # include "account.h"
46 # include "quota.h"
47 # include "character.h"
48 # include "versioncheck.h"
49 # include "anongame.h"
50 # include "anongame_wol.h"
51 # include "realm.h"
52 # include "common/queue.h"
53 # include "common/tag.h"
54 # include "common/elist.h"
55 # include "common/packet.h"
56 # include "common/rcm.h"
57 # undef JUST_NEED_TYPES
58 #endif
59
60 #endif
61
62 namespace pvpgn
63 {
64
65 namespace bnetd
66 {
67
68 typedef enum
69 {
70 conn_class_init,
71 conn_class_bnet,
72 conn_class_file,
73 conn_class_bot,
74 conn_class_telnet,
75 conn_class_ircinit, /* IRC based protocol INIT*/
76 conn_class_irc, /* Internet Relay Chat */
77 conn_class_wol, /* Westwood Chat and Game protocol (IRC based) */
78 conn_class_wserv, /* Westwood servserv (IRC based) */
79 conn_class_wgameres, /* Westwood Gameresolution */
80 conn_class_wladder, /* Westwood Ladder server */
81 conn_class_apireg, /* Westwood API Register */
82 conn_class_d2cs_bnetd,
83 conn_class_w3route,
84 conn_class_none
85 } t_conn_class;
86
87 typedef enum
88 {
89 conn_state_empty,
90 conn_state_initial,
91 conn_state_connected,
92 conn_state_loggedin,
93 conn_state_destroy,
94 conn_state_bot_username,
95 conn_state_bot_password,
96 conn_state_untrusted,
97 conn_state_pending_raw
98 } t_conn_state;
99
100 #ifdef CONNECTION_INTERNAL_ACCESS
101 typedef enum
102 {
103 conn_flags_welcomed = 0x01,
104 conn_flags_udpok = 0x02,
105 conn_flags_joingamewhisper = 0x04,
106 conn_flags_leavegamewhisper = 0x08,
107 conn_flags_echoback = 0x10
108
109 } t_conn_flags;
110
111 #endif
112
113 typedef struct connection
114 #ifdef CONNECTION_INTERNAL_ACCESS
115 {
116 struct {
117 int tcp_sock;
118 unsigned int tcp_addr;
119 unsigned short tcp_port;
120 int udp_sock;
121 unsigned int udp_addr;
122 unsigned short udp_port;
123 unsigned int local_addr;
124 unsigned short local_port;
125 unsigned int real_local_addr;
126 unsigned short real_local_port;
127 int fdw_idx;
128 } socket; /* IP and socket specific data */
129 struct {
130 t_conn_class cclass;
131 t_conn_state state;
132 unsigned int sessionkey;
133 unsigned int sessionnum;
134 unsigned int secret; /* random number... never sent over net unencrypted */
135 unsigned int flags;
136 unsigned int latency;
137 t_account * account;
138 struct {
139 t_tag archtag;
140 t_tag gamelang;
141 t_clienttag clienttag;
142 char const * clientver;
143 unsigned long versionid; /* AKA bnversion */
144 unsigned long gameversion;
145 unsigned long checksum;
146 char const * country;
147 int tzbias;
148 char const * host;
149 char const * user;
150 char const * clientexe;
151 char const * owner;
152 char const * cdkey;
153 const VersionCheck *versioncheck;
154 } client; /* client program specific data */
155 struct {
156 t_queue * outqueue; /* packets waiting to be sent */
157 unsigned int outsize; /* amount sent from the current output packet */
158 unsigned int outsizep;
159 t_packet * inqueue; /* packet waiting to be processed */
160 unsigned int insize; /* amount received into the current input packet */
161 } queues; /* network queues and related data */
162 struct {
163 t_channel * channel;
164 char const * tmpOP_channel;
165 char const * tmpVOICE_channel;
166 char const * away;
167 char const * dnd;
168 t_account * * ignore_list;
169 unsigned int ignore_count;
170 t_quota quota;
171 std::time_t last_message;
172 char const * lastsender; /* last person to whisper to this connection */
173 struct {
174 char const * ircline; /* line cache for IRC connections */
175 unsigned int ircping; /* value of last ping */
176 char const * ircpass; /* hashed password for PASS authentication */
177 } irc; /* irc chat specific data */
178 } chat; /* chat and messages specific data */
179 t_game * game;
180 const char * loggeduser; /* username as logged in or given (not taken from account) */
181 struct connection * bound; /* matching Diablo II auth connection */
182 t_elist timers; /* cached list of timers for cleaning */
183 /* FIXME: this d2/w3 specific data could be unified into an union */
184 struct {
185 t_realm * realm;
186 t_rcm_regref realm_regref;
187 t_character * character;
188 char const * realminfo;
189 char const * charname;
190 } d2;
191 struct {
192 char const * w3_playerinfo; /* ADDED BY UNDYING SOULZZ 4/7/02 */
193 std::time_t anongame_search_starttime;
194 /* [zap-zero] 20020527 - matching w3route connection for game connection /
195 matching game connection for w3route connection */
196 /* FIXME: this "optimization" is so confusing leading to many possible bugs */
197 struct connection * routeconn;
198 t_anongame * anongame;
199 /* those will be filled when recieving 0x53ff and wiped out after 54ff */
200 char const * client_proof;
201 char const * server_proof;
202 } w3;
203 struct {
204 int ingame; /* Are we in a game channel? */
205 int codepage;
206 int findme; /* Allow others to find me? */
207 int pageme; /* Allow others to page me? */
208 char const * apgar; /* WOL User Password (encrypted) */
209 t_anongame_wol_player * anongame_player;
210 } wol;
211 std::time_t cr_time;
212 /* Pass fail count for bruteforce protection */
213 unsigned int passfail_count;
214 /* connection flag substituting some other values */
215 unsigned int cflags;
216 } protocol;
217 }
218 #endif
219 t_connection;
220
221 }
222
223 }
224
225 #endif
226
227
228 /*****/
229 #ifndef JUST_NEED_TYPES
230 #ifndef INCLUDED_CONNECTION_PROTOS
231 #define INCLUDED_CONNECTION_PROTOS
232
233 #include <ctime>
234
235 #define JUST_NEED_TYPES
236 #include "common/packet.h"
237 #include "common/queue.h"
238 #include "channel.h"
239 #include "game.h"
240 #include "account.h"
241 #include "common/list.h"
242 #include "character.h"
243 #include "versioncheck.h"
244 #include "timer.h"
245 #include "anongame.h"
246 #include "anongame_wol.h"
247 #include "realm.h"
248 #include "message.h"
249 #include "common/tag.h"
250 #include "common/fdwatch.h"
251 #undef JUST_NEED_TYPES
252
253 #define DESTROY_FROM_CONNLIST 0
254 #define DESTROY_FROM_DEADLIST 1
255
256 namespace pvpgn
257 {
258
259 namespace bnetd
260 {
261
262 extern t_anongame * conn_create_anongame(t_connection * c);
263 extern void conn_destroy_anongame(t_connection * c);
264
265 extern t_anongame * conn_get_anongame(t_connection *c);
266
267
268 extern void conn_shutdown(t_connection * c, std::time_t now, t_timer_data foo);
269 extern void conn_test_latency(t_connection * c, std::time_t now, t_timer_data delta);
270 extern char const * conn_class_get_str(t_conn_class cclass);
271 extern char const * conn_state_get_str(t_conn_state state);
272
273 extern t_connection * conn_create(int tsock, int usock, unsigned int real_local_addr, unsigned short real_local_port, unsigned int local_addr, unsigned short local_port, unsigned int addr, unsigned short port);
274 extern void conn_destroy(t_connection * c, t_elem ** elem, int conn_or_dead_list);
275 extern int conn_match(t_connection const * c, char const * user);
276 extern t_conn_class conn_get_class(t_connection const * c);
277 extern void conn_set_class(t_connection * c, t_conn_class cclass);
278 extern t_conn_state conn_get_state(t_connection const * c);
279 extern void conn_set_state(t_connection * c, t_conn_state state);
280 extern unsigned int conn_get_sessionkey(t_connection const * c);
281 extern unsigned int conn_get_sessionnum(t_connection const * c);
282 extern unsigned int conn_get_secret(t_connection const * c);
283 extern unsigned int conn_get_addr(t_connection const * c);
284 extern unsigned short conn_get_port(t_connection const * c);
285 extern unsigned int conn_get_local_addr(t_connection const * c);
286 extern unsigned short conn_get_local_port(t_connection const * c);
287 extern unsigned int conn_get_real_local_addr(t_connection const * c);
288 extern unsigned short conn_get_real_local_port(t_connection const * c);
289 extern unsigned int conn_get_game_addr(t_connection const * c);
290 extern int conn_set_game_addr(t_connection * c, unsigned int game_addr);
291 extern unsigned short conn_get_game_port(t_connection const * c);
292 extern int conn_set_game_port(t_connection * c, unsigned short game_port);
293 extern void conn_set_host(t_connection * c, char const * host);
294 extern void conn_set_user(t_connection * c, char const * user);
295 extern const char * conn_get_user(t_connection const * c);
296 extern void conn_set_owner(t_connection * c, char const * owner);
297 extern const char * conn_get_owner(t_connection const * c);
298 extern void conn_set_cdkey(t_connection * c, char const * cdkey);
299 extern char const * conn_get_clientexe(t_connection const * c);
300 extern void conn_set_clientexe(t_connection * c, char const * clientexe);
301 extern t_tag conn_get_archtag(t_connection const * c);
302 extern void conn_set_archtag(t_connection * c, t_tag archtag);
303 extern t_tag conn_get_gamelang(t_connection const * c);
304 extern void conn_set_gamelang(t_connection * c, t_tag gamelang);
305 extern t_clienttag conn_get_clienttag(t_connection const * c);
306 extern t_clienttag conn_get_fake_clienttag(t_connection const * c);
307 extern void conn_set_clienttag(t_connection * c, t_clienttag clienttag);
308 extern unsigned long conn_get_versionid(t_connection const * c);
309 extern int conn_set_versionid(t_connection * c, unsigned long versionid);
310 extern unsigned long conn_get_gameversion(t_connection const * c);
311 extern int conn_set_gameversion(t_connection * c, unsigned long gameversion);
312 extern unsigned long conn_get_checksum(t_connection const * c);
313 extern int conn_set_checksum(t_connection * c, unsigned long checksum);
314 extern char const * conn_get_clientver(t_connection const * c);
315 extern void conn_set_clientver(t_connection * c, char const * clientver);
316 extern int conn_get_tzbias(t_connection const * c);
317 extern void conn_set_tzbias(t_connection * c, int tzbias);
318 extern int conn_set_loggeduser(t_connection * c, char const * username);
319 extern char const * conn_get_loggeduser(t_connection const * c);
320 extern unsigned int conn_get_flags(t_connection const * c);
321 extern int conn_set_flags(t_connection * c, unsigned int flags);
322 extern void conn_add_flags(t_connection * c, unsigned int flags);
323 extern void conn_del_flags(t_connection * c, unsigned int flags);
324 extern unsigned int conn_get_latency(t_connection const * c);
325 extern void conn_set_latency(t_connection * c, unsigned int ms);
326 extern char const * conn_get_awaystr(t_connection const * c);
327 extern int conn_set_awaystr(t_connection * c, char const * away);
328 extern char const * conn_get_dndstr(t_connection const * c);
329 extern int conn_set_dndstr(t_connection * c, char const * dnd);
330 extern int conn_add_ignore(t_connection * c, t_account * account);
331 extern int conn_del_ignore(t_connection * c, t_account const * account);
332 extern int conn_add_watch(t_connection * c, t_account * account, t_clienttag clienttag);
333 extern int conn_del_watch(t_connection * c, t_account * account, t_clienttag clienttag);
334 extern t_channel * conn_get_channel(t_connection const * c);
335 extern int conn_set_channel_var(t_connection * c, t_channel * channel);
336 extern int conn_set_channel(t_connection * c, char const * channelname);
337 extern int conn_part_channel(t_connection * c);
338 extern int conn_kick_channel(t_connection * c, char const * text);
339 extern int conn_quit_channel(t_connection * c, char const * text);
340 extern t_game * conn_get_game(t_connection const * c);
341 extern int conn_set_game(t_connection * c, char const * gamename, char const * gamepass, char const * gameinfo, t_game_type type, int version);
342 extern unsigned int conn_get_tcpaddr(t_connection * c);
343 extern t_packet * conn_get_in_queue(t_connection * c);
344 extern void conn_put_in_queue(t_connection * c, t_packet *packet);
345 extern unsigned int conn_get_in_size(t_connection const * c);
346 extern void conn_set_in_size(t_connection * c, unsigned int size);
347 extern unsigned int conn_get_out_size(t_connection const * c);
348 extern void conn_set_out_size(t_connection * c, unsigned int size);
349 extern int conn_push_outqueue(t_connection * c, t_packet * packet);
350 extern t_packet * conn_peek_outqueue(t_connection * c);
351 extern t_packet * conn_pull_outqueue(t_connection * c);
352 extern int conn_clear_outqueue(t_connection * c);
353 extern void conn_close_read(t_connection * c);
354 extern int conn_check_ignoring(t_connection const * c, char const * me);
355 extern t_account * conn_get_account(t_connection const * c);
356 extern void conn_login(t_connection * c, t_account * account, const char *loggeduser);
357 extern int conn_get_socket(t_connection const * c);
358 extern int conn_get_game_socket(t_connection const * c);
359 extern int conn_set_game_socket(t_connection * c, int usock);
360 extern char const * conn_get_username_real(t_connection const * c, char const * fn, unsigned int ln);
361 #define conn_get_username(C) conn_get_username_real(C,__FILE__,__LINE__)
362 extern char const * conn_get_chatname(t_connection const * c);
363 extern int conn_unget_chatname(t_connection const * c, char const * name);
364 extern char const * conn_get_chatcharname(t_connection const * c, t_connection const * dst);
365 extern int conn_unget_chatcharname(t_connection const * c, char const * name);
366 extern t_message_class conn_get_message_class(t_connection const * c, t_connection const * dst);
367 extern unsigned int conn_get_userid(t_connection const * c);
368 extern char const * conn_get_playerinfo(t_connection const * c);
369 extern int conn_set_playerinfo(t_connection const * c, char const * playerinfo);
370 extern char const * conn_get_realminfo(t_connection const * c);
371 extern int conn_set_realminfo(t_connection * c, char const * realminfo);
372 extern char const * conn_get_charname(t_connection const * c);
373 extern int conn_set_charname(t_connection * c, char const * charname);
374 extern int conn_set_idletime(t_connection * c);
375 extern unsigned int conn_get_idletime(t_connection const * c);
376 extern t_realm * conn_get_realm(t_connection const * c);
377 extern int conn_set_realm(t_connection * c, t_realm * realm);
378 extern int conn_set_character(t_connection * c, t_character * ch);
379 extern int conn_bind(t_connection * c1, t_connection * c2);
380 extern void conn_set_country(t_connection * c, char const * country);
381 extern char const * conn_get_country(t_connection const * c);
382 extern int conn_quota_exceeded(t_connection * c, char const * message);
383 extern int conn_set_lastsender(t_connection * c, char const * sender);
384 extern char const * conn_get_lastsender(t_connection const * c);
385 const VersionCheck *conn_get_versioncheck(t_connection *c);
386 bool conn_set_versioncheck(t_connection *c, const VersionCheck* versioncheck);
387 extern int conn_get_echoback(t_connection * c);
388 extern void conn_set_echoback(t_connection * c, int echoback);
389 extern int conn_set_ircline(t_connection * c, char const * line);
390 extern char const * conn_get_ircline(t_connection const * c);
391 extern int conn_set_ircpass(t_connection * c, char const * pass);
392 extern char const * conn_get_ircpass(t_connection const * c);
393 extern int conn_set_ircping(t_connection * c, unsigned int ping);
394 extern unsigned int conn_get_ircping(t_connection const * c);
395 extern int conn_set_udpok(t_connection * c);
396 extern int conn_get_welcomed(t_connection const * c);
397 extern void conn_set_welcomed(t_connection * c, int welcomed);
398
399 extern int conn_set_w3_playerinfo(t_connection * c, char const * w3_playerinfo);
400 extern const char * conn_get_w3_playerinfo(t_connection * c);
401
402 extern int conn_get_crtime(t_connection *c);
403
404 extern int conn_set_w3_loginreq(t_connection * c, char const * loginreq);
405 extern char const * conn_get_w3_loginreq(t_connection * c);
406
407 extern int conn_set_routeconn(t_connection * c, t_connection * rc);
408 extern t_connection * conn_get_routeconn(t_connection const * c);
409 extern int connlist_create(void);
410 extern void connlist_reap(void);
411 extern int connlist_destroy(void);
412 extern t_list * connlist(void);
413 extern t_connection * connlist_find_connection_by_sessionkey(unsigned int sessionkey);
414 extern t_connection * connlist_find_connection_by_socket(int socket);
415 extern t_connection * connlist_find_connection_by_sessionnum(unsigned int sessionnum);
416 extern t_connection * connlist_find_connection_by_name(char const * name, t_realm * realm); /* any chat name format */
417 extern t_connection * connlist_find_connection_by_accountname(char const * username);
418 extern t_connection * connlist_find_connection_by_charname(char const * charname, char const * realmname);
419 extern t_connection * connlist_find_connection_by_account(t_account * account);
420 extern t_connection * connlist_find_connection_by_uid(unsigned int uid);
421 extern int connlist_get_length(void);
422 extern unsigned int connlist_login_get_length(void);
423 extern int connlist_total_logins(void);
424 extern int conn_set_joingamewhisper_ack(t_connection * c, unsigned int value);
425 extern int conn_get_joingamewhisper_ack(t_connection * c);
426 extern int conn_set_leavegamewhisper_ack(t_connection * c, unsigned int value);
427 extern int conn_get_leavegamewhisper_ack(t_connection * c);
428 extern int conn_set_anongame_search_starttime(t_connection * c, std::time_t t);
429 extern std::time_t conn_get_anongame_search_starttime(t_connection * c);
430
431 extern int conn_get_user_count_by_clienttag(t_clienttag ct);
432
433 extern unsigned int connlist_count_connections(unsigned int addr);
434
435 extern int conn_update_w3_playerinfo(t_connection * c);
436
437 extern int conn_get_passfail_count(t_connection * c);
438 extern int conn_set_passfail_count(t_connection * c, unsigned int failcount);
439 extern int conn_increment_passfail_count(t_connection * c);
440
441 extern char const * conn_get_client_proof(t_connection * c);
442 extern int conn_set_client_proof(t_connection * c, char const * client_proof);
443
444 extern char const * conn_get_server_proof(t_connection * c);
445 extern int conn_set_server_proof(t_connection * c, char const * server_proof);
446
447 extern int conn_set_tmpOP_channel(t_connection * c, char const * tmpOP_channel);
448 extern char const * conn_get_tmpOP_channel(t_connection * c);
449 extern int conn_set_tmpVOICE_channel(t_connection * c, char const * tmpVOICE_channel);
450 extern char const * conn_get_tmpVOICE_channel(t_connection * c);
451 extern t_elist *conn_get_timer(t_connection * c);
452 extern int conn_add_fdwatch(t_connection *c, fdwatch_handler handle);
453 extern int conn_is_irc_variant(t_connection * c);
454
455 /* Westwood Online Extensions */
456 extern int conn_get_wol(t_connection * c);
457 extern void conn_wol_set_apgar(t_connection * c, char const * apgar);
458 extern char const * conn_wol_get_apgar(t_connection * c);
459 extern void conn_wol_set_codepage(t_connection * c, int codepage);
460 extern int conn_wol_get_codepage(t_connection * c);
461 extern void conn_wol_set_findme(t_connection * c, bool findme);
462 extern bool conn_wol_get_findme(t_connection * c);
463 extern void conn_wol_set_pageme(t_connection * c, bool pageme);
464 extern bool conn_wol_get_pageme(t_connection * c);
465 extern void conn_wol_set_anongame_player(t_connection * c, t_anongame_wol_player * anongame_player);
466 extern t_anongame_wol_player * conn_wol_get_anongame_player(t_connection * c);
467
468 extern int conn_client_readmemory(t_connection * c, unsigned int request_id, unsigned int offset, unsigned int length);
469 extern int conn_client_requiredwork(t_connection * c, const char * filename);
470 }
471
472 }
473
474 #endif
475 #endif