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"
22 #include "handle_wserv.h"
23
24 #include <cstring>
25 #include <cctype>
26 #include <cstdlib>
27
28 #include "compat/strcasecmp.h"
29 #include "common/irc_protocol.h"
30 #include "common/eventlog.h"
31 #include "common/tag.h"
32 #include "common/util.h"
33 #include "common/list.h"
34 #include "common/addr.h"
35 #include "common/trans.h"
36
37 #include "prefs.h"
38 #include "irc.h"
39 #include "message.h"
40 #include "tick.h"
41 #include "server.h"
42 #include "autoupdate.h"
43 #include "common/setup_after.h"
44
45 namespace pvpgn
46 {
47
48 namespace bnetd
49 {
50
51 typedef int(*t_wserv_command)(t_connection * conn, int numparams, char ** params, char * text);
52
53 typedef struct {
54 const char * wserv_command_string;
55 t_wserv_command wserv_command_handler;
56 } t_wserv_command_table_row;
57
58 static int _handle_verchk_command(t_connection * conn, int numparams, char ** params, char * text);
59 static int _handle_lobcount_command(t_connection * conn, int numparams, char ** params, char * text);
60 static int _handle_whereto_command(t_connection * conn, int numparams, char ** params, char * text);
61 static int _handle_quit_command(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_row wserv_con_command_table[] =
65 {
66 { "VERCHK", _handle_verchk_command },
67 { "LOBCOUNT", _handle_lobcount_command },
68 { "WHERETO", _handle_whereto_command },
69 { "QUIT", _handle_quit_command },
70
71 { NULL, NULL }
72 };
73
74 extern int handle_wserv_con_command(t_connection * conn, char const * command, int numparams, char ** params, char * text)
75 {
76 t_wserv_command_table_row const *p;
77
78 for (p = wserv_con_command_table; p->wserv_command_string != NULL; p++) {
79 if (strcasecmp(command, p->wserv_command_string) == 0) {
80 if (p->wserv_command_handler != NULL)
81 return ((p->wserv_command_handler)(conn, numparams, params, text));
82 }
83 }
84 return -1;
85 }
86
87 static int _handle_verchk_command(t_connection * conn, int numparams, char ** params, char * text)
88 {
89 char temp[MAX_IRC_MESSAGE_LEN];
90 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(std::atoi(params[0]));
109
110 if (clienttag != CLIENTTAG_WWOL_UINT)
111 conn_set_clienttag(conn, clienttag);
112
113 const char* const filestring = autoupdate_check(ARCHTAG_WINX86_UINT, clienttag, TAG_UNKNOWN_UINT, 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_serverhost();
118 ftpusername = prefs_get_wol_autoupdate_username();
119 ftppassword = prefs_get_wol_autoupdate_password();
120 std::snprintf(temp, sizeof(temp), ":%s %s %s %s 131075 %s REQ", ftphostname, ftpusername, ftppassword, filestring, params[0]);
121 irc_send(conn, RPL_UPDATE_FTP, temp);
122 xfree((void*)filestring);
123 }
124 else
125 {
126 irc_send(conn, RPL_UPDATE_NONEX, ":Update record non-existant");
127 }
128 }
129 else
130 irc_send(conn, ERR_NEEDMOREPARAMS, "VERCHK :Not enough parameters");
131 return 0;
132 }
133
134 static int _handle_lobcount_command(t_connection * conn, int numparams, char ** params, char * text)
135 {
136 /* Ignore command but, return 1 */
137 irc_send(conn, RPL_LOBCOUNT, "1");
138
139 return 0;
140 }
141
142 static int _handle_whereto_command(t_connection * conn, int numparams, char ** params, char * text)
143 {
144 char temp[MAX_IRC_MESSAGE_LEN];
145
146 /* Casted to avoid warnings */
147 const char * wolip;
148 const char * wolname = prefs_get_servername();
149 const char * woltimezone = prefs_get_wol_timezone();
150 const char * wollong = prefs_get_wol_longitude();
151 const char * wollat = prefs_get_wol_latitude();
152
153 { /* trans support */
154 unsigned short port = conn_get_real_local_port(conn);
155 unsigned int addr = conn_get_real_local_addr(conn);
156
157 trans_net(conn_get_addr(conn), &addr, &port);
158
159 wolip = addr_num_to_ip_str(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_clienttag(conn), prefs_get_allowed_clients())) {
166 // This is for anyone game but not for Emperor
167 if (conn_get_clienttag(conn) != CLIENTTAG_EMPERORBD_UINT) {
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 std::snprintf(temp, sizeof(temp), ":%s %d '0:%s' %s %s %s", wolip, BNETD_WOLV2_PORT, wolname, woltimezone, wollong, wollat);
177 irc_send(conn, RPL_WOLSERV, temp);
178 }
179
180 // Only for Emperor: Battle for Dune
181 if (conn_get_clienttag(conn) == CLIENTTAG_EMPERORBD_UINT) {
182 std::snprintf(temp, sizeof(temp), ":%s %d '0:Emperor %s' %s %s %s", wolip, BNETD_WOLV2_PORT, wolname, woltimezone, wollong, wollat);
183 irc_send(conn, RPL_WOLSERV, temp);
184 }
185
186 // Only for CnC Renegade
187 if ((conn_get_clienttag(conn) == CLIENTTAG_RENEGADE_UINT) || (conn_get_clienttag(conn) == CLIENTTAG_RENGDFDS_UINT)) {
188 snprintf(temp, sizeof(temp), ":%s 0 'Ping server' %s %s %s", wolip, woltimezone, wollong, wollat);
189 irc_send(conn, RPL_PINGSERVER, 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 std::snprintf(temp, sizeof(temp), ":%s %d 'Live chat server' %s %s %s", wolip, BNETD_WOLV1_PORT, woltimezone, wollong, wollat);
200 irc_send(conn, RPL_WOLSERV, temp);
201 }
202
203 // If game is not allowed than we still send this servers
204 std::snprintf(temp, sizeof(temp), ":%s %d 'Gameres server' %s %s %s", wolip, BNETD_WGAMERES_PORT, woltimezone, wollong, wollat);
205 irc_send(conn, RPL_GAMERESSERV, temp);
206 std::snprintf(temp, sizeof(temp), ":%s %d 'Ladder server' %s %s %s", wolip, BNETD_WOLV2_PORT, woltimezone, wollong, wollat);
207 irc_send(conn, RPL_LADDERSERV, 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_command(t_connection * conn, int numparams, char ** params, char * text)
216 {
217 irc_send(conn, RPL_QUIT, ":goodbye");
218 conn_set_state(conn, conn_state_destroy);
219
220 return 0;
221 }
222
223 }
224
225 }