diff options
-rw-r--r-- | src/coremods/core_user/cmd_away.cpp | 28 | ||||
-rw-r--r-- | src/coremods/core_user/cmd_mode.cpp | 53 | ||||
-rw-r--r-- | src/coremods/core_user/cmd_nick.cpp | 24 | ||||
-rw-r--r-- | src/coremods/core_user/cmd_part.cpp | 29 | ||||
-rw-r--r-- | src/coremods/core_user/cmd_pass.cpp | 53 | ||||
-rw-r--r-- | src/coremods/core_user/cmd_ping.cpp | 45 | ||||
-rw-r--r-- | src/coremods/core_user/cmd_pong.cpp | 47 | ||||
-rw-r--r-- | src/coremods/core_user/cmd_quit.cpp | 31 | ||||
-rw-r--r-- | src/coremods/core_user/cmd_user.cpp | 23 | ||||
-rw-r--r-- | src/coremods/core_user/core_user.cpp | 164 | ||||
-rw-r--r-- | src/coremods/core_user/core_user.h | 110 |
11 files changed, 317 insertions, 290 deletions
diff --git a/src/coremods/core_user/cmd_away.cpp b/src/coremods/core_user/cmd_away.cpp index 4f61cec3f..adc6e6c18 100644 --- a/src/coremods/core_user/cmd_away.cpp +++ b/src/coremods/core_user/cmd_away.cpp @@ -19,26 +19,13 @@ #include "inspircd.h" +#include "core_user.h" -/** Handle /AWAY. - */ -class CommandAway : public Command +CommandAway::CommandAway(Module* parent) + : Command(parent, "AWAY", 0, 0) { - public: - /** Constructor for away. - */ - CommandAway ( Module* parent) : Command(parent,"AWAY",0,0) { syntax = "[<message>]"; } - /** Handle command. - * @param parameters The parameters to the 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); - RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) - { - return (IS_LOCAL(user) ? ROUTE_LOCALONLY : ROUTE_BROADCAST); - } -}; + syntax = "[<message>]"; +} /** Handle /AWAY */ @@ -72,4 +59,7 @@ CmdResult CommandAway::Handle (const std::vector<std::string>& parameters, User return CMD_SUCCESS; } -COMMAND_INIT(CommandAway) +RouteDescriptor CommandAway::GetRouting(User* user, const std::vector<std::string>& parameters) +{ + return (IS_LOCAL(user) ? ROUTE_LOCALONLY : ROUTE_BROADCAST); +} diff --git a/src/coremods/core_user/cmd_mode.cpp b/src/coremods/core_user/cmd_mode.cpp deleted file mode 100644 index d2e9b4f63..000000000 --- a/src/coremods/core_user/cmd_mode.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * InspIRCd -- Internet Relay Chat Daemon - * - * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org> - * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net> - * - * This file is part of InspIRCd. InspIRCd is free software: you can - * redistribute it and/or modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - - -#include "inspircd.h" - -/** Handle /MODE. - */ -class CommandMode : public Command -{ - public: - /** Constructor for mode. - */ - CommandMode ( Module* parent) : Command(parent,"MODE",1) { syntax = "<target> <modes> {<mode-parameters>}"; } - /** Handle command. - * @param parameters The parameters to the 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); - RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) - { - return (IS_LOCAL(user) ? ROUTE_LOCALONLY : ROUTE_BROADCAST); - } -}; - - -/** Handle /MODE - */ -CmdResult CommandMode::Handle (const std::vector<std::string>& parameters, User *user) -{ - ServerInstance->Modes->Process(parameters, user, (IS_LOCAL(user) ? ModeParser::MODE_NONE : ModeParser::MODE_LOCALONLY)); - return CMD_SUCCESS; -} - - -COMMAND_INIT(CommandMode) diff --git a/src/coremods/core_user/cmd_nick.cpp b/src/coremods/core_user/cmd_nick.cpp index 486fce7eb..166941c6d 100644 --- a/src/coremods/core_user/cmd_nick.cpp +++ b/src/coremods/core_user/cmd_nick.cpp @@ -21,22 +21,15 @@ #include "inspircd.h" +#include "core_user.h" -/** Handle /NICK. - */ -class CommandNick : public Command +CommandNick::CommandNick(Module* parent) + : Command(parent, "NICK", 1, 1) { - public: - /** Constructor for nick. - */ - CommandNick ( Module* parent) : Command(parent,"NICK", 1, 1) { works_before_reg = true; syntax = "<newnick>"; Penalty = 0; } - /** Handle command. - * @param parameters The parameters to the 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); -}; + works_before_reg = true; + syntax = "<newnick>"; + Penalty = 0; +} /** Handle nick changes from users. * NOTE: If you are used to ircds based on ircd2.8, and are looking @@ -89,6 +82,3 @@ CmdResult CommandNick::Handle (const std::vector<std::string>& parameters, User return CMD_SUCCESS; } - - -COMMAND_INIT(CommandNick) diff --git a/src/coremods/core_user/cmd_part.cpp b/src/coremods/core_user/cmd_part.cpp index f427063ea..b8395f43e 100644 --- a/src/coremods/core_user/cmd_part.cpp +++ b/src/coremods/core_user/cmd_part.cpp @@ -19,26 +19,14 @@ #include "inspircd.h" +#include "core_user.h" -/** Handle /PART. - */ -class CommandPart : public Command +CommandPart::CommandPart(Module* parent) + : Command(parent, "PART", 1, 2) { - public: - /** Constructor for part. - */ - CommandPart (Module* parent) : Command(parent,"PART", 1, 2) { Penalty = 5; syntax = "<channel>{,<channel>} [<reason>]"; } - /** Handle command. - * @param parameters The parameters to the 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); - RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) - { - return (IS_LOCAL(user) ? ROUTE_LOCALONLY : ROUTE_BROADCAST); - } -}; + Penalty = 5; + syntax = "<channel>{,<channel>} [<reason>]"; +} CmdResult CommandPart::Handle (const std::vector<std::string>& parameters, User *user) { @@ -75,4 +63,7 @@ CmdResult CommandPart::Handle (const std::vector<std::string>& parameters, User return CMD_SUCCESS; } -COMMAND_INIT(CommandPart) +RouteDescriptor CommandPart::GetRouting(User* user, const std::vector<std::string>& parameters) +{ + return (IS_LOCAL(user) ? ROUTE_LOCALONLY : ROUTE_BROADCAST); +} diff --git a/src/coremods/core_user/cmd_pass.cpp b/src/coremods/core_user/cmd_pass.cpp deleted file mode 100644 index 66b2b5726..000000000 --- a/src/coremods/core_user/cmd_pass.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * InspIRCd -- Internet Relay Chat Daemon - * - * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org> - * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net> - * - * This file is part of InspIRCd. InspIRCd is free software: you can - * redistribute it and/or modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - - -#include "inspircd.h" - -/** Handle /PASS. - */ -class CommandPass : public SplitCommand -{ - public: - /** Constructor for pass. - */ - CommandPass (Module* parent) : SplitCommand(parent,"PASS",1,1) { works_before_reg = true; Penalty = 0; syntax = "<password>"; } - /** Handle command. - * @param parameters The parameters to the command - * @param user The user issuing the command - * @return A value from CmdResult to indicate command success or failure. - */ - CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser *user); -}; - - -CmdResult CommandPass::HandleLocal(const std::vector<std::string>& parameters, LocalUser *user) -{ - // Check to make sure they haven't registered -- Fix by FCS - if (user->registered == REG_ALL) - { - user->WriteNumeric(ERR_ALREADYREGISTERED, ":You may not reregister"); - return CMD_FAILURE; - } - user->password = parameters[0]; - - return CMD_SUCCESS; -} - -COMMAND_INIT(CommandPass) diff --git a/src/coremods/core_user/cmd_ping.cpp b/src/coremods/core_user/cmd_ping.cpp deleted file mode 100644 index 06135f83c..000000000 --- a/src/coremods/core_user/cmd_ping.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * InspIRCd -- Internet Relay Chat Daemon - * - * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org> - * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net> - * - * This file is part of InspIRCd. InspIRCd is free software: you can - * redistribute it and/or modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - - -#include "inspircd.h" - -/** Handle /PING. - */ -class CommandPing : public Command -{ - public: - /** Constructor for ping. - */ - CommandPing ( Module* parent) : Command(parent,"PING", 1, 2) { Penalty = 0; syntax = "<servername> [:<servername>]"; } - /** Handle command. - * @param parameters The parameters to the 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 CommandPing::Handle (const std::vector<std::string>& parameters, User *user) -{ - user->WriteServ("PONG %s :%s", ServerInstance->Config->ServerName.c_str(), parameters[0].c_str()); - return CMD_SUCCESS; -} - -COMMAND_INIT(CommandPing) diff --git a/src/coremods/core_user/cmd_pong.cpp b/src/coremods/core_user/cmd_pong.cpp deleted file mode 100644 index 06db92604..000000000 --- a/src/coremods/core_user/cmd_pong.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * InspIRCd -- Internet Relay Chat Daemon - * - * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org> - * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net> - * - * This file is part of InspIRCd. InspIRCd is free software: you can - * redistribute it and/or modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - - -#include "inspircd.h" - -/** Handle /PONG. - */ -class CommandPong : public Command -{ - public: - /** Constructor for pong. - */ - CommandPong ( Module* parent) : Command(parent,"PONG", 0, 1) { Penalty = 0; syntax = "<ping-text>"; } - /** Handle command. - * @param parameters The parameters to the 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 CommandPong::Handle (const std::vector<std::string>&, User *user) -{ - // set the user as alive so they survive to next ping - if (IS_LOCAL(user)) - IS_LOCAL(user)->lastping = 1; - return CMD_SUCCESS; -} - -COMMAND_INIT(CommandPong) diff --git a/src/coremods/core_user/cmd_quit.cpp b/src/coremods/core_user/cmd_quit.cpp index 15dc07d6c..40653745c 100644 --- a/src/coremods/core_user/cmd_quit.cpp +++ b/src/coremods/core_user/cmd_quit.cpp @@ -19,27 +19,14 @@ #include "inspircd.h" +#include "core_user.h" -/** Handle /QUIT. - */ -class CommandQuit : public Command +CommandQuit::CommandQuit(Module* parent) + : Command(parent, "QUIT", 0, 1) { - public: - /** Constructor for quit. - */ - CommandQuit ( Module* parent) : Command(parent,"QUIT",0,1) { works_before_reg = true; syntax = "[<message>]"; } - /** Handle command. - * @param parameters The parameters to the 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); - RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) - { - return (IS_LOCAL(user) ? ROUTE_LOCALONLY : ROUTE_BROADCAST); - } -}; - + works_before_reg = true; + syntax = "[<message>]"; +} CmdResult CommandQuit::Handle (const std::vector<std::string>& parameters, User *user) { @@ -64,5 +51,7 @@ CmdResult CommandQuit::Handle (const std::vector<std::string>& parameters, User return CMD_SUCCESS; } - -COMMAND_INIT(CommandQuit) +RouteDescriptor CommandQuit::GetRouting(User* user, const std::vector<std::string>& parameters) +{ + return (IS_LOCAL(user) ? ROUTE_LOCALONLY : ROUTE_BROADCAST); +} diff --git a/src/coremods/core_user/cmd_user.cpp b/src/coremods/core_user/cmd_user.cpp index cec11c104..6de762e44 100644 --- a/src/coremods/core_user/cmd_user.cpp +++ b/src/coremods/core_user/cmd_user.cpp @@ -19,22 +19,15 @@ #include "inspircd.h" +#include "core_user.h" -/** Handle /USER. - */ -class CommandUser : public SplitCommand +CommandUser::CommandUser(Module* parent) + : SplitCommand(parent, "USER", 4, 4) { - public: - /** Constructor for user. - */ - CommandUser ( Module* parent) : SplitCommand(parent,"USER",4,4) { works_before_reg = true; Penalty = 0; syntax = "<username> <localhost> <remotehost> <GECOS>"; } - /** Handle command. - * @param parameters The parameters to the command - * @param user The user issuing the command - * @return A value from CmdResult to indicate command success or failure. - */ - CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser *user); -}; + works_before_reg = true; + Penalty = 0; + syntax = "<username> <localhost> <remotehost> <GECOS>"; +} CmdResult CommandUser::HandleLocal(const std::vector<std::string>& parameters, LocalUser *user) { @@ -82,5 +75,3 @@ CmdResult CommandUser::HandleLocal(const std::vector<std::string>& parameters, L return CMD_SUCCESS; } - -COMMAND_INIT(CommandUser) diff --git a/src/coremods/core_user/core_user.cpp b/src/coremods/core_user/core_user.cpp new file mode 100644 index 000000000..c862c0eb1 --- /dev/null +++ b/src/coremods/core_user/core_user.cpp @@ -0,0 +1,164 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com> + * + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "inspircd.h" +#include "core_user.h" + +class CommandMode : public Command +{ + public: + /** Constructor for mode. + */ + CommandMode(Module* parent) + : Command(parent, "MODE", 1) + { + syntax = "<target> <modes> {<mode-parameters>}"; + } + + /** Handle command. + * @param parameters The parameters to the 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) + { + ServerInstance->Modes->Process(parameters, user, (IS_LOCAL(user) ? ModeParser::MODE_NONE : ModeParser::MODE_LOCALONLY)); + return CMD_SUCCESS; + } + + RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) + { + return (IS_LOCAL(user) ? ROUTE_LOCALONLY : ROUTE_BROADCAST); + } +}; + +/** Handle /PASS. + */ +class CommandPass : public SplitCommand +{ + public: + /** Constructor for pass. + */ + CommandPass(Module* parent) + : SplitCommand(parent, "PASS", 1, 1) + { + works_before_reg = true; + Penalty = 0; + syntax = "<password>"; + } + + /** Handle command. + * @param parameters The parameters to the command + * @param user The user issuing the command + * @return A value from CmdResult to indicate command success or failure. + */ + CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser *user) + { + // Check to make sure they haven't registered -- Fix by FCS + if (user->registered == REG_ALL) + { + user->WriteNumeric(ERR_ALREADYREGISTERED, ":You may not reregister"); + return CMD_FAILURE; + } + user->password = parameters[0]; + + return CMD_SUCCESS; + } +}; + +/** Handle /PING. + */ +class CommandPing : public Command +{ + public: + /** Constructor for ping. + */ + CommandPing(Module* parent) + : Command(parent, "PING", 1, 2) + { + Penalty = 0; + syntax = "<servername> [:<servername>]"; + } + + /** Handle command. + * @param parameters The parameters to the 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) + { + user->WriteServ("PONG %s :%s", ServerInstance->Config->ServerName.c_str(), parameters[0].c_str()); + return CMD_SUCCESS; + } +}; + +/** Handle /PONG. + */ +class CommandPong : public Command +{ + public: + /** Constructor for pong. + */ + CommandPong(Module* parent) + : Command(parent, "PONG", 0, 1) + { + Penalty = 0; + syntax = "<ping-text>"; + } + + /** Handle command. + * @param parameters The parameters to the 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) + { + // set the user as alive so they survive to next ping + if (IS_LOCAL(user)) + IS_LOCAL(user)->lastping = 1; + return CMD_SUCCESS; + } +}; + +class CoreModUser : public Module +{ + CommandAway cmdaway; + CommandMode cmdmode; + CommandNick cmdnick; + CommandPart cmdpart; + CommandPass cmdpass; + CommandPing cmdping; + CommandPong cmdpong; + CommandQuit cmdquit; + CommandUser cmduser; + + public: + CoreModUser() + : cmdaway(this), cmdmode(this), cmdnick(this), cmdpart(this), cmdpass(this), cmdping(this) + , cmdpong(this), cmdquit(this), cmduser(this) + { + } + + Version GetVersion() CXX11_OVERRIDE + { + return Version("Provides the AWAY, MODE, NICK, PART, PASS, PING, PONG, QUIT and USER commands", VF_VENDOR|VF_CORE); + } +}; + +MODULE_INIT(CoreModUser) diff --git a/src/coremods/core_user/core_user.h b/src/coremods/core_user/core_user.h new file mode 100644 index 000000000..ad4b73919 --- /dev/null +++ b/src/coremods/core_user/core_user.h @@ -0,0 +1,110 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com> + * + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + +#pragma once + +#include "inspircd.h" + +/** Handle /AWAY. + */ +class CommandAway : public Command +{ + public: + /** Constructor for away. + */ + CommandAway(Module* parent); + /** Handle command. + * @param parameters The parameters to the 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); + RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters); +}; + +/** Handle /NICK. + */ +class CommandNick : public Command +{ + public: + /** Constructor for nick. + */ + CommandNick(Module* parent); + + /** Handle command. + * @param parameters The parameters to the 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); +}; + +/** Handle /PART. + */ +class CommandPart : public Command +{ + public: + /** Constructor for part. + */ + CommandPart(Module* parent); + + /** Handle command. + * @param parameters The parameters to the 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); + RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters); +}; + +/** Handle /QUIT. + */ +class CommandQuit : public Command +{ + public: + /** Constructor for quit. + */ + CommandQuit(Module* parent); + + /** Handle command. + * @param parameters The parameters to the 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); + + RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters); +}; + +/** Handle /USER. + */ +class CommandUser : public SplitCommand +{ + public: + /** Constructor for user. + */ + CommandUser(Module* parent); + + /** Handle command. + * @param parameters The parameters to the command + * @param user The user issuing the command + * @return A value from CmdResult to indicate command success or failure. + */ + CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser *user); +}; |