1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 #include "configreader.h"
19 #include "socketengine.h"
22 #include "cull_list.h"
24 static unsigned long already_sent[MAX_DESCRIPTORS] = {0};
26 /* XXX: Used for speeding up WriteCommon operations */
27 unsigned long uniq_id = 0;
29 bool InitTypes(ServerConfig* conf, const char* tag)
31 if (conf->opertypes.size())
33 conf->GetInstance()->Log(DEBUG,"Currently %d items to clear",conf->opertypes.size());
34 for (opertype_t::iterator n = conf->opertypes.begin(); n != conf->opertypes.end(); n++)
36 conf->GetInstance()->Log(DEBUG,"Clear item");
42 conf->opertypes.clear();
46 bool InitClasses(ServerConfig* conf, const char* tag)
48 if (conf->operclass.size())
50 for (operclass_t::iterator n = conf->operclass.begin(); n != conf->operclass.end(); n++)
57 conf->operclass.clear();
61 bool DoType(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
63 const char* TypeName = values[0].GetString();
64 const char* Classes = values[1].GetString();
66 conf->opertypes[TypeName] = strdup(Classes);
67 conf->GetInstance()->Log(DEBUG,"Read oper TYPE '%s' with classes '%s'",TypeName,Classes);
71 bool DoClass(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
73 const char* ClassName = values[0].GetString();
74 const char* CommandList = values[1].GetString();
76 conf->operclass[ClassName] = strdup(CommandList);
77 conf->GetInstance()->Log(DEBUG,"Read oper CLASS '%s' with commands '%s'",ClassName,CommandList);
81 bool DoneClassesAndTypes(ServerConfig* conf, const char* tag)
86 std::string userrec::ProcessNoticeMasks(const char *sm)
88 bool adding = true, oldadding = false;
92 ServerInstance->Log(DEBUG,"Process notice masks");
96 ServerInstance->Log(DEBUG,"Process notice mask %c",*c);
107 for (unsigned char d = 'A'; d <= 'z'; d++)
109 if (ServerInstance->SNO->IsEnabled(d))
111 if ((!IsNoticeMaskSet(d) && adding) || (IsNoticeMaskSet(d) && !adding))
113 if ((oldadding != adding) || (!output.length()))
114 output += (adding ? '+' : '-');
116 this->SetNoticeMask(d, adding);
125 if ((*c >= 'A') && (*c <= 'z') && (ServerInstance->SNO->IsEnabled(*c)))
127 if ((!IsNoticeMaskSet(*c) && adding) || (IsNoticeMaskSet(*c) && !adding))
129 if ((oldadding != adding) || (!output.length()))
130 output += (adding ? '+' : '-');
132 this->SetNoticeMask(*c, adding);
147 void userrec::StartDNSLookup()
149 ServerInstance->Log(DEBUG,"Commencing reverse lookup");
152 ServerInstance->Log(DEBUG,"Passing instance: %08x",this->ServerInstance);
153 res_reverse = new UserResolver(this->ServerInstance, this, this->GetIPString(), DNS_QUERY_REVERSE);
154 this->ServerInstance->AddResolver(res_reverse);
156 catch (ModuleException& e)
158 ServerInstance->Log(DEBUG,"Error in resolver: %s",e.GetReason());
162 UserResolver::UserResolver(InspIRCd* Instance, userrec* user, std::string to_resolve, QueryType qt) :
163 Resolver(Instance, to_resolve, qt), bound_user(user)
165 this->fwd = (qt == DNS_QUERY_A || qt == DNS_QUERY_AAAA);
166 this->bound_fd = user->GetFd();
169 void UserResolver::OnLookupComplete(const std::string &result)
171 if ((!this->fwd) && (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user))
173 ServerInstance->Log(DEBUG,"Commencing forward lookup");
174 this->bound_user->stored_host = result;
177 /* Check we didnt time out */
178 if (this->bound_user->registered != REG_ALL)
181 const char *ip = this->bound_user->GetIPString();
182 bound_user->res_forward = new UserResolver(this->ServerInstance, this->bound_user, result, (strstr(ip,"0::ffff:") == ip ? DNS_QUERY_A : DNS_QUERY_AAAA));
184 bound_user->res_forward = new UserResolver(this->ServerInstance, this->bound_user, result, DNS_QUERY_A);
186 this->ServerInstance->AddResolver(bound_user->res_forward);
189 catch (ModuleException& e)
191 ServerInstance->Log(DEBUG,"Error in resolver: %s",e.GetReason());
194 else if ((this->fwd) && (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user))
196 /* Both lookups completed */
197 std::string result2 = "0::ffff:";
198 result2.append(result);
199 if (this->bound_user->GetIPString() == result || this->bound_user->GetIPString() == result2)
201 std::string hostname = this->bound_user->stored_host;
202 if (hostname.length() < 65)
204 /* Check we didnt time out */
205 if (this->bound_user->registered != REG_ALL)
207 /* Hostnames starting with : are not a good thing (tm) */
208 if (*(hostname.c_str()) == ':')
209 hostname = "0" + hostname;
211 this->bound_user->WriteServ("NOTICE Auth :*** Found your hostname (%s)", hostname.c_str());
212 this->bound_user->dns_done = true;
213 strlcpy(this->bound_user->dhost, hostname.c_str(),64);
214 strlcpy(this->bound_user->host, hostname.c_str(),64);
219 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());
224 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());
229 void UserResolver::OnError(ResolverError e, const std::string &errormessage)
231 if (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user)
233 /* Error message here */
234 this->bound_user->WriteServ("NOTICE Auth :*** Could not resolve your hostname, using your IP address (%s) instead.", this->bound_user->GetIPString());
235 this->bound_user->dns_done = true;
240 bool userrec::IsNoticeMaskSet(unsigned char sm)
242 return (snomasks[sm-65]);
245 void userrec::SetNoticeMask(unsigned char sm, bool value)
247 snomasks[sm-65] = value;
250 const char* userrec::FormatNoticeMasks()
252 static char data[MAXBUF];
255 for (int n = 0; n < 64; n++)
258 data[offset++] = n+65;
267 bool userrec::IsModeSet(unsigned char m)
269 return (modes[m-65]);
272 void userrec::SetMode(unsigned char m, bool value)
277 const char* userrec::FormatModes()
279 static char data[MAXBUF];
281 for (int n = 0; n < 64; n++)
284 data[offset++] = n+65;
290 userrec::userrec(InspIRCd* Instance) : ServerInstance(Instance)
292 ServerInstance->Log(DEBUG,"userrec::userrec(): Instance: %08x",ServerInstance);
293 // the PROPER way to do it, AVOID bzero at *ALL* costs
294 *password = *nick = *ident = *host = *dhost = *fullname = *awaymsg = *oper = 0;
295 server = (char*)Instance->FindServerNamePtr(Instance->Config->ServerName);
296 reset_due = ServerInstance->Time();
297 age = ServerInstance->Time(true);
298 lines_in = lastping = signon = idle_lastmsg = nping = registered = 0;
299 ChannelCount = timeout = flood = bytes_in = bytes_out = cmds_in = cmds_out = 0;
300 exempt = haspassed = dns_done = false;
305 res_forward = res_reverse = NULL;
309 memset(modes,0,sizeof(modes));
310 memset(snomasks,0,sizeof(snomasks));
317 clonemap::iterator x = ServerInstance->local_clones.find(this->GetIPString());
318 if (x != ServerInstance->local_clones.end())
323 ServerInstance->local_clones.erase(x);
327 clonemap::iterator y = ServerInstance->global_clones.find(this->GetIPString());
328 if (y != ServerInstance->global_clones.end())
333 ServerInstance->global_clones.erase(y);
337 if (this->GetProtocolFamily() == AF_INET)
339 delete (sockaddr_in*)ip;
341 #ifdef SUPPORT_IP6LINKS
344 delete (sockaddr_in6*)ip;
350 char* userrec::MakeHost()
352 static char nhost[MAXBUF];
353 /* This is much faster than snprintf */
355 for(char* n = ident; *n; n++)
358 for(char* n = host; *n; n++)
364 char* userrec::MakeHostIP()
366 static char ihost[MAXBUF];
367 /* This is much faster than snprintf */
369 for(char* n = ident; *n; n++)
372 for(const char* n = this->GetIPString(); *n; n++)
378 void userrec::CloseSocket()
380 shutdown(this->fd,2);
384 char* userrec::GetFullHost()
386 static char result[MAXBUF];
388 for(char* n = nick; *n; n++)
391 for(char* n = ident; *n; n++)
394 for(char* n = dhost; *n; n++)
400 char* userrec::MakeWildHost()
402 static char nresult[MAXBUF];
404 *t++ = '*'; *t++ = '!';
405 *t++ = '*'; *t++ = '@';
406 for(char* n = dhost; *n; n++)
412 int userrec::ReadData(void* buffer, size_t size)
416 return read(this->fd, buffer, size);
423 char* userrec::GetFullRealHost()
425 static char fresult[MAXBUF];
427 for(char* n = nick; *n; n++)
430 for(char* n = ident; *n; n++)
433 for(char* n = host; *n; n++)
439 bool userrec::IsInvited(const irc::string &channel)
441 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
451 InvitedList* userrec::GetInviteList()
456 void userrec::InviteTo(const irc::string &channel)
458 invites.push_back(channel);
461 void userrec::RemoveInvite(const irc::string &channel)
463 ServerInstance->Log(DEBUG,"Removing invites");
464 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
474 bool userrec::HasPermission(const std::string &command)
481 * users on remote servers can completely bypass all permissions based checks.
482 * This prevents desyncs when one server has different type/class tags to another.
483 * That having been said, this does open things up to the possibility of source changes
484 * allowing remote kills, etc - but if they have access to the src, they most likely have
485 * access to the conf - so it's an end to a means either way.
490 // are they even an oper at all?
493 opertype_t::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper);
494 if (iter_opertype != ServerInstance->Config->opertypes.end())
496 char* Classes = strdup(iter_opertype->second);
497 char* myclass = strtok_r(Classes," ",&savept);
500 operclass_t::iterator iter_operclass = ServerInstance->Config->operclass.find(myclass);
501 if (iter_operclass != ServerInstance->Config->operclass.end())
503 char* CommandList = strdup(iter_operclass->second);
504 mycmd = strtok_r(CommandList," ",&savept2);
507 if ((!strcasecmp(mycmd,command.c_str())) || (*mycmd == '*'))
513 mycmd = strtok_r(NULL," ",&savept2);
517 myclass = strtok_r(NULL," ",&savept);
525 /** NOTE: We cannot pass a const reference to this method.
526 * The string is changed by the workings of the method,
527 * so that if we pass const ref, we end up copying it to
528 * something we can change anyway. Makes sense to just let
529 * the compiler do that copy for us.
531 bool userrec::AddBuffer(std::string a)
535 std::string::size_type i = a.rfind('\r');
537 while (i != std::string::npos)
546 if (recvq.length() > (unsigned)this->recvqmax)
548 this->SetWriteError("RecvQ exceeded");
549 ServerInstance->WriteOpers("*** User %s RecvQ of %d exceeds connect class maximum of %d",this->nick,recvq.length(),this->recvqmax);
558 ServerInstance->Log(DEBUG,"Exception in userrec::AddBuffer()");
563 bool userrec::BufferIsReady()
565 return (recvq.find('\n') != std::string::npos);
568 void userrec::ClearBuffer()
573 std::string userrec::GetBuffer()
580 /* Strip any leading \r or \n off the string.
581 * Usually there are only one or two of these,
582 * so its is computationally cheap to do.
584 while ((*recvq.begin() == '\r') || (*recvq.begin() == '\n'))
585 recvq.erase(recvq.begin());
587 for (std::string::iterator x = recvq.begin(); x != recvq.end(); x++)
589 /* Find the first complete line, return it as the
590 * result, and leave the recvq as whats left
594 std::string ret = std::string(recvq.begin(), x);
595 recvq.erase(recvq.begin(), x + 1);
604 ServerInstance->Log(DEBUG,"Exception in userrec::GetBuffer()");
609 void userrec::AddWriteBuf(const std::string &data)
611 if (*this->GetWriteError())
614 if (sendq.length() + data.length() > (unsigned)this->sendqmax)
617 * Fix by brain - Set the error text BEFORE calling writeopers, because
618 * if we dont it'll recursively call here over and over again trying
619 * to repeatedly add the text to the sendq!
621 this->SetWriteError("SendQ exceeded");
622 ServerInstance->WriteOpers("*** User %s SendQ of %d exceeds connect class maximum of %d",this->nick,sendq.length() + data.length(),this->sendqmax);
628 if (data.length() > 512)
629 sendq.append(data.substr(0,510)).append("\r\n");
635 this->SetWriteError("SendQ exceeded");
636 ServerInstance->WriteOpers("*** User %s SendQ got an exception",this->nick);
640 // send AS MUCH OF THE USERS SENDQ as we are able to (might not be all of it)
641 void userrec::FlushWriteBuf()
645 if ((this->fd == FD_MAGIC_NUMBER) || (*this->GetWriteError()))
649 if ((sendq.length()) && (this->fd != FD_MAGIC_NUMBER))
651 int old_sendq_length = sendq.length();
652 int n_sent = write(this->fd, this->sendq.data(), this->sendq.length());
657 /* The socket buffer is full. This isnt fatal,
660 ServerInstance->Log(DEBUG,"EAGAIN, want write");
661 this->ServerInstance->SE->WantWrite(this);
665 /* Fatal error, set write error and bail
667 this->SetWriteError(strerror(errno));
673 /* advance the queue */
675 this->sendq = this->sendq.substr(n_sent);
676 /* update the user's stats counters */
677 this->bytes_out += n_sent;
679 if (n_sent != old_sendq_length)
681 ServerInstance->Log(DEBUG,"Not all written, want write");
682 this->ServerInstance->SE->WantWrite(this);
690 ServerInstance->Log(DEBUG,"Exception in userrec::FlushWriteBuf()");
694 void userrec::SetWriteError(const std::string &error)
698 // don't try to set the error twice, its already set take the first string.
699 if (this->WriteError.empty())
701 ServerInstance->Log(DEBUG,"Setting error string for %s to '%s'",this->nick,error.c_str());
702 this->WriteError = error;
708 ServerInstance->Log(DEBUG,"Exception in userrec::SetWriteError()");
712 const char* userrec::GetWriteError()
714 return this->WriteError.c_str();
717 void userrec::Oper(const std::string &opertype)
721 this->modes[UM_OPERATOR] = 1;
722 this->WriteServ("MODE %s :+o", this->nick);
723 FOREACH_MOD(I_OnOper, OnOper(this, opertype));
724 ServerInstance->Log(DEFAULT,"OPER: %s!%s@%s opered as type: %s", this->nick, this->ident, this->host, opertype.c_str());
725 strlcpy(this->oper, opertype.c_str(), NICKMAX - 1);
726 ServerInstance->all_opers.push_back(this);
727 FOREACH_MOD(I_OnPostOper,OnPostOper(this, opertype));
732 ServerInstance->Log(DEBUG,"Exception in userrec::Oper()");
736 void userrec::UnOper()
743 this->modes[UM_OPERATOR] = 0;
744 for (std::vector<userrec*>::iterator a = ServerInstance->all_opers.begin(); a < ServerInstance->all_opers.end(); a++)
748 ServerInstance->Log(DEBUG,"Oper removed from optimization list");
749 ServerInstance->all_opers.erase(a);
758 ServerInstance->Log(DEBUG,"Exception in userrec::UnOper()");
762 void userrec::QuitUser(InspIRCd* Instance, userrec *user, const std::string &quitreason)
764 user_hash::iterator iter = Instance->clientlist.find(user->nick);
765 std::string reason = quitreason;
767 if (reason.length() > MAXQUIT - 1)
768 reason.resize(MAXQUIT - 1);
772 user->Write("ERROR :Closing link (%s@%s) [%s]",user->ident,user->host,reason.c_str());
773 if ((!user->sendq.empty()) && (!(*user->GetWriteError())))
774 user->FlushWriteBuf();
777 if (user->registered == REG_ALL)
779 user->PurgeEmptyChannels();
780 user->WriteCommonExcept("QUIT :%s",reason.c_str());
781 FOREACH_MOD_I(Instance,I_OnUserQuit,OnUserQuit(user,reason));
784 FOREACH_MOD_I(Instance,I_OnUserDisconnect,OnUserDisconnect(user));
788 if (Instance->Config->GetIOHook(user->GetPort()))
792 Instance->Config->GetIOHook(user->GetPort())->OnRawSocketClose(user->fd);
794 catch (ModuleException& modexcept)
796 Instance->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason());
800 Instance->SE->DelFd(user);
805 * this must come before the ServerInstance->SNO->WriteToSnoMaskso that it doesnt try to fill their buffer with anything
806 * if they were an oper with +sn +qQ.
808 if (user->registered == REG_ALL)
811 Instance->SNO->WriteToSnoMask('q',"Client exiting: %s!%s@%s [%s]",user->nick,user->ident,user->host,reason.c_str());
813 Instance->SNO->WriteToSnoMask('Q',"Client exiting on server %s: %s!%s@%s [%s]",user->server,user->nick,user->ident,user->host,reason.c_str());
817 if (iter != Instance->clientlist.end())
819 Instance->Log(DEBUG,"deleting user hash value %lx",(unsigned long)user);
822 if (find(Instance->local_users.begin(),Instance->local_users.end(),user) != Instance->local_users.end())
823 Instance->local_users.erase(find(Instance->local_users.begin(),Instance->local_users.end(),user));
825 Instance->clientlist.erase(iter);
835 WhoWasGroup::WhoWasGroup(userrec* user) : host(NULL), dhost(NULL), ident(NULL), server(NULL), gecos(NULL), signon(user->signon)
837 this->host = strdup(user->host);
838 this->dhost = strdup(user->dhost);
839 this->ident = strdup(user->ident);
840 this->server = user->server;
841 this->gecos = strdup(user->fullname);
844 WhoWasGroup::~WhoWasGroup()
856 /* every hour, run this function which removes all entries older than Config->WhoWasMaxKeep */
857 void MaintainWhoWas(InspIRCd* ServerInstance, time_t t)
859 for (whowas_users::iterator iter = ServerInstance->whowas.begin(); iter != ServerInstance->whowas.end(); iter++)
861 whowas_set* n = (whowas_set*)iter->second;
864 while ((n->begin() != n->end()) && ((*n->begin())->signon < t - ServerInstance->Config->WhoWasMaxKeep))
866 WhoWasGroup *a = *(n->begin());
868 n->erase(n->begin());
873 /* on rehash, refactor maps according to new conf values */
874 void PruneWhoWas(InspIRCd* ServerInstance, time_t t)
877 int groupsize = ServerInstance->Config->WhoWasGroupSize;
878 int maxgroups = ServerInstance->Config->WhoWasMaxGroups;
879 int maxkeep = ServerInstance->Config->WhoWasMaxKeep;
881 int groupcount = ServerInstance->whowas.size();
882 /* iterate whowas_fifo oldest first */
883 whowas_users_fifo::iterator iter, safeiter;
884 for (iter = ServerInstance->whowas_fifo.begin(); iter != ServerInstance->whowas_fifo.end(); iter++)
886 /** prune all groups that has expired due to new maxkeep time and
887 * also any group number higher than new maxgroups. The oldest are
888 * removed first due to iteration over whowas_fifo
890 if (groupcount > maxgroups || iter->first < t - maxkeep)
892 whowas_set* n = (whowas_set*)ServerInstance->whowas.find(iter->second)->second;
895 while (n->begin() != n->end())
897 WhoWasGroup *a = *(n->begin());
899 n->erase(n->begin());
902 ServerInstance->whowas.erase(iter->second);
903 /* use a safe iter copy for erase and set the orig iter old valid ref by decrementing it */
906 ServerInstance->whowas_fifo.erase(safeiter);
909 /* also trim individual groupsizes in case groupsize should have been lowered */
910 whowas_set* n = (whowas_set*)ServerInstance->whowas.find(iter->second)->second;
913 int nickcount = n->size();
914 while (n->begin() != n->end() && nickcount > groupsize)
916 WhoWasGroup *a = *(n->begin());
918 n->erase(n->begin());
929 /* adds or updates an entry in the whowas list */
930 void userrec::AddToWhoWas()
932 /* if whowas disabled */
933 if (ServerInstance->Config->WhoWasGroupSize == 0 || ServerInstance->Config->WhoWasMaxGroups == 0)
938 irc::whowas::whowas_users::iterator iter = ServerInstance->whowas.find(this->nick);
940 ServerInstance->Log(DEBUG,"Add to whowas lists");
942 if (iter == ServerInstance->whowas.end())
944 ServerInstance->Log(DEBUG,"Adding new whowas set for %s",this->nick);
945 irc::whowas::whowas_set* n = new irc::whowas::whowas_set;
946 irc::whowas::WhoWasGroup *a = new irc::whowas::WhoWasGroup(this);
948 ServerInstance->whowas[this->nick] = n;
949 ServerInstance->whowas_fifo[ServerInstance->Time()] = this->nick;
950 if ((int)(ServerInstance->whowas.size()) > ServerInstance->Config->WhoWasMaxGroups)
952 ServerInstance->Log(DEBUG,"Maxgroups of %d reached deleting oldest group '%s'",ServerInstance->Config->WhoWasMaxGroups, ServerInstance->whowas_fifo.begin()->second.c_str());
953 ServerInstance->whowas.erase(ServerInstance->whowas_fifo.begin()->second);
954 ServerInstance->whowas_fifo.erase(ServerInstance->whowas_fifo.begin());
959 irc::whowas::whowas_set* group = (irc::whowas::whowas_set*)iter->second;
961 ServerInstance->Log(DEBUG,"Using existing whowas group for %s",this->nick);
963 if ((int)(group->size()) >= ServerInstance->Config->WhoWasGroupSize)
965 ServerInstance->Log(DEBUG,"Trimming existing group '%s' to %d entries",this->nick, ServerInstance->Config->WhoWasGroupSize);
966 irc::whowas::WhoWasGroup *a = (irc::whowas::WhoWasGroup*)*(group->begin());
971 irc::whowas::WhoWasGroup *a = new irc::whowas::WhoWasGroup(this);
976 /* add a client connection to the sockets list */
977 void userrec::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, insp_inaddr ip)
979 std::string tempnick = ConvToStr(socket) + "-unknown";
980 user_hash::iterator iter = Instance->clientlist.find(tempnick);
981 const char *ipaddr = insp_ntoa(ip);
987 * as these nicknames are 'RFC impossible', we can be sure nobody is going to be
988 * using one as a registered connection. As they are per fd, we can also safely assume
989 * that we wont have collisions. Therefore, if the nick exists in the list, its only
990 * used by a dead socket, erase the iterator so that the new client may reclaim it.
991 * this was probably the cause of 'server ignores me when i hammer it with reconnects'
992 * issue in earlier alphas/betas
994 if (iter != Instance->clientlist.end())
996 userrec* goner = iter->second;
998 Instance->clientlist.erase(iter);
1001 Instance->Log(DEBUG,"AddClient: %d %d %s",socket,port,ipaddr);
1003 New = new userrec(Instance);
1004 Instance->clientlist[tempnick] = New;
1006 strlcpy(New->nick,tempnick.c_str(),NICKMAX-1);
1008 New->server = Instance->FindServerNamePtr(Instance->Config->ServerName);
1009 /* We don't need range checking here, we KNOW 'unknown\0' will fit into the ident field. */
1010 strcpy(New->ident, "unknown");
1012 New->registered = REG_NONE;
1013 New->signon = Instance->Time() + Instance->Config->dns_timeout;
1016 New->SetSockAddr(AF_FAMILY, ipaddr, port);
1018 /* Smarter than your average bear^H^H^H^Hset of strlcpys. */
1019 for (const char* temp = New->GetIPString(); *temp && j < 64; temp++, j++)
1020 New->dhost[j] = New->host[j] = *temp;
1021 New->dhost[j] = New->host[j] = 0;
1023 Instance->AddLocalClone(New);
1024 Instance->AddGlobalClone(New);
1026 // set the registration timeout for this user
1027 unsigned long class_regtimeout = 90;
1028 int class_flood = 0;
1029 long class_threshold = 5;
1030 long class_sqmax = 262144; // 256kb
1031 long class_rqmax = 4096; // 4k
1033 for (ClassVector::iterator i = Instance->Config->Classes.begin(); i != Instance->Config->Classes.end(); i++)
1035 if ((i->type == CC_ALLOW) && (match(ipaddr,i->host.c_str(),true)))
1037 class_regtimeout = (unsigned long)i->registration_timeout;
1038 class_flood = i->flood;
1039 New->pingmax = i->pingtime;
1040 class_threshold = i->threshold;
1041 class_sqmax = i->sendqmax;
1042 class_rqmax = i->recvqmax;
1047 New->nping = Instance->Time() + New->pingmax + Instance->Config->dns_timeout;
1048 New->timeout = Instance->Time() + class_regtimeout;
1049 New->flood = class_flood;
1050 New->threshold = class_threshold;
1051 New->sendqmax = class_sqmax;
1052 New->recvqmax = class_rqmax;
1054 Instance->local_users.push_back(New);
1056 if ((Instance->local_users.size() > Instance->Config->SoftLimit) || (Instance->local_users.size() >= MAXCLIENTS))
1058 Instance->WriteOpers("*** Warning: softlimit value has been reached: %d clients", Instance->Config->SoftLimit);
1059 userrec::QuitUser(Instance, New,"No more connections allowed");
1065 * this is done as a safety check to keep the file descriptors within range of fd_ref_table.
1066 * its a pretty big but for the moment valid assumption:
1067 * file descriptors are handed out starting at 0, and are recycled as theyre freed.
1068 * therefore if there is ever an fd over 65535, 65536 clients must be connected to the
1069 * irc server at once (or the irc server otherwise initiating this many connections, files etc)
1070 * which for the time being is a physical impossibility (even the largest networks dont have more
1071 * than about 10,000 users on ONE server!)
1073 if ((unsigned int)socket >= MAX_DESCRIPTORS)
1075 userrec::QuitUser(Instance, New, "Server is full");
1079 New->exempt = (Instance->XLines->matches_exception(New) != NULL);
1082 ZLine* r = Instance->XLines->matches_zline(ipaddr);
1085 char reason[MAXBUF];
1086 snprintf(reason,MAXBUF,"Z-Lined: %s",r->reason);
1087 userrec::QuitUser(Instance, New, reason);
1094 if (!Instance->SE->AddFd(New))
1096 userrec::QuitUser(Instance, New, "Internal error handling connection");
1101 /* NOTE: even if dns lookups are *off*, we still need to display this.
1102 * BOPM and other stuff requires it.
1104 New->WriteServ("NOTICE Auth :*** Looking up your hostname...");
1107 long userrec::GlobalCloneCount()
1109 clonemap::iterator x = ServerInstance->global_clones.find(this->GetIPString());
1110 if (x != ServerInstance->global_clones.end())
1116 long userrec::LocalCloneCount()
1118 clonemap::iterator x = ServerInstance->local_clones.find(this->GetIPString());
1119 if (x != ServerInstance->local_clones.end())
1125 void userrec::FullConnect(CullList* Goners)
1127 ServerInstance->stats->statsConnects++;
1128 this->idle_lastmsg = ServerInstance->Time();
1130 ConnectClass a = this->GetClass();
1132 if (a.type == CC_DENY)
1134 Goners->AddItem(this,"Unauthorised connection");
1138 if ((*(a.pass.c_str())) && (!this->haspassed))
1140 Goners->AddItem(this,"Invalid password");
1144 if (this->LocalCloneCount() > a.maxlocal)
1146 Goners->AddItem(this, "No more connections allowed from your host via this connect class (local)");
1147 ServerInstance->WriteOpers("*** WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a.maxlocal, this->GetIPString());
1150 else if (this->GlobalCloneCount() > a.maxglobal)
1152 Goners->AddItem(this, "No more connections allowed from your host via this connect class (global)");
1153 ServerInstance->WriteOpers("*** WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s",a.maxglobal, this->GetIPString());
1159 GLine* r = ServerInstance->XLines->matches_gline(this);
1163 char reason[MAXBUF];
1164 snprintf(reason,MAXBUF,"G-Lined: %s",r->reason);
1165 Goners->AddItem(this, reason);
1169 KLine* n = ServerInstance->XLines->matches_kline(this);
1173 char reason[MAXBUF];
1174 snprintf(reason,MAXBUF,"K-Lined: %s",n->reason);
1175 Goners->AddItem(this, reason);
1181 this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network);
1182 this->WriteServ("001 %s :Welcome to the %s IRC Network %s!%s@%s",this->nick, ServerInstance->Config->Network, this->nick, this->ident, this->host);
1183 this->WriteServ("002 %s :Your host is %s, running version %s",this->nick,ServerInstance->Config->ServerName,VERSION);
1184 this->WriteServ("003 %s :This server was created %s %s", this->nick, __TIME__, __DATE__);
1185 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());
1187 ServerInstance->Config->Send005(this);
1192 * fix 3 by brain, move registered = 7 below these so that spurious modes and host
1193 * changes dont go out onto the network and produce 'fake direction'.
1195 FOREACH_MOD(I_OnUserConnect,OnUserConnect(this));
1197 this->registered = REG_ALL;
1199 FOREACH_MOD(I_OnPostConnect,OnPostConnect(this));
1201 ServerInstance->SNO->WriteToSnoMask('c',"Client connecting on port %d: %s!%s@%s [%s]", this->GetPort(), this->nick, this->ident, this->host, this->GetIPString());
1204 /** userrec::UpdateNick()
1205 * re-allocates a nick in the user_hash after they change nicknames,
1206 * returns a pointer to the new user as it may have moved
1208 userrec* userrec::UpdateNickHash(const char* New)
1212 //user_hash::iterator newnick;
1213 user_hash::iterator oldnick = ServerInstance->clientlist.find(this->nick);
1215 if (!strcasecmp(this->nick,New))
1216 return oldnick->second;
1218 if (oldnick == ServerInstance->clientlist.end())
1219 return NULL; /* doesnt exist */
1221 userrec* olduser = oldnick->second;
1222 ServerInstance->clientlist[New] = olduser;
1223 ServerInstance->clientlist.erase(oldnick);
1224 return ServerInstance->clientlist[New];
1229 ServerInstance->Log(DEBUG,"Exception in userrec::UpdateNickHash()");
1234 bool userrec::ForceNickChange(const char* newnick)
1240 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(this, newnick));
1244 ServerInstance->stats->statsCollisions++;
1248 if (ServerInstance->XLines->matches_qline(newnick))
1250 ServerInstance->stats->statsCollisions++;
1254 if (this->registered == REG_ALL)
1256 const char* pars[1];
1258 std::string cmd = "NICK";
1259 return (ServerInstance->Parser->CallHandler(cmd, pars, 1, this) == CMD_SUCCESS);
1266 ServerInstance->Log(DEBUG,"Exception in userrec::ForceNickChange()");
1271 void userrec::SetSockAddr(int protocol_family, const char* ip, int port)
1273 switch (protocol_family)
1275 #ifdef SUPPORT_IP6LINKS
1278 ServerInstance->Log(DEBUG,"Set inet6 protocol address");
1279 sockaddr_in6* sin = new sockaddr_in6;
1280 sin->sin6_family = AF_INET6;
1281 sin->sin6_port = port;
1282 inet_pton(AF_INET6, ip, &sin->sin6_addr);
1283 this->ip = (sockaddr*)sin;
1289 ServerInstance->Log(DEBUG,"Set inet4 protocol address");
1290 sockaddr_in* sin = new sockaddr_in;
1291 sin->sin_family = AF_INET;
1292 sin->sin_port = port;
1293 inet_pton(AF_INET, ip, &sin->sin_addr);
1294 this->ip = (sockaddr*)sin;
1298 ServerInstance->Log(DEBUG,"Ut oh, I dont know protocol %d to be set on '%s'!", protocol_family, this->nick);
1303 int userrec::GetPort()
1305 if (this->ip == NULL)
1308 switch (this->GetProtocolFamily())
1310 #ifdef SUPPORT_IP6LINKS
1313 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1314 return sin->sin6_port;
1320 sockaddr_in* sin = (sockaddr_in*)this->ip;
1321 return sin->sin_port;
1330 int userrec::GetProtocolFamily()
1332 if (this->ip == NULL)
1335 sockaddr_in* sin = (sockaddr_in*)this->ip;
1336 return sin->sin_family;
1339 const char* userrec::GetIPString()
1341 static char buf[1024];
1343 if (this->ip == NULL)
1346 switch (this->GetProtocolFamily())
1348 #ifdef SUPPORT_IP6LINKS
1351 static char temp[1024];
1353 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1354 inet_ntop(sin->sin6_family, &sin->sin6_addr, buf, sizeof(buf));
1355 /* IP addresses starting with a : on irc are a Bad Thing (tm) */
1358 strlcpy(&temp[1], buf, sizeof(temp) - 1);
1368 sockaddr_in* sin = (sockaddr_in*)this->ip;
1369 inet_ntop(sin->sin_family, &sin->sin_addr, buf, sizeof(buf));
1379 const char* userrec::GetIPString(char* buf)
1381 if (this->ip == NULL)
1387 switch (this->GetProtocolFamily())
1389 #ifdef SUPPORT_IP6LINKS
1392 static char temp[1024];
1394 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1395 inet_ntop(sin->sin6_family, &sin->sin6_addr, buf, sizeof(buf));
1396 /* IP addresses starting with a : on irc are a Bad Thing (tm) */
1399 strlcpy(&temp[1], buf, sizeof(temp) - 1);
1401 strlcpy(buf, temp, sizeof(temp));
1409 sockaddr_in* sin = (sockaddr_in*)this->ip;
1410 inet_ntop(sin->sin_family, &sin->sin_addr, buf, sizeof(buf));
1421 /** NOTE: We cannot pass a const reference to this method.
1422 * The string is changed by the workings of the method,
1423 * so that if we pass const ref, we end up copying it to
1424 * something we can change anyway. Makes sense to just let
1425 * the compiler do that copy for us.
1427 void userrec::Write(std::string text)
1429 if ((this->fd < 0) || (this->fd > MAX_DESCRIPTORS))
1434 text.append("\r\n");
1438 ServerInstance->Log(DEBUG,"Exception in userrec::Write() std::string::append");
1442 if (ServerInstance->Config->GetIOHook(this->GetPort()))
1446 ServerInstance->Config->GetIOHook(this->GetPort())->OnRawSocketWrite(this->fd, text.data(), text.length());
1448 catch (ModuleException& modexcept)
1450 ServerInstance->Log(DEBUG,"Module exception caught: %s",modexcept.GetReason());
1455 this->AddWriteBuf(text);
1457 ServerInstance->stats->statsSent += text.length();
1458 this->ServerInstance->SE->WantWrite(this);
1463 void userrec::Write(const char *text, ...)
1466 char textbuffer[MAXBUF];
1468 va_start(argsPtr, text);
1469 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1472 this->Write(std::string(textbuffer));
1475 void userrec::WriteServ(const std::string& text)
1477 char textbuffer[MAXBUF];
1479 snprintf(textbuffer,MAXBUF,":%s %s",ServerInstance->Config->ServerName,text.c_str());
1480 this->Write(std::string(textbuffer));
1484 * Same as Write(), except `text' is prefixed with `:server.name '.
1486 void userrec::WriteServ(const char* text, ...)
1489 char textbuffer[MAXBUF];
1491 va_start(argsPtr, text);
1492 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1495 this->WriteServ(std::string(textbuffer));
1499 void userrec::WriteFrom(userrec *user, const std::string &text)
1503 snprintf(tb,MAXBUF,":%s %s",user->GetFullHost(),text.c_str());
1505 this->Write(std::string(tb));
1509 /* write text from an originating user to originating user */
1511 void userrec::WriteFrom(userrec *user, const char* text, ...)
1514 char textbuffer[MAXBUF];
1516 va_start(argsPtr, text);
1517 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1520 this->WriteFrom(user, std::string(textbuffer));
1524 /* write text to an destination user from a source user (e.g. user privmsg) */
1526 void userrec::WriteTo(userrec *dest, const char *data, ...)
1528 char textbuffer[MAXBUF];
1531 va_start(argsPtr, data);
1532 vsnprintf(textbuffer, MAXBUF, data, argsPtr);
1535 this->WriteTo(dest, std::string(textbuffer));
1538 void userrec::WriteTo(userrec *dest, const std::string &data)
1540 dest->WriteFrom(this, data);
1544 void userrec::WriteCommon(const char* text, ...)
1546 char textbuffer[MAXBUF];
1549 if (this->registered != REG_ALL)
1552 va_start(argsPtr, text);
1553 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1556 this->WriteCommon(std::string(textbuffer));
1559 void userrec::WriteCommon(const std::string &text)
1563 bool sent_to_at_least_one = false;
1565 if (this->registered != REG_ALL)
1570 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1572 CUList* ulist = v->first->GetUsers();
1573 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1575 if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
1577 already_sent[i->second->fd] = uniq_id;
1578 i->second->WriteFrom(this, std::string(text));
1579 sent_to_at_least_one = true;
1585 * if the user was not in any channels, no users will receive the text. Make sure the user
1586 * receives their OWN message for WriteCommon
1588 if (!sent_to_at_least_one)
1590 this->WriteFrom(this,std::string(text));
1596 ServerInstance->Log(DEBUG,"Exception in userrec::WriteCommon()");
1601 /* write a formatted string to all users who share at least one common
1602 * channel, NOT including the source user e.g. for use in QUIT
1605 void userrec::WriteCommonExcept(const char* text, ...)
1607 char textbuffer[MAXBUF];
1610 va_start(argsPtr, text);
1611 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1614 this->WriteCommonExcept(std::string(textbuffer));
1617 void userrec::WriteCommonExcept(const std::string &text)
1619 bool quit_munge = false;
1620 char oper_quit[MAXBUF];
1621 char textbuffer[MAXBUF];
1623 strlcpy(textbuffer, text.c_str(), MAXBUF);
1625 if (this->registered != REG_ALL)
1630 /* TODO: We need some form of WriteCommonExcept that will send two lines, one line to
1631 * opers and the other line to non-opers, then all this hidebans and hidesplits gunk
1634 if (ServerInstance->Config->HideSplits)
1636 char* check = textbuffer + 6;
1638 if (!strncasecmp(textbuffer, "QUIT :",6))
1640 std::stringstream split(check);
1641 std::string server_one;
1642 std::string server_two;
1644 split >> server_one;
1645 split >> server_two;
1647 if ((ServerInstance->FindServerName(server_one)) && (ServerInstance->FindServerName(server_two)))
1649 strlcpy(oper_quit,textbuffer,MAXQUIT);
1650 strlcpy(check,"*.net *.split",MAXQUIT);
1656 if ((ServerInstance->Config->HideBans) && (!quit_munge))
1658 if ((!strncasecmp(textbuffer, "QUIT :G-Lined:",14)) || (!strncasecmp(textbuffer, "QUIT :K-Lined:",14))
1659 || (!strncasecmp(textbuffer, "QUIT :Q-Lined:",14)) || (!strncasecmp(textbuffer, "QUIT :Z-Lined:",14)))
1661 char* check = textbuffer + 13;
1662 strlcpy(oper_quit,textbuffer,MAXQUIT);
1663 *check = 0; // We don't need to strlcpy, we just chop it from the :
1668 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1670 CUList *ulist = v->first->GetUsers();
1671 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1673 if (this != i->second)
1675 if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
1677 already_sent[i->second->fd] = uniq_id;
1679 i->second->WriteFrom(this, *i->second->oper ? std::string(oper_quit) : std::string(textbuffer));
1681 i->second->WriteFrom(this, std::string(textbuffer));
1689 void userrec::WriteWallOps(const std::string &text)
1691 /* Does nothing if theyre not opered */
1692 if ((!*this->oper) && (IS_LOCAL(this)))
1695 std::string wallop = "WALLOPS :";
1699 wallop.append(text);
1703 ServerInstance->Log(DEBUG,"Exception in userrec::Write() std::string::append");
1707 for (std::vector<userrec*>::const_iterator i = ServerInstance->local_users.begin(); i != ServerInstance->local_users.end(); i++)
1710 if ((IS_LOCAL(t)) && (t->modes[UM_WALLOPS]))
1711 this->WriteTo(t,wallop);
1715 void userrec::WriteWallOps(const char* text, ...)
1717 char textbuffer[MAXBUF];
1720 va_start(argsPtr, text);
1721 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1724 this->WriteWallOps(std::string(textbuffer));
1727 /* return 0 or 1 depending if users u and u2 share one or more common channels
1728 * (used by QUIT, NICK etc which arent channel specific notices)
1730 * The old algorithm in 1.0 for this was relatively inefficient, iterating over
1731 * the first users channels then the second users channels within the outer loop,
1732 * therefore it was a maximum of x*y iterations (upon returning 0 and checking
1733 * all possible iterations). However this new function instead checks against the
1734 * channel's userlist in the inner loop which is a std::map<userrec*,userrec*>
1735 * and saves us time as we already know what pointer value we are after.
1736 * Don't quote me on the maths as i am not a mathematician or computer scientist,
1737 * but i believe this algorithm is now x+(log y) maximum iterations instead.
1739 bool userrec::SharesChannelWith(userrec *other)
1741 if ((!other) || (this->registered != REG_ALL) || (other->registered != REG_ALL))
1745 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1747 /* Eliminate the inner loop (which used to be ~equal in size to the outer loop)
1748 * by replacing it with a map::find which *should* be more efficient
1750 if (i->first->HasUser(other))
1756 bool userrec::ChangeName(const char* gecos)
1758 if (!strcmp(gecos, this->fullname))
1764 FOREACH_RESULT(I_OnChangeLocalUserGECOS,OnChangeLocalUserGECOS(this,gecos));
1767 FOREACH_MOD(I_OnChangeName,OnChangeName(this,gecos));
1769 strlcpy(this->fullname,gecos,MAXGECOS+1);
1773 bool userrec::ChangeDisplayedHost(const char* host)
1775 if (!strcmp(host, this->dhost))
1781 FOREACH_RESULT(I_OnChangeLocalUserHost,OnChangeLocalUserHost(this,host));
1784 FOREACH_MOD(I_OnChangeHost,OnChangeHost(this,host));
1786 if (this->ServerInstance->Config->CycleHosts)
1787 this->WriteCommonExcept("QUIT :Changing hosts");
1789 /* Fix by Om: userrec::dhost is 65 long, this was truncating some long hosts */
1790 strlcpy(this->dhost,host,64);
1792 if (this->ServerInstance->Config->CycleHosts)
1794 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1796 i->first->WriteAllExceptSender(this, false, 0, "JOIN %s", i->first->name);
1797 std::string n = this->ServerInstance->Modes->ModeString(this, i->first);
1799 i->first->WriteAllExceptSender(this, true, 0, "MODE %s +%s", i->first->name, n.c_str());
1804 this->WriteServ("396 %s %s :is now your hidden host",this->nick,this->dhost);
1809 bool userrec::ChangeIdent(const char* newident)
1811 if (!strcmp(newident, this->ident))
1814 if (this->ServerInstance->Config->CycleHosts)
1815 this->WriteCommonExcept("%s","QUIT :Changing ident");
1817 strlcpy(this->ident, newident, IDENTMAX+2);
1819 if (this->ServerInstance->Config->CycleHosts)
1821 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1823 i->first->WriteAllExceptSender(this, false, 0, "JOIN %s", i->first->name);
1824 std::string n = this->ServerInstance->Modes->ModeString(this, i->first);
1826 i->first->WriteAllExceptSender(this, true, 0, "MODE %s +%s", i->first->name, n.c_str());
1833 void userrec::NoticeAll(char* text, ...)
1835 char textbuffer[MAXBUF];
1836 char formatbuffer[MAXBUF];
1839 va_start(argsPtr, text);
1840 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1843 snprintf(formatbuffer,MAXBUF,"NOTICE $* :%s",textbuffer);
1845 for (std::vector<userrec*>::const_iterator i = ServerInstance->local_users.begin(); i != ServerInstance->local_users.end(); i++)
1848 t->WriteFrom(this, std::string(formatbuffer));
1853 std::string userrec::ChannelList(userrec* source)
1858 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1860 /* If the target is the same as the sender, let them see all their channels.
1861 * If the channel is NOT private/secret OR the user shares a common channel
1862 * If the user is an oper, and the <options:operspywhois> option is set.
1864 if ((source == this) || (*source->oper && ServerInstance->Config->OperSpyWhois) || (((!i->first->modes[CM_PRIVATE]) && (!i->first->modes[CM_SECRET])) || (i->first->HasUser(source))))
1866 list.append(i->first->GetPrefixChar(this)).append(i->first->name).append(" ");
1873 ServerInstance->Log(DEBUG,"Exception in userrec::ChannelList()");
1878 void userrec::SplitChanList(userrec* dest, const std::string &cl)
1881 std::ostringstream prefix;
1882 std::string::size_type start, pos, length;
1886 prefix << this->nick << " " << dest->nick << " :";
1887 line = prefix.str();
1888 int namelen = strlen(ServerInstance->Config->ServerName) + 6;
1890 for (start = 0; (pos = cl.find(' ', start)) != std::string::npos; start = pos+1)
1892 length = (pos == std::string::npos) ? cl.length() : pos;
1894 if (line.length() + namelen + length - start > 510)
1896 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1897 line = prefix.str();
1900 if(pos == std::string::npos)
1902 line.append(cl.substr(start, length - start));
1907 line.append(cl.substr(start, length - start + 1));
1913 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1919 ServerInstance->Log(DEBUG,"Exception in userrec::SplitChanList()");
1924 /* looks up a users password for their connection class (<ALLOW>/<DENY> tags)
1925 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1926 * then their ip will be taken as 'priority' anyway, so for example,
1927 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1929 ConnectClass& userrec::GetClass()
1931 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1933 if ((match(this->GetIPString(),i->host.c_str(),true)) || (match(this->host,i->host.c_str())))
1937 return *(ServerInstance->Config->Classes.begin());
1940 void userrec::PurgeEmptyChannels()
1942 std::vector<chanrec*> to_delete;
1944 // firstly decrement the count on each channel
1945 for (UCListIter f = this->chans.begin(); f != this->chans.end(); f++)
1947 f->first->RemoveAllPrefixes(this);
1948 if (f->first->DelUser(this) == 0)
1950 /* No users left in here, mark it for deletion */
1953 to_delete.push_back(f->first);
1957 ServerInstance->Log(DEBUG,"Exception in userrec::PurgeEmptyChannels to_delete.push_back()");
1962 for (std::vector<chanrec*>::iterator n = to_delete.begin(); n != to_delete.end(); n++)
1964 chanrec* thischan = *n;
1965 chan_hash::iterator i2 = ServerInstance->chanlist.find(thischan->name);
1966 if (i2 != ServerInstance->chanlist.end())
1968 FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(i2->second));
1970 ServerInstance->chanlist.erase(i2);
1977 void userrec::ShowMOTD()
1979 if (!ServerInstance->Config->MOTD.size())
1981 this->WriteServ("422 %s :Message of the day file is missing.",this->nick);
1984 this->WriteServ("375 %s :%s message of the day", this->nick, ServerInstance->Config->ServerName);
1986 for (file_cache::iterator i = ServerInstance->Config->MOTD.begin(); i != ServerInstance->Config->MOTD.end(); i++)
1987 this->WriteServ("372 %s :- %s",this->nick,i->c_str());
1989 this->WriteServ("376 %s :End of message of the day.", this->nick);
1992 void userrec::ShowRULES()
1994 if (!ServerInstance->Config->RULES.size())
1996 this->WriteServ("NOTICE %s :Rules file is missing.",this->nick);
1999 this->WriteServ("NOTICE %s :%s rules",this->nick,ServerInstance->Config->ServerName);
2001 for (file_cache::iterator i = ServerInstance->Config->RULES.begin(); i != ServerInstance->Config->RULES.end(); i++)
2002 this->WriteServ("NOTICE %s :%s",this->nick,i->c_str());
2004 this->WriteServ("NOTICE %s :End of %s rules.",this->nick,ServerInstance->Config->ServerName);
2007 void userrec::HandleEvent(EventType et, int errornum)
2009 /* WARNING: May delete this user! */
2015 ServerInstance->ProcessUser(this);
2019 this->FlushWriteBuf();
2022 /** This should be safe, but dont DARE do anything after it -- Brain */
2023 this->SetWriteError(errornum ? strerror(errornum) : "EOF from client");
2029 ServerInstance->Log(DEBUG,"Exception in userrec::HandleEvent intercepted");
2032 /* If the user has raised an error whilst being processed, quit them now we're safe to */
2033 if (!WriteError.empty())
2035 userrec::QuitUser(ServerInstance, this, GetWriteError());