From bbb5f6ee63b4a226e6679119a1ee8c725d7d2abc Mon Sep 17 00:00:00 2001 From: danieldg Date: Wed, 21 Oct 2009 23:44:58 +0000 Subject: Move SetClass to LocalUser git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11941 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/ctables.h | 15 +++++++++++++++ include/users.h | 22 +++++++++++----------- src/commands.cpp | 28 ++++++++++++++++++++++++++++ src/commands/cmd_oper.cpp | 8 ++++---- src/userprocess.cpp | 2 +- src/users.cpp | 7 ++----- 6 files changed, 61 insertions(+), 21 deletions(-) diff --git a/include/ctables.h b/include/ctables.h index 80962b67e..4cb530e63 100644 --- a/include/ctables.h +++ b/include/ctables.h @@ -214,6 +214,21 @@ class CoreExport Command : public classbase virtual ~Command(); }; +class LocalUser; +class RemoteUser; +class FakeUser; + +class CoreExport SplitCommand : public Command +{ + public: + SplitCommand(Module* me, const std::string &cmd, int minpara = 0, int maxpara = 0) + : Command(me, cmd, minpara, maxpara) {} + virtual CmdResult Handle(const std::vector& parameters, User* user); + virtual CmdResult HandleLocal(const std::vector& parameters, LocalUser* user); + virtual CmdResult HandleRemote(const std::vector& parameters, RemoteUser* user); + virtual CmdResult HandleServer(const std::vector& parameters, FakeUser* user); +}; + /** A hash of commands used by the core */ typedef nspace::hash_map Commandtable; diff --git a/include/users.h b/include/users.h index c60d5f033..fcdc5b374 100644 --- a/include/users.h +++ b/include/users.h @@ -639,11 +639,6 @@ class CoreExport User : public StreamSocket */ void CheckClass(); - /** Use this method to fully connect a user. - * This will send the message of the day, check G/K/E lines, etc. - */ - void FullConnect(); - /** Change this users hash key to a new string. * You should not call this function directly. It is used by the core * to update the users hash entry on a nickchange. @@ -835,12 +830,6 @@ class CoreExport User : public StreamSocket */ ConnectClass *GetClass(); - /** Set the connect class to which this user belongs to. - * @param explicit_name Set this string to tie the user to a specific class name. Otherwise, the class is fitted by checking tags from the configuration file. - * @return A reference to this user's current connect class. - */ - ConnectClass *SetClass(const std::string &explicit_name = ""); - /** Show the message of the day to this user */ void ShowMOTD(); @@ -890,6 +879,17 @@ class CoreExport LocalUser : public User public: LocalUser(); virtual void SendText(const std::string& line); + + /** Use this method to fully connect a user. + * This will send the message of the day, check G/K/E lines, etc. + */ + void FullConnect(); + + /** Set the connect class to which this user belongs to. + * @param explicit_name Set this string to tie the user to a specific class name. Otherwise, the class is fitted by checking tags from the configuration file. + * @return A reference to this user's current connect class. + */ + ConnectClass *SetClass(const std::string &explicit_name = ""); }; class CoreExport RemoteUser : public User diff --git a/src/commands.cpp b/src/commands.cpp index 1aeba2d80..41ba0aada 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -108,3 +108,31 @@ bool InspIRCd::NickMatchesEveryone(const std::string &nick, User* user) } return false; } + +CmdResult SplitCommand::Handle(const std::vector& parms, User* u) +{ + if (IS_LOCAL(u)) + return HandleLocal(parms, static_cast(u)); + if (IS_MODULE_CREATED(u)) + return HandleRemote(parms, static_cast(u)); + if (IS_SERVER(u)) + return HandleServer(parms, static_cast(u)); + ServerInstance->Logs->Log("COMMAND", ERROR, "Unknown user type in command (fd=%d)!", u->GetFd()); + return CMD_INVALID; +} + +CmdResult SplitCommand::HandleLocal(const std::vector&, LocalUser*) +{ + return CMD_INVALID; +} + +CmdResult SplitCommand::HandleRemote(const std::vector&, RemoteUser*) +{ + return CMD_INVALID; +} + +CmdResult SplitCommand::HandleServer(const std::vector&, FakeUser*) +{ + return CMD_INVALID; +} + diff --git a/src/commands/cmd_oper.cpp b/src/commands/cmd_oper.cpp index 683df9091..dc15a5415 100644 --- a/src/commands/cmd_oper.cpp +++ b/src/commands/cmd_oper.cpp @@ -21,19 +21,19 @@ bool OneOfMatches(const char* host, const char* ip, const char* hostlist); * the same way, however, they can be fully unloaded, where these * may not. */ -class CommandOper : public Command +class CommandOper : public SplitCommand { public: /** Constructor for oper. */ - CommandOper ( Module* parent) : Command(parent,"OPER",2,2) { syntax = " "; } + CommandOper ( Module* parent) : SplitCommand(parent,"OPER",2,2) { syntax = " "; } /** Handle command. * @param parameters The parameters to the comamnd * @param pcnt The number of parameters passed to teh command * @param user The user issuing the command * @return A value from CmdResult to indicate command success or failure. */ - CmdResult Handle(const std::vector& parameters, User *user); + CmdResult HandleLocal(const std::vector& parameters, LocalUser *user); }; bool OneOfMatches(const char* host, const char* ip, const std::string& hostlist) @@ -50,7 +50,7 @@ bool OneOfMatches(const char* host, const char* ip, const std::string& hostlist) return false; } -CmdResult CommandOper::Handle (const std::vector& parameters, User *user) +CmdResult CommandOper::HandleLocal(const std::vector& parameters, LocalUser *user) { char TheHost[MAXBUF]; char TheIP[MAXBUF]; diff --git a/src/userprocess.cpp b/src/userprocess.cpp index aa05504d5..4cc3f0a88 100644 --- a/src/userprocess.cpp +++ b/src/userprocess.cpp @@ -49,7 +49,7 @@ void InspIRCd::DoBackgroundUserStuff() std::vector::reverse_iterator count2 = this->Users->local_users.rbegin(); while (count2 != this->Users->local_users.rend()) { - User *curr = *count2; + LocalUser *curr = *count2; count2++; if (curr->quitting) diff --git a/src/users.cpp b/src/users.cpp index e24f59a0c..899db8bc6 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -834,7 +834,7 @@ bool User::CheckLines(bool doZline) return false; } -void User::FullConnect() +void LocalUser::FullConnect() { ServerInstance->stats->statsConnects++; this->idle_lastmsg = ServerInstance->Time(); @@ -1631,13 +1631,10 @@ void User::SplitChanList(User* dest, const std::string &cl) * then their ip will be taken as 'priority' anyway, so for example, * will match joe!bloggs@localhost */ -ConnectClass* User::SetClass(const std::string &explicit_name) +ConnectClass* LocalUser::SetClass(const std::string &explicit_name) { ConnectClass *found = NULL; - if (!IS_LOCAL(this)) - return NULL; - ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Setting connect class for UID %s", this->uuid.c_str()); if (!explicit_name.empty()) -- cgit v1.2.3