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