#include "xline.h"
#include "cull_list.h"
-irc::whowas::whowas_users whowas;
static unsigned long already_sent[MAX_DESCRIPTORS] = {0};
-typedef std::map<irc::string,char*> opertype_t;
-typedef opertype_t operclass_t;
-
-opertype_t opertypes;
-operclass_t operclass;
-
/* XXX: Used for speeding up WriteCommon operations */
unsigned long uniq_id = 0;
bool InitTypes(ServerConfig* conf, const char* tag)
{
- for (opertype_t::iterator n = opertypes.begin(); n != opertypes.end(); n++)
+ for (opertype_t::iterator n = conf->opertypes.begin(); n != conf->opertypes.end(); n++)
{
if (n->second)
delete[] n->second;
}
- opertypes.clear();
+ conf->opertypes.clear();
return true;
}
bool InitClasses(ServerConfig* conf, const char* tag)
{
- for (operclass_t::iterator n = operclass.begin(); n != operclass.end(); n++)
+ for (operclass_t::iterator n = conf->operclass.begin(); n != conf->operclass.end(); n++)
{
if (n->second)
delete[] n->second;
}
- operclass.clear();
+ conf->operclass.clear();
return true;
}
char* TypeName = (char*)values[0];
char* Classes = (char*)values[1];
- opertypes[TypeName] = strdup(Classes);
+ conf->opertypes[TypeName] = strdup(Classes);
conf->GetInstance()->Log(DEBUG,"Read oper TYPE '%s' with classes '%s'",TypeName,Classes);
return true;
}
char* ClassName = (char*)values[0];
char* CommandList = (char*)values[1];
- operclass[ClassName] = strdup(CommandList);
+ conf->operclass[ClassName] = strdup(CommandList);
conf->GetInstance()->Log(DEBUG,"Read oper CLASS '%s' with commands '%s'",ClassName,CommandList);
return true;
}
{
bool adding = true, oldadding = false;
const char *c = sm;
- std::string output = "";
+ std::string output;
ServerInstance->Log(DEBUG,"Process notice masks");
int userrec::ReadData(void* buffer, size_t size)
{
- if (this->fd > -1)
+ if (IS_LOCAL(this))
{
return read(this->fd, buffer, size);
}
// are they even an oper at all?
if (*this->oper)
{
- opertype_t::iterator iter_opertype = opertypes.find(this->oper);
- if (iter_opertype != opertypes.end())
+ opertype_t::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper);
+ if (iter_opertype != ServerInstance->Config->opertypes.end())
{
char* Classes = strdup(iter_opertype->second);
char* myclass = strtok_r(Classes," ",&savept);
while (myclass)
{
- operclass_t::iterator iter_operclass = operclass.find(myclass);
- if (iter_operclass != operclass.end())
+ operclass_t::iterator iter_operclass = ServerInstance->Config->operclass.find(myclass);
+ if (iter_operclass != ServerInstance->Config->operclass.end())
{
char* CommandList = strdup(iter_operclass->second);
mycmd = strtok_r(CommandList," ",&savept2);
if ((sendq.length()) && (this->fd != FD_MAGIC_NUMBER))
{
const char* tb = this->sendq.c_str();
- int n_sent = write(this->fd,tb,this->sendq.length());
+ int n_sent = write(this->fd,tb,this->sendq.length());
if (n_sent == -1)
{
if (errno != EAGAIN)
if (*this->oper)
{
*this->oper = 0;
- this->modes[UM_OPERATOR] = 0;
+ this->modes[UM_OPERATOR] = 0;
for (std::vector<userrec*>::iterator a = ServerInstance->all_opers.begin(); a < ServerInstance->all_opers.end(); a++)
{
if (*a == this)
}
}
-void userrec::QuitUser(InspIRCd* Instance, userrec *user,const std::string &quitreason)
+void userrec::QuitUser(InspIRCd* Instance, userrec *user, const std::string &quitreason)
{
user_hash::iterator iter = Instance->clientlist.find(user->nick);
-
-/*
- * I'm pretty sure returning here is causing a desync when part of the net thinks a user is gone,
- * and another part doesn't. We want to broadcast the quit/kill before bailing so the net stays in sync.
- *
- * I can't imagine this blowing up, so I'm commenting it out. We still check
- * before playing with a bad iterator below in our if(). DISCUSS THIS BEFORE YOU DO ANYTHING. --w00t
- *
- * if (iter == clientlist.end())
- * return;
- */
std::string reason = quitreason;
if (reason.length() > MAXQUIT - 1)
}
/* every hour, run this function which removes all entries over 3 days */
- void MaintainWhoWas(time_t t)
+ void MaintainWhoWas(InspIRCd* ServerInstance, time_t t)
{
- for (whowas_users::iterator iter = ::whowas.begin(); iter != ::whowas.end(); iter++)
+ for (whowas_users::iterator iter = ServerInstance->whowas.begin(); iter != ServerInstance->whowas.end(); iter++)
{
whowas_set* n = (whowas_set*)iter->second;
if (n->size())
/* adds or updates an entry in the whowas list */
void userrec::AddToWhoWas()
{
- irc::whowas::whowas_users::iterator iter = whowas.find(this->nick);
+ irc::whowas::whowas_users::iterator iter = ServerInstance->whowas.find(this->nick);
- if (iter == whowas.end())
+ ServerInstance->Log(DEBUG,"Add to whowas lists");
+
+ 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);
- whowas[this->nick] = n;
+ ServerInstance->whowas[this->nick] = n;
}
else
{
irc::whowas::whowas_set* group = (irc::whowas::whowas_set*)iter->second;
+ ServerInstance->Log(DEBUG,"Using existing whowas group for %s",this->nick);
+
if (group->size() > 10)
{
+ ServerInstance->Log(DEBUG,"Trimming existing group to ten entries for %s",this->nick);
irc::whowas::WhoWasGroup *a = (irc::whowas::WhoWasGroup*)*(group->begin());
DELETE(a);
group->pop_front();
std::string tempnick = ConvToStr(socket) + "-unknown";
user_hash::iterator iter = Instance->clientlist.find(tempnick);
const char *ipaddr = insp_ntoa(ip);
- userrec* _new;
+ userrec* New;
int j = 0;
/*
Instance->Log(DEBUG,"AddClient: %d %d %s",socket,port,ipaddr);
- _new = new userrec(Instance);
- Instance->clientlist[tempnick] = _new;
- _new->fd = socket;
- strlcpy(_new->nick,tempnick.c_str(),NICKMAX-1);
+ New = new userrec(Instance);
+ Instance->clientlist[tempnick] = New;
+ New->fd = socket;
+ strlcpy(New->nick,tempnick.c_str(),NICKMAX-1);
- _new->server = Instance->FindServerNamePtr(Instance->Config->ServerName);
+ 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");
+ strcpy(New->ident, "unknown");
- _new->registered = REG_NONE;
- _new->signon = Instance->Time() + Instance->Config->dns_timeout;
- _new->lastping = 1;
+ New->registered = REG_NONE;
+ New->signon = Instance->Time() + Instance->Config->dns_timeout;
+ New->lastping = 1;
Instance->Log(DEBUG,"Setting socket addresses");
- _new->SetSockAddr(AF_FAMILY, ipaddr, port);
+ 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;
+ 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;
// set the registration timeout for this user
unsigned long class_regtimeout = 90;
{
class_regtimeout = (unsigned long)i->registration_timeout;
class_flood = i->flood;
- _new->pingmax = i->pingtime;
+ New->pingmax = i->pingtime;
class_threshold = i->threshold;
class_sqmax = i->sendqmax;
class_rqmax = i->recvqmax;
}
}
- _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->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;
- Instance->local_users.push_back(_new);
+ Instance->local_users.push_back(New);
- if (Instance->local_users.size() > Instance->Config->SoftLimit)
+ if ((Instance->local_users.size() > Instance->Config->SoftLimit) || (Instance->local_users.size() >= MAXCLIENTS))
{
- userrec::QuitUser(Instance, _new,"No more connections allowed");
- return;
- }
-
- if (Instance->local_users.size() >= MAXCLIENTS)
- {
- userrec::QuitUser(Instance, _new,"No more connections allowed");
+ userrec::QuitUser(Instance, New,"No more connections allowed");
return;
}
*/
if ((unsigned)socket >= MAX_DESCRIPTORS)
{
- userrec::QuitUser(Instance, _new,"Server is full");
+ userrec::QuitUser(Instance, New, "Server is full");
return;
}
- char* e = Instance->XLines->matches_exception(_new);
+
+ ELine* e = Instance->XLines->matches_exception(New);
if (!e)
{
- char* r = Instance->XLines->matches_zline(ipaddr);
+ ZLine* r = Instance->XLines->matches_zline(ipaddr);
if (r)
{
char reason[MAXBUF];
- snprintf(reason,MAXBUF,"Z-Lined: %s",r);
- userrec::QuitUser(Instance, _new,reason);
+ snprintf(reason,MAXBUF,"Z-Lined: %s",r->reason);
+ userrec::QuitUser(Instance, New, reason);
return;
}
}
if (socket > -1)
{
- if (!Instance->SE->AddFd(_new))
+ if (!Instance->SE->AddFd(New))
{
- userrec::QuitUser(Instance, _new, "Internal error handling connection");
+ userrec::QuitUser(Instance, New, "Internal error handling connection");
return;
}
}
- _new->WriteServ("NOTICE Auth :*** Looking up your hostname...");
+ New->WriteServ("NOTICE Auth :*** Looking up your hostname...");
}
long userrec::GlobalCloneCount()
{
- char u1[1024] = {0};
- char u2[1024] = {0};
+ char u1[128];
+ char u2[128];
long x = 0;
+
for (user_hash::const_iterator a = ServerInstance->clientlist.begin(); a != ServerInstance->clientlist.end(); a++)
{
/* We have to match ip's as strings - we don't know what protocol
* a remote user may be using
*/
- if (!strcasecmp(a->second->GetIPString(u1), this->GetIPString(u2)))
- x++;
+ if (strcmp(a->second->GetIPString(u1), this->GetIPString(u2)) == 0)
+ x++;
}
+
return x;
}
return;
}
- char* e = ServerInstance->XLines->matches_exception(this);
+ ELine* e = ServerInstance->XLines->matches_exception(this);
if (!e)
{
- char* r = ServerInstance->XLines->matches_gline(this);
+ GLine* r = ServerInstance->XLines->matches_gline(this);
if (r)
{
char reason[MAXBUF];
- snprintf(reason,MAXBUF,"G-Lined: %s",r);
+ snprintf(reason,MAXBUF,"G-Lined: %s",r->reason);
Goners->AddItem(this, reason);
return;
}
- r = ServerInstance->XLines->matches_kline(this);
+ KLine* n = ServerInstance->XLines->matches_kline(this);
- if (r)
+ if (n)
{
char reason[MAXBUF];
- snprintf(reason,MAXBUF,"K-Lined: %s",r);
+ snprintf(reason,MAXBUF,"K-Lined: %s",n->reason);
Goners->AddItem(this, reason);
return;
}