summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-10 15:44:03 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-10 15:44:03 +0000
commitdafc021be4f3ad34ca37953de6a0109a161dd165 (patch)
treef6263063894fa0a923656d64d0e3e1351e0e205f /src
parent667bf736370b1d632f6ff99ce32bdcd7f0de9b3f (diff)
cmode(), cflags(), cstatus() -> chanrec::GetStatusChar(), chanrec::GetStatusFlags(), chanrec::GetStatus()
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4837 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/channels.cpp77
-rw-r--r--src/cmd_invite.cpp2
-rw-r--r--src/cmd_notice.cpp2
-rw-r--r--src/cmd_privmsg.cpp2
-rw-r--r--src/cmd_topic.cpp2
-rw-r--r--src/cmd_who.cpp6
-rw-r--r--src/message.cpp86
-rw-r--r--src/mode.cpp2
-rw-r--r--src/modes/cmode_b.cpp2
-rw-r--r--src/modes/cmode_h.cpp4
-rw-r--r--src/modes/cmode_o.cpp4
-rw-r--r--src/modes/cmode_v.cpp4
-rw-r--r--src/modules.cpp5
-rw-r--r--src/modules/m_check.cpp2
-rw-r--r--src/modules/m_nonotice.cpp2
-rw-r--r--src/modules/m_override.cpp6
-rw-r--r--src/modules/m_remove.cpp8
-rw-r--r--src/modules/m_spanningtree.cpp2
-rw-r--r--src/modules/m_spy.cpp2
-rw-r--r--src/modules/m_timedbans.cpp4
-rw-r--r--src/modules/m_uninvite.cpp2
-rw-r--r--src/users.cpp2
22 files changed, 104 insertions, 124 deletions
diff --git a/src/channels.cpp b/src/channels.cpp
index a78b92642..20353ff1f 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -588,8 +588,8 @@ long chanrec::KickUser(userrec *src, userrec *user, const char* reason)
if ((MOD_RESULT == ACR_DEFAULT) || (!is_uline(src->server)))
{
- int them = cstatus(src, this);
- int us = cstatus(user, this);
+ int them = this->GetStatus(src);
+ int us = this->GetStatus(user);
if ((them < STATUS_HOP) || (them < us))
{
if (them == STATUS_HOP)
@@ -838,7 +838,7 @@ void chanrec::UserList(userrec *user)
continue;
}
- size_t ptrlen = snprintf(ptr, MAXBUF, "%s%s ", cmode(i->second, this), i->second->nick);
+ size_t ptrlen = snprintf(ptr, MAXBUF, "%s%s ", this->GetStatusChar(i->second), i->second->nick);
curlen += ptrlen;
ptr += ptrlen;
@@ -881,3 +881,74 @@ long chanrec::GetMaxBans()
}
+/* returns the status character for a given user on a channel, e.g. @ for op,
+ * % for halfop etc. If the user has several modes set, the highest mode
+ * the user has must be returned. */
+
+const char* chanrec::GetStatusChar(userrec *user)
+{
+ for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
+ {
+ if ((*i)->channel == this)
+ {
+ if (((*i)->uc_modes & UCMODE_OP) > 0)
+ {
+ return "@";
+ }
+ if (((*i)->uc_modes & UCMODE_HOP) > 0)
+ {
+ return "%";
+ }
+ if (((*i)->uc_modes & UCMODE_VOICE) > 0)
+ {
+ return "+";
+ }
+ return "";
+ }
+ }
+ return "";
+}
+
+
+int chanrec::GetStatusFlags(userrec *user)
+{
+ for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
+ {
+ if ((*i)->channel == this)
+ {
+ return (*i)->uc_modes;
+ }
+ }
+ return 0;
+}
+
+
+
+int chanrec::GetStatus(userrec *user)
+{
+ if (is_uline(user->server))
+ return STATUS_OP;
+
+ for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
+ {
+ if ((*i)->channel == this)
+ {
+ if (((*i)->uc_modes & UCMODE_OP) > 0)
+ {
+ return STATUS_OP;
+ }
+ if (((*i)->uc_modes & UCMODE_HOP) > 0)
+ {
+ return STATUS_HOP;
+ }
+ if (((*i)->uc_modes & UCMODE_VOICE) > 0)
+ {
+ return STATUS_VOICE;
+ }
+ return STATUS_NORMAL;
+ }
+ }
+ return STATUS_NORMAL;
+}
+
+
diff --git a/src/cmd_invite.cpp b/src/cmd_invite.cpp
index 78de20cd8..33cc6bb5e 100644
--- a/src/cmd_invite.cpp
+++ b/src/cmd_invite.cpp
@@ -53,7 +53,7 @@ void cmd_invite::Handle (const char** parameters, int pcnt, userrec *user)
if ((c->modes[CM_INVITEONLY]) && (IS_LOCAL(user)))
{
- if (cstatus(user,c) < STATUS_HOP)
+ if (c->GetStatus(user) < STATUS_HOP)
{
user->WriteServ("482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, c->name);
return;
diff --git a/src/cmd_notice.cpp b/src/cmd_notice.cpp
index 6825ea5ea..156fc8f55 100644
--- a/src/cmd_notice.cpp
+++ b/src/cmd_notice.cpp
@@ -79,7 +79,7 @@ void cmd_notice::Handle (const char** parameters, int pcnt, userrec *user)
user->WriteServ("404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
return;
}
- if ((chan->modes[CM_MODERATED]) && (cstatus(user,chan)<STATUS_VOICE))
+ if ((chan->modes[CM_MODERATED]) && (chan->GetStatus(user) < STATUS_VOICE))
{
user->WriteServ("404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
return;
diff --git a/src/cmd_privmsg.cpp b/src/cmd_privmsg.cpp
index e72e1ef75..9255b67e3 100644
--- a/src/cmd_privmsg.cpp
+++ b/src/cmd_privmsg.cpp
@@ -77,7 +77,7 @@ void cmd_privmsg::Handle (const char** parameters, int pcnt, userrec *user)
user->WriteServ("404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
return;
}
- if ((chan->modes[CM_MODERATED]) && (cstatus(user,chan)<STATUS_VOICE))
+ if ((chan->modes[CM_MODERATED]) && (chan->GetStatus(user) < STATUS_VOICE))
{
user->WriteServ("404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
return;
diff --git a/src/cmd_topic.cpp b/src/cmd_topic.cpp
index bd7308f26..57b4e0433 100644
--- a/src/cmd_topic.cpp
+++ b/src/cmd_topic.cpp
@@ -71,7 +71,7 @@ void cmd_topic::Handle (const char** parameters, int pcnt, userrec *user)
user->WriteServ("442 %s %s :You're not on that channel!",user->nick, Ptr->name);
return;
}
- if ((Ptr->modes[CM_TOPICLOCK]) && (cstatus(user,Ptr)<STATUS_HOP))
+ if ((Ptr->modes[CM_TOPICLOCK]) && (Ptr->GetStatus(user) < STATUS_HOP))
{
user->WriteServ("482 %s %s :You must be at least a half-operator to change modes on this channel", user->nick, Ptr->name);
return;
diff --git a/src/cmd_who.cpp b/src/cmd_who.cpp
index 140fa92e2..cc29801cc 100644
--- a/src/cmd_who.cpp
+++ b/src/cmd_who.cpp
@@ -150,7 +150,7 @@ void cmd_who::Handle (const char** parameters, int pcnt, userrec *user)
wholine.append("*");
}
- wholine = wholine + cmode(i->second, ch) + " :0 " + i->second->fullname;
+ wholine = wholine + ch->GetStatusChar(i->second) + " :0 " + i->second->fullname;
whoresults.push_back(wholine);
}
}
@@ -188,7 +188,7 @@ void cmd_who::Handle (const char** parameters, int pcnt, userrec *user)
wholine.append("*");
}
- wholine = wholine + cmode(oper, ch) + " :0 " + oper->fullname;
+ wholine = wholine + ch->GetStatusChar(oper) + " :0 " + oper->fullname;
whoresults.push_back(wholine);
}
}
@@ -220,7 +220,7 @@ void cmd_who::Handle (const char** parameters, int pcnt, userrec *user)
wholine.append("*");
}
- wholine = wholine + cmode(i->second, ch) + " :0 " + i->second->fullname;
+ wholine = wholine + ch->GetStatusChar(i->second) + " :0 " + i->second->fullname;
whoresults.push_back(wholine);
}
}
diff --git a/src/message.cpp b/src/message.cpp
index 6d5941f7e..7a1811a63 100644
--- a/src/message.cpp
+++ b/src/message.cpp
@@ -97,89 +97,3 @@ int isnick(const char* n)
return (p < NICKMAX - 1);
}
-/* returns the status character for a given user on a channel, e.g. @ for op,
- * % for halfop etc. If the user has several modes set, the highest mode
- * the user has must be returned. */
-
-const char* cmode(userrec *user, chanrec *chan)
-{
- if ((!user) || (!chan))
- {
- log(DEFAULT,"*** BUG *** cmode was given an invalid parameter");
- return "";
- }
-
- for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
- {
- if ((*i)->channel == chan)
- {
- if (((*i)->uc_modes & UCMODE_OP) > 0)
- {
- return "@";
- }
- if (((*i)->uc_modes & UCMODE_HOP) > 0)
- {
- return "%";
- }
- if (((*i)->uc_modes & UCMODE_VOICE) > 0)
- {
- return "+";
- }
- return "";
- }
- }
- return "";
-}
-
-int cflags(userrec *user, chanrec *chan)
-{
- if ((!chan) || (!user))
- return 0;
-
- for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
- {
- if ((*i)->channel == chan)
- {
- return (*i)->uc_modes;
- }
- }
- return 0;
-}
-
-/* returns the status value for a given user on a channel, e.g. STATUS_OP for
- * op, STATUS_VOICE for voice etc. If the user has several modes set, the
- * highest mode the user has must be returned. */
-
-int cstatus(userrec *user, chanrec *chan)
-{
- if ((!chan) || (!user))
- {
- log(DEFAULT,"*** BUG *** cstatus was given an invalid parameter");
- return 0;
- }
-
- if (is_uline(user->server))
- return STATUS_OP;
-
- for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
- {
- if ((*i)->channel == chan)
- {
- if (((*i)->uc_modes & UCMODE_OP) > 0)
- {
- return STATUS_OP;
- }
- if (((*i)->uc_modes & UCMODE_HOP) > 0)
- {
- return STATUS_HOP;
- }
- if (((*i)->uc_modes & UCMODE_VOICE) > 0)
- {
- return STATUS_VOICE;
- }
- return STATUS_NORMAL;
- }
- }
- return STATUS_NORMAL;
-}
-
diff --git a/src/mode.cpp b/src/mode.cpp
index 266d06350..d34770ab4 100644
--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -309,7 +309,7 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool
* (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");
diff --git a/src/modes/cmode_b.cpp b/src/modes/cmode_b.cpp
index d0c783ad9..d03213f2e 100644
--- a/src/modes/cmode_b.cpp
+++ b/src/modes/cmode_b.cpp
@@ -27,7 +27,7 @@ ModeChannelBan::ModeChannelBan() : ModeHandler('b', 1, 1, true, MODETYPE_CHANNEL
ModeAction ModeChannelBan::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
{
- int status = cstatus(source, channel);
+ int status = channel->GetStatus(source);
/* Call the correct method depending on wether we're adding or removing the mode */
if (adding)
{
diff --git a/src/modes/cmode_h.cpp b/src/modes/cmode_h.cpp
index 49bf08288..3e5d5a372 100644
--- a/src/modes/cmode_h.cpp
+++ b/src/modes/cmode_h.cpp
@@ -31,7 +31,7 @@ ModePair ModeChannelHalfOp::ModeSet(userrec* source, userrec* dest, chanrec* cha
userrec* x = ServerInstance->FindNick(parameter);
if (x)
{
- if (cstatus(x, channel) == STATUS_HOP)
+ if (channel->GetStatus(x) == STATUS_HOP)
{
return std::make_pair(true, x->nick);
}
@@ -54,7 +54,7 @@ ModeAction ModeChannelHalfOp::OnModeChange(userrec* source, userrec* dest, chanr
return MODEACTION_DENY;
}
- int status = cstatus(source, channel);
+ int status = channel->GetStatus(source);
/* Call the correct method depending on wether we're adding or removing the mode */
if (adding)
diff --git a/src/modes/cmode_o.cpp b/src/modes/cmode_o.cpp
index 580fcc636..4e60a1abd 100644
--- a/src/modes/cmode_o.cpp
+++ b/src/modes/cmode_o.cpp
@@ -31,7 +31,7 @@ ModePair ModeChannelOp::ModeSet(userrec* source, userrec* dest, chanrec* channel
userrec* x = ServerInstance->FindNick(parameter);
if (x)
{
- if (cstatus(x, channel) == STATUS_OP)
+ if (channel->GetStatus(x) == STATUS_OP)
{
return std::make_pair(true, x->nick);
}
@@ -45,7 +45,7 @@ ModePair ModeChannelOp::ModeSet(userrec* source, userrec* dest, chanrec* channel
ModeAction ModeChannelOp::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
{
- int status = cstatus(source, channel);
+ int status = channel->GetStatus(source);
/* Call the correct method depending on wether we're adding or removing the mode */
if (adding)
diff --git a/src/modes/cmode_v.cpp b/src/modes/cmode_v.cpp
index b93a04f49..b71775885 100644
--- a/src/modes/cmode_v.cpp
+++ b/src/modes/cmode_v.cpp
@@ -31,7 +31,7 @@ ModePair ModeChannelVoice::ModeSet(userrec* source, userrec* dest, chanrec* chan
userrec* x = ServerInstance->FindNick(parameter);
if (x)
{
- if (cstatus(x, channel) == STATUS_VOICE)
+ if (channel->GetStatus(x) == STATUS_VOICE)
{
return std::make_pair(true, x->nick);
}
@@ -45,7 +45,7 @@ ModePair ModeChannelVoice::ModeSet(userrec* source, userrec* dest, chanrec* chan
ModeAction ModeChannelVoice::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
{
- int status = cstatus(source, channel);
+ int status = channel->GetStatus(source);
/* Call the correct method depending on wether we're adding or removing the mode */
if (adding)
diff --git a/src/modules.cpp b/src/modules.cpp
index ef0136a8e..d5ddc3bb0 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -430,11 +430,6 @@ userrec* Server::FindDescriptor(int socket)
return (socket < 65536 ? ServerInstance->fd_ref_table[socket] : NULL);
}
-std::string Server::ChanMode(userrec* User, chanrec* Chan)
-{
- return cmode(User,Chan);
-}
-
std::string Server::GetServerName()
{
return ServerInstance->Config->ServerName;
diff --git a/src/modules/m_check.cpp b/src/modules/m_check.cpp
index f8d84154e..8da57d9f2 100644
--- a/src/modules/m_check.cpp
+++ b/src/modules/m_check.cpp
@@ -127,7 +127,7 @@ class cmd_check : public command_t
char list[MAXBUF];
char tmpbuf[MAXBUF];
char* ptr = list;
- int flags = cflags(i->second, targchan);
+ int flags = targchan->GetStatusFlags(i->second);
/*
* find how many connections from this user's IP -- unlike Asuka,
* I define a clone as coming from the same host. --w00t
diff --git a/src/modules/m_nonotice.cpp b/src/modules/m_nonotice.cpp
index a92b327d7..673915ee8 100644
--- a/src/modules/m_nonotice.cpp
+++ b/src/modules/m_nonotice.cpp
@@ -79,7 +79,7 @@ class ModuleNoNotice : public Module
chanrec* c = (chanrec*)dest;
if (c->IsModeSet('T'))
{
- if ((Srv->IsUlined(user->server)) || (Srv->ChanMode(user,c) == "@") || (Srv->ChanMode(user,c) == "%"))
+ if ((Srv->IsUlined(user->server)) || (c->GetStatus(user) == STATUS_OP) || (c->GetStatus(user) == STATUS_HOP))
{
// ops and halfops can still /NOTICE the channel
return 0;
diff --git a/src/modules/m_override.cpp b/src/modules/m_override.cpp
index 4f188b0cb..a3bb407ed 100644
--- a/src/modules/m_override.cpp
+++ b/src/modules/m_override.cpp
@@ -93,7 +93,7 @@ class ModuleOverride : public Module
{
if ((*source->oper) && (CanOverride(source,"KICK")))
{
- if (((Srv->ChanMode(source,chan) == "%") && (Srv->ChanMode(user,chan) == "@")) || (Srv->ChanMode(source,chan) == ""))
+ if (((chan->GetStatus(source) == STATUS_HOP) && (chan->GetStatus(user) == STATUS_OP)) || (chan->GetStatus(source) < STATUS_VOICE))
{
ServerInstance->WriteOpers("*** NOTICE: "+std::string(source->nick)+" Override-Kicked "+std::string(user->nick)+" on "+std::string(chan->name)+" ("+reason+")");
}
@@ -111,8 +111,8 @@ class ModuleOverride : public Module
{
// Fix by brain - allow the change if they arent on channel - rely on boolean short-circuit
// to not check the other items in the statement if they arent on the channel
- std::string mode = Srv->ChanMode(source,channel);
- if ((!channel->HasUser(source)) || ((mode != "%") && (mode != "@")))
+ int mode = channel->GetStatus(source);
+ if ((!channel->HasUser(source)) || ((mode != STATUS_HOP) && (mode != STATUS_OP)))
{
switch (access_type)
{
diff --git a/src/modules/m_remove.cpp b/src/modules/m_remove.cpp
index 587edac86..354fe7a8d 100644
--- a/src/modules/m_remove.cpp
+++ b/src/modules/m_remove.cpp
@@ -127,8 +127,8 @@ class RemoveBase
}
else
{
- log(DEBUG, "Setting ulevel to %s", Srv->ChanMode(user, channel).c_str());
- ulevel = chartolevel(Srv->ChanMode(user, channel));
+ log(DEBUG, "Setting ulevel to %s", channel->GetStatusChar(user));
+ ulevel = chartolevel(channel->GetStatusChar(user));
}
/* Now it's the same idea, except for the target. If they're ulined make sure they get a higher level than the sender can */
@@ -149,8 +149,8 @@ class RemoveBase
}
else
{
- log(DEBUG, "Setting tlevel to %s", Srv->ChanMode(target, channel).c_str());
- tlevel = chartolevel(Srv->ChanMode(target, channel));
+ log(DEBUG, "Setting tlevel to %s", channel->GetStatusChar(target));
+ tlevel = chartolevel(channel->GetStatusChar(target));
}
hasnokicks = (Srv->FindModule("m_nokicks.so") && channel->IsModeSet('Q'));
diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp
index 3cee35deb..19a217178 100644
--- a/src/modules/m_spanningtree.cpp
+++ b/src/modules/m_spanningtree.cpp
@@ -1616,7 +1616,7 @@ class TreeSocket : public InspSocket
for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- int x = cflags(i->second,c);
+ int x = c->GetStatusFlags(i->second);
if ((x & UCMODE_HOP) && (x & UCMODE_OP))
{
specific_halfop.push_back(i->second);
diff --git a/src/modules/m_spy.cpp b/src/modules/m_spy.cpp
index 041814f9b..939af8662 100644
--- a/src/modules/m_spy.cpp
+++ b/src/modules/m_spy.cpp
@@ -63,7 +63,7 @@ void spy_userlist(userrec *user,chanrec *c)
CUList *ulist= c->GetUsers();
for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- strlcat(list,cmode(i->second,c),MAXBUF);
+ strlcat(list,c->GetStatusChar(i->second),MAXBUF);
strlcat(list,i->second->nick,MAXBUF);
strlcat(list," ",MAXBUF);
if (strlen(list)>(480-NICKMAX))
diff --git a/src/modules/m_timedbans.cpp b/src/modules/m_timedbans.cpp
index 14e68dfda..076ae09d5 100644
--- a/src/modules/m_timedbans.cpp
+++ b/src/modules/m_timedbans.cpp
@@ -55,8 +55,8 @@ class cmd_tban : public command_t
chanrec* channel = ServerInstance->FindChan(parameters[0]);
if (channel)
{
- std::string cm = Srv->ChanMode(user,channel);
- if ((cm == "%") || (cm == "@"))
+ int cm = channel->GetStatus(user);
+ if ((cm == STATUS_HOP) || (cm == STATUS_OP))
{
if (!Srv->IsValidMask(parameters[2]))
{
diff --git a/src/modules/m_uninvite.cpp b/src/modules/m_uninvite.cpp
index 8d8d46c47..70e73cfad 100644
--- a/src/modules/m_uninvite.cpp
+++ b/src/modules/m_uninvite.cpp
@@ -59,7 +59,7 @@ class cmd_uninvite : public command_t
if (c->modes[CM_INVITEONLY])
{
- if (cstatus(user,c) < STATUS_HOP)
+ if (c->GetStatus(user) < STATUS_HOP)
{
user->WriteServ("482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, c->name);
return;
diff --git a/src/users.cpp b/src/users.cpp
index baef05e28..ad358211d 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -1669,7 +1669,7 @@ std::string userrec::ChannelList(userrec* source)
*/
if ((source == this) || (*source->oper && ServerInstance->Config->OperSpyWhois) || (((!rec->channel->modes[CM_PRIVATE]) && (!rec->channel->modes[CM_SECRET])) || (rec->channel->HasUser(source))))
{
- list.append(cmode(this, rec->channel)).append(rec->channel->name).append(" ");
+ list.append(rec->channel->GetStatusChar(this)).append(rec->channel->name).append(" ");
}
}
}