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 = strchr(sip, ':') ? DNS_QUERY_PTR6 : DNS_QUERY_PTR4;
111 // when GetProtocolFamily() works correctly with 4in6, this can be replaced by
112 // this->GetProtocolFamily() == AF_INET ? DNS_QUERY_PTR4 : DNS_QUERY_PTR6;
113 res_reverse = new UserResolver(this->ServerInstance, this, sip, resolvtype, cached);
115 this->ServerInstance->AddResolver(res_reverse, cached);
117 catch (CoreException& e)
119 ServerInstance->Logs->Log("USERS", DEBUG,"Error in resolver: %s",e.GetReason());
123 bool User::IsNoticeMaskSet(unsigned char sm)
127 return (snomasks[sm-65]);
130 void User::SetNoticeMask(unsigned char sm, bool value)
134 snomasks[sm-65] = value;
137 const char* User::FormatNoticeMasks()
139 static char data[MAXBUF];
142 for (int n = 0; n < 64; n++)
145 data[offset++] = n+65;
152 bool User::IsModeSet(unsigned char m)
156 return (modes[m-65]);
159 void User::SetMode(unsigned char m, bool value)
166 const char* User::FormatModes(bool showparameters)
168 static char data[MAXBUF];
172 for (unsigned char n = 0; n < 64; n++)
176 data[offset++] = n + 65;
177 ModeHandler* mh = ServerInstance->Modes->FindMode(n + 65, MODETYPE_USER);
178 if (showparameters && mh && mh->GetNumParams(true))
180 std::string p = mh->GetUserParameter(this);
182 params.append(" ").append(p);
187 strlcat(data, params.c_str(), MAXBUF);
191 void User::DecrementModes()
193 ServerInstance->Logs->Log("USERS", DEBUG, "DecrementModes()");
194 for (unsigned char n = 'A'; n <= 'z'; n++)
198 ServerInstance->Logs->Log("USERS", DEBUG,"DecrementModes() found mode %c", n);
199 ModeHandler* mh = ServerInstance->Modes->FindMode(n, MODETYPE_USER);
202 ServerInstance->Logs->Log("USERS", DEBUG,"Found handler %c and call ChangeCount", n);
209 User::User(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance)
211 server = (char*)Instance->FindServerNamePtr(Instance->Config->ServerName);
212 age = ServerInstance->Time();
214 lastping = signon = idle_lastmsg = nping = registered = 0;
215 bytes_in = bytes_out = cmds_in = cmds_out = 0;
216 quietquit = quitting = exempt = haspassed = dns_done = false;
223 AllowedPrivs = AllowedOperCommands = NULL;
228 uuid.assign(Instance->GetUID(), 0, UUID_LENGTH - 1);
230 uuid.assign(uid, 0, UUID_LENGTH - 1);
232 ServerInstance->Logs->Log("USERS", DEBUG,"New UUID for user: %s (%s)", uuid.c_str(), uid.empty() ? "allocated new" : "used remote");
234 user_hash::iterator finduuid = Instance->Users->uuidlist->find(uuid);
235 if (finduuid == Instance->Users->uuidlist->end())
236 (*Instance->Users->uuidlist)[uuid] = this;
238 throw CoreException("Duplicate UUID "+std::string(uuid)+" in User constructor");
243 /* NULL for remote users :) */
246 this->MyClass->RefCount--;
247 ServerInstance->Logs->Log("USERS", DEBUG, "User destructor -- connect refcount now: %lu", this->MyClass->RefCount);
248 if (MyClass->RefCount == 0)
252 if (this->AllowedOperCommands)
254 delete AllowedOperCommands;
255 AllowedOperCommands = NULL;
258 if (this->AllowedPrivs)
264 this->InvalidateCache();
265 this->DecrementModes();
269 ServerInstance->Users->RemoveCloneCounts(this);
271 if (this->GetProtocolFamily() == AF_INET)
273 delete (sockaddr_in*)ip;
275 #ifdef SUPPORT_IP6LINKS
278 delete (sockaddr_in6*)ip;
283 ServerInstance->Users->uuidlist->erase(uuid);
286 const std::string& User::MakeHost()
288 if (!this->cached_makehost.empty())
289 return this->cached_makehost;
292 /* This is much faster than snprintf */
294 for(const char* n = ident.c_str(); *n; n++)
297 for(const char* n = host.c_str(); *n; n++)
301 this->cached_makehost.assign(nhost);
303 return this->cached_makehost;
306 const std::string& User::MakeHostIP()
308 if (!this->cached_hostip.empty())
309 return this->cached_hostip;
312 /* This is much faster than snprintf */
314 for(const char* n = ident.c_str(); *n; n++)
317 for(const char* n = this->GetIPString(); *n; n++)
321 this->cached_hostip = ihost;
323 return this->cached_hostip;
326 void User::CloseSocket()
330 ServerInstance->SE->Shutdown(this, 2);
331 ServerInstance->SE->Close(this);
335 const std::string User::GetFullHost()
337 if (!this->cached_fullhost.empty())
338 return this->cached_fullhost;
342 for(const char* n = nick.c_str(); *n; n++)
345 for(const char* n = ident.c_str(); *n; n++)
348 for(const char* n = dhost.c_str(); *n; n++)
352 this->cached_fullhost = result;
354 return this->cached_fullhost;
357 char* User::MakeWildHost()
359 static char nresult[MAXBUF];
361 *t++ = '*'; *t++ = '!';
362 *t++ = '*'; *t++ = '@';
363 for(const char* n = dhost.c_str(); *n; n++)
369 int User::ReadData(void* buffer, size_t size)
374 return read(this->fd, buffer, size);
376 return recv(this->fd, (char*)buffer, size, 0);
384 const std::string User::GetFullRealHost()
386 if (!this->cached_fullrealhost.empty())
387 return this->cached_fullrealhost;
389 char fresult[MAXBUF];
391 for(const char* n = nick.c_str(); *n; n++)
394 for(const char* n = ident.c_str(); *n; n++)
397 for(const char* n = host.c_str(); *n; n++)
401 this->cached_fullrealhost = fresult;
403 return this->cached_fullrealhost;
406 bool User::IsInvited(const irc::string &channel)
408 time_t now = ServerInstance->Time();
409 InvitedList::iterator safei;
410 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
412 if (channel == i->first)
414 if (i->second != 0 && now > i->second)
416 /* Expired invite, remove it. */
419 invites.erase(safei);
428 InvitedList* User::GetInviteList()
430 time_t now = ServerInstance->Time();
431 /* Weed out expired invites here. */
432 InvitedList::iterator safei;
433 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
435 if (i->second != 0 && now > i->second)
437 /* Expired invite, remove it. */
440 invites.erase(safei);
446 void User::InviteTo(const irc::string &channel, time_t invtimeout)
448 time_t now = ServerInstance->Time();
449 if (invtimeout != 0 && now > invtimeout) return; /* Don't add invites that are expired from the get-go. */
450 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
452 if (channel == i->first)
454 if (i->second != 0 && invtimeout > i->second)
456 i->second = invtimeout;
462 invites.push_back(std::make_pair(channel, invtimeout));
465 void User::RemoveInvite(const irc::string &channel)
467 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
469 if (channel == i->first)
477 bool User::HasModePermission(unsigned char mode, ModeType type)
485 if (mode < 'A' || mode > ('A' + 64)) return false;
487 return ((type == MODETYPE_USER ? AllowedUserModes : AllowedChanModes))[(mode - 'A')];
491 bool User::HasPermission(const std::string &command)
494 * users on remote servers can completely bypass all permissions based checks.
495 * This prevents desyncs when one server has different type/class tags to another.
496 * That having been said, this does open things up to the possibility of source changes
497 * allowing remote kills, etc - but if they have access to the src, they most likely have
498 * access to the conf - so it's an end to a means either way.
503 // are they even an oper at all?
509 if (!AllowedOperCommands)
512 if (AllowedOperCommands->find(command) != AllowedOperCommands->end())
514 else if (AllowedOperCommands->find("*") != AllowedOperCommands->end())
521 bool User::HasPrivPermission(const std::string &privstr, bool noisy)
525 ServerInstance->Logs->Log("PRIVS", DEBUG, "Remote (yes)");
532 this->WriteServ("NOTICE %s :You are not an oper", this->nick.c_str());
539 this->WriteServ("NOTICE %s :Privset empty(!?)", this->nick.c_str());
543 if (AllowedPrivs->find(privstr) != AllowedPrivs->end())
547 else if (AllowedPrivs->find("*") != AllowedPrivs->end())
553 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());
557 bool User::AddBuffer(const std::string &a)
559 std::string::size_type start = 0;
560 std::string::size_type i = a.find('\r');
563 * The old implementation here took a copy, and rfind() on \r, removing as it found them, before
564 * copying a second time onto the recvq. That's ok, but involves three copies minimum (recv() to buffer,
565 * buffer to here, here to recvq) - The new method now copies twice (recv() to buffer, buffer to recvq).
567 * We use find() instead of rfind() for clarity, however unlike the old code, our scanning of the string is
568 * contiguous: as we specify a startpoint, we never see characters we have scanned previously, making this
569 * marginally faster in cases with a number of \r hidden early on in the buffer.
572 * Start at first pos of string, find first \r, append everything in the chunk (excluding \r) to recvq. Set
573 * i ahead of the \r, search for next \r, add next chunk to buffer... repeat.
574 * -- w00t (7 may, 2008)
576 if (i == std::string::npos)
578 // no \r that we need to dance around, just add to buffer
583 // While we can find the end of a chunk to add
584 while (i != std::string::npos)
586 // Append the chunk that we have
587 recvq.append(a, start, (i - start));
589 // Start looking for the next one
591 i = a.find('\r', start);
594 if (start != a.length())
597 * This is here to catch a corner case when we get something like:
601 * in successive calls to us.
603 * Without this conditional, the 'U' on the second case will be dropped,
604 * which is most *certainly* not the behaviour we want!
607 recvq.append(a, start, (a.length() - start));
611 if (this->MyClass && !this->HasPrivPermission("users/flood/increased-buffers") && recvq.length() > this->MyClass->GetRecvqMax())
613 ServerInstance->Users->QuitUser(this, "RecvQ exceeded");
614 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());
621 bool User::BufferIsReady()
623 return (recvq.find('\n') != std::string::npos);
626 void User::ClearBuffer()
631 std::string User::GetBuffer()
638 /* Strip any leading \r or \n off the string.
639 * Usually there are only one or two of these,
640 * so its is computationally cheap to do.
642 std::string::iterator t = recvq.begin();
643 while (t != recvq.end() && (*t == '\r' || *t == '\n'))
649 for (std::string::iterator x = recvq.begin(); x != recvq.end(); x++)
651 /* Find the first complete line, return it as the
652 * result, and leave the recvq as whats left
656 std::string ret = std::string(recvq.begin(), x);
657 recvq.erase(recvq.begin(), x + 1);
666 ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::GetBuffer()");
671 void User::AddWriteBuf(const std::string &data)
673 if (!this->quitting && this->MyClass && !this->HasPrivPermission("users/flood/increased-buffers") && sendq.length() + data.length() > this->MyClass->GetSendqMax())
676 * Fix by brain - Set the error text BEFORE calling, because
677 * if we dont it'll recursively call here over and over again trying
678 * to repeatedly add the text to the sendq!
680 ServerInstance->Users->QuitUser(this, "SendQ exceeded");
681 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());
685 // We still want to append data to the sendq of a quitting user,
686 // e.g. their ERROR message that says 'closing link'
688 if (data.length() > MAXBUF - 2) /* MAXBUF has a value of 514, to account for line terminators */
689 sendq.append(data.substr(0,MAXBUF - 4)).append("\r\n"); /* MAXBUF-4 = 510 */
694 // send AS MUCH OF THE USERS SENDQ as we are able to (might not be all of it)
695 void User::FlushWriteBuf()
697 if (this->fd == FD_MAGIC_NUMBER)
703 if ((sendq.length()) && (this->fd != FD_MAGIC_NUMBER))
705 int old_sendq_length = sendq.length();
706 int n_sent = ServerInstance->SE->Send(this, this->sendq.data(), this->sendq.length(), 0);
712 /* The socket buffer is full. This isnt fatal,
715 ServerInstance->SE->WantWrite(this);
719 /* Fatal error, set write error and bail */
720 ServerInstance->Users->QuitUser(this, errno ? strerror(errno) : "Write error");
726 /* advance the queue */
728 this->sendq = this->sendq.substr(n_sent);
729 /* update the user's stats counters */
730 this->bytes_out += n_sent;
732 if (n_sent != old_sendq_length)
733 this->ServerInstance->SE->WantWrite(this);
737 /* note: NOT else if! */
738 if (this->sendq.empty())
740 FOREACH_MOD(I_OnBufferFlushed,OnBufferFlushed(this));
744 void User::Oper(const std::string &opertype, const std::string &opername)
746 if (this->IsModeSet('o'))
749 this->modes[UM_OPERATOR] = 1;
750 this->WriteServ("MODE %s :+o", this->nick.c_str());
751 FOREACH_MOD(I_OnOper, OnOper(this, opertype));
753 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());
754 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()));
756 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());
757 this->oper.assign(opertype, 0, 512);
758 ServerInstance->Users->all_opers.push_back(this);
761 * This might look like it's in the wrong place.
764 * 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.
767 opertype_t::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper.c_str());
768 if (iter_opertype != ServerInstance->Config->opertypes.end())
770 if (AllowedOperCommands)
771 AllowedOperCommands->clear();
773 AllowedOperCommands = new std::set<std::string>;
776 AllowedPrivs->clear();
778 AllowedPrivs = new std::set<std::string>;
780 AllowedUserModes.reset();
781 AllowedChanModes.reset();
782 this->AllowedUserModes['o' - 'A'] = true; // Call me paranoid if you want.
784 std::string myclass, mycmd, mypriv;
785 irc::spacesepstream Classes(iter_opertype->second.c_str());
786 while (Classes.GetToken(myclass))
788 operclass_t::iterator iter_operclass = ServerInstance->Config->operclass.find(myclass.c_str());
789 if (iter_operclass != ServerInstance->Config->operclass.end())
791 /* Process commands */
792 irc::spacesepstream CommandList(iter_operclass->second.commandlist);
793 while (CommandList.GetToken(mycmd))
795 this->AllowedOperCommands->insert(mycmd);
798 irc::spacesepstream PrivList(iter_operclass->second.privs);
799 while (PrivList.GetToken(mypriv))
801 this->AllowedPrivs->insert(mypriv);
804 for (unsigned char* c = (unsigned char*)iter_operclass->second.umodelist; *c; ++c)
808 this->AllowedUserModes.set();
812 this->AllowedUserModes[*c - 'A'] = true;
816 for (unsigned char* c = (unsigned char*)iter_operclass->second.cmodelist; *c; ++c)
820 this->AllowedChanModes.set();
824 this->AllowedChanModes[*c - 'A'] = true;
831 FOREACH_MOD(I_OnPostOper,OnPostOper(this, opertype, opername));
839 * unset their oper type (what IS_OPER checks).
840 * note, order is important - this must come before modes as -o attempts
841 * to call UnOper. -- w00t
846 /* Remove all oper only modes from the user when the deoper - Bug #466*/
847 std::string moderemove("-");
849 for (unsigned char letter = 'A'; letter <= 'z'; letter++)
851 ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_USER);
852 if (mh && mh->NeedsOper())
853 moderemove += letter;
857 std::vector<std::string> parameters;
858 parameters.push_back(this->nick);
859 parameters.push_back(moderemove);
861 ServerInstance->Parser->CallHandler("MODE", parameters, this);
863 /* remove the user from the oper list. Will remove multiple entries as a safeguard against bug #404 */
864 ServerInstance->Users->all_opers.remove(this);
866 if (AllowedOperCommands)
868 delete AllowedOperCommands;
869 AllowedOperCommands = NULL;
878 AllowedUserModes.reset();
879 AllowedChanModes.reset();
880 this->modes[UM_OPERATOR] = 0;
884 /* adds or updates an entry in the whowas list */
885 void User::AddToWhoWas()
887 Command* whowas_command = ServerInstance->Parser->GetHandler("WHOWAS");
890 std::deque<classbase*> params;
891 params.push_back(this);
892 whowas_command->HandleInternal(WHOWAS_ADD, params);
897 * Check class restrictions
899 void User::CheckClass()
901 ConnectClass* a = this->MyClass;
903 if ((!a) || (a->type == CC_DENY))
905 ServerInstance->Users->QuitUser(this, "Unauthorised connection");
908 else if ((a->GetMaxLocal()) && (ServerInstance->Users->LocalCloneCount(this) > a->GetMaxLocal()))
910 ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (local)");
911 ServerInstance->SNO->WriteToSnoMask('a', "WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString());
914 else if ((a->GetMaxGlobal()) && (ServerInstance->Users->GlobalCloneCount(this) > a->GetMaxGlobal()))
916 ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (global)");
917 ServerInstance->SNO->WriteToSnoMask('a', "WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString());
921 this->nping = ServerInstance->Time() + a->GetPingTime() + ServerInstance->Config->dns_timeout;
924 bool User::CheckLines(bool doZline)
926 const char* check[] = { "G" , "K", (doZline) ? "Z" : NULL, NULL };
930 for (int n = 0; check[n]; ++n)
932 XLine *r = ServerInstance->XLines->MatchesLine(check[n], this);
945 void User::FullConnect()
947 ServerInstance->stats->statsConnects++;
948 this->idle_lastmsg = ServerInstance->Time();
951 * You may be thinking "wtf, we checked this in User::AddClient!" - and yes, we did, BUT.
952 * At the time AddClient is called, we don't have a resolved host, by here we probably do - which
953 * may put the user into a totally seperate class with different restrictions! so we *must* check again.
954 * Don't remove this! -- w00t
958 /* Check the password, if one is required by the user's connect class.
959 * This CANNOT be in CheckClass(), because that is called prior to PASS as well!
961 if (this->MyClass && !this->MyClass->GetPass().empty() && !this->haspassed)
963 ServerInstance->Users->QuitUser(this, "Invalid password");
967 if (this->CheckLines())
970 this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network);
971 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());
972 this->WriteNumeric(RPL_YOURHOSTIS, "%s :Your host is %s, running version InspIRCd-1.2",this->nick.c_str(),ServerInstance->Config->ServerName);
973 this->WriteNumeric(RPL_SERVERCREATED, "%s :This server was created %s %s", this->nick.c_str(), __TIME__, __DATE__);
974 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());
976 ServerInstance->Config->Send005(this);
977 this->WriteNumeric(RPL_YOURUUID, "%s %s :your unique ID", this->nick.c_str(), this->uuid.c_str());
983 if (ServerInstance->Users->unregistered_count)
984 ServerInstance->Users->unregistered_count--;
986 /* Trigger LUSERS output, give modules a chance too */
988 std::string command("LUSERS");
989 std::vector<std::string> parameters;
990 FOREACH_RESULT(I_OnPreCommand, OnPreCommand(command, parameters, this, true, "LUSERS"));
992 ServerInstance->CallCommandHandler(command, parameters, this);
995 * We don't set REG_ALL until triggering OnUserConnect, so some module events don't spew out stuff
996 * for a user that doesn't exist yet.
998 FOREACH_MOD(I_OnUserConnect,OnUserConnect(this));
1000 this->registered = REG_ALL;
1002 ServerInstance->PI->Introduce(this);
1004 FOREACH_MOD(I_OnPostConnect,OnPostConnect(this));
1006 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());
1007 ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCache: Adding NEGATIVE hit for %s", this->GetIPString());
1008 ServerInstance->BanCache->AddHit(this->GetIPString(), "", "");
1011 /** User::UpdateNick()
1012 * re-allocates a nick in the user_hash after they change nicknames,
1013 * returns a pointer to the new user as it may have moved
1015 User* User::UpdateNickHash(const char* New)
1017 //user_hash::iterator newnick;
1018 user_hash::iterator oldnick = ServerInstance->Users->clientlist->find(this->nick);
1020 if (!irc::string(this->nick.c_str()).compare(New))
1021 return oldnick->second;
1023 if (oldnick == ServerInstance->Users->clientlist->end())
1024 return NULL; /* doesnt exist */
1026 User* olduser = oldnick->second;
1027 ServerInstance->Users->clientlist->erase(oldnick);
1028 (*(ServerInstance->Users->clientlist))[New] = olduser;
1032 void User::InvalidateCache()
1034 /* Invalidate cache */
1035 cached_fullhost.clear();
1036 cached_hostip.clear();
1037 cached_makehost.clear();
1038 cached_fullrealhost.clear();
1041 bool User::ForceNickChange(const char* newnick)
1045 this->InvalidateCache();
1047 this->Extend("NICKForced", "Enabled");
1049 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(this, newnick));
1051 this->Shrink("NICKForced");
1055 ServerInstance->stats->statsCollisions++;
1059 std::deque<classbase*> dummy;
1060 Command* nickhandler = ServerInstance->Parser->GetHandler("NICK");
1061 if (nickhandler) // wtfbbq, when would this not be here
1063 std::vector<std::string> parameters;
1064 nickhandler->HandleInternal(1, dummy);
1065 parameters.push_back(newnick);
1066 this->Extend("NICKForced", "Enabled");
1067 bool result = (ServerInstance->Parser->CallHandler("NICK", parameters, this) == CMD_SUCCESS);
1068 this->Shrink("NICKForced");
1069 nickhandler->HandleInternal(0, dummy);
1073 // Unreachable, we hope
1077 void User::SetSockAddr(int protocol_family, const char* sip, int port)
1079 this->cachedip = "";
1081 switch (protocol_family)
1083 #ifdef SUPPORT_IP6LINKS
1086 sockaddr_in6* sin = new sockaddr_in6;
1087 sin->sin6_family = AF_INET6;
1088 sin->sin6_port = port;
1089 inet_pton(AF_INET6, sip, &sin->sin6_addr);
1090 this->ip = (sockaddr*)sin;
1096 sockaddr_in* sin = new sockaddr_in;
1097 sin->sin_family = AF_INET;
1098 sin->sin_port = port;
1099 inet_pton(AF_INET, sip, &sin->sin_addr);
1100 this->ip = (sockaddr*)sin;
1104 ServerInstance->Logs->Log("USERS",DEBUG,"Uh oh, I dont know protocol %d to be set on '%s'!", protocol_family, this->nick.c_str());
1111 if (this->ip == NULL)
1114 switch (this->GetProtocolFamily())
1116 #ifdef SUPPORT_IP6LINKS
1119 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1120 return sin->sin6_port;
1126 sockaddr_in* sin = (sockaddr_in*)this->ip;
1127 return sin->sin_port;
1136 int User::GetProtocolFamily()
1138 if (this->ip == NULL)
1141 sockaddr_in* sin = (sockaddr_in*)this->ip;
1142 return sin->sin_family;
1145 const char* User::GetCIDRMask(int range)
1147 static char buf[44];
1149 if (this->ip == NULL)
1153 throw "Negative range, sorry, no.";
1156 * Original code written by Oliver Lupton (Om).
1157 * Integrated by me. Thanks. :) -- w00t
1159 switch (this->GetProtocolFamily())
1161 #ifdef SUPPORT_IP6LINKS
1164 /* unsigned char s6_addr[16]; */
1167 int i, bytestozero, extrabits;
1171 throw "CIDR mask width greater than address width (IPv6, 128 bit)";
1173 /* Access the user's IP structure directly */
1174 sin = (sockaddr_in6*)this->ip;
1176 /* To create the CIDR mask we want to set all the bits after 'range' bits of the address
1177 * to zero. This means the last (128 - range) bits of the address must be set to zero.
1178 * Hence this number divided by 8 is the number of whole bytes from the end of the address
1179 * which must be set to zero.
1181 bytestozero = (128 - range) / 8;
1183 /* Some of the least significant bits of the next most significant byte may also have to
1184 * be zeroed. The number of bits is the remainder of the above division.
1186 extrabits = (128 - range) % 8;
1188 /* Populate our working struct with the parts of the user's IP which are required in the
1189 * final CIDR mask. Set all the subsequent bytes to zero.
1190 * (16 - bytestozero) is the number of bytes which must be populated with actual IP data.
1192 for(i = 0; i < (16 - bytestozero); i++)
1194 v6.s6_addr[i] = sin->sin6_addr.s6_addr[i];
1197 /* And zero all the remaining bytes in the IP. */
1203 /* And finally, zero the extra bits required. */
1204 v6.s6_addr[15 - bytestozero] = (v6.s6_addr[15 - bytestozero] >> extrabits) << extrabits;
1206 snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET6, &v6, buffer, 40), range);
1218 throw "CIDR mask width greater than address width (IPv4, 32 bit)";
1220 /* Users already have a sockaddr* pointer (User::ip) which contains either a v4 or v6 structure */
1221 sin = (sockaddr_in*)this->ip;
1222 v4.s_addr = sin->sin_addr.s_addr;
1224 /* To create the CIDR mask we want to set all the bits after 'range' bits of the address
1225 * to zero. This means the last (32 - range) bits of the address must be set to zero.
1226 * This is done by shifting the value right and then back left by (32 - range) bits.
1230 v4.s_addr = ntohl(v4.s_addr);
1231 v4.s_addr = (v4.s_addr >> (32 - range)) << (32 - range);
1232 v4.s_addr = htonl(v4.s_addr);
1236 /* a range of zero would cause a 32 bit value to be shifted by 32 bits.
1237 * this has undefined behaviour, but for CIDR purposes the resulting mask
1238 * from a.b.c.d/0 is 0.0.0.0/0
1243 snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET, &v4, buffer, 16), range);
1249 return ""; // unused, but oh well
1252 const char* User::GetIPString()
1254 static char buf[40];
1256 if (this->ip == NULL)
1259 if (!this->cachedip.empty())
1260 return this->cachedip.c_str();
1262 switch (this->GetProtocolFamily())
1264 #ifdef SUPPORT_IP6LINKS
1267 static char temp[1024];
1269 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1270 inet_ntop(sin->sin6_family, &sin->sin6_addr, buf, sizeof(buf));
1271 /* IP addresses starting with a : on irc are a Bad Thing (tm) */
1274 strlcpy(&temp[1], buf, sizeof(temp) - 1);
1276 this->cachedip = temp;
1280 this->cachedip = buf;
1287 sockaddr_in* sin = (sockaddr_in*)this->ip;
1288 inet_ntop(sin->sin_family, &sin->sin_addr, buf, sizeof(buf));
1289 this->cachedip = buf;
1297 // Unreachable, probably
1301 /** NOTE: We cannot pass a const reference to this method.
1302 * The string is changed by the workings of the method,
1303 * so that if we pass const ref, we end up copying it to
1304 * something we can change anyway. Makes sense to just let
1305 * the compiler do that copy for us.
1307 void User::Write(std::string text)
1309 if (!ServerInstance->SE->BoundsCheckFd(this))
1314 ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"C[%d] O %s", this->GetFd(), text.c_str());
1315 text.append("\r\n");
1319 ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"Exception in User::Write() std::string::append");
1323 if (this->GetIOHook())
1325 /* XXX: The lack of buffering here is NOT a bug, modules implementing this interface have to
1326 * implement their own buffering mechanisms
1330 this->GetIOHook()->OnRawSocketWrite(this->fd, text.data(), text.length());
1332 catch (CoreException& modexcept)
1334 ServerInstance->Logs->Log("USEROUTPUT", DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
1339 this->AddWriteBuf(text);
1341 ServerInstance->stats->statsSent += text.length();
1342 this->ServerInstance->SE->WantWrite(this);
1347 void User::Write(const char *text, ...)
1350 char textbuffer[MAXBUF];
1352 va_start(argsPtr, text);
1353 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1356 this->Write(std::string(textbuffer));
1359 void User::WriteServ(const std::string& text)
1361 char textbuffer[MAXBUF];
1363 snprintf(textbuffer,MAXBUF,":%s %s",ServerInstance->Config->ServerName,text.c_str());
1364 this->Write(std::string(textbuffer));
1368 * Same as Write(), except `text' is prefixed with `:server.name '.
1370 void User::WriteServ(const char* text, ...)
1373 char textbuffer[MAXBUF];
1375 va_start(argsPtr, text);
1376 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1379 this->WriteServ(std::string(textbuffer));
1383 void User::WriteNumeric(unsigned int numeric, const char* text, ...)
1386 char textbuffer[MAXBUF];
1388 va_start(argsPtr, text);
1389 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1392 this->WriteNumeric(numeric, std::string(textbuffer));
1395 void User::WriteNumeric(unsigned int numeric, const std::string &text)
1397 char textbuffer[MAXBUF];
1400 FOREACH_RESULT(I_OnNumeric, OnNumeric(this, numeric, text));
1405 snprintf(textbuffer,MAXBUF,":%s %03u %s",ServerInstance->Config->ServerName, numeric, text.c_str());
1406 this->Write(std::string(textbuffer));
1409 void User::WriteFrom(User *user, const std::string &text)
1413 snprintf(tb,MAXBUF,":%s %s",user->GetFullHost().c_str(),text.c_str());
1415 this->Write(std::string(tb));
1419 /* write text from an originating user to originating user */
1421 void User::WriteFrom(User *user, const char* text, ...)
1424 char textbuffer[MAXBUF];
1426 va_start(argsPtr, text);
1427 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1430 this->WriteFrom(user, std::string(textbuffer));
1434 /* write text to an destination user from a source user (e.g. user privmsg) */
1436 void User::WriteTo(User *dest, const char *data, ...)
1438 char textbuffer[MAXBUF];
1441 va_start(argsPtr, data);
1442 vsnprintf(textbuffer, MAXBUF, data, argsPtr);
1445 this->WriteTo(dest, std::string(textbuffer));
1448 void User::WriteTo(User *dest, const std::string &data)
1450 dest->WriteFrom(this, data);
1454 void User::WriteCommon(const char* text, ...)
1456 char textbuffer[MAXBUF];
1459 if (this->registered != REG_ALL)
1462 va_start(argsPtr, text);
1463 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1466 this->WriteCommon(std::string(textbuffer));
1469 void User::WriteCommon(const std::string &text)
1471 bool sent_to_at_least_one = false;
1474 if (this->registered != REG_ALL)
1480 InitializeAlreadySent(ServerInstance->SE);
1482 /* We dont want to be doing this n times, just once */
1483 snprintf(tb,MAXBUF,":%s %s",this->GetFullHost().c_str(),text.c_str());
1484 std::string out = tb;
1486 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1488 CUList* ulist = v->first->GetUsers();
1489 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1491 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1493 already_sent[i->first->fd] = uniq_id;
1494 i->first->Write(out);
1495 sent_to_at_least_one = true;
1501 * if the user was not in any channels, no users will receive the text. Make sure the user
1502 * receives their OWN message for WriteCommon
1504 if (!sent_to_at_least_one)
1506 this->Write(std::string(tb));
1511 /* write a formatted string to all users who share at least one common
1512 * channel, NOT including the source user e.g. for use in QUIT
1515 void User::WriteCommonExcept(const char* text, ...)
1517 char textbuffer[MAXBUF];
1520 va_start(argsPtr, text);
1521 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1524 this->WriteCommonExcept(std::string(textbuffer));
1527 void User::WriteCommonQuit(const std::string &normal_text, const std::string &oper_text)
1532 if (this->registered != REG_ALL)
1538 InitializeAlreadySent(ServerInstance->SE);
1540 snprintf(tb1,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),normal_text.c_str());
1541 snprintf(tb2,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),oper_text.c_str());
1542 std::string out1 = tb1;
1543 std::string out2 = tb2;
1545 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1547 CUList *ulist = v->first->GetUsers();
1548 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1550 if (this != i->first)
1552 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1554 already_sent[i->first->fd] = uniq_id;
1555 i->first->Write(IS_OPER(i->first) ? out2 : out1);
1562 void User::WriteCommonExcept(const std::string &text)
1567 if (this->registered != REG_ALL)
1573 InitializeAlreadySent(ServerInstance->SE);
1575 snprintf(tb1,MAXBUF,":%s %s",this->GetFullHost().c_str(),text.c_str());
1578 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1580 CUList *ulist = v->first->GetUsers();
1581 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1583 if (this != i->first)
1585 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1587 already_sent[i->first->fd] = uniq_id;
1588 i->first->Write(out1);
1596 void User::WriteWallOps(const std::string &text)
1598 std::string wallop("WALLOPS :");
1599 wallop.append(text);
1601 for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
1604 if (t->IsModeSet('w'))
1605 this->WriteTo(t,wallop);
1609 void User::WriteWallOps(const char* text, ...)
1611 if (!IS_LOCAL(this))
1614 char textbuffer[MAXBUF];
1617 va_start(argsPtr, text);
1618 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1621 this->WriteWallOps(std::string(textbuffer));
1624 /* return 0 or 1 depending if users u and u2 share one or more common channels
1625 * (used by QUIT, NICK etc which arent channel specific notices)
1627 * The old algorithm in 1.0 for this was relatively inefficient, iterating over
1628 * the first users channels then the second users channels within the outer loop,
1629 * therefore it was a maximum of x*y iterations (upon returning 0 and checking
1630 * all possible iterations). However this new function instead checks against the
1631 * channel's userlist in the inner loop which is a std::map<User*,User*>
1632 * and saves us time as we already know what pointer value we are after.
1633 * Don't quote me on the maths as i am not a mathematician or computer scientist,
1634 * but i believe this algorithm is now x+(log y) maximum iterations instead.
1636 bool User::SharesChannelWith(User *other)
1638 if ((!other) || (this->registered != REG_ALL) || (other->registered != REG_ALL))
1642 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1644 /* Eliminate the inner loop (which used to be ~equal in size to the outer loop)
1645 * by replacing it with a map::find which *should* be more efficient
1647 if (i->first->HasUser(other))
1653 bool User::ChangeName(const char* gecos)
1655 if (!this->fullname.compare(gecos))
1661 FOREACH_RESULT(I_OnChangeLocalUserGECOS,OnChangeLocalUserGECOS(this,gecos));
1664 FOREACH_MOD(I_OnChangeName,OnChangeName(this,gecos));
1666 this->fullname.assign(gecos, 0, ServerInstance->Config->Limits.MaxGecos);
1671 bool User::ChangeDisplayedHost(const char* shost)
1679 FOREACH_RESULT(I_OnChangeLocalUserHost,OnChangeLocalUserHost(this,shost));
1684 FOREACH_MOD(I_OnChangeHost, OnChangeHost(this,shost));
1687 FOREACH_RESULT(I_OnHostCycle, OnHostCycle(this));
1689 if (this->ServerInstance->Config->CycleHosts && !MOD_RESULT)
1690 this->WriteCommonExcept("QUIT :Changing hosts");
1692 /* Fix by Om: User::dhost is 65 long, this was truncating some long hosts */
1693 this->dhost.assign(shost, 0, 64);
1695 this->InvalidateCache();
1697 if (this->ServerInstance->Config->CycleHosts && !MOD_RESULT)
1699 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1701 i->first->WriteAllExceptSender(this, false, 0, "JOIN %s", i->first->name.c_str());
1702 std::string n = this->ServerInstance->Modes->ModeString(this, i->first);
1704 i->first->WriteAllExceptSender(this, true, 0, "MODE %s +%s", i->first->name.c_str(), n.c_str());
1709 this->WriteNumeric(RPL_YOURDISPLAYEDHOST, "%s %s :is now your displayed host",this->nick.c_str(),this->dhost.c_str());
1714 bool User::ChangeIdent(const char* newident)
1716 if (this->ident == newident)
1720 FOREACH_RESULT(I_OnHostCycle, OnHostCycle(this));
1722 if (this->ServerInstance->Config->CycleHosts && !MOD_RESULT)
1723 this->WriteCommonExcept("%s","QUIT :Changing ident");
1725 this->ident.assign(newident, 0, ServerInstance->Config->Limits.IdentMax + 1);
1727 this->InvalidateCache();
1729 if (this->ServerInstance->Config->CycleHosts && !MOD_RESULT)
1731 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1733 i->first->WriteAllExceptSender(this, false, 0, "JOIN %s", i->first->name.c_str());
1734 std::string n = this->ServerInstance->Modes->ModeString(this, i->first);
1736 i->first->WriteAllExceptSender(this, true, 0, "MODE %s +%s", i->first->name.c_str(), n.c_str());
1743 void User::SendAll(const char* command, const char* text, ...)
1745 char textbuffer[MAXBUF];
1746 char formatbuffer[MAXBUF];
1749 va_start(argsPtr, text);
1750 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1753 snprintf(formatbuffer,MAXBUF,":%s %s $* :%s", this->GetFullHost().c_str(), command, textbuffer);
1754 std::string fmt = formatbuffer;
1756 for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
1763 std::string User::ChannelList(User* source)
1767 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1769 /* If the target is the same as the sender, let them see all their channels.
1770 * If the channel is NOT private/secret OR the user shares a common channel
1771 * If the user is an oper, and the <options:operspywhois> option is set.
1773 if ((source == this) || (IS_OPER(source) && ServerInstance->Config->OperSpyWhois) || (((!i->first->IsModeSet('p')) && (!i->first->IsModeSet('s'))) || (i->first->HasUser(source))))
1775 list.append(i->first->GetPrefixChar(this)).append(i->first->name).append(" ");
1782 void User::SplitChanList(User* dest, const std::string &cl)
1785 std::ostringstream prefix;
1786 std::string::size_type start, pos, length;
1788 prefix << this->nick << " " << dest->nick << " :";
1789 line = prefix.str();
1790 int namelen = strlen(ServerInstance->Config->ServerName) + 6;
1792 for (start = 0; (pos = cl.find(' ', start)) != std::string::npos; start = pos+1)
1794 length = (pos == std::string::npos) ? cl.length() : pos;
1796 if (line.length() + namelen + length - start > 510)
1798 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1799 line = prefix.str();
1802 if(pos == std::string::npos)
1804 line.append(cl.substr(start, length - start));
1809 line.append(cl.substr(start, length - start + 1));
1815 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1820 * Sets a user's connection class.
1821 * If the class name is provided, it will be used. Otherwise, the class will be guessed using host/ip/ident/etc.
1822 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1823 * then their ip will be taken as 'priority' anyway, so for example,
1824 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1826 ConnectClass* User::SetClass(const std::string &explicit_name)
1828 ConnectClass *found = NULL;
1830 if (!IS_LOCAL(this))
1833 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Setting connect class for UID %s", this->uuid.c_str());
1835 if (!explicit_name.empty())
1837 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1839 ConnectClass* c = *i;
1841 if (explicit_name == c->name)
1843 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Explicitly set to %s", explicit_name.c_str());
1850 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1852 ConnectClass* c = *i;
1854 if (c->type == CC_ALLOW)
1856 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "ALLOW %s %d %s", c->host.c_str(), c->GetPort(), c->GetName().c_str());
1860 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "DENY %s %d %s", c->GetHost().c_str(), c->GetPort(), c->GetName().c_str());
1863 /* check if host matches.. */
1864 if (c->GetHost().length() && !InspIRCd::MatchCIDR(this->GetIPString(), c->GetHost(), NULL) &&
1865 !InspIRCd::MatchCIDR(this->host, c->GetHost(), NULL))
1867 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "No host match (for %s)", c->GetHost().c_str());
1872 * deny change if change will take class over the limit check it HERE, not after we found a matching class,
1873 * because we should attempt to find another class if this one doesn't match us. -- w00t
1875 if (c->limit && (c->RefCount >= c->limit))
1877 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "OOPS: Connect class limit (%lu) hit, denying", c->limit);
1881 /* if it requires a port ... */
1884 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Requires port (%d)", c->GetPort());
1886 /* and our port doesn't match, fail. */
1887 if (this->GetPort() != c->GetPort())
1889 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Port match failed (%d)", this->GetPort());
1894 /* we stop at the first class that meets ALL critera. */
1901 * Okay, assuming we found a class that matches.. switch us into that class, keeping refcounts up to date.
1905 /* only fiddle with refcounts if they are already in a class .. */
1908 if (found == this->MyClass) // no point changing this shit :P
1909 return this->MyClass;
1910 this->MyClass->RefCount--;
1911 ServerInstance->Logs->Log("USERS", DEBUG, "Untying user from connect class -- refcount: %lu", this->MyClass->RefCount);
1912 if (MyClass->RefCount == 0)
1916 this->MyClass = found;
1917 this->MyClass->RefCount++;
1918 ServerInstance->Logs->Log("USERS", DEBUG, "User tied to new class -- connect refcount now: %lu", this->MyClass->RefCount);
1921 return this->MyClass;
1924 /* looks up a users password for their connection class (<ALLOW>/<DENY> tags)
1925 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1926 * then their ip will be taken as 'priority' anyway, so for example,
1927 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1929 ConnectClass* User::GetClass()
1931 return this->MyClass;
1934 void User::PurgeEmptyChannels()
1936 std::vector<Channel*> to_delete;
1938 // firstly decrement the count on each channel
1939 for (UCListIter f = this->chans.begin(); f != this->chans.end(); f++)
1941 f->first->RemoveAllPrefixes(this);
1942 if (f->first->DelUser(this) == 0)
1944 /* No users left in here, mark it for deletion */
1947 to_delete.push_back(f->first);
1951 ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::PurgeEmptyChannels to_delete.push_back()");
1956 for (std::vector<Channel*>::iterator n = to_delete.begin(); n != to_delete.end(); n++)
1958 Channel* thischan = *n;
1959 chan_hash::iterator i2 = ServerInstance->chanlist->find(thischan->name);
1960 if (i2 != ServerInstance->chanlist->end())
1963 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(i2->second));
1964 if (MOD_RESULT == 1)
1965 continue; // delete halted by module
1966 FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(i2->second));
1968 ServerInstance->chanlist->erase(i2);
1969 this->chans.erase(*n);
1976 void User::ShowMOTD()
1978 if (!ServerInstance->Config->MOTD.size())
1980 this->WriteNumeric(ERR_NOMOTD, "%s :Message of the day file is missing.",this->nick.c_str());
1983 this->WriteNumeric(RPL_MOTDSTART, "%s :%s message of the day", this->nick.c_str(), ServerInstance->Config->ServerName);
1985 for (file_cache::iterator i = ServerInstance->Config->MOTD.begin(); i != ServerInstance->Config->MOTD.end(); i++)
1986 this->WriteNumeric(RPL_MOTD, "%s :- %s",this->nick.c_str(),i->c_str());
1988 this->WriteNumeric(RPL_ENDOFMOTD, "%s :End of message of the day.", this->nick.c_str());
1991 void User::ShowRULES()
1993 if (!ServerInstance->Config->RULES.size())
1995 this->WriteNumeric(ERR_NORULES, "%s :RULES File is missing",this->nick.c_str());
1999 this->WriteNumeric(RPL_RULESTART, "%s :- %s Server Rules -",this->nick.c_str(),ServerInstance->Config->ServerName);
2001 for (file_cache::iterator i = ServerInstance->Config->RULES.begin(); i != ServerInstance->Config->RULES.end(); i++)
2002 this->WriteNumeric(RPL_RULES, "%s :- %s",this->nick.c_str(),i->c_str());
2004 this->WriteNumeric(RPL_RULESEND, "%s :End of RULES command.",this->nick.c_str());
2007 void User::HandleEvent(EventType et, int errornum)
2009 if (this->quitting) // drop everything, user is due to be quit
2015 ServerInstance->ProcessUser(this);
2018 this->FlushWriteBuf();
2021 ServerInstance->Users->QuitUser(this, errornum ? strerror(errornum) : "Client closed the connection");
2026 void User::SetOperQuit(const std::string &oquit)
2028 operquitmsg = oquit;
2031 const std::string& User::GetOperQuit()
2036 void User::IncreasePenalty(int increase)
2038 this->Penalty += increase;
2041 void User::DecreasePenalty(int decrease)
2043 this->Penalty -= decrease;
2046 void FakeUser::SetFakeServer(std::string name)
2049 this->server = nick.c_str();
2052 const std::string FakeUser::GetFullHost()
2054 if (*ServerInstance->Config->HideWhoisServer)
2055 return ServerInstance->Config->HideWhoisServer;
2059 const std::string FakeUser::GetFullRealHost()
2061 if (*ServerInstance->Config->HideWhoisServer)
2062 return ServerInstance->Config->HideWhoisServer;
2074 bool VisData::VisibleTo(User* user)
2080 ConnectClass::ConnectClass(char t, const std::string& mask)
2081 : 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)
2085 ConnectClass::ConnectClass(char t, const std::string& mask, const ConnectClass& parent)
2086 : 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)
2090 void ConnectClass::Update(const ConnectClass* src)
2093 registration_timeout = src->registration_timeout;
2095 pingtime = src->pingtime;
2098 sendqmax = src->sendqmax;
2099 recvqmax = src->recvqmax;
2100 maxlocal = src->maxlocal;
2101 maxglobal = src->maxglobal;