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;
28 LocalIntExt User::NICKForced("NICKForced", NULL);
29 LocalStringExt User::OperQuit("OperQuit", NULL);
31 void InitializeAlreadySent(SocketEngine* SE)
33 already_sent = new unsigned long[SE->GetMaxFds()];
34 memset(already_sent, 0, SE->GetMaxFds() * sizeof(unsigned long));
37 std::string User::ProcessNoticeMasks(const char *sm)
39 bool adding = true, oldadding = false;
54 for (unsigned char d = 'A'; d <= 'z'; d++)
56 if (ServerInstance->SNO->IsEnabled(d))
58 if ((!IsNoticeMaskSet(d) && adding) || (IsNoticeMaskSet(d) && !adding))
60 if ((oldadding != adding) || (!output.length()))
61 output += (adding ? '+' : '-');
63 this->SetNoticeMask(d, adding);
72 if ((*c >= 'A') && (*c <= 'z') && (ServerInstance->SNO->IsEnabled(*c)))
74 if ((!IsNoticeMaskSet(*c) && adding) || (IsNoticeMaskSet(*c) && !adding))
76 if ((oldadding != adding) || (!output.length()))
77 output += (adding ? '+' : '-');
79 this->SetNoticeMask(*c, adding);
85 this->WriteNumeric(ERR_UNKNOWNSNOMASK, "%s %c :is unknown snomask char to me", this->nick.c_str(), *c);
94 std::string s = this->FormatNoticeMasks();
97 this->modes[UM_SNOMASK] = false;
103 void User::StartDNSLookup()
108 const char* sip = this->GetIPString();
109 UserResolver *res_reverse;
111 QueryType resolvtype = this->client_sa.sa.sa_family == AF_INET6 ? DNS_QUERY_PTR6 : DNS_QUERY_PTR4;
112 res_reverse = new UserResolver(ServerInstance, this, sip, resolvtype, cached);
114 ServerInstance->AddResolver(res_reverse, cached);
116 catch (CoreException& e)
118 ServerInstance->Logs->Log("USERS", DEBUG,"Error in resolver: %s",e.GetReason());
122 bool User::IsNoticeMaskSet(unsigned char sm)
126 return (snomasks[sm-65]);
129 void User::SetNoticeMask(unsigned char sm, bool value)
133 snomasks[sm-65] = value;
136 const char* User::FormatNoticeMasks()
138 static char data[MAXBUF];
141 for (int n = 0; n < 64; n++)
144 data[offset++] = n+65;
151 bool User::IsModeSet(unsigned char m)
155 return (modes[m-65]);
158 void User::SetMode(unsigned char m, bool value)
165 const char* User::FormatModes(bool showparameters)
167 static char data[MAXBUF];
171 for (unsigned char n = 0; n < 64; n++)
175 data[offset++] = n + 65;
176 ModeHandler* mh = ServerInstance->Modes->FindMode(n + 65, MODETYPE_USER);
177 if (showparameters && mh && mh->GetNumParams(true))
179 std::string p = mh->GetUserParameter(this);
181 params.append(" ").append(p);
186 strlcat(data, params.c_str(), MAXBUF);
190 void User::DecrementModes()
192 ServerInstance->Logs->Log("USERS", DEBUG, "DecrementModes()");
193 for (unsigned char n = 'A'; n <= 'z'; n++)
197 ServerInstance->Logs->Log("USERS", DEBUG,"DecrementModes() found mode %c", n);
198 ModeHandler* mh = ServerInstance->Modes->FindMode(n, MODETYPE_USER);
201 ServerInstance->Logs->Log("USERS", DEBUG,"Found handler %c and call ChangeCount", n);
208 User::User(InspIRCd* Instance, const std::string &uid)
210 server = Instance->FindServerNamePtr(Instance->Config->ServerName);
211 age = ServerInstance->Time();
213 lastping = signon = idle_lastmsg = nping = registered = 0;
214 bytes_in = bytes_out = cmds_in = cmds_out = 0;
215 quietquit = quitting = exempt = haspassed = dns_done = false;
217 server_sa.sa.sa_family = AF_UNSPEC;
218 client_sa.sa.sa_family = AF_UNSPEC;
222 AllowedPrivs = AllowedOperCommands = NULL;
227 uuid.assign(Instance->GetUID(), 0, UUID_LENGTH - 1);
229 uuid.assign(uid, 0, UUID_LENGTH - 1);
231 ServerInstance->Logs->Log("USERS", DEBUG,"New UUID for user: %s (%s)", uuid.c_str(), uid.empty() ? "allocated new" : "used remote");
233 user_hash::iterator finduuid = Instance->Users->uuidlist->find(uuid);
234 if (finduuid == Instance->Users->uuidlist->end())
235 (*Instance->Users->uuidlist)[uuid] = this;
237 throw CoreException("Duplicate UUID "+std::string(uuid)+" in User constructor");
242 /* NULL for remote users :) */
245 this->MyClass->RefCount--;
246 ServerInstance->Logs->Log("USERS", DEBUG, "User destructor -- connect refcount now: %lu", this->MyClass->RefCount);
247 if (MyClass->RefCount == 0)
251 if (this->AllowedOperCommands)
253 delete AllowedOperCommands;
254 AllowedOperCommands = NULL;
257 if (this->AllowedPrivs)
263 this->InvalidateCache();
264 this->DecrementModes();
266 if (client_sa.sa.sa_family != AF_UNSPEC)
267 ServerInstance->Users->RemoveCloneCounts(this);
269 ServerInstance->Users->uuidlist->erase(uuid);
272 const std::string& User::MakeHost()
274 if (!this->cached_makehost.empty())
275 return this->cached_makehost;
278 /* This is much faster than snprintf */
280 for(const char* n = ident.c_str(); *n; n++)
283 for(const char* n = host.c_str(); *n; n++)
287 this->cached_makehost.assign(nhost);
289 return this->cached_makehost;
292 const std::string& User::MakeHostIP()
294 if (!this->cached_hostip.empty())
295 return this->cached_hostip;
298 /* This is much faster than snprintf */
300 for(const char* n = ident.c_str(); *n; n++)
303 for(const char* n = this->GetIPString(); *n; n++)
307 this->cached_hostip = ihost;
309 return this->cached_hostip;
312 void User::CloseSocket()
316 ServerInstance->SE->Shutdown(this, 2);
317 ServerInstance->SE->Close(this);
321 const std::string User::GetFullHost()
323 if (!this->cached_fullhost.empty())
324 return this->cached_fullhost;
328 for(const char* n = nick.c_str(); *n; n++)
331 for(const char* n = ident.c_str(); *n; n++)
334 for(const char* n = dhost.c_str(); *n; n++)
338 this->cached_fullhost = result;
340 return this->cached_fullhost;
343 char* User::MakeWildHost()
345 static char nresult[MAXBUF];
347 *t++ = '*'; *t++ = '!';
348 *t++ = '*'; *t++ = '@';
349 for(const char* n = dhost.c_str(); *n; n++)
355 int User::ReadData(void* buffer, size_t size)
360 return read(this->fd, buffer, size);
362 return recv(this->fd, (char*)buffer, size, 0);
370 const std::string User::GetFullRealHost()
372 if (!this->cached_fullrealhost.empty())
373 return this->cached_fullrealhost;
375 char fresult[MAXBUF];
377 for(const char* n = nick.c_str(); *n; n++)
380 for(const char* n = ident.c_str(); *n; n++)
383 for(const char* n = host.c_str(); *n; n++)
387 this->cached_fullrealhost = fresult;
389 return this->cached_fullrealhost;
392 bool User::IsInvited(const irc::string &channel)
394 time_t now = ServerInstance->Time();
395 InvitedList::iterator safei;
396 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
398 if (channel == i->first)
400 if (i->second != 0 && now > i->second)
402 /* Expired invite, remove it. */
405 invites.erase(safei);
414 InvitedList* User::GetInviteList()
416 time_t now = ServerInstance->Time();
417 /* Weed out expired invites here. */
418 InvitedList::iterator safei;
419 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
421 if (i->second != 0 && now > i->second)
423 /* Expired invite, remove it. */
426 invites.erase(safei);
432 void User::InviteTo(const irc::string &channel, time_t invtimeout)
434 time_t now = ServerInstance->Time();
435 if (invtimeout != 0 && now > invtimeout) return; /* Don't add invites that are expired from the get-go. */
436 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
438 if (channel == i->first)
440 if (i->second != 0 && invtimeout > i->second)
442 i->second = invtimeout;
448 invites.push_back(std::make_pair(channel, invtimeout));
451 void User::RemoveInvite(const irc::string &channel)
453 for (InvitedList::iterator i = invites.begin(); i != invites.end(); i++)
455 if (channel == i->first)
463 bool User::HasModePermission(unsigned char mode, ModeType type)
471 if (mode < 'A' || mode > ('A' + 64)) return false;
473 return ((type == MODETYPE_USER ? AllowedUserModes : AllowedChanModes))[(mode - 'A')];
477 bool User::HasPermission(const std::string &command)
480 * users on remote servers can completely bypass all permissions based checks.
481 * This prevents desyncs when one server has different type/class tags to another.
482 * That having been said, this does open things up to the possibility of source changes
483 * allowing remote kills, etc - but if they have access to the src, they most likely have
484 * access to the conf - so it's an end to a means either way.
489 // are they even an oper at all?
495 if (!AllowedOperCommands)
498 if (AllowedOperCommands->find(command) != AllowedOperCommands->end())
500 else if (AllowedOperCommands->find("*") != AllowedOperCommands->end())
507 bool User::HasPrivPermission(const std::string &privstr, bool noisy)
511 ServerInstance->Logs->Log("PRIVS", DEBUG, "Remote (yes)");
518 this->WriteServ("NOTICE %s :You are not an oper", this->nick.c_str());
525 this->WriteServ("NOTICE %s :Privset empty(!?)", this->nick.c_str());
529 if (AllowedPrivs->find(privstr) != AllowedPrivs->end())
533 else if (AllowedPrivs->find("*") != AllowedPrivs->end())
539 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());
543 bool User::AddBuffer(const std::string &a)
545 std::string::size_type start = 0;
546 std::string::size_type i = a.find('\r');
549 * The old implementation here took a copy, and rfind() on \r, removing as it found them, before
550 * copying a second time onto the recvq. That's ok, but involves three copies minimum (recv() to buffer,
551 * buffer to here, here to recvq) - The new method now copies twice (recv() to buffer, buffer to recvq).
553 * We use find() instead of rfind() for clarity, however unlike the old code, our scanning of the string is
554 * contiguous: as we specify a startpoint, we never see characters we have scanned previously, making this
555 * marginally faster in cases with a number of \r hidden early on in the buffer.
558 * Start at first pos of string, find first \r, append everything in the chunk (excluding \r) to recvq. Set
559 * i ahead of the \r, search for next \r, add next chunk to buffer... repeat.
560 * -- w00t (7 may, 2008)
562 if (i == std::string::npos)
564 // no \r that we need to dance around, just add to buffer
569 // While we can find the end of a chunk to add
570 while (i != std::string::npos)
572 // Append the chunk that we have
573 recvq.append(a, start, (i - start));
575 // Start looking for the next one
577 i = a.find('\r', start);
580 if (start != a.length())
583 * This is here to catch a corner case when we get something like:
587 * in successive calls to us.
589 * Without this conditional, the 'U' on the second case will be dropped,
590 * which is most *certainly* not the behaviour we want!
593 recvq.append(a, start, (a.length() - start));
597 if (this->MyClass && !this->HasPrivPermission("users/flood/increased-buffers") && recvq.length() > this->MyClass->GetRecvqMax())
599 ServerInstance->Users->QuitUser(this, "RecvQ exceeded");
600 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());
607 bool User::BufferIsReady()
609 return (recvq.find('\n') != std::string::npos);
612 void User::ClearBuffer()
617 std::string User::GetBuffer()
624 /* Strip any leading \r or \n off the string.
625 * Usually there are only one or two of these,
626 * so its is computationally cheap to do.
628 std::string::iterator t = recvq.begin();
629 while (t != recvq.end() && (*t == '\r' || *t == '\n'))
635 for (std::string::iterator x = recvq.begin(); x != recvq.end(); x++)
637 /* Find the first complete line, return it as the
638 * result, and leave the recvq as whats left
642 std::string ret = std::string(recvq.begin(), x);
643 recvq.erase(recvq.begin(), x + 1);
652 ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::GetBuffer()");
657 void User::AddWriteBuf(const std::string &data)
659 if (!this->quitting && this->MyClass && !this->HasPrivPermission("users/flood/increased-buffers") && sendq.length() + data.length() > this->MyClass->GetSendqMax())
662 * Fix by brain - Set the error text BEFORE calling, because
663 * if we dont it'll recursively call here over and over again trying
664 * to repeatedly add the text to the sendq!
666 ServerInstance->Users->QuitUser(this, "SendQ exceeded");
667 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());
671 // We still want to append data to the sendq of a quitting user,
672 // e.g. their ERROR message that says 'closing link'
674 if (data.length() > MAXBUF - 2) /* MAXBUF has a value of 514, to account for line terminators */
675 sendq.append(data.substr(0,MAXBUF - 4)).append("\r\n"); /* MAXBUF-4 = 510 */
680 // send AS MUCH OF THE USERS SENDQ as we are able to (might not be all of it)
681 void User::FlushWriteBuf()
683 if (this->fd == FD_MAGIC_NUMBER)
689 if ((sendq.length()) && (this->fd != FD_MAGIC_NUMBER))
691 int old_sendq_length = sendq.length();
692 int n_sent = ServerInstance->SE->Send(this, this->sendq.data(), this->sendq.length(), 0);
698 /* The socket buffer is full. This isnt fatal,
701 ServerInstance->SE->WantWrite(this);
705 /* Fatal error, set write error and bail */
706 ServerInstance->Users->QuitUser(this, errno ? strerror(errno) : "Write error");
712 /* advance the queue */
714 this->sendq = this->sendq.substr(n_sent);
715 /* update the user's stats counters */
716 this->bytes_out += n_sent;
718 if (n_sent != old_sendq_length)
719 ServerInstance->SE->WantWrite(this);
723 /* note: NOT else if! */
724 if (this->sendq.empty())
726 FOREACH_MOD(I_OnBufferFlushed,OnBufferFlushed(this));
730 void User::Oper(const std::string &opertype, const std::string &opername)
732 if (this->IsModeSet('o'))
735 this->modes[UM_OPERATOR] = 1;
736 this->WriteServ("MODE %s :+o", this->nick.c_str());
737 FOREACH_MOD(I_OnOper, OnOper(this, opertype));
739 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());
740 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()));
742 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());
743 this->oper.assign(opertype, 0, 512);
744 ServerInstance->Users->all_opers.push_back(this);
747 * This might look like it's in the wrong place.
750 * 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.
753 opertype_t::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper.c_str());
754 if (iter_opertype != ServerInstance->Config->opertypes.end())
756 if (AllowedOperCommands)
757 AllowedOperCommands->clear();
759 AllowedOperCommands = new std::set<std::string>;
762 AllowedPrivs->clear();
764 AllowedPrivs = new std::set<std::string>;
766 AllowedUserModes.reset();
767 AllowedChanModes.reset();
768 this->AllowedUserModes['o' - 'A'] = true; // Call me paranoid if you want.
770 std::string myclass, mycmd, mypriv;
771 irc::spacesepstream Classes(iter_opertype->second.c_str());
772 while (Classes.GetToken(myclass))
774 operclass_t::iterator iter_operclass = ServerInstance->Config->operclass.find(myclass.c_str());
775 if (iter_operclass != ServerInstance->Config->operclass.end())
777 /* Process commands */
778 irc::spacesepstream CommandList(iter_operclass->second.commandlist);
779 while (CommandList.GetToken(mycmd))
781 this->AllowedOperCommands->insert(mycmd);
784 irc::spacesepstream PrivList(iter_operclass->second.privs);
785 while (PrivList.GetToken(mypriv))
787 this->AllowedPrivs->insert(mypriv);
790 for (unsigned char* c = (unsigned char*)iter_operclass->second.umodelist.c_str(); *c; ++c)
794 this->AllowedUserModes.set();
798 this->AllowedUserModes[*c - 'A'] = true;
802 for (unsigned char* c = (unsigned char*)iter_operclass->second.cmodelist.c_str(); *c; ++c)
806 this->AllowedChanModes.set();
810 this->AllowedChanModes[*c - 'A'] = true;
817 FOREACH_MOD(I_OnPostOper,OnPostOper(this, opertype, opername));
825 * unset their oper type (what IS_OPER checks).
826 * note, order is important - this must come before modes as -o attempts
827 * to call UnOper. -- w00t
832 /* Remove all oper only modes from the user when the deoper - Bug #466*/
833 std::string moderemove("-");
835 for (unsigned char letter = 'A'; letter <= 'z'; letter++)
837 ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_USER);
838 if (mh && mh->NeedsOper())
839 moderemove += letter;
843 std::vector<std::string> parameters;
844 parameters.push_back(this->nick);
845 parameters.push_back(moderemove);
847 ServerInstance->Parser->CallHandler("MODE", parameters, this);
849 /* remove the user from the oper list. Will remove multiple entries as a safeguard against bug #404 */
850 ServerInstance->Users->all_opers.remove(this);
852 if (AllowedOperCommands)
854 delete AllowedOperCommands;
855 AllowedOperCommands = NULL;
864 AllowedUserModes.reset();
865 AllowedChanModes.reset();
866 this->modes[UM_OPERATOR] = 0;
870 /* adds or updates an entry in the whowas list */
871 void User::AddToWhoWas()
873 Module* whowas = ServerInstance->Modules->Find("cmd_whowas.so");
876 WhowasRequest req(NULL, whowas, WhowasRequest::WHOWAS_ADD);
883 * Check class restrictions
885 void User::CheckClass()
887 ConnectClass* a = this->MyClass;
889 if ((!a) || (a->type == CC_DENY))
891 ServerInstance->Users->QuitUser(this, "Unauthorised connection");
894 else if ((a->GetMaxLocal()) && (ServerInstance->Users->LocalCloneCount(this) > a->GetMaxLocal()))
896 ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (local)");
897 ServerInstance->SNO->WriteToSnoMask('a', "WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString());
900 else if ((a->GetMaxGlobal()) && (ServerInstance->Users->GlobalCloneCount(this) > a->GetMaxGlobal()))
902 ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (global)");
903 ServerInstance->SNO->WriteToSnoMask('a', "WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString());
907 this->nping = ServerInstance->Time() + a->GetPingTime() + ServerInstance->Config->dns_timeout;
910 bool User::CheckLines(bool doZline)
912 const char* check[] = { "G" , "K", (doZline) ? "Z" : NULL, NULL };
916 for (int n = 0; check[n]; ++n)
918 XLine *r = ServerInstance->XLines->MatchesLine(check[n], this);
931 void User::FullConnect()
933 ServerInstance->stats->statsConnects++;
934 this->idle_lastmsg = ServerInstance->Time();
937 * You may be thinking "wtf, we checked this in User::AddClient!" - and yes, we did, BUT.
938 * At the time AddClient is called, we don't have a resolved host, by here we probably do - which
939 * may put the user into a totally seperate class with different restrictions! so we *must* check again.
940 * Don't remove this! -- w00t
944 /* Check the password, if one is required by the user's connect class.
945 * This CANNOT be in CheckClass(), because that is called prior to PASS as well!
947 if (this->MyClass && !this->MyClass->GetPass().empty() && !this->haspassed)
949 ServerInstance->Users->QuitUser(this, "Invalid password");
953 if (this->CheckLines())
956 this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network);
957 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());
958 this->WriteNumeric(RPL_YOURHOSTIS, "%s :Your host is %s, running version InspIRCd-2.0",this->nick.c_str(),ServerInstance->Config->ServerName);
959 this->WriteNumeric(RPL_SERVERCREATED, "%s :This server was created %s %s", this->nick.c_str(), __TIME__, __DATE__);
960 this->WriteNumeric(RPL_SERVERVERSION, "%s %s InspIRCd-2.0 %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());
962 ServerInstance->Config->Send005(this);
963 this->WriteNumeric(RPL_YOURUUID, "%s %s :your unique ID", this->nick.c_str(), this->uuid.c_str());
969 if (ServerInstance->Users->unregistered_count)
970 ServerInstance->Users->unregistered_count--;
972 /* Trigger LUSERS output, give modules a chance too */
973 ModResult MOD_RESULT;
974 std::string command("LUSERS");
975 std::vector<std::string> parameters;
976 FIRST_MOD_RESULT(ServerInstance, OnPreCommand, MOD_RESULT, (command, parameters, this, true, "LUSERS"));
978 ServerInstance->CallCommandHandler(command, parameters, this);
981 * We don't set REG_ALL until triggering OnUserConnect, so some module events don't spew out stuff
982 * for a user that doesn't exist yet.
984 FOREACH_MOD(I_OnUserConnect,OnUserConnect(this));
986 this->registered = REG_ALL;
988 FOREACH_MOD(I_OnPostConnect,OnPostConnect(this));
990 ServerInstance->SNO->WriteToSnoMask('c',"Client connecting on port %d: %s!%s@%s [%s] [%s]",
991 this->GetServerPort(), this->nick.c_str(), this->ident.c_str(), this->host.c_str(), this->GetIPString(), this->fullname.c_str());
992 ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCache: Adding NEGATIVE hit for %s", this->GetIPString());
993 ServerInstance->BanCache->AddHit(this->GetIPString(), "", "");
996 /** User::UpdateNick()
997 * re-allocates a nick in the user_hash after they change nicknames,
998 * returns a pointer to the new user as it may have moved
1000 User* User::UpdateNickHash(const char* New)
1002 //user_hash::iterator newnick;
1003 user_hash::iterator oldnick = ServerInstance->Users->clientlist->find(this->nick);
1005 if (!irc::string(this->nick.c_str()).compare(New))
1006 return oldnick->second;
1008 if (oldnick == ServerInstance->Users->clientlist->end())
1009 return NULL; /* doesnt exist */
1011 User* olduser = oldnick->second;
1012 ServerInstance->Users->clientlist->erase(oldnick);
1013 (*(ServerInstance->Users->clientlist))[New] = olduser;
1017 void User::InvalidateCache()
1019 /* Invalidate cache */
1020 cached_fullhost.clear();
1021 cached_hostip.clear();
1022 cached_makehost.clear();
1023 cached_fullrealhost.clear();
1026 bool User::ForceNickChange(const char* newnick)
1028 ModResult MOD_RESULT;
1030 this->InvalidateCache();
1032 NICKForced.set(this, 1);
1033 FIRST_MOD_RESULT(ServerInstance, OnUserPreNick, MOD_RESULT, (this, newnick));
1034 NICKForced.set(this, 0);
1036 if (MOD_RESULT == MOD_RES_DENY)
1038 ServerInstance->stats->statsCollisions++;
1042 std::deque<classbase*> dummy;
1043 Command* nickhandler = ServerInstance->Parser->GetHandler("NICK");
1044 if (nickhandler) // wtfbbq, when would this not be here
1046 std::vector<std::string> parameters;
1047 parameters.push_back(newnick);
1048 NICKForced.set(this, 1);
1049 bool result = (ServerInstance->Parser->CallHandler("NICK", parameters, this) == CMD_SUCCESS);
1050 NICKForced.set(this, 0);
1054 // Unreachable, we hope
1058 int User::GetServerPort()
1060 switch (this->server_sa.sa.sa_family)
1063 return htons(this->server_sa.in6.sin6_port);
1065 return htons(this->server_sa.in4.sin_port);
1070 const char* User::GetCIDRMask(int range)
1072 static char buf[44];
1075 throw "Negative range, sorry, no.";
1078 * Original code written by Oliver Lupton (Om).
1079 * Integrated by me. Thanks. :) -- w00t
1081 switch (this->client_sa.sa.sa_family)
1085 /* unsigned char s6_addr[16]; */
1087 int i, bytestozero, extrabits;
1091 throw "CIDR mask width greater than address width (IPv6, 128 bit)";
1093 /* To create the CIDR mask we want to set all the bits after 'range' bits of the address
1094 * to zero. This means the last (128 - range) bits of the address must be set to zero.
1095 * Hence this number divided by 8 is the number of whole bytes from the end of the address
1096 * which must be set to zero.
1098 bytestozero = (128 - range) / 8;
1100 /* Some of the least significant bits of the next most significant byte may also have to
1101 * be zeroed. The number of bits is the remainder of the above division.
1103 extrabits = (128 - range) % 8;
1105 /* Populate our working struct with the parts of the user's IP which are required in the
1106 * final CIDR mask. Set all the subsequent bytes to zero.
1107 * (16 - bytestozero) is the number of bytes which must be populated with actual IP data.
1109 for(i = 0; i < (16 - bytestozero); i++)
1111 v6.s6_addr[i] = client_sa.in6.sin6_addr.s6_addr[i];
1114 /* And zero all the remaining bytes in the IP. */
1120 /* And finally, zero the extra bits required. */
1121 v6.s6_addr[15 - bytestozero] = (v6.s6_addr[15 - bytestozero] >> extrabits) << extrabits;
1123 snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET6, &v6, buffer, 40), range);
1133 throw "CIDR mask width greater than address width (IPv4, 32 bit)";
1135 /* Users already have a sockaddr* pointer (User::ip) which contains either a v4 or v6 structure */
1136 v4.s_addr = client_sa.in4.sin_addr.s_addr;
1138 /* To create the CIDR mask we want to set all the bits after 'range' bits of the address
1139 * to zero. This means the last (32 - range) bits of the address must be set to zero.
1140 * This is done by shifting the value right and then back left by (32 - range) bits.
1144 v4.s_addr = ntohl(v4.s_addr);
1145 v4.s_addr = (v4.s_addr >> (32 - range)) << (32 - range);
1146 v4.s_addr = htonl(v4.s_addr);
1150 /* a range of zero would cause a 32 bit value to be shifted by 32 bits.
1151 * this has undefined behaviour, but for CIDR purposes the resulting mask
1152 * from a.b.c.d/0 is 0.0.0.0/0
1157 snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET, &v4, buffer, 16), range);
1163 return ""; // unused, but oh well
1166 std::string User::GetServerIP()
1170 irc::sockets::satoap(&server_sa, ip, port);
1174 const char* User::GetIPString()
1177 if (cachedip.empty())
1179 irc::sockets::satoap(&client_sa, cachedip, port);
1180 /* IP addresses starting with a : on irc are a Bad Thing (tm) */
1181 if (cachedip.c_str()[0] == ':')
1182 cachedip.insert(0,1,'0');
1185 return cachedip.c_str();
1188 bool User::SetClientIP(const char* sip)
1190 this->cachedip = "";
1191 return irc::sockets::aptosa(sip, 0, &client_sa);
1194 void User::Write(const std::string& text)
1196 if (!ServerInstance->SE->BoundsCheckFd(this))
1199 ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"C[%d] O %s", this->GetFd(), text.c_str());
1201 if (this->GetIOHook())
1203 /* XXX: The lack of buffering here is NOT a bug, modules implementing this interface have to
1204 * implement their own buffering mechanisms
1208 this->GetIOHook()->OnRawSocketWrite(this->fd, text.data(), text.length());
1209 this->GetIOHook()->OnRawSocketWrite(this->fd, "\r\n", 2);
1211 catch (CoreException& modexcept)
1213 ServerInstance->Logs->Log("USEROUTPUT", DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
1218 this->AddWriteBuf(text);
1219 this->AddWriteBuf("\r\n");
1221 ServerInstance->stats->statsSent += text.length() + 2;
1222 ServerInstance->SE->WantWrite(this);
1227 void User::Write(const char *text, ...)
1230 char textbuffer[MAXBUF];
1232 va_start(argsPtr, text);
1233 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1236 this->Write(std::string(textbuffer));
1239 void User::WriteServ(const std::string& text)
1241 this->Write(":%s %s",ServerInstance->Config->ServerName,text.c_str());
1245 * Same as Write(), except `text' is prefixed with `:server.name '.
1247 void User::WriteServ(const char* text, ...)
1250 char textbuffer[MAXBUF];
1252 va_start(argsPtr, text);
1253 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1256 this->WriteServ(std::string(textbuffer));
1260 void User::WriteNumeric(unsigned int numeric, const char* text, ...)
1263 char textbuffer[MAXBUF];
1265 va_start(argsPtr, text);
1266 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1269 this->WriteNumeric(numeric, std::string(textbuffer));
1272 void User::WriteNumeric(unsigned int numeric, const std::string &text)
1274 char textbuffer[MAXBUF];
1275 ModResult MOD_RESULT;
1277 FIRST_MOD_RESULT(ServerInstance, OnNumeric, MOD_RESULT, (this, numeric, text));
1279 if (MOD_RESULT == MOD_RES_DENY)
1282 snprintf(textbuffer,MAXBUF,":%s %03u %s",ServerInstance->Config->ServerName, numeric, text.c_str());
1283 this->Write(std::string(textbuffer));
1286 void User::WriteFrom(User *user, const std::string &text)
1290 snprintf(tb,MAXBUF,":%s %s",user->GetFullHost().c_str(),text.c_str());
1292 this->Write(std::string(tb));
1296 /* write text from an originating user to originating user */
1298 void User::WriteFrom(User *user, const char* text, ...)
1301 char textbuffer[MAXBUF];
1303 va_start(argsPtr, text);
1304 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1307 this->WriteFrom(user, std::string(textbuffer));
1311 /* write text to an destination user from a source user (e.g. user privmsg) */
1313 void User::WriteTo(User *dest, const char *data, ...)
1315 char textbuffer[MAXBUF];
1318 va_start(argsPtr, data);
1319 vsnprintf(textbuffer, MAXBUF, data, argsPtr);
1322 this->WriteTo(dest, std::string(textbuffer));
1325 void User::WriteTo(User *dest, const std::string &data)
1327 dest->WriteFrom(this, data);
1331 void User::WriteCommon(const char* text, ...)
1333 char textbuffer[MAXBUF];
1336 if (this->registered != REG_ALL)
1339 va_start(argsPtr, text);
1340 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1343 this->WriteCommon(std::string(textbuffer));
1346 void User::WriteCommon(const std::string &text)
1348 bool sent_to_at_least_one = false;
1351 if (this->registered != REG_ALL)
1357 InitializeAlreadySent(ServerInstance->SE);
1359 /* We dont want to be doing this n times, just once */
1360 snprintf(tb,MAXBUF,":%s %s",this->GetFullHost().c_str(),text.c_str());
1361 std::string out = tb;
1363 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1365 const UserMembList* ulist = (*v)->GetUsers();
1366 for (UserMembList::const_iterator i = ulist->begin(); i != ulist->end(); i++)
1368 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1370 already_sent[i->first->fd] = uniq_id;
1371 i->first->Write(out);
1372 sent_to_at_least_one = true;
1378 * if the user was not in any channels, no users will receive the text. Make sure the user
1379 * receives their OWN message for WriteCommon
1381 if (!sent_to_at_least_one)
1383 this->Write(std::string(tb));
1388 /* write a formatted string to all users who share at least one common
1389 * channel, NOT including the source user e.g. for use in QUIT
1392 void User::WriteCommonExcept(const char* text, ...)
1394 char textbuffer[MAXBUF];
1397 va_start(argsPtr, text);
1398 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1401 this->WriteCommonExcept(std::string(textbuffer));
1404 void User::WriteCommonQuit(const std::string &normal_text, const std::string &oper_text)
1409 if (this->registered != REG_ALL)
1415 InitializeAlreadySent(ServerInstance->SE);
1417 snprintf(tb1,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),normal_text.c_str());
1418 snprintf(tb2,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),oper_text.c_str());
1419 std::string out1 = tb1;
1420 std::string out2 = tb2;
1422 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1424 const UserMembList* ulist = (*v)->GetUsers();
1425 for (UserMembList::const_iterator i = ulist->begin(); i != ulist->end(); i++)
1427 if (this != i->first)
1429 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1431 already_sent[i->first->fd] = uniq_id;
1432 i->first->Write(IS_OPER(i->first) ? out2 : out1);
1439 void User::WriteCommonExcept(const std::string &text)
1444 if (this->registered != REG_ALL)
1450 InitializeAlreadySent(ServerInstance->SE);
1452 snprintf(tb1,MAXBUF,":%s %s",this->GetFullHost().c_str(),text.c_str());
1455 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1457 const UserMembList* ulist = (*v)->GetUsers();
1458 for (UserMembList::const_iterator i = ulist->begin(); i != ulist->end(); i++)
1460 if (this != i->first)
1462 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1464 already_sent[i->first->fd] = uniq_id;
1465 i->first->Write(out1);
1473 void User::WriteWallOps(const std::string &text)
1475 std::string wallop("WALLOPS :");
1476 wallop.append(text);
1478 for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
1481 if (t->IsModeSet('w'))
1482 this->WriteTo(t,wallop);
1486 void User::WriteWallOps(const char* text, ...)
1488 if (!IS_LOCAL(this))
1491 char textbuffer[MAXBUF];
1494 va_start(argsPtr, text);
1495 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1498 this->WriteWallOps(std::string(textbuffer));
1501 /* return 0 or 1 depending if users u and u2 share one or more common channels
1502 * (used by QUIT, NICK etc which arent channel specific notices)
1504 * The old algorithm in 1.0 for this was relatively inefficient, iterating over
1505 * the first users channels then the second users channels within the outer loop,
1506 * therefore it was a maximum of x*y iterations (upon returning 0 and checking
1507 * all possible iterations). However this new function instead checks against the
1508 * channel's userlist in the inner loop which is a std::map<User*,User*>
1509 * and saves us time as we already know what pointer value we are after.
1510 * Don't quote me on the maths as i am not a mathematician or computer scientist,
1511 * but i believe this algorithm is now x+(log y) maximum iterations instead.
1513 bool User::SharesChannelWith(User *other)
1515 if ((!other) || (this->registered != REG_ALL) || (other->registered != REG_ALL))
1519 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1521 /* Eliminate the inner loop (which used to be ~equal in size to the outer loop)
1522 * by replacing it with a map::find which *should* be more efficient
1524 if ((*i)->HasUser(other))
1530 bool User::ChangeName(const char* gecos)
1532 if (!this->fullname.compare(gecos))
1537 ModResult MOD_RESULT;
1538 FIRST_MOD_RESULT(ServerInstance, OnChangeLocalUserGECOS, MOD_RESULT, (this,gecos));
1539 if (MOD_RESULT == MOD_RES_DENY)
1541 FOREACH_MOD(I_OnChangeName,OnChangeName(this,gecos));
1543 this->fullname.assign(gecos, 0, ServerInstance->Config->Limits.MaxGecos);
1548 void User::DoHostCycle(const std::string &quitline)
1550 char buffer[MAXBUF];
1552 ModResult result = MOD_RES_PASSTHRU;
1553 FIRST_MOD_RESULT(ServerInstance, OnHostCycle, result, (this));
1555 if (result == MOD_RES_DENY)
1557 if (result == MOD_RES_PASSTHRU && !ServerInstance->Config->CycleHosts)
1563 InitializeAlreadySent(ServerInstance->SE);
1565 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1568 snprintf(buffer, MAXBUF, ":%s JOIN %s", GetFullHost().c_str(), c->name.c_str());
1569 std::string joinline(buffer);
1570 std::string modeline = ServerInstance->Modes->ModeString(this, c);
1571 if (modeline.length() > 0)
1573 snprintf(buffer, MAXBUF, ":%s MODE %s +%s", GetFullHost().c_str(), c->name.c_str(), modeline.c_str());
1577 const UserMembList *ulist = c->GetUsers();
1578 for (UserMembList::const_iterator i = ulist->begin(); i != ulist->end(); i++)
1581 if (u == this || !IS_LOCAL(u))
1584 if (already_sent[i->first->fd] != uniq_id)
1587 already_sent[i->first->fd] = uniq_id;
1590 if (modeline.length() > 0)
1596 bool User::ChangeDisplayedHost(const char* shost)
1603 ModResult MOD_RESULT;
1604 FIRST_MOD_RESULT(ServerInstance, OnChangeLocalUserHost, MOD_RESULT, (this,shost));
1605 if (MOD_RESULT == MOD_RES_DENY)
1609 FOREACH_MOD(I_OnChangeHost, OnChangeHost(this,shost));
1611 std::string quitstr = ":" + GetFullHost() + " QUIT :Changing host";
1613 /* Fix by Om: User::dhost is 65 long, this was truncating some long hosts */
1614 this->dhost.assign(shost, 0, 64);
1616 this->InvalidateCache();
1618 this->DoHostCycle(quitstr);
1621 this->WriteNumeric(RPL_YOURDISPLAYEDHOST, "%s %s :is now your displayed host",this->nick.c_str(),this->dhost.c_str());
1626 bool User::ChangeIdent(const char* newident)
1628 if (this->ident == newident)
1631 FOREACH_MOD(I_OnChangeIdent, OnChangeIdent(this,newident));
1633 std::string quitstr = ":" + GetFullHost() + " QUIT :Changing ident";
1635 this->ident.assign(newident, 0, ServerInstance->Config->Limits.IdentMax + 1);
1637 this->InvalidateCache();
1639 this->DoHostCycle(quitstr);
1644 void User::SendAll(const char* command, const char* text, ...)
1646 char textbuffer[MAXBUF];
1647 char formatbuffer[MAXBUF];
1650 va_start(argsPtr, text);
1651 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1654 snprintf(formatbuffer,MAXBUF,":%s %s $* :%s", this->GetFullHost().c_str(), command, textbuffer);
1655 std::string fmt = formatbuffer;
1657 for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
1664 std::string User::ChannelList(User* source, bool spy)
1668 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1671 /* If the target is the sender, neither +p nor +s is set, or
1672 * the channel contains the user, it is not a spy channel
1674 if (spy != (source == this || !(c->IsModeSet('p') || c->IsModeSet('s')) || c->HasUser(source)))
1675 list.append(c->GetPrefixChar(this)).append(c->name).append(" ");
1681 void User::SplitChanList(User* dest, const std::string &cl)
1684 std::ostringstream prefix;
1685 std::string::size_type start, pos, length;
1687 prefix << this->nick << " " << dest->nick << " :";
1688 line = prefix.str();
1689 int namelen = strlen(ServerInstance->Config->ServerName) + 6;
1691 for (start = 0; (pos = cl.find(' ', start)) != std::string::npos; start = pos+1)
1693 length = (pos == std::string::npos) ? cl.length() : pos;
1695 if (line.length() + namelen + length - start > 510)
1697 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1698 line = prefix.str();
1701 if(pos == std::string::npos)
1703 line.append(cl.substr(start, length - start));
1708 line.append(cl.substr(start, length - start + 1));
1714 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1719 * Sets a user's connection class.
1720 * If the class name is provided, it will be used. Otherwise, the class will be guessed using host/ip/ident/etc.
1721 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1722 * then their ip will be taken as 'priority' anyway, so for example,
1723 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1725 ConnectClass* User::SetClass(const std::string &explicit_name)
1727 ConnectClass *found = NULL;
1729 if (!IS_LOCAL(this))
1732 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Setting connect class for UID %s", this->uuid.c_str());
1734 if (!explicit_name.empty())
1736 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1738 ConnectClass* c = *i;
1740 if (explicit_name == c->name)
1742 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Explicitly set to %s", explicit_name.c_str());
1749 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1751 ConnectClass* c = *i;
1753 if (c->type == CC_ALLOW)
1755 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "ALLOW %s %d %s", c->host.c_str(), c->GetPort(), c->GetName().c_str());
1759 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "DENY %s %d %s", c->GetHost().c_str(), c->GetPort(), c->GetName().c_str());
1762 /* check if host matches.. */
1763 if (c->GetHost().length() && !InspIRCd::MatchCIDR(this->GetIPString(), c->GetHost(), NULL) &&
1764 !InspIRCd::MatchCIDR(this->host, c->GetHost(), NULL))
1766 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "No host match (for %s)", c->GetHost().c_str());
1771 * deny change if change will take class over the limit check it HERE, not after we found a matching class,
1772 * because we should attempt to find another class if this one doesn't match us. -- w00t
1774 if (c->limit && (c->RefCount >= c->limit))
1776 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "OOPS: Connect class limit (%lu) hit, denying", c->limit);
1780 /* if it requires a port ... */
1783 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Requires port (%d)", c->GetPort());
1785 /* and our port doesn't match, fail. */
1786 if (this->GetServerPort() != c->GetPort())
1788 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Port match failed (%d)", this->GetServerPort());
1793 /* we stop at the first class that meets ALL critera. */
1800 * Okay, assuming we found a class that matches.. switch us into that class, keeping refcounts up to date.
1804 /* only fiddle with refcounts if they are already in a class .. */
1807 if (found == this->MyClass) // no point changing this shit :P
1808 return this->MyClass;
1809 this->MyClass->RefCount--;
1810 ServerInstance->Logs->Log("USERS", DEBUG, "Untying user from connect class -- refcount: %lu", this->MyClass->RefCount);
1811 if (MyClass->RefCount == 0)
1815 this->MyClass = found;
1816 this->MyClass->RefCount++;
1817 ServerInstance->Logs->Log("USERS", DEBUG, "User tied to new class -- connect refcount now: %lu", this->MyClass->RefCount);
1820 return this->MyClass;
1823 /* looks up a users password for their connection class (<ALLOW>/<DENY> tags)
1824 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1825 * then their ip will be taken as 'priority' anyway, so for example,
1826 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1828 ConnectClass* User::GetClass()
1830 return this->MyClass;
1833 void User::PurgeEmptyChannels()
1835 std::vector<Channel*> to_delete;
1837 // firstly decrement the count on each channel
1838 for (UCListIter f = this->chans.begin(); f != this->chans.end(); f++)
1841 c->RemoveAllPrefixes(this);
1842 if (c->DelUser(this) == 0)
1844 /* No users left in here, mark it for deletion */
1847 to_delete.push_back(c);
1851 ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::PurgeEmptyChannels to_delete.push_back()");
1856 for (std::vector<Channel*>::iterator n = to_delete.begin(); n != to_delete.end(); n++)
1858 Channel* thischan = *n;
1859 chan_hash::iterator i2 = ServerInstance->chanlist->find(thischan->name);
1860 if (i2 != ServerInstance->chanlist->end())
1862 ModResult MOD_RESULT;
1863 FIRST_MOD_RESULT(ServerInstance, OnChannelPreDelete, MOD_RESULT, (i2->second));
1864 if (MOD_RESULT == MOD_RES_DENY)
1865 continue; // delete halted by module
1866 FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(i2->second));
1868 ServerInstance->chanlist->erase(i2);
1869 this->chans.erase(*n);
1876 void User::ShowMOTD()
1878 if (!ServerInstance->Config->MOTD.size())
1880 this->WriteNumeric(ERR_NOMOTD, "%s :Message of the day file is missing.",this->nick.c_str());
1883 this->WriteNumeric(RPL_MOTDSTART, "%s :%s message of the day", this->nick.c_str(), ServerInstance->Config->ServerName);
1885 for (file_cache::iterator i = ServerInstance->Config->MOTD.begin(); i != ServerInstance->Config->MOTD.end(); i++)
1886 this->WriteNumeric(RPL_MOTD, "%s :- %s",this->nick.c_str(),i->c_str());
1888 this->WriteNumeric(RPL_ENDOFMOTD, "%s :End of message of the day.", this->nick.c_str());
1891 void User::ShowRULES()
1893 if (!ServerInstance->Config->RULES.size())
1895 this->WriteNumeric(ERR_NORULES, "%s :RULES File is missing",this->nick.c_str());
1899 this->WriteNumeric(RPL_RULESTART, "%s :- %s Server Rules -",this->nick.c_str(),ServerInstance->Config->ServerName);
1901 for (file_cache::iterator i = ServerInstance->Config->RULES.begin(); i != ServerInstance->Config->RULES.end(); i++)
1902 this->WriteNumeric(RPL_RULES, "%s :- %s",this->nick.c_str(),i->c_str());
1904 this->WriteNumeric(RPL_RULESEND, "%s :End of RULES command.",this->nick.c_str());
1907 void User::HandleEvent(EventType et, int errornum)
1909 if (this->quitting) // drop everything, user is due to be quit
1915 ServerInstance->ProcessUser(this);
1918 this->FlushWriteBuf();
1921 ServerInstance->Users->QuitUser(this, errornum ? strerror(errornum) : "Client closed the connection");
1926 void User::IncreasePenalty(int increase)
1928 this->Penalty += increase;
1931 void User::DecreasePenalty(int decrease)
1933 this->Penalty -= decrease;
1936 void FakeUser::SetFakeServer(std::string name)
1939 this->server = nick.c_str();
1942 const std::string FakeUser::GetFullHost()
1944 if (*ServerInstance->Config->HideWhoisServer)
1945 return ServerInstance->Config->HideWhoisServer;
1949 const std::string FakeUser::GetFullRealHost()
1951 if (*ServerInstance->Config->HideWhoisServer)
1952 return ServerInstance->Config->HideWhoisServer;
1956 ConnectClass::ConnectClass(char t, const std::string& mask)
1957 : 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)
1961 ConnectClass::ConnectClass(char t, const std::string& mask, const ConnectClass& parent)
1962 : 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)
1966 void ConnectClass::Update(const ConnectClass* src)
1969 registration_timeout = src->registration_timeout;
1971 pingtime = src->pingtime;
1974 sendqmax = src->sendqmax;
1975 recvqmax = src->recvqmax;
1976 maxlocal = src->maxlocal;
1977 maxglobal = src->maxglobal;