summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-08 15:38:59 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-08 15:38:59 +0000
commit922d4ebf7a27a6577d6b4f91e0f42ccdfa989455 (patch)
treede1a76fa9c7934f9dab301986b63a3cceea3b073 /src
parent8d99003c221b7d6dcc04d0fc58629c243b48dbf0 (diff)
userrec::UpdateNickHash(), userrec::ForceNickChange(), userrec::FullConnect()
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4793 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/cmd_nick.cpp2
-rw-r--r--src/modules.cpp4
-rw-r--r--src/modules/m_nicklock.cpp11
-rw-r--r--src/modules/m_sanick.cpp7
-rw-r--r--src/modules/m_spanningtree.cpp6
-rw-r--r--src/userprocess.cpp4
-rw-r--r--src/users.cpp111
7 files changed, 67 insertions, 78 deletions
diff --git a/src/cmd_nick.cpp b/src/cmd_nick.cpp
index b767bc32b..cdb37690e 100644
--- a/src/cmd_nick.cpp
+++ b/src/cmd_nick.cpp
@@ -124,7 +124,7 @@ void cmd_nick::Handle (const char** parameters, int pcnt, userrec *user)
strlcpy(oldnick, user->nick, NICKMAX - 1);
/* change the nick of the user in the users_hash */
- user = ReHashNick(user->nick, parameters[0]);
+ user = user->UpdateNickHash(parameters[0]);
/* actually change the nick within the record */
if (!user) return;
if (!user->nick) return;
diff --git a/src/modules.cpp b/src/modules.cpp
index 71dee1a59..a0e150764 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -409,10 +409,6 @@ chanuserlist Server::GetUsers(chanrec* chan)
userl.push_back(i->second);
return userl;
}
-void Server::ChangeUserNick(userrec* user, const std::string &nickname)
-{
- force_nickchange(user,nickname.c_str());
-}
bool Server::IsUlined(const std::string &server)
{
diff --git a/src/modules/m_nicklock.cpp b/src/modules/m_nicklock.cpp
index 315f8390e..36bf0598d 100644
--- a/src/modules/m_nicklock.cpp
+++ b/src/modules/m_nicklock.cpp
@@ -55,11 +55,12 @@ class cmd_nicklock : public command_t
{
// give them a lock flag
Srv->SendOpers(std::string(user->nick)+" used NICKLOCK to change and hold "+std::string(parameters[0])+" to "+parameters[1]);
- Srv->ChangeUserNick(source,std::string(parameters[1]));
- // only attempt to set their lockflag after we know the change succeeded
- source = Srv->FindNick(std::string(parameters[1]));
- if (source)
- source->Extend("nick_locked", "ON");
+ if (!source->ForceNickChange(parameters[1]))
+ {
+ userrec::QuitUser(source, "Nickname collision");
+ return;
+ }
+ source->Extend("nick_locked", "ON");
}
}
}
diff --git a/src/modules/m_sanick.cpp b/src/modules/m_sanick.cpp
index 09b585b14..561bca613 100644
--- a/src/modules/m_sanick.cpp
+++ b/src/modules/m_sanick.cpp
@@ -50,7 +50,12 @@ class cmd_sanick : public command_t
// FIX by brain: Cant use source->nick here because if it traverses a server link then
// source->nick becomes invalid as the object data moves in memory.
Srv->SendOpers(std::string(user->nick)+" used SANICK to change "+std::string(parameters[0])+" to "+parameters[1]);
- Srv->ChangeUserNick(source,std::string(parameters[1]));
+ if (!source->ForceNickChange(parameters[1]))
+ {
+ /* We couldnt change the nick */
+ userrec::QuitUser(source, "Nickname collision");
+ return;
+ }
}
}
}
diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp
index 491c3c471..1e908f07b 100644
--- a/src/modules/m_spanningtree.cpp
+++ b/src/modules/m_spanningtree.cpp
@@ -2014,7 +2014,11 @@ class TreeSocket : public InspSocket
/* This is not required as one is sent in OnUserPostNick below
*/
//DoOneToMany(u->nick,"NICK",par);
- Srv->ChangeUserNick(u,params[1]);
+ if (!u->ForceNickChange(params[1].c_str()))
+ {
+ userrec::QuitUser(u, "Nickname collision");
+ return true;
+ }
u->age = atoi(params[2].c_str());
}
}
diff --git a/src/userprocess.cpp b/src/userprocess.cpp
index ba05032ca..9c253a074 100644
--- a/src/userprocess.cpp
+++ b/src/userprocess.cpp
@@ -345,13 +345,13 @@ void DoBackgroundUserStuff(time_t TIME)
curr->dns_done = true;
//ZapThisDns(curr->fd);
ServerInstance->stats->statsDnsBad++;
- FullConnectUser(curr,&GlobalGoners);
+ curr->FullConnect(&GlobalGoners);
continue;
}
if ((curr->dns_done) && (curr->registered == REG_NICKUSER) && (AllModulesReportReady(curr)))
{
log(DEBUG,"dns done, registered=3, and modules ready, OK");
- FullConnectUser(curr,&GlobalGoners);
+ curr->FullConnect(&GlobalGoners);
//ZapThisDns(curr->fd);
continue;
}
diff --git a/src/users.cpp b/src/users.cpp
index 327d0b5bb..61600bd04 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -962,43 +962,42 @@ long FindMatchingLocal(userrec* user)
return x;
}
-void FullConnectUser(userrec* user, CullList* Goners)
+void userrec::FullConnect(CullList* Goners)
{
ServerInstance->stats->statsConnects++;
- user->idle_lastmsg = TIME;
- log(DEBUG,"ConnectUser: %s",user->nick);
+ this->idle_lastmsg = TIME;
+
+ ConnectClass a = GetClass(this);
- ConnectClass a = GetClass(user);
-
if (a.type == CC_DENY)
{
- Goners->AddItem(user,"Unauthorised connection");
+ Goners->AddItem(this,"Unauthorised connection");
return;
}
- if ((*(a.pass.c_str())) && (!user->haspassed))
+ if ((*(a.pass.c_str())) && (!this->haspassed))
{
- Goners->AddItem(user,"Invalid password");
+ Goners->AddItem(this,"Invalid password");
return;
}
- if (FindMatchingLocal(user) > a.maxlocal)
+ if (FindMatchingLocal(this) > a.maxlocal)
{
- Goners->AddItem(user,"No more connections allowed from your host via this connect class (local)");
- WriteOpers("*** WARNING: maximum LOCAL connections (%ld) exceeded for IP %s",a.maxlocal,user->GetIPString());
+ Goners->AddItem(this, "No more connections allowed from your host via this connect class (local)");
+ WriteOpers("*** WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a.maxlocal, this->GetIPString());
return;
}
- else if (FindMatchingGlobal(user) > a.maxglobal)
+ else if (FindMatchingGlobal(this) > a.maxglobal)
{
- Goners->AddItem(user,"No more connections allowed from your host via this connect class (global)");
- WriteOpers("*** WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s",a.maxglobal,user->GetIPString());
+ Goners->AddItem(this, "No more connections allowed from your host via this connect class (global)");
+ WriteOpers("*** WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s",a.maxglobal, this->GetIPString());
return;
}
char match_against[MAXBUF];
- snprintf(match_against,MAXBUF,"%s@%s",user->ident,user->host);
+ snprintf(match_against,MAXBUF,"%s@%s", this->ident, this->host);
char* e = matches_exception(match_against);
-
+
if (!e)
{
char* r = matches_gline(match_against);
@@ -1007,7 +1006,7 @@ void FullConnectUser(userrec* user, CullList* Goners)
{
char reason[MAXBUF];
snprintf(reason,MAXBUF,"G-Lined: %s",r);
- Goners->AddItem(user,reason);
+ Goners->AddItem(this, reason);
return;
}
@@ -1017,18 +1016,18 @@ void FullConnectUser(userrec* user, CullList* Goners)
{
char reason[MAXBUF];
snprintf(reason,MAXBUF,"K-Lined: %s",r);
- Goners->AddItem(user,reason);
+ Goners->AddItem(this, reason);
return;
}
}
- WriteServ(user->fd,"NOTICE Auth :Welcome to \002%s\002!",Config->Network);
- WriteServ(user->fd,"001 %s :Welcome to the %s IRC Network %s!%s@%s",user->nick,Config->Network,user->nick,user->ident,user->host);
- WriteServ(user->fd,"002 %s :Your host is %s, running version %s",user->nick,Config->ServerName,VERSION);
- WriteServ(user->fd,"003 %s :This server was created %s %s",user->nick,__TIME__,__DATE__);
- WriteServ(user->fd,"004 %s %s %s %s %s %s",user->nick,Config->ServerName,VERSION,ServerInstance->ModeGrok->UserModeList().c_str(),ServerInstance->ModeGrok->ChannelModeList().c_str(),+ServerInstance->ModeGrok->ParaModeList().c_str());
-
+ WriteServ(this->fd,"NOTICE Auth :Welcome to \002%s\002!",Config->Network);
+ WriteServ(this->fd,"001 %s :Welcome to the %s IRC Network %s!%s@%s",this->nick, Config->Network, this->nick, this->ident, this->host);
+ WriteServ(this->fd,"002 %s :Your host is %s, running version %s",this->nick,Config->ServerName,VERSION);
+ WriteServ(this->fd,"003 %s :This server was created %s %s", this->nick, __TIME__, __DATE__);
+ WriteServ(this->fd,"004 %s %s %s %s %s %s", this->nick, Config->ServerName, VERSION, ServerInstance->ModeGrok->UserModeList().c_str(), ServerInstance->ModeGrok->ChannelModeList().c_str(), ServerInstance->ModeGrok->ParaModeList().c_str());
+
// anfl @ #ratbox, efnet reminded me that according to the RFC this cant contain more than 13 tokens per line...
// so i'd better split it :)
std::stringstream out(Config->data005);
@@ -1044,94 +1043,78 @@ void FullConnectUser(userrec* user, CullList* Goners)
if ((token_counter >= 13) || (out.eof() == true))
{
- WriteServ(user->fd,"005 %s %s:are supported by this server",user->nick,line5.c_str());
+ WriteServ(this->fd,"005 %s %s:are supported by this server", this->nick, line5.c_str());
line5 = "";
token_counter = 0;
}
}
- ShowMOTD(user);
+ ShowMOTD(this);
/*
* fix 3 by brain, move registered = 7 below these so that spurious modes and host
* changes dont go out onto the network and produce 'fake direction'.
*/
- FOREACH_MOD(I_OnUserConnect,OnUserConnect(user));
- FOREACH_MOD(I_OnGlobalConnect,OnGlobalConnect(user));
- user->registered = REG_ALL;
- WriteOpers("*** Client connecting on port %d: %s!%s@%s [%s]",user->GetPort(),user->nick,user->ident,user->host,user->GetIPString());
+ FOREACH_MOD(I_OnUserConnect,OnUserConnect(this));
+ FOREACH_MOD(I_OnGlobalConnect,OnGlobalConnect(this));
+ this->registered = REG_ALL;
+ WriteOpers("*** Client connecting on port %d: %s!%s@%s [%s]", this->GetPort(), this->nick, this->ident, this->host, this->GetIPString());
}
-/** ReHashNick()
+/** userrec::UpdateNick()
* re-allocates a nick in the user_hash after they change nicknames,
* returns a pointer to the new user as it may have moved
*/
-userrec* ReHashNick(const char* Old, const char* New)
+userrec* userrec::UpdateNickHash(const char* New)
{
//user_hash::iterator newnick;
- user_hash::iterator oldnick = clientlist.find(Old);
-
- log(DEBUG,"ReHashNick: %s %s",Old,New);
+ user_hash::iterator oldnick = clientlist.find(this->nick);
- if (!strcasecmp(Old,New))
- {
- log(DEBUG,"old nick is new nick, skipping");
+ if (!strcasecmp(this->nick,New))
return oldnick->second;
- }
if (oldnick == clientlist.end())
return NULL; /* doesnt exist */
- log(DEBUG,"ReHashNick: Found hashed nick %s",Old);
-
userrec* olduser = oldnick->second;
clientlist[New] = olduser;
clientlist.erase(oldnick);
-
- log(DEBUG,"ReHashNick: Nick rehashed as %s",New);
-
return clientlist[New];
}
-void force_nickchange(userrec* user,const char* newnick)
+bool userrec::ForceNickChange(const char* newnick)
{
char nick[MAXBUF];
int MOD_RESULT = 0;
*nick = 0;
- FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(user,newnick));
+ FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(this, newnick));
if (MOD_RESULT)
{
ServerInstance->stats->statsCollisions++;
- userrec::QuitUser(user,"Nickname collision");
- return;
+ return false;
}
if (matches_qline(newnick))
{
ServerInstance->stats->statsCollisions++;
- userrec::QuitUser(user,"Nickname collision");
- return;
+ return false;
}
- if (user)
+ if (newnick)
{
- if (newnick)
- {
- strlcpy(nick,newnick,MAXBUF-1);
- }
-
- if (user->registered == REG_ALL)
- {
- const char* pars[1];
- pars[0] = nick;
- std::string cmd = "NICK";
-
- ServerInstance->Parser->CallHandler(cmd,pars,1,user);
- }
+ strlcpy(this->nick, newnick, NICKMAX - 1);
}
+ if (this->registered == REG_ALL)
+ {
+ const char* pars[1];
+ pars[0] = nick;
+ std::string cmd = "NICK";
+ ServerInstance->Parser->CallHandler(cmd, pars, 1, this);
+ }
+ return true;
}
void userrec::SetSockAddr(int protocol_family, const char* ip, int port)