1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
18 #include "socketengine.h"
21 #include "commands/cmd_whowas.h"
23 /* XXX: Used for speeding up WriteCommon operations */
24 unsigned long uniq_id = 1;
26 static unsigned long* already_sent = NULL;
29 void InitializeAlreadySent(SocketEngine* SE)
31 already_sent = new unsigned long[SE->GetMaxFds()];
32 memset(already_sent, 0, SE->GetMaxFds() * sizeof(unsigned long));
36 std::string User::ProcessNoticeMasks(const char *sm)
38 bool adding = true, oldadding = false;
53 for (unsigned char d = 'A'; d <= 'z'; d++)
55 if (ServerInstance->SNO->IsEnabled(d))
57 if ((!IsNoticeMaskSet(d) && adding) || (IsNoticeMaskSet(d) && !adding))
59 if ((oldadding != adding) || (!output.length()))
60 output += (adding ? '+' : '-');
62 this->SetNoticeMask(d, adding);
71 if ((*c >= 'A') && (*c <= 'z') && (ServerInstance->SNO->IsEnabled(*c)))
73 if ((!IsNoticeMaskSet(*c) && adding) || (IsNoticeMaskSet(*c) && !adding))
75 if ((oldadding != adding) || (!output.length()))
76 output += (adding ? '+' : '-');
78 this->SetNoticeMask(*c, adding);
84 this->WriteNumeric(ERR_UNKNOWNSNOMASK, "%s %c :is unknown snomask char to me", this->nick.c_str(), *c);
93 std::string s = this->FormatNoticeMasks();
96 this->modes[UM_SNOMASK] = false;
102 void User::StartDNSLookup()
107 const char* sip = this->GetIPString();
108 UserResolver *res_reverse;
110 QueryType resolvtype = this->client_sa.sa.sa_family == AF_INET6 ? DNS_QUERY_PTR6 : DNS_QUERY_PTR4;
111 res_reverse = new UserResolver(this->ServerInstance, this, sip, resolvtype, cached);
113 this->ServerInstance->AddResolver(res_reverse, cached);
115 catch (CoreException& e)
117 ServerInstance->Logs->Log("USERS", DEBUG,"Error in resolver: %s",e.GetReason());
121 bool User::IsNoticeMaskSet(unsigned char sm)
125 return (snomasks[sm-65]);
128 void User::SetNoticeMask(unsigned char sm, bool value)
132 snomasks[sm-65] = value;
135 const char* User::FormatNoticeMasks()
137 static char data[MAXBUF];
140 for (int n = 0; n < 64; n++)
143 data[offset++] = n+65;
150 bool User::IsModeSet(unsigned char m)
154 return (modes[m-65]);
157 void User::SetMode(unsigned char m, bool value)
164 const char* User::FormatModes(bool showparameters)
166 static char data[MAXBUF];
170 for (unsigned char n = 0; n < 64; n++)
174 data[offset++] = n + 65;
175 ModeHandler* mh = ServerInstance->Modes->FindMode(n + 65, MODETYPE_USER);
176 if (showparameters && mh && mh->GetNumParams(true))
178 std::string p = mh->GetUserParameter(this);
180 params.append(" ").append(p);
185 strlcat(data, params.c_str(), MAXBUF);
189 void User::DecrementModes()
191 ServerInstance->Logs->Log("USERS", DEBUG, "DecrementModes()");
192 for (unsigned char n = 'A'; n <= 'z'; n++)
196 ServerInstance->Logs->Log("USERS", DEBUG,"DecrementModes() found mode %c", n);
197 ModeHandler* mh = ServerInstance->Modes->FindMode(n, MODETYPE_USER);
200 ServerInstance->Logs->Log("USERS", DEBUG,"Found handler %c and call ChangeCount", n);
207 User::User(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance)
209 server = Instance->FindServerNamePtr(Instance->Config->ServerName);
210 age = ServerInstance->Time();
212 lastping = signon = idle_lastmsg = nping = registered = 0;
213 bytes_in = bytes_out = cmds_in = cmds_out = 0;
214 quietquit = quitting = exempt = haspassed = dns_done = false;
216 server_sa.sa.sa_family = AF_UNSPEC;
217 client_sa.sa.sa_family = AF_UNSPEC;
221 AllowedPrivs = AllowedOperCommands = NULL;
226 uuid.assign(Instance->GetUID(), 0, UUID_LENGTH - 1);
228 uuid.assign(uid, 0, UUID_LENGTH - 1);
230 ServerInstance->Logs->Log("USERS", DEBUG,"New UUID for user: %s (%s)", uuid.c_str(), uid.empty() ? "allocated new" : "used remote");
232 user_hash::iterator finduuid = Instance->Users->uuidlist->find(uuid);
233 if (finduuid == Instance->Users->uuidlist->end())
234 (*Instance->Users->uuidlist)[uuid] = this;
236 throw CoreException("Duplicate UUID "+std::string(uuid)+" in User constructor");
241 /* NULL for remote users :) */
244 this->MyClass->RefCount--;
245 ServerInstance->Logs->Log("USERS", DEBUG, "User destructor -- connect refcount now: %lu", this->MyClass->RefCount);
246 if (MyClass->RefCount == 0)
250 if (this->AllowedOperCommands)
252 delete AllowedOperCommands;
253 AllowedOperCommands = NULL;
256 if (this->AllowedPrivs)
262 this->InvalidateCache();
263 this->DecrementModes();
265 if (client_sa.sa.sa_family != AF_UNSPEC)
266 ServerInstance->Users->RemoveCloneCounts(this);
268 ServerInstance->Users->uuidlist->erase(uuid);
271 const std::string& User::MakeHost()
273 if (!this->cached_makehost.empty())
274 return this->cached_makehost;
277 /* This is much faster than snprintf */
279 for(const char* n = ident.c_str(); *n; n++)
282 for(const char* n = host.c_str(); *n; n++)
286 this->cached_makehost.assign(nhost);
288 return this->cached_makehost;
291 const std::string& User::MakeHostIP()
293 if (!this->cached_hostip.empty())
294 return this->cached_hostip;
297 /* This is much faster than snprintf */
299 for(const char* n = ident.c_str(); *n; n++)
302 for(const char* n = this->GetIPString(); *n; n++)
306 this->cached_hostip = ihost;
308 return this->cached_hostip;
311 void User::CloseSocket()
315 ServerInstance->SE->Shutdown(this, 2);
316 ServerInstance->SE->Close(this);
320 const std::string User::GetFullHost()
322 if (!this->cached_fullhost.empty())
323 return this->cached_fullhost;
327 for(const char* n = nick.c_str(); *n; n++)
330 for(const char* n = ident.c_str(); *n; n++)
333 for(const char* n = dhost.c_str(); *n; n++)
337 this->cached_fullhost = result;
339 return this->cached_fullhost;
342 char* User::MakeWildHost()
344 static char nresult[MAXBUF];
346 *t++ = '*'; *t++ = '!';
347 *t++ = '*'; *t++ = '@';
348 for(const char* n = dhost.c_str(); *n; n++)
354 int User::ReadData(void* buffer, size_t size)
359 return read(this->fd, buffer, size);
361 return recv(this->fd, (char*)buffer, size, 0);
369 const std::string User::GetFullRealHost()
371 if (!this->cached_fullrealhost.empty())
372 return this->cached_fullrealhost;
374 char fresult[MAXBUF];
376 for(const char* n = nick.c_str(); *n; n++)
379 for(const char* n = ident.c_str(); *n; n++)
382 for(const char* n = host.c_str(); *n; n++)
386 this->cached_fullrealhost = fresult;
388 return this->cached_fullrealhost;
391 bool User::IsInvited(const irc::string &channel)
393 time_t now = ServerInstance->Time();
394 InvitedList::iterator safei;
395 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
397 if (channel == i->first)
399 if (i->second != 0 && now > i->second)
401 /* Expired invite, remove it. */
404 invites.erase(safei);
413 InvitedList* User::GetInviteList()
415 time_t now = ServerInstance->Time();
416 /* Weed out expired invites here. */
417 InvitedList::iterator safei;
418 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
420 if (i->second != 0 && now > i->second)
422 /* Expired invite, remove it. */
425 invites.erase(safei);
431 void User::InviteTo(const irc::string &channel, time_t invtimeout)
433 time_t now = ServerInstance->Time();
434 if (invtimeout != 0 && now > invtimeout) return; /* Don't add invites that are expired from the get-go. */
435 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
437 if (channel == i->first)
439 if (i->second != 0 && invtimeout > i->second)
441 i->second = invtimeout;
447 invites.push_back(std::make_pair(channel, invtimeout));
450 void User::RemoveInvite(const irc::string &channel)
452 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
454 if (channel == i->first)
462 bool User::HasModePermission(unsigned char mode, ModeType type)
470 if (mode < 'A' || mode > ('A' + 64)) return false;
472 return ((type == MODETYPE_USER ? AllowedUserModes : AllowedChanModes))[(mode - 'A')];
476 bool User::HasPermission(const std::string &command)
479 * users on remote servers can completely bypass all permissions based checks.
480 * This prevents desyncs when one server has different type/class tags to another.
481 * That having been said, this does open things up to the possibility of source changes
482 * allowing remote kills, etc - but if they have access to the src, they most likely have
483 * access to the conf - so it's an end to a means either way.
488 // are they even an oper at all?
494 if (!AllowedOperCommands)
497 if (AllowedOperCommands->find(command) != AllowedOperCommands->end())
499 else if (AllowedOperCommands->find("*") != AllowedOperCommands->end())
506 bool User::HasPrivPermission(const std::string &privstr, bool noisy)
510 ServerInstance->Logs->Log("PRIVS", DEBUG, "Remote (yes)");
517 this->WriteServ("NOTICE %s :You are not an oper", this->nick.c_str());
524 this->WriteServ("NOTICE %s :Privset empty(!?)", this->nick.c_str());
528 if (AllowedPrivs->find(privstr) != AllowedPrivs->end())
532 else if (AllowedPrivs->find("*") != AllowedPrivs->end())
538 this->WriteServ("NOTICE %s :Oper type %s does not have access to priv %s", this->nick.c_str(), this->oper.c_str(), privstr.c_str());
542 bool User::AddBuffer(const std::string &a)
544 std::string::size_type start = 0;
545 std::string::size_type i = a.find('\r');
548 * The old implementation here took a copy, and rfind() on \r, removing as it found them, before
549 * copying a second time onto the recvq. That's ok, but involves three copies minimum (recv() to buffer,
550 * buffer to here, here to recvq) - The new method now copies twice (recv() to buffer, buffer to recvq).
552 * We use find() instead of rfind() for clarity, however unlike the old code, our scanning of the string is
553 * contiguous: as we specify a startpoint, we never see characters we have scanned previously, making this
554 * marginally faster in cases with a number of \r hidden early on in the buffer.
557 * Start at first pos of string, find first \r, append everything in the chunk (excluding \r) to recvq. Set
558 * i ahead of the \r, search for next \r, add next chunk to buffer... repeat.
559 * -- w00t (7 may, 2008)
561 if (i == std::string::npos)
563 // no \r that we need to dance around, just add to buffer
568 // While we can find the end of a chunk to add
569 while (i != std::string::npos)
571 // Append the chunk that we have
572 recvq.append(a, start, (i - start));
574 // Start looking for the next one
576 i = a.find('\r', start);
579 if (start != a.length())
582 * This is here to catch a corner case when we get something like:
586 * in successive calls to us.
588 * Without this conditional, the 'U' on the second case will be dropped,
589 * which is most *certainly* not the behaviour we want!
592 recvq.append(a, start, (a.length() - start));
596 if (this->MyClass && !this->HasPrivPermission("users/flood/increased-buffers") && recvq.length() > this->MyClass->GetRecvqMax())
598 ServerInstance->Users->QuitUser(this, "RecvQ exceeded");
599 ServerInstance->SNO->WriteToSnoMask('a', "User %s RecvQ of %lu exceeds connect class maximum of %lu",this->nick.c_str(),(unsigned long int)recvq.length(),this->MyClass->GetRecvqMax());
606 bool User::BufferIsReady()
608 return (recvq.find('\n') != std::string::npos);
611 void User::ClearBuffer()
616 std::string User::GetBuffer()
623 /* Strip any leading \r or \n off the string.
624 * Usually there are only one or two of these,
625 * so its is computationally cheap to do.
627 std::string::iterator t = recvq.begin();
628 while (t != recvq.end() && (*t == '\r' || *t == '\n'))
634 for (std::string::iterator x = recvq.begin(); x != recvq.end(); x++)
636 /* Find the first complete line, return it as the
637 * result, and leave the recvq as whats left
641 std::string ret = std::string(recvq.begin(), x);
642 recvq.erase(recvq.begin(), x + 1);
651 ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::GetBuffer()");
656 void User::AddWriteBuf(const std::string &data)
658 if (!this->quitting && this->MyClass && !this->HasPrivPermission("users/flood/increased-buffers") && sendq.length() + data.length() > this->MyClass->GetSendqMax())
661 * Fix by brain - Set the error text BEFORE calling, because
662 * if we dont it'll recursively call here over and over again trying
663 * to repeatedly add the text to the sendq!
665 ServerInstance->Users->QuitUser(this, "SendQ exceeded");
666 ServerInstance->SNO->WriteToSnoMask('a', "User %s SendQ of %lu exceeds connect class maximum of %lu",this->nick.c_str(),(unsigned long int)sendq.length() + data.length(),this->MyClass->GetSendqMax());
670 // We still want to append data to the sendq of a quitting user,
671 // e.g. their ERROR message that says 'closing link'
673 if (data.length() > MAXBUF - 2) /* MAXBUF has a value of 514, to account for line terminators */
674 sendq.append(data.substr(0,MAXBUF - 4)).append("\r\n"); /* MAXBUF-4 = 510 */
679 // send AS MUCH OF THE USERS SENDQ as we are able to (might not be all of it)
680 void User::FlushWriteBuf()
682 if (this->fd == FD_MAGIC_NUMBER)
688 if ((sendq.length()) && (this->fd != FD_MAGIC_NUMBER))
690 int old_sendq_length = sendq.length();
691 int n_sent = ServerInstance->SE->Send(this, this->sendq.data(), this->sendq.length(), 0);
697 /* The socket buffer is full. This isnt fatal,
700 ServerInstance->SE->WantWrite(this);
704 /* Fatal error, set write error and bail */
705 ServerInstance->Users->QuitUser(this, errno ? strerror(errno) : "Write error");
711 /* advance the queue */
713 this->sendq = this->sendq.substr(n_sent);
714 /* update the user's stats counters */
715 this->bytes_out += n_sent;
717 if (n_sent != old_sendq_length)
718 this->ServerInstance->SE->WantWrite(this);
722 /* note: NOT else if! */
723 if (this->sendq.empty())
725 FOREACH_MOD(I_OnBufferFlushed,OnBufferFlushed(this));
729 void User::Oper(const std::string &opertype, const std::string &opername)
731 if (this->IsModeSet('o'))
734 this->modes[UM_OPERATOR] = 1;
735 this->WriteServ("MODE %s :+o", this->nick.c_str());
736 FOREACH_MOD(I_OnOper, OnOper(this, opertype));
738 ServerInstance->SNO->WriteToSnoMask('o',"%s (%s@%s) is now an IRC operator of type %s (using oper '%s')", this->nick.c_str(), this->ident.c_str(), this->host.c_str(), irc::Spacify(opertype.c_str()), opername.c_str());
739 this->WriteNumeric(381, "%s :You are now %s %s", this->nick.c_str(), strchr("aeiouAEIOU", *opertype.c_str()) ? "an" : "a", irc::Spacify(opertype.c_str()));
741 ServerInstance->Logs->Log("OPER", DEFAULT, "%s!%s@%s opered as type: %s", this->nick.c_str(), this->ident.c_str(), this->host.c_str(), opertype.c_str());
742 this->oper.assign(opertype, 0, 512);
743 ServerInstance->Users->all_opers.push_back(this);
746 * This might look like it's in the wrong place.
749 * For multi-network servers, we may not have the opertypes of the remote server, but we still want to mark the user as an oper of that type.
752 opertype_t::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper.c_str());
753 if (iter_opertype != ServerInstance->Config->opertypes.end())
755 if (AllowedOperCommands)
756 AllowedOperCommands->clear();
758 AllowedOperCommands = new std::set<std::string>;
761 AllowedPrivs->clear();
763 AllowedPrivs = new std::set<std::string>;
765 AllowedUserModes.reset();
766 AllowedChanModes.reset();
767 this->AllowedUserModes['o' - 'A'] = true; // Call me paranoid if you want.
769 std::string myclass, mycmd, mypriv;
770 irc::spacesepstream Classes(iter_opertype->second.c_str());
771 while (Classes.GetToken(myclass))
773 operclass_t::iterator iter_operclass = ServerInstance->Config->operclass.find(myclass.c_str());
774 if (iter_operclass != ServerInstance->Config->operclass.end())
776 /* Process commands */
777 irc::spacesepstream CommandList(iter_operclass->second.commandlist);
778 while (CommandList.GetToken(mycmd))
780 this->AllowedOperCommands->insert(mycmd);
783 irc::spacesepstream PrivList(iter_operclass->second.privs);
784 while (PrivList.GetToken(mypriv))
786 this->AllowedPrivs->insert(mypriv);
789 for (unsigned char* c = (unsigned char*)iter_operclass->second.umodelist.c_str(); *c; ++c)
793 this->AllowedUserModes.set();
797 this->AllowedUserModes[*c - 'A'] = true;
801 for (unsigned char* c = (unsigned char*)iter_operclass->second.cmodelist.c_str(); *c; ++c)
805 this->AllowedChanModes.set();
809 this->AllowedChanModes[*c - 'A'] = true;
816 FOREACH_MOD(I_OnPostOper,OnPostOper(this, opertype, opername));
824 * unset their oper type (what IS_OPER checks).
825 * note, order is important - this must come before modes as -o attempts
826 * to call UnOper. -- w00t
831 /* Remove all oper only modes from the user when the deoper - Bug #466*/
832 std::string moderemove("-");
834 for (unsigned char letter = 'A'; letter <= 'z'; letter++)
836 ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_USER);
837 if (mh && mh->NeedsOper())
838 moderemove += letter;
842 std::vector<std::string> parameters;
843 parameters.push_back(this->nick);
844 parameters.push_back(moderemove);
846 ServerInstance->Parser->CallHandler("MODE", parameters, this);
848 /* remove the user from the oper list. Will remove multiple entries as a safeguard against bug #404 */
849 ServerInstance->Users->all_opers.remove(this);
851 if (AllowedOperCommands)
853 delete AllowedOperCommands;
854 AllowedOperCommands = NULL;
863 AllowedUserModes.reset();
864 AllowedChanModes.reset();
865 this->modes[UM_OPERATOR] = 0;
869 /* adds or updates an entry in the whowas list */
870 void User::AddToWhoWas()
872 Command* whowas_command = ServerInstance->Parser->GetHandler("WHOWAS");
875 std::deque<classbase*> params;
876 params.push_back(this);
877 whowas_command->HandleInternal(WHOWAS_ADD, params);
882 * Check class restrictions
884 void User::CheckClass()
886 ConnectClass* a = this->MyClass;
888 if ((!a) || (a->type == CC_DENY))
890 ServerInstance->Users->QuitUser(this, "Unauthorised connection");
893 else if ((a->GetMaxLocal()) && (ServerInstance->Users->LocalCloneCount(this) > a->GetMaxLocal()))
895 ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (local)");
896 ServerInstance->SNO->WriteToSnoMask('a', "WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString());
899 else if ((a->GetMaxGlobal()) && (ServerInstance->Users->GlobalCloneCount(this) > a->GetMaxGlobal()))
901 ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (global)");
902 ServerInstance->SNO->WriteToSnoMask('a', "WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString());
906 this->nping = ServerInstance->Time() + a->GetPingTime() + ServerInstance->Config->dns_timeout;
909 bool User::CheckLines(bool doZline)
911 const char* check[] = { "G" , "K", (doZline) ? "Z" : NULL, NULL };
915 for (int n = 0; check[n]; ++n)
917 XLine *r = ServerInstance->XLines->MatchesLine(check[n], this);
930 void User::FullConnect()
932 ServerInstance->stats->statsConnects++;
933 this->idle_lastmsg = ServerInstance->Time();
936 * You may be thinking "wtf, we checked this in User::AddClient!" - and yes, we did, BUT.
937 * At the time AddClient is called, we don't have a resolved host, by here we probably do - which
938 * may put the user into a totally seperate class with different restrictions! so we *must* check again.
939 * Don't remove this! -- w00t
943 /* Check the password, if one is required by the user's connect class.
944 * This CANNOT be in CheckClass(), because that is called prior to PASS as well!
946 if (this->MyClass && !this->MyClass->GetPass().empty() && !this->haspassed)
948 ServerInstance->Users->QuitUser(this, "Invalid password");
952 if (this->CheckLines())
955 this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network);
956 this->WriteNumeric(RPL_WELCOME, "%s :Welcome to the %s IRC Network %s!%s@%s",this->nick.c_str(), ServerInstance->Config->Network, this->nick.c_str(), this->ident.c_str(), this->host.c_str());
957 this->WriteNumeric(RPL_YOURHOSTIS, "%s :Your host is %s, running version InspIRCd-1.2",this->nick.c_str(),ServerInstance->Config->ServerName);
958 this->WriteNumeric(RPL_SERVERCREATED, "%s :This server was created %s %s", this->nick.c_str(), __TIME__, __DATE__);
959 this->WriteNumeric(RPL_SERVERVERSION, "%s %s InspIRCd-1.2 %s %s %s", this->nick.c_str(), ServerInstance->Config->ServerName, ServerInstance->Modes->UserModeList().c_str(), ServerInstance->Modes->ChannelModeList().c_str(), ServerInstance->Modes->ParaModeList().c_str());
961 ServerInstance->Config->Send005(this);
962 this->WriteNumeric(RPL_YOURUUID, "%s %s :your unique ID", this->nick.c_str(), this->uuid.c_str());
968 if (ServerInstance->Users->unregistered_count)
969 ServerInstance->Users->unregistered_count--;
971 /* Trigger LUSERS output, give modules a chance too */
972 ModResult MOD_RESULT;
973 std::string command("LUSERS");
974 std::vector<std::string> parameters;
975 FIRST_MOD_RESULT(ServerInstance, OnPreCommand, MOD_RESULT, (command, parameters, this, true, "LUSERS"));
977 ServerInstance->CallCommandHandler(command, parameters, this);
980 * We don't set REG_ALL until triggering OnUserConnect, so some module events don't spew out stuff
981 * for a user that doesn't exist yet.
983 FOREACH_MOD(I_OnUserConnect,OnUserConnect(this));
985 this->registered = REG_ALL;
987 FOREACH_MOD(I_OnPostConnect,OnPostConnect(this));
989 ServerInstance->SNO->WriteToSnoMask('c',"Client connecting on port %d: %s!%s@%s [%s] [%s]",
990 this->GetServerPort(), this->nick.c_str(), this->ident.c_str(), this->host.c_str(), this->GetIPString(), this->fullname.c_str());
991 ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCache: Adding NEGATIVE hit for %s", this->GetIPString());
992 ServerInstance->BanCache->AddHit(this->GetIPString(), "", "");
995 /** User::UpdateNick()
996 * re-allocates a nick in the user_hash after they change nicknames,
997 * returns a pointer to the new user as it may have moved
999 User* User::UpdateNickHash(const char* New)
1001 //user_hash::iterator newnick;
1002 user_hash::iterator oldnick = ServerInstance->Users->clientlist->find(this->nick);
1004 if (!irc::string(this->nick.c_str()).compare(New))
1005 return oldnick->second;
1007 if (oldnick == ServerInstance->Users->clientlist->end())
1008 return NULL; /* doesnt exist */
1010 User* olduser = oldnick->second;
1011 ServerInstance->Users->clientlist->erase(oldnick);
1012 (*(ServerInstance->Users->clientlist))[New] = olduser;
1016 void User::InvalidateCache()
1018 /* Invalidate cache */
1019 cached_fullhost.clear();
1020 cached_hostip.clear();
1021 cached_makehost.clear();
1022 cached_fullrealhost.clear();
1025 bool User::ForceNickChange(const char* newnick)
1027 ModResult MOD_RESULT;
1029 this->InvalidateCache();
1031 this->Extend("NICKForced");
1033 FIRST_MOD_RESULT(ServerInstance, OnUserPreNick, MOD_RESULT, (this, newnick));
1035 this->Shrink("NICKForced");
1037 if (MOD_RESULT == MOD_RES_DENY)
1039 ServerInstance->stats->statsCollisions++;
1043 std::deque<classbase*> dummy;
1044 Command* nickhandler = ServerInstance->Parser->GetHandler("NICK");
1045 if (nickhandler) // wtfbbq, when would this not be here
1047 std::vector<std::string> parameters;
1048 nickhandler->HandleInternal(1, dummy);
1049 parameters.push_back(newnick);
1050 this->Extend("NICKForced");
1051 bool result = (ServerInstance->Parser->CallHandler("NICK", parameters, this) == CMD_SUCCESS);
1052 this->Shrink("NICKForced");
1053 nickhandler->HandleInternal(0, dummy);
1057 // Unreachable, we hope
1061 int User::GetServerPort()
1063 switch (this->server_sa.sa.sa_family)
1066 return htons(this->server_sa.in6.sin6_port);
1068 return htons(this->server_sa.in4.sin_port);
1073 const char* User::GetCIDRMask(int range)
1075 static char buf[44];
1078 throw "Negative range, sorry, no.";
1081 * Original code written by Oliver Lupton (Om).
1082 * Integrated by me. Thanks. :) -- w00t
1084 switch (this->client_sa.sa.sa_family)
1088 /* unsigned char s6_addr[16]; */
1090 int i, bytestozero, extrabits;
1094 throw "CIDR mask width greater than address width (IPv6, 128 bit)";
1096 /* To create the CIDR mask we want to set all the bits after 'range' bits of the address
1097 * to zero. This means the last (128 - range) bits of the address must be set to zero.
1098 * Hence this number divided by 8 is the number of whole bytes from the end of the address
1099 * which must be set to zero.
1101 bytestozero = (128 - range) / 8;
1103 /* Some of the least significant bits of the next most significant byte may also have to
1104 * be zeroed. The number of bits is the remainder of the above division.
1106 extrabits = (128 - range) % 8;
1108 /* Populate our working struct with the parts of the user's IP which are required in the
1109 * final CIDR mask. Set all the subsequent bytes to zero.
1110 * (16 - bytestozero) is the number of bytes which must be populated with actual IP data.
1112 for(i = 0; i < (16 - bytestozero); i++)
1114 v6.s6_addr[i] = client_sa.in6.sin6_addr.s6_addr[i];
1117 /* And zero all the remaining bytes in the IP. */
1123 /* And finally, zero the extra bits required. */
1124 v6.s6_addr[15 - bytestozero] = (v6.s6_addr[15 - bytestozero] >> extrabits) << extrabits;
1126 snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET6, &v6, buffer, 40), range);
1136 throw "CIDR mask width greater than address width (IPv4, 32 bit)";
1138 /* Users already have a sockaddr* pointer (User::ip) which contains either a v4 or v6 structure */
1139 v4.s_addr = client_sa.in4.sin_addr.s_addr;
1141 /* To create the CIDR mask we want to set all the bits after 'range' bits of the address
1142 * to zero. This means the last (32 - range) bits of the address must be set to zero.
1143 * This is done by shifting the value right and then back left by (32 - range) bits.
1147 v4.s_addr = ntohl(v4.s_addr);
1148 v4.s_addr = (v4.s_addr >> (32 - range)) << (32 - range);
1149 v4.s_addr = htonl(v4.s_addr);
1153 /* a range of zero would cause a 32 bit value to be shifted by 32 bits.
1154 * this has undefined behaviour, but for CIDR purposes the resulting mask
1155 * from a.b.c.d/0 is 0.0.0.0/0
1160 snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET, &v4, buffer, 16), range);
1166 return ""; // unused, but oh well
1169 std::string User::GetServerIP()
1173 irc::sockets::satoap(&server_sa, ip, port);
1177 const char* User::GetIPString()
1180 if (cachedip.empty())
1182 irc::sockets::satoap(&client_sa, cachedip, port);
1183 /* IP addresses starting with a : on irc are a Bad Thing (tm) */
1184 if (cachedip.c_str()[0] == ':')
1185 cachedip.insert(0,1,'0');
1188 return cachedip.c_str();
1191 bool User::SetClientIP(const char* sip)
1193 this->cachedip = "";
1194 return irc::sockets::aptosa(sip, 0, &client_sa);
1197 void User::Write(const std::string& text)
1199 if (!ServerInstance->SE->BoundsCheckFd(this))
1202 ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"C[%d] O %s", this->GetFd(), text.c_str());
1204 if (this->GetIOHook())
1206 /* XXX: The lack of buffering here is NOT a bug, modules implementing this interface have to
1207 * implement their own buffering mechanisms
1211 this->GetIOHook()->OnRawSocketWrite(this->fd, text.data(), text.length());
1212 this->GetIOHook()->OnRawSocketWrite(this->fd, "\r\n", 2);
1214 catch (CoreException& modexcept)
1216 ServerInstance->Logs->Log("USEROUTPUT", DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
1221 this->AddWriteBuf(text);
1222 this->AddWriteBuf("\r\n");
1224 ServerInstance->stats->statsSent += text.length() + 2;
1225 this->ServerInstance->SE->WantWrite(this);
1230 void User::Write(const char *text, ...)
1233 char textbuffer[MAXBUF];
1235 va_start(argsPtr, text);
1236 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1239 this->Write(std::string(textbuffer));
1242 void User::WriteServ(const std::string& text)
1244 this->Write(":%s %s",ServerInstance->Config->ServerName,text.c_str());
1248 * Same as Write(), except `text' is prefixed with `:server.name '.
1250 void User::WriteServ(const char* text, ...)
1253 char textbuffer[MAXBUF];
1255 va_start(argsPtr, text);
1256 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1259 this->WriteServ(std::string(textbuffer));
1263 void User::WriteNumeric(unsigned int numeric, const char* text, ...)
1266 char textbuffer[MAXBUF];
1268 va_start(argsPtr, text);
1269 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1272 this->WriteNumeric(numeric, std::string(textbuffer));
1275 void User::WriteNumeric(unsigned int numeric, const std::string &text)
1277 char textbuffer[MAXBUF];
1278 ModResult MOD_RESULT;
1280 FIRST_MOD_RESULT(ServerInstance, OnNumeric, MOD_RESULT, (this, numeric, text));
1282 if (MOD_RESULT == MOD_RES_DENY)
1285 snprintf(textbuffer,MAXBUF,":%s %03u %s",ServerInstance->Config->ServerName, numeric, text.c_str());
1286 this->Write(std::string(textbuffer));
1289 void User::WriteFrom(User *user, const std::string &text)
1293 snprintf(tb,MAXBUF,":%s %s",user->GetFullHost().c_str(),text.c_str());
1295 this->Write(std::string(tb));
1299 /* write text from an originating user to originating user */
1301 void User::WriteFrom(User *user, const char* text, ...)
1304 char textbuffer[MAXBUF];
1306 va_start(argsPtr, text);
1307 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1310 this->WriteFrom(user, std::string(textbuffer));
1314 /* write text to an destination user from a source user (e.g. user privmsg) */
1316 void User::WriteTo(User *dest, const char *data, ...)
1318 char textbuffer[MAXBUF];
1321 va_start(argsPtr, data);
1322 vsnprintf(textbuffer, MAXBUF, data, argsPtr);
1325 this->WriteTo(dest, std::string(textbuffer));
1328 void User::WriteTo(User *dest, const std::string &data)
1330 dest->WriteFrom(this, data);
1334 void User::WriteCommon(const char* text, ...)
1336 char textbuffer[MAXBUF];
1339 if (this->registered != REG_ALL)
1342 va_start(argsPtr, text);
1343 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1346 this->WriteCommon(std::string(textbuffer));
1349 void User::WriteCommon(const std::string &text)
1351 bool sent_to_at_least_one = false;
1354 if (this->registered != REG_ALL)
1360 InitializeAlreadySent(ServerInstance->SE);
1362 /* We dont want to be doing this n times, just once */
1363 snprintf(tb,MAXBUF,":%s %s",this->GetFullHost().c_str(),text.c_str());
1364 std::string out = tb;
1366 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1368 CUList* ulist = v->first->GetUsers();
1369 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1371 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1373 already_sent[i->first->fd] = uniq_id;
1374 i->first->Write(out);
1375 sent_to_at_least_one = true;
1381 * if the user was not in any channels, no users will receive the text. Make sure the user
1382 * receives their OWN message for WriteCommon
1384 if (!sent_to_at_least_one)
1386 this->Write(std::string(tb));
1391 /* write a formatted string to all users who share at least one common
1392 * channel, NOT including the source user e.g. for use in QUIT
1395 void User::WriteCommonExcept(const char* text, ...)
1397 char textbuffer[MAXBUF];
1400 va_start(argsPtr, text);
1401 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1404 this->WriteCommonExcept(std::string(textbuffer));
1407 void User::WriteCommonQuit(const std::string &normal_text, const std::string &oper_text)
1412 if (this->registered != REG_ALL)
1418 InitializeAlreadySent(ServerInstance->SE);
1420 snprintf(tb1,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),normal_text.c_str());
1421 snprintf(tb2,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),oper_text.c_str());
1422 std::string out1 = tb1;
1423 std::string out2 = tb2;
1425 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1427 CUList *ulist = v->first->GetUsers();
1428 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1430 if (this != i->first)
1432 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1434 already_sent[i->first->fd] = uniq_id;
1435 i->first->Write(IS_OPER(i->first) ? out2 : out1);
1442 void User::WriteCommonExcept(const std::string &text)
1447 if (this->registered != REG_ALL)
1453 InitializeAlreadySent(ServerInstance->SE);
1455 snprintf(tb1,MAXBUF,":%s %s",this->GetFullHost().c_str(),text.c_str());
1458 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1460 CUList *ulist = v->first->GetUsers();
1461 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1463 if (this != i->first)
1465 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1467 already_sent[i->first->fd] = uniq_id;
1468 i->first->Write(out1);
1476 void User::WriteWallOps(const std::string &text)
1478 std::string wallop("WALLOPS :");
1479 wallop.append(text);
1481 for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
1484 if (t->IsModeSet('w'))
1485 this->WriteTo(t,wallop);
1489 void User::WriteWallOps(const char* text, ...)
1491 if (!IS_LOCAL(this))
1494 char textbuffer[MAXBUF];
1497 va_start(argsPtr, text);
1498 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1501 this->WriteWallOps(std::string(textbuffer));
1504 /* return 0 or 1 depending if users u and u2 share one or more common channels
1505 * (used by QUIT, NICK etc which arent channel specific notices)
1507 * The old algorithm in 1.0 for this was relatively inefficient, iterating over
1508 * the first users channels then the second users channels within the outer loop,
1509 * therefore it was a maximum of x*y iterations (upon returning 0 and checking
1510 * all possible iterations). However this new function instead checks against the
1511 * channel's userlist in the inner loop which is a std::map<User*,User*>
1512 * and saves us time as we already know what pointer value we are after.
1513 * Don't quote me on the maths as i am not a mathematician or computer scientist,
1514 * but i believe this algorithm is now x+(log y) maximum iterations instead.
1516 bool User::SharesChannelWith(User *other)
1518 if ((!other) || (this->registered != REG_ALL) || (other->registered != REG_ALL))
1522 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1524 /* Eliminate the inner loop (which used to be ~equal in size to the outer loop)
1525 * by replacing it with a map::find which *should* be more efficient
1527 if (i->first->HasUser(other))
1533 bool User::ChangeName(const char* gecos)
1535 if (!this->fullname.compare(gecos))
1540 ModResult MOD_RESULT;
1541 FIRST_MOD_RESULT(ServerInstance, OnChangeLocalUserGECOS, MOD_RESULT, (this,gecos));
1542 if (MOD_RESULT == MOD_RES_DENY)
1544 FOREACH_MOD(I_OnChangeName,OnChangeName(this,gecos));
1546 this->fullname.assign(gecos, 0, ServerInstance->Config->Limits.MaxGecos);
1551 void User::DoHostCycle(const std::string &quitline)
1553 char buffer[MAXBUF];
1555 ModResult result = MOD_RES_PASSTHRU;
1556 FIRST_MOD_RESULT(ServerInstance, OnHostCycle, result, (this));
1558 if (result == MOD_RES_DENY)
1560 if (result == MOD_RES_PASSTHRU && !ServerInstance->Config->CycleHosts)
1566 InitializeAlreadySent(ServerInstance->SE);
1568 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1570 Channel* c = v->first;
1571 snprintf(buffer, MAXBUF, ":%s JOIN %s", GetFullHost().c_str(), c->name.c_str());
1572 std::string joinline(buffer);
1573 std::string modeline = this->ServerInstance->Modes->ModeString(this, c);
1574 if (modeline.length() > 0)
1576 snprintf(buffer, MAXBUF, ":%s MODE %s +%s", GetFullHost().c_str(), c->name.c_str(), modeline.c_str());
1580 CUList *ulist = c->GetUsers();
1581 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1584 if (u == this || !IS_LOCAL(u))
1587 if (already_sent[i->first->fd] != uniq_id)
1590 already_sent[i->first->fd] = uniq_id;
1593 if (modeline.length() > 0)
1599 bool User::ChangeDisplayedHost(const char* shost)
1606 ModResult MOD_RESULT;
1607 FIRST_MOD_RESULT(ServerInstance, OnChangeLocalUserHost, MOD_RESULT, (this,shost));
1608 if (MOD_RESULT == MOD_RES_DENY)
1612 FOREACH_MOD(I_OnChangeHost, OnChangeHost(this,shost));
1614 std::string quitstr = ":" + GetFullHost() + " QUIT :Changing host";
1616 /* Fix by Om: User::dhost is 65 long, this was truncating some long hosts */
1617 this->dhost.assign(shost, 0, 64);
1619 this->InvalidateCache();
1621 this->DoHostCycle(quitstr);
1624 this->WriteNumeric(RPL_YOURDISPLAYEDHOST, "%s %s :is now your displayed host",this->nick.c_str(),this->dhost.c_str());
1629 bool User::ChangeIdent(const char* newident)
1631 if (this->ident == newident)
1634 std::string quitstr = ":" + GetFullHost() + " QUIT :Changing ident";
1636 this->ident.assign(newident, 0, ServerInstance->Config->Limits.IdentMax + 1);
1638 this->InvalidateCache();
1640 this->DoHostCycle(quitstr);
1645 void User::SendAll(const char* command, const char* text, ...)
1647 char textbuffer[MAXBUF];
1648 char formatbuffer[MAXBUF];
1651 va_start(argsPtr, text);
1652 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1655 snprintf(formatbuffer,MAXBUF,":%s %s $* :%s", this->GetFullHost().c_str(), command, textbuffer);
1656 std::string fmt = formatbuffer;
1658 for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
1665 std::string User::ChannelList(User* source)
1669 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1671 /* If the target is the same as the sender, let them see all their channels.
1672 * If the channel is NOT private/secret OR the user shares a common channel
1673 * If the user is an oper, and the <options:operspywhois> option is set.
1675 if ((source == this) || (IS_OPER(source) && ServerInstance->Config->OperSpyWhois) || (((!i->first->IsModeSet('p')) && (!i->first->IsModeSet('s'))) || (i->first->HasUser(source))))
1677 list.append(i->first->GetPrefixChar(this)).append(i->first->name).append(" ");
1684 void User::SplitChanList(User* dest, const std::string &cl)
1687 std::ostringstream prefix;
1688 std::string::size_type start, pos, length;
1690 prefix << this->nick << " " << dest->nick << " :";
1691 line = prefix.str();
1692 int namelen = strlen(ServerInstance->Config->ServerName) + 6;
1694 for (start = 0; (pos = cl.find(' ', start)) != std::string::npos; start = pos+1)
1696 length = (pos == std::string::npos) ? cl.length() : pos;
1698 if (line.length() + namelen + length - start > 510)
1700 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1701 line = prefix.str();
1704 if(pos == std::string::npos)
1706 line.append(cl.substr(start, length - start));
1711 line.append(cl.substr(start, length - start + 1));
1717 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1722 * Sets a user's connection class.
1723 * If the class name is provided, it will be used. Otherwise, the class will be guessed using host/ip/ident/etc.
1724 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1725 * then their ip will be taken as 'priority' anyway, so for example,
1726 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1728 ConnectClass* User::SetClass(const std::string &explicit_name)
1730 ConnectClass *found = NULL;
1732 if (!IS_LOCAL(this))
1735 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Setting connect class for UID %s", this->uuid.c_str());
1737 if (!explicit_name.empty())
1739 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1741 ConnectClass* c = *i;
1743 if (explicit_name == c->name)
1745 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Explicitly set to %s", explicit_name.c_str());
1752 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1754 ConnectClass* c = *i;
1756 if (c->type == CC_ALLOW)
1758 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "ALLOW %s %d %s", c->host.c_str(), c->GetPort(), c->GetName().c_str());
1762 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "DENY %s %d %s", c->GetHost().c_str(), c->GetPort(), c->GetName().c_str());
1765 /* check if host matches.. */
1766 if (c->GetHost().length() && !InspIRCd::MatchCIDR(this->GetIPString(), c->GetHost(), NULL) &&
1767 !InspIRCd::MatchCIDR(this->host, c->GetHost(), NULL))
1769 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "No host match (for %s)", c->GetHost().c_str());
1774 * deny change if change will take class over the limit check it HERE, not after we found a matching class,
1775 * because we should attempt to find another class if this one doesn't match us. -- w00t
1777 if (c->limit && (c->RefCount >= c->limit))
1779 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "OOPS: Connect class limit (%lu) hit, denying", c->limit);
1783 /* if it requires a port ... */
1786 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Requires port (%d)", c->GetPort());
1788 /* and our port doesn't match, fail. */
1789 if (this->GetServerPort() != c->GetPort())
1791 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Port match failed (%d)", this->GetServerPort());
1796 /* we stop at the first class that meets ALL critera. */
1803 * Okay, assuming we found a class that matches.. switch us into that class, keeping refcounts up to date.
1807 /* only fiddle with refcounts if they are already in a class .. */
1810 if (found == this->MyClass) // no point changing this shit :P
1811 return this->MyClass;
1812 this->MyClass->RefCount--;
1813 ServerInstance->Logs->Log("USERS", DEBUG, "Untying user from connect class -- refcount: %lu", this->MyClass->RefCount);
1814 if (MyClass->RefCount == 0)
1818 this->MyClass = found;
1819 this->MyClass->RefCount++;
1820 ServerInstance->Logs->Log("USERS", DEBUG, "User tied to new class -- connect refcount now: %lu", this->MyClass->RefCount);
1823 return this->MyClass;
1826 /* looks up a users password for their connection class (<ALLOW>/<DENY> tags)
1827 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1828 * then their ip will be taken as 'priority' anyway, so for example,
1829 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1831 ConnectClass* User::GetClass()
1833 return this->MyClass;
1836 void User::PurgeEmptyChannels()
1838 std::vector<Channel*> to_delete;
1840 // firstly decrement the count on each channel
1841 for (UCListIter f = this->chans.begin(); f != this->chans.end(); f++)
1843 f->first->RemoveAllPrefixes(this);
1844 if (f->first->DelUser(this) == 0)
1846 /* No users left in here, mark it for deletion */
1849 to_delete.push_back(f->first);
1853 ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::PurgeEmptyChannels to_delete.push_back()");
1858 for (std::vector<Channel*>::iterator n = to_delete.begin(); n != to_delete.end(); n++)
1860 Channel* thischan = *n;
1861 chan_hash::iterator i2 = ServerInstance->chanlist->find(thischan->name);
1862 if (i2 != ServerInstance->chanlist->end())
1864 ModResult MOD_RESULT;
1865 FIRST_MOD_RESULT(ServerInstance, OnChannelPreDelete, MOD_RESULT, (i2->second));
1866 if (MOD_RESULT == MOD_RES_DENY)
1867 continue; // delete halted by module
1868 FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(i2->second));
1870 ServerInstance->chanlist->erase(i2);
1871 this->chans.erase(*n);
1878 void User::ShowMOTD()
1880 if (!ServerInstance->Config->MOTD.size())
1882 this->WriteNumeric(ERR_NOMOTD, "%s :Message of the day file is missing.",this->nick.c_str());
1885 this->WriteNumeric(RPL_MOTDSTART, "%s :%s message of the day", this->nick.c_str(), ServerInstance->Config->ServerName);
1887 for (file_cache::iterator i = ServerInstance->Config->MOTD.begin(); i != ServerInstance->Config->MOTD.end(); i++)
1888 this->WriteNumeric(RPL_MOTD, "%s :- %s",this->nick.c_str(),i->c_str());
1890 this->WriteNumeric(RPL_ENDOFMOTD, "%s :End of message of the day.", this->nick.c_str());
1893 void User::ShowRULES()
1895 if (!ServerInstance->Config->RULES.size())
1897 this->WriteNumeric(ERR_NORULES, "%s :RULES File is missing",this->nick.c_str());
1901 this->WriteNumeric(RPL_RULESTART, "%s :- %s Server Rules -",this->nick.c_str(),ServerInstance->Config->ServerName);
1903 for (file_cache::iterator i = ServerInstance->Config->RULES.begin(); i != ServerInstance->Config->RULES.end(); i++)
1904 this->WriteNumeric(RPL_RULES, "%s :- %s",this->nick.c_str(),i->c_str());
1906 this->WriteNumeric(RPL_RULESEND, "%s :End of RULES command.",this->nick.c_str());
1909 void User::HandleEvent(EventType et, int errornum)
1911 if (this->quitting) // drop everything, user is due to be quit
1917 ServerInstance->ProcessUser(this);
1920 this->FlushWriteBuf();
1923 ServerInstance->Users->QuitUser(this, errornum ? strerror(errornum) : "Client closed the connection");
1928 void User::IncreasePenalty(int increase)
1930 this->Penalty += increase;
1933 void User::DecreasePenalty(int decrease)
1935 this->Penalty -= decrease;
1938 void FakeUser::SetFakeServer(std::string name)
1941 this->server = nick.c_str();
1944 const std::string FakeUser::GetFullHost()
1946 if (*ServerInstance->Config->HideWhoisServer)
1947 return ServerInstance->Config->HideWhoisServer;
1951 const std::string FakeUser::GetFullRealHost()
1953 if (*ServerInstance->Config->HideWhoisServer)
1954 return ServerInstance->Config->HideWhoisServer;
1958 ConnectClass::ConnectClass(char t, const std::string& mask)
1959 : 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)
1963 ConnectClass::ConnectClass(char t, const std::string& mask, const ConnectClass& parent)
1964 : 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)
1968 void ConnectClass::Update(const ConnectClass* src)
1971 registration_timeout = src->registration_timeout;
1973 pingtime = src->pingtime;
1976 sendqmax = src->sendqmax;
1977 recvqmax = src->recvqmax;
1978 maxlocal = src->maxlocal;
1979 maxglobal = src->maxglobal;