Debian Codegraph @

src/bnetd/handle_init.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 1999,2000 Ross Combs ([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 "handle_init.h"
20
21 #include "common/init_protocol.h"
22 #include "common/eventlog.h"
23 #include "common/packet.h"
24 #include "common/bn_type.h"
25 #include "common/addr.h"
26
27 #include "prefs.h"
28 #include "connection.h"
29 #include "realm.h"
30 #include "handle_d2cs.h"
31 #include "common/setup_after.h"
32
33
34 namespace pvpgn
35 {
36
37 namespace bnetd
38 {
39
40 extern int handle_init_packet(t_connection * c, t_packet const * const packet)
41 {
42 if (!c)
43 {
44 eventlog(eventlog_level_error, __FUNCTION__, "[{}] got NULL connection", conn_get_socket(c));
45 return -1;
46 }
47 if (!packet)
48 {
49 eventlog(eventlog_level_error, __FUNCTION__, "[{}] got NULL packet", conn_get_socket(c));
50 return -1;
51 }
52 if (packet_get_class(packet) != packet_class_init)
53 {
54 eventlog(eventlog_level_error, __FUNCTION__, "[{}] got bad packet (class {})", conn_get_socket(c), (int)packet_get_class(packet));
55 return -1;
56 }
57 if ((prefs_get_max_conns_per_IP() != 0) &&
58 bn_byte_get(packet->u.client_initconn.cclass) != CLIENT_INITCONN_CLASS_D2CS_BNETD &&
59 (connlist_count_connections(conn_get_addr(c)) > prefs_get_max_conns_per_IP()))
60 {
61 eventlog(eventlog_level_error, __FUNCTION__, "[{}] too many connections from address {} (closing connection)", conn_get_socket(c), addr_num_to_addr_str(conn_get_addr(c), conn_get_port(c)));
62 return -1;
63 }
64
65 switch (packet_get_type(packet))
66 {
67 case CLIENT_INITCONN:
68 switch (bn_byte_get(packet->u.client_initconn.cclass))
69 {
70 case CLIENT_INITCONN_CLASS_BNET:
71 eventlog(eventlog_level_info, __FUNCTION__, "[{}] client initiated bnet connection", conn_get_socket(c));
72 conn_set_state(c, conn_state_connected);
73 conn_set_class(c, conn_class_bnet);
74
75 break;
76
77 case CLIENT_INITCONN_CLASS_FILE:
78 eventlog(eventlog_level_info, __FUNCTION__, "[{}] client initiated file download connection", conn_get_socket(c));
79 conn_set_state(c, conn_state_connected);
80 conn_set_class(c, conn_class_file);
81
82 break;
83
84 case CLIENT_INITCONN_CLASS_BOT:
85 eventlog(eventlog_level_info, __FUNCTION__, "[{}] client initiated chat bot connection", conn_get_socket(c));
86 conn_set_state(c, conn_state_connected);
87 conn_set_class(c, conn_class_bot);
88
89 break;
90
91 case CLIENT_INITCONN_CLASS_TELNET:
92 eventlog(eventlog_level_info, __FUNCTION__, "[{}] client initiated telnet connection", conn_get_socket(c));
93 conn_set_state(c, conn_state_connected);
94 conn_set_class(c, conn_class_telnet);
95
96 break;
97
98 case CLIENT_INITCONN_CLASS_D2CS_BNETD:
99 {
100 eventlog(eventlog_level_info, __FUNCTION__, "[{}] client initiated d2cs_bnetd connection", conn_get_socket(c));
101
102 if (!(realmlist_find_realm_by_ip(conn_get_addr(c))))
103 {
104 eventlog(eventlog_level_info, __FUNCTION__, "[{}] d2cs connection from unknown ip address {}", conn_get_socket(c), addr_num_to_addr_str(conn_get_addr(c), conn_get_port(c)));
105 return -1;
106 }
107
108 conn_set_state(c, conn_state_connected);
109 conn_set_class(c, conn_class_d2cs_bnetd);
110 if (handle_d2cs_init(c) < 0)
111 {
112 eventlog(eventlog_level_info, __FUNCTION__, "faild to init d2cs connection");
113 return -1;
114 }
115 }
116 break;
117
118 case CLIENT_INITCONN_CLASS_ENC:
119 eventlog(eventlog_level_info, __FUNCTION__, "[{}] client initiated encrypted connection (not supported)", conn_get_socket(c));
120 return -1;
121 break;
122
123 case CLIENT_INITCONN_CLASS_LOCALMACHINE:
124 eventlog(eventlog_level_info, __FUNCTION__, "[{}] client initiated connection from local computer to 127.0.0.1", conn_get_socket(c));
125 /*
126 conn_set_state(c, conn_state_connected);
127 conn_set_class(c, conn_class_localmachine;
128 */
129 return -1;
130 break;
131
132 default:
133 eventlog(eventlog_level_error, __FUNCTION__, "[{}] client requested unknown class 0x{:02x} (length {}) (closing connection)", conn_get_socket(c), (unsigned int)bn_byte_get(packet->u.client_initconn.cclass), packet_get_size(packet));
134 return -1;
135 }
136 break;
137 default:
138 eventlog(eventlog_level_error, __FUNCTION__, "[{}] unknown init packet type 0x{:04x}, len {}", conn_get_socket(c), packet_get_type(packet), packet_get_size(packet));
139 return -1;
140 }
141
142 return 0;
143 }
144
145 }
146
147 }