command.c
上传用户:tany51
上传日期:2013-06-12
资源大小:1397k
文件大小:142k
- /*
- * Copyright (C) 1998 Mark Baysinger (mbaysing@ucsd.edu)
- * Copyright (C) 1998,1999,2000,2001 Ross Combs (rocombs@cs.nmsu.edu)
- * Copyright (C) 1999 Gediminas (gediminas_lt@mailexcite.com)
- * Copyright (C) 1999 Rob Crittenden (rcrit@greyoak.com)
- * Copyright (C) 2000,2001 Marco Ziech (mmz@gmx.net)
- * Copyright (C) 2000 Dizzy (dizzy@roedu.net)
- * Copyright (C) 2000 Onlyer (onlyer@263.net)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- #include "common/setup_before.h"
- #include <stdio.h>
- #ifdef HAVE_STDDEF_H
- # include <stddef.h>
- #else
- # ifndef NULL
- # define NULL ((void *)0)
- # endif
- #endif
- #ifdef STDC_HEADERS
- # include <stdlib.h>
- #else
- # ifdef HAVE_MALLOC_H
- # include <malloc.h>
- # endif
- #endif
- #include "compat/strtoul.h"
- #ifdef HAVE_STRING_H
- # include <string.h>
- #else
- # ifdef HAVE_STRINGS_H
- # include <strings.h>
- # endif
- #endif
- #include "compat/strdup.h"
- #include "compat/strcasecmp.h"
- #include <ctype.h>
- #include <errno.h>
- #include "compat/strerror.h"
- #ifdef TIME_WITH_SYS_TIME
- # include <sys/time.h>
- # include <time.h>
- #else
- # ifdef HAVE_SYS_TIME_H
- # include <sys/time.h>
- # else
- # include <time.h>
- # endif
- #endif
- #ifdef HAVE_SYS_TYPES
- # include <sys/types.h>
- #endif
- #include "compat/strftime.h"
- #include "message.h"
- #include "common/tag.h"
- #include "connection.h"
- #include "channel.h"
- #include "game.h"
- #include "common/util.h"
- #include "common/version.h"
- #include "account.h"
- #include "server.h"
- #include "prefs.h"
- #include "common/eventlog.h"
- #include "ladder.h"
- #include "timer.h"
- #include "common/bnettime.h"
- #include "common/addr.h"
- #include "common/packet.h"
- #include "gametrans.h"
- #include "helpfile.h"
- #include "mail.h"
- #include "common/bnethash.h"
- #include "runprog.h"
- #include "common/list.h"
- #include "common/proginfo.h"
- #include "alias_command.h"
- #include "realm.h"
- #include "ipban.h"
- #include "command_groups.h"
- #include "common/queue.h"
- #include "common/bn_type.h"
- #include "command.h"
- #include "news.h"
- #include "common/setup_after.h"
- // aaron
- #include "topic.h"
- #include "friends.h"
- #include "clan.h"
- static char const * bnclass_get_str(unsigned int class);
- static void do_whisper(t_connection * user_c, char const * dest, char const * text);
- static void do_whois(t_connection * c, char const * dest);
- static void user_timer_cb(t_connection * c, time_t now, t_timer_data str);
- char msgtemp[MAX_MESSAGE_LEN];
- static char const * bnclass_get_str(unsigned int class)
- {
- switch (class)
- {
- case PLAYERINFO_DRTL_CLASS_WARRIOR:
- return "warrior";
- case PLAYERINFO_DRTL_CLASS_ROGUE:
- return "rogue";
- case PLAYERINFO_DRTL_CLASS_SORCERER:
- return "sorcerer";
- default:
- return "unknown";
- }
- }
- static void do_whisper(t_connection * user_c, char const * dest, char const * text)
- {
- t_connection * dest_c;
- char const * tname;
-
- if (!(dest_c = connlist_find_connection_by_name(dest,conn_get_realmname(user_c))))
- {
- message_send_text(user_c,message_type_error,user_c,"That user is not logged on.");
- return;
- }
-
- if (conn_get_dndstr(dest_c))
- {
- sprintf(msgtemp,"%.64s is unavailable (%.128s)",(tname = conn_get_username(dest_c)),conn_get_dndstr(dest_c));
- conn_unget_username(dest_c,tname);
- message_send_text(user_c,message_type_info,user_c,msgtemp);
- return;
- }
-
- message_send_text(user_c,message_type_whisperack,dest_c,text);
-
- if (conn_get_awaystr(dest_c))
- {
- sprintf(msgtemp,"%.64s is away (%.128s)",(tname = conn_get_username(dest_c)),conn_get_awaystr(dest_c));
- conn_unget_username(dest_c,tname);
- message_send_text(user_c,message_type_info,user_c,msgtemp);
- }
-
- message_send_text(dest_c,message_type_whisper,user_c,text);
-
- if ((tname = conn_get_username(user_c)))
- {
- char username[1+USER_NAME_MAX]; /* '*' + username (including NUL) */
-
- if (strlen(tname)<USER_NAME_MAX)
- {
- sprintf(username,"*%s",tname);
- conn_set_lastsender(dest_c,username);
- }
- conn_unget_username(dest_c,tname);
- }
- }
- static void do_whois(t_connection * c, char const * dest)
- {
- t_connection * dest_c;
- char namepart[136]; /* 64 + " (" + 64 + ")" + NUL */
- char const * verb;
- t_game const * game;
- t_channel const * channel;
-
- if (!(dest_c = connlist_find_connection_by_accountname(dest)))
- {
- t_account * dest_a;
- t_bnettime btlogin;
- time_t ulogin;
- struct tm * tmlogin;
- if (!(dest_a = accountlist_find_account(dest))) {
- message_send_text(c,message_type_error,c,"Unknown user.");
- return;
- }
- if (conn_get_class(c) == conn_class_bnet) {
- btlogin = time_to_bnettime((time_t)account_get_ll_time(dest_a),0);
- btlogin = bnettime_add_tzbias(btlogin, conn_get_tzbias(c));
- ulogin = bnettime_to_time(btlogin);
- if (!(tmlogin = gmtime(&ulogin)))
- strcpy(msgtemp, "User was last seen on ?");
- else
- strftime(msgtemp, sizeof(msgtemp), "User was last seen on : %a %b %d %H:%M:%S",tmlogin);
- } else strcpy(msgtemp, "User is offline");
- message_send_text(c, message_type_info, c, msgtemp);
- return;
- }
-
- if (c==dest_c)
- {
- strcpy(namepart,"You");
- verb = "are";
- }
- else
- {
- char const * tname;
-
- sprintf(namepart,"%.64s",(tname = conn_get_username(dest_c)));
- conn_unget_username(dest_c,tname);
- verb = "is";
- }
-
- if ((game = conn_get_game(dest_c)))
- {
- sprintf(msgtemp,"%s %s logged on from account "UID_FORMAT", and %s currently in %s game "%.64s".",
- namepart,
- verb,
- conn_get_userid(dest_c),
- verb,
- game_get_flag(game) == game_flag_private ? "private" : "",
- game_get_name(game));
- }
- else if ((channel = conn_get_channel(dest_c)))
- {
- sprintf(msgtemp,"%s %s logged on from account "UID_FORMAT", and %s currently in channel "%.64s".",
- namepart,
- verb,
- conn_get_userid(dest_c),
- verb,
- channel_get_name(channel));
- }
- else
- sprintf(msgtemp,"%s %s logged on from account "UID_FORMAT".",
- namepart,
- verb,
- conn_get_userid(dest_c));
- message_send_text(c,message_type_info,c,msgtemp);
-
- if (conn_get_dndstr(dest_c))
- {
- sprintf(msgtemp,"%s %s refusing messages (%.128s)",
- namepart,
- verb,
- conn_get_dndstr(dest_c));
- message_send_text(c,message_type_info,c,msgtemp);
- }
- else
- if (conn_get_awaystr(dest_c))
- {
- sprintf(msgtemp,"%s away (%.128s)",
- namepart,
- conn_get_awaystr(dest_c));
- message_send_text(c,message_type_info,c,msgtemp);
- }
- }
- static void user_timer_cb(t_connection * c, time_t now, t_timer_data str)
- {
- if (!c)
- {
- eventlog(eventlog_level_error,"user_timer_cb","got NULL connection");
- return;
- }
- if (!str.p)
- {
- eventlog(eventlog_level_error,"user_timer_cb","got NULL str");
- return;
- }
-
- if (now!=(time_t)0) /* zero means user logged out before expiration */
- message_send_text(c,message_type_info,c,str.p);
- free(str.p);
- }
- typedef int (* t_command)(t_connection * c, char const * text);
- typedef struct {
- const char * command_string;
- t_command command_handler;
- } t_command_table_row;
- static int command_set_flags(t_connection * c); // [Omega]
- // command handler prototypes
- static int _handle_clan_command(t_connection * c, char const * text);
- static int _handle_admin_command(t_connection * c, char const * text);
- static int _handle_aop_command(t_connection * c, char const * text);
- static int _handle_op_command(t_connection * c, char const * text);
- static int _handle_tmpop_command(t_connection * c, char const * text);
- static int _handle_deop_command(t_connection * c, char const * text);
- static int _handle_voice_command(t_connection * c, char const * text);
- static int _handle_devoice_command(t_connection * c, char const * text);
- static int _handle_vop_command(t_connection * c, char const * text);
- static int _handle_friends_command(t_connection * c, char const * text);
- static int _handle_me_command(t_connection * c, char const * text);
- static int _handle_whisper_command(t_connection * c, char const * text);
- static int _handle_status_command(t_connection * c, char const * text);
- static int _handle_who_command(t_connection * c, char const * text);
- static int _handle_whois_command(t_connection * c, char const * text);
- static int _handle_whoami_command(t_connection * c, char const * text);
- static int _handle_announce_command(t_connection * c, char const * text);
- static int _handle_beep_command(t_connection * c, char const * text);
- static int _handle_nobeep_command(t_connection * c, char const * text);
- static int _handle_version_command(t_connection * c, char const * text);
- static int _handle_copyright_command(t_connection * c, char const * text);
- static int _handle_uptime_command(t_connection * c, char const * text);
- static int _handle_stats_command(t_connection * c, char const * text);
- static int _handle_time_command(t_connection * c, char const * text);
- static int _handle_channel_command(t_connection * c, char const * text);
- static int _handle_rejoin_command(t_connection * c, char const * text);
- static int _handle_away_command(t_connection * c, char const * text);
- static int _handle_dnd_command(t_connection * c, char const * text);
- static int _handle_squelch_command(t_connection * c, char const * text);
- static int _handle_unsquelch_command(t_connection * c, char const * text);
- //static int _handle_designate_command(t_connection * c, char const * text); Obsolete function [Omega]
- //static int _handle_resign_command(t_connection * c, char const * text); Obsolete function [Omega]
- static int _handle_kick_command(t_connection * c, char const * text);
- static int _handle_ban_command(t_connection * c, char const * text);
- static int _handle_unban_command(t_connection * c, char const * text);
- static int _handle_reply_command(t_connection * c, char const * text);
- static int _handle_realmann_command(t_connection * c, char const * text);
- static int _handle_watch_command(t_connection * c, char const * text);
- static int _handle_unwatch_command(t_connection * c, char const * text);
- static int _handle_watchall_command(t_connection * c, char const * text);
- static int _handle_unwatchall_command(t_connection * c, char const * text);
- static int _handle_lusers_command(t_connection * c, char const * text);
- static int _handle_news_command(t_connection * c, char const * text);
- static int _handle_games_command(t_connection * c, char const * text);
- static int _handle_channels_command(t_connection * c, char const * text);
- static int _handle_addacct_command(t_connection * c, char const * text);
- static int _handle_chpass_command(t_connection * c, char const * text);
- static int _handle_connections_command(t_connection * c, char const * text);
- static int _handle_finger_command(t_connection * c, char const * text);
- static int _handle_operator_command(t_connection * c, char const * text);
- static int _handle_admins_command(t_connection * c, char const * text);
- static int _handle_quit_command(t_connection * c, char const * text);
- static int _handle_kill_command(t_connection * c, char const * text);
- static int _handle_killsession_command(t_connection * c, char const * text);
- static int _handle_gameinfo_command(t_connection * c, char const * text);
- static int _handle_ladderactivate_command(t_connection * c, char const * text);
- static int _handle_rehash_command(t_connection * c, char const * text);
- //static int _handle_rank_all_accounts_command(t_connection * c, char const * text);
- static int _handle_shutdown_command(t_connection * c, char const * text);
- static int _handle_ladderinfo_command(t_connection * c, char const * text);
- static int _handle_timer_command(t_connection * c, char const * text);
- static int _handle_serverban_command(t_connection * c, char const * text);
- static int _handle_netinfo_command(t_connection * c, char const * text);
- static int _handle_quota_command(t_connection * c, char const * text);
- static int _handle_lockacct_command(t_connection * c, char const * text);
- static int _handle_unlockacct_command(t_connection * c, char const * text);
- static int _handle_flag_command(t_connection * c, char const * text);
- static int _handle_tag_command(t_connection * c, char const * text);
- //static int _handle_ipban_command(t_connection * c, char const * text); Redirected to handle_ipban_command() in ipban.c [Omega]
- static int _handle_set_command(t_connection * c, char const * text);
- static int _handle_motd_command(t_connection * c, char const * text);
- static int _handle_ping_command(t_connection * c, char const * text);
- static int _handle_commandgroups_command(t_connection * c, char const * text);
- static int _handle_topic_command(t_connection * c, char const * text);
- static const t_command_table_row standard_command_table[] =
- {
- { "/clan" , _handle_clan_command },
- { "/c" , _handle_clan_command },
- { "/admin" , _handle_admin_command },
- { "/f" , _handle_friends_command },
- { "/friends" , _handle_friends_command },
- { "/me" , _handle_me_command },
- { "/msg" , _handle_whisper_command },
- { "/whisper" , _handle_whisper_command },
- { "/w" , _handle_whisper_command },
- { "/m" , _handle_whisper_command },
- { "/status" , _handle_status_command },
- { "/users" , _handle_status_command },
- { "/who" , _handle_who_command },
- { "/whois" , _handle_whois_command },
- { "/whereis" , _handle_whois_command },
- { "/where" , _handle_whois_command },
- { "/whoami" , _handle_whoami_command },
- { "/announce" , _handle_announce_command },
- { "/beep" , _handle_beep_command },
- { "/nobeep" , _handle_nobeep_command },
- { "/version" , _handle_version_command },
- { "/copyright" , _handle_copyright_command },
- { "/warrenty" , _handle_copyright_command },
- { "/license" , _handle_copyright_command },
- { "/uptime" , _handle_uptime_command },
- { "/stats" , _handle_stats_command },
- { "/astat" , _handle_stats_command },
- { "/time" , _handle_time_command },
- { "/channel" , _handle_channel_command },
- { "/join" , _handle_channel_command },
- { "/rejoin" , _handle_rejoin_command },
- { "/away" , _handle_away_command },
- { "/dnd" , _handle_dnd_command },
- { "/ignore" , _handle_squelch_command },
- { "/squelch" , _handle_squelch_command },
- { "/unignore" , _handle_unsquelch_command },
- { "/unsquelch" , _handle_unsquelch_command },
- // { "/designate" , _handle_designate_command }, Obsotele command [Omega]
- // { "/resign" , _handle_resign_command }, Obsolete command [Omega]
- { "/kick" , _handle_kick_command },
- { "/ban" , _handle_ban_command },
- { "/unban" , _handle_unban_command },
- { NULL , NULL }
-
- };
- static const t_command_table_row extended_command_table[] =
- {
- { "/ann" , _handle_announce_command },
- { "/r" , _handle_reply_command },
- { "/reply" , _handle_reply_command },
- { "/realmann" , _handle_realmann_command },
- { "/watch" , _handle_watch_command },
- { "/unwatch" , _handle_unwatch_command },
- { "/watchall" , _handle_watchall_command },
- { "/unwatchall" , _handle_unwatchall_command },
- { "/lusers" , _handle_lusers_command },
- { "/news" , _handle_news_command },
- { "/games" , _handle_games_command },
- { "/channels" , _handle_channels_command },
- { "/chs" , _handle_channels_command },
- { "/addacct" , _handle_addacct_command },
- { "/chpass" , _handle_chpass_command },
- { "/connections" , _handle_connections_command },
- { "/con" , _handle_connections_command },
- { "/finger" , _handle_finger_command },
- { "/operator" , _handle_operator_command },
- { "/aop" , _handle_aop_command },
- { "/op" , _handle_op_command },
- { "/tmpop" , _handle_tmpop_command },
- { "/deop" , _handle_deop_command },
- { "/voice" , _handle_voice_command },
- { "/devoice" , _handle_devoice_command },
- { "/vop" , _handle_vop_command },
- { "/admins" , _handle_admins_command },
- { "/logout" , _handle_quit_command },
- { "/quit" , _handle_quit_command },
- { "/exit" , _handle_quit_command },
- { "/kill" , _handle_kill_command },
- { "/killsession" , _handle_killsession_command },
- { "/gameinfo" , _handle_gameinfo_command },
- { "/ladderactivate" , _handle_ladderactivate_command },
- { "/rehash" , _handle_rehash_command },
- // { "/rank_all_accounts" , _handle_rank_all_accounts_command },
- { "/shutdown" , _handle_shutdown_command },
- { "/ladderinfo" , _handle_ladderinfo_command },
- { "/timer" , _handle_timer_command },
- { "/serverban" , _handle_serverban_command },
- { "/netinfo" , _handle_netinfo_command },
- { "/quota" , _handle_quota_command },
- { "/lockacct" , _handle_lockacct_command },
- { "/unlockacct" , _handle_unlockacct_command },
- { "/flag" , _handle_flag_command },
- { "/tag" , _handle_tag_command },
- { "/help" , handle_help_command },
- { "/mail" , handle_mail_command },
- { "/ipban" , handle_ipban_command }, // in ipban.c
- { "/set" , _handle_set_command },
- { "/motd" , _handle_motd_command },
- { "/latency" , _handle_ping_command },
- { "/ping" , _handle_ping_command },
- { "/p" , _handle_ping_command },
- { "/commandgroups" , _handle_commandgroups_command },
- { "/cg" , _handle_commandgroups_command },
- { "/topic" , _handle_topic_command },
- { NULL , NULL }
- };
- char const * skip_command(char const * org_text)
- {
- unsigned int i;
- char * text = (char *)org_text;
- for (i=0; text[i]!=' ' && text[i]!=' '; i++); /* skip command */
- if (text[i]!=' ') text[i++]=' '; /*