Debian Codegraph @

src/d2cs/handle_init.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2000,2001 Onlyer ([email protected])
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18 #include "common/setup_before.h"
19 #include "setup.h"
20 #include "handle_init.h"
21
22 #include "common/eventlog.h"
23 #include "common/addr.h"
24 #include "common/init_protocol.h"
25 #include "d2gs.h"
26 #include "handle_d2gs.h"
27 #include "prefs.h"
28 #include "common/setup_after.h"
29
30 namespace pvpgn
31 {
32
33 namespace d2cs
34 {
35
36 static int on_d2gs_initconn(t_connection * c);
37 static int on_d2cs_initconn(t_connection * c);
38
39 extern int d2cs_handle_init_packet(t_connection * c, t_packet * packet)
40 {
41 int cclass;
42 int retval;
43
44 ASSERT(c,-1);
45 ASSERT(packet,-1);
46 cclass=bn_byte_get(packet->u.client_initconn.cclass);
47 switch (cclass) {
48 case CLIENT_INITCONN_CLASS_D2CS:
49 retval=on_d2cs_initconn(c);
50 break;
51 case CLIENT_INITCONN_CLASS_D2GS:
52 retval=on_d2gs_initconn(c);
53 break;
54 default:
55 eventlog(eventlog_level_error,__FUNCTION__,"got bad connection class {}",cclass);
56 retval=-1;
57 break;
58 }
59 return retval;
60 }
61
62 static int on_d2gs_initconn(t_connection * c)
63 {
64 t_d2gs * gs;
65
66 eventlog(eventlog_level_info,__FUNCTION__,"[{}] client initiated d2gs connection",d2cs_conn_get_socket(c));
67 if (!(gs=d2gslist_find_gs_by_ip(d2cs_conn_get_addr(c)))) {
68 // reload list and see if any dns addy's has changed
69 if (d2gslist_reload(prefs_get_d2gs_list())<0) {
70 eventlog(eventlog_level_error,__FUNCTION__,"error reloading game server list,exitting");
71 return -1;
72 }
73 //recheck
74 if (!(gs=d2gslist_find_gs_by_ip(d2cs_conn_get_addr(c)))) {
75 eventlog(eventlog_level_error,__FUNCTION__,"d2gs connection from invalid ip address {}",addr_num_to_ip_str(d2cs_conn_get_addr(c)));
76 return -1;
77 }
78 }
79 d2cs_conn_set_class(c,conn_class_d2gs);
80 d2cs_conn_set_state(c,conn_state_connected);
81 conn_set_d2gs_id(c,d2gs_get_id(gs));
82 if (handle_d2gs_init(c)<0) {
83 eventlog(eventlog_level_error,__FUNCTION__,"failed to init d2gs connection");
84 return -1;
85 }
86 return 0;
87 }
88
89 static int on_d2cs_initconn(t_connection * c)
90 {
91 eventlog(eventlog_level_info,__FUNCTION__,"[{}] client initiated d2cs connection",d2cs_conn_get_socket(c));
92 d2cs_conn_set_class(c,conn_class_d2cs);
93 d2cs_conn_set_state(c,conn_state_connected);
94 return 0;
95 }
96
97 }
98
99 }