Debian Codegraph @

src/bnetd/anongame_wol.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2008 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 #define ANONGAME_WOL_INTERNAL_ACCESScxx . . $ `src/bnetd/anongame_wol.cpp:19:9`!
20 #include "common/setup_before.h"cxx . . $ `<file>/src/common/setup_before.h`/
21 #include "anongame_wol.h"cxx . . $ `<file>/src/bnetd/anongame_wol.h`/
22
23 #include <cstring>
24 #include <cctype>
25 #include <cstdlib>
26
27 #include "compat/strcasecmp.h"cxx . . $ `<file>/src/compat/strcasecmp.h`/
28
29 #include "common/irc_protocol.h"cxx . . $ `<file>/src/common/irc_protocol.h`/
30 #include "common/packet.h"cxx . . $ `<file>/src/common/packet.h`/
31 #include "common/eventlog.h"cxx . . $ `<file>/src/common/eventlog.h`/
32 #include "common/tag.h"cxx . . $ `<file>/src/common/tag.h`/
33 #include "common/list.h"cxx . . $ `<file>/src/common/list.h`/
34 #include "common/anongame_protocol.h"cxx . . $ `<file>/src/common/anongame_protocol.h`/
35
36 #include "irc.h"cxx . . $ `<file>/src/bnetd/irc.h`/
37 #include "handle_wol.h"cxx . . $ `<file>/src/bnetd/handle_wol.h`/
38 #include "connection.h"cxx . . $ `<file>/src/bnetd/connection.h`/
39 #include "channel.h"cxx . . $ `<file>/src/bnetd/channel.h`/
40 #include "anongame.h"cxx . . $ `<file>/src/bnetd/anongame.h`/
41 #include "common/setup_after.h"cxx . . $ `<file>/src/common/setup_after.h`/
42
43 namespace pvpgncxx . . $ pvpgn/
44 {
45
46 namespace bnetdcxx . . $ pvpgn/bnetd/
47 {
48
49 typedef int(*t_anong_tagcxx . . $ pvpgn/bnetd/t_anong_tag#)(t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# * player, char * param);
50
51 typedef structcxx . . $ pvpgn/bnetd/$anonymous_type_c48eb5ecdf398674_0# {
52 const char * wol_anong_tag_stringcxx . . $ pvpgn/bnetd/$anonymous_type_c48eb5ecdf398674_0#wol_anong_tag_string.;
53 t_anong_tagcxx . . $ pvpgn/bnetd/t_anong_tag# wol_anong_tag_handlercxx . . $ pvpgn/bnetd/$anonymous_type_c48eb5ecdf398674_0#wol_anong_tag_handler.;
54 } t_wol_anongame_tag_table_rowcxx . . $ pvpgn/bnetd/t_wol_anongame_tag_table_row#;
55
56 static t_listcxx . . $ pvpgn/t_list# * anongame_wol_matchlist_headcxx . . $ pvpgn/bnetd/anongame_wol_matchlist_head. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
57
58 static int _handle_address_tagcxx . . $ pvpgn/bnetd/_handle_address_tag(27d71860dddf548c).(t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# * player, char * param);
59 static int _handle_port_tagcxx . . $ pvpgn/bnetd/_handle_port_tag(27d71860dddf548c).(t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# * player, char * param);
60 static int _handle_country_tagcxx . . $ pvpgn/bnetd/_handle_country_tag(27d71860dddf548c).(t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# * player, char * param);
61 static int _handle_colour_tagcxx . . $ pvpgn/bnetd/_handle_colour_tag(27d71860dddf548c).(t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# * player, char * param);
62
63 static const t_wol_anongame_tag_table_rowcxx . . $ pvpgn/bnetd/t_wol_anongame_tag_table_row# t_wol_anongame_tag_tablecxx . . $ pvpgn/bnetd/t_wol_anongame_tag_table.[] =
64 {
65 { MATCHTAG_ADDRESScxx . . $ `src/bnetd/anongame_wol.h:30:9`!, _handle_address_tagcxx . . $ pvpgn/bnetd/_handle_address_tag(27d71860dddf548c). },
66 { MATCHTAG_PORTcxx . . $ `src/bnetd/anongame_wol.h:31:9`!, _handle_port_tagcxx . . $ pvpgn/bnetd/_handle_port_tag(27d71860dddf548c). },
67 { MATCHTAG_COUNTRYcxx . . $ `src/bnetd/anongame_wol.h:32:9`!, _handle_country_tagcxx . . $ pvpgn/bnetd/_handle_country_tag(27d71860dddf548c). },
68 { MATCHTAG_COLOURcxx . . $ `src/bnetd/anongame_wol.h:33:9`!, _handle_colour_tagcxx . . $ pvpgn/bnetd/_handle_colour_tag(27d71860dddf548c). },
69
70 { 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`! }
71 };
72
73 static int anongame_wol_set_playersettingcxx . . $ pvpgn/bnetd/anongame_wol_set_playersetting(9da82400726d1680).(t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# * player, char const * tag, char * param)
74 {
75 t_wol_anongame_tag_table_rowcxx . . $ pvpgn/bnetd/t_wol_anongame_tag_table_row# const *p;
76
77 for (p = t_wol_anongame_tag_tablecxx . . $ pvpgn/bnetd/t_wol_anongame_tag_table.; p->wol_anong_tag_stringcxx . . $ pvpgn/bnetd/$anonymous_type_c48eb5ecdf398674_0#wol_anong_tag_string. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; p++) {
78 if (strcasecmp(tag, p->wol_anong_tag_stringcxx . . $ pvpgn/bnetd/$anonymous_type_c48eb5ecdf398674_0#wol_anong_tag_string.) == 0) {
79 if (p->wol_anong_tag_handlercxx . . $ pvpgn/bnetd/$anonymous_type_c48eb5ecdf398674_0#wol_anong_tag_handler. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
80 return ((p->wol_anong_tag_handlercxx . . $ pvpgn/bnetd/$anonymous_type_c48eb5ecdf398674_0#wol_anong_tag_handler.)(player, param));
81 }
82 }
83 return -1;
84 }
85
86 /* anongame_wol player functions: */
87
88 static t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# * anongame_wol_player_createcxx . . $ pvpgn/bnetd/anongame_wol_player_create(52b288ba16d756a0).(t_connection * conn)
89 {
90 t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# * player;
91
92 player = (t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player#*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(sizeof(t_anongame_wol_player));
93
94 player->conncxx . . $ pvpgn/bnetd/anongame_wol_player#conn. = conn;
95
96 /* Used only in Red Alert 2 and Yuri's Revenge */
97 player->addresscxx . . $ pvpgn/bnetd/anongame_wol_player#address. = 0;
98 player->portcxx . . $ pvpgn/bnetd/anongame_wol_player#port. = 0;
99 player->countrycxx . . $ pvpgn/bnetd/anongame_wol_player#country. = -2; /* Default values are form packet dumps - not prefered country */
100 player->colourcxx . . $ pvpgn/bnetd/anongame_wol_player#colour. = -2; /* Default values are form packet dumps - not prefered colour */
101
102 conn_wol_set_anongame_playercxx . . $ pvpgn/bnetd/conn_wol_set_anongame_player(2bb94d995f9d33).(conn, player);
103
104 list_append_datacxx . . $ pvpgn/list_append_data(4e1348bd294d996f).(anongame_wol_matchlist_headcxx . . $ pvpgn/bnetd/anongame_wol_matchlist_head., player);
105
106 DEBUG1cxx . . $ `src/common/eventlog.h:89:9`!("[** WOL **] annongame player created: {}", conn_get_chatname(conn));
107
108 return player;
109 }
110
111 static int anongame_wol_player_destroycxx . . $ pvpgn/bnetd/anongame_wol_player_destroy(13f630afdf582a1a).(t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# * player, t_elemcxx . . $ pvpgn/t_elem# ** curr)
112 {
113 if (list_remove_datacxx . . $ pvpgn/list_remove_data(9d29d8ce7cabbadf).(anongame_wol_matchlist_headcxx . . $ pvpgn/bnetd/anongame_wol_matchlist_head., player, curr) < 0){
114 ERROR0cxx . . $ `src/common/eventlog.h:73:9`!("could not remove item from list");
115 return -1;
116 }
117
118 DEBUG0cxx . . $ `src/common/eventlog.h:88:9`!("[** WOL **] destroying annongame player");
119
120 xfreecxx . . $ `src/common/xalloc.h:51:9`!(player);
121
122 return 0;
123 }
124
125 static t_connection * anongame_wol_player_get_conncxx . . $ pvpgn/bnetd/anongame_wol_player_get_conn(c56e4e465c5cb86d).(t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# const * player)
126 {
127 if (!player) {
128 ERROR0cxx . . $ `src/common/eventlog.h:73:9`!("got NULL player");
129 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
130 }
131
132 return player->conncxx . . $ pvpgn/bnetd/anongame_wol_player#conn.;
133 }
134
135
136 static int anongame_wol_player_get_addresscxx . . $ pvpgn/bnetd/anongame_wol_player_get_address(d7a0fe1c039854fd).(t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# const * player)
137 {
138 if (!player) {
139 ERROR0cxx . . $ `src/common/eventlog.h:73:9`!("got NULL player");
140 return -1;
141 }
142
143 return player->addresscxx . . $ pvpgn/bnetd/anongame_wol_player#address.;
144 }
145
146 static int _handle_address_tagcxx . . $ pvpgn/bnetd/_handle_address_tag(27d71860dddf548c).(t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# * player, char * param)
147 {
148 if (!player) {
149 ERROR0cxx . . $ `src/common/eventlog.h:73:9`!("got NULL player");
150 return -1;
151 }
152
153 if (param)
154 player->addresscxx . . $ pvpgn/bnetd/anongame_wol_player#address. = stdcxx . . $ std/::atoi(param);
155
156 return 0;
157 }
158
159 static int anongame_wol_player_get_portcxx . . $ pvpgn/bnetd/anongame_wol_player_get_port(d7a0fe1c039854fd).(t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# const * player)
160 {
161 if (!player) {
162 ERROR0cxx . . $ `src/common/eventlog.h:73:9`!("got NULL player");
163 return -1;
164 }
165
166 return player->portcxx . . $ pvpgn/bnetd/anongame_wol_player#port.;
167 }
168
169 static int _handle_port_tagcxx . . $ pvpgn/bnetd/_handle_port_tag(27d71860dddf548c).(t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# * player, char * param)
170 {
171 if (!player) {
172 ERROR0cxx . . $ `src/common/eventlog.h:73:9`!("got NULL player");
173 return -1;
174 }
175
176 if (param)
177 player->portcxx . . $ pvpgn/bnetd/anongame_wol_player#port. = stdcxx . . $ std/::atoi(param);
178
179 return 0;
180 }
181
182 static int anongame_wol_player_get_countrycxx . . $ pvpgn/bnetd/anongame_wol_player_get_country(d7a0fe1c039854fd).(t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# const * player)
183 {
184 if (!player) {
185 ERROR0cxx . . $ `src/common/eventlog.h:73:9`!("got NULL player");
186 return -1;
187 }
188
189 return player->countrycxx . . $ pvpgn/bnetd/anongame_wol_player#country.;
190 }
191
192 static int _handle_country_tagcxx . . $ pvpgn/bnetd/_handle_country_tag(27d71860dddf548c).(t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# * player, char * param)
193 {
194 if (!player) {
195 ERROR0cxx . . $ `src/common/eventlog.h:73:9`!("got NULL player");
196 return -1;
197 }
198
199 if (param)
200 player->countrycxx . . $ pvpgn/bnetd/anongame_wol_player#country. = stdcxx . . $ std/::atoi(param);
201
202 return 0;
203 }
204
205 static int anongame_wol_player_get_colourcxx . . $ pvpgn/bnetd/anongame_wol_player_get_colour(d7a0fe1c039854fd).(t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# const * player)
206 {
207 if (!player) {
208 ERROR0cxx . . $ `src/common/eventlog.h:73:9`!("got NULL player");
209 return -1;
210 }
211
212 return player->colourcxx . . $ pvpgn/bnetd/anongame_wol_player#colour.;
213 }
214
215 static int _handle_colour_tagcxx . . $ pvpgn/bnetd/_handle_colour_tag(27d71860dddf548c).(t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# * player, char * param)
216 {
217 if (!player) {
218 ERROR0cxx . . $ `src/common/eventlog.h:73:9`!("got NULL player");
219 return -1;
220 }
221
222 if (param)
223 player->colourcxx . . $ pvpgn/bnetd/anongame_wol_player#colour. = stdcxx . . $ std/::atoi(param);
224
225 return 0;
226 }
227
228 /* Matchlist functions:*/
229
230 extern int anongame_wol_matchlist_createcxx . . $ pvpgn/bnetd/anongame_wol_matchlist_create(b126dc7c1de90089).(void)
231 {
232 anongame_wol_matchlist_headcxx . . $ pvpgn/bnetd/anongame_wol_matchlist_head. = list_createcxx . . $ pvpgn/list_create(7a6cb11de248e2c9).();
233
234 return 0;
235 }
236
237 extern int anongame_wol_matchlist_destroycxx . . $ pvpgn/bnetd/anongame_wol_matchlist_destroy(b126dc7c1de90089).(void)
238 {
239 t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# * player;
240 t_elemcxx . . $ pvpgn/t_elem# * curr;
241
242 if (anongame_wol_matchlist_headcxx . . $ pvpgn/bnetd/anongame_wol_matchlist_head.) {
243 LIST_TRAVERSEcxx . . $ `src/common/list.h:94:9`!(anongame_wol_matchlist_head, curr) {
244 if (!(player = (t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player#*)elem_get_datacxx . . $ pvpgn/elem_get_data(317ff0e7f02bf2b).(curr))) { /* should not happen */
245 ERROR0cxx . . $ `src/common/eventlog.h:73:9`!("wol_matchlist contains NULL item");
246 continue;
247 }
248 anongame_wol_player_destroycxx . . $ pvpgn/bnetd/anongame_wol_player_destroy(13f630afdf582a1a).(player, &curr);
249 }
250
251 if (list_destroycxx . . $ pvpgn/list_destroy(20db0232078327de).(anongame_wol_matchlist_headcxx . . $ pvpgn/bnetd/anongame_wol_matchlist_head.) < 0)
252 return -1;
253 anongame_wol_matchlist_headcxx . . $ pvpgn/bnetd/anongame_wol_matchlist_head. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
254 }
255
256 return 0;
257 }
258
259 extern t_listcxx . . $ pvpgn/t_list# * anongame_wol_matchlistcxx . . $ pvpgn/bnetd/anongame_wol_matchlist(7a6cb11de248e2c9).(void)
260 {
261 return anongame_wol_matchlist_headcxx . . $ pvpgn/bnetd/anongame_wol_matchlist_head.;
262 }
263
264 static t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# * anongame_wol_matchlist_find_player_by_conncxx . . $ pvpgn/bnetd/anongame_wol_matchlist_find_player_by_conn(52b288ba16d756a0).(t_connection * conn)
265 {
266 t_elemcxx . . $ pvpgn/t_elem# * curr;
267
268 if (!conn) {
269 ERROR0cxx . . $ `src/common/eventlog.h:73:9`!("got NULL conn");
270 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
271 }
272
273 LIST_TRAVERSEcxx . . $ `src/common/list.h:94:9`!(anongame_wol_matchlist(), curr) {
274 t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# * player = (t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# *)elem_get_datacxx . . $ pvpgn/elem_get_data(317ff0e7f02bf2b).(curr);
275 if (conn == anongame_wol_player_get_conncxx . . $ pvpgn/bnetd/anongame_wol_player_get_conn(c56e4e465c5cb86d).(player)) {
276 return player;
277 }
278 }
279
280 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
281 }
282
283 static int anongame_wol_matchlist_get_lengthcxx . . $ pvpgn/bnetd/anongame_wol_matchlist_get_length(b126dc7c1de90089).(void)
284 {
285 return list_get_lengthcxx . . $ pvpgn/list_get_length(ff288adc7992d0f0).(anongame_wol_matchlist_headcxx . . $ pvpgn/bnetd/anongame_wol_matchlist_head.);
286 }
287
288 /* support functions */
289
290 static int _send_msgcxx . . $ pvpgn/bnetd/_send_msg(973a17a902b892b0).(t_connection * conn, char const * command, char const * text)
291 {
292 if (!conn)
293 {
294 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL connection");
295 return -1;
296 }
297 if (!command)
298 {
299 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL command");
300 return -1;
301 }
302 if (!text)
303 {
304 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL text");
305 return -1;
306 }
307
308 t_packetcxx . . $ pvpgn/t_packet# * p = packet_createcxx . . $ pvpgn/packet_create(f721c565085e24c0).(packet_class_rawcxx . . $ pvpgn/packet_class_raw.);
309 if (!p)
310 {
311 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "could not create packet");
312 return -1;
313 }
314
315 const char *nick = conn_get_loggedusercxx . . $ pvpgn/bnetd/conn_get_loggeduser(c99dbccf638f5c6).(conn);
316 if (!nick)
317 nick = "UserName";
318
319 stdcxx . . $ std/::stringcxx . . $ std/string# data(":matchbot!u@h " +cxx . . $ std/operator+(39ed2c165380f78e). stdcxx . . $ std/::stringcxx . . $ std/string#(command) +cxx . . $ std/operator+(900ec9581c410ad9). " " +cxx . . $ std/operator+(aa1c00e85b87da6b). stdcxx . . $ std/::stringcxx . . $ std/string#(nick) +cxx . . $ std/operator+(900ec9581c410ad9). " " +cxx . . $ std/operator+(aa1c00e85b87da6b). stdcxx . . $ std/::stringcxx . . $ std/string#(text));
320 data.erasecxx . . $ std/__cxx11/basic_string#erase(710c914f019a9041).(MAX_IRC_MESSAGE_LENcxx . . $ MAX_IRC_MESSAGE_LEN., stdcxx . . $ std/::stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos.);
321
322 DEBUG2cxx . . $ `src/common/eventlog.h:90:9`!("[{}] sent \"{}\"", conn_get_socket(conn), data.c_str());
323 data.appendcxx . . $ std/__cxx11/basic_string#append(978ca1133b5f6e74).("\r\n");
324 packet_set_sizecxx . . $ pvpgn/packet_set_size(a12d8724e4c46208).(p, 0);
325 packet_append_datacxx . . $ pvpgn/packet_append_data(d82347a7305550af).(p, data.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), data.lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).());
326 conn_push_outqueuecxx . . $ pvpgn/bnetd/conn_push_outqueue(212cf84cd7032d49).(conn, p);
327 packet_del_refcxx . . $ pvpgn/packet_del_ref(d23439d9c1f63082).(p);
328 return 0;
329 }
330
331 static int _get_paircxx . . $ pvpgn/bnetd/_get_pair(ca86de63bc0fddf7).(int * i, int * j, int max, bool different)
332 {
333 max++; /* We want to use just real maximum number - no metter what function do */
334
335 if (*i == -2)
336 *i = (max * rand() / (RAND_MAXcxx . . $ `<external>/10696550936717951914/stdlib.h:87:9`! + 1));
337
338 if (*j == -2)
339 *j = (max * rand() / (RAND_MAXcxx . . $ `<external>/10696550936717951914/stdlib.h:87:9`! + 1));
340
341 if ((different) && (*i == *j)) {
342 do {
343 *j = (max * rand() / (RAND_MAXcxx . . $ `<external>/10696550936717951914/stdlib.h:87:9`! + 1));
344 } while (*i == *j);
345 }
346 return 0;
347 }
348
349
350 static int anongame_wol_trystartcxx . . $ pvpgn/bnetd/anongame_wol_trystart(d7a0fe1c039854fd).(t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# const * player1)
351 {
352 t_elemcxx . . $ pvpgn/t_elem# * curr;
353 char temp[MAX_IRC_MESSAGE_LENcxx . . $ MAX_IRC_MESSAGE_LEN.];
354 char _temp[MAX_IRC_MESSAGE_LENcxx . . $ MAX_IRC_MESSAGE_LEN.];
355 int random;
356
357 t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# * player2;
358 t_connection * conn_pl1;
359 t_connection * conn_pl2;
360 char const * channelname;
361 const char * mapname;
362 t_clienttagcxx . . $ pvpgn/t_clienttag# ctag;
363
364 stdcxx . . $ std/::memset(temp, 0, sizeof(temp));
365 stdcxx . . $ std/::memset(_temp, 0, sizeof(_temp));
366
367 /**
368 * Expected start message is
369 *
370 * Red Alert 2:
371 * :Start [rand_num],0,0,[credits],0,1,[super_weapon],1,1,0,1,x,2,1,[mapsize_kilobytes],[mapname],1:
372 * [nick1_name],[nick1_country],[nick1_colour],[nick1_addr_hex],[nick1_nat],[nick1_prt_hex],
373 * [nick2_name],[nick2_country],[nick2_colour],[nick2_addr_hex],[nick2_nat],[nick2_prt_hex]
374 *
375 * Yuris Revenge Quick game:
376 *
377 * Yuris Revenge Quick Coop:
378 *
379 */
380
381 if (!player1) {
382 ERROR0cxx . . $ `src/common/eventlog.h:73:9`!("got NULL player");
383 return -1;
384 }
385
386 conn_pl1 = anongame_wol_player_get_conncxx . . $ pvpgn/bnetd/anongame_wol_player_get_conn(c56e4e465c5cb86d).(player1);
387 ctag = conn_get_clienttagcxx . . $ pvpgn/bnetd/conn_get_clienttag(8bd2285a65940781).(conn_pl1);
388 channelname = channel_get_namecxx . . $ pvpgn/bnetd/channel_get_name(7800017c14723985).(conn_get_channelcxx . . $ pvpgn/bnetd/conn_get_channel(17dd609cd0747384).(conn_pl1));
389
390 LIST_TRAVERSEcxx . . $ `src/common/list.h:94:9`!(anongame_wol_matchlist(), curr) {
391 player2 = (t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# *)elem_get_datacxx . . $ pvpgn/elem_get_data(317ff0e7f02bf2b).(curr);
392 conn_pl2 = anongame_wol_player_get_conncxx . . $ pvpgn/bnetd/anongame_wol_player_get_conn(c56e4e465c5cb86d).(player2);
393
394 if ((player1 != player2) && ((conn_get_channelcxx . . $ pvpgn/bnetd/conn_get_channel(17dd609cd0747384).(conn_pl1)) == (conn_get_channelcxx . . $ pvpgn/bnetd/conn_get_channel(17dd609cd0747384).(conn_pl2)))) {
395 switch (ctag) {
396 case CLIENTTAG_REDALERT2_UINTcxx . . $ `/build/tmp.prHwK0hYwT/package/src/common/tag.h:128:9`!: {
397 random = rand();
398
399 if (stdcxx . . $ std/::strcmp(channelname, RAL2_CHANNEL_FFAcxx . . $ `src/bnetd/anongame_wol.h:38:9`!) == 0) {
400 int pl1_colour = anongame_wol_player_get_colourcxx . . $ pvpgn/bnetd/anongame_wol_player_get_colour(d7a0fe1c039854fd).(player1);
401 int pl1_country = anongame_wol_player_get_countrycxx . . $ pvpgn/bnetd/anongame_wol_player_get_country(d7a0fe1c039854fd).(player1);
402 int pl2_colour = anongame_wol_player_get_colourcxx . . $ pvpgn/bnetd/anongame_wol_player_get_colour(d7a0fe1c039854fd).(player2);
403 int pl2_country = anongame_wol_player_get_countrycxx . . $ pvpgn/bnetd/anongame_wol_player_get_country(d7a0fe1c039854fd).(player2);
404
405 DEBUG0cxx . . $ `src/common/eventlog.h:88:9`!("Generating SOLO game for Red Alert 2");
406
407 _get_paircxx . . $ pvpgn/bnetd/_get_pair(ca86de63bc0fddf7).(&pl1_colour, &pl2_colour, 7, true);
408 _get_paircxx . . $ pvpgn/bnetd/_get_pair(ca86de63bc0fddf7).(&pl1_country, &pl2_country, 8, false);
409 mapname = anongame_get_map_from_prefscxx . . $ pvpgn/bnetd/anongame_get_map_from_prefs(1663101b4c2f8326).(ANONGAME_TYPE_1V1cxx . . $ `src/common/anongame_protocol.h:448:9`!, ctag);
410
411 /* We have madatory of game */
412 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(_temp, sizeof(_temp), ":Start %d,0,0,10000,0,1,0,1,1,0,1,x,2,1,165368,%s,1:", random, mapname);
413 stdcxx . . $ std/::strcat(temp, _temp);
414
415 /* GameHost informations */
416 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(_temp, sizeof(_temp), "%s,%d,%d,%x,1,%x,", conn_get_chatnamecxx . . $ pvpgn/bnetd/conn_get_chatname(c99dbccf638f5c6).(conn_pl1), pl1_country, pl1_colour, anongame_wol_player_get_addresscxx . . $ pvpgn/bnetd/anongame_wol_player_get_address(d7a0fe1c039854fd).(player1), anongame_wol_player_get_portcxx . . $ pvpgn/bnetd/anongame_wol_player_get_port(d7a0fe1c039854fd).(player1));
417 stdcxx . . $ std/::strcat(temp, _temp);
418
419 /* GameJoinie informations */
420 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(_temp, sizeof(_temp), "%s,%d,%d,%x,1,%x", conn_get_chatnamecxx . . $ pvpgn/bnetd/conn_get_chatname(c99dbccf638f5c6).(conn_pl2), pl2_country, pl2_colour, anongame_wol_player_get_addresscxx . . $ pvpgn/bnetd/anongame_wol_player_get_address(d7a0fe1c039854fd).(player2), anongame_wol_player_get_portcxx . . $ pvpgn/bnetd/anongame_wol_player_get_port(d7a0fe1c039854fd).(player2));
421 stdcxx . . $ std/::strcat(temp, _temp);
422
423 _send_msgcxx . . $ pvpgn/bnetd/_send_msg(973a17a902b892b0).(conn_pl1, "PRIVMSG", temp);
424 _send_msgcxx . . $ pvpgn/bnetd/_send_msg(973a17a902b892b0).(conn_pl2, "PRIVMSG", temp);
425 }
426 else
427 ERROR1cxx . . $ `src/common/eventlog.h:74:9`!("undefined channel type for {} channel", channelname);
428 }
429 return 0;
430 case CLIENTTAG_YURISREV_UINTcxx . . $ `/build/tmp.prHwK0hYwT/package/src/common/tag.h:140:9`!: {
431 random = rand();
432
433 if (stdcxx . . $ std/::strcmp(channelname, YURI_CHANNEL_FFAcxx . . $ `src/bnetd/anongame_wol.h:39:9`!) == 0) {
434 int pl1_colour = anongame_wol_player_get_colourcxx . . $ pvpgn/bnetd/anongame_wol_player_get_colour(d7a0fe1c039854fd).(player1);
435 int pl1_country = anongame_wol_player_get_countrycxx . . $ pvpgn/bnetd/anongame_wol_player_get_country(d7a0fe1c039854fd).(player1);
436 int pl2_colour = anongame_wol_player_get_colourcxx . . $ pvpgn/bnetd/anongame_wol_player_get_colour(d7a0fe1c039854fd).(player2);
437 int pl2_country = anongame_wol_player_get_countrycxx . . $ pvpgn/bnetd/anongame_wol_player_get_country(d7a0fe1c039854fd).(player2);
438
439 DEBUG0cxx . . $ `src/common/eventlog.h:88:9`!("Generating SOLO game for Yuri's Revenge");
440
441 _get_paircxx . . $ pvpgn/bnetd/_get_pair(ca86de63bc0fddf7).(&pl1_colour, &pl2_colour, 7, true);
442 _get_paircxx . . $ pvpgn/bnetd/_get_pair(ca86de63bc0fddf7).(&pl1_country, &pl2_country, 9, false);
443 mapname = anongame_get_map_from_prefscxx . . $ pvpgn/bnetd/anongame_get_map_from_prefs(1663101b4c2f8326).(ANONGAME_TYPE_1V1cxx . . $ `src/common/anongame_protocol.h:448:9`!, ctag);
444
445 /* We have madatory of game */
446 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(_temp, sizeof(_temp), ":Start %d,0,0,10000,0,0,1,1,1,0,3,0,x,2,1,163770,%s,1:", random, mapname);
447 stdcxx . . $ std/::strcat(temp, _temp);
448
449 /* GameHost informations */
450 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(_temp, sizeof(_temp), "%s,%d,%d,-2,-2,", conn_get_chatnamecxx . . $ pvpgn/bnetd/conn_get_chatname(c99dbccf638f5c6).(conn_pl1), pl1_country, pl1_colour);
451 stdcxx . . $ std/::strcat(temp, _temp);
452 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(_temp, sizeof(_temp), "%x,1,%x,", anongame_wol_player_get_addresscxx . . $ pvpgn/bnetd/anongame_wol_player_get_address(d7a0fe1c039854fd).(player1), anongame_wol_player_get_portcxx . . $ pvpgn/bnetd/anongame_wol_player_get_port(d7a0fe1c039854fd).(player1));
453 stdcxx . . $ std/::strcat(temp, _temp);
454
455 /* GameJoinie informations */
456 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(_temp, sizeof(_temp), "%s,%d,%d,-2,-2,", conn_get_chatnamecxx . . $ pvpgn/bnetd/conn_get_chatname(c99dbccf638f5c6).(conn_pl2), pl2_country, pl2_colour);
457 stdcxx . . $ std/::strcat(temp, _temp);
458 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(_temp, sizeof(_temp), "%x,1,%x", anongame_wol_player_get_addresscxx . . $ pvpgn/bnetd/anongame_wol_player_get_address(d7a0fe1c039854fd).(player2), anongame_wol_player_get_portcxx . . $ pvpgn/bnetd/anongame_wol_player_get_port(d7a0fe1c039854fd).(player2));
459 stdcxx . . $ std/::strcat(temp, _temp);
460
461 _send_msgcxx . . $ pvpgn/bnetd/_send_msg(973a17a902b892b0).(conn_pl1, "PRIVMSG", temp);
462 _send_msgcxx . . $ pvpgn/bnetd/_send_msg(973a17a902b892b0).(conn_pl2, "PRIVMSG", temp);
463 }
464 else if (stdcxx . . $ std/::strcmp(channelname, YURI_CHANNEL_COOPcxx . . $ `src/bnetd/anongame_wol.h:40:9`!) == 0) {
465 DEBUG0cxx . . $ `src/common/eventlog.h:88:9`!("Generating COOP game for Yuri's Revenge");
466
467 /* We have madatory of game */
468 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(_temp, sizeof(_temp), ":Start %d,0,0,10000,10,0,1,1,0,1,3,0,x,2,1,163770,C1A01MD.MAP,1:", random);
469 stdcxx . . $ std/::strcat(temp, _temp);
470
471 /* GameHost informations */
472 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(_temp, sizeof(_temp), "%s,0,4,0,-2,", conn_get_chatnamecxx . . $ pvpgn/bnetd/conn_get_chatname(c99dbccf638f5c6).(conn_pl1));
473 stdcxx . . $ std/::strcat(temp, _temp);
474 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(_temp, sizeof(_temp), "%x,1,%x,", anongame_wol_player_get_addresscxx . . $ pvpgn/bnetd/anongame_wol_player_get_address(d7a0fe1c039854fd).(player1), anongame_wol_player_get_portcxx . . $ pvpgn/bnetd/anongame_wol_player_get_port(d7a0fe1c039854fd).(player1));
475 stdcxx . . $ std/::strcat(temp, _temp);
476
477 /* GameJoinie informations */
478 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(_temp, sizeof(_temp), "%s,0,5,1,-2,", conn_get_chatnamecxx . . $ pvpgn/bnetd/conn_get_chatname(c99dbccf638f5c6).(anongame_wol_player_get_conncxx . . $ pvpgn/bnetd/anongame_wol_player_get_conn(c56e4e465c5cb86d).(player2)));
479 stdcxx . . $ std/::strcat(temp, _temp);
480 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(_temp, sizeof(_temp), "%x,1,%x", anongame_wol_player_get_addresscxx . . $ pvpgn/bnetd/anongame_wol_player_get_address(d7a0fe1c039854fd).(player2), anongame_wol_player_get_portcxx . . $ pvpgn/bnetd/anongame_wol_player_get_port(d7a0fe1c039854fd).(player2));
481 stdcxx . . $ std/::strcat(temp, _temp);
482
483 /* Some computers for coop games */
484 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(_temp, sizeof(_temp), ":@:0,-1,-1,-2,-2,0,-1,-1,-2,-2,1,8,1,-2,-2,1,8,2,-2,-2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,");
485 stdcxx . . $ std/::strcat(temp, _temp);
486
487 _send_msgcxx . . $ pvpgn/bnetd/_send_msg(973a17a902b892b0).(conn_pl1, "PRIVMSG", temp);
488 _send_msgcxx . . $ pvpgn/bnetd/_send_msg(973a17a902b892b0).(conn_pl2, "PRIVMSG", temp);
489 }
490 else
491 ERROR1cxx . . $ `src/common/eventlog.h:74:9`!("undefined channel type for {} channel", channelname);
492 }
493 return 0;
494 default:
495 DEBUG0cxx . . $ `src/common/eventlog.h:88:9`!("unsupported client for WOL Matchgame");
496 return 0;
497 }
498 }
499 }
500
501 return 0;
502 }
503
504 static int anongame_wol_tokenize_linecxx . . $ pvpgn/bnetd/anongame_wol_tokenize_line(2e9022cda97b266d).(t_connection * conn, char const * text)
505 {
506 t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# * player;
507 char * command; /* Match, CINFO, SINFO, Pings */
508 char * tag; /* ADR, COL, COU... */
509 char * param; /* value of paramtag */
510 char * line; /* Copy of text */
511 char * temp;
512 char * p;
513
514 if (!conn) {
515 ERROR0cxx . . $ `src/common/eventlog.h:73:9`!("got NULL conn");
516 return -1;
517 }
518
519 if (!text) {
520 ERROR0cxx . . $ `src/common/eventlog.h:73:9`!("got NULL text");
521 return -1;
522 }
523
524 if (!(player = anongame_wol_player_createcxx . . $ pvpgn/bnetd/anongame_wol_player_create(52b288ba16d756a0).(conn))) {
525 ERROR0cxx . . $ `src/common/eventlog.h:73:9`!("player was not created");
526 return -1;
527 }
528
529 /**
530 * Here are expected privmsgs:
531 * :user!EMPR@host PRIVMSG matchbot :Match COU=-1,COL=-1,SHA=-1,SHB=-1,LOC=2,RAT=0
532 * :user!RAL2@host PRIVMSG matchbot :Match COU=-2, COL=-2, LOC=1, RAT=3, RES=640, ADR=202680512, NAT=1, PRT=1295
533 * :user!RAL2@host PRIVMSG matchbot :Match COU=-2, COL=-2, LOC=1, RAT=3, RES=640, ADR=202680512, NAT=1, PRT=1340
534 * :user!RAL2@host PRIVMSG matchbot :Match COU=-2, COL=-2, LOC=25, RAT=1, RES=640, ADR=-501962560, NAT=1, PRT=1320
535 * :user!YURI@host PRIVMSG matchbot :Match COU=-2, COL=-2, MBR=1, LOC=5, RAT=2, RES=800, ADR=202680512, NAT=1, PRT=1390
536 * :user!RNGD@host PRIVMSG matchbot :CINFO VER=1329937315 CPU=2981 MEM=1023 TPOINTS=0 PLAYED=0 PINGS=00FFFFFFFFFFFFFF
537 * :user!RNGD@host PRIVMSG matchbot :SINFO 4F453BA3DBAE41CB00000000000000002d# 9Dedicated Renegade Server-C&C_Field.mix07FF0656FFFF1C2D|090000000000
538 * :user!YURI@host PRIVMSG matchbot :Pings nickname,2;
539 */
540
541 line = (char *)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(std::strlen(text) + 2);
542 strcpy(line, text);
543
544 command = line;
545 if (!(temp = strchr(command, ' '))) {
546 WARN0cxx . . $ `src/common/eventlog.h:78:9`!("got malformed line (missing command)");
547 xfreecxx . . $ `src/common/xalloc.h:51:9`!(line);
548 return -1;
549 }
550 *temp++ = '\0';
551
552 if ((stdcxx . . $ std/::strcmp(command, "Match") == 0)) {
553 strcat(temp, ","); /* FIXME: This is DUMB - without that we lost the last tag/param */
554
555 for (p = temp; *p && (*p != '\0'); p++) {
556 if ((*p == ',') || (*p == ' ')) {
557 *p++ = '\0';
558 if (temp[0] == ' ') /* Pelish: Emperor sends line without spaces but RA2/Yuri do */
559 *temp++;
560 tag = temp;
561 param = strchr(tag, '=');
562 if (param)
563 *param++ = '\0';
564 if (anongame_wol_set_playersettingcxx . . $ pvpgn/bnetd/anongame_wol_set_playersetting(9da82400726d1680).(player, tag, param) == -1)
565 WARN2cxx . . $ `src/common/eventlog.h:80:9`!("[** WOL **] got unknown tag {} param {}", tag, param);
566 temp = p;
567 }
568 }
569 _send_msgcxx . . $ pvpgn/bnetd/_send_msg(973a17a902b892b0).(conn, "PRIVMSG", ":Working");
570 anongame_wol_trystartcxx . . $ pvpgn/bnetd/anongame_wol_trystart(d7a0fe1c039854fd).(player);
571 }
572 else {
573 DEBUG1cxx . . $ `src/common/eventlog.h:89:9`!("[** WOL **] got line /{}/", text);
574 }
575
576 if (line)
577 xfreecxx . . $ `src/common/xalloc.h:51:9`!(line);
578
579 return 0;
580 }
581
582 /* Functions for getting/sending player informations */
583
584 extern int anongame_wol_destroycxx . . $ pvpgn/bnetd/anongame_wol_destroy(c4dfbc2386fe4fc3).(t_connection * conn)
585 {
586 t_elemcxx . . $ pvpgn/t_elem# *curr;
587
588 /* Player destroying */
589
590 LIST_TRAVERSEcxx . . $ `src/common/list.h:94:9`!(anongame_wol_matchlist_head, curr) {
591 t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player# * player = (t_anongame_wol_playercxx . . $ pvpgn/bnetd/t_anongame_wol_player#*)elem_get_datacxx . . $ pvpgn/elem_get_data(317ff0e7f02bf2b).(curr);
592
593 if (conn == anongame_wol_player_get_conncxx . . $ pvpgn/bnetd/anongame_wol_player_get_conn(c56e4e465c5cb86d).(player))
594 anongame_wol_player_destroycxx . . $ pvpgn/bnetd/anongame_wol_player_destroy(13f630afdf582a1a).(player, &curr);
595 }
596
597 return 0;
598 }
599
600 extern int anongame_wol_privmsgcxx . . $ pvpgn/bnetd/anongame_wol_privmsg(93df5f0f7c1da4a4).(t_connection * conn, int numparams, char ** params, char * text)
601 {
602
603 if (!conn) {
604 ERROR0cxx . . $ `src/common/eventlog.h:73:9`!("got NULL conn");
605 return -1;
606 }
607
608 anongame_wol_tokenize_linecxx . . $ pvpgn/bnetd/anongame_wol_tokenize_line(2e9022cda97b266d).(conn, text);
609
610 return 0;
611 }
612
613 }
614
615 }