* | Inspire Internet Relay Chat Daemon |
* +------------------------------------+
*
- * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
- * E-mail:
- * <brain@chatspike.net>
- * <Craig@chatspike.net>
- *
- * Written by Craig Edwards, Craig McLure, and others.
+ * InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
+ *
* This program is free but copyrighted software; see
- * the file COPYING for details.
+ * the file COPYING for details.
*
* ---------------------------------------------------
*/
res_reverse = new UserResolver(this->ServerInstance, this, this->GetIPString(), DNS_QUERY_REVERSE);
this->ServerInstance->AddResolver(res_reverse);
}
- catch (ModuleException& e)
+ catch (CoreException& e)
{
ServerInstance->Log(DEBUG,"Error in resolver: %s",e.GetReason());
}
this->ServerInstance->AddResolver(bound_user->res_forward);
}
}
- catch (ModuleException& e)
+ catch (CoreException& e)
{
ServerInstance->Log(DEBUG,"Error in resolver: %s",e.GetReason());
}
this->bound_user->dns_done = true;
strlcpy(this->bound_user->dhost, hostname.c_str(),64);
strlcpy(this->bound_user->host, hostname.c_str(),64);
+ /* Invalidate cache */
+ this->bound_user->InvalidateCache();
}
}
else
if (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user)
{
/* Error message here */
- this->bound_user->WriteServ("NOTICE Auth :*** Could not resolve your hostname, using your IP address (%s) instead.", this->bound_user->GetIPString());
+ this->bound_user->WriteServ("NOTICE Auth :*** Could not resolve your hostname: %s; using your IP address (%s) instead.", errormessage.c_str(), this->bound_user->GetIPString());
this->bound_user->dns_done = true;
}
}
return data;
}
+void userrec::DecrementModes()
+{
+ for (int n = 0; n < 64; n++)
+ {
+ if (modes[n])
+ {
+ ModeHandler* mh = ServerInstance->Modes->FindMode(n+65, MODETYPE_USER);
+ if (mh)
+ mh->ChangeCount(-1);
+ }
+ }
+}
+
userrec::userrec(InspIRCd* Instance) : ServerInstance(Instance)
{
ServerInstance->Log(DEBUG,"userrec::userrec(): Instance: %08x",ServerInstance);
age = ServerInstance->Time(true);
lines_in = lastping = signon = idle_lastmsg = nping = registered = 0;
ChannelCount = timeout = flood = bytes_in = bytes_out = cmds_in = cmds_out = 0;
- haspassed = dns_done = false;
+ exempt = haspassed = dns_done = false;
fd = -1;
recvq = "";
sendq = "";
ip = NULL;
chans.clear();
invites.clear();
- chans.resize(MAXCHANS);
memset(modes,0,sizeof(modes));
memset(snomasks,0,sizeof(snomasks));
-
- for (unsigned int n = 0; n < MAXCHANS; n++)
- {
- chans[n] = new ucrec();
- chans[n]->channel = NULL;
- chans[n]->uc_modes = 0;
- }
+ /* Invalidate cache */
+ cached_fullhost = cached_hostip = cached_makehost = cached_fullrealhost = NULL;
}
userrec::~userrec()
{
- for (std::vector<ucrec*>::iterator n = chans.begin(); n != chans.end(); n++)
- {
- ucrec* x = (ucrec*)*n;
- delete x;
- }
-
+ this->InvalidateCache();
+ this->DecrementModes();
if (ip)
{
clonemap::iterator x = ServerInstance->local_clones.find(this->GetIPString());
char* userrec::MakeHost()
{
- static char nhost[MAXBUF];
+ if (this->cached_makehost)
+ return this->cached_makehost;
+
+ char nhost[MAXBUF];
/* This is much faster than snprintf */
char* t = nhost;
for(char* n = ident; *n; n++)
for(char* n = host; *n; n++)
*t++ = *n;
*t = 0;
- return nhost;
+
+ this->cached_makehost = strdup(nhost);
+
+ return this->cached_makehost;
}
char* userrec::MakeHostIP()
{
- static char ihost[MAXBUF];
+ if (this->cached_hostip)
+ return this->cached_hostip;
+
+ char ihost[MAXBUF];
/* This is much faster than snprintf */
char* t = ihost;
for(char* n = ident; *n; n++)
for(const char* n = this->GetIPString(); *n; n++)
*t++ = *n;
*t = 0;
- return ihost;
+
+ this->cached_hostip = strdup(ihost);
+
+ return this->cached_hostip;
}
void userrec::CloseSocket()
char* userrec::GetFullHost()
{
- static char result[MAXBUF];
+ if (this->cached_fullhost)
+ return this->cached_fullhost;
+
+ char result[MAXBUF];
char* t = result;
for(char* n = nick; *n; n++)
*t++ = *n;
for(char* n = dhost; *n; n++)
*t++ = *n;
*t = 0;
- return result;
+
+ this->cached_fullhost = strdup(result);
+
+ return this->cached_fullhost;
}
char* userrec::MakeWildHost()
char* userrec::GetFullRealHost()
{
- static char fresult[MAXBUF];
+ if (this->cached_fullrealhost)
+ return this->cached_fullrealhost;
+
+ char fresult[MAXBUF];
char* t = fresult;
for(char* n = nick; *n; n++)
*t++ = *n;
for(char* n = host; *n; n++)
*t++ = *n;
*t = 0;
- return fresult;
+
+ this->cached_fullrealhost = strdup(fresult);
+
+ return this->cached_fullrealhost;
}
-bool userrec::IsInvited(irc::string &channel)
+bool userrec::IsInvited(const irc::string &channel)
{
for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
{
- irc::string compare = i->channel;
-
- if (compare == channel)
+ if (channel == *i)
{
return true;
}
return &invites;
}
-void userrec::InviteTo(irc::string &channel)
+void userrec::InviteTo(const irc::string &channel)
{
- Invited i;
- i.channel = channel;
- invites.push_back(i);
+ invites.push_back(channel);
}
-void userrec::RemoveInvite(irc::string &channel)
+void userrec::RemoveInvite(const irc::string &channel)
{
ServerInstance->Log(DEBUG,"Removing invites");
-
- if (invites.size())
+ for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
{
- for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
+ if (channel == *i)
{
- irc::string compare = i->channel;
-
- if (compare == channel)
- {
- invites.erase(i);
- return;
- }
- }
- }
+ invites.erase(i);
+ return;
+ }
+ }
}
bool userrec::HasPermission(const std::string &command)
try
{
if (data.length() > 512)
- {
- std::string newdata(data);
- newdata.resize(510);
- newdata.append("\r\n");
- sendq.append(newdata);
- }
+ sendq.append(data.substr(0,510)).append("\r\n");
else
- {
sendq.append(data);
- }
}
catch (...)
{
if ((sendq.length()) && (this->fd != FD_MAGIC_NUMBER))
{
int old_sendq_length = sendq.length();
- const char* tb = this->sendq.c_str();
- int n_sent = write(this->fd,tb,this->sendq.length());
+ int n_sent = write(this->fd, this->sendq.data(), this->sendq.length());
if (n_sent == -1)
{
if (errno == EAGAIN)
{
+ /* The socket buffer is full. This isnt fatal,
+ * try again later.
+ */
ServerInstance->Log(DEBUG,"EAGAIN, want write");
this->ServerInstance->SE->WantWrite(this);
}
else
{
- this->QuitUser(ServerInstance, this, strerror(errno));
+ /* Fatal error, set write error and bail
+ */
+ this->SetWriteError(strerror(errno));
return;
}
}
else
{
- /*ServerInstance->Log(DEBUG,"Wrote: %d of %d: %s", n_sent, old_sendq_length, sendq.substr(0, n_sent).c_str());*/
- // advance the queue
- tb += n_sent;
- this->sendq = tb;
- // update the user's stats counters
+ /* advance the queue */
+ if (n_sent)
+ this->sendq = this->sendq.substr(n_sent);
+ /* update the user's stats counters */
this->bytes_out += n_sent;
this->cmds_out++;
if (n_sent != old_sendq_length)
{
try
{
- ServerInstance->Log(DEBUG,"SetWriteError: %s",error.c_str());
// don't try to set the error twice, its already set take the first string.
- if (!this->WriteError.length())
+ if (this->WriteError.empty())
{
ServerInstance->Log(DEBUG,"Setting error string for %s to '%s'",this->nick,error.c_str());
this->WriteError = error;
void userrec::QuitUser(InspIRCd* Instance, userrec *user, const std::string &quitreason)
{
- user_hash::iterator iter = Instance->clientlist.find(user->nick);
+ user_hash::iterator iter = Instance->clientlist->find(user->nick);
std::string reason = quitreason;
if (reason.length() > MAXQUIT - 1)
reason.resize(MAXQUIT - 1);
-
+
+ if (user->registered != REG_ALL)
+ if (Instance->unregistered_count)
+ Instance->unregistered_count--;
+
if (IS_LOCAL(user))
+ {
user->Write("ERROR :Closing link (%s@%s) [%s]",user->ident,user->host,reason.c_str());
+ if ((!user->sendq.empty()) && (!(*user->GetWriteError())))
+ user->FlushWriteBuf();
+ }
if (user->registered == REG_ALL)
{
user->PurgeEmptyChannels();
- FOREACH_MOD_I(Instance,I_OnUserQuit,OnUserQuit(user,reason));
user->WriteCommonExcept("QUIT :%s",reason.c_str());
+ FOREACH_MOD_I(Instance,I_OnUserQuit,OnUserQuit(user,reason));
}
FOREACH_MOD_I(Instance,I_OnUserDisconnect,OnUserDisconnect(user));
{
Instance->Config->GetIOHook(user->GetPort())->OnRawSocketClose(user->fd);
}
- catch (ModuleException& modexcept)
+ catch (CoreException& modexcept)
{
- Instance->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason());
+ Instance->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
}
}
user->AddToWhoWas();
}
- if (iter != Instance->clientlist.end())
+ if (iter != Instance->clientlist->end())
{
Instance->Log(DEBUG,"deleting user hash value %lx",(unsigned long)user);
if (IS_LOCAL(user))
{
- if (find(Instance->local_users.begin(),Instance->local_users.end(),user) != Instance->local_users.end())
- Instance->local_users.erase(find(Instance->local_users.begin(),Instance->local_users.end(),user));
+ std::vector<userrec*>::iterator x = find(Instance->local_users.begin(),Instance->local_users.end(),user);
+ if (x != Instance->local_users.end())
+ Instance->local_users.erase(x);
}
- Instance->clientlist.erase(iter);
+ Instance->clientlist->erase(iter);
DELETE(user);
}
}
int maxgroups = ServerInstance->Config->WhoWasMaxGroups;
int maxkeep = ServerInstance->Config->WhoWasMaxKeep;
- int groupcount = ServerInstance->whowas.size();
- /* iterate whowas_fifo oldest first */
- whowas_users_fifo::iterator iter, safeiter;
- for (iter = ServerInstance->whowas_fifo.begin(); iter != ServerInstance->whowas_fifo.end(); iter++)
+ /* first cut the list to new size (maxgroups) and also prune entries that are timed out. */
+ whowas_users::iterator iter;
+ int fifosize;
+ while ((fifosize = (int)ServerInstance->whowas_fifo.size()) > 0)
{
- /** prune all groups that has expired due to new maxkeep time and
- * also any group number higher than new maxgroups. The oldest are
- * removed first due to iteration over whowas_fifo
- */
- if (groupcount > maxgroups || iter->first < t - maxkeep)
+ if (fifosize > maxgroups || ServerInstance->whowas_fifo[0].first < t - maxkeep)
{
- whowas_set* n = (whowas_set*)ServerInstance->whowas.find(iter->second)->second;
+ iter = ServerInstance->whowas.find(ServerInstance->whowas_fifo[0].second);
+ /* hopefully redundant integrity check, but added while debugging r6216 */
+ if (iter == ServerInstance->whowas.end())
+ {
+ /* this should never happen, if it does maps are corrupt */
+ ServerInstance->Log(DEBUG, "Whowas maps got corrupted! (1)");
+ return;
+ }
+ whowas_set* n = (whowas_set*)iter->second;
if (n->size())
{
while (n->begin() != n->end())
{
WhoWasGroup *a = *(n->begin());
DELETE(a);
- n->erase(n->begin());
+ n->pop_front();
}
}
- ServerInstance->whowas.erase(iter->second);
- /* use a safe iter copy for erase and set the orig iter old valid ref by decrementing it */
- safeiter = iter;
- --iter;
- ServerInstance->whowas_fifo.erase(safeiter);
+ ServerInstance->whowas.erase(iter);
+ ServerInstance->whowas_fifo.pop_front();
}
- else {
- /* also trim individual groupsizes in case groupsize should have been lowered */
- whowas_set* n = (whowas_set*)ServerInstance->whowas.find(iter->second)->second;
- if (n->size())
+ else
+ break;
+ }
+
+ /* Then cut the whowas sets to new size (groupsize) */
+ for (int i = 0; i < fifosize; i++)
+ {
+ iter = ServerInstance->whowas.find(ServerInstance->whowas_fifo[0].second);
+ /* hopefully redundant integrity check, but added while debugging r6216 */
+ if (iter == ServerInstance->whowas.end())
+ {
+ /* this should never happen, if it does maps are corrupt */
+ ServerInstance->Log(DEBUG, "Whowas maps got corrupted! (2)");
+ return;
+ }
+ whowas_set* n = (whowas_set*)iter->second;
+ if (n->size())
+ {
+ int nickcount = n->size();
+ while (n->begin() != n->end() && nickcount > groupsize)
{
- int nickcount = n->size();
- while (n->begin() != n->end() && nickcount > groupsize)
- {
- WhoWasGroup *a = *(n->begin());
- DELETE(a);
- n->erase(n->begin());
- nickcount--;
- }
+ WhoWasGroup *a = *(n->begin());
+ DELETE(a);
+ n->pop_front();
+ nickcount--;
}
}
- groupcount--;
}
}
};
if (iter == ServerInstance->whowas.end())
{
ServerInstance->Log(DEBUG,"Adding new whowas set for %s",this->nick);
+
irc::whowas::whowas_set* n = new irc::whowas::whowas_set;
irc::whowas::WhoWasGroup *a = new irc::whowas::WhoWasGroup(this);
n->push_back(a);
ServerInstance->whowas[this->nick] = n;
- ServerInstance->whowas_fifo[ServerInstance->Time()] = this->nick;
+ ServerInstance->whowas_fifo.push_back(std::make_pair(ServerInstance->Time(),this->nick));
+
if ((int)(ServerInstance->whowas.size()) > ServerInstance->Config->WhoWasMaxGroups)
{
- ServerInstance->Log(DEBUG,"Maxgroups of %d reached deleting oldest group '%s'",ServerInstance->Config->WhoWasMaxGroups, ServerInstance->whowas_fifo.begin()->second.c_str());
- ServerInstance->whowas.erase(ServerInstance->whowas_fifo.begin()->second);
- ServerInstance->whowas_fifo.erase(ServerInstance->whowas_fifo.begin());
+ ServerInstance->Log(DEBUG,"Maxgroups of %d reached deleting oldest group '%s'",ServerInstance->Config->WhoWasMaxGroups, ServerInstance->whowas_fifo[0].second.c_str());
+
+ irc::whowas::whowas_users::iterator iter = ServerInstance->whowas.find(ServerInstance->whowas_fifo[0].second);
+ if (iter != ServerInstance->whowas.end())
+ {
+ irc::whowas::whowas_set* n = (irc::whowas::whowas_set*)iter->second;
+ if (n->size())
+ {
+ while (n->begin() != n->end())
+ {
+ irc::whowas::WhoWasGroup *a = *(n->begin());
+ DELETE(a);
+ n->pop_front();
+ }
+ }
+ ServerInstance->whowas.erase(iter);
+ }
+ ServerInstance->whowas_fifo.pop_front();
}
}
else
ServerInstance->Log(DEBUG,"Using existing whowas group for %s",this->nick);
- if ((int)(group->size()) >= ServerInstance->Config->WhoWasGroupSize)
+ irc::whowas::WhoWasGroup *a = new irc::whowas::WhoWasGroup(this);
+ group->push_back(a);
+
+ if ((int)(group->size()) > ServerInstance->Config->WhoWasGroupSize)
{
ServerInstance->Log(DEBUG,"Trimming existing group '%s' to %d entries",this->nick, ServerInstance->Config->WhoWasGroupSize);
irc::whowas::WhoWasGroup *a = (irc::whowas::WhoWasGroup*)*(group->begin());
DELETE(a);
group->pop_front();
}
-
- irc::whowas::WhoWasGroup *a = new irc::whowas::WhoWasGroup(this);
- group->push_back(a);
}
}
void userrec::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, insp_inaddr ip)
{
std::string tempnick = ConvToStr(socket) + "-unknown";
- user_hash::iterator iter = Instance->clientlist.find(tempnick);
+ user_hash::iterator iter = Instance->clientlist->find(tempnick);
const char *ipaddr = insp_ntoa(ip);
userrec* New;
int j = 0;
+ Instance->unregistered_count++;
+
/*
* fix by brain.
* as these nicknames are 'RFC impossible', we can be sure nobody is going to be
* this was probably the cause of 'server ignores me when i hammer it with reconnects'
* issue in earlier alphas/betas
*/
- if (iter != Instance->clientlist.end())
+ if (iter != Instance->clientlist->end())
{
userrec* goner = iter->second;
DELETE(goner);
- Instance->clientlist.erase(iter);
+ Instance->clientlist->erase(iter);
}
Instance->Log(DEBUG,"AddClient: %d %d %s",socket,port,ipaddr);
-
+
New = new userrec(Instance);
- Instance->clientlist[tempnick] = New;
+ (*(Instance->clientlist))[tempnick] = New;
New->fd = socket;
strlcpy(New->nick,tempnick.c_str(),NICKMAX-1);
New->signon = Instance->Time() + Instance->Config->dns_timeout;
New->lastping = 1;
- Instance->Log(DEBUG,"Setting socket addresses");
New->SetSockAddr(AF_FAMILY, ipaddr, port);
- Instance->Log(DEBUG,"Socket addresses set.");
/* 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->Log(DEBUG,"Hosts set.");
Instance->AddLocalClone(New);
Instance->AddGlobalClone(New);
- // set the registration timeout for this user
- unsigned long class_regtimeout = 90;
- int class_flood = 0;
- long class_threshold = 5;
- long class_sqmax = 262144; // 256kb
- long class_rqmax = 4096; // 4k
+ ConnectClass* i = New->GetClass();
- Instance->Log(DEBUG,"Class stuff set.");
-
- for (ClassVector::iterator i = Instance->Config->Classes.begin(); i != Instance->Config->Classes.end(); i++)
+ if ((!i) || (i->GetType() == CC_DENY))
{
- if ((i->type == CC_ALLOW) && (match(ipaddr,i->host.c_str(),true)))
- {
- class_regtimeout = (unsigned long)i->registration_timeout;
- class_flood = i->flood;
- New->pingmax = i->pingtime;
- class_threshold = i->threshold;
- class_sqmax = i->sendqmax;
- class_rqmax = i->recvqmax;
- break;
- }
+ userrec::QuitUser(Instance, New,"Unauthorised connection");
+ return;
}
- Instance->Log(DEBUG,"nping etc set.");
-
- New->nping = Instance->Time() + New->pingmax + Instance->Config->dns_timeout;
- New->timeout = Instance->Time() + class_regtimeout;
- New->flood = class_flood;
- New->threshold = class_threshold;
- New->sendqmax = class_sqmax;
- New->recvqmax = class_rqmax;
+ New->pingmax = i->GetPingTime();
+ New->nping = Instance->Time() + i->GetPingTime() + Instance->Config->dns_timeout;
+ New->timeout = Instance->Time() + i->GetRegTimeout();
+ New->flood = i->GetFlood();
+ New->threshold = i->GetThreshold();
+ New->sendqmax = i->GetSendqMax();
+ New->recvqmax = i->GetRecvqMax();
- Instance->Log(DEBUG,"Push back to local users.");
Instance->local_users.push_back(New);
- Instance->Log(DEBUG,"Check softlimit: %d %d %d",Instance->local_users.size(), Instance->Config->SoftLimit, MAXCLIENTS);
if ((Instance->local_users.size() > Instance->Config->SoftLimit) || (Instance->local_users.size() >= MAXCLIENTS))
{
- Instance->Log(DEBUG,"Check softlimit failed");
Instance->WriteOpers("*** Warning: softlimit value has been reached: %d clients", Instance->Config->SoftLimit);
userrec::QuitUser(Instance, New,"No more connections allowed");
return;
}
- Instance->Log(DEBUG,"Softlimit passed.");
-
/*
* XXX -
* this is done as a safety check to keep the file descriptors within range of fd_ref_table.
return;
}
- Instance->Log(DEBUG,"socket < MAX_DESCRIPTORS passed.");
-
- ELine* e = Instance->XLines->matches_exception(New);
- if (!e)
+ New->exempt = (Instance->XLines->matches_exception(New) != NULL);
+ if (!New->exempt)
{
- Instance->Log(DEBUG,"Doesnt match eline.");
ZLine* r = Instance->XLines->matches_zline(ipaddr);
if (r)
{
- Instance->Log(DEBUG,"Matches zline.");
char reason[MAXBUF];
snprintf(reason,MAXBUF,"Z-Lined: %s",r->reason);
userrec::QuitUser(Instance, New, reason);
return;
}
- Instance->Log(DEBUG,"Doesnt match zline.");
}
- Instance->Log(DEBUG,"Check before AddFd.");
-
if (socket > -1)
{
- Instance->Log(DEBUG,"Adding fd.");
if (!Instance->SE->AddFd(New))
{
- Instance->Log(DEBUG,"Oops, fd already exists");
userrec::QuitUser(Instance, New, "Internal error handling connection");
return;
}
}
+ /* 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...");
}
-long userrec::GlobalCloneCount()
+unsigned long userrec::GlobalCloneCount()
{
clonemap::iterator x = ServerInstance->global_clones.find(this->GetIPString());
if (x != ServerInstance->global_clones.end())
return 0;
}
-long userrec::LocalCloneCount()
+unsigned long userrec::LocalCloneCount()
{
clonemap::iterator x = ServerInstance->local_clones.find(this->GetIPString());
if (x != ServerInstance->local_clones.end())
ServerInstance->stats->statsConnects++;
this->idle_lastmsg = ServerInstance->Time();
- ConnectClass a = this->GetClass();
+ ConnectClass* a = this->GetClass();
- if (a.type == CC_DENY)
+ if ((!a) || (a->GetType() == CC_DENY))
{
Goners->AddItem(this,"Unauthorised connection");
return;
}
-
- if ((*(a.pass.c_str())) && (!this->haspassed))
+
+ if ((!a->GetPass().empty()) && (!this->haspassed))
{
Goners->AddItem(this,"Invalid password");
return;
}
- if (this->LocalCloneCount() > a.maxlocal)
+ if (this->LocalCloneCount() > a->GetMaxLocal())
{
Goners->AddItem(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.maxlocal, this->GetIPString());
+ ServerInstance->WriteOpers("*** WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString());
return;
}
- else if (this->GlobalCloneCount() > a.maxglobal)
+ else if (this->GlobalCloneCount() > a->GetMaxGlobal())
{
Goners->AddItem(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.maxglobal, this->GetIPString());
+ ServerInstance->WriteOpers("*** WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s",a->GetMaxGlobal(), this->GetIPString());
return;
}
- ELine* e = ServerInstance->XLines->matches_exception(this);
-
- if (!e)
+ if (!this->exempt)
{
GLine* r = ServerInstance->XLines->matches_gline(this);
Goners->AddItem(this, reason);
return;
}
- }
+ }
this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network);
this->WriteServ("001 %s :Welcome to the %s IRC Network %s!%s@%s",this->nick, ServerInstance->Config->Network, this->nick, this->ident, this->host);
this->WriteServ("003 %s :This server was created %s %s", this->nick, __TIME__, __DATE__);
this->WriteServ("004 %s %s %s %s %s %s", this->nick, ServerInstance->Config->ServerName, VERSION, ServerInstance->Modes->UserModeList().c_str(), ServerInstance->Modes->ChannelModeList().c_str(), ServerInstance->Modes->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(ServerInstance->Config->data005);
- std::string token = "";
- std::string line5 = "";
- int token_counter = 0;
-
- while (!out.eof())
- {
- out >> token;
- line5 = line5 + token + " ";
- token_counter++;
-
- if ((token_counter >= 13) || (out.eof() == true))
- {
- this->WriteServ("005 %s %s:are supported by this server", this->nick, line5.c_str());
- line5 = "";
- token_counter = 0;
- }
- }
-
+ ServerInstance->Config->Send005(this);
+
this->ShowMOTD();
+ /* Now registered */
+ if (ServerInstance->unregistered_count)
+ ServerInstance->unregistered_count--;
+
/*
* 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'.
try
{
//user_hash::iterator newnick;
- user_hash::iterator oldnick = ServerInstance->clientlist.find(this->nick);
+ user_hash::iterator oldnick = ServerInstance->clientlist->find(this->nick);
if (!strcasecmp(this->nick,New))
return oldnick->second;
- if (oldnick == ServerInstance->clientlist.end())
+ if (oldnick == ServerInstance->clientlist->end())
return NULL; /* doesnt exist */
userrec* olduser = oldnick->second;
- ServerInstance->clientlist[New] = olduser;
- ServerInstance->clientlist.erase(oldnick);
- return ServerInstance->clientlist[New];
+ (*(ServerInstance->clientlist))[New] = olduser;
+ ServerInstance->clientlist->erase(oldnick);
+ return olduser;
}
catch (...)
}
}
+void userrec::InvalidateCache()
+{
+ /* Invalidate cache */
+ if (cached_fullhost)
+ free(cached_fullhost);
+ if (cached_hostip)
+ free(cached_hostip);
+ if (cached_makehost)
+ free(cached_makehost);
+ if (cached_fullrealhost)
+ free(cached_fullrealhost);
+ cached_fullhost = cached_hostip = cached_makehost = cached_fullrealhost = NULL;
+}
+
bool userrec::ForceNickChange(const char* newnick)
{
try
{
int MOD_RESULT = 0;
+
+ this->InvalidateCache();
FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(this, newnick));
}
break;
default:
- ServerInstance->Log(DEBUG,"Ut oh, '%s' has an unknown protocol family!",this->nick);
break;
}
return 0;
}
break;
default:
- ServerInstance->Log(DEBUG,"Ut oh, '%s' has an unknown protocol family!",this->nick);
break;
}
return "";
break;
default:
- ServerInstance->Log(DEBUG,"Ut oh, '%s' has an unknown protocol family!",this->nick);
break;
}
return "";
{
ServerInstance->Config->GetIOHook(this->GetPort())->OnRawSocketWrite(this->fd, text.data(), text.length());
}
- catch (ModuleException& modexcept)
+ catch (CoreException& modexcept)
{
- ServerInstance->Log(DEBUG,"Module exception caught: %s",modexcept.GetReason());
+ ServerInstance->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
}
}
else
try
{
bool sent_to_at_least_one = false;
+ char tb[MAXBUF];
if (this->registered != REG_ALL)
return;
uniq_id++;
+
+ /* We dont want to be doing this n times, just once */
+ snprintf(tb,MAXBUF,":%s %s",this->GetFullHost(),text.c_str());
+ std::string out = tb;
- for (std::vector<ucrec*>::const_iterator v = this->chans.begin(); v != this->chans.end(); v++)
+ for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
{
- ucrec *n = *v;
- if (n->channel)
+ CUList* ulist = v->first->GetUsers();
+ for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- CUList *ulist= n->channel->GetUsers();
-
- for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
+ if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
{
- if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
- {
- already_sent[i->second->fd] = uniq_id;
- i->second->WriteFrom(this, std::string(text));
- sent_to_at_least_one = true;
- }
+ already_sent[i->second->fd] = uniq_id;
+ i->second->Write(out);
+ sent_to_at_least_one = true;
}
}
}
*/
if (!sent_to_at_least_one)
{
- this->WriteFrom(this,std::string(text));
+ this->Write(std::string(tb));
}
}
bool quit_munge = false;
char oper_quit[MAXBUF];
char textbuffer[MAXBUF];
+ char tb1[MAXBUF];
+ char tb2[MAXBUF];
+ std::string out1;
+ std::string out2;
strlcpy(textbuffer, text.c_str(), MAXBUF);
uniq_id++;
+ snprintf(tb1,MAXBUF,":%s %s",this->GetFullHost(),textbuffer);
+
/* TODO: We need some form of WriteCommonExcept that will send two lines, one line to
* opers and the other line to non-opers, then all this hidebans and hidesplits gunk
* can go byebye.
strlcpy(oper_quit,textbuffer,MAXQUIT);
strlcpy(check,"*.net *.split",MAXQUIT);
quit_munge = true;
+ snprintf(tb2,MAXBUF,":%s %s",this->GetFullHost(),oper_quit);
+ out2 = tb2;
}
}
}
strlcpy(oper_quit,textbuffer,MAXQUIT);
*check = 0; // We don't need to strlcpy, we just chop it from the :
quit_munge = true;
+ snprintf(tb2,MAXBUF,":%s %s",this->GetFullHost(),oper_quit);
+ out2 = tb2;
}
}
- for (std::vector<ucrec*>::const_iterator v = this->chans.begin(); v != this->chans.end(); v++)
+ out1 = tb1;
+
+ for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
{
- ucrec* n = *v;
- if (n->channel)
+ CUList *ulist = v->first->GetUsers();
+ for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- CUList *ulist= n->channel->GetUsers();
-
- for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
+ if (this != i->second)
{
- if (this != i->second)
+ if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
{
- if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
- {
- already_sent[i->second->fd] = uniq_id;
- if (quit_munge)
- i->second->WriteFrom(this, *i->second->oper ? std::string(oper_quit) : std::string(textbuffer));
- else
- i->second->WriteFrom(this, std::string(textbuffer));
- }
+ already_sent[i->second->fd] = uniq_id;
+ if (quit_munge)
+ i->second->Write(*i->second->oper ? out2 : out1);
+ else
+ i->second->Write(out1);
}
}
}
return false;
/* Outer loop */
- for (std::vector<ucrec*>::const_iterator i = this->chans.begin(); i != this->chans.end(); i++)
+ for (UCListIter 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;
- }
+ /* 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 (i->first->HasUser(other))
+ return true;
}
return false;
}
-int userrec::CountChannels()
-{
- return ChannelCount;
-}
-
-void userrec::ModChannelCount(int n)
-{
- ChannelCount += n;
-}
-
bool userrec::ChangeName(const char* gecos)
{
if (!strcmp(gecos, this->fullname))
FOREACH_MOD(I_OnChangeName,OnChangeName(this,gecos));
}
strlcpy(this->fullname,gecos,MAXGECOS+1);
+
return true;
}
/* Fix by Om: userrec::dhost is 65 long, this was truncating some long hosts */
strlcpy(this->dhost,host,64);
+ this->InvalidateCache();
+
if (this->ServerInstance->Config->CycleHosts)
{
- for (std::vector<ucrec*>::const_iterator i = this->chans.begin(); i != this->chans.end(); i++)
+ for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
{
- if ((*i)->channel)
- {
- (*i)->channel->WriteAllExceptSender(this, false, 0, "JOIN %s", (*i)->channel->name);
- std::string n = this->ServerInstance->Modes->ModeString(this, (*i)->channel);
- if (n.length() > 0)
- (*i)->channel->WriteAllExceptSender(this, true, 0, "MODE %s +%s", (*i)->channel->name, n.c_str());
- }
+ i->first->WriteAllExceptSender(this, false, 0, "JOIN %s", i->first->name);
+ std::string n = this->ServerInstance->Modes->ModeString(this, i->first);
+ if (n.length() > 0)
+ i->first->WriteAllExceptSender(this, true, 0, "MODE %s +%s", i->first->name, n.c_str());
}
}
strlcpy(this->ident, newident, IDENTMAX+2);
+ this->InvalidateCache();
+
if (this->ServerInstance->Config->CycleHosts)
{
- for (std::vector<ucrec*>::const_iterator i = this->chans.begin(); i != this->chans.end(); i++)
+ for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
{
- if ((*i)->channel)
- {
- (*i)->channel->WriteAllExceptSender(this, false, 0, "JOIN %s", (*i)->channel->name);
- std::string n = this->ServerInstance->Modes->ModeString(this, (*i)->channel);
- if (n.length() > 0)
- (*i)->channel->WriteAllExceptSender(this, true, 0, "MODE %s +%s", (*i)->channel->name, n.c_str());
- }
+ i->first->WriteAllExceptSender(this, false, 0, "JOIN %s", i->first->name);
+ std::string n = this->ServerInstance->Modes->ModeString(this, i->first);
+ if (n.length() > 0)
+ i->first->WriteAllExceptSender(this, true, 0, "MODE %s +%s", i->first->name, n.c_str());
}
}
vsnprintf(textbuffer, MAXBUF, text, argsPtr);
va_end(argsPtr);
- snprintf(formatbuffer,MAXBUF,"NOTICE $* :%s",textbuffer);
+ snprintf(formatbuffer,MAXBUF,":%s NOTICE $* :%s", this->GetFullHost(), textbuffer);
+ std::string fmt = formatbuffer;
for (std::vector<userrec*>::const_iterator i = ServerInstance->local_users.begin(); i != ServerInstance->local_users.end(); i++)
{
- userrec* t = *i;
- t->WriteFrom(this, std::string(formatbuffer));
+ (*i)->Write(fmt);
}
}
try
{
std::string list;
- for (std::vector<ucrec*>::const_iterator i = this->chans.begin(); i != this->chans.end(); i++)
+ for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
{
- ucrec* rec = *i;
-
- if(rec->channel && rec->channel->name)
+ /* If the target is the same as the sender, let them see all their channels.
+ * If the channel is NOT private/secret OR the user shares a common channel
+ * If the user is an oper, and the <options:operspywhois> option is set.
+ */
+ if ((source == this) || (*source->oper && ServerInstance->Config->OperSpyWhois) || (((!i->first->modes[CM_PRIVATE]) && (!i->first->modes[CM_SECRET])) || (i->first->HasUser(source))))
{
- /* If the target is the same as the sender, let them see all their channels.
- * If the channel is NOT private/secret OR the user shares a common channel
- * If the user is an oper, and the <options:operspywhois> option is set.
- */
- if ((source == this) || (*source->oper && ServerInstance->Config->OperSpyWhois) || (((!rec->channel->modes[CM_PRIVATE]) && (!rec->channel->modes[CM_SECRET])) || (rec->channel->HasUser(source))))
- {
- list.append(rec->channel->GetPrefixChar(this)).append(rec->channel->name).append(" ");
- }
+ list.append(i->first->GetPrefixChar(this)).append(i->first->name).append(" ");
}
}
return list;
* then their ip will be taken as 'priority' anyway, so for example,
* <connect allow="127.0.0.1"> will match joe!bloggs@localhost
*/
-ConnectClass& userrec::GetClass()
+ConnectClass* userrec::GetClass()
{
for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
{
- if ((match(this->GetIPString(),i->host.c_str(),true)) || (match(this->host,i->host.c_str())))
- return *i;
+ if ((match(this->GetIPString(),i->GetHost().c_str(),true)) || (match(this->host,i->GetHost().c_str())))
+ return &(*i);
}
-
- return *(ServerInstance->Config->Classes.begin());
+ return NULL;
}
void userrec::PurgeEmptyChannels()
std::vector<chanrec*> to_delete;
// firstly decrement the count on each channel
- for (std::vector<ucrec*>::iterator f = this->chans.begin(); f != this->chans.end(); f++)
+ for (UCListIter f = this->chans.begin(); f != this->chans.end(); f++)
{
- ucrec* uc = *f;
- if (uc->channel)
+ f->first->RemoveAllPrefixes(this);
+ if (f->first->DelUser(this) == 0)
{
- uc->channel->RemoveAllPrefixes(this);
- if (uc->channel->DelUser(this) == 0)
+ /* No users left in here, mark it for deletion */
+ try
{
- /* No users left in here, mark it for deletion */
- try
- {
- to_delete.push_back(uc->channel);
- }
- catch (...)
- {
- ServerInstance->Log(DEBUG,"Exception in userrec::PurgeEmptyChannels to_delete.push_back()");
- }
- uc->channel = NULL;
+ to_delete.push_back(f->first);
+ }
+ catch (...)
+ {
+ ServerInstance->Log(DEBUG,"Exception in userrec::PurgeEmptyChannels to_delete.push_back()");
}
}
}
for (std::vector<chanrec*>::iterator n = to_delete.begin(); n != to_delete.end(); n++)
{
chanrec* thischan = *n;
- chan_hash::iterator i2 = ServerInstance->chanlist.find(thischan->name);
- if (i2 != ServerInstance->chanlist.end())
+ chan_hash::iterator i2 = ServerInstance->chanlist->find(thischan->name);
+ if (i2 != ServerInstance->chanlist->end())
{
FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(i2->second));
DELETE(i2->second);
- ServerInstance->chanlist.erase(i2);
+ ServerInstance->chanlist->erase(i2);
+ this->chans.erase(*n);
}
}
}
this->WriteServ("375 %s :%s message of the day", this->nick, ServerInstance->Config->ServerName);
- for (unsigned int i = 0; i < ServerInstance->Config->MOTD.size(); i++)
- this->WriteServ("372 %s :- %s",this->nick,ServerInstance->Config->MOTD[i].c_str());
+ for (file_cache::iterator i = ServerInstance->Config->MOTD.begin(); i != ServerInstance->Config->MOTD.end(); i++)
+ this->WriteServ("372 %s :- %s",this->nick,i->c_str());
this->WriteServ("376 %s :End of message of the day.", this->nick);
}
}
this->WriteServ("NOTICE %s :%s rules",this->nick,ServerInstance->Config->ServerName);
- for (unsigned int i = 0; i < ServerInstance->Config->RULES.size(); i++)
- this->WriteServ("NOTICE %s :%s",this->nick,ServerInstance->Config->RULES[i].c_str());
+ for (file_cache::iterator i = ServerInstance->Config->RULES.begin(); i != ServerInstance->Config->RULES.end(); i++)
+ this->WriteServ("NOTICE %s :%s",this->nick,i->c_str());
this->WriteServ("NOTICE %s :End of %s rules.",this->nick,ServerInstance->Config->ServerName);
}
void userrec::HandleEvent(EventType et, int errornum)
{
/* WARNING: May delete this user! */
+ int thisfd = this->GetFd();
+
try
{
switch (et)
break;
case EVENT_ERROR:
/** This should be safe, but dont DARE do anything after it -- Brain */
- userrec::QuitUser(ServerInstance, this, errornum ? strerror(errornum) : "EOF from client");
+ this->SetWriteError(errornum ? strerror(errornum) : "EOF from client");
break;
}
}
{
ServerInstance->Log(DEBUG,"Exception in userrec::HandleEvent intercepted");
}
+
+ /* If the user has raised an error whilst being processed, quit them now we're safe to */
+ if ((ServerInstance->SE->GetRef(thisfd) == this))
+ {
+ if (!WriteError.empty())
+ {
+ userrec::QuitUser(ServerInstance, this, GetWriteError());
+ }
+ }
}
+