1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 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 * ---------------------------------------------------
18 #include "socketengine.h"
21 #include "commands/cmd_whowas.h"
23 /* XXX: Used for speeding up WriteCommon operations */
24 unsigned long uniq_id = 1;
26 static unsigned long* already_sent = NULL;
29 void InitializeAlreadySent(SocketEngine* SE)
31 already_sent = new unsigned long[SE->GetMaxFds()];
32 memset(already_sent, 0, SE->GetMaxFds() * sizeof(unsigned long));
36 std::string User::ProcessNoticeMasks(const char *sm)
38 bool adding = true, oldadding = false;
53 for (unsigned char d = 'A'; d <= 'z'; d++)
55 if (ServerInstance->SNO->IsEnabled(d))
57 if ((!IsNoticeMaskSet(d) && adding) || (IsNoticeMaskSet(d) && !adding))
59 if ((oldadding != adding) || (!output.length()))
60 output += (adding ? '+' : '-');
62 this->SetNoticeMask(d, adding);
71 if ((*c >= 'A') && (*c <= 'z') && (ServerInstance->SNO->IsEnabled(*c)))
73 if ((!IsNoticeMaskSet(*c) && adding) || (IsNoticeMaskSet(*c) && !adding))
75 if ((oldadding != adding) || (!output.length()))
76 output += (adding ? '+' : '-');
78 this->SetNoticeMask(*c, adding);
84 this->WriteNumeric(ERR_UNKNOWNSNOMASK, "%s %c :is unknown snomask char to me", this->nick.c_str(), *c);
96 void User::StartDNSLookup()
101 const char* sip = this->GetIPString(false);
102 UserResolver *res_reverse;
104 /* Special case for 4in6 (Have i mentioned i HATE 4in6?) */
105 if (!strncmp(sip, "0::ffff:", 8))
106 res_reverse = new UserResolver(this->ServerInstance, this, sip + 8, DNS_QUERY_PTR4, cached);
108 res_reverse = new UserResolver(this->ServerInstance, this, sip, this->GetProtocolFamily() == AF_INET ? DNS_QUERY_PTR4 : DNS_QUERY_PTR6, cached);
110 this->ServerInstance->AddResolver(res_reverse, cached);
112 catch (CoreException& e)
114 ServerInstance->Logs->Log("USERS", DEBUG,"Error in resolver: %s",e.GetReason());
118 bool User::IsNoticeMaskSet(unsigned char sm)
122 return (snomasks[sm-65]);
125 void User::SetNoticeMask(unsigned char sm, bool value)
129 snomasks[sm-65] = value;
132 const char* User::FormatNoticeMasks()
134 static char data[MAXBUF];
137 for (int n = 0; n < 64; n++)
140 data[offset++] = n+65;
147 bool User::IsModeSet(unsigned char m)
151 return (modes[m-65]);
154 void User::SetMode(unsigned char m, bool value)
161 const char* User::FormatModes(bool showparameters)
163 static char data[MAXBUF];
167 for (unsigned char n = 0; n < 64; n++)
171 data[offset++] = n + 65;
172 ModeHandler* mh = ServerInstance->Modes->FindMode(n + 65, MODETYPE_USER);
173 if (showparameters && mh && mh->GetNumParams(true))
175 std::string p = mh->GetUserParameter(this);
177 params.append(" ").append(p);
182 strlcat(data, params.c_str(), MAXBUF);
186 void User::DecrementModes()
188 ServerInstance->Logs->Log("USERS", DEBUG, "DecrementModes()");
189 for (unsigned char n = 'A'; n <= 'z'; n++)
193 ServerInstance->Logs->Log("USERS", DEBUG,"DecrementModes() found mode %c", n);
194 ModeHandler* mh = ServerInstance->Modes->FindMode(n, MODETYPE_USER);
197 ServerInstance->Logs->Log("USERS", DEBUG,"Found handler %c and call ChangeCount", n);
204 User::User(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance)
206 server = (char*)Instance->FindServerNamePtr(Instance->Config->ServerName);
207 reset_due = ServerInstance->Time();
208 age = ServerInstance->Time();
210 lines_in = lastping = signon = idle_lastmsg = nping = registered = 0;
211 bytes_in = bytes_out = cmds_in = cmds_out = 0;
212 quietquit = OverPenalty = ExemptFromPenalty = quitting = exempt = haspassed = dns_done = false;
219 AllowedOperCommands = NULL;
224 uuid.assign(Instance->GetUID(), 0, UUID_LENGTH - 1);
226 uuid.assign(uid, 0, UUID_LENGTH - 1);
228 ServerInstance->Logs->Log("USERS", DEBUG,"New UUID for user: %s (%s)", uuid.c_str(), uid.empty() ? "allocated new" : "used remote");
230 user_hash::iterator finduuid = Instance->Users->uuidlist->find(uuid);
231 if (finduuid == Instance->Users->uuidlist->end())
232 (*Instance->Users->uuidlist)[uuid] = this;
234 throw CoreException("Duplicate UUID "+std::string(uuid)+" in User constructor");
239 /* NULL for remote users :) */
242 this->MyClass->RefCount--;
243 ServerInstance->Logs->Log("USERS", DEBUG, "User destructor -- connect refcount now: %lu", this->MyClass->RefCount);
245 if (this->AllowedOperCommands)
247 delete AllowedOperCommands;
248 AllowedOperCommands = NULL;
251 this->InvalidateCache();
252 this->DecrementModes();
256 ServerInstance->Users->RemoveCloneCounts(this);
258 if (this->GetProtocolFamily() == AF_INET)
260 delete (sockaddr_in*)ip;
262 #ifdef SUPPORT_IP6LINKS
265 delete (sockaddr_in6*)ip;
270 ServerInstance->Users->uuidlist->erase(uuid);
273 const std::string& User::MakeHost()
275 if (!this->cached_makehost.empty())
276 return this->cached_makehost;
279 /* This is much faster than snprintf */
281 for(const char* n = ident.c_str(); *n; n++)
284 for(const char* n = host.c_str(); *n; n++)
288 this->cached_makehost.assign(nhost);
290 return this->cached_makehost;
293 const std::string& User::MakeHostIP()
295 if (!this->cached_hostip.empty())
296 return this->cached_hostip;
299 /* This is much faster than snprintf */
301 for(const char* n = ident.c_str(); *n; n++)
304 for(const char* n = this->GetIPString(); *n; n++)
308 this->cached_hostip = ihost;
310 return this->cached_hostip;
313 void User::CloseSocket()
317 ServerInstance->SE->Shutdown(this, 2);
318 ServerInstance->SE->Close(this);
322 const std::string& User::GetFullHost()
324 if (!this->cached_fullhost.empty())
325 return this->cached_fullhost;
329 for(const char* n = nick.c_str(); *n; n++)
332 for(const char* n = ident.c_str(); *n; n++)
335 for(const char* n = dhost.c_str(); *n; n++)
339 this->cached_fullhost = result;
341 return this->cached_fullhost;
344 char* User::MakeWildHost()
346 static char nresult[MAXBUF];
348 *t++ = '*'; *t++ = '!';
349 *t++ = '*'; *t++ = '@';
350 for(const char* n = dhost.c_str(); *n; n++)
356 int User::ReadData(void* buffer, size_t size)
361 return read(this->fd, buffer, size);
363 return recv(this->fd, (char*)buffer, size, 0);
371 const std::string& User::GetFullRealHost()
373 if (!this->cached_fullrealhost.empty())
374 return this->cached_fullrealhost;
376 char fresult[MAXBUF];
378 for(const char* n = nick.c_str(); *n; n++)
381 for(const char* n = ident.c_str(); *n; n++)
384 for(const char* n = host.c_str(); *n; n++)
388 this->cached_fullrealhost = fresult;
390 return this->cached_fullrealhost;
393 bool User::IsInvited(const irc::string &channel)
395 time_t now = time(NULL);
396 InvitedList::iterator safei;
397 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
399 if (channel == i->first)
401 if (i->second != 0 && now > i->second)
403 /* Expired invite, remove it. */
406 invites.erase(safei);
415 InvitedList* User::GetInviteList()
417 time_t now = time(NULL);
418 /* Weed out expired invites here. */
419 InvitedList::iterator safei;
420 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
422 if (i->second != 0 && now > i->second)
424 /* Expired invite, remove it. */
427 invites.erase(safei);
433 void User::InviteTo(const irc::string &channel, time_t invtimeout)
435 time_t now = time(NULL);
436 if (invtimeout != 0 && now > invtimeout) return; /* Don't add invites that are expired from the get-go. */
437 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
439 if (channel == i->first)
441 if (i->second != 0 && invtimeout > i->second)
443 i->second = invtimeout;
449 invites.push_back(std::make_pair(channel, invtimeout));
452 void User::RemoveInvite(const irc::string &channel)
454 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
456 if (channel == i->first)
464 bool User::HasModePermission(unsigned char mode, ModeType type)
472 if (mode < 'A' || mode > ('A' + 64)) return false;
474 return ((type == MODETYPE_USER ? AllowedUserModes : AllowedChanModes))[(mode - 'A')];
478 bool User::HasPermission(const std::string &command)
481 * users on remote servers can completely bypass all permissions based checks.
482 * This prevents desyncs when one server has different type/class tags to another.
483 * That having been said, this does open things up to the possibility of source changes
484 * allowing remote kills, etc - but if they have access to the src, they most likely have
485 * access to the conf - so it's an end to a means either way.
490 // are they even an oper at all?
496 if (!AllowedOperCommands)
499 if (AllowedOperCommands->find(command) != AllowedOperCommands->end())
501 else if (AllowedOperCommands->find("*") != AllowedOperCommands->end())
507 bool User::AddBuffer(const std::string &a)
509 std::string::size_type start = 0;
510 std::string::size_type i = a.find('\r');
513 * The old implementation here took a copy, and rfind() on \r, removing as it found them, before
514 * copying a second time onto the recvq. That's ok, but involves three copies minimum (recv() to buffer,
515 * buffer to here, here to recvq) - The new method now copies twice (recv() to buffer, buffer to recvq).
517 * We use find() instead of rfind() for clarity, however unlike the old code, our scanning of the string is
518 * contiguous: as we specify a startpoint, we never see characters we have scanned previously, making this
519 * marginally faster in cases with a number of \r hidden early on in the buffer.
522 * Start at first pos of string, find first \r, append everything in the chunk (excluding \r) to recvq. Set
523 * i ahead of the \r, search for next \r, add next chunk to buffer... repeat.
524 * -- w00t (7 may, 2008)
526 if (i == std::string::npos)
528 // no \r that we need to dance around, just add to buffer
533 // While we can find the end of a chunk to add
534 while (i != std::string::npos)
536 // Append the chunk that we have
537 recvq.append(a, start, (i - start));
539 // Start looking for the next one
541 i = a.find('\r', start);
544 if (start != a.length())
547 * This is here to catch a corner case when we get something like:
551 * in successive calls to us.
553 * Without this conditional, the 'U' on the second case will be dropped,
554 * which is most *certainly* not the behaviour we want!
557 recvq.append(a, start, (a.length() - start));
561 if (this->MyClass && (recvq.length() > this->MyClass->GetRecvqMax()))
563 ServerInstance->Users->QuitUser(this, "RecvQ exceeded");
564 ServerInstance->SNO->WriteToSnoMask('A', "User %s RecvQ of %lu exceeds connect class maximum of %lu",this->nick.c_str(),(unsigned long int)recvq.length(),this->MyClass->GetRecvqMax());
571 bool User::BufferIsReady()
573 return (recvq.find('\n') != std::string::npos);
576 void User::ClearBuffer()
581 std::string User::GetBuffer()
588 /* Strip any leading \r or \n off the string.
589 * Usually there are only one or two of these,
590 * so its is computationally cheap to do.
592 std::string::iterator t = recvq.begin();
593 while (t != recvq.end() && (*t == '\r' || *t == '\n'))
599 for (std::string::iterator x = recvq.begin(); x != recvq.end(); x++)
601 /* Find the first complete line, return it as the
602 * result, and leave the recvq as whats left
606 std::string ret = std::string(recvq.begin(), x);
607 recvq.erase(recvq.begin(), x + 1);
616 ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::GetBuffer()");
621 void User::AddWriteBuf(const std::string &data)
626 if (this->MyClass && (sendq.length() + data.length() > this->MyClass->GetSendqMax()))
629 * Fix by brain - Set the error text BEFORE calling, because
630 * if we dont it'll recursively call here over and over again trying
631 * to repeatedly add the text to the sendq!
633 ServerInstance->Users->QuitUser(this, "SendQ exceeded");
634 ServerInstance->SNO->WriteToSnoMask('A', "User %s SendQ of %lu exceeds connect class maximum of %lu",this->nick.c_str(),(unsigned long int)sendq.length() + data.length(),this->MyClass->GetSendqMax());
638 if (data.length() > MAXBUF - 2) /* MAXBUF has a value of 514, to account for line terminators */
639 sendq.append(data.substr(0,MAXBUF - 4)).append("\r\n"); /* MAXBUF-4 = 510 */
644 // send AS MUCH OF THE USERS SENDQ as we are able to (might not be all of it)
645 void User::FlushWriteBuf()
647 if (this->fd == FD_MAGIC_NUMBER)
653 if ((sendq.length()) && (this->fd != FD_MAGIC_NUMBER))
655 int old_sendq_length = sendq.length();
656 int n_sent = ServerInstance->SE->Send(this, this->sendq.data(), this->sendq.length(), 0);
662 /* The socket buffer is full. This isnt fatal,
665 ServerInstance->SE->WantWrite(this);
669 /* Fatal error, set write error and bail */
670 ServerInstance->Users->QuitUser(this, errno ? strerror(errno) : "Write error");
676 /* advance the queue */
678 this->sendq = this->sendq.substr(n_sent);
679 /* update the user's stats counters */
680 this->bytes_out += n_sent;
682 if (n_sent != old_sendq_length)
683 this->ServerInstance->SE->WantWrite(this);
687 /* note: NOT else if! */
688 if (this->sendq.empty())
690 FOREACH_MOD(I_OnBufferFlushed,OnBufferFlushed(this));
694 void User::Oper(const std::string &opertype, const std::string &opername)
696 if (this->IsModeSet('o'))
699 this->modes[UM_OPERATOR] = 1;
700 this->WriteServ("MODE %s :+o", this->nick.c_str());
701 FOREACH_MOD(I_OnOper, OnOper(this, opertype));
703 ServerInstance->SNO->WriteToSnoMask('o',"%s (%s@%s) is now an IRC operator of type %s (using oper '%s')", this->nick.c_str(), this->ident.c_str(), this->host.c_str(), irc::Spacify(opertype.c_str()), opername.c_str());
704 this->WriteNumeric(381, "%s :You are now %s %s", this->nick.c_str(), strchr("aeiouAEIOU", *opertype.c_str()) ? "an" : "a", irc::Spacify(opertype.c_str()));
706 ServerInstance->Logs->Log("OPER", DEFAULT, "%s!%s@%s opered as type: %s", this->nick.c_str(), this->ident.c_str(), this->host.c_str(), opertype.c_str());
707 this->oper.assign(opertype, 0, 512);
708 ServerInstance->Users->all_opers.push_back(this);
710 opertype_t::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper.c_str());
711 if (iter_opertype != ServerInstance->Config->opertypes.end())
714 if (AllowedOperCommands)
715 AllowedOperCommands->clear();
717 AllowedOperCommands = new std::map<std::string, bool>;
719 AllowedUserModes.reset();
720 AllowedChanModes.reset();
721 this->AllowedUserModes['o' - 'A'] = true; // Call me paranoid if you want.
723 std::string myclass, mycmd;
724 irc::spacesepstream Classes(iter_opertype->second);
725 while (Classes.GetToken(myclass))
727 operclass_t::iterator iter_operclass = ServerInstance->Config->operclass.find(myclass.c_str());
728 if (iter_operclass != ServerInstance->Config->operclass.end())
730 irc::spacesepstream CommandList(iter_operclass->second.commandlist);
731 while (CommandList.GetToken(mycmd))
733 this->AllowedOperCommands->insert(std::make_pair(mycmd, true));
735 for (unsigned char* c = (unsigned char*)iter_operclass->second.umodelist; *c; ++c)
739 this->AllowedUserModes.set();
743 this->AllowedUserModes[*c - 'A'] = true;
746 for (unsigned char* c = (unsigned char*)iter_operclass->second.cmodelist; *c; ++c)
750 this->AllowedChanModes.set();
754 this->AllowedChanModes[*c - 'A'] = true;
761 FOREACH_MOD(I_OnPostOper,OnPostOper(this, opertype, opername));
769 * unset their oper type (what IS_OPER checks).
770 * note, order is important - this must come before modes as -o attempts
771 * to call UnOper. -- w00t
775 /* Remove all oper only modes from the user when the deoper - Bug #466*/
776 std::string moderemove("-");
778 for (unsigned char letter = 'A'; letter <= 'z'; letter++)
780 ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_USER);
781 if (mh && mh->NeedsOper())
782 moderemove += letter;
785 std::vector<std::string> parameters;
786 parameters.push_back(this->nick);
787 parameters.push_back(moderemove);
789 ServerInstance->Parser->CallHandler("MODE", parameters, this);
791 /* remove the user from the oper list. Will remove multiple entries as a safeguard against bug #404 */
792 ServerInstance->Users->all_opers.remove(this);
794 if (AllowedOperCommands)
796 delete AllowedOperCommands;
797 AllowedOperCommands = NULL;
800 AllowedUserModes.reset();
801 AllowedChanModes.reset();
805 /* adds or updates an entry in the whowas list */
806 void User::AddToWhoWas()
808 Command* whowas_command = ServerInstance->Parser->GetHandler("WHOWAS");
811 std::deque<classbase*> params;
812 params.push_back(this);
813 whowas_command->HandleInternal(WHOWAS_ADD, params);
818 * Check class restrictions
820 void User::CheckClass()
822 ConnectClass* a = this->MyClass;
824 if ((!a) || (a->GetType() == CC_DENY))
826 ServerInstance->Users->QuitUser(this, "Unauthorised connection");
829 else if ((a->GetMaxLocal()) && (ServerInstance->Users->LocalCloneCount(this) > a->GetMaxLocal()))
831 ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (local)");
832 ServerInstance->SNO->WriteToSnoMask('A', "WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString());
835 else if ((a->GetMaxGlobal()) && (ServerInstance->Users->GlobalCloneCount(this) > a->GetMaxGlobal()))
837 ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (global)");
838 ServerInstance->SNO->WriteToSnoMask('A', "WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString());
842 this->nping = ServerInstance->Time() + a->GetPingTime() + ServerInstance->Config->dns_timeout;
845 bool User::CheckLines()
847 const char* check[] = { "G" , "K", NULL };
851 for (int n = 0; check[n]; ++n)
853 XLine *r = ServerInstance->XLines->MatchesLine(check[n], this);
866 void User::FullConnect()
868 ServerInstance->stats->statsConnects++;
869 this->idle_lastmsg = ServerInstance->Time();
872 * You may be thinking "wtf, we checked this in User::AddClient!" - and yes, we did, BUT.
873 * At the time AddClient is called, we don't have a resolved host, by here we probably do - which
874 * may put the user into a totally seperate class with different restrictions! so we *must* check again.
875 * Don't remove this! -- w00t
879 /* Check the password, if one is required by the user's connect class.
880 * This CANNOT be in CheckClass(), because that is called prior to PASS as well!
882 if (this->MyClass && !this->MyClass->GetPass().empty() && !this->haspassed)
884 ServerInstance->Users->QuitUser(this, "Invalid password");
888 if (this->CheckLines())
891 this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network);
892 this->WriteNumeric(RPL_WELCOME, "%s :Welcome to the %s IRC Network %s!%s@%s",this->nick.c_str(), ServerInstance->Config->Network, this->nick.c_str(), this->ident.c_str(), this->host.c_str());
893 this->WriteNumeric(RPL_YOURHOSTIS, "%s :Your host is %s, running version InspIRCd-1.2",this->nick.c_str(),ServerInstance->Config->ServerName);
894 this->WriteNumeric(RPL_SERVERCREATED, "%s :This server was created %s %s", this->nick.c_str(), __TIME__, __DATE__);
895 this->WriteNumeric(RPL_SERVERVERSION, "%s %s InspIRCd-1.2 %s %s %s", this->nick.c_str(), ServerInstance->Config->ServerName, ServerInstance->Modes->UserModeList().c_str(), ServerInstance->Modes->ChannelModeList().c_str(), ServerInstance->Modes->ParaModeList().c_str());
897 ServerInstance->Config->Send005(this);
898 this->WriteNumeric(RPL_YOURUUID, "%s %s :your unique ID", this->nick.c_str(), this->uuid.c_str());
904 if (ServerInstance->Users->unregistered_count)
905 ServerInstance->Users->unregistered_count--;
907 /* Trigger LUSERS output, give modules a chance too */
909 std::string command("LUSERS");
910 std::vector<std::string> parameters;
911 FOREACH_RESULT(I_OnPreCommand, OnPreCommand(command, parameters, this, true, "LUSERS"));
913 ServerInstance->CallCommandHandler(command, parameters, this);
916 * We don't set REG_ALL until triggering OnUserConnect, so some module events don't spew out stuff
917 * for a user that doesn't exist yet.
919 FOREACH_MOD(I_OnUserConnect,OnUserConnect(this));
921 this->registered = REG_ALL;
923 ServerInstance->PI->Introduce(this);
925 FOREACH_MOD(I_OnPostConnect,OnPostConnect(this));
927 ServerInstance->SNO->WriteToSnoMask('c',"Client connecting on port %d: %s!%s@%s [%s] [%s]", this->GetPort(), this->nick.c_str(), this->ident.c_str(), this->host.c_str(), this->GetIPString(), this->fullname.c_str());
928 ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCache: Adding NEGATIVE hit for %s", this->GetIPString());
929 ServerInstance->BanCache->AddHit(this->GetIPString(), "", "");
932 /** User::UpdateNick()
933 * re-allocates a nick in the user_hash after they change nicknames,
934 * returns a pointer to the new user as it may have moved
936 User* User::UpdateNickHash(const char* New)
938 //user_hash::iterator newnick;
939 user_hash::iterator oldnick = ServerInstance->Users->clientlist->find(this->nick);
941 if (!irc::string(this->nick.c_str()).compare(New))
942 return oldnick->second;
944 if (oldnick == ServerInstance->Users->clientlist->end())
945 return NULL; /* doesnt exist */
947 User* olduser = oldnick->second;
948 (*(ServerInstance->Users->clientlist))[New] = olduser;
949 ServerInstance->Users->clientlist->erase(oldnick);
953 void User::InvalidateCache()
955 /* Invalidate cache */
956 cached_fullhost.clear();
957 cached_hostip.clear();
958 cached_makehost.clear();
959 cached_fullrealhost.clear();
962 bool User::ForceNickChange(const char* newnick)
966 this->InvalidateCache();
968 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(this, newnick));
972 ServerInstance->stats->statsCollisions++;
976 std::deque<classbase*> dummy;
977 Command* nickhandler = ServerInstance->Parser->GetHandler("NICK");
978 if (nickhandler) // wtfbbq, when would this not be here
980 std::vector<std::string> parameters;
981 nickhandler->HandleInternal(1, dummy);
982 parameters.push_back(newnick);
983 bool result = (ServerInstance->Parser->CallHandler("NICK", parameters, this) == CMD_SUCCESS);
984 nickhandler->HandleInternal(0, dummy);
988 // Unreachable, we hope
992 void User::SetSockAddr(int protocol_family, const char* sip, int port)
996 switch (protocol_family)
998 #ifdef SUPPORT_IP6LINKS
1001 sockaddr_in6* sin = new sockaddr_in6;
1002 sin->sin6_family = AF_INET6;
1003 sin->sin6_port = port;
1004 inet_pton(AF_INET6, sip, &sin->sin6_addr);
1005 this->ip = (sockaddr*)sin;
1011 sockaddr_in* sin = new sockaddr_in;
1012 sin->sin_family = AF_INET;
1013 sin->sin_port = port;
1014 inet_pton(AF_INET, sip, &sin->sin_addr);
1015 this->ip = (sockaddr*)sin;
1019 ServerInstance->Logs->Log("USERS",DEBUG,"Uh oh, I dont know protocol %d to be set on '%s'!", protocol_family, this->nick.c_str());
1026 if (this->ip == NULL)
1029 switch (this->GetProtocolFamily())
1031 #ifdef SUPPORT_IP6LINKS
1034 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1035 return sin->sin6_port;
1041 sockaddr_in* sin = (sockaddr_in*)this->ip;
1042 return sin->sin_port;
1051 int User::GetProtocolFamily()
1053 if (this->ip == NULL)
1056 sockaddr_in* sin = (sockaddr_in*)this->ip;
1057 return sin->sin_family;
1060 const char* User::GetCIDRMask(int range)
1062 static char buf[44];
1064 if (this->ip == NULL)
1068 throw "Negative range, sorry, no.";
1071 * Original code written by Oliver Lupton (Om).
1072 * Integrated by me. Thanks. :) -- w00t
1074 switch (this->GetProtocolFamily())
1076 #ifdef SUPPORT_IP6LINKS
1079 /* unsigned char s6_addr[16]; */
1082 int i, bytestozero, extrabits;
1086 throw "CIDR mask width greater than address width (IPv6, 128 bit)";
1088 /* Access the user's IP structure directly */
1089 sin = (sockaddr_in6*)this->ip;
1091 /* To create the CIDR mask we want to set all the bits after 'range' bits of the address
1092 * to zero. This means the last (128 - range) bits of the address must be set to zero.
1093 * Hence this number divided by 8 is the number of whole bytes from the end of the address
1094 * which must be set to zero.
1096 bytestozero = (128 - range) / 8;
1098 /* Some of the least significant bits of the next most significant byte may also have to
1099 * be zeroed. The number of bits is the remainder of the above division.
1101 extrabits = (128 - range) % 8;
1103 /* Populate our working struct with the parts of the user's IP which are required in the
1104 * final CIDR mask. Set all the subsequent bytes to zero.
1105 * (16 - bytestozero) is the number of bytes which must be populated with actual IP data.
1107 for(i = 0; i < (16 - bytestozero); i++)
1109 v6.s6_addr[i] = sin->sin6_addr.s6_addr[i];
1112 /* And zero all the remaining bytes in the IP. */
1118 /* And finally, zero the extra bits required. */
1119 v6.s6_addr[15 - bytestozero] = (v6.s6_addr[15 - bytestozero] >> extrabits) << extrabits;
1121 snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET6, &v6, buffer, 40), range);
1133 throw "CIDR mask width greater than address width (IPv4, 32 bit)";
1135 /* Users already have a sockaddr* pointer (User::ip) which contains either a v4 or v6 structure */
1136 sin = (sockaddr_in*)this->ip;
1137 v4.s_addr = sin->sin_addr.s_addr;
1139 /* To create the CIDR mask we want to set all the bits after 'range' bits of the address
1140 * to zero. This means the last (32 - range) bits of the address must be set to zero.
1141 * This is done by shifting the value right and then back left by (32 - range) bits.
1145 v4.s_addr = ntohl(v4.s_addr);
1146 v4.s_addr = (v4.s_addr >> (32 - range)) << (32 - range);
1147 v4.s_addr = htonl(v4.s_addr);
1151 /* a range of zero would cause a 32 bit value to be shifted by 32 bits.
1152 * this has undefined behaviour, but for CIDR purposes the resulting mask
1153 * from a.b.c.d/0 is 0.0.0.0/0
1158 snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET, &v4, buffer, 16), range);
1164 return ""; // unused, but oh well
1167 const char* User::GetIPString(bool translate4in6)
1169 static char buf[40];
1171 if (this->ip == NULL)
1174 if (!this->cachedip.empty())
1175 return this->cachedip.c_str();
1177 switch (this->GetProtocolFamily())
1179 #ifdef SUPPORT_IP6LINKS
1182 static char temp[1024];
1184 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1185 inet_ntop(sin->sin6_family, &sin->sin6_addr, buf, sizeof(buf));
1186 /* IP addresses starting with a : on irc are a Bad Thing (tm) */
1189 strlcpy(&temp[1], buf, sizeof(temp) - 1);
1191 if (translate4in6 && !strncmp(temp, "0::ffff:", 8))
1193 this->cachedip = temp + 8;
1197 this->cachedip = temp;
1201 this->cachedip = buf;
1208 sockaddr_in* sin = (sockaddr_in*)this->ip;
1209 inet_ntop(sin->sin_family, &sin->sin_addr, buf, sizeof(buf));
1210 this->cachedip = buf;
1218 // Unreachable, probably
1222 /** NOTE: We cannot pass a const reference to this method.
1223 * The string is changed by the workings of the method,
1224 * so that if we pass const ref, we end up copying it to
1225 * something we can change anyway. Makes sense to just let
1226 * the compiler do that copy for us.
1228 void User::Write(std::string text)
1230 if (!ServerInstance->SE->BoundsCheckFd(this))
1235 ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"C[%d] O %s", this->GetFd(), text.c_str());
1236 text.append("\r\n");
1240 ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"Exception in User::Write() std::string::append");
1244 if (this->GetIOHook())
1246 /* XXX: The lack of buffering here is NOT a bug, modules implementing this interface have to
1247 * implement their own buffering mechanisms
1251 this->GetIOHook()->OnRawSocketWrite(this->fd, text.data(), text.length());
1253 catch (CoreException& modexcept)
1255 ServerInstance->Logs->Log("USEROUTPUT", DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
1260 this->AddWriteBuf(text);
1262 ServerInstance->stats->statsSent += text.length();
1263 this->ServerInstance->SE->WantWrite(this);
1268 void User::Write(const char *text, ...)
1271 char textbuffer[MAXBUF];
1273 va_start(argsPtr, text);
1274 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1277 this->Write(std::string(textbuffer));
1280 void User::WriteServ(const std::string& text)
1282 char textbuffer[MAXBUF];
1284 snprintf(textbuffer,MAXBUF,":%s %s",ServerInstance->Config->ServerName,text.c_str());
1285 this->Write(std::string(textbuffer));
1289 * Same as Write(), except `text' is prefixed with `:server.name '.
1291 void User::WriteServ(const char* text, ...)
1294 char textbuffer[MAXBUF];
1296 va_start(argsPtr, text);
1297 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1300 this->WriteServ(std::string(textbuffer));
1304 void User::WriteNumeric(unsigned int numeric, const char* text, ...)
1307 char textbuffer[MAXBUF];
1309 va_start(argsPtr, text);
1310 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1313 this->WriteNumeric(numeric, std::string(textbuffer));
1316 void User::WriteNumeric(unsigned int numeric, const std::string &text)
1318 char textbuffer[MAXBUF];
1321 FOREACH_RESULT(I_OnNumeric, OnNumeric(this, numeric, text));
1326 snprintf(textbuffer,MAXBUF,":%s %03u %s",ServerInstance->Config->ServerName, numeric, text.c_str());
1327 this->Write(std::string(textbuffer));
1330 void User::WriteFrom(User *user, const std::string &text)
1334 snprintf(tb,MAXBUF,":%s %s",user->GetFullHost().c_str(),text.c_str());
1336 this->Write(std::string(tb));
1340 /* write text from an originating user to originating user */
1342 void User::WriteFrom(User *user, const char* text, ...)
1345 char textbuffer[MAXBUF];
1347 va_start(argsPtr, text);
1348 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1351 this->WriteFrom(user, std::string(textbuffer));
1355 /* write text to an destination user from a source user (e.g. user privmsg) */
1357 void User::WriteTo(User *dest, const char *data, ...)
1359 char textbuffer[MAXBUF];
1362 va_start(argsPtr, data);
1363 vsnprintf(textbuffer, MAXBUF, data, argsPtr);
1366 this->WriteTo(dest, std::string(textbuffer));
1369 void User::WriteTo(User *dest, const std::string &data)
1371 dest->WriteFrom(this, data);
1375 void User::WriteCommon(const char* text, ...)
1377 char textbuffer[MAXBUF];
1380 if (this->registered != REG_ALL)
1383 va_start(argsPtr, text);
1384 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1387 this->WriteCommon(std::string(textbuffer));
1390 void User::WriteCommon(const std::string &text)
1392 bool sent_to_at_least_one = false;
1395 if (this->registered != REG_ALL)
1401 InitializeAlreadySent(ServerInstance->SE);
1403 /* We dont want to be doing this n times, just once */
1404 snprintf(tb,MAXBUF,":%s %s",this->GetFullHost().c_str(),text.c_str());
1405 std::string out = tb;
1407 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1409 CUList* ulist = v->first->GetUsers();
1410 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1412 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1414 already_sent[i->first->fd] = uniq_id;
1415 i->first->Write(out);
1416 sent_to_at_least_one = true;
1422 * if the user was not in any channels, no users will receive the text. Make sure the user
1423 * receives their OWN message for WriteCommon
1425 if (!sent_to_at_least_one)
1427 this->Write(std::string(tb));
1432 /* write a formatted string to all users who share at least one common
1433 * channel, NOT including the source user e.g. for use in QUIT
1436 void User::WriteCommonExcept(const char* text, ...)
1438 char textbuffer[MAXBUF];
1441 va_start(argsPtr, text);
1442 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1445 this->WriteCommonExcept(std::string(textbuffer));
1448 void User::WriteCommonQuit(const std::string &normal_text, const std::string &oper_text)
1453 if (this->registered != REG_ALL)
1459 InitializeAlreadySent(ServerInstance->SE);
1461 snprintf(tb1,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),normal_text.c_str());
1462 snprintf(tb2,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),oper_text.c_str());
1463 std::string out1 = tb1;
1464 std::string out2 = tb2;
1466 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1468 CUList *ulist = v->first->GetUsers();
1469 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1471 if (this != i->first)
1473 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1475 already_sent[i->first->fd] = uniq_id;
1476 i->first->Write(IS_OPER(i->first) ? out2 : out1);
1483 void User::WriteCommonExcept(const std::string &text)
1488 if (this->registered != REG_ALL)
1494 InitializeAlreadySent(ServerInstance->SE);
1496 snprintf(tb1,MAXBUF,":%s %s",this->GetFullHost().c_str(),text.c_str());
1499 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1501 CUList *ulist = v->first->GetUsers();
1502 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1504 if (this != i->first)
1506 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1508 already_sent[i->first->fd] = uniq_id;
1509 i->first->Write(out1);
1517 void User::WriteWallOps(const std::string &text)
1519 if (!IS_LOCAL(this))
1522 std::string wallop("WALLOPS :");
1523 wallop.append(text);
1525 for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
1528 if (t->IsModeSet('w'))
1529 this->WriteTo(t,wallop);
1533 void User::WriteWallOps(const char* text, ...)
1535 if (!IS_LOCAL(this))
1538 char textbuffer[MAXBUF];
1541 va_start(argsPtr, text);
1542 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1545 this->WriteWallOps(std::string(textbuffer));
1548 /* return 0 or 1 depending if users u and u2 share one or more common channels
1549 * (used by QUIT, NICK etc which arent channel specific notices)
1551 * The old algorithm in 1.0 for this was relatively inefficient, iterating over
1552 * the first users channels then the second users channels within the outer loop,
1553 * therefore it was a maximum of x*y iterations (upon returning 0 and checking
1554 * all possible iterations). However this new function instead checks against the
1555 * channel's userlist in the inner loop which is a std::map<User*,User*>
1556 * and saves us time as we already know what pointer value we are after.
1557 * Don't quote me on the maths as i am not a mathematician or computer scientist,
1558 * but i believe this algorithm is now x+(log y) maximum iterations instead.
1560 bool User::SharesChannelWith(User *other)
1562 if ((!other) || (this->registered != REG_ALL) || (other->registered != REG_ALL))
1566 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1568 /* Eliminate the inner loop (which used to be ~equal in size to the outer loop)
1569 * by replacing it with a map::find which *should* be more efficient
1571 if (i->first->HasUser(other))
1577 bool User::ChangeName(const char* gecos)
1579 if (!this->fullname.compare(gecos))
1585 FOREACH_RESULT(I_OnChangeLocalUserGECOS,OnChangeLocalUserGECOS(this,gecos));
1588 FOREACH_MOD(I_OnChangeName,OnChangeName(this,gecos));
1590 this->fullname.assign(gecos, 0, ServerInstance->Config->Limits.MaxGecos);
1595 bool User::ChangeDisplayedHost(const char* shost)
1603 FOREACH_RESULT(I_OnChangeLocalUserHost,OnChangeLocalUserHost(this,shost));
1606 FOREACH_MOD(I_OnChangeHost,OnChangeHost(this,shost));
1609 if (this->ServerInstance->Config->CycleHosts)
1610 this->WriteCommonExcept("QUIT :Changing hosts");
1612 /* Fix by Om: User::dhost is 65 long, this was truncating some long hosts */
1613 this->dhost.assign(shost, 0, 64);
1615 this->InvalidateCache();
1617 if (this->ServerInstance->Config->CycleHosts)
1619 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1621 i->first->WriteAllExceptSender(this, false, 0, "JOIN %s", i->first->name.c_str());
1622 std::string n = this->ServerInstance->Modes->ModeString(this, i->first);
1624 i->first->WriteAllExceptSender(this, true, 0, "MODE %s +%s", i->first->name.c_str(), n.c_str());
1629 this->WriteNumeric(RPL_YOURDISPLAYEDHOST, "%s %s :is now your displayed host",this->nick.c_str(),this->dhost.c_str());
1634 bool User::ChangeIdent(const char* newident)
1636 if (!this->ident.compare(newident))
1639 if (this->ServerInstance->Config->CycleHosts)
1640 this->WriteCommonExcept("%s","QUIT :Changing ident");
1642 this->ident.assign(newident, 0, ServerInstance->Config->Limits.IdentMax + 1);
1644 this->InvalidateCache();
1646 if (this->ServerInstance->Config->CycleHosts)
1648 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1650 i->first->WriteAllExceptSender(this, false, 0, "JOIN %s", i->first->name.c_str());
1651 std::string n = this->ServerInstance->Modes->ModeString(this, i->first);
1653 i->first->WriteAllExceptSender(this, true, 0, "MODE %s +%s", i->first->name.c_str(), n.c_str());
1660 void User::SendAll(const char* command, const char* text, ...)
1662 char textbuffer[MAXBUF];
1663 char formatbuffer[MAXBUF];
1666 va_start(argsPtr, text);
1667 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1670 snprintf(formatbuffer,MAXBUF,":%s %s $* :%s", this->GetFullHost().c_str(), command, textbuffer);
1671 std::string fmt = formatbuffer;
1673 for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
1680 std::string User::ChannelList(User* source)
1684 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1686 /* If the target is the same as the sender, let them see all their channels.
1687 * If the channel is NOT private/secret OR the user shares a common channel
1688 * If the user is an oper, and the <options:operspywhois> option is set.
1690 if ((source == this) || (IS_OPER(source) && ServerInstance->Config->OperSpyWhois) || (((!i->first->IsModeSet('p')) && (!i->first->IsModeSet('s'))) || (i->first->HasUser(source))))
1692 list.append(i->first->GetPrefixChar(this)).append(i->first->name).append(" ");
1699 void User::SplitChanList(User* dest, const std::string &cl)
1702 std::ostringstream prefix;
1703 std::string::size_type start, pos, length;
1705 prefix << this->nick << " " << dest->nick << " :";
1706 line = prefix.str();
1707 int namelen = strlen(ServerInstance->Config->ServerName) + 6;
1709 for (start = 0; (pos = cl.find(' ', start)) != std::string::npos; start = pos+1)
1711 length = (pos == std::string::npos) ? cl.length() : pos;
1713 if (line.length() + namelen + length - start > 510)
1715 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1716 line = prefix.str();
1719 if(pos == std::string::npos)
1721 line.append(cl.substr(start, length - start));
1726 line.append(cl.substr(start, length - start + 1));
1732 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1737 * Sets a user's connection class.
1738 * If the class name is provided, it will be used. Otherwise, the class will be guessed using host/ip/ident/etc.
1739 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1740 * then their ip will be taken as 'priority' anyway, so for example,
1741 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1743 ConnectClass* User::SetClass(const std::string &explicit_name)
1745 ConnectClass *found = NULL;
1747 if (!IS_LOCAL(this))
1750 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Setting connect class for UID %s", this->uuid.c_str());
1752 if (!explicit_name.empty())
1754 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1756 ConnectClass* c = *i;
1758 if (c->GetDisabled())
1759 continue; // can't possibly match, removed from conf
1761 if (explicit_name == c->GetName())
1763 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Explicitly set to %s", explicit_name.c_str());
1770 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1772 ConnectClass* c = *i;
1774 if (c->GetType() == CC_ALLOW)
1776 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "ALLOW %s %d %s", c->GetHost().c_str(), c->GetPort(), c->GetName().c_str());
1780 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "DENY %s %d %s", c->GetHost().c_str(), c->GetPort(), c->GetName().c_str());
1783 /* if it's disabled, we can't match this one. */
1784 if (c->GetDisabled())
1786 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Class disabled");
1790 /* check if host matches.. */
1791 if (!InspIRCd::MatchCIDR(this->GetIPString(), c->GetHost(), NULL) &&
1792 !InspIRCd::MatchCIDR(this->host, c->GetHost(), NULL))
1794 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "No host match (for %s)", c->GetHost().c_str());
1799 * deny change if change will take class over the limit check it HERE, not after we found a matching class,
1800 * because we should attempt to find another class if this one doesn't match us. -- w00t
1802 if (c->limit && (c->RefCount + 1 >= c->limit))
1804 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "OOPS: Connect class limit (%lu) hit, denying", c->limit);
1808 /* if it requires a port ... */
1811 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Requires port (%d)", c->GetPort());
1813 /* and our port doesn't match, fail. */
1814 if (this->GetPort() != c->GetPort())
1816 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Port match failed (%d)", this->GetPort());
1821 /* we stop at the first class that meets ALL critera. */
1828 * Okay, assuming we found a class that matches.. switch us into that class, keeping refcounts up to date.
1832 /* only fiddle with refcounts if they are already in a class .. */
1835 if (found == this->MyClass) // no point changing this shit :P
1836 return this->MyClass;
1837 this->MyClass->RefCount--;
1838 ServerInstance->Logs->Log("USERS", DEBUG, "Untying user from connect class -- refcount: %lu", this->MyClass->RefCount);
1841 this->MyClass = found;
1842 this->MyClass->RefCount++;
1843 ServerInstance->Logs->Log("USERS", DEBUG, "User tied to new class -- connect refcount now: %lu", this->MyClass->RefCount);
1846 return this->MyClass;
1849 /* looks up a users password for their connection class (<ALLOW>/<DENY> tags)
1850 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1851 * then their ip will be taken as 'priority' anyway, so for example,
1852 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1854 ConnectClass* User::GetClass()
1856 return this->MyClass;
1859 void User::PurgeEmptyChannels()
1861 std::vector<Channel*> to_delete;
1863 // firstly decrement the count on each channel
1864 for (UCListIter f = this->chans.begin(); f != this->chans.end(); f++)
1866 f->first->RemoveAllPrefixes(this);
1867 if (f->first->DelUser(this) == 0)
1869 /* No users left in here, mark it for deletion */
1872 to_delete.push_back(f->first);
1876 ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::PurgeEmptyChannels to_delete.push_back()");
1881 for (std::vector<Channel*>::iterator n = to_delete.begin(); n != to_delete.end(); n++)
1883 Channel* thischan = *n;
1884 chan_hash::iterator i2 = ServerInstance->chanlist->find(thischan->name);
1885 if (i2 != ServerInstance->chanlist->end())
1887 FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(i2->second));
1889 ServerInstance->chanlist->erase(i2);
1890 this->chans.erase(*n);
1897 void User::ShowMOTD()
1899 if (!ServerInstance->Config->MOTD.size())
1901 this->WriteNumeric(ERR_NOMOTD, "%s :Message of the day file is missing.",this->nick.c_str());
1904 this->WriteNumeric(RPL_MOTDSTART, "%s :%s message of the day", this->nick.c_str(), ServerInstance->Config->ServerName);
1906 for (file_cache::iterator i = ServerInstance->Config->MOTD.begin(); i != ServerInstance->Config->MOTD.end(); i++)
1907 this->WriteNumeric(RPL_MOTD, "%s :- %s",this->nick.c_str(),i->c_str());
1909 this->WriteNumeric(RPL_ENDOFMOTD, "%s :End of message of the day.", this->nick.c_str());
1912 void User::ShowRULES()
1914 if (!ServerInstance->Config->RULES.size())
1916 this->WriteNumeric(ERR_NORULES, "%s :RULES File is missing",this->nick.c_str());
1920 this->WriteNumeric(RPL_RULESTART, "%s :- %s Server Rules -",this->nick.c_str(),ServerInstance->Config->ServerName);
1922 for (file_cache::iterator i = ServerInstance->Config->RULES.begin(); i != ServerInstance->Config->RULES.end(); i++)
1923 this->WriteNumeric(RPL_RULES, "%s :- %s",this->nick.c_str(),i->c_str());
1925 this->WriteNumeric(RPL_RULESEND, "%s :End of RULES command.",this->nick.c_str());
1928 void User::HandleEvent(EventType et, int errornum)
1930 if (this->quitting) // drop everything, user is due to be quit
1936 ServerInstance->ProcessUser(this);
1939 this->FlushWriteBuf();
1942 ServerInstance->Users->QuitUser(this, errornum ? strerror(errornum) : "Client closed the connection");
1947 void User::SetOperQuit(const std::string &oquit)
1949 operquitmsg = oquit;
1952 const std::string& User::GetOperQuit()
1957 void User::IncreasePenalty(int increase)
1959 this->Penalty += increase;
1962 void User::DecreasePenalty(int decrease)
1964 this->Penalty -= decrease;
1975 bool VisData::VisibleTo(User* user)