PARAM_ALWAYS
};
-/**
- * Used by ModeHandler::ModeSet() to return the state of a mode upon a channel or user.
- * The pair contains an activity flag, true if the mode is set with the given parameter,
- * and the parameter of the mode (or the parameter provided) in the std::string.
- */
-typedef std::pair<bool,std::string> ModePair;
-
/** Each mode is implemented by ONE ModeHandler class.
* You must derive ModeHandler and add the child class to
* the list of modes handled by the ircd, using
*/
virtual bool ResolveModeConflict(std::string &their_param, const std::string &our_param, Channel* channel);
- /**
- * When a remote server needs to bounce a set of modes, it will call this method for every mode
- * in the mode string to determine if the mode is set or not.
- * @param source of the mode change, this will be NULL for a server mode
- * @param dest Target user of the mode change, if this is a user mode
- * @param channel Target channel of the mode change, if this is a channel mode
- * @param parameter The parameter given for the mode change, or an empty string
- * @returns The first value of the pair should be true if the mode is set with the given parameter.
- * In the case of permissions modes such as channelmode +o, this should return true if the user given
- * as the parameter has the given privilage on the given channel. The string value of the pair will hold
- * the current setting for this mode set locally, when the bool is true, or, the parameter given.
- * This allows the local server to enforce our locally set parameters back to a remote server.
- */
- virtual ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter);
-
/**
* When a MODETYPE_USER mode handler is being removed, the server will call this method for every user on the server.
* Your mode handler should remove its user mode from the user by sending the appropriate server modes using
/** This returns the PREFIX=(ohv)@%+ section of the 005 numeric.
*/
std::string BuildPrefixes();
-
- /** This returns the privilages of a user upon a channel, in the format of a mode change.
- * For example, if a user has privilages +avh, this will return the string "avh nick nick nick".
- * This is used by the core when cycling a user to refresh their hostname. You may use it for
- * similar purposes.
- * @param user The username to look up
- * @param channel The channel name to look up the privilages of the user for
- * @param nick_suffix true (the default) if you want nicknames in the mode string, for easy
- * use with the mode stacker, false if you just want the "avh" part of "avh nick nick nick".
- * @return The mode string.
- */
- std::string ModeString(User* user, Channel* channel, bool nick_suffix = true);
};
#endif
std::string& DelBan(User *user,std::string& dest,Channel *chan,int status);
void DisplayList(User* user, Channel* channel);
void DisplayEmptyList(User* user, Channel* channel);
- ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter);
void RemoveMode(User* user, irc::modestacker* stack = NULL);
void RemoveMode(Channel* channel, irc::modestacker* stack = NULL);
};
public:
ModeChannelHalfOp();
ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding);
- ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter);
unsigned int GetPrefixRank();
void RemoveMode(Channel* channel, irc::modestacker* stack = NULL);
void RemoveMode(User* user, irc::modestacker* stack = NULL);
public:
ModeChannelKey();
ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding);
- ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter);
void RemoveMode(Channel* channel, irc::modestacker* stack = NULL);
void RemoveMode(User* user, irc::modestacker* stack = NULL);
};
public:
ModeChannelLimit();
ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding);
- ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter);
bool ResolveModeConflict(std::string &their_param, const std::string &our_param, Channel* channel);
};
public:
ModeChannelOp();
ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding);
- ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter);
unsigned int GetPrefixRank();
void RemoveMode(Channel* channel, irc::modestacker* stack = NULL);
void RemoveMode(User* user, irc::modestacker* stack = NULL);
public:
ModeChannelVoice();
ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding);
- ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter);
unsigned int GetPrefixRank();
void RemoveMode(User* user, irc::modestacker* stack = NULL);
void RemoveMode(Channel* channel, irc::modestacker* stack = NULL);
Ptr->WriteAllExcept(user, false, 0, except_list, "JOIN :%s", Ptr->name.c_str());
/* Theyre not the first ones in here, make sure everyone else sees the modes we gave the user */
- std::string ms = ServerInstance->Modes->ModeString(user, Ptr);
+ std::string ms = memb->modes;
+ for(unsigned int i=0; i < memb->modes.length(); i++)
+ ms.append(" ").append(user->nick);
if ((Ptr->GetUserCounter() > 1) && (ms.length()))
Ptr->WriteAllExceptSender(user, true, 0, "MODE %s +%s", Ptr->name.c_str(), ms.c_str());
irc::sockets::sockaddrs client;
irc::sockets::sockaddrs server;
- ServerInstance->Logs->Log("SOCKET",DEBUG,"HandleEvent for Listensoket");
- int incomingSockfd;
-
socklen_t length = sizeof(client);
- incomingSockfd = ServerInstance->SE->Accept(this, &client.sa, &length);
+ int incomingSockfd = ServerInstance->SE->Accept(this, &client.sa, &length);
+ ServerInstance->Logs->Log("SOCKET",DEBUG,"HandleEvent for Listensoket %s nfd=%d", bind_desc.c_str(), incomingSockfd);
if (incomingSockfd < 0)
{
- ServerInstance->SE->Shutdown(incomingSockfd, 2);
- ServerInstance->SE->Close(incomingSockfd);
ServerInstance->stats->statsRefused++;
return;
}
}
ServerInstance->SE->NonBlocking(incomingSockfd);
- ServerInstance->stats->statsAccept++;
ModResult res;
FIRST_MOD_RESULT(OnAcceptConnection, res, (incomingSockfd, this, &client, &server));
res = MOD_RES_ALLOW;
}
}
- if (res != MOD_RES_ALLOW)
+ if (res == MOD_RES_ALLOW)
{
+ ServerInstance->stats->statsAccept++;
+ }
+ else
+ {
+ ServerInstance->stats->statsRefused++;
ServerInstance->Logs->Log("SOCKET",DEFAULT,"Refusing connection on %s - %s",
bind_desc.c_str(), res == MOD_RES_DENY ? "Connection refused by module" : "Module for this port not found");
ServerInstance->SE->Close(incomingSockfd);
return MODEACTION_DENY;
}
-ModePair ModeHandler::ModeSet(User*, User* dest, Channel* channel, const std::string&)
-{
- if (dest)
- {
- return std::make_pair(dest->IsModeSet(this->mode), "");
- }
- else
- {
- return std::make_pair(channel->IsModeSet(this->mode), "");
- }
-}
-
void ModeHandler::DisplayList(User*, Channel*)
{
}
return NULL;
}
-std::string ModeParser::ModeString(User* user, Channel* channel, bool nick_suffix)
-{
- std::string types;
- std::string pars;
-
- if (!channel || !user)
- return "";
-
- for (unsigned char mode = 'A'; mode <= 'z'; mode++)
- {
- unsigned char pos = (mode-65) | MASK_CHANNEL;
- ModeHandler* mh = modehandlers[pos];
- if ((mh) && (mh->GetNumParams(true)) && (mh->GetNumParams(false)))
- {
- ModePair ret;
- ret = mh->ModeSet(NULL, user, channel, user->nick);
- if ((ret.first) && (ret.second == user->nick))
- {
- if (nick_suffix)
- {
- pars.append(" ");
- pars.append(user->nick);
- }
- types.push_back(mh->GetModeChar());
- }
- }
- }
-
- if (nick_suffix)
- return types+pars;
- else
- return types;
-}
-
std::string ModeParser::GiveModeList(ModeMasks m)
{
std::string type1; /* Listmodes EXCEPT those with a prefix */
return dest;
}
-ModePair ModeChannelBan::ModeSet(User*, User*, Channel* channel, const std::string ¶meter)
-{
- for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
- {
- if (!strcasecmp(i->data.c_str(), parameter.c_str()))
- {
- return std::make_pair(true, i->data);
- }
- }
- return std::make_pair(false, parameter);
-}
-
std::string& ModeChannelBan::DelBan(User *user, std::string& dest, Channel *chan, int)
{
if ((!user) || (!chan))
return HALFOP_VALUE;
}
-ModePair ModeChannelHalfOp::ModeSet(User*, User*, Channel* channel, const std::string ¶meter)
-{
- User* x = ServerInstance->FindNick(parameter);
- if (x)
- {
- Membership* memb = channel->GetUser(x);
- if (memb && memb->hasMode('h'))
- {
- return std::make_pair(true, x->nick);
- }
- else
- {
- return std::make_pair(false, x->nick);
- }
- }
- return std::make_pair(false, parameter);
-}
-
void ModeChannelHalfOp::RemoveMode(Channel* channel, irc::modestacker* stack)
{
const UserMembList* clist = channel->GetUsers();
{
}
-ModePair ModeChannelKey::ModeSet(User*, User*, Channel* channel, const std::string ¶meter)
-{
- if (channel->modes[CM_KEY])
- {
- std::string ckey = channel->GetModeParameter('k');
- return std::make_pair(true, ckey);
- }
- else
- {
- return std::make_pair(false, parameter);
- }
-}
-
void ModeChannelKey::RemoveMode(Channel* channel, irc::modestacker* stack)
{
/** +k needs a parameter when being removed,
{
}
-ModePair ModeChannelLimit::ModeSet(User*, User*, Channel* channel, const std::string ¶meter)
-{
- std::string climit = channel->GetModeParameter('l');
- if (!climit.empty())
- {
- return std::make_pair(true, climit);
- }
- else
- {
- return std::make_pair(false, parameter);
- }
-}
-
bool ModeChannelLimit::ResolveModeConflict(std::string &their_param, const std::string &our_param, Channel*)
{
/* When TS is equal, the higher channel limit wins */
return OP_VALUE;
}
-ModePair ModeChannelOp::ModeSet(User*, User*, Channel* channel, const std::string ¶meter)
-{
- User* x = ServerInstance->FindNick(parameter);
- if (x)
- {
- Membership* memb = channel->GetUser(x);
- if (memb && memb->hasMode('o'))
- {
- return std::make_pair(true, x->nick);
- }
- else
- {
- return std::make_pair(false, parameter);
- }
- }
- return std::make_pair(false, parameter);
-}
-
-
void ModeChannelOp::RemoveMode(Channel* channel, irc::modestacker* stack)
{
const UserMembList* clist = channel->GetUsers();
return VOICE_VALUE;
}
-ModePair ModeChannelVoice::ModeSet(User*, User*, Channel* channel, const std::string ¶meter)
-{
- User* x = ServerInstance->FindNick(parameter);
- if (x)
- {
- Membership* memb = channel->GetUser(x);
- if (memb && memb->hasMode('v'))
- {
- return std::make_pair(true, x->nick);
- }
- else
- {
- return std::make_pair(false, parameter);
- }
- }
- return std::make_pair(false, parameter);
-}
-
void ModeChannelVoice::RemoveMode(Channel* channel, irc::modestacker* stack)
{
const UserMembList* clist = channel->GetUsers();
{
}
- ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter)
- {
- User* x = ServerInstance->FindNick(parameter);
- if (x)
- {
- Membership* memb = channel->GetUser(x);
- if (!memb)
- {
- return std::make_pair(false, parameter);
- }
- else
- {
- if (memb->hasMode(mode))
- {
- return std::make_pair(true, x->nick);
- }
- else
- {
- return std::make_pair(false, parameter);
- }
- }
- }
- return std::make_pair(false, parameter);
- }
-
void RemoveMode(Channel* channel, irc::modestacker* stack)
{
const UserMembList* cl = channel->GetUsers();
return FOUNDER_VALUE;
}
- ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter)
- {
- return FounderProtectBase::ModeSet(source, dest, channel, parameter);
- }
-
void RemoveMode(Channel* channel, irc::modestacker* stack)
{
FounderProtectBase::RemoveMode(channel, stack);
return PROTECT_VALUE;
}
- ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter)
- {
- return FounderProtectBase::ModeSet(source, dest, channel, parameter);
- }
-
void RemoveMode(Channel* channel, irc::modestacker* stack)
{
FounderProtectBase::RemoveMode(channel, stack);
/* Display the join to everyone else (the user who joined got it earlier) */
channel->WriteAllExceptSender(user, false, 0, "JOIN %s", channel->name.c_str());
- std::string n = ServerInstance->Modes->ModeString(user, channel);
- if (n.length() > 0)
- channel->WriteAllExceptSender(user, false, 0, "MODE %s +%s", channel->name.c_str(), n.c_str());
+ std::string ms = memb->modes;
+ for(unsigned int i=0; i < memb->modes.length(); i++)
+ ms.append(" ").append(user->nick);
+
+ if (ms.length() > 0)
+ channel->WriteAllExceptSender(user, false, 0, "MODE %s +%s", channel->name.c_str(), ms.c_str());
}
MODULE_INIT(ModuleDelayJoin)
levelrequired = OP_VALUE;
}
- ModePair ModeSet(User*, User*, Channel* channel, const std::string ¶meter)
- {
- std::string climit = channel->GetModeParameter('d');
- if (!climit.empty())
- {
- return std::make_pair(true, climit);
- }
- else
- {
- return std::make_pair(false, parameter);
- }
- }
-
bool ResolveModeConflict(std::string &their_param, const std::string &our_param, Channel*)
{
return (atoi(their_param.c_str()) < atoi(our_param.c_str()));
snprintf(tb,MAXBUF,":%s %s %s", dest->GetFullHost().c_str(), adding ? "PART" : "JOIN", (*f)->name.c_str());
std::string out = tb;
- std::string n = ServerInstance->Modes->ModeString(dest, (*f));
+ Membership* memb = (**f).GetUser(dest);
+ std::string ms = memb->modes;
+ for(unsigned int i=0; i < memb->modes.length(); i++)
+ ms.append(" ").append(dest->nick);
+
for (UserMembCIter i = ulist->begin(); i != ulist->end(); i++)
{
if (IS_LOCAL(i->first) && !IS_OPER(i->first))
{
i->first->Write(out);
- if (!n.empty() && !adding)
- i->first->WriteServ("MODE %s +%s", (*f)->name.c_str(), n.c_str());
+ if (!ms.empty() && !adding)
+ i->first->WriteServ("MODE %s +%s", (**f).name.c_str(), ms.c_str());
}
}
}
JoinFlood(Module* Creator) : ModeHandler(Creator, "joinflood", 'j', PARAM_SETONLY, MODETYPE_CHANNEL),
ext("joinflood", Creator) { }
- ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter)
- {
- joinfloodsettings* x = ext.get(channel);
- if (x)
- return std::make_pair(true, ConvToStr(x->joins)+":"+ConvToStr(x->secs));
- else
- return std::make_pair(false, parameter);
- }
-
ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
{
if (adding)
KickRejoin(Module* Creator) : ModeHandler(Creator, "kicknorejoin", 'J', PARAM_SETONLY, MODETYPE_CHANNEL),
ext("norejoinusers", Creator) { }
- ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter)
- {
- if (channel->IsModeSet('J'))
- return std::make_pair(true, channel->GetModeParameter('J'));
- else
- return std::make_pair(false, parameter);
- }
-
ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
{
if (!adding)
MsgFlood(Module* Creator) : ModeHandler(Creator, "flood", 'f', PARAM_SETONLY, MODETYPE_CHANNEL),
ext("messageflood", Creator) { }
- ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter)
- {
- floodsettings* x = ext.get(channel);
- if (x)
- return std::make_pair(true, (x->ban ? "*" : "")+ConvToStr(x->lines)+":"+ConvToStr(x->secs));
- else
- return std::make_pair(false, parameter);
- }
-
ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
{
floodsettings *f = ext.get(channel);
NickFlood(Module* Creator) : ModeHandler(Creator, "nickflood", 'F', PARAM_SETONLY, MODETYPE_CHANNEL),
ext("nickflood", Creator) { }
- ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter)
- {
- nickfloodsettings* x = ext.get(channel);
- if (x)
- return std::make_pair(true, ConvToStr(x->nicks)+":"+ConvToStr(x->secs));
- else
- return std::make_pair(false, parameter);
- }
-
ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
{
nickfloodsettings *f = ext.get(channel);
m_paramtype = TR_NICK;
}
- ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter)
- {
- User* x = ServerInstance->FindNick(parameter);
- if (x)
- {
- Membership* m = channel->GetUser(x);
- if (!m)
- {
- return std::make_pair(false, parameter);
- }
- else
- {
- if (m->hasMode('Y'))
- {
- return std::make_pair(true, x->nick);
- }
- else
- {
- return std::make_pair(false, parameter);
- }
- }
- }
- return std::make_pair(false, parameter);
- }
-
void RemoveMode(Channel* channel, irc::modestacker* stack)
{
const UserMembList* cl = channel->GetUsers();
}
}
- ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter)
- {
- User* x = ServerInstance->FindNick(parameter);
- Membership* m = channel->GetUser(x);
- if (x)
- {
- if (!m)
- {
- return std::make_pair(false, parameter);
- }
- else
- {
- if (m->hasMode('y'))
- return std::make_pair(true, x->nick);
- else
- return std::make_pair(false, parameter);
- }
- }
- return std::make_pair(false, parameter);
- }
-
bool NeedsOper() { return true; }
};
public:
Redirect(Module* Creator) : ModeHandler(Creator, "redirect", 'L', PARAM_SETONLY, MODETYPE_CHANNEL) { }
- ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter)
- {
- if (channel->IsModeSet('L'))
- return std::make_pair(true, channel->GetModeParameter('L'));
- else
- return std::make_pair(false, parameter);
- }
-
ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
{
if (adding)
User *u = ServerInstance->FindNick(param);
if (u)
{
+ Membership* memb = chan->GetUser(u);
/* The target user has +k set on themselves, and you are trying to remove a privilege mode the user has set on themselves.
* This includes any prefix permission mode, even those registered in other modules, e.g. +qaohv. Using ::ModeString()
* here means that the number of modes is restricted to only modes the user has, limiting it to as short a loop as possible.
*/
- if (u->IsModeSet('k') && ServerInstance->Modes->ModeString(u, chan, false).find(mode) != std::string::npos)
+ if (u->IsModeSet('k') && memb && memb->modes.find(mode) != std::string::npos)
{
/* BZZZT, Denied! */
user->WriteNumeric(482, "%s %s :You are not permitted to remove privileges from %s services", user->nick.c_str(), chan->name.c_str(), ServerInstance->Config->Network.c_str());
for (UserMembCIter i = ulist->begin(); i != ulist->end(); i++)
{
size_t ptrlen = 0;
- std::string modestr = ServerInstance->Modes->ModeString(i->first, c, false);
+ std::string modestr = i->second->modes;
if ((curlen + modestr.length() + i->first->uuid.length() + 4) > 480)
{
Channel* c = *v;
snprintf(buffer, MAXBUF, ":%s JOIN %s", GetFullHost().c_str(), c->name.c_str());
std::string joinline(buffer);
- std::string modeline = ServerInstance->Modes->ModeString(this, c);
+ Membership* memb = c->GetUser(this);
+ std::string modeline = memb->modes;
if (modeline.length() > 0)
{
+ for(unsigned int i=0; i < memb->modes.length(); i++)
+ modeline.append(" ").append(nick);
snprintf(buffer, MAXBUF, ":%s MODE %s +%s", GetFullHost().c_str(), c->name.c_str(), modeline.c_str());
modeline = buffer;
}