* | 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());
}
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;
- }
}
userrec::~userrec()
{
- for (std::vector<ucrec*>::iterator n = chans.begin(); n != chans.end(); n++)
- {
- ucrec* x = (ucrec*)*n;
- delete x;
- }
-
if (ip)
{
clonemap::iterator x = ServerInstance->local_clones.find(this->GetIPString());
return fresult;
}
-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;
reason.resize(MAXQUIT - 1);
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());
}
}
}
Instance->Log(DEBUG,"AddClient: %d %d %s",socket,port,ipaddr);
-
+
New = new userrec(Instance);
Instance->clientlist[tempnick] = New;
New->fd = socket;
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);
long class_sqmax = 262144; // 256kb
long class_rqmax = 4096; // 4k
- Instance->Log(DEBUG,"Class stuff set.");
-
for (ClassVector::iterator i = Instance->Config->Classes.begin(); i != Instance->Config->Classes.end(); i++)
{
if ((i->type == CC_ALLOW) && (match(ipaddr,i->host.c_str(),true)))
}
}
- 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->sendqmax = class_sqmax;
New->recvqmax = class_rqmax;
- 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...");
}
return;
}
- ELine* e = ServerInstance->XLines->matches_exception(this);
-
- if (!e)
+ if (!this->exempt)
{
GLine* r = ServerInstance->XLines->matches_gline(this);
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();
/*
}
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
uniq_id++;
- 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->WriteFrom(this, std::string(text));
+ sent_to_at_least_one = true;
}
}
}
}
}
- 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 (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->WriteFrom(this, *i->second->oper ? std::string(oper_quit) : std::string(textbuffer));
+ else
+ i->second->WriteFrom(this, std::string(textbuffer));
}
}
}
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))
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());
}
}
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());
}
}
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;
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()");
}
}
}
}
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);
}
{
case EVENT_READ:
ServerInstance->ProcessUser(this);
+
break;
case EVENT_WRITE:
this->FlushWriteBuf();
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 (!WriteError.empty())
+ {
+ userrec::QuitUser(ServerInstance, this, GetWriteError());
+ }
}
+