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(irc::string &channel)
444 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
446 irc::string compare = i->channel;
448 if (compare == channel)
456 InvitedList* userrec::GetInviteList()
461 void userrec::InviteTo(irc::string &channel)
465 invites.push_back(i);
468 void userrec::RemoveInvite(irc::string &channel)
470 ServerInstance->Log(DEBUG,"Removing invites");
474 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
476 irc::string compare = i->channel;
478 if (compare == channel)
487 bool userrec::HasPermission(const std::string &command)
494 * users on remote servers can completely bypass all permissions based checks.
495 * This prevents desyncs when one server has different type/class tags to another.
496 * That having been said, this does open things up to the possibility of source changes
497 * allowing remote kills, etc - but if they have access to the src, they most likely have
498 * access to the conf - so it's an end to a means either way.
503 // are they even an oper at all?
506 opertype_t::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper);
507 if (iter_opertype != ServerInstance->Config->opertypes.end())
509 char* Classes = strdup(iter_opertype->second);
510 char* myclass = strtok_r(Classes," ",&savept);
513 operclass_t::iterator iter_operclass = ServerInstance->Config->operclass.find(myclass);
514 if (iter_operclass != ServerInstance->Config->operclass.end())
516 char* CommandList = strdup(iter_operclass->second);
517 mycmd = strtok_r(CommandList," ",&savept2);
520 if ((!strcasecmp(mycmd,command.c_str())) || (*mycmd == '*'))
526 mycmd = strtok_r(NULL," ",&savept2);
530 myclass = strtok_r(NULL," ",&savept);
538 /** NOTE: We cannot pass a const reference to this method.
539 * The string is changed by the workings of the method,
540 * so that if we pass const ref, we end up copying it to
541 * something we can change anyway. Makes sense to just let
542 * the compiler do that copy for us.
544 bool userrec::AddBuffer(std::string a)
548 std::string::size_type i = a.rfind('\r');
550 while (i != std::string::npos)
559 if (recvq.length() > (unsigned)this->recvqmax)
561 this->SetWriteError("RecvQ exceeded");
562 ServerInstance->WriteOpers("*** User %s RecvQ of %d exceeds connect class maximum of %d",this->nick,recvq.length(),this->recvqmax);
571 ServerInstance->Log(DEBUG,"Exception in userrec::AddBuffer()");
576 bool userrec::BufferIsReady()
578 return (recvq.find('\n') != std::string::npos);
581 void userrec::ClearBuffer()
586 std::string userrec::GetBuffer()
593 /* Strip any leading \r or \n off the string.
594 * Usually there are only one or two of these,
595 * so its is computationally cheap to do.
597 while ((*recvq.begin() == '\r') || (*recvq.begin() == '\n'))
598 recvq.erase(recvq.begin());
600 for (std::string::iterator x = recvq.begin(); x != recvq.end(); x++)
602 /* Find the first complete line, return it as the
603 * result, and leave the recvq as whats left
607 std::string ret = std::string(recvq.begin(), x);
608 recvq.erase(recvq.begin(), x + 1);
617 ServerInstance->Log(DEBUG,"Exception in userrec::GetBuffer()");
622 void userrec::AddWriteBuf(const std::string &data)
624 if (*this->GetWriteError())
627 if (sendq.length() + data.length() > (unsigned)this->sendqmax)
630 * Fix by brain - Set the error text BEFORE calling writeopers, because
631 * if we dont it'll recursively call here over and over again trying
632 * to repeatedly add the text to the sendq!
634 this->SetWriteError("SendQ exceeded");
635 ServerInstance->WriteOpers("*** User %s SendQ of %d exceeds connect class maximum of %d",this->nick,sendq.length() + data.length(),this->sendqmax);
641 if (data.length() > 512)
642 sendq.append(data.substr(0,510)).append("\r\n");
648 this->SetWriteError("SendQ exceeded");
649 ServerInstance->WriteOpers("*** User %s SendQ got an exception",this->nick);
653 // send AS MUCH OF THE USERS SENDQ as we are able to (might not be all of it)
654 void userrec::FlushWriteBuf()
658 if ((this->fd == FD_MAGIC_NUMBER) || (*this->GetWriteError()))
662 if ((sendq.length()) && (this->fd != FD_MAGIC_NUMBER))
664 int old_sendq_length = sendq.length();
665 int n_sent = write(this->fd, this->sendq.data(), this->sendq.length());
670 ServerInstance->Log(DEBUG,"EAGAIN, want write");
671 this->ServerInstance->SE->WantWrite(this);
675 this->QuitUser(ServerInstance, this, strerror(errno));
683 this->sendq = this->sendq.substr(n_sent);
684 // update the user's stats counters
685 this->bytes_out += n_sent;
687 if (n_sent != old_sendq_length)
689 ServerInstance->Log(DEBUG,"Not all written, want write");
690 this->ServerInstance->SE->WantWrite(this);
698 ServerInstance->Log(DEBUG,"Exception in userrec::FlushWriteBuf()");
702 void userrec::SetWriteError(const std::string &error)
706 ServerInstance->Log(DEBUG,"SetWriteError: %s",error.c_str());
707 // don't try to set the error twice, its already set take the first string.
708 if (this->WriteError.empty())
710 ServerInstance->Log(DEBUG,"Setting error string for %s to '%s'",this->nick,error.c_str());
711 this->WriteError = error;
717 ServerInstance->Log(DEBUG,"Exception in userrec::SetWriteError()");
721 const char* userrec::GetWriteError()
723 return this->WriteError.c_str();
726 void userrec::Oper(const std::string &opertype)
730 this->modes[UM_OPERATOR] = 1;
731 this->WriteServ("MODE %s :+o", this->nick);
732 FOREACH_MOD(I_OnOper, OnOper(this, opertype));
733 ServerInstance->Log(DEFAULT,"OPER: %s!%s@%s opered as type: %s", this->nick, this->ident, this->host, opertype.c_str());
734 strlcpy(this->oper, opertype.c_str(), NICKMAX - 1);
735 ServerInstance->all_opers.push_back(this);
736 FOREACH_MOD(I_OnPostOper,OnPostOper(this, opertype));
741 ServerInstance->Log(DEBUG,"Exception in userrec::Oper()");
745 void userrec::UnOper()
752 this->modes[UM_OPERATOR] = 0;
753 for (std::vector<userrec*>::iterator a = ServerInstance->all_opers.begin(); a < ServerInstance->all_opers.end(); a++)
757 ServerInstance->Log(DEBUG,"Oper removed from optimization list");
758 ServerInstance->all_opers.erase(a);
767 ServerInstance->Log(DEBUG,"Exception in userrec::UnOper()");
771 void userrec::QuitUser(InspIRCd* Instance, userrec *user, const std::string &quitreason)
773 user_hash::iterator iter = Instance->clientlist.find(user->nick);
774 std::string reason = quitreason;
776 if (reason.length() > MAXQUIT - 1)
777 reason.resize(MAXQUIT - 1);
780 user->Write("ERROR :Closing link (%s@%s) [%s]",user->ident,user->host,reason.c_str());
782 if (user->registered == REG_ALL)
784 user->PurgeEmptyChannels();
785 FOREACH_MOD_I(Instance,I_OnUserQuit,OnUserQuit(user,reason));
786 user->WriteCommonExcept("QUIT :%s",reason.c_str());
789 FOREACH_MOD_I(Instance,I_OnUserDisconnect,OnUserDisconnect(user));
793 if (Instance->Config->GetIOHook(user->GetPort()))
797 Instance->Config->GetIOHook(user->GetPort())->OnRawSocketClose(user->fd);
799 catch (ModuleException& modexcept)
801 Instance->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason());
805 Instance->SE->DelFd(user);
810 * this must come before the ServerInstance->SNO->WriteToSnoMaskso that it doesnt try to fill their buffer with anything
811 * if they were an oper with +sn +qQ.
813 if (user->registered == REG_ALL)
816 Instance->SNO->WriteToSnoMask('q',"Client exiting: %s!%s@%s [%s]",user->nick,user->ident,user->host,reason.c_str());
818 Instance->SNO->WriteToSnoMask('Q',"Client exiting on server %s: %s!%s@%s [%s]",user->server,user->nick,user->ident,user->host,reason.c_str());
822 if (iter != Instance->clientlist.end())
824 Instance->Log(DEBUG,"deleting user hash value %lx",(unsigned long)user);
827 if (find(Instance->local_users.begin(),Instance->local_users.end(),user) != Instance->local_users.end())
828 Instance->local_users.erase(find(Instance->local_users.begin(),Instance->local_users.end(),user));
830 Instance->clientlist.erase(iter);
840 WhoWasGroup::WhoWasGroup(userrec* user) : host(NULL), dhost(NULL), ident(NULL), server(NULL), gecos(NULL), signon(user->signon)
842 this->host = strdup(user->host);
843 this->dhost = strdup(user->dhost);
844 this->ident = strdup(user->ident);
845 this->server = user->server;
846 this->gecos = strdup(user->fullname);
849 WhoWasGroup::~WhoWasGroup()
861 /* every hour, run this function which removes all entries older than Config->WhoWasMaxKeep */
862 void MaintainWhoWas(InspIRCd* ServerInstance, time_t t)
864 for (whowas_users::iterator iter = ServerInstance->whowas.begin(); iter != ServerInstance->whowas.end(); iter++)
866 whowas_set* n = (whowas_set*)iter->second;
869 while ((n->begin() != n->end()) && ((*n->begin())->signon < t - ServerInstance->Config->WhoWasMaxKeep))
871 WhoWasGroup *a = *(n->begin());
873 n->erase(n->begin());
878 /* on rehash, refactor maps according to new conf values */
879 void PruneWhoWas(InspIRCd* ServerInstance, time_t t)
882 int groupsize = ServerInstance->Config->WhoWasGroupSize;
883 int maxgroups = ServerInstance->Config->WhoWasMaxGroups;
884 int maxkeep = ServerInstance->Config->WhoWasMaxKeep;
886 int groupcount = ServerInstance->whowas.size();
887 /* iterate whowas_fifo oldest first */
888 whowas_users_fifo::iterator iter, safeiter;
889 for (iter = ServerInstance->whowas_fifo.begin(); iter != ServerInstance->whowas_fifo.end(); iter++)
891 /** prune all groups that has expired due to new maxkeep time and
892 * also any group number higher than new maxgroups. The oldest are
893 * removed first due to iteration over whowas_fifo
895 if (groupcount > maxgroups || iter->first < t - maxkeep)
897 whowas_set* n = (whowas_set*)ServerInstance->whowas.find(iter->second)->second;
900 while (n->begin() != n->end())
902 WhoWasGroup *a = *(n->begin());
904 n->erase(n->begin());
907 ServerInstance->whowas.erase(iter->second);
908 /* use a safe iter copy for erase and set the orig iter old valid ref by decrementing it */
911 ServerInstance->whowas_fifo.erase(safeiter);
914 /* also trim individual groupsizes in case groupsize should have been lowered */
915 whowas_set* n = (whowas_set*)ServerInstance->whowas.find(iter->second)->second;
918 int nickcount = n->size();
919 while (n->begin() != n->end() && nickcount > groupsize)
921 WhoWasGroup *a = *(n->begin());
923 n->erase(n->begin());
934 /* adds or updates an entry in the whowas list */
935 void userrec::AddToWhoWas()
937 /* if whowas disabled */
938 if (ServerInstance->Config->WhoWasGroupSize == 0 || ServerInstance->Config->WhoWasMaxGroups == 0)
943 irc::whowas::whowas_users::iterator iter = ServerInstance->whowas.find(this->nick);
945 ServerInstance->Log(DEBUG,"Add to whowas lists");
947 if (iter == ServerInstance->whowas.end())
949 ServerInstance->Log(DEBUG,"Adding new whowas set for %s",this->nick);
950 irc::whowas::whowas_set* n = new irc::whowas::whowas_set;
951 irc::whowas::WhoWasGroup *a = new irc::whowas::WhoWasGroup(this);
953 ServerInstance->whowas[this->nick] = n;
954 ServerInstance->whowas_fifo[ServerInstance->Time()] = this->nick;
955 if ((int)(ServerInstance->whowas.size()) > ServerInstance->Config->WhoWasMaxGroups)
957 ServerInstance->Log(DEBUG,"Maxgroups of %d reached deleting oldest group '%s'",ServerInstance->Config->WhoWasMaxGroups, ServerInstance->whowas_fifo.begin()->second.c_str());
958 ServerInstance->whowas.erase(ServerInstance->whowas_fifo.begin()->second);
959 ServerInstance->whowas_fifo.erase(ServerInstance->whowas_fifo.begin());
964 irc::whowas::whowas_set* group = (irc::whowas::whowas_set*)iter->second;
966 ServerInstance->Log(DEBUG,"Using existing whowas group for %s",this->nick);
968 if ((int)(group->size()) >= ServerInstance->Config->WhoWasGroupSize)
970 ServerInstance->Log(DEBUG,"Trimming existing group '%s' to %d entries",this->nick, ServerInstance->Config->WhoWasGroupSize);
971 irc::whowas::WhoWasGroup *a = (irc::whowas::WhoWasGroup*)*(group->begin());
976 irc::whowas::WhoWasGroup *a = new irc::whowas::WhoWasGroup(this);
981 /* add a client connection to the sockets list */
982 void userrec::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, insp_inaddr ip)
984 std::string tempnick = ConvToStr(socket) + "-unknown";
985 user_hash::iterator iter = Instance->clientlist.find(tempnick);
986 const char *ipaddr = insp_ntoa(ip);
992 * as these nicknames are 'RFC impossible', we can be sure nobody is going to be
993 * using one as a registered connection. As they are per fd, we can also safely assume
994 * that we wont have collisions. Therefore, if the nick exists in the list, its only
995 * used by a dead socket, erase the iterator so that the new client may reclaim it.
996 * this was probably the cause of 'server ignores me when i hammer it with reconnects'
997 * issue in earlier alphas/betas
999 if (iter != Instance->clientlist.end())
1001 userrec* goner = iter->second;
1003 Instance->clientlist.erase(iter);
1006 Instance->Log(DEBUG,"AddClient: %d %d %s",socket,port,ipaddr);
1008 New = new userrec(Instance);
1009 Instance->clientlist[tempnick] = New;
1011 strlcpy(New->nick,tempnick.c_str(),NICKMAX-1);
1013 New->server = Instance->FindServerNamePtr(Instance->Config->ServerName);
1014 /* We don't need range checking here, we KNOW 'unknown\0' will fit into the ident field. */
1015 strcpy(New->ident, "unknown");
1017 New->registered = REG_NONE;
1018 New->signon = Instance->Time() + Instance->Config->dns_timeout;
1021 New->SetSockAddr(AF_FAMILY, ipaddr, port);
1023 /* Smarter than your average bear^H^H^H^Hset of strlcpys. */
1024 for (const char* temp = New->GetIPString(); *temp && j < 64; temp++, j++)
1025 New->dhost[j] = New->host[j] = *temp;
1026 New->dhost[j] = New->host[j] = 0;
1028 Instance->AddLocalClone(New);
1029 Instance->AddGlobalClone(New);
1031 // set the registration timeout for this user
1032 unsigned long class_regtimeout = 90;
1033 int class_flood = 0;
1034 long class_threshold = 5;
1035 long class_sqmax = 262144; // 256kb
1036 long class_rqmax = 4096; // 4k
1038 for (ClassVector::iterator i = Instance->Config->Classes.begin(); i != Instance->Config->Classes.end(); i++)
1040 if ((i->type == CC_ALLOW) && (match(ipaddr,i->host.c_str(),true)))
1042 class_regtimeout = (unsigned long)i->registration_timeout;
1043 class_flood = i->flood;
1044 New->pingmax = i->pingtime;
1045 class_threshold = i->threshold;
1046 class_sqmax = i->sendqmax;
1047 class_rqmax = i->recvqmax;
1052 New->nping = Instance->Time() + New->pingmax + Instance->Config->dns_timeout;
1053 New->timeout = Instance->Time() + class_regtimeout;
1054 New->flood = class_flood;
1055 New->threshold = class_threshold;
1056 New->sendqmax = class_sqmax;
1057 New->recvqmax = class_rqmax;
1059 Instance->local_users.push_back(New);
1061 if ((Instance->local_users.size() > Instance->Config->SoftLimit) || (Instance->local_users.size() >= MAXCLIENTS))
1063 Instance->WriteOpers("*** Warning: softlimit value has been reached: %d clients", Instance->Config->SoftLimit);
1064 userrec::QuitUser(Instance, New,"No more connections allowed");
1070 * this is done as a safety check to keep the file descriptors within range of fd_ref_table.
1071 * its a pretty big but for the moment valid assumption:
1072 * file descriptors are handed out starting at 0, and are recycled as theyre freed.
1073 * therefore if there is ever an fd over 65535, 65536 clients must be connected to the
1074 * irc server at once (or the irc server otherwise initiating this many connections, files etc)
1075 * which for the time being is a physical impossibility (even the largest networks dont have more
1076 * than about 10,000 users on ONE server!)
1078 if ((unsigned int)socket >= MAX_DESCRIPTORS)
1080 userrec::QuitUser(Instance, New, "Server is full");
1084 New->exempt = (Instance->XLines->matches_exception(New) != NULL);
1087 ZLine* r = Instance->XLines->matches_zline(ipaddr);
1090 char reason[MAXBUF];
1091 snprintf(reason,MAXBUF,"Z-Lined: %s",r->reason);
1092 userrec::QuitUser(Instance, New, reason);
1099 if (!Instance->SE->AddFd(New))
1101 userrec::QuitUser(Instance, New, "Internal error handling connection");
1106 /* NOTE: even if dns lookups are *off*, we still need to display this.
1107 * BOPM and other stuff requires it.
1109 New->WriteServ("NOTICE Auth :*** Looking up your hostname...");
1112 long userrec::GlobalCloneCount()
1114 clonemap::iterator x = ServerInstance->global_clones.find(this->GetIPString());
1115 if (x != ServerInstance->global_clones.end())
1121 long userrec::LocalCloneCount()
1123 clonemap::iterator x = ServerInstance->local_clones.find(this->GetIPString());
1124 if (x != ServerInstance->local_clones.end())
1130 void userrec::FullConnect(CullList* Goners)
1132 ServerInstance->stats->statsConnects++;
1133 this->idle_lastmsg = ServerInstance->Time();
1135 ConnectClass a = this->GetClass();
1137 if (a.type == CC_DENY)
1139 Goners->AddItem(this,"Unauthorised connection");
1143 if ((*(a.pass.c_str())) && (!this->haspassed))
1145 Goners->AddItem(this,"Invalid password");
1149 if (this->LocalCloneCount() > a.maxlocal)
1151 Goners->AddItem(this, "No more connections allowed from your host via this connect class (local)");
1152 ServerInstance->WriteOpers("*** WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a.maxlocal, this->GetIPString());
1155 else if (this->GlobalCloneCount() > a.maxglobal)
1157 Goners->AddItem(this, "No more connections allowed from your host via this connect class (global)");
1158 ServerInstance->WriteOpers("*** WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s",a.maxglobal, this->GetIPString());
1164 GLine* r = ServerInstance->XLines->matches_gline(this);
1168 char reason[MAXBUF];
1169 snprintf(reason,MAXBUF,"G-Lined: %s",r->reason);
1170 Goners->AddItem(this, reason);
1174 KLine* n = ServerInstance->XLines->matches_kline(this);
1178 char reason[MAXBUF];
1179 snprintf(reason,MAXBUF,"K-Lined: %s",n->reason);
1180 Goners->AddItem(this, reason);
1186 this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network);
1187 this->WriteServ("001 %s :Welcome to the %s IRC Network %s!%s@%s",this->nick, ServerInstance->Config->Network, this->nick, this->ident, this->host);
1188 this->WriteServ("002 %s :Your host is %s, running version %s",this->nick,ServerInstance->Config->ServerName,VERSION);
1189 this->WriteServ("003 %s :This server was created %s %s", this->nick, __TIME__, __DATE__);
1190 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());
1192 ServerInstance->Config->Send005(this);
1197 * fix 3 by brain, move registered = 7 below these so that spurious modes and host
1198 * changes dont go out onto the network and produce 'fake direction'.
1200 FOREACH_MOD(I_OnUserConnect,OnUserConnect(this));
1202 this->registered = REG_ALL;
1204 FOREACH_MOD(I_OnPostConnect,OnPostConnect(this));
1206 ServerInstance->SNO->WriteToSnoMask('c',"Client connecting on port %d: %s!%s@%s [%s]", this->GetPort(), this->nick, this->ident, this->host, this->GetIPString());
1209 /** userrec::UpdateNick()
1210 * re-allocates a nick in the user_hash after they change nicknames,
1211 * returns a pointer to the new user as it may have moved
1213 userrec* userrec::UpdateNickHash(const char* New)
1217 //user_hash::iterator newnick;
1218 user_hash::iterator oldnick = ServerInstance->clientlist.find(this->nick);
1220 if (!strcasecmp(this->nick,New))
1221 return oldnick->second;
1223 if (oldnick == ServerInstance->clientlist.end())
1224 return NULL; /* doesnt exist */
1226 userrec* olduser = oldnick->second;
1227 ServerInstance->clientlist[New] = olduser;
1228 ServerInstance->clientlist.erase(oldnick);
1229 return ServerInstance->clientlist[New];
1234 ServerInstance->Log(DEBUG,"Exception in userrec::UpdateNickHash()");
1239 bool userrec::ForceNickChange(const char* newnick)
1245 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(this, newnick));
1249 ServerInstance->stats->statsCollisions++;
1253 if (ServerInstance->XLines->matches_qline(newnick))
1255 ServerInstance->stats->statsCollisions++;
1259 if (this->registered == REG_ALL)
1261 const char* pars[1];
1263 std::string cmd = "NICK";
1264 return (ServerInstance->Parser->CallHandler(cmd, pars, 1, this) == CMD_SUCCESS);
1271 ServerInstance->Log(DEBUG,"Exception in userrec::ForceNickChange()");
1276 void userrec::SetSockAddr(int protocol_family, const char* ip, int port)
1278 switch (protocol_family)
1280 #ifdef SUPPORT_IP6LINKS
1283 ServerInstance->Log(DEBUG,"Set inet6 protocol address");
1284 sockaddr_in6* sin = new sockaddr_in6;
1285 sin->sin6_family = AF_INET6;
1286 sin->sin6_port = port;
1287 inet_pton(AF_INET6, ip, &sin->sin6_addr);
1288 this->ip = (sockaddr*)sin;
1294 ServerInstance->Log(DEBUG,"Set inet4 protocol address");
1295 sockaddr_in* sin = new sockaddr_in;
1296 sin->sin_family = AF_INET;
1297 sin->sin_port = port;
1298 inet_pton(AF_INET, ip, &sin->sin_addr);
1299 this->ip = (sockaddr*)sin;
1303 ServerInstance->Log(DEBUG,"Ut oh, I dont know protocol %d to be set on '%s'!", protocol_family, this->nick);
1308 int userrec::GetPort()
1310 if (this->ip == NULL)
1313 switch (this->GetProtocolFamily())
1315 #ifdef SUPPORT_IP6LINKS
1318 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1319 return sin->sin6_port;
1325 sockaddr_in* sin = (sockaddr_in*)this->ip;
1326 return sin->sin_port;
1330 ServerInstance->Log(DEBUG,"Ut oh, '%s' has an unknown protocol family!",this->nick);
1336 int userrec::GetProtocolFamily()
1338 if (this->ip == NULL)
1341 sockaddr_in* sin = (sockaddr_in*)this->ip;
1342 return sin->sin_family;
1345 const char* userrec::GetIPString()
1347 static char buf[1024];
1349 if (this->ip == NULL)
1352 switch (this->GetProtocolFamily())
1354 #ifdef SUPPORT_IP6LINKS
1357 static char temp[1024];
1359 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1360 inet_ntop(sin->sin6_family, &sin->sin6_addr, buf, sizeof(buf));
1361 /* IP addresses starting with a : on irc are a Bad Thing (tm) */
1364 strlcpy(&temp[1], buf, sizeof(temp) - 1);
1374 sockaddr_in* sin = (sockaddr_in*)this->ip;
1375 inet_ntop(sin->sin_family, &sin->sin_addr, buf, sizeof(buf));
1380 ServerInstance->Log(DEBUG,"Ut oh, '%s' has an unknown protocol family!",this->nick);
1386 const char* userrec::GetIPString(char* buf)
1388 if (this->ip == NULL)
1394 switch (this->GetProtocolFamily())
1396 #ifdef SUPPORT_IP6LINKS
1399 static char temp[1024];
1401 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1402 inet_ntop(sin->sin6_family, &sin->sin6_addr, buf, sizeof(buf));
1403 /* IP addresses starting with a : on irc are a Bad Thing (tm) */
1406 strlcpy(&temp[1], buf, sizeof(temp) - 1);
1408 strlcpy(buf, temp, sizeof(temp));
1416 sockaddr_in* sin = (sockaddr_in*)this->ip;
1417 inet_ntop(sin->sin_family, &sin->sin_addr, buf, sizeof(buf));
1423 ServerInstance->Log(DEBUG,"Ut oh, '%s' has an unknown protocol family!",this->nick);
1429 /** NOTE: We cannot pass a const reference to this method.
1430 * The string is changed by the workings of the method,
1431 * so that if we pass const ref, we end up copying it to
1432 * something we can change anyway. Makes sense to just let
1433 * the compiler do that copy for us.
1435 void userrec::Write(std::string text)
1437 if ((this->fd < 0) || (this->fd > MAX_DESCRIPTORS))
1442 text.append("\r\n");
1446 ServerInstance->Log(DEBUG,"Exception in userrec::Write() std::string::append");
1450 if (ServerInstance->Config->GetIOHook(this->GetPort()))
1454 ServerInstance->Config->GetIOHook(this->GetPort())->OnRawSocketWrite(this->fd, text.data(), text.length());
1456 catch (ModuleException& modexcept)
1458 ServerInstance->Log(DEBUG,"Module exception caught: %s",modexcept.GetReason());
1463 this->AddWriteBuf(text);
1465 ServerInstance->stats->statsSent += text.length();
1466 this->ServerInstance->SE->WantWrite(this);
1471 void userrec::Write(const char *text, ...)
1474 char textbuffer[MAXBUF];
1476 va_start(argsPtr, text);
1477 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1480 this->Write(std::string(textbuffer));
1483 void userrec::WriteServ(const std::string& text)
1485 char textbuffer[MAXBUF];
1487 snprintf(textbuffer,MAXBUF,":%s %s",ServerInstance->Config->ServerName,text.c_str());
1488 this->Write(std::string(textbuffer));
1492 * Same as Write(), except `text' is prefixed with `:server.name '.
1494 void userrec::WriteServ(const char* text, ...)
1497 char textbuffer[MAXBUF];
1499 va_start(argsPtr, text);
1500 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1503 this->WriteServ(std::string(textbuffer));
1507 void userrec::WriteFrom(userrec *user, const std::string &text)
1511 snprintf(tb,MAXBUF,":%s %s",user->GetFullHost(),text.c_str());
1513 this->Write(std::string(tb));
1517 /* write text from an originating user to originating user */
1519 void userrec::WriteFrom(userrec *user, const char* text, ...)
1522 char textbuffer[MAXBUF];
1524 va_start(argsPtr, text);
1525 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1528 this->WriteFrom(user, std::string(textbuffer));
1532 /* write text to an destination user from a source user (e.g. user privmsg) */
1534 void userrec::WriteTo(userrec *dest, const char *data, ...)
1536 char textbuffer[MAXBUF];
1539 va_start(argsPtr, data);
1540 vsnprintf(textbuffer, MAXBUF, data, argsPtr);
1543 this->WriteTo(dest, std::string(textbuffer));
1546 void userrec::WriteTo(userrec *dest, const std::string &data)
1548 dest->WriteFrom(this, data);
1552 void userrec::WriteCommon(const char* text, ...)
1554 char textbuffer[MAXBUF];
1557 if (this->registered != REG_ALL)
1560 va_start(argsPtr, text);
1561 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1564 this->WriteCommon(std::string(textbuffer));
1567 void userrec::WriteCommon(const std::string &text)
1571 bool sent_to_at_least_one = false;
1573 if (this->registered != REG_ALL)
1578 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1580 CUList* ulist = v->first->GetUsers();
1581 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1583 if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
1585 already_sent[i->second->fd] = uniq_id;
1586 i->second->WriteFrom(this, std::string(text));
1587 sent_to_at_least_one = true;
1593 * if the user was not in any channels, no users will receive the text. Make sure the user
1594 * receives their OWN message for WriteCommon
1596 if (!sent_to_at_least_one)
1598 this->WriteFrom(this,std::string(text));
1604 ServerInstance->Log(DEBUG,"Exception in userrec::WriteCommon()");
1609 /* write a formatted string to all users who share at least one common
1610 * channel, NOT including the source user e.g. for use in QUIT
1613 void userrec::WriteCommonExcept(const char* text, ...)
1615 char textbuffer[MAXBUF];
1618 va_start(argsPtr, text);
1619 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1622 this->WriteCommonExcept(std::string(textbuffer));
1625 void userrec::WriteCommonExcept(const std::string &text)
1627 bool quit_munge = false;
1628 char oper_quit[MAXBUF];
1629 char textbuffer[MAXBUF];
1631 strlcpy(textbuffer, text.c_str(), MAXBUF);
1633 if (this->registered != REG_ALL)
1638 /* TODO: We need some form of WriteCommonExcept that will send two lines, one line to
1639 * opers and the other line to non-opers, then all this hidebans and hidesplits gunk
1642 if (ServerInstance->Config->HideSplits)
1644 char* check = textbuffer + 6;
1646 if (!strncasecmp(textbuffer, "QUIT :",6))
1648 std::stringstream split(check);
1649 std::string server_one;
1650 std::string server_two;
1652 split >> server_one;
1653 split >> server_two;
1655 if ((ServerInstance->FindServerName(server_one)) && (ServerInstance->FindServerName(server_two)))
1657 strlcpy(oper_quit,textbuffer,MAXQUIT);
1658 strlcpy(check,"*.net *.split",MAXQUIT);
1664 if ((ServerInstance->Config->HideBans) && (!quit_munge))
1666 if ((!strncasecmp(textbuffer, "QUIT :G-Lined:",14)) || (!strncasecmp(textbuffer, "QUIT :K-Lined:",14))
1667 || (!strncasecmp(textbuffer, "QUIT :Q-Lined:",14)) || (!strncasecmp(textbuffer, "QUIT :Z-Lined:",14)))
1669 char* check = textbuffer + 13;
1670 strlcpy(oper_quit,textbuffer,MAXQUIT);
1671 *check = 0; // We don't need to strlcpy, we just chop it from the :
1676 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1678 CUList *ulist = v->first->GetUsers();
1679 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1681 if (this != i->second)
1683 if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
1685 already_sent[i->second->fd] = uniq_id;
1687 i->second->WriteFrom(this, *i->second->oper ? std::string(oper_quit) : std::string(textbuffer));
1689 i->second->WriteFrom(this, std::string(textbuffer));
1697 void userrec::WriteWallOps(const std::string &text)
1699 /* Does nothing if theyre not opered */
1700 if ((!*this->oper) && (IS_LOCAL(this)))
1703 std::string wallop = "WALLOPS :";
1707 wallop.append(text);
1711 ServerInstance->Log(DEBUG,"Exception in userrec::Write() std::string::append");
1715 for (std::vector<userrec*>::const_iterator i = ServerInstance->local_users.begin(); i != ServerInstance->local_users.end(); i++)
1718 if ((IS_LOCAL(t)) && (t->modes[UM_WALLOPS]))
1719 this->WriteTo(t,wallop);
1723 void userrec::WriteWallOps(const char* text, ...)
1725 char textbuffer[MAXBUF];
1728 va_start(argsPtr, text);
1729 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1732 this->WriteWallOps(std::string(textbuffer));
1735 /* return 0 or 1 depending if users u and u2 share one or more common channels
1736 * (used by QUIT, NICK etc which arent channel specific notices)
1738 * The old algorithm in 1.0 for this was relatively inefficient, iterating over
1739 * the first users channels then the second users channels within the outer loop,
1740 * therefore it was a maximum of x*y iterations (upon returning 0 and checking
1741 * all possible iterations). However this new function instead checks against the
1742 * channel's userlist in the inner loop which is a std::map<userrec*,userrec*>
1743 * and saves us time as we already know what pointer value we are after.
1744 * Don't quote me on the maths as i am not a mathematician or computer scientist,
1745 * but i believe this algorithm is now x+(log y) maximum iterations instead.
1747 bool userrec::SharesChannelWith(userrec *other)
1749 if ((!other) || (this->registered != REG_ALL) || (other->registered != REG_ALL))
1753 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1755 /* Eliminate the inner loop (which used to be ~equal in size to the outer loop)
1756 * by replacing it with a map::find which *should* be more efficient
1758 if (i->first->HasUser(other))
1764 int userrec::CountChannels()
1766 return ChannelCount;
1769 void userrec::ModChannelCount(int n)
1774 bool userrec::ChangeName(const char* gecos)
1776 if (!strcmp(gecos, this->fullname))
1782 FOREACH_RESULT(I_OnChangeLocalUserGECOS,OnChangeLocalUserGECOS(this,gecos));
1785 FOREACH_MOD(I_OnChangeName,OnChangeName(this,gecos));
1787 strlcpy(this->fullname,gecos,MAXGECOS+1);
1791 bool userrec::ChangeDisplayedHost(const char* host)
1793 if (!strcmp(host, this->dhost))
1799 FOREACH_RESULT(I_OnChangeLocalUserHost,OnChangeLocalUserHost(this,host));
1802 FOREACH_MOD(I_OnChangeHost,OnChangeHost(this,host));
1804 if (this->ServerInstance->Config->CycleHosts)
1805 this->WriteCommonExcept("QUIT :Changing hosts");
1807 /* Fix by Om: userrec::dhost is 65 long, this was truncating some long hosts */
1808 strlcpy(this->dhost,host,64);
1810 if (this->ServerInstance->Config->CycleHosts)
1812 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1814 i->first->WriteAllExceptSender(this, false, 0, "JOIN %s", i->first->name);
1815 std::string n = this->ServerInstance->Modes->ModeString(this, i->first);
1817 i->first->WriteAllExceptSender(this, true, 0, "MODE %s +%s", i->first->name, n.c_str());
1822 this->WriteServ("396 %s %s :is now your hidden host",this->nick,this->dhost);
1827 bool userrec::ChangeIdent(const char* newident)
1829 if (!strcmp(newident, this->ident))
1832 if (this->ServerInstance->Config->CycleHosts)
1833 this->WriteCommonExcept("%s","QUIT :Changing ident");
1835 strlcpy(this->ident, newident, IDENTMAX+2);
1837 if (this->ServerInstance->Config->CycleHosts)
1839 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1841 i->first->WriteAllExceptSender(this, false, 0, "JOIN %s", i->first->name);
1842 std::string n = this->ServerInstance->Modes->ModeString(this, i->first);
1844 i->first->WriteAllExceptSender(this, true, 0, "MODE %s +%s", i->first->name, n.c_str());
1851 void userrec::NoticeAll(char* text, ...)
1853 char textbuffer[MAXBUF];
1854 char formatbuffer[MAXBUF];
1857 va_start(argsPtr, text);
1858 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1861 snprintf(formatbuffer,MAXBUF,"NOTICE $* :%s",textbuffer);
1863 for (std::vector<userrec*>::const_iterator i = ServerInstance->local_users.begin(); i != ServerInstance->local_users.end(); i++)
1866 t->WriteFrom(this, std::string(formatbuffer));
1871 std::string userrec::ChannelList(userrec* source)
1876 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1878 /* If the target is the same as the sender, let them see all their channels.
1879 * If the channel is NOT private/secret OR the user shares a common channel
1880 * If the user is an oper, and the <options:operspywhois> option is set.
1882 if ((source == this) || (*source->oper && ServerInstance->Config->OperSpyWhois) || (((!i->first->modes[CM_PRIVATE]) && (!i->first->modes[CM_SECRET])) || (i->first->HasUser(source))))
1884 list.append(i->first->GetPrefixChar(this)).append(i->first->name).append(" ");
1891 ServerInstance->Log(DEBUG,"Exception in userrec::ChannelList()");
1896 void userrec::SplitChanList(userrec* dest, const std::string &cl)
1899 std::ostringstream prefix;
1900 std::string::size_type start, pos, length;
1904 prefix << this->nick << " " << dest->nick << " :";
1905 line = prefix.str();
1906 int namelen = strlen(ServerInstance->Config->ServerName) + 6;
1908 for (start = 0; (pos = cl.find(' ', start)) != std::string::npos; start = pos+1)
1910 length = (pos == std::string::npos) ? cl.length() : pos;
1912 if (line.length() + namelen + length - start > 510)
1914 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1915 line = prefix.str();
1918 if(pos == std::string::npos)
1920 line.append(cl.substr(start, length - start));
1925 line.append(cl.substr(start, length - start + 1));
1931 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1937 ServerInstance->Log(DEBUG,"Exception in userrec::SplitChanList()");
1942 /* looks up a users password for their connection class (<ALLOW>/<DENY> tags)
1943 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1944 * then their ip will be taken as 'priority' anyway, so for example,
1945 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1947 ConnectClass& userrec::GetClass()
1949 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1951 if ((match(this->GetIPString(),i->host.c_str(),true)) || (match(this->host,i->host.c_str())))
1955 return *(ServerInstance->Config->Classes.begin());
1958 void userrec::PurgeEmptyChannels()
1960 std::vector<chanrec*> to_delete;
1962 // firstly decrement the count on each channel
1963 for (UCListIter f = this->chans.begin(); f != this->chans.end(); f++)
1965 f->first->RemoveAllPrefixes(this);
1966 if (f->first->DelUser(this) == 0)
1968 /* No users left in here, mark it for deletion */
1971 to_delete.push_back(f->first);
1975 ServerInstance->Log(DEBUG,"Exception in userrec::PurgeEmptyChannels to_delete.push_back()");
1980 for (std::vector<chanrec*>::iterator n = to_delete.begin(); n != to_delete.end(); n++)
1982 chanrec* thischan = *n;
1983 chan_hash::iterator i2 = ServerInstance->chanlist.find(thischan->name);
1984 if (i2 != ServerInstance->chanlist.end())
1986 FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(i2->second));
1988 ServerInstance->chanlist.erase(i2);
1995 void userrec::ShowMOTD()
1997 if (!ServerInstance->Config->MOTD.size())
1999 this->WriteServ("422 %s :Message of the day file is missing.",this->nick);
2002 this->WriteServ("375 %s :%s message of the day", this->nick, ServerInstance->Config->ServerName);
2004 for (file_cache::iterator i = ServerInstance->Config->MOTD.begin(); i != ServerInstance->Config->MOTD.end(); i++)
2005 this->WriteServ("372 %s :- %s",this->nick,i->c_str());
2007 this->WriteServ("376 %s :End of message of the day.", this->nick);
2010 void userrec::ShowRULES()
2012 if (!ServerInstance->Config->RULES.size())
2014 this->WriteServ("NOTICE %s :Rules file is missing.",this->nick);
2017 this->WriteServ("NOTICE %s :%s rules",this->nick,ServerInstance->Config->ServerName);
2019 for (file_cache::iterator i = ServerInstance->Config->RULES.begin(); i != ServerInstance->Config->RULES.end(); i++)
2020 this->WriteServ("NOTICE %s :%s",this->nick,i->c_str());
2022 this->WriteServ("NOTICE %s :End of %s rules.",this->nick,ServerInstance->Config->ServerName);
2025 void userrec::HandleEvent(EventType et, int errornum)
2027 /* WARNING: May delete this user! */
2033 ServerInstance->ProcessUser(this);
2036 this->FlushWriteBuf();
2039 /** This should be safe, but dont DARE do anything after it -- Brain */
2040 userrec::QuitUser(ServerInstance, this, errornum ? strerror(errornum) : "EOF from client");
2046 ServerInstance->Log(DEBUG,"Exception in userrec::HandleEvent intercepted");