X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fcmd_topic.cpp;h=b3034ba39c76441ff326a6bd38cef775dd9dd4aa;hb=4487dde76ffbdb21e7dc319b3b87d09c3cf60d8c;hp=2cb64632353bfc96c93feaf56dc5f45971295ccf;hpb=293df6a8b55e89c127e60e92711ef0ef1027bff8;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/cmd_topic.cpp b/src/cmd_topic.cpp index 2cb646323..b3034ba39 100644 --- a/src/cmd_topic.cpp +++ b/src/cmd_topic.cpp @@ -2,147 +2,114 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * Inspire is copyright (C) 2002-2005 ChatSpike-Dev. - * E-mail: - * - * + * InspIRCd: (C) 2002-2007 InspIRCd Development Team + * See: http://www.inspircd.org/wiki/index.php/Credits * - * Written by Craig Edwards, Craig McLure, and others. * This program is free but copyrighted software; see * the file COPYING for details. * * --------------------------------------------------- */ -using namespace std; - -#include "inspircd_config.h" #include "inspircd.h" -#include "inspircd_io.h" -#include -#include -#ifdef GCC3 -#include -#else -#include -#endif -#include -#include -#include -#include -#include "users.h" -#include "ctables.h" -#include "globals.h" -#include "modules.h" -#include "dynamic.h" -#include "wildcard.h" -#include "message.h" -#include "commands.h" -#include "mode.h" -#include "xline.h" -#include "inspstring.h" -#include "dnsqueue.h" -#include "helperfuncs.h" -#include "hashcomp.h" -#include "socketengine.h" -#include "typedefs.h" -#include "command_parse.h" -#include "cmd_topic.h" +#include "commands/cmd_topic.h" + -extern ServerConfig* Config; -extern InspIRCd* ServerInstance; -extern int MODCOUNT; -extern std::vector modules; -extern std::vector factory; -extern time_t TIME; -extern user_hash clientlist; -extern chan_hash chanlist; -extern whowas_hash whowas; -extern std::vector all_opers; -extern std::vector local_users; -extern userrec* fd_ref_table[65536]; +extern "C" DllExport Command* init_command(InspIRCd* Instance) +{ + return new cmd_topic(Instance); +} -void cmd_topic::Handle (char **parameters, int pcnt, userrec *user) +CmdResult cmd_topic::Handle (const char** parameters, int pcnt, User *user) { - chanrec* Ptr; + Channel* Ptr; if (pcnt == 1) { - if (strlen(parameters[0]) <= CHANMAX) + Ptr = ServerInstance->FindChan(parameters[0]); + if (Ptr) { - Ptr = FindChan(parameters[0]); - if (Ptr) + if ((Ptr->IsModeSet('s')) && (!Ptr->HasUser(user))) { - if (((Ptr) && (!has_channel(user,Ptr))) && (Ptr->binarymodes & CM_SECRET)) - { - WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, Ptr->name); - return; - } - if (Ptr->topicset) - { - WriteServ(user->fd,"332 %s %s :%s", user->nick, Ptr->name, Ptr->topic); - WriteServ(user->fd,"333 %s %s %s %d", user->nick, Ptr->name, Ptr->setby, Ptr->topicset); - } - else - { - WriteServ(user->fd,"331 %s %s :No topic is set.", user->nick, Ptr->name); - } + user->WriteServ("401 %s %s :No such nick/channel",user->nick, Ptr->name); + return CMD_FAILURE; + } + if (Ptr->topicset) + { + user->WriteServ("332 %s %s :%s", user->nick, Ptr->name, Ptr->topic); + user->WriteServ("333 %s %s %s %d", user->nick, Ptr->name, Ptr->setby, Ptr->topicset); } else { - WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]); + user->WriteServ("331 %s %s :No topic is set.", user->nick, Ptr->name); } } - return; + else + { + user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]); + return CMD_FAILURE; + } + return CMD_SUCCESS; } else if (pcnt>1) { - if (strlen(parameters[0]) <= CHANMAX) + Ptr = ServerInstance->FindChan(parameters[0]); + if (Ptr) { - Ptr = FindChan(parameters[0]); - if (Ptr) + if (IS_LOCAL(user)) { - if ((Ptr) && (!has_channel(user,Ptr))) + if (!Ptr->HasUser(user)) { - WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, Ptr->name); - return; + user->WriteServ("442 %s %s :You're not on that channel!",user->nick, Ptr->name); + return CMD_FAILURE; } - if ((Ptr->binarymodes & CM_TOPICLOCK) && (cstatus(user,Ptr)IsModeSet('t')) && (Ptr->GetStatus(user) < STATUS_HOP)) { - WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel", user->nick, Ptr->name); - return; + user->WriteServ("482 %s %s :You must be at least a half-operator to change the topic on this channel", user->nick, Ptr->name); + return CMD_FAILURE; } + } - char topic[MAXBUF]; - strlcpy(topic,parameters[1],MAXBUF); - if (strlen(topic)>MAXTOPIC) - { - topic[MAXTOPIC] = '\0'; - } + char topic[MAXTOPIC]; - if (user->fd > -1) - { - int MOD_RESULT = 0; - FOREACH_RESULT(OnLocalTopicChange(user,Ptr,topic)); - if (MOD_RESULT) - return; - } + if (IS_LOCAL(user)) + { + /* XXX: we need two string copies for a local topic, because we cant + * let a module see the topic as longer than it actually is + */ + int MOD_RESULT = 0; - strlcpy(Ptr->topic,topic,MAXTOPIC); - strlcpy(Ptr->setby,user->nick,NICKMAX); - Ptr->topicset = TIME; - WriteChannel(Ptr,user,"TOPIC %s :%s",Ptr->name, Ptr->topic); - if (user->fd > -1) - { - FOREACH_MOD OnPostLocalTopicChange(user,Ptr,topic); - } + strlcpy(topic,parameters[1],MAXTOPIC-1); + FOREACH_RESULT(I_OnLocalTopicChange,OnLocalTopicChange(user,Ptr,topic)); + if (MOD_RESULT) + return CMD_FAILURE; + + strlcpy(Ptr->topic,topic,MAXTOPIC-1); } else { - WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]); + /* Sneaky shortcut, one string copy for a remote topic */ + strlcpy(Ptr->topic, parameters[1], MAXTOPIC-1); } + + if (ServerInstance->Config->FullHostInTopic) + strlcpy(Ptr->setby,user->GetFullHost(),127); + else + strlcpy(Ptr->setby,user->nick,127); + + Ptr->topicset = ServerInstance->Time(); + Ptr->WriteChannel(user, "TOPIC %s :%s", Ptr->name, Ptr->topic); + + if (IS_LOCAL(user)) + /* We know 'topic' will contain valid data here */ + FOREACH_MOD(I_OnPostLocalTopicChange,OnPostLocalTopicChange(user, Ptr, topic)); + } + else + { + user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]); + return CMD_FAILURE; } } + return CMD_SUCCESS; } -