1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/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);
93 std::string s = this->FormatNoticeMasks();
96 this->modes[UM_SNOMASK] = false;
102 void User::StartDNSLookup()
107 const char* sip = this->GetIPString();
108 UserResolver *res_reverse;
110 QueryType resolvtype = this->ip.sa.sa_family == AF_INET6 ? DNS_QUERY_PTR6 : DNS_QUERY_PTR4;
111 res_reverse = new UserResolver(this->ServerInstance, this, sip, resolvtype, cached);
113 this->ServerInstance->AddResolver(res_reverse, cached);
115 catch (CoreException& e)
117 ServerInstance->Logs->Log("USERS", DEBUG,"Error in resolver: %s",e.GetReason());
121 bool User::IsNoticeMaskSet(unsigned char sm)
125 return (snomasks[sm-65]);
128 void User::SetNoticeMask(unsigned char sm, bool value)
132 snomasks[sm-65] = value;
135 const char* User::FormatNoticeMasks()
137 static char data[MAXBUF];
140 for (int n = 0; n < 64; n++)
143 data[offset++] = n+65;
150 bool User::IsModeSet(unsigned char m)
154 return (modes[m-65]);
157 void User::SetMode(unsigned char m, bool value)
164 const char* User::FormatModes(bool showparameters)
166 static char data[MAXBUF];
170 for (unsigned char n = 0; n < 64; n++)
174 data[offset++] = n + 65;
175 ModeHandler* mh = ServerInstance->Modes->FindMode(n + 65, MODETYPE_USER);
176 if (showparameters && mh && mh->GetNumParams(true))
178 std::string p = mh->GetUserParameter(this);
180 params.append(" ").append(p);
185 strlcat(data, params.c_str(), MAXBUF);
189 void User::DecrementModes()
191 ServerInstance->Logs->Log("USERS", DEBUG, "DecrementModes()");
192 for (unsigned char n = 'A'; n <= 'z'; n++)
196 ServerInstance->Logs->Log("USERS", DEBUG,"DecrementModes() found mode %c", n);
197 ModeHandler* mh = ServerInstance->Modes->FindMode(n, MODETYPE_USER);
200 ServerInstance->Logs->Log("USERS", DEBUG,"Found handler %c and call ChangeCount", n);
207 User::User(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance)
209 server = (char*)Instance->FindServerNamePtr(Instance->Config->ServerName);
210 age = ServerInstance->Time();
212 lastping = signon = idle_lastmsg = nping = registered = 0;
213 bytes_in = bytes_out = cmds_in = cmds_out = 0;
214 quietquit = quitting = exempt = haspassed = dns_done = false;
216 ip.sa.sa_family = AF_UNSPEC;
221 AllowedPrivs = AllowedOperCommands = NULL;
226 uuid.assign(Instance->GetUID(), 0, UUID_LENGTH - 1);
228 uuid.assign(uid, 0, UUID_LENGTH - 1);
230 ServerInstance->Logs->Log("USERS", DEBUG,"New UUID for user: %s (%s)", uuid.c_str(), uid.empty() ? "allocated new" : "used remote");
232 user_hash::iterator finduuid = Instance->Users->uuidlist->find(uuid);
233 if (finduuid == Instance->Users->uuidlist->end())
234 (*Instance->Users->uuidlist)[uuid] = this;
236 throw CoreException("Duplicate UUID "+std::string(uuid)+" in User constructor");
241 /* NULL for remote users :) */
244 this->MyClass->RefCount--;
245 ServerInstance->Logs->Log("USERS", DEBUG, "User destructor -- connect refcount now: %lu", this->MyClass->RefCount);
246 if (MyClass->RefCount == 0)
250 if (this->AllowedOperCommands)
252 delete AllowedOperCommands;
253 AllowedOperCommands = NULL;
256 if (this->AllowedPrivs)
262 this->InvalidateCache();
263 this->DecrementModes();
265 if (ip.sa.sa_family != AF_UNSPEC)
266 ServerInstance->Users->RemoveCloneCounts(this);
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 = ServerInstance->Time();
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 = ServerInstance->Time();
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 = ServerInstance->Time();
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;
447 invites.push_back(std::make_pair(channel, invtimeout));
450 void User::RemoveInvite(const irc::string &channel)
452 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
454 if (channel == i->first)
462 bool User::HasModePermission(unsigned char mode, ModeType type)
470 if (mode < 'A' || mode > ('A' + 64)) return false;
472 return ((type == MODETYPE_USER ? AllowedUserModes : AllowedChanModes))[(mode - 'A')];
476 bool User::HasPermission(const std::string &command)
479 * users on remote servers can completely bypass all permissions based checks.
480 * This prevents desyncs when one server has different type/class tags to another.
481 * That having been said, this does open things up to the possibility of source changes
482 * allowing remote kills, etc - but if they have access to the src, they most likely have
483 * access to the conf - so it's an end to a means either way.
488 // are they even an oper at all?
494 if (!AllowedOperCommands)
497 if (AllowedOperCommands->find(command) != AllowedOperCommands->end())
499 else if (AllowedOperCommands->find("*") != AllowedOperCommands->end())
506 bool User::HasPrivPermission(const std::string &privstr, bool noisy)
510 ServerInstance->Logs->Log("PRIVS", DEBUG, "Remote (yes)");
517 this->WriteServ("NOTICE %s :You are not an oper", this->nick.c_str());
524 this->WriteServ("NOTICE %s :Privset empty(!?)", this->nick.c_str());
528 if (AllowedPrivs->find(privstr) != AllowedPrivs->end())
532 else if (AllowedPrivs->find("*") != AllowedPrivs->end())
538 this->WriteServ("NOTICE %s :Oper type %s does not have access to priv %s", this->nick.c_str(), this->oper.c_str(), privstr.c_str());
542 bool User::AddBuffer(const std::string &a)
544 std::string::size_type start = 0;
545 std::string::size_type i = a.find('\r');
548 * The old implementation here took a copy, and rfind() on \r, removing as it found them, before
549 * copying a second time onto the recvq. That's ok, but involves three copies minimum (recv() to buffer,
550 * buffer to here, here to recvq) - The new method now copies twice (recv() to buffer, buffer to recvq).
552 * We use find() instead of rfind() for clarity, however unlike the old code, our scanning of the string is
553 * contiguous: as we specify a startpoint, we never see characters we have scanned previously, making this
554 * marginally faster in cases with a number of \r hidden early on in the buffer.
557 * Start at first pos of string, find first \r, append everything in the chunk (excluding \r) to recvq. Set
558 * i ahead of the \r, search for next \r, add next chunk to buffer... repeat.
559 * -- w00t (7 may, 2008)
561 if (i == std::string::npos)
563 // no \r that we need to dance around, just add to buffer
568 // While we can find the end of a chunk to add
569 while (i != std::string::npos)
571 // Append the chunk that we have
572 recvq.append(a, start, (i - start));
574 // Start looking for the next one
576 i = a.find('\r', start);
579 if (start != a.length())
582 * This is here to catch a corner case when we get something like:
586 * in successive calls to us.
588 * Without this conditional, the 'U' on the second case will be dropped,
589 * which is most *certainly* not the behaviour we want!
592 recvq.append(a, start, (a.length() - start));
596 if (this->MyClass && !this->HasPrivPermission("users/flood/increased-buffers") && recvq.length() > this->MyClass->GetRecvqMax())
598 ServerInstance->Users->QuitUser(this, "RecvQ exceeded");
599 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());
606 bool User::BufferIsReady()
608 return (recvq.find('\n') != std::string::npos);
611 void User::ClearBuffer()
616 std::string User::GetBuffer()
623 /* Strip any leading \r or \n off the string.
624 * Usually there are only one or two of these,
625 * so its is computationally cheap to do.
627 std::string::iterator t = recvq.begin();
628 while (t != recvq.end() && (*t == '\r' || *t == '\n'))
634 for (std::string::iterator x = recvq.begin(); x != recvq.end(); x++)
636 /* Find the first complete line, return it as the
637 * result, and leave the recvq as whats left
641 std::string ret = std::string(recvq.begin(), x);
642 recvq.erase(recvq.begin(), x + 1);
651 ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::GetBuffer()");
656 void User::AddWriteBuf(const std::string &data)
658 if (!this->quitting && this->MyClass && !this->HasPrivPermission("users/flood/increased-buffers") && sendq.length() + data.length() > this->MyClass->GetSendqMax())
661 * Fix by brain - Set the error text BEFORE calling, because
662 * if we dont it'll recursively call here over and over again trying
663 * to repeatedly add the text to the sendq!
665 ServerInstance->Users->QuitUser(this, "SendQ exceeded");
666 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());
670 // We still want to append data to the sendq of a quitting user,
671 // e.g. their ERROR message that says 'closing link'
673 if (data.length() > MAXBUF - 2) /* MAXBUF has a value of 514, to account for line terminators */
674 sendq.append(data.substr(0,MAXBUF - 4)).append("\r\n"); /* MAXBUF-4 = 510 */
679 // send AS MUCH OF THE USERS SENDQ as we are able to (might not be all of it)
680 void User::FlushWriteBuf()
682 if (this->fd == FD_MAGIC_NUMBER)
688 if ((sendq.length()) && (this->fd != FD_MAGIC_NUMBER))
690 int old_sendq_length = sendq.length();
691 int n_sent = ServerInstance->SE->Send(this, this->sendq.data(), this->sendq.length(), 0);
697 /* The socket buffer is full. This isnt fatal,
700 ServerInstance->SE->WantWrite(this);
704 /* Fatal error, set write error and bail */
705 ServerInstance->Users->QuitUser(this, errno ? strerror(errno) : "Write error");
711 /* advance the queue */
713 this->sendq = this->sendq.substr(n_sent);
714 /* update the user's stats counters */
715 this->bytes_out += n_sent;
717 if (n_sent != old_sendq_length)
718 this->ServerInstance->SE->WantWrite(this);
722 /* note: NOT else if! */
723 if (this->sendq.empty())
725 FOREACH_MOD(I_OnBufferFlushed,OnBufferFlushed(this));
729 void User::Oper(const std::string &opertype, const std::string &opername)
731 if (this->IsModeSet('o'))
734 this->modes[UM_OPERATOR] = 1;
735 this->WriteServ("MODE %s :+o", this->nick.c_str());
736 FOREACH_MOD(I_OnOper, OnOper(this, opertype));
738 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());
739 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()));
741 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());
742 this->oper.assign(opertype, 0, 512);
743 ServerInstance->Users->all_opers.push_back(this);
746 * This might look like it's in the wrong place.
749 * For multi-network servers, we may not have the opertypes of the remote server, but we still want to mark the user as an oper of that type.
752 opertype_t::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper.c_str());
753 if (iter_opertype != ServerInstance->Config->opertypes.end())
755 if (AllowedOperCommands)
756 AllowedOperCommands->clear();
758 AllowedOperCommands = new std::set<std::string>;
761 AllowedPrivs->clear();
763 AllowedPrivs = new std::set<std::string>;
765 AllowedUserModes.reset();
766 AllowedChanModes.reset();
767 this->AllowedUserModes['o' - 'A'] = true; // Call me paranoid if you want.
769 std::string myclass, mycmd, mypriv;
770 irc::spacesepstream Classes(iter_opertype->second.c_str());
771 while (Classes.GetToken(myclass))
773 operclass_t::iterator iter_operclass = ServerInstance->Config->operclass.find(myclass.c_str());
774 if (iter_operclass != ServerInstance->Config->operclass.end())
776 /* Process commands */
777 irc::spacesepstream CommandList(iter_operclass->second.commandlist);
778 while (CommandList.GetToken(mycmd))
780 this->AllowedOperCommands->insert(mycmd);
783 irc::spacesepstream PrivList(iter_operclass->second.privs);
784 while (PrivList.GetToken(mypriv))
786 this->AllowedPrivs->insert(mypriv);
789 for (unsigned char* c = (unsigned char*)iter_operclass->second.umodelist; *c; ++c)
793 this->AllowedUserModes.set();
797 this->AllowedUserModes[*c - 'A'] = true;
801 for (unsigned char* c = (unsigned char*)iter_operclass->second.cmodelist; *c; ++c)
805 this->AllowedChanModes.set();
809 this->AllowedChanModes[*c - 'A'] = true;
816 FOREACH_MOD(I_OnPostOper,OnPostOper(this, opertype, opername));
824 * unset their oper type (what IS_OPER checks).
825 * note, order is important - this must come before modes as -o attempts
826 * to call UnOper. -- w00t
831 /* Remove all oper only modes from the user when the deoper - Bug #466*/
832 std::string moderemove("-");
834 for (unsigned char letter = 'A'; letter <= 'z'; letter++)
836 ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_USER);
837 if (mh && mh->NeedsOper())
838 moderemove += letter;
842 std::vector<std::string> parameters;
843 parameters.push_back(this->nick);
844 parameters.push_back(moderemove);
846 ServerInstance->Parser->CallHandler("MODE", parameters, this);
848 /* remove the user from the oper list. Will remove multiple entries as a safeguard against bug #404 */
849 ServerInstance->Users->all_opers.remove(this);
851 if (AllowedOperCommands)
853 delete AllowedOperCommands;
854 AllowedOperCommands = NULL;
863 AllowedUserModes.reset();
864 AllowedChanModes.reset();
865 this->modes[UM_OPERATOR] = 0;
869 /* adds or updates an entry in the whowas list */
870 void User::AddToWhoWas()
872 Command* whowas_command = ServerInstance->Parser->GetHandler("WHOWAS");
875 std::deque<classbase*> params;
876 params.push_back(this);
877 whowas_command->HandleInternal(WHOWAS_ADD, params);
882 * Check class restrictions
884 void User::CheckClass()
886 ConnectClass* a = this->MyClass;
888 if ((!a) || (a->type == CC_DENY))
890 ServerInstance->Users->QuitUser(this, "Unauthorised connection");
893 else if ((a->GetMaxLocal()) && (ServerInstance->Users->LocalCloneCount(this) > a->GetMaxLocal()))
895 ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (local)");
896 ServerInstance->SNO->WriteToSnoMask('a', "WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString());
899 else if ((a->GetMaxGlobal()) && (ServerInstance->Users->GlobalCloneCount(this) > a->GetMaxGlobal()))
901 ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (global)");
902 ServerInstance->SNO->WriteToSnoMask('a', "WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString());
906 this->nping = ServerInstance->Time() + a->GetPingTime() + ServerInstance->Config->dns_timeout;
909 bool User::CheckLines(bool doZline)
911 const char* check[] = { "G" , "K", (doZline) ? "Z" : NULL, NULL };
915 for (int n = 0; check[n]; ++n)
917 XLine *r = ServerInstance->XLines->MatchesLine(check[n], this);
930 void User::FullConnect()
932 ServerInstance->stats->statsConnects++;
933 this->idle_lastmsg = ServerInstance->Time();
936 * You may be thinking "wtf, we checked this in User::AddClient!" - and yes, we did, BUT.
937 * At the time AddClient is called, we don't have a resolved host, by here we probably do - which
938 * may put the user into a totally seperate class with different restrictions! so we *must* check again.
939 * Don't remove this! -- w00t
943 /* Check the password, if one is required by the user's connect class.
944 * This CANNOT be in CheckClass(), because that is called prior to PASS as well!
946 if (this->MyClass && !this->MyClass->GetPass().empty() && !this->haspassed)
948 ServerInstance->Users->QuitUser(this, "Invalid password");
952 if (this->CheckLines())
955 this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network);
956 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());
957 this->WriteNumeric(RPL_YOURHOSTIS, "%s :Your host is %s, running version InspIRCd-1.2",this->nick.c_str(),ServerInstance->Config->ServerName);
958 this->WriteNumeric(RPL_SERVERCREATED, "%s :This server was created %s %s", this->nick.c_str(), __TIME__, __DATE__);
959 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());
961 ServerInstance->Config->Send005(this);
962 this->WriteNumeric(RPL_YOURUUID, "%s %s :your unique ID", this->nick.c_str(), this->uuid.c_str());
968 if (ServerInstance->Users->unregistered_count)
969 ServerInstance->Users->unregistered_count--;
971 /* Trigger LUSERS output, give modules a chance too */
973 std::string command("LUSERS");
974 std::vector<std::string> parameters;
975 FOREACH_RESULT(I_OnPreCommand, OnPreCommand(command, parameters, this, true, "LUSERS"));
977 ServerInstance->CallCommandHandler(command, parameters, this);
980 * We don't set REG_ALL until triggering OnUserConnect, so some module events don't spew out stuff
981 * for a user that doesn't exist yet.
983 FOREACH_MOD(I_OnUserConnect,OnUserConnect(this));
985 this->registered = REG_ALL;
987 ServerInstance->PI->Introduce(this);
989 FOREACH_MOD(I_OnPostConnect,OnPostConnect(this));
991 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());
992 ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCache: Adding NEGATIVE hit for %s", this->GetIPString());
993 ServerInstance->BanCache->AddHit(this->GetIPString(), "", "");
996 /** User::UpdateNick()
997 * re-allocates a nick in the user_hash after they change nicknames,
998 * returns a pointer to the new user as it may have moved
1000 User* User::UpdateNickHash(const char* New)
1002 //user_hash::iterator newnick;
1003 user_hash::iterator oldnick = ServerInstance->Users->clientlist->find(this->nick);
1005 if (!irc::string(this->nick.c_str()).compare(New))
1006 return oldnick->second;
1008 if (oldnick == ServerInstance->Users->clientlist->end())
1009 return NULL; /* doesnt exist */
1011 User* olduser = oldnick->second;
1012 ServerInstance->Users->clientlist->erase(oldnick);
1013 (*(ServerInstance->Users->clientlist))[New] = olduser;
1017 void User::InvalidateCache()
1019 /* Invalidate cache */
1020 cached_fullhost.clear();
1021 cached_hostip.clear();
1022 cached_makehost.clear();
1023 cached_fullrealhost.clear();
1026 bool User::ForceNickChange(const char* newnick)
1030 this->InvalidateCache();
1032 this->Extend("NICKForced", "Enabled");
1034 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(this, newnick));
1036 this->Shrink("NICKForced");
1040 ServerInstance->stats->statsCollisions++;
1044 std::deque<classbase*> dummy;
1045 Command* nickhandler = ServerInstance->Parser->GetHandler("NICK");
1046 if (nickhandler) // wtfbbq, when would this not be here
1048 std::vector<std::string> parameters;
1049 nickhandler->HandleInternal(1, dummy);
1050 parameters.push_back(newnick);
1051 this->Extend("NICKForced", "Enabled");
1052 bool result = (ServerInstance->Parser->CallHandler("NICK", parameters, this) == CMD_SUCCESS);
1053 this->Shrink("NICKForced");
1054 nickhandler->HandleInternal(0, dummy);
1058 // Unreachable, we hope
1062 void User::SetSockAddr(const char* sip, int port)
1064 this->cachedip = "";
1066 if (inet_pton(AF_INET, sip, &ip.in4.sin_addr))
1068 ip.in4.sin_family = AF_INET;
1069 ip.in4.sin_port = port;
1072 else if (inet_pton(AF_INET6, sip, &ip.in6.sin6_addr))
1074 ip.in6.sin6_family = AF_INET6;
1075 ip.in6.sin6_port = port;
1079 ServerInstance->Logs->Log("USERS",DEBUG,"Uh oh, I dont know how to read IP '%s' on '%s'!",
1080 sip, this->nick.c_str());
1086 switch (this->ip.sa.sa_family)
1089 return this->ip.in6.sin6_port;
1091 return this->ip.in4.sin_port;
1096 const char* User::GetCIDRMask(int range)
1098 static char buf[44];
1101 throw "Negative range, sorry, no.";
1104 * Original code written by Oliver Lupton (Om).
1105 * Integrated by me. Thanks. :) -- w00t
1107 switch (this->ip.sa.sa_family)
1111 /* unsigned char s6_addr[16]; */
1113 int i, bytestozero, extrabits;
1117 throw "CIDR mask width greater than address width (IPv6, 128 bit)";
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] = ip.in6.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);
1159 throw "CIDR mask width greater than address width (IPv4, 32 bit)";
1161 /* Users already have a sockaddr* pointer (User::ip) which contains either a v4 or v6 structure */
1162 v4.s_addr = ip.in4.sin_addr.s_addr;
1164 /* To create the CIDR mask we want to set all the bits after 'range' bits of the address
1165 * to zero. This means the last (32 - range) bits of the address must be set to zero.
1166 * This is done by shifting the value right and then back left by (32 - range) bits.
1170 v4.s_addr = ntohl(v4.s_addr);
1171 v4.s_addr = (v4.s_addr >> (32 - range)) << (32 - range);
1172 v4.s_addr = htonl(v4.s_addr);
1176 /* a range of zero would cause a 32 bit value to be shifted by 32 bits.
1177 * this has undefined behaviour, but for CIDR purposes the resulting mask
1178 * from a.b.c.d/0 is 0.0.0.0/0
1183 snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET, &v4, buffer, 16), range);
1189 return ""; // unused, but oh well
1192 const char* User::GetIPString()
1194 static char buf[40];
1196 if (!this->cachedip.empty())
1197 return this->cachedip.c_str();
1199 switch (this->ip.sa.sa_family)
1203 static char temp[41];
1205 inet_ntop(ip.in6.sin6_family, &ip.in6.sin6_addr, buf, sizeof(buf));
1206 /* IP addresses starting with a : on irc are a Bad Thing (tm) */
1209 strlcpy(&temp[1], buf, sizeof(temp) - 1);
1211 this->cachedip = temp;
1215 this->cachedip = buf;
1221 inet_ntop(ip.in4.sin_family, &ip.in4.sin_addr, buf, sizeof(buf));
1222 this->cachedip = buf;
1230 // Unreachable, probably
1234 /** NOTE: We cannot pass a const reference to this method.
1235 * The string is changed by the workings of the method,
1236 * so that if we pass const ref, we end up copying it to
1237 * something we can change anyway. Makes sense to just let
1238 * the compiler do that copy for us.
1240 void User::Write(std::string text)
1242 if (!ServerInstance->SE->BoundsCheckFd(this))
1247 ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"C[%d] O %s", this->GetFd(), text.c_str());
1248 text.append("\r\n");
1252 ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"Exception in User::Write() std::string::append");
1256 if (this->GetIOHook())
1258 /* XXX: The lack of buffering here is NOT a bug, modules implementing this interface have to
1259 * implement their own buffering mechanisms
1263 this->GetIOHook()->OnRawSocketWrite(this->fd, text.data(), text.length());
1265 catch (CoreException& modexcept)
1267 ServerInstance->Logs->Log("USEROUTPUT", DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
1272 this->AddWriteBuf(text);
1274 ServerInstance->stats->statsSent += text.length();
1275 this->ServerInstance->SE->WantWrite(this);
1280 void User::Write(const char *text, ...)
1283 char textbuffer[MAXBUF];
1285 va_start(argsPtr, text);
1286 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1289 this->Write(std::string(textbuffer));
1292 void User::WriteServ(const std::string& text)
1294 char textbuffer[MAXBUF];
1296 snprintf(textbuffer,MAXBUF,":%s %s",ServerInstance->Config->ServerName,text.c_str());
1297 this->Write(std::string(textbuffer));
1301 * Same as Write(), except `text' is prefixed with `:server.name '.
1303 void User::WriteServ(const char* text, ...)
1306 char textbuffer[MAXBUF];
1308 va_start(argsPtr, text);
1309 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1312 this->WriteServ(std::string(textbuffer));
1316 void User::WriteNumeric(unsigned int numeric, const char* text, ...)
1319 char textbuffer[MAXBUF];
1321 va_start(argsPtr, text);
1322 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1325 this->WriteNumeric(numeric, std::string(textbuffer));
1328 void User::WriteNumeric(unsigned int numeric, const std::string &text)
1330 char textbuffer[MAXBUF];
1333 FOREACH_RESULT(I_OnNumeric, OnNumeric(this, numeric, text));
1338 snprintf(textbuffer,MAXBUF,":%s %03u %s",ServerInstance->Config->ServerName, numeric, text.c_str());
1339 this->Write(std::string(textbuffer));
1342 void User::WriteFrom(User *user, const std::string &text)
1346 snprintf(tb,MAXBUF,":%s %s",user->GetFullHost().c_str(),text.c_str());
1348 this->Write(std::string(tb));
1352 /* write text from an originating user to originating user */
1354 void User::WriteFrom(User *user, const char* text, ...)
1357 char textbuffer[MAXBUF];
1359 va_start(argsPtr, text);
1360 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1363 this->WriteFrom(user, std::string(textbuffer));
1367 /* write text to an destination user from a source user (e.g. user privmsg) */
1369 void User::WriteTo(User *dest, const char *data, ...)
1371 char textbuffer[MAXBUF];
1374 va_start(argsPtr, data);
1375 vsnprintf(textbuffer, MAXBUF, data, argsPtr);
1378 this->WriteTo(dest, std::string(textbuffer));
1381 void User::WriteTo(User *dest, const std::string &data)
1383 dest->WriteFrom(this, data);
1387 void User::WriteCommon(const char* text, ...)
1389 char textbuffer[MAXBUF];
1392 if (this->registered != REG_ALL)
1395 va_start(argsPtr, text);
1396 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1399 this->WriteCommon(std::string(textbuffer));
1402 void User::WriteCommon(const std::string &text)
1404 bool sent_to_at_least_one = false;
1407 if (this->registered != REG_ALL)
1413 InitializeAlreadySent(ServerInstance->SE);
1415 /* We dont want to be doing this n times, just once */
1416 snprintf(tb,MAXBUF,":%s %s",this->GetFullHost().c_str(),text.c_str());
1417 std::string out = tb;
1419 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1421 CUList* ulist = v->first->GetUsers();
1422 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1424 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1426 already_sent[i->first->fd] = uniq_id;
1427 i->first->Write(out);
1428 sent_to_at_least_one = true;
1434 * if the user was not in any channels, no users will receive the text. Make sure the user
1435 * receives their OWN message for WriteCommon
1437 if (!sent_to_at_least_one)
1439 this->Write(std::string(tb));
1444 /* write a formatted string to all users who share at least one common
1445 * channel, NOT including the source user e.g. for use in QUIT
1448 void User::WriteCommonExcept(const char* text, ...)
1450 char textbuffer[MAXBUF];
1453 va_start(argsPtr, text);
1454 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1457 this->WriteCommonExcept(std::string(textbuffer));
1460 void User::WriteCommonQuit(const std::string &normal_text, const std::string &oper_text)
1465 if (this->registered != REG_ALL)
1471 InitializeAlreadySent(ServerInstance->SE);
1473 snprintf(tb1,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),normal_text.c_str());
1474 snprintf(tb2,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),oper_text.c_str());
1475 std::string out1 = tb1;
1476 std::string out2 = tb2;
1478 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1480 CUList *ulist = v->first->GetUsers();
1481 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1483 if (this != i->first)
1485 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1487 already_sent[i->first->fd] = uniq_id;
1488 i->first->Write(IS_OPER(i->first) ? out2 : out1);
1495 void User::WriteCommonExcept(const std::string &text)
1500 if (this->registered != REG_ALL)
1506 InitializeAlreadySent(ServerInstance->SE);
1508 snprintf(tb1,MAXBUF,":%s %s",this->GetFullHost().c_str(),text.c_str());
1511 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1513 CUList *ulist = v->first->GetUsers();
1514 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1516 if (this != i->first)
1518 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1520 already_sent[i->first->fd] = uniq_id;
1521 i->first->Write(out1);
1529 void User::WriteWallOps(const std::string &text)
1531 std::string wallop("WALLOPS :");
1532 wallop.append(text);
1534 for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
1537 if (t->IsModeSet('w'))
1538 this->WriteTo(t,wallop);
1542 void User::WriteWallOps(const char* text, ...)
1544 if (!IS_LOCAL(this))
1547 char textbuffer[MAXBUF];
1550 va_start(argsPtr, text);
1551 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1554 this->WriteWallOps(std::string(textbuffer));
1557 /* return 0 or 1 depending if users u and u2 share one or more common channels
1558 * (used by QUIT, NICK etc which arent channel specific notices)
1560 * The old algorithm in 1.0 for this was relatively inefficient, iterating over
1561 * the first users channels then the second users channels within the outer loop,
1562 * therefore it was a maximum of x*y iterations (upon returning 0 and checking
1563 * all possible iterations). However this new function instead checks against the
1564 * channel's userlist in the inner loop which is a std::map<User*,User*>
1565 * and saves us time as we already know what pointer value we are after.
1566 * Don't quote me on the maths as i am not a mathematician or computer scientist,
1567 * but i believe this algorithm is now x+(log y) maximum iterations instead.
1569 bool User::SharesChannelWith(User *other)
1571 if ((!other) || (this->registered != REG_ALL) || (other->registered != REG_ALL))
1575 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1577 /* Eliminate the inner loop (which used to be ~equal in size to the outer loop)
1578 * by replacing it with a map::find which *should* be more efficient
1580 if (i->first->HasUser(other))
1586 bool User::ChangeName(const char* gecos)
1588 if (!this->fullname.compare(gecos))
1594 FOREACH_RESULT(I_OnChangeLocalUserGECOS,OnChangeLocalUserGECOS(this,gecos));
1597 FOREACH_MOD(I_OnChangeName,OnChangeName(this,gecos));
1599 this->fullname.assign(gecos, 0, ServerInstance->Config->Limits.MaxGecos);
1604 bool User::ChangeDisplayedHost(const char* shost)
1612 FOREACH_RESULT(I_OnChangeLocalUserHost,OnChangeLocalUserHost(this,shost));
1617 FOREACH_MOD(I_OnChangeHost, OnChangeHost(this,shost));
1620 FOREACH_RESULT(I_OnHostCycle, OnHostCycle(this));
1622 if (this->ServerInstance->Config->CycleHosts && !MOD_RESULT)
1623 this->WriteCommonExcept("QUIT :Changing hosts");
1625 /* Fix by Om: User::dhost is 65 long, this was truncating some long hosts */
1626 this->dhost.assign(shost, 0, 64);
1628 this->InvalidateCache();
1630 if (this->ServerInstance->Config->CycleHosts && !MOD_RESULT)
1632 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1634 i->first->WriteAllExceptSender(this, false, 0, "JOIN %s", i->first->name.c_str());
1635 std::string n = this->ServerInstance->Modes->ModeString(this, i->first);
1637 i->first->WriteAllExceptSender(this, true, 0, "MODE %s +%s", i->first->name.c_str(), n.c_str());
1642 this->WriteNumeric(RPL_YOURDISPLAYEDHOST, "%s %s :is now your displayed host",this->nick.c_str(),this->dhost.c_str());
1647 bool User::ChangeIdent(const char* newident)
1649 if (this->ident == newident)
1653 FOREACH_RESULT(I_OnHostCycle, OnHostCycle(this));
1655 if (this->ServerInstance->Config->CycleHosts && !MOD_RESULT)
1656 this->WriteCommonExcept("%s","QUIT :Changing ident");
1658 this->ident.assign(newident, 0, ServerInstance->Config->Limits.IdentMax + 1);
1660 this->InvalidateCache();
1662 if (this->ServerInstance->Config->CycleHosts && !MOD_RESULT)
1664 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1666 i->first->WriteAllExceptSender(this, false, 0, "JOIN %s", i->first->name.c_str());
1667 std::string n = this->ServerInstance->Modes->ModeString(this, i->first);
1669 i->first->WriteAllExceptSender(this, true, 0, "MODE %s +%s", i->first->name.c_str(), n.c_str());
1676 void User::SendAll(const char* command, const char* text, ...)
1678 char textbuffer[MAXBUF];
1679 char formatbuffer[MAXBUF];
1682 va_start(argsPtr, text);
1683 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1686 snprintf(formatbuffer,MAXBUF,":%s %s $* :%s", this->GetFullHost().c_str(), command, textbuffer);
1687 std::string fmt = formatbuffer;
1689 for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
1696 std::string User::ChannelList(User* source)
1700 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1702 /* If the target is the same as the sender, let them see all their channels.
1703 * If the channel is NOT private/secret OR the user shares a common channel
1704 * If the user is an oper, and the <options:operspywhois> option is set.
1706 if ((source == this) || (IS_OPER(source) && ServerInstance->Config->OperSpyWhois) || (((!i->first->IsModeSet('p')) && (!i->first->IsModeSet('s'))) || (i->first->HasUser(source))))
1708 list.append(i->first->GetPrefixChar(this)).append(i->first->name).append(" ");
1715 void User::SplitChanList(User* dest, const std::string &cl)
1718 std::ostringstream prefix;
1719 std::string::size_type start, pos, length;
1721 prefix << this->nick << " " << dest->nick << " :";
1722 line = prefix.str();
1723 int namelen = strlen(ServerInstance->Config->ServerName) + 6;
1725 for (start = 0; (pos = cl.find(' ', start)) != std::string::npos; start = pos+1)
1727 length = (pos == std::string::npos) ? cl.length() : pos;
1729 if (line.length() + namelen + length - start > 510)
1731 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1732 line = prefix.str();
1735 if(pos == std::string::npos)
1737 line.append(cl.substr(start, length - start));
1742 line.append(cl.substr(start, length - start + 1));
1748 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1753 * Sets a user's connection class.
1754 * If the class name is provided, it will be used. Otherwise, the class will be guessed using host/ip/ident/etc.
1755 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1756 * then their ip will be taken as 'priority' anyway, so for example,
1757 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1759 ConnectClass* User::SetClass(const std::string &explicit_name)
1761 ConnectClass *found = NULL;
1763 if (!IS_LOCAL(this))
1766 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Setting connect class for UID %s", this->uuid.c_str());
1768 if (!explicit_name.empty())
1770 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1772 ConnectClass* c = *i;
1774 if (explicit_name == c->name)
1776 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Explicitly set to %s", explicit_name.c_str());
1783 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1785 ConnectClass* c = *i;
1787 if (c->type == CC_ALLOW)
1789 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "ALLOW %s %d %s", c->host.c_str(), c->GetPort(), c->GetName().c_str());
1793 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "DENY %s %d %s", c->GetHost().c_str(), c->GetPort(), c->GetName().c_str());
1796 /* check if host matches.. */
1797 if (c->GetHost().length() && !InspIRCd::MatchCIDR(this->GetIPString(), c->GetHost(), NULL) &&
1798 !InspIRCd::MatchCIDR(this->host, c->GetHost(), NULL))
1800 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "No host match (for %s)", c->GetHost().c_str());
1805 * deny change if change will take class over the limit check it HERE, not after we found a matching class,
1806 * because we should attempt to find another class if this one doesn't match us. -- w00t
1808 if (c->limit && (c->RefCount >= c->limit))
1810 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "OOPS: Connect class limit (%lu) hit, denying", c->limit);
1814 /* if it requires a port ... */
1817 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Requires port (%d)", c->GetPort());
1819 /* and our port doesn't match, fail. */
1820 if (this->GetPort() != c->GetPort())
1822 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Port match failed (%d)", this->GetPort());
1827 /* we stop at the first class that meets ALL critera. */
1834 * Okay, assuming we found a class that matches.. switch us into that class, keeping refcounts up to date.
1838 /* only fiddle with refcounts if they are already in a class .. */
1841 if (found == this->MyClass) // no point changing this shit :P
1842 return this->MyClass;
1843 this->MyClass->RefCount--;
1844 ServerInstance->Logs->Log("USERS", DEBUG, "Untying user from connect class -- refcount: %lu", this->MyClass->RefCount);
1845 if (MyClass->RefCount == 0)
1849 this->MyClass = found;
1850 this->MyClass->RefCount++;
1851 ServerInstance->Logs->Log("USERS", DEBUG, "User tied to new class -- connect refcount now: %lu", this->MyClass->RefCount);
1854 return this->MyClass;
1857 /* looks up a users password for their connection class (<ALLOW>/<DENY> tags)
1858 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1859 * then their ip will be taken as 'priority' anyway, so for example,
1860 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1862 ConnectClass* User::GetClass()
1864 return this->MyClass;
1867 void User::PurgeEmptyChannels()
1869 std::vector<Channel*> to_delete;
1871 // firstly decrement the count on each channel
1872 for (UCListIter f = this->chans.begin(); f != this->chans.end(); f++)
1874 f->first->RemoveAllPrefixes(this);
1875 if (f->first->DelUser(this) == 0)
1877 /* No users left in here, mark it for deletion */
1880 to_delete.push_back(f->first);
1884 ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::PurgeEmptyChannels to_delete.push_back()");
1889 for (std::vector<Channel*>::iterator n = to_delete.begin(); n != to_delete.end(); n++)
1891 Channel* thischan = *n;
1892 chan_hash::iterator i2 = ServerInstance->chanlist->find(thischan->name);
1893 if (i2 != ServerInstance->chanlist->end())
1896 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(i2->second));
1897 if (MOD_RESULT == 1)
1898 continue; // delete halted by module
1899 FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(i2->second));
1901 ServerInstance->chanlist->erase(i2);
1902 this->chans.erase(*n);
1909 void User::ShowMOTD()
1911 if (!ServerInstance->Config->MOTD.size())
1913 this->WriteNumeric(ERR_NOMOTD, "%s :Message of the day file is missing.",this->nick.c_str());
1916 this->WriteNumeric(RPL_MOTDSTART, "%s :%s message of the day", this->nick.c_str(), ServerInstance->Config->ServerName);
1918 for (file_cache::iterator i = ServerInstance->Config->MOTD.begin(); i != ServerInstance->Config->MOTD.end(); i++)
1919 this->WriteNumeric(RPL_MOTD, "%s :- %s",this->nick.c_str(),i->c_str());
1921 this->WriteNumeric(RPL_ENDOFMOTD, "%s :End of message of the day.", this->nick.c_str());
1924 void User::ShowRULES()
1926 if (!ServerInstance->Config->RULES.size())
1928 this->WriteNumeric(ERR_NORULES, "%s :RULES File is missing",this->nick.c_str());
1932 this->WriteNumeric(RPL_RULESTART, "%s :- %s Server Rules -",this->nick.c_str(),ServerInstance->Config->ServerName);
1934 for (file_cache::iterator i = ServerInstance->Config->RULES.begin(); i != ServerInstance->Config->RULES.end(); i++)
1935 this->WriteNumeric(RPL_RULES, "%s :- %s",this->nick.c_str(),i->c_str());
1937 this->WriteNumeric(RPL_RULESEND, "%s :End of RULES command.",this->nick.c_str());
1940 void User::HandleEvent(EventType et, int errornum)
1942 if (this->quitting) // drop everything, user is due to be quit
1948 ServerInstance->ProcessUser(this);
1951 this->FlushWriteBuf();
1954 ServerInstance->Users->QuitUser(this, errornum ? strerror(errornum) : "Client closed the connection");
1959 void User::SetOperQuit(const std::string &oquit)
1961 operquitmsg = oquit;
1964 const std::string& User::GetOperQuit()
1969 void User::IncreasePenalty(int increase)
1971 this->Penalty += increase;
1974 void User::DecreasePenalty(int decrease)
1976 this->Penalty -= decrease;
1979 void FakeUser::SetFakeServer(std::string name)
1982 this->server = nick.c_str();
1985 const std::string FakeUser::GetFullHost()
1987 if (*ServerInstance->Config->HideWhoisServer)
1988 return ServerInstance->Config->HideWhoisServer;
1992 const std::string FakeUser::GetFullRealHost()
1994 if (*ServerInstance->Config->HideWhoisServer)
1995 return ServerInstance->Config->HideWhoisServer;
2007 bool VisData::VisibleTo(User* user)
2013 ConnectClass::ConnectClass(char t, const std::string& mask)
2014 : type(t), name("unnamed"), registration_timeout(0), host(mask), pingtime(0), pass(""), hash(""), sendqmax(0), recvqmax(0), maxlocal(0), maxglobal(0), maxchans(0), port(0), limit(0), RefCount(1)
2018 ConnectClass::ConnectClass(char t, const std::string& mask, const ConnectClass& parent)
2019 : type(t), name("unnamed"), registration_timeout(parent.registration_timeout), host(mask), pingtime(parent.pingtime), pass(parent.pass), hash(parent.hash), sendqmax(parent.sendqmax), recvqmax(parent.recvqmax), maxlocal(parent.maxlocal), maxglobal(parent.maxglobal), maxchans(parent.maxchans), port(parent.port), limit(parent.limit), RefCount(1)
2023 void ConnectClass::Update(const ConnectClass* src)
2026 registration_timeout = src->registration_timeout;
2028 pingtime = src->pingtime;
2031 sendqmax = src->sendqmax;
2032 recvqmax = src->recvqmax;
2033 maxlocal = src->maxlocal;
2034 maxglobal = src->maxglobal;