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 conf->GetInstance()->Log(DEBUG,"Currently %d items to clear",conf->opertypes.size());
35 for (opertype_t::iterator n = conf->opertypes.begin(); n != conf->opertypes.end(); n++)
37 conf->GetInstance()->Log(DEBUG,"Clear item");
42 conf->opertypes.clear();
46 bool InitClasses(ServerConfig* conf, const char* tag)
48 for (operclass_t::iterator n = conf->operclass.begin(); n != conf->operclass.end(); n++)
54 conf->operclass.clear();
58 bool DoType(ServerConfig* conf, const char* tag, char** entries, void** values, int* types)
60 char* TypeName = (char*)values[0];
61 char* Classes = (char*)values[1];
63 conf->opertypes[TypeName] = strdup(Classes);
64 conf->GetInstance()->Log(DEBUG,"Read oper TYPE '%s' with classes '%s'",TypeName,Classes);
68 bool DoClass(ServerConfig* conf, const char* tag, char** entries, void** values, int* types)
70 char* ClassName = (char*)values[0];
71 char* CommandList = (char*)values[1];
73 conf->operclass[ClassName] = strdup(CommandList);
74 conf->GetInstance()->Log(DEBUG,"Read oper CLASS '%s' with commands '%s'",ClassName,CommandList);
78 bool DoneClassesAndTypes(ServerConfig* conf, const char* tag)
83 std::string userrec::ProcessNoticeMasks(const char *sm)
85 bool adding = true, oldadding = false;
89 ServerInstance->Log(DEBUG,"Process notice masks");
93 ServerInstance->Log(DEBUG,"Process notice mask %c",*c);
104 for (unsigned char d = 'A'; d <= 'z'; d++)
106 if (ServerInstance->SNO->IsEnabled(d))
108 if ((!IsNoticeMaskSet(d) && adding) || (IsNoticeMaskSet(d) && !adding))
110 if ((oldadding != adding) || (!output.length()))
111 output += (adding ? '+' : '-');
113 this->SetNoticeMask(d, adding);
122 if ((*c >= 'A') && (*c <= 'z') && (ServerInstance->SNO->IsEnabled(*c)))
124 if ((!IsNoticeMaskSet(*c) && adding) || (IsNoticeMaskSet(*c) && !adding))
126 if ((oldadding != adding) || (!output.length()))
127 output += (adding ? '+' : '-');
129 this->SetNoticeMask(*c, adding);
144 void userrec::StartDNSLookup()
146 ServerInstance->Log(DEBUG,"Commencing reverse lookup");
149 ServerInstance->Log(DEBUG,"Passing instance: %08x",this->ServerInstance);
150 res_reverse = new UserResolver(this->ServerInstance, this, this->GetIPString(), false);
151 this->ServerInstance->AddResolver(res_reverse);
153 catch (ModuleException& e)
155 ServerInstance->Log(DEBUG,"Error in resolver: %s",e.GetReason());
159 UserResolver::UserResolver(InspIRCd* Instance, userrec* user, std::string to_resolve, bool forward) :
160 Resolver(Instance, to_resolve, forward ? DNS_QUERY_FORWARD : DNS_QUERY_REVERSE), bound_user(user)
163 this->bound_fd = user->GetFd();
166 void UserResolver::OnLookupComplete(const std::string &result)
168 if ((!this->fwd) && (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user))
170 ServerInstance->Log(DEBUG,"Commencing forward lookup");
171 this->bound_user->stored_host = result;
174 /* Check we didnt time out */
175 if (this->bound_user->registered != REG_ALL)
177 bound_user->res_forward = new UserResolver(this->ServerInstance, this->bound_user, result, true);
178 this->ServerInstance->AddResolver(bound_user->res_forward);
181 catch (ModuleException& e)
183 ServerInstance->Log(DEBUG,"Error in resolver: %s",e.GetReason());
186 else if ((this->fwd) && (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user))
188 /* Both lookups completed */
189 if (this->bound_user->GetIPString() == result)
191 std::string hostname = this->bound_user->stored_host;
192 if (hostname.length() < 65)
194 /* Check we didnt time out */
195 if (this->bound_user->registered != REG_ALL)
197 /* Hostnames starting with : are not a good thing (tm) */
198 if (*(hostname.c_str()) == ':')
199 hostname = "0" + hostname;
201 this->bound_user->WriteServ("NOTICE Auth :*** Found your hostname (%s)", hostname.c_str());
202 this->bound_user->dns_done = true;
203 strlcpy(this->bound_user->dhost, hostname.c_str(),64);
204 strlcpy(this->bound_user->host, hostname.c_str(),64);
209 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());
214 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());
219 void UserResolver::OnError(ResolverError e, const std::string &errormessage)
221 if (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user)
223 /* Error message here */
224 this->bound_user->WriteServ("NOTICE Auth :*** Could not resolve your hostname, using your IP address (%s) instead.", this->bound_user->GetIPString());
225 this->bound_user->dns_done = true;
230 bool userrec::IsNoticeMaskSet(unsigned char sm)
232 return (snomasks[sm-65]);
235 void userrec::SetNoticeMask(unsigned char sm, bool value)
237 snomasks[sm-65] = value;
240 const char* userrec::FormatNoticeMasks()
242 static char data[MAXBUF];
245 for (int n = 0; n < 64; n++)
248 data[offset++] = n+65;
257 bool userrec::IsModeSet(unsigned char m)
259 return (modes[m-65]);
262 void userrec::SetMode(unsigned char m, bool value)
267 const char* userrec::FormatModes()
269 static char data[MAXBUF];
271 for (int n = 0; n < 64; n++)
274 data[offset++] = n+65;
280 userrec::userrec(InspIRCd* Instance) : ServerInstance(Instance)
282 ServerInstance->Log(DEBUG,"userrec::userrec(): Instance: %08x",ServerInstance);
283 // the PROPER way to do it, AVOID bzero at *ALL* costs
284 *password = *nick = *ident = *host = *dhost = *fullname = *awaymsg = *oper = 0;
285 server = (char*)Instance->FindServerNamePtr(Instance->Config->ServerName);
286 reset_due = ServerInstance->Time();
287 lines_in = lastping = signon = idle_lastmsg = nping = registered = 0;
288 ChannelCount = timeout = flood = bytes_in = bytes_out = cmds_in = cmds_out = 0;
289 haspassed = dns_done = false;
294 res_forward = res_reverse = NULL;
298 chans.resize(MAXCHANS);
299 memset(modes,0,sizeof(modes));
300 memset(snomasks,0,sizeof(snomasks));
302 for (unsigned int n = 0; n < MAXCHANS; n++)
304 chans[n] = new ucrec();
305 chans[n]->channel = NULL;
306 chans[n]->uc_modes = 0;
312 for (std::vector<ucrec*>::iterator n = chans.begin(); n != chans.end(); n++)
314 ucrec* x = (ucrec*)*n;
320 if (this->GetProtocolFamily() == AF_INET)
322 delete (sockaddr_in*)ip;
324 #ifdef SUPPORT_IP6LINKS
327 delete (sockaddr_in6*)ip;
333 /* XXX - minor point, other *Host functions return a char *, this one creates it. Might be nice to be consistant? */
334 void userrec::MakeHost(char* nhost)
336 /* This is much faster than snprintf */
338 for(char* n = ident; *n; n++)
341 for(char* n = host; *n; n++)
346 void userrec::CloseSocket()
348 shutdown(this->fd,2);
352 char* userrec::GetFullHost()
354 static char result[MAXBUF];
356 for(char* n = nick; *n; n++)
359 for(char* n = ident; *n; n++)
362 for(char* n = dhost; *n; n++)
368 char* userrec::MakeWildHost()
370 static char nresult[MAXBUF];
372 *t++ = '*'; *t++ = '!';
373 *t++ = '*'; *t++ = '@';
374 for(char* n = dhost; *n; n++)
380 int userrec::ReadData(void* buffer, size_t size)
384 return read(this->fd, buffer, size);
391 char* userrec::GetFullRealHost()
393 static char fresult[MAXBUF];
395 for(char* n = nick; *n; n++)
398 for(char* n = ident; *n; n++)
401 for(char* n = host; *n; n++)
407 bool userrec::IsInvited(irc::string &channel)
409 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
411 irc::string compare = i->channel;
413 if (compare == channel)
421 InvitedList* userrec::GetInviteList()
426 void userrec::InviteTo(irc::string &channel)
430 invites.push_back(i);
433 void userrec::RemoveInvite(irc::string &channel)
435 ServerInstance->Log(DEBUG,"Removing invites");
439 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
441 irc::string compare = i->channel;
443 if (compare == channel)
452 bool userrec::HasPermission(const std::string &command)
459 * users on remote servers can completely bypass all permissions based checks.
460 * This prevents desyncs when one server has different type/class tags to another.
461 * That having been said, this does open things up to the possibility of source changes
462 * allowing remote kills, etc - but if they have access to the src, they most likely have
463 * access to the conf - so it's an end to a means either way.
468 // are they even an oper at all?
471 opertype_t::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper);
472 if (iter_opertype != ServerInstance->Config->opertypes.end())
474 char* Classes = strdup(iter_opertype->second);
475 char* myclass = strtok_r(Classes," ",&savept);
478 operclass_t::iterator iter_operclass = ServerInstance->Config->operclass.find(myclass);
479 if (iter_operclass != ServerInstance->Config->operclass.end())
481 char* CommandList = strdup(iter_operclass->second);
482 mycmd = strtok_r(CommandList," ",&savept2);
485 if ((!strcasecmp(mycmd,command.c_str())) || (*mycmd == '*'))
491 mycmd = strtok_r(NULL," ",&savept2);
495 myclass = strtok_r(NULL," ",&savept);
503 /** NOTE: We cannot pass a const reference to this method.
504 * The string is changed by the workings of the method,
505 * so that if we pass const ref, we end up copying it to
506 * something we can change anyway. Makes sense to just let
507 * the compiler do that copy for us.
509 bool userrec::AddBuffer(std::string a)
513 std::string::size_type i = a.rfind('\r');
515 while (i != std::string::npos)
524 if (recvq.length() > (unsigned)this->recvqmax)
526 this->SetWriteError("RecvQ exceeded");
527 ServerInstance->WriteOpers("*** User %s RecvQ of %d exceeds connect class maximum of %d",this->nick,recvq.length(),this->recvqmax);
536 ServerInstance->Log(DEBUG,"Exception in userrec::AddBuffer()");
541 bool userrec::BufferIsReady()
543 return (recvq.find('\n') != std::string::npos);
546 void userrec::ClearBuffer()
551 std::string userrec::GetBuffer()
558 /* Strip any leading \r or \n off the string.
559 * Usually there are only one or two of these,
560 * so its is computationally cheap to do.
562 while ((*recvq.begin() == '\r') || (*recvq.begin() == '\n'))
563 recvq.erase(recvq.begin());
565 for (std::string::iterator x = recvq.begin(); x != recvq.end(); x++)
567 /* Find the first complete line, return it as the
568 * result, and leave the recvq as whats left
572 std::string ret = std::string(recvq.begin(), x);
573 recvq.erase(recvq.begin(), x + 1);
582 ServerInstance->Log(DEBUG,"Exception in userrec::GetBuffer()");
587 void userrec::AddWriteBuf(const std::string &data)
589 if (*this->GetWriteError())
592 if (sendq.length() + data.length() > (unsigned)this->sendqmax)
595 * Fix by brain - Set the error text BEFORE calling writeopers, because
596 * if we dont it'll recursively call here over and over again trying
597 * to repeatedly add the text to the sendq!
599 this->SetWriteError("SendQ exceeded");
600 ServerInstance->WriteOpers("*** User %s SendQ of %d exceeds connect class maximum of %d",this->nick,sendq.length() + data.length(),this->sendqmax);
606 if (data.length() > 512)
608 std::string newdata(data);
610 newdata.append("\r\n");
611 sendq.append(newdata);
620 this->SetWriteError("SendQ exceeded");
621 ServerInstance->WriteOpers("*** User %s SendQ got an exception",this->nick);
625 // send AS MUCH OF THE USERS SENDQ as we are able to (might not be all of it)
626 void userrec::FlushWriteBuf()
630 if (this->fd == FD_MAGIC_NUMBER)
634 if ((sendq.length()) && (this->fd != FD_MAGIC_NUMBER))
636 const char* tb = this->sendq.c_str();
637 int n_sent = write(this->fd,tb,this->sendq.length());
641 this->SetWriteError(strerror(errno));
648 // update the user's stats counters
649 this->bytes_out += n_sent;
657 ServerInstance->Log(DEBUG,"Exception in userrec::FlushWriteBuf()");
661 void userrec::SetWriteError(const std::string &error)
665 ServerInstance->Log(DEBUG,"SetWriteError: %s",error.c_str());
666 // don't try to set the error twice, its already set take the first string.
667 if (!this->WriteError.length())
669 ServerInstance->Log(DEBUG,"Setting error string for %s to '%s'",this->nick,error.c_str());
670 this->WriteError = error;
676 ServerInstance->Log(DEBUG,"Exception in userrec::SetWriteError()");
680 const char* userrec::GetWriteError()
682 return this->WriteError.c_str();
685 void userrec::Oper(const std::string &opertype)
689 this->modes[UM_OPERATOR] = 1;
690 this->WriteServ("MODE %s :+o", this->nick);
691 FOREACH_MOD(I_OnOper, OnOper(this, opertype));
692 ServerInstance->Log(DEFAULT,"OPER: %s!%s@%s opered as type: %s", this->nick, this->ident, this->host, opertype.c_str());
693 strlcpy(this->oper, opertype.c_str(), NICKMAX - 1);
694 ServerInstance->all_opers.push_back(this);
695 FOREACH_MOD(I_OnPostOper,OnPostOper(this, opertype));
700 ServerInstance->Log(DEBUG,"Exception in userrec::Oper()");
704 void userrec::UnOper()
711 this->modes[UM_OPERATOR] = 0;
712 for (std::vector<userrec*>::iterator a = ServerInstance->all_opers.begin(); a < ServerInstance->all_opers.end(); a++)
716 ServerInstance->Log(DEBUG,"Oper removed from optimization list");
717 ServerInstance->all_opers.erase(a);
726 ServerInstance->Log(DEBUG,"Exception in userrec::UnOper()");
730 void userrec::QuitUser(InspIRCd* Instance, userrec *user, const std::string &quitreason)
732 user_hash::iterator iter = Instance->clientlist.find(user->nick);
733 std::string reason = quitreason;
735 if (reason.length() > MAXQUIT - 1)
736 reason.resize(MAXQUIT - 1);
739 user->Write("ERROR :Closing link (%s@%s) [%s]",user->ident,user->host,reason.c_str());
741 if (user->registered == REG_ALL)
743 user->PurgeEmptyChannels();
744 FOREACH_MOD_I(Instance,I_OnUserQuit,OnUserQuit(user,reason));
745 user->WriteCommonExcept("QUIT :%s",reason.c_str());
749 user->FlushWriteBuf();
751 FOREACH_MOD_I(Instance,I_OnUserDisconnect,OnUserDisconnect(user));
755 if (Instance->Config->GetIOHook(user->GetPort()))
759 Instance->Config->GetIOHook(user->GetPort())->OnRawSocketClose(user->fd);
761 catch (ModuleException& modexcept)
763 Instance->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason());
767 Instance->SE->DelFd(user);
772 * this must come before the ServerInstance->SNO->WriteToSnoMaskso that it doesnt try to fill their buffer with anything
773 * if they were an oper with +sn +qQ.
775 if (user->registered == REG_ALL)
778 Instance->SNO->WriteToSnoMask('q',"Client exiting: %s!%s@%s [%s]",user->nick,user->ident,user->host,reason.c_str());
780 Instance->SNO->WriteToSnoMask('Q',"Client exiting on server %s: %s!%s@%s [%s]",user->server,user->nick,user->ident,user->host,reason.c_str());
784 if (iter != Instance->clientlist.end())
786 Instance->Log(DEBUG,"deleting user hash value %lx",(unsigned long)user);
789 if (find(Instance->local_users.begin(),Instance->local_users.end(),user) != Instance->local_users.end())
790 Instance->local_users.erase(find(Instance->local_users.begin(),Instance->local_users.end(),user));
792 Instance->clientlist.erase(iter);
802 WhoWasGroup::WhoWasGroup(userrec* user) : host(NULL), dhost(NULL), ident(NULL), server(NULL), gecos(NULL), signon(user->signon)
804 this->host = strdup(user->host);
805 this->dhost = strdup(user->dhost);
806 this->ident = strdup(user->ident);
807 this->server = user->server;
808 this->gecos = strdup(user->fullname);
811 WhoWasGroup::~WhoWasGroup()
823 /* every hour, run this function which removes all entries over 3 days */
824 void MaintainWhoWas(InspIRCd* ServerInstance, time_t t)
826 for (whowas_users::iterator iter = ServerInstance->whowas.begin(); iter != ServerInstance->whowas.end(); iter++)
828 whowas_set* n = (whowas_set*)iter->second;
831 while ((n->begin() != n->end()) && ((*n->begin())->signon < t - 259200)) // 3 days
833 WhoWasGroup *a = *(n->begin());
835 n->erase(n->begin());
843 /* adds or updates an entry in the whowas list */
844 void userrec::AddToWhoWas()
846 irc::whowas::whowas_users::iterator iter = ServerInstance->whowas.find(this->nick);
848 ServerInstance->Log(DEBUG,"Add to whowas lists");
850 if (iter == ServerInstance->whowas.end())
852 ServerInstance->Log(DEBUG,"Adding new whowas set for %s",this->nick);
853 irc::whowas::whowas_set* n = new irc::whowas::whowas_set;
854 irc::whowas::WhoWasGroup *a = new irc::whowas::WhoWasGroup(this);
856 ServerInstance->whowas[this->nick] = n;
860 irc::whowas::whowas_set* group = (irc::whowas::whowas_set*)iter->second;
862 ServerInstance->Log(DEBUG,"Using existing whowas group for %s",this->nick);
864 if (group->size() > 10)
866 ServerInstance->Log(DEBUG,"Trimming existing group to ten entries for %s",this->nick);
867 irc::whowas::WhoWasGroup *a = (irc::whowas::WhoWasGroup*)*(group->begin());
872 irc::whowas::WhoWasGroup *a = new irc::whowas::WhoWasGroup(this);
877 /* add a client connection to the sockets list */
878 void userrec::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, insp_inaddr ip)
880 std::string tempnick = ConvToStr(socket) + "-unknown";
881 user_hash::iterator iter = Instance->clientlist.find(tempnick);
882 const char *ipaddr = insp_ntoa(ip);
888 * as these nicknames are 'RFC impossible', we can be sure nobody is going to be
889 * using one as a registered connection. As they are per fd, we can also safely assume
890 * that we wont have collisions. Therefore, if the nick exists in the list, its only
891 * used by a dead socket, erase the iterator so that the new client may reclaim it.
892 * this was probably the cause of 'server ignores me when i hammer it with reconnects'
893 * issue in earlier alphas/betas
895 if (iter != Instance->clientlist.end())
897 userrec* goner = iter->second;
899 Instance->clientlist.erase(iter);
902 Instance->Log(DEBUG,"AddClient: %d %d %s",socket,port,ipaddr);
904 New = new userrec(Instance);
905 Instance->clientlist[tempnick] = New;
907 strlcpy(New->nick,tempnick.c_str(),NICKMAX-1);
909 New->server = Instance->FindServerNamePtr(Instance->Config->ServerName);
910 /* We don't need range checking here, we KNOW 'unknown\0' will fit into the ident field. */
911 strcpy(New->ident, "unknown");
913 New->registered = REG_NONE;
914 New->signon = Instance->Time() + Instance->Config->dns_timeout;
917 Instance->Log(DEBUG,"Setting socket addresses");
918 New->SetSockAddr(AF_FAMILY, ipaddr, port);
919 Instance->Log(DEBUG,"Socket addresses set.");
921 /* Smarter than your average bear^H^H^H^Hset of strlcpys. */
922 for (const char* temp = New->GetIPString(); *temp && j < 64; temp++, j++)
923 New->dhost[j] = New->host[j] = *temp;
924 New->dhost[j] = New->host[j] = 0;
926 Instance->Log(DEBUG,"Hosts set.");
928 // set the registration timeout for this user
929 unsigned long class_regtimeout = 90;
931 long class_threshold = 5;
932 long class_sqmax = 262144; // 256kb
933 long class_rqmax = 4096; // 4k
935 Instance->Log(DEBUG,"Class stuff set.");
937 for (ClassVector::iterator i = Instance->Config->Classes.begin(); i != Instance->Config->Classes.end(); i++)
939 if ((i->type == CC_ALLOW) && (match(ipaddr,i->host.c_str(),true)))
941 class_regtimeout = (unsigned long)i->registration_timeout;
942 class_flood = i->flood;
943 New->pingmax = i->pingtime;
944 class_threshold = i->threshold;
945 class_sqmax = i->sendqmax;
946 class_rqmax = i->recvqmax;
951 Instance->Log(DEBUG,"nping etc set.");
953 New->nping = Instance->Time() + New->pingmax + Instance->Config->dns_timeout;
954 New->timeout = Instance->Time() + class_regtimeout;
955 New->flood = class_flood;
956 New->threshold = class_threshold;
957 New->sendqmax = class_sqmax;
958 New->recvqmax = class_rqmax;
960 Instance->Log(DEBUG,"Push back to local users.");
961 Instance->local_users.push_back(New);
963 Instance->Log(DEBUG,"Check softlimit: %d %d %d",Instance->local_users.size(), Instance->Config->SoftLimit, MAXCLIENTS);
964 if ((Instance->local_users.size() > Instance->Config->SoftLimit) || (Instance->local_users.size() >= MAXCLIENTS))
966 Instance->Log(DEBUG,"Check softlimit failed");
967 Instance->WriteOpers("*** Warning: softlimit value has been reached: %d clients", Instance->Config->SoftLimit);
968 userrec::QuitUser(Instance, New,"No more connections allowed");
972 Instance->Log(DEBUG,"Softlimit passed.");
976 * this is done as a safety check to keep the file descriptors within range of fd_ref_table.
977 * its a pretty big but for the moment valid assumption:
978 * file descriptors are handed out starting at 0, and are recycled as theyre freed.
979 * therefore if there is ever an fd over 65535, 65536 clients must be connected to the
980 * irc server at once (or the irc server otherwise initiating this many connections, files etc)
981 * which for the time being is a physical impossibility (even the largest networks dont have more
982 * than about 10,000 users on ONE server!)
984 if ((unsigned int)socket >= MAX_DESCRIPTORS)
986 userrec::QuitUser(Instance, New, "Server is full");
990 Instance->Log(DEBUG,"socket < MAX_DESCRIPTORS passed.");
992 ELine* e = Instance->XLines->matches_exception(New);
995 Instance->Log(DEBUG,"Doesnt match eline.");
996 ZLine* r = Instance->XLines->matches_zline(ipaddr);
999 Instance->Log(DEBUG,"Matches zline.");
1000 char reason[MAXBUF];
1001 snprintf(reason,MAXBUF,"Z-Lined: %s",r->reason);
1002 userrec::QuitUser(Instance, New, reason);
1005 Instance->Log(DEBUG,"Doesnt match zline.");
1008 Instance->Log(DEBUG,"Check before AddFd.");
1012 Instance->Log(DEBUG,"Adding fd.");
1013 if (!Instance->SE->AddFd(New))
1015 Instance->Log(DEBUG,"Oops, fd already exists");
1016 userrec::QuitUser(Instance, New, "Internal error handling connection");
1021 New->WriteServ("NOTICE Auth :*** Looking up your hostname...");
1024 long userrec::GlobalCloneCount()
1028 strlcpy(u2, this->GetIPString(), 64);
1030 for (user_hash::const_iterator a = ServerInstance->clientlist.begin(); a != ServerInstance->clientlist.end(); a++)
1032 /* We have to match ip's as strings - we don't know what protocol
1033 * a remote user may be using
1035 if (strcasecmp(a->second->GetIPString(), u2) == 0)
1042 long userrec::LocalCloneCount()
1045 for (std::vector<userrec*>::const_iterator a = ServerInstance->local_users.begin(); a != ServerInstance->local_users.end(); a++)
1049 /* I dont think theres any faster way of matching two ipv6 addresses than memcmp */
1050 in6_addr* s1 = &(((sockaddr_in6*)comp->ip)->sin6_addr);
1051 in6_addr* s2 = &(((sockaddr_in6*)this->ip)->sin6_addr);
1052 if (!memcmp(s1->s6_addr, s2->s6_addr, sizeof(in6_addr)))
1055 in_addr* s1 = &((sockaddr_in*)comp->ip)->sin_addr;
1056 in_addr* s2 = &((sockaddr_in*)this->ip)->sin_addr;
1057 if (s1->s_addr == s2->s_addr)
1064 void userrec::FullConnect(CullList* Goners)
1066 ServerInstance->stats->statsConnects++;
1067 this->idle_lastmsg = ServerInstance->Time();
1069 ConnectClass a = this->GetClass();
1071 if (a.type == CC_DENY)
1073 Goners->AddItem(this,"Unauthorised connection");
1077 if ((*(a.pass.c_str())) && (!this->haspassed))
1079 Goners->AddItem(this,"Invalid password");
1083 if (this->LocalCloneCount() > a.maxlocal)
1085 Goners->AddItem(this, "No more connections allowed from your host via this connect class (local)");
1086 ServerInstance->WriteOpers("*** WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a.maxlocal, this->GetIPString());
1089 else if (this->GlobalCloneCount() > a.maxglobal)
1091 Goners->AddItem(this, "No more connections allowed from your host via this connect class (global)");
1092 ServerInstance->WriteOpers("*** WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s",a.maxglobal, this->GetIPString());
1096 ELine* e = ServerInstance->XLines->matches_exception(this);
1100 GLine* r = ServerInstance->XLines->matches_gline(this);
1104 char reason[MAXBUF];
1105 snprintf(reason,MAXBUF,"G-Lined: %s",r->reason);
1106 Goners->AddItem(this, reason);
1110 KLine* n = ServerInstance->XLines->matches_kline(this);
1114 char reason[MAXBUF];
1115 snprintf(reason,MAXBUF,"K-Lined: %s",n->reason);
1116 Goners->AddItem(this, reason);
1122 this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network);
1123 this->WriteServ("001 %s :Welcome to the %s IRC Network %s!%s@%s",this->nick, ServerInstance->Config->Network, this->nick, this->ident, this->host);
1124 this->WriteServ("002 %s :Your host is %s, running version %s",this->nick,ServerInstance->Config->ServerName,VERSION);
1125 this->WriteServ("003 %s :This server was created %s %s", this->nick, __TIME__, __DATE__);
1126 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());
1128 // anfl @ #ratbox, efnet reminded me that according to the RFC this cant contain more than 13 tokens per line...
1129 // so i'd better split it :)
1130 std::stringstream out(ServerInstance->Config->data005);
1131 std::string token = "";
1132 std::string line5 = "";
1133 int token_counter = 0;
1138 line5 = line5 + token + " ";
1141 if ((token_counter >= 13) || (out.eof() == true))
1143 this->WriteServ("005 %s %s:are supported by this server", this->nick, line5.c_str());
1152 * fix 3 by brain, move registered = 7 below these so that spurious modes and host
1153 * changes dont go out onto the network and produce 'fake direction'.
1155 FOREACH_MOD(I_OnUserConnect,OnUserConnect(this));
1157 this->registered = REG_ALL;
1159 FOREACH_MOD(I_OnPostConnect,OnPostConnect(this));
1161 ServerInstance->SNO->WriteToSnoMask('c',"Client connecting on port %d: %s!%s@%s [%s]", this->GetPort(), this->nick, this->ident, this->host, this->GetIPString());
1164 /** userrec::UpdateNick()
1165 * re-allocates a nick in the user_hash after they change nicknames,
1166 * returns a pointer to the new user as it may have moved
1168 userrec* userrec::UpdateNickHash(const char* New)
1172 //user_hash::iterator newnick;
1173 user_hash::iterator oldnick = ServerInstance->clientlist.find(this->nick);
1175 if (!strcasecmp(this->nick,New))
1176 return oldnick->second;
1178 if (oldnick == ServerInstance->clientlist.end())
1179 return NULL; /* doesnt exist */
1181 userrec* olduser = oldnick->second;
1182 ServerInstance->clientlist[New] = olduser;
1183 ServerInstance->clientlist.erase(oldnick);
1184 return ServerInstance->clientlist[New];
1189 ServerInstance->Log(DEBUG,"Exception in userrec::UpdateNickHash()");
1194 bool userrec::ForceNickChange(const char* newnick)
1200 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(this, newnick));
1204 ServerInstance->stats->statsCollisions++;
1208 if (ServerInstance->XLines->matches_qline(newnick))
1210 ServerInstance->stats->statsCollisions++;
1214 if (this->registered == REG_ALL)
1216 const char* pars[1];
1218 std::string cmd = "NICK";
1219 return (ServerInstance->Parser->CallHandler(cmd, pars, 1, this) == CMD_SUCCESS);
1226 ServerInstance->Log(DEBUG,"Exception in userrec::ForceNickChange()");
1231 void userrec::SetSockAddr(int protocol_family, const char* ip, int port)
1233 switch (protocol_family)
1235 #ifdef SUPPORT_IP6LINKS
1238 ServerInstance->Log(DEBUG,"Set inet6 protocol address");
1239 sockaddr_in6* sin = new sockaddr_in6;
1240 sin->sin6_family = AF_INET6;
1241 sin->sin6_port = port;
1242 inet_pton(AF_INET6, ip, &sin->sin6_addr);
1243 this->ip = (sockaddr*)sin;
1249 ServerInstance->Log(DEBUG,"Set inet4 protocol address");
1250 sockaddr_in* sin = new sockaddr_in;
1251 sin->sin_family = AF_INET;
1252 sin->sin_port = port;
1253 inet_pton(AF_INET, ip, &sin->sin_addr);
1254 this->ip = (sockaddr*)sin;
1258 ServerInstance->Log(DEBUG,"Ut oh, I dont know protocol %d to be set on '%s'!", protocol_family, this->nick);
1263 int userrec::GetPort()
1265 if (this->ip == NULL)
1268 switch (this->GetProtocolFamily())
1270 #ifdef SUPPORT_IP6LINKS
1273 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1274 return sin->sin6_port;
1280 sockaddr_in* sin = (sockaddr_in*)this->ip;
1281 return sin->sin_port;
1285 ServerInstance->Log(DEBUG,"Ut oh, '%s' has an unknown protocol family!",this->nick);
1291 int userrec::GetProtocolFamily()
1293 if (this->ip == NULL)
1296 sockaddr_in* sin = (sockaddr_in*)this->ip;
1297 return sin->sin_family;
1300 const char* userrec::GetIPString()
1302 static char buf[1024];
1304 if (this->ip == NULL)
1307 switch (this->GetProtocolFamily())
1309 #ifdef SUPPORT_IP6LINKS
1312 static char temp[1024];
1314 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1315 inet_ntop(sin->sin6_family, &sin->sin6_addr, buf, sizeof(buf));
1316 /* IP addresses starting with a : on irc are a Bad Thing (tm) */
1319 strlcpy(&temp[1], buf, sizeof(temp));
1329 sockaddr_in* sin = (sockaddr_in*)this->ip;
1330 inet_ntop(sin->sin_family, &sin->sin_addr, buf, sizeof(buf));
1335 ServerInstance->Log(DEBUG,"Ut oh, '%s' has an unknown protocol family!",this->nick);
1341 const char* userrec::GetIPString(char* buf)
1343 if (this->ip == NULL)
1349 switch (this->GetProtocolFamily())
1351 #ifdef SUPPORT_IP6LINKS
1354 static char temp[1024];
1356 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1357 inet_ntop(sin->sin6_family, &sin->sin6_addr, buf, sizeof(buf));
1358 /* IP addresses starting with a : on irc are a Bad Thing (tm) */
1361 strlcpy(&temp[1], buf, sizeof(temp));
1363 strlcpy(buf, temp, sizeof(temp));
1371 sockaddr_in* sin = (sockaddr_in*)this->ip;
1372 inet_ntop(sin->sin_family, &sin->sin_addr, buf, sizeof(buf));
1378 ServerInstance->Log(DEBUG,"Ut oh, '%s' has an unknown protocol family!",this->nick);
1384 /** NOTE: We cannot pass a const reference to this method.
1385 * The string is changed by the workings of the method,
1386 * so that if we pass const ref, we end up copying it to
1387 * something we can change anyway. Makes sense to just let
1388 * the compiler do that copy for us.
1390 void userrec::Write(std::string text)
1392 if ((this->fd < 0) || (this->fd > MAX_DESCRIPTORS))
1397 text.append("\r\n");
1401 ServerInstance->Log(DEBUG,"Exception in userrec::Write() std::string::append");
1405 if (ServerInstance->Config->GetIOHook(this->GetPort()))
1409 ServerInstance->Config->GetIOHook(this->GetPort())->OnRawSocketWrite(this->fd, text.data(), text.length());
1411 catch (ModuleException& modexcept)
1413 ServerInstance->Log(DEBUG,"Module exception caught: %s",modexcept.GetReason());
1418 this->AddWriteBuf(text);
1420 ServerInstance->stats->statsSent += text.length();
1425 void userrec::Write(const char *text, ...)
1428 char textbuffer[MAXBUF];
1430 va_start(argsPtr, text);
1431 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1434 this->Write(std::string(textbuffer));
1437 void userrec::WriteServ(const std::string& text)
1439 char textbuffer[MAXBUF];
1441 snprintf(textbuffer,MAXBUF,":%s %s",ServerInstance->Config->ServerName,text.c_str());
1442 this->Write(std::string(textbuffer));
1446 * Same as Write(), except `text' is prefixed with `:server.name '.
1448 void userrec::WriteServ(const char* text, ...)
1451 char textbuffer[MAXBUF];
1453 va_start(argsPtr, text);
1454 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1457 this->WriteServ(std::string(textbuffer));
1461 void userrec::WriteFrom(userrec *user, const std::string &text)
1465 snprintf(tb,MAXBUF,":%s %s",user->GetFullHost(),text.c_str());
1467 this->Write(std::string(tb));
1471 /* write text from an originating user to originating user */
1473 void userrec::WriteFrom(userrec *user, const char* text, ...)
1476 char textbuffer[MAXBUF];
1478 va_start(argsPtr, text);
1479 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1482 this->WriteFrom(user, std::string(textbuffer));
1486 /* write text to an destination user from a source user (e.g. user privmsg) */
1488 void userrec::WriteTo(userrec *dest, const char *data, ...)
1490 char textbuffer[MAXBUF];
1493 va_start(argsPtr, data);
1494 vsnprintf(textbuffer, MAXBUF, data, argsPtr);
1497 this->WriteTo(dest, std::string(textbuffer));
1500 void userrec::WriteTo(userrec *dest, const std::string &data)
1502 dest->WriteFrom(this, data);
1506 void userrec::WriteCommon(const char* text, ...)
1508 char textbuffer[MAXBUF];
1511 if (this->registered != REG_ALL)
1514 va_start(argsPtr, text);
1515 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1518 this->WriteCommon(std::string(textbuffer));
1521 void userrec::WriteCommon(const std::string &text)
1525 bool sent_to_at_least_one = false;
1527 if (this->registered != REG_ALL)
1532 for (std::vector<ucrec*>::const_iterator v = this->chans.begin(); v != this->chans.end(); v++)
1537 CUList *ulist= n->channel->GetUsers();
1539 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1541 if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
1543 already_sent[i->second->fd] = uniq_id;
1544 i->second->WriteFrom(this, std::string(text));
1545 sent_to_at_least_one = true;
1552 * if the user was not in any channels, no users will receive the text. Make sure the user
1553 * receives their OWN message for WriteCommon
1555 if (!sent_to_at_least_one)
1557 this->WriteFrom(this,std::string(text));
1563 ServerInstance->Log(DEBUG,"Exception in userrec::WriteCommon()");
1568 /* write a formatted string to all users who share at least one common
1569 * channel, NOT including the source user e.g. for use in QUIT
1572 void userrec::WriteCommonExcept(const char* text, ...)
1574 char textbuffer[MAXBUF];
1577 va_start(argsPtr, text);
1578 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1581 this->WriteCommonExcept(std::string(textbuffer));
1584 void userrec::WriteCommonExcept(const std::string &text)
1586 bool quit_munge = false;
1587 char oper_quit[MAXBUF];
1588 char textbuffer[MAXBUF];
1590 strlcpy(textbuffer, text.c_str(), MAXBUF);
1592 if (this->registered != REG_ALL)
1597 /* TODO: We need some form of WriteCommonExcept that will send two lines, one line to
1598 * opers and the other line to non-opers, then all this hidebans and hidesplits gunk
1601 if (ServerInstance->Config->HideSplits)
1603 char* check = textbuffer + 6;
1605 if (!strncasecmp(textbuffer, "QUIT :",6))
1607 std::stringstream split(check);
1608 std::string server_one;
1609 std::string server_two;
1611 split >> server_one;
1612 split >> server_two;
1614 if ((ServerInstance->FindServerName(server_one)) && (ServerInstance->FindServerName(server_two)))
1616 strlcpy(oper_quit,textbuffer,MAXQUIT);
1617 strlcpy(check,"*.net *.split",MAXQUIT);
1623 if ((ServerInstance->Config->HideBans) && (!quit_munge))
1625 if ((!strncasecmp(textbuffer, "QUIT :G-Lined:",14)) || (!strncasecmp(textbuffer, "QUIT :K-Lined:",14))
1626 || (!strncasecmp(textbuffer, "QUIT :Q-Lined:",14)) || (!strncasecmp(textbuffer, "QUIT :Z-Lined:",14)))
1628 char* check = textbuffer + 13;
1629 strlcpy(oper_quit,textbuffer,MAXQUIT);
1630 *check = 0; // We don't need to strlcpy, we just chop it from the :
1635 for (std::vector<ucrec*>::const_iterator v = this->chans.begin(); v != this->chans.end(); v++)
1640 CUList *ulist= n->channel->GetUsers();
1642 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1644 if (this != i->second)
1646 if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
1648 already_sent[i->second->fd] = uniq_id;
1650 i->second->WriteFrom(this, *i->second->oper ? std::string(oper_quit) : std::string(textbuffer));
1652 i->second->WriteFrom(this, std::string(textbuffer));
1661 void userrec::WriteWallOps(const std::string &text)
1663 /* Does nothing if theyre not opered */
1664 if ((!*this->oper) && (IS_LOCAL(this)))
1667 std::string wallop = "WALLOPS :";
1671 wallop.append(text);
1675 ServerInstance->Log(DEBUG,"Exception in userrec::Write() std::string::append");
1679 for (std::vector<userrec*>::const_iterator i = ServerInstance->local_users.begin(); i != ServerInstance->local_users.end(); i++)
1682 if ((IS_LOCAL(t)) && (t->modes[UM_WALLOPS]))
1683 this->WriteTo(t,wallop);
1687 void userrec::WriteWallOps(const char* text, ...)
1689 char textbuffer[MAXBUF];
1692 va_start(argsPtr, text);
1693 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1696 this->WriteWallOps(std::string(textbuffer));
1699 /* return 0 or 1 depending if users u and u2 share one or more common channels
1700 * (used by QUIT, NICK etc which arent channel specific notices)
1702 * The old algorithm in 1.0 for this was relatively inefficient, iterating over
1703 * the first users channels then the second users channels within the outer loop,
1704 * therefore it was a maximum of x*y iterations (upon returning 0 and checking
1705 * all possible iterations). However this new function instead checks against the
1706 * channel's userlist in the inner loop which is a std::map<userrec*,userrec*>
1707 * and saves us time as we already know what pointer value we are after.
1708 * Don't quote me on the maths as i am not a mathematician or computer scientist,
1709 * but i believe this algorithm is now x+(log y) maximum iterations instead.
1711 bool userrec::SharesChannelWith(userrec *other)
1713 if ((!other) || (this->registered != REG_ALL) || (other->registered != REG_ALL))
1717 for (std::vector<ucrec*>::const_iterator i = this->chans.begin(); i != this->chans.end(); i++)
1719 /* Fetch the channel from the user */
1720 ucrec* user_channel = *i;
1722 if (user_channel->channel)
1724 /* Eliminate the inner loop (which used to be ~equal in size to the outer loop)
1725 * by replacing it with a map::find which *should* be more efficient
1727 if (user_channel->channel->HasUser(other))
1734 int userrec::CountChannels()
1736 return ChannelCount;
1739 void userrec::ModChannelCount(int n)
1744 bool userrec::ChangeName(const char* gecos)
1746 if (!strcmp(gecos, this->fullname))
1752 FOREACH_RESULT(I_OnChangeLocalUserGECOS,OnChangeLocalUserGECOS(this,gecos));
1755 FOREACH_MOD(I_OnChangeName,OnChangeName(this,gecos));
1757 strlcpy(this->fullname,gecos,MAXGECOS+1);
1761 bool userrec::ChangeDisplayedHost(const char* host)
1763 if (!strcmp(host, this->dhost))
1769 FOREACH_RESULT(I_OnChangeLocalUserHost,OnChangeLocalUserHost(this,host));
1772 FOREACH_MOD(I_OnChangeHost,OnChangeHost(this,host));
1774 if (this->ServerInstance->Config->CycleHosts)
1775 this->WriteCommonExcept("%s","QUIT :Changing hosts");
1777 strlcpy(this->dhost,host,63);
1779 if (this->ServerInstance->Config->CycleHosts)
1781 for (std::vector<ucrec*>::const_iterator i = this->chans.begin(); i != this->chans.end(); i++)
1785 (*i)->channel->WriteAllExceptSender(this, false, 0, "JOIN %s", (*i)->channel->name);
1786 std::string n = this->ServerInstance->Modes->ModeString(this, (*i)->channel);
1788 (*i)->channel->WriteAllExceptSender(this, true, 0, "MODE %s +%s", (*i)->channel->name, n.c_str());
1794 this->WriteServ("396 %s %s :is now your hidden host",this->nick,this->dhost);
1799 bool userrec::ChangeIdent(const char* newident)
1801 if (!strcmp(newident, this->ident))
1804 if (this->ServerInstance->Config->CycleHosts)
1805 this->WriteCommonExcept("%s","QUIT :Changing ident");
1807 strlcpy(this->ident, newident, IDENTMAX+2);
1809 if (this->ServerInstance->Config->CycleHosts)
1811 for (std::vector<ucrec*>::const_iterator i = this->chans.begin(); i != this->chans.end(); i++)
1815 (*i)->channel->WriteAllExceptSender(this, false, 0, "JOIN %s", (*i)->channel->name);
1816 std::string n = this->ServerInstance->Modes->ModeString(this, (*i)->channel);
1818 (*i)->channel->WriteAllExceptSender(this, true, 0, "MODE %s +%s", (*i)->channel->name, n.c_str());
1826 void userrec::NoticeAll(char* text, ...)
1828 char textbuffer[MAXBUF];
1829 char formatbuffer[MAXBUF];
1832 va_start(argsPtr, text);
1833 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1836 snprintf(formatbuffer,MAXBUF,"NOTICE $* :%s",textbuffer);
1838 for (std::vector<userrec*>::const_iterator i = ServerInstance->local_users.begin(); i != ServerInstance->local_users.end(); i++)
1841 t->WriteFrom(this, std::string(formatbuffer));
1846 std::string userrec::ChannelList(userrec* source)
1851 for (std::vector<ucrec*>::const_iterator i = this->chans.begin(); i != this->chans.end(); i++)
1855 if(rec->channel && rec->channel->name)
1857 /* If the target is the same as the sender, let them see all their channels.
1858 * If the channel is NOT private/secret OR the user shares a common channel
1859 * If the user is an oper, and the <options:operspywhois> option is set.
1861 if ((source == this) || (*source->oper && ServerInstance->Config->OperSpyWhois) || (((!rec->channel->modes[CM_PRIVATE]) && (!rec->channel->modes[CM_SECRET])) || (rec->channel->HasUser(source))))
1863 list.append(rec->channel->GetPrefixChar(this)).append(rec->channel->name).append(" ");
1871 ServerInstance->Log(DEBUG,"Exception in userrec::ChannelList()");
1876 void userrec::SplitChanList(userrec* dest, const std::string &cl)
1879 std::ostringstream prefix;
1880 std::string::size_type start, pos, length;
1884 prefix << ":" << ServerInstance->Config->ServerName << " 319 " << this->nick << " " << dest->nick << " :";
1885 line = prefix.str();
1887 for (start = 0; (pos = cl.find(' ', start)) != std::string::npos; start = pos+1)
1889 length = (pos == std::string::npos) ? cl.length() : pos;
1891 if (line.length() + length - start > 510)
1894 line = prefix.str();
1897 if(pos == std::string::npos)
1899 line.append(cl.substr(start, length - start));
1904 line.append(cl.substr(start, length - start + 1));
1916 ServerInstance->Log(DEBUG,"Exception in userrec::SplitChanList()");
1921 /* looks up a users password for their connection class (<ALLOW>/<DENY> tags)
1922 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1923 * then their ip will be taken as 'priority' anyway, so for example,
1924 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1926 ConnectClass& userrec::GetClass()
1928 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1930 if ((match(this->GetIPString(),i->host.c_str(),true)) || (match(this->host,i->host.c_str())))
1934 return *(ServerInstance->Config->Classes.begin());
1937 void userrec::PurgeEmptyChannels()
1939 std::vector<chanrec*> to_delete;
1941 // firstly decrement the count on each channel
1942 for (std::vector<ucrec*>::iterator f = this->chans.begin(); f != this->chans.end(); f++)
1947 uc->channel->RemoveAllPrefixes(this);
1948 if (uc->channel->DelUser(this) == 0)
1950 /* No users left in here, mark it for deletion */
1953 to_delete.push_back(uc->channel);
1957 ServerInstance->Log(DEBUG,"Exception in userrec::PurgeEmptyChannels to_delete.push_back()");
1964 for (std::vector<chanrec*>::iterator n = to_delete.begin(); n != to_delete.end(); n++)
1966 chanrec* thischan = *n;
1967 chan_hash::iterator i2 = ServerInstance->chanlist.find(thischan->name);
1968 if (i2 != ServerInstance->chanlist.end())
1970 FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(i2->second));
1972 ServerInstance->chanlist.erase(i2);
1979 void userrec::ShowMOTD()
1981 if (!ServerInstance->Config->MOTD.size())
1983 this->WriteServ("422 %s :Message of the day file is missing.",this->nick);
1986 this->WriteServ("375 %s :%s message of the day", this->nick, ServerInstance->Config->ServerName);
1988 for (unsigned int i = 0; i < ServerInstance->Config->MOTD.size(); i++)
1989 this->WriteServ("372 %s :- %s",this->nick,ServerInstance->Config->MOTD[i].c_str());
1991 this->WriteServ("376 %s :End of message of the day.", this->nick);
1994 void userrec::ShowRULES()
1996 if (!ServerInstance->Config->RULES.size())
1998 this->WriteServ("NOTICE %s :Rules file is missing.",this->nick);
2001 this->WriteServ("NOTICE %s :%s rules",this->nick,ServerInstance->Config->ServerName);
2003 for (unsigned int i = 0; i < ServerInstance->Config->RULES.size(); i++)
2004 this->WriteServ("NOTICE %s :%s",this->nick,ServerInstance->Config->RULES[i].c_str());
2006 this->WriteServ("NOTICE %s :End of %s rules.",this->nick,ServerInstance->Config->ServerName);
2009 void userrec::HandleEvent(EventType et)
2011 /* WARNING: May delete this user! */
2014 ServerInstance->ProcessUser(this);
2018 ServerInstance->Log(DEBUG,"Exception in userrec::HandleEvent intercepted");