* +------------------------------------+
*
* InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
- * E-mail:
- * <brain@chatspike.net>
- * <Craig@chatspike.net>
+ * E-mail:
+ * <brain@chatspike.net>
+ * <Craig@chatspike.net>
*
* Written by Craig Edwards, Craig McLure, and others.
* This program is free but copyrighted software; see
- * the file COPYING for details.
+ * the file COPYING for details.
*
* ---------------------------------------------------
*/
#include "connection.h"
#include "users.h"
#include "modules.h"
-#include "message.h"
#include "inspstring.h"
#include "helperfuncs.h"
#include "commands.h"
/* +n (notice mask - our implementation of snomasks) */
#include "modes/umode_n.h"
-extern int MODCOUNT;
-extern std::vector<Module*> modules;
-extern std::vector<ircd_module*> factory;
-extern InspIRCd* ServerInstance;
-extern ServerConfig* Config;
-
-extern time_t TIME;
-
-ModeHandler::ModeHandler(char modeletter, int parameters_on, int parameters_off, bool listmode, ModeType type, bool operonly)
- : mode(modeletter), n_params_on(parameters_on), n_params_off(parameters_off), list(listmode), m_type(type), oper(operonly)
+ModeHandler::ModeHandler(InspIRCd* Instance, char modeletter, int parameters_on, int parameters_off, bool listmode, ModeType type, bool operonly)
+ : ServerInstance(Instance), mode(modeletter), n_params_on(parameters_on), n_params_off(parameters_off), list(listmode), m_type(type), oper(operonly)
{
}
return (ours < theirs);
}
-ModeWatcher::ModeWatcher(char modeletter, ModeType type) : mode(modeletter), m_type(type)
+ModeWatcher::ModeWatcher(InspIRCd* Instance, char modeletter, ModeType type) : ServerInstance(Instance), mode(modeletter), m_type(type)
{
}
{
return NULL;
}
- d = Find(dest);
+ d = ServerInstance->FindNick(dest);
if (!d)
{
user->WriteServ("401 %s %s :No such nick/channel",user->nick, dest);
if (targetchannel)
{
/* Display channel's current mode string */
- user->WriteServ("324 %s %s +%s",user->nick, targetchannel->name, chanmodes(targetchannel, targetchannel->HasUser(user)));
+ user->WriteServ("324 %s %s +%s",user->nick, targetchannel->name, targetchannel->ChanModes(targetchannel->HasUser(user)));
user->WriteServ("329 %s %s %d", user->nick, targetchannel->name, targetchannel->created);
return;
}
std::string target = parameters[0];
ModeType type = MODETYPE_USER;
unsigned char mask = 0;
- chanrec* targetchannel = FindChan(parameters[0]);
- userrec* targetuser = Find(parameters[0]);
+ chanrec* targetchannel = ServerInstance->FindChan(parameters[0]);
+ userrec* targetuser = ServerInstance->FindNick(parameters[0]);
log(DEBUG,"ModeParser::Process start");
* (e.g. are they a (half)op?
*/
- if ((IS_LOCAL(user)) && (cstatus(user, targetchannel) < STATUS_HOP))
+ if ((IS_LOCAL(user)) && (targetchannel->GetStatus(user) < STATUS_HOP))
{
/* We don't have halfop */
log(DEBUG,"The user is not a halfop or above, checking other reasons for being able to set the modes");
{
if (type == MODETYPE_CHANNEL)
{
- targetchannel->WriteChannelWithServ(Config->ServerName, "MODE %s %s%s", targetchannel->name, output_sequence.c_str(), parameter_list.str().c_str());
+ targetchannel->WriteChannelWithServ(ServerInstance->Config->ServerName, "MODE %s %s%s", targetchannel->name, output_sequence.c_str(), parameter_list.str().c_str());
}
else
{
return true;
}
-ModeParser::ModeParser()
+ModeParser::ModeParser(InspIRCd* Instance) : ServerInstance(Instance)
{
/* Clear mode list */
memset(modehandlers, 0, sizeof(modehandlers));
/* Initialise the RFC mode letters */
/* Start with channel simple modes, no params */
- this->AddMode(new ModeChannelSecret, 's');
- this->AddMode(new ModeChannelPrivate, 'p');
- this->AddMode(new ModeChannelModerated, 'm');
- this->AddMode(new ModeChannelTopicOps, 't');
- this->AddMode(new ModeChannelNoExternal, 'n');
- this->AddMode(new ModeChannelInviteOnly, 'i');
+ this->AddMode(new ModeChannelSecret(Instance), 's');
+ this->AddMode(new ModeChannelPrivate(Instance), 'p');
+ this->AddMode(new ModeChannelModerated(Instance), 'm');
+ this->AddMode(new ModeChannelTopicOps(Instance), 't');
+ this->AddMode(new ModeChannelNoExternal(Instance), 'n');
+ this->AddMode(new ModeChannelInviteOnly(Instance), 'i');
/* Cannel modes with params */
- this->AddMode(new ModeChannelKey, 'k');
- this->AddMode(new ModeChannelLimit, 'l');
+ this->AddMode(new ModeChannelKey(Instance), 'k');
+ this->AddMode(new ModeChannelLimit(Instance), 'l');
/* Channel listmodes */
- this->AddMode(new ModeChannelBan, 'b');
- this->AddMode(new ModeChannelOp, 'o');
- this->AddMode(new ModeChannelHalfOp, 'h');
- this->AddMode(new ModeChannelVoice, 'v');
+ this->AddMode(new ModeChannelBan(Instance), 'b');
+ this->AddMode(new ModeChannelOp(Instance), 'o');
+ this->AddMode(new ModeChannelHalfOp(Instance), 'h');
+ this->AddMode(new ModeChannelVoice(Instance), 'v');
/* Now for usermodes */
- this->AddMode(new ModeUserServerNotice, 's');
- this->AddMode(new ModeUserWallops, 'w');
- this->AddMode(new ModeUserInvisible, 'i');
- this->AddMode(new ModeUserOperator, 'o');
- this->AddMode(new ModeUserServerNoticeMask, 'n');
+ this->AddMode(new ModeUserServerNotice(Instance), 's');
+ this->AddMode(new ModeUserWallops(Instance), 'w');
+ this->AddMode(new ModeUserInvisible(Instance), 'i');
+ this->AddMode(new ModeUserOperator(Instance), 'o');
+ this->AddMode(new ModeUserServerNoticeMask(Instance), 'n');
+}
+
+bool ModeParser::InsertMode(std::string &output, const char* mode, unsigned short section)
+{
+ unsigned short currsection = 1;
+ unsigned int pos = output.find("CHANMODES=", 0) + 10; // +10 for the length of "CHANMODES="
+
+ if(section > 4 || section == 0)
+ {
+ log(DEBUG, "InsertMode: CHANMODES doesn't have a section %dh :/", section);
+ return false;
+ }
+
+ for(; pos < output.size(); pos++)
+ {
+ if(section == currsection)
+ break;
+
+ if(output[pos] == ',')
+ currsection++;
+ }
+
+ output.insert(pos, mode);
+ return true;
}