Debian Codegraph @

src/bnetd/handle_wserv.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2001 Marco Ziech ([email protected])
3 * Copyright (C) 2005 Bryan Biedenkapp ([email protected])
4 * Copyright (C) 2006,2007,2008 Pelish ([email protected])
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21 #include "common/setup_before.h"cxx . . $ `<file>/src/common/setup_before.h`/
22 #include "handle_wserv.h"cxx . . $ `<file>/src/bnetd/handle_wserv.h`/
23
24 #include <cstring>
25 #include <cctype>
26 #include <cstdlib>
27
28 #include "compat/strcasecmp.h"cxx . . $ `<file>/src/compat/strcasecmp.h`/
29 #include "common/irc_protocol.h"cxx . . $ `<file>/src/common/irc_protocol.h`/
30 #include "common/eventlog.h"cxx . . $ `<file>/src/common/eventlog.h`/
31 #include "common/tag.h"cxx . . $ `<file>/src/common/tag.h`/
32 #include "common/util.h"cxx . . $ `<file>/src/common/util.h`/
33 #include "common/list.h"cxx . . $ `<file>/src/common/list.h`/
34 #include "common/addr.h"cxx . . $ `<file>/src/common/addr.h`/
35 #include "common/trans.h"cxx . . $ `<file>/src/common/trans.h`/
36
37 #include "prefs.h"cxx . . $ `<file>/src/bnetd/prefs.h`/
38 #include "irc.h"cxx . . $ `<file>/src/bnetd/irc.h`/
39 #include "message.h"cxx . . $ `<file>/src/bnetd/message.h`/
40 #include "tick.h"cxx . . $ `<file>/src/bnetd/tick.h`/
41 #include "server.h"cxx . . $ `<file>/src/bnetd/server.h`/
42 #include "autoupdate.h"cxx . . $ `<file>/src/bnetd/autoupdate.h`/
43 #include "common/setup_after.h"cxx . . $ `<file>/src/common/setup_after.h`/
44
45 namespace pvpgncxx . . $ pvpgn/
46 {
47
48 namespace bnetdcxx . . $ pvpgn/bnetd/
49 {
50
51 typedef int(*t_wserv_commandcxx . . $ pvpgn/bnetd/t_wserv_command#)(t_connectioncxx . . $ pvpgn/bnetd/t_connection# * conn, int numparams, char ** params, char * text);
52
53 typedef structcxx . . $ pvpgn/bnetd/$anonymous_type_b068c7785c715b8_0# {
54 const char * wserv_command_stringcxx . . $ pvpgn/bnetd/$anonymous_type_b068c7785c715b8_0#wserv_command_string.;
55 t_wserv_commandcxx . . $ pvpgn/bnetd/t_wserv_command# wserv_command_handlercxx . . $ pvpgn/bnetd/$anonymous_type_b068c7785c715b8_0#wserv_command_handler.;
56 } t_wserv_command_table_rowcxx . . $ pvpgn/bnetd/t_wserv_command_table_row#;
57
58 static int _handle_verchk_commandcxx . . $ pvpgn/bnetd/_handle_verchk_command(93df5f0f7c1da4a4).(t_connectioncxx . . $ pvpgn/bnetd/t_connection# * conn, int numparams, char ** params, char * text);
59 static int _handle_lobcount_commandcxx . . $ pvpgn/bnetd/_handle_lobcount_command(93df5f0f7c1da4a4).(t_connectioncxx . . $ pvpgn/bnetd/t_connection# * conn, int numparams, char ** params, char * text);
60 static int _handle_whereto_commandcxx . . $ pvpgn/bnetd/_handle_whereto_command(93df5f0f7c1da4a4).(t_connectioncxx . . $ pvpgn/bnetd/t_connection# * conn, int numparams, char ** params, char * text);
61 static int _handle_quit_commandcxx . . $ pvpgn/bnetd/_handle_quit_command(93df5f0f7c1da4a4).(t_connectioncxx . . $ pvpgn/bnetd/t_connection# * conn, int numparams, char ** params, char * text);
62
63 /* state "connected" handlers (on Westwood ServServ server are not loged-in) */
64 static const t_wserv_command_table_rowcxx . . $ pvpgn/bnetd/t_wserv_command_table_row# wserv_con_command_tablecxx . . $ pvpgn/bnetd/wserv_con_command_table.[] =
65 {
66 { "VERCHK", _handle_verchk_commandcxx . . $ pvpgn/bnetd/_handle_verchk_command(93df5f0f7c1da4a4). },
67 { "LOBCOUNT", _handle_lobcount_commandcxx . . $ pvpgn/bnetd/_handle_lobcount_command(93df5f0f7c1da4a4). },
68 { "WHERETO", _handle_whereto_commandcxx . . $ pvpgn/bnetd/_handle_whereto_command(93df5f0f7c1da4a4). },
69 { "QUIT", _handle_quit_commandcxx . . $ pvpgn/bnetd/_handle_quit_command(93df5f0f7c1da4a4). },
70
71 { NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! }
72 };
73
74 extern int handle_wserv_con_commandcxx . . $ pvpgn/bnetd/handle_wserv_con_command(893e223956009815).(t_connectioncxx . . $ pvpgn/bnetd/t_connection# * conn, char const * command, int numparams, char ** params, char * text)
75 {
76 t_wserv_command_table_rowcxx . . $ pvpgn/bnetd/t_wserv_command_table_row# const *p;
77
78 for (p = wserv_con_command_tablecxx . . $ pvpgn/bnetd/wserv_con_command_table.; p->wserv_command_stringcxx . . $ pvpgn/bnetd/$anonymous_type_b068c7785c715b8_0#wserv_command_string. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; p++) {
79 if (strcasecmp(command, p->wserv_command_stringcxx . . $ pvpgn/bnetd/$anonymous_type_b068c7785c715b8_0#wserv_command_string.) == 0) {
80 if (p->wserv_command_handlercxx . . $ pvpgn/bnetd/$anonymous_type_b068c7785c715b8_0#wserv_command_handler. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
81 return ((p->wserv_command_handlercxx . . $ pvpgn/bnetd/$anonymous_type_b068c7785c715b8_0#wserv_command_handler.)(conn, numparams, params, text));
82 }
83 }
84 return -1;
85 }
86
87 static int _handle_verchk_commandcxx . . $ pvpgn/bnetd/_handle_verchk_command(93df5f0f7c1da4a4).(t_connectioncxx . . $ pvpgn/bnetd/t_connection# * conn, int numparams, char ** params, char * text)
88 {
89 char temp[MAX_IRC_MESSAGE_LENcxx . . $ MAX_IRC_MESSAGE_LEN.];
90 t_clienttagcxx . . $ pvpgn/t_clienttag# clienttag;
91 char const *ftphostname;
92 char const *ftpusername;
93 char const *ftppassword;
94
95 /**
96 * Heres the imput expected:
97 * vercheck [SKU] [version]
98 *
99 * Here is output expected for ServServ server:
100 * 1) Update non-existant:
101 * :[servername] 602 [username] :Update record non-existant
102 * 2) Update existant:
103 * :[servername] 606 [username] :[ftpserveraddr] [ftpusername] [ftppaswd] [path] [file.rtp] [newversion] [SKU] REQ
104 */
105
106 if (numparams >= 2)
107 {
108 clienttag = tag_sku_to_uint(stdcxx . . $ std/::atoi(params[0]));
109
110 if (clienttag != CLIENTTAG_WWOL_UINTcxx . . $ `/build/tmp.prHwK0hYwT/package/src/common/tag.h:146:9`!)
111 conn_set_clienttagcxx . . $ pvpgn/bnetd/conn_set_clienttag(d97ad1b62a895b69).(conn, clienttag);
112
113 const char* const filestring = autoupdate_checkcxx . . $ pvpgn/bnetd/autoupdate_check(89dc5b73db77f621).(ARCHTAG_WINX86_UINTcxx . . $ `/build/tmp.prHwK0hYwT/package/src/common/tag.h:159:9`!, clienttag, TAG_UNKNOWN_UINTcxx . . $ `/build/tmp.prHwK0hYwT/package/src/common/tag.h:177:9`!, params[1], params[0]);
114 if (filestring)
115 {
116 //:westwood-patch.ea.com update world96 lore3/1.003 65539_65536_6400.rtp 65539 6400 REQ
117 ftphostname = prefs_get_wol_autoupdate_serverhostcxx . . $ pvpgn/bnetd/prefs_get_wol_autoupdate_serverhost(33a1f659e94feb42).();
118 ftpusername = prefs_get_wol_autoupdate_usernamecxx . . $ pvpgn/bnetd/prefs_get_wol_autoupdate_username(33a1f659e94feb42).();
119 ftppassword = prefs_get_wol_autoupdate_passwordcxx . . $ pvpgn/bnetd/prefs_get_wol_autoupdate_password(33a1f659e94feb42).();
120 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(temp, sizeof(temp), ":%s %s %s %s 131075 %s REQ", ftphostname, ftpusername, ftppassword, filestring, params[0]);
121 irc_sendcxx . . $ pvpgn/bnetd/irc_send(2e21047ccae6acf).(conn, RPL_UPDATE_FTPcxx . . $ `src/common/irc_protocol.h:359:9`!, temp);
122 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void*)filestring);
123 }
124 else
125 {
126 irc_sendcxx . . $ pvpgn/bnetd/irc_send(2e21047ccae6acf).(conn, RPL_UPDATE_NONEXcxx . . $ `src/common/irc_protocol.h:355:9`!, ":Update record non-existant");
127 }
128 }
129 else
130 irc_sendcxx . . $ pvpgn/bnetd/irc_send(2e21047ccae6acf).(conn, ERR_NEEDMOREPARAMScxx . . $ `src/common/irc_protocol.h:441:9`!, "VERCHK :Not enough parameters");
131 return 0;
132 }
133
134 static int _handle_lobcount_commandcxx . . $ pvpgn/bnetd/_handle_lobcount_command(93df5f0f7c1da4a4).(t_connectioncxx . . $ pvpgn/bnetd/t_connection# * conn, int numparams, char ** params, char * text)
135 {
136 /* Ignore command but, return 1 */
137 irc_sendcxx . . $ pvpgn/bnetd/irc_send(2e21047ccae6acf).(conn, RPL_LOBCOUNTcxx . . $ `src/common/irc_protocol.h:363:9`!, "1");
138
139 return 0;
140 }
141
142 static int _handle_whereto_commandcxx . . $ pvpgn/bnetd/_handle_whereto_command(93df5f0f7c1da4a4).(t_connectioncxx . . $ pvpgn/bnetd/t_connection# * conn, int numparams, char ** params, char * text)
143 {
144 char temp[MAX_IRC_MESSAGE_LENcxx . . $ MAX_IRC_MESSAGE_LEN.];
145
146 /* Casted to avoid warnings */
147 const char * wolip;
148 const char * wolname = prefs_get_servernamecxx . . $ pvpgn/bnetd/prefs_get_servername(33a1f659e94feb42).();
149 const char * woltimezone = prefs_get_wol_timezonecxx . . $ pvpgn/bnetd/prefs_get_wol_timezone(33a1f659e94feb42).();
150 const char * wollong = prefs_get_wol_longitudecxx . . $ pvpgn/bnetd/prefs_get_wol_longitude(33a1f659e94feb42).();
151 const char * wollat = prefs_get_wol_latitudecxx . . $ pvpgn/bnetd/prefs_get_wol_latitude(33a1f659e94feb42).();
152
153 { /* trans support */
154 unsigned short port = conn_get_real_local_portcxx . . $ pvpgn/bnetd/conn_get_real_local_port(70207a9c46bcade7).(conn);
155 unsigned int addr = conn_get_real_local_addrcxx . . $ pvpgn/bnetd/conn_get_real_local_addr(8bd2285a65940781).(conn);
156
157 trans_netcxx . . $ pvpgn/trans_net(cf0ba8ec647fd542).(conn_get_addrcxx . . $ pvpgn/bnetd/conn_get_addr(8bd2285a65940781).(conn), &addr, &port);
158
159 wolip = addr_num_to_ip_strcxx . . $ pvpgn/addr_num_to_ip_str(81a3ae90da26a711).(addr);
160 }
161
162 //irc_send(conn,RPL_UPDATE_EXIST,":You must update before connecting!");
163
164 // Check if it's an allowed client type
165 if (!tag_check_in_list(conn_get_clienttagcxx . . $ pvpgn/bnetd/conn_get_clienttag(8bd2285a65940781).(conn), prefs_get_allowed_clientscxx . . $ pvpgn/bnetd/prefs_get_allowed_clients(33a1f659e94feb42).())) {
166 // This is for anyone game but not for Emperor
167 if (conn_get_clienttagcxx . . $ pvpgn/bnetd/conn_get_clienttag(8bd2285a65940781).(conn) != CLIENTTAG_EMPERORBD_UINTcxx . . $ `/build/tmp.prHwK0hYwT/package/src/common/tag.h:142:9`!) {
168 // a.xwis.net 4009 RA2
169 // c.xwis.net 4000 TSUN
170 // c.xwis.net 4010 RNGD
171 // a.xwis.net 4010 YURI
172 // snprintf(temp, sizeof(temp), ":a.xwis.net 4009 '0:%s' %s %s %s", wolname, woltimezone, wollong, wollat);
173 // snprintf(temp, sizeof(temp), ":c.xwis.net 4000 '0:%s' %s %s %s", wolname, woltimezone, wollong, wollat);
174 // snprintf(temp, sizeof(temp), ":c.xwis.net 4010 '0:%s' %s %s %s", wolname, woltimezone, wollong, wollat);
175 // snprintf(temp, sizeof(temp), ":a.xwis.net 4010 '0:%s' %s %s %s", wolname, woltimezone, wollong, wollat);
176 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(temp, sizeof(temp), ":%s %d '0:%s' %s %s %s", wolip, BNETD_WOLV2_PORTcxx . . $ BNETD_WOLV2_PORT., wolname, woltimezone, wollong, wollat);
177 irc_sendcxx . . $ pvpgn/bnetd/irc_send(2e21047ccae6acf).(conn, RPL_WOLSERVcxx . . $ `src/common/irc_protocol.h:358:9`!, temp);
178 }
179
180 // Only for Emperor: Battle for Dune
181 if (conn_get_clienttagcxx . . $ pvpgn/bnetd/conn_get_clienttag(8bd2285a65940781).(conn) == CLIENTTAG_EMPERORBD_UINTcxx . . $ `/build/tmp.prHwK0hYwT/package/src/common/tag.h:142:9`!) {
182 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(temp, sizeof(temp), ":%s %d '0:Emperor %s' %s %s %s", wolip, BNETD_WOLV2_PORTcxx . . $ BNETD_WOLV2_PORT., wolname, woltimezone, wollong, wollat);
183 irc_sendcxx . . $ pvpgn/bnetd/irc_send(2e21047ccae6acf).(conn, RPL_WOLSERVcxx . . $ `src/common/irc_protocol.h:358:9`!, temp);
184 }
185
186 // Only for CnC Renegade
187 if ((conn_get_clienttagcxx . . $ pvpgn/bnetd/conn_get_clienttag(8bd2285a65940781).(conn) == CLIENTTAG_RENEGADE_UINTcxx . . $ `/build/tmp.prHwK0hYwT/package/src/common/tag.h:136:9`!) || (conn_get_clienttagcxx . . $ pvpgn/bnetd/conn_get_clienttag(8bd2285a65940781).(conn) == CLIENTTAG_RENGDFDS_UINTcxx . . $ `/build/tmp.prHwK0hYwT/package/src/common/tag.h:138:9`!)) {
188 snprintf(temp, sizeof(temp), ":%s 0 'Ping server' %s %s %s", wolip, woltimezone, wollong, wollat);
189 irc_sendcxx . . $ pvpgn/bnetd/irc_send(2e21047ccae6acf).(conn, RPL_PINGSERVERcxx . . $ `src/common/irc_protocol.h:368:9`!, temp);
190 //I dont know for what is this server...? (used in renegade and yuri)
191 //snprintf(temp, sizeof(temp), ":%s 4321 'Port Mangler' %s %s %s", wolip, woltimezone, wollong, wollat);
192 //irc_send(conn,RPL_MANGLERSERV,temp);
193 // on official server list is for Renegade also this server:
194 //:noxchat1.wol.abn-sjc.ea.com 613 UserName :ea4.str.ea.com 0 '0,1,2,3,4,5,6,7,8,9,10:EA Ticket Server' -8 36.1083 -115.0582
195 }
196
197 // There are servers for anyone game
198 // FIXME: Check if is WOLv1 supported
199 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(temp, sizeof(temp), ":%s %d 'Live chat server' %s %s %s", wolip, BNETD_WOLV1_PORTcxx . . $ BNETD_WOLV1_PORT., woltimezone, wollong, wollat);
200 irc_sendcxx . . $ pvpgn/bnetd/irc_send(2e21047ccae6acf).(conn, RPL_WOLSERVcxx . . $ `src/common/irc_protocol.h:358:9`!, temp);
201 }
202
203 // If game is not allowed than we still send this servers
204 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(temp, sizeof(temp), ":%s %d 'Gameres server' %s %s %s", wolip, BNETD_WGAMERES_PORTcxx . . $ BNETD_WGAMERES_PORT., woltimezone, wollong, wollat);
205 irc_sendcxx . . $ pvpgn/bnetd/irc_send(2e21047ccae6acf).(conn, RPL_GAMERESSERVcxx . . $ `src/common/irc_protocol.h:361:9`!, temp);
206 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(temp, sizeof(temp), ":%s %d 'Ladder server' %s %s %s", wolip, BNETD_WOLV2_PORTcxx . . $ BNETD_WOLV2_PORT., woltimezone, wollong, wollat);
207 irc_sendcxx . . $ pvpgn/bnetd/irc_send(2e21047ccae6acf).(conn, RPL_LADDERSERVcxx . . $ `src/common/irc_protocol.h:362:9`!, temp);
208 // There is Word Domination Tour server for Firestorm (maybe for future coding)
209 //snprintf(temp, sizeof(temp), ":%s %d 'WDT server' %s %s %s", wolip, BNETD_WOLV2_PORT, woltimezone, wollong, wollat); //I dont know for what is this server...?
210 //irc_send(conn,RPL_WDTSERV,temp);
211
212 return 0;
213 }
214
215 static int _handle_quit_commandcxx . . $ pvpgn/bnetd/_handle_quit_command(93df5f0f7c1da4a4).(t_connectioncxx . . $ pvpgn/bnetd/t_connection# * conn, int numparams, char ** params, char * text)
216 {
217 irc_sendcxx . . $ pvpgn/bnetd/irc_send(2e21047ccae6acf).(conn, RPL_QUITcxx . . $ `src/common/irc_protocol.h:360:9`!, ":goodbye");
218 conn_set_statecxx . . $ pvpgn/bnetd/conn_set_state(7b556497952c81aa).(conn, conn_state_destroycxx . . $ pvpgn/bnetd/conn_state_destroy.);
219
220 return 0;
221 }
222
223 }
224
225 }