2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "core_user.h"
25 class CommandPass : public SplitCommand
28 /** Constructor for pass.
30 CommandPass(Module* parent)
31 : SplitCommand(parent, "PASS", 1, 1)
33 works_before_reg = true;
35 syntax = "<password>";
39 * @param parameters The parameters to the command
40 * @param user The user issuing the command
41 * @return A value from CmdResult to indicate command success or failure.
43 CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser *user)
45 // Check to make sure they haven't registered -- Fix by FCS
46 if (user->registered == REG_ALL)
48 user->CommandFloodPenalty += 1000;
49 user->WriteNumeric(ERR_ALREADYREGISTERED, "You may not reregister");
52 user->password = parameters[0];
60 class CommandPing : public Command
63 /** Constructor for ping.
65 CommandPing(Module* parent)
66 : Command(parent, "PING", 1, 2)
68 syntax = "<servername> [:<servername>]";
72 * @param parameters The parameters to the command
73 * @param user The user issuing the command
74 * @return A value from CmdResult to indicate command success or failure.
76 CmdResult Handle(const std::vector<std::string>& parameters, User* user)
78 user->WriteServ("PONG %s :%s", ServerInstance->Config->ServerName.c_str(), parameters[0].c_str());
85 class CommandPong : public Command
88 /** Constructor for pong.
90 CommandPong(Module* parent)
91 : Command(parent, "PONG", 0, 1)
94 syntax = "<ping-text>";
98 * @param parameters The parameters to the command
99 * @param user The user issuing the command
100 * @return A value from CmdResult to indicate command success or failure.
102 CmdResult Handle(const std::vector<std::string>& parameters, User* user)
104 // set the user as alive so they survive to next ping
105 LocalUser* localuser = IS_LOCAL(user);
108 // Increase penalty unless we've sent a PING and this is the reply
109 if (localuser->lastping)
110 localuser->CommandFloodPenalty += 1000;
112 localuser->lastping = 1;
118 void MessageWrapper::Wrap(const std::string& message, std::string& out)
120 // If there is a fixed message, it is stored in prefix. Otherwise prefix contains
121 // only the prefix, so append the message and the suffix
124 out.append(message).append(suffix);
127 void MessageWrapper::ReadConfig(const char* prefixname, const char* suffixname, const char* fixedname)
129 ConfigTag* tag = ServerInstance->Config->ConfValue("options");
130 prefix = tag->getString(fixedname);
131 fixed = (!prefix.empty());
134 prefix = tag->getString(prefixname);
135 suffix = tag->getString(suffixname);
139 class CoreModUser : public Module
153 : cmdaway(this), cmdmode(this), cmdnick(this), cmdpart(this), cmdpass(this), cmdping(this)
154 , cmdpong(this), cmdquit(this), cmduser(this)
158 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
160 cmdpart.msgwrap.ReadConfig("prefixpart", "suffixpart", "fixedpart");
161 cmdquit.msgwrap.ReadConfig("prefixquit", "suffixquit", "fixedquit");
164 Version GetVersion() CXX11_OVERRIDE
166 return Version("Provides the AWAY, MODE, NICK, PART, PASS, PING, PONG, QUIT and USER commands", VF_VENDOR|VF_CORE);
170 MODULE_INIT(CoreModUser)