| 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"cxx . . $ `<file>/src/common/setup_before.h`/ |
| 19 | #include "handle_init.h"cxx . . $ `<file>/src/bnetd/handle_init.h`/ |
| 20 | |
| 21 | #include "common/init_protocol.h"cxx . . $ `<file>/src/common/init_protocol.h`/ |
| 22 | #include "common/eventlog.h"cxx . . $ `<file>/src/common/eventlog.h`/ |
| 23 | #include "common/packet.h"cxx . . $ `<file>/src/common/packet.h`/ |
| 24 | #include "common/bn_type.h"cxx . . $ `<file>/src/common/bn_type.h`/ |
| 25 | #include "common/addr.h"cxx . . $ `<file>/src/common/addr.h`/ |
| 26 | |
| 27 | #include "prefs.h"cxx . . $ `<file>/src/bnetd/prefs.h`/ |
| 28 | #include "connection.h"cxx . . $ `<file>/src/bnetd/connection.h`/ |
| 29 | #include "realm.h"cxx . . $ `<file>/src/bnetd/realm.h`/ |
| 30 | #include "handle_d2cs.h"cxx . . $ `<file>/src/bnetd/handle_d2cs.h`/ |
| 31 | #include "common/setup_after.h"cxx . . $ `<file>/src/common/setup_after.h`/ |
| 32 | |
| 33 | |
| 34 | namespace pvpgncxx . . $ pvpgn/ |
| 35 | { |
| 36 | |
| 37 | namespace bnetdcxx . . $ pvpgn/bnetd/ |
| 38 | { |
| 39 | |
| 40 | extern int handle_init_packetcxx . . $ pvpgn/bnetd/handle_init_packet(8d07eb83d60bed1d).(t_connection * c, t_packetcxx . . $ pvpgn/t_packet# const * const packet) |
| 41 | { |
| 42 | if (!c) |
| 43 | { |
| 44 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "[{}] got NULL connection", conn_get_socketcxx . . $ pvpgn/bnetd/conn_get_socket(b5160de3e9803af4).(c)); |
| 45 | return -1; |
| 46 | } |
| 47 | if (!packet) |
| 48 | { |
| 49 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "[{}] got NULL packet", conn_get_socketcxx . . $ pvpgn/bnetd/conn_get_socket(b5160de3e9803af4).(c)); |
| 50 | return -1; |
| 51 | } |
| 52 | if (packet_get_classcxx . . $ pvpgn/packet_get_class(6361653567fd72e5).(packet) != packet_class_initcxx . . $ pvpgn/packet_class_init.) |
| 53 | { |
| 54 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "[{}] got bad packet (class {})", conn_get_socketcxx . . $ pvpgn/bnetd/conn_get_socket(b5160de3e9803af4).(c), (int)packet_get_classcxx . . $ pvpgn/packet_get_class(6361653567fd72e5).(packet)); |
| 55 | return -1; |
| 56 | } |
| 57 | if ((prefs_get_max_conns_per_IPcxx . . $ pvpgn/bnetd/prefs_get_max_conns_per_IP(db52760e79bf9054).() != 0) && |
| 58 | bn_byte_get(packet->ucxx . . $ pvpgn/$anonymous_type_a1640d8ff791e3e5_2#u..client_initconncxx . . $ pvpgn/$anonymous_type_a1640d8ff791e3e5_2#$anonymous_type_3#client_initconn..cclasscxx . . $ pvpgn/$anonymous_type_7cca3803bac3bad7_0#cclass.) != CLIENT_INITCONN_CLASS_D2CS_BNETDcxx . . $ `src/common/init_protocol.h:66:9`! && |
| 59 | (connlist_count_connectionscxx . . $ pvpgn/bnetd/connlist_count_connections(2141b656ce2cc063).(conn_get_addrcxx . . $ pvpgn/bnetd/conn_get_addr(8bd2285a65940781).(c)) > prefs_get_max_conns_per_IPcxx . . $ pvpgn/bnetd/prefs_get_max_conns_per_IP(db52760e79bf9054).())) |
| 60 | { |
| 61 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "[{}] too many connections from address {} (closing connection)", conn_get_socketcxx . . $ pvpgn/bnetd/conn_get_socket(b5160de3e9803af4).(c), addr_num_to_addr_strcxx . . $ pvpgn/addr_num_to_addr_str(9313bf3c546cb16).(conn_get_addrcxx . . $ pvpgn/bnetd/conn_get_addr(8bd2285a65940781).(c), conn_get_portcxx . . $ pvpgn/bnetd/conn_get_port(70207a9c46bcade7).(c))); |
| 62 | return -1; |
| 63 | } |
| 64 | |
| 65 | switch (packet_get_typecxx . . $ pvpgn/packet_get_type(e4ac9e2b4744cb4b).(packet)) |
| 66 | { |
| 67 | case CLIENT_INITCONNcxx . . $ `src/common/init_protocol.h:42:9`!: |
| 68 | switch (bn_byte_get(packet->ucxx . . $ pvpgn/$anonymous_type_a1640d8ff791e3e5_2#u..client_initconncxx . . $ pvpgn/$anonymous_type_a1640d8ff791e3e5_2#$anonymous_type_3#client_initconn..cclasscxx . . $ pvpgn/$anonymous_type_7cca3803bac3bad7_0#cclass.)) |
| 69 | { |
| 70 | case CLIENT_INITCONN_CLASS_BNETcxx . . $ `src/common/init_protocol.h:59:9`!: |
| 71 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_infocxx . . $ pvpgn/eventlog_level_info., __FUNCTION__, "[{}] client initiated bnet connection", conn_get_socketcxx . . $ pvpgn/bnetd/conn_get_socket(b5160de3e9803af4).(c)); |
| 72 | conn_set_statecxx . . $ pvpgn/bnetd/conn_set_state(7b556497952c81aa).(c, conn_state_connected); |
| 73 | conn_set_classcxx . . $ pvpgn/bnetd/conn_set_class(a3757502d22a5f05).(c, conn_class_bnet); |
| 74 | |
| 75 | break; |
| 76 | |
| 77 | case CLIENT_INITCONN_CLASS_FILEcxx . . $ `src/common/init_protocol.h:60:9`!: |
| 78 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_infocxx . . $ pvpgn/eventlog_level_info., __FUNCTION__, "[{}] client initiated file download connection", conn_get_socketcxx . . $ pvpgn/bnetd/conn_get_socket(b5160de3e9803af4).(c)); |
| 79 | conn_set_statecxx . . $ pvpgn/bnetd/conn_set_state(7b556497952c81aa).(c, conn_state_connected); |
| 80 | conn_set_classcxx . . $ pvpgn/bnetd/conn_set_class(a3757502d22a5f05).(c, conn_class_file); |
| 81 | |
| 82 | break; |
| 83 | |
| 84 | case CLIENT_INITCONN_CLASS_BOTcxx . . $ `src/common/init_protocol.h:61:9`!: |
| 85 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_infocxx . . $ pvpgn/eventlog_level_info., __FUNCTION__, "[{}] client initiated chat bot connection", conn_get_socketcxx . . $ pvpgn/bnetd/conn_get_socket(b5160de3e9803af4).(c)); |
| 86 | conn_set_statecxx . . $ pvpgn/bnetd/conn_set_state(7b556497952c81aa).(c, conn_state_connected); |
| 87 | conn_set_classcxx . . $ pvpgn/bnetd/conn_set_class(a3757502d22a5f05).(c, conn_class_bot); |
| 88 | |
| 89 | break; |
| 90 | |
| 91 | case CLIENT_INITCONN_CLASS_TELNETcxx . . $ `src/common/init_protocol.h:63:9`!: |
| 92 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_infocxx . . $ pvpgn/eventlog_level_info., __FUNCTION__, "[{}] client initiated telnet connection", conn_get_socketcxx . . $ pvpgn/bnetd/conn_get_socket(b5160de3e9803af4).(c)); |
| 93 | conn_set_statecxx . . $ pvpgn/bnetd/conn_set_state(7b556497952c81aa).(c, conn_state_connected); |
| 94 | conn_set_classcxx . . $ pvpgn/bnetd/conn_set_class(a3757502d22a5f05).(c, conn_class_telnet); |
| 95 | |
| 96 | break; |
| 97 | |
| 98 | case CLIENT_INITCONN_CLASS_D2CS_BNETDcxx . . $ `src/common/init_protocol.h:66:9`!: |
| 99 | { |
| 100 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_infocxx . . $ pvpgn/eventlog_level_info., __FUNCTION__, "[{}] client initiated d2cs_bnetd connection", conn_get_socketcxx . . $ pvpgn/bnetd/conn_get_socket(b5160de3e9803af4).(c)); |
| 101 | |
| 102 | if (!(realmlist_find_realm_by_ipcxx . . $ pvpgn/bnetd/realmlist_find_realm_by_ip(a00e58d003047626).(conn_get_addrcxx . . $ pvpgn/bnetd/conn_get_addr(8bd2285a65940781).(c)))) |
| 103 | { |
| 104 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_infocxx . . $ pvpgn/eventlog_level_info., __FUNCTION__, "[{}] d2cs connection from unknown ip address {}", conn_get_socketcxx . . $ pvpgn/bnetd/conn_get_socket(b5160de3e9803af4).(c), addr_num_to_addr_strcxx . . $ pvpgn/addr_num_to_addr_str(9313bf3c546cb16).(conn_get_addrcxx . . $ pvpgn/bnetd/conn_get_addr(8bd2285a65940781).(c), conn_get_portcxx . . $ pvpgn/bnetd/conn_get_port(70207a9c46bcade7).(c))); |
| 105 | return -1; |
| 106 | } |
| 107 | |
| 108 | conn_set_statecxx . . $ pvpgn/bnetd/conn_set_state(7b556497952c81aa).(c, conn_state_connected); |
| 109 | conn_set_classcxx . . $ pvpgn/bnetd/conn_set_class(a3757502d22a5f05).(c, conn_class_d2cs_bnetd); |
| 110 | if (handle_d2cs_initcxx . . $ pvpgn/bnetd/handle_d2cs_init(c4dfbc2386fe4fc3).(c) < 0) |
| 111 | { |
| 112 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_infocxx . . $ pvpgn/eventlog_level_info., __FUNCTION__, "faild to init d2cs connection"); |
| 113 | return -1; |
| 114 | } |
| 115 | } |
| 116 | break; |
| 117 | |
| 118 | case CLIENT_INITCONN_CLASS_ENCcxx . . $ `src/common/init_protocol.h:62:9`!: |
| 119 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_infocxx . . $ pvpgn/eventlog_level_info., __FUNCTION__, "[{}] client initiated encrypted connection (not supported)", conn_get_socketcxx . . $ pvpgn/bnetd/conn_get_socket(b5160de3e9803af4).(c)); |
| 120 | return -1; |
| 121 | break; |
| 122 | |
| 123 | case CLIENT_INITCONN_CLASS_LOCALMACHINEcxx . . $ `src/common/init_protocol.h:67:9`!: |
| 124 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_infocxx . . $ pvpgn/eventlog_level_info., __FUNCTION__, "[{}] client initiated connection from local computer to 127.0.0.1", conn_get_socketcxx . . $ pvpgn/bnetd/conn_get_socket(b5160de3e9803af4).(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 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "[{}] client requested unknown class 0x{:02x} (length {}) (closing connection)", conn_get_socketcxx . . $ pvpgn/bnetd/conn_get_socket(b5160de3e9803af4).(c), (unsigned int)bn_byte_get(packet->ucxx . . $ pvpgn/$anonymous_type_a1640d8ff791e3e5_2#u..client_initconncxx . . $ pvpgn/$anonymous_type_a1640d8ff791e3e5_2#$anonymous_type_3#client_initconn..cclasscxx . . $ pvpgn/$anonymous_type_7cca3803bac3bad7_0#cclass.), packet_get_sizecxx . . $ pvpgn/packet_get_size(e4ac9e2b4744cb4b).(packet)); |
| 134 | return -1; |
| 135 | } |
| 136 | break; |
| 137 | default: |
| 138 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "[{}] unknown init packet type 0x{:04x}, len {}", conn_get_socketcxx . . $ pvpgn/bnetd/conn_get_socket(b5160de3e9803af4).(c), packet_get_typecxx . . $ pvpgn/packet_get_type(e4ac9e2b4744cb4b).(packet), packet_get_sizecxx . . $ pvpgn/packet_get_size(e4ac9e2b4744cb4b).(packet)); |
| 139 | return -1; |
| 140 | } |
| 141 | |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | } |
| 146 | |
| 147 | } |