diff options
Diffstat (limited to 'src')
-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 |
5 files changed, 61 insertions, 76 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) 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; } |