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, void** values, int* types)
66 char* TypeName = (char*)values[0];
67 char* Classes = (char*)values[1];
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, void** values, int* types)
76 char* ClassName = (char*)values[0];
77 char* CommandList = (char*)values[1];
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(), false);
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, bool forward) :
166 Resolver(Instance, to_resolve, forward ? DNS_QUERY_FORWARD : DNS_QUERY_REVERSE), bound_user(user)
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)
183 bound_user->res_forward = new UserResolver(this->ServerInstance, this->bound_user, result, true);
184 this->ServerInstance->AddResolver(bound_user->res_forward);
187 catch (ModuleException& e)
189 ServerInstance->Log(DEBUG,"Error in resolver: %s",e.GetReason());
192 else if ((this->fwd) && (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user))
194 /* Both lookups completed */
195 if (this->bound_user->GetIPString() == result)
197 std::string hostname = this->bound_user->stored_host;
198 if (hostname.length() < 65)
200 /* Check we didnt time out */
201 if (this->bound_user->registered != REG_ALL)
203 /* Hostnames starting with : are not a good thing (tm) */
204 if (*(hostname.c_str()) == ':')
205 hostname = "0" + hostname;
207 this->bound_user->WriteServ("NOTICE Auth :*** Found your hostname (%s)", hostname.c_str());
208 this->bound_user->dns_done = true;
209 strlcpy(this->bound_user->dhost, hostname.c_str(),64);
210 strlcpy(this->bound_user->host, hostname.c_str(),64);
215 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());
220 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());
225 void UserResolver::OnError(ResolverError e, const std::string &errormessage)
227 if (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user)
229 /* Error message here */
230 this->bound_user->WriteServ("NOTICE Auth :*** Could not resolve your hostname, using your IP address (%s) instead.", this->bound_user->GetIPString());
231 this->bound_user->dns_done = true;
236 bool userrec::IsNoticeMaskSet(unsigned char sm)
238 return (snomasks[sm-65]);
241 void userrec::SetNoticeMask(unsigned char sm, bool value)
243 snomasks[sm-65] = value;
246 const char* userrec::FormatNoticeMasks()
248 static char data[MAXBUF];
251 for (int n = 0; n < 64; n++)
254 data[offset++] = n+65;
263 bool userrec::IsModeSet(unsigned char m)
265 return (modes[m-65]);
268 void userrec::SetMode(unsigned char m, bool value)
273 const char* userrec::FormatModes()
275 static char data[MAXBUF];
277 for (int n = 0; n < 64; n++)
280 data[offset++] = n+65;
286 userrec::userrec(InspIRCd* Instance) : ServerInstance(Instance)
288 ServerInstance->Log(DEBUG,"userrec::userrec(): Instance: %08x",ServerInstance);
289 // the PROPER way to do it, AVOID bzero at *ALL* costs
290 *password = *nick = *ident = *host = *dhost = *fullname = *awaymsg = *oper = 0;
291 server = (char*)Instance->FindServerNamePtr(Instance->Config->ServerName);
292 reset_due = ServerInstance->Time();
293 lines_in = lastping = signon = idle_lastmsg = nping = registered = 0;
294 ChannelCount = timeout = flood = bytes_in = bytes_out = cmds_in = cmds_out = 0;
295 haspassed = dns_done = false;
300 res_forward = res_reverse = NULL;
304 chans.resize(MAXCHANS);
305 memset(modes,0,sizeof(modes));
306 memset(snomasks,0,sizeof(snomasks));
308 for (unsigned int n = 0; n < MAXCHANS; n++)
310 chans[n] = new ucrec();
311 chans[n]->channel = NULL;
312 chans[n]->uc_modes = 0;
318 for (std::vector<ucrec*>::iterator n = chans.begin(); n != chans.end(); n++)
320 ucrec* x = (ucrec*)*n;
326 if (this->GetProtocolFamily() == AF_INET)
328 delete (sockaddr_in*)ip;
330 #ifdef SUPPORT_IP6LINKS
333 delete (sockaddr_in6*)ip;
339 /* XXX - minor point, other *Host functions return a char *, this one creates it. Might be nice to be consistant? */
340 void userrec::MakeHost(char* nhost)
342 /* This is much faster than snprintf */
344 for(char* n = ident; *n; n++)
347 for(char* n = host; *n; n++)
352 void userrec::CloseSocket()
354 shutdown(this->fd,2);
358 char* userrec::GetFullHost()
360 static char result[MAXBUF];
362 for(char* n = nick; *n; n++)
365 for(char* n = ident; *n; n++)
368 for(char* n = dhost; *n; n++)
374 char* userrec::MakeWildHost()
376 static char nresult[MAXBUF];
378 *t++ = '*'; *t++ = '!';
379 *t++ = '*'; *t++ = '@';
380 for(char* n = dhost; *n; n++)
386 int userrec::ReadData(void* buffer, size_t size)
390 return read(this->fd, buffer, size);
397 char* userrec::GetFullRealHost()
399 static char fresult[MAXBUF];
401 for(char* n = nick; *n; n++)
404 for(char* n = ident; *n; n++)
407 for(char* n = host; *n; n++)
413 bool userrec::IsInvited(irc::string &channel)
415 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
417 irc::string compare = i->channel;
419 if (compare == channel)
427 InvitedList* userrec::GetInviteList()
432 void userrec::InviteTo(irc::string &channel)
436 invites.push_back(i);
439 void userrec::RemoveInvite(irc::string &channel)
441 ServerInstance->Log(DEBUG,"Removing invites");
445 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
447 irc::string compare = i->channel;
449 if (compare == channel)
458 bool userrec::HasPermission(const std::string &command)
465 * users on remote servers can completely bypass all permissions based checks.
466 * This prevents desyncs when one server has different type/class tags to another.
467 * That having been said, this does open things up to the possibility of source changes
468 * allowing remote kills, etc - but if they have access to the src, they most likely have
469 * access to the conf - so it's an end to a means either way.
474 // are they even an oper at all?
477 opertype_t::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper);
478 if (iter_opertype != ServerInstance->Config->opertypes.end())
480 char* Classes = strdup(iter_opertype->second);
481 char* myclass = strtok_r(Classes," ",&savept);
484 operclass_t::iterator iter_operclass = ServerInstance->Config->operclass.find(myclass);
485 if (iter_operclass != ServerInstance->Config->operclass.end())
487 char* CommandList = strdup(iter_operclass->second);
488 mycmd = strtok_r(CommandList," ",&savept2);
491 if ((!strcasecmp(mycmd,command.c_str())) || (*mycmd == '*'))
497 mycmd = strtok_r(NULL," ",&savept2);
501 myclass = strtok_r(NULL," ",&savept);
509 /** NOTE: We cannot pass a const reference to this method.
510 * The string is changed by the workings of the method,
511 * so that if we pass const ref, we end up copying it to
512 * something we can change anyway. Makes sense to just let
513 * the compiler do that copy for us.
515 bool userrec::AddBuffer(std::string a)
519 std::string::size_type i = a.rfind('\r');
521 while (i != std::string::npos)
530 if (recvq.length() > (unsigned)this->recvqmax)
532 this->SetWriteError("RecvQ exceeded");
533 ServerInstance->WriteOpers("*** User %s RecvQ of %d exceeds connect class maximum of %d",this->nick,recvq.length(),this->recvqmax);
542 ServerInstance->Log(DEBUG,"Exception in userrec::AddBuffer()");
547 bool userrec::BufferIsReady()
549 return (recvq.find('\n') != std::string::npos);
552 void userrec::ClearBuffer()
557 std::string userrec::GetBuffer()
564 /* Strip any leading \r or \n off the string.
565 * Usually there are only one or two of these,
566 * so its is computationally cheap to do.
568 while ((*recvq.begin() == '\r') || (*recvq.begin() == '\n'))
569 recvq.erase(recvq.begin());
571 for (std::string::iterator x = recvq.begin(); x != recvq.end(); x++)
573 /* Find the first complete line, return it as the
574 * result, and leave the recvq as whats left
578 std::string ret = std::string(recvq.begin(), x);
579 recvq.erase(recvq.begin(), x + 1);
588 ServerInstance->Log(DEBUG,"Exception in userrec::GetBuffer()");
593 void userrec::AddWriteBuf(const std::string &data)
595 if (*this->GetWriteError())
598 if (sendq.length() + data.length() > (unsigned)this->sendqmax)
601 * Fix by brain - Set the error text BEFORE calling writeopers, because
602 * if we dont it'll recursively call here over and over again trying
603 * to repeatedly add the text to the sendq!
605 this->SetWriteError("SendQ exceeded");
606 ServerInstance->WriteOpers("*** User %s SendQ of %d exceeds connect class maximum of %d",this->nick,sendq.length() + data.length(),this->sendqmax);
612 if (data.length() > 512)
614 std::string newdata(data);
616 newdata.append("\r\n");
617 sendq.append(newdata);
626 this->SetWriteError("SendQ exceeded");
627 ServerInstance->WriteOpers("*** User %s SendQ got an exception",this->nick);
631 // send AS MUCH OF THE USERS SENDQ as we are able to (might not be all of it)
632 void userrec::FlushWriteBuf()
636 if ((this->fd == FD_MAGIC_NUMBER) || (*this->GetWriteError()))
640 if ((sendq.length()) && (this->fd != FD_MAGIC_NUMBER))
642 int old_sendq_length = sendq.length();
643 const char* tb = this->sendq.c_str();
644 int n_sent = write(this->fd,tb,this->sendq.length());
649 ServerInstance->Log(DEBUG,"EAGAIN, want write");
650 this->ServerInstance->SE->WantWrite(this);
653 this->SetWriteError(strerror(errno));
657 /*ServerInstance->Log(DEBUG,"Wrote: %d of %d: %s", n_sent, old_sendq_length, sendq.substr(0, n_sent).c_str());*/
661 // update the user's stats counters
662 this->bytes_out += n_sent;
664 if (n_sent != old_sendq_length)
666 ServerInstance->Log(DEBUG,"Not all written, want write");
667 this->ServerInstance->SE->WantWrite(this);
675 ServerInstance->Log(DEBUG,"Exception in userrec::FlushWriteBuf()");
679 void userrec::SetWriteError(const std::string &error)
683 ServerInstance->Log(DEBUG,"SetWriteError: %s",error.c_str());
684 // don't try to set the error twice, its already set take the first string.
685 if (!this->WriteError.length())
687 ServerInstance->Log(DEBUG,"Setting error string for %s to '%s'",this->nick,error.c_str());
688 this->WriteError = error;
694 ServerInstance->Log(DEBUG,"Exception in userrec::SetWriteError()");
698 const char* userrec::GetWriteError()
700 return this->WriteError.c_str();
703 void userrec::Oper(const std::string &opertype)
707 this->modes[UM_OPERATOR] = 1;
708 this->WriteServ("MODE %s :+o", this->nick);
709 FOREACH_MOD(I_OnOper, OnOper(this, opertype));
710 ServerInstance->Log(DEFAULT,"OPER: %s!%s@%s opered as type: %s", this->nick, this->ident, this->host, opertype.c_str());
711 strlcpy(this->oper, opertype.c_str(), NICKMAX - 1);
712 ServerInstance->all_opers.push_back(this);
713 FOREACH_MOD(I_OnPostOper,OnPostOper(this, opertype));
718 ServerInstance->Log(DEBUG,"Exception in userrec::Oper()");
722 void userrec::UnOper()
729 this->modes[UM_OPERATOR] = 0;
730 for (std::vector<userrec*>::iterator a = ServerInstance->all_opers.begin(); a < ServerInstance->all_opers.end(); a++)
734 ServerInstance->Log(DEBUG,"Oper removed from optimization list");
735 ServerInstance->all_opers.erase(a);
744 ServerInstance->Log(DEBUG,"Exception in userrec::UnOper()");
748 void userrec::QuitUser(InspIRCd* Instance, userrec *user, const std::string &quitreason)
750 user_hash::iterator iter = Instance->clientlist.find(user->nick);
751 std::string reason = quitreason;
753 if (reason.length() > MAXQUIT - 1)
754 reason.resize(MAXQUIT - 1);
757 user->Write("ERROR :Closing link (%s@%s) [%s]",user->ident,user->host,reason.c_str());
759 if (user->registered == REG_ALL)
761 user->PurgeEmptyChannels();
762 FOREACH_MOD_I(Instance,I_OnUserQuit,OnUserQuit(user,reason));
763 user->WriteCommonExcept("QUIT :%s",reason.c_str());
767 user->FlushWriteBuf();
769 FOREACH_MOD_I(Instance,I_OnUserDisconnect,OnUserDisconnect(user));
773 if (Instance->Config->GetIOHook(user->GetPort()))
777 Instance->Config->GetIOHook(user->GetPort())->OnRawSocketClose(user->fd);
779 catch (ModuleException& modexcept)
781 Instance->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason());
785 Instance->SE->DelFd(user);
790 * this must come before the ServerInstance->SNO->WriteToSnoMaskso that it doesnt try to fill their buffer with anything
791 * if they were an oper with +sn +qQ.
793 if (user->registered == REG_ALL)
796 Instance->SNO->WriteToSnoMask('q',"Client exiting: %s!%s@%s [%s]",user->nick,user->ident,user->host,reason.c_str());
798 Instance->SNO->WriteToSnoMask('Q',"Client exiting on server %s: %s!%s@%s [%s]",user->server,user->nick,user->ident,user->host,reason.c_str());
802 if (iter != Instance->clientlist.end())
804 Instance->Log(DEBUG,"deleting user hash value %lx",(unsigned long)user);
807 if (find(Instance->local_users.begin(),Instance->local_users.end(),user) != Instance->local_users.end())
808 Instance->local_users.erase(find(Instance->local_users.begin(),Instance->local_users.end(),user));
810 Instance->clientlist.erase(iter);
820 WhoWasGroup::WhoWasGroup(userrec* user) : host(NULL), dhost(NULL), ident(NULL), server(NULL), gecos(NULL), signon(user->signon)
822 this->host = strdup(user->host);
823 this->dhost = strdup(user->dhost);
824 this->ident = strdup(user->ident);
825 this->server = user->server;
826 this->gecos = strdup(user->fullname);
829 WhoWasGroup::~WhoWasGroup()
841 /* every hour, run this function which removes all entries over 3 days */
842 void MaintainWhoWas(InspIRCd* ServerInstance, time_t t)
844 for (whowas_users::iterator iter = ServerInstance->whowas.begin(); iter != ServerInstance->whowas.end(); iter++)
846 whowas_set* n = (whowas_set*)iter->second;
849 while ((n->begin() != n->end()) && ((*n->begin())->signon < t - 259200)) // 3 days
851 WhoWasGroup *a = *(n->begin());
853 n->erase(n->begin());
861 /* adds or updates an entry in the whowas list */
862 void userrec::AddToWhoWas()
864 irc::whowas::whowas_users::iterator iter = ServerInstance->whowas.find(this->nick);
866 ServerInstance->Log(DEBUG,"Add to whowas lists");
868 if (iter == ServerInstance->whowas.end())
870 ServerInstance->Log(DEBUG,"Adding new whowas set for %s",this->nick);
871 irc::whowas::whowas_set* n = new irc::whowas::whowas_set;
872 irc::whowas::WhoWasGroup *a = new irc::whowas::WhoWasGroup(this);
874 ServerInstance->whowas[this->nick] = n;
878 irc::whowas::whowas_set* group = (irc::whowas::whowas_set*)iter->second;
880 ServerInstance->Log(DEBUG,"Using existing whowas group for %s",this->nick);
882 if (group->size() > 10)
884 ServerInstance->Log(DEBUG,"Trimming existing group to ten entries for %s",this->nick);
885 irc::whowas::WhoWasGroup *a = (irc::whowas::WhoWasGroup*)*(group->begin());
890 irc::whowas::WhoWasGroup *a = new irc::whowas::WhoWasGroup(this);
895 /* add a client connection to the sockets list */
896 void userrec::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, insp_inaddr ip)
898 std::string tempnick = ConvToStr(socket) + "-unknown";
899 user_hash::iterator iter = Instance->clientlist.find(tempnick);
900 const char *ipaddr = insp_ntoa(ip);
906 * as these nicknames are 'RFC impossible', we can be sure nobody is going to be
907 * using one as a registered connection. As they are per fd, we can also safely assume
908 * that we wont have collisions. Therefore, if the nick exists in the list, its only
909 * used by a dead socket, erase the iterator so that the new client may reclaim it.
910 * this was probably the cause of 'server ignores me when i hammer it with reconnects'
911 * issue in earlier alphas/betas
913 if (iter != Instance->clientlist.end())
915 userrec* goner = iter->second;
917 Instance->clientlist.erase(iter);
920 Instance->Log(DEBUG,"AddClient: %d %d %s",socket,port,ipaddr);
922 New = new userrec(Instance);
923 Instance->clientlist[tempnick] = New;
925 strlcpy(New->nick,tempnick.c_str(),NICKMAX-1);
927 New->server = Instance->FindServerNamePtr(Instance->Config->ServerName);
928 /* We don't need range checking here, we KNOW 'unknown\0' will fit into the ident field. */
929 strcpy(New->ident, "unknown");
931 New->registered = REG_NONE;
932 New->signon = Instance->Time() + Instance->Config->dns_timeout;
935 Instance->Log(DEBUG,"Setting socket addresses");
936 New->SetSockAddr(AF_FAMILY, ipaddr, port);
937 Instance->Log(DEBUG,"Socket addresses set.");
939 /* Smarter than your average bear^H^H^H^Hset of strlcpys. */
940 for (const char* temp = New->GetIPString(); *temp && j < 64; temp++, j++)
941 New->dhost[j] = New->host[j] = *temp;
942 New->dhost[j] = New->host[j] = 0;
944 Instance->Log(DEBUG,"Hosts set.");
946 // set the registration timeout for this user
947 unsigned long class_regtimeout = 90;
949 long class_threshold = 5;
950 long class_sqmax = 262144; // 256kb
951 long class_rqmax = 4096; // 4k
953 Instance->Log(DEBUG,"Class stuff set.");
955 for (ClassVector::iterator i = Instance->Config->Classes.begin(); i != Instance->Config->Classes.end(); i++)
957 if ((i->type == CC_ALLOW) && (match(ipaddr,i->host.c_str(),true)))
959 class_regtimeout = (unsigned long)i->registration_timeout;
960 class_flood = i->flood;
961 New->pingmax = i->pingtime;
962 class_threshold = i->threshold;
963 class_sqmax = i->sendqmax;
964 class_rqmax = i->recvqmax;
969 Instance->Log(DEBUG,"nping etc set.");
971 New->nping = Instance->Time() + New->pingmax + Instance->Config->dns_timeout;
972 New->timeout = Instance->Time() + class_regtimeout;
973 New->flood = class_flood;
974 New->threshold = class_threshold;
975 New->sendqmax = class_sqmax;
976 New->recvqmax = class_rqmax;
978 Instance->Log(DEBUG,"Push back to local users.");
979 Instance->local_users.push_back(New);
981 Instance->Log(DEBUG,"Check softlimit: %d %d %d",Instance->local_users.size(), Instance->Config->SoftLimit, MAXCLIENTS);
982 if ((Instance->local_users.size() > Instance->Config->SoftLimit) || (Instance->local_users.size() >= MAXCLIENTS))
984 Instance->Log(DEBUG,"Check softlimit failed");
985 Instance->WriteOpers("*** Warning: softlimit value has been reached: %d clients", Instance->Config->SoftLimit);
986 userrec::QuitUser(Instance, New,"No more connections allowed");
990 Instance->Log(DEBUG,"Softlimit passed.");
994 * this is done as a safety check to keep the file descriptors within range of fd_ref_table.
995 * its a pretty big but for the moment valid assumption:
996 * file descriptors are handed out starting at 0, and are recycled as theyre freed.
997 * therefore if there is ever an fd over 65535, 65536 clients must be connected to the
998 * irc server at once (or the irc server otherwise initiating this many connections, files etc)
999 * which for the time being is a physical impossibility (even the largest networks dont have more
1000 * than about 10,000 users on ONE server!)
1002 if ((unsigned int)socket >= MAX_DESCRIPTORS)
1004 userrec::QuitUser(Instance, New, "Server is full");
1008 Instance->Log(DEBUG,"socket < MAX_DESCRIPTORS passed.");
1010 ELine* e = Instance->XLines->matches_exception(New);
1013 Instance->Log(DEBUG,"Doesnt match eline.");
1014 ZLine* r = Instance->XLines->matches_zline(ipaddr);
1017 Instance->Log(DEBUG,"Matches zline.");
1018 char reason[MAXBUF];
1019 snprintf(reason,MAXBUF,"Z-Lined: %s",r->reason);
1020 userrec::QuitUser(Instance, New, reason);
1023 Instance->Log(DEBUG,"Doesnt match zline.");
1026 Instance->Log(DEBUG,"Check before AddFd.");
1030 Instance->Log(DEBUG,"Adding fd.");
1031 if (!Instance->SE->AddFd(New))
1033 Instance->Log(DEBUG,"Oops, fd already exists");
1034 userrec::QuitUser(Instance, New, "Internal error handling connection");
1039 New->WriteServ("NOTICE Auth :*** Looking up your hostname...");
1042 long userrec::GlobalCloneCount()
1046 strlcpy(u2, this->GetIPString(), 64);
1048 for (user_hash::const_iterator a = ServerInstance->clientlist.begin(); a != ServerInstance->clientlist.end(); a++)
1050 /* We have to match ip's as strings - we don't know what protocol
1051 * a remote user may be using
1053 if (strcasecmp(a->second->GetIPString(), u2) == 0)
1060 long userrec::LocalCloneCount()
1063 for (std::vector<userrec*>::const_iterator a = ServerInstance->local_users.begin(); a != ServerInstance->local_users.end(); a++)
1067 /* I dont think theres any faster way of matching two ipv6 addresses than memcmp */
1068 in6_addr* s1 = &(((sockaddr_in6*)comp->ip)->sin6_addr);
1069 in6_addr* s2 = &(((sockaddr_in6*)this->ip)->sin6_addr);
1070 if (!memcmp(s1->s6_addr, s2->s6_addr, sizeof(in6_addr)))
1073 in_addr* s1 = &((sockaddr_in*)comp->ip)->sin_addr;
1074 in_addr* s2 = &((sockaddr_in*)this->ip)->sin_addr;
1075 if (s1->s_addr == s2->s_addr)
1082 void userrec::FullConnect(CullList* Goners)
1084 ServerInstance->stats->statsConnects++;
1085 this->idle_lastmsg = ServerInstance->Time();
1087 ConnectClass a = this->GetClass();
1089 if (a.type == CC_DENY)
1091 Goners->AddItem(this,"Unauthorised connection");
1095 if ((*(a.pass.c_str())) && (!this->haspassed))
1097 Goners->AddItem(this,"Invalid password");
1101 if (this->LocalCloneCount() > a.maxlocal)
1103 Goners->AddItem(this, "No more connections allowed from your host via this connect class (local)");
1104 ServerInstance->WriteOpers("*** WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a.maxlocal, this->GetIPString());
1107 else if (this->GlobalCloneCount() > a.maxglobal)
1109 Goners->AddItem(this, "No more connections allowed from your host via this connect class (global)");
1110 ServerInstance->WriteOpers("*** WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s",a.maxglobal, this->GetIPString());
1114 ELine* e = ServerInstance->XLines->matches_exception(this);
1118 GLine* r = ServerInstance->XLines->matches_gline(this);
1122 char reason[MAXBUF];
1123 snprintf(reason,MAXBUF,"G-Lined: %s",r->reason);
1124 Goners->AddItem(this, reason);
1128 KLine* n = ServerInstance->XLines->matches_kline(this);
1132 char reason[MAXBUF];
1133 snprintf(reason,MAXBUF,"K-Lined: %s",n->reason);
1134 Goners->AddItem(this, reason);
1140 this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network);
1141 this->WriteServ("001 %s :Welcome to the %s IRC Network %s!%s@%s",this->nick, ServerInstance->Config->Network, this->nick, this->ident, this->host);
1142 this->WriteServ("002 %s :Your host is %s, running version %s",this->nick,ServerInstance->Config->ServerName,VERSION);
1143 this->WriteServ("003 %s :This server was created %s %s", this->nick, __TIME__, __DATE__);
1144 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());
1146 // anfl @ #ratbox, efnet reminded me that according to the RFC this cant contain more than 13 tokens per line...
1147 // so i'd better split it :)
1148 std::stringstream out(ServerInstance->Config->data005);
1149 std::string token = "";
1150 std::string line5 = "";
1151 int token_counter = 0;
1156 line5 = line5 + token + " ";
1159 if ((token_counter >= 13) || (out.eof() == true))
1161 this->WriteServ("005 %s %s:are supported by this server", this->nick, line5.c_str());
1170 * fix 3 by brain, move registered = 7 below these so that spurious modes and host
1171 * changes dont go out onto the network and produce 'fake direction'.
1173 FOREACH_MOD(I_OnUserConnect,OnUserConnect(this));
1175 this->registered = REG_ALL;
1177 FOREACH_MOD(I_OnPostConnect,OnPostConnect(this));
1179 ServerInstance->SNO->WriteToSnoMask('c',"Client connecting on port %d: %s!%s@%s [%s]", this->GetPort(), this->nick, this->ident, this->host, this->GetIPString());
1182 /** userrec::UpdateNick()
1183 * re-allocates a nick in the user_hash after they change nicknames,
1184 * returns a pointer to the new user as it may have moved
1186 userrec* userrec::UpdateNickHash(const char* New)
1190 //user_hash::iterator newnick;
1191 user_hash::iterator oldnick = ServerInstance->clientlist.find(this->nick);
1193 if (!strcasecmp(this->nick,New))
1194 return oldnick->second;
1196 if (oldnick == ServerInstance->clientlist.end())
1197 return NULL; /* doesnt exist */
1199 userrec* olduser = oldnick->second;
1200 ServerInstance->clientlist[New] = olduser;
1201 ServerInstance->clientlist.erase(oldnick);
1202 return ServerInstance->clientlist[New];
1207 ServerInstance->Log(DEBUG,"Exception in userrec::UpdateNickHash()");
1212 bool userrec::ForceNickChange(const char* newnick)
1218 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(this, newnick));
1222 ServerInstance->stats->statsCollisions++;
1226 if (ServerInstance->XLines->matches_qline(newnick))
1228 ServerInstance->stats->statsCollisions++;
1232 if (this->registered == REG_ALL)
1234 const char* pars[1];
1236 std::string cmd = "NICK";
1237 return (ServerInstance->Parser->CallHandler(cmd, pars, 1, this) == CMD_SUCCESS);
1244 ServerInstance->Log(DEBUG,"Exception in userrec::ForceNickChange()");
1249 void userrec::SetSockAddr(int protocol_family, const char* ip, int port)
1251 switch (protocol_family)
1253 #ifdef SUPPORT_IP6LINKS
1256 ServerInstance->Log(DEBUG,"Set inet6 protocol address");
1257 sockaddr_in6* sin = new sockaddr_in6;
1258 sin->sin6_family = AF_INET6;
1259 sin->sin6_port = port;
1260 inet_pton(AF_INET6, ip, &sin->sin6_addr);
1261 this->ip = (sockaddr*)sin;
1267 ServerInstance->Log(DEBUG,"Set inet4 protocol address");
1268 sockaddr_in* sin = new sockaddr_in;
1269 sin->sin_family = AF_INET;
1270 sin->sin_port = port;
1271 inet_pton(AF_INET, ip, &sin->sin_addr);
1272 this->ip = (sockaddr*)sin;
1276 ServerInstance->Log(DEBUG,"Ut oh, I dont know protocol %d to be set on '%s'!", protocol_family, this->nick);
1281 int userrec::GetPort()
1283 if (this->ip == NULL)
1286 switch (this->GetProtocolFamily())
1288 #ifdef SUPPORT_IP6LINKS
1291 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1292 return sin->sin6_port;
1298 sockaddr_in* sin = (sockaddr_in*)this->ip;
1299 return sin->sin_port;
1303 ServerInstance->Log(DEBUG,"Ut oh, '%s' has an unknown protocol family!",this->nick);
1309 int userrec::GetProtocolFamily()
1311 if (this->ip == NULL)
1314 sockaddr_in* sin = (sockaddr_in*)this->ip;
1315 return sin->sin_family;
1318 const char* userrec::GetIPString()
1320 static char buf[1024];
1322 if (this->ip == NULL)
1325 switch (this->GetProtocolFamily())
1327 #ifdef SUPPORT_IP6LINKS
1330 static char temp[1024];
1332 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1333 inet_ntop(sin->sin6_family, &sin->sin6_addr, buf, sizeof(buf));
1334 /* IP addresses starting with a : on irc are a Bad Thing (tm) */
1337 strlcpy(&temp[1], buf, sizeof(temp) - 1);
1347 sockaddr_in* sin = (sockaddr_in*)this->ip;
1348 inet_ntop(sin->sin_family, &sin->sin_addr, buf, sizeof(buf));
1353 ServerInstance->Log(DEBUG,"Ut oh, '%s' has an unknown protocol family!",this->nick);
1359 const char* userrec::GetIPString(char* buf)
1361 if (this->ip == NULL)
1367 switch (this->GetProtocolFamily())
1369 #ifdef SUPPORT_IP6LINKS
1372 static char temp[1024];
1374 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1375 inet_ntop(sin->sin6_family, &sin->sin6_addr, buf, sizeof(buf));
1376 /* IP addresses starting with a : on irc are a Bad Thing (tm) */
1379 strlcpy(&temp[1], buf, sizeof(temp) - 1);
1381 strlcpy(buf, temp, sizeof(temp));
1389 sockaddr_in* sin = (sockaddr_in*)this->ip;
1390 inet_ntop(sin->sin_family, &sin->sin_addr, buf, sizeof(buf));
1396 ServerInstance->Log(DEBUG,"Ut oh, '%s' has an unknown protocol family!",this->nick);
1402 /** NOTE: We cannot pass a const reference to this method.
1403 * The string is changed by the workings of the method,
1404 * so that if we pass const ref, we end up copying it to
1405 * something we can change anyway. Makes sense to just let
1406 * the compiler do that copy for us.
1408 void userrec::Write(std::string text)
1410 if ((this->fd < 0) || (this->fd > MAX_DESCRIPTORS))
1415 text.append("\r\n");
1419 ServerInstance->Log(DEBUG,"Exception in userrec::Write() std::string::append");
1423 if (ServerInstance->Config->GetIOHook(this->GetPort()))
1427 ServerInstance->Config->GetIOHook(this->GetPort())->OnRawSocketWrite(this->fd, text.data(), text.length());
1429 catch (ModuleException& modexcept)
1431 ServerInstance->Log(DEBUG,"Module exception caught: %s",modexcept.GetReason());
1436 this->AddWriteBuf(text);
1438 ServerInstance->stats->statsSent += text.length();
1439 this->ServerInstance->SE->WantWrite(this);
1444 void userrec::Write(const char *text, ...)
1447 char textbuffer[MAXBUF];
1449 va_start(argsPtr, text);
1450 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1453 this->Write(std::string(textbuffer));
1456 void userrec::WriteServ(const std::string& text)
1458 char textbuffer[MAXBUF];
1460 snprintf(textbuffer,MAXBUF,":%s %s",ServerInstance->Config->ServerName,text.c_str());
1461 this->Write(std::string(textbuffer));
1465 * Same as Write(), except `text' is prefixed with `:server.name '.
1467 void userrec::WriteServ(const char* text, ...)
1470 char textbuffer[MAXBUF];
1472 va_start(argsPtr, text);
1473 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1476 this->WriteServ(std::string(textbuffer));
1480 void userrec::WriteFrom(userrec *user, const std::string &text)
1484 snprintf(tb,MAXBUF,":%s %s",user->GetFullHost(),text.c_str());
1486 this->Write(std::string(tb));
1490 /* write text from an originating user to originating user */
1492 void userrec::WriteFrom(userrec *user, const char* text, ...)
1495 char textbuffer[MAXBUF];
1497 va_start(argsPtr, text);
1498 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1501 this->WriteFrom(user, std::string(textbuffer));
1505 /* write text to an destination user from a source user (e.g. user privmsg) */
1507 void userrec::WriteTo(userrec *dest, const char *data, ...)
1509 char textbuffer[MAXBUF];
1512 va_start(argsPtr, data);
1513 vsnprintf(textbuffer, MAXBUF, data, argsPtr);
1516 this->WriteTo(dest, std::string(textbuffer));
1519 void userrec::WriteTo(userrec *dest, const std::string &data)
1521 dest->WriteFrom(this, data);
1525 void userrec::WriteCommon(const char* text, ...)
1527 char textbuffer[MAXBUF];
1530 if (this->registered != REG_ALL)
1533 va_start(argsPtr, text);
1534 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1537 this->WriteCommon(std::string(textbuffer));
1540 void userrec::WriteCommon(const std::string &text)
1544 bool sent_to_at_least_one = false;
1546 if (this->registered != REG_ALL)
1551 for (std::vector<ucrec*>::const_iterator v = this->chans.begin(); v != this->chans.end(); v++)
1556 CUList *ulist= n->channel->GetUsers();
1558 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1560 if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
1562 already_sent[i->second->fd] = uniq_id;
1563 i->second->WriteFrom(this, std::string(text));
1564 sent_to_at_least_one = true;
1571 * if the user was not in any channels, no users will receive the text. Make sure the user
1572 * receives their OWN message for WriteCommon
1574 if (!sent_to_at_least_one)
1576 this->WriteFrom(this,std::string(text));
1582 ServerInstance->Log(DEBUG,"Exception in userrec::WriteCommon()");
1587 /* write a formatted string to all users who share at least one common
1588 * channel, NOT including the source user e.g. for use in QUIT
1591 void userrec::WriteCommonExcept(const char* text, ...)
1593 char textbuffer[MAXBUF];
1596 va_start(argsPtr, text);
1597 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1600 this->WriteCommonExcept(std::string(textbuffer));
1603 void userrec::WriteCommonExcept(const std::string &text)
1605 bool quit_munge = false;
1606 char oper_quit[MAXBUF];
1607 char textbuffer[MAXBUF];
1609 strlcpy(textbuffer, text.c_str(), MAXBUF);
1611 if (this->registered != REG_ALL)
1616 /* TODO: We need some form of WriteCommonExcept that will send two lines, one line to
1617 * opers and the other line to non-opers, then all this hidebans and hidesplits gunk
1620 if (ServerInstance->Config->HideSplits)
1622 char* check = textbuffer + 6;
1624 if (!strncasecmp(textbuffer, "QUIT :",6))
1626 std::stringstream split(check);
1627 std::string server_one;
1628 std::string server_two;
1630 split >> server_one;
1631 split >> server_two;
1633 if ((ServerInstance->FindServerName(server_one)) && (ServerInstance->FindServerName(server_two)))
1635 strlcpy(oper_quit,textbuffer,MAXQUIT);
1636 strlcpy(check,"*.net *.split",MAXQUIT);
1642 if ((ServerInstance->Config->HideBans) && (!quit_munge))
1644 if ((!strncasecmp(textbuffer, "QUIT :G-Lined:",14)) || (!strncasecmp(textbuffer, "QUIT :K-Lined:",14))
1645 || (!strncasecmp(textbuffer, "QUIT :Q-Lined:",14)) || (!strncasecmp(textbuffer, "QUIT :Z-Lined:",14)))
1647 char* check = textbuffer + 13;
1648 strlcpy(oper_quit,textbuffer,MAXQUIT);
1649 *check = 0; // We don't need to strlcpy, we just chop it from the :
1654 for (std::vector<ucrec*>::const_iterator v = this->chans.begin(); v != this->chans.end(); v++)
1659 CUList *ulist= n->channel->GetUsers();
1661 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1663 if (this != i->second)
1665 if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
1667 already_sent[i->second->fd] = uniq_id;
1669 i->second->WriteFrom(this, *i->second->oper ? std::string(oper_quit) : std::string(textbuffer));
1671 i->second->WriteFrom(this, std::string(textbuffer));
1680 void userrec::WriteWallOps(const std::string &text)
1682 /* Does nothing if theyre not opered */
1683 if ((!*this->oper) && (IS_LOCAL(this)))
1686 std::string wallop = "WALLOPS :";
1690 wallop.append(text);
1694 ServerInstance->Log(DEBUG,"Exception in userrec::Write() std::string::append");
1698 for (std::vector<userrec*>::const_iterator i = ServerInstance->local_users.begin(); i != ServerInstance->local_users.end(); i++)
1701 if ((IS_LOCAL(t)) && (t->modes[UM_WALLOPS]))
1702 this->WriteTo(t,wallop);
1706 void userrec::WriteWallOps(const char* text, ...)
1708 char textbuffer[MAXBUF];
1711 va_start(argsPtr, text);
1712 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1715 this->WriteWallOps(std::string(textbuffer));
1718 /* return 0 or 1 depending if users u and u2 share one or more common channels
1719 * (used by QUIT, NICK etc which arent channel specific notices)
1721 * The old algorithm in 1.0 for this was relatively inefficient, iterating over
1722 * the first users channels then the second users channels within the outer loop,
1723 * therefore it was a maximum of x*y iterations (upon returning 0 and checking
1724 * all possible iterations). However this new function instead checks against the
1725 * channel's userlist in the inner loop which is a std::map<userrec*,userrec*>
1726 * and saves us time as we already know what pointer value we are after.
1727 * Don't quote me on the maths as i am not a mathematician or computer scientist,
1728 * but i believe this algorithm is now x+(log y) maximum iterations instead.
1730 bool userrec::SharesChannelWith(userrec *other)
1732 if ((!other) || (this->registered != REG_ALL) || (other->registered != REG_ALL))
1736 for (std::vector<ucrec*>::const_iterator i = this->chans.begin(); i != this->chans.end(); i++)
1738 /* Fetch the channel from the user */
1739 ucrec* user_channel = *i;
1741 if (user_channel->channel)
1743 /* Eliminate the inner loop (which used to be ~equal in size to the outer loop)
1744 * by replacing it with a map::find which *should* be more efficient
1746 if (user_channel->channel->HasUser(other))
1753 int userrec::CountChannels()
1755 return ChannelCount;
1758 void userrec::ModChannelCount(int n)
1763 bool userrec::ChangeName(const char* gecos)
1765 if (!strcmp(gecos, this->fullname))
1771 FOREACH_RESULT(I_OnChangeLocalUserGECOS,OnChangeLocalUserGECOS(this,gecos));
1774 FOREACH_MOD(I_OnChangeName,OnChangeName(this,gecos));
1776 strlcpy(this->fullname,gecos,MAXGECOS+1);
1780 bool userrec::ChangeDisplayedHost(const char* host)
1782 if (!strcmp(host, this->dhost))
1788 FOREACH_RESULT(I_OnChangeLocalUserHost,OnChangeLocalUserHost(this,host));
1791 FOREACH_MOD(I_OnChangeHost,OnChangeHost(this,host));
1793 if (this->ServerInstance->Config->CycleHosts)
1794 this->WriteCommonExcept("%s","QUIT :Changing hosts");
1796 strlcpy(this->dhost,host,63);
1798 if (this->ServerInstance->Config->CycleHosts)
1800 for (std::vector<ucrec*>::const_iterator i = this->chans.begin(); i != this->chans.end(); i++)
1804 (*i)->channel->WriteAllExceptSender(this, false, 0, "JOIN %s", (*i)->channel->name);
1805 std::string n = this->ServerInstance->Modes->ModeString(this, (*i)->channel);
1807 (*i)->channel->WriteAllExceptSender(this, true, 0, "MODE %s +%s", (*i)->channel->name, n.c_str());
1813 this->WriteServ("396 %s %s :is now your hidden host",this->nick,this->dhost);
1818 bool userrec::ChangeIdent(const char* newident)
1820 if (!strcmp(newident, this->ident))
1823 if (this->ServerInstance->Config->CycleHosts)
1824 this->WriteCommonExcept("%s","QUIT :Changing ident");
1826 strlcpy(this->ident, newident, IDENTMAX+2);
1828 if (this->ServerInstance->Config->CycleHosts)
1830 for (std::vector<ucrec*>::const_iterator i = this->chans.begin(); i != this->chans.end(); i++)
1834 (*i)->channel->WriteAllExceptSender(this, false, 0, "JOIN %s", (*i)->channel->name);
1835 std::string n = this->ServerInstance->Modes->ModeString(this, (*i)->channel);
1837 (*i)->channel->WriteAllExceptSender(this, true, 0, "MODE %s +%s", (*i)->channel->name, n.c_str());
1845 void userrec::NoticeAll(char* text, ...)
1847 char textbuffer[MAXBUF];
1848 char formatbuffer[MAXBUF];
1851 va_start(argsPtr, text);
1852 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1855 snprintf(formatbuffer,MAXBUF,"NOTICE $* :%s",textbuffer);
1857 for (std::vector<userrec*>::const_iterator i = ServerInstance->local_users.begin(); i != ServerInstance->local_users.end(); i++)
1860 t->WriteFrom(this, std::string(formatbuffer));
1865 std::string userrec::ChannelList(userrec* source)
1870 for (std::vector<ucrec*>::const_iterator i = this->chans.begin(); i != this->chans.end(); i++)
1874 if(rec->channel && rec->channel->name)
1876 /* If the target is the same as the sender, let them see all their channels.
1877 * If the channel is NOT private/secret OR the user shares a common channel
1878 * If the user is an oper, and the <options:operspywhois> option is set.
1880 if ((source == this) || (*source->oper && ServerInstance->Config->OperSpyWhois) || (((!rec->channel->modes[CM_PRIVATE]) && (!rec->channel->modes[CM_SECRET])) || (rec->channel->HasUser(source))))
1882 list.append(rec->channel->GetPrefixChar(this)).append(rec->channel->name).append(" ");
1890 ServerInstance->Log(DEBUG,"Exception in userrec::ChannelList()");
1895 void userrec::SplitChanList(userrec* dest, const std::string &cl)
1898 std::ostringstream prefix;
1899 std::string::size_type start, pos, length;
1903 prefix << this->nick << " " << dest->nick << " :";
1904 line = prefix.str();
1905 int namelen = strlen(ServerInstance->Config->ServerName) + 6;
1907 for (start = 0; (pos = cl.find(' ', start)) != std::string::npos; start = pos+1)
1909 length = (pos == std::string::npos) ? cl.length() : pos;
1911 if (line.length() + namelen + length - start > 510)
1914 line = prefix.str();
1917 if(pos == std::string::npos)
1919 line.append(cl.substr(start, length - start));
1924 line.append(cl.substr(start, length - start + 1));
1930 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1936 ServerInstance->Log(DEBUG,"Exception in userrec::SplitChanList()");
1941 /* looks up a users password for their connection class (<ALLOW>/<DENY> tags)
1942 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1943 * then their ip will be taken as 'priority' anyway, so for example,
1944 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1946 ConnectClass& userrec::GetClass()
1948 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1950 if ((match(this->GetIPString(),i->host.c_str(),true)) || (match(this->host,i->host.c_str())))
1954 return *(ServerInstance->Config->Classes.begin());
1957 void userrec::PurgeEmptyChannels()
1959 std::vector<chanrec*> to_delete;
1961 // firstly decrement the count on each channel
1962 for (std::vector<ucrec*>::iterator f = this->chans.begin(); f != this->chans.end(); f++)
1967 uc->channel->RemoveAllPrefixes(this);
1968 if (uc->channel->DelUser(this) == 0)
1970 /* No users left in here, mark it for deletion */
1973 to_delete.push_back(uc->channel);
1977 ServerInstance->Log(DEBUG,"Exception in userrec::PurgeEmptyChannels to_delete.push_back()");
1984 for (std::vector<chanrec*>::iterator n = to_delete.begin(); n != to_delete.end(); n++)
1986 chanrec* thischan = *n;
1987 chan_hash::iterator i2 = ServerInstance->chanlist.find(thischan->name);
1988 if (i2 != ServerInstance->chanlist.end())
1990 FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(i2->second));
1992 ServerInstance->chanlist.erase(i2);
1999 void userrec::ShowMOTD()
2001 if (!ServerInstance->Config->MOTD.size())
2003 this->WriteServ("422 %s :Message of the day file is missing.",this->nick);
2006 this->WriteServ("375 %s :%s message of the day", this->nick, ServerInstance->Config->ServerName);
2008 for (unsigned int i = 0; i < ServerInstance->Config->MOTD.size(); i++)
2009 this->WriteServ("372 %s :- %s",this->nick,ServerInstance->Config->MOTD[i].c_str());
2011 this->WriteServ("376 %s :End of message of the day.", this->nick);
2014 void userrec::ShowRULES()
2016 if (!ServerInstance->Config->RULES.size())
2018 this->WriteServ("NOTICE %s :Rules file is missing.",this->nick);
2021 this->WriteServ("NOTICE %s :%s rules",this->nick,ServerInstance->Config->ServerName);
2023 for (unsigned int i = 0; i < ServerInstance->Config->RULES.size(); i++)
2024 this->WriteServ("NOTICE %s :%s",this->nick,ServerInstance->Config->RULES[i].c_str());
2026 this->WriteServ("NOTICE %s :End of %s rules.",this->nick,ServerInstance->Config->ServerName);
2029 void userrec::HandleEvent(EventType et, int errornum)
2031 /* WARNING: May delete this user! */
2037 ServerInstance->ProcessUser(this);
2040 this->FlushWriteBuf();
2043 this->SetWriteError(strerror(errornum));
2049 ServerInstance->Log(DEBUG,"Exception in userrec::HandleEvent intercepted");