summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2014-03-05 16:15:20 +0100
committerAttila Molnar <attilamolnar@hush.com>2014-03-05 16:15:20 +0100
commitecd3eb27966d6399fb3834a942d60ecbe3e4e437 (patch)
tree868418c684bc53a3456a2304d23649fabc8e9bfd
parentbb51cfe506e6e534ea6ce1f4d5649ba27f51666f (diff)
Create the core_oper module
-rw-r--r--src/coremods/core_oper/cmd_die.cpp25
-rw-r--r--src/coremods/core_oper/cmd_kill.cpp62
-rw-r--r--src/coremods/core_oper/cmd_oper.cpp21
-rw-r--r--src/coremods/core_oper/cmd_rehash.cpp24
-rw-r--r--src/coremods/core_oper/cmd_restart.cpp23
-rw-r--r--src/coremods/core_oper/core_oper.cpp43
-rw-r--r--src/coremods/core_oper/core_oper.h113
7 files changed, 205 insertions, 106 deletions
diff --git a/src/coremods/core_oper/cmd_die.cpp b/src/coremods/core_oper/cmd_die.cpp
index 63e4c596a..16603d73e 100644
--- a/src/coremods/core_oper/cmd_die.cpp
+++ b/src/coremods/core_oper/cmd_die.cpp
@@ -19,24 +19,15 @@
#include "inspircd.h"
+#include "exitcodes.h"
+#include "core_oper.h"
-/** Handle /DIE.
- */
-class CommandDie : public Command
+CommandDie::CommandDie(Module* parent)
+ : Command(parent, "DIE", 1)
{
- public:
- /** Constructor for die.
- */
- CommandDie ( Module* parent) : Command(parent,"DIE",1) { flags_needed = 'o'; 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 Handle(const std::vector<std::string>& parameters, User *user);
-};
-
-#include "exitcodes.h"
+ flags_needed = 'o';
+ syntax = "<password>";
+}
/** Handle /DIE
*/
@@ -60,5 +51,3 @@ CmdResult CommandDie::Handle (const std::vector<std::string>& parameters, User *
}
return CMD_SUCCESS;
}
-
-COMMAND_INIT(CommandDie)
diff --git a/src/coremods/core_oper/cmd_kill.cpp b/src/coremods/core_oper/cmd_kill.cpp
index 454bab03f..b60885c64 100644
--- a/src/coremods/core_oper/cmd_kill.cpp
+++ b/src/coremods/core_oper/cmd_kill.cpp
@@ -20,46 +20,16 @@
#include "inspircd.h"
+#include "core_oper.h"
-/** Handle /KILL.
- */
-class CommandKill : public Command
+CommandKill::CommandKill(Module* parent)
+ : Command(parent, "KILL", 2, 2)
{
- std::string lastuuid;
- std::string killreason;
-
- public:
- /** Constructor for kill.
- */
- CommandKill ( Module* parent) : Command(parent,"KILL",2,2) {
- flags_needed = 'o';
- syntax = "<nickname> <reason>";
- TRANSLATE2(TR_CUSTOM, TR_CUSTOM);
- }
- /** 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)
- {
- // FindNick() doesn't work here because we quit the target user in Handle() which
- // removes it from the nicklist, so we check lastuuid: if it's empty then this KILL
- // was for a local user, otherwise it contains the uuid of the user who was killed.
- if (lastuuid.empty())
- return ROUTE_LOCALONLY;
- return ROUTE_BROADCAST;
- }
+ flags_needed = 'o';
+ syntax = "<nickname> <reason>";
+ TRANSLATE2(TR_CUSTOM, TR_CUSTOM);
+}
- void EncodeParameter(std::string& param, int index)
- {
- // Manually translate the nick -> uuid (see above), and also the reason (params[1])
- // because we decorate it if the oper is local and want remote servers to see the
- // decorated reason not the original.
- param = ((index == 0) ? lastuuid : killreason);
- }
-};
/** Handle /KILL
*/
@@ -166,5 +136,21 @@ CmdResult CommandKill::Handle (const std::vector<std::string>& parameters, User
return CMD_SUCCESS;
}
+RouteDescriptor CommandKill::GetRouting(User* user, const std::vector<std::string>& parameters)
+{
+ // FindNick() doesn't work here because we quit the target user in Handle() which
+ // removes it from the nicklist, so we check lastuuid: if it's empty then this KILL
+ // was for a local user, otherwise it contains the uuid of the user who was killed.
+ if (lastuuid.empty())
+ return ROUTE_LOCALONLY;
+ return ROUTE_BROADCAST;
+}
+
-COMMAND_INIT(CommandKill)
+void CommandKill::EncodeParameter(std::string& param, int index)
+{
+ // Manually translate the nick -> uuid (see above), and also the reason (params[1])
+ // because we decorate it if the oper is local and want remote servers to see the
+ // decorated reason not the original.
+ param = ((index == 0) ? lastuuid : killreason);
+}
diff --git a/src/coremods/core_oper/cmd_oper.cpp b/src/coremods/core_oper/cmd_oper.cpp
index bd7a35060..8c0d05ce2 100644
--- a/src/coremods/core_oper/cmd_oper.cpp
+++ b/src/coremods/core_oper/cmd_oper.cpp
@@ -20,22 +20,13 @@
#include "inspircd.h"
+#include "core_oper.h"
-/** Handle /OPER.
- */
-class CommandOper : public SplitCommand
+CommandOper::CommandOper(Module* parent)
+ : SplitCommand(parent, "OPER", 2, 2)
{
- public:
- /** Constructor for oper.
- */
- CommandOper ( Module* parent) : SplitCommand(parent,"OPER",2,2) { syntax = "<username> <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);
-};
+ syntax = "<username> <password>";
+}
CmdResult CommandOper::HandleLocal(const std::vector<std::string>& parameters, LocalUser *user)
{
@@ -79,5 +70,3 @@ CmdResult CommandOper::HandleLocal(const std::vector<std::string>& parameters, L
ServerInstance->Logs->Log("OPER", LOG_DEFAULT, "OPER: Failed oper attempt by %s using login '%s': The following fields did not match: %s", user->GetFullRealHost().c_str(), parameters[0].c_str(), fields.c_str());
return CMD_FAILURE;
}
-
-COMMAND_INIT(CommandOper)
diff --git a/src/coremods/core_oper/cmd_rehash.cpp b/src/coremods/core_oper/cmd_rehash.cpp
index f71219f75..48dfa6fb1 100644
--- a/src/coremods/core_oper/cmd_rehash.cpp
+++ b/src/coremods/core_oper/cmd_rehash.cpp
@@ -20,22 +20,15 @@
#include "inspircd.h"
+#include "core_oper.h"
-/** Handle /REHASH.
- */
-class CommandRehash : public Command
+CommandRehash::CommandRehash(Module* parent)
+ : Command(parent, "REHASH", 0)
{
- public:
- /** Constructor for rehash.
- */
- CommandRehash ( Module* parent) : Command(parent,"REHASH",0) { flags_needed = 'o'; Penalty = 2; syntax = "[<servermask>]"; }
- /** 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);
-};
+ flags_needed = 'o';
+ Penalty = 2;
+ syntax = "[<servermask>]";
+}
CmdResult CommandRehash::Handle (const std::vector<std::string>& parameters, User *user)
{
@@ -99,6 +92,3 @@ CmdResult CommandRehash::Handle (const std::vector<std::string>& parameters, Use
// Always return success so spanningtree forwards an incoming REHASH even if we failed
return CMD_SUCCESS;
}
-
-
-COMMAND_INIT(CommandRehash)
diff --git a/src/coremods/core_oper/cmd_restart.cpp b/src/coremods/core_oper/cmd_restart.cpp
index 33627b540..39fbd8140 100644
--- a/src/coremods/core_oper/cmd_restart.cpp
+++ b/src/coremods/core_oper/cmd_restart.cpp
@@ -19,22 +19,14 @@
#include "inspircd.h"
+#include "core_oper.h"
-/** Handle /RESTART
- */
-class CommandRestart : public Command
+CommandRestart::CommandRestart(Module* parent)
+ : Command(parent, "RESTART", 1, 1)
{
- public:
- /** Constructor for restart.
- */
- CommandRestart(Module* parent) : Command(parent,"RESTART",1,1) { flags_needed = 'o'; 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 Handle(const std::vector<std::string>& parameters, User *user);
-};
+ flags_needed = 'o';
+ syntax = "<password>";
+}
CmdResult CommandRestart::Handle (const std::vector<std::string>& parameters, User *user)
{
@@ -70,6 +62,3 @@ CmdResult CommandRestart::Handle (const std::vector<std::string>& parameters, Us
}
return CMD_FAILURE;
}
-
-
-COMMAND_INIT(CommandRestart)
diff --git a/src/coremods/core_oper/core_oper.cpp b/src/coremods/core_oper/core_oper.cpp
new file mode 100644
index 000000000..f94681138
--- /dev/null
+++ b/src/coremods/core_oper/core_oper.cpp
@@ -0,0 +1,43 @@
+/*
+ * 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_oper.h"
+
+class CoreModOper : public Module
+{
+ CommandDie cmddie;
+ CommandKill cmdkill;
+ CommandOper cmdoper;
+ CommandRehash cmdrehash;
+ CommandRestart cmdrestart;
+
+ public:
+ CoreModOper()
+ : cmddie(this), cmdkill(this), cmdoper(this), cmdrehash(this), cmdrestart(this)
+ {
+ }
+
+ Version GetVersion() CXX11_OVERRIDE
+ {
+ return Version("Provides the DIE, KILL, OPER, REHASH, and RESTART commands", VF_VENDOR|VF_CORE);
+ }
+};
+
+MODULE_INIT(CoreModOper)
diff --git a/src/coremods/core_oper/core_oper.h b/src/coremods/core_oper/core_oper.h
new file mode 100644
index 000000000..2e2a152a0
--- /dev/null
+++ b/src/coremods/core_oper/core_oper.h
@@ -0,0 +1,113 @@
+/*
+ * 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 /DIE.
+ */
+class CommandDie : public Command
+{
+ public:
+ /** Constructor for die.
+ */
+ CommandDie(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 /KILL.
+ */
+class CommandKill : public Command
+{
+ std::string lastuuid;
+ std::string killreason;
+
+ public:
+ /** Constructor for kill.
+ */
+ CommandKill(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);
+
+ void EncodeParameter(std::string& param, int index);
+};
+
+/** Handle /OPER.
+ */
+class CommandOper : public SplitCommand
+{
+ public:
+ /** Constructor for oper.
+ */
+ CommandOper(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);
+};
+
+/** Handle /REHASH.
+ */
+class CommandRehash : public Command
+{
+ public:
+ /** Constructor for rehash.
+ */
+ CommandRehash(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 /RESTART
+ */
+class CommandRestart : public Command
+{
+ public:
+ /** Constructor for restart.
+ */
+ CommandRestart(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);
+};