diff options
-rw-r--r-- | include/ctables.h | 15 | ||||
-rw-r--r-- | include/users.h | 22 | ||||
-rw-r--r-- | src/commands.cpp | 28 | ||||
-rw-r--r-- | src/commands/cmd_oper.cpp | 8 | ||||
-rw-r--r-- | src/userprocess.cpp | 2 | ||||
-rw-r--r-- | 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<std::string>& parameters, User* user); + virtual CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* user); + virtual CmdResult HandleRemote(const std::vector<std::string>& parameters, RemoteUser* user); + virtual CmdResult HandleServer(const std::vector<std::string>& parameters, FakeUser* user); +}; + /** A hash of commands used by the core */ typedef nspace::hash_map<std::string,Command*> 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 <connect> 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 <connect> 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<std::string>& parms, User* u) +{ + if (IS_LOCAL(u)) + return HandleLocal(parms, static_cast<LocalUser*>(u)); + if (IS_MODULE_CREATED(u)) + return HandleRemote(parms, static_cast<RemoteUser*>(u)); + if (IS_SERVER(u)) + return HandleServer(parms, static_cast<FakeUser*>(u)); + ServerInstance->Logs->Log("COMMAND", ERROR, "Unknown user type in command (fd=%d)!", u->GetFd()); + return CMD_INVALID; +} + +CmdResult SplitCommand::HandleLocal(const std::vector<std::string>&, LocalUser*) +{ + return CMD_INVALID; +} + +CmdResult SplitCommand::HandleRemote(const std::vector<std::string>&, RemoteUser*) +{ + return CMD_INVALID; +} + +CmdResult SplitCommand::HandleServer(const std::vector<std::string>&, 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 = "<username> <password>"; } + CommandOper ( Module* parent) : SplitCommand(parent,"OPER",2,2) { syntax = "<username> <password>"; } /** 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<std::string>& parameters, User *user); + CmdResult HandleLocal(const std::vector<std::string>& 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<std::string>& parameters, User *user) +CmdResult CommandOper::HandleLocal(const std::vector<std::string>& 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<LocalUser*>::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, * <connect allow="127.0.0.1"> 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()) |