* | Inspire Internet Relay Chat Daemon |
* +------------------------------------+
*
- * InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * InspIRCd: (C) 2002-2008 InspIRCd Development Team
* See: http://www.inspircd.org/wiki/index.php/Credits
*
* This program is free but copyrighted software; see
Penalty = 0;
lines_in = lastping = signon = idle_lastmsg = nping = registered = 0;
ChannelCount = timeout = bytes_in = bytes_out = cmds_in = cmds_out = 0;
- OverPenalty = ExemptFromPenalty = muted = exempt = haspassed = dns_done = false;
+ OverPenalty = ExemptFromPenalty = quitting = exempt = haspassed = dns_done = false;
fd = -1;
recvq.clear();
sendq.clear();
memset(modes,0,sizeof(modes));
memset(snomasks,0,sizeof(snomasks));
/* Invalidate cache */
- operquit = cached_fullhost = cached_hostip = cached_makehost = cached_fullrealhost = NULL;
+ cached_fullhost = cached_hostip = cached_makehost = cached_fullrealhost = NULL;
if (uid.empty())
strlcpy(uuid, Instance->GetUID().c_str(), UUID_LENGTH);
ServerInstance->Log(DEBUG,"New UUID for user: %s (%s)", uuid, uid.empty() ? "allocated new" : "used remote");
- user_hash::iterator finduuid = Instance->uuidlist->find(uuid);
- if (finduuid == Instance->uuidlist->end())
- (*Instance->uuidlist)[uuid] = this;
+ user_hash::iterator finduuid = Instance->Users->uuidlist->find(uuid);
+ if (finduuid == Instance->Users->uuidlist->end())
+ (*Instance->Users->uuidlist)[uuid] = this;
else
throw CoreException("Duplicate UUID "+std::string(uuid)+" in User constructor");
}
-void User::RemoveCloneCounts()
-{
- clonemap::iterator x = ServerInstance->local_clones.find(this->GetIPString());
- if (x != ServerInstance->local_clones.end())
- {
- x->second--;
- if (!x->second)
- {
- ServerInstance->local_clones.erase(x);
- }
- }
-
- clonemap::iterator y = ServerInstance->global_clones.find(this->GetIPString());
- if (y != ServerInstance->global_clones.end())
- {
- y->second--;
- if (!y->second)
- {
- ServerInstance->global_clones.erase(y);
- }
- }
-}
-
User::~User()
{
/* NULL for remote users :) */
this->InvalidateCache();
this->DecrementModes();
- if (operquit)
- free(operquit);
+
if (ip)
{
- this->RemoveCloneCounts();
+ ServerInstance->Users->RemoveCloneCounts(this);
if (this->GetProtocolFamily() == AF_INET)
{
#endif
}
- ServerInstance->uuidlist->erase(uuid);
+ ServerInstance->Users->uuidlist->erase(uuid);
}
char* User::MakeHost()
if (this->MyClass && (recvq.length() > this->MyClass->GetRecvqMax()))
{
this->SetWriteError("RecvQ exceeded");
- ServerInstance->WriteOpers("*** User %s RecvQ of %d exceeds connect class maximum of %d",this->nick,recvq.length(),this->MyClass->GetRecvqMax());
+ ServerInstance->SNO->WriteToSnoMask('A', "User %s RecvQ of %d exceeds connect class maximum of %d",this->nick,recvq.length(),this->MyClass->GetRecvqMax());
return false;
}
if (this->MyClass && (sendq.length() + data.length() > this->MyClass->GetSendqMax()))
{
/*
- * Fix by brain - Set the error text BEFORE calling writeopers, because
+ * Fix by brain - Set the error text BEFORE calling, because
* if we dont it'll recursively call here over and over again trying
* to repeatedly add the text to the sendq!
*/
this->SetWriteError("SendQ exceeded");
- ServerInstance->WriteOpers("*** User %s SendQ of %d exceeds connect class maximum of %d",this->nick,sendq.length() + data.length(),this->MyClass->GetSendqMax());
+ ServerInstance->SNO->WriteToSnoMask('A', "User %s SendQ of %d exceeds connect class maximum of %d",this->nick,sendq.length() + data.length(),this->MyClass->GetSendqMax());
return;
}
catch (...)
{
this->SetWriteError("SendQ exceeded");
- ServerInstance->WriteOpers("*** User %s SendQ got an exception",this->nick);
+ ServerInstance->SNO->WriteToSnoMask('A', "User %s SendQ got an exception",this->nick);
}
}
FOREACH_MOD(I_OnOper, OnOper(this, opertype));
ServerInstance->Log(DEFAULT,"OPER: %s!%s@%s opered as type: %s", this->nick, this->ident, this->host, opertype.c_str());
strlcpy(this->oper, opertype.c_str(), NICKMAX - 1);
- ServerInstance->all_opers.push_back(this);
+ ServerInstance->Users->all_opers.push_back(this);
opertype_t::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper);
if (iter_opertype != ServerInstance->Config->opertypes.end())
this->modes[UM_OPERATOR] = 0;
// remove the user from the oper list. Will remove multiple entries as a safeguard against bug #404
- ServerInstance->all_opers.remove(this);
+ ServerInstance->Users->all_opers.remove(this);
if (AllowedOperCommands)
{
{
Instance->Log(DEBUG,"QuitUser: %s '%s'", user->nick, quitreason.c_str());
user->Write("ERROR :Closing link (%s@%s) [%s]", user->ident, user->host, *operreason ? operreason : quitreason.c_str());
- user->muted = true;
- Instance->GlobalCulls.AddItem(user, quitreason.c_str(), operreason);
+ user->quietquit = false;
+ user->quitmsg = quitreason;
+ user->operquitmsg = operreason;
+ Instance->GlobalCulls.AddItem(user);
}
/* adds or updates an entry in the whowas list */
}
}
-/* add a client connection to the sockets list */
-void User::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, int socketfamily, sockaddr* ip)
-{
- /* NOTE: Calling this one parameter constructor for User automatically
- * allocates a new UUID and places it in the hash_map.
- */
- User* New = NULL;
- try
- {
- New = new User(Instance);
- }
- catch (...)
- {
- Instance->Log(DEFAULT,"*** WTF *** Duplicated UUID! -- Crack smoking monkies have been unleashed.");
- Instance->WriteOpers("*** WARNING *** Duplicate UUID allocated!");
- return;
- }
-
- Instance->Log(DEBUG,"New user fd: %d", socket);
-
- int j = 0;
-
- Instance->unregistered_count++;
-
- char ipaddr[MAXBUF];
-#ifdef IPV6
- if (socketfamily == AF_INET6)
- inet_ntop(AF_INET6, &((const sockaddr_in6*)ip)->sin6_addr, ipaddr, sizeof(ipaddr));
- else
-#endif
- inet_ntop(AF_INET, &((const sockaddr_in*)ip)->sin_addr, ipaddr, sizeof(ipaddr));
-
- (*(Instance->clientlist))[New->uuid] = New;
- New->SetFd(socket);
-
- /* The users default nick is their UUID */
- strlcpy(New->nick, New->uuid, NICKMAX - 1);
-
- New->server = Instance->FindServerNamePtr(Instance->Config->ServerName);
- /* We don't need range checking here, we KNOW 'unknown\0' will fit into the ident field. */
- strcpy(New->ident, "unknown");
-
- New->registered = REG_NONE;
- New->signon = Instance->Time() + Instance->Config->dns_timeout;
- New->lastping = 1;
-
- New->SetSockAddr(socketfamily, ipaddr, port);
-
- /* Smarter than your average bear^H^H^H^Hset of strlcpys. */
- for (const char* temp = New->GetIPString(); *temp && j < 64; temp++, j++)
- New->dhost[j] = New->host[j] = *temp;
- New->dhost[j] = New->host[j] = 0;
-
- Instance->AddLocalClone(New);
- Instance->AddGlobalClone(New);
-
- /*
- * First class check. We do this again in FullConnect after DNS is done, and NICK/USER is recieved.
- * See my note down there for why this is required. DO NOT REMOVE. :) -- w00t
- */
- ConnectClass* i = New->SetClass();
-
- if (!i)
- {
- User::QuitUser(Instance, New, "Access denied by configuration");
- return;
- }
-
- /*
- * Check connect class settings and initialise settings into User.
- * This will be done again after DNS resolution. -- w00t
- */
- New->CheckClass();
-
- Instance->local_users.push_back(New);
-
- if ((Instance->local_users.size() > Instance->Config->SoftLimit) || (Instance->local_users.size() >= MAXCLIENTS))
- {
- Instance->WriteOpers("*** Warning: softlimit value has been reached: %d clients", Instance->Config->SoftLimit);
- User::QuitUser(Instance, New,"No more connections allowed");
- return;
- }
-
- /*
- * XXX -
- * this is done as a safety check to keep the file descriptors within range of fd_ref_table.
- * its a pretty big but for the moment valid assumption:
- * file descriptors are handed out starting at 0, and are recycled as theyre freed.
- * therefore if there is ever an fd over 65535, 65536 clients must be connected to the
- * irc server at once (or the irc server otherwise initiating this many connections, files etc)
- * which for the time being is a physical impossibility (even the largest networks dont have more
- * than about 10,000 users on ONE server!)
- */
-#ifndef WINDOWS
- if ((unsigned int)socket >= MAX_DESCRIPTORS)
- {
- User::QuitUser(Instance, New, "Server is full");
- return;
- }
-#endif
- /*
- * even with bancache, we still have to keep User::exempt current.
- * besides that, if we get a positive bancache hit, we still won't fuck
- * them over if they are exempt. -- w00t
- */
- New->exempt = (Instance->XLines->MatchesLine("E",New) != NULL);
-
- if (BanCacheHit *b = Instance->BanCache->GetHit(New->GetIPString()))
- {
- if (!b->Type.empty() && !New->exempt)
- {
- /* user banned */
- Instance->Log(DEBUG, std::string("BanCache: Positive hit for ") + New->GetIPString());
- if (*Instance->Config->MoronBanner)
- New->WriteServ("NOTICE %s :*** %s", New->nick, Instance->Config->MoronBanner);
- User::QuitUser(Instance, New, b->Reason);
- return;
- }
- else
- {
- Instance->Log(DEBUG, std::string("BanCache: Negative hit for ") + New->GetIPString());
- }
- }
- else
- {
- if (!New->exempt)
- {
- XLine* r = Instance->XLines->MatchesLine("Z",New);
-
- if (r)
- {
- r->Apply(New);
- return;
- }
- }
- }
-
- if (socket > -1)
- {
- if (!Instance->SE->AddFd(New))
- {
- Instance->Log(DEBUG,"Internal error on new connection");
- User::QuitUser(Instance, New, "Internal error handling connection");
- }
- }
-
- /* NOTE: even if dns lookups are *off*, we still need to display this.
- * BOPM and other stuff requires it.
- */
- New->WriteServ("NOTICE Auth :*** Looking up your hostname...");
-
- if (Instance->Config->NoUserDns)
- {
- New->dns_done = true;
- }
- else
- {
- New->StartDNSLookup();
- }
-}
-
-unsigned long User::GlobalCloneCount()
-{
- clonemap::iterator x = ServerInstance->global_clones.find(this->GetIPString());
- if (x != ServerInstance->global_clones.end())
- return x->second;
- else
- return 0;
-}
-
-unsigned long User::LocalCloneCount()
-{
- clonemap::iterator x = ServerInstance->local_clones.find(this->GetIPString());
- if (x != ServerInstance->local_clones.end())
- return x->second;
- else
- return 0;
-}
-
/*
* Check class restrictions
*/
User::QuitUser(ServerInstance, this, "Unauthorised connection");
return;
}
- else if ((a->GetMaxLocal()) && (this->LocalCloneCount() > a->GetMaxLocal()))
+ else if ((a->GetMaxLocal()) && (ServerInstance->Users->LocalCloneCount(this) > a->GetMaxLocal()))
{
User::QuitUser(ServerInstance, this, "No more connections allowed from your host via this connect class (local)");
- ServerInstance->WriteOpers("*** WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString());
+ ServerInstance->SNO->WriteToSnoMask('A', "WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString());
return;
}
- else if ((a->GetMaxGlobal()) && (this->GlobalCloneCount() > a->GetMaxGlobal()))
+ else if ((a->GetMaxGlobal()) && (ServerInstance->Users->GlobalCloneCount(this) > a->GetMaxGlobal()))
{
User::QuitUser(ServerInstance, this, "No more connections allowed from your host via this connect class (global)");
- ServerInstance->WriteOpers("*** WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString());
+ ServerInstance->SNO->WriteToSnoMask('A', "WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString());
return;
}
if (r)
{
- this->muted = true;
r->Apply(this);
return;
}
if (n)
{
- this->muted = true;
n->Apply(this);
return;
}
this->ShowMOTD();
/* Now registered */
- if (ServerInstance->unregistered_count)
- ServerInstance->unregistered_count--;
+ if (ServerInstance->Users->unregistered_count)
+ ServerInstance->Users->unregistered_count--;
/* Trigger LUSERS output, give modules a chance too */
int MOD_RESULT = 0;
try
{
//user_hash::iterator newnick;
- user_hash::iterator oldnick = ServerInstance->clientlist->find(this->nick);
+ user_hash::iterator oldnick = ServerInstance->Users->clientlist->find(this->nick);
if (!strcasecmp(this->nick,New))
return oldnick->second;
- if (oldnick == ServerInstance->clientlist->end())
+ if (oldnick == ServerInstance->Users->clientlist->end())
return NULL; /* doesnt exist */
User* olduser = oldnick->second;
- (*(ServerInstance->clientlist))[New] = olduser;
- ServerInstance->clientlist->erase(oldnick);
+ (*(ServerInstance->Users->clientlist))[New] = olduser;
+ ServerInstance->Users->clientlist->erase(oldnick);
return olduser;
}
{
try
{
- int MOD_RESULT = 0;
+ /*
+ * XXX this makes no sense..
+ * why do we do nothing for change on users not REG_ALL?
+ * why do we trigger events twice for everyone previously (and just them now)
+ * i think the first if () needs removing totally, or? -- w00t
+ */
+ if (this->registered != REG_ALL)
+ {
+ int MOD_RESULT = 0;
- this->InvalidateCache();
+ this->InvalidateCache();
- FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(this, newnick));
+ FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(this, newnick));
- if (MOD_RESULT)
- {
- ServerInstance->stats->statsCollisions++;
- return false;
- }
+ if (MOD_RESULT)
+ {
+ ServerInstance->stats->statsCollisions++;
+ return false;
+ }
- if (ServerInstance->XLines->MatchesLine("Q",newnick))
- {
- ServerInstance->stats->statsCollisions++;
- return false;
+ if (ServerInstance->XLines->MatchesLine("Q",newnick))
+ {
+ ServerInstance->stats->statsCollisions++;
+ return false;
+ }
}
-
- if (this->registered == REG_ALL)
+ else
{
std::deque<classbase*> dummy;
Command* nickhandler = ServerInstance->Parser->GetHandler("NICK");
void User::SetSockAddr(int protocol_family, const char* ip, int port)
{
+ this->cachedip = "";
+
switch (protocol_family)
{
#ifdef SUPPORT_IP6LINKS
if (this->ip == NULL)
return "";
+ if (!this->cachedip.empty())
+ return this->cachedip.c_str();
+
switch (this->GetProtocolFamily())
{
#ifdef SUPPORT_IP6LINKS
{
strlcpy(&temp[1], buf, sizeof(temp) - 1);
*temp = '0';
+ this->cachedip = temp;
return temp;
}
+
+ this->cachedip = buf;
return buf;
}
break;
{
sockaddr_in* sin = (sockaddr_in*)this->ip;
inet_ntop(sin->sin_family, &sin->sin_addr, buf, sizeof(buf));
+ this->cachedip = buf;
return buf;
}
break;
default:
break;
}
+
+ // Unreachable, probably
return "";
}
std::string wallop("WALLOPS :");
wallop.append(text);
- for (std::vector<User*>::const_iterator i = ServerInstance->local_users.begin(); i != ServerInstance->local_users.end(); i++)
+ for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
{
User* t = *i;
if (t->IsModeSet('w'))
if (this->ServerInstance->Config->CycleHosts)
this->WriteCommonExcept("%s","QUIT :Changing ident");
- strlcpy(this->ident, newident, IDENTMAX+2);
+ strlcpy(this->ident, newident, IDENTMAX+1);
this->InvalidateCache();
snprintf(formatbuffer,MAXBUF,":%s %s $* :%s", this->GetFullHost(), command, textbuffer);
std::string fmt = formatbuffer;
- for (std::vector<User*>::const_iterator i = ServerInstance->local_users.begin(); i != ServerInstance->local_users.end(); i++)
+ for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
{
(*i)->Write(fmt);
}
void User::HandleEvent(EventType et, int errornum)
{
+ if (this->quitting) // drop everything, user is due to be quit
+ return;
+
/* WARNING: May delete this user! */
int thisfd = this->GetFd();
void User::SetOperQuit(const std::string &oquit)
{
- if (operquit)
- return;
-
- operquit = strdup(oquit.c_str());
+ operquitmsg = oquit;
}
const char* User::GetOperQuit()
{
- return operquit ? operquit : "";
+ return operquitmsg.c_str();
}
void User::IncreasePenalty(int increase)