1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
18 #include "socketengine.h"
21 #include "commands/cmd_whowas.h"
23 /* XXX: Used for speeding up WriteCommon operations */
24 unsigned long uniq_id = 1;
26 static unsigned long* already_sent = NULL;
29 void InitializeAlreadySent(SocketEngine* SE)
31 already_sent = new unsigned long[SE->GetMaxFds()];
32 memset(already_sent, 0, SE->GetMaxFds() * sizeof(unsigned long));
36 std::string User::ProcessNoticeMasks(const char *sm)
38 bool adding = true, oldadding = false;
53 for (unsigned char d = 'A'; d <= 'z'; d++)
55 if (ServerInstance->SNO->IsEnabled(d))
57 if ((!IsNoticeMaskSet(d) && adding) || (IsNoticeMaskSet(d) && !adding))
59 if ((oldadding != adding) || (!output.length()))
60 output += (adding ? '+' : '-');
62 this->SetNoticeMask(d, adding);
71 if ((*c >= 'A') && (*c <= 'z') && (ServerInstance->SNO->IsEnabled(*c)))
73 if ((!IsNoticeMaskSet(*c) && adding) || (IsNoticeMaskSet(*c) && !adding))
75 if ((oldadding != adding) || (!output.length()))
76 output += (adding ? '+' : '-');
78 this->SetNoticeMask(*c, adding);
84 this->WriteNumeric(ERR_UNKNOWNSNOMASK, "%s %c :is unknown snomask char to me", this->nick.c_str(), *c);
96 void User::StartDNSLookup()
101 const char* sip = this->GetIPString();
102 UserResolver *res_reverse;
104 QueryType resolvtype = strchr(sip, ':') ? DNS_QUERY_PTR6 : DNS_QUERY_PTR4;
105 // when GetProtocolFamily() works correctly with 4in6, this can be replaced by
106 // this->GetProtocolFamily() == AF_INET ? DNS_QUERY_PTR4 : DNS_QUERY_PTR6;
107 res_reverse = new UserResolver(this->ServerInstance, this, sip, resolvtype, cached);
109 this->ServerInstance->AddResolver(res_reverse, cached);
111 catch (CoreException& e)
113 ServerInstance->Logs->Log("USERS", DEBUG,"Error in resolver: %s",e.GetReason());
117 bool User::IsNoticeMaskSet(unsigned char sm)
121 return (snomasks[sm-65]);
124 void User::SetNoticeMask(unsigned char sm, bool value)
128 snomasks[sm-65] = value;
131 const char* User::FormatNoticeMasks()
133 static char data[MAXBUF];
136 for (int n = 0; n < 64; n++)
139 data[offset++] = n+65;
146 bool User::IsModeSet(unsigned char m)
150 return (modes[m-65]);
153 void User::SetMode(unsigned char m, bool value)
160 const char* User::FormatModes(bool showparameters)
162 static char data[MAXBUF];
166 for (unsigned char n = 0; n < 64; n++)
170 data[offset++] = n + 65;
171 ModeHandler* mh = ServerInstance->Modes->FindMode(n + 65, MODETYPE_USER);
172 if (showparameters && mh && mh->GetNumParams(true))
174 std::string p = mh->GetUserParameter(this);
176 params.append(" ").append(p);
181 strlcat(data, params.c_str(), MAXBUF);
185 void User::DecrementModes()
187 ServerInstance->Logs->Log("USERS", DEBUG, "DecrementModes()");
188 for (unsigned char n = 'A'; n <= 'z'; n++)
192 ServerInstance->Logs->Log("USERS", DEBUG,"DecrementModes() found mode %c", n);
193 ModeHandler* mh = ServerInstance->Modes->FindMode(n, MODETYPE_USER);
196 ServerInstance->Logs->Log("USERS", DEBUG,"Found handler %c and call ChangeCount", n);
203 User::User(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance)
205 server = (char*)Instance->FindServerNamePtr(Instance->Config->ServerName);
206 reset_due = ServerInstance->Time();
207 age = ServerInstance->Time();
209 lines_in = lastping = signon = idle_lastmsg = nping = registered = 0;
210 bytes_in = bytes_out = cmds_in = cmds_out = 0;
211 quietquit = OverPenalty = ExemptFromPenalty = quitting = exempt = haspassed = dns_done = false;
218 AllowedPrivs = AllowedOperCommands = NULL;
223 uuid.assign(Instance->GetUID(), 0, UUID_LENGTH - 1);
225 uuid.assign(uid, 0, UUID_LENGTH - 1);
227 ServerInstance->Logs->Log("USERS", DEBUG,"New UUID for user: %s (%s)", uuid.c_str(), uid.empty() ? "allocated new" : "used remote");
229 user_hash::iterator finduuid = Instance->Users->uuidlist->find(uuid);
230 if (finduuid == Instance->Users->uuidlist->end())
231 (*Instance->Users->uuidlist)[uuid] = this;
233 throw CoreException("Duplicate UUID "+std::string(uuid)+" in User constructor");
238 /* NULL for remote users :) */
241 this->MyClass->RefCount--;
242 ServerInstance->Logs->Log("USERS", DEBUG, "User destructor -- connect refcount now: %lu", this->MyClass->RefCount);
245 if (this->AllowedOperCommands)
247 delete AllowedOperCommands;
248 AllowedOperCommands = NULL;
251 if (this->AllowedPrivs)
257 this->InvalidateCache();
258 this->DecrementModes();
262 ServerInstance->Users->RemoveCloneCounts(this);
264 if (this->GetProtocolFamily() == AF_INET)
266 delete (sockaddr_in*)ip;
268 #ifdef SUPPORT_IP6LINKS
271 delete (sockaddr_in6*)ip;
276 ServerInstance->Users->uuidlist->erase(uuid);
279 const std::string& User::MakeHost()
281 if (!this->cached_makehost.empty())
282 return this->cached_makehost;
285 /* This is much faster than snprintf */
287 for(const char* n = ident.c_str(); *n; n++)
290 for(const char* n = host.c_str(); *n; n++)
294 this->cached_makehost.assign(nhost);
296 return this->cached_makehost;
299 const std::string& User::MakeHostIP()
301 if (!this->cached_hostip.empty())
302 return this->cached_hostip;
305 /* This is much faster than snprintf */
307 for(const char* n = ident.c_str(); *n; n++)
310 for(const char* n = this->GetIPString(); *n; n++)
314 this->cached_hostip = ihost;
316 return this->cached_hostip;
319 void User::CloseSocket()
323 ServerInstance->SE->Shutdown(this, 2);
324 ServerInstance->SE->Close(this);
328 const std::string& User::GetFullHost()
330 if (!this->cached_fullhost.empty())
331 return this->cached_fullhost;
335 for(const char* n = nick.c_str(); *n; n++)
338 for(const char* n = ident.c_str(); *n; n++)
341 for(const char* n = dhost.c_str(); *n; n++)
345 this->cached_fullhost = result;
347 return this->cached_fullhost;
350 char* User::MakeWildHost()
352 static char nresult[MAXBUF];
354 *t++ = '*'; *t++ = '!';
355 *t++ = '*'; *t++ = '@';
356 for(const char* n = dhost.c_str(); *n; n++)
362 int User::ReadData(void* buffer, size_t size)
367 return read(this->fd, buffer, size);
369 return recv(this->fd, (char*)buffer, size, 0);
377 const std::string& User::GetFullRealHost()
379 if (!this->cached_fullrealhost.empty())
380 return this->cached_fullrealhost;
382 char fresult[MAXBUF];
384 for(const char* n = nick.c_str(); *n; n++)
387 for(const char* n = ident.c_str(); *n; n++)
390 for(const char* n = host.c_str(); *n; n++)
394 this->cached_fullrealhost = fresult;
396 return this->cached_fullrealhost;
399 bool User::IsInvited(const irc::string &channel)
401 time_t now = time(NULL);
402 InvitedList::iterator safei;
403 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
405 if (channel == i->first)
407 if (i->second != 0 && now > i->second)
409 /* Expired invite, remove it. */
412 invites.erase(safei);
421 InvitedList* User::GetInviteList()
423 time_t now = time(NULL);
424 /* Weed out expired invites here. */
425 InvitedList::iterator safei;
426 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
428 if (i->second != 0 && now > i->second)
430 /* Expired invite, remove it. */
433 invites.erase(safei);
439 void User::InviteTo(const irc::string &channel, time_t invtimeout)
441 time_t now = time(NULL);
442 if (invtimeout != 0 && now > invtimeout) return; /* Don't add invites that are expired from the get-go. */
443 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
445 if (channel == i->first)
447 if (i->second != 0 && invtimeout > i->second)
449 i->second = invtimeout;
455 invites.push_back(std::make_pair(channel, invtimeout));
458 void User::RemoveInvite(const irc::string &channel)
460 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
462 if (channel == i->first)
470 bool User::HasModePermission(unsigned char mode, ModeType type)
478 if (mode < 'A' || mode > ('A' + 64)) return false;
480 return ((type == MODETYPE_USER ? AllowedUserModes : AllowedChanModes))[(mode - 'A')];
484 bool User::HasPermission(const std::string &command)
487 * users on remote servers can completely bypass all permissions based checks.
488 * This prevents desyncs when one server has different type/class tags to another.
489 * That having been said, this does open things up to the possibility of source changes
490 * allowing remote kills, etc - but if they have access to the src, they most likely have
491 * access to the conf - so it's an end to a means either way.
496 // are they even an oper at all?
502 if (!AllowedOperCommands)
505 if (AllowedOperCommands->find(command) != AllowedOperCommands->end())
507 else if (AllowedOperCommands->find("*") != AllowedOperCommands->end())
514 bool User::HasPrivPermission(const std::string &privstr, bool noisy)
516 ServerInstance->Logs->Log("PRIVS", DEBUG, "Checking if I have " + privstr);
519 ServerInstance->Logs->Log("PRIVS", DEBUG, "Remote (yes)");
526 this->WriteServ("NOTICE %s :You are not an oper", this->nick.c_str());
527 ServerInstance->Logs->Log("PRIVS", DEBUG, "Not oper (no)");
534 this->WriteServ("NOTICE %s :Privset empty(!?)", this->nick.c_str());
535 ServerInstance->Logs->Log("PRIVS", DEBUG, "No privs(?) (no)");
539 if (AllowedPrivs->find(privstr) != AllowedPrivs->end())
541 ServerInstance->Logs->Log("PRIVS", DEBUG, "I do have it.");
544 else if (AllowedPrivs->find("*") != AllowedPrivs->end())
546 ServerInstance->Logs->Log("PRIVS", DEBUG, "I allow all.");
551 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());
552 ServerInstance->Logs->Log("PRIVS", DEBUG, "I don't have it...");
556 bool User::AddBuffer(const std::string &a)
558 std::string::size_type start = 0;
559 std::string::size_type i = a.find('\r');
562 * The old implementation here took a copy, and rfind() on \r, removing as it found them, before
563 * copying a second time onto the recvq. That's ok, but involves three copies minimum (recv() to buffer,
564 * buffer to here, here to recvq) - The new method now copies twice (recv() to buffer, buffer to recvq).
566 * We use find() instead of rfind() for clarity, however unlike the old code, our scanning of the string is
567 * contiguous: as we specify a startpoint, we never see characters we have scanned previously, making this
568 * marginally faster in cases with a number of \r hidden early on in the buffer.
571 * Start at first pos of string, find first \r, append everything in the chunk (excluding \r) to recvq. Set
572 * i ahead of the \r, search for next \r, add next chunk to buffer... repeat.
573 * -- w00t (7 may, 2008)
575 if (i == std::string::npos)
577 // no \r that we need to dance around, just add to buffer
582 // While we can find the end of a chunk to add
583 while (i != std::string::npos)
585 // Append the chunk that we have
586 recvq.append(a, start, (i - start));
588 // Start looking for the next one
590 i = a.find('\r', start);
593 if (start != a.length())
596 * This is here to catch a corner case when we get something like:
600 * in successive calls to us.
602 * Without this conditional, the 'U' on the second case will be dropped,
603 * which is most *certainly* not the behaviour we want!
606 recvq.append(a, start, (a.length() - start));
610 if (this->MyClass && (recvq.length() > this->MyClass->GetRecvqMax()))
612 ServerInstance->Users->QuitUser(this, "RecvQ exceeded");
613 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());
620 bool User::BufferIsReady()
622 return (recvq.find('\n') != std::string::npos);
625 void User::ClearBuffer()
630 std::string User::GetBuffer()
637 /* Strip any leading \r or \n off the string.
638 * Usually there are only one or two of these,
639 * so its is computationally cheap to do.
641 std::string::iterator t = recvq.begin();
642 while (t != recvq.end() && (*t == '\r' || *t == '\n'))
648 for (std::string::iterator x = recvq.begin(); x != recvq.end(); x++)
650 /* Find the first complete line, return it as the
651 * result, and leave the recvq as whats left
655 std::string ret = std::string(recvq.begin(), x);
656 recvq.erase(recvq.begin(), x + 1);
665 ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::GetBuffer()");
670 void User::AddWriteBuf(const std::string &data)
675 if (this->MyClass && (sendq.length() + data.length() > this->MyClass->GetSendqMax()))
678 * Fix by brain - Set the error text BEFORE calling, because
679 * if we dont it'll recursively call here over and over again trying
680 * to repeatedly add the text to the sendq!
682 ServerInstance->Users->QuitUser(this, "SendQ exceeded");
683 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());
687 if (data.length() > MAXBUF - 2) /* MAXBUF has a value of 514, to account for line terminators */
688 sendq.append(data.substr(0,MAXBUF - 4)).append("\r\n"); /* MAXBUF-4 = 510 */
693 // send AS MUCH OF THE USERS SENDQ as we are able to (might not be all of it)
694 void User::FlushWriteBuf()
696 if (this->fd == FD_MAGIC_NUMBER)
702 if ((sendq.length()) && (this->fd != FD_MAGIC_NUMBER))
704 int old_sendq_length = sendq.length();
705 int n_sent = ServerInstance->SE->Send(this, this->sendq.data(), this->sendq.length(), 0);
711 /* The socket buffer is full. This isnt fatal,
714 ServerInstance->SE->WantWrite(this);
718 /* Fatal error, set write error and bail */
719 ServerInstance->Users->QuitUser(this, errno ? strerror(errno) : "Write error");
725 /* advance the queue */
727 this->sendq = this->sendq.substr(n_sent);
728 /* update the user's stats counters */
729 this->bytes_out += n_sent;
731 if (n_sent != old_sendq_length)
732 this->ServerInstance->SE->WantWrite(this);
736 /* note: NOT else if! */
737 if (this->sendq.empty())
739 FOREACH_MOD(I_OnBufferFlushed,OnBufferFlushed(this));
743 void User::Oper(const std::string &opertype, const std::string &opername)
745 if (this->IsModeSet('o'))
748 this->modes[UM_OPERATOR] = 1;
749 this->WriteServ("MODE %s :+o", this->nick.c_str());
750 FOREACH_MOD(I_OnOper, OnOper(this, opertype));
752 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());
753 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()));
755 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());
756 this->oper.assign(opertype, 0, 512);
757 ServerInstance->Users->all_opers.push_back(this);
759 opertype_t::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper.c_str());
760 if (iter_opertype != ServerInstance->Config->opertypes.end())
762 if (AllowedOperCommands)
763 AllowedOperCommands->clear();
765 AllowedOperCommands = new std::set<std::string>;
768 AllowedPrivs->clear();
770 AllowedPrivs = new std::set<std::string>;
772 AllowedUserModes.reset();
773 AllowedChanModes.reset();
774 this->AllowedUserModes['o' - 'A'] = true; // Call me paranoid if you want.
776 std::string myclass, mycmd, mypriv;
777 irc::spacesepstream Classes(iter_opertype->second);
778 while (Classes.GetToken(myclass))
780 operclass_t::iterator iter_operclass = ServerInstance->Config->operclass.find(myclass.c_str());
781 if (iter_operclass != ServerInstance->Config->operclass.end())
783 /* Process commands */
784 irc::spacesepstream CommandList(iter_operclass->second.commandlist);
785 while (CommandList.GetToken(mycmd))
787 this->AllowedOperCommands->insert(mycmd);
790 irc::spacesepstream PrivList(iter_operclass->second.privs);
791 while (PrivList.GetToken(mypriv))
793 this->AllowedPrivs->insert(mypriv);
796 for (unsigned char* c = (unsigned char*)iter_operclass->second.umodelist; *c; ++c)
800 this->AllowedUserModes.set();
804 this->AllowedUserModes[*c - 'A'] = true;
808 for (unsigned char* c = (unsigned char*)iter_operclass->second.cmodelist; *c; ++c)
812 this->AllowedChanModes.set();
816 this->AllowedChanModes[*c - 'A'] = true;
823 FOREACH_MOD(I_OnPostOper,OnPostOper(this, opertype, opername));
831 * unset their oper type (what IS_OPER checks).
832 * note, order is important - this must come before modes as -o attempts
833 * to call UnOper. -- w00t
837 /* Remove all oper only modes from the user when the deoper - Bug #466*/
838 std::string moderemove("-");
840 for (unsigned char letter = 'A'; letter <= 'z'; letter++)
842 ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_USER);
843 if (mh && mh->NeedsOper())
844 moderemove += letter;
847 std::vector<std::string> parameters;
848 parameters.push_back(this->nick);
849 parameters.push_back(moderemove);
851 ServerInstance->Parser->CallHandler("MODE", parameters, this);
853 /* remove the user from the oper list. Will remove multiple entries as a safeguard against bug #404 */
854 ServerInstance->Users->all_opers.remove(this);
856 if (AllowedOperCommands)
858 delete AllowedOperCommands;
859 AllowedOperCommands = NULL;
868 AllowedUserModes.reset();
869 AllowedChanModes.reset();
873 /* adds or updates an entry in the whowas list */
874 void User::AddToWhoWas()
876 Command* whowas_command = ServerInstance->Parser->GetHandler("WHOWAS");
879 std::deque<classbase*> params;
880 params.push_back(this);
881 whowas_command->HandleInternal(WHOWAS_ADD, params);
886 * Check class restrictions
888 void User::CheckClass()
890 ConnectClass* a = this->MyClass;
892 if ((!a) || (a->GetType() == CC_DENY))
894 ServerInstance->Users->QuitUser(this, "Unauthorised connection");
897 else if ((a->GetMaxLocal()) && (ServerInstance->Users->LocalCloneCount(this) > a->GetMaxLocal()))
899 ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (local)");
900 ServerInstance->SNO->WriteToSnoMask('A', "WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString());
903 else if ((a->GetMaxGlobal()) && (ServerInstance->Users->GlobalCloneCount(this) > a->GetMaxGlobal()))
905 ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (global)");
906 ServerInstance->SNO->WriteToSnoMask('A', "WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString());
910 this->nping = ServerInstance->Time() + a->GetPingTime() + ServerInstance->Config->dns_timeout;
913 bool User::CheckLines(bool doZline)
915 const char* check[] = { "G" , "K", (doZline) ? "Z" : NULL, NULL };
919 for (int n = 0; check[n]; ++n)
921 XLine *r = ServerInstance->XLines->MatchesLine(check[n], this);
934 void User::FullConnect()
936 ServerInstance->stats->statsConnects++;
937 this->idle_lastmsg = ServerInstance->Time();
940 * You may be thinking "wtf, we checked this in User::AddClient!" - and yes, we did, BUT.
941 * At the time AddClient is called, we don't have a resolved host, by here we probably do - which
942 * may put the user into a totally seperate class with different restrictions! so we *must* check again.
943 * Don't remove this! -- w00t
947 /* Check the password, if one is required by the user's connect class.
948 * This CANNOT be in CheckClass(), because that is called prior to PASS as well!
950 if (this->MyClass && !this->MyClass->GetPass().empty() && !this->haspassed)
952 ServerInstance->Users->QuitUser(this, "Invalid password");
956 if (this->CheckLines())
959 this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network);
960 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());
961 this->WriteNumeric(RPL_YOURHOSTIS, "%s :Your host is %s, running version InspIRCd-1.2",this->nick.c_str(),ServerInstance->Config->ServerName);
962 this->WriteNumeric(RPL_SERVERCREATED, "%s :This server was created %s %s", this->nick.c_str(), __TIME__, __DATE__);
963 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());
965 ServerInstance->Config->Send005(this);
966 this->WriteNumeric(RPL_YOURUUID, "%s %s :your unique ID", this->nick.c_str(), this->uuid.c_str());
972 if (ServerInstance->Users->unregistered_count)
973 ServerInstance->Users->unregistered_count--;
975 /* Trigger LUSERS output, give modules a chance too */
977 std::string command("LUSERS");
978 std::vector<std::string> parameters;
979 FOREACH_RESULT(I_OnPreCommand, OnPreCommand(command, parameters, this, true, "LUSERS"));
981 ServerInstance->CallCommandHandler(command, parameters, this);
984 * We don't set REG_ALL until triggering OnUserConnect, so some module events don't spew out stuff
985 * for a user that doesn't exist yet.
987 FOREACH_MOD(I_OnUserConnect,OnUserConnect(this));
989 this->registered = REG_ALL;
991 ServerInstance->PI->Introduce(this);
993 FOREACH_MOD(I_OnPostConnect,OnPostConnect(this));
995 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());
996 ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCache: Adding NEGATIVE hit for %s", this->GetIPString());
997 ServerInstance->BanCache->AddHit(this->GetIPString(), "", "");
1000 /** User::UpdateNick()
1001 * re-allocates a nick in the user_hash after they change nicknames,
1002 * returns a pointer to the new user as it may have moved
1004 User* User::UpdateNickHash(const char* New)
1006 //user_hash::iterator newnick;
1007 user_hash::iterator oldnick = ServerInstance->Users->clientlist->find(this->nick);
1009 if (!irc::string(this->nick.c_str()).compare(New))
1010 return oldnick->second;
1012 if (oldnick == ServerInstance->Users->clientlist->end())
1013 return NULL; /* doesnt exist */
1015 User* olduser = oldnick->second;
1016 ServerInstance->Users->clientlist->erase(oldnick);
1017 (*(ServerInstance->Users->clientlist))[New] = olduser;
1021 void User::InvalidateCache()
1023 /* Invalidate cache */
1024 cached_fullhost.clear();
1025 cached_hostip.clear();
1026 cached_makehost.clear();
1027 cached_fullrealhost.clear();
1030 bool User::ForceNickChange(const char* newnick)
1034 this->InvalidateCache();
1036 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(this, newnick));
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 bool result = (ServerInstance->Parser->CallHandler("NICK", parameters, this) == CMD_SUCCESS);
1052 nickhandler->HandleInternal(0, dummy);
1056 // Unreachable, we hope
1060 void User::SetSockAddr(int protocol_family, const char* sip, int port)
1062 this->cachedip = "";
1064 switch (protocol_family)
1066 #ifdef SUPPORT_IP6LINKS
1069 sockaddr_in6* sin = new sockaddr_in6;
1070 sin->sin6_family = AF_INET6;
1071 sin->sin6_port = port;
1072 inet_pton(AF_INET6, sip, &sin->sin6_addr);
1073 this->ip = (sockaddr*)sin;
1079 sockaddr_in* sin = new sockaddr_in;
1080 sin->sin_family = AF_INET;
1081 sin->sin_port = port;
1082 inet_pton(AF_INET, sip, &sin->sin_addr);
1083 this->ip = (sockaddr*)sin;
1087 ServerInstance->Logs->Log("USERS",DEBUG,"Uh oh, I dont know protocol %d to be set on '%s'!", protocol_family, this->nick.c_str());
1094 if (this->ip == NULL)
1097 switch (this->GetProtocolFamily())
1099 #ifdef SUPPORT_IP6LINKS
1102 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1103 return sin->sin6_port;
1109 sockaddr_in* sin = (sockaddr_in*)this->ip;
1110 return sin->sin_port;
1119 int User::GetProtocolFamily()
1121 if (this->ip == NULL)
1124 sockaddr_in* sin = (sockaddr_in*)this->ip;
1125 return sin->sin_family;
1128 const char* User::GetCIDRMask(int range)
1130 static char buf[44];
1132 if (this->ip == NULL)
1136 throw "Negative range, sorry, no.";
1139 * Original code written by Oliver Lupton (Om).
1140 * Integrated by me. Thanks. :) -- w00t
1142 switch (this->GetProtocolFamily())
1144 #ifdef SUPPORT_IP6LINKS
1147 /* unsigned char s6_addr[16]; */
1150 int i, bytestozero, extrabits;
1154 throw "CIDR mask width greater than address width (IPv6, 128 bit)";
1156 /* Access the user's IP structure directly */
1157 sin = (sockaddr_in6*)this->ip;
1159 /* To create the CIDR mask we want to set all the bits after 'range' bits of the address
1160 * to zero. This means the last (128 - range) bits of the address must be set to zero.
1161 * Hence this number divided by 8 is the number of whole bytes from the end of the address
1162 * which must be set to zero.
1164 bytestozero = (128 - range) / 8;
1166 /* Some of the least significant bits of the next most significant byte may also have to
1167 * be zeroed. The number of bits is the remainder of the above division.
1169 extrabits = (128 - range) % 8;
1171 /* Populate our working struct with the parts of the user's IP which are required in the
1172 * final CIDR mask. Set all the subsequent bytes to zero.
1173 * (16 - bytestozero) is the number of bytes which must be populated with actual IP data.
1175 for(i = 0; i < (16 - bytestozero); i++)
1177 v6.s6_addr[i] = sin->sin6_addr.s6_addr[i];
1180 /* And zero all the remaining bytes in the IP. */
1186 /* And finally, zero the extra bits required. */
1187 v6.s6_addr[15 - bytestozero] = (v6.s6_addr[15 - bytestozero] >> extrabits) << extrabits;
1189 snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET6, &v6, buffer, 40), range);
1201 throw "CIDR mask width greater than address width (IPv4, 32 bit)";
1203 /* Users already have a sockaddr* pointer (User::ip) which contains either a v4 or v6 structure */
1204 sin = (sockaddr_in*)this->ip;
1205 v4.s_addr = sin->sin_addr.s_addr;
1207 /* To create the CIDR mask we want to set all the bits after 'range' bits of the address
1208 * to zero. This means the last (32 - range) bits of the address must be set to zero.
1209 * This is done by shifting the value right and then back left by (32 - range) bits.
1213 v4.s_addr = ntohl(v4.s_addr);
1214 v4.s_addr = (v4.s_addr >> (32 - range)) << (32 - range);
1215 v4.s_addr = htonl(v4.s_addr);
1219 /* a range of zero would cause a 32 bit value to be shifted by 32 bits.
1220 * this has undefined behaviour, but for CIDR purposes the resulting mask
1221 * from a.b.c.d/0 is 0.0.0.0/0
1226 snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET, &v4, buffer, 16), range);
1232 return ""; // unused, but oh well
1235 const char* User::GetIPString()
1237 static char buf[40];
1239 if (this->ip == NULL)
1242 if (!this->cachedip.empty())
1243 return this->cachedip.c_str();
1245 switch (this->GetProtocolFamily())
1247 #ifdef SUPPORT_IP6LINKS
1250 static char temp[1024];
1252 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1253 inet_ntop(sin->sin6_family, &sin->sin6_addr, buf, sizeof(buf));
1254 /* IP addresses starting with a : on irc are a Bad Thing (tm) */
1257 strlcpy(&temp[1], buf, sizeof(temp) - 1);
1259 this->cachedip = temp;
1263 this->cachedip = buf;
1270 sockaddr_in* sin = (sockaddr_in*)this->ip;
1271 inet_ntop(sin->sin_family, &sin->sin_addr, buf, sizeof(buf));
1272 this->cachedip = buf;
1280 // Unreachable, probably
1284 /** NOTE: We cannot pass a const reference to this method.
1285 * The string is changed by the workings of the method,
1286 * so that if we pass const ref, we end up copying it to
1287 * something we can change anyway. Makes sense to just let
1288 * the compiler do that copy for us.
1290 void User::Write(std::string text)
1292 if (!ServerInstance->SE->BoundsCheckFd(this))
1297 ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"C[%d] O %s", this->GetFd(), text.c_str());
1298 text.append("\r\n");
1302 ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"Exception in User::Write() std::string::append");
1306 if (this->GetIOHook())
1308 /* XXX: The lack of buffering here is NOT a bug, modules implementing this interface have to
1309 * implement their own buffering mechanisms
1313 this->GetIOHook()->OnRawSocketWrite(this->fd, text.data(), text.length());
1315 catch (CoreException& modexcept)
1317 ServerInstance->Logs->Log("USEROUTPUT", DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
1322 this->AddWriteBuf(text);
1324 ServerInstance->stats->statsSent += text.length();
1325 this->ServerInstance->SE->WantWrite(this);
1330 void User::Write(const char *text, ...)
1333 char textbuffer[MAXBUF];
1335 va_start(argsPtr, text);
1336 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1339 this->Write(std::string(textbuffer));
1342 void User::WriteServ(const std::string& text)
1344 char textbuffer[MAXBUF];
1346 snprintf(textbuffer,MAXBUF,":%s %s",ServerInstance->Config->ServerName,text.c_str());
1347 this->Write(std::string(textbuffer));
1351 * Same as Write(), except `text' is prefixed with `:server.name '.
1353 void User::WriteServ(const char* text, ...)
1356 char textbuffer[MAXBUF];
1358 va_start(argsPtr, text);
1359 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1362 this->WriteServ(std::string(textbuffer));
1366 void User::WriteNumeric(unsigned int numeric, const char* text, ...)
1369 char textbuffer[MAXBUF];
1371 va_start(argsPtr, text);
1372 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1375 this->WriteNumeric(numeric, std::string(textbuffer));
1378 void User::WriteNumeric(unsigned int numeric, const std::string &text)
1380 char textbuffer[MAXBUF];
1383 FOREACH_RESULT(I_OnNumeric, OnNumeric(this, numeric, text));
1388 snprintf(textbuffer,MAXBUF,":%s %03u %s",ServerInstance->Config->ServerName, numeric, text.c_str());
1389 this->Write(std::string(textbuffer));
1392 void User::WriteFrom(User *user, const std::string &text)
1396 snprintf(tb,MAXBUF,":%s %s",user->GetFullHost().c_str(),text.c_str());
1398 this->Write(std::string(tb));
1402 /* write text from an originating user to originating user */
1404 void User::WriteFrom(User *user, const char* text, ...)
1407 char textbuffer[MAXBUF];
1409 va_start(argsPtr, text);
1410 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1413 this->WriteFrom(user, std::string(textbuffer));
1417 /* write text to an destination user from a source user (e.g. user privmsg) */
1419 void User::WriteTo(User *dest, const char *data, ...)
1421 char textbuffer[MAXBUF];
1424 va_start(argsPtr, data);
1425 vsnprintf(textbuffer, MAXBUF, data, argsPtr);
1428 this->WriteTo(dest, std::string(textbuffer));
1431 void User::WriteTo(User *dest, const std::string &data)
1433 dest->WriteFrom(this, data);
1437 void User::WriteCommon(const char* text, ...)
1439 char textbuffer[MAXBUF];
1442 if (this->registered != REG_ALL)
1445 va_start(argsPtr, text);
1446 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1449 this->WriteCommon(std::string(textbuffer));
1452 void User::WriteCommon(const std::string &text)
1454 bool sent_to_at_least_one = false;
1457 if (this->registered != REG_ALL)
1463 InitializeAlreadySent(ServerInstance->SE);
1465 /* We dont want to be doing this n times, just once */
1466 snprintf(tb,MAXBUF,":%s %s",this->GetFullHost().c_str(),text.c_str());
1467 std::string out = tb;
1469 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1471 CUList* ulist = v->first->GetUsers();
1472 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1474 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1476 already_sent[i->first->fd] = uniq_id;
1477 i->first->Write(out);
1478 sent_to_at_least_one = true;
1484 * if the user was not in any channels, no users will receive the text. Make sure the user
1485 * receives their OWN message for WriteCommon
1487 if (!sent_to_at_least_one)
1489 this->Write(std::string(tb));
1494 /* write a formatted string to all users who share at least one common
1495 * channel, NOT including the source user e.g. for use in QUIT
1498 void User::WriteCommonExcept(const char* text, ...)
1500 char textbuffer[MAXBUF];
1503 va_start(argsPtr, text);
1504 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1507 this->WriteCommonExcept(std::string(textbuffer));
1510 void User::WriteCommonQuit(const std::string &normal_text, const std::string &oper_text)
1515 if (this->registered != REG_ALL)
1521 InitializeAlreadySent(ServerInstance->SE);
1523 snprintf(tb1,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),normal_text.c_str());
1524 snprintf(tb2,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),oper_text.c_str());
1525 std::string out1 = tb1;
1526 std::string out2 = tb2;
1528 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1530 CUList *ulist = v->first->GetUsers();
1531 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1533 if (this != i->first)
1535 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1537 already_sent[i->first->fd] = uniq_id;
1538 i->first->Write(IS_OPER(i->first) ? out2 : out1);
1545 void User::WriteCommonExcept(const std::string &text)
1550 if (this->registered != REG_ALL)
1556 InitializeAlreadySent(ServerInstance->SE);
1558 snprintf(tb1,MAXBUF,":%s %s",this->GetFullHost().c_str(),text.c_str());
1561 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1563 CUList *ulist = v->first->GetUsers();
1564 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1566 if (this != i->first)
1568 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1570 already_sent[i->first->fd] = uniq_id;
1571 i->first->Write(out1);
1579 void User::WriteWallOps(const std::string &text)
1581 if (!IS_LOCAL(this))
1584 std::string wallop("WALLOPS :");
1585 wallop.append(text);
1587 for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
1590 if (t->IsModeSet('w'))
1591 this->WriteTo(t,wallop);
1595 void User::WriteWallOps(const char* text, ...)
1597 if (!IS_LOCAL(this))
1600 char textbuffer[MAXBUF];
1603 va_start(argsPtr, text);
1604 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1607 this->WriteWallOps(std::string(textbuffer));
1610 /* return 0 or 1 depending if users u and u2 share one or more common channels
1611 * (used by QUIT, NICK etc which arent channel specific notices)
1613 * The old algorithm in 1.0 for this was relatively inefficient, iterating over
1614 * the first users channels then the second users channels within the outer loop,
1615 * therefore it was a maximum of x*y iterations (upon returning 0 and checking
1616 * all possible iterations). However this new function instead checks against the
1617 * channel's userlist in the inner loop which is a std::map<User*,User*>
1618 * and saves us time as we already know what pointer value we are after.
1619 * Don't quote me on the maths as i am not a mathematician or computer scientist,
1620 * but i believe this algorithm is now x+(log y) maximum iterations instead.
1622 bool User::SharesChannelWith(User *other)
1624 if ((!other) || (this->registered != REG_ALL) || (other->registered != REG_ALL))
1628 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1630 /* Eliminate the inner loop (which used to be ~equal in size to the outer loop)
1631 * by replacing it with a map::find which *should* be more efficient
1633 if (i->first->HasUser(other))
1639 bool User::ChangeName(const char* gecos)
1641 if (!this->fullname.compare(gecos))
1647 FOREACH_RESULT(I_OnChangeLocalUserGECOS,OnChangeLocalUserGECOS(this,gecos));
1650 FOREACH_MOD(I_OnChangeName,OnChangeName(this,gecos));
1652 this->fullname.assign(gecos, 0, ServerInstance->Config->Limits.MaxGecos);
1657 bool User::ChangeDisplayedHost(const char* shost)
1665 FOREACH_RESULT(I_OnChangeLocalUserHost,OnChangeLocalUserHost(this,shost));
1670 FOREACH_MOD(I_OnChangeHost, OnChangeHost(this,shost));
1673 FOREACH_RESULT(I_OnHostCycle, OnHostCycle(this));
1675 if (this->ServerInstance->Config->CycleHosts && !MOD_RESULT)
1676 this->WriteCommonExcept("QUIT :Changing hosts");
1678 /* Fix by Om: User::dhost is 65 long, this was truncating some long hosts */
1679 this->dhost.assign(shost, 0, 64);
1681 this->InvalidateCache();
1683 if (this->ServerInstance->Config->CycleHosts && !MOD_RESULT)
1685 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1687 i->first->WriteAllExceptSender(this, false, 0, "JOIN %s", i->first->name.c_str());
1688 std::string n = this->ServerInstance->Modes->ModeString(this, i->first);
1690 i->first->WriteAllExceptSender(this, true, 0, "MODE %s +%s", i->first->name.c_str(), n.c_str());
1695 this->WriteNumeric(RPL_YOURDISPLAYEDHOST, "%s %s :is now your displayed host",this->nick.c_str(),this->dhost.c_str());
1700 bool User::ChangeIdent(const char* newident)
1702 if (this->ident == newident)
1706 FOREACH_RESULT(I_OnHostCycle, OnHostCycle(this));
1708 if (this->ServerInstance->Config->CycleHosts && !MOD_RESULT)
1709 this->WriteCommonExcept("%s","QUIT :Changing ident");
1711 this->ident.assign(newident, 0, ServerInstance->Config->Limits.IdentMax + 1);
1713 this->InvalidateCache();
1715 if (this->ServerInstance->Config->CycleHosts && !MOD_RESULT)
1717 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1719 i->first->WriteAllExceptSender(this, false, 0, "JOIN %s", i->first->name.c_str());
1720 std::string n = this->ServerInstance->Modes->ModeString(this, i->first);
1722 i->first->WriteAllExceptSender(this, true, 0, "MODE %s +%s", i->first->name.c_str(), n.c_str());
1729 void User::SendAll(const char* command, const char* text, ...)
1731 char textbuffer[MAXBUF];
1732 char formatbuffer[MAXBUF];
1735 va_start(argsPtr, text);
1736 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1739 snprintf(formatbuffer,MAXBUF,":%s %s $* :%s", this->GetFullHost().c_str(), command, textbuffer);
1740 std::string fmt = formatbuffer;
1742 for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
1749 std::string User::ChannelList(User* source)
1753 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1755 /* If the target is the same as the sender, let them see all their channels.
1756 * If the channel is NOT private/secret OR the user shares a common channel
1757 * If the user is an oper, and the <options:operspywhois> option is set.
1759 if ((source == this) || (IS_OPER(source) && ServerInstance->Config->OperSpyWhois) || (((!i->first->IsModeSet('p')) && (!i->first->IsModeSet('s'))) || (i->first->HasUser(source))))
1761 list.append(i->first->GetPrefixChar(this)).append(i->first->name).append(" ");
1768 void User::SplitChanList(User* dest, const std::string &cl)
1771 std::ostringstream prefix;
1772 std::string::size_type start, pos, length;
1774 prefix << this->nick << " " << dest->nick << " :";
1775 line = prefix.str();
1776 int namelen = strlen(ServerInstance->Config->ServerName) + 6;
1778 for (start = 0; (pos = cl.find(' ', start)) != std::string::npos; start = pos+1)
1780 length = (pos == std::string::npos) ? cl.length() : pos;
1782 if (line.length() + namelen + length - start > 510)
1784 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1785 line = prefix.str();
1788 if(pos == std::string::npos)
1790 line.append(cl.substr(start, length - start));
1795 line.append(cl.substr(start, length - start + 1));
1801 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1806 * Sets a user's connection class.
1807 * If the class name is provided, it will be used. Otherwise, the class will be guessed using host/ip/ident/etc.
1808 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1809 * then their ip will be taken as 'priority' anyway, so for example,
1810 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1812 ConnectClass* User::SetClass(const std::string &explicit_name)
1814 ConnectClass *found = NULL;
1816 if (!IS_LOCAL(this))
1819 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Setting connect class for UID %s", this->uuid.c_str());
1821 if (!explicit_name.empty())
1823 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1825 ConnectClass* c = *i;
1827 if (c->GetDisabled())
1828 continue; // can't possibly match, removed from conf
1830 if (explicit_name == c->GetName())
1832 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Explicitly set to %s", explicit_name.c_str());
1839 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1841 ConnectClass* c = *i;
1843 if (c->GetType() == CC_ALLOW)
1845 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "ALLOW %s %d %s", c->GetHost().c_str(), c->GetPort(), c->GetName().c_str());
1849 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "DENY %s %d %s", c->GetHost().c_str(), c->GetPort(), c->GetName().c_str());
1852 /* if it's disabled, we can't match this one. */
1853 if (c->GetDisabled())
1855 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Class disabled");
1859 /* check if host matches.. */
1860 if (!InspIRCd::MatchCIDR(this->GetIPString(), c->GetHost(), NULL) &&
1861 !InspIRCd::MatchCIDR(this->host, c->GetHost(), NULL))
1863 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "No host match (for %s)", c->GetHost().c_str());
1868 * deny change if change will take class over the limit check it HERE, not after we found a matching class,
1869 * because we should attempt to find another class if this one doesn't match us. -- w00t
1871 if (c->limit && (c->RefCount + 1 >= c->limit))
1873 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "OOPS: Connect class limit (%lu) hit, denying", c->limit);
1877 /* if it requires a port ... */
1880 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Requires port (%d)", c->GetPort());
1882 /* and our port doesn't match, fail. */
1883 if (this->GetPort() != c->GetPort())
1885 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Port match failed (%d)", this->GetPort());
1890 /* we stop at the first class that meets ALL critera. */
1897 * Okay, assuming we found a class that matches.. switch us into that class, keeping refcounts up to date.
1901 /* only fiddle with refcounts if they are already in a class .. */
1904 if (found == this->MyClass) // no point changing this shit :P
1905 return this->MyClass;
1906 this->MyClass->RefCount--;
1907 ServerInstance->Logs->Log("USERS", DEBUG, "Untying user from connect class -- refcount: %lu", this->MyClass->RefCount);
1910 this->MyClass = found;
1911 this->MyClass->RefCount++;
1912 ServerInstance->Logs->Log("USERS", DEBUG, "User tied to new class -- connect refcount now: %lu", this->MyClass->RefCount);
1915 return this->MyClass;
1918 /* looks up a users password for their connection class (<ALLOW>/<DENY> tags)
1919 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1920 * then their ip will be taken as 'priority' anyway, so for example,
1921 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1923 ConnectClass* User::GetClass()
1925 return this->MyClass;
1928 void User::PurgeEmptyChannels()
1930 std::vector<Channel*> to_delete;
1932 // firstly decrement the count on each channel
1933 for (UCListIter f = this->chans.begin(); f != this->chans.end(); f++)
1935 f->first->RemoveAllPrefixes(this);
1936 if (f->first->DelUser(this) == 0)
1938 /* No users left in here, mark it for deletion */
1941 to_delete.push_back(f->first);
1945 ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::PurgeEmptyChannels to_delete.push_back()");
1950 for (std::vector<Channel*>::iterator n = to_delete.begin(); n != to_delete.end(); n++)
1952 Channel* thischan = *n;
1953 chan_hash::iterator i2 = ServerInstance->chanlist->find(thischan->name);
1954 if (i2 != ServerInstance->chanlist->end())
1956 FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(i2->second));
1958 ServerInstance->chanlist->erase(i2);
1959 this->chans.erase(*n);
1966 void User::ShowMOTD()
1968 if (!ServerInstance->Config->MOTD.size())
1970 this->WriteNumeric(ERR_NOMOTD, "%s :Message of the day file is missing.",this->nick.c_str());
1973 this->WriteNumeric(RPL_MOTDSTART, "%s :%s message of the day", this->nick.c_str(), ServerInstance->Config->ServerName);
1975 for (file_cache::iterator i = ServerInstance->Config->MOTD.begin(); i != ServerInstance->Config->MOTD.end(); i++)
1976 this->WriteNumeric(RPL_MOTD, "%s :- %s",this->nick.c_str(),i->c_str());
1978 this->WriteNumeric(RPL_ENDOFMOTD, "%s :End of message of the day.", this->nick.c_str());
1981 void User::ShowRULES()
1983 if (!ServerInstance->Config->RULES.size())
1985 this->WriteNumeric(ERR_NORULES, "%s :RULES File is missing",this->nick.c_str());
1989 this->WriteNumeric(RPL_RULESTART, "%s :- %s Server Rules -",this->nick.c_str(),ServerInstance->Config->ServerName);
1991 for (file_cache::iterator i = ServerInstance->Config->RULES.begin(); i != ServerInstance->Config->RULES.end(); i++)
1992 this->WriteNumeric(RPL_RULES, "%s :- %s",this->nick.c_str(),i->c_str());
1994 this->WriteNumeric(RPL_RULESEND, "%s :End of RULES command.",this->nick.c_str());
1997 void User::HandleEvent(EventType et, int errornum)
1999 if (this->quitting) // drop everything, user is due to be quit
2005 ServerInstance->ProcessUser(this);
2008 this->FlushWriteBuf();
2011 ServerInstance->Users->QuitUser(this, errornum ? strerror(errornum) : "Client closed the connection");
2016 void User::SetOperQuit(const std::string &oquit)
2018 operquitmsg = oquit;
2021 const std::string& User::GetOperQuit()
2026 void User::IncreasePenalty(int increase)
2028 this->Penalty += increase;
2031 void User::DecreasePenalty(int decrease)
2033 this->Penalty -= decrease;
2044 bool VisData::VisibleTo(User* user)