1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
17 #include "configreader.h"
22 #include "socketengine.h"
25 #include "cull_list.h"
27 static unsigned long already_sent[MAX_DESCRIPTORS] = {0};
29 /* XXX: Used for speeding up WriteCommon operations */
30 unsigned long uniq_id = 0;
32 bool InitTypes(ServerConfig* conf, const char* tag)
34 if (conf->opertypes.size())
36 conf->GetInstance()->Log(DEBUG,"Currently %d items to clear",conf->opertypes.size());
37 for (opertype_t::iterator n = conf->opertypes.begin(); n != conf->opertypes.end(); n++)
39 conf->GetInstance()->Log(DEBUG,"Clear item");
45 conf->opertypes.clear();
49 bool InitClasses(ServerConfig* conf, const char* tag)
51 if (conf->operclass.size())
53 for (operclass_t::iterator n = conf->operclass.begin(); n != conf->operclass.end(); n++)
60 conf->operclass.clear();
64 bool DoType(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
66 const char* TypeName = values[0].GetString();
67 const char* Classes = values[1].GetString();
69 conf->opertypes[TypeName] = strdup(Classes);
70 conf->GetInstance()->Log(DEBUG,"Read oper TYPE '%s' with classes '%s'",TypeName,Classes);
74 bool DoClass(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
76 const char* ClassName = values[0].GetString();
77 const char* CommandList = values[1].GetString();
79 conf->operclass[ClassName] = strdup(CommandList);
80 conf->GetInstance()->Log(DEBUG,"Read oper CLASS '%s' with commands '%s'",ClassName,CommandList);
84 bool DoneClassesAndTypes(ServerConfig* conf, const char* tag)
89 std::string userrec::ProcessNoticeMasks(const char *sm)
91 bool adding = true, oldadding = false;
95 ServerInstance->Log(DEBUG,"Process notice masks");
99 ServerInstance->Log(DEBUG,"Process notice mask %c",*c);
110 for (unsigned char d = 'A'; d <= 'z'; d++)
112 if (ServerInstance->SNO->IsEnabled(d))
114 if ((!IsNoticeMaskSet(d) && adding) || (IsNoticeMaskSet(d) && !adding))
116 if ((oldadding != adding) || (!output.length()))
117 output += (adding ? '+' : '-');
119 this->SetNoticeMask(d, adding);
128 if ((*c >= 'A') && (*c <= 'z') && (ServerInstance->SNO->IsEnabled(*c)))
130 if ((!IsNoticeMaskSet(*c) && adding) || (IsNoticeMaskSet(*c) && !adding))
132 if ((oldadding != adding) || (!output.length()))
133 output += (adding ? '+' : '-');
135 this->SetNoticeMask(*c, adding);
150 void userrec::StartDNSLookup()
152 ServerInstance->Log(DEBUG,"Commencing reverse lookup");
155 ServerInstance->Log(DEBUG,"Passing instance: %08x",this->ServerInstance);
156 res_reverse = new UserResolver(this->ServerInstance, this, this->GetIPString(), DNS_QUERY_REVERSE);
157 this->ServerInstance->AddResolver(res_reverse);
159 catch (ModuleException& e)
161 ServerInstance->Log(DEBUG,"Error in resolver: %s",e.GetReason());
165 UserResolver::UserResolver(InspIRCd* Instance, userrec* user, std::string to_resolve, QueryType qt) :
166 Resolver(Instance, to_resolve, qt), bound_user(user)
168 this->fwd = (qt == DNS_QUERY_A || qt == DNS_QUERY_AAAA);
169 this->bound_fd = user->GetFd();
172 void UserResolver::OnLookupComplete(const std::string &result)
174 if ((!this->fwd) && (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user))
176 ServerInstance->Log(DEBUG,"Commencing forward lookup");
177 this->bound_user->stored_host = result;
180 /* Check we didnt time out */
181 if (this->bound_user->registered != REG_ALL)
184 const char *ip = this->bound_user->GetIPString();
185 bound_user->res_forward = new UserResolver(this->ServerInstance, this->bound_user, result, (strstr(ip,"0::ffff:") == ip ? DNS_QUERY_A : DNS_QUERY_AAAA));
187 bound_user->res_forward = new UserResolver(this->ServerInstance, this->bound_user, result, DNS_QUERY_A);
189 this->ServerInstance->AddResolver(bound_user->res_forward);
192 catch (ModuleException& e)
194 ServerInstance->Log(DEBUG,"Error in resolver: %s",e.GetReason());
197 else if ((this->fwd) && (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user))
199 /* Both lookups completed */
200 std::string result2 = "0::ffff:";
201 result2.append(result);
202 if (this->bound_user->GetIPString() == result || this->bound_user->GetIPString() == result2)
204 std::string hostname = this->bound_user->stored_host;
205 if (hostname.length() < 65)
207 /* Check we didnt time out */
208 if (this->bound_user->registered != REG_ALL)
210 /* Hostnames starting with : are not a good thing (tm) */
211 if (*(hostname.c_str()) == ':')
212 hostname = "0" + hostname;
214 this->bound_user->WriteServ("NOTICE Auth :*** Found your hostname (%s)", hostname.c_str());
215 this->bound_user->dns_done = true;
216 strlcpy(this->bound_user->dhost, hostname.c_str(),64);
217 strlcpy(this->bound_user->host, hostname.c_str(),64);
222 this->bound_user->WriteServ("NOTICE Auth :*** Your hostname is longer than the maximum of 64 characters, using your IP address (%s) instead.", this->bound_user->GetIPString());
227 this->bound_user->WriteServ("NOTICE Auth :*** Your hostname does not match up with your IP address. Sorry, using your IP address (%s) instead.", this->bound_user->GetIPString());
232 void UserResolver::OnError(ResolverError e, const std::string &errormessage)
234 if (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user)
236 /* Error message here */
237 this->bound_user->WriteServ("NOTICE Auth :*** Could not resolve your hostname, using your IP address (%s) instead.", this->bound_user->GetIPString());
238 this->bound_user->dns_done = true;
243 bool userrec::IsNoticeMaskSet(unsigned char sm)
245 return (snomasks[sm-65]);
248 void userrec::SetNoticeMask(unsigned char sm, bool value)
250 snomasks[sm-65] = value;
253 const char* userrec::FormatNoticeMasks()
255 static char data[MAXBUF];
258 for (int n = 0; n < 64; n++)
261 data[offset++] = n+65;
270 bool userrec::IsModeSet(unsigned char m)
272 return (modes[m-65]);
275 void userrec::SetMode(unsigned char m, bool value)
280 const char* userrec::FormatModes()
282 static char data[MAXBUF];
284 for (int n = 0; n < 64; n++)
287 data[offset++] = n+65;
293 userrec::userrec(InspIRCd* Instance) : ServerInstance(Instance)
295 ServerInstance->Log(DEBUG,"userrec::userrec(): Instance: %08x",ServerInstance);
296 // the PROPER way to do it, AVOID bzero at *ALL* costs
297 *password = *nick = *ident = *host = *dhost = *fullname = *awaymsg = *oper = 0;
298 server = (char*)Instance->FindServerNamePtr(Instance->Config->ServerName);
299 reset_due = ServerInstance->Time();
300 age = ServerInstance->Time(true);
301 lines_in = lastping = signon = idle_lastmsg = nping = registered = 0;
302 ChannelCount = timeout = flood = bytes_in = bytes_out = cmds_in = cmds_out = 0;
303 exempt = haspassed = dns_done = false;
308 res_forward = res_reverse = NULL;
312 memset(modes,0,sizeof(modes));
313 memset(snomasks,0,sizeof(snomasks));
320 clonemap::iterator x = ServerInstance->local_clones.find(this->GetIPString());
321 if (x != ServerInstance->local_clones.end())
326 ServerInstance->local_clones.erase(x);
330 clonemap::iterator y = ServerInstance->global_clones.find(this->GetIPString());
331 if (y != ServerInstance->global_clones.end())
336 ServerInstance->global_clones.erase(y);
340 if (this->GetProtocolFamily() == AF_INET)
342 delete (sockaddr_in*)ip;
344 #ifdef SUPPORT_IP6LINKS
347 delete (sockaddr_in6*)ip;
353 char* userrec::MakeHost()
355 static char nhost[MAXBUF];
356 /* This is much faster than snprintf */
358 for(char* n = ident; *n; n++)
361 for(char* n = host; *n; n++)
367 char* userrec::MakeHostIP()
369 static char ihost[MAXBUF];
370 /* This is much faster than snprintf */
372 for(char* n = ident; *n; n++)
375 for(const char* n = this->GetIPString(); *n; n++)
381 void userrec::CloseSocket()
383 shutdown(this->fd,2);
387 char* userrec::GetFullHost()
389 static char result[MAXBUF];
391 for(char* n = nick; *n; n++)
394 for(char* n = ident; *n; n++)
397 for(char* n = dhost; *n; n++)
403 char* userrec::MakeWildHost()
405 static char nresult[MAXBUF];
407 *t++ = '*'; *t++ = '!';
408 *t++ = '*'; *t++ = '@';
409 for(char* n = dhost; *n; n++)
415 int userrec::ReadData(void* buffer, size_t size)
419 return read(this->fd, buffer, size);
426 char* userrec::GetFullRealHost()
428 static char fresult[MAXBUF];
430 for(char* n = nick; *n; n++)
433 for(char* n = ident; *n; n++)
436 for(char* n = host; *n; n++)
442 bool userrec::IsInvited(const irc::string &channel)
444 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
454 InvitedList* userrec::GetInviteList()
459 void userrec::InviteTo(const irc::string &channel)
461 invites.push_back(channel);
464 void userrec::RemoveInvite(const irc::string &channel)
466 ServerInstance->Log(DEBUG,"Removing invites");
467 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
477 bool userrec::HasPermission(const std::string &command)
484 * users on remote servers can completely bypass all permissions based checks.
485 * This prevents desyncs when one server has different type/class tags to another.
486 * That having been said, this does open things up to the possibility of source changes
487 * allowing remote kills, etc - but if they have access to the src, they most likely have
488 * access to the conf - so it's an end to a means either way.
493 // are they even an oper at all?
496 opertype_t::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper);
497 if (iter_opertype != ServerInstance->Config->opertypes.end())
499 char* Classes = strdup(iter_opertype->second);
500 char* myclass = strtok_r(Classes," ",&savept);
503 operclass_t::iterator iter_operclass = ServerInstance->Config->operclass.find(myclass);
504 if (iter_operclass != ServerInstance->Config->operclass.end())
506 char* CommandList = strdup(iter_operclass->second);
507 mycmd = strtok_r(CommandList," ",&savept2);
510 if ((!strcasecmp(mycmd,command.c_str())) || (*mycmd == '*'))
516 mycmd = strtok_r(NULL," ",&savept2);
520 myclass = strtok_r(NULL," ",&savept);
528 /** NOTE: We cannot pass a const reference to this method.
529 * The string is changed by the workings of the method,
530 * so that if we pass const ref, we end up copying it to
531 * something we can change anyway. Makes sense to just let
532 * the compiler do that copy for us.
534 bool userrec::AddBuffer(std::string a)
538 std::string::size_type i = a.rfind('\r');
540 while (i != std::string::npos)
549 if (recvq.length() > (unsigned)this->recvqmax)
551 this->SetWriteError("RecvQ exceeded");
552 ServerInstance->WriteOpers("*** User %s RecvQ of %d exceeds connect class maximum of %d",this->nick,recvq.length(),this->recvqmax);
561 ServerInstance->Log(DEBUG,"Exception in userrec::AddBuffer()");
566 bool userrec::BufferIsReady()
568 return (recvq.find('\n') != std::string::npos);
571 void userrec::ClearBuffer()
576 std::string userrec::GetBuffer()
583 /* Strip any leading \r or \n off the string.
584 * Usually there are only one or two of these,
585 * so its is computationally cheap to do.
587 while ((*recvq.begin() == '\r') || (*recvq.begin() == '\n'))
588 recvq.erase(recvq.begin());
590 for (std::string::iterator x = recvq.begin(); x != recvq.end(); x++)
592 /* Find the first complete line, return it as the
593 * result, and leave the recvq as whats left
597 std::string ret = std::string(recvq.begin(), x);
598 recvq.erase(recvq.begin(), x + 1);
607 ServerInstance->Log(DEBUG,"Exception in userrec::GetBuffer()");
612 void userrec::AddWriteBuf(const std::string &data)
614 if (*this->GetWriteError())
617 if (sendq.length() + data.length() > (unsigned)this->sendqmax)
620 * Fix by brain - Set the error text BEFORE calling writeopers, because
621 * if we dont it'll recursively call here over and over again trying
622 * to repeatedly add the text to the sendq!
624 this->SetWriteError("SendQ exceeded");
625 ServerInstance->WriteOpers("*** User %s SendQ of %d exceeds connect class maximum of %d",this->nick,sendq.length() + data.length(),this->sendqmax);
631 if (data.length() > 512)
632 sendq.append(data.substr(0,510)).append("\r\n");
638 this->SetWriteError("SendQ exceeded");
639 ServerInstance->WriteOpers("*** User %s SendQ got an exception",this->nick);
643 // send AS MUCH OF THE USERS SENDQ as we are able to (might not be all of it)
644 void userrec::FlushWriteBuf()
648 if ((this->fd == FD_MAGIC_NUMBER) || (*this->GetWriteError()))
652 if ((sendq.length()) && (this->fd != FD_MAGIC_NUMBER))
654 int old_sendq_length = sendq.length();
655 int n_sent = write(this->fd, this->sendq.data(), this->sendq.length());
660 /* The socket buffer is full. This isnt fatal,
663 ServerInstance->Log(DEBUG,"EAGAIN, want write");
664 this->ServerInstance->SE->WantWrite(this);
668 /* Fatal error, set write error and bail
670 this->SetWriteError(strerror(errno));
676 /* advance the queue */
678 this->sendq = this->sendq.substr(n_sent);
679 /* update the user's stats counters */
680 this->bytes_out += n_sent;
682 if (n_sent != old_sendq_length)
684 ServerInstance->Log(DEBUG,"Not all written, want write");
685 this->ServerInstance->SE->WantWrite(this);
693 ServerInstance->Log(DEBUG,"Exception in userrec::FlushWriteBuf()");
697 void userrec::SetWriteError(const std::string &error)
701 // don't try to set the error twice, its already set take the first string.
702 if (this->WriteError.empty())
704 ServerInstance->Log(DEBUG,"Setting error string for %s to '%s'",this->nick,error.c_str());
705 this->WriteError = error;
711 ServerInstance->Log(DEBUG,"Exception in userrec::SetWriteError()");
715 const char* userrec::GetWriteError()
717 return this->WriteError.c_str();
720 void userrec::Oper(const std::string &opertype)
724 this->modes[UM_OPERATOR] = 1;
725 this->WriteServ("MODE %s :+o", this->nick);
726 FOREACH_MOD(I_OnOper, OnOper(this, opertype));
727 ServerInstance->Log(DEFAULT,"OPER: %s!%s@%s opered as type: %s", this->nick, this->ident, this->host, opertype.c_str());
728 strlcpy(this->oper, opertype.c_str(), NICKMAX - 1);
729 ServerInstance->all_opers.push_back(this);
730 FOREACH_MOD(I_OnPostOper,OnPostOper(this, opertype));
735 ServerInstance->Log(DEBUG,"Exception in userrec::Oper()");
739 void userrec::UnOper()
746 this->modes[UM_OPERATOR] = 0;
747 for (std::vector<userrec*>::iterator a = ServerInstance->all_opers.begin(); a < ServerInstance->all_opers.end(); a++)
751 ServerInstance->Log(DEBUG,"Oper removed from optimization list");
752 ServerInstance->all_opers.erase(a);
761 ServerInstance->Log(DEBUG,"Exception in userrec::UnOper()");
765 void userrec::QuitUser(InspIRCd* Instance, userrec *user, const std::string &quitreason)
767 user_hash::iterator iter = Instance->clientlist.find(user->nick);
768 std::string reason = quitreason;
770 if (reason.length() > MAXQUIT - 1)
771 reason.resize(MAXQUIT - 1);
774 user->Write("ERROR :Closing link (%s@%s) [%s]",user->ident,user->host,reason.c_str());
776 if (user->registered == REG_ALL)
778 user->PurgeEmptyChannels();
779 user->WriteCommonExcept("QUIT :%s",reason.c_str());
780 FOREACH_MOD_I(Instance,I_OnUserQuit,OnUserQuit(user,reason));
783 FOREACH_MOD_I(Instance,I_OnUserDisconnect,OnUserDisconnect(user));
787 if (Instance->Config->GetIOHook(user->GetPort()))
791 Instance->Config->GetIOHook(user->GetPort())->OnRawSocketClose(user->fd);
793 catch (ModuleException& modexcept)
795 Instance->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason());
799 Instance->SE->DelFd(user);
804 * this must come before the ServerInstance->SNO->WriteToSnoMaskso that it doesnt try to fill their buffer with anything
805 * if they were an oper with +sn +qQ.
807 if (user->registered == REG_ALL)
810 Instance->SNO->WriteToSnoMask('q',"Client exiting: %s!%s@%s [%s]",user->nick,user->ident,user->host,reason.c_str());
812 Instance->SNO->WriteToSnoMask('Q',"Client exiting on server %s: %s!%s@%s [%s]",user->server,user->nick,user->ident,user->host,reason.c_str());
816 if (iter != Instance->clientlist.end())
818 Instance->Log(DEBUG,"deleting user hash value %lx",(unsigned long)user);
821 if (find(Instance->local_users.begin(),Instance->local_users.end(),user) != Instance->local_users.end())
822 Instance->local_users.erase(find(Instance->local_users.begin(),Instance->local_users.end(),user));
824 Instance->clientlist.erase(iter);
834 WhoWasGroup::WhoWasGroup(userrec* user) : host(NULL), dhost(NULL), ident(NULL), server(NULL), gecos(NULL), signon(user->signon)
836 this->host = strdup(user->host);
837 this->dhost = strdup(user->dhost);
838 this->ident = strdup(user->ident);
839 this->server = user->server;
840 this->gecos = strdup(user->fullname);
843 WhoWasGroup::~WhoWasGroup()
855 /* every hour, run this function which removes all entries older than Config->WhoWasMaxKeep */
856 void MaintainWhoWas(InspIRCd* ServerInstance, time_t t)
858 for (whowas_users::iterator iter = ServerInstance->whowas.begin(); iter != ServerInstance->whowas.end(); iter++)
860 whowas_set* n = (whowas_set*)iter->second;
863 while ((n->begin() != n->end()) && ((*n->begin())->signon < t - ServerInstance->Config->WhoWasMaxKeep))
865 WhoWasGroup *a = *(n->begin());
867 n->erase(n->begin());
872 /* on rehash, refactor maps according to new conf values */
873 void PruneWhoWas(InspIRCd* ServerInstance, time_t t)
876 int groupsize = ServerInstance->Config->WhoWasGroupSize;
877 int maxgroups = ServerInstance->Config->WhoWasMaxGroups;
878 int maxkeep = ServerInstance->Config->WhoWasMaxKeep;
880 int groupcount = ServerInstance->whowas.size();
881 /* iterate whowas_fifo oldest first */
882 whowas_users_fifo::iterator iter, safeiter;
883 for (iter = ServerInstance->whowas_fifo.begin(); iter != ServerInstance->whowas_fifo.end(); iter++)
885 /** prune all groups that has expired due to new maxkeep time and
886 * also any group number higher than new maxgroups. The oldest are
887 * removed first due to iteration over whowas_fifo
889 if (groupcount > maxgroups || iter->first < t - maxkeep)
891 whowas_set* n = (whowas_set*)ServerInstance->whowas.find(iter->second)->second;
894 while (n->begin() != n->end())
896 WhoWasGroup *a = *(n->begin());
898 n->erase(n->begin());
901 ServerInstance->whowas.erase(iter->second);
902 /* use a safe iter copy for erase and set the orig iter old valid ref by decrementing it */
905 ServerInstance->whowas_fifo.erase(safeiter);
908 /* also trim individual groupsizes in case groupsize should have been lowered */
909 whowas_set* n = (whowas_set*)ServerInstance->whowas.find(iter->second)->second;
912 int nickcount = n->size();
913 while (n->begin() != n->end() && nickcount > groupsize)
915 WhoWasGroup *a = *(n->begin());
917 n->erase(n->begin());
928 /* adds or updates an entry in the whowas list */
929 void userrec::AddToWhoWas()
931 /* if whowas disabled */
932 if (ServerInstance->Config->WhoWasGroupSize == 0 || ServerInstance->Config->WhoWasMaxGroups == 0)
937 irc::whowas::whowas_users::iterator iter = ServerInstance->whowas.find(this->nick);
939 ServerInstance->Log(DEBUG,"Add to whowas lists");
941 if (iter == ServerInstance->whowas.end())
943 ServerInstance->Log(DEBUG,"Adding new whowas set for %s",this->nick);
944 irc::whowas::whowas_set* n = new irc::whowas::whowas_set;
945 irc::whowas::WhoWasGroup *a = new irc::whowas::WhoWasGroup(this);
947 ServerInstance->whowas[this->nick] = n;
948 ServerInstance->whowas_fifo[ServerInstance->Time()] = this->nick;
949 if ((int)(ServerInstance->whowas.size()) > ServerInstance->Config->WhoWasMaxGroups)
951 ServerInstance->Log(DEBUG,"Maxgroups of %d reached deleting oldest group '%s'",ServerInstance->Config->WhoWasMaxGroups, ServerInstance->whowas_fifo.begin()->second.c_str());
952 ServerInstance->whowas.erase(ServerInstance->whowas_fifo.begin()->second);
953 ServerInstance->whowas_fifo.erase(ServerInstance->whowas_fifo.begin());
958 irc::whowas::whowas_set* group = (irc::whowas::whowas_set*)iter->second;
960 ServerInstance->Log(DEBUG,"Using existing whowas group for %s",this->nick);
962 if ((int)(group->size()) >= ServerInstance->Config->WhoWasGroupSize)
964 ServerInstance->Log(DEBUG,"Trimming existing group '%s' to %d entries",this->nick, ServerInstance->Config->WhoWasGroupSize);
965 irc::whowas::WhoWasGroup *a = (irc::whowas::WhoWasGroup*)*(group->begin());
970 irc::whowas::WhoWasGroup *a = new irc::whowas::WhoWasGroup(this);
975 /* add a client connection to the sockets list */
976 void userrec::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, insp_inaddr ip)
978 std::string tempnick = ConvToStr(socket) + "-unknown";
979 user_hash::iterator iter = Instance->clientlist.find(tempnick);
980 const char *ipaddr = insp_ntoa(ip);
986 * as these nicknames are 'RFC impossible', we can be sure nobody is going to be
987 * using one as a registered connection. As they are per fd, we can also safely assume
988 * that we wont have collisions. Therefore, if the nick exists in the list, its only
989 * used by a dead socket, erase the iterator so that the new client may reclaim it.
990 * this was probably the cause of 'server ignores me when i hammer it with reconnects'
991 * issue in earlier alphas/betas
993 if (iter != Instance->clientlist.end())
995 userrec* goner = iter->second;
997 Instance->clientlist.erase(iter);
1000 Instance->Log(DEBUG,"AddClient: %d %d %s",socket,port,ipaddr);
1002 New = new userrec(Instance);
1003 Instance->clientlist[tempnick] = New;
1005 strlcpy(New->nick,tempnick.c_str(),NICKMAX-1);
1007 New->server = Instance->FindServerNamePtr(Instance->Config->ServerName);
1008 /* We don't need range checking here, we KNOW 'unknown\0' will fit into the ident field. */
1009 strcpy(New->ident, "unknown");
1011 New->registered = REG_NONE;
1012 New->signon = Instance->Time() + Instance->Config->dns_timeout;
1015 New->SetSockAddr(AF_FAMILY, ipaddr, port);
1017 /* Smarter than your average bear^H^H^H^Hset of strlcpys. */
1018 for (const char* temp = New->GetIPString(); *temp && j < 64; temp++, j++)
1019 New->dhost[j] = New->host[j] = *temp;
1020 New->dhost[j] = New->host[j] = 0;
1022 Instance->AddLocalClone(New);
1023 Instance->AddGlobalClone(New);
1025 // set the registration timeout for this user
1026 unsigned long class_regtimeout = 90;
1027 int class_flood = 0;
1028 long class_threshold = 5;
1029 long class_sqmax = 262144; // 256kb
1030 long class_rqmax = 4096; // 4k
1032 for (ClassVector::iterator i = Instance->Config->Classes.begin(); i != Instance->Config->Classes.end(); i++)
1034 if ((i->type == CC_ALLOW) && (match(ipaddr,i->host.c_str(),true)))
1036 class_regtimeout = (unsigned long)i->registration_timeout;
1037 class_flood = i->flood;
1038 New->pingmax = i->pingtime;
1039 class_threshold = i->threshold;
1040 class_sqmax = i->sendqmax;
1041 class_rqmax = i->recvqmax;
1046 New->nping = Instance->Time() + New->pingmax + Instance->Config->dns_timeout;
1047 New->timeout = Instance->Time() + class_regtimeout;
1048 New->flood = class_flood;
1049 New->threshold = class_threshold;
1050 New->sendqmax = class_sqmax;
1051 New->recvqmax = class_rqmax;
1053 Instance->local_users.push_back(New);
1055 if ((Instance->local_users.size() > Instance->Config->SoftLimit) || (Instance->local_users.size() >= MAXCLIENTS))
1057 Instance->WriteOpers("*** Warning: softlimit value has been reached: %d clients", Instance->Config->SoftLimit);
1058 userrec::QuitUser(Instance, New,"No more connections allowed");
1064 * this is done as a safety check to keep the file descriptors within range of fd_ref_table.
1065 * its a pretty big but for the moment valid assumption:
1066 * file descriptors are handed out starting at 0, and are recycled as theyre freed.
1067 * therefore if there is ever an fd over 65535, 65536 clients must be connected to the
1068 * irc server at once (or the irc server otherwise initiating this many connections, files etc)
1069 * which for the time being is a physical impossibility (even the largest networks dont have more
1070 * than about 10,000 users on ONE server!)
1072 if ((unsigned int)socket >= MAX_DESCRIPTORS)
1074 userrec::QuitUser(Instance, New, "Server is full");
1078 New->exempt = (Instance->XLines->matches_exception(New) != NULL);
1081 ZLine* r = Instance->XLines->matches_zline(ipaddr);
1084 char reason[MAXBUF];
1085 snprintf(reason,MAXBUF,"Z-Lined: %s",r->reason);
1086 userrec::QuitUser(Instance, New, reason);
1093 if (!Instance->SE->AddFd(New))
1095 userrec::QuitUser(Instance, New, "Internal error handling connection");
1100 /* NOTE: even if dns lookups are *off*, we still need to display this.
1101 * BOPM and other stuff requires it.
1103 New->WriteServ("NOTICE Auth :*** Looking up your hostname...");
1106 long userrec::GlobalCloneCount()
1108 clonemap::iterator x = ServerInstance->global_clones.find(this->GetIPString());
1109 if (x != ServerInstance->global_clones.end())
1115 long userrec::LocalCloneCount()
1117 clonemap::iterator x = ServerInstance->local_clones.find(this->GetIPString());
1118 if (x != ServerInstance->local_clones.end())
1124 void userrec::FullConnect(CullList* Goners)
1126 ServerInstance->stats->statsConnects++;
1127 this->idle_lastmsg = ServerInstance->Time();
1129 ConnectClass a = this->GetClass();
1131 if (a.type == CC_DENY)
1133 Goners->AddItem(this,"Unauthorised connection");
1137 if ((*(a.pass.c_str())) && (!this->haspassed))
1139 Goners->AddItem(this,"Invalid password");
1143 if (this->LocalCloneCount() > a.maxlocal)
1145 Goners->AddItem(this, "No more connections allowed from your host via this connect class (local)");
1146 ServerInstance->WriteOpers("*** WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a.maxlocal, this->GetIPString());
1149 else if (this->GlobalCloneCount() > a.maxglobal)
1151 Goners->AddItem(this, "No more connections allowed from your host via this connect class (global)");
1152 ServerInstance->WriteOpers("*** WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s",a.maxglobal, this->GetIPString());
1158 GLine* r = ServerInstance->XLines->matches_gline(this);
1162 char reason[MAXBUF];
1163 snprintf(reason,MAXBUF,"G-Lined: %s",r->reason);
1164 Goners->AddItem(this, reason);
1168 KLine* n = ServerInstance->XLines->matches_kline(this);
1172 char reason[MAXBUF];
1173 snprintf(reason,MAXBUF,"K-Lined: %s",n->reason);
1174 Goners->AddItem(this, reason);
1180 this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network);
1181 this->WriteServ("001 %s :Welcome to the %s IRC Network %s!%s@%s",this->nick, ServerInstance->Config->Network, this->nick, this->ident, this->host);
1182 this->WriteServ("002 %s :Your host is %s, running version %s",this->nick,ServerInstance->Config->ServerName,VERSION);
1183 this->WriteServ("003 %s :This server was created %s %s", this->nick, __TIME__, __DATE__);
1184 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());
1186 ServerInstance->Config->Send005(this);
1191 * fix 3 by brain, move registered = 7 below these so that spurious modes and host
1192 * changes dont go out onto the network and produce 'fake direction'.
1194 FOREACH_MOD(I_OnUserConnect,OnUserConnect(this));
1196 this->registered = REG_ALL;
1198 FOREACH_MOD(I_OnPostConnect,OnPostConnect(this));
1200 ServerInstance->SNO->WriteToSnoMask('c',"Client connecting on port %d: %s!%s@%s [%s]", this->GetPort(), this->nick, this->ident, this->host, this->GetIPString());
1203 /** userrec::UpdateNick()
1204 * re-allocates a nick in the user_hash after they change nicknames,
1205 * returns a pointer to the new user as it may have moved
1207 userrec* userrec::UpdateNickHash(const char* New)
1211 //user_hash::iterator newnick;
1212 user_hash::iterator oldnick = ServerInstance->clientlist.find(this->nick);
1214 if (!strcasecmp(this->nick,New))
1215 return oldnick->second;
1217 if (oldnick == ServerInstance->clientlist.end())
1218 return NULL; /* doesnt exist */
1220 userrec* olduser = oldnick->second;
1221 ServerInstance->clientlist[New] = olduser;
1222 ServerInstance->clientlist.erase(oldnick);
1223 return ServerInstance->clientlist[New];
1228 ServerInstance->Log(DEBUG,"Exception in userrec::UpdateNickHash()");
1233 bool userrec::ForceNickChange(const char* newnick)
1239 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(this, newnick));
1243 ServerInstance->stats->statsCollisions++;
1247 if (ServerInstance->XLines->matches_qline(newnick))
1249 ServerInstance->stats->statsCollisions++;
1253 if (this->registered == REG_ALL)
1255 const char* pars[1];
1257 std::string cmd = "NICK";
1258 return (ServerInstance->Parser->CallHandler(cmd, pars, 1, this) == CMD_SUCCESS);
1265 ServerInstance->Log(DEBUG,"Exception in userrec::ForceNickChange()");
1270 void userrec::SetSockAddr(int protocol_family, const char* ip, int port)
1272 switch (protocol_family)
1274 #ifdef SUPPORT_IP6LINKS
1277 ServerInstance->Log(DEBUG,"Set inet6 protocol address");
1278 sockaddr_in6* sin = new sockaddr_in6;
1279 sin->sin6_family = AF_INET6;
1280 sin->sin6_port = port;
1281 inet_pton(AF_INET6, ip, &sin->sin6_addr);
1282 this->ip = (sockaddr*)sin;
1288 ServerInstance->Log(DEBUG,"Set inet4 protocol address");
1289 sockaddr_in* sin = new sockaddr_in;
1290 sin->sin_family = AF_INET;
1291 sin->sin_port = port;
1292 inet_pton(AF_INET, ip, &sin->sin_addr);
1293 this->ip = (sockaddr*)sin;
1297 ServerInstance->Log(DEBUG,"Ut oh, I dont know protocol %d to be set on '%s'!", protocol_family, this->nick);
1302 int userrec::GetPort()
1304 if (this->ip == NULL)
1307 switch (this->GetProtocolFamily())
1309 #ifdef SUPPORT_IP6LINKS
1312 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1313 return sin->sin6_port;
1319 sockaddr_in* sin = (sockaddr_in*)this->ip;
1320 return sin->sin_port;
1329 int userrec::GetProtocolFamily()
1331 if (this->ip == NULL)
1334 sockaddr_in* sin = (sockaddr_in*)this->ip;
1335 return sin->sin_family;
1338 const char* userrec::GetIPString()
1340 static char buf[1024];
1342 if (this->ip == NULL)
1345 switch (this->GetProtocolFamily())
1347 #ifdef SUPPORT_IP6LINKS
1350 static char temp[1024];
1352 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1353 inet_ntop(sin->sin6_family, &sin->sin6_addr, buf, sizeof(buf));
1354 /* IP addresses starting with a : on irc are a Bad Thing (tm) */
1357 strlcpy(&temp[1], buf, sizeof(temp) - 1);
1367 sockaddr_in* sin = (sockaddr_in*)this->ip;
1368 inet_ntop(sin->sin_family, &sin->sin_addr, buf, sizeof(buf));
1378 const char* userrec::GetIPString(char* buf)
1380 if (this->ip == NULL)
1386 switch (this->GetProtocolFamily())
1388 #ifdef SUPPORT_IP6LINKS
1391 static char temp[1024];
1393 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1394 inet_ntop(sin->sin6_family, &sin->sin6_addr, buf, sizeof(buf));
1395 /* IP addresses starting with a : on irc are a Bad Thing (tm) */
1398 strlcpy(&temp[1], buf, sizeof(temp) - 1);
1400 strlcpy(buf, temp, sizeof(temp));
1408 sockaddr_in* sin = (sockaddr_in*)this->ip;
1409 inet_ntop(sin->sin_family, &sin->sin_addr, buf, sizeof(buf));
1420 /** NOTE: We cannot pass a const reference to this method.
1421 * The string is changed by the workings of the method,
1422 * so that if we pass const ref, we end up copying it to
1423 * something we can change anyway. Makes sense to just let
1424 * the compiler do that copy for us.
1426 void userrec::Write(std::string text)
1428 if ((this->fd < 0) || (this->fd > MAX_DESCRIPTORS))
1433 text.append("\r\n");
1437 ServerInstance->Log(DEBUG,"Exception in userrec::Write() std::string::append");
1441 if (ServerInstance->Config->GetIOHook(this->GetPort()))
1445 ServerInstance->Config->GetIOHook(this->GetPort())->OnRawSocketWrite(this->fd, text.data(), text.length());
1447 catch (ModuleException& modexcept)
1449 ServerInstance->Log(DEBUG,"Module exception caught: %s",modexcept.GetReason());
1454 this->AddWriteBuf(text);
1456 ServerInstance->stats->statsSent += text.length();
1457 this->ServerInstance->SE->WantWrite(this);
1462 void userrec::Write(const char *text, ...)
1465 char textbuffer[MAXBUF];
1467 va_start(argsPtr, text);
1468 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1471 this->Write(std::string(textbuffer));
1474 void userrec::WriteServ(const std::string& text)
1476 char textbuffer[MAXBUF];
1478 snprintf(textbuffer,MAXBUF,":%s %s",ServerInstance->Config->ServerName,text.c_str());
1479 this->Write(std::string(textbuffer));
1483 * Same as Write(), except `text' is prefixed with `:server.name '.
1485 void userrec::WriteServ(const char* text, ...)
1488 char textbuffer[MAXBUF];
1490 va_start(argsPtr, text);
1491 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1494 this->WriteServ(std::string(textbuffer));
1498 void userrec::WriteFrom(userrec *user, const std::string &text)
1502 snprintf(tb,MAXBUF,":%s %s",user->GetFullHost(),text.c_str());
1504 this->Write(std::string(tb));
1508 /* write text from an originating user to originating user */
1510 void userrec::WriteFrom(userrec *user, const char* text, ...)
1513 char textbuffer[MAXBUF];
1515 va_start(argsPtr, text);
1516 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1519 this->WriteFrom(user, std::string(textbuffer));
1523 /* write text to an destination user from a source user (e.g. user privmsg) */
1525 void userrec::WriteTo(userrec *dest, const char *data, ...)
1527 char textbuffer[MAXBUF];
1530 va_start(argsPtr, data);
1531 vsnprintf(textbuffer, MAXBUF, data, argsPtr);
1534 this->WriteTo(dest, std::string(textbuffer));
1537 void userrec::WriteTo(userrec *dest, const std::string &data)
1539 dest->WriteFrom(this, data);
1543 void userrec::WriteCommon(const char* text, ...)
1545 char textbuffer[MAXBUF];
1548 if (this->registered != REG_ALL)
1551 va_start(argsPtr, text);
1552 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1555 this->WriteCommon(std::string(textbuffer));
1558 void userrec::WriteCommon(const std::string &text)
1562 bool sent_to_at_least_one = false;
1564 if (this->registered != REG_ALL)
1569 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1571 CUList* ulist = v->first->GetUsers();
1572 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1574 if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
1576 already_sent[i->second->fd] = uniq_id;
1577 i->second->WriteFrom(this, std::string(text));
1578 sent_to_at_least_one = true;
1584 * if the user was not in any channels, no users will receive the text. Make sure the user
1585 * receives their OWN message for WriteCommon
1587 if (!sent_to_at_least_one)
1589 this->WriteFrom(this,std::string(text));
1595 ServerInstance->Log(DEBUG,"Exception in userrec::WriteCommon()");
1600 /* write a formatted string to all users who share at least one common
1601 * channel, NOT including the source user e.g. for use in QUIT
1604 void userrec::WriteCommonExcept(const char* text, ...)
1606 char textbuffer[MAXBUF];
1609 va_start(argsPtr, text);
1610 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1613 this->WriteCommonExcept(std::string(textbuffer));
1616 void userrec::WriteCommonExcept(const std::string &text)
1618 bool quit_munge = false;
1619 char oper_quit[MAXBUF];
1620 char textbuffer[MAXBUF];
1622 strlcpy(textbuffer, text.c_str(), MAXBUF);
1624 if (this->registered != REG_ALL)
1629 /* TODO: We need some form of WriteCommonExcept that will send two lines, one line to
1630 * opers and the other line to non-opers, then all this hidebans and hidesplits gunk
1633 if (ServerInstance->Config->HideSplits)
1635 char* check = textbuffer + 6;
1637 if (!strncasecmp(textbuffer, "QUIT :",6))
1639 std::stringstream split(check);
1640 std::string server_one;
1641 std::string server_two;
1643 split >> server_one;
1644 split >> server_two;
1646 if ((ServerInstance->FindServerName(server_one)) && (ServerInstance->FindServerName(server_two)))
1648 strlcpy(oper_quit,textbuffer,MAXQUIT);
1649 strlcpy(check,"*.net *.split",MAXQUIT);
1655 if ((ServerInstance->Config->HideBans) && (!quit_munge))
1657 if ((!strncasecmp(textbuffer, "QUIT :G-Lined:",14)) || (!strncasecmp(textbuffer, "QUIT :K-Lined:",14))
1658 || (!strncasecmp(textbuffer, "QUIT :Q-Lined:",14)) || (!strncasecmp(textbuffer, "QUIT :Z-Lined:",14)))
1660 char* check = textbuffer + 13;
1661 strlcpy(oper_quit,textbuffer,MAXQUIT);
1662 *check = 0; // We don't need to strlcpy, we just chop it from the :
1667 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1669 CUList *ulist = v->first->GetUsers();
1670 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1672 if (this != i->second)
1674 if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
1676 already_sent[i->second->fd] = uniq_id;
1678 i->second->WriteFrom(this, *i->second->oper ? std::string(oper_quit) : std::string(textbuffer));
1680 i->second->WriteFrom(this, std::string(textbuffer));
1688 void userrec::WriteWallOps(const std::string &text)
1690 /* Does nothing if theyre not opered */
1691 if ((!*this->oper) && (IS_LOCAL(this)))
1694 std::string wallop = "WALLOPS :";
1698 wallop.append(text);
1702 ServerInstance->Log(DEBUG,"Exception in userrec::Write() std::string::append");
1706 for (std::vector<userrec*>::const_iterator i = ServerInstance->local_users.begin(); i != ServerInstance->local_users.end(); i++)
1709 if ((IS_LOCAL(t)) && (t->modes[UM_WALLOPS]))
1710 this->WriteTo(t,wallop);
1714 void userrec::WriteWallOps(const char* text, ...)
1716 char textbuffer[MAXBUF];
1719 va_start(argsPtr, text);
1720 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1723 this->WriteWallOps(std::string(textbuffer));
1726 /* return 0 or 1 depending if users u and u2 share one or more common channels
1727 * (used by QUIT, NICK etc which arent channel specific notices)
1729 * The old algorithm in 1.0 for this was relatively inefficient, iterating over
1730 * the first users channels then the second users channels within the outer loop,
1731 * therefore it was a maximum of x*y iterations (upon returning 0 and checking
1732 * all possible iterations). However this new function instead checks against the
1733 * channel's userlist in the inner loop which is a std::map<userrec*,userrec*>
1734 * and saves us time as we already know what pointer value we are after.
1735 * Don't quote me on the maths as i am not a mathematician or computer scientist,
1736 * but i believe this algorithm is now x+(log y) maximum iterations instead.
1738 bool userrec::SharesChannelWith(userrec *other)
1740 if ((!other) || (this->registered != REG_ALL) || (other->registered != REG_ALL))
1744 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1746 /* Eliminate the inner loop (which used to be ~equal in size to the outer loop)
1747 * by replacing it with a map::find which *should* be more efficient
1749 if (i->first->HasUser(other))
1755 bool userrec::ChangeName(const char* gecos)
1757 if (!strcmp(gecos, this->fullname))
1763 FOREACH_RESULT(I_OnChangeLocalUserGECOS,OnChangeLocalUserGECOS(this,gecos));
1766 FOREACH_MOD(I_OnChangeName,OnChangeName(this,gecos));
1768 strlcpy(this->fullname,gecos,MAXGECOS+1);
1772 bool userrec::ChangeDisplayedHost(const char* host)
1774 if (!strcmp(host, this->dhost))
1780 FOREACH_RESULT(I_OnChangeLocalUserHost,OnChangeLocalUserHost(this,host));
1783 FOREACH_MOD(I_OnChangeHost,OnChangeHost(this,host));
1785 if (this->ServerInstance->Config->CycleHosts)
1786 this->WriteCommonExcept("QUIT :Changing hosts");
1788 /* Fix by Om: userrec::dhost is 65 long, this was truncating some long hosts */
1789 strlcpy(this->dhost,host,64);
1791 if (this->ServerInstance->Config->CycleHosts)
1793 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1795 i->first->WriteAllExceptSender(this, false, 0, "JOIN %s", i->first->name);
1796 std::string n = this->ServerInstance->Modes->ModeString(this, i->first);
1798 i->first->WriteAllExceptSender(this, true, 0, "MODE %s +%s", i->first->name, n.c_str());
1803 this->WriteServ("396 %s %s :is now your hidden host",this->nick,this->dhost);
1808 bool userrec::ChangeIdent(const char* newident)
1810 if (!strcmp(newident, this->ident))
1813 if (this->ServerInstance->Config->CycleHosts)
1814 this->WriteCommonExcept("%s","QUIT :Changing ident");
1816 strlcpy(this->ident, newident, IDENTMAX+2);
1818 if (this->ServerInstance->Config->CycleHosts)
1820 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1822 i->first->WriteAllExceptSender(this, false, 0, "JOIN %s", i->first->name);
1823 std::string n = this->ServerInstance->Modes->ModeString(this, i->first);
1825 i->first->WriteAllExceptSender(this, true, 0, "MODE %s +%s", i->first->name, n.c_str());
1832 void userrec::NoticeAll(char* text, ...)
1834 char textbuffer[MAXBUF];
1835 char formatbuffer[MAXBUF];
1838 va_start(argsPtr, text);
1839 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1842 snprintf(formatbuffer,MAXBUF,"NOTICE $* :%s",textbuffer);
1844 for (std::vector<userrec*>::const_iterator i = ServerInstance->local_users.begin(); i != ServerInstance->local_users.end(); i++)
1847 t->WriteFrom(this, std::string(formatbuffer));
1852 std::string userrec::ChannelList(userrec* source)
1857 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1859 /* If the target is the same as the sender, let them see all their channels.
1860 * If the channel is NOT private/secret OR the user shares a common channel
1861 * If the user is an oper, and the <options:operspywhois> option is set.
1863 if ((source == this) || (*source->oper && ServerInstance->Config->OperSpyWhois) || (((!i->first->modes[CM_PRIVATE]) && (!i->first->modes[CM_SECRET])) || (i->first->HasUser(source))))
1865 list.append(i->first->GetPrefixChar(this)).append(i->first->name).append(" ");
1872 ServerInstance->Log(DEBUG,"Exception in userrec::ChannelList()");
1877 void userrec::SplitChanList(userrec* dest, const std::string &cl)
1880 std::ostringstream prefix;
1881 std::string::size_type start, pos, length;
1885 prefix << this->nick << " " << dest->nick << " :";
1886 line = prefix.str();
1887 int namelen = strlen(ServerInstance->Config->ServerName) + 6;
1889 for (start = 0; (pos = cl.find(' ', start)) != std::string::npos; start = pos+1)
1891 length = (pos == std::string::npos) ? cl.length() : pos;
1893 if (line.length() + namelen + length - start > 510)
1895 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1896 line = prefix.str();
1899 if(pos == std::string::npos)
1901 line.append(cl.substr(start, length - start));
1906 line.append(cl.substr(start, length - start + 1));
1912 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1918 ServerInstance->Log(DEBUG,"Exception in userrec::SplitChanList()");
1923 /* looks up a users password for their connection class (<ALLOW>/<DENY> tags)
1924 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1925 * then their ip will be taken as 'priority' anyway, so for example,
1926 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1928 ConnectClass& userrec::GetClass()
1930 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1932 if ((match(this->GetIPString(),i->host.c_str(),true)) || (match(this->host,i->host.c_str())))
1936 return *(ServerInstance->Config->Classes.begin());
1939 void userrec::PurgeEmptyChannels()
1941 std::vector<chanrec*> to_delete;
1943 // firstly decrement the count on each channel
1944 for (UCListIter f = this->chans.begin(); f != this->chans.end(); f++)
1946 f->first->RemoveAllPrefixes(this);
1947 if (f->first->DelUser(this) == 0)
1949 /* No users left in here, mark it for deletion */
1952 to_delete.push_back(f->first);
1956 ServerInstance->Log(DEBUG,"Exception in userrec::PurgeEmptyChannels to_delete.push_back()");
1961 for (std::vector<chanrec*>::iterator n = to_delete.begin(); n != to_delete.end(); n++)
1963 chanrec* thischan = *n;
1964 chan_hash::iterator i2 = ServerInstance->chanlist.find(thischan->name);
1965 if (i2 != ServerInstance->chanlist.end())
1967 FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(i2->second));
1969 ServerInstance->chanlist.erase(i2);
1976 void userrec::ShowMOTD()
1978 if (!ServerInstance->Config->MOTD.size())
1980 this->WriteServ("422 %s :Message of the day file is missing.",this->nick);
1983 this->WriteServ("375 %s :%s message of the day", this->nick, ServerInstance->Config->ServerName);
1985 for (file_cache::iterator i = ServerInstance->Config->MOTD.begin(); i != ServerInstance->Config->MOTD.end(); i++)
1986 this->WriteServ("372 %s :- %s",this->nick,i->c_str());
1988 this->WriteServ("376 %s :End of message of the day.", this->nick);
1991 void userrec::ShowRULES()
1993 if (!ServerInstance->Config->RULES.size())
1995 this->WriteServ("NOTICE %s :Rules file is missing.",this->nick);
1998 this->WriteServ("NOTICE %s :%s rules",this->nick,ServerInstance->Config->ServerName);
2000 for (file_cache::iterator i = ServerInstance->Config->RULES.begin(); i != ServerInstance->Config->RULES.end(); i++)
2001 this->WriteServ("NOTICE %s :%s",this->nick,i->c_str());
2003 this->WriteServ("NOTICE %s :End of %s rules.",this->nick,ServerInstance->Config->ServerName);
2006 void userrec::HandleEvent(EventType et, int errornum)
2008 /* WARNING: May delete this user! */
2014 ServerInstance->ProcessUser(this);
2018 this->FlushWriteBuf();
2021 /** This should be safe, but dont DARE do anything after it -- Brain */
2022 this->SetWriteError(errornum ? strerror(errornum) : "EOF from client");
2028 ServerInstance->Log(DEBUG,"Exception in userrec::HandleEvent intercepted");
2031 /* If the user has raised an error whilst being processed, quit them now we're safe to */
2032 if (!WriteError.empty())
2034 userrec::QuitUser(ServerInstance, this, GetWriteError());