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"
22 #include "commands/cmd_whowas.h"
24 /* XXX: Used for speeding up WriteCommon operations */
25 unsigned long uniq_id = 1;
27 static unsigned long* already_sent = NULL;
30 void InitializeAlreadySent(SocketEngine* SE)
32 already_sent = new unsigned long[SE->GetMaxFds()];
33 memset(already_sent, 0, SE->GetMaxFds() * sizeof(unsigned long));
37 std::string User::ProcessNoticeMasks(const char *sm)
39 bool adding = true, oldadding = false;
54 for (unsigned char d = 'A'; d <= 'z'; d++)
56 if (ServerInstance->SNO->IsEnabled(d))
58 if ((!IsNoticeMaskSet(d) && adding) || (IsNoticeMaskSet(d) && !adding))
60 if ((oldadding != adding) || (!output.length()))
61 output += (adding ? '+' : '-');
63 this->SetNoticeMask(d, adding);
72 if ((*c >= 'A') && (*c <= 'z') && (ServerInstance->SNO->IsEnabled(*c)))
74 if ((!IsNoticeMaskSet(*c) && adding) || (IsNoticeMaskSet(*c) && !adding))
76 if ((oldadding != adding) || (!output.length()))
77 output += (adding ? '+' : '-');
79 this->SetNoticeMask(*c, adding);
85 this->WriteNumeric(ERR_UNKNOWNSNOMASK, "%s %c :is unknown snomask char to me", this->nick.c_str(), *c);
97 void User::StartDNSLookup()
102 const char* sip = this->GetIPString(false);
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)
120 return (snomasks[sm-65]);
123 void User::SetNoticeMask(unsigned char sm, bool value)
125 snomasks[sm-65] = value;
128 const char* User::FormatNoticeMasks()
130 static char data[MAXBUF];
133 for (int n = 0; n < 64; n++)
136 data[offset++] = n+65;
145 bool User::IsModeSet(unsigned char m)
147 return (modes[m-65]);
150 void User::SetMode(unsigned char m, bool value)
155 const char* User::FormatModes()
157 static char data[MAXBUF];
159 for (int n = 0; n < 64; n++)
162 data[offset++] = n+65;
168 void User::DecrementModes()
170 ServerInstance->Logs->Log("USERS", DEBUG, "DecrementModes()");
171 for (unsigned char n = 'A'; n <= 'z'; n++)
175 ServerInstance->Logs->Log("USERS", DEBUG,"DecrementModes() found mode %c", n);
176 ModeHandler* mh = ServerInstance->Modes->FindMode(n, MODETYPE_USER);
179 ServerInstance->Logs->Log("USERS", DEBUG,"Found handler %c and call ChangeCount", n);
186 User::User(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance)
188 server = (char*)Instance->FindServerNamePtr(Instance->Config->ServerName);
189 reset_due = ServerInstance->Time();
190 age = ServerInstance->Time();
192 lines_in = lastping = signon = idle_lastmsg = nping = registered = 0;
193 bytes_in = bytes_out = cmds_in = cmds_out = 0;
194 quietquit = OverPenalty = ExemptFromPenalty = quitting = exempt = haspassed = dns_done = false;
198 res_forward = res_reverse = NULL;
203 AllowedUserModes = NULL;
204 AllowedChanModes = NULL;
205 AllowedOperCommands = NULL;
210 uuid.assign(Instance->GetUID(), 0, UUID_LENGTH - 1);
212 uuid.assign(uid, 0, UUID_LENGTH - 1);
214 ServerInstance->Logs->Log("USERS", DEBUG,"New UUID for user: %s (%s)", uuid.c_str(), uid.empty() ? "allocated new" : "used remote");
216 user_hash::iterator finduuid = Instance->Users->uuidlist->find(uuid);
217 if (finduuid == Instance->Users->uuidlist->end())
218 (*Instance->Users->uuidlist)[uuid] = this;
220 throw CoreException("Duplicate UUID "+std::string(uuid)+" in User constructor");
225 /* NULL for remote users :) */
228 this->MyClass->RefCount--;
229 ServerInstance->Logs->Log("USERS", DEBUG, "User destructor -- connect refcount now: %lu", this->MyClass->RefCount);
231 if (this->AllowedOperCommands)
233 delete AllowedOperCommands;
234 AllowedOperCommands = NULL;
237 if (this->AllowedUserModes)
239 delete[] AllowedUserModes;
240 AllowedUserModes = NULL;
243 if (this->AllowedChanModes)
245 delete[] AllowedChanModes;
246 AllowedChanModes = NULL;
249 this->InvalidateCache();
250 this->DecrementModes();
254 ServerInstance->Users->RemoveCloneCounts(this);
256 if (this->GetProtocolFamily() == AF_INET)
258 delete (sockaddr_in*)ip;
260 #ifdef SUPPORT_IP6LINKS
263 delete (sockaddr_in6*)ip;
268 ServerInstance->Users->uuidlist->erase(uuid);
271 const std::string& User::MakeHost()
273 if (!this->cached_makehost.empty())
274 return this->cached_makehost;
277 /* This is much faster than snprintf */
279 for(const char* n = ident.c_str(); *n; n++)
282 for(const char* n = host.c_str(); *n; n++)
286 this->cached_makehost.assign(nhost);
288 return this->cached_makehost;
291 const std::string& User::MakeHostIP()
293 if (!this->cached_hostip.empty())
294 return this->cached_hostip;
297 /* This is much faster than snprintf */
299 for(const char* n = ident.c_str(); *n; n++)
302 for(const char* n = this->GetIPString(); *n; n++)
306 this->cached_hostip = ihost;
308 return this->cached_hostip;
311 void User::CloseSocket()
315 ServerInstance->SE->Shutdown(this, 2);
316 ServerInstance->SE->Close(this);
320 const std::string& User::GetFullHost()
322 if (!this->cached_fullhost.empty())
323 return this->cached_fullhost;
327 for(const char* n = nick.c_str(); *n; n++)
330 for(const char* n = ident.c_str(); *n; n++)
333 for(const char* n = dhost.c_str(); *n; n++)
337 this->cached_fullhost = result;
339 return this->cached_fullhost;
342 char* User::MakeWildHost()
344 static char nresult[MAXBUF];
346 *t++ = '*'; *t++ = '!';
347 *t++ = '*'; *t++ = '@';
348 for(const char* n = dhost.c_str(); *n; n++)
354 int User::ReadData(void* buffer, size_t size)
359 return read(this->fd, buffer, size);
361 return recv(this->fd, (char*)buffer, size, 0);
369 const std::string& User::GetFullRealHost()
371 if (!this->cached_fullrealhost.empty())
372 return this->cached_fullrealhost;
374 char fresult[MAXBUF];
376 for(const char* n = nick.c_str(); *n; n++)
379 for(const char* n = ident.c_str(); *n; n++)
382 for(const char* n = host.c_str(); *n; n++)
386 this->cached_fullrealhost = fresult;
388 return this->cached_fullrealhost;
391 bool User::IsInvited(const irc::string &channel)
393 time_t now = time(NULL);
394 InvitedList::iterator safei;
395 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
397 if (channel == i->first)
399 if (i->second != 0 && now > i->second)
401 /* Expired invite, remove it. */
404 invites.erase(safei);
413 InvitedList* User::GetInviteList()
415 time_t now = time(NULL);
416 /* Weed out expired invites here. */
417 InvitedList::iterator safei;
418 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
420 if (i->second != 0 && now > i->second)
422 /* Expired invite, remove it. */
425 invites.erase(safei);
431 void User::InviteTo(const irc::string &channel, time_t invtimeout)
433 time_t now = time(NULL);
434 if (invtimeout != 0 && now > invtimeout) return; /* Don't add invites that are expired from the get-go. */
435 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
437 if (channel == i->first)
439 if (i->second != 0 && invtimeout > i->second)
441 i->second = invtimeout;
445 invites.push_back(std::make_pair(channel, invtimeout));
448 void User::RemoveInvite(const irc::string &channel)
450 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
452 if (channel == i->first)
460 bool User::HasModePermission(unsigned char mode, ModeType type)
468 if (!AllowedUserModes || !AllowedChanModes)
471 return ((type == MODETYPE_USER ? AllowedUserModes : AllowedChanModes))[(mode - 'A')];
475 bool User::HasPermission(const std::string &command)
478 * users on remote servers can completely bypass all permissions based checks.
479 * This prevents desyncs when one server has different type/class tags to another.
480 * That having been said, this does open things up to the possibility of source changes
481 * allowing remote kills, etc - but if they have access to the src, they most likely have
482 * access to the conf - so it's an end to a means either way.
487 // are they even an oper at all?
493 if (!AllowedOperCommands)
496 if (AllowedOperCommands->find(command) != AllowedOperCommands->end())
498 else if (AllowedOperCommands->find("*") != AllowedOperCommands->end())
504 bool User::AddBuffer(const std::string &a)
506 std::string::size_type start = 0;
507 std::string::size_type i = a.find('\r');
510 * The old implementation here took a copy, and rfind() on \r, removing as it found them, before
511 * copying a second time onto the recvq. That's ok, but involves three copies minimum (recv() to buffer,
512 * buffer to here, here to recvq) - The new method now copies twice (recv() to buffer, buffer to recvq).
514 * We use find() instead of rfind() for clarity, however unlike the old code, our scanning of the string is
515 * contiguous: as we specify a startpoint, we never see characters we have scanned previously, making this
516 * marginally faster in cases with a number of \r hidden early on in the buffer.
519 * Start at first pos of string, find first \r, append everything in the chunk (excluding \r) to recvq. Set
520 * i ahead of the \r, search for next \r, add next chunk to buffer... repeat.
521 * -- w00t (7 may, 2008)
523 if (i == std::string::npos)
525 // no \r that we need to dance around, just add to buffer
530 // While we can find the end of a chunk to add
531 while (i != std::string::npos)
533 // Append the chunk that we have
534 recvq.append(a, start, (i - start));
536 // Start looking for the next one
538 i = a.find('\r', start);
541 if (start != a.length())
544 * This is here to catch a corner case when we get something like:
548 * in successive calls to us.
550 * Without this conditional, the 'U' on the second case will be dropped,
551 * which is most *certainly* not the behaviour we want!
554 recvq.append(a, start, (a.length() - start));
558 if (this->MyClass && (recvq.length() > this->MyClass->GetRecvqMax()))
560 ServerInstance->Users->QuitUser(this, "RecvQ exceeded");
561 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());
568 bool User::BufferIsReady()
570 return (recvq.find('\n') != std::string::npos);
573 void User::ClearBuffer()
578 std::string User::GetBuffer()
585 /* Strip any leading \r or \n off the string.
586 * Usually there are only one or two of these,
587 * so its is computationally cheap to do.
589 std::string::iterator t = recvq.begin();
590 while (t != recvq.end() && (*t == '\r' || *t == '\n'))
596 for (std::string::iterator x = recvq.begin(); x != recvq.end(); x++)
598 /* Find the first complete line, return it as the
599 * result, and leave the recvq as whats left
603 std::string ret = std::string(recvq.begin(), x);
604 recvq.erase(recvq.begin(), x + 1);
613 ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::GetBuffer()");
618 void User::AddWriteBuf(const std::string &data)
623 if (this->MyClass && (sendq.length() + data.length() > this->MyClass->GetSendqMax()))
626 * Fix by brain - Set the error text BEFORE calling, because
627 * if we dont it'll recursively call here over and over again trying
628 * to repeatedly add the text to the sendq!
630 ServerInstance->Users->QuitUser(this, "SendQ exceeded");
631 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());
635 if (data.length() > MAXBUF - 2) /* MAXBUF has a value of 514, to account for line terminators */
636 sendq.append(data.substr(0,MAXBUF - 4)).append("\r\n"); /* MAXBUF-4 = 510 */
641 // send AS MUCH OF THE USERS SENDQ as we are able to (might not be all of it)
642 void User::FlushWriteBuf()
644 if (this->fd == FD_MAGIC_NUMBER)
650 if ((sendq.length()) && (this->fd != FD_MAGIC_NUMBER))
652 int old_sendq_length = sendq.length();
653 int n_sent = ServerInstance->SE->Send(this, this->sendq.data(), this->sendq.length(), 0);
659 /* The socket buffer is full. This isnt fatal,
662 ServerInstance->SE->WantWrite(this);
666 /* Fatal error, set write error and bail */
667 ServerInstance->Users->QuitUser(this, errno ? strerror(errno) : "Write error");
673 /* advance the queue */
675 this->sendq = this->sendq.substr(n_sent);
676 /* update the user's stats counters */
677 this->bytes_out += n_sent;
679 if (n_sent != old_sendq_length)
680 this->ServerInstance->SE->WantWrite(this);
684 /* note: NOT else if! */
685 if (this->sendq.empty())
687 FOREACH_MOD(I_OnBufferFlushed,OnBufferFlushed(this));
691 void User::Oper(const std::string &opertype, const std::string &opername)
699 this->modes[UM_OPERATOR] = 1;
700 this->WriteServ("MODE %s :+o", this->nick.c_str());
701 FOREACH_MOD(I_OnOper, OnOper(this, opertype));
702 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());
703 this->oper.assign(opertype, 0, 512);
704 ServerInstance->Users->all_opers.push_back(this);
706 opertype_t::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper.c_str());
707 if (iter_opertype != ServerInstance->Config->opertypes.end())
710 if (AllowedOperCommands)
711 AllowedOperCommands->clear();
713 AllowedOperCommands = new std::map<std::string, bool>;
715 if (!AllowedChanModes)
716 AllowedChanModes = new bool[64];
718 if (!AllowedUserModes)
719 AllowedUserModes = new bool[64];
721 memset(AllowedUserModes, 0, 64);
722 memset(AllowedChanModes, 0, 64);
724 char* Classes = strdup(iter_opertype->second);
725 char* myclass = strtok_r(Classes," ",&savept);
728 operclass_t::iterator iter_operclass = ServerInstance->Config->operclass.find(myclass);
729 if (iter_operclass != ServerInstance->Config->operclass.end())
731 char* CommandList = strdup(iter_operclass->second.commandlist);
732 mycmd = strtok_r(CommandList," ",&savept2);
735 this->AllowedOperCommands->insert(std::make_pair(mycmd, true));
736 mycmd = strtok_r(NULL," ",&savept2);
739 this->AllowedUserModes['o' - 'A'] = true; // Call me paranoid if you want.
740 for (unsigned char* c = (unsigned char*)iter_operclass->second.umodelist; *c; ++c)
744 memset(this->AllowedUserModes, (int)(true), 64);
748 this->AllowedUserModes[*c - 'A'] = true;
751 for (unsigned char* c = (unsigned char*)iter_operclass->second.cmodelist; *c; ++c)
755 memset(this->AllowedChanModes, (int)(true), 64);
759 this->AllowedChanModes[*c - 'A'] = true;
763 myclass = strtok_r(NULL," ",&savept);
768 FOREACH_MOD(I_OnPostOper,OnPostOper(this, opertype, opername));
773 ServerInstance->Logs->Log("OPER", DEBUG,"Exception in User::Oper()");
781 /* Remove all oper only modes from the user when the deoper - Bug #466*/
782 std::string moderemove("-");
784 for (unsigned char letter = 'A'; letter <= 'z'; letter++)
788 ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_USER);
789 if (mh && mh->NeedsOper())
790 moderemove += letter;
794 std::vector<std::string> parameters;
795 parameters.push_back(this->nick);
796 parameters.push_back(moderemove);
798 ServerInstance->Parser->CallHandler("MODE", parameters, this);
800 /* unset their oper type (what IS_OPER checks), and remove +o */
802 this->modes[UM_OPERATOR] = 0;
804 /* remove the user from the oper list. Will remove multiple entries as a safeguard against bug #404 */
805 ServerInstance->Users->all_opers.remove(this);
807 if (AllowedOperCommands)
809 delete AllowedOperCommands;
810 AllowedOperCommands = NULL;
812 if (AllowedUserModes)
814 delete[] AllowedUserModes;
815 AllowedUserModes = NULL;
817 if (AllowedChanModes)
819 delete[] AllowedChanModes;
820 AllowedChanModes = NULL;
826 /* adds or updates an entry in the whowas list */
827 void User::AddToWhoWas()
829 Command* whowas_command = ServerInstance->Parser->GetHandler("WHOWAS");
832 std::deque<classbase*> params;
833 params.push_back(this);
834 whowas_command->HandleInternal(WHOWAS_ADD, params);
839 * Check class restrictions
841 void User::CheckClass()
843 ConnectClass* a = this->MyClass;
845 if ((!a) || (a->GetType() == CC_DENY))
847 ServerInstance->Users->QuitUser(this, "Unauthorised connection");
850 else if ((a->GetMaxLocal()) && (ServerInstance->Users->LocalCloneCount(this) > a->GetMaxLocal()))
852 ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (local)");
853 ServerInstance->SNO->WriteToSnoMask('A', "WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString());
856 else if ((a->GetMaxGlobal()) && (ServerInstance->Users->GlobalCloneCount(this) > a->GetMaxGlobal()))
858 ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (global)");
859 ServerInstance->SNO->WriteToSnoMask('A', "WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString());
863 this->nping = ServerInstance->Time() + a->GetPingTime() + ServerInstance->Config->dns_timeout;
866 bool User::CheckLines()
868 const char* check[] = { "G" , "K", NULL };
872 for (int n = 0; check[n]; ++n)
874 XLine *r = ServerInstance->XLines->MatchesLine(check[n], this);
887 void User::FullConnect()
889 ServerInstance->stats->statsConnects++;
890 this->idle_lastmsg = ServerInstance->Time();
893 * You may be thinking "wtf, we checked this in User::AddClient!" - and yes, we did, BUT.
894 * At the time AddClient is called, we don't have a resolved host, by here we probably do - which
895 * may put the user into a totally seperate class with different restrictions! so we *must* check again.
896 * Don't remove this! -- w00t
900 /* Check the password, if one is required by the user's connect class.
901 * This CANNOT be in CheckClass(), because that is called prior to PASS as well!
903 if (this->MyClass && !this->MyClass->GetPass().empty() && !this->haspassed)
905 ServerInstance->Users->QuitUser(this, "Invalid password");
909 if (this->CheckLines())
912 this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network);
913 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());
914 this->WriteNumeric(RPL_YOURHOSTIS, "%s :Your host is %s, running version InspIRCd-1.2",this->nick.c_str(),ServerInstance->Config->ServerName);
915 this->WriteNumeric(RPL_SERVERCREATED, "%s :This server was created %s %s", this->nick.c_str(), __TIME__, __DATE__);
916 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());
918 ServerInstance->Config->Send005(this);
919 this->WriteNumeric(RPL_YOURUUID, "%s %s :your unique ID", this->nick.c_str(), this->uuid.c_str());
925 if (ServerInstance->Users->unregistered_count)
926 ServerInstance->Users->unregistered_count--;
928 /* Trigger LUSERS output, give modules a chance too */
930 std::string command("LUSERS");
931 std::vector<std::string> parameters;
932 FOREACH_RESULT(I_OnPreCommand, OnPreCommand(command, parameters, this, true, "LUSERS"));
934 ServerInstance->CallCommandHandler(command, parameters, this);
937 * We don't set REG_ALL until triggering OnUserConnect, so some module events don't spew out stuff
938 * for a user that doesn't exist yet.
940 FOREACH_MOD(I_OnUserConnect,OnUserConnect(this));
942 this->registered = REG_ALL;
944 ServerInstance->PI->Introduce(this);
946 FOREACH_MOD(I_OnPostConnect,OnPostConnect(this));
948 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());
949 ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCache: Adding NEGATIVE hit for %s", this->GetIPString());
950 ServerInstance->BanCache->AddHit(this->GetIPString(), "", "");
953 /** User::UpdateNick()
954 * re-allocates a nick in the user_hash after they change nicknames,
955 * returns a pointer to the new user as it may have moved
957 User* User::UpdateNickHash(const char* New)
959 //user_hash::iterator newnick;
960 user_hash::iterator oldnick = ServerInstance->Users->clientlist->find(this->nick);
962 if (!irc::string(this->nick.c_str()).compare(New))
963 return oldnick->second;
965 if (oldnick == ServerInstance->Users->clientlist->end())
966 return NULL; /* doesnt exist */
968 User* olduser = oldnick->second;
969 (*(ServerInstance->Users->clientlist))[New] = olduser;
970 ServerInstance->Users->clientlist->erase(oldnick);
974 void User::InvalidateCache()
976 /* Invalidate cache */
977 cached_fullhost.clear();
978 cached_hostip.clear();
979 cached_makehost.clear();
980 cached_fullrealhost.clear();
983 bool User::ForceNickChange(const char* newnick)
987 this->InvalidateCache();
989 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(this, newnick));
993 ServerInstance->stats->statsCollisions++;
997 std::deque<classbase*> dummy;
998 Command* nickhandler = ServerInstance->Parser->GetHandler("NICK");
999 if (nickhandler) // wtfbbq, when would this not be here
1001 std::vector<std::string> parameters;
1002 nickhandler->HandleInternal(1, dummy);
1003 parameters.push_back(newnick);
1004 bool result = (ServerInstance->Parser->CallHandler("NICK", parameters, this) == CMD_SUCCESS);
1005 nickhandler->HandleInternal(0, dummy);
1009 // Unreachable, we hope
1013 void User::SetSockAddr(int protocol_family, const char* sip, int port)
1015 this->cachedip = "";
1017 switch (protocol_family)
1019 #ifdef SUPPORT_IP6LINKS
1022 sockaddr_in6* sin = new sockaddr_in6;
1023 sin->sin6_family = AF_INET6;
1024 sin->sin6_port = port;
1025 inet_pton(AF_INET6, sip, &sin->sin6_addr);
1026 this->ip = (sockaddr*)sin;
1032 sockaddr_in* sin = new sockaddr_in;
1033 sin->sin_family = AF_INET;
1034 sin->sin_port = port;
1035 inet_pton(AF_INET, sip, &sin->sin_addr);
1036 this->ip = (sockaddr*)sin;
1040 ServerInstance->Logs->Log("USERS",DEBUG,"Uh oh, I dont know protocol %d to be set on '%s'!", protocol_family, this->nick.c_str());
1047 if (this->ip == NULL)
1050 switch (this->GetProtocolFamily())
1052 #ifdef SUPPORT_IP6LINKS
1055 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1056 return sin->sin6_port;
1062 sockaddr_in* sin = (sockaddr_in*)this->ip;
1063 return sin->sin_port;
1072 int User::GetProtocolFamily()
1074 if (this->ip == NULL)
1077 sockaddr_in* sin = (sockaddr_in*)this->ip;
1078 return sin->sin_family;
1081 const char* User::GetCIDRMask(int range)
1083 static char buf[44];
1085 if (this->ip == NULL)
1089 throw "Negative range, sorry, no.";
1092 * Original code written by Oliver Lupton (Om).
1093 * Integrated by me. Thanks. :) -- w00t
1095 switch (this->GetProtocolFamily())
1097 #ifdef SUPPORT_IP6LINKS
1100 /* unsigned char s6_addr[16]; */
1103 int i, bytestozero, extrabits;
1107 throw "CIDR mask width greater than address width (IPv6, 128 bit)";
1109 /* Access the user's IP structure directly */
1110 sin = (sockaddr_in6*)this->ip;
1112 /* To create the CIDR mask we want to set all the bits after 'range' bits of the address
1113 * to zero. This means the last (128 - range) bits of the address must be set to zero.
1114 * Hence this number divided by 8 is the number of whole bytes from the end of the address
1115 * which must be set to zero.
1117 bytestozero = (128 - range) / 8;
1119 /* Some of the least significant bits of the next most significant byte may also have to
1120 * be zeroed. The number of bits is the remainder of the above division.
1122 extrabits = (128 - range) % 8;
1124 /* Populate our working struct with the parts of the user's IP which are required in the
1125 * final CIDR mask. Set all the subsequent bytes to zero.
1126 * (16 - bytestozero) is the number of bytes which must be populated with actual IP data.
1128 for(i = 0; i < (16 - bytestozero); i++)
1130 v6.s6_addr[i] = sin->sin6_addr.s6_addr[i];
1133 /* And zero all the remaining bytes in the IP. */
1139 /* And finally, zero the extra bits required. */
1140 v6.s6_addr[15 - bytestozero] = (v6.s6_addr[15 - bytestozero] >> extrabits) << extrabits;
1142 snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET6, &v6, buffer, 40), range);
1154 throw "CIDR mask width greater than address width (IPv4, 32 bit)";
1156 /* Users already have a sockaddr* pointer (User::ip) which contains either a v4 or v6 structure */
1157 sin = (sockaddr_in*)this->ip;
1158 v4.s_addr = sin->sin_addr.s_addr;
1160 /* To create the CIDR mask we want to set all the bits after 'range' bits of the address
1161 * to zero. This means the last (32 - range) bits of the address must be set to zero.
1162 * This is done by shifting the value right and then back left by (32 - range) bits.
1166 v4.s_addr = ntohl(v4.s_addr);
1167 v4.s_addr = (v4.s_addr >> (32 - range)) << (32 - range);
1168 v4.s_addr = htonl(v4.s_addr);
1172 /* a range of zero would cause a 32 bit value to be shifted by 32 bits.
1173 * this has undefined behaviour, but for CIDR purposes the resulting mask
1174 * from a.b.c.d/0 is 0.0.0.0/0
1179 snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET, &v4, buffer, 16), range);
1185 return ""; // unused, but oh well
1188 const char* User::GetIPString(bool translate4in6)
1190 static char buf[40];
1192 if (this->ip == NULL)
1195 if (!this->cachedip.empty())
1196 return this->cachedip.c_str();
1198 switch (this->GetProtocolFamily())
1200 #ifdef SUPPORT_IP6LINKS
1203 static char temp[1024];
1205 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1206 inet_ntop(sin->sin6_family, &sin->sin6_addr, buf, sizeof(buf));
1207 /* IP addresses starting with a : on irc are a Bad Thing (tm) */
1210 strlcpy(&temp[1], buf, sizeof(temp) - 1);
1212 if (translate4in6 && !strncmp(temp, "0::ffff:", 8))
1214 this->cachedip = temp + 8;
1218 this->cachedip = temp;
1222 this->cachedip = buf;
1229 sockaddr_in* sin = (sockaddr_in*)this->ip;
1230 inet_ntop(sin->sin_family, &sin->sin_addr, buf, sizeof(buf));
1231 this->cachedip = buf;
1239 // Unreachable, probably
1243 /** NOTE: We cannot pass a const reference to this method.
1244 * The string is changed by the workings of the method,
1245 * so that if we pass const ref, we end up copying it to
1246 * something we can change anyway. Makes sense to just let
1247 * the compiler do that copy for us.
1249 void User::Write(std::string text)
1251 if (!ServerInstance->SE->BoundsCheckFd(this))
1256 ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"C[%d] O %s", this->GetFd(), text.c_str());
1257 text.append("\r\n");
1261 ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"Exception in User::Write() std::string::append");
1267 /* XXX: The lack of buffering here is NOT a bug, modules implementing this interface have to
1268 * implement their own buffering mechanisms
1272 this->io->OnRawSocketWrite(this->fd, text.data(), text.length());
1274 catch (CoreException& modexcept)
1276 ServerInstance->Logs->Log("USEROUTPUT", DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
1281 this->AddWriteBuf(text);
1283 ServerInstance->stats->statsSent += text.length();
1284 this->ServerInstance->SE->WantWrite(this);
1289 void User::Write(const char *text, ...)
1292 char textbuffer[MAXBUF];
1294 va_start(argsPtr, text);
1295 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1298 this->Write(std::string(textbuffer));
1301 void User::WriteServ(const std::string& text)
1303 char textbuffer[MAXBUF];
1305 snprintf(textbuffer,MAXBUF,":%s %s",ServerInstance->Config->ServerName,text.c_str());
1306 this->Write(std::string(textbuffer));
1310 * Same as Write(), except `text' is prefixed with `:server.name '.
1312 void User::WriteServ(const char* text, ...)
1315 char textbuffer[MAXBUF];
1317 va_start(argsPtr, text);
1318 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1321 this->WriteServ(std::string(textbuffer));
1325 void User::WriteNumeric(unsigned int numeric, const char* text, ...)
1328 char textbuffer[MAXBUF];
1330 va_start(argsPtr, text);
1331 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1334 this->WriteNumeric(numeric, std::string(textbuffer));
1337 void User::WriteNumeric(unsigned int numeric, const std::string &text)
1339 char textbuffer[MAXBUF];
1342 FOREACH_RESULT(I_OnNumeric, OnNumeric(this, numeric, text));
1347 snprintf(textbuffer,MAXBUF,":%s %03u %s",ServerInstance->Config->ServerName, numeric, text.c_str());
1348 this->Write(std::string(textbuffer));
1351 void User::WriteFrom(User *user, const std::string &text)
1355 snprintf(tb,MAXBUF,":%s %s",user->GetFullHost().c_str(),text.c_str());
1357 this->Write(std::string(tb));
1361 /* write text from an originating user to originating user */
1363 void User::WriteFrom(User *user, const char* text, ...)
1366 char textbuffer[MAXBUF];
1368 va_start(argsPtr, text);
1369 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1372 this->WriteFrom(user, std::string(textbuffer));
1376 /* write text to an destination user from a source user (e.g. user privmsg) */
1378 void User::WriteTo(User *dest, const char *data, ...)
1380 char textbuffer[MAXBUF];
1383 va_start(argsPtr, data);
1384 vsnprintf(textbuffer, MAXBUF, data, argsPtr);
1387 this->WriteTo(dest, std::string(textbuffer));
1390 void User::WriteTo(User *dest, const std::string &data)
1392 dest->WriteFrom(this, data);
1396 void User::WriteCommon(const char* text, ...)
1398 char textbuffer[MAXBUF];
1401 if (this->registered != REG_ALL)
1404 va_start(argsPtr, text);
1405 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1408 this->WriteCommon(std::string(textbuffer));
1411 void User::WriteCommon(const std::string &text)
1413 bool sent_to_at_least_one = false;
1416 if (this->registered != REG_ALL)
1422 InitializeAlreadySent(ServerInstance->SE);
1424 /* We dont want to be doing this n times, just once */
1425 snprintf(tb,MAXBUF,":%s %s",this->GetFullHost().c_str(),text.c_str());
1426 std::string out = tb;
1428 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1430 CUList* ulist = v->first->GetUsers();
1431 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1433 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1435 already_sent[i->first->fd] = uniq_id;
1436 i->first->Write(out);
1437 sent_to_at_least_one = true;
1443 * if the user was not in any channels, no users will receive the text. Make sure the user
1444 * receives their OWN message for WriteCommon
1446 if (!sent_to_at_least_one)
1448 this->Write(std::string(tb));
1453 /* write a formatted string to all users who share at least one common
1454 * channel, NOT including the source user e.g. for use in QUIT
1457 void User::WriteCommonExcept(const char* text, ...)
1459 char textbuffer[MAXBUF];
1462 va_start(argsPtr, text);
1463 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1466 this->WriteCommonExcept(std::string(textbuffer));
1469 void User::WriteCommonQuit(const std::string &normal_text, const std::string &oper_text)
1474 if (this->registered != REG_ALL)
1480 InitializeAlreadySent(ServerInstance->SE);
1482 snprintf(tb1,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),normal_text.c_str());
1483 snprintf(tb2,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),oper_text.c_str());
1484 std::string out1 = tb1;
1485 std::string out2 = tb2;
1487 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1489 CUList *ulist = v->first->GetUsers();
1490 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1492 if (this != i->first)
1494 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1496 already_sent[i->first->fd] = uniq_id;
1497 i->first->Write(IS_OPER(i->first) ? out2 : out1);
1504 void User::WriteCommonExcept(const std::string &text)
1509 if (this->registered != REG_ALL)
1515 InitializeAlreadySent(ServerInstance->SE);
1517 snprintf(tb1,MAXBUF,":%s %s",this->GetFullHost().c_str(),text.c_str());
1520 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1522 CUList *ulist = v->first->GetUsers();
1523 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1525 if (this != i->first)
1527 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1529 already_sent[i->first->fd] = uniq_id;
1530 i->first->Write(out1);
1538 void User::WriteWallOps(const std::string &text)
1540 if (!IS_LOCAL(this))
1543 std::string wallop("WALLOPS :");
1544 wallop.append(text);
1546 for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
1549 if (t->IsModeSet('w'))
1550 this->WriteTo(t,wallop);
1554 void User::WriteWallOps(const char* text, ...)
1556 if (!IS_LOCAL(this))
1559 char textbuffer[MAXBUF];
1562 va_start(argsPtr, text);
1563 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1566 this->WriteWallOps(std::string(textbuffer));
1569 /* return 0 or 1 depending if users u and u2 share one or more common channels
1570 * (used by QUIT, NICK etc which arent channel specific notices)
1572 * The old algorithm in 1.0 for this was relatively inefficient, iterating over
1573 * the first users channels then the second users channels within the outer loop,
1574 * therefore it was a maximum of x*y iterations (upon returning 0 and checking
1575 * all possible iterations). However this new function instead checks against the
1576 * channel's userlist in the inner loop which is a std::map<User*,User*>
1577 * and saves us time as we already know what pointer value we are after.
1578 * Don't quote me on the maths as i am not a mathematician or computer scientist,
1579 * but i believe this algorithm is now x+(log y) maximum iterations instead.
1581 bool User::SharesChannelWith(User *other)
1583 if ((!other) || (this->registered != REG_ALL) || (other->registered != REG_ALL))
1587 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1589 /* Eliminate the inner loop (which used to be ~equal in size to the outer loop)
1590 * by replacing it with a map::find which *should* be more efficient
1592 if (i->first->HasUser(other))
1598 bool User::ChangeName(const char* gecos)
1600 if (!this->fullname.compare(gecos))
1606 FOREACH_RESULT(I_OnChangeLocalUserGECOS,OnChangeLocalUserGECOS(this,gecos));
1609 FOREACH_MOD(I_OnChangeName,OnChangeName(this,gecos));
1611 this->fullname.assign(gecos, 0, ServerInstance->Config->Limits.MaxGecos);
1616 bool User::ChangeDisplayedHost(const char* shost)
1624 FOREACH_RESULT(I_OnChangeLocalUserHost,OnChangeLocalUserHost(this,shost));
1627 FOREACH_MOD(I_OnChangeHost,OnChangeHost(this,shost));
1630 if (this->ServerInstance->Config->CycleHosts)
1631 this->WriteCommonExcept("QUIT :Changing hosts");
1633 /* Fix by Om: User::dhost is 65 long, this was truncating some long hosts */
1634 this->dhost.assign(shost, 0, 64);
1636 this->InvalidateCache();
1638 if (this->ServerInstance->Config->CycleHosts)
1640 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1642 i->first->WriteAllExceptSender(this, false, 0, "JOIN %s", i->first->name.c_str());
1643 std::string n = this->ServerInstance->Modes->ModeString(this, i->first);
1645 i->first->WriteAllExceptSender(this, true, 0, "MODE %s +%s", i->first->name.c_str(), n.c_str());
1650 this->WriteNumeric(RPL_YOURDISPLAYEDHOST, "%s %s :is now your displayed host",this->nick.c_str(),this->dhost.c_str());
1655 bool User::ChangeIdent(const char* newident)
1657 if (!this->ident.compare(newident))
1660 if (this->ServerInstance->Config->CycleHosts)
1661 this->WriteCommonExcept("%s","QUIT :Changing ident");
1663 this->ident.assign(newident, 0, ServerInstance->Config->Limits.IdentMax + 1);
1665 this->InvalidateCache();
1667 if (this->ServerInstance->Config->CycleHosts)
1669 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1671 i->first->WriteAllExceptSender(this, false, 0, "JOIN %s", i->first->name.c_str());
1672 std::string n = this->ServerInstance->Modes->ModeString(this, i->first);
1674 i->first->WriteAllExceptSender(this, true, 0, "MODE %s +%s", i->first->name.c_str(), n.c_str());
1681 void User::SendAll(const char* command, const char* text, ...)
1683 char textbuffer[MAXBUF];
1684 char formatbuffer[MAXBUF];
1687 va_start(argsPtr, text);
1688 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1691 snprintf(formatbuffer,MAXBUF,":%s %s $* :%s", this->GetFullHost().c_str(), command, textbuffer);
1692 std::string fmt = formatbuffer;
1694 for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
1701 std::string User::ChannelList(User* source)
1705 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1707 /* If the target is the same as the sender, let them see all their channels.
1708 * If the channel is NOT private/secret OR the user shares a common channel
1709 * If the user is an oper, and the <options:operspywhois> option is set.
1711 if ((source == this) || (IS_OPER(source) && ServerInstance->Config->OperSpyWhois) || (((!i->first->IsModeSet('p')) && (!i->first->IsModeSet('s'))) || (i->first->HasUser(source))))
1713 list.append(i->first->GetPrefixChar(this)).append(i->first->name).append(" ");
1720 void User::SplitChanList(User* dest, const std::string &cl)
1723 std::ostringstream prefix;
1724 std::string::size_type start, pos, length;
1726 prefix << this->nick << " " << dest->nick << " :";
1727 line = prefix.str();
1728 int namelen = strlen(ServerInstance->Config->ServerName) + 6;
1730 for (start = 0; (pos = cl.find(' ', start)) != std::string::npos; start = pos+1)
1732 length = (pos == std::string::npos) ? cl.length() : pos;
1734 if (line.length() + namelen + length - start > 510)
1736 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1737 line = prefix.str();
1740 if(pos == std::string::npos)
1742 line.append(cl.substr(start, length - start));
1747 line.append(cl.substr(start, length - start + 1));
1753 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1758 * Sets a user's connection class.
1759 * If the class name is provided, it will be used. Otherwise, the class will be guessed using host/ip/ident/etc.
1760 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1761 * then their ip will be taken as 'priority' anyway, so for example,
1762 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1764 ConnectClass* User::SetClass(const std::string &explicit_name)
1766 ConnectClass *found = NULL;
1768 if (!IS_LOCAL(this))
1771 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Setting connect class for UID %s", this->uuid.c_str());
1773 if (!explicit_name.empty())
1775 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1777 ConnectClass* c = *i;
1779 if (c->GetDisabled())
1780 continue; // can't possibly match, removed from conf
1782 if (explicit_name == c->GetName())
1784 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Explicitly set to %s", explicit_name.c_str());
1791 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1793 ConnectClass* c = *i;
1795 if (c->GetType() == CC_ALLOW)
1797 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "ALLOW %s %d %s", c->GetHost().c_str(), c->GetPort(), c->GetName().c_str());
1801 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "DENY %s %d %s", c->GetHost().c_str(), c->GetPort(), c->GetName().c_str());
1804 /* if it's disabled, we can't match this one. */
1805 if (c->GetDisabled())
1807 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Class disabled");
1811 /* check if host matches.. */
1812 if (((!match(this->GetIPString(),c->GetHost(),true)) && (!match(this->host,c->GetHost()))))
1814 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "No host match (for %s)", c->GetHost().c_str());
1819 * deny change if change will take class over the limit check it HERE, not after we found a matching class,
1820 * because we should attempt to find another class if this one doesn't match us. -- w00t
1822 if (c->limit && (c->RefCount + 1 >= c->limit))
1824 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "OOPS: Connect class limit (%lu) hit, denying", c->limit);
1828 /* if it requires a port ... */
1831 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Requires port (%d)", c->GetPort());
1833 /* and our port doesn't match, fail. */
1834 if (this->GetPort() != c->GetPort())
1836 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Port match failed (%d)", this->GetPort());
1841 /* we stop at the first class that meets ALL critera. */
1848 * Okay, assuming we found a class that matches.. switch us into that class, keeping refcounts up to date.
1852 /* only fiddle with refcounts if they are already in a class .. */
1855 if (found == this->MyClass) // no point changing this shit :P
1856 return this->MyClass;
1857 this->MyClass->RefCount--;
1858 ServerInstance->Logs->Log("USERS", DEBUG, "Untying user from connect class -- refcount: %lu", this->MyClass->RefCount);
1861 this->MyClass = found;
1862 this->MyClass->RefCount++;
1863 ServerInstance->Logs->Log("USERS", DEBUG, "User tied to new class -- connect refcount now: %lu", this->MyClass->RefCount);
1866 return this->MyClass;
1869 /* looks up a users password for their connection class (<ALLOW>/<DENY> tags)
1870 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1871 * then their ip will be taken as 'priority' anyway, so for example,
1872 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1874 ConnectClass* User::GetClass()
1876 return this->MyClass;
1879 void User::PurgeEmptyChannels()
1881 std::vector<Channel*> to_delete;
1883 // firstly decrement the count on each channel
1884 for (UCListIter f = this->chans.begin(); f != this->chans.end(); f++)
1886 f->first->RemoveAllPrefixes(this);
1887 if (f->first->DelUser(this) == 0)
1889 /* No users left in here, mark it for deletion */
1892 to_delete.push_back(f->first);
1896 ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::PurgeEmptyChannels to_delete.push_back()");
1901 for (std::vector<Channel*>::iterator n = to_delete.begin(); n != to_delete.end(); n++)
1903 Channel* thischan = *n;
1904 chan_hash::iterator i2 = ServerInstance->chanlist->find(thischan->name);
1905 if (i2 != ServerInstance->chanlist->end())
1907 FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(i2->second));
1909 ServerInstance->chanlist->erase(i2);
1910 this->chans.erase(*n);
1917 void User::ShowMOTD()
1919 if (!ServerInstance->Config->MOTD.size())
1921 this->WriteNumeric(ERR_NOMOTD, "%s :Message of the day file is missing.",this->nick.c_str());
1924 this->WriteNumeric(RPL_MOTDSTART, "%s :%s message of the day", this->nick.c_str(), ServerInstance->Config->ServerName);
1926 for (file_cache::iterator i = ServerInstance->Config->MOTD.begin(); i != ServerInstance->Config->MOTD.end(); i++)
1927 this->WriteNumeric(RPL_MOTD, "%s :- %s",this->nick.c_str(),i->c_str());
1929 this->WriteNumeric(RPL_ENDOFMOTD, "%s :End of message of the day.", this->nick.c_str());
1932 void User::ShowRULES()
1934 if (!ServerInstance->Config->RULES.size())
1936 this->WriteNumeric(ERR_NORULES, "%s :RULES File is missing",this->nick.c_str());
1940 this->WriteNumeric(RPL_RULESTART, "%s :- %s Server Rules -",this->nick.c_str(),ServerInstance->Config->ServerName);
1942 for (file_cache::iterator i = ServerInstance->Config->RULES.begin(); i != ServerInstance->Config->RULES.end(); i++)
1943 this->WriteNumeric(RPL_RULES, "%s :- %s",this->nick.c_str(),i->c_str());
1945 this->WriteNumeric(RPL_RULESEND, "%s :End of RULES command.",this->nick.c_str());
1948 void User::HandleEvent(EventType et, int errornum)
1950 if (this->quitting) // drop everything, user is due to be quit
1956 ServerInstance->ProcessUser(this);
1959 this->FlushWriteBuf();
1962 ServerInstance->Users->QuitUser(this, errornum ? strerror(errornum) : "Client closed the connection");
1967 void User::SetOperQuit(const std::string &oquit)
1969 operquitmsg = oquit;
1972 const std::string& User::GetOperQuit()
1977 void User::IncreasePenalty(int increase)
1979 this->Penalty += increase;
1982 void User::DecreasePenalty(int decrease)
1984 this->Penalty -= decrease;
1995 bool VisData::VisibleTo(User* user)