diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-09-03 21:06:44 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-09-03 21:06:44 +0000 |
commit | 17fd32bf7492aa40ce531b64c81754f039907ca7 (patch) | |
tree | 52fce21614c7697cee868135fe1c715be09dfe0e | |
parent | 1c1c5fc3f01c42a09d34594989679bbc8fb21c0d (diff) |
Remove HandleInternal and HandleServer, they are duplicated by Request* and FakeUser
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11672 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/commands/cmd_whowas.h | 41 | ||||
-rw-r--r-- | include/ctables.h | 21 | ||||
-rw-r--r-- | src/commands/cmd_nick.cpp | 25 | ||||
-rw-r--r-- | src/commands/cmd_whowas.cpp | 75 | ||||
-rw-r--r-- | src/configreader.cpp | 7 | ||||
-rw-r--r-- | src/stats.cpp | 18 | ||||
-rw-r--r-- | src/users.cpp | 12 |
7 files changed, 80 insertions, 119 deletions
diff --git a/include/commands/cmd_whowas.h b/include/commands/cmd_whowas.h index b28f44e17..e4fc69533 100644 --- a/include/commands/cmd_whowas.h +++ b/include/commands/cmd_whowas.h @@ -13,20 +13,25 @@ #ifndef __CMD_WHOWAS_H__ #define __CMD_WHOWAS_H__ +#include "modules.h" - -// include the common header files - -#include "users.h" -#include "channels.h" - -/* list of available internal commands */ -enum Internals +struct WhowasRequest : public Request { - WHOWAS_ADD = 1, - WHOWAS_STATS = 2, - WHOWAS_PRUNE = 3, - WHOWAS_MAINTAIN = 4 + /* list of available internal commands */ + enum Internals + { + WHOWAS_ADD = 1, + WHOWAS_STATS = 2, + WHOWAS_PRUNE = 3, + WHOWAS_MAINTAIN = 4 + }; + + const Internals type; + std::string value; + User* user; + + WhowasRequest(Module* src, Module* whowas, Internals Type) : Request(src, whowas, "WHOWAS"), type(Type) + {} }; /* Forward ref for timer */ @@ -80,19 +85,11 @@ class CommandWhowas : public Command * @return A value from CmdResult to indicate command success or failure. */ CmdResult Handle(const std::vector<std::string>& parameters, User *user); - /** Handle an internal request from another command, the core, or a module - * @param Command ID - * @param Zero or more parameters, whos form is specified by the command ID. - * @return Return CMD_SUCCESS on success, or CMD_FAILURE on failure. - * If the command succeeds but should remain local to this server, - * return CMD_LOCALONLY. - */ - CmdResult HandleInternal(const unsigned int id, const std::deque<classbase*> ¶meters); void AddToWhoWas(User* user); - void GetStats(Extensible* ext); + std::string GetStats(); void PruneWhoWas(time_t t); void MaintainWhoWas(time_t t); - virtual ~CommandWhowas(); + ~CommandWhowas(); }; /** Used to hold WHOWAS information diff --git a/include/ctables.h b/include/ctables.h index b57a29b4d..d3baec041 100644 --- a/include/ctables.h +++ b/include/ctables.h @@ -179,27 +179,6 @@ class CoreExport Command : public Extensible return ROUTE_LOCALONLY; } - /** Handle an internal request from another command, the core, or a module - * @param Command ID - * @param Zero or more parameters, whos form is specified by the command ID. - * @return Return CMD_SUCCESS on success, or CMD_FAILURE on failure. - */ - virtual CmdResult HandleInternal(const unsigned int /* id */, const std::deque<classbase*>& /* params */) - { - return CMD_INVALID; - } - - /** Handle the command from a server. - * Not currently used in this version of InspIRCd. - * @param parameters The parameters given - * @param servername The server name which issued the command - * @return Return CMD_SUCCESS on success, or CMD_FAILURE on failure. - */ - virtual CmdResult HandleServer(const std::vector<std::string>& /* parameters */, const std::string& /* servername */) - { - return CMD_INVALID; - } - /** Encode a parameter for server->server transmission. * Used for parameters for which the translation type is TR_CUSTOM. * @param parameter The parameter to encode. Can be modified in place. diff --git a/src/commands/cmd_nick.cpp b/src/commands/cmd_nick.cpp index ecc254f17..3851b36e6 100644 --- a/src/commands/cmd_nick.cpp +++ b/src/commands/cmd_nick.cpp @@ -41,11 +41,10 @@ */ class CommandNick : public Command { - bool allowinvalid; public: /** Constructor for nick. */ - CommandNick (InspIRCd* Instance, Module* parent) : Command(Instance,parent,"NICK", 0, 1, true, 3), allowinvalid(false) { syntax = "<newnick>"; } + CommandNick (InspIRCd* Instance, Module* parent) : Command(Instance,parent,"NICK", 0, 1, true, 3) { syntax = "<newnick>"; } /** Handle command. * @param parameters The parameters to the comamnd * @param pcnt The number of parameters passed to teh command @@ -53,13 +52,6 @@ class CommandNick : public Command * @return A value from CmdResult to indicate command success or failure. */ CmdResult Handle(const std::vector<std::string>& parameters, User *user); - - /** Handle internal command - * @param id Used to indicate if invalid nick changes are allowed. - * Set to 1 to allow invalid nicks and 0 to deny them. - * @param parameters Currently unused - */ - CmdResult HandleInternal(const unsigned int id, const std::deque<classbase*> ¶meters); }; #endif @@ -83,17 +75,16 @@ CmdResult CommandNick::Handle (const std::vector<std::string>& parameters, User if (((!ServerInstance->IsNick(parameters[0].c_str(), ServerInstance->Config->Limits.NickMax))) && (IS_LOCAL(user))) { - if (!allowinvalid) + if (!user->GetExt("NICKForced")) { if (parameters[0] == "0") { // Special case, Fake a /nick UIDHERE. Useful for evading "ERR: NICK IN USE" on connect etc. std::vector<std::string> p2; - std::deque<classbase*> dummy; p2.push_back(user->uuid); - this->HandleInternal(1, dummy); + user->Extend("NICKForced"); this->Handle(p2, user); - this->HandleInternal(0, dummy); + user->Shrink("NICKForced"); return CMD_SUCCESS; } @@ -136,7 +127,7 @@ CmdResult CommandNick::Handle (const std::vector<std::string>& parameters, User * Also don't check Q:Lines for remote nickchanges, they should have our Q:Lines anyway to enforce themselves. * -- w00t */ - if (!allowinvalid || !IS_LOCAL(user)) + if (!IS_LOCAL(user)) { XLine* mq = ServerInstance->XLines->MatchesLine("Q",parameters[0]); if (mq) @@ -251,11 +242,5 @@ CmdResult CommandNick::Handle (const std::vector<std::string>& parameters, User } -CmdResult CommandNick::HandleInternal(const unsigned int id, const std::deque<classbase*>&) -{ - allowinvalid = (id != 0); - return CMD_SUCCESS; -} - COMMAND_INIT(CommandNick) diff --git a/src/commands/cmd_whowas.cpp b/src/commands/cmd_whowas.cpp index 5e77671a6..3df97086e 100644 --- a/src/commands/cmd_whowas.cpp +++ b/src/commands/cmd_whowas.cpp @@ -82,33 +82,7 @@ CmdResult CommandWhowas::Handle (const std::vector<std::string>& parameters, Use return CMD_SUCCESS; } -CmdResult CommandWhowas::HandleInternal(const unsigned int id, const std::deque<classbase*> ¶meters) -{ - switch (id) - { - case WHOWAS_ADD: - AddToWhoWas(static_cast<User*>(parameters[0])); - break; - - case WHOWAS_STATS: - GetStats(static_cast<Extensible*>(parameters[0])); - break; - - case WHOWAS_PRUNE: - PruneWhoWas(ServerInstance->Time()); - break; - - case WHOWAS_MAINTAIN: - MaintainWhoWas(ServerInstance->Time()); - break; - - default: - break; - } - return CMD_SUCCESS; -} - -void CommandWhowas::GetStats(Extensible* ext) +std::string CommandWhowas::GetStats() { int whowas_size = 0; int whowas_bytes = 0; @@ -123,7 +97,7 @@ void CommandWhowas::GetStats(Extensible* ext) } } stats.assign("Whowas(MAPSETS) " +ConvToStr(whowas_size)+" ("+ConvToStr(whowas_bytes)+" bytes)"); - ext->Extend("stats", stats.c_str()); + return stats; } void CommandWhowas::AddToWhoWas(User* user) @@ -323,12 +297,47 @@ WhoWasGroup::~WhoWasGroup() /* every hour, run this function which removes all entries older than Config->WhoWasMaxKeep */ void WhoWasMaintainTimer::Tick(time_t) { - Command* whowas_command = ServerInstance->Parser->GetHandler("WHOWAS"); - if (whowas_command) + Module* whowas = ServerInstance->Modules->Find("cmd_whowas.so"); + if (whowas) { - std::deque<classbase*> params; - whowas_command->HandleInternal(WHOWAS_MAINTAIN, params); + WhowasRequest(whowas, whowas, WhowasRequest::WHOWAS_MAINTAIN).Send(); } } -COMMAND_INIT(CommandWhowas) +class ModuleWhoWas : public Module +{ + CommandWhowas cmd; + public: + ModuleWhoWas(InspIRCd *Me) : Module(Me), cmd(Me, this) + { + ServerInstance->AddCommand(&cmd); + } + + const char* OnRequest(Request* request) + { + WhowasRequest* req = static_cast<WhowasRequest*>(request); + switch (req->type) + { + case WhowasRequest::WHOWAS_ADD: + cmd.AddToWhoWas(req->user); + break; + case WhowasRequest::WHOWAS_STATS: + req->value = cmd.GetStats(); + break; + case WhowasRequest::WHOWAS_PRUNE: + cmd.PruneWhoWas(ServerInstance->Time()); + break; + case WhowasRequest::WHOWAS_MAINTAIN: + cmd.MaintainWhoWas(ServerInstance->Time()); + break; + } + return NULL; + } + + Version GetVersion() + { + return Version("WHOWAS Command", VF_VENDOR); + } +}; + +MODULE_INIT(ModuleWhoWas) diff --git a/src/configreader.cpp b/src/configreader.cpp index eaea3f006..a41e5d07f 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -442,11 +442,10 @@ static bool ValidateWhoWas(ServerConfig* conf, const char*, const char*, ValueIt conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"WARNING: <whowas:maxkeep> value less than 3600, setting to default 3600"); } - Command* whowas_command = conf->GetInstance()->Parser->GetHandler("WHOWAS"); - if (whowas_command) + Module* whowas = conf->GetInstance()->Modules->Find("cmd_whowas.so"); + if (whowas) { - std::deque<classbase*> params; - whowas_command->HandleInternal(WHOWAS_PRUNE, params); + WhowasRequest(NULL, whowas, WhowasRequest::WHOWAS_PRUNE).Send(); } return true; diff --git a/src/stats.cpp b/src/stats.cpp index d385112c2..40ee40b18 100644 --- a/src/stats.cpp +++ b/src/stats.cpp @@ -157,19 +157,13 @@ void InspIRCd::DoStats(char statschar, User* user, string_list &results) if (!this->Config->WhoWasGroupSize == 0 && !this->Config->WhoWasMaxGroups == 0) { - Command* whowas_command = this->Parser->GetHandler("WHOWAS"); - if (whowas_command) + Module* whowas = Modules->Find("cmd_whowas.so"); + if (whowas) { - std::deque<classbase*> params; - Extensible whowas_stats; - params.push_back(&whowas_stats); - whowas_command->HandleInternal(WHOWAS_STATS, params); - if (whowas_stats.GetExt("stats")) - { - char* statc; - whowas_stats.GetExt("stats", statc); - results.push_back(sn+" 249 "+user->nick+" :"+ConvToStr(statc)); - } + WhowasRequest req(NULL, whowas, WhowasRequest::WHOWAS_STATS); + req.user = user; + req.Send(); + results.push_back(sn+" 249 "+user->nick+" :"+req.value); } } diff --git a/src/users.cpp b/src/users.cpp index 192b4aace..22441a989 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -869,12 +869,12 @@ void User::UnOper() /* adds or updates an entry in the whowas list */ void User::AddToWhoWas() { - Command* whowas_command = ServerInstance->Parser->GetHandler("WHOWAS"); - if (whowas_command) + Module* whowas = ServerInstance->Modules->Find("cmd_whowas.so"); + if (whowas) { - std::deque<classbase*> params; - params.push_back(this); - whowas_command->HandleInternal(WHOWAS_ADD, params); + WhowasRequest req(NULL, whowas, WhowasRequest::WHOWAS_ADD); + req.user = this; + req.Send(); } } @@ -1045,12 +1045,10 @@ bool User::ForceNickChange(const char* newnick) if (nickhandler) // wtfbbq, when would this not be here { std::vector<std::string> parameters; - nickhandler->HandleInternal(1, dummy); parameters.push_back(newnick); this->Extend("NICKForced"); bool result = (ServerInstance->Parser->CallHandler("NICK", parameters, this) == CMD_SUCCESS); this->Shrink("NICKForced"); - nickhandler->HandleInternal(0, dummy); return result; } |