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 /src/commands | |
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
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/cmd_nick.cpp | 25 | ||||
-rw-r--r-- | src/commands/cmd_whowas.cpp | 75 |
2 files changed, 47 insertions, 53 deletions
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) |