1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 #include "socketengine.h"
19 #include "commands/cmd_whowas.h"
21 static unsigned long already_sent[MAX_DESCRIPTORS] = {0};
23 /* XXX: Used for speeding up WriteCommon operations */
24 unsigned long uniq_id = 0;
26 bool InitTypes(ServerConfig* conf, const char* tag)
28 if (conf->opertypes.size())
30 for (opertype_t::iterator n = conf->opertypes.begin(); n != conf->opertypes.end(); n++)
37 conf->opertypes.clear();
41 bool InitClasses(ServerConfig* conf, const char* tag)
43 if (conf->operclass.size())
45 for (operclass_t::iterator n = conf->operclass.begin(); n != conf->operclass.end(); n++)
52 conf->operclass.clear();
56 bool DoType(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
58 const char* TypeName = values[0].GetString();
59 const char* Classes = values[1].GetString();
61 conf->opertypes[TypeName] = strnewdup(Classes);
65 bool DoClass(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
67 const char* ClassName = values[0].GetString();
68 const char* CommandList = values[1].GetString();
70 conf->operclass[ClassName] = strnewdup(CommandList);
74 bool DoneClassesAndTypes(ServerConfig* conf, const char* tag)
79 std::string userrec::ProcessNoticeMasks(const char *sm)
81 bool adding = true, oldadding = false;
96 for (unsigned char d = 'A'; d <= 'z'; d++)
98 if (ServerInstance->SNO->IsEnabled(d))
100 if ((!IsNoticeMaskSet(d) && adding) || (IsNoticeMaskSet(d) && !adding))
102 if ((oldadding != adding) || (!output.length()))
103 output += (adding ? '+' : '-');
105 this->SetNoticeMask(d, adding);
114 if ((*c >= 'A') && (*c <= 'z') && (ServerInstance->SNO->IsEnabled(*c)))
116 if ((!IsNoticeMaskSet(*c) && adding) || (IsNoticeMaskSet(*c) && !adding))
118 if ((oldadding != adding) || (!output.length()))
119 output += (adding ? '+' : '-');
121 this->SetNoticeMask(*c, adding);
136 void userrec::StartDNSLookup()
141 const char* ip = this->GetIPString();
143 /* Special case for 4in6 (Have i mentioned i HATE 4in6?) */
144 if (!strncmp(ip, "0::ffff:", 8))
145 res_reverse = new UserResolver(this->ServerInstance, this, ip + 8, DNS_QUERY_PTR4, cached);
147 res_reverse = new UserResolver(this->ServerInstance, this, ip, this->GetProtocolFamily() == AF_INET ? DNS_QUERY_PTR4 : DNS_QUERY_PTR6, cached);
149 this->ServerInstance->AddResolver(res_reverse, cached);
151 catch (CoreException& e)
153 ServerInstance->Log(DEBUG,"Error in resolver: %s",e.GetReason());
157 UserResolver::UserResolver(InspIRCd* Instance, userrec* user, std::string to_resolve, QueryType qt, bool &cache) :
158 Resolver(Instance, to_resolve, qt, cache), bound_user(user)
160 this->fwd = (qt == DNS_QUERY_A || qt == DNS_QUERY_AAAA);
161 this->bound_fd = user->GetFd();
164 void UserResolver::OnLookupComplete(const std::string &result, unsigned int ttl, bool cached, int resultnum)
166 /* We are only interested in the first matching result */
170 if ((!this->fwd) && (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user))
172 this->bound_user->stored_host = result;
175 /* Check we didnt time out */
176 if (this->bound_user->registered != REG_ALL)
180 if (this->bound_user->GetProtocolFamily() == AF_INET6)
182 /* IPV6 forward lookup (with possibility of 4in6) */
183 const char* ip = this->bound_user->GetIPString();
184 bound_user->res_forward = new UserResolver(this->ServerInstance, this->bound_user, result, (!strncmp(ip, "0::ffff:", 8) ? DNS_QUERY_A : DNS_QUERY_AAAA), cached);
187 /* IPV4 lookup (mixed protocol mode) */
189 /* IPV4 lookup (ipv4 only mode) */
190 bound_user->res_forward = new UserResolver(this->ServerInstance, this->bound_user, result, DNS_QUERY_A, cached);
191 this->ServerInstance->AddResolver(bound_user->res_forward, cached);
194 catch (CoreException& e)
196 ServerInstance->Log(DEBUG,"Error in resolver: %s",e.GetReason());
199 else if ((this->fwd) && (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user))
201 /* Both lookups completed */
202 std::string result2("0::ffff:");
203 result2.append(result);
204 if (this->bound_user->GetIPString() == result || this->bound_user->GetIPString() == result2)
206 std::string hostname = this->bound_user->stored_host;
207 if (hostname.length() < 65)
209 /* Check we didnt time out */
210 if ((this->bound_user->registered != REG_ALL) && (!this->bound_user->dns_done))
212 /* Hostnames starting with : are not a good thing (tm) */
213 if (*(hostname.c_str()) == ':')
214 hostname.insert(0, "0");
216 this->bound_user->WriteServ("NOTICE Auth :*** Found your hostname (%s)%s", hostname.c_str(), (cached ? " -- cached" : ""));
217 this->bound_user->dns_done = true;
218 strlcpy(this->bound_user->dhost, hostname.c_str(),64);
219 strlcpy(this->bound_user->host, hostname.c_str(),64);
220 /* Invalidate cache */
221 this->bound_user->InvalidateCache();
226 if (!this->bound_user->dns_done)
228 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());
229 this->bound_user->dns_done = true;
235 if (!this->bound_user->dns_done)
237 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());
238 this->bound_user->dns_done = true;
244 void UserResolver::OnError(ResolverError e, const std::string &errormessage)
246 if (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user)
248 /* Since dns timeout is implemented outside of the resolver, this was a race condition that could result in this message being sent *after*
249 * the user was fully connected. This check fixes that issue - Special */
250 if (!this->bound_user->dns_done)
252 /* Error message here */
253 this->bound_user->WriteServ("NOTICE Auth :*** Could not resolve your hostname: %s; using your IP address (%s) instead.", errormessage.c_str(), this->bound_user->GetIPString());
254 this->bound_user->dns_done = true;
260 bool userrec::IsNoticeMaskSet(unsigned char sm)
262 return (snomasks[sm-65]);
265 void userrec::SetNoticeMask(unsigned char sm, bool value)
267 snomasks[sm-65] = value;
270 const char* userrec::FormatNoticeMasks()
272 static char data[MAXBUF];
275 for (int n = 0; n < 64; n++)
278 data[offset++] = n+65;
287 bool userrec::IsModeSet(unsigned char m)
289 return (modes[m-65]);
292 void userrec::SetMode(unsigned char m, bool value)
297 const char* userrec::FormatModes()
299 static char data[MAXBUF];
301 for (int n = 0; n < 64; n++)
304 data[offset++] = n+65;
310 void userrec::DecrementModes()
312 for (int n = 0; n < 64; n++)
316 ModeHandler* mh = ServerInstance->Modes->FindMode(n+65, MODETYPE_USER);
323 userrec::userrec(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance)
325 *password = *nick = *ident = *host = *dhost = *fullname = *awaymsg = *oper = *uuid = 0;
326 server = (char*)Instance->FindServerNamePtr(Instance->Config->ServerName);
327 reset_due = ServerInstance->Time();
328 age = ServerInstance->Time(true);
329 lines_in = lastping = signon = idle_lastmsg = nping = registered = 0;
330 ChannelCount = timeout = flood = bytes_in = bytes_out = cmds_in = cmds_out = 0;
331 muted = exempt = haspassed = dns_done = false;
336 res_forward = res_reverse = NULL;
341 memset(modes,0,sizeof(modes));
342 memset(snomasks,0,sizeof(snomasks));
343 /* Invalidate cache */
344 operquit = cached_fullhost = cached_hostip = cached_makehost = cached_fullrealhost = NULL;
347 strlcpy(uuid, Instance->GetUID().c_str(), UUID_LENGTH);
349 strlcpy(uuid, uid.c_str(), UUID_LENGTH);
351 ServerInstance->Log(DEBUG,"New UUID for user: %s (%s)", uuid, uid.empty() ? "allocated new" : "used remote");
353 user_hash::iterator finduuid = Instance->uuidlist->find(uuid);
354 if (finduuid == Instance->uuidlist->end())
355 (*Instance->uuidlist)[uuid] = this;
357 throw CoreException("Duplicate UUID "+std::string(uuid)+" in userrec constructor");
360 void userrec::RemoveCloneCounts()
362 clonemap::iterator x = ServerInstance->local_clones.find(this->GetIPString());
363 if (x != ServerInstance->local_clones.end())
368 ServerInstance->local_clones.erase(x);
372 clonemap::iterator y = ServerInstance->global_clones.find(this->GetIPString());
373 if (y != ServerInstance->global_clones.end())
378 ServerInstance->global_clones.erase(y);
385 this->InvalidateCache();
386 this->DecrementModes();
391 this->RemoveCloneCounts();
393 if (this->GetProtocolFamily() == AF_INET)
395 delete (sockaddr_in*)ip;
397 #ifdef SUPPORT_IP6LINKS
400 delete (sockaddr_in6*)ip;
405 ServerInstance->uuidlist->erase(uuid);
408 char* userrec::MakeHost()
410 if (this->cached_makehost)
411 return this->cached_makehost;
414 /* This is much faster than snprintf */
416 for(char* n = ident; *n; n++)
419 for(char* n = host; *n; n++)
423 this->cached_makehost = strdup(nhost);
425 return this->cached_makehost;
428 char* userrec::MakeHostIP()
430 if (this->cached_hostip)
431 return this->cached_hostip;
434 /* This is much faster than snprintf */
436 for(char* n = ident; *n; n++)
439 for(const char* n = this->GetIPString(); *n; n++)
443 this->cached_hostip = strdup(ihost);
445 return this->cached_hostip;
448 void userrec::CloseSocket()
450 ServerInstance->SE->Shutdown(this, 2);
451 ServerInstance->SE->Close(this);
454 char* userrec::GetFullHost()
456 if (this->cached_fullhost)
457 return this->cached_fullhost;
461 for(char* n = nick; *n; n++)
464 for(char* n = ident; *n; n++)
467 for(char* n = dhost; *n; n++)
471 this->cached_fullhost = strdup(result);
473 return this->cached_fullhost;
476 char* userrec::MakeWildHost()
478 static char nresult[MAXBUF];
480 *t++ = '*'; *t++ = '!';
481 *t++ = '*'; *t++ = '@';
482 for(char* n = dhost; *n; n++)
488 int userrec::ReadData(void* buffer, size_t size)
493 return read(this->fd, buffer, size);
495 return recv(this->fd, (char*)buffer, size, 0);
503 char* userrec::GetFullRealHost()
505 if (this->cached_fullrealhost)
506 return this->cached_fullrealhost;
508 char fresult[MAXBUF];
510 for(char* n = nick; *n; n++)
513 for(char* n = ident; *n; n++)
516 for(char* n = host; *n; n++)
520 this->cached_fullrealhost = strdup(fresult);
522 return this->cached_fullrealhost;
525 bool userrec::IsInvited(const irc::string &channel)
527 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
537 InvitedList* userrec::GetInviteList()
542 void userrec::InviteTo(const irc::string &channel)
544 invites.push_back(channel);
547 void userrec::RemoveInvite(const irc::string &channel)
549 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
559 bool userrec::HasPermission(const std::string &command)
566 * users on remote servers can completely bypass all permissions based checks.
567 * This prevents desyncs when one server has different type/class tags to another.
568 * That having been said, this does open things up to the possibility of source changes
569 * allowing remote kills, etc - but if they have access to the src, they most likely have
570 * access to the conf - so it's an end to a means either way.
575 // are they even an oper at all?
578 opertype_t::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper);
579 if (iter_opertype != ServerInstance->Config->opertypes.end())
581 char* Classes = strdup(iter_opertype->second);
582 char* myclass = strtok_r(Classes," ",&savept);
585 operclass_t::iterator iter_operclass = ServerInstance->Config->operclass.find(myclass);
586 if (iter_operclass != ServerInstance->Config->operclass.end())
588 char* CommandList = strdup(iter_operclass->second);
589 mycmd = strtok_r(CommandList," ",&savept2);
592 if ((!strcasecmp(mycmd,command.c_str())) || (*mycmd == '*'))
598 mycmd = strtok_r(NULL," ",&savept2);
602 myclass = strtok_r(NULL," ",&savept);
610 /** NOTE: We cannot pass a const reference to this method.
611 * The string is changed by the workings of the method,
612 * so that if we pass const ref, we end up copying it to
613 * something we can change anyway. Makes sense to just let
614 * the compiler do that copy for us.
616 bool userrec::AddBuffer(std::string a)
620 std::string::size_type i = a.rfind('\r');
622 while (i != std::string::npos)
631 if (recvq.length() > (unsigned)this->recvqmax)
633 this->SetWriteError("RecvQ exceeded");
634 ServerInstance->WriteOpers("*** User %s RecvQ of %d exceeds connect class maximum of %d",this->nick,recvq.length(),this->recvqmax);
643 ServerInstance->Log(DEBUG,"Exception in userrec::AddBuffer()");
648 bool userrec::BufferIsReady()
650 return (recvq.find('\n') != std::string::npos);
653 void userrec::ClearBuffer()
658 std::string userrec::GetBuffer()
665 /* Strip any leading \r or \n off the string.
666 * Usually there are only one or two of these,
667 * so its is computationally cheap to do.
669 std::string::iterator t = recvq.begin();
670 while (t != recvq.end() && (*t == '\r' || *t == '\n'))
676 for (std::string::iterator x = recvq.begin(); x != recvq.end(); x++)
678 /* Find the first complete line, return it as the
679 * result, and leave the recvq as whats left
683 std::string ret = std::string(recvq.begin(), x);
684 recvq.erase(recvq.begin(), x + 1);
693 ServerInstance->Log(DEBUG,"Exception in userrec::GetBuffer()");
698 void userrec::AddWriteBuf(const std::string &data)
700 if (*this->GetWriteError())
703 if (sendq.length() + data.length() > (unsigned)this->sendqmax)
706 * Fix by brain - Set the error text BEFORE calling writeopers, because
707 * if we dont it'll recursively call here over and over again trying
708 * to repeatedly add the text to the sendq!
710 this->SetWriteError("SendQ exceeded");
711 ServerInstance->WriteOpers("*** User %s SendQ of %d exceeds connect class maximum of %d",this->nick,sendq.length() + data.length(),this->sendqmax);
717 if (data.length() > MAXBUF - 2) /* MAXBUF has a value of 514, to account for line terminators */
718 sendq.append(data.substr(0,MAXBUF - 4)).append("\r\n"); /* MAXBUF-4 = 510 */
724 this->SetWriteError("SendQ exceeded");
725 ServerInstance->WriteOpers("*** User %s SendQ got an exception",this->nick);
729 // send AS MUCH OF THE USERS SENDQ as we are able to (might not be all of it)
730 void userrec::FlushWriteBuf()
734 if ((this->fd == FD_MAGIC_NUMBER) || (*this->GetWriteError()))
738 if ((sendq.length()) && (this->fd != FD_MAGIC_NUMBER))
740 int old_sendq_length = sendq.length();
741 int n_sent = ServerInstance->SE->Send(this, this->sendq.data(), this->sendq.length(), 0);
747 /* The socket buffer is full. This isnt fatal,
750 this->ServerInstance->SE->WantWrite(this);
754 /* Fatal error, set write error and bail
756 this->SetWriteError(errno ? strerror(errno) : "EOF from client");
762 /* advance the queue */
764 this->sendq = this->sendq.substr(n_sent);
765 /* update the user's stats counters */
766 this->bytes_out += n_sent;
768 if (n_sent != old_sendq_length)
769 this->ServerInstance->SE->WantWrite(this);
776 ServerInstance->Log(DEBUG,"Exception in userrec::FlushWriteBuf()");
779 if (this->sendq.empty())
781 FOREACH_MOD(I_OnBufferFlushed,OnBufferFlushed(this));
785 void userrec::SetWriteError(const std::string &error)
789 // don't try to set the error twice, its already set take the first string.
790 if (this->WriteError.empty())
791 this->WriteError = error;
796 ServerInstance->Log(DEBUG,"Exception in userrec::SetWriteError()");
800 const char* userrec::GetWriteError()
802 return this->WriteError.c_str();
805 void userrec::Oper(const std::string &opertype)
809 this->modes[UM_OPERATOR] = 1;
810 this->WriteServ("MODE %s :+o", this->nick);
811 FOREACH_MOD(I_OnOper, OnOper(this, opertype));
812 ServerInstance->Log(DEFAULT,"OPER: %s!%s@%s opered as type: %s", this->nick, this->ident, this->host, opertype.c_str());
813 strlcpy(this->oper, opertype.c_str(), NICKMAX - 1);
814 ServerInstance->all_opers.push_back(this);
815 FOREACH_MOD(I_OnPostOper,OnPostOper(this, opertype));
820 ServerInstance->Log(DEBUG,"Exception in userrec::Oper()");
824 void userrec::UnOper()
830 // unset their oper type (what IS_OPER checks), and remove +o
832 this->modes[UM_OPERATOR] = 0;
834 // remove them from the opers list.
835 for (std::vector<userrec*>::iterator a = ServerInstance->all_opers.begin(); a < ServerInstance->all_opers.end(); a++)
839 ServerInstance->all_opers.erase(a);
848 ServerInstance->Log(DEBUG,"Exception in userrec::UnOper()");
852 void userrec::QuitUser(InspIRCd* Instance, userrec *user, const std::string &quitreason, const char* operreason)
855 Instance->GlobalCulls.AddItem(user, quitreason.c_str(), operreason);
858 /* adds or updates an entry in the whowas list */
859 void userrec::AddToWhoWas()
861 command_t* whowas_command = ServerInstance->Parser->GetHandler("WHOWAS");
864 std::deque<classbase*> params;
865 params.push_back(this);
866 whowas_command->HandleInternal(WHOWAS_ADD, params);
870 /* add a client connection to the sockets list */
871 void userrec::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, int socketfamily, sockaddr* ip)
873 /* NOTE: Calling this one parameter constructor for userrec automatically
874 * allocates a new UUID and places it in the hash_map.
879 New = new userrec(Instance);
881 catch (CoreException &e)
883 Instance->Log(DEFAULT,"*** WTF *** Duplicated UUID! -- Crack smoking monkies have been unleashed.");
889 Instance->unregistered_count++;
893 if (socketfamily == AF_INET6)
894 inet_ntop(AF_INET6, &((const sockaddr_in6*)ip)->sin6_addr, ipaddr, sizeof(ipaddr));
897 inet_ntop(AF_INET, &((const sockaddr_in*)ip)->sin_addr, ipaddr, sizeof(ipaddr));
899 (*(Instance->clientlist))[New->uuid] = New;
902 /* The users default nick is their UUID */
903 strlcpy(New->nick, New->uuid, NICKMAX - 1);
905 New->server = Instance->FindServerNamePtr(Instance->Config->ServerName);
906 /* We don't need range checking here, we KNOW 'unknown\0' will fit into the ident field. */
907 strcpy(New->ident, "unknown");
909 New->registered = REG_NONE;
910 New->signon = Instance->Time() + Instance->Config->dns_timeout;
913 New->SetSockAddr(socketfamily, ipaddr, port);
915 /* Smarter than your average bear^H^H^H^Hset of strlcpys. */
916 for (const char* temp = New->GetIPString(); *temp && j < 64; temp++, j++)
917 New->dhost[j] = New->host[j] = *temp;
918 New->dhost[j] = New->host[j] = 0;
920 Instance->AddLocalClone(New);
921 Instance->AddGlobalClone(New);
924 * First class check. We do this again in FullConnect after DNS is done, and NICK/USER is recieved.
925 * See my note down there for why this is required. DO NOT REMOVE. :) -- w00t
927 ConnectClass* i = New->GetClass();
931 userrec::QuitUser(Instance, New, "Access denied by configuration");
936 * Check connect class settings and initialise settings into userrec.
937 * This will be done again after DNS resolution. -- w00t
941 Instance->local_users.push_back(New);
943 if ((Instance->local_users.size() > Instance->Config->SoftLimit) || (Instance->local_users.size() >= MAXCLIENTS))
945 Instance->WriteOpers("*** Warning: softlimit value has been reached: %d clients", Instance->Config->SoftLimit);
946 userrec::QuitUser(Instance, New,"No more connections allowed");
952 * this is done as a safety check to keep the file descriptors within range of fd_ref_table.
953 * its a pretty big but for the moment valid assumption:
954 * file descriptors are handed out starting at 0, and are recycled as theyre freed.
955 * therefore if there is ever an fd over 65535, 65536 clients must be connected to the
956 * irc server at once (or the irc server otherwise initiating this many connections, files etc)
957 * which for the time being is a physical impossibility (even the largest networks dont have more
958 * than about 10,000 users on ONE server!)
961 if ((unsigned int)socket >= MAX_DESCRIPTORS)
963 userrec::QuitUser(Instance, New, "Server is full");
968 New->exempt = (Instance->XLines->matches_exception(New) != NULL);
971 ZLine* r = Instance->XLines->matches_zline(ipaddr);
975 if (*Instance->Config->MoronBanner)
976 New->WriteServ("NOTICE %s :*** %s", New->nick, Instance->Config->MoronBanner);
977 snprintf(reason,MAXBUF,"Z-Lined: %s",r->reason);
978 userrec::QuitUser(Instance, New, reason);
985 if (!Instance->SE->AddFd(New))
987 userrec::QuitUser(Instance, New, "Internal error handling connection");
992 /* NOTE: even if dns lookups are *off*, we still need to display this.
993 * BOPM and other stuff requires it.
995 New->WriteServ("NOTICE Auth :*** Looking up your hostname...");
998 unsigned long userrec::GlobalCloneCount()
1000 clonemap::iterator x = ServerInstance->global_clones.find(this->GetIPString());
1001 if (x != ServerInstance->global_clones.end())
1007 unsigned long userrec::LocalCloneCount()
1009 clonemap::iterator x = ServerInstance->local_clones.find(this->GetIPString());
1010 if (x != ServerInstance->local_clones.end())
1017 * Check class restrictions
1019 void userrec::CheckClass(const std::string &explicit_class)
1021 ConnectClass* a = this->GetClass(explicit_class);
1023 if ((!a) || (a->GetType() == CC_DENY))
1025 userrec::QuitUser(ServerInstance, this, "Unauthorised connection");
1028 else if ((a->GetMaxLocal()) && (this->LocalCloneCount() > a->GetMaxLocal()))
1030 userrec::QuitUser(ServerInstance, this, "No more connections allowed from your host via this connect class (local)");
1031 ServerInstance->WriteOpers("*** WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString());
1034 else if ((a->GetMaxGlobal()) && (this->GlobalCloneCount() > a->GetMaxGlobal()))
1036 userrec::QuitUser(ServerInstance, this, "No more connections allowed from your host via this connect class (global)");
1037 ServerInstance->WriteOpers("*** WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString());
1041 this->pingmax = a->GetPingTime();
1042 this->nping = ServerInstance->Time() + a->GetPingTime() + ServerInstance->Config->dns_timeout;
1043 this->timeout = ServerInstance->Time() + a->GetRegTimeout();
1044 this->flood = a->GetFlood();
1045 this->threshold = a->GetThreshold();
1046 this->sendqmax = a->GetSendqMax();
1047 this->recvqmax = a->GetRecvqMax();
1048 this->MaxChans = a->GetMaxChans();
1051 void userrec::FullConnect()
1053 ServerInstance->stats->statsConnects++;
1054 this->idle_lastmsg = ServerInstance->Time();
1057 * You may be thinking "wtf, we checked this in userrec::AddClient!" - and yes, we did, BUT.
1058 * At the time AddClient is called, we don't have a resolved host, by here we probably do - which
1059 * may put the user into a totally seperate class with different restrictions! so we *must* check again.
1060 * Don't remove this! -- w00t
1064 /* Check the password, if one is required by the user's connect class.
1065 * This CANNOT be in CheckClass(), because that is called prior to PASS as well!
1067 if ((!this->GetClass()->GetPass().empty()) && (!this->haspassed))
1069 userrec::QuitUser(ServerInstance, this, "Invalid password");
1075 GLine* r = ServerInstance->XLines->matches_gline(this);
1080 char reason[MAXBUF];
1081 if (*ServerInstance->Config->MoronBanner)
1082 this->WriteServ("NOTICE %s :*** %s", this->nick, ServerInstance->Config->MoronBanner);
1083 snprintf(reason,MAXBUF,"G-Lined: %s",r->reason);
1084 userrec::QuitUser(ServerInstance, this, reason);
1088 KLine* n = ServerInstance->XLines->matches_kline(this);
1093 char reason[MAXBUF];
1094 if (*ServerInstance->Config->MoronBanner)
1095 this->WriteServ("NOTICE %s :*** %s", this, ServerInstance->Config->MoronBanner);
1096 snprintf(reason,MAXBUF,"K-Lined: %s",n->reason);
1097 userrec::QuitUser(ServerInstance, this, reason);
1102 this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network);
1103 this->WriteServ("001 %s :Welcome to the %s IRC Network %s!%s@%s",this->nick, ServerInstance->Config->Network, this->nick, this->ident, this->host);
1104 this->WriteServ("002 %s :Your host is %s, running version %s",this->nick,ServerInstance->Config->ServerName,VERSION);
1105 this->WriteServ("003 %s :This server was created %s %s", this->nick, __TIME__, __DATE__);
1106 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());
1108 ServerInstance->Config->Send005(this);
1110 this->WriteServ("042 %s %s :your unique ID", this->nick, this->uuid);
1115 /* Now registered */
1116 if (ServerInstance->unregistered_count)
1117 ServerInstance->unregistered_count--;
1119 /* Trigger LUSERS output, give modules a chance too */
1121 FOREACH_RESULT(I_OnPreCommand, OnPreCommand("LUSERS", NULL, 0, this, true, "LUSERS"));
1123 ServerInstance->CallCommandHandler("LUSERS", NULL, 0, this);
1126 * fix 3 by brain, move registered = 7 below these so that spurious modes and host
1127 * changes dont go out onto the network and produce 'fake direction'.
1129 FOREACH_MOD(I_OnUserConnect,OnUserConnect(this));
1131 this->registered = REG_ALL;
1133 FOREACH_MOD(I_OnPostConnect,OnPostConnect(this));
1135 ServerInstance->SNO->WriteToSnoMask('c',"Client connecting on port %d: %s!%s@%s [%s] [%s]", this->GetPort(), this->nick, this->ident, this->host, this->GetIPString(), this->fullname);
1138 /** userrec::UpdateNick()
1139 * re-allocates a nick in the user_hash after they change nicknames,
1140 * returns a pointer to the new user as it may have moved
1142 userrec* userrec::UpdateNickHash(const char* New)
1146 //user_hash::iterator newnick;
1147 user_hash::iterator oldnick = ServerInstance->clientlist->find(this->nick);
1149 if (!strcasecmp(this->nick,New))
1150 return oldnick->second;
1152 if (oldnick == ServerInstance->clientlist->end())
1153 return NULL; /* doesnt exist */
1155 userrec* olduser = oldnick->second;
1156 (*(ServerInstance->clientlist))[New] = olduser;
1157 ServerInstance->clientlist->erase(oldnick);
1163 ServerInstance->Log(DEBUG,"Exception in userrec::UpdateNickHash()");
1168 void userrec::InvalidateCache()
1170 /* Invalidate cache */
1171 if (cached_fullhost)
1172 free(cached_fullhost);
1174 free(cached_hostip);
1175 if (cached_makehost)
1176 free(cached_makehost);
1177 if (cached_fullrealhost)
1178 free(cached_fullrealhost);
1179 cached_fullhost = cached_hostip = cached_makehost = cached_fullrealhost = NULL;
1182 bool userrec::ForceNickChange(const char* newnick)
1188 this->InvalidateCache();
1190 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(this, newnick));
1194 ServerInstance->stats->statsCollisions++;
1198 if (ServerInstance->XLines->matches_qline(newnick))
1200 ServerInstance->stats->statsCollisions++;
1204 if (this->registered == REG_ALL)
1206 std::deque<classbase*> dummy;
1207 command_t* nickhandler = ServerInstance->Parser->GetHandler("NICK");
1210 nickhandler->HandleInternal(1, dummy);
1211 bool result = (ServerInstance->Parser->CallHandler("NICK", &newnick, 1, this) == CMD_SUCCESS);
1212 nickhandler->HandleInternal(0, dummy);
1221 ServerInstance->Log(DEBUG,"Exception in userrec::ForceNickChange()");
1226 void userrec::SetSockAddr(int protocol_family, const char* ip, int port)
1228 switch (protocol_family)
1230 #ifdef SUPPORT_IP6LINKS
1233 sockaddr_in6* sin = new sockaddr_in6;
1234 sin->sin6_family = AF_INET6;
1235 sin->sin6_port = port;
1236 inet_pton(AF_INET6, ip, &sin->sin6_addr);
1237 this->ip = (sockaddr*)sin;
1243 sockaddr_in* sin = new sockaddr_in;
1244 sin->sin_family = AF_INET;
1245 sin->sin_port = port;
1246 inet_pton(AF_INET, ip, &sin->sin_addr);
1247 this->ip = (sockaddr*)sin;
1251 ServerInstance->Log(DEBUG,"Ut oh, I dont know protocol %d to be set on '%s'!", protocol_family, this->nick);
1256 int userrec::GetPort()
1258 if (this->ip == NULL)
1261 switch (this->GetProtocolFamily())
1263 #ifdef SUPPORT_IP6LINKS
1266 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1267 return sin->sin6_port;
1273 sockaddr_in* sin = (sockaddr_in*)this->ip;
1274 return sin->sin_port;
1283 int userrec::GetProtocolFamily()
1285 if (this->ip == NULL)
1288 sockaddr_in* sin = (sockaddr_in*)this->ip;
1289 return sin->sin_family;
1292 const char* userrec::GetIPString()
1294 static char buf[1024];
1296 if (this->ip == NULL)
1299 switch (this->GetProtocolFamily())
1301 #ifdef SUPPORT_IP6LINKS
1304 static char temp[1024];
1306 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1307 inet_ntop(sin->sin6_family, &sin->sin6_addr, buf, sizeof(buf));
1308 /* IP addresses starting with a : on irc are a Bad Thing (tm) */
1311 strlcpy(&temp[1], buf, sizeof(temp) - 1);
1321 sockaddr_in* sin = (sockaddr_in*)this->ip;
1322 inet_ntop(sin->sin_family, &sin->sin_addr, buf, sizeof(buf));
1332 const char* userrec::GetIPString(char* buf)
1334 if (this->ip == NULL)
1340 switch (this->GetProtocolFamily())
1342 #ifdef SUPPORT_IP6LINKS
1345 static char temp[1024];
1347 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1348 inet_ntop(sin->sin6_family, &sin->sin6_addr, buf, sizeof(buf));
1349 /* IP addresses starting with a : on irc are a Bad Thing (tm) */
1352 strlcpy(&temp[1], buf, sizeof(temp) - 1);
1354 strlcpy(buf, temp, sizeof(temp));
1362 sockaddr_in* sin = (sockaddr_in*)this->ip;
1363 inet_ntop(sin->sin_family, &sin->sin_addr, buf, sizeof(buf));
1374 /** NOTE: We cannot pass a const reference to this method.
1375 * The string is changed by the workings of the method,
1376 * so that if we pass const ref, we end up copying it to
1377 * something we can change anyway. Makes sense to just let
1378 * the compiler do that copy for us.
1380 void userrec::Write(std::string text)
1382 if (!ServerInstance->SE->BoundsCheckFd(this))
1387 /* ServerInstance->Log(DEBUG,"C[%d] O %s", this->GetFd(), text.c_str());
1388 * WARNING: The above debug line is VERY loud, do NOT
1389 * enable it till we have a good way of filtering it
1390 * out of the logs (e.g. 1.2 would be good).
1392 text.append("\r\n");
1396 ServerInstance->Log(DEBUG,"Exception in userrec::Write() std::string::append");
1400 if (ServerInstance->Config->GetIOHook(this->GetPort()))
1404 /* XXX: The lack of buffering here is NOT a bug, modules implementing this interface have to
1405 * implement their own buffering mechanisms
1407 ServerInstance->Config->GetIOHook(this->GetPort())->OnRawSocketWrite(this->fd, text.data(), text.length());
1409 catch (CoreException& modexcept)
1411 ServerInstance->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
1416 this->AddWriteBuf(text);
1418 ServerInstance->stats->statsSent += text.length();
1419 this->ServerInstance->SE->WantWrite(this);
1424 void userrec::Write(const char *text, ...)
1427 char textbuffer[MAXBUF];
1429 va_start(argsPtr, text);
1430 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1433 this->Write(std::string(textbuffer));
1436 void userrec::WriteServ(const std::string& text)
1438 char textbuffer[MAXBUF];
1440 snprintf(textbuffer,MAXBUF,":%s %s",ServerInstance->Config->ServerName,text.c_str());
1441 this->Write(std::string(textbuffer));
1445 * Same as Write(), except `text' is prefixed with `:server.name '.
1447 void userrec::WriteServ(const char* text, ...)
1450 char textbuffer[MAXBUF];
1452 va_start(argsPtr, text);
1453 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1456 this->WriteServ(std::string(textbuffer));
1460 void userrec::WriteFrom(userrec *user, const std::string &text)
1464 snprintf(tb,MAXBUF,":%s %s",user->GetFullHost(),text.c_str());
1466 this->Write(std::string(tb));
1470 /* write text from an originating user to originating user */
1472 void userrec::WriteFrom(userrec *user, const char* text, ...)
1475 char textbuffer[MAXBUF];
1477 va_start(argsPtr, text);
1478 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1481 this->WriteFrom(user, std::string(textbuffer));
1485 /* write text to an destination user from a source user (e.g. user privmsg) */
1487 void userrec::WriteTo(userrec *dest, const char *data, ...)
1489 char textbuffer[MAXBUF];
1492 va_start(argsPtr, data);
1493 vsnprintf(textbuffer, MAXBUF, data, argsPtr);
1496 this->WriteTo(dest, std::string(textbuffer));
1499 void userrec::WriteTo(userrec *dest, const std::string &data)
1501 dest->WriteFrom(this, data);
1505 void userrec::WriteCommon(const char* text, ...)
1507 char textbuffer[MAXBUF];
1510 if (this->registered != REG_ALL)
1513 va_start(argsPtr, text);
1514 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1517 this->WriteCommon(std::string(textbuffer));
1520 void userrec::WriteCommon(const std::string &text)
1524 bool sent_to_at_least_one = false;
1527 if (this->registered != REG_ALL)
1532 /* We dont want to be doing this n times, just once */
1533 snprintf(tb,MAXBUF,":%s %s",this->GetFullHost(),text.c_str());
1534 std::string out = tb;
1536 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1538 CUList* ulist = v->first->GetUsers();
1539 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1541 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1543 already_sent[i->first->fd] = uniq_id;
1544 i->first->Write(out);
1545 sent_to_at_least_one = true;
1551 * if the user was not in any channels, no users will receive the text. Make sure the user
1552 * receives their OWN message for WriteCommon
1554 if (!sent_to_at_least_one)
1556 this->Write(std::string(tb));
1562 ServerInstance->Log(DEBUG,"Exception in userrec::WriteCommon()");
1567 /* write a formatted string to all users who share at least one common
1568 * channel, NOT including the source user e.g. for use in QUIT
1571 void userrec::WriteCommonExcept(const char* text, ...)
1573 char textbuffer[MAXBUF];
1576 va_start(argsPtr, text);
1577 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1580 this->WriteCommonExcept(std::string(textbuffer));
1583 void userrec::WriteCommonQuit(const std::string &normal_text, const std::string &oper_text)
1588 if (this->registered != REG_ALL)
1592 snprintf(tb1,MAXBUF,":%s QUIT :%s",this->GetFullHost(),normal_text.c_str());
1593 snprintf(tb2,MAXBUF,":%s QUIT :%s",this->GetFullHost(),oper_text.c_str());
1594 std::string out1 = tb1;
1595 std::string out2 = tb2;
1597 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1599 CUList *ulist = v->first->GetUsers();
1600 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1602 if (this != i->first)
1604 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1606 already_sent[i->first->fd] = uniq_id;
1607 i->first->Write(IS_OPER(i->first) ? out2 : out1);
1614 void userrec::WriteCommonExcept(const std::string &text)
1619 if (this->registered != REG_ALL)
1623 snprintf(tb1,MAXBUF,":%s %s",this->GetFullHost(),text.c_str());
1626 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1628 CUList *ulist = v->first->GetUsers();
1629 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1631 if (this != i->first)
1633 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1635 already_sent[i->first->fd] = uniq_id;
1636 i->first->Write(out1);
1644 void userrec::WriteWallOps(const std::string &text)
1646 if (!IS_OPER(this) && IS_LOCAL(this))
1649 std::string wallop("WALLOPS :");
1650 wallop.append(text);
1652 for (std::vector<userrec*>::const_iterator i = ServerInstance->local_users.begin(); i != ServerInstance->local_users.end(); i++)
1655 if (t->IsModeSet('w'))
1656 this->WriteTo(t,wallop);
1660 void userrec::WriteWallOps(const char* text, ...)
1662 char textbuffer[MAXBUF];
1665 va_start(argsPtr, text);
1666 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1669 this->WriteWallOps(std::string(textbuffer));
1672 /* return 0 or 1 depending if users u and u2 share one or more common channels
1673 * (used by QUIT, NICK etc which arent channel specific notices)
1675 * The old algorithm in 1.0 for this was relatively inefficient, iterating over
1676 * the first users channels then the second users channels within the outer loop,
1677 * therefore it was a maximum of x*y iterations (upon returning 0 and checking
1678 * all possible iterations). However this new function instead checks against the
1679 * channel's userlist in the inner loop which is a std::map<userrec*,userrec*>
1680 * and saves us time as we already know what pointer value we are after.
1681 * Don't quote me on the maths as i am not a mathematician or computer scientist,
1682 * but i believe this algorithm is now x+(log y) maximum iterations instead.
1684 bool userrec::SharesChannelWith(userrec *other)
1686 if ((!other) || (this->registered != REG_ALL) || (other->registered != REG_ALL))
1690 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1692 /* Eliminate the inner loop (which used to be ~equal in size to the outer loop)
1693 * by replacing it with a map::find which *should* be more efficient
1695 if (i->first->HasUser(other))
1701 bool userrec::ChangeName(const char* gecos)
1703 if (!strcmp(gecos, this->fullname))
1709 FOREACH_RESULT(I_OnChangeLocalUserGECOS,OnChangeLocalUserGECOS(this,gecos));
1712 FOREACH_MOD(I_OnChangeName,OnChangeName(this,gecos));
1714 strlcpy(this->fullname,gecos,MAXGECOS+1);
1719 bool userrec::ChangeDisplayedHost(const char* host)
1721 if (!strcmp(host, this->dhost))
1727 FOREACH_RESULT(I_OnChangeLocalUserHost,OnChangeLocalUserHost(this,host));
1730 FOREACH_MOD(I_OnChangeHost,OnChangeHost(this,host));
1732 if (this->ServerInstance->Config->CycleHosts)
1733 this->WriteCommonExcept("QUIT :Changing hosts");
1735 /* Fix by Om: userrec::dhost is 65 long, this was truncating some long hosts */
1736 strlcpy(this->dhost,host,64);
1738 this->InvalidateCache();
1740 if (this->ServerInstance->Config->CycleHosts)
1742 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1744 i->first->WriteAllExceptSender(this, false, 0, "JOIN %s", i->first->name);
1745 std::string n = this->ServerInstance->Modes->ModeString(this, i->first);
1747 i->first->WriteAllExceptSender(this, true, 0, "MODE %s +%s", i->first->name, n.c_str());
1752 this->WriteServ("396 %s %s :is now your displayed host",this->nick,this->dhost);
1757 bool userrec::ChangeIdent(const char* newident)
1759 if (!strcmp(newident, this->ident))
1762 if (this->ServerInstance->Config->CycleHosts)
1763 this->WriteCommonExcept("%s","QUIT :Changing ident");
1765 strlcpy(this->ident, newident, IDENTMAX+2);
1767 this->InvalidateCache();
1769 if (this->ServerInstance->Config->CycleHosts)
1771 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1773 i->first->WriteAllExceptSender(this, false, 0, "JOIN %s", i->first->name);
1774 std::string n = this->ServerInstance->Modes->ModeString(this, i->first);
1776 i->first->WriteAllExceptSender(this, true, 0, "MODE %s +%s", i->first->name, n.c_str());
1783 void userrec::SendAll(const char* command, char* text, ...)
1785 char textbuffer[MAXBUF];
1786 char formatbuffer[MAXBUF];
1789 va_start(argsPtr, text);
1790 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1793 snprintf(formatbuffer,MAXBUF,":%s %s $* :%s", this->GetFullHost(), command, textbuffer);
1794 std::string fmt = formatbuffer;
1796 for (std::vector<userrec*>::const_iterator i = ServerInstance->local_users.begin(); i != ServerInstance->local_users.end(); i++)
1803 std::string userrec::ChannelList(userrec* source)
1808 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1810 /* If the target is the same as the sender, let them see all their channels.
1811 * If the channel is NOT private/secret OR the user shares a common channel
1812 * If the user is an oper, and the <options:operspywhois> option is set.
1814 if ((source == this) || (IS_OPER(source) && ServerInstance->Config->OperSpyWhois) || (((!i->first->IsModeSet('p')) && (!i->first->IsModeSet('s'))) || (i->first->HasUser(source))))
1816 list.append(i->first->GetPrefixChar(this)).append(i->first->name).append(" ");
1823 ServerInstance->Log(DEBUG,"Exception in userrec::ChannelList()");
1828 void userrec::SplitChanList(userrec* dest, const std::string &cl)
1831 std::ostringstream prefix;
1832 std::string::size_type start, pos, length;
1836 prefix << this->nick << " " << dest->nick << " :";
1837 line = prefix.str();
1838 int namelen = strlen(ServerInstance->Config->ServerName) + 6;
1840 for (start = 0; (pos = cl.find(' ', start)) != std::string::npos; start = pos+1)
1842 length = (pos == std::string::npos) ? cl.length() : pos;
1844 if (line.length() + namelen + length - start > 510)
1846 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1847 line = prefix.str();
1850 if(pos == std::string::npos)
1852 line.append(cl.substr(start, length - start));
1857 line.append(cl.substr(start, length - start + 1));
1863 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1869 ServerInstance->Log(DEBUG,"Exception in userrec::SplitChanList()");
1873 unsigned int userrec::GetMaxChans()
1875 return this->MaxChans;
1878 /* looks up a users password for their connection class (<ALLOW>/<DENY> tags)
1879 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1880 * then their ip will be taken as 'priority' anyway, so for example,
1881 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1883 ConnectClass* userrec::GetClass(const std::string &explicit_name)
1885 if (!explicit_name.empty())
1887 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1889 if (explicit_name == i->GetName())
1895 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1897 if (((match(this->GetIPString(),i->GetHost().c_str(),true)) || (match(this->host,i->GetHost().c_str()))))
1901 if (this->GetPort() == i->GetPort())
1914 void userrec::PurgeEmptyChannels()
1916 std::vector<chanrec*> to_delete;
1918 // firstly decrement the count on each channel
1919 for (UCListIter f = this->chans.begin(); f != this->chans.end(); f++)
1921 f->first->RemoveAllPrefixes(this);
1922 if (f->first->DelUser(this) == 0)
1924 /* No users left in here, mark it for deletion */
1927 to_delete.push_back(f->first);
1931 ServerInstance->Log(DEBUG,"Exception in userrec::PurgeEmptyChannels to_delete.push_back()");
1936 for (std::vector<chanrec*>::iterator n = to_delete.begin(); n != to_delete.end(); n++)
1938 chanrec* thischan = *n;
1939 chan_hash::iterator i2 = ServerInstance->chanlist->find(thischan->name);
1940 if (i2 != ServerInstance->chanlist->end())
1942 FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(i2->second));
1944 ServerInstance->chanlist->erase(i2);
1945 this->chans.erase(*n);
1952 void userrec::ShowMOTD()
1954 if (!ServerInstance->Config->MOTD.size())
1956 this->WriteServ("422 %s :Message of the day file is missing.",this->nick);
1959 this->WriteServ("375 %s :%s message of the day", this->nick, ServerInstance->Config->ServerName);
1961 for (file_cache::iterator i = ServerInstance->Config->MOTD.begin(); i != ServerInstance->Config->MOTD.end(); i++)
1962 this->WriteServ("372 %s :- %s",this->nick,i->c_str());
1964 this->WriteServ("376 %s :End of message of the day.", this->nick);
1967 void userrec::ShowRULES()
1969 if (!ServerInstance->Config->RULES.size())
1971 this->WriteServ("434 %s :RULES File is missing",this->nick);
1975 this->WriteServ("308 %s :- %s Server Rules -",this->nick,ServerInstance->Config->ServerName);
1977 for (file_cache::iterator i = ServerInstance->Config->RULES.begin(); i != ServerInstance->Config->RULES.end(); i++)
1978 this->WriteServ("232 %s :- %s",this->nick,i->c_str());
1980 this->WriteServ("309 %s :End of RULES command.",this->nick);
1983 void userrec::HandleEvent(EventType et, int errornum)
1985 /* WARNING: May delete this user! */
1986 int thisfd = this->GetFd();
1993 ServerInstance->ProcessUser(this);
1996 this->FlushWriteBuf();
1999 /** This should be safe, but dont DARE do anything after it -- Brain */
2000 this->SetWriteError(errornum ? strerror(errornum) : "EOF from client");
2006 ServerInstance->Log(DEBUG,"Exception in userrec::HandleEvent intercepted");
2009 /* If the user has raised an error whilst being processed, quit them now we're safe to */
2010 if ((ServerInstance->SE->GetRef(thisfd) == this))
2012 if (!WriteError.empty())
2014 userrec::QuitUser(ServerInstance, this, GetWriteError());
2019 void userrec::SetOperQuit(const std::string &oquit)
2024 operquit = strdup(oquit.c_str());
2027 const char* userrec::GetOperQuit()
2029 return operquit ? operquit : "";
2040 bool VisData::VisibleTo(userrec* user)