| 1 | /* |
| 2 | * Copyright (C) 2007 Pelish ([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 | |
| 19 | #include "common/setup_before.h"cxx . . $ `<file>/src/common/setup_before.h`/ |
| 20 | #include "handle_irc_common.h"cxx . . $ `<file>/src/bnetd/handle_irc_common.h`/ |
| 21 | |
| 22 | #include <cstring> |
| 23 | #include <cctype> |
| 24 | #include <cstdlib> |
| 25 | #include <string> |
| 26 | |
| 27 | #include "compat/strcasecmp.h"cxx . . $ `<file>/src/compat/strcasecmp.h`/ |
| 28 | #include "common/eventlog.h"cxx . . $ `<file>/src/common/eventlog.h`/ |
| 29 | #include "common/util.h"cxx . . $ `<file>/src/common/util.h`/ |
| 30 | #include "common/irc_protocol.h"cxx . . $ `<file>/src/common/irc_protocol.h`/ |
| 31 | |
| 32 | #include "handle_irc.h"cxx . . $ `<file>/src/bnetd/handle_irc.h`/ |
| 33 | #include "handle_wol.h"cxx . . $ `<file>/src/bnetd/handle_wol.h`/ |
| 34 | #include "handle_wserv.h"cxx . . $ `<file>/src/bnetd/handle_wserv.h`/ |
| 35 | |
| 36 | #include "prefs.h"cxx . . $ `<file>/src/bnetd/prefs.h`/ |
| 37 | #include "command.h"cxx . . $ `<file>/src/bnetd/command.h`/ |
| 38 | #include "irc.h"cxx . . $ `<file>/src/bnetd/irc.h`/ |
| 39 | |
| 40 | #include "common/setup_after.h"cxx . . $ `<file>/src/common/setup_after.h`/ |
| 41 | |
| 42 | namespace pvpgncxx . . $ pvpgn/ |
| 43 | { |
| 44 | |
| 45 | namespace bnetdcxx . . $ pvpgn/bnetd/ |
| 46 | { |
| 47 | |
| 48 | static int handle_irc_common_con_commandcxx . . $ pvpgn/bnetd/handle_irc_common_con_command(893e223956009815).(t_connectioncxx . . $ pvpgn/bnetd/t_connection# * conn, char const * command, int numparams, char ** params, char * text) |
| 49 | { |
| 50 | if (!conn) { |
| 51 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL connection"); |
| 52 | return -1; |
| 53 | } |
| 54 | |
| 55 | switch (conn_get_classcxx . . $ pvpgn/bnetd/conn_get_class(1f98a8b9c19f47bc).(conn)) { |
| 56 | case conn_class_irccxx . . $ pvpgn/bnetd/conn_class_irc.: |
| 57 | return handle_irc_con_commandcxx . . $ pvpgn/bnetd/handle_irc_con_command(893e223956009815).(conn, command, numparams, params, text); |
| 58 | case conn_class_wservcxx . . $ pvpgn/bnetd/conn_class_wserv.: |
| 59 | return handle_wserv_con_commandcxx . . $ pvpgn/bnetd/handle_wserv_con_command(893e223956009815).(conn, command, numparams, params, text); |
| 60 | case conn_class_wolcxx . . $ pvpgn/bnetd/conn_class_wol.: |
| 61 | case conn_class_wladdercxx . . $ pvpgn/bnetd/conn_class_wladder.: |
| 62 | case conn_class_wgamerescxx . . $ pvpgn/bnetd/conn_class_wgameres.: |
| 63 | return handle_wol_con_commandcxx . . $ pvpgn/bnetd/handle_wol_con_command(893e223956009815).(conn, command, numparams, params, text); |
| 64 | default: |
| 65 | return handle_irc_con_commandcxx . . $ pvpgn/bnetd/handle_irc_con_command(893e223956009815).(conn, command, numparams, params, text); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | static int handle_irc_common_log_commandcxx . . $ pvpgn/bnetd/handle_irc_common_log_command(893e223956009815).(t_connectioncxx . . $ pvpgn/bnetd/t_connection# * conn, char const * command, int numparams, char ** params, char * text) |
| 70 | { |
| 71 | if (!conn) { |
| 72 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL connection"); |
| 73 | return -1; |
| 74 | } |
| 75 | |
| 76 | switch (conn_get_classcxx . . $ pvpgn/bnetd/conn_get_class(1f98a8b9c19f47bc).(conn)) { |
| 77 | case conn_class_irccxx . . $ pvpgn/bnetd/conn_class_irc.: |
| 78 | return handle_irc_log_commandcxx . . $ pvpgn/bnetd/handle_irc_log_command(893e223956009815).(conn, command, numparams, params, text); |
| 79 | case conn_class_wolcxx . . $ pvpgn/bnetd/conn_class_wol.: |
| 80 | case conn_class_wgamerescxx . . $ pvpgn/bnetd/conn_class_wgameres.: |
| 81 | return handle_wol_log_commandcxx . . $ pvpgn/bnetd/handle_wol_log_command(893e223956009815).(conn, command, numparams, params, text); |
| 82 | default: |
| 83 | return handle_irc_log_commandcxx . . $ pvpgn/bnetd/handle_irc_log_command(893e223956009815).(conn, command, numparams, params, text); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | static int handle_irc_common_set_classcxx . . $ pvpgn/bnetd/handle_irc_common_set_class(893e223956009815).(t_connectioncxx . . $ pvpgn/bnetd/t_connection# * conn, char const * command, int numparams, char ** params, char * text) |
| 88 | { |
| 89 | if (!conn) { |
| 90 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL connection"); |
| 91 | return -1; |
| 92 | } |
| 93 | |
| 94 | if (conn_get_classcxx . . $ pvpgn/bnetd/conn_get_class(1f98a8b9c19f47bc).(conn) != conn_class_ircinitcxx . . $ pvpgn/bnetd/conn_class_ircinit.) { |
| 95 | DEBUG0cxx . . $ `src/common/eventlog.h:88:9`!("FIXME: conn_get_class(conn) != conn_class_ircinit"); |
| 96 | return -1; |
| 97 | } |
| 98 | else { |
| 99 | if (strcasecmp(command, "VERCHK") == 0) { |
| 100 | DEBUG0cxx . . $ `src/common/eventlog.h:88:9`!("Got WSERV packet"); |
| 101 | if (stdcxx . . $ std/::strcmp(prefs_get_wolv2_addrscxx . . $ pvpgn/bnetd/prefs_get_wolv2_addrs(33a1f659e94feb42).(), "") != 0) |
| 102 | conn_set_classcxx . . $ pvpgn/bnetd/conn_set_class(a3757502d22a5f05).(conn, conn_class_wservcxx . . $ pvpgn/bnetd/conn_class_wserv.); |
| 103 | else |
| 104 | conn_set_statecxx . . $ pvpgn/bnetd/conn_set_state(7b556497952c81aa).(conn, conn_state_destroycxx . . $ pvpgn/bnetd/conn_state_destroy.); |
| 105 | return 0; |
| 106 | } |
| 107 | else if (strcasecmp(command, "CVERS") == 0) { |
| 108 | DEBUG0cxx . . $ `src/common/eventlog.h:88:9`!("Got WOL packet"); |
| 109 | /* FIXME: We can check it not by address but check if client is supported by tag_check_in_list() */ |
| 110 | if ((stdcxx . . $ std/::strcmp(prefs_get_wolv1_addrscxx . . $ pvpgn/bnetd/prefs_get_wolv1_addrs(33a1f659e94feb42).(), "") != 0) || (stdcxx . . $ std/::strcmp(prefs_get_wolv2_addrscxx . . $ pvpgn/bnetd/prefs_get_wolv2_addrs(33a1f659e94feb42).(), "") != 0)) |
| 111 | conn_set_classcxx . . $ pvpgn/bnetd/conn_set_class(a3757502d22a5f05).(conn, conn_class_wolcxx . . $ pvpgn/bnetd/conn_class_wol.); |
| 112 | else |
| 113 | conn_set_statecxx . . $ pvpgn/bnetd/conn_set_state(7b556497952c81aa).(conn, conn_state_destroycxx . . $ pvpgn/bnetd/conn_state_destroy.); |
| 114 | return 0; |
| 115 | } |
| 116 | else if ((strcasecmp(command, "LISTSEARCH") == 0) || |
| 117 | (strcasecmp(command, "RUNGSEARCH") == 0) || |
| 118 | (strcasecmp(command, "HIGHSCORE") == 0)) { |
| 119 | DEBUG0cxx . . $ `src/common/eventlog.h:88:9`!("Got WOL Ladder packet"); |
| 120 | if (stdcxx . . $ std/::strcmp(prefs_get_wolv2_addrscxx . . $ pvpgn/bnetd/prefs_get_wolv2_addrs(33a1f659e94feb42).(), "") != 0) |
| 121 | conn_set_classcxx . . $ pvpgn/bnetd/conn_set_class(a3757502d22a5f05).(conn, conn_class_wladdercxx . . $ pvpgn/bnetd/conn_class_wladder.); /* is handled in handle_wol.* now */ |
| 122 | else |
| 123 | conn_set_statecxx . . $ pvpgn/bnetd/conn_set_state(7b556497952c81aa).(conn, conn_state_destroycxx . . $ pvpgn/bnetd/conn_state_destroy.); |
| 124 | return 0; |
| 125 | } |
| 126 | else if ((strcasecmp(command, "CRYPT") == 0) || |
| 127 | (strcasecmp(command, "LOGIN") == 0)) { |
| 128 | DEBUG0cxx . . $ `src/common/eventlog.h:88:9`!("Got GameSpy packet"); |
| 129 | if (stdcxx . . $ std/::strcmp(prefs_get_irc_addrscxx . . $ pvpgn/bnetd/prefs_get_irc_addrs(33a1f659e94feb42).(), "") != 0) |
| 130 | conn_set_classcxx . . $ pvpgn/bnetd/conn_set_class(a3757502d22a5f05).(conn, conn_class_irccxx . . $ pvpgn/bnetd/conn_class_irc.); |
| 131 | // conn_set_class(conn,conn_class_gspy_peerchat); |
| 132 | else |
| 133 | conn_set_statecxx . . $ pvpgn/bnetd/conn_set_state(7b556497952c81aa).(conn, conn_state_destroycxx . . $ pvpgn/bnetd/conn_state_destroy.); |
| 134 | return 0; |
| 135 | } |
| 136 | else { |
| 137 | DEBUG0cxx . . $ `src/common/eventlog.h:88:9`!("Got IRC packet"); |
| 138 | if (stdcxx . . $ std/::strcmp(prefs_get_irc_addrscxx . . $ pvpgn/bnetd/prefs_get_irc_addrs(33a1f659e94feb42).(), "") != 0) |
| 139 | conn_set_classcxx . . $ pvpgn/bnetd/conn_set_class(a3757502d22a5f05).(conn, conn_class_irccxx . . $ pvpgn/bnetd/conn_class_irc.); |
| 140 | else |
| 141 | conn_set_statecxx . . $ pvpgn/bnetd/conn_set_state(7b556497952c81aa).(conn, conn_state_destroycxx . . $ pvpgn/bnetd/conn_state_destroy.); |
| 142 | return 0; |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | static int handle_irc_common_linecxx . . $ pvpgn/bnetd/handle_irc_common_line(2e9022cda97b266d).(t_connectioncxx . . $ pvpgn/bnetd/t_connection# * conn, char const * ircline) |
| 148 | { |
| 149 | /* [:prefix] <command> [[param1] [param2] ... [paramN]] [:<text>] */ |
| 150 | char * line; /* copy of ircline */ |
| 151 | char * prefix = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; /* optional; mostly NULL */ |
| 152 | char * command; /* mandatory */ |
| 153 | char ** params = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; /* optional (array of params) */ |
| 154 | char * text = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; /* optional */ |
| 155 | char * bnet_command = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; /* amadeo: used for battle.net.commands */ |
| 156 | int unrecognized_before = 0; |
| 157 | int linelen; /* amadeo: counter for stringlenghts */ |
| 158 | int numparams = 0; |
| 159 | char * tempparams; |
| 160 | int i; |
| 161 | |
| 162 | if (!conn) { |
| 163 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL connection"); |
| 164 | return -1; |
| 165 | } |
| 166 | if (!ircline) { |
| 167 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL ircline"); |
| 168 | return -1; |
| 169 | } |
| 170 | if (ircline[0] == '\0') { |
| 171 | /** |
| 172 | * PELISH: We dont send warning about that because it is client-side problem. |
| 173 | * eventlog(eventlog_level_error,__FUNCTION__,"got empty ircline"); |
| 174 | */ |
| 175 | return -1; |
| 176 | } |
| 177 | |
| 178 | //amadeo: code was sent by some unknown fellow of pvpgn, prevents buffer-overflow for |
| 179 | // too long irc-lines |
| 180 | //PELISH: According to RFC2812 we do truncation on 512 byte |
| 181 | |
| 182 | if (stdcxx . . $ std/::strlen(ircline) > MAX_IRC_MESSAGE_LENcxx . . $ MAX_IRC_MESSAGE_LEN.) { |
| 183 | char * tmp = (char *)ircline; |
| 184 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_warncxx . . $ pvpgn/eventlog_level_warn., __FUNCTION__, "line too long, truncation..."); |
| 185 | tmp[MAX_IRC_MESSAGE_LENcxx . . $ MAX_IRC_MESSAGE_LEN.] = '\0'; |
| 186 | } |
| 187 | |
| 188 | line = xstrdupcxx . . $ `src/common/xalloc.h:49:9`!(ircline); |
| 189 | |
| 190 | /* split the message */ |
| 191 | if (line[0] == ':') { |
| 192 | /* The prefix is optional and is rarely provided */ |
| 193 | prefix = line; |
| 194 | if (!(command = stdcxx . . $ std/::strchr(line, ' '))) { |
| 195 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_warncxx . . $ pvpgn/eventlog_level_warn., __FUNCTION__, "got malformed line (missing command)"); |
| 196 | xfreecxx . . $ `src/common/xalloc.h:51:9`!(line); |
| 197 | return -1; |
| 198 | } |
| 199 | *command++ = '\0'; |
| 200 | } |
| 201 | else { |
| 202 | /* In most cases command is the first thing on the line */ |
| 203 | command = line; |
| 204 | } |
| 205 | |
| 206 | tempparams = stdcxx . . $ std/::strchr(command, ' '); |
| 207 | if (tempparams) { |
| 208 | *tempparams++ = '\0'; |
| 209 | if (tempparams[0] == ':') { |
| 210 | text = tempparams + 1; /* theres just text, no params. skip the colon */ |
| 211 | } |
| 212 | else { |
| 213 | for (i = 0; tempparams[i] != '\0'; i++) { |
| 214 | if ((tempparams[i] == ' ') && (tempparams[i + 1] == ':')) { |
| 215 | text = tempparams + i; |
| 216 | *text++ = '\0'; |
| 217 | text++; /* skip the colon */ |
| 218 | break; /* text found, stop search */ |
| 219 | } |
| 220 | } |
| 221 | params = irc_get_paramelemscxx . . $ pvpgn/bnetd/irc_get_paramelems(c5fc499caf24bdd3).(tempparams); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | if (params) { |
| 226 | /* count parameters */ |
| 227 | for (numparams = 0; params[numparams]; numparams++); |
| 228 | } |
| 229 | |
| 230 | { |
| 231 | stdcxx . . $ std/::stringcxx . . $ std/string# paramtempcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; |
| 232 | bool first = true; |
| 233 | for (i = 0; ((numparams > 0) && (params[i])); i++) |
| 234 | { |
| 235 | if (first) |
| 236 | { |
| 237 | first = false; |
| 238 | } |
| 239 | else |
| 240 | { |
| 241 | paramtemp.appendcxx . . $ std/__cxx11/basic_string#append(978ca1133b5f6e74).(" "); |
| 242 | } |
| 243 | |
| 244 | paramtemp.appendcxx . . $ std/__cxx11/basic_string#append(c0b47be1fddc0e75).("\"" +cxx . . $ std/operator+(39ed2c165380f78e). stdcxx . . $ std/::stringcxx . . $ std/string#(params[i]) +cxx . . $ std/operator+(900ec9581c410ad9). "\""); |
| 245 | } |
| 246 | |
| 247 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_debugcxx . . $ pvpgn/eventlog_level_debug., __FUNCTION__, "[{}] got \"{}\" \"{}\" [{}] \"{}\"", conn_get_socketcxx . . $ pvpgn/bnetd/conn_get_socket(b5160de3e9803af4).(conn), ((prefix) ? (prefix) : ("")), command, paramtemp, ((text) ? (text) : (""))); |
| 248 | } |
| 249 | |
| 250 | if (conn_get_classcxx . . $ pvpgn/bnetd/conn_get_class(1f98a8b9c19f47bc).(conn) == conn_class_ircinitcxx . . $ pvpgn/bnetd/conn_class_ircinit.) { |
| 251 | handle_irc_common_set_classcxx . . $ pvpgn/bnetd/handle_irc_common_set_class(893e223956009815).(conn, command, numparams, params, text); |
| 252 | } |
| 253 | |
| 254 | if (conn_get_statecxx . . $ pvpgn/bnetd/conn_get_state(14586157a79399d4).(conn) == conn_state_connectedcxx . . $ pvpgn/bnetd/conn_state_connected.) { |
| 255 | conn_set_statecxx . . $ pvpgn/bnetd/conn_set_state(7b556497952c81aa).(conn, conn_state_bot_usernamecxx . . $ pvpgn/bnetd/conn_state_bot_username.); /* PELISH: What is this for? */ |
| 256 | |
| 257 | if ((conn_get_classcxx . . $ pvpgn/bnetd/conn_get_class(1f98a8b9c19f47bc).(conn) != conn_class_wservcxx . . $ pvpgn/bnetd/conn_class_wserv.) && |
| 258 | (conn_get_classcxx . . $ pvpgn/bnetd/conn_get_class(1f98a8b9c19f47bc).(conn) != conn_class_wladdercxx . . $ pvpgn/bnetd/conn_class_wladder.)) { |
| 259 | |
| 260 | t_timer_datacxx . . $ pvpgn/bnetd/t_timer_data# temp; |
| 261 | temp.ncxx . . $ pvpgn/bnetd/$anonymous_type_64e82d6b10ad28f9_0#n. = prefs_get_irc_latencycxx . . $ pvpgn/bnetd/prefs_get_irc_latency(db52760e79bf9054).(); |
| 262 | conn_test_latencycxx . . $ pvpgn/bnetd/conn_test_latency(9b6c929c3dbc4c93).(conn, stdcxx . . $ std/::timecxx . . $ std/time(a7cd306b2d326b09).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!), temp); |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | if (handle_irc_common_con_commandcxx . . $ pvpgn/bnetd/handle_irc_common_con_command(893e223956009815).(conn, command, numparams, params, text) != -1) {} |
| 267 | else if (conn_get_statecxx . . $ pvpgn/bnetd/conn_get_state(14586157a79399d4).(conn) != conn_state_loggedincxx . . $ pvpgn/bnetd/conn_state_loggedin.) |
| 268 | { |
| 269 | stdcxx . . $ std/::stringcxx . . $ std/string# tmp(":Unrecognized command \"" +cxx . . $ std/operator+(39ed2c165380f78e). stdcxx . . $ std/::stringcxx . . $ std/string#(command) +cxx . . $ std/operator+(900ec9581c410ad9). "\" (before login)"); |
| 270 | if (tmp.lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).() > MAX_IRC_MESSAGE_LENcxx . . $ MAX_IRC_MESSAGE_LEN.) |
| 271 | irc_sendcxx . . $ pvpgn/bnetd/irc_send(2e21047ccae6acf).(conn, ERR_UNKNOWNCOMMANDcxx . . $ `src/common/irc_protocol.h:404:9`!, tmp.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()); |
| 272 | else |
| 273 | irc_sendcxx . . $ pvpgn/bnetd/irc_send(2e21047ccae6acf).(conn, ERR_UNKNOWNCOMMANDcxx . . $ `src/common/irc_protocol.h:404:9`!, ":Unrecognized command (before login)"); |
| 274 | } |
| 275 | else |
| 276 | { |
| 277 | /* command is handled later */ |
| 278 | unrecognized_before = 1; |
| 279 | } |
| 280 | /* --- The following should only be executable after login --- */ |
| 281 | if ((conn_get_statecxx . . $ pvpgn/bnetd/conn_get_state(14586157a79399d4).(conn) == conn_state_loggedincxx . . $ pvpgn/bnetd/conn_state_loggedin.) && (unrecognized_before)) { |
| 282 | |
| 283 | if (handle_irc_common_log_commandcxx . . $ pvpgn/bnetd/handle_irc_common_log_command(893e223956009815).(conn, command, numparams, params, text) != -1) {} |
| 284 | else if ((strstartcxx . . $ pvpgn/strstart(5ae29d726ae57f88).(command, "LAG") != 0) && (strstartcxx . . $ pvpgn/strstart(5ae29d726ae57f88).(command, "JOIN") != 0)){ |
| 285 | linelen = stdcxx . . $ std/::strlen(ircline); |
| 286 | bnet_command = (char*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(linelen + 2); |
| 287 | bnet_command[0] = '/'; |
| 288 | stdcxx . . $ std/::strcpy(bnet_command + 1, ircline); |
| 289 | handle_commandcxx . . $ pvpgn/bnetd/handle_command(2e9022cda97b266d).(conn, bnet_command); |
| 290 | xfreecxx . . $ `src/common/xalloc.h:51:9`!((void*)bnet_command); |
| 291 | } |
| 292 | } /* loggedin */ |
| 293 | if (params) |
| 294 | irc_unget_paramelemscxx . . $ pvpgn/bnetd/irc_unget_paramelems(b90f8021b121110e).(params); |
| 295 | xfreecxx . . $ `src/common/xalloc.h:51:9`!(line); |
| 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | |
| 300 | extern int handle_irc_common_packetcxx . . $ pvpgn/bnetd/handle_irc_common_packet(8d07eb83d60bed1d).(t_connectioncxx . . $ pvpgn/bnetd/t_connection# * conn, t_packetcxx . . $ pvpgn/t_packet# const * const packet) |
| 301 | { |
| 302 | unsigned int i; |
| 303 | char ircline[MAX_IRC_MESSAGE_LENcxx . . $ MAX_IRC_MESSAGE_LEN.]; |
| 304 | char const * data; |
| 305 | |
| 306 | if (!packet) { |
| 307 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL packet"); |
| 308 | return -1; |
| 309 | } |
| 310 | if ((conn_get_classcxx . . $ pvpgn/bnetd/conn_get_class(1f98a8b9c19f47bc).(conn) != conn_class_ircinitcxx . . $ pvpgn/bnetd/conn_class_ircinit.) && |
| 311 | (conn_get_classcxx . . $ pvpgn/bnetd/conn_get_class(1f98a8b9c19f47bc).(conn) != conn_class_irccxx . . $ pvpgn/bnetd/conn_class_irc.) && |
| 312 | (conn_get_classcxx . . $ pvpgn/bnetd/conn_get_class(1f98a8b9c19f47bc).(conn) != conn_class_wolcxx . . $ pvpgn/bnetd/conn_class_wol.) && |
| 313 | (conn_get_classcxx . . $ pvpgn/bnetd/conn_get_class(1f98a8b9c19f47bc).(conn) != conn_class_wservcxx . . $ pvpgn/bnetd/conn_class_wserv.) && |
| 314 | (conn_get_classcxx . . $ pvpgn/bnetd/conn_get_class(1f98a8b9c19f47bc).(conn) != conn_class_wladdercxx . . $ pvpgn/bnetd/conn_class_wladder.)) { |
| 315 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "FIXME: handle_irc_packet without any reason (conn->class != conn_class_irc/ircinit/wol/wserv...)"); |
| 316 | return -1; |
| 317 | } |
| 318 | |
| 319 | // eventlog(eventlog_level_debug,__FUNCTION__,"got \"%s\"",packet_get_raw_data_const(packet,0)); |
| 320 | |
| 321 | stdcxx . . $ std/::memset(ircline, 0, sizeof(ircline)); |
| 322 | data = conn_get_irclinecxx . . $ pvpgn/bnetd/conn_get_ircline(c99dbccf638f5c6).(conn); /* fetch current status */ |
| 323 | if (data) |
| 324 | stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(ircline, sizeof ircline, "%s", data); |
| 325 | unsigned ircpos = stdcxx . . $ std/::strlen(ircline); |
| 326 | data = (const char *)packet_get_raw_data_constcxx . . $ pvpgn/packet_get_raw_data_const(1f58ab00371793b4).(packet, 0); |
| 327 | |
| 328 | for (i = 0; i < packet_get_sizecxx . . $ pvpgn/packet_get_size(e4ac9e2b4744cb4b).(packet); i++) { |
| 329 | if (data[i] == '\n') { |
| 330 | /* end of line */ |
| 331 | handle_irc_common_linecxx . . $ pvpgn/bnetd/handle_irc_common_line(2e9022cda97b266d).(conn, ircline); |
| 332 | stdcxx . . $ std/::memset(ircline, 0, sizeof(ircline)); |
| 333 | ircpos = 0; |
| 334 | } |
| 335 | else { |
| 336 | if (ircpos < MAX_IRC_MESSAGE_LENcxx . . $ MAX_IRC_MESSAGE_LEN. - 1) |
| 337 | ircline[ircpos++] = data[i]; |
| 338 | else { |
| 339 | ircpos++; /* for the statistic :) */ |
| 340 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_warncxx . . $ pvpgn/eventlog_level_warn., __FUNCTION__, "[{}] client exceeded maximum allowed message length by {} characters", conn_get_socketcxx . . $ pvpgn/bnetd/conn_get_socket(b5160de3e9803af4).(conn), ircpos - MAX_IRC_MESSAGE_LENcxx . . $ MAX_IRC_MESSAGE_LEN.); |
| 341 | if (ircpos > 100 + MAX_IRC_MESSAGE_LENcxx . . $ MAX_IRC_MESSAGE_LEN.) { |
| 342 | /* automatic flood protection */ |
| 343 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "[{}] excess flood", conn_get_socketcxx . . $ pvpgn/bnetd/conn_get_socket(b5160de3e9803af4).(conn)); |
| 344 | return -1; |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | conn_set_irclinecxx . . $ pvpgn/bnetd/conn_set_ircline(2e9022cda97b266d).(conn, ircline); /* write back current status */ |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | } |
| 354 | |
| 355 | } |