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);
103 /* Special case for 4in6 (Have i mentioned i HATE 4in6?) */
104 if (!strncmp(sip, "0::ffff:", 8))
105 res_reverse = new UserResolver(this->ServerInstance, this, sip + 8, DNS_QUERY_PTR4, cached);
107 res_reverse = new UserResolver(this->ServerInstance, this, sip, this->GetProtocolFamily() == AF_INET ? DNS_QUERY_PTR4 : DNS_QUERY_PTR6, cached);
109 this->ServerInstance->AddResolver(res_reverse, cached);
111 catch (CoreException& e)
113 ServerInstance->Logs->Log("USERS", DEBUG,"Error in resolver: %s",e.GetReason());
117 bool User::IsNoticeMaskSet(unsigned char sm)
121 return (snomasks[sm-65]);
124 void User::SetNoticeMask(unsigned char sm, bool value)
128 snomasks[sm-65] = value;
131 const char* User::FormatNoticeMasks()
133 static char data[MAXBUF];
136 for (int n = 0; n < 64; n++)
139 data[offset++] = n+65;
146 bool User::IsModeSet(unsigned char m)
150 return (modes[m-65]);
153 void User::SetMode(unsigned char m, bool value)
160 const char* User::FormatModes()
162 static char data[MAXBUF];
164 for (int n = 0; n < 64; n++)
167 data[offset++] = n+65;
173 void User::DecrementModes()
175 ServerInstance->Logs->Log("USERS", DEBUG, "DecrementModes()");
176 for (unsigned char n = 'A'; n <= 'z'; n++)
180 ServerInstance->Logs->Log("USERS", DEBUG,"DecrementModes() found mode %c", n);
181 ModeHandler* mh = ServerInstance->Modes->FindMode(n, MODETYPE_USER);
184 ServerInstance->Logs->Log("USERS", DEBUG,"Found handler %c and call ChangeCount", n);
191 User::User(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance)
193 server = (char*)Instance->FindServerNamePtr(Instance->Config->ServerName);
194 reset_due = ServerInstance->Time();
195 age = ServerInstance->Time();
197 lines_in = lastping = signon = idle_lastmsg = nping = registered = 0;
198 bytes_in = bytes_out = cmds_in = cmds_out = 0;
199 quietquit = OverPenalty = ExemptFromPenalty = quitting = exempt = haspassed = dns_done = false;
203 res_forward = res_reverse = NULL;
208 AllowedUserModes = NULL;
209 AllowedChanModes = NULL;
210 AllowedOperCommands = NULL;
215 uuid.assign(Instance->GetUID(), 0, UUID_LENGTH - 1);
217 uuid.assign(uid, 0, UUID_LENGTH - 1);
219 ServerInstance->Logs->Log("USERS", DEBUG,"New UUID for user: %s (%s)", uuid.c_str(), uid.empty() ? "allocated new" : "used remote");
221 user_hash::iterator finduuid = Instance->Users->uuidlist->find(uuid);
222 if (finduuid == Instance->Users->uuidlist->end())
223 (*Instance->Users->uuidlist)[uuid] = this;
225 throw CoreException("Duplicate UUID "+std::string(uuid)+" in User constructor");
230 /* NULL for remote users :) */
233 this->MyClass->RefCount--;
234 ServerInstance->Logs->Log("USERS", DEBUG, "User destructor -- connect refcount now: %lu", this->MyClass->RefCount);
236 if (this->AllowedOperCommands)
238 delete AllowedOperCommands;
239 AllowedOperCommands = NULL;
242 if (this->AllowedUserModes)
244 delete[] AllowedUserModes;
245 AllowedUserModes = NULL;
248 if (this->AllowedChanModes)
250 delete[] AllowedChanModes;
251 AllowedChanModes = NULL;
254 this->InvalidateCache();
255 this->DecrementModes();
259 ServerInstance->Users->RemoveCloneCounts(this);
261 if (this->GetProtocolFamily() == AF_INET)
263 delete (sockaddr_in*)ip;
265 #ifdef SUPPORT_IP6LINKS
268 delete (sockaddr_in6*)ip;
273 ServerInstance->Users->uuidlist->erase(uuid);
276 const std::string& User::MakeHost()
278 if (!this->cached_makehost.empty())
279 return this->cached_makehost;
282 /* This is much faster than snprintf */
284 for(const char* n = ident.c_str(); *n; n++)
287 for(const char* n = host.c_str(); *n; n++)
291 this->cached_makehost.assign(nhost);
293 return this->cached_makehost;
296 const std::string& User::MakeHostIP()
298 if (!this->cached_hostip.empty())
299 return this->cached_hostip;
302 /* This is much faster than snprintf */
304 for(const char* n = ident.c_str(); *n; n++)
307 for(const char* n = this->GetIPString(); *n; n++)
311 this->cached_hostip = ihost;
313 return this->cached_hostip;
316 void User::CloseSocket()
320 ServerInstance->SE->Shutdown(this, 2);
321 ServerInstance->SE->Close(this);
325 const std::string& User::GetFullHost()
327 if (!this->cached_fullhost.empty())
328 return this->cached_fullhost;
332 for(const char* n = nick.c_str(); *n; n++)
335 for(const char* n = ident.c_str(); *n; n++)
338 for(const char* n = dhost.c_str(); *n; n++)
342 this->cached_fullhost = result;
344 return this->cached_fullhost;
347 char* User::MakeWildHost()
349 static char nresult[MAXBUF];
351 *t++ = '*'; *t++ = '!';
352 *t++ = '*'; *t++ = '@';
353 for(const char* n = dhost.c_str(); *n; n++)
359 int User::ReadData(void* buffer, size_t size)
364 return read(this->fd, buffer, size);
366 return recv(this->fd, (char*)buffer, size, 0);
374 const std::string& User::GetFullRealHost()
376 if (!this->cached_fullrealhost.empty())
377 return this->cached_fullrealhost;
379 char fresult[MAXBUF];
381 for(const char* n = nick.c_str(); *n; n++)
384 for(const char* n = ident.c_str(); *n; n++)
387 for(const char* n = host.c_str(); *n; n++)
391 this->cached_fullrealhost = fresult;
393 return this->cached_fullrealhost;
396 bool User::IsInvited(const irc::string &channel)
398 time_t now = time(NULL);
399 InvitedList::iterator safei;
400 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
402 if (channel == i->first)
404 if (i->second != 0 && now > i->second)
406 /* Expired invite, remove it. */
409 invites.erase(safei);
418 InvitedList* User::GetInviteList()
420 time_t now = time(NULL);
421 /* Weed out expired invites here. */
422 InvitedList::iterator safei;
423 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
425 if (i->second != 0 && now > i->second)
427 /* Expired invite, remove it. */
430 invites.erase(safei);
436 void User::InviteTo(const irc::string &channel, time_t invtimeout)
438 time_t now = time(NULL);
439 if (invtimeout != 0 && now > invtimeout) return; /* Don't add invites that are expired from the get-go. */
440 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
442 if (channel == i->first)
444 if (i->second != 0 && invtimeout > i->second)
446 i->second = invtimeout;
452 invites.push_back(std::make_pair(channel, invtimeout));
455 void User::RemoveInvite(const irc::string &channel)
457 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
459 if (channel == i->first)
467 bool User::HasModePermission(unsigned char mode, ModeType type)
475 if (!AllowedUserModes || !AllowedChanModes)
478 return ((type == MODETYPE_USER ? AllowedUserModes : AllowedChanModes))[(mode - 'A')];
482 bool User::HasPermission(const std::string &command)
485 * users on remote servers can completely bypass all permissions based checks.
486 * This prevents desyncs when one server has different type/class tags to another.
487 * That having been said, this does open things up to the possibility of source changes
488 * allowing remote kills, etc - but if they have access to the src, they most likely have
489 * access to the conf - so it's an end to a means either way.
494 // are they even an oper at all?
500 if (!AllowedOperCommands)
503 if (AllowedOperCommands->find(command) != AllowedOperCommands->end())
505 else if (AllowedOperCommands->find("*") != AllowedOperCommands->end())
511 bool User::AddBuffer(const std::string &a)
513 std::string::size_type start = 0;
514 std::string::size_type i = a.find('\r');
517 * The old implementation here took a copy, and rfind() on \r, removing as it found them, before
518 * copying a second time onto the recvq. That's ok, but involves three copies minimum (recv() to buffer,
519 * buffer to here, here to recvq) - The new method now copies twice (recv() to buffer, buffer to recvq).
521 * We use find() instead of rfind() for clarity, however unlike the old code, our scanning of the string is
522 * contiguous: as we specify a startpoint, we never see characters we have scanned previously, making this
523 * marginally faster in cases with a number of \r hidden early on in the buffer.
526 * Start at first pos of string, find first \r, append everything in the chunk (excluding \r) to recvq. Set
527 * i ahead of the \r, search for next \r, add next chunk to buffer... repeat.
528 * -- w00t (7 may, 2008)
530 if (i == std::string::npos)
532 // no \r that we need to dance around, just add to buffer
537 // While we can find the end of a chunk to add
538 while (i != std::string::npos)
540 // Append the chunk that we have
541 recvq.append(a, start, (i - start));
543 // Start looking for the next one
545 i = a.find('\r', start);
548 if (start != a.length())
551 * This is here to catch a corner case when we get something like:
555 * in successive calls to us.
557 * Without this conditional, the 'U' on the second case will be dropped,
558 * which is most *certainly* not the behaviour we want!
561 recvq.append(a, start, (a.length() - start));
565 if (this->MyClass && (recvq.length() > this->MyClass->GetRecvqMax()))
567 ServerInstance->Users->QuitUser(this, "RecvQ exceeded");
568 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());
575 bool User::BufferIsReady()
577 return (recvq.find('\n') != std::string::npos);
580 void User::ClearBuffer()
585 std::string User::GetBuffer()
592 /* Strip any leading \r or \n off the string.
593 * Usually there are only one or two of these,
594 * so its is computationally cheap to do.
596 std::string::iterator t = recvq.begin();
597 while (t != recvq.end() && (*t == '\r' || *t == '\n'))
603 for (std::string::iterator x = recvq.begin(); x != recvq.end(); x++)
605 /* Find the first complete line, return it as the
606 * result, and leave the recvq as whats left
610 std::string ret = std::string(recvq.begin(), x);
611 recvq.erase(recvq.begin(), x + 1);
620 ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::GetBuffer()");
625 void User::AddWriteBuf(const std::string &data)
630 if (this->MyClass && (sendq.length() + data.length() > this->MyClass->GetSendqMax()))
633 * Fix by brain - Set the error text BEFORE calling, because
634 * if we dont it'll recursively call here over and over again trying
635 * to repeatedly add the text to the sendq!
637 ServerInstance->Users->QuitUser(this, "SendQ exceeded");
638 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());
642 if (data.length() > MAXBUF - 2) /* MAXBUF has a value of 514, to account for line terminators */
643 sendq.append(data.substr(0,MAXBUF - 4)).append("\r\n"); /* MAXBUF-4 = 510 */
648 // send AS MUCH OF THE USERS SENDQ as we are able to (might not be all of it)
649 void User::FlushWriteBuf()
651 if (this->fd == FD_MAGIC_NUMBER)
657 if ((sendq.length()) && (this->fd != FD_MAGIC_NUMBER))
659 int old_sendq_length = sendq.length();
660 int n_sent = ServerInstance->SE->Send(this, this->sendq.data(), this->sendq.length(), 0);
666 /* The socket buffer is full. This isnt fatal,
669 ServerInstance->SE->WantWrite(this);
673 /* Fatal error, set write error and bail */
674 ServerInstance->Users->QuitUser(this, errno ? strerror(errno) : "Write error");
680 /* advance the queue */
682 this->sendq = this->sendq.substr(n_sent);
683 /* update the user's stats counters */
684 this->bytes_out += n_sent;
686 if (n_sent != old_sendq_length)
687 this->ServerInstance->SE->WantWrite(this);
691 /* note: NOT else if! */
692 if (this->sendq.empty())
694 FOREACH_MOD(I_OnBufferFlushed,OnBufferFlushed(this));
698 void User::Oper(const std::string &opertype, const std::string &opername)
706 this->modes[UM_OPERATOR] = 1;
707 this->WriteServ("MODE %s :+o", this->nick.c_str());
708 FOREACH_MOD(I_OnOper, OnOper(this, opertype));
709 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());
710 this->oper.assign(opertype, 0, 512);
711 ServerInstance->Users->all_opers.push_back(this);
713 opertype_t::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper.c_str());
714 if (iter_opertype != ServerInstance->Config->opertypes.end())
717 if (AllowedOperCommands)
718 AllowedOperCommands->clear();
720 AllowedOperCommands = new std::map<std::string, bool>;
722 if (!AllowedChanModes)
723 AllowedChanModes = new bool[64];
725 if (!AllowedUserModes)
726 AllowedUserModes = new bool[64];
728 memset(AllowedUserModes, 0, 64);
729 memset(AllowedChanModes, 0, 64);
731 char* Classes = strdup(iter_opertype->second);
732 char* myclass = strtok_r(Classes," ",&savept);
735 operclass_t::iterator iter_operclass = ServerInstance->Config->operclass.find(myclass);
736 if (iter_operclass != ServerInstance->Config->operclass.end())
738 char* CommandList = strdup(iter_operclass->second.commandlist);
739 mycmd = strtok_r(CommandList," ",&savept2);
742 this->AllowedOperCommands->insert(std::make_pair(mycmd, true));
743 mycmd = strtok_r(NULL," ",&savept2);
746 this->AllowedUserModes['o' - 'A'] = true; // Call me paranoid if you want.
747 for (unsigned char* c = (unsigned char*)iter_operclass->second.umodelist; *c; ++c)
751 memset(this->AllowedUserModes, (int)(true), 64);
755 this->AllowedUserModes[*c - 'A'] = true;
758 for (unsigned char* c = (unsigned char*)iter_operclass->second.cmodelist; *c; ++c)
762 memset(this->AllowedChanModes, (int)(true), 64);
766 this->AllowedChanModes[*c - 'A'] = true;
770 myclass = strtok_r(NULL," ",&savept);
775 FOREACH_MOD(I_OnPostOper,OnPostOper(this, opertype, opername));
780 ServerInstance->Logs->Log("OPER", DEBUG,"Exception in User::Oper()");
788 /* Remove all oper only modes from the user when the deoper - Bug #466*/
789 std::string moderemove("-");
791 for (unsigned char letter = 'A'; letter <= 'z'; letter++)
795 ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_USER);
796 if (mh && mh->NeedsOper())
797 moderemove += letter;
801 std::vector<std::string> parameters;
802 parameters.push_back(this->nick);
803 parameters.push_back(moderemove);
805 ServerInstance->Parser->CallHandler("MODE", parameters, this);
807 /* unset their oper type (what IS_OPER checks), and remove +o */
809 this->modes[UM_OPERATOR] = 0;
811 /* remove the user from the oper list. Will remove multiple entries as a safeguard against bug #404 */
812 ServerInstance->Users->all_opers.remove(this);
814 if (AllowedOperCommands)
816 delete AllowedOperCommands;
817 AllowedOperCommands = NULL;
819 if (AllowedUserModes)
821 delete[] AllowedUserModes;
822 AllowedUserModes = NULL;
824 if (AllowedChanModes)
826 delete[] AllowedChanModes;
827 AllowedChanModes = NULL;
833 /* adds or updates an entry in the whowas list */
834 void User::AddToWhoWas()
836 Command* whowas_command = ServerInstance->Parser->GetHandler("WHOWAS");
839 std::deque<classbase*> params;
840 params.push_back(this);
841 whowas_command->HandleInternal(WHOWAS_ADD, params);
846 * Check class restrictions
848 void User::CheckClass()
850 ConnectClass* a = this->MyClass;
852 if ((!a) || (a->GetType() == CC_DENY))
854 ServerInstance->Users->QuitUser(this, "Unauthorised connection");
857 else if ((a->GetMaxLocal()) && (ServerInstance->Users->LocalCloneCount(this) > a->GetMaxLocal()))
859 ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (local)");
860 ServerInstance->SNO->WriteToSnoMask('A', "WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString());
863 else if ((a->GetMaxGlobal()) && (ServerInstance->Users->GlobalCloneCount(this) > a->GetMaxGlobal()))
865 ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (global)");
866 ServerInstance->SNO->WriteToSnoMask('A', "WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString());
870 this->nping = ServerInstance->Time() + a->GetPingTime() + ServerInstance->Config->dns_timeout;
873 bool User::CheckLines()
875 const char* check[] = { "G" , "K", NULL };
879 for (int n = 0; check[n]; ++n)
881 XLine *r = ServerInstance->XLines->MatchesLine(check[n], this);
894 void User::FullConnect()
896 ServerInstance->stats->statsConnects++;
897 this->idle_lastmsg = ServerInstance->Time();
900 * You may be thinking "wtf, we checked this in User::AddClient!" - and yes, we did, BUT.
901 * At the time AddClient is called, we don't have a resolved host, by here we probably do - which
902 * may put the user into a totally seperate class with different restrictions! so we *must* check again.
903 * Don't remove this! -- w00t
907 /* Check the password, if one is required by the user's connect class.
908 * This CANNOT be in CheckClass(), because that is called prior to PASS as well!
910 if (this->MyClass && !this->MyClass->GetPass().empty() && !this->haspassed)
912 ServerInstance->Users->QuitUser(this, "Invalid password");
916 if (this->CheckLines())
919 this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network);
920 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());
921 this->WriteNumeric(RPL_YOURHOSTIS, "%s :Your host is %s, running version InspIRCd-1.2",this->nick.c_str(),ServerInstance->Config->ServerName);
922 this->WriteNumeric(RPL_SERVERCREATED, "%s :This server was created %s %s", this->nick.c_str(), __TIME__, __DATE__);
923 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());
925 ServerInstance->Config->Send005(this);
926 this->WriteNumeric(RPL_YOURUUID, "%s %s :your unique ID", this->nick.c_str(), this->uuid.c_str());
932 if (ServerInstance->Users->unregistered_count)
933 ServerInstance->Users->unregistered_count--;
935 /* Trigger LUSERS output, give modules a chance too */
937 std::string command("LUSERS");
938 std::vector<std::string> parameters;
939 FOREACH_RESULT(I_OnPreCommand, OnPreCommand(command, parameters, this, true, "LUSERS"));
941 ServerInstance->CallCommandHandler(command, parameters, this);
944 * We don't set REG_ALL until triggering OnUserConnect, so some module events don't spew out stuff
945 * for a user that doesn't exist yet.
947 FOREACH_MOD(I_OnUserConnect,OnUserConnect(this));
949 this->registered = REG_ALL;
951 ServerInstance->PI->Introduce(this);
953 FOREACH_MOD(I_OnPostConnect,OnPostConnect(this));
955 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());
956 ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCache: Adding NEGATIVE hit for %s", this->GetIPString());
957 ServerInstance->BanCache->AddHit(this->GetIPString(), "", "");
960 /** User::UpdateNick()
961 * re-allocates a nick in the user_hash after they change nicknames,
962 * returns a pointer to the new user as it may have moved
964 User* User::UpdateNickHash(const char* New)
966 //user_hash::iterator newnick;
967 user_hash::iterator oldnick = ServerInstance->Users->clientlist->find(this->nick);
969 if (!irc::string(this->nick.c_str()).compare(New))
970 return oldnick->second;
972 if (oldnick == ServerInstance->Users->clientlist->end())
973 return NULL; /* doesnt exist */
975 User* olduser = oldnick->second;
976 (*(ServerInstance->Users->clientlist))[New] = olduser;
977 ServerInstance->Users->clientlist->erase(oldnick);
981 void User::InvalidateCache()
983 /* Invalidate cache */
984 cached_fullhost.clear();
985 cached_hostip.clear();
986 cached_makehost.clear();
987 cached_fullrealhost.clear();
990 bool User::ForceNickChange(const char* newnick)
994 this->InvalidateCache();
996 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(this, newnick));
1000 ServerInstance->stats->statsCollisions++;
1004 std::deque<classbase*> dummy;
1005 Command* nickhandler = ServerInstance->Parser->GetHandler("NICK");
1006 if (nickhandler) // wtfbbq, when would this not be here
1008 std::vector<std::string> parameters;
1009 nickhandler->HandleInternal(1, dummy);
1010 parameters.push_back(newnick);
1011 bool result = (ServerInstance->Parser->CallHandler("NICK", parameters, this) == CMD_SUCCESS);
1012 nickhandler->HandleInternal(0, dummy);
1016 // Unreachable, we hope
1020 void User::SetSockAddr(int protocol_family, const char* sip, int port)
1022 this->cachedip = "";
1024 switch (protocol_family)
1026 #ifdef SUPPORT_IP6LINKS
1029 sockaddr_in6* sin = new sockaddr_in6;
1030 sin->sin6_family = AF_INET6;
1031 sin->sin6_port = port;
1032 inet_pton(AF_INET6, sip, &sin->sin6_addr);
1033 this->ip = (sockaddr*)sin;
1039 sockaddr_in* sin = new sockaddr_in;
1040 sin->sin_family = AF_INET;
1041 sin->sin_port = port;
1042 inet_pton(AF_INET, sip, &sin->sin_addr);
1043 this->ip = (sockaddr*)sin;
1047 ServerInstance->Logs->Log("USERS",DEBUG,"Uh oh, I dont know protocol %d to be set on '%s'!", protocol_family, this->nick.c_str());
1054 if (this->ip == NULL)
1057 switch (this->GetProtocolFamily())
1059 #ifdef SUPPORT_IP6LINKS
1062 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1063 return sin->sin6_port;
1069 sockaddr_in* sin = (sockaddr_in*)this->ip;
1070 return sin->sin_port;
1079 int User::GetProtocolFamily()
1081 if (this->ip == NULL)
1084 sockaddr_in* sin = (sockaddr_in*)this->ip;
1085 return sin->sin_family;
1088 const char* User::GetCIDRMask(int range)
1090 static char buf[44];
1092 if (this->ip == NULL)
1096 throw "Negative range, sorry, no.";
1099 * Original code written by Oliver Lupton (Om).
1100 * Integrated by me. Thanks. :) -- w00t
1102 switch (this->GetProtocolFamily())
1104 #ifdef SUPPORT_IP6LINKS
1107 /* unsigned char s6_addr[16]; */
1110 int i, bytestozero, extrabits;
1114 throw "CIDR mask width greater than address width (IPv6, 128 bit)";
1116 /* Access the user's IP structure directly */
1117 sin = (sockaddr_in6*)this->ip;
1119 /* To create the CIDR mask we want to set all the bits after 'range' bits of the address
1120 * to zero. This means the last (128 - range) bits of the address must be set to zero.
1121 * Hence this number divided by 8 is the number of whole bytes from the end of the address
1122 * which must be set to zero.
1124 bytestozero = (128 - range) / 8;
1126 /* Some of the least significant bits of the next most significant byte may also have to
1127 * be zeroed. The number of bits is the remainder of the above division.
1129 extrabits = (128 - range) % 8;
1131 /* Populate our working struct with the parts of the user's IP which are required in the
1132 * final CIDR mask. Set all the subsequent bytes to zero.
1133 * (16 - bytestozero) is the number of bytes which must be populated with actual IP data.
1135 for(i = 0; i < (16 - bytestozero); i++)
1137 v6.s6_addr[i] = sin->sin6_addr.s6_addr[i];
1140 /* And zero all the remaining bytes in the IP. */
1146 /* And finally, zero the extra bits required. */
1147 v6.s6_addr[15 - bytestozero] = (v6.s6_addr[15 - bytestozero] >> extrabits) << extrabits;
1149 snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET6, &v6, buffer, 40), range);
1161 throw "CIDR mask width greater than address width (IPv4, 32 bit)";
1163 /* Users already have a sockaddr* pointer (User::ip) which contains either a v4 or v6 structure */
1164 sin = (sockaddr_in*)this->ip;
1165 v4.s_addr = sin->sin_addr.s_addr;
1167 /* To create the CIDR mask we want to set all the bits after 'range' bits of the address
1168 * to zero. This means the last (32 - range) bits of the address must be set to zero.
1169 * This is done by shifting the value right and then back left by (32 - range) bits.
1173 v4.s_addr = ntohl(v4.s_addr);
1174 v4.s_addr = (v4.s_addr >> (32 - range)) << (32 - range);
1175 v4.s_addr = htonl(v4.s_addr);
1179 /* a range of zero would cause a 32 bit value to be shifted by 32 bits.
1180 * this has undefined behaviour, but for CIDR purposes the resulting mask
1181 * from a.b.c.d/0 is 0.0.0.0/0
1186 snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET, &v4, buffer, 16), range);
1192 return ""; // unused, but oh well
1195 const char* User::GetIPString(bool translate4in6)
1197 static char buf[40];
1199 if (this->ip == NULL)
1202 if (!this->cachedip.empty())
1203 return this->cachedip.c_str();
1205 switch (this->GetProtocolFamily())
1207 #ifdef SUPPORT_IP6LINKS
1210 static char temp[1024];
1212 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1213 inet_ntop(sin->sin6_family, &sin->sin6_addr, buf, sizeof(buf));
1214 /* IP addresses starting with a : on irc are a Bad Thing (tm) */
1217 strlcpy(&temp[1], buf, sizeof(temp) - 1);
1219 if (translate4in6 && !strncmp(temp, "0::ffff:", 8))
1221 this->cachedip = temp + 8;
1225 this->cachedip = temp;
1229 this->cachedip = buf;
1236 sockaddr_in* sin = (sockaddr_in*)this->ip;
1237 inet_ntop(sin->sin_family, &sin->sin_addr, buf, sizeof(buf));
1238 this->cachedip = buf;
1246 // Unreachable, probably
1250 /** NOTE: We cannot pass a const reference to this method.
1251 * The string is changed by the workings of the method,
1252 * so that if we pass const ref, we end up copying it to
1253 * something we can change anyway. Makes sense to just let
1254 * the compiler do that copy for us.
1256 void User::Write(std::string text)
1258 if (!ServerInstance->SE->BoundsCheckFd(this))
1263 ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"C[%d] O %s", this->GetFd(), text.c_str());
1264 text.append("\r\n");
1268 ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"Exception in User::Write() std::string::append");
1274 /* XXX: The lack of buffering here is NOT a bug, modules implementing this interface have to
1275 * implement their own buffering mechanisms
1279 this->io->OnRawSocketWrite(this->fd, text.data(), text.length());
1281 catch (CoreException& modexcept)
1283 ServerInstance->Logs->Log("USEROUTPUT", DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
1288 this->AddWriteBuf(text);
1290 ServerInstance->stats->statsSent += text.length();
1291 this->ServerInstance->SE->WantWrite(this);
1296 void User::Write(const char *text, ...)
1299 char textbuffer[MAXBUF];
1301 va_start(argsPtr, text);
1302 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1305 this->Write(std::string(textbuffer));
1308 void User::WriteServ(const std::string& text)
1310 char textbuffer[MAXBUF];
1312 snprintf(textbuffer,MAXBUF,":%s %s",ServerInstance->Config->ServerName,text.c_str());
1313 this->Write(std::string(textbuffer));
1317 * Same as Write(), except `text' is prefixed with `:server.name '.
1319 void User::WriteServ(const char* text, ...)
1322 char textbuffer[MAXBUF];
1324 va_start(argsPtr, text);
1325 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1328 this->WriteServ(std::string(textbuffer));
1332 void User::WriteNumeric(unsigned int numeric, const char* text, ...)
1335 char textbuffer[MAXBUF];
1337 va_start(argsPtr, text);
1338 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1341 this->WriteNumeric(numeric, std::string(textbuffer));
1344 void User::WriteNumeric(unsigned int numeric, const std::string &text)
1346 char textbuffer[MAXBUF];
1349 FOREACH_RESULT(I_OnNumeric, OnNumeric(this, numeric, text));
1354 snprintf(textbuffer,MAXBUF,":%s %03u %s",ServerInstance->Config->ServerName, numeric, text.c_str());
1355 this->Write(std::string(textbuffer));
1358 void User::WriteFrom(User *user, const std::string &text)
1362 snprintf(tb,MAXBUF,":%s %s",user->GetFullHost().c_str(),text.c_str());
1364 this->Write(std::string(tb));
1368 /* write text from an originating user to originating user */
1370 void User::WriteFrom(User *user, const char* text, ...)
1373 char textbuffer[MAXBUF];
1375 va_start(argsPtr, text);
1376 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1379 this->WriteFrom(user, std::string(textbuffer));
1383 /* write text to an destination user from a source user (e.g. user privmsg) */
1385 void User::WriteTo(User *dest, const char *data, ...)
1387 char textbuffer[MAXBUF];
1390 va_start(argsPtr, data);
1391 vsnprintf(textbuffer, MAXBUF, data, argsPtr);
1394 this->WriteTo(dest, std::string(textbuffer));
1397 void User::WriteTo(User *dest, const std::string &data)
1399 dest->WriteFrom(this, data);
1403 void User::WriteCommon(const char* text, ...)
1405 char textbuffer[MAXBUF];
1408 if (this->registered != REG_ALL)
1411 va_start(argsPtr, text);
1412 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1415 this->WriteCommon(std::string(textbuffer));
1418 void User::WriteCommon(const std::string &text)
1420 bool sent_to_at_least_one = false;
1423 if (this->registered != REG_ALL)
1429 InitializeAlreadySent(ServerInstance->SE);
1431 /* We dont want to be doing this n times, just once */
1432 snprintf(tb,MAXBUF,":%s %s",this->GetFullHost().c_str(),text.c_str());
1433 std::string out = tb;
1435 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1437 CUList* ulist = v->first->GetUsers();
1438 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1440 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1442 already_sent[i->first->fd] = uniq_id;
1443 i->first->Write(out);
1444 sent_to_at_least_one = true;
1450 * if the user was not in any channels, no users will receive the text. Make sure the user
1451 * receives their OWN message for WriteCommon
1453 if (!sent_to_at_least_one)
1455 this->Write(std::string(tb));
1460 /* write a formatted string to all users who share at least one common
1461 * channel, NOT including the source user e.g. for use in QUIT
1464 void User::WriteCommonExcept(const char* text, ...)
1466 char textbuffer[MAXBUF];
1469 va_start(argsPtr, text);
1470 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1473 this->WriteCommonExcept(std::string(textbuffer));
1476 void User::WriteCommonQuit(const std::string &normal_text, const std::string &oper_text)
1481 if (this->registered != REG_ALL)
1487 InitializeAlreadySent(ServerInstance->SE);
1489 snprintf(tb1,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),normal_text.c_str());
1490 snprintf(tb2,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),oper_text.c_str());
1491 std::string out1 = tb1;
1492 std::string out2 = tb2;
1494 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1496 CUList *ulist = v->first->GetUsers();
1497 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1499 if (this != i->first)
1501 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1503 already_sent[i->first->fd] = uniq_id;
1504 i->first->Write(IS_OPER(i->first) ? out2 : out1);
1511 void User::WriteCommonExcept(const std::string &text)
1516 if (this->registered != REG_ALL)
1522 InitializeAlreadySent(ServerInstance->SE);
1524 snprintf(tb1,MAXBUF,":%s %s",this->GetFullHost().c_str(),text.c_str());
1527 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1529 CUList *ulist = v->first->GetUsers();
1530 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1532 if (this != i->first)
1534 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1536 already_sent[i->first->fd] = uniq_id;
1537 i->first->Write(out1);
1545 void User::WriteWallOps(const std::string &text)
1547 if (!IS_LOCAL(this))
1550 std::string wallop("WALLOPS :");
1551 wallop.append(text);
1553 for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
1556 if (t->IsModeSet('w'))
1557 this->WriteTo(t,wallop);
1561 void User::WriteWallOps(const char* text, ...)
1563 if (!IS_LOCAL(this))
1566 char textbuffer[MAXBUF];
1569 va_start(argsPtr, text);
1570 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1573 this->WriteWallOps(std::string(textbuffer));
1576 /* return 0 or 1 depending if users u and u2 share one or more common channels
1577 * (used by QUIT, NICK etc which arent channel specific notices)
1579 * The old algorithm in 1.0 for this was relatively inefficient, iterating over
1580 * the first users channels then the second users channels within the outer loop,
1581 * therefore it was a maximum of x*y iterations (upon returning 0 and checking
1582 * all possible iterations). However this new function instead checks against the
1583 * channel's userlist in the inner loop which is a std::map<User*,User*>
1584 * and saves us time as we already know what pointer value we are after.
1585 * Don't quote me on the maths as i am not a mathematician or computer scientist,
1586 * but i believe this algorithm is now x+(log y) maximum iterations instead.
1588 bool User::SharesChannelWith(User *other)
1590 if ((!other) || (this->registered != REG_ALL) || (other->registered != REG_ALL))
1594 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1596 /* Eliminate the inner loop (which used to be ~equal in size to the outer loop)
1597 * by replacing it with a map::find which *should* be more efficient
1599 if (i->first->HasUser(other))
1605 bool User::ChangeName(const char* gecos)
1607 if (!this->fullname.compare(gecos))
1613 FOREACH_RESULT(I_OnChangeLocalUserGECOS,OnChangeLocalUserGECOS(this,gecos));
1616 FOREACH_MOD(I_OnChangeName,OnChangeName(this,gecos));
1618 this->fullname.assign(gecos, 0, ServerInstance->Config->Limits.MaxGecos);
1623 bool User::ChangeDisplayedHost(const char* shost)
1631 FOREACH_RESULT(I_OnChangeLocalUserHost,OnChangeLocalUserHost(this,shost));
1634 FOREACH_MOD(I_OnChangeHost,OnChangeHost(this,shost));
1637 if (this->ServerInstance->Config->CycleHosts)
1638 this->WriteCommonExcept("QUIT :Changing hosts");
1640 /* Fix by Om: User::dhost is 65 long, this was truncating some long hosts */
1641 this->dhost.assign(shost, 0, 64);
1643 this->InvalidateCache();
1645 if (this->ServerInstance->Config->CycleHosts)
1647 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1649 i->first->WriteAllExceptSender(this, false, 0, "JOIN %s", i->first->name.c_str());
1650 std::string n = this->ServerInstance->Modes->ModeString(this, i->first);
1652 i->first->WriteAllExceptSender(this, true, 0, "MODE %s +%s", i->first->name.c_str(), n.c_str());
1657 this->WriteNumeric(RPL_YOURDISPLAYEDHOST, "%s %s :is now your displayed host",this->nick.c_str(),this->dhost.c_str());
1662 bool User::ChangeIdent(const char* newident)
1664 if (!this->ident.compare(newident))
1667 if (this->ServerInstance->Config->CycleHosts)
1668 this->WriteCommonExcept("%s","QUIT :Changing ident");
1670 this->ident.assign(newident, 0, ServerInstance->Config->Limits.IdentMax + 1);
1672 this->InvalidateCache();
1674 if (this->ServerInstance->Config->CycleHosts)
1676 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1678 i->first->WriteAllExceptSender(this, false, 0, "JOIN %s", i->first->name.c_str());
1679 std::string n = this->ServerInstance->Modes->ModeString(this, i->first);
1681 i->first->WriteAllExceptSender(this, true, 0, "MODE %s +%s", i->first->name.c_str(), n.c_str());
1688 void User::SendAll(const char* command, const char* text, ...)
1690 char textbuffer[MAXBUF];
1691 char formatbuffer[MAXBUF];
1694 va_start(argsPtr, text);
1695 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1698 snprintf(formatbuffer,MAXBUF,":%s %s $* :%s", this->GetFullHost().c_str(), command, textbuffer);
1699 std::string fmt = formatbuffer;
1701 for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
1708 std::string User::ChannelList(User* source)
1712 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1714 /* If the target is the same as the sender, let them see all their channels.
1715 * If the channel is NOT private/secret OR the user shares a common channel
1716 * If the user is an oper, and the <options:operspywhois> option is set.
1718 if ((source == this) || (IS_OPER(source) && ServerInstance->Config->OperSpyWhois) || (((!i->first->IsModeSet('p')) && (!i->first->IsModeSet('s'))) || (i->first->HasUser(source))))
1720 list.append(i->first->GetPrefixChar(this)).append(i->first->name).append(" ");
1727 void User::SplitChanList(User* dest, const std::string &cl)
1730 std::ostringstream prefix;
1731 std::string::size_type start, pos, length;
1733 prefix << this->nick << " " << dest->nick << " :";
1734 line = prefix.str();
1735 int namelen = strlen(ServerInstance->Config->ServerName) + 6;
1737 for (start = 0; (pos = cl.find(' ', start)) != std::string::npos; start = pos+1)
1739 length = (pos == std::string::npos) ? cl.length() : pos;
1741 if (line.length() + namelen + length - start > 510)
1743 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1744 line = prefix.str();
1747 if(pos == std::string::npos)
1749 line.append(cl.substr(start, length - start));
1754 line.append(cl.substr(start, length - start + 1));
1760 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1765 * Sets a user's connection class.
1766 * If the class name is provided, it will be used. Otherwise, the class will be guessed using host/ip/ident/etc.
1767 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1768 * then their ip will be taken as 'priority' anyway, so for example,
1769 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1771 ConnectClass* User::SetClass(const std::string &explicit_name)
1773 ConnectClass *found = NULL;
1775 if (!IS_LOCAL(this))
1778 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Setting connect class for UID %s", this->uuid.c_str());
1780 if (!explicit_name.empty())
1782 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1784 ConnectClass* c = *i;
1786 if (c->GetDisabled())
1787 continue; // can't possibly match, removed from conf
1789 if (explicit_name == c->GetName())
1791 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Explicitly set to %s", explicit_name.c_str());
1798 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1800 ConnectClass* c = *i;
1802 if (c->GetType() == CC_ALLOW)
1804 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "ALLOW %s %d %s", c->GetHost().c_str(), c->GetPort(), c->GetName().c_str());
1808 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "DENY %s %d %s", c->GetHost().c_str(), c->GetPort(), c->GetName().c_str());
1811 /* if it's disabled, we can't match this one. */
1812 if (c->GetDisabled())
1814 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Class disabled");
1818 /* check if host matches.. */
1819 if (!InspIRCd::MatchCIDR(this->GetIPString(), c->GetHost(), NULL) &&
1820 !InspIRCd::MatchCIDR(this->host, c->GetHost(), NULL))
1822 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "No host match (for %s)", c->GetHost().c_str());
1827 * deny change if change will take class over the limit check it HERE, not after we found a matching class,
1828 * because we should attempt to find another class if this one doesn't match us. -- w00t
1830 if (c->limit && (c->RefCount + 1 >= c->limit))
1832 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "OOPS: Connect class limit (%lu) hit, denying", c->limit);
1836 /* if it requires a port ... */
1839 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Requires port (%d)", c->GetPort());
1841 /* and our port doesn't match, fail. */
1842 if (this->GetPort() != c->GetPort())
1844 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Port match failed (%d)", this->GetPort());
1849 /* we stop at the first class that meets ALL critera. */
1856 * Okay, assuming we found a class that matches.. switch us into that class, keeping refcounts up to date.
1860 /* only fiddle with refcounts if they are already in a class .. */
1863 if (found == this->MyClass) // no point changing this shit :P
1864 return this->MyClass;
1865 this->MyClass->RefCount--;
1866 ServerInstance->Logs->Log("USERS", DEBUG, "Untying user from connect class -- refcount: %lu", this->MyClass->RefCount);
1869 this->MyClass = found;
1870 this->MyClass->RefCount++;
1871 ServerInstance->Logs->Log("USERS", DEBUG, "User tied to new class -- connect refcount now: %lu", this->MyClass->RefCount);
1874 return this->MyClass;
1877 /* looks up a users password for their connection class (<ALLOW>/<DENY> tags)
1878 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1879 * then their ip will be taken as 'priority' anyway, so for example,
1880 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1882 ConnectClass* User::GetClass()
1884 return this->MyClass;
1887 void User::PurgeEmptyChannels()
1889 std::vector<Channel*> to_delete;
1891 // firstly decrement the count on each channel
1892 for (UCListIter f = this->chans.begin(); f != this->chans.end(); f++)
1894 f->first->RemoveAllPrefixes(this);
1895 if (f->first->DelUser(this) == 0)
1897 /* No users left in here, mark it for deletion */
1900 to_delete.push_back(f->first);
1904 ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::PurgeEmptyChannels to_delete.push_back()");
1909 for (std::vector<Channel*>::iterator n = to_delete.begin(); n != to_delete.end(); n++)
1911 Channel* thischan = *n;
1912 chan_hash::iterator i2 = ServerInstance->chanlist->find(thischan->name);
1913 if (i2 != ServerInstance->chanlist->end())
1915 FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(i2->second));
1917 ServerInstance->chanlist->erase(i2);
1918 this->chans.erase(*n);
1925 void User::ShowMOTD()
1927 if (!ServerInstance->Config->MOTD.size())
1929 this->WriteNumeric(ERR_NOMOTD, "%s :Message of the day file is missing.",this->nick.c_str());
1932 this->WriteNumeric(RPL_MOTDSTART, "%s :%s message of the day", this->nick.c_str(), ServerInstance->Config->ServerName);
1934 for (file_cache::iterator i = ServerInstance->Config->MOTD.begin(); i != ServerInstance->Config->MOTD.end(); i++)
1935 this->WriteNumeric(RPL_MOTD, "%s :- %s",this->nick.c_str(),i->c_str());
1937 this->WriteNumeric(RPL_ENDOFMOTD, "%s :End of message of the day.", this->nick.c_str());
1940 void User::ShowRULES()
1942 if (!ServerInstance->Config->RULES.size())
1944 this->WriteNumeric(ERR_NORULES, "%s :RULES File is missing",this->nick.c_str());
1948 this->WriteNumeric(RPL_RULESTART, "%s :- %s Server Rules -",this->nick.c_str(),ServerInstance->Config->ServerName);
1950 for (file_cache::iterator i = ServerInstance->Config->RULES.begin(); i != ServerInstance->Config->RULES.end(); i++)
1951 this->WriteNumeric(RPL_RULES, "%s :- %s",this->nick.c_str(),i->c_str());
1953 this->WriteNumeric(RPL_RULESEND, "%s :End of RULES command.",this->nick.c_str());
1956 void User::HandleEvent(EventType et, int errornum)
1958 if (this->quitting) // drop everything, user is due to be quit
1964 ServerInstance->ProcessUser(this);
1967 this->FlushWriteBuf();
1970 ServerInstance->Users->QuitUser(this, errornum ? strerror(errornum) : "Client closed the connection");
1975 void User::SetOperQuit(const std::string &oquit)
1977 operquitmsg = oquit;
1980 const std::string& User::GetOperQuit()
1985 void User::IncreasePenalty(int increase)
1987 this->Penalty += increase;
1990 void User::DecreasePenalty(int decrease)
1992 this->Penalty -= decrease;
2003 bool VisData::VisibleTo(User* user)