| 1 | /* |
| 2 | * Copyright (C) 1998 Mark Baysinger ([email protected]) |
| 3 | * Copyright (C) 1998,1999,2000,2001 Ross Combs ([email protected]) |
| 4 | * Copyright (C) 1999 Gediminas ([email protected]) |
| 5 | * Copyright (C) 1999 Rob Crittenden ([email protected]) |
| 6 | * Copyright (C) 2000,2001 Marco Ziech ([email protected]) |
| 7 | * Copyright (C) 2000 Dizzy |
| 8 | * Copyright (C) 2000 Onlyer ([email protected]) |
| 9 | * Copyright (C) 2003,2004 Aaron |
| 10 | * Copyright (C) 2004 Donny Redmond ([email protected]) |
| 11 | * Copyright (C) 2008 Pelish ([email protected]) |
| 12 | * Copyright (C) 2014 HarpyWar ([email protected]) |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or |
| 15 | * modify it under the terms of the GNU General Public License |
| 16 | * as published by the Free Software Foundation; either version 2 |
| 17 | * of the License, or (at your option) any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, write to the Free Software |
| 26 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 27 | */ |
| 28 | #include "common/setup_before.h" |
| 29 | #include "command.h" |
| 30 | |
| 31 | #include <algorithm> |
| 32 | #include <cctype> |
| 33 | #include <cerrno> |
| 34 | #include <cstring> |
| 35 | #include <cstdlib> |
| 36 | #include <iostream> |
| 37 | #include <string> |
| 38 | |
| 39 | #include "compat/strcasecmp.h" |
| 40 | #include "common/tag.h" |
| 41 | #include "common/util.h" |
| 42 | #include "common/version.h" |
| 43 | #include "common/eventlog.h" |
| 44 | #include "common/bnettime.h" |
| 45 | #include "common/addr.h" |
| 46 | #include "common/packet.h" |
| 47 | #include "common/bnethash.h" |
| 48 | #include "common/list.h" |
| 49 | #include "common/proginfo.h" |
| 50 | #include "common/queue.h" |
| 51 | #include "common/bn_type.h" |
| 52 | #include "common/xalloc.h" |
| 53 | #include "common/xstr.h" |
| 54 | #include "common/trans.h" |
| 55 | #include "common/lstr.h" |
| 56 | #include "common/hashtable.h" |
| 57 | #include "common/xstring.h" |
| 58 | |
| 59 | #include "connection.h" |
| 60 | #include "message.h" |
| 61 | #include "channel.h" |
| 62 | #include "game.h" |
| 63 | #include "team.h" |
| 64 | #include "account.h" |
| 65 | #include "account_wrap.h" |
| 66 | #include "server.h" |
| 67 | #include "prefs.h" |
| 68 | #include "ladder.h" |
| 69 | #include "timer.h" |
| 70 | #include "helpfile.h" |
| 71 | #include "mail.h" |
| 72 | #include "runprog.h" |
| 73 | #include "alias_command.h" |
| 74 | #include "realm.h" |
| 75 | #include "ipban.h" |
| 76 | #include "command_groups.h" |
| 77 | #include "news.h" |
| 78 | #include "topic.h" |
| 79 | #include "friends.h" |
| 80 | #include "clan.h" |
| 81 | #include "common/flags.h" |
| 82 | #include "icons.h" |
| 83 | #include "userlog.h" |
| 84 | #include "i18n.h" |
| 85 | |
| 86 | #include "attrlayer.h" |
| 87 | |
| 88 | #ifdef WITH_LUA |
| 89 | #include "luainterface.h" |
| 90 | #endif |
| 91 | #include "common/setup_after.h" |
| 92 | |
| 93 | namespace pvpgn |
| 94 | { |
| 95 | |
| 96 | namespace bnetd |
| 97 | { |
| 98 | static char const * bnclass_get_str(unsigned int cclass); |
| 99 | static void do_whisper(t_connection * user_c, char const * dest, char const * text); |
| 100 | static void do_whois(t_connection * c, char const * dest); |
| 101 | static void user_timer_cb(t_connection * c, std::time_t now, t_timer_data str); |
| 102 | |
| 103 | std::string msgtemp, msgtemp2; |
| 104 | char msgtemp0[MAX_MESSAGE_LEN]; |
| 105 | |
| 106 | |
| 107 | static char const * bnclass_get_str(unsigned int cclass) |
| 108 | { |
| 109 | switch (cclass) |
| 110 | { |
| 111 | case PLAYERINFO_DRTL_CLASS_WARRIOR: |
| 112 | return "warrior"; |
| 113 | case PLAYERINFO_DRTL_CLASS_ROGUE: |
| 114 | return "rogue"; |
| 115 | case PLAYERINFO_DRTL_CLASS_SORCERER: |
| 116 | return "sorcerer"; |
| 117 | default: |
| 118 | return "unknown"; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | /* |
| 123 | * Split text by spaces and return array of arguments. |
| 124 | * First text argument is a command name (index = 0) |
| 125 | * Last text argument always reads to end |
| 126 | */ |
| 127 | extern std::vector<std::string> split_command(char const * text, int args_count) |
| 128 | { |
| 129 | std::vector<std::string> result(args_count + 1); |
| 130 | |
| 131 | std::string s(text); |
| 132 | // remove slash from the command |
| 133 | if (!s.empty()) |
| 134 | s.erase(0, 1); |
| 135 | |
| 136 | std::istringstream iss(s); |
| 137 | |
| 138 | int i = 0; |
| 139 | std::string tmp = std::string(); // to end |
| 140 | do |
| 141 | { |
| 142 | std::string sub; |
| 143 | iss >> sub; |
| 144 | |
| 145 | if (sub.empty()) |
| 146 | continue; |
| 147 | |
| 148 | if (i < args_count) |
| 149 | { |
| 150 | result[i] = sub; |
| 151 | i++; |
| 152 | } |
| 153 | else |
| 154 | { |
| 155 | if (!tmp.empty()) |
| 156 | tmp += " "; |
| 157 | tmp += sub; |
| 158 | } |
| 159 | |
| 160 | } while (iss); |
| 161 | |
| 162 | // push remaining text at the end |
| 163 | if (tmp.length() > 0) |
| 164 | result[args_count] = tmp; |
| 165 | |
| 166 | return result; |
| 167 | } |
| 168 | std::string msgt; |
| 169 | static void do_whisper(t_connection * user_c, char const * dest, char const * text) |
| 170 | { |
| 171 | t_connection * dest_c; |
| 172 | char const * tname; |
| 173 | |
| 174 | if (account_get_auth_mute(conn_get_account(user_c)) == 1) |
| 175 | { |
| 176 | message_send_text(user_c, message_type_error, user_c, localize(user_c, "Your account has been muted, you can't whisper to other users.")); |
| 177 | return; |
| 178 | } |
| 179 | |
| 180 | if (!(dest_c = connlist_find_connection_by_name(dest, conn_get_realm(user_c)))) |
| 181 | { |
| 182 | message_send_text(user_c, message_type_error, user_c, localize(user_c, "That user is not logged on.")); |
| 183 | return; |
| 184 | } |
| 185 | |
| 186 | |
| 187 | #ifdef WITH_LUA |
| 188 | if (lua_handle_user(user_c, dest_c, text, luaevent_user_whisper) == 1) |
| 189 | return; |
| 190 | #endif |
| 191 | |
| 192 | if (conn_get_dndstr(dest_c)) |
| 193 | { |
| 194 | msgtemp = localize(user_c, "{} is unavailable ({})", conn_get_username(dest_c), conn_get_dndstr(dest_c)); |
| 195 | message_send_text(user_c, message_type_info, user_c, msgtemp); |
| 196 | return; |
| 197 | } |
| 198 | |
| 199 | message_send_text(user_c, message_type_whisperack, dest_c, text); |
| 200 | |
| 201 | if (conn_get_awaystr(dest_c)) |
| 202 | { |
| 203 | msgtemp = localize(user_c, "{} is away ({})", conn_get_username(dest_c), conn_get_awaystr(dest_c)); |
| 204 | message_send_text(user_c, message_type_info, user_c, msgtemp); |
| 205 | } |
| 206 | |
| 207 | message_send_text(dest_c, message_type_whisper, user_c, text); |
| 208 | |
| 209 | if ((tname = conn_get_username(user_c))) |
| 210 | { |
| 211 | char username[1 + MAX_USERNAME_LEN]; /* '*' + username (including NUL) */ |
| 212 | |
| 213 | if (std::strlen(tname) < MAX_USERNAME_LEN) |
| 214 | { |
| 215 | std::sprintf(username, "*%s", tname); |
| 216 | conn_set_lastsender(dest_c, username); |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | |
| 222 | static void do_whois(t_connection * c, char const * dest) |
| 223 | { |
| 224 | t_connection * dest_c; |
| 225 | std::string namepart, verb; /* 64 + " (" + 64 + ")" + NUL */ |
| 226 | t_game const * game; |
| 227 | t_channel const * channel; |
| 228 | |
| 229 | if ((!(dest_c = connlist_find_connection_by_accountname(dest))) && |
| 230 | (!(dest_c = connlist_find_connection_by_name(dest, conn_get_realm(c))))) |
| 231 | { |
| 232 | t_account * dest_a; |
| 233 | t_bnettime btlogin; |
| 234 | std::time_t ulogin; |
| 235 | struct std::tm * tmlogin; |
| 236 | |
| 237 | if (!(dest_a = accountlist_find_account(dest))) { |
| 238 | message_send_text(c, message_type_error, c, localize(c, "Unknown user.")); |
| 239 | return; |
| 240 | } |
| 241 | |
| 242 | if (conn_get_class(c) == conn_class_bnet) { |
| 243 | btlogin = time_to_bnettime((std::time_t)account_get_ll_time(dest_a), 0); |
| 244 | btlogin = bnettime_add_tzbias(btlogin, conn_get_tzbias(c)); |
| 245 | ulogin = bnettime_to_time(btlogin); |
| 246 | if (!(tmlogin = std::gmtime(&ulogin))) |
| 247 | std::strcpy(msgtemp0, "?"); |
| 248 | else |
| 249 | std::strftime(msgtemp0, sizeof(msgtemp0), "%a %b %d %H:%M:%S", tmlogin); |
| 250 | msgtemp = localize(c, "User was last seen on: {}", msgtemp0); |
| 251 | } |
| 252 | else |
| 253 | msgtemp = localize(c, "User is offline"); |
| 254 | message_send_text(c, message_type_info, c, msgtemp); |
| 255 | return; |
| 256 | } |
| 257 | |
| 258 | if (c == dest_c) |
| 259 | { |
| 260 | namepart = localize(c, "You"); |
| 261 | verb = localize(c, "are"); |
| 262 | } |
| 263 | else |
| 264 | { |
| 265 | char const * tname; |
| 266 | |
| 267 | namepart = (tname = conn_get_chatcharname(dest_c, c)); |
| 268 | conn_unget_chatcharname(dest_c, tname); |
| 269 | verb = localize(c, "is"); |
| 270 | } |
| 271 | |
| 272 | if ((game = conn_get_game(dest_c))) |
| 273 | { |
| 274 | msgtemp = localize(c, "{} {} using {} and {} currently in {} game \"{}\".", |
| 275 | namepart, |
| 276 | verb, |
| 277 | clienttag_get_title(conn_get_clienttag(dest_c)), |
| 278 | verb, |
| 279 | game_get_flag(game) == game_flag_private ? localize(c, "private") : "", |
| 280 | game_get_name(game)); |
| 281 | } |
| 282 | else if ((channel = conn_get_channel(dest_c))) |
| 283 | { |
| 284 | msgtemp = localize(c, "{} {} using {} and {} currently in channel \"{}\".", |
| 285 | namepart, |
| 286 | verb, |
| 287 | clienttag_get_title(conn_get_clienttag(dest_c)), |
| 288 | verb, |
| 289 | channel_get_name(channel)); |
| 290 | } |
| 291 | else |
| 292 | msgtemp = localize(c, "{} {} using {}.", |
| 293 | namepart, |
| 294 | verb, |
| 295 | clienttag_get_title(conn_get_clienttag(dest_c))); |
| 296 | message_send_text(c, message_type_info, c, msgtemp); |
| 297 | |
| 298 | if (conn_get_dndstr(dest_c)) |
| 299 | { |
| 300 | msgtemp = localize(c, "{} {} refusing messages ({})", |
| 301 | namepart, |
| 302 | verb, |
| 303 | conn_get_dndstr(dest_c)); |
| 304 | message_send_text(c, message_type_info, c, msgtemp); |
| 305 | } |
| 306 | else |
| 307 | if (conn_get_awaystr(dest_c)) |
| 308 | { |
| 309 | msgtemp = localize(c, "{} away ({})", |
| 310 | namepart, |
| 311 | conn_get_awaystr(dest_c)); |
| 312 | message_send_text(c, message_type_info, c, msgtemp); |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | |
| 317 | static void user_timer_cb(t_connection * c, std::time_t now, t_timer_data str) |
| 318 | { |
| 319 | if (!c) |
| 320 | { |
| 321 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL connection"); |
| 322 | return; |
| 323 | } |
| 324 | if (!str.p) |
| 325 | { |
| 326 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL str"); |
| 327 | return; |
| 328 | } |
| 329 | |
| 330 | if (now != (std::time_t)0) /* zero means user logged out before expiration */ |
| 331 | message_send_text(c, message_type_info, c, (char*)str.p); |
| 332 | xfree(str.p); |
| 333 | } |
| 334 | |
| 335 | typedef int(*t_command)(t_connection * c, char const * text); |
| 336 | |
| 337 | typedef struct { |
| 338 | const char * command_string; |
| 339 | t_command command_handler; |
| 340 | } t_command_table_row; |
| 341 | |
| 342 | static int command_set_flags(t_connection * c); // [Omega] |
| 343 | // command handler prototypes |
| 344 | static int _handle_clan_command(t_connection * c, char const * text); |
| 345 | static int _handle_admin_command(t_connection * c, char const * text); |
| 346 | static int _handle_aop_command(t_connection * c, char const * text); |
| 347 | static int _handle_op_command(t_connection * c, char const * text); |
| 348 | static int _handle_tmpop_command(t_connection * c, char const * text); |
| 349 | static int _handle_deop_command(t_connection * c, char const * text); |
| 350 | static int _handle_voice_command(t_connection * c, char const * text); |
| 351 | static int _handle_devoice_command(t_connection * c, char const * text); |
| 352 | static int _handle_vop_command(t_connection * c, char const * text); |
| 353 | static int _handle_friends_command(t_connection * c, char const * text); |
| 354 | static int _handle_me_command(t_connection * c, char const * text); |
| 355 | static int _handle_whisper_command(t_connection * c, char const * text); |
| 356 | static int _handle_status_command(t_connection * c, char const * text); |
| 357 | static int _handle_who_command(t_connection * c, char const * text); |
| 358 | static int _handle_whois_command(t_connection * c, char const * text); |
| 359 | static int _handle_whoami_command(t_connection * c, char const * text); |
| 360 | static int _handle_announce_command(t_connection * c, char const * text); |
| 361 | static int _handle_beep_command(t_connection * c, char const * text); |
| 362 | static int _handle_nobeep_command(t_connection * c, char const * text); |
| 363 | static int _handle_version_command(t_connection * c, char const * text); |
| 364 | static int _handle_copyright_command(t_connection * c, char const * text); |
| 365 | static int _handle_uptime_command(t_connection * c, char const * text); |
| 366 | static int _handle_stats_command(t_connection * c, char const * text); |
| 367 | static int _handle_time_command(t_connection * c, char const * text); |
| 368 | static int _handle_channel_command(t_connection * c, char const * text); |
| 369 | static int _handle_rejoin_command(t_connection * c, char const * text); |
| 370 | static int _handle_away_command(t_connection * c, char const * text); |
| 371 | static int _handle_dnd_command(t_connection * c, char const * text); |
| 372 | static int _handle_squelch_command(t_connection * c, char const * text); |
| 373 | static int _handle_unsquelch_command(t_connection * c, char const * text); |
| 374 | static int _handle_kick_command(t_connection * c, char const * text); |
| 375 | static int _handle_ban_command(t_connection * c, char const * text); |
| 376 | static int _handle_unban_command(t_connection * c, char const * text); |
| 377 | static int _handle_reply_command(t_connection * c, char const * text); |
| 378 | static int _handle_realmann_command(t_connection * c, char const * text); |
| 379 | static int _handle_watch_command(t_connection * c, char const * text); |
| 380 | static int _handle_unwatch_command(t_connection * c, char const * text); |
| 381 | static int _handle_watchall_command(t_connection * c, char const * text); |
| 382 | static int _handle_unwatchall_command(t_connection * c, char const * text); |
| 383 | static int _handle_lusers_command(t_connection * c, char const * text); |
| 384 | static int _handle_news_command(t_connection * c, char const * text); |
| 385 | static int _handle_games_command(t_connection * c, char const * text); |
| 386 | static int _handle_channels_command(t_connection * c, char const * text); |
| 387 | static int _handle_addacct_command(t_connection * c, char const * text); |
| 388 | static int _handle_chpass_command(t_connection * c, char const * text); |
| 389 | static int _handle_connections_command(t_connection * c, char const * text); |
| 390 | static int _handle_finger_command(t_connection * c, char const * text); |
| 391 | static int _handle_operator_command(t_connection * c, char const * text); |
| 392 | static int _handle_admins_command(t_connection * c, char const * text); |
| 393 | static int _handle_quit_command(t_connection * c, char const * text); |
| 394 | static int _handle_kill_command(t_connection * c, char const * text); |
| 395 | static int _handle_killsession_command(t_connection * c, char const * text); |
| 396 | static int _handle_gameinfo_command(t_connection * c, char const * text); |
| 397 | static int _handle_ladderactivate_command(t_connection * c, char const * text); |
| 398 | static int _handle_rehash_command(t_connection * c, char const * text); |
| 399 | static int _handle_find_command(t_connection * c, char const *text); |
| 400 | static int _handle_save_command(t_connection * c, char const * text); |
| 401 | |
| 402 | static int _handle_shutdown_command(t_connection * c, char const * text); |
| 403 | static int _handle_ladderinfo_command(t_connection * c, char const * text); |
| 404 | static int _handle_timer_command(t_connection * c, char const * text); |
| 405 | static int _handle_serverban_command(t_connection * c, char const * text); |
| 406 | static int _handle_netinfo_command(t_connection * c, char const * text); |
| 407 | static int _handle_quota_command(t_connection * c, char const * text); |
| 408 | static int _handle_lockacct_command(t_connection * c, char const * text); |
| 409 | static int _handle_unlockacct_command(t_connection * c, char const * text); |
| 410 | static int _handle_muteacct_command(t_connection * c, char const * text); |
| 411 | static int _handle_unmuteacct_command(t_connection * c, char const * text); |
| 412 | static int _handle_flag_command(t_connection * c, char const * text); |
| 413 | static int _handle_tag_command(t_connection * c, char const * text); |
| 414 | static int _handle_ipscan_command(t_connection * c, char const * text); |
| 415 | static int _handle_set_command(t_connection * c, char const * text); |
| 416 | static int _handle_motd_command(t_connection * c, char const * text); |
| 417 | static int _handle_ping_command(t_connection * c, char const * text); |
| 418 | static int _handle_commandgroups_command(t_connection * c, char const * text); |
| 419 | static int _handle_topic_command(t_connection * c, char const * text); |
| 420 | static int _handle_moderate_command(t_connection * c, char const * text); |
| 421 | static int _handle_clearstats_command(t_connection * c, char const * text); |
| 422 | static int _handle_tos_command(t_connection * c, char const * text); |
| 423 | static int _handle_alert_command(t_connection * c, char const * text); |
| 424 | |
| 425 | static const t_command_table_row standard_command_table[] = |
| 426 | { |
| 427 | { "/clan", _handle_clan_command }, |
| 428 | { "/c", _handle_clan_command }, |
| 429 | { "/admin", _handle_admin_command }, |
| 430 | { "/f", _handle_friends_command }, |
| 431 | { "/friends", _handle_friends_command }, |
| 432 | { "/me", _handle_me_command }, |
| 433 | { "/emote", _handle_me_command }, |
| 434 | { "/msg", _handle_whisper_command }, |
| 435 | { "/whisper", _handle_whisper_command }, |
| 436 | { "/w", _handle_whisper_command }, |
| 437 | { "/m", _handle_whisper_command }, |
| 438 | { "/status", _handle_status_command }, |
| 439 | { "/users", _handle_status_command }, |
| 440 | { "/who", _handle_who_command }, |
| 441 | { "/whois", _handle_whois_command }, |
| 442 | { "/whereis", _handle_whois_command }, |
| 443 | { "/where", _handle_whois_command }, |
| 444 | { "/whoami", _handle_whoami_command }, |
| 445 | { "/announce", _handle_announce_command }, |
| 446 | { "/beep", _handle_beep_command }, |
| 447 | { "/nobeep", _handle_nobeep_command }, |
| 448 | { "/version", _handle_version_command }, |
| 449 | { "/copyright", _handle_copyright_command }, |
| 450 | { "/warranty", _handle_copyright_command }, |
| 451 | { "/license", _handle_copyright_command }, |
| 452 | { "/uptime", _handle_uptime_command }, |
| 453 | { "/stats", _handle_stats_command }, |
| 454 | { "/astat", _handle_stats_command }, |
| 455 | { "/time", _handle_time_command }, |
| 456 | { "/channel", _handle_channel_command }, |
| 457 | { "/join", _handle_channel_command }, |
| 458 | { "/j", _handle_channel_command }, |
| 459 | { "/rejoin", _handle_rejoin_command }, |
| 460 | { "/away", _handle_away_command }, |
| 461 | { "/dnd", _handle_dnd_command }, |
| 462 | { "/ignore", _handle_squelch_command }, |
| 463 | { "/squelch", _handle_squelch_command }, |
| 464 | { "/unignore", _handle_unsquelch_command }, |
| 465 | { "/unsquelch", _handle_unsquelch_command }, |
| 466 | { "/kick", _handle_kick_command }, |
| 467 | { "/ban", _handle_ban_command }, |
| 468 | { "/unban", _handle_unban_command }, |
| 469 | { "/tos", _handle_tos_command }, |
| 470 | |
| 471 | { "/ann", _handle_announce_command }, |
| 472 | { "/r", _handle_reply_command }, |
| 473 | { "/reply", _handle_reply_command }, |
| 474 | { "/realmann", _handle_realmann_command }, |
| 475 | { "/watch", _handle_watch_command }, |
| 476 | { "/unwatch", _handle_unwatch_command }, |
| 477 | { "/watchall", _handle_watchall_command }, |
| 478 | { "/unwatchall", _handle_unwatchall_command }, |
| 479 | { "/lusers", _handle_lusers_command }, |
| 480 | { "/news", _handle_news_command }, |
| 481 | { "/games", _handle_games_command }, |
| 482 | { "/channels", _handle_channels_command }, |
| 483 | { "/chs", _handle_channels_command }, |
| 484 | { "/addacct", _handle_addacct_command }, |
| 485 | { "/chpass", _handle_chpass_command }, |
| 486 | { "/connections", _handle_connections_command }, |
| 487 | { "/con", _handle_connections_command }, |
| 488 | { "/finger", _handle_finger_command }, |
| 489 | { "/operator", _handle_operator_command }, |
| 490 | { "/aop", _handle_aop_command }, |
| 491 | { "/op", _handle_op_command }, |
| 492 | { "/tmpop", _handle_tmpop_command }, |
| 493 | { "/deop", _handle_deop_command }, |
| 494 | { "/voice", _handle_voice_command }, |
| 495 | { "/devoice", _handle_devoice_command }, |
| 496 | { "/vop", _handle_vop_command }, |
| 497 | { "/admins", _handle_admins_command }, |
| 498 | { "/logout", _handle_quit_command }, |
| 499 | { "/quit", _handle_quit_command }, |
| 500 | { "/exit", _handle_quit_command }, |
| 501 | { "/kill", _handle_kill_command }, |
| 502 | { "/killsession", _handle_killsession_command }, |
| 503 | { "/gameinfo", _handle_gameinfo_command }, |
| 504 | { "/ladderactivate", _handle_ladderactivate_command }, |
| 505 | { "/rehash", _handle_rehash_command }, |
| 506 | { "/find", _handle_find_command }, |
| 507 | { "/save", _handle_save_command }, |
| 508 | { "/shutdown", _handle_shutdown_command }, |
| 509 | { "/ladderinfo", _handle_ladderinfo_command }, |
| 510 | { "/timer", _handle_timer_command }, |
| 511 | { "/serverban", _handle_serverban_command }, |
| 512 | { "/netinfo", _handle_netinfo_command }, |
| 513 | { "/quota", _handle_quota_command }, |
| 514 | { "/lockacct", _handle_lockacct_command }, |
| 515 | { "/lock", _handle_lockacct_command }, |
| 516 | { "/unlockacct", _handle_unlockacct_command }, |
| 517 | { "/unlock", _handle_unlockacct_command }, |
| 518 | { "/muteacct", _handle_muteacct_command }, |
| 519 | { "/mute", _handle_muteacct_command }, |
| 520 | { "/unmuteacct", _handle_unmuteacct_command }, |
| 521 | { "/unmute", _handle_unmuteacct_command }, |
| 522 | { "/flag", _handle_flag_command }, |
| 523 | { "/tag", _handle_tag_command }, |
| 524 | { "/help", handle_help_command }, |
| 525 | { "/?", handle_help_command }, |
| 526 | { "/mail", handle_mail_command }, |
| 527 | { "/ipban", handle_ipban_command }, // in ipban.c |
| 528 | { "/ipscan", _handle_ipscan_command }, |
| 529 | { "/set", _handle_set_command }, |
| 530 | { "/motd", _handle_motd_command }, |
| 531 | { "/latency", _handle_ping_command }, |
| 532 | { "/ping", _handle_ping_command }, |
| 533 | { "/p", _handle_ping_command }, |
| 534 | { "/commandgroups", _handle_commandgroups_command }, |
| 535 | { "/cg", _handle_commandgroups_command }, |
| 536 | { "/topic", _handle_topic_command }, |
| 537 | { "/moderate", _handle_moderate_command }, |
| 538 | { "/clearstats", _handle_clearstats_command }, |
| 539 | { "/icon", handle_icon_command }, |
| 540 | { "/alert", _handle_alert_command }, |
| 541 | { "/language", handle_language_command }, |
| 542 | { "/lang", handle_language_command }, |
| 543 | { "/log", handle_log_command }, |
| 544 | |
| 545 | { NULL, NULL } |
| 546 | |
| 547 | }; |
| 548 | |
| 549 | |
| 550 | extern int handle_command(t_connection * c, char const * text) |
| 551 | { |
| 552 | int result = 0; |
| 553 | t_command_table_row const *p; |
| 554 | |
| 555 | #ifdef WITH_LUA |
| 556 | // feature to ignore flood protection |
| 557 | result = lua_handle_command(c, text, luaevent_command_before); |
| 558 | #endif |
| 559 | if (result == -1) |
| 560 | return result; |
| 561 | |
| 562 | if (result == 0) |
| 563 | if ((text[0] != '\0') && (conn_quota_exceeded(c, text))) |
| 564 | { |
| 565 | msgtemp = localize(c, "You are sending commands to {} too quickly and risk being disconnected for flooding. Please slow down.", prefs_get_servername()); |
| 566 | message_send_text(c, message_type_error, c, msgtemp); |
| 567 | return 0; |
| 568 | } |
| 569 | |
| 570 | #ifdef WITH_LUA |
| 571 | result = lua_handle_command(c, text, luaevent_command); |
| 572 | // -1 = unsuccess, 0 = success, 1 = execute next c++ code |
| 573 | if (result == 0) |
| 574 | { |
| 575 | // log command |
| 576 | if (t_account * account = conn_get_account(c)) |
| 577 | userlog_append(account, text); |
| 578 | } |
| 579 | if (result == 0 || result == -1) |
| 580 | return result; |
| 581 | #endif |
| 582 | |
| 583 | for (p = standard_command_table; p->command_string != NULL; p++) |
| 584 | { |
| 585 | if (strstart(text, p->command_string) == 0) |
| 586 | { |
| 587 | if (!(command_get_group(p->command_string))) |
| 588 | { |
| 589 | message_send_text(c, message_type_error, c, localize(c, "This command has been deactivated")); |
| 590 | return 0; |
| 591 | } |
| 592 | if (!((command_get_group(p->command_string) & account_get_command_groups(conn_get_account(c))))) |
| 593 | { |
| 594 | message_send_text(c, message_type_error, c, localize(c, "This command is reserved for admins.")); |
| 595 | return 0; |
| 596 | } |
| 597 | if (p->command_handler != NULL) |
| 598 | { |
| 599 | result = ((p->command_handler)(c, text)); |
| 600 | // -1 = unsuccess, 0 = success |
| 601 | if (result == 0) |
| 602 | { |
| 603 | // log command |
| 604 | if (t_account * account = conn_get_account(c)) |
| 605 | userlog_append(account, text); |
| 606 | } |
| 607 | return result; |
| 608 | } |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | if (std::strlen(text) >= 2 && std::strncmp(text, "//", 2) == 0) |
| 613 | { |
| 614 | handle_alias_command(c, text); |
| 615 | return 0; |
| 616 | } |
| 617 | |
| 618 | message_send_text(c, message_type_error, c, localize(c, "Unknown command.")); |
| 619 | eventlog(eventlog_level_debug, __FUNCTION__, "got unknown command \"{}\"", text); |
| 620 | return -1; |
| 621 | } |
| 622 | |
| 623 | |
| 624 | |
| 625 | |
| 626 | |
| 627 | // +++++++++++++++++++++++++++++++++ command implementations +++++++++++++++++++++++++++++++++++++++ |
| 628 | |
| 629 | static int _handle_clan_command(t_connection * c, char const * text) |
| 630 | { |
| 631 | t_account * acc; |
| 632 | t_clanmember * member; |
| 633 | t_clan * clan; |
| 634 | |
| 635 | if (!(acc = conn_get_account(c))){ |
| 636 | ERROR0("got NULL account"); |
| 637 | } |
| 638 | |
| 639 | std::vector<std::string> args = split_command(text, 2); |
| 640 | |
| 641 | if (args[1].empty()) { |
| 642 | describe_command(c, args[0].c_str()); |
| 643 | return -1; |
| 644 | } |
| 645 | |
| 646 | /* FIXME: can get clan as is in creating process */ |
| 647 | |
| 648 | // user in clan |
| 649 | if ((member = account_get_clanmember_forced(acc)) && (clan = clanmember_get_clan(member))) |
| 650 | { |
| 651 | // user is full member of clan |
| 652 | if (clanmember_get_fullmember(member) == 1) |
| 653 | { |
| 654 | if (args[1] == "msg" || args[1] == "m" || args[1] == "w" || args[1] == "whisper") |
| 655 | { |
| 656 | if (args[2].empty()) { |
| 657 | describe_command(c, args[0].c_str()); |
| 658 | return -1; |
| 659 | } |
| 660 | char const *msg = args[2].c_str(); // message |
| 661 | |
| 662 | if (clan_send_message_to_online_members(clan, message_type_whisper, c, msg) >= 1) |
| 663 | message_send_text(c, message_type_info, c, localize(c, "Message was sent to all currently available clan members.")); |
| 664 | else |
| 665 | message_send_text(c, message_type_info, c, localize(c, "All fellow members of your clan are currently offline.")); |
| 666 | |
| 667 | return 0; |
| 668 | } |
| 669 | |
| 670 | if (clanmember_get_status(member) >= CLAN_SHAMAN) |
| 671 | { |
| 672 | if (args[1] == "public" || args[1] == "pub") |
| 673 | { |
| 674 | if (clan_get_channel_type(clan) != 0) { |
| 675 | clan_set_channel_type(clan, 0); |
| 676 | message_send_text(c, message_type_info, c, localize(c, "Clan channel is opened up!")); |
| 677 | } |
| 678 | else |
| 679 | message_send_text(c, message_type_error, c, localize(c, "Clan channel has already been opened up!")); |
| 680 | return 0; |
| 681 | } |
| 682 | else if (args[1] == "private" || args[1] == "priv") |
| 683 | { |
| 684 | if (clan_get_channel_type(clan) != 1) { |
| 685 | clan_set_channel_type(clan, 1); |
| 686 | message_send_text(c, message_type_info, c, localize(c, "Clan channel is closed!")); |
| 687 | } |
| 688 | else |
| 689 | message_send_text(c, message_type_error, c, localize(c, "Clan channel has already been closed!")); |
| 690 | return 0; |
| 691 | } |
| 692 | else if (args[1] == "motd") |
| 693 | { |
| 694 | if (args[2].empty()) |
| 695 | { |
| 696 | describe_command(c, args[0].c_str()); |
| 697 | return 0; |
| 698 | } |
| 699 | const char * msg = args[2].c_str(); // message |
| 700 | |
| 701 | clan_set_motd(clan, msg); |
| 702 | message_send_text(c, message_type_info, c, localize(c, "Clan message of day is updated!")); |
| 703 | return 0; |
| 704 | } |
| 705 | else if (args[1] == "invite" || args[1] == "inv") |
| 706 | { |
| 707 | t_account * dest_account; |
| 708 | t_connection * dest_conn; |
| 709 | if (args[2].empty()) |
| 710 | { |
| 711 | describe_command(c, args[0].c_str()); |
| 712 | return -1; |
| 713 | } |
| 714 | const char * username = args[2].c_str(); |
| 715 | |
| 716 | if ((dest_account = accountlist_find_account(username)) && (dest_conn = account_get_conn(dest_account)) |
| 717 | && (account_get_clan(dest_account) == NULL) && (account_get_creating_clan(dest_account) == NULL)) |
| 718 | { |
| 719 | if (prefs_get_clan_newer_time() > 0) |
| 720 | clan_add_member(clan, dest_account, CLAN_NEW); |
| 721 | else |
| 722 | clan_add_member(clan, dest_account, CLAN_PEON); |
| 723 | msgtemp = localize(c, "User {} was invited to your clan!", username); |
| 724 | message_send_text(c, message_type_error, c, msgtemp); |
| 725 | msgtemp = localize(c, "You are invited to {} by {}!", clan_get_name(clan), conn_get_chatname(c)); |
| 726 | message_send_text(dest_conn, message_type_error, c, msgtemp); |
| 727 | } |
| 728 | else { |
| 729 | msgtemp = localize(c, "User {} is not online or is already member of clan!", username); |
| 730 | message_send_text(c, message_type_error, c, msgtemp); |
| 731 | } |
| 732 | return 0; |
| 733 | } |
| 734 | else if (args[1] == "disband" || args[1] == "dis") |
| 735 | { |
| 736 | if (args[2] != "yes") { |
| 737 | message_send_text(c, message_type_info, c, localize(c, "This is one-way action! If you really want")); |
| 738 | message_send_text(c, message_type_info, c, localize(c, "to disband your clan, type /clan disband yes")); |
| 739 | } |
| 740 | /* PELISH: fixme - Find out better solution! */ |
| 741 | if (clanlist_remove_clan(clan) == 0) { |
| 742 | if (clan_get_created(clan) == 1) |
| 743 | clan_remove(clan_get_clantag(clan)); |
| 744 | clan_destroy(clan); |
| 745 | message_send_text(c, message_type_info, c, localize(c, "Your clan was disbanded.")); |
| 746 | } |
| 747 | return 0; |
| 748 | } |
| 749 | } |
| 750 | } |
| 751 | // user is not full member (invitation was not accepted yet) |
| 752 | else if (clanmember_get_fullmember(member) == 0) |
| 753 | { |
| 754 | /* User is not in clan, but he can accept invitation to someone */ |
| 755 | if (args[1] != "invite" && args[1] != "inv") |
| 756 | { |
| 757 | describe_command(c, args[0].c_str()); |
| 758 | return -1; |
| 759 | } |
| 760 | |
| 761 | if (args[2] == "get") { |
| 762 | msgtemp = localize(c, "You have been invited to {}", clan_get_name(clan)); |
| 763 | message_send_text(c, message_type_info, c, msgtemp); |
| 764 | return 0; |
| 765 | } |
| 766 | else if (args[2] == "accept" || args[2] == "acc") { |
| 767 | int created = clan_get_created(clan); |
| 768 | |
| 769 | clanmember_set_fullmember(member, 1); |
| 770 | clanmember_set_join_time(member, std::time(NULL)); |
| 771 | msgtemp = localize(c, "You are now a clan member of {}", clan_get_name(clan)); |
| 772 | message_send_text(c, message_type_info, c, msgtemp); |
| 773 | if (created > 0) { |
| 774 | DEBUG1("clan {} has already been created", clan_get_name(clan)); |
| 775 | return -1; |
| 776 | } |
| 777 | created++; |
| 778 | if (created >= 0) { |
| 779 | clan_set_created(clan, 1); |
| 780 | clan_set_creation_time(clan, std::time(NULL)); |
| 781 | /* FIXME: send message "CLAN was be created" to members */ |
| 782 | msgtemp = localize(c, "Clan {} was be created", clan_get_name(clan)); |
| 783 | clan_send_message_to_online_members(clan, message_type_whisper, c, msgtemp.c_str()); /* Send message to all members */ |
| 784 | message_send_text(c, message_type_whisper, c, msgtemp); /* also to self */ |
| 785 | clan_save(clan); |
| 786 | } |
| 787 | else |
| 788 | clan_set_created(clan, created); |
| 789 | return 0; |
| 790 | } |
| 791 | else if (args[2] == "decline" || args[2] == "dec") { |
| 792 | clan_remove_member(clan, member); |
| 793 | msgtemp = localize(c, "You are no longer ivited to {}", clan_get_name(clan)); |
| 794 | message_send_text(c, message_type_info, c, msgtemp); |
| 795 | return 0; |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | if ((args[1] == "create" || args[1] == "cre")) |
| 800 | { |
| 801 | message_send_text(c, message_type_error, c, localize(c, "You are already in clan \"{}\"", clan_get_name(clan))); |
| 802 | return -1; |
| 803 | } |
| 804 | } |
| 805 | // user not in clan |
| 806 | else |
| 807 | { |
| 808 | if ((args[1] == "create" || args[1] == "cre")) |
| 809 | { |
| 810 | char const *clantag, *clanname; |
| 811 | std::vector<std::string> args = split_command(text, 3); |
| 812 | |
| 813 | if (args[3].empty()) |
| 814 | { |
| 815 | describe_command(c, args[0].c_str()); |
| 816 | return -1; |
| 817 | } |
| 818 | clantag = args[2].c_str(); // clan tag |
| 819 | clanname = args[3].c_str(); // clan name |
| 820 | |
| 821 | if (clan = clanlist_find_clan_by_clantag(str_to_clantag(clantag))) { |
| 822 | message_send_text(c, message_type_error, c, localize(c, "Clan with your specified <clantag> already exist!")); |
| 823 | message_send_text(c, message_type_error, c, localize(c, "Please choice another one.")); |
| 824 | return -1; |
| 825 | } |
| 826 | |
| 827 | if ((clan = clan_create(conn_get_account(c), str_to_clantag(clantag), clanname, NULL)) && clanlist_add_clan(clan)) |
| 828 | { |
| 829 | member = account_get_clanmember_forced(acc); |
| 830 | if (prefs_get_clan_min_invites() == 0) { |
| 831 | clan_set_created(clan, 1); |
| 832 | clan_set_creation_time(clan, std::time(NULL)); |
| 833 | msgtemp = localize(c, "Clan {} is created!", clan_get_name(clan)); |
| 834 | message_send_text(c, message_type_info, c, msgtemp); |
| 835 | clan_save(clan); |
| 836 | } |
| 837 | else { |
| 838 | clan_set_created(clan, -prefs_get_clan_min_invites() + 1); //Pelish: +1 means that creator of clan is already invited |
| 839 | msgtemp = localize(c, "Clan {} is pre-created, please invite", clan_get_name(clan)); |
| 840 | message_send_text(c, message_type_info, c, msgtemp); |
| 841 | msgtemp = localize(c, "at least {} players to your clan by using", prefs_get_clan_min_invites()); |
| 842 | message_send_text(c, message_type_info, c, msgtemp); |
| 843 | message_send_text(c, message_type_info, c, localize(c, "/clan invite <username> command.")); |
| 844 | } |
| 845 | } |
| 846 | return 0; |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | describe_command(c, args[0].c_str()); |
| 851 | return -1; |
| 852 | } |
| 853 | |
| 854 | static int command_set_flags(t_connection * c) |
| 855 | { |
| 856 | return channel_set_userflags(c); |
| 857 | } |
| 858 | |
| 859 | static int _handle_admin_command(t_connection * c, char const * text) |
| 860 | { |
| 861 | char const * username; |
| 862 | char command; |
| 863 | t_account * acc; |
| 864 | t_connection * dst_c; |
| 865 | int changed = 0; |
| 866 | |
| 867 | std::vector<std::string> args = split_command(text, 1); |
| 868 | |
| 869 | if (args[1].empty() || (args[1][0] != '+' && args[1][0] != '-')) { |
| 870 | describe_command(c, args[0].c_str()); |
| 871 | return -1; |
| 872 | } |
| 873 | |
| 874 | text = args[1].c_str(); |
| 875 | command = text[0]; // command type (+/-) |
| 876 | username = &text[1]; // username |
| 877 | |
| 878 | if (!*username) { |
| 879 | message_send_text(c, message_type_info, c, localize(c, "You must supply a username.")); |
| 880 | return -1; |
| 881 | } |
| 882 | |
| 883 | if (!(acc = accountlist_find_account(username))) { |
| 884 | msgtemp = localize(c, "There's no account with username {}.", username); |
| 885 | message_send_text(c, message_type_info, c, msgtemp); |
| 886 | return -1; |
| 887 | } |
| 888 | dst_c = account_get_conn(acc); |
| 889 | |
| 890 | if (command == '+') { |
| 891 | if (account_get_auth_admin(acc, NULL) == 1) { |
| 892 | msgtemp = localize(c, "{} is already a Server Admin", username); |
| 893 | } |
| 894 | else { |
| 895 | account_set_auth_admin(acc, NULL, 1); |
| 896 | msgtemp = localize(c, "{} has been promoted to a Server Admin", username); |
| 897 | msgtemp2 = localize(c, "{} has promoted you to a Server Admin", conn_get_loggeduser(c)); |
| 898 | changed = 1; |
| 899 | } |
| 900 | } |
| 901 | else { |
| 902 | if (account_get_auth_admin(acc, NULL) != 1) |
| 903 | msgtemp = localize(c, "{} is not a Server Admin.", username); |
| 904 | else { |
| 905 | account_set_auth_admin(acc, NULL, 0); |
| 906 | msgtemp = localize(c, "{} has been demoted from a Server Admin", username); |
| 907 | msgtemp2 = localize(c, "{} has demoted you from a Server Admin", conn_get_loggeduser(c)); |
| 908 | changed = 1; |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | if (changed && dst_c) message_send_text(dst_c, message_type_info, c, msgtemp2); |
| 913 | message_send_text(c, message_type_info, c, msgtemp); |
| 914 | command_set_flags(dst_c); |
| 915 | return 0; |
| 916 | } |
| 917 | |
| 918 | static int _handle_operator_command(t_connection * c, char const * text) |
| 919 | { |
| 920 | char const * username; |
| 921 | char command; |
| 922 | t_account * acc; |
| 923 | t_connection * dst_c; |
| 924 | int changed = 0; |
| 925 | |
| 926 | std::vector<std::string> args = split_command(text, 1); |
| 927 | |
| 928 | if (args[1].empty() || (args[1][0] != '+' && args[1][0] != '-')) { |
| 929 | describe_command(c, args[0].c_str()); |
| 930 | return -1; |
| 931 | } |
| 932 | |
| 933 | text = args[1].c_str(); |
| 934 | command = text[0]; // command type (+/-) |
| 935 | username = &text[1]; // username |
| 936 | |
| 937 | if (!*username) { |
| 938 | message_send_text(c, message_type_info, c, localize(c, "You must supply a username.")); |
| 939 | return -1; |
| 940 | } |
| 941 | |
| 942 | if (!(acc = accountlist_find_account(username))) { |
| 943 | msgtemp = localize(c, "There's no account with username {}.", username); |
| 944 | message_send_text(c, message_type_info, c, msgtemp); |
| 945 | return -1; |
| 946 | } |
| 947 | dst_c = account_get_conn(acc); |
| 948 | |
| 949 | if (command == '+') { |
| 950 | if (account_get_auth_operator(acc, NULL) == 1) |
| 951 | msgtemp = localize(c, "{} is already a Server Operator", username); |
| 952 | else { |
| 953 | account_set_auth_operator(acc, NULL, 1); |
| 954 | msgtemp = localize(c, "{} has been promoted to a Server Operator", username); |
| 955 | msgtemp2 = localize(c, "{} has promoted you to a Server Operator", conn_get_loggeduser(c)); |
| 956 | changed = 1; |
| 957 | } |
| 958 | } |
| 959 | else { |
| 960 | if (account_get_auth_operator(acc, NULL) != 1) |
| 961 | msgtemp = localize(c, "{} is no Server Operator, so you can't demote him", username); |
| 962 | else { |
| 963 | account_set_auth_operator(acc, NULL, 0); |
| 964 | msgtemp = localize(c, "{} has been demoted from a Server Operator", username); |
| 965 | msgtemp2 = localize(c, "{} has promoted you to a Server Operator", conn_get_loggeduser(c)); |
| 966 | changed = 1; |
| 967 | } |
| 968 | } |
| 969 | |
| 970 | if (changed && dst_c) message_send_text(dst_c, message_type_info, c, msgtemp2); |
| 971 | message_send_text(c, message_type_info, c, msgtemp); |
| 972 | command_set_flags(dst_c); |
| 973 | return 0; |
| 974 | } |
| 975 | |
| 976 | static int _handle_aop_command(t_connection * c, char const * text) |
| 977 | { |
| 978 | char const * username; |
| 979 | char const * channel; |
| 980 | t_account * acc; |
| 981 | t_connection * dst_c; |
| 982 | int changed = 0; |
| 983 | |
| 984 | if (!(conn_get_channel(c)) || !(channel = channel_get_name(conn_get_channel(c)))) { |
| 985 | message_send_text(c, message_type_error, c, localize(c, "This command can only be used inside a channel.")); |
| 986 | return -1; |
| 987 | } |
| 988 | |
| 989 | if (account_get_auth_admin(conn_get_account(c), NULL) != 1 && account_get_auth_admin(conn_get_account(c), channel) != 1) { |
| 990 | message_send_text(c, message_type_error, c, localize(c, "You must be at least a Channel Admin to use this command.")); |
| 991 | return -1; |
| 992 | } |
| 993 | |
| 994 | std::vector<std::string> args = split_command(text, 1); |
| 995 | |
| 996 | if (args[1].empty()) { |
| 997 | describe_command(c, args[0].c_str()); |
| 998 | return -1; |
| 999 | } |
| 1000 | username = args[1].c_str(); // username |
| 1001 | |
| 1002 | if (!(acc = accountlist_find_account(username))) { |
| 1003 | msgtemp = localize(c, "There's no account with username {}.", username); |
| 1004 | message_send_text(c, message_type_info, c, msgtemp); |
| 1005 | return -1; |
| 1006 | } |
| 1007 | |
| 1008 | dst_c = account_get_conn(acc); |
| 1009 | |
| 1010 | if (account_get_auth_admin(acc, channel) == 1) |
| 1011 | msgtemp = localize(c, "{} is already a Channel Admin", username); |
| 1012 | else { |
| 1013 | account_set_auth_admin(acc, channel, 1); |
| 1014 | msgtemp = localize(c, "{} has been promoted to a Channel Admin", username); |
| 1015 | msgtemp2 = localize(c, "{} has promoted you to a Channel Admin for channel \"{}\"", conn_get_loggeduser(c), channel); |
| 1016 | changed = 1; |
| 1017 | } |
| 1018 | |
| 1019 | if (changed && dst_c) message_send_text(dst_c, message_type_info, c, msgtemp2); |
| 1020 | message_send_text(c, message_type_info, c, msgtemp); |
| 1021 | command_set_flags(dst_c); |
| 1022 | return 0; |
| 1023 | } |
| 1024 | |
| 1025 | static int _handle_vop_command(t_connection * c, char const * text) |
| 1026 | { |
| 1027 | char const * username; |
| 1028 | char const * channel; |
| 1029 | t_account * acc; |
| 1030 | t_connection * dst_c; |
| 1031 | int changed = 0; |
| 1032 | |
| 1033 | if (!(conn_get_channel(c)) || !(channel = channel_get_name(conn_get_channel(c)))) { |
| 1034 | message_send_text(c, message_type_error, c, localize(c, "This command can only be used inside a channel.")); |
| 1035 | return -1; |
| 1036 | } |
| 1037 | |
| 1038 | if (account_get_auth_admin(conn_get_account(c), NULL) != 1 && account_get_auth_admin(conn_get_account(c), channel) != 1) { |
| 1039 | message_send_text(c, message_type_error, c, localize(c, "You must be at least a Channel Admin to use this command.")); |
| 1040 | return -1; |
| 1041 | } |
| 1042 | |
| 1043 | std::vector<std::string> args = split_command(text, 1); |
| 1044 | |
| 1045 | if (args[1].empty()) { |
| 1046 | describe_command(c, args[0].c_str()); |
| 1047 | return -1; |
| 1048 | } |
| 1049 | username = args[1].c_str(); // username |
| 1050 | |
| 1051 | if (!(acc = accountlist_find_account(username))) { |
| 1052 | msgtemp = localize(c, "There's no account with username {}.", username); |
| 1053 | message_send_text(c, message_type_info, c, msgtemp); |
| 1054 | return -1; |
| 1055 | } |
| 1056 | |
| 1057 | dst_c = account_get_conn(acc); |
| 1058 | |
| 1059 | if (account_get_auth_voice(acc, channel) == 1) |
| 1060 | msgtemp = localize(c, "{} is already on VOP list", username); |
| 1061 | else { |
| 1062 | account_set_auth_voice(acc, channel, 1); |
| 1063 | msgtemp = localize(c, "{} has been added to the VOP list", username); |
| 1064 | msgtemp2 = localize(c, "{} has added you to the VOP list of channel \"{}\"", conn_get_loggeduser(c), channel); |
| 1065 | changed = 1; |
| 1066 | } |
| 1067 | |
| 1068 | if (changed && dst_c) message_send_text(dst_c, message_type_info, c, msgtemp2); |
| 1069 | message_send_text(c, message_type_info, c, msgtemp); |
| 1070 | command_set_flags(dst_c); |
| 1071 | return 0; |
| 1072 | } |
| 1073 | |
| 1074 | static int _handle_voice_command(t_connection * c, char const * text) |
| 1075 | { |
| 1076 | char const * username; |
| 1077 | char const * channel; |
| 1078 | t_account * acc; |
| 1079 | t_connection * dst_c; |
| 1080 | int changed = 0; |
| 1081 | |
| 1082 | if (!(conn_get_channel(c)) || !(channel = channel_get_name(conn_get_channel(c)))) { |
| 1083 | message_send_text(c, message_type_error, c, localize(c, "This command can only be used inside a channel.")); |
| 1084 | return -1; |
| 1085 | } |
| 1086 | |
| 1087 | if (!(account_is_operator_or_admin(conn_get_account(c), channel_get_name(conn_get_channel(c))))) { |
| 1088 | message_send_text(c, message_type_error, c, localize(c, "You must be at least a Channel Operator to use this command.")); |
| 1089 | return -1; |
| 1090 | } |
| 1091 | |
| 1092 | std::vector<std::string> args = split_command(text, 1); |
| 1093 | |
| 1094 | if (args[1].empty()) { |
| 1095 | describe_command(c, args[0].c_str()); |
| 1096 | return -1; |
| 1097 | } |
| 1098 | username = args[1].c_str(); // username |
| 1099 | |
| 1100 | if (!(acc = accountlist_find_account(username))) { |
| 1101 | msgtemp = localize(c, "There's no account with username {}.", username); |
| 1102 | message_send_text(c, message_type_info, c, msgtemp); |
| 1103 | return -1; |
| 1104 | } |
| 1105 | dst_c = account_get_conn(acc); |
| 1106 | if (account_get_auth_voice(acc, channel) == 1) |
| 1107 | msgtemp = localize(c, "{} is already on VOP list, no need to Voice him", username); |
| 1108 | else |
| 1109 | { |
| 1110 | if ((!dst_c) || conn_get_channel(c) != conn_get_channel(dst_c)) |
| 1111 | { |
| 1112 | msgtemp = localize(c, "{} must be on the same channel to voice him", username); |
| 1113 | } |
| 1114 | else |
| 1115 | { |
| 1116 | if (channel_conn_has_tmpVOICE(conn_get_channel(c), dst_c)) |
| 1117 | msgtemp = localize(c, "{} already has Voice in this channel", username); |
| 1118 | else { |
| 1119 | if (account_is_operator_or_admin(acc, channel)) |
| 1120 | msgtemp = localize(c, "{} is already an operator or admin.", username); |
| 1121 | else |
| 1122 | { |
| 1123 | conn_set_tmpVOICE_channel(dst_c, channel); |
| 1124 | msgtemp = localize(c, "{} has been granted Voice in this channel", username); |
| 1125 | msgtemp2 = localize(c, "{} has granted you Voice in this channel", conn_get_loggeduser(c)); |
| 1126 | changed = 1; |
| 1127 | } |
| 1128 | } |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | if (changed && dst_c) message_send_text(dst_c, message_type_info, c, msgtemp2); |
| 1133 | message_send_text(c, message_type_info, c, msgtemp); |
| 1134 | command_set_flags(dst_c); |
| 1135 | return 0; |
| 1136 | } |
| 1137 | |
| 1138 | static int _handle_devoice_command(t_connection * c, char const * text) |
| 1139 | { |
| 1140 | char const * username; |
| 1141 | char const * channel; |
| 1142 | t_account * acc; |
| 1143 | t_connection * dst_c; |
| 1144 | int done = 0; |
| 1145 | int changed = 0; |
| 1146 | |
| 1147 | if (!(conn_get_channel(c)) || !(channel = channel_get_name(conn_get_channel(c)))) { |
| 1148 | message_send_text(c, message_type_error, c, localize(c, "This command can only be used inside a channel.")); |
| 1149 | return -1; |
| 1150 | } |
| 1151 | |
| 1152 | if (!(account_is_operator_or_admin(conn_get_account(c), channel_get_name(conn_get_channel(c))))) { |
| 1153 | message_send_text(c, message_type_error, c, localize(c, "You must be at least a Channel Operator to use this command.")); |
| 1154 | return -1; |
| 1155 | } |
| 1156 | |
| 1157 | std::vector<std::string> args = split_command(text, 1); |
| 1158 | |
| 1159 | if (args[1].empty()) { |
| 1160 | describe_command(c, args[0].c_str()); |
| 1161 | return -1; |
| 1162 | } |
| 1163 | username = args[1].c_str(); // username |
| 1164 | |
| 1165 | if (!(acc = accountlist_find_account(username))) { |
| 1166 | msgtemp = localize(c, "There's no account with username {}.", username); |
| 1167 | message_send_text(c, message_type_info, c, msgtemp); |
| 1168 | return -1; |
| 1169 | } |
| 1170 | dst_c = account_get_conn(acc); |
| 1171 | |
| 1172 | if (account_get_auth_voice(acc, channel) == 1) |
| 1173 | { |
| 1174 | if ((account_get_auth_admin(conn_get_account(c), channel) == 1) || (account_get_auth_admin(conn_get_account(c), NULL) == 1)) |
| 1175 | { |
| 1176 | account_set_auth_voice(acc, channel, 0); |
| 1177 | msgtemp = localize(c, "{} has been removed from VOP list.", username); |
| 1178 | msgtemp2 = localize(c, "{} has removed you from VOP list of channel \"{}\"", conn_get_loggeduser(c), channel); |
| 1179 | changed = 1; |
| 1180 | } |
| 1181 | else |
| 1182 | { |
| 1183 | msgtemp = localize(c, "You must be at least Channel Admin to remove {} from the VOP list", username); |
| 1184 | } |
| 1185 | done = 1; |
| 1186 | } |
| 1187 | |
| 1188 | if (changed && dst_c) message_send_text(dst_c, message_type_info, c, msgtemp2); |
| 1189 | message_send_text(c, message_type_info, c, msgtemp); |
| 1190 | changed = 0; |
| 1191 | |
| 1192 | if ((dst_c) && channel_conn_has_tmpVOICE(conn_get_channel(c), dst_c) == 1) |
| 1193 | { |
| 1194 | conn_set_tmpVOICE_channel(dst_c, NULL); |
| 1195 | msgtemp = localize(c, "Voice has been taken from {} in this channel", username); |
| 1196 | msgtemp2 = localize(c, "{} has taken your Voice in channel \"{}\"", conn_get_loggeduser(c), channel); |
| 1197 | changed = 1; |
| 1198 | done = 1; |
| 1199 | } |
| 1200 | |
| 1201 | if (changed && dst_c) message_send_text(dst_c, message_type_info, c, msgtemp2); |
| 1202 | message_send_text(c, message_type_info, c, msgtemp); |
| 1203 | |
| 1204 | if (!done) |
| 1205 | { |
| 1206 | msgtemp = localize(c, "{} has no Voice in this channel, so it can't be taken away", username); |
| 1207 | message_send_text(c, message_type_info, c, msgtemp); |
| 1208 | } |
| 1209 | |
| 1210 | command_set_flags(dst_c); |
| 1211 | return 0; |
| 1212 | } |
| 1213 | |
| 1214 | static int _handle_op_command(t_connection * c, char const * text) |
| 1215 | { |
| 1216 | char const * username; |
| 1217 | char const * channel; |
| 1218 | t_account * acc; |
| 1219 | int OP_lvl; |
| 1220 | t_connection * dst_c; |
| 1221 | int changed = 0; |
| 1222 | |
| 1223 | if (!(conn_get_channel(c)) || !(channel = channel_get_name(conn_get_channel(c)))) { |
| 1224 | message_send_text(c, message_type_error, c, localize(c, "This command can only be used inside a channel.")); |
| 1225 | return -1; |
| 1226 | } |
| 1227 | |
| 1228 | acc = conn_get_account(c); |
| 1229 | OP_lvl = 0; |
| 1230 | |
| 1231 | if (account_is_operator_or_admin(acc, channel)) |
| 1232 | OP_lvl = 1; |
| 1233 | else if (channel_conn_is_tmpOP(conn_get_channel(c), c)) |
| 1234 | OP_lvl = 2; |
| 1235 | |
| 1236 | if (OP_lvl == 0) |
| 1237 | { |
| 1238 | message_send_text(c, message_type_error, c, localize(c, "You must be at least a Channel Operator or tempOP to use this command.")); |
| 1239 | return -1; |
| 1240 | } |
| 1241 | |
| 1242 | std::vector<std::string> args = split_command(text, 1); |
| 1243 | |
| 1244 | if (args[1].empty()) { |
| 1245 | describe_command(c, args[0].c_str()); |
| 1246 | return -1; |
| 1247 | } |
| 1248 | username = args[1].c_str(); // username |
| 1249 | |
| 1250 | if (!(acc = accountlist_find_account(username))) { |
| 1251 | msgtemp = localize(c, "There's no account with username {}.", username); |
| 1252 | message_send_text(c, message_type_info, c, msgtemp); |
| 1253 | return -1; |
| 1254 | } |
| 1255 | |
| 1256 | dst_c = account_get_conn(acc); |
| 1257 | |
| 1258 | if (OP_lvl == 1) // user is full op so he may fully op others |
| 1259 | { |
| 1260 | if (account_get_auth_operator(acc, channel) == 1) |
| 1261 | msgtemp = localize(c, "{} is already a Channel Operator", username); |
| 1262 | else { |
| 1263 | account_set_auth_operator(acc, channel, 1); |
| 1264 | msgtemp = localize(c, "{} has been promoted to a Channel Operator", username); |
| 1265 | msgtemp2 = localize(c, "{} has promoted you to a Channel Operator in channel \"{}\"", conn_get_loggeduser(c), channel); |
| 1266 | changed = 1; |
| 1267 | } |
| 1268 | } |
| 1269 | else { // user is only tempOP so he may only tempOP others |
| 1270 | if ((!(dst_c)) || (conn_get_channel(c) != conn_get_channel(dst_c))) |
| 1271 | msgtemp = localize(c, "{} must be on the same channel to tempOP him", username); |
| 1272 | else |
| 1273 | { |
| 1274 | if (account_is_operator_or_admin(acc, channel)) |
| 1275 | msgtemp = localize(c, "{} already is operator or admin, no need to tempOP him", username); |
| 1276 | else |
| 1277 | { |
| 1278 | conn_set_tmpOP_channel(dst_c, channel); |
| 1279 | msgtemp = localize(c, "{} has been promoted to a tempOP", username); |
| 1280 | msgtemp2 = localize(c, "{} has promoted you to a tempOP in this channel", conn_get_loggeduser(c)); |
| 1281 | changed = 1; |
| 1282 | } |
| 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | if (changed && dst_c) message_send_text(dst_c, message_type_info, c, msgtemp2); |
| 1287 | message_send_text(c, message_type_info, c, msgtemp); |
| 1288 | command_set_flags(dst_c); |
| 1289 | return 0; |
| 1290 | } |
| 1291 | |
| 1292 | static int _handle_tmpop_command(t_connection * c, char const * text) |
| 1293 | { |
| 1294 | char const * username; |
| 1295 | char const * channel; |
| 1296 | t_account * acc; |
| 1297 | t_connection * dst_c; |
| 1298 | int changed = 0; |
| 1299 | |
| 1300 | if (!(conn_get_channel(c)) || !(channel = channel_get_name(conn_get_channel(c)))) { |
| 1301 | message_send_text(c, message_type_error, c, localize(c, "This command can only be used inside a channel.")); |
| 1302 | return -1; |
| 1303 | } |
| 1304 | |
| 1305 | if (!(account_is_operator_or_admin(conn_get_account(c), channel_get_name(conn_get_channel(c))) || channel_conn_is_tmpOP(conn_get_channel(c), c))) { |
| 1306 | message_send_text(c, message_type_error, c, localize(c, "You must be at least a Channel Operator or tmpOP to use this command.")); |
| 1307 | return -1; |
| 1308 | } |
| 1309 | |
| 1310 | std::vector<std::string> args = split_command(text, 1); |
| 1311 | |
| 1312 | if (args[1].empty()) { |
| 1313 | describe_command(c, args[0].c_str()); |
| 1314 | return -1; |
| 1315 | } |
| 1316 | username = args[1].c_str(); // username |
| 1317 | |
| 1318 | if (!(acc = accountlist_find_account(username))) { |
| 1319 | msgtemp = localize(c, "There's no account with username {}.", username); |
| 1320 | message_send_text(c, message_type_info, c, msgtemp); |
| 1321 | return -1; |
| 1322 | } |
| 1323 | |
| 1324 | dst_c = account_get_conn(acc); |
| 1325 | |
| 1326 | if (channel_conn_is_tmpOP(conn_get_channel(c), dst_c)) |
| 1327 | msgtemp = localize(c, "{} has already tmpOP in this channel", username); |
| 1328 | else |
| 1329 | { |
| 1330 | if ((!(dst_c)) || (conn_get_channel(c) != conn_get_channel(dst_c))) |
| 1331 | msgtemp = localize(c, "{} must be on the same channel to tempOP him", username); |
| 1332 | else |
| 1333 | { |
| 1334 | if (account_is_operator_or_admin(acc, channel)) |
| 1335 | msgtemp = localize(c, "{} already is operator or admin, no need to tempOP him", username); |
| 1336 | else |
| 1337 | { |
| 1338 | conn_set_tmpOP_channel(dst_c, channel); |
| 1339 | msgtemp = localize(c, "{} has been promoted to tmpOP in this channel", username); |
| 1340 | msgtemp2 = localize(c, "{} has promoted you to a tempOP in this channel", conn_get_loggeduser(c)); |
| 1341 | changed = 1; |
| 1342 | } |
| 1343 | } |
| 1344 | } |
| 1345 | |
| 1346 | if (changed && dst_c) message_send_text(dst_c, message_type_info, c, msgtemp2); |
| 1347 | message_send_text(c, message_type_info, c, msgtemp); |
| 1348 | command_set_flags(dst_c); |
| 1349 | return 0; |
| 1350 | } |
| 1351 | |
| 1352 | static int _handle_deop_command(t_connection * c, char const * text) |
| 1353 | { |
| 1354 | char const * username; |
| 1355 | char const * channel; |
| 1356 | t_account * acc; |
| 1357 | int OP_lvl; |
| 1358 | t_connection * dst_c; |
| 1359 | int done = 0; |
| 1360 | |
| 1361 | if (!(conn_get_channel(c)) || !(channel = channel_get_name(conn_get_channel(c)))) { |
| 1362 | message_send_text(c, message_type_error, c, localize(c, "This command can only be used inside a channel.")); |
| 1363 | return -1; |
| 1364 | } |
| 1365 | |
| 1366 | acc = conn_get_account(c); |
| 1367 | OP_lvl = 0; |
| 1368 | |
| 1369 | if (account_is_operator_or_admin(acc, channel)) |
| 1370 | OP_lvl = 1; |
| 1371 | else if (channel_conn_is_tmpOP(conn_get_channel(c), account_get_conn(acc))) |
| 1372 | OP_lvl = 2; |
| 1373 | |
| 1374 | if (OP_lvl == 0) |
| 1375 | { |
| 1376 | message_send_text(c, message_type_error, c, localize(c, "You must be at least a Channel Operator or tempOP to use this command.")); |
| 1377 | return -1; |
| 1378 | } |
| 1379 | |
| 1380 | std::vector<std::string> args = split_command(text, 1); |
| 1381 | |
| 1382 | if (args[1].empty()) { |
| 1383 | describe_command(c, args[0].c_str()); |
| 1384 | return -1; |
| 1385 | } |
| 1386 | username = args[1].c_str(); // username |
| 1387 | |
| 1388 | |
| 1389 | if (!(acc = accountlist_find_account(username))) { |
| 1390 | msgtemp = localize(c, "There's no account with username {}.", username); |
| 1391 | message_send_text(c, message_type_info, c, msgtemp); |
| 1392 | return -1; |
| 1393 | } |
| 1394 | |
| 1395 | dst_c = account_get_conn(acc); |
| 1396 | |
| 1397 | if (OP_lvl == 1) // user is real OP and allowed to deOP |
| 1398 | { |
| 1399 | if (account_get_auth_admin(acc, channel) == 1 || account_get_auth_operator(acc, channel) == 1) { |
| 1400 | if (account_get_auth_admin(acc, channel) == 1) { |
| 1401 | if (account_get_auth_admin(conn_get_account(c), channel) != 1 && account_get_auth_admin(conn_get_account(c), NULL) != 1) |
| 1402 | message_send_text(c, message_type_info, c, localize(c, "You must be at least a Channel Admin to demote another Channel Admin")); |
| 1403 | else { |
| 1404 | account_set_auth_admin(acc, channel, 0); |
| 1405 | msgtemp = localize(c, "{} has been demoted from a Channel Admin.", username); |
| 1406 | message_send_text(c, message_type_info, c, msgtemp); |
| 1407 | if (dst_c) |
| 1408 | { |
| 1409 | msgtemp2 = localize(c, "{} has demoted you from a Channel Admin of channel \"{}\"", conn_get_loggeduser(c), channel); |
| 1410 | message_send_text(dst_c, message_type_info, c, msgtemp2); |
| 1411 | } |
| 1412 | } |
| 1413 | } |
| 1414 | if (account_get_auth_operator(acc, channel) == 1) { |
| 1415 | account_set_auth_operator(acc, channel, 0); |
| 1416 | msgtemp = localize(c, "{} has been demoted from a Channel Operator", username); |
| 1417 | message_send_text(c, message_type_info, c, msgtemp); |
| 1418 | if (dst_c) |
| 1419 | { |
| 1420 | msgtemp2 = localize(c, "{} has demoted you from a Channel Operator of channel \"{}\"", conn_get_loggeduser(c), channel); |
| 1421 | message_send_text(dst_c, message_type_info, c, msgtemp2); |
| 1422 | } |
| 1423 | } |
| 1424 | done = 1; |
| 1425 | } |
| 1426 | if ((dst_c) && channel_conn_is_tmpOP(conn_get_channel(c), dst_c)) |
| 1427 | { |
| 1428 | conn_set_tmpOP_channel(dst_c, NULL); |
| 1429 | msgtemp = localize(c, "{} has been demoted from a tempOP of this channel", username); |
| 1430 | message_send_text(c, message_type_info, c, msgtemp); |
| 1431 | if (dst_c) |
| 1432 | { |
| 1433 | msgtemp2 = localize(c, "{} has demoted you from a tmpOP of channel \"{}\"", conn_get_loggeduser(c), channel); |
| 1434 | message_send_text(dst_c, message_type_info, c, msgtemp2); |
| 1435 | } |
| 1436 | done = 1; |
| 1437 | } |
| 1438 | if (!done) { |
| 1439 | msgtemp = localize(c, "{} is no Channel Admin or Channel Operator or tempOP, so you can't demote him.", username); |
| 1440 | message_send_text(c, message_type_info, c, msgtemp); |
| 1441 | } |
| 1442 | } |
| 1443 | else //user is just a tempOP and may only deOP other tempOPs |
| 1444 | { |
| 1445 | if (dst_c && channel_conn_is_tmpOP(conn_get_channel(c), dst_c)) |
| 1446 | { |
| 1447 | conn_set_tmpOP_channel(account_get_conn(acc), NULL); |
| 1448 | msgtemp = localize(c, "{} has been demoted from a tempOP of this channel", username); |
| 1449 | message_send_text(c, message_type_info, c, msgtemp); |
| 1450 | msgtemp2 = localize(c, "{} has demoted you from a tempOP of channel \"{}\"", conn_get_loggeduser(c), channel); |
| 1451 | if (dst_c) message_send_text(dst_c, message_type_info, c, msgtemp2); |
| 1452 | } |
| 1453 | else |
| 1454 | { |
| 1455 | msgtemp = localize(c, "{} is no tempOP in this channel, so you can't demote him", username); |
| 1456 | message_send_text(c, message_type_info, c, msgtemp); |
| 1457 | } |
| 1458 | } |
| 1459 | |
| 1460 | command_set_flags(connlist_find_connection_by_accountname(username)); |
| 1461 | return 0; |
| 1462 | } |
| 1463 | |
| 1464 | static int _handle_friends_command(t_connection * c, char const * text) |
| 1465 | { |
| 1466 | int i; |
| 1467 | t_account *my_acc = conn_get_account(c); |
| 1468 | |
| 1469 | std::vector<std::string> args = split_command(text, 2); |
| 1470 | |
| 1471 | if (args[1] == "add" || args[1] == "a") { |
| 1472 | t_packet * rpacket; |
| 1473 | t_connection * dest_c; |
| 1474 | t_account * friend_acc; |
| 1475 | t_server_friendslistreply_status status; |
| 1476 | t_game * game; |
| 1477 | t_channel * channel; |
| 1478 | char stat; |
| 1479 | t_list * flist; |
| 1480 | t_friend * fr; |
| 1481 | |
| 1482 | if (args[2].empty()) { |
| 1483 | describe_command(c, args[0].c_str()); |
| 1484 | return -1; |
| 1485 | } |
| 1486 | text = args[2].c_str(); // username |
| 1487 | |
| 1488 | if (!(friend_acc = accountlist_find_account(text))) { |
| 1489 | message_send_text(c, message_type_info, c, localize(c, "That user does not exist.")); |
| 1490 | return -1; |
| 1491 | } |
| 1492 | |
| 1493 | switch (account_add_friend(my_acc, friend_acc)) { |
| 1494 | case -1: |
| 1495 | message_send_text(c, message_type_error, c, localize(c, "Server error.")); |
| 1496 | return -1; |
| 1497 | case -2: |
| 1498 | message_send_text(c, message_type_info, c, localize(c, "You can't add yourself to your friends list.")); |
| 1499 | return -1; |
| 1500 | case -3: |
| 1501 | msgtemp = localize(c, "You can only have a maximum of {} friends.", prefs_get_max_friends()); |
| 1502 | message_send_text(c, message_type_info, c, msgtemp); |
| 1503 | return -1; |
| 1504 | case -4: |
| 1505 | msgtemp = localize(c, "{} is already on your friends list!", text); |
| 1506 | message_send_text(c, message_type_info, c, msgtemp); |
| 1507 | return -1; |
| 1508 | } |
| 1509 | |
| 1510 | msgtemp = localize(c, "Added {} to your friends list.", text); |
| 1511 | message_send_text(c, message_type_info, c, msgtemp); |
| 1512 | dest_c = connlist_find_connection_by_account(friend_acc); |
| 1513 | if (dest_c != NULL) { |
| 1514 | msgtemp = localize(c, "{} added you to his/her friends list.", conn_get_username(c)); |
| 1515 | message_send_text(dest_c, message_type_info, dest_c, msgtemp); |
| 1516 | } |
| 1517 | |
| 1518 | if ((conn_get_class(c) != conn_class_bnet) || (!(rpacket = packet_create(packet_class_bnet)))) |
| 1519 | return 0; |
| 1520 | |
| 1521 | packet_set_size(rpacket, sizeof(t_server_friendadd_ack)); |
| 1522 | packet_set_type(rpacket, SERVER_FRIENDADD_ACK); |
| 1523 | |
| 1524 | packet_append_string(rpacket, account_get_name(friend_acc)); |
| 1525 | |
| 1526 | game = NULL; |
| 1527 | channel = NULL; |
| 1528 | |
| 1529 | if (!(dest_c)) |
| 1530 | { |
| 1531 | bn_byte_set(&status.location, FRIENDSTATUS_OFFLINE); |
| 1532 | bn_byte_set(&status.status, 0); |
| 1533 | bn_int_set(&status.clienttag, 0); |
| 1534 | } |
| 1535 | else |
| 1536 | { |
| 1537 | bn_int_set(&status.clienttag, conn_get_clienttag(dest_c)); |
| 1538 | stat = 0; |
| 1539 | flist = account_get_friends(my_acc); |
| 1540 | fr = friendlist_find_account(flist, friend_acc); |
| 1541 | if ((friend_get_mutual(fr))) stat |= FRIEND_TYPE_MUTUAL; |
| 1542 | if ((conn_get_dndstr(dest_c))) stat |= FRIEND_TYPE_DND; |
| 1543 | if ((conn_get_awaystr(dest_c))) stat |= FRIEND_TYPE_AWAY; |
| 1544 | bn_byte_set(&status.status, stat); |
| 1545 | if ((game = conn_get_game(dest_c))) |
| 1546 | { |
| 1547 | if (game_get_flag(game) != game_flag_private) |
| 1548 | bn_byte_set(&status.location, FRIENDSTATUS_PUBLIC_GAME); |
| 1549 | else |
| 1550 | bn_byte_set(&status.location, FRIENDSTATUS_PRIVATE_GAME); |
| 1551 | } |
| 1552 | else if ((channel = conn_get_channel(dest_c))) |
| 1553 | { |
| 1554 | bn_byte_set(&status.location, FRIENDSTATUS_CHAT); |
| 1555 | } |
| 1556 | else |
| 1557 | { |
| 1558 | bn_byte_set(&status.location, FRIENDSTATUS_ONLINE); |
| 1559 | } |
| 1560 | } |
| 1561 | |
| 1562 | packet_append_data(rpacket, &status, sizeof(status)); |
| 1563 | |
| 1564 | if (game) packet_append_string(rpacket, game_get_name(game)); |
| 1565 | else if (channel) packet_append_string(rpacket, channel_get_name(channel)); |
| 1566 | else packet_append_string(rpacket, ""); |
| 1567 | |
| 1568 | conn_push_outqueue(c, rpacket); |
| 1569 | packet_del_ref(rpacket); |
| 1570 | } |
| 1571 | else if (args[1] == "msg" || args[1] == "w" || args[1] == "whisper" || args[1] == "m") |
| 1572 | { |
| 1573 | char const *msg; |
| 1574 | int cnt = 0; |
| 1575 | t_connection * dest_c; |
| 1576 | t_elem * curr; |
| 1577 | t_friend * fr; |
| 1578 | t_list * flist; |
| 1579 | |
| 1580 | if (args[2].empty()) { |
| 1581 | describe_command(c, args[0].c_str()); |
| 1582 | return -1; |
| 1583 | } |
| 1584 | msg = args[2].c_str(); // message |
| 1585 | |
| 1586 | flist = account_get_friends(my_acc); |
| 1587 | if (flist == NULL) |
| 1588 | return -1; |
| 1589 | |
| 1590 | LIST_TRAVERSE(flist, curr) |
| 1591 | { |
| 1592 | if (!(fr = (t_friend*)elem_get_data(curr))) { |
| 1593 | eventlog(eventlog_level_error, __FUNCTION__, "found NULL entry in list"); |
| 1594 | continue; |
| 1595 | } |
| 1596 | if (friend_get_mutual(fr)) { |
| 1597 | dest_c = connlist_find_connection_by_account(friend_get_account(fr)); |
| 1598 | if (!dest_c) continue; |
| 1599 | message_send_text(dest_c, message_type_whisper, c, msg); |
| 1600 | cnt++; |
| 1601 | } |
| 1602 | } |
| 1603 | if (cnt) |
| 1604 | message_send_text(c, message_type_friendwhisperack, c, msg); |
| 1605 | else |
| 1606 | message_send_text(c, message_type_info, c, localize(c, "All of your friends are offline.")); |
| 1607 | } |
| 1608 | else if (args[1] == "r" || args[1] == "remove" || args[1] == "del" || args[1] == "delete") |
| 1609 | { |
| 1610 | int num; |
| 1611 | t_packet * rpacket; |
| 1612 | |
| 1613 | if (args[2].empty()) { |
| 1614 | describe_command(c, args[0].c_str()); |
| 1615 | return -1; |
| 1616 | } |
| 1617 | text = args[2].c_str(); // username |
| 1618 | |
| 1619 | switch ((num = account_remove_friend2(my_acc, text))) { |
| 1620 | case -1: return -1; |
| 1621 | case -2: |
| 1622 | msgtemp = localize(c, "{} was not found on your friends list.", text); |
| 1623 | message_send_text(c, message_type_info, c, msgtemp); |
| 1624 | return -1; |
| 1625 | default: |
| 1626 | msgtemp = localize(c, "Removed {} from your friends list.", text); |
| 1627 | message_send_text(c, message_type_info, c, msgtemp); |
| 1628 | |
| 1629 | if ((conn_get_class(c) != conn_class_bnet) || (!(rpacket = packet_create(packet_class_bnet)))) |
| 1630 | return 0; |
| 1631 | |
| 1632 | packet_set_size(rpacket, sizeof(t_server_frienddel_ack)); |
| 1633 | packet_set_type(rpacket, SERVER_FRIENDDEL_ACK); |
| 1634 | |
| 1635 | bn_byte_set(&rpacket->u.server_frienddel_ack.friendnum, num); |
| 1636 | |
| 1637 | conn_push_outqueue(c, rpacket); |
| 1638 | packet_del_ref(rpacket); |
| 1639 | |
| 1640 | return 0; |
| 1641 | } |
| 1642 | } |
| 1643 | else if (args[1] == "p" || args[1] == "promote") { |
| 1644 | int num; |
| 1645 | int n; |
| 1646 | char const * dest_name; |
| 1647 | t_packet * rpacket; |
| 1648 | t_list * flist; |
| 1649 | t_friend * fr; |
| 1650 | t_account * dest_acc; |
| 1651 | unsigned int dest_uid; |
| 1652 | |
| 1653 | if (args[2].empty()) { |
| 1654 | describe_command(c, args[0].c_str()); |
| 1655 | return -1; |
| 1656 | } |
| 1657 | text = args[2].c_str(); // username |
| 1658 | |
| 1659 | num = account_get_friendcount(my_acc); |
| 1660 | flist = account_get_friends(my_acc); |
| 1661 | for (n = 1; n < num; n++) |
| 1662 | if ((dest_uid = account_get_friend(my_acc, n)) && |
| 1663 | (fr = friendlist_find_uid(flist, dest_uid)) && |
| 1664 | (dest_acc = friend_get_account(fr)) && |
| 1665 | (dest_name = account_get_name(dest_acc)) && |
| 1666 | (strcasecmp(dest_name, text) == 0)) |
| 1667 | { |
| 1668 | account_set_friend(my_acc, n, account_get_friend(my_acc, n - 1)); |
| 1669 | account_set_friend(my_acc, n - 1, dest_uid); |
| 1670 | msgtemp = localize(c, "Promoted {} in your friends list.", dest_name); |
| 1671 | message_send_text(c, message_type_info, c, msgtemp); |
| 1672 | |
| 1673 | if ((conn_get_class(c) != conn_class_bnet) || (!(rpacket = packet_create(packet_class_bnet)))) |
| 1674 | return 0; |
| 1675 | |
| 1676 | packet_set_size(rpacket, sizeof(t_server_friendmove_ack)); |
| 1677 | packet_set_type(rpacket, SERVER_FRIENDMOVE_ACK); |
| 1678 | bn_byte_set(&rpacket->u.server_friendmove_ack.pos1, n - 1); |
| 1679 | bn_byte_set(&rpacket->u.server_friendmove_ack.pos2, n); |
| 1680 | |
| 1681 | conn_push_outqueue(c, rpacket); |
| 1682 | packet_del_ref(rpacket); |
| 1683 | return 0; |
| 1684 | } |
| 1685 | } |
| 1686 | else if (args[1] == "d" || args[1] == "demote") { |
| 1687 | int num; |
| 1688 | int n; |
| 1689 | char const * dest_name; |
| 1690 | t_packet * rpacket; |
| 1691 | t_list * flist; |
| 1692 | t_friend * fr; |
| 1693 | t_account * dest_acc; |
| 1694 | unsigned int dest_uid; |
| 1695 | |
| 1696 | if (args[2].empty()) { |
| 1697 | describe_command(c, args[0].c_str()); |
| 1698 | return -1; |
| 1699 | } |
| 1700 | text = args[2].c_str(); // username |
| 1701 | |
| 1702 | num = account_get_friendcount(my_acc); |
| 1703 | flist = account_get_friends(my_acc); |
| 1704 | for (n = 0; n < num - 1; n++) |
| 1705 | if ((dest_uid = account_get_friend(my_acc, n)) && |
| 1706 | (fr = friendlist_find_uid(flist, dest_uid)) && |
| 1707 | (dest_acc = friend_get_account(fr)) && |
| 1708 | (dest_name = account_get_name(dest_acc)) && |
| 1709 | (strcasecmp(dest_name, text) == 0)) |
| 1710 | { |
| 1711 | account_set_friend(my_acc, n, account_get_friend(my_acc, n + 1)); |
| 1712 | account_set_friend(my_acc, n + 1, dest_uid); |
| 1713 | msgtemp = localize(c, "Demoted {} in your friends list.", dest_name); |
| 1714 | message_send_text(c, message_type_info, c, msgtemp); |
| 1715 | |
| 1716 | if ((conn_get_class(c) != conn_class_bnet) || (!(rpacket = packet_create(packet_class_bnet)))) |
| 1717 | return 0; |
| 1718 | |
| 1719 | packet_set_size(rpacket, sizeof(t_server_friendmove_ack)); |
| 1720 | packet_set_type(rpacket, SERVER_FRIENDMOVE_ACK); |
| 1721 | bn_byte_set(&rpacket->u.server_friendmove_ack.pos1, n); |
| 1722 | bn_byte_set(&rpacket->u.server_friendmove_ack.pos2, n + 1); |
| 1723 | |
| 1724 | conn_push_outqueue(c, rpacket); |
| 1725 | packet_del_ref(rpacket); |
| 1726 | return 0; |
| 1727 | } |
| 1728 | } |
| 1729 | else if (args[1] == "list" || args[1] == "l" || args[1] == "online" || args[1] == "o") { |
| 1730 | char const * frienduid; |
| 1731 | std::string status, software; |
| 1732 | t_connection * dest_c; |
| 1733 | t_account * friend_acc; |
| 1734 | t_game const * game; |
| 1735 | t_channel const * channel; |
| 1736 | t_friend * fr; |
| 1737 | t_list * flist; |
| 1738 | int num; |
| 1739 | unsigned int uid; |
| 1740 | bool online_only = false; |
| 1741 | |
| 1742 | if (args[1] == "online" || args[1] == "o") |
| 1743 | { |
| 1744 | online_only = true; |
| 1745 | } |
| 1746 | if (!online_only) |
| 1747 | { |
| 1748 | msgtemp = localize(c, "Your {} - Friends List", prefs_get_servername()); |
| 1749 | message_send_text(c, message_type_info, c, msgtemp); |
| 1750 | } |
| 1751 | else |
| 1752 | { |
| 1753 | msgtemp = localize(c, "Your {} - Online Friends List", prefs_get_servername()); |
| 1754 | message_send_text(c, message_type_info, c, msgtemp); |
| 1755 | } |
| 1756 | message_send_text(c, message_type_info, c, "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="); |
| 1757 | num = account_get_friendcount(my_acc); |
| 1758 | |
| 1759 | flist = account_get_friends(my_acc); |
| 1760 | if (flist != NULL) { |
| 1761 | for (i = 0; i < num; i++) |
| 1762 | { |
| 1763 | if ((!(uid = account_get_friend(my_acc, i))) || (!(fr = friendlist_find_uid(flist, uid)))) |
| 1764 | { |
| 1765 | eventlog(eventlog_level_error, __FUNCTION__, "friend uid in list"); |
| 1766 | continue; |
| 1767 | } |
| 1768 | friend_acc = friend_get_account(fr); |
| 1769 | if (!(dest_c = connlist_find_connection_by_account(friend_acc))) { |
| 1770 | if (online_only) { |
| 1771 | continue; |
| 1772 | } |
| 1773 | status = localize(c, ", offline"); |
| 1774 | } |
| 1775 | else { |
| 1776 | software = localize(c, " using {}", clienttag_get_title(conn_get_clienttag(dest_c))); |
| 1777 | |
| 1778 | if (friend_get_mutual(fr)) { |
| 1779 | if ((game = conn_get_game(dest_c))) |
| 1780 | status = localize(c, ", in game \"{}\"", game_get_name(game)); |
| 1781 | else if ((channel = conn_get_channel(dest_c))) { |
| 1782 | if (strcasecmp(channel_get_name(channel), "Arranged Teams") == 0) |
| 1783 | status = localize(c, ", in game AT Preparation"); |
| 1784 | else |
| 1785 | status = localize(c, ", in channel \"{}\",", channel_get_name(channel)); |
| 1786 | } |
| 1787 | else |
| 1788 | status = localize(c, ", is in AT Preparation"); |
| 1789 | } |
| 1790 | else { |
| 1791 | if ((game = conn_get_game(dest_c))) |
| 1792 | status = localize(c, ", is in a game"); |
| 1793 | else if ((channel = conn_get_channel(dest_c))) |
| 1794 | status = localize(c, ", is in a chat channel"); |
| 1795 | else |
| 1796 | status = localize(c, ", is in AT Preparation"); |
| 1797 | } |
| 1798 | } |
| 1799 | |
| 1800 | frienduid = account_get_name(friend_acc); |
| 1801 | if (!software.empty()) std::snprintf(msgtemp0, sizeof(msgtemp0), "%d: %s%.16s%.128s, %.64s", i + 1, friend_get_mutual(fr) ? "*" : " ", frienduid, status.c_str(), software.c_str()); |
| 1802 | else std::snprintf(msgtemp0, sizeof(msgtemp0), "%d: %.16s%.128s", i + 1, frienduid, status.c_str()); |
| 1803 | message_send_text(c, message_type_info, c, msgtemp0); |
| 1804 | } |
| 1805 | } |
| 1806 | message_send_text(c, message_type_info, c, "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="); |
| 1807 | message_send_text(c, message_type_info, c, localize(c, "End of Friends List")); |
| 1808 | } |
| 1809 | else { |
| 1810 | describe_command(c, args[0].c_str()); |
| 1811 | return -1; |
| 1812 | } |
| 1813 | |
| 1814 | return 0; |
| 1815 | } |
| 1816 | |
| 1817 | static int _handle_me_command(t_connection * c, char const * text) |
| 1818 | { |
| 1819 | t_channel const * channel; |
| 1820 | |
| 1821 | if (!(channel = conn_get_channel(c))) |
| 1822 | { |
| 1823 | message_send_text(c, message_type_error, c, localize(c, "You are not in a channel.")); |
| 1824 | return -1; |
| 1825 | } |
| 1826 | |
| 1827 | std::vector<std::string> args = split_command(text, 1); |
| 1828 | |
| 1829 | if (args[1].empty()) { |
| 1830 | describe_command(c, args[0].c_str()); |
| 1831 | return -1; |
| 1832 | } |
| 1833 | text = args[1].c_str(); // message |
| 1834 | |
| 1835 | if (!conn_quota_exceeded(c, text)) |
| 1836 | channel_message_send(channel, message_type_emote, c, text); |
| 1837 | return 0; |
| 1838 | } |
| 1839 | |
| 1840 | static int _handle_whisper_command(t_connection * c, char const *text) |
| 1841 | { |
| 1842 | char const * username; /* both include NUL, so no need to add one for middle @ or * */ |
| 1843 | |
| 1844 | std::vector<std::string> args = split_command(text, 2); |
| 1845 | |
| 1846 | if (args[2].empty()) |
| 1847 | { |
| 1848 | describe_command(c, args[0].c_str()); |
| 1849 | return -1; |
| 1850 | } |
| 1851 | username = args[1].c_str(); // username |
| 1852 | text = args[2].c_str(); // message |
| 1853 | |
| 1854 | do_whisper(c, username, text); |
| 1855 | |
| 1856 | return 0; |
| 1857 | } |
| 1858 | |
| 1859 | static int _handle_status_command(t_connection * c, char const *text) |
| 1860 | { |
| 1861 | t_clienttag clienttag; |
| 1862 | |
| 1863 | // get clienttag |
| 1864 | std::vector<std::string> args = split_command(text, 1); |
| 1865 | |
| 1866 | if (!args[1].empty() && (clienttag = tag_validate_client(args[1].c_str()))) |
| 1867 | { |
| 1868 | // clienttag status |
| 1869 | msgtemp = localize(c, "There are currently {} user(s) in {} games of {}", |
| 1870 | conn_get_user_count_by_clienttag(clienttag), |
| 1871 | game_get_count_by_clienttag(clienttag), |
| 1872 | clienttag_get_title(clienttag)); |
| 1873 | message_send_text(c, message_type_info, c, msgtemp); |
| 1874 | } |
| 1875 | else |
| 1876 | { |
| 1877 | // overall status |
| 1878 | msgtemp = localize(c, "There are currently {} users online, in {} games, and in {} channels.", |
| 1879 | connlist_login_get_length(), |
| 1880 | gamelist_get_length(), |
| 1881 | channellist_get_length()); |
| 1882 | message_send_text(c, message_type_info, c, msgtemp); |
| 1883 | } |
| 1884 | |
| 1885 | return 0; |
| 1886 | } |
| 1887 | |
| 1888 | static int _handle_who_command(t_connection * c, char const *text) |
| 1889 | { |
| 1890 | t_connection const * conn; |
| 1891 | t_channel const * channel; |
| 1892 | unsigned int i; |
| 1893 | char const * tname; |
| 1894 | |
| 1895 | std::vector<std::string> args = split_command(text, 1); |
| 1896 | |
| 1897 | if (args[1].empty()) |
| 1898 | { |
| 1899 | describe_command(c, args[0].c_str()); |
| 1900 | return -1; |
| 1901 | } |
| 1902 | char const * cname = args[1].c_str(); // channel name |
| 1903 | |
| 1904 | |
| 1905 | if (!(channel = channellist_find_channel_by_name(cname, conn_get_country(c), realm_get_name(conn_get_realm(c))))) |
| 1906 | { |
| 1907 | message_send_text(c, message_type_error, c, localize(c, "That channel does not exist.")); |
| 1908 | message_send_text(c, message_type_error, c, localize(c, "(If you are trying to search for a user, use the /whois command.)")); |
| 1909 | return -1; |
| 1910 | } |
| 1911 | if (channel_check_banning(channel, c) == 1) |
| 1912 | { |
| 1913 | message_send_text(c, message_type_error, c, localize(c, "You are banned from that channel.")); |
| 1914 | return -1; |
| 1915 | } |
| 1916 | |
| 1917 | std::snprintf(msgtemp0, sizeof msgtemp0, "%s", localize(c, "Users in channel {}:", cname).c_str()); |
| 1918 | i = std::strlen(msgtemp0); |
| 1919 | for (conn = channel_get_first(channel); conn; conn = channel_get_next()) |
| 1920 | { |
| 1921 | if (i + std::strlen((tname = conn_get_username(conn))) + 2 > sizeof(msgtemp0)) /* " ", name, '\0' */ |
| 1922 | { |
| 1923 | message_send_text(c, message_type_info, c, msgtemp0); |
| 1924 | i = 0; |
| 1925 | } |
| 1926 | std::sprintf(&msgtemp0[i], " %s", tname); |
| 1927 | i += std::strlen(&msgtemp0[i]); |
| 1928 | } |
| 1929 | if (i > 0) |
| 1930 | message_send_text(c, message_type_info, c, msgtemp0); |
| 1931 | |
| 1932 | return 0; |
| 1933 | } |
| 1934 | |
| 1935 | static int _handle_whois_command(t_connection * c, char const * text) |
| 1936 | { |
| 1937 | std::vector<std::string> args = split_command(text, 1); |
| 1938 | |
| 1939 | if (args[1].empty()) |
| 1940 | { |
| 1941 | describe_command(c, args[0].c_str()); |
| 1942 | return -1; |
| 1943 | } |
| 1944 | text = args[1].c_str(); // username |
| 1945 | |
| 1946 | do_whois(c, text); |
| 1947 | |
| 1948 | return 0; |
| 1949 | } |
| 1950 | |
| 1951 | static int _handle_whoami_command(t_connection * c, char const *text) |
| 1952 | { |
| 1953 | char const * tname; |
| 1954 | |
| 1955 | if (!(tname = conn_get_username(c))) |
| 1956 | { |
| 1957 | message_send_text(c, message_type_error, c, localize(c, "Unable to obtain your account name.")); |
| 1958 | return -1; |
| 1959 | } |
| 1960 | |
| 1961 | do_whois(c, tname); |
| 1962 | |
| 1963 | return 0; |
| 1964 | } |
| 1965 | |
| 1966 | static int _handle_announce_command(t_connection * c, char const *text) |
| 1967 | { |
| 1968 | t_message * message; |
| 1969 | |
| 1970 | std::vector<std::string> args = split_command(text, 1); |
| 1971 | |
| 1972 | if (args[1].empty()) |
| 1973 | { |
| 1974 | describe_command(c, args[0].c_str()); |
| 1975 | return -1; |
| 1976 | } |
| 1977 | text = args[1].c_str(); // message |
| 1978 | |
| 1979 | msgtemp = localize(c, "Announcement from {}: {}", conn_get_username(c), text); |
| 1980 | if (!(message = message_create(message_type_broadcast, c, msgtemp.c_str()))) |
| 1981 | message_send_text(c, message_type_info, c, localize(c, "Could not broadcast message.")); |
| 1982 | else |
| 1983 | { |
| 1984 | if (message_send_all(message) < 0) |
| 1985 | message_send_text(c, message_type_info, c, localize(c, "Could not broadcast message.")); |
| 1986 | message_destroy(message); |
| 1987 | } |
| 1988 | |
| 1989 | return 0; |
| 1990 | } |
| 1991 | |
| 1992 | static int _handle_beep_command(t_connection * c, char const *text) |
| 1993 | { |
| 1994 | message_send_text(c, message_type_info, c, localize(c, "Audible notification on.")); /* FIXME: actually do something */ |
| 1995 | return 0; /* FIXME: these only affect CHAT clients... I think they prevent ^G from being sent */ |
| 1996 | } |
| 1997 | |
| 1998 | static int _handle_nobeep_command(t_connection * c, char const *text) |
| 1999 | { |
| 2000 | message_send_text(c, message_type_info, c, localize(c, "Audible notification off.")); /* FIXME: actually do something */ |
| 2001 | return 0; |
| 2002 | } |
| 2003 | |
| 2004 | static int _handle_version_command(t_connection * c, char const *text) |
| 2005 | { |
| 2006 | message_send_text(c, message_type_info, c, PVPGN_SOFTWARE " " PVPGN_VERSION); |
| 2007 | return 0; |
| 2008 | } |
| 2009 | |
| 2010 | static int _handle_copyright_command(t_connection * c, char const *text) |
| 2011 | { |
| 2012 | static char const * const info[] = |
| 2013 | { |
| 2014 | " Copyright (C) 2002 - 2014 See source for details", |
| 2015 | " ", |
| 2016 | " PvPGN is free software; you can redistribute it and/or", |
| 2017 | " modify it under the terms of the GNU General Public License", |
| 2018 | " as published by the Free Software Foundation; either version 2", |
| 2019 | " of the License, or (at your option) any later version.", |
| 2020 | " ", |
| 2021 | " This program is distributed in the hope that it will be useful,", |
| 2022 | " but WITHOUT ANY WARRANTY; without even the implied warranty of", |
| 2023 | " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the", |
| 2024 | " GNU General Public License for more details.", |
| 2025 | " ", |
| 2026 | " You should have received a copy of the GNU General Public License", |
| 2027 | " along with this program; if not, write to the Free Software", |
| 2028 | " Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.", |
| 2029 | NULL |
| 2030 | }; |
| 2031 | unsigned int i; |
| 2032 | |
| 2033 | for (i = 0; info[i]; i++) |
| 2034 | message_send_text(c, message_type_info, c, info[i]); |
| 2035 | |
| 2036 | return 0; |
| 2037 | } |
| 2038 | |
| 2039 | static int _handle_uptime_command(t_connection * c, char const *text) |
| 2040 | { |
| 2041 | |
| 2042 | msgtemp = localize(c, "Uptime: {}", seconds_to_timestr(server_get_uptime())); |
| 2043 | message_send_text(c, message_type_info, c, msgtemp); |
| 2044 | |
| 2045 | return 0; |
| 2046 | } |
| 2047 | |
| 2048 | static int _handle_stats_command(t_connection * c, char const *text) |
| 2049 | { |
| 2050 | char const * username; |
| 2051 | t_account * account; |
| 2052 | char const * clienttag = NULL; |
| 2053 | t_clienttag clienttag_uint; |
| 2054 | char clienttag_str[5]; |
| 2055 | |
| 2056 | std::vector<std::string> args = split_command(text, 2); |
| 2057 | |
| 2058 | // username |
| 2059 | username = args[1].c_str(); |
| 2060 | if (args[1].empty()) { |
| 2061 | account = conn_get_account(c); |
| 2062 | } |
| 2063 | else if (!(account = accountlist_find_account(username))) { |
| 2064 | message_send_text(c, message_type_error, c, localize(c, "Invalid user.")); |
| 2065 | return -1; |
| 2066 | } |
| 2067 | |
| 2068 | // clienttag |
| 2069 | if (!args[2].empty() && args[2].length() == 4) |
| 2070 | clienttag = args[2].c_str(); |
| 2071 | else if (!(clienttag = tag_uint_to_str(clienttag_str, conn_get_clienttag(c)))) { |
| 2072 | message_send_text(c, message_type_error, c, localize(c, "Unable to determine client game.")); |
| 2073 | return -1; |
| 2074 | } |
| 2075 | |
| 2076 | clienttag_uint = tag_case_str_to_uint(clienttag); |
| 2077 | |
| 2078 | // custom stats |
| 2079 | if (prefs_get_custom_icons() == 1 && customicons_allowed_by_client(clienttag_uint)) |
| 2080 | { |
| 2081 | const char *text; |
| 2082 | |
| 2083 | // if text is not empty |
| 2084 | if (text = customicons_get_stats_text(account, clienttag_uint)) |
| 2085 | { |
| 2086 | // split by lines |
| 2087 | char* output_array = strtok((char*)text, "\n"); |
| 2088 | while (output_array) |
| 2089 | { |
| 2090 | message_send_text(c, message_type_info, c, output_array); |
| 2091 | output_array = strtok(NULL, "\n"); |
| 2092 | } |
| 2093 | xfree((char*)text); |
| 2094 | |
| 2095 | return 0; |
| 2096 | } |
| 2097 | } |
| 2098 | |
| 2099 | |
| 2100 | switch (clienttag_uint) |
| 2101 | { |
| 2102 | case CLIENTTAG_BNCHATBOT_UINT: |
| 2103 | message_send_text(c, message_type_error, c, localize(c, "This game does not support win/loss records.")); |
| 2104 | message_send_text(c, message_type_error, c, localize(c, "You must supply a user name and a valid program ID.")); |
| 2105 | message_send_text(c, message_type_error, c, localize(c, "Example: /stats joe STAR")); |
| 2106 | return -1; |
| 2107 | case CLIENTTAG_DIABLORTL_UINT: |
| 2108 | case CLIENTTAG_DIABLOSHR_UINT: |
| 2109 | msgtemp = localize(c, "{}'s record:", account_get_name(account)); |
| 2110 | message_send_text(c, message_type_info, c, msgtemp); |
| 2111 | msgtemp = localize(c, "level: {}", account_get_normal_level(account, clienttag_uint)); |
| 2112 | message_send_text(c, message_type_info, c, msgtemp); |
| 2113 | msgtemp = localize(c, "class: {}", bnclass_get_str(account_get_normal_class(account, clienttag_uint))); |
| 2114 | message_send_text(c, message_type_info, c, msgtemp); |
| 2115 | msgtemp = localize(c, "stats: {} str {} mag {} dex {} vit {} gld", |
| 2116 | account_get_normal_strength(account, clienttag_uint), |
| 2117 | account_get_normal_magic(account, clienttag_uint), |
| 2118 | account_get_normal_dexterity(account, clienttag_uint), |
| 2119 | account_get_normal_vitality(account, clienttag_uint), |
| 2120 | account_get_normal_gold(account, clienttag_uint)); |
| 2121 | message_send_text(c, message_type_info, c, msgtemp); |
| 2122 | msgtemp = localize(c, "Diablo kills: {}", account_get_normal_diablo_kills(account, clienttag_uint)); |
| 2123 | message_send_text(c, message_type_info, c, msgtemp); |
| 2124 | return 0; |
| 2125 | case CLIENTTAG_WARCIIBNE_UINT: |
| 2126 | msgtemp = localize(c, "{}'s record:", account_get_name(account)); |
| 2127 | message_send_text(c, message_type_info, c, msgtemp); |
| 2128 | msgtemp = localize(c, "Normal games: {}-{}-{}", |
| 2129 | account_get_normal_wins(account, clienttag_uint), |
| 2130 | account_get_normal_losses(account, clienttag_uint), |
| 2131 | account_get_normal_disconnects(account, clienttag_uint)); |
| 2132 | message_send_text(c, message_type_info, c, msgtemp); |
| 2133 | if (account_get_ladder_rating(account, clienttag_uint, ladder_id_normal) > 0) |
| 2134 | msgtemp = localize(c, "Ladder games: {}-{}-{} (rating {})", |
| 2135 | account_get_ladder_wins(account, clienttag_uint, ladder_id_normal), |
| 2136 | account_get_ladder_losses(account, clienttag_uint, ladder_id_normal), |
| 2137 | account_get_ladder_disconnects(account, clienttag_uint, ladder_id_normal), |
| 2138 | account_get_ladder_rating(account, clienttag_uint, ladder_id_normal)); |
| 2139 | else |
| 2140 | msgtemp = localize(c, "Ladder games: 0-0-0"); |
| 2141 | message_send_text(c, message_type_info, c, msgtemp); |
| 2142 | if (account_get_ladder_rating(account, clienttag_uint, ladder_id_ironman) > 0) |
| 2143 | msgtemp = localize(c, "IronMan games: {}-{}-{} (rating {})", |
| 2144 | account_get_ladder_wins(account, clienttag_uint, ladder_id_ironman), |
| 2145 | account_get_ladder_losses(account, clienttag_uint, ladder_id_ironman), |
| 2146 | account_get_ladder_disconnects(account, clienttag_uint, ladder_id_ironman), |
| 2147 | account_get_ladder_rating(account, clienttag_uint, ladder_id_ironman)); |
| 2148 | else |
| 2149 | msgtemp = localize(c, "IronMan games: 0-0-0"); |
| 2150 | message_send_text(c, message_type_info, c, msgtemp); |
| 2151 | return 0; |
| 2152 | case CLIENTTAG_WARCRAFT3_UINT: |
| 2153 | case CLIENTTAG_WAR3XP_UINT: |
| 2154 | msgtemp = localize(c, "{}'s Ladder Record's:", account_get_name(account)); |
| 2155 | message_send_text(c, message_type_info, c, msgtemp); |
| 2156 | msgtemp = localize(c, "Users Solo Level: {}, Experience: {}", |
| 2157 | account_get_ladder_level(account, clienttag_uint, ladder_id_solo), |
| 2158 | account_get_ladder_xp(account, clienttag_uint, ladder_id_solo)); |
| 2159 | message_send_text(c, message_type_info, c, msgtemp); |
| 2160 | msgtemp = localize(c, "SOLO Ladder Record: {}-{}-0", |
| 2161 | account_get_ladder_wins(account, clienttag_uint, ladder_id_solo), |
| 2162 | account_get_ladder_losses(account, clienttag_uint, ladder_id_solo)); |
| 2163 | message_send_text(c, message_type_info, c, msgtemp); |
| 2164 | msgtemp = localize(c, "SOLO Rank: {}", |
| 2165 | account_get_ladder_rank(account, clienttag_uint, ladder_id_solo)); |
| 2166 | message_send_text(c, message_type_info, c, msgtemp); |
| 2167 | msgtemp = localize(c, "Users Team Level: {}, Experience: {}", |
| 2168 | account_get_ladder_level(account, clienttag_uint, ladder_id_team), |
| 2169 | account_get_ladder_xp(account, clienttag_uint, ladder_id_team)); |
| 2170 | message_send_text(c, message_type_info, c, msgtemp); |
| 2171 | msgtemp = localize(c, "TEAM Ladder Record: {}-{}-0", |
| 2172 | account_get_ladder_wins(account, clienttag_uint, ladder_id_team), |
| 2173 | account_get_ladder_losses(account, clienttag_uint, ladder_id_team)); |
| 2174 | message_send_text(c, message_type_info, c, msgtemp); |
| 2175 | msgtemp = localize(c, "TEAM Rank: {}", |
| 2176 | account_get_ladder_rank(account, clienttag_uint, ladder_id_team)); |
| 2177 | message_send_text(c, message_type_info, c, msgtemp); |
| 2178 | msgtemp = localize(c, "Users FFA Level: {}, Experience: {}", |
| 2179 | account_get_ladder_level(account, clienttag_uint, ladder_id_ffa), |
| 2180 | account_get_ladder_xp(account, clienttag_uint, ladder_id_ffa)); |
| 2181 | message_send_text(c, message_type_info, c, msgtemp); |
| 2182 | msgtemp = localize(c, "FFA Ladder Record: {}-{}-0", |
| 2183 | account_get_ladder_wins(account, clienttag_uint, ladder_id_ffa), |
| 2184 | account_get_ladder_losses(account, clienttag_uint, ladder_id_ffa)); |
| 2185 | message_send_text(c, message_type_info, c, msgtemp); |
| 2186 | msgtemp = localize(c, "FFA Rank: {}", |
| 2187 | account_get_ladder_rank(account, clienttag_uint, ladder_id_ffa)); |
| 2188 | message_send_text(c, message_type_info, c, msgtemp); |
| 2189 | if (account_get_teams(account)) { |
| 2190 | t_elem * curr; |
| 2191 | t_list * list; |
| 2192 | t_team * team; |
| 2193 | int teamcount = 0; |
| 2194 | |
| 2195 | list = account_get_teams(account); |
| 2196 | |
| 2197 | LIST_TRAVERSE(list, curr) |
| 2198 | { |
| 2199 | if (!(team = (t_team*)elem_get_data(curr))) |
| 2200 | { |
| 2201 | eventlog(eventlog_level_error, __FUNCTION__, "found NULL entry in list"); |
| 2202 | continue; |
| 2203 | } |
| 2204 | |
| 2205 | if (team_get_clienttag(team) != clienttag_uint) |
| 2206 | continue; |
| 2207 | |
| 2208 | teamcount++; |
| 2209 | msgtemp = localize(c, "Users AT Team No. {}", teamcount); |
| 2210 | message_send_text(c, message_type_info, c, msgtemp); |
| 2211 | msgtemp = localize(c, "Users AT TEAM Level: {}, Experience: {}", |
| 2212 | team_get_level(team), team_get_xp(team)); |
| 2213 | message_send_text(c, message_type_info, c, msgtemp); |
| 2214 | msgtemp = localize(c, "AT TEAM Ladder Record: {}-{}-0", |
| 2215 | team_get_wins(team), team_get_losses(team)); |
| 2216 | message_send_text(c, message_type_info, c, msgtemp); |
| 2217 | msgtemp = localize(c, "AT TEAM Rank: {}", |
| 2218 | team_get_rank(team)); |
| 2219 | message_send_text(c, message_type_info, c, msgtemp); |
| 2220 | } |
| 2221 | } |
| 2222 | return 0; |
| 2223 | default: |
| 2224 | msgtemp = localize(c, "{}'s record:", account_get_name(account)); |
| 2225 | message_send_text(c, message_type_info, c, msgtemp); |
| 2226 | msgtemp = localize(c, "Normal games: {}-{}-{}", |
| 2227 | account_get_normal_wins(account, clienttag_uint), |
| 2228 | account_get_normal_losses(account, clienttag_uint), |
| 2229 | account_get_normal_disconnects(account, clienttag_uint)); |
| 2230 | message_send_text(c, message_type_info, c, msgtemp); |
| 2231 | if (account_get_ladder_rating(account, clienttag_uint, ladder_id_normal) > 0) |
| 2232 | msgtemp = localize(c, "Ladder games: {}-{}-{} (rating {})", |
| 2233 | account_get_ladder_wins(account, clienttag_uint, ladder_id_normal), |
| 2234 | account_get_ladder_losses(account, clienttag_uint, ladder_id_normal), |
| 2235 | account_get_ladder_disconnects(account, clienttag_uint, ladder_id_normal), |
| 2236 | account_get_ladder_rating(account, clienttag_uint, ladder_id_normal)); |
| 2237 | else |
| 2238 | msgtemp = localize(c, "Ladder games: 0-0-0"); |
| 2239 | message_send_text(c, message_type_info, c, msgtemp); |
| 2240 | return 0; |
| 2241 | } |
| 2242 | } |
| 2243 | |
| 2244 | static int _handle_time_command(t_connection * c, char const *text) |
| 2245 | { |
| 2246 | t_bnettime btsystem; |
| 2247 | t_bnettime btlocal; |
| 2248 | std::time_t now; |
| 2249 | struct std::tm * tmnow; |
| 2250 | |
| 2251 | btsystem = bnettime(); |
| 2252 | |
| 2253 | /* Battle.net time: Wed Jun 23 15:15:29 */ |
| 2254 | btlocal = bnettime_add_tzbias(btsystem, local_tzbias()); |
| 2255 | now = bnettime_to_time(btlocal); |
| 2256 | if (!(tmnow = std::gmtime(&now))) |
| 2257 | std::strcpy(msgtemp0, "?"); |
| 2258 | else |
| 2259 | std::strftime(msgtemp0, sizeof(msgtemp0), "%a %b %d %H:%M:%S", tmnow); |
| 2260 | msgtemp = localize(c, "Server Time: {}", msgtemp0); |
| 2261 | message_send_text(c, message_type_info, c, msgtemp); |
| 2262 | if (conn_get_class(c) == conn_class_bnet) |
| 2263 | { |
| 2264 | btlocal = bnettime_add_tzbias(btsystem, conn_get_tzbias(c)); |
| 2265 | now = bnettime_to_time(btlocal); |
| 2266 | if (!(tmnow = std::gmtime(&now))) |
| 2267 | std::strcpy(msgtemp0, "?"); |
| 2268 | else |
| 2269 | std::strftime(msgtemp0, sizeof(msgtemp0), "%a %b %d %H:%M:%S", tmnow); |
| 2270 | msgtemp = localize(c, "Your local time: {}", msgtemp0); |
| 2271 | message_send_text(c, message_type_info, c, msgtemp); |
| 2272 | } |
| 2273 | |
| 2274 | return 0; |
| 2275 | } |
| 2276 | |
| 2277 | static int _handle_channel_command(t_connection * c, char const *text) |
| 2278 | { |
| 2279 | t_channel * channel; |
| 2280 | |
| 2281 | std::vector<std::string> args = split_command(text, 1); |
| 2282 | |
| 2283 | if (args[1].empty()) |
| 2284 | { |
| 2285 | describe_command(c, args[0].c_str()); |
| 2286 | return -1; |
| 2287 | } |
| 2288 | text = args[1].c_str(); // channelname |
| 2289 | |
| 2290 | if (!conn_get_game(c)) { |
| 2291 | if (strcasecmp(text, "Arranged Teams") == 0) |
| 2292 | { |
| 2293 | message_send_text(c, message_type_error, c, msgtemp = localize(c, "Channel Arranged Teams is a RESTRICTED Channel!")); |
| 2294 | return -1; |
| 2295 | } |
| 2296 | |
| 2297 | if (!(std::strlen(text) < MAX_CHANNELNAME_LEN)) |
| 2298 | { |
| 2299 | msgtemp = localize(c, "Max channel name length exceeded (max {} symbols)", MAX_CHANNELNAME_LEN - 1); |
| 2300 | message_send_text(c, message_type_error, c, msgtemp); |
| 2301 | return -1; |
| 2302 | } |
| 2303 | |
| 2304 | if ((channel = conn_get_channel(c)) && (strcasecmp(channel_get_name(channel), text) == 0)) |
| 2305 | return -1; // we don't have to do anything, we are already in this channel |
| 2306 | |
| 2307 | if (conn_set_channel(c, text) < 0) |
| 2308 | conn_set_channel(c, CHANNEL_NAME_BANNED); /* should not fail */ |
| 2309 | if ((conn_get_clienttag(c) == CLIENTTAG_WARCRAFT3_UINT) || (conn_get_clienttag(c) == CLIENTTAG_WAR3XP_UINT)) |
| 2310 | conn_update_w3_playerinfo(c); |
| 2311 | command_set_flags(c); |
| 2312 | } |
| 2313 | else |
| 2314 | message_send_text(c, message_type_error, c, localize(c, "Command disabled while inside a game.")); |
| 2315 | |
| 2316 | return 0; |
| 2317 | } |
| 2318 | |
| 2319 | static int _handle_rejoin_command(t_connection * c, char const *text) |
| 2320 | { |
| 2321 | |
| 2322 | if (channel_rejoin(c) != 0) |
| 2323 | message_send_text(c, message_type_error, c, localize(c, "You are not in a channel.")); |
| 2324 | if ((conn_get_clienttag(c) == CLIENTTAG_WARCRAFT3_UINT) || (conn_get_clienttag(c) == CLIENTTAG_WAR3XP_UINT)) |
| 2325 | conn_update_w3_playerinfo(c); |
| 2326 | command_set_flags(c); |
| 2327 | |
| 2328 | return 0; |
| 2329 | } |
| 2330 | |
| 2331 | static int _handle_away_command(t_connection * c, char const *text) |
| 2332 | { |
| 2333 | std::vector<std::string> args = split_command(text, 1); |
| 2334 | text = args[1].c_str(); // message |
| 2335 | |
| 2336 | if (text[0] == '\0') /* toggle away mode */ |
| 2337 | { |
| 2338 | if (!conn_get_awaystr(c)) |
| 2339 | { |
| 2340 | message_send_text(c, message_type_info, c, localize(c, "You are now marked as being away.")); |
| 2341 | conn_set_awaystr(c, "Currently not available"); |
| 2342 | } |
| 2343 | else |
| 2344 | { |
| 2345 | message_send_text(c, message_type_info, c, localize(c, "You are no longer marked as away.")); |
| 2346 | conn_set_awaystr(c, NULL); |
| 2347 | } |
| 2348 | } |
| 2349 | else |
| 2350 | { |
| 2351 | message_send_text(c, message_type_info, c, localize(c, "You are now marked as being away.")); |
| 2352 | conn_set_awaystr(c, text); |
| 2353 | } |
| 2354 | |
| 2355 | return 0; |
| 2356 | } |
| 2357 | |
| 2358 | static int _handle_dnd_command(t_connection * c, char const *text) |
| 2359 | { |
| 2360 | std::vector<std::string> args = split_command(text, 1); |
| 2361 | text = args[1].c_str(); // message |
| 2362 | |
| 2363 | if (text[0] == '\0') /* toggle dnd mode */ |
| 2364 | { |
| 2365 | if (!conn_get_dndstr(c)) |
| 2366 | { |
| 2367 | message_send_text(c, message_type_info, c, localize(c, "Do Not Disturb mode engaged.")); |
| 2368 | conn_set_dndstr(c, localize(c, "Not available").c_str()); |
| 2369 | } |
| 2370 | else |
| 2371 | { |
| 2372 | message_send_text(c, message_type_info, c, localize(c, "Do Not Disturb mode canceled.")); |
| 2373 | conn_set_dndstr(c, NULL); |
| 2374 | } |
| 2375 | } |
| 2376 | else |
| 2377 | { |
| 2378 | message_send_text(c, message_type_info, c, localize(c, "Do Not Disturb mode engaged.")); |
| 2379 | conn_set_dndstr(c, text); |
| 2380 | } |
| 2381 | |
| 2382 | return 0; |
| 2383 | } |
| 2384 | |
| 2385 | static int _handle_squelch_command(t_connection * c, char const *text) |
| 2386 | { |
| 2387 | t_account * account; |
| 2388 | |
| 2389 | std::vector<std::string> args = split_command(text, 1); |
| 2390 | |
| 2391 | if (args[1].empty()) |
| 2392 | { |
| 2393 | describe_command(c, args[0].c_str()); |
| 2394 | return -1; |
| 2395 | } |
| 2396 | text = args[1].c_str(); // username |
| 2397 | |
| 2398 | /* D2 std::puts * before username */ |
| 2399 | if (text[0] == '*') |
| 2400 | text++; |
| 2401 | |
| 2402 | if (!(account = accountlist_find_account(text))) |
| 2403 | { |
| 2404 | message_send_text(c, message_type_error, c, localize(c, "No such user.")); |
| 2405 | return -1; |
| 2406 | } |
| 2407 | |
| 2408 | if (conn_get_account(c) == account) |
| 2409 | { |
| 2410 | message_send_text(c, message_type_error, c, localize(c, "You can't squelch yourself.")); |
| 2411 | return -1; |
| 2412 | } |
| 2413 | |
| 2414 | if (conn_add_ignore(c, account) < 0) |
| 2415 | { |
| 2416 | message_send_text(c, message_type_error, c, localize(c, "Could not squelch user.")); |
| 2417 | return -1; |
| 2418 | } |
| 2419 | else |
| 2420 | { |
| 2421 | msgtemp = localize(c, "{} has been squelched.", account_get_name(account)); |
| 2422 | message_send_text(c, message_type_info, c, msgtemp); |
| 2423 | } |
| 2424 | |
| 2425 | return 0; |
| 2426 | } |
| 2427 | |
| 2428 | static int _handle_unsquelch_command(t_connection * c, char const *text) |
| 2429 | { |
| 2430 | t_account * account; |
| 2431 | t_connection * dest_c; |
| 2432 | |
| 2433 | std::vector<std::string> args = split_command(text, 1); |
| 2434 | |
| 2435 | if (args[1].empty()) |
| 2436 | { |
| 2437 | describe_command(c, args[0].c_str()); |
| 2438 | return -1; |
| 2439 | } |
| 2440 | text = args[1].c_str(); // username |
| 2441 | |
| 2442 | /* D2 std::puts * before username */ |
| 2443 | if (text[0] == '*') |
| 2444 | text++; |
| 2445 | |
| 2446 | if (!(account = accountlist_find_account(text))) |
| 2447 | { |
| 2448 | message_send_text(c, message_type_info, c, localize(c, "No such user.")); |
| 2449 | return -1; |
| 2450 | } |
| 2451 | |
| 2452 | if (conn_del_ignore(c, account) < 0) |
| 2453 | { |
| 2454 | message_send_text(c, message_type_info, c, localize(c, "User was not being ignored.")); |
| 2455 | return -1; |
| 2456 | } |
| 2457 | else |
| 2458 | { |
| 2459 | t_message * message; |
| 2460 | |
| 2461 | message_send_text(c, message_type_info, c, localize(c, "No longer ignoring.")); |
| 2462 | |
| 2463 | if ((dest_c = account_get_conn(account))) |
| 2464 | { |
| 2465 | if (!(message = message_create(message_type_userflags, dest_c, NULL))) /* handles NULL text */ |
| 2466 | return -1; |
| 2467 | message_send(message, c); |
| 2468 | message_destroy(message); |
| 2469 | } |
| 2470 | } |
| 2471 | |
| 2472 | return 0; |
| 2473 | } |
| 2474 | |
| 2475 | static int _handle_kick_command(t_connection * c, char const *text) |
| 2476 | { |
| 2477 | char const * username; |
| 2478 | t_channel const * channel; |
| 2479 | t_connection * kuc; |
| 2480 | t_account * acc; |
| 2481 | |
| 2482 | std::vector<std::string> args = split_command(text, 2); |
| 2483 | |
| 2484 | if (args[1].empty()) |
| 2485 | { |
| 2486 | describe_command(c, args[0].c_str()); |
| 2487 | return -1; |
| 2488 | } |
| 2489 | username = args[1].c_str(); // username |
| 2490 | text = args[2].c_str(); // reason |
| 2491 | |
| 2492 | if (!(channel = conn_get_channel(c))) |
| 2493 | { |
| 2494 | message_send_text(c, message_type_error, c, localize(c, "This command can only be used inside a channel.")); |
| 2495 | return -1; |
| 2496 | } |
| 2497 | |
| 2498 | acc = conn_get_account(c); |
| 2499 | if (account_get_auth_admin(acc, NULL) != 1 && /* default to false */ |
| 2500 | account_get_auth_admin(acc, channel_get_name(channel)) != 1 && /* default to false */ |
| 2501 | account_get_auth_operator(acc, NULL) != 1 && /* default to false */ |
| 2502 | account_get_auth_operator(acc, channel_get_name(channel)) != 1 && /* default to false */ |
| 2503 | !channel_conn_is_tmpOP(channel, account_get_conn(acc))) |
| 2504 | { |
| 2505 | message_send_text(c, message_type_error, c, localize(c, "You have to be at least a Channel Operator or tempOP to use this command.")); |
| 2506 | return -1; |
| 2507 | } |
| 2508 | if (!(kuc = connlist_find_connection_by_accountname(username))) |
| 2509 | { |
| 2510 | message_send_text(c, message_type_error, c, localize(c, "That user is not logged in.")); |
| 2511 | return -1; |
| 2512 | } |
| 2513 | if (conn_get_channel(kuc) != channel) |
| 2514 | { |
| 2515 | message_send_text(c, message_type_error, c, localize(c, "That user is not in this channel.")); |
| 2516 | return -1; |
| 2517 | } |
| 2518 | if (account_get_auth_admin(conn_get_account(kuc), NULL) == 1 || |
| 2519 | account_get_auth_admin(conn_get_account(kuc), channel_get_name(channel)) == 1) |
| 2520 | { |
| 2521 | message_send_text(c, message_type_error, c, localize(c, "You cannot kick administrators.")); |
| 2522 | return -1; |
| 2523 | } |
| 2524 | else if (account_get_auth_operator(conn_get_account(kuc), NULL) == 1 || |
| 2525 | account_get_auth_operator(conn_get_account(kuc), channel_get_name(channel)) == 1) |
| 2526 | { |
| 2527 | message_send_text(c, message_type_error, c, localize(c, "You cannot kick operators.")); |
| 2528 | return -1; |
| 2529 | } |
| 2530 | |
| 2531 | { |
| 2532 | char const * tname1; |
| 2533 | char const * tname2; |
| 2534 | |
| 2535 | tname1 = conn_get_loggeduser(kuc); |
| 2536 | tname2 = conn_get_loggeduser(c); |
| 2537 | if (!tname1 || !tname2) { |
| 2538 | eventlog(eventlog_level_error, __FUNCTION__, "got NULL username"); |
| 2539 | return -1; |
| 2540 | } |
| 2541 | |
| 2542 | if (text[0] != '\0') |
| 2543 | msgtemp = localize(c, "{} has been kicked by {} ({}).", tname1, tname2, text); |
| 2544 | else |
| 2545 | msgtemp = localize(c, "{} has been kicked by {}.", tname1, tname2); |
| 2546 | channel_message_send(channel, message_type_info, c, msgtemp.c_str()); |
| 2547 | } |
| 2548 | conn_kick_channel(kuc, "Bye"); |
| 2549 | if (conn_get_class(kuc) == conn_class_bnet) |
| 2550 | conn_set_channel(kuc, CHANNEL_NAME_KICKED); /* should not fail */ |
| 2551 | |
| 2552 | return 0; |
| 2553 | } |
| 2554 | |
| 2555 | static int _handle_ban_command(t_connection * c, char const *text) |
| 2556 | { |
| 2557 | char const * username; |
| 2558 | t_channel * channel; |
| 2559 | t_connection * buc; |
| 2560 | |
| 2561 | std::vector<std::string> args = split_command(text, 2); |
| 2562 | |
| 2563 | if (args[1].empty()) |
| 2564 | { |
| 2565 | describe_command(c, args[0].c_str()); |
| 2566 | return -1; |
| 2567 | } |
| 2568 | username = args[1].c_str(); // username |
| 2569 | text = args[2].c_str(); // reason |
| 2570 | |
| 2571 | if (!(channel = conn_get_channel(c))) |
| 2572 | { |
| 2573 | message_send_text(c, message_type_error, c, localize(c, "This command can only be used inside a channel.")); |
| 2574 | return -1; |
| 2575 | } |
| 2576 | if (account_get_auth_admin(conn_get_account(c), NULL) != 1 && /* default to false */ |
| 2577 | account_get_auth_admin(conn_get_account(c), channel_get_name(channel)) != 1 && /* default to false */ |
| 2578 | account_get_auth_operator(conn_get_account(c), NULL) != 1 && /* default to false */ |
| 2579 | account_get_auth_operator(conn_get_account(c), channel_get_name(channel)) != 1) /* default to false */ |
| 2580 | { |
| 2581 | message_send_text(c, message_type_error, c, localize(c, "You have to be at least a Channel Operator to use this command.")); |
| 2582 | return -1; |
| 2583 | } |
| 2584 | { |
| 2585 | t_account * account; |
| 2586 | |
| 2587 | if (!(account = accountlist_find_account(username))) |
| 2588 | { |
| 2589 | message_send_text(c, message_type_info, c, localize(c, "That account doesn't currently exist.")); |
| 2590 | return -1; |
| 2591 | } |
| 2592 | else if (account_get_auth_admin(account, NULL) == 1 || account_get_auth_admin(account, channel_get_name(channel)) == 1) |
| 2593 | { |
| 2594 | message_send_text(c, message_type_error, c, localize(c, "You cannot ban administrators.")); |
| 2595 | return -1; |
| 2596 | } |
| 2597 | else if (account_get_auth_operator(account, NULL) == 1 || |
| 2598 | account_get_auth_operator(account, channel_get_name(channel)) == 1) |
| 2599 | { |
| 2600 | message_send_text(c, message_type_error, c, localize(c, "You cannot ban operators.")); |
| 2601 | return -1; |
| 2602 | } |
| 2603 | } |
| 2604 | |
| 2605 | if (channel_ban_user(channel, username) < 0) |
| 2606 | { |
| 2607 | msgtemp = localize(c, "Unable to ban {}.", username); |
| 2608 | message_send_text(c, message_type_error, c, msgtemp); |
| 2609 | } |
| 2610 | else |
| 2611 | { |
| 2612 | char const * tname; |
| 2613 | |
| 2614 | tname = conn_get_loggeduser(c); |
| 2615 | if (text[0] != '\0') |
| 2616 | msgtemp = localize(c, "{} has been banned by {} ({}).", username, tname ? tname : "unknown", text); |
| 2617 | else |
| 2618 | msgtemp = localize(c, "{} has been banned by {}.", username, tname ? tname : "unknown"); |
| 2619 | channel_message_send(channel, message_type_info, c, msgtemp.c_str()); |
| 2620 | } |
| 2621 | if ((buc = connlist_find_connection_by_accountname(username)) && |
| 2622 | conn_get_channel(buc) == channel) |
| 2623 | conn_set_channel(buc, CHANNEL_NAME_BANNED); |
| 2624 | |
| 2625 | return 0; |
| 2626 | } |
| 2627 | |
| 2628 | static int _handle_unban_command(t_connection * c, char const *text) |
| 2629 | { |
| 2630 | t_channel * channel; |
| 2631 | |
| 2632 | std::vector<std::string> args = split_command(text, 1); |
| 2633 | |
| 2634 | if (args[1].empty()) |
| 2635 | { |
| 2636 | describe_command(c, args[0].c_str()); |
| 2637 | return -1; |
| 2638 | } |
| 2639 | text = args[1].c_str(); // username |
| 2640 | |
| 2641 | if (!(channel = conn_get_channel(c))) |
| 2642 | { |
| 2643 | message_send_text(c, message_type_error, c, localize(c, "This command can only be used inside a channel.")); |
| 2644 | return -1; |
| 2645 | } |
| 2646 | if (account_get_auth_admin(conn_get_account(c), NULL) != 1 && /* default to false */ |
| 2647 | account_get_auth_admin(conn_get_account(c), channel_get_name(channel)) != 1 && /* default to false */ |
| 2648 | account_get_auth_operator(conn_get_account(c), NULL) != 1 && /* default to false */ |
| 2649 | account_get_auth_operator(conn_get_account(c), channel_get_name(channel)) != 1) /* default to false */ |
| 2650 | { |
| 2651 | message_send_text(c, message_type_error, c, localize(c, "You are not a channel operator.")); |
| 2652 | return -1; |
| 2653 | } |
| 2654 | |
| 2655 | if (channel_unban_user(channel, text) < 0) |
| 2656 | { |
| 2657 | message_send_text(c, message_type_error, c, localize(c, "That user is not banned.")); |
| 2658 | return -1; |
| 2659 | } |
| 2660 | else |
| 2661 | { |
| 2662 | msgtemp = localize(c, "{} is no longer banned from this channel.", text); |
| 2663 | message_send_text(c, message_type_info, c, msgtemp); |
| 2664 | } |
| 2665 | |
| 2666 | return 0; |
| 2667 | } |
| 2668 | |
| 2669 | static int _handle_reply_command(t_connection * c, char const *text) |
| 2670 | { |
| 2671 | char const * dest; |
| 2672 | |
| 2673 | if (!(dest = conn_get_lastsender(c))) |
| 2674 | { |
| 2675 | message_send_text(c, message_type_error, c, localize(c, "No one messaged you, use /m instead")); |
| 2676 | return -1; |
| 2677 | } |
| 2678 | |
| 2679 | std::vector<std::string> args = split_command(text, 1); |
| 2680 | |
| 2681 | if (args[1].empty()) |
| 2682 | { |
| 2683 | describe_command(c, args[0].c_str()); |
| 2684 | return -1; |
| 2685 | } |
| 2686 | text = args[1].c_str(); // message |
| 2687 | |
| 2688 | do_whisper(c, dest, text); |
| 2689 | return 0; |
| 2690 | } |
| 2691 | |
| 2692 | static int _handle_realmann_command(t_connection * c, char const *text) |
| 2693 | { |
| 2694 | t_realm * realm; |
| 2695 | t_realm * trealm; |
| 2696 | t_connection * tc; |
| 2697 | t_elem const * curr; |
| 2698 | t_message * message; |
| 2699 | |
| 2700 | if (!(realm = conn_get_realm(c))) { |
| 2701 | message_send_text(c, message_type_info, c, localize(c, "You must join a realm first")); |
| 2702 | return -1; |
| 2703 | } |
| 2704 | |
| 2705 | std::vector<std::string> args = split_command(text, 1); |
| 2706 | |
| 2707 | if (args[1].empty()) |
| 2708 | { |
| 2709 | describe_command(c, args[0].c_str()); |
| 2710 | return -1; |
| 2711 | } |
| 2712 | text = args[1].c_str(); // message |
| 2713 | |
| 2714 | msgtemp = localize(c, "Announcement from {}@{}: {}", conn_get_username(c), realm_get_name(realm), text); |
| 2715 | if (!(message = message_create(message_type_broadcast, c, msgtemp.c_str()))) |
| 2716 | { |
| 2717 | message_send_text(c, message_type_info, c, "Could not broadcast message."); |
| 2718 | return -1; |
| 2719 | } |
| 2720 | else |
| 2721 | { |
| 2722 | LIST_TRAVERSE_CONST(connlist(), curr) |
| 2723 | { |
| 2724 | tc = (t_connection*)elem_get_data(curr); |
| 2725 | if (!tc) |
| 2726 | continue; |
| 2727 | if ((trealm = conn_get_realm(tc)) && (trealm == realm)) |
| 2728 | { |
| 2729 | message_send(message, tc); |
| 2730 | } |
| 2731 | } |
| 2732 | } |
| 2733 | |
| 2734 | message_destroy(message); |
| 2735 | |
| 2736 | return 0; |
| 2737 | } |
| 2738 | |
| 2739 | static int _handle_watch_command(t_connection * c, char const *text) |
| 2740 | { |
| 2741 | t_account * account; |
| 2742 | |
| 2743 | std::vector<std::string> args = split_command(text, 1); |
| 2744 | |
| 2745 | if (args[1].empty()) |
| 2746 | { |
| 2747 | describe_command(c, args[0].c_str()); |
| 2748 | return -1; |
| 2749 | } |
| 2750 | text = args[1].c_str(); // username |
| 2751 | |
| 2752 | if (!(account = accountlist_find_account(text))) |
| 2753 | { |
| 2754 | message_send_text(c, message_type_info, c, localize(c, "That user does not exist.")); |
| 2755 | return -1; |
| 2756 | } |
| 2757 | |
| 2758 | if (conn_add_watch(c, account, 0) < 0) /* FIXME: adds all events for now */ |
| 2759 | { |
| 2760 | message_send_text(c, message_type_error, c, localize(c, "Add to watch list failed.")); |
| 2761 | return -1; |
| 2762 | } |
| 2763 | else |
| 2764 | { |
| 2765 | msgtemp = localize(c, "User {} added to your watch list.", text); |
| 2766 | message_send_text(c, message_type_info, c, msgtemp); |
| 2767 | } |
| 2768 | |
| 2769 | return 0; |
| 2770 | } |
| 2771 | |
| 2772 | static int _handle_unwatch_command(t_connection * c, char const *text) |
| 2773 | { |
| 2774 | t_account * account; |
| 2775 | |
| 2776 | std::vector<std::string> args = split_command(text, 1); |
| 2777 | |
| 2778 | if (args[1].empty()) |
| 2779 | { |
| 2780 | describe_command(c, args[0].c_str()); |
| 2781 | return -1; |
| 2782 | } |
| 2783 | text = args[1].c_str(); // username |
| 2784 | if (!(account = accountlist_find_account(text))) |
| 2785 | { |
| 2786 | message_send_text(c, message_type_info, c, localize(c, "That user does not exist.")); |
| 2787 | return -1; |
| 2788 | } |
| 2789 | |
| 2790 | if (conn_del_watch(c, account, 0) < 0) /* FIXME: deletes all events for now */ |
| 2791 | { |
| 2792 | message_send_text(c, message_type_error, c, localize(c, "Removal from watch list failed.")); |
| 2793 | return -1; |
| 2794 | } |
| 2795 | else |
| 2796 | { |
| 2797 | msgtemp = localize(c, "User {} removed from your watch list.", text); |
| 2798 | message_send_text(c, message_type_info, c, msgtemp); |
| 2799 | } |
| 2800 | |
| 2801 | return 0; |
| 2802 | } |
| 2803 | |
| 2804 | static int _handle_watchall_command(t_connection * c, char const *text) |
| 2805 | { |
| 2806 | t_clienttag clienttag = 0; |
| 2807 | char const * clienttag_str; |
| 2808 | |
| 2809 | std::vector<std::string> args = split_command(text, 1); |
| 2810 | clienttag_str = args[1].c_str(); // clienttag |
| 2811 | |
| 2812 | if (clienttag_str[0] != '\0') |
| 2813 | { |
| 2814 | if ( !(clienttag = tag_validate_client(args[1].c_str())) ) |
| 2815 | { |
| 2816 | describe_command(c, args[0].c_str()); |
| 2817 | return -1; |
| 2818 | } |
| 2819 | } |
| 2820 | |
| 2821 | if (conn_add_watch(c, NULL, clienttag) < 0) /* FIXME: adds all events for now */ |
| 2822 | message_send_text(c, message_type_error, c, localize(c, "Add to watch list failed.")); |
| 2823 | else |
| 2824 | if (clienttag) { |
| 2825 | msgtemp = localize(c, "All {} users added to your watch list.", tag_uint_to_str((char*)clienttag_str, clienttag)); |
| 2826 | message_send_text(c, message_type_info, c, msgtemp); |
| 2827 | } |
| 2828 | else |
| 2829 | message_send_text(c, message_type_info, c, localize(c, "All users added to your watch list.")); |
| 2830 | |
| 2831 | return 0; |
| 2832 | } |
| 2833 | |
| 2834 | static int _handle_unwatchall_command(t_connection * c, char const *text) |
| 2835 | { |
| 2836 | t_clienttag clienttag = 0; |
| 2837 | char const * clienttag_str; |
| 2838 | |
| 2839 | std::vector<std::string> args = split_command(text, 1); |
| 2840 | clienttag_str = args[1].c_str(); // clienttag |
| 2841 | |
| 2842 | if (clienttag_str[0] != '\0') |
| 2843 | { |
| 2844 | if (!(clienttag = tag_validate_client(args[1].c_str()))) |
| 2845 | { |
| 2846 | describe_command(c, args[0].c_str()); |
| 2847 | return -1; |
| 2848 | } |
| 2849 | } |
| 2850 | |
| 2851 | if (conn_del_watch(c, NULL, clienttag) < 0) /* FIXME: deletes all events for now */ |
| 2852 | message_send_text(c, message_type_error, c, localize(c, "Removal from watch list failed.")); |
| 2853 | else |
| 2854 | if (clienttag) { |
| 2855 | msgtemp = localize(c, "All {} users removed from your watch list.", tag_uint_to_str((char*)clienttag_str, clienttag)); |
| 2856 | message_send_text(c, message_type_info, c, msgtemp); |
| 2857 | } |
| 2858 | else |
| 2859 | message_send_text(c, message_type_info, c, localize(c, "All users removed from your watch list.")); |
| 2860 | |
| 2861 | return 0; |
| 2862 | } |
| 2863 | |
| 2864 | static int _handle_lusers_command(t_connection * c, char const *text) |
| 2865 | { |
| 2866 | t_channel * channel; |
| 2867 | t_elem const * curr; |
| 2868 | char const * banned; |
| 2869 | unsigned int i; |
| 2870 | |
| 2871 | if (!(channel = conn_get_channel(c))) |
| 2872 | { |
| 2873 | message_send_text(c, message_type_error, c, localize(c, "This command can only be used inside a channel.")); |
| 2874 | return -1; |
| 2875 | } |
| 2876 | |
| 2877 | std::snprintf(msgtemp0, sizeof msgtemp0, "%s", localize(c, "Banned users:").c_str()); |
| 2878 | i = std::strlen(msgtemp0); |
| 2879 | LIST_TRAVERSE_CONST(channel_get_banlist(channel), curr) |
| 2880 | { |
| 2881 | banned = (char*)elem_get_data(curr); |
| 2882 | if (i + std::strlen(banned) + 2 > sizeof(msgtemp0)) /* " ", name, '\0' */ |
| 2883 | { |
| 2884 | message_send_text(c, message_type_info, c, msgtemp0); |
| 2885 | i = 0; |
| 2886 | } |
| 2887 | std::sprintf(&msgtemp0[i], " %s", banned); |
| 2888 | i += std::strlen(&msgtemp0[i]); |
| 2889 | } |
| 2890 | if (i > 0) |
| 2891 | message_send_text(c, message_type_info, c, msgtemp0); |
| 2892 | |
| 2893 | return 0; |
| 2894 | } |
| 2895 | |
| 2896 | static int _news_cb(std::time_t date, t_lstr *lstr, void *data) |
| 2897 | { |
| 2898 | char strdate[64]; |
| 2899 | struct std::tm *tm; |
| 2900 | char save, *p, *q; |
| 2901 | t_connection *c = (t_connection*)data; |
| 2902 | |
| 2903 | tm = std::localtime(&date); |
| 2904 | if (tm) |
| 2905 | std::strftime(strdate, 64, "%B %d, %Y", tm); |
| 2906 | else |
| 2907 | std::snprintf(strdate, sizeof strdate, "%s", localize(c, "(invalid date)").c_str()); |
| 2908 | |
| 2909 | message_send_text(c, message_type_info, c, strdate); |
| 2910 | |
| 2911 | for (p = lstr_get_str(lstr); *p;) { |
| 2912 | for (q = p; *q && *q != '\r' && *q != '\n'; q++); |
| 2913 | save = *q; |
| 2914 | *q = '\0'; |
| 2915 | message_send_text(c, message_type_info, c, p); |
| 2916 | *q = save; |
| 2917 | p = q; |
| 2918 | for (; *p == '\n' || *p == '\r'; p++); |
| 2919 | } |
| 2920 | |
| 2921 | return 0; |
| 2922 | } |
| 2923 | |
| 2924 | static int _handle_news_command(t_connection * c, char const *text) |
| 2925 | { |
| 2926 | news_traverse(_news_cb, c); |
| 2927 | return 0; |
| 2928 | } |
| 2929 | |
| 2930 | struct glist_cb_struct { |
| 2931 | t_game_difficulty diff; |
| 2932 | t_clienttag tag; |
| 2933 | t_connection *c; |
| 2934 | bool lobby; |
| 2935 | }; |
| 2936 | |
| 2937 | static int _glist_cb(t_game *game, void *data) |
| 2938 | { |
| 2939 | auto cbdata = reinterpret_cast<struct glist_cb_struct*>(data); |
| 2940 | |
| 2941 | // when cbdata->tag != 0, user is requesting games of the same client tag |
| 2942 | // return early when the game's client tag does not match the user's client tag |
| 2943 | if (cbdata->tag != 0 && cbdata->tag != game_get_clienttag(game)) |
| 2944 | { |
| 2945 | return 0; |
| 2946 | } |
| 2947 | |
| 2948 | // when cbdata->lobby == true, only display list of all games in the lobby |
| 2949 | // return early if game has started or is already finished |
| 2950 | if (cbdata->lobby == true && (game_get_status(game) == game_status_started || game_get_status(game) == game_status_done)) |
| 2951 | { |
| 2952 | return 0; |
| 2953 | } |
| 2954 | |
| 2955 | // when cbdata->diff != game_difficulty_none, user is requesting a specific game difficulty |
| 2956 | // return early if user is requesting a specific game difficulty that does not match the game's difficulty |
| 2957 | if (cbdata->diff != game_difficulty_none && cbdata->diff != game_get_difficulty(game)) |
| 2958 | { |
| 2959 | return 0; |
| 2960 | } |
| 2961 | |
| 2962 | unsigned int pref = prefs_get_hide_pass_games(); |
| 2963 | if (pref && game_get_flag(game) == game_flag_private) |
| 2964 | { |
| 2965 | // return early if hide_pass_games is true and the game is private |
| 2966 | if (cbdata->tag != 0) |
| 2967 | { |
| 2968 | return 0; |
| 2969 | } |
| 2970 | // if user used /games all and is not an admin, return early |
| 2971 | else if (cbdata->tag == 0 && account_get_auth_admin(conn_get_account(cbdata->c), nullptr) != 1) |
| 2972 | { |
| 2973 | return 0; |
| 2974 | } |
| 2975 | } |
| 2976 | |
| 2977 | |
| 2978 | std::snprintf(msgtemp0, sizeof(msgtemp0), " %-16.16s %1.1s %-8.8s %-21.21s %5u ", |
| 2979 | game_get_name(game), |
| 2980 | game_get_flag(game) != game_flag_private ? "n" : "y", |
| 2981 | game_status_get_str(game_get_status(game)), |
| 2982 | game_type_get_str(game_get_type(game)), |
| 2983 | game_get_ref(game)); |
| 2984 | |
| 2985 | if (!cbdata->tag) |
| 2986 | { |
| 2987 | |
| 2988 | std::strcat(msgtemp0, clienttag_uint_to_str(game_get_clienttag(game))); |
| 2989 | std::strcat(msgtemp0, " "); |
| 2990 | } |
| 2991 | |
| 2992 | if ((!prefs_get_hide_addr()) || (account_get_command_groups(conn_get_account(cbdata->c)) & command_get_group("/admin-addr"))) /* default to false */ |
| 2993 | std::strcat(msgtemp0, addr_num_to_addr_str(game_get_addr(game), game_get_port(game))); |
| 2994 | |
| 2995 | message_send_text(cbdata->c, message_type_info, cbdata->c, msgtemp0); |
| 2996 | |
| 2997 | return 0; |
| 2998 | } |
| 2999 | |
| 3000 | static int _handle_games_command(t_connection * c, char const *text) |
| 3001 | { |
| 3002 | char clienttag_str[5]; |
| 3003 | char const * dest; |
| 3004 | char const * difficulty; |
| 3005 | struct glist_cb_struct cbdata; |
| 3006 | |
| 3007 | std::vector<std::string> args = split_command(text, 2); |
| 3008 | |
| 3009 | dest = args[1].c_str(); // clienttag |
| 3010 | difficulty = args[1].c_str(); // difficulty (only for diablo) |
| 3011 | |
| 3012 | cbdata.c = c; |
| 3013 | cbdata.lobby = false; |
| 3014 | |
| 3015 | if (strcasecmp(difficulty, "norm") == 0) |
| 3016 | cbdata.diff = game_difficulty_normal; |
| 3017 | else if (strcasecmp(difficulty, "night") == 0) |
| 3018 | cbdata.diff = game_difficulty_nightmare; |
| 3019 | else if (strcasecmp(difficulty, "hell") == 0) |
| 3020 | cbdata.diff = game_difficulty_hell; |
| 3021 | else |
| 3022 | cbdata.diff = game_difficulty_none; |
| 3023 | |
| 3024 | if (dest[0] == '\0') |
| 3025 | { |
| 3026 | cbdata.tag = conn_get_clienttag(c); |
| 3027 | message_send_text(c, message_type_info, c, localize(c, "Currently accessible games:")); |
| 3028 | } |
| 3029 | else if (strcasecmp(dest, "all") == 0) |
| 3030 | { |
| 3031 | cbdata.tag = 0; |
| 3032 | message_send_text(c, message_type_info, c, localize(c, "All current games:")); |
| 3033 | } |
| 3034 | else if (strcasecmp(dest, "lobby") == 0 || strcasecmp(dest, "l") == 0) |
| 3035 | { |
| 3036 | cbdata.tag = conn_get_clienttag(c); |
| 3037 | cbdata.lobby = true; |
| 3038 | message_send_text(c, message_type_info, c, localize(c, "Games in lobby:")); |
| 3039 | } |
| 3040 | else |
| 3041 | { |
| 3042 | if (!(cbdata.tag = tag_validate_client(dest))) |
| 3043 | { |
| 3044 | describe_command(c, args[0].c_str()); |
| 3045 | return -1; |
| 3046 | } |
| 3047 | |
| 3048 | if (cbdata.diff == game_difficulty_none) |
| 3049 | msgtemp = localize(c, "Current games of type {}", tag_uint_to_str(clienttag_str, cbdata.tag)); |
| 3050 | else |
| 3051 | msgtemp = localize(c, "Current games of type {} {}", tag_uint_to_str(clienttag_str, cbdata.tag), difficulty); |
| 3052 | message_send_text(c, message_type_info, c, msgtemp); |
| 3053 | } |
| 3054 | |
| 3055 | msgtemp = localize(c, " ------name------ p -status- --------type--------- count "); |
| 3056 | if (!cbdata.tag) |
| 3057 | msgtemp += localize(c, "ctag "); |
| 3058 | if ((!prefs_get_hide_addr()) || (account_get_command_groups(conn_get_account(c)) & command_get_group("/admin-addr"))) /* default to false */ |
| 3059 | msgtemp += localize(c, "--------addr--------"); |
| 3060 | message_send_text(c, message_type_info, c, msgtemp); |
| 3061 | gamelist_traverse(_glist_cb, &cbdata, gamelist_source_none); |
| 3062 | |
| 3063 | return 0; |
| 3064 | } |
| 3065 | |
| 3066 | static int _handle_channels_command(t_connection * c, char const *text) |
| 3067 | { |
| 3068 | t_elem const * curr; |
| 3069 | t_channel const * channel; |
| 3070 | t_clienttag clienttag; |
| 3071 | t_connection const * conn; |
| 3072 | t_account * acc; |
| 3073 | char const * name; |
| 3074 | int first; |
| 3075 | |
| 3076 | std::vector<std::string> args = split_command(text, 1); |
| 3077 | |
| 3078 | if (args[1].empty()) |
| 3079 | { |
| 3080 | describe_command(c, args[0].c_str()); |
| 3081 | return -1; |
| 3082 | } |
| 3083 | text = args[1].c_str(); // clienttag |
| 3084 | |
| 3085 | if (text[0] == '\0') |
| 3086 | { |
| 3087 | clienttag = conn_get_clienttag(c); |
| 3088 | message_send_text(c, message_type_info, c, localize(c, "Currently accessible channels:")); |
| 3089 | } |
| 3090 | else if (strcasecmp(text, "all") == 0) |
| 3091 | { |
| 3092 | clienttag = 0; |
| 3093 | message_send_text(c, message_type_info, c, localize(c, "All current channels:")); |
| 3094 | } |
| 3095 | else |
| 3096 | { |
| 3097 | if (!(clienttag = tag_validate_client(text))) |
| 3098 | { |
| 3099 | describe_command(c, args[0].c_str()); |
| 3100 | return -1; |
| 3101 | } |
| 3102 | msgtemp = localize(c, "Current channels of type {}", text); |
| 3103 | message_send_text(c, message_type_info, c, msgtemp); |
| 3104 | } |
| 3105 | |
| 3106 | msgtemp = localize(c, " -----------name----------- users ----admin/operator----"); |
| 3107 | message_send_text(c, message_type_info, c, msgtemp); |
| 3108 | LIST_TRAVERSE_CONST(channellist(), curr) |
| 3109 | { |
| 3110 | channel = (t_channel*)elem_get_data(curr); |
| 3111 | if ((!(channel_get_flags(channel) & channel_flags_clan)) && (!clienttag || !prefs_get_hide_temp_channels() || channel_get_permanent(channel)) && |
| 3112 | (!clienttag || !channel_get_clienttag(channel) || |
| 3113 | channel_get_clienttag(channel) == clienttag) && |
| 3114 | ((channel_get_max(channel) != 0) || //only show restricted channels to OPs and Admins |
| 3115 | ((channel_get_max(channel) == 0 && account_is_operator_or_admin(conn_get_account(c), NULL)))) && |
| 3116 | (!(channel_get_flags(channel) & channel_flags_thevoid)) // don't list TheVoid |
| 3117 | ) |
| 3118 | { |
| 3119 | |
| 3120 | std::snprintf(msgtemp0, sizeof(msgtemp0), " %-26.26s %5d - ", |
| 3121 | channel_get_name(channel), |
| 3122 | channel_get_length(channel)); |
| 3123 | |
| 3124 | first = 1; |
| 3125 | |
| 3126 | for (conn = channel_get_first(channel); conn; conn = channel_get_next()) |
| 3127 | { |
| 3128 | acc = conn_get_account(conn); |
| 3129 | if (account_is_operator_or_admin(acc, channel_get_name(channel)) || |
| 3130 | channel_conn_is_tmpOP(channel, account_get_conn(acc))) |
| 3131 | { |
| 3132 | name = conn_get_loggeduser(conn); |
| 3133 | if (std::strlen(msgtemp0) + std::strlen(name) + 6 >= MAX_MESSAGE_LEN) break; |
| 3134 | if (!first) std::strcat(msgtemp0, " ,"); |
| 3135 | std::strcat(msgtemp0, name); |
| 3136 | if (account_get_auth_admin(acc, NULL) == 1) std::strcat(msgtemp0, "(A)"); |
| 3137 | else if (account_get_auth_operator(acc, NULL) == 1) std::strcat(msgtemp0, "(O)"); |
| 3138 | else if (account_get_auth_admin(acc, channel_get_name(channel)) == 1) std::strcat(msgtemp0, "(a)"); |
| 3139 | else if (account_get_auth_operator(acc, channel_get_name(channel)) == 1) std::strcat(msgtemp0, "(o)"); |
| 3140 | first = 0; |
| 3141 | } |
| 3142 | } |
| 3143 | |
| 3144 | message_send_text(c, message_type_info, c, msgtemp0); |
| 3145 | } |
| 3146 | } |
| 3147 | |
| 3148 | return 0; |
| 3149 | } |
| 3150 | |
| 3151 | static int _handle_addacct_command(t_connection * c, char const *text) |
| 3152 | { |
| 3153 | unsigned int i; |
| 3154 | t_account * temp; |
| 3155 | t_hash passhash; |
| 3156 | char const * username, *pass; |
| 3157 | |
| 3158 | std::vector<std::string> args = split_command(text, 2); |
| 3159 | |
| 3160 | if (args[2].empty()) |
| 3161 | { |
| 3162 | describe_command(c, args[0].c_str()); |
| 3163 | return -1; |
| 3164 | } |
| 3165 | username = args[1].c_str(); // username |
| 3166 | |
| 3167 | if (account_check_name(username) < 0) { |
| 3168 | message_send_text(c, message_type_error, c, localize(c, "Account name contains some invalid symbol!")); |
| 3169 | return -1; |
| 3170 | } |
| 3171 | |
| 3172 | if (args[2].length() > MAX_USERPASS_LEN) |
| 3173 | { |
| 3174 | msgtemp = localize(c, "Maximum password length allowed is {}", MAX_USERPASS_LEN); |
| 3175 | message_send_text(c, message_type_error, c, msgtemp); |
| 3176 | return -1; |
| 3177 | } |
| 3178 | for (i = 0; i < args[2].length(); i++) |
| 3179 | args[2][i] = safe_tolower(args[2][i]); |
| 3180 | pass = args[2].c_str(); // password |
| 3181 | |
| 3182 | |
| 3183 | bnet_hash(&passhash, std::strlen(pass), pass); |
| 3184 | |
| 3185 | msgtemp = localize(c, "Trying to add account \"{}\" with password \"{}\"", username, pass); |
| 3186 | message_send_text(c, message_type_info, c, msgtemp); |
| 3187 | |
| 3188 | msgtemp = localize(c, "Hash is: {}", hash_get_str(passhash)); |
| 3189 | message_send_text(c, message_type_info, c, msgtemp); |
| 3190 | |
| 3191 | temp = accountlist_create_account(username, hash_get_str(passhash)); |
| 3192 | if (!temp) { |
| 3193 | message_send_text(c, message_type_error, c, localize(c, "Failed to create account!")); |
| 3194 | eventlog(eventlog_level_debug, __FUNCTION__, "[{}] account \"{}\" not created (failed)", conn_get_socket(c), username); |
| 3195 | return -1; |
| 3196 | } |
| 3197 | |
| 3198 | msgtemp = localize(c, "Account {} created.", account_get_uid(temp)); |
| 3199 | message_send_text(c, message_type_info, c, msgtemp); |
| 3200 | eventlog(eventlog_level_debug, __FUNCTION__, "[{}] account \"{}\" created", conn_get_socket(c), username); |
| 3201 | |
| 3202 | return 0; |
| 3203 | } |
| 3204 | |
| 3205 | static int _handle_chpass_command(t_connection * c, char const *text) |
| 3206 | { |
| 3207 | unsigned int i; |
| 3208 | t_account * account; |
| 3209 | t_account * temp; |
| 3210 | t_hash passhash; |
| 3211 | char const * username; |
| 3212 | std::string pass; |
| 3213 | |
| 3214 | std::vector<std::string> args = split_command(text, 2); |
| 3215 | |
| 3216 | if (args[1].empty()) |
| 3217 | { |
| 3218 | describe_command(c, args[0].c_str()); |
| 3219 | return -1; |
| 3220 | } |
| 3221 | |
| 3222 | if (args[2].empty()) |
| 3223 | { |
| 3224 | username = conn_get_username(c); |
| 3225 | pass = args[1]; |
| 3226 | } |
| 3227 | else |
| 3228 | { |
| 3229 | username = args[1].c_str(); |
| 3230 | pass = args[2]; |
| 3231 | } |
| 3232 | |
| 3233 | temp = accountlist_find_account(username); |
| 3234 | |
| 3235 | account = conn_get_account(c); |
| 3236 | |
| 3237 | if ((temp == account && account_get_auth_changepass(account) == 0) || /* default to true */ |
| 3238 | (temp != account && !(account_get_command_groups(conn_get_account(c)) & command_get_group("/admin-chpass")))) /* default to false */ |
| 3239 | { |
| 3240 | eventlog(eventlog_level_info, __FUNCTION__, "[{}] password change for \"{}\" refused (no change access)", conn_get_socket(c), username); |
| 3241 | message_send_text(c, message_type_error, c, localize(c, "Only admins may change passwords for other accounts.")); |
| 3242 | return -1; |
| 3243 | } |
| 3244 | |
| 3245 | if (!temp) |
| 3246 | { |
| 3247 | message_send_text(c, message_type_error, c, localize(c, "Account does not exist.")); |
| 3248 | return -1; |
| 3249 | } |
| 3250 | |
| 3251 | if (pass.length() > MAX_USERPASS_LEN) |
| 3252 | { |
| 3253 | msgtemp = localize(c, "Maximum password length allowed is {}", MAX_USERPASS_LEN); |
| 3254 | message_send_text(c, message_type_error, c, msgtemp); |
| 3255 | return -1; |
| 3256 | } |
| 3257 | |
| 3258 | for (i = 0; i < pass.length(); i++) |
| 3259 | pass[i] = safe_tolower(pass[i]); |
| 3260 | |
| 3261 | bnet_hash(&passhash, pass.length(), pass.c_str()); |
| 3262 | |
| 3263 | msgtemp = localize(c, "Trying to change password for account \"{}\" to \"{}\"", username, pass.c_str()); |
| 3264 | message_send_text(c, message_type_info, c, msgtemp); |
| 3265 | |
| 3266 | if (account_set_pass(temp, hash_get_str(passhash)) < 0) |
| 3267 | { |
| 3268 | message_send_text(c, message_type_error, c, localize(c, "Unable to set password.")); |
| 3269 | return -1; |
| 3270 | } |
| 3271 | |
| 3272 | if (account_get_auth_admin(account, NULL) == 1 || |
| 3273 | account_get_auth_operator(account, NULL) == 1) { |
| 3274 | msgtemp = localize(c, "Password for account {} updated.", account_get_uid(temp)); |
| 3275 | message_send_text(c, message_type_info, c, msgtemp); |
| 3276 | |
| 3277 | msgtemp = localize(c, "Hash is: {}", hash_get_str(passhash)); |
| 3278 | message_send_text(c, message_type_info, c, msgtemp); |
| 3279 | } |
| 3280 | else { |
| 3281 | msgtemp = localize(c, "Password for account {} updated.", username); |
| 3282 | message_send_text(c, message_type_info, c, msgtemp); |
| 3283 | } |
| 3284 | |
| 3285 | return 0; |
| 3286 | } |
| 3287 | |
| 3288 | static int _handle_connections_command(t_connection *c, char const *text) |
| 3289 | { |
| 3290 | t_elem const * curr; |
| 3291 | t_connection * conn; |
| 3292 | char name[19]; |
| 3293 | char const * channel_name; |
| 3294 | char clienttag_str[5]; |
| 3295 | |
| 3296 | if (!prefs_get_enable_conn_all() && !(account_get_command_groups(conn_get_account(c)) & command_get_group("/admin-con"))) /* default to false */ |
| 3297 | { |
| 3298 | message_send_text(c, message_type_error, c, localize(c, "This command is only enabled for admins.")); |
| 3299 | return -1; |
| 3300 | } |
| 3301 | |
| 3302 | message_send_text(c, message_type_info, c, localize(c, "Current connections:")); |
| 3303 | |
| 3304 | std::vector<std::string> args = split_command(text, 1); |
| 3305 | text = args[1].c_str(); |
| 3306 | |
| 3307 | if (text[0] == '\0') |
| 3308 | { |
| 3309 | msgtemp = localize(c, " -class -tag -----name------ -lat(ms)- ----channel---- --game--"); |
| 3310 | message_send_text(c, message_type_info, c, msgtemp); |
| 3311 | } |
| 3312 | else |
| 3313 | if (std::strcmp(text, "all") == 0) /* print extended info */ |
| 3314 | { |
| 3315 | if (prefs_get_hide_addr() && !(account_get_command_groups(conn_get_account(c)) & command_get_group("/admin-addr"))) |
| 3316 | msgtemp = localize(c, " -#- -class ----state--- -tag -----name------ -session-- -flag- -lat(ms)- ----channel---- --game--"); |
| 3317 | else |
| 3318 | msgtemp = localize(c, " -#- -class ----state--- -tag -----name------ -session-- -flag- -lat(ms)- ----channel---- --game-- ---------addr--------"); |
| 3319 | message_send_text(c, message_type_info, c, msgtemp); |
| 3320 | } |
| 3321 | else |
| 3322 | { |
| 3323 | message_send_text(c, message_type_error, c, localize(c, "Unknown option.")); |
| 3324 | return -1; |
| 3325 | } |
| 3326 | |
| 3327 | LIST_TRAVERSE_CONST(connlist(), curr) |
| 3328 | { |
| 3329 | conn = (t_connection*)elem_get_data(curr); |
| 3330 | std::snprintf(name, sizeof name, "%s", conn_get_account(conn) ? conn_get_username(conn) : "(none)"); |
| 3331 | |
| 3332 | if (conn_get_channel(conn) != NULL) |
| 3333 | channel_name = channel_get_name(conn_get_channel(conn)); |
| 3334 | else |
| 3335 | channel_name = localize(c, "none").c_str(); |
| 3336 | |
| 3337 | std::string game_name; |
| 3338 | if (conn_get_game(conn) != NULL) |
| 3339 | game_name = game_get_name(conn_get_game(conn)); |
| 3340 | else |
| 3341 | game_name = localize(c, "none"); |
| 3342 | |
| 3343 | if (text[0] == '\0') |
| 3344 | std::snprintf(msgtemp0, sizeof(msgtemp0), " %-6.6s %4.4s %-15.15s %9u %-16.16s %-8.8s", |
| 3345 | conn_class_get_str(conn_get_class(conn)), |
| 3346 | tag_uint_to_str(clienttag_str, conn_get_fake_clienttag(conn)), |
| 3347 | name, |
| 3348 | conn_get_latency(conn), |
| 3349 | channel_name, |
| 3350 | game_name.c_str()); |
| 3351 | else |
| 3352 | if (prefs_get_hide_addr() && !(account_get_command_groups(conn_get_account(c)) & command_get_group("/admin-addr"))) /* default to false */ |
| 3353 | std::snprintf(msgtemp0, sizeof(msgtemp0), " %3d %-6.6s %-12.12s %4.4s %-15.15s 0x%08x 0x%04x %9u %-16.16s %-8.8s", |
| 3354 | conn_get_socket(conn), |
| 3355 | conn_class_get_str(conn_get_class(conn)), |
| 3356 | conn_state_get_str(conn_get_state(conn)), |
| 3357 | tag_uint_to_str(clienttag_str, conn_get_fake_clienttag(conn)), |
| 3358 | name, |
| 3359 | conn_get_sessionkey(conn), |
| 3360 | conn_get_flags(conn), |
| 3361 | conn_get_latency(conn), |
| 3362 | channel_name, |
| 3363 | game_name.c_str()); |
| 3364 | else |
| 3365 | std::snprintf(msgtemp0, sizeof(msgtemp0), " %3d %-6.6s %-12.12s %4.4s %-15.15s 0x%08x 0x%04x %9u %-16.16s %-8.8s %.16s", |
| 3366 | conn_get_socket(conn), |
| 3367 | conn_class_get_str(conn_get_class(conn)), |
| 3368 | conn_state_get_str(conn_get_state(conn)), |
| 3369 | tag_uint_to_str(clienttag_str, conn_get_fake_clienttag(conn)), |
| 3370 | name, |
| 3371 | conn_get_sessionkey(conn), |
| 3372 | conn_get_flags(conn), |
| 3373 | conn_get_latency(conn), |
| 3374 | channel_name, |
| 3375 | game_name.c_str(), |
| 3376 | addr_num_to_addr_str(conn_get_addr(conn), conn_get_port(conn))); |
| 3377 | |
| 3378 | message_send_text(c, message_type_info, c, msgtemp0); |
| 3379 | } |
| 3380 | |
| 3381 | return 0; |
| 3382 | } |
| 3383 | |
| 3384 | static int _handle_finger_command(t_connection * c, char const *text) |
| 3385 | { |
| 3386 | char const * dest; |
| 3387 | t_account * account; |
| 3388 | t_connection * conn; |
| 3389 | char * tok; |
| 3390 | t_clanmember * clanmemb; |
| 3391 | std::time_t then; |
| 3392 | struct std::tm * tmthen; |
| 3393 | |
| 3394 | std::vector<std::string> args = split_command(text, 1); |
| 3395 | |
| 3396 | if (args[1].empty()) |
| 3397 | { |
| 3398 | describe_command(c, args[0].c_str()); |
| 3399 | return -1; |
| 3400 | } |
| 3401 | dest = args[1].c_str(); // username; |
| 3402 | |
| 3403 | if (!(account = accountlist_find_account(dest))) |
| 3404 | { |
| 3405 | message_send_text(c, message_type_error, c, localize(c, "Invalid user.")); |
| 3406 | return -1; |
| 3407 | } |
| 3408 | |
| 3409 | then = account_get_ll_ctime(account); |
| 3410 | tmthen = std::localtime(&then); /* FIXME: determine user's timezone */ |
| 3411 | |
| 3412 | // do not display sex if empty |
| 3413 | std::string sex = account_get_sex(account); |
| 3414 | std::string pattern = "Login: {} {} Sex: {}"; |
| 3415 | pattern = (sex.length() > 0) |
| 3416 | ? pattern |
| 3417 | : pattern.substr(0, pattern.find("Sex: ", 0)); |
| 3418 | |
| 3419 | msgtemp = localize(c, pattern.c_str(), |
| 3420 | account_get_name(account), |
| 3421 | account_get_uid(account), |
| 3422 | account_get_sex(account)); |
| 3423 | message_send_text(c, message_type_info, c, msgtemp); |
| 3424 | |
| 3425 | std::strftime(msgtemp0, sizeof(msgtemp0), "%a %b %d %H:%M %Y", tmthen); |
| 3426 | msgtemp = localize(c, "Created: {}", msgtemp0); |
| 3427 | message_send_text(c, message_type_info, c, msgtemp); |
| 3428 | |
| 3429 | if ((clanmemb = account_get_clanmember(account))) |
| 3430 | { |
| 3431 | t_clan * clan; |
| 3432 | char status; |
| 3433 | |
| 3434 | if ((clan = clanmember_get_clan(clanmemb))) |
| 3435 | { |
| 3436 | msgtemp = localize(c, "Clan: {}", clan_get_name(clan)); |
| 3437 | if ((status = clanmember_get_status(clanmemb))) |
| 3438 | { |
| 3439 | switch (status) |
| 3440 | { |
| 3441 | case CLAN_CHIEFTAIN: |
| 3442 | msgtemp += localize(c, " Rank: Chieftain"); |
| 3443 | break; |
| 3444 | case CLAN_SHAMAN: |
| 3445 | msgtemp += localize(c, " Rank: Shaman"); |
| 3446 | break; |
| 3447 | case CLAN_GRUNT: |
| 3448 | msgtemp += localize(c, " Rank: Grunt"); |
| 3449 | break; |
| 3450 | case CLAN_PEON: |
| 3451 | msgtemp += localize(c, " Rank: Peon"); |
| 3452 | break; |
| 3453 | default:; |
| 3454 | } |
| 3455 | } |
| 3456 | message_send_text(c, message_type_info, c, msgtemp); |
| 3457 | |
| 3458 | } |
| 3459 | } |
| 3460 | |
| 3461 | // do not display age if empty |
| 3462 | std::string age = account_get_age(account); |
| 3463 | pattern = "Location: {} Age: {}"; |
| 3464 | pattern = (age.length() > 0) |
| 3465 | ? pattern |
| 3466 | : pattern.substr(0, pattern.find("Age: ", 0)); |
| 3467 | std::string loc = account_get_loc(account); |
| 3468 | msgtemp = localize(c, pattern.c_str(), |
| 3469 | (!loc.empty()) ? loc : "unknown", |
| 3470 | account_get_age(account)); |
| 3471 | message_send_text(c, message_type_info, c, msgtemp); |
| 3472 | |
| 3473 | if ((conn = connlist_find_connection_by_accountname(dest))) |
| 3474 | { |
| 3475 | msgtemp = localize(c, "Client: {} Ver: {} Country: {}", |
| 3476 | clienttag_get_title(conn_get_clienttag(conn)), |
| 3477 | conn_get_clientver(conn), |
| 3478 | conn_get_country(conn)); |
| 3479 | message_send_text(c, message_type_info, c, msgtemp); |
| 3480 | } |
| 3481 | |
| 3482 | const char* const ip_tmp = account_get_ll_ip(account); |
| 3483 | std::string ip(ip_tmp ? ip_tmp : ""); |
| 3484 | if (ip.empty() == true || |
| 3485 | !(account_get_command_groups(conn_get_account(c)) & command_get_group("/admin-addr"))) /* default to false */ |
| 3486 | ip = localize(c, "unknown"); |
| 3487 | |
| 3488 | { |
| 3489 | |
| 3490 | then = account_get_ll_time(account); |
| 3491 | tmthen = std::localtime(&then); /* FIXME: determine user's timezone */ |
| 3492 | if (tmthen) |
| 3493 | std::strftime(msgtemp0, sizeof(msgtemp0), "%a %b %d %H:%M %Y", tmthen); |
| 3494 | else |
| 3495 | std::strcpy(msgtemp0, "?"); |
| 3496 | |
| 3497 | if (!(conn)) |
| 3498 | msgtemp = localize(c, "Last login {} from ", msgtemp0); |
| 3499 | else |
| 3500 | msgtemp = localize(c, "On since {} from ", msgtemp0); |
| 3501 | } |
| 3502 | msgtemp += ip; |
| 3503 | message_send_text(c, message_type_info, c, msgtemp); |
| 3504 | |
| 3505 | /* check /admin-addr for admin privileges */ |
| 3506 | if ((account_get_command_groups(conn_get_account(c)) & command_get_group("/admin-addr"))) |
| 3507 | { |
| 3508 | std::string yes = localize(c, "Yes"); |
| 3509 | std::string no = localize(c, "No"); |
| 3510 | /* the player who requested /finger has admin privileges |
| 3511 | give him more info about the one he queries; |
| 3512 | is_admin, is_operator, is_locked, email */ |
| 3513 | msgtemp = localize(c, "Operator: {}, Admin: {}, Locked: {}, Muted: {}", |
| 3514 | account_get_auth_operator(account, NULL) == 1 ? yes : no, |
| 3515 | account_get_auth_admin(account, NULL) == 1 ? yes : no, |
| 3516 | account_get_auth_lock(account) == 1 ? yes : no, |
| 3517 | account_get_auth_mute(account) == 1 ? yes : no); |
| 3518 | message_send_text(c, message_type_info, c, msgtemp); |
| 3519 | |
| 3520 | msgtemp = localize(c, "Email: {}", account_get_email(account)); |
| 3521 | message_send_text(c, message_type_info, c, msgtemp); |
| 3522 | |
| 3523 | msgtemp = localize(c, "Last login Owner: {}", account_get_ll_owner(account)); |
| 3524 | message_send_text(c, message_type_info, c, msgtemp); |
| 3525 | } |
| 3526 | |
| 3527 | |
| 3528 | if (conn) |
| 3529 | { |
| 3530 | msgtemp = localize(c, "Idle {}", seconds_to_timestr(conn_get_idletime(conn))); |
| 3531 | message_send_text(c, message_type_info, c, msgtemp); |
| 3532 | } |
| 3533 | |
| 3534 | std::strncpy(msgtemp0, account_get_desc(account).c_str(), sizeof(msgtemp0)); |
| 3535 | msgtemp0[sizeof(msgtemp0)-1] = '\0'; |
| 3536 | for (tok = std::strtok(msgtemp0, "\r\n"); tok; tok = std::strtok(NULL, "\r\n")) |
| 3537 | message_send_text(c, message_type_info, c, tok); |
| 3538 | message_send_text(c, message_type_info, c, ""); |
| 3539 | |
| 3540 | return 0; |
| 3541 | } |
| 3542 | |
| 3543 | |
| 3544 | /* FIXME: do we want to show just Server Admin or Channel Admin Also? [Omega] */ |
| 3545 | static int _handle_admins_command(t_connection * c, char const *text) |
| 3546 | { |
| 3547 | unsigned int i; |
| 3548 | t_elem const * curr; |
| 3549 | t_connection * tc; |
| 3550 | char const * nick; |
| 3551 | |
| 3552 | std::snprintf(msgtemp0, sizeof msgtemp0, "%s", localize(c, "Currently logged on Administrators:").c_str()); |
| 3553 | i = std::strlen(msgtemp0); |
| 3554 | LIST_TRAVERSE_CONST(connlist(), curr) |
| 3555 | { |
| 3556 | tc = (t_connection*)elem_get_data(curr); |
| 3557 | if (!tc) |
| 3558 | continue; |
| 3559 | if (!conn_get_account(tc)) |
| 3560 | continue; |
| 3561 | if (account_get_auth_admin(conn_get_account(tc), NULL) == 1) |
| 3562 | { |
| 3563 | if ((nick = conn_get_username(tc))) |
| 3564 | { |
| 3565 | if (i + std::strlen(nick) + 2 > sizeof(msgtemp0)) /* " ", name, '\0' */ |
| 3566 | { |
| 3567 | message_send_text(c, message_type_info, c, msgtemp0); |
| 3568 | i = 0; |
| 3569 | } |
| 3570 | std::sprintf(&msgtemp0[i], " %s", nick); |
| 3571 | i += std::strlen(&msgtemp0[i]); |
| 3572 | } |
| 3573 | } |
| 3574 | } |
| 3575 | if (i > 0) |
| 3576 | message_send_text(c, message_type_info, c, msgtemp0); |
| 3577 | |
| 3578 | return 0; |
| 3579 | } |
| 3580 | |
| 3581 | static int _handle_quit_command(t_connection * c, char const *text) |
| 3582 | { |
| 3583 | if (conn_get_game(c)) |
| 3584 | eventlog(eventlog_level_warn, __FUNCTION__, "[{}] user '{}' tried to disconnect while in game, cheat attempt ?", conn_get_socket(c), conn_get_loggeduser(c)); |
| 3585 | else { |
| 3586 | message_send_text(c, message_type_info, c, localize(c, "Connection closed.")); |
| 3587 | conn_set_state(c, conn_state_destroy); |
| 3588 | } |
| 3589 | |
| 3590 | return 0; |
| 3591 | } |
| 3592 | |
| 3593 | static int _handle_kill_command(t_connection * c, char const *text) |
| 3594 | { |
| 3595 | t_connection * user; |
| 3596 | char const * username, * min; |
| 3597 | |
| 3598 | std::vector<std::string> args = split_command(text, 2); |
| 3599 | username = args[1].c_str(); // username |
| 3600 | min = args[2].c_str(); // minutes of ban |
| 3601 | |
| 3602 | if (username[0] == '\0' || (username[0] == '#' && (username[1] < '0' || username[1] > '9'))) |
| 3603 | { |
| 3604 | describe_command(c, args[0].c_str()); |
| 3605 | return -1; |
| 3606 | } |
| 3607 | |
| 3608 | if (username[0] == '#') { |
| 3609 | if (!(user = connlist_find_connection_by_socket(std::atoi(username + 1)))) { |
| 3610 | message_send_text(c, message_type_error, c, localize(c, "That connection doesn't exist.")); |
| 3611 | return -1; |
| 3612 | } |
| 3613 | } |
| 3614 | else { |
| 3615 | if (!(user = connlist_find_connection_by_accountname(username))) { |
| 3616 | message_send_text(c, message_type_error, c, localize(c, "That user is not logged in?")); |
| 3617 | return -1; |
| 3618 | } |
| 3619 | } |
| 3620 | |
| 3621 | if (min[0] != '\0' && ipbanlist_add(c, addr_num_to_ip_str(conn_get_addr(user)), ipbanlist_str_to_time_t(c, min)) == 0) |
| 3622 | { |
| 3623 | ipbanlist_save(prefs_get_ipbanfile()); |
| 3624 | message_send_text(user, message_type_info, user, localize(c, "An admin has closed your connection and banned your IP address.")); |
| 3625 | } |
| 3626 | else |
| 3627 | message_send_text(user, message_type_info, user, localize(c, "Connection closed by admin.")); |
| 3628 | conn_set_state(user, conn_state_destroy); |
| 3629 | |
| 3630 | message_send_text(c, message_type_info, c, localize(c, "Operation successful.")); |
| 3631 | |
| 3632 | return 0; |
| 3633 | } |
| 3634 | |
| 3635 | static int _handle_killsession_command(t_connection * c, char const *text) |
| 3636 | { |
| 3637 | t_connection * user; |
| 3638 | char const * session, *min; |
| 3639 | |
| 3640 | |
| 3641 | std::vector<std::string> args = split_command(text, 2); |
| 3642 | |
| 3643 | if (args[1].empty()) |
| 3644 | { |
| 3645 | describe_command(c, args[0].c_str()); |
| 3646 | return -1; |
| 3647 | } |
| 3648 | session = args[1].c_str(); // session id |
| 3649 | min = args[1].c_str(); // minutes of ban |
| 3650 | |
| 3651 | if (!std::isxdigit((int)session[0])) |
| 3652 | { |
| 3653 | message_send_text(c, message_type_error, c, localize(c, "That is not a valid session.")); |
| 3654 | return -1; |
| 3655 | } |
| 3656 | if (!(user = connlist_find_connection_by_sessionkey((unsigned int)std::strtoul(session, NULL, 16)))) |
| 3657 | { |
| 3658 | message_send_text(c, message_type_error, c, localize(c, "That session does not exist.")); |
| 3659 | return -1; |
| 3660 | } |
| 3661 | if (min[0] != '\0' && ipbanlist_add(c, addr_num_to_ip_str(conn_get_addr(user)), ipbanlist_str_to_time_t(c, min)) == 0) |
| 3662 | { |
| 3663 | ipbanlist_save(prefs_get_ipbanfile()); |
| 3664 | message_send_text(user, message_type_info, user, localize(c, "Connection closed by admin and banned your IP's.")); |
| 3665 | } |
| 3666 | else |
| 3667 | message_send_text(user, message_type_info, user, localize(c, "Connection closed by admin.")); |
| 3668 | conn_set_state(user, conn_state_destroy); |
| 3669 | return 0; |
| 3670 | } |
| 3671 | |
| 3672 | static int _handle_gameinfo_command(t_connection * c, char const *text) |
| 3673 | { |
| 3674 | t_game const * game; |
| 3675 | char clienttag_str[5]; |
| 3676 | |
| 3677 | std::vector<std::string> args = split_command(text, 1); |
| 3678 | text = args[1].c_str(); |
| 3679 | |
| 3680 | if (text[0] == '\0') |
| 3681 | { |
| 3682 | // current user game |
| 3683 | if (!(game = conn_get_game(c))) |
| 3684 | { |
| 3685 | message_send_text(c, message_type_error, c, localize(c, "You are not in a game.")); |
| 3686 | return -1; |
| 3687 | } |
| 3688 | } |
| 3689 | else |
| 3690 | if (!(game = gamelist_find_game_available(text, conn_get_clienttag(c), game_type_all))) |
| 3691 | { |
| 3692 | message_send_text(c, message_type_error, c, localize(c, "That game does not exist.")); |
| 3693 | return -1; |
| 3694 | } |
| 3695 | std::string pub = localize(c, "public"); |
| 3696 | std::string prv = localize(c, "private"); |
| 3697 | msgtemp = localize(c, "Name: {} ID: {} ({})", game_get_name(game), game_get_id(game), game_get_flag(game) != game_flag_private ? pub : prv); |
| 3698 | message_send_text(c, message_type_info, c, msgtemp); |
| 3699 | |
| 3700 | { |
| 3701 | t_account * owner; |
| 3702 | char const * tname; |
| 3703 | char const * namestr; |
| 3704 | |
| 3705 | if (!(owner = conn_get_account(game_get_owner(game)))) |
| 3706 | { |
| 3707 | tname = NULL; |
| 3708 | namestr = localize(c, "none").c_str(); |
| 3709 | } |
| 3710 | else |
| 3711 | if (!(tname = conn_get_loggeduser(game_get_owner(game)))) |
| 3712 | namestr = localize(c, "unknown").c_str(); |
| 3713 | else |
| 3714 | namestr = tname; |
| 3715 | |
| 3716 | msgtemp = localize(c, "Owner: {}", namestr); |
| 3717 | |
| 3718 | } |
| 3719 | message_send_text(c, message_type_info, c, msgtemp); |
| 3720 | |
| 3721 | if (!prefs_get_hide_addr() || (account_get_command_groups(conn_get_account(c)) & command_get_group("/admin-addr"))) /* default to false */ |
| 3722 | { |
| 3723 | unsigned int addr; |
| 3724 | unsigned short port; |
| 3725 | unsigned int taddr; |
| 3726 | unsigned short tport; |
| 3727 | |
| 3728 | taddr = addr = game_get_addr(game); |
| 3729 | tport = port = game_get_port(game); |
| 3730 | trans_net(conn_get_addr(c), &taddr, &tport); |
| 3731 | |
| 3732 | if (taddr == addr && tport == port) |
| 3733 | msgtemp = localize(c, "Address: {}", |
| 3734 | addr_num_to_addr_str(addr, port)); |
| 3735 | else |
| 3736 | msgtemp = localize(c, "Address: {} (trans {})", |
| 3737 | addr_num_to_addr_str(addr, port), |
| 3738 | addr_num_to_addr_str(taddr, tport)); |
| 3739 | message_send_text(c, message_type_info, c, msgtemp); |
| 3740 | } |
| 3741 | |
| 3742 | msgtemp = localize(c, "Client: {} (version {}, startver {})", tag_uint_to_str(clienttag_str, game_get_clienttag(game)), vernum_to_verstr(game_get_version(game)), game_get_startver(game)); |
| 3743 | message_send_text(c, message_type_info, c, msgtemp); |
| 3744 | |
| 3745 | { |
| 3746 | std::time_t gametime; |
| 3747 | struct std::tm * gmgametime; |
| 3748 | |
| 3749 | gametime = game_get_create_time(game); |
| 3750 | if (!(gmgametime = std::localtime(&gametime))) |
| 3751 | std::strcpy(msgtemp0, "?"); |
| 3752 | else |
| 3753 | std::strftime(msgtemp0, sizeof(msgtemp0), GAME_TIME_FORMAT, gmgametime); |
| 3754 | msgtemp = localize(c, "Created: {}", msgtemp0); |
| 3755 | message_send_text(c, message_type_info, c, msgtemp); |
| 3756 | |
| 3757 | gametime = game_get_start_time(game); |
| 3758 | if (gametime != (std::time_t)0) |
| 3759 | { |
| 3760 | if (!(gmgametime = std::localtime(&gametime))) |
| 3761 | std::strcpy(msgtemp0, "?"); |
| 3762 | else |
| 3763 | std::strftime(msgtemp0, sizeof(msgtemp0), GAME_TIME_FORMAT, gmgametime); |
| 3764 | } |
| 3765 | else |
| 3766 | std::strcpy(msgtemp0, ""); |
| 3767 | msgtemp = localize(c, "Started: {}", msgtemp0); |
| 3768 | message_send_text(c, message_type_info, c, msgtemp); |
| 3769 | } |
| 3770 | |
| 3771 | msgtemp = localize(c, "Status: {}", game_status_get_str(game_get_status(game))); |
| 3772 | message_send_text(c, message_type_info, c, msgtemp); |
| 3773 | |
| 3774 | msgtemp = localize(c, "Type: {}", game_type_get_str(game_get_type(game))); |
| 3775 | message_send_text(c, message_type_info, c, msgtemp); |
| 3776 | |
| 3777 | msgtemp = localize(c, "Speed: {}", game_speed_get_str(game_get_speed(game))); |
| 3778 | message_send_text(c, message_type_info, c, msgtemp); |
| 3779 | |
| 3780 | msgtemp = localize(c, "Difficulty: {}", game_difficulty_get_str(game_get_difficulty(game))); |
| 3781 | message_send_text(c, message_type_info, c, msgtemp); |
| 3782 | |
| 3783 | msgtemp = localize(c, "Option: {}", game_option_get_str(game_get_option(game))); |
| 3784 | message_send_text(c, message_type_info, c, msgtemp); |
| 3785 | |
| 3786 | { |
| 3787 | char const * mapname; |
| 3788 | |
| 3789 | if (!(mapname = game_get_mapname(game))) |
| 3790 | mapname = localize(c, "unknown").c_str(); |
| 3791 | msgtemp = localize(c, "Map: {}", mapname); |
| 3792 | message_send_text(c, message_type_info, c, msgtemp); |
| 3793 | } |
| 3794 | |
| 3795 | msgtemp = localize(c, "Map Size: {}x{}", game_get_mapsize_x(game), game_get_mapsize_y(game)); |
| 3796 | message_send_text(c, message_type_info, c, msgtemp); |
| 3797 | msgtemp = localize(c, "Map Tileset: {}", game_tileset_get_str(game_get_tileset(game))); |
| 3798 | message_send_text(c, message_type_info, c, msgtemp); |
| 3799 | msgtemp = localize(c, "Map Type: {}", game_maptype_get_str(game_get_maptype(game))); |
| 3800 | message_send_text(c, message_type_info, c, msgtemp); |
| 3801 | |
| 3802 | msgtemp = localize(c, "Players: {} current, {} total, {} max", game_get_ref(game), game_get_count(game), game_get_maxplayers(game)); |
| 3803 | message_send_text(c, message_type_info, c, msgtemp); |
| 3804 | |
| 3805 | { |
| 3806 | char const * description; |
| 3807 | |
| 3808 | if (!(description = game_get_description(game))) |
| 3809 | description = ""; |
| 3810 | msgtemp = localize(c, "Description: {}", description); |
| 3811 | } |
| 3812 | |
| 3813 | return 0; |
| 3814 | } |
| 3815 | |
| 3816 | static int _handle_ladderactivate_command(t_connection * c, char const *text) |
| 3817 | { |
| 3818 | ladders.activate(); |
| 3819 | message_send_text(c, message_type_info, c, localize(c, "Copied current scores to active scores on all ladders.")); |
| 3820 | return 0; |
| 3821 | } |
| 3822 | |
| 3823 | static int _handle_rehash_command(t_connection * c, char const *text) |
| 3824 | { |
| 3825 | int mode = restart_mode_all; // all by default |
| 3826 | |
| 3827 | std::vector<std::string> args = split_command(text, 1); |
| 3828 | |
| 3829 | if (args[1].empty()) |
| 3830 | { |
| 3831 | describe_command(c, args[0].c_str()); |
| 3832 | return -1; |
| 3833 | } |
| 3834 | std::string mode_str = args[1]; |
| 3835 | |
| 3836 | if (mode_str == "all") |
| 3837 | mode = restart_mode_all; |
| 3838 | else if (mode_str == "i18n") |
| 3839 | mode = restart_mode_i18n; |
| 3840 | else if (mode_str == "channels") |
| 3841 | mode = restart_mode_channels; |
| 3842 | else if (mode_str == "realms") |
| 3843 | mode = restart_mode_realms; |
| 3844 | else if (mode_str == "autoupdate") |
| 3845 | mode = restart_mode_autoupdate; |
| 3846 | else if (mode_str == "news") |
| 3847 | mode = restart_mode_news; |
| 3848 | else if (mode_str == "versioncheck") |
| 3849 | mode = restart_mode_versioncheck; |
| 3850 | else if (mode_str == "ipbans") |
| 3851 | mode = restart_mode_ipbans; |
| 3852 | else if (mode_str == "helpfile") |
| 3853 | mode = restart_mode_helpfile; |
| 3854 | else if (mode_str == "banners") |
| 3855 | mode = restart_mode_banners; |
| 3856 | else if (mode_str == "tracker") |
| 3857 | mode = restart_mode_tracker; |
| 3858 | else if (mode_str == "commandgroups") |
| 3859 | mode = restart_mode_commandgroups; |
| 3860 | else if (mode_str == "aliasfile") |
| 3861 | mode = restart_mode_aliasfile; |
| 3862 | else if (mode_str == "transfile") |
| 3863 | mode = restart_mode_transfile; |
| 3864 | else if (mode_str == "tournament") |
| 3865 | mode = restart_mode_tournament; |
| 3866 | else if (mode_str == "icons") |
| 3867 | mode = restart_mode_icons; |
| 3868 | else if (mode_str == "anongame") |
| 3869 | mode = restart_mode_anongame; |
| 3870 | else if (mode_str == "lua") |
| 3871 | mode = restart_mode_lua; |
| 3872 | else |
| 3873 | { |
| 3874 | message_send_text(c, message_type_info, c, localize(c, "Invalid mode.")); |
| 3875 | return -1; |
| 3876 | } |
| 3877 | |
| 3878 | server_restart_wraper(mode); |
| 3879 | msgtemp = localize(c, "Rehash of \"{}\" is complete!", mode_str.c_str()); |
| 3880 | message_send_text(c, message_type_info, c, msgtemp); |
| 3881 | return 0; |
| 3882 | } |
| 3883 | |
| 3884 | /** |
| 3885 | * /find <substr to search for inside username> |
| 3886 | */ |
| 3887 | static int _handle_find_command(t_connection * c, char const *text) |
| 3888 | { |
| 3889 | unsigned int i = 0; |
| 3890 | t_account *account; |
| 3891 | char const *tname; |
| 3892 | t_entry *curr; |
| 3893 | t_hashtable *accountlist_head = accountlist(); |
| 3894 | |
| 3895 | std::vector<std::string> args = split_command(text, 1); |
| 3896 | if (args[1].empty()) |
| 3897 | { |
| 3898 | describe_command(c, args[0].c_str()); |
| 3899 | return -1; |
| 3900 | } |
| 3901 | text = args[1].c_str(); |
| 3902 | |
| 3903 | msgtemp = localize(c, " -- name -- similar to {}", text); |
| 3904 | message_send_text(c, message_type_info, c, msgtemp); |
| 3905 | |
| 3906 | |
| 3907 | HASHTABLE_TRAVERSE(accountlist_head, curr) |
| 3908 | { |
| 3909 | if (!curr) |
| 3910 | { |
| 3911 | eventlog(eventlog_level_error, __FUNCTION__, "found NULL account in list"); |
| 3912 | } |
| 3913 | else |
| 3914 | { |
| 3915 | account = (t_account *)entry_get_data(curr); |
| 3916 | if ((tname = accountlist_find_vague_account(account, text)) != NULL) { |
| 3917 | message_send_text(c, message_type_info, c, tname); |
| 3918 | return 0; |
| 3919 | } |
| 3920 | } |
| 3921 | } |
| 3922 | return 0; |
| 3923 | } |
| 3924 | |
| 3925 | /** |
| 3926 | * Save changes of accounts and clans from the cache to a storage |
| 3927 | */ |
| 3928 | static int _handle_save_command(t_connection * c, char const *text) |
| 3929 | { |
| 3930 | clanlist_save(); |
| 3931 | |
| 3932 | accountlist_save(FS_FORCE | FS_ALL); |
| 3933 | accountlist_flush(FS_FORCE | FS_ALL); |
| 3934 | |
| 3935 | message_send_text(c, message_type_info, c, localize(c, "Pending changes has been saved into the database.")); |
| 3936 | return 0; |
| 3937 | } |
| 3938 | |
| 3939 | static int _handle_shutdown_command(t_connection * c, char const *text) |
| 3940 | { |
| 3941 | char const * dest; |
| 3942 | unsigned int delay; |
| 3943 | |
| 3944 | std::vector<std::string> args = split_command(text, 1); |
| 3945 | dest = args[1].c_str(); // delay |
| 3946 | |
| 3947 | if (dest[0] == '\0') |
| 3948 | delay = prefs_get_shutdown_delay(); |
| 3949 | else |
| 3950 | if (clockstr_to_seconds(dest, &delay) < 0) |
| 3951 | { |
| 3952 | message_send_text(c, message_type_error, c, localize(c, "Invalid delay.")); |
| 3953 | return -1; |
| 3954 | } |
| 3955 | |
| 3956 | server_quit_delay(delay); |
| 3957 | |
| 3958 | if (delay) |
| 3959 | message_send_text(c, message_type_info, c, localize(c, "You've initialized the shutdown sequence.")); |
| 3960 | else |
| 3961 | message_send_text(c, message_type_info, c, localize(c, "You've canceled the shutdown sequence.")); |
| 3962 | |
| 3963 | return 0; |
| 3964 | } |
| 3965 | |
| 3966 | static int _handle_ladderinfo_command(t_connection * c, char const *text) |
| 3967 | { |
| 3968 | char const * rank_s, *tag_s; |
| 3969 | unsigned int rank; |
| 3970 | t_account * account; |
| 3971 | t_team * team; |
| 3972 | t_clienttag clienttag; |
| 3973 | const LadderReferencedObject* referencedObject; |
| 3974 | LadderList* ladderList; |
| 3975 | |
| 3976 | std::vector<std::string> args = split_command(text, 2); |
| 3977 | if (args[1].empty()) |
| 3978 | { |
| 3979 | describe_command(c, args[0].c_str()); |
| 3980 | return -1; |
| 3981 | } |
| 3982 | rank_s = args[1].c_str(); // rank |
| 3983 | tag_s = args[2].c_str(); // clienttag |
| 3984 | |
| 3985 | if (str_to_uint(rank_s, &rank) < 0 || rank < 1) |
| 3986 | { |
| 3987 | message_send_text(c, message_type_error, c, "Invalid rank."); |
| 3988 | return -1; |
| 3989 | } |
| 3990 | |
| 3991 | if (!(clienttag = tag_validate_client(tag_s))) |
| 3992 | { |
| 3993 | if (!(clienttag = conn_get_clienttag(c))) |
| 3994 | { |
| 3995 | message_send_text(c, message_type_error, c, localize(c, "Unable to determine client game.")); |
| 3996 | return -1; |
| 3997 | } |
| 3998 | } |
| 3999 | |
| 4000 | if (clienttag == CLIENTTAG_STARCRAFT_UINT) |
| 4001 | { |
| 4002 | ladderList = ladders.getLadderList(LadderKey(ladder_id_normal, clienttag, ladder_sort_highestrated, ladder_time_active)); |
| 4003 | referencedObject = ladderList->getReferencedObject(rank); |
| 4004 | if ((referencedObject) && (account = referencedObject->getAccount())) |
| 4005 | { |
| 4006 | std::snprintf(msgtemp0, sizeof(msgtemp0), "StarCraft active %5u: %-20.20s %u/%u/%u rating %u", |
| 4007 | rank, |
| 4008 | account_get_name(account), |
| 4009 | account_get_ladder_active_wins(account, CLIENTTAG_STARCRAFT_UINT, ladder_id_normal), |
| 4010 | account_get_ladder_active_losses(account, CLIENTTAG_STARCRAFT_UINT, ladder_id_normal), |
| 4011 | account_get_ladder_active_disconnects(account, CLIENTTAG_STARCRAFT_UINT, ladder_id_normal), |
| 4012 | account_get_ladder_active_rating(account, CLIENTTAG_STARCRAFT_UINT, ladder_id_normal)); |
| 4013 | } |
| 4014 | else |
| 4015 | std::snprintf(msgtemp0, sizeof(msgtemp0), "StarCraft active %5u: <none>", rank); |
| 4016 | message_send_text(c, message_type_info, c, msgtemp0); |
| 4017 | |
| 4018 | ladderList = ladders.getLadderList(LadderKey(ladder_id_normal, clienttag, ladder_sort_highestrated, ladder_time_current)); |
| 4019 | referencedObject = ladderList->getReferencedObject(rank); |
| 4020 | if ((referencedObject) && (account = referencedObject->getAccount())) |
| 4021 | { |
| 4022 | std::snprintf(msgtemp0, sizeof(msgtemp0), "StarCraft current %5u: %-20.20s %u/%u/%u rating %u", |
| 4023 | rank, |
| 4024 | account_get_name(account), |
| 4025 | account_get_ladder_wins(account, CLIENTTAG_STARCRAFT_UINT, ladder_id_normal), |
| 4026 | account_get_ladder_losses(account, CLIENTTAG_STARCRAFT_UINT, ladder_id_normal), |
| 4027 | account_get_ladder_disconnects(account, CLIENTTAG_STARCRAFT_UINT, ladder_id_normal), |
| 4028 | account_get_ladder_rating(account, CLIENTTAG_STARCRAFT_UINT, ladder_id_normal)); |
| 4029 | } |
| 4030 | else |
| 4031 | std::snprintf(msgtemp0, sizeof(msgtemp0), "StarCraft current %5u: <none>", rank); |
| 4032 | message_send_text(c, message_type_info, c, msgtemp0); |
| 4033 | } |
| 4034 | else if (clienttag == CLIENTTAG_BROODWARS_UINT) |
| 4035 | { |
| 4036 | ladderList = ladders.getLadderList(LadderKey(ladder_id_normal, clienttag, ladder_sort_highestrated, ladder_time_active)); |
| 4037 | referencedObject = ladderList->getReferencedObject(rank); |
| 4038 | if ((referencedObject) && (account = referencedObject->getAccount())) |
| 4039 | { |
| 4040 | std::snprintf(msgtemp0, sizeof(msgtemp0), "Brood War active %5u: %-20.20s %u/%u/%u rating %u", |
| 4041 | rank, |
| 4042 | account_get_name(account), |
| 4043 | account_get_ladder_active_wins(account, CLIENTTAG_BROODWARS_UINT, ladder_id_normal), |
| 4044 | account_get_ladder_active_losses(account, CLIENTTAG_BROODWARS_UINT, ladder_id_normal), |
| 4045 | account_get_ladder_active_disconnects(account, CLIENTTAG_BROODWARS_UINT, ladder_id_normal), |
| 4046 | account_get_ladder_active_rating(account, CLIENTTAG_BROODWARS_UINT, ladder_id_normal)); |
| 4047 | } |
| 4048 | else |
| 4049 | std::snprintf(msgtemp0, sizeof(msgtemp0), "Brood War active %5u: <none>", rank); |
| 4050 | message_send_text(c, message_type_info, c, msgtemp0); |
| 4051 | |
| 4052 | ladderList = ladders.getLadderList(LadderKey(ladder_id_normal, clienttag, ladder_sort_highestrated, ladder_time_current)); |
| 4053 | referencedObject = ladderList->getReferencedObject(rank); |
| 4054 | if ((referencedObject) && (account = referencedObject->getAccount())) |
| 4055 | { |
| 4056 | std::snprintf(msgtemp0, sizeof(msgtemp0), "Brood War current %5u: %-20.20s %u/%u/%u rating %u", |
| 4057 | rank, |
| 4058 | account_get_name(account), |
| 4059 | account_get_ladder_wins(account, CLIENTTAG_BROODWARS_UINT, ladder_id_normal), |
| 4060 | account_get_ladder_losses(account, CLIENTTAG_BROODWARS_UINT, ladder_id_normal), |
| 4061 | account_get_ladder_disconnects(account, CLIENTTAG_BROODWARS_UINT, ladder_id_normal), |
| 4062 | account_get_ladder_rating(account, CLIENTTAG_BROODWARS_UINT, ladder_id_normal)); |
| 4063 | } |
| 4064 | else |
| 4065 | std::snprintf(msgtemp0, sizeof(msgtemp0), "Brood War current %5u: <none>", rank); |
| 4066 | message_send_text(c, message_type_info, c, msgtemp0); |
| 4067 | } |
| 4068 | else if (clienttag == CLIENTTAG_WARCIIBNE_UINT) |
| 4069 | { |
| 4070 | ladderList = ladders.getLadderList(LadderKey(ladder_id_normal, clienttag, ladder_sort_highestrated, ladder_time_active)); |
| 4071 | referencedObject = ladderList->getReferencedObject(rank); |
| 4072 | if ((referencedObject) && (account = referencedObject->getAccount())) |
| 4073 | { |
| 4074 | std::snprintf(msgtemp0, sizeof(msgtemp0), "WarCraft II standard active %5u: %-20.20s %u/%u/%u rating %u", |
| 4075 | rank, |
| 4076 | account_get_name(account), |
| 4077 | account_get_ladder_active_wins(account, CLIENTTAG_WARCIIBNE_UINT, ladder_id_normal), |
| 4078 | account_get_ladder_active_losses(account, CLIENTTAG_WARCIIBNE_UINT, ladder_id_normal), |
| 4079 | account_get_ladder_active_disconnects(account, CLIENTTAG_WARCIIBNE_UINT, ladder_id_normal), |
| 4080 | account_get_ladder_active_rating(account, CLIENTTAG_WARCIIBNE_UINT, ladder_id_normal)); |
| 4081 | } |
| 4082 | else |
| 4083 | std::snprintf(msgtemp0, sizeof(msgtemp0), "WarCraft II standard active %5u: <none>", rank); |
| 4084 | message_send_text(c, message_type_info, c, msgtemp0); |
| 4085 | |
| 4086 | ladderList = ladders.getLadderList(LadderKey(ladder_id_ironman, clienttag, ladder_sort_highestrated, ladder_time_active)); |
| 4087 | referencedObject = ladderList->getReferencedObject(rank); |
| 4088 | if ((referencedObject) && (account = referencedObject->getAccount())) |
| 4089 | { |
| 4090 | std::snprintf(msgtemp0, sizeof(msgtemp0), "WarCraft II IronMan active %5u: %-20.20s %u/%u/%u rating %u", |
| 4091 | rank, |
| 4092 | account_get_name(account), |
| 4093 | account_get_ladder_active_wins(account, CLIENTTAG_WARCIIBNE_UINT, ladder_id_ironman), |
| 4094 | account_get_ladder_active_losses(account, CLIENTTAG_WARCIIBNE_UINT, ladder_id_ironman), |
| 4095 | account_get_ladder_active_disconnects(account, CLIENTTAG_WARCIIBNE_UINT, ladder_id_ironman), |
| 4096 | account_get_ladder_active_rating(account, CLIENTTAG_WARCIIBNE_UINT, ladder_id_ironman)); |
| 4097 | } |
| 4098 | else |
| 4099 | std::snprintf(msgtemp0, sizeof(msgtemp0), "WarCraft II IronMan active %5u: <none>", rank); |
| 4100 | message_send_text(c, message_type_info, c, msgtemp0); |
| 4101 | |
| 4102 | ladderList = ladders.getLadderList(LadderKey(ladder_id_normal, clienttag, ladder_sort_highestrated, ladder_time_current)); |
| 4103 | referencedObject = ladderList->getReferencedObject(rank); |
| 4104 | if ((referencedObject) && (account = referencedObject->getAccount())) |
| 4105 | { |
| 4106 | std::snprintf(msgtemp0, sizeof(msgtemp0), "WarCraft II standard current %5u: %-20.20s %u/%u/%u rating %u", |
| 4107 | rank, |
| 4108 | account_get_name(account), |
| 4109 | account_get_ladder_wins(account, CLIENTTAG_WARCIIBNE_UINT, ladder_id_normal), |
| 4110 | account_get_ladder_losses(account, CLIENTTAG_WARCIIBNE_UINT, ladder_id_normal), |
| 4111 | account_get_ladder_disconnects(account, CLIENTTAG_WARCIIBNE_UINT, ladder_id_normal), |
| 4112 | account_get_ladder_rating(account, CLIENTTAG_WARCIIBNE_UINT, ladder_id_normal)); |
| 4113 | } |
| 4114 | else |
| 4115 | std::snprintf(msgtemp0, sizeof(msgtemp0), "WarCraft II standard current %5u: <none>", rank); |
| 4116 | message_send_text(c, message_type_info, c, msgtemp0); |
| 4117 | |
| 4118 | ladderList = ladders.getLadderList(LadderKey(ladder_id_ironman, clienttag, ladder_sort_highestrated, ladder_time_current)); |
| 4119 | referencedObject = ladderList->getReferencedObject(rank); |
| 4120 | if ((referencedObject) && (account = referencedObject->getAccount())) |
| 4121 | { |
| 4122 | std::snprintf(msgtemp0, sizeof(msgtemp0), "WarCraft II IronMan current %5u: %-20.20s %u/%u/%u rating %u", |
| 4123 | rank, |
| 4124 | account_get_name(account), |
| 4125 | account_get_ladder_wins(account, CLIENTTAG_WARCIIBNE_UINT, ladder_id_ironman), |
| 4126 | account_get_ladder_losses(account, CLIENTTAG_WARCIIBNE_UINT, ladder_id_ironman), |
| 4127 | account_get_ladder_disconnects(account, CLIENTTAG_WARCIIBNE_UINT, ladder_id_ironman), |
| 4128 | account_get_ladder_rating(account, CLIENTTAG_WARCIIBNE_UINT, ladder_id_ironman)); |
| 4129 | } |
| 4130 | else |
| 4131 | std::snprintf(msgtemp0, sizeof(msgtemp0), "WarCraft II IronMan current %5u: <none>", rank); |
| 4132 | message_send_text(c, message_type_info, c, msgtemp0); |
| 4133 | } |
| 4134 | // --> aaron |
| 4135 | else if (clienttag == CLIENTTAG_WARCRAFT3_UINT || clienttag == CLIENTTAG_WAR3XP_UINT) |
| 4136 | { |
| 4137 | ladderList = ladders.getLadderList(LadderKey(ladder_id_solo, clienttag, ladder_sort_default, ladder_time_default)); |
| 4138 | referencedObject = ladderList->getReferencedObject(rank); |
| 4139 | if ((referencedObject) && (account = referencedObject->getAccount())) |
| 4140 | { |
| 4141 | std::snprintf(msgtemp0, sizeof(msgtemp0), "WarCraft3 Solo %5u: %-20.20s %u/%u/0", |
| 4142 | rank, |
| 4143 | account_get_name(account), |
| 4144 | account_get_ladder_wins(account, clienttag, ladder_id_solo), |
| 4145 | account_get_ladder_losses(account, clienttag, ladder_id_solo)); |
| 4146 | } |
| 4147 | else |
| 4148 | std::snprintf(msgtemp0, sizeof(msgtemp0), "WarCraft3 Solo %5u: <none>", rank); |
| 4149 | message_send_text(c, message_type_info, c, msgtemp0); |
| 4150 | |
| 4151 | ladderList = ladders.getLadderList(LadderKey(ladder_id_team, clienttag, ladder_sort_default, ladder_time_default)); |
| 4152 | referencedObject = ladderList->getReferencedObject(rank); |
| 4153 | if ((referencedObject) && (account = referencedObject->getAccount())) |
| 4154 | { |
| 4155 | std::snprintf(msgtemp0, sizeof(msgtemp0), "WarCraft3 Team %5u: %-20.20s %u/%u/0", |
| 4156 | rank, |
| 4157 | account_get_name(account), |
| 4158 | account_get_ladder_wins(account, clienttag, ladder_id_team), |
| 4159 | account_get_ladder_losses(account, clienttag, ladder_id_team)); |
| 4160 | } |
| 4161 | else |
| 4162 | std::snprintf(msgtemp0, sizeof(msgtemp0), "WarCraft3 Team %5u: <none>", rank); |
| 4163 | message_send_text(c, message_type_info, c, msgtemp0); |
| 4164 | |
| 4165 | ladderList = ladders.getLadderList(LadderKey(ladder_id_ffa, clienttag, ladder_sort_default, ladder_time_default)); |
| 4166 | referencedObject = ladderList->getReferencedObject(rank); |
| 4167 | if ((referencedObject) && (account = referencedObject->getAccount())) |
| 4168 | { |
| 4169 | std::snprintf(msgtemp0, sizeof(msgtemp0), "WarCraft3 FFA %5u: %-20.20s %u/%u/0", |
| 4170 | rank, |
| 4171 | account_get_name(account), |
| 4172 | account_get_ladder_wins(account, clienttag, ladder_id_ffa), |
| 4173 | account_get_ladder_losses(account, clienttag, ladder_id_ffa)); |
| 4174 | } |
| 4175 | else |
| 4176 | std::snprintf(msgtemp0, sizeof(msgtemp0), "WarCraft3 FFA %5u: <none>", rank); |
| 4177 | message_send_text(c, message_type_info, c, msgtemp0); |
| 4178 | |
| 4179 | ladderList = ladders.getLadderList(LadderKey(ladder_id_ateam, clienttag, ladder_sort_default, ladder_time_default)); |
| 4180 | referencedObject = ladderList->getReferencedObject(rank); |
| 4181 | if ((referencedObject) && (team = referencedObject->getTeam())) |
| 4182 | { |
| 4183 | t_xstr * membernames = xstr_alloc(); |
| 4184 | for (unsigned char i = 0; i < team_get_size(team); i++){ |
| 4185 | xstr_cat_str(membernames, account_get_name(team_get_member(team, i))); |
| 4186 | if ((i)) xstr_cat_char(membernames, ','); |
| 4187 | } |
| 4188 | std::snprintf(msgtemp0, sizeof(msgtemp0), "WarCraft3 AT Team %5u: %-80.80s %d/%d/0", |
| 4189 | rank, |
| 4190 | xstr_get_str(membernames), |
| 4191 | team_get_wins(team), |
| 4192 | team_get_losses(team)); |
| 4193 | xstr_free(membernames); |
| 4194 | } |
| 4195 | else |
| 4196 | std::snprintf(msgtemp0, sizeof(msgtemp0), "WarCraft3 AT Team %5u: <none>", rank); |
| 4197 | message_send_text(c, message_type_info, c, msgtemp0); |
| 4198 | } |
| 4199 | //<--- |
| 4200 | else |
| 4201 | { |
| 4202 | message_send_text(c, message_type_error, c, localize(c, "This game does not support win/loss records.")); |
| 4203 | message_send_text(c, message_type_error, c, localize(c, "You must supply a rank and a valid program ID.")); |
| 4204 | message_send_text(c, message_type_error, c, localize(c, "Example: /ladderinfo 1 STAR")); |
| 4205 | } |
| 4206 | |
| 4207 | return 0; |
| 4208 | } |
| 4209 | |
| 4210 | static int _handle_timer_command(t_connection * c, char const *text) |
| 4211 | { |
| 4212 | unsigned int delta; |
| 4213 | t_timer_data data; |
| 4214 | |
| 4215 | char const * delta_s, *msgtext_s; |
| 4216 | std::vector<std::string> args = split_command(text, 2); |
| 4217 | if (args[1].empty()) |
| 4218 | { |
| 4219 | describe_command(c, args[0].c_str()); |
| 4220 | return -1; |
| 4221 | } |
| 4222 | delta_s = args[1].c_str(); // timer delta |
| 4223 | msgtext_s = args[2].c_str(); // message text display when timer elapsed |
| 4224 | |
| 4225 | if (clockstr_to_seconds(delta_s, &delta) < 0) |
| 4226 | { |
| 4227 | message_send_text(c, message_type_error, c, localize(c, "Invalid duration.")); |
| 4228 | return -1; |
| 4229 | } |
| 4230 | |
| 4231 | if (msgtext_s[0] == '\0') |
| 4232 | data.p = xstrdup(localize(c, "Your timer has expired.").c_str()); |
| 4233 | else |
| 4234 | data.p = xstrdup(msgtext_s); |
| 4235 | |
| 4236 | if (timerlist_add_timer(c, std::time(NULL) + (std::time_t)delta, user_timer_cb, data) < 0) |
| 4237 | { |
| 4238 | eventlog(eventlog_level_error, __FUNCTION__, "Could not add timer"); |
| 4239 | xfree(data.p); |
| 4240 | message_send_text(c, message_type_error, c, localize(c, "Could not set timer.")); |
| 4241 | } |
| 4242 | else |
| 4243 | { |
| 4244 | msgtemp = localize(c, "Timer set for {} second(s)", seconds_to_timestr(delta)); |
| 4245 | message_send_text(c, message_type_info, c, msgtemp); |
| 4246 | } |
| 4247 | |
| 4248 | return 0; |
| 4249 | } |
| 4250 | |
| 4251 | static int _handle_serverban_command(t_connection *c, char const *text) |
| 4252 | { |
| 4253 | char const * username; |
| 4254 | t_connection * dest_c; |
| 4255 | |
| 4256 | std::vector<std::string> args = split_command(text, 1); |
| 4257 | if (args[1].empty()) |
| 4258 | { |
| 4259 | describe_command(c, args[0].c_str()); |
| 4260 | return -1; |
| 4261 | } |
| 4262 | username = args[1].c_str(); // username |
| 4263 | |
| 4264 | if (!(dest_c = connlist_find_connection_by_accountname(username))) |
| 4265 | { |
| 4266 | message_send_text(c, message_type_error, c, localize(c, "That user is not logged on.")); |
| 4267 | return -1; |
| 4268 | } |
| 4269 | msgtemp = localize(c, "Banning {} who is using IP address {}", conn_get_username(dest_c), addr_num_to_ip_str(conn_get_game_addr(dest_c))); |
| 4270 | message_send_text(c, message_type_info, c, msgtemp); |
| 4271 | message_send_text(c, message_type_info, c, localize(c, "User's account is also LOCKED! Only an admin can unlock it!")); |
| 4272 | msgtemp = localize(c, "/ipban a {}", addr_num_to_ip_str(conn_get_game_addr(dest_c))); |
| 4273 | handle_ipban_command(c, msgtemp.c_str()); |
| 4274 | account_set_auth_lock(conn_get_account(dest_c), 1); |
| 4275 | //now kill the connection |
| 4276 | msgtemp = localize(c, "You have been banned by Admin: {}", conn_get_username(c)); |
| 4277 | message_send_text(dest_c, message_type_error, dest_c, msgtemp); |
| 4278 | message_send_text(dest_c, message_type_error, dest_c, localize(c, "Your account is also LOCKED! Only an admin can UNLOCK it!")); |
| 4279 | conn_set_state(dest_c, conn_state_destroy); |
| 4280 | return 0; |
| 4281 | } |
| 4282 | |
| 4283 | static int _handle_netinfo_command(t_connection * c, char const *text) |
| 4284 | { |
| 4285 | char const * username; |
| 4286 | t_connection * conn; |
| 4287 | t_game const * game; |
| 4288 | unsigned int addr; |
| 4289 | unsigned short port; |
| 4290 | unsigned int taddr; |
| 4291 | unsigned short tport; |
| 4292 | |
| 4293 | std::vector<std::string> args = split_command(text, 1); |
| 4294 | username = args[1].c_str(); // username |
| 4295 | |
| 4296 | if (username[0] == '\0') |
| 4297 | username = conn_get_username(c); |
| 4298 | |
| 4299 | if (!(conn = connlist_find_connection_by_accountname(username))) |
| 4300 | { |
| 4301 | message_send_text(c, message_type_error, c, localize(c, "That user is not logged on.")); |
| 4302 | return -1; |
| 4303 | } |
| 4304 | |
| 4305 | if (conn_get_account(conn) != conn_get_account(c) && |
| 4306 | prefs_get_hide_addr() && !(account_get_command_groups(conn_get_account(c)) & command_get_group("/admin-addr"))) // default to false |
| 4307 | { |
| 4308 | message_send_text(c, message_type_error, c, localize(c, "Address information for other users is only available to admins.")); |
| 4309 | return -1; |
| 4310 | } |
| 4311 | |
| 4312 | msgtemp = localize(c, "Server TCP: {} (bind {})", addr_num_to_addr_str(conn_get_real_local_addr(conn), conn_get_real_local_port(conn)), addr_num_to_addr_str(conn_get_local_addr(conn), conn_get_local_port(conn))); |
| 4313 | message_send_text(c, message_type_info, c, msgtemp); |
| 4314 | |
| 4315 | msgtemp = localize(c, "Client TCP: {}", addr_num_to_addr_str(conn_get_addr(conn), conn_get_port(conn))); |
| 4316 | message_send_text(c, message_type_info, c, msgtemp); |
| 4317 | |
| 4318 | taddr = addr = conn_get_game_addr(conn); |
| 4319 | tport = port = conn_get_game_port(conn); |
| 4320 | trans_net(conn_get_addr(c), &taddr, &tport); |
| 4321 | |
| 4322 | if (taddr == addr && tport == port) |
| 4323 | msgtemp = localize(c, "Client UDP: {}", |
| 4324 | addr_num_to_addr_str(addr, port)); |
| 4325 | else |
| 4326 | msgtemp = localize(c, "Client UDP: {} (trans {})", |
| 4327 | addr_num_to_addr_str(addr, port), |
| 4328 | addr_num_to_addr_str(taddr, tport)); |
| 4329 | message_send_text(c, message_type_info, c, msgtemp); |
| 4330 | |
| 4331 | if ((game = conn_get_game(conn))) |
| 4332 | { |
| 4333 | taddr = addr = game_get_addr(game); |
| 4334 | tport = port = game_get_port(game); |
| 4335 | trans_net(conn_get_addr(c), &taddr, &tport); |
| 4336 | |
| 4337 | if (taddr == addr && tport == port) |
| 4338 | msgtemp = localize(c, "Game UDP: {}", |
| 4339 | addr_num_to_addr_str(addr, port)); |
| 4340 | else |
| 4341 | msgtemp = localize(c, "Game UDP: {} (trans {})", |
| 4342 | addr_num_to_addr_str(addr, port), |
| 4343 | addr_num_to_addr_str(taddr, tport)); |
| 4344 | } |
| 4345 | else |
| 4346 | msgtemp = localize(c, "Game UDP: none"); |
| 4347 | message_send_text(c, message_type_info, c, msgtemp); |
| 4348 | |
| 4349 | return 0; |
| 4350 | } |
| 4351 | |
| 4352 | static int _handle_quota_command(t_connection * c, char const * text) |
| 4353 | { |
| 4354 | msgtemp = localize(c, "Your quota allows you to write {} line(s) per {} second(s).", prefs_get_quota_lines(), prefs_get_quota_time()); |
| 4355 | message_send_text(c, message_type_info, c, msgtemp); |
| 4356 | msgtemp = localize(c, "Long lines will be wrapped every {} characters.", prefs_get_quota_wrapline()); |
| 4357 | message_send_text(c, message_type_info, c, msgtemp); |
| 4358 | msgtemp = localize(c, "You are not allowed to send lines with more than {} characters.", prefs_get_quota_maxline()); |
| 4359 | message_send_text(c, message_type_info, c, msgtemp); |
| 4360 | |
| 4361 | return 0; |
| 4362 | } |
| 4363 | |
| 4364 | static int _handle_lockacct_command(t_connection * c, char const *text) |
| 4365 | { |
| 4366 | t_connection * user; |
| 4367 | t_account * account; |
| 4368 | char const * username, *reason = "", *hours = "24"; // default time 24 hours |
| 4369 | unsigned int sectime; |
| 4370 | |
| 4371 | std::vector<std::string> args = split_command(text, 3); |
| 4372 | if (args[1].empty()) |
| 4373 | { |
| 4374 | describe_command(c, args[0].c_str()); |
| 4375 | return -1; |
| 4376 | } |
| 4377 | username = args[1].c_str(); // username |
| 4378 | if (!args[2].empty()) |
| 4379 | hours = args[2].c_str(); // hours |
| 4380 | if (!args[3].empty()) |
| 4381 | reason = args[3].c_str(); // reason |
| 4382 | |
| 4383 | if (!(account = accountlist_find_account(username))) |
| 4384 | { |
| 4385 | message_send_text(c, message_type_error, c, localize(c, "Invalid user.")); |
| 4386 | return -1; |
| 4387 | } |
| 4388 | |
| 4389 | account_set_auth_lock(account, 1); |
| 4390 | sectime = (atoi(hours) == 0) ? 0 : (atoi(hours) * 60 * 60) + now; // get unlock time in the future |
| 4391 | account_set_auth_locktime(account, sectime); |
| 4392 | account_set_auth_lockreason(account, reason); |
| 4393 | account_set_auth_lockby(account, conn_get_username(c)); |
| 4394 | |
| 4395 | |
| 4396 | // send message to author |
| 4397 | msgtemp = localize(c, "Account {} is now locked", account_get_name(account)); |
| 4398 | msgtemp += account_get_locktext(c, account, false); |
| 4399 | message_send_text(c, message_type_error, c, msgtemp); |
| 4400 | |
| 4401 | // send message to locked user |
| 4402 | if ((user = connlist_find_connection_by_accountname(username))) |
| 4403 | { |
| 4404 | msgtemp = localize(c, "Your account has just been locked"); |
| 4405 | msgtemp += account_get_locktext(c, account, true); |
| 4406 | message_send_text(user, message_type_error, user, msgtemp); |
| 4407 | } |
| 4408 | |
| 4409 | return 0; |
| 4410 | } |
| 4411 | |
| 4412 | static int _handle_unlockacct_command(t_connection * c, char const *text) |
| 4413 | { |
| 4414 | t_connection * user; |
| 4415 | t_account * account; |
| 4416 | |
| 4417 | std::vector<std::string> args = split_command(text, 1); |
| 4418 | if (args[1].empty()) |
| 4419 | { |
| 4420 | describe_command(c, args[0].c_str()); |
| 4421 | return -1; |
| 4422 | } |
| 4423 | text = args[1].c_str(); // username |
| 4424 | |
| 4425 | if (!(account = accountlist_find_account(text))) |
| 4426 | { |
| 4427 | message_send_text(c, message_type_error, c, localize(c, "Invalid user.")); |
| 4428 | return -1; |
| 4429 | } |
| 4430 | |
| 4431 | if ((user = connlist_find_connection_by_accountname(text))) |
| 4432 | { |
| 4433 | msgtemp = localize(c, "Your account has just been unlocked by {}", conn_get_username(c)); |
| 4434 | message_send_text(user, message_type_info, user, msgtemp); |
| 4435 | } |
| 4436 | |
| 4437 | account_set_auth_lock(account, 0); |
| 4438 | message_send_text(c, message_type_error, c, localize(c, "That user's account is now unlocked.")); |
| 4439 | return 0; |
| 4440 | } |
| 4441 | |
| 4442 | |
| 4443 | static int _handle_muteacct_command(t_connection * c, char const *text) |
| 4444 | { |
| 4445 | t_connection * user; |
| 4446 | t_account * account; |
| 4447 | char const * username, *reason = "", *hours = "1"; // default time 1 hour |
| 4448 | unsigned int sectime; |
| 4449 | |
| 4450 | std::vector<std::string> args = split_command(text, 3); |
| 4451 | if (args[1].empty()) |
| 4452 | { |
| 4453 | describe_command(c, args[0].c_str()); |
| 4454 | return -1; |
| 4455 | } |
| 4456 | username = args[1].c_str(); // username |
| 4457 | if (!args[2].empty()) |
| 4458 | hours = args[2].c_str(); // hours |
| 4459 | if (!args[3].empty()) |
| 4460 | reason = args[3].c_str(); // reason |
| 4461 | |
| 4462 | if (!(account = accountlist_find_account(username))) |
| 4463 | { |
| 4464 | message_send_text(c, message_type_error, c, localize(c, "Invalid user.")); |
| 4465 | return -1; |
| 4466 | } |
| 4467 | |
| 4468 | account_set_auth_mute(account, 1); |
| 4469 | // get unlock time in the future |
| 4470 | sectime = (atoi(hours) == 0) ? 0 : (atoi(hours) * 60 * 60) + now; |
| 4471 | account_set_auth_mutetime(account, sectime); |
| 4472 | account_set_auth_mutereason(account, reason); |
| 4473 | account_set_auth_muteby(account, conn_get_username(c)); |
| 4474 | |
| 4475 | // send message to author |
| 4476 | msgtemp = localize(c, "Account {} is now muted", account_get_name(account)); |
| 4477 | msgtemp += account_get_mutetext(c, account, false); |
| 4478 | message_send_text(c, message_type_error, c, msgtemp); |
| 4479 | |
| 4480 | // send message to muted user |
| 4481 | if ((user = connlist_find_connection_by_accountname(username))) |
| 4482 | { |
| 4483 | msgtemp = localize(c, "Your account has just been muted"); |
| 4484 | msgtemp += account_get_mutetext(c, account, true); |
| 4485 | message_send_text(user, message_type_error, user, msgtemp); |
| 4486 | } |
| 4487 | |
| 4488 | return 0; |
| 4489 | } |
| 4490 | |
| 4491 | static int _handle_unmuteacct_command(t_connection * c, char const *text) |
| 4492 | { |
| 4493 | t_connection * user; |
| 4494 | t_account * account; |
| 4495 | |
| 4496 | std::vector<std::string> args = split_command(text, 1); |
| 4497 | if (args[1].empty()) |
| 4498 | { |
| 4499 | describe_command(c, args[0].c_str()); |
| 4500 | return -1; |
| 4501 | } |
| 4502 | text = args[1].c_str(); // username |
| 4503 | |
| 4504 | if (!(account = accountlist_find_account(text))) |
| 4505 | { |
| 4506 | message_send_text(c, message_type_error, c, localize(c, "Invalid user.")); |
| 4507 | return -1; |
| 4508 | } |
| 4509 | |
| 4510 | if ((user = connlist_find_connection_by_accountname(text))) |
| 4511 | { |
| 4512 | msgtemp = localize(c, "Your account has just been unmuted by {}", conn_get_username(c)); |
| 4513 | message_send_text(user, message_type_info, user, msgtemp); |
| 4514 | } |
| 4515 | |
| 4516 | account_set_auth_mute(account, 0); |
| 4517 | message_send_text(c, message_type_error, c, localize(c, "That user's account is now unmuted.")); |
| 4518 | return 0; |
| 4519 | } |
| 4520 | |
| 4521 | static int _handle_flag_command(t_connection * c, char const *text) |
| 4522 | { |
| 4523 | char const * flag_s; |
| 4524 | unsigned int newflag; |
| 4525 | |
| 4526 | std::vector<std::string> args = split_command(text, 1); |
| 4527 | if (args[1].empty()) |
| 4528 | { |
| 4529 | describe_command(c, args[0].c_str()); |
| 4530 | return -1; |
| 4531 | } |
| 4532 | flag_s = args[1].c_str(); // flag |
| 4533 | |
| 4534 | newflag = std::strtoul(flag_s, NULL, 0); |
| 4535 | conn_set_flags(c, newflag); |
| 4536 | |
| 4537 | std::snprintf(msgtemp0, sizeof(msgtemp0), "0x%08x.", newflag); |
| 4538 | |
| 4539 | msgtemp = localize(c, "Flags set to {}.", msgtemp0); |
| 4540 | message_send_text(c, message_type_info, c, msgtemp); |
| 4541 | return 0; |
| 4542 | } |
| 4543 | |
| 4544 | static int _handle_tag_command(t_connection * c, char const *text) |
| 4545 | { |
| 4546 | char const * tag_s; |
| 4547 | t_clienttag clienttag; |
| 4548 | |
| 4549 | std::vector<std::string> args = split_command(text, 1); |
| 4550 | if (args[1].empty()) |
| 4551 | { |
| 4552 | describe_command(c, args[0].c_str()); |
| 4553 | return -1; |
| 4554 | } |
| 4555 | tag_s = args[1].c_str(); // flag |
| 4556 | |
| 4557 | if (clienttag = tag_validate_client(tag_s)) |
| 4558 | { |
| 4559 | unsigned int oldflags = conn_get_flags(c); |
| 4560 | conn_set_clienttag(c, clienttag); |
| 4561 | if ((clienttag == CLIENTTAG_WARCRAFT3_UINT) || (clienttag == CLIENTTAG_WAR3XP_UINT)) |
| 4562 | conn_update_w3_playerinfo(c); |
| 4563 | channel_rejoin(c); |
| 4564 | conn_set_flags(c, oldflags); |
| 4565 | channel_update_userflags(c); |
| 4566 | msgtemp = localize(c, "Client tag set to {}.", tag_s); |
| 4567 | } |
| 4568 | else |
| 4569 | msgtemp = localize(c, "Invalid clienttag {} specified", tag_s); |
| 4570 | message_send_text(c, message_type_info, c, msgtemp); |
| 4571 | return 0; |
| 4572 | } |
| 4573 | |
| 4574 | static int _handle_ipscan_command(t_connection * c, char const * text) |
| 4575 | { |
| 4576 | /* |
| 4577 | Description of _handle_ipscan_command |
| 4578 | --------------------------------------- |
| 4579 | Finds all currently logged in users with the given ip address. |
| 4580 | */ |
| 4581 | |
| 4582 | t_account * account; |
| 4583 | t_connection * conn; |
| 4584 | |
| 4585 | std::vector<std::string> args = split_command(text, 1); |
| 4586 | if (args[1].empty()) |
| 4587 | { |
| 4588 | describe_command(c, args[0].c_str()); |
| 4589 | return -1; |
| 4590 | } |
| 4591 | text = args[1].c_str(); // ip or username |
| 4592 | |
| 4593 | std::string ip; |
| 4594 | if (account = accountlist_find_account(text)) |
| 4595 | { |
| 4596 | conn = account_get_conn(account); |
| 4597 | if (conn) |
| 4598 | { |
| 4599 | // conn_get_addr returns int, so there can never be a NULL string construct |
| 4600 | ip = addr_num_to_ip_str(conn_get_addr(conn)); |
| 4601 | } |
| 4602 | else |
| 4603 | { |
| 4604 | message_send_text(c, message_type_info, c, localize(c, "Warning: That user is not online, using last known address.")); |
| 4605 | ip = account_get_ll_ip(account); |
| 4606 | if (ip.empty()) |
| 4607 | { |
| 4608 | message_send_text(c, message_type_error, c, localize(c, "Sorry, no IP address could be retrieved.")); |
| 4609 | return 0; |
| 4610 | } |
| 4611 | } |
| 4612 | } |
| 4613 | else |
| 4614 | { |
| 4615 | ip = text; |
| 4616 | } |
| 4617 | |
| 4618 | message_send_text(c, message_type_info, c, localize(c, "Scanning online users for IP {}...", ip)); |
| 4619 | |
| 4620 | t_elem const * curr; |
| 4621 | int count = 0; |
| 4622 | LIST_TRAVERSE_CONST(connlist(), curr) { |
| 4623 | conn = (t_connection *)elem_get_data(curr); |
| 4624 | if (!conn) { |
| 4625 | // got empty element |
| 4626 | continue; |
| 4627 | } |
| 4628 | |
| 4629 | if (ip.compare(addr_num_to_ip_str(conn_get_addr(conn))) == 0) |
| 4630 | { |
| 4631 | std::snprintf(msgtemp0, sizeof(msgtemp0), " %s", conn_get_loggeduser(conn)); |
| 4632 | message_send_text(c, message_type_info, c, msgtemp0); |
| 4633 | count++; |
| 4634 | } |
| 4635 | } |
| 4636 | |
| 4637 | if (count == 0) { |
| 4638 | message_send_text(c, message_type_error, c, localize(c, "There are no online users with that IP address")); |
| 4639 | } |
| 4640 | |
| 4641 | return 0; |
| 4642 | } |
| 4643 | |
| 4644 | static int _handle_set_command(t_connection * c, char const *text) |
| 4645 | { |
| 4646 | t_account * account; |
| 4647 | char const * username, *key, *value; |
| 4648 | |
| 4649 | std::vector<std::string> args = split_command(text, 3); |
| 4650 | if (args[2].empty()) |
| 4651 | { |
| 4652 | describe_command(c, args[0].c_str()); |
| 4653 | return -1; |
| 4654 | } |
| 4655 | username = args[1].c_str(); // username |
| 4656 | key = args[2].c_str(); // key |
| 4657 | value = args[3].c_str(); // value |
| 4658 | |
| 4659 | |
| 4660 | // disallow get/set value for password hash and username (hash can be cracked easily, account name should be permanent) |
| 4661 | if (strcasecmp(key, "bnet\\acct\\passhash1") == 0 || strcasecmp(key, "bnet\\acct\\username") == 0 || strcasecmp(key, "bnet\\acct\\verifier") == 0 || strcasecmp(key, "bnet\\acct\\salt") == 0 || strcasecmp(key, "bnet\\username") == 0) |
| 4662 | { |
| 4663 | message_send_text(c, message_type_info, c, localize(c, "Access denied due to security reasons.")); |
| 4664 | return -1; |
| 4665 | } |
| 4666 | |
| 4667 | if (!(account = accountlist_find_account(username))) |
| 4668 | { |
| 4669 | message_send_text(c, message_type_error, c, localize(c, "Invalid user.")); |
| 4670 | return -1; |
| 4671 | } |
| 4672 | |
| 4673 | if (*value == '\0') |
| 4674 | { |
| 4675 | if (account_get_strattr(account, key)) |
| 4676 | { |
| 4677 | msgtemp = localize(c, "Current value of {} is \"{}\"", key, account_get_strattr(account, key)); |
| 4678 | message_send_text(c, message_type_error, c, msgtemp); |
| 4679 | } |
| 4680 | else |
| 4681 | message_send_text(c, message_type_error, c, localize(c, "Value currently not set")); |
| 4682 | return 0; |
| 4683 | } |
| 4684 | |
| 4685 | // unset value |
| 4686 | if (strcasecmp(value, "null") == 0) |
| 4687 | value = NULL; |
| 4688 | |
| 4689 | std::sprintf(msgtemp0, " \"%.64s\" (%.128s = \"%.128s\")", account_get_name(account), key, value); |
| 4690 | |
| 4691 | if (account_set_strattr(account, key, value) < 0) |
| 4692 | { |
| 4693 | msgtemp = localize(c, "Unable to set key for"); |
| 4694 | msgtemp += msgtemp0; |
| 4695 | message_send_text(c, message_type_error, c, msgtemp); |
| 4696 | } |
| 4697 | else |
| 4698 | { |
| 4699 | msgtemp = localize(c, "Key set successfully for"); |
| 4700 | msgtemp += msgtemp0; |
| 4701 | message_send_text(c, message_type_error, c, msgtemp); |
| 4702 | eventlog(eventlog_level_warn, __FUNCTION__, "Key set by \"{}\" for {}", account_get_name(conn_get_account(c)),msgtemp0); |
| 4703 | } |
| 4704 | return 0; |
| 4705 | } |
| 4706 | |
| 4707 | static int _handle_motd_command(t_connection * c, char const *text) |
| 4708 | { |
| 4709 | std::string filename = i18n_filename(prefs_get_motdfile(), conn_get_gamelang_localized(c)); |
| 4710 | |
| 4711 | std::FILE* fp = std::fopen(filename.c_str(), "r"); |
| 4712 | if (fp) |
| 4713 | { |
| 4714 | message_send_file(c, fp); |
| 4715 | if (std::fclose(fp) < 0) |
| 4716 | eventlog(eventlog_level_error, __FUNCTION__, "could not close motd file \"{}\" after reading (std::fopen: {})", filename, std::strerror(errno)); |
| 4717 | } |
| 4718 | else |
| 4719 | { |
| 4720 | eventlog(eventlog_level_error, __FUNCTION__, "could not open motd file \"{}\" for reading (std::fopen: {})", filename, std::strerror(errno)); |
| 4721 | message_send_text(c, message_type_error, c, localize(c, "Unable to open motd.")); |
| 4722 | } |
| 4723 | |
| 4724 | return 0; |
| 4725 | } |
| 4726 | |
| 4727 | static int _handle_tos_command(t_connection * c, char const * text) |
| 4728 | { |
| 4729 | /* handle /tos - shows terms of service by user request -raistlinthewiz */ |
| 4730 | |
| 4731 | std::string filename = i18n_filename(prefs_get_tosfile(), conn_get_gamelang_localized(c)); |
| 4732 | /* FIXME: if user enters relative path to tos file in config, |
| 4733 | above routine will fail */ |
| 4734 | std::FILE* fp = std::fopen(filename.c_str(), "r"); |
| 4735 | if (fp) |
| 4736 | { |
| 4737 | char * buff; |
| 4738 | unsigned len; |
| 4739 | |
| 4740 | while ((buff = file_get_line(fp))) |
| 4741 | { |
| 4742 | |
| 4743 | if ((len = std::strlen(buff)) < MAX_MESSAGE_LEN) |
| 4744 | { |
| 4745 | i18n_convert(c, buff); |
| 4746 | message_send_text(c, message_type_info, c, buff); |
| 4747 | } |
| 4748 | else { |
| 4749 | /* lines in TOS file can be > MAX_MESSAGE_LEN, so split them |
| 4750 | truncating is not an option for TOS -raistlinthewiz |
| 4751 | */ |
| 4752 | |
| 4753 | while (len > MAX_MESSAGE_LEN - 1) |
| 4754 | { |
| 4755 | std::strncpy(msgtemp0, buff, MAX_MESSAGE_LEN - 1); |
| 4756 | msgtemp0[MAX_MESSAGE_LEN-1] = '\0'; |
| 4757 | buff += MAX_MESSAGE_LEN - 1; |
| 4758 | len -= MAX_MESSAGE_LEN - 1; |
| 4759 | message_send_text(c, message_type_info, c, msgtemp0); |
| 4760 | } |
| 4761 | |
| 4762 | if (len > 0) /* does it exist a small last part ? */ |
| 4763 | { |
| 4764 | i18n_convert(c, buff); |
| 4765 | message_send_text(c, message_type_info, c, buff); |
| 4766 | } |
| 4767 | |
| 4768 | } |
| 4769 | } |
| 4770 | |
| 4771 | |
| 4772 | if (std::fclose(fp) < 0) |
| 4773 | eventlog(eventlog_level_error, __FUNCTION__, "could not close tos file \"{}\" after reading (std::fopen: {})", filename, std::strerror(errno)); |
| 4774 | } |
| 4775 | else |
| 4776 | { |
| 4777 | eventlog(eventlog_level_error, __FUNCTION__, "could not open tos file \"{}\" for reading (std::fopen: {})", filename, std::strerror(errno)); |
| 4778 | message_send_text(c, message_type_error, c, localize(c, "Unable to send TOS (Terms of Service).")); |
| 4779 | } |
| 4780 | |
| 4781 | return 0; |
| 4782 | |
| 4783 | } |
| 4784 | |
| 4785 | |
| 4786 | static int _handle_ping_command(t_connection * c, char const *text) |
| 4787 | { |
| 4788 | unsigned int i; |
| 4789 | t_connection * user; |
| 4790 | t_game * game; |
| 4791 | |
| 4792 | std::vector<std::string> args = split_command(text, 1); |
| 4793 | text = args[1].c_str(); // username |
| 4794 | |
| 4795 | if (text[0] == '\0') |
| 4796 | { |
| 4797 | if ((game = conn_get_game(c))) |
| 4798 | { |
| 4799 | for (i = 0; i < game_get_count(game); i++) |
| 4800 | { |
| 4801 | if ((user = game_get_player_conn(game, i))) |
| 4802 | { |
| 4803 | msgtemp = localize(c, "{} latency: {}", conn_get_username(user), conn_get_latency(user)); |
| 4804 | message_send_text(c, message_type_info, c, msgtemp); |
| 4805 | } |
| 4806 | } |
| 4807 | return 0; |
| 4808 | } |
| 4809 | msgtemp = localize(c, "Your latency {}", conn_get_latency(c)); |
| 4810 | } |
| 4811 | else if ((user = connlist_find_connection_by_accountname(text))) |
| 4812 | msgtemp = localize(c, "{} latency ()", text, conn_get_latency(user)); |
| 4813 | else |
| 4814 | { |
| 4815 | msgtemp = localize(c, "Invalid user."); |
| 4816 | return -1; |
| 4817 | } |
| 4818 | |
| 4819 | message_send_text(c, message_type_info, c, msgtemp); |
| 4820 | return 0; |
| 4821 | } |
| 4822 | |
| 4823 | static int _handle_commandgroups_command(t_connection * c, char const * text) |
| 4824 | { |
| 4825 | t_account * account; |
| 4826 | char const * command, *username; |
| 4827 | |
| 4828 | unsigned int usergroups; // from user account |
| 4829 | unsigned int groups = 0; // converted from arg3 |
| 4830 | char tempgroups[9]; // converted from usergroups |
| 4831 | |
| 4832 | std::vector<std::string> args = split_command(text, 3); |
| 4833 | // display help if [list] without [username], or not [list] without [groups] |
| 4834 | if ( ((args[1] == "list" || args[1] == "l") && args[2].empty()) |
| 4835 | || (!(args[1] == "list" || args[1] == "l") && args[3].empty()) ) |
| 4836 | { |
| 4837 | describe_command(c, args[0].c_str()); |
| 4838 | return -1; |
| 4839 | } |
| 4840 | command = args[1].c_str(); // command |
| 4841 | username = args[2].c_str(); // username |
| 4842 | //args[3]; // groups |
| 4843 | |
| 4844 | |
| 4845 | if (!(account = accountlist_find_account(username))) { |
| 4846 | message_send_text(c, message_type_error, c, localize(c, "Invalid user.")); |
| 4847 | return -1; |
| 4848 | } |
| 4849 | |
| 4850 | usergroups = account_get_command_groups(account); |
| 4851 | |
| 4852 | if (!std::strcmp(command, "list") || !std::strcmp(command, "l")) { |
| 4853 | if (usergroups & 1) tempgroups[0] = '1'; else tempgroups[0] = ' '; |
| 4854 | if (usergroups & 2) tempgroups[1] = '2'; else tempgroups[1] = ' '; |
| 4855 | if (usergroups & 4) tempgroups[2] = '3'; else tempgroups[2] = ' '; |
| 4856 | if (usergroups & 8) tempgroups[3] = '4'; else tempgroups[3] = ' '; |
| 4857 | if (usergroups & 16) tempgroups[4] = '5'; else tempgroups[4] = ' '; |
| 4858 | if (usergroups & 32) tempgroups[5] = '6'; else tempgroups[5] = ' '; |
| 4859 | if (usergroups & 64) tempgroups[6] = '7'; else tempgroups[6] = ' '; |
| 4860 | if (usergroups & 128) tempgroups[7] = '8'; else tempgroups[7] = ' '; |
| 4861 | tempgroups[8] = '\0'; |
| 4862 | msgtemp = localize(c, "{}'s command group(s): {}", username, tempgroups); |
| 4863 | message_send_text(c, message_type_info, c, msgtemp); |
| 4864 | return 0; |
| 4865 | } |
| 4866 | |
| 4867 | // iterate chars in string |
| 4868 | for (std::string::iterator g = args[3].begin(); g != args[3].end(); ++g) { |
| 4869 | if (*g == '1') groups |= 1; |
| 4870 | else if (*g == '2') groups |= 2; |
| 4871 | else if (*g == '3') groups |= 4; |
| 4872 | else if (*g == '4') groups |= 8; |
| 4873 | else if (*g == '5') groups |= 16; |
| 4874 | else if (*g == '6') groups |= 32; |
| 4875 | else if (*g == '7') groups |= 64; |
| 4876 | else if (*g == '8') groups |= 128; |
| 4877 | else { |
| 4878 | msgtemp = localize(c, "Got bad group: {}", *g); |
| 4879 | message_send_text(c, message_type_info, c, msgtemp); |
| 4880 | return -1; |
| 4881 | } |
| 4882 | } |
| 4883 | |
| 4884 | if (!std::strcmp(command, "add") || !std::strcmp(command, "a")) { |
| 4885 | account_set_command_groups(account, usergroups | groups); |
| 4886 | msgtemp = localize(c, "Groups {} has been added to {}", args[3].c_str(), username); |
| 4887 | message_send_text(c, message_type_info, c, msgtemp); |
| 4888 | return 0; |
| 4889 | } |
| 4890 | |
| 4891 | if (!std::strcmp(command, "del") || !std::strcmp(command, "d")) { |
| 4892 | account_set_command_groups(account, usergroups & (255 - groups)); |
| 4893 | msgtemp = localize(c, "Groups {} has been deleted from {}", args[3].c_str(), username); |
| 4894 | message_send_text(c, message_type_info, c, msgtemp); |
| 4895 | return 0; |
| 4896 | } |
| 4897 | |
| 4898 | msgtemp = localize(c, "Got unknown command: {}", command); |
| 4899 | message_send_text(c, message_type_info, c, msgtemp); |
| 4900 | return -1; |
| 4901 | } |
| 4902 | |
| 4903 | static int _handle_topic_command(t_connection * c, char const * text) |
| 4904 | { |
| 4905 | std::vector<std::string> args = split_command(text, 1); |
| 4906 | std::string topicstr = args[1]; |
| 4907 | |
| 4908 | |
| 4909 | t_channel * channel = conn_get_channel(c); |
| 4910 | if (channel == nullptr) |
| 4911 | { |
| 4912 | message_send_text(c, message_type_error, c, localize(c, "This command can only be used inside a channel.")); |
| 4913 | return -1; |
| 4914 | } |
| 4915 | |
| 4916 | class_topic Topic; |
| 4917 | char const * channel_name = channel_get_name(channel); |
| 4918 | |
| 4919 | // set channel topic |
| 4920 | if (!topicstr.empty()) |
| 4921 | { |
| 4922 | if ((topicstr.size() + 1) > MAX_TOPIC_LEN) |
| 4923 | { |
| 4924 | msgtemp = localize(c, "Max topic length exceeded (max {} symbols)", MAX_TOPIC_LEN); |
| 4925 | message_send_text(c, message_type_error, c, msgtemp); |
| 4926 | return -1; |
| 4927 | } |
| 4928 | |
| 4929 | if (!(account_is_operator_or_admin(conn_get_account(c), channel_name))) |
| 4930 | { |
| 4931 | msgtemp = localize(c, "You must be at least a Channel Operator of {} to set the topic", channel_name); |
| 4932 | message_send_text(c, message_type_error, c, msgtemp); |
| 4933 | return -1; |
| 4934 | } |
| 4935 | |
| 4936 | bool do_save; |
| 4937 | if (channel_get_permanent(channel)) |
| 4938 | do_save = true; |
| 4939 | else |
| 4940 | do_save = false; |
| 4941 | |
| 4942 | Topic.set(std::string(channel_name), std::string(topicstr), do_save); |
| 4943 | } |
| 4944 | |
| 4945 | // display channel topic |
| 4946 | if (Topic.display(c, std::string(channel_name)) == false) |
| 4947 | { |
| 4948 | msgtemp = localize(c, "{} topic: no topic", channel_name); |
| 4949 | message_send_text(c, message_type_info, c, msgtemp); |
| 4950 | } |
| 4951 | |
| 4952 | return 0; |
| 4953 | } |
| 4954 | |
| 4955 | static int _handle_moderate_command(t_connection * c, char const * text) |
| 4956 | { |
| 4957 | unsigned oldflags; |
| 4958 | t_channel * channel; |
| 4959 | |
| 4960 | if (!(channel = conn_get_channel(c))) { |
| 4961 | message_send_text(c, message_type_error, c, localize(c, "This command can only be used inside a channel.")); |
| 4962 | return -1; |
| 4963 | } |
| 4964 | |
| 4965 | if (!(account_is_operator_or_admin(conn_get_account(c), channel_get_name(channel)))) { |
| 4966 | message_send_text(c, message_type_error, c, localize(c, "You must be at least a Channel Operator to use this command.")); |
| 4967 | return -1; |
| 4968 | } |
| 4969 | |
| 4970 | oldflags = channel_get_flags(channel); |
| 4971 | |
| 4972 | if (channel_set_flags(channel, oldflags ^ channel_flags_moderated)) { |
| 4973 | eventlog(eventlog_level_error, __FUNCTION__, "could not set channel {} flags", channel_get_name(channel)); |
| 4974 | message_send_text(c, message_type_error, c, localize(c, "Unable to change channel flags.")); |
| 4975 | return -1; |
| 4976 | } |
| 4977 | else { |
| 4978 | if (oldflags & channel_flags_moderated) |
| 4979 | channel_message_send(channel, message_type_info, c, localize(c, "Channel is now unmoderated.").c_str()); |
| 4980 | else |
| 4981 | channel_message_send(channel, message_type_info, c, localize(c, "Channel is now moderated.").c_str()); |
| 4982 | } |
| 4983 | |
| 4984 | return 0; |
| 4985 | } |
| 4986 | |
| 4987 | static void _reset_d1_stats(t_account *account, t_clienttag ctag, t_connection *c) |
| 4988 | { |
| 4989 | account_set_normal_level(account, ctag, 0); |
| 4990 | account_set_normal_strength(account, ctag, 0), |
| 4991 | account_set_normal_magic(account, ctag, 0), |
| 4992 | account_set_normal_dexterity(account, ctag, 0), |
| 4993 | account_set_normal_vitality(account, ctag, 0), |
| 4994 | account_set_normal_gold(account, ctag, 0); |
| 4995 | |
| 4996 | msgtemp = localize(c, "Reset {}'s {} stats", account_get_name(account), clienttag_get_title(ctag)); |
| 4997 | message_send_text(c, message_type_info, c, msgtemp); |
| 4998 | } |
| 4999 | |
| 5000 | static void _reset_scw2_stats(t_account *account, t_clienttag ctag, t_connection *c) |
| 5001 | { |
| 5002 | LadderList* ladderList; |
| 5003 | unsigned int uid = account_get_uid(account); |
| 5004 | |
| 5005 | account_set_normal_wins(account, ctag, 0); |
| 5006 | account_set_normal_losses(account, ctag, 0); |
| 5007 | account_set_normal_draws(account, ctag, 0); |
| 5008 | account_set_normal_disconnects(account, ctag, 0); |
| 5009 | |
| 5010 | // normal, current |
| 5011 | if (account_get_ladder_rating(account, ctag, ladder_id_normal) > 0) { |
| 5012 | account_set_ladder_wins(account, ctag, ladder_id_normal, 0); |
| 5013 | account_set_ladder_losses(account, ctag, ladder_id_normal, 0); |
| 5014 | account_set_ladder_draws(account, ctag, ladder_id_normal, 0); |
| 5015 | account_set_ladder_disconnects(account, ctag, ladder_id_normal, 0); |
| 5016 | account_set_ladder_rating(account, ctag, ladder_id_normal, 0); |
| 5017 | ladderList = ladders.getLadderList(LadderKey(ladder_id_normal, ctag, ladder_sort_highestrated, ladder_time_current)); |
| 5018 | if (ladderList != NULL) |
| 5019 | ladderList->delEntry(uid); |
| 5020 | ladderList = ladders.getLadderList(LadderKey(ladder_id_normal, ctag, ladder_sort_mostwins, ladder_time_current)); |
| 5021 | if (ladderList != NULL) |
| 5022 | ladderList->delEntry(uid); |
| 5023 | ladderList = ladders.getLadderList(LadderKey(ladder_id_normal, ctag, ladder_sort_mostgames, ladder_time_current)); |
| 5024 | if (ladderList != NULL) |
| 5025 | ladderList->delEntry(uid); |
| 5026 | } |
| 5027 | |
| 5028 | // ironman, current |
| 5029 | if (account_get_ladder_rating(account, ctag, ladder_id_ironman) > 0) { |
| 5030 | account_set_ladder_wins(account, ctag, ladder_id_ironman, 0); |
| 5031 | account_set_ladder_losses(account, ctag, ladder_id_ironman, 0); |
| 5032 | account_set_ladder_draws(account, ctag, ladder_id_ironman, 0); |
| 5033 | account_set_ladder_disconnects(account, ctag, ladder_id_ironman, 0); |
| 5034 | account_set_ladder_rating(account, ctag, ladder_id_ironman, 0); |
| 5035 | ladderList = ladders.getLadderList(LadderKey(ladder_id_ironman, ctag, ladder_sort_highestrated, ladder_time_current)); |
| 5036 | if (ladderList != NULL) |
| 5037 | ladderList->delEntry(uid); |
| 5038 | ladderList = ladders.getLadderList(LadderKey(ladder_id_ironman, ctag, ladder_sort_mostwins, ladder_time_current)); |
| 5039 | if (ladderList != NULL) |
| 5040 | ladderList->delEntry(uid); |
| 5041 | ladderList = ladders.getLadderList(LadderKey(ladder_id_ironman, ctag, ladder_sort_mostgames, ladder_time_current)); |
| 5042 | if (ladderList != NULL) |
| 5043 | ladderList->delEntry(uid); |
| 5044 | } |
| 5045 | |
| 5046 | // normal, active |
| 5047 | if (account_get_ladder_active_rating(account, ctag, ladder_id_normal) > 0) { |
| 5048 | account_set_ladder_active_wins(account, ctag, ladder_id_normal, 0); |
| 5049 | account_set_ladder_active_losses(account, ctag, ladder_id_normal, 0); |
| 5050 | account_set_ladder_active_draws(account, ctag, ladder_id_normal, 0); |
| 5051 | account_set_ladder_active_disconnects(account, ctag, ladder_id_normal, 0); |
| 5052 | account_set_ladder_active_rating(account, ctag, ladder_id_normal, 0); |
| 5053 | ladderList = ladders.getLadderList(LadderKey(ladder_id_normal, ctag, ladder_sort_highestrated, ladder_time_active)); |
| 5054 | if (ladderList != NULL) |
| 5055 | ladderList->delEntry(uid); |
| 5056 | ladderList = ladders.getLadderList(LadderKey(ladder_id_normal, ctag, ladder_sort_mostwins, ladder_time_active)); |
| 5057 | if (ladderList != NULL) |
| 5058 | ladderList->delEntry(uid); |
| 5059 | ladderList = ladders.getLadderList(LadderKey(ladder_id_normal, ctag, ladder_sort_mostgames, ladder_time_active)); |
| 5060 | if (ladderList != NULL) |
| 5061 | ladderList->delEntry(uid); |
| 5062 | } |
| 5063 | |
| 5064 | // ironman, active |
| 5065 | if (account_get_ladder_active_rating(account, ctag, ladder_id_ironman) > 0) { |
| 5066 | account_set_ladder_active_wins(account, ctag, ladder_id_ironman, 0); |
| 5067 | account_set_ladder_active_losses(account, ctag, ladder_id_ironman, 0); |
| 5068 | account_set_ladder_active_draws(account, ctag, ladder_id_ironman, 0); |
| 5069 | account_set_ladder_active_disconnects(account, ctag, ladder_id_ironman, 0); |
| 5070 | account_set_ladder_active_rating(account, ctag, ladder_id_ironman, 0); |
| 5071 | ladderList = ladders.getLadderList(LadderKey(ladder_id_ironman, ctag, ladder_sort_highestrated, ladder_time_active)); |
| 5072 | if (ladderList != NULL) |
| 5073 | ladderList->delEntry(uid); |
| 5074 | ladderList = ladders.getLadderList(LadderKey(ladder_id_ironman, ctag, ladder_sort_mostwins, ladder_time_active)); |
| 5075 | if (ladderList != NULL) |
| 5076 | ladderList->delEntry(uid); |
| 5077 | ladderList = ladders.getLadderList(LadderKey(ladder_id_ironman, ctag, ladder_sort_mostgames, ladder_time_active)); |
| 5078 | if (ladderList != NULL) |
| 5079 | ladderList->delEntry(uid); |
| 5080 | } |
| 5081 | |
| 5082 | msgtemp = localize(c, "Reset {}'s {} stats", account_get_name(account), clienttag_get_title(ctag)); |
| 5083 | message_send_text(c, message_type_info, c, msgtemp); |
| 5084 | } |
| 5085 | |
| 5086 | static void _reset_w3_stats(t_account *account, t_clienttag ctag, t_connection *c) |
| 5087 | { |
| 5088 | LadderList* ladderList; |
| 5089 | unsigned int uid = account_get_uid(account); |
| 5090 | |
| 5091 | account_set_ladder_level(account, ctag, ladder_id_solo, 0); |
| 5092 | account_set_ladder_xp(account, ctag, ladder_id_solo, 0); |
| 5093 | account_set_ladder_wins(account, ctag, ladder_id_solo, 0); |
| 5094 | account_set_ladder_losses(account, ctag, ladder_id_solo, 0); |
| 5095 | account_set_ladder_rank(account, ctag, ladder_id_solo, 0); |
| 5096 | ladderList = ladders.getLadderList(LadderKey(ladder_id_solo, ctag, ladder_sort_default, ladder_time_default)); |
| 5097 | if (ladderList != NULL) |
| 5098 | ladderList->delEntry(uid); |
| 5099 | |
| 5100 | account_set_ladder_level(account, ctag, ladder_id_team, 0); |
| 5101 | account_set_ladder_xp(account, ctag, ladder_id_team, 0); |
| 5102 | account_set_ladder_wins(account, ctag, ladder_id_team, 0); |
| 5103 | account_set_ladder_losses(account, ctag, ladder_id_team, 0); |
| 5104 | account_set_ladder_rank(account, ctag, ladder_id_team, 0); |
| 5105 | ladderList = ladders.getLadderList(LadderKey(ladder_id_team, ctag, ladder_sort_default, ladder_time_default)); |
| 5106 | if (ladderList != NULL) |
| 5107 | ladderList->delEntry(uid); |
| 5108 | |
| 5109 | account_set_ladder_level(account, ctag, ladder_id_ffa, 0); |
| 5110 | account_set_ladder_xp(account, ctag, ladder_id_ffa, 0); |
| 5111 | account_set_ladder_wins(account, ctag, ladder_id_ffa, 0); |
| 5112 | account_set_ladder_losses(account, ctag, ladder_id_ffa, 0); |
| 5113 | account_set_ladder_rank(account, ctag, ladder_id_ffa, 0); |
| 5114 | ladderList = ladders.getLadderList(LadderKey(ladder_id_ffa, ctag, ladder_sort_default, ladder_time_default)); |
| 5115 | if (ladderList != NULL) |
| 5116 | ladderList->delEntry(uid); |
| 5117 | // this would now need a way to delete the team for all members now |
| 5118 | //account_set_atteamcount(account,ctag,0); |
| 5119 | |
| 5120 | msgtemp = localize(c, "Reset {}'s {} stats", account_get_name(account), clienttag_get_title(ctag)); |
| 5121 | message_send_text(c, message_type_info, c, msgtemp); |
| 5122 | } |
| 5123 | |
| 5124 | static int _handle_clearstats_command(t_connection *c, char const *text) |
| 5125 | { |
| 5126 | char const * username, * tag; |
| 5127 | unsigned int all; |
| 5128 | t_account * account; |
| 5129 | t_clienttag ctag = 0; |
| 5130 | |
| 5131 | std::vector<std::string> args = split_command(text, 2); |
| 5132 | if (args[2].empty()) |
| 5133 | { |
| 5134 | describe_command(c, args[0].c_str()); |
| 5135 | return -1; |
| 5136 | } |
| 5137 | username = args[1].c_str(); |
| 5138 | tag = args[2].c_str(); // clienttag |
| 5139 | |
| 5140 | account = accountlist_find_account(username); |
| 5141 | if (!account) { |
| 5142 | message_send_text(c, message_type_error, c, localize(c, "Invalid user.")); |
| 5143 | return -1; |
| 5144 | } |
| 5145 | |
| 5146 | if (strcasecmp(tag, "all") != 0) |
| 5147 | { |
| 5148 | ctag = tag_validate_client(tag); |
| 5149 | all = 0; |
| 5150 | } |
| 5151 | else all = 1; |
| 5152 | |
| 5153 | if (all || ctag == CLIENTTAG_DIABLORTL_UINT) |
| 5154 | _reset_d1_stats(account, CLIENTTAG_DIABLORTL_UINT, c); |
| 5155 | |
| 5156 | if (all || ctag == CLIENTTAG_DIABLOSHR_UINT) |
| 5157 | _reset_d1_stats(account, CLIENTTAG_DIABLOSHR_UINT, c); |
| 5158 | |
| 5159 | if (all || ctag == CLIENTTAG_WARCIIBNE_UINT) |
| 5160 | _reset_scw2_stats(account, CLIENTTAG_WARCIIBNE_UINT, c); |
| 5161 | |
| 5162 | if (all || ctag == CLIENTTAG_STARCRAFT_UINT) |
| 5163 | _reset_scw2_stats(account, CLIENTTAG_STARCRAFT_UINT, c); |
| 5164 | |
| 5165 | if (all || ctag == CLIENTTAG_BROODWARS_UINT) |
| 5166 | _reset_scw2_stats(account, CLIENTTAG_BROODWARS_UINT, c); |
| 5167 | |
| 5168 | if (all || ctag == CLIENTTAG_SHAREWARE_UINT) |
| 5169 | _reset_scw2_stats(account, CLIENTTAG_SHAREWARE_UINT, c); |
| 5170 | |
| 5171 | if (all || ctag == CLIENTTAG_WARCRAFT3_UINT) |
| 5172 | _reset_w3_stats(account, CLIENTTAG_WARCRAFT3_UINT, c); |
| 5173 | |
| 5174 | if (all || ctag == CLIENTTAG_WAR3XP_UINT) |
| 5175 | _reset_w3_stats(account, CLIENTTAG_WAR3XP_UINT, c); |
| 5176 | |
| 5177 | ladders.update(); |
| 5178 | |
| 5179 | return 0; |
| 5180 | } |
| 5181 | |
| 5182 | /* Send message to all clients (similar to announce, but in messagebox) */ |
| 5183 | static int _handle_alert_command(t_connection * c, char const * text) |
| 5184 | { |
| 5185 | t_clienttag clienttag; |
| 5186 | t_clienttag clienttag_dest; |
| 5187 | |
| 5188 | clienttag = conn_get_clienttag(c); |
| 5189 | // disallow clients that doesn't support SID_MESSAGEBOX |
| 5190 | if (clienttag != CLIENTTAG_STARCRAFT_UINT && clienttag != CLIENTTAG_BROODWARS_UINT && clienttag != CLIENTTAG_STARJAPAN_UINT && clienttag != CLIENTTAG_SHAREWARE_UINT && |
| 5191 | clienttag != CLIENTTAG_DIABLORTL_UINT && clienttag != CLIENTTAG_DIABLOSHR_UINT && |
| 5192 | clienttag != CLIENTTAG_WARCIIBNE_UINT && clienttag != CLIENTTAG_BNCHATBOT_UINT) |
| 5193 | { |
| 5194 | message_send_text(c, message_type_error, c, localize(c, "Your game client doesn't support MessageBox.")); |
| 5195 | return -1; |
| 5196 | } |
| 5197 | |
| 5198 | std::vector<std::string> args = split_command(text, 1); |
| 5199 | if (args[1].empty()) |
| 5200 | { |
| 5201 | describe_command(c, args[0].c_str()); |
| 5202 | return -1; |
| 5203 | } |
| 5204 | |
| 5205 | // reduntant line - it adds a caption to message box |
| 5206 | std::string goodtext = args[1] + localize(c, "\n\n***************************\nBy {}", conn_get_username(c)); |
| 5207 | |
| 5208 | // caption |
| 5209 | msgtemp = localize(c, "Information from {}", prefs_get_servername()); |
| 5210 | msgtemp = localize(c, " for {}", prefs_get_servername()); |
| 5211 | |
| 5212 | t_connection * conn; |
| 5213 | t_elem const * curr; |
| 5214 | // send to online users |
| 5215 | LIST_TRAVERSE_CONST(connlist(), curr) |
| 5216 | { |
| 5217 | if (conn = (t_connection*)elem_get_data(curr)) |
| 5218 | { |
| 5219 | clienttag_dest = conn_get_clienttag(conn); |
| 5220 | |
| 5221 | if (clienttag_dest != CLIENTTAG_STARCRAFT_UINT && clienttag_dest != CLIENTTAG_BROODWARS_UINT && clienttag_dest != CLIENTTAG_STARJAPAN_UINT && clienttag_dest != CLIENTTAG_SHAREWARE_UINT && |
| 5222 | clienttag_dest != CLIENTTAG_DIABLORTL_UINT && clienttag_dest != CLIENTTAG_DIABLOSHR_UINT && |
| 5223 | clienttag_dest != CLIENTTAG_WARCIIBNE_UINT && clienttag_dest != CLIENTTAG_BNCHATBOT_UINT) { |
| 5224 | continue; |
| 5225 | } |
| 5226 | messagebox_show(conn, goodtext.c_str(), msgtemp.c_str()); |
| 5227 | } |
| 5228 | } |
| 5229 | |
| 5230 | return 0; |
| 5231 | } |
| 5232 | |
| 5233 | } |
| 5234 | } |