summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cmd_oper.cpp2
-rw-r--r--src/message.cpp37
-rw-r--r--src/modules.cpp20
-rw-r--r--src/modules/extra/m_sqloper.cpp2
-rw-r--r--src/modules/m_chanprotect.cpp106
-rw-r--r--src/modules/m_chghost.cpp3
-rw-r--r--src/modules/m_cloaking.cpp4
-rw-r--r--src/modules/m_hostchange.cpp3
-rw-r--r--src/modules/m_sethost.cpp4
-rw-r--r--src/modules/m_setname.cpp2
-rw-r--r--src/modules/m_spanningtree.cpp4
-rw-r--r--src/modules/m_sslmodes.cpp13
-rw-r--r--src/modules/m_vhost.cpp2
-rw-r--r--src/users.cpp80
14 files changed, 135 insertions, 147 deletions
diff --git a/src/cmd_oper.cpp b/src/cmd_oper.cpp
index eafeb227b..abd34f653 100644
--- a/src/cmd_oper.cpp
+++ b/src/cmd_oper.cpp
@@ -93,7 +93,7 @@ void cmd_oper::Handle (const char** parameters, int pcnt, userrec *user)
/* found this oper's opertype */
Config->ConfValue(Config->config_data, "type","host", j, HostName, MAXBUF);
if (*HostName)
- ChangeDisplayedHost(user,HostName);
+ user->ChangeDisplayedHost(HostName);
if (!isnick(TypeName))
{
user->WriteServ("491 %s :Invalid oper type (oper types must follow the same syntax as nicknames)",user->nick);
diff --git a/src/message.cpp b/src/message.cpp
index e69ce94ab..455c9754f 100644
--- a/src/message.cpp
+++ b/src/message.cpp
@@ -48,43 +48,6 @@ extern std::vector<ircd_module*> factory;
extern time_t TIME;
extern ServerConfig* Config;
-int c_count(userrec* u)
-{
- int z = 0;
- for (std::vector<ucrec*>::const_iterator i = u->chans.begin(); i != u->chans.end(); i++)
- if ((*i)->channel)
- z++;
- return z;
-
-}
-
-void ChangeName(userrec* user, const char* gecos)
-{
- if (user->fd > -1)
- {
- int MOD_RESULT = 0;
- FOREACH_RESULT(I_OnChangeLocalUserGECOS,OnChangeLocalUserGECOS(user,gecos));
- if (MOD_RESULT)
- return;
- FOREACH_MOD(I_OnChangeName,OnChangeName(user,gecos));
- }
- strlcpy(user->fullname,gecos,MAXGECOS+1);
-}
-
-void ChangeDisplayedHost(userrec* user, const char* host)
-{
- if (user->fd > -1)
- {
- int MOD_RESULT = 0;
- FOREACH_RESULT(I_OnChangeLocalUserHost,OnChangeLocalUserHost(user,host));
- if (MOD_RESULT)
- return;
- FOREACH_MOD(I_OnChangeHost,OnChangeHost(user,host));
- }
- strlcpy(user->dhost,host,63);
- user->WriteServ("396 %s %s :is now your hidden host",user->nick,user->dhost);
-}
-
/* verify that a user's ident and nickname is valid */
int isident(const char* n)
diff --git a/src/modules.cpp b/src/modules.cpp
index d9f13987f..3675319ec 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -400,16 +400,6 @@ void Server::SendToModeMask(const std::string &modes, int flags, const std::stri
WriteMode(modes.c_str(),flags,"%s",text.c_str());
}
-chanuserlist Server::GetUsers(chanrec* chan)
-{
- chanuserlist userl;
- userl.clear();
- CUList *list = chan->GetUsers();
- for (CUList::iterator i = list->begin(); i != list->end(); i++)
- userl.push_back(i->second);
- return userl;
-}
-
bool Server::IsUlined(const std::string &server)
{
return is_uline(server.c_str());
@@ -460,16 +450,6 @@ void Server::DumpText(userrec* User, const std::string &LinePrefix, stringstream
User->WriteServ(CompleteLine);
}
-void Server::ChangeHost(userrec* user, const std::string &host)
-{
- ChangeDisplayedHost(user,host.c_str());
-}
-
-void Server::ChangeGECOS(userrec* user, const std::string &gecos)
-{
- ChangeName(user,gecos.c_str());
-}
-
bool Server::IsNick(const std::string &nick)
{
return (isnick(nick.c_str()) != 0);
diff --git a/src/modules/extra/m_sqloper.cpp b/src/modules/extra/m_sqloper.cpp
index 3e91959b8..a67ec46e2 100644
--- a/src/modules/extra/m_sqloper.cpp
+++ b/src/modules/extra/m_sqloper.cpp
@@ -231,7 +231,7 @@ public:
std::string operhost = Conf.ReadValue("type", "host", j);
if (operhost.size())
- Srv->ChangeHost(user, operhost);
+ user->ChangeDisplayedHost(operhost);
strlcpy(user->oper, type.c_str(), NICKMAX-1);
diff --git a/src/modules/m_chanprotect.cpp b/src/modules/m_chanprotect.cpp
index 85e8d4a78..4ad3796b9 100644
--- a/src/modules/m_chanprotect.cpp
+++ b/src/modules/m_chanprotect.cpp
@@ -3,13 +3,13 @@
* +------------------------------------+
*
* 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.
*
* ---------------------------------------------------
*/
@@ -33,9 +33,9 @@ class ChanFounder : public ModeHandler
ModePair ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter)
{
- userrec* x = Find(parameter);
- if (x)
- {
+ userrec* x = Find(parameter);
+ if (x)
+ {
if (!channel->HasUser(x))
{
return std::make_pair(false, parameter);
@@ -44,15 +44,15 @@ class ChanFounder : public ModeHandler
{
std::string founder = "cm_founder_"+std::string(channel->name);
if (x->GetExt(founder,dummyptr))
- {
- return std::make_pair(true, x->nick);
- }
- else
- {
- return std::make_pair(false, parameter);
- }
+ {
+ return std::make_pair(true, x->nick);
+ }
+ else
+ {
+ return std::make_pair(false, parameter);
+ }
}
- }
+ }
return std::make_pair(false, parameter);
}
@@ -125,13 +125,13 @@ class ChanFounder : public ModeHandler
void DisplayList(userrec* user, chanrec* channel)
{
- chanuserlist cl = Srv->GetUsers(channel);
+ CUList* cl = channel->GetUsers();
std::string founder = "cm_founder_"+std::string(channel->name);
- for (unsigned int i = 0; i < cl.size(); i++)
+ for (CUList::iterator i = cl->begin(); i != cl->end(); i++)
{
- if (cl[i]->GetExt(founder, dummyptr))
+ if (i->second->GetExt(founder, dummyptr))
{
- user->WriteServ("386 %s %s %s",user->nick, channel->name,cl[i]->nick);
+ user->WriteServ("386 %s %s %s",user->nick, channel->name,i->second->nick);
}
}
user->WriteServ("387 %s %s :End of channel founder list",user->nick, channel->name);
@@ -146,30 +146,30 @@ class ChanProtect : public ModeHandler
public:
ChanProtect(Server* s) : ModeHandler('a', 1, 1, true, MODETYPE_CHANNEL, false), Srv(s) { }
- ModePair ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter)
- {
- userrec* x = Find(parameter);
- if (x)
- {
- if (!channel->HasUser(x))
- {
- return std::make_pair(false, parameter);
- }
- else
- {
- std::string founder = "cm_protect_"+std::string(channel->name);
- if (x->GetExt(founder,dummyptr))
- {
- return std::make_pair(true, x->nick);
- }
- else
- {
- return std::make_pair(false, parameter);
- }
- }
- }
- return std::make_pair(false, parameter);
- }
+ ModePair ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter)
+ {
+ userrec* x = Find(parameter);
+ if (x)
+ {
+ if (!channel->HasUser(x))
+ {
+ return std::make_pair(false, parameter);
+ }
+ else
+ {
+ std::string founder = "cm_protect_"+std::string(channel->name);
+ if (x->GetExt(founder,dummyptr))
+ {
+ return std::make_pair(true, x->nick);
+ }
+ else
+ {
+ return std::make_pair(false, parameter);
+ }
+ }
+ }
+ return std::make_pair(false, parameter);
+ }
ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
{
@@ -227,13 +227,13 @@ class ChanProtect : public ModeHandler
virtual void DisplayList(userrec* user, chanrec* channel)
{
- chanuserlist cl = Srv->GetUsers(channel);
+ CUList* cl = channel->GetUsers();
std::string protect = "cm_protect_"+std::string(channel->name);
- for (unsigned int i = 0; i < cl.size(); i++)
+ for (CUList::iterator i = cl->begin(); i != cl->end(); i++)
{
- if (cl[i]->GetExt(protect,dummyptr))
+ if (i->second->GetExt(protect,dummyptr))
{
- user->WriteServ("388 %s %s %s",user->nick, channel->name,cl[i]->nick);
+ user->WriteServ("388 %s %s %s",user->nick, channel->name,i->second->nick);
}
}
user->WriteServ("389 %s %s :End of channel protected user list",user->nick, channel->name);
@@ -436,19 +436,19 @@ class ModuleChanProtect : public Module
// this is called when the server is linking into a net and wants to sync channel data.
// we should send our mode changes for the channel here to ensure that other servers
// know whos +q/+a on the channel.
- chanuserlist cl = Srv->GetUsers(chan);
+ CUList* cl = chan->GetUsers();
string_list commands;
std::string founder = "cm_founder_"+std::string(chan->name);
std::string protect = "cm_protect_"+std::string(chan->name);
- for (unsigned int i = 0; i < cl.size(); i++)
+ for (CUList::iterator i = cl->begin(); i != cl->end(); i++)
{
- if (cl[i]->GetExt(founder,dummyptr))
+ if (i->second->GetExt(founder,dummyptr))
{
- proto->ProtoSendMode(opaque,TYPE_CHANNEL,chan,"+q "+std::string(cl[i]->nick));
+ proto->ProtoSendMode(opaque,TYPE_CHANNEL,chan,"+q "+std::string(i->second->nick));
}
- if (cl[i]->GetExt(protect,dummyptr))
+ if (i->second->GetExt(protect,dummyptr))
{
- proto->ProtoSendMode(opaque,TYPE_CHANNEL,chan,"+a "+std::string(cl[i]->nick));
+ proto->ProtoSendMode(opaque,TYPE_CHANNEL,chan,"+a "+std::string(i->second->nick));
}
}
}
diff --git a/src/modules/m_chghost.cpp b/src/modules/m_chghost.cpp
index 82a94fadc..23a482a65 100644
--- a/src/modules/m_chghost.cpp
+++ b/src/modules/m_chghost.cpp
@@ -59,8 +59,7 @@ class cmd_chghost : public command_t
userrec* dest = Srv->FindNick(std::string(parameters[0]));
if (dest)
{
- Srv->ChangeHost(dest,parameters[1]);
- if (!Srv->IsUlined(user->server))
+ if ((dest->ChangeDisplayedHost(parameters[1])) && (!Srv->IsUlined(user->server)))
{
// fix by brain - ulines set hosts silently
Srv->SendOpers(std::string(user->nick)+" used CHGHOST to make the displayed host of "+std::string(dest->nick)+" become "+std::string(parameters[1]));
diff --git a/src/modules/m_cloaking.cpp b/src/modules/m_cloaking.cpp
index 1e1826b41..b8164d9ba 100644
--- a/src/modules/m_cloaking.cpp
+++ b/src/modules/m_cloaking.cpp
@@ -347,7 +347,7 @@ class CloakUser : public ModeHandler
b = std::string(ra) + "." + prefix + ".cloak";
}
Srv->Log(DEBUG,"cloak: allocated "+b);
- Srv->ChangeHost(dest,b);
+ dest->ChangeDisplayedHost(b.c_str());
}
dest->SetMode('x',true);
@@ -361,7 +361,7 @@ class CloakUser : public ModeHandler
/* User is removing the mode, so just restore their real host
* and make it match the displayed one.
*/
- Srv->ChangeHost(dest,dest->host);
+ dest->ChangeDisplayedHost(dest->host);
dest->SetMode('x',false);
return MODEACTION_ALLOW;
}
diff --git a/src/modules/m_hostchange.cpp b/src/modules/m_hostchange.cpp
index 0a9ea8ccc..354eea3ed 100644
--- a/src/modules/m_hostchange.cpp
+++ b/src/modules/m_hostchange.cpp
@@ -134,7 +134,8 @@ class ModuleHostChange : public Module
if (newhost != "")
{
user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your virtual host: " + newhost);
- Srv->ChangeHost(user,newhost);
+ if (!user->ChangeDisplayedHost(newhost.c_str()))
+ user->WriteServ("NOTICE "+std::string(user->nick)+" :Could not set your virtual host: " + newhost);
return;
}
}
diff --git a/src/modules/m_sethost.cpp b/src/modules/m_sethost.cpp
index 94e811d79..631bd13a1 100644
--- a/src/modules/m_sethost.cpp
+++ b/src/modules/m_sethost.cpp
@@ -54,8 +54,8 @@ class cmd_sethost : public command_t
}
}
}
- Srv->ChangeHost(user,parameters[0]);
- Srv->SendOpers(std::string(user->nick)+" used SETHOST to change their displayed host to "+std::string(parameters[0]));
+ if (user->ChangeDisplayedHost(parameters[0]))
+ Srv->SendOpers(std::string(user->nick)+" used SETHOST to change their displayed host to "+std::string(parameters[0]));
}
};
diff --git a/src/modules/m_setname.cpp b/src/modules/m_setname.cpp
index 72d255be7..30eab34df 100644
--- a/src/modules/m_setname.cpp
+++ b/src/modules/m_setname.cpp
@@ -44,7 +44,7 @@ class cmd_setname : public command_t
line = line + std::string(parameters[i]) + " ";
}
line = line + std::string(parameters[pcnt-1]);
- Srv->ChangeGECOS(user,line);
+ user->ChangeName(line.c_str());
}
};
diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp
index 6ced44c9f..aeeaa2c52 100644
--- a/src/modules/m_spanningtree.cpp
+++ b/src/modules/m_spanningtree.cpp
@@ -2189,7 +2189,7 @@ class TreeSocket : public InspSocket
if (u)
{
- Srv->ChangeHost(u,params[0]);
+ u->ChangeDisplayedHost(params[0].c_str());
DoOneToAllButSender(prefix,"FHOST",params,u->server);
}
return true;
@@ -2261,7 +2261,7 @@ class TreeSocket : public InspSocket
if (u)
{
- Srv->ChangeGECOS(u,params[0]);
+ u->ChangeName(params[0].c_str());
params[0] = ":" + params[0];
DoOneToAllButSender(prefix,"FNAME",params,u->server);
}
diff --git a/src/modules/m_sslmodes.cpp b/src/modules/m_sslmodes.cpp
index 673c30536..0d4b0e515 100644
--- a/src/modules/m_sslmodes.cpp
+++ b/src/modules/m_sslmodes.cpp
@@ -19,13 +19,16 @@ class SSLMode : public ModeHandler
{
if (!channel->IsModeSet('z'))
{
- chanuserlist userlist = Srv->GetUsers(channel);
- for(unsigned int i = 0; i < userlist.size(); i++)
+ if (IS_LOCAL(source))
{
- if(!userlist[i]->GetExt("ssl", dummy))
+ CUList* userlist = channel->GetUsers();
+ for(CUList::iterator i = userlist->begin(); i != userlist->end(); i++)
{
- source->WriteServ("490 %s %s :all members of the channel must be connected via SSL", source->nick, channel->name);
- return MODEACTION_DENY;
+ if(!i->second->GetExt("ssl", dummy))
+ {
+ source->WriteServ("490 %s %s :all members of the channel must be connected via SSL", source->nick, channel->name);
+ return MODEACTION_DENY;
+ }
}
}
channel->SetMode('z',true);
diff --git a/src/modules/m_vhost.cpp b/src/modules/m_vhost.cpp
index 71fadf2f9..80d3f8f6b 100644
--- a/src/modules/m_vhost.cpp
+++ b/src/modules/m_vhost.cpp
@@ -48,7 +48,7 @@ class cmd_vhost : public command_t
if (mask != "")
{
user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your VHost: " + mask);
- Srv->ChangeHost(user,mask);
+ user->ChangeDisplayedHost(mask.c_str());
return;
}
}
diff --git a/src/users.cpp b/src/users.cpp
index 929caf19c..bb3ef18e9 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -1578,23 +1578,65 @@ void userrec::WriteWallOps(const char* text, ...)
*/
bool userrec::SharesChannelWith(userrec *other)
{
- if ((!other) || (this->registered != REG_ALL) || (other->registered != REG_ALL))
- return false;
-
- /* Outer loop */
- for (std::vector<ucrec*>::const_iterator i = this->chans.begin(); i != this->chans.end(); i++)
- {
- /* Fetch the channel from the user */
- ucrec* user_channel = *i;
-
- if (user_channel->channel)
- {
- /* Eliminate the inner loop (which used to be ~equal in size to the outer loop)
- * by replacing it with a map::find which *should* be more efficient
- */
- if (user_channel->channel->HasUser(other))
- return true;
- }
- }
- return false;
+ if ((!other) || (this->registered != REG_ALL) || (other->registered != REG_ALL))
+ return false;
+
+ /* Outer loop */
+ for (std::vector<ucrec*>::const_iterator i = this->chans.begin(); i != this->chans.end(); i++)
+ {
+ /* Fetch the channel from the user */
+ ucrec* user_channel = *i;
+
+ if (user_channel->channel)
+ {
+ /* Eliminate the inner loop (which used to be ~equal in size to the outer loop)
+ * by replacing it with a map::find which *should* be more efficient
+ */
+ if (user_channel->channel->HasUser(other))
+ return true;
+ }
+ }
+ return false;
+}
+
+int userrec::CountChannels()
+{
+ int z = 0;
+ for (std::vector<ucrec*>::const_iterator i = this->chans.begin(); i != this->chans.end(); i++)
+ if ((*i)->channel)
+ z++;
+ return z;
+}
+
+bool userrec::ChangeName(const char* gecos)
+{
+ if (IS_LOCAL(this))
+ {
+ int MOD_RESULT = 0;
+ FOREACH_RESULT(I_OnChangeLocalUserGECOS,OnChangeLocalUserGECOS(this,gecos));
+ if (MOD_RESULT)
+ return false;
+ FOREACH_MOD(I_OnChangeName,OnChangeName(this,gecos));
+ }
+ strlcpy(this->fullname,gecos,MAXGECOS+1);
+ return true;
}
+
+bool userrec::ChangeDisplayedHost(const char* host)
+{
+ if (IS_LOCAL(this))
+ {
+ int MOD_RESULT = 0;
+ FOREACH_RESULT(I_OnChangeLocalUserHost,OnChangeLocalUserHost(this,host));
+ if (MOD_RESULT)
+ return false;
+ FOREACH_MOD(I_OnChangeHost,OnChangeHost(this,host));
+ }
+ strlcpy(this->dhost,host,63);
+
+ if (IS_LOCAL(this))
+ this->WriteServ("396 %s %s :is now your hidden host",this->nick,this->dhost);
+
+ return true;
+}
+