1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 /* $Core: libIRCDusers */
18 #include "socketengine.h"
22 #include "commands/cmd_whowas.h"
24 /* XXX: Used for speeding up WriteCommon operations */
25 unsigned long uniq_id = 1;
27 static unsigned long* already_sent = NULL;
30 void InitializeAlreadySent(SocketEngine* SE)
32 already_sent = new unsigned long[SE->GetMaxFds()];
33 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);
97 void User::StartDNSLookup()
102 const char* sip = this->GetIPString(false);
104 /* Special case for 4in6 (Have i mentioned i HATE 4in6?) */
105 if (!strncmp(sip, "0::ffff:", 8))
106 res_reverse = new UserResolver(this->ServerInstance, this, sip + 8, DNS_QUERY_PTR4, cached);
108 res_reverse = new UserResolver(this->ServerInstance, this, sip, this->GetProtocolFamily() == AF_INET ? DNS_QUERY_PTR4 : DNS_QUERY_PTR6, cached);
110 this->ServerInstance->AddResolver(res_reverse, cached);
112 catch (CoreException& e)
114 ServerInstance->Logs->Log("USERS", DEBUG,"Error in resolver: %s",e.GetReason());
118 bool User::IsNoticeMaskSet(unsigned char sm)
120 return (snomasks[sm-65]);
123 void User::SetNoticeMask(unsigned char sm, bool value)
125 snomasks[sm-65] = value;
128 const char* User::FormatNoticeMasks()
130 static char data[MAXBUF];
133 for (int n = 0; n < 64; n++)
136 data[offset++] = n+65;
145 bool User::IsModeSet(unsigned char m)
147 return (modes[m-65]);
150 void User::SetMode(unsigned char m, bool value)
155 const char* User::FormatModes()
157 static char data[MAXBUF];
159 for (int n = 0; n < 64; n++)
162 data[offset++] = n+65;
168 void User::DecrementModes()
170 ServerInstance->Logs->Log("USERS", DEBUG, "DecrementModes()");
171 for (unsigned char n = 'A'; n <= 'z'; n++)
175 ServerInstance->Logs->Log("USERS", DEBUG,"DecrementModes() found mode %c", n);
176 ModeHandler* mh = ServerInstance->Modes->FindMode(n, MODETYPE_USER);
179 ServerInstance->Logs->Log("USERS", DEBUG,"Found handler %c and call ChangeCount", n);
186 User::User(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance)
188 server = (char*)Instance->FindServerNamePtr(Instance->Config->ServerName);
189 reset_due = ServerInstance->Time();
190 age = ServerInstance->Time();
192 lines_in = lastping = signon = idle_lastmsg = nping = registered = 0;
193 ChannelCount = timeout = bytes_in = bytes_out = cmds_in = cmds_out = 0;
194 quietquit = OverPenalty = ExemptFromPenalty = quitting = exempt = haspassed = dns_done = false;
199 res_forward = res_reverse = NULL;
204 AllowedUserModes = NULL;
205 AllowedChanModes = NULL;
206 AllowedOperCommands = NULL;
209 memset(modes,0,sizeof(modes));
210 memset(snomasks,0,sizeof(snomasks));
213 uuid.assign(Instance->GetUID(), 0, UUID_LENGTH - 1);
215 uuid.assign(uid, 0, UUID_LENGTH - 1);
217 ServerInstance->Logs->Log("USERS", DEBUG,"New UUID for user: %s (%s)", uuid.c_str(), uid.empty() ? "allocated new" : "used remote");
219 user_hash::iterator finduuid = Instance->Users->uuidlist->find(uuid);
220 if (finduuid == Instance->Users->uuidlist->end())
221 (*Instance->Users->uuidlist)[uuid] = this;
223 throw CoreException("Duplicate UUID "+std::string(uuid)+" in User constructor");
228 /* NULL for remote users :) */
231 this->MyClass->RefCount--;
232 ServerInstance->Logs->Log("USERS", DEBUG, "User destructor -- connect refcount now: %lu", this->MyClass->RefCount);
234 if (this->AllowedOperCommands)
236 delete AllowedOperCommands;
237 AllowedOperCommands = NULL;
240 if (this->AllowedUserModes)
242 delete[] AllowedUserModes;
243 AllowedUserModes = NULL;
246 if (this->AllowedChanModes)
248 delete[] AllowedChanModes;
249 AllowedChanModes = NULL;
252 this->InvalidateCache();
253 this->DecrementModes();
257 ServerInstance->Users->RemoveCloneCounts(this);
259 if (this->GetProtocolFamily() == AF_INET)
261 delete (sockaddr_in*)ip;
263 #ifdef SUPPORT_IP6LINKS
266 delete (sockaddr_in6*)ip;
271 ServerInstance->Users->uuidlist->erase(uuid);
274 const std::string& User::MakeHost()
276 if (!this->cached_makehost.empty())
277 return this->cached_makehost;
280 /* This is much faster than snprintf */
282 for(const char* n = ident.c_str(); *n; n++)
285 for(const char* n = host.c_str(); *n; n++)
289 this->cached_makehost.assign(nhost);
291 return this->cached_makehost;
294 const std::string& User::MakeHostIP()
296 if (!this->cached_hostip.empty())
297 return this->cached_hostip;
300 /* This is much faster than snprintf */
302 for(const char* n = ident.c_str(); *n; n++)
305 for(const char* n = this->GetIPString(); *n; n++)
309 this->cached_hostip = ihost;
311 return this->cached_hostip;
314 void User::CloseSocket()
318 ServerInstance->SE->Shutdown(this, 2);
319 ServerInstance->SE->Close(this);
323 const std::string& User::GetFullHost()
325 if (!this->cached_fullhost.empty())
326 return this->cached_fullhost;
330 for(const char* n = nick.c_str(); *n; n++)
333 for(const char* n = ident.c_str(); *n; n++)
336 for(const char* n = dhost.c_str(); *n; n++)
340 this->cached_fullhost = result;
342 return this->cached_fullhost;
345 char* User::MakeWildHost()
347 static char nresult[MAXBUF];
349 *t++ = '*'; *t++ = '!';
350 *t++ = '*'; *t++ = '@';
351 for(const char* n = dhost.c_str(); *n; n++)
357 int User::ReadData(void* buffer, size_t size)
362 return read(this->fd, buffer, size);
364 return recv(this->fd, (char*)buffer, size, 0);
372 const std::string& User::GetFullRealHost()
374 if (!this->cached_fullrealhost.empty())
375 return this->cached_fullrealhost;
377 char fresult[MAXBUF];
379 for(const char* n = nick.c_str(); *n; n++)
382 for(const char* n = ident.c_str(); *n; n++)
385 for(const char* n = host.c_str(); *n; n++)
389 this->cached_fullrealhost = fresult;
391 return this->cached_fullrealhost;
394 bool User::IsInvited(const irc::string &channel)
396 time_t now = time(NULL);
397 InvitedList::iterator safei;
398 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
400 if (channel == i->first)
402 if (i->second != 0 && now > i->second)
404 /* Expired invite, remove it. */
407 invites.erase(safei);
416 InvitedList* User::GetInviteList()
418 time_t now = time(NULL);
419 /* Weed out expired invites here. */
420 InvitedList::iterator safei;
421 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
423 if (i->second != 0 && now > i->second)
425 /* Expired invite, remove it. */
428 invites.erase(safei);
434 void User::InviteTo(const irc::string &channel, time_t invtimeout)
436 time_t now = time(NULL);
437 if (invtimeout != 0 && now > invtimeout) return; /* Don't add invites that are expired from the get-go. */
438 for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i)
440 if (channel == i->first)
442 if (i->second != 0 && invtimeout > i->second)
444 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 (!AllowedUserModes || !AllowedChanModes)
474 return ((type == MODETYPE_USER ? AllowedUserModes : AllowedChanModes))[(mode - 'A')];
478 bool User::HasPermission(const std::string &command)
481 * users on remote servers can completely bypass all permissions based checks.
482 * This prevents desyncs when one server has different type/class tags to another.
483 * That having been said, this does open things up to the possibility of source changes
484 * allowing remote kills, etc - but if they have access to the src, they most likely have
485 * access to the conf - so it's an end to a means either way.
490 // are they even an oper at all?
496 if (!AllowedOperCommands)
499 if (AllowedOperCommands->find(command) != AllowedOperCommands->end())
501 else if (AllowedOperCommands->find("*") != AllowedOperCommands->end())
507 bool User::AddBuffer(const std::string &a)
509 std::string::size_type start = 0;
510 std::string::size_type i = a.find('\r');
513 * The old implementation here took a copy, and rfind() on \r, removing as it found them, before
514 * copying a second time onto the recvq. That's ok, but involves three copies minimum (recv() to buffer,
515 * buffer to here, here to recvq) - The new method now copies twice (recv() to buffer, buffer to recvq).
517 * We use find() instead of rfind() for clarity, however unlike the old code, our scanning of the string is
518 * contiguous: as we specify a startpoint, we never see characters we have scanned previously, making this
519 * marginally faster in cases with a number of \r hidden early on in the buffer.
522 * Start at first pos of string, find first \r, append everything in the chunk (excluding \r) to recvq. Set
523 * i ahead of the \r, search for next \r, add next chunk to buffer... repeat.
524 * -- w00t (7 may, 2008)
526 if (i == std::string::npos)
528 // no \r that we need to dance around, just add to buffer
533 // While we can find the end of a chunk to add
534 while (i != std::string::npos)
536 // Append the chunk that we have
537 recvq.append(a, start, (i - start));
539 // Start looking for the next one
541 i = a.find('\r', start);
544 if (start != a.length())
547 * This is here to catch a corner case when we get something like:
551 * in successive calls to us.
553 * Without this conditional, the 'U' on the second case will be dropped,
554 * which is most *certainly* not the behaviour we want!
557 recvq.append(a, start, (a.length() - start));
561 if (this->MyClass && (recvq.length() > this->MyClass->GetRecvqMax()))
563 this->SetWriteError("RecvQ exceeded");
564 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());
571 bool User::BufferIsReady()
573 return (recvq.find('\n') != std::string::npos);
576 void User::ClearBuffer()
581 std::string User::GetBuffer()
588 /* Strip any leading \r or \n off the string.
589 * Usually there are only one or two of these,
590 * so its is computationally cheap to do.
592 std::string::iterator t = recvq.begin();
593 while (t != recvq.end() && (*t == '\r' || *t == '\n'))
599 for (std::string::iterator x = recvq.begin(); x != recvq.end(); x++)
601 /* Find the first complete line, return it as the
602 * result, and leave the recvq as whats left
606 std::string ret = std::string(recvq.begin(), x);
607 recvq.erase(recvq.begin(), x + 1);
616 ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::GetBuffer()");
621 void User::AddWriteBuf(const std::string &data)
623 if (*this->GetWriteError())
626 if (this->MyClass && (sendq.length() + data.length() > this->MyClass->GetSendqMax()))
629 * Fix by brain - Set the error text BEFORE calling, because
630 * if we dont it'll recursively call here over and over again trying
631 * to repeatedly add the text to the sendq!
633 this->SetWriteError("SendQ exceeded");
634 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());
638 if (data.length() > MAXBUF - 2) /* MAXBUF has a value of 514, to account for line terminators */
639 sendq.append(data.substr(0,MAXBUF - 4)).append("\r\n"); /* MAXBUF-4 = 510 */
644 // send AS MUCH OF THE USERS SENDQ as we are able to (might not be all of it)
645 void User::FlushWriteBuf()
649 if ((this->fd == FD_MAGIC_NUMBER) || (*this->GetWriteError()))
653 if ((sendq.length()) && (this->fd != FD_MAGIC_NUMBER))
655 int old_sendq_length = sendq.length();
656 int n_sent = ServerInstance->SE->Send(this, this->sendq.data(), this->sendq.length(), 0);
662 /* The socket buffer is full. This isnt fatal,
665 this->ServerInstance->SE->WantWrite(this);
669 /* Fatal error, set write error and bail
671 this->SetWriteError(errno ? strerror(errno) : "EOF from client");
677 /* advance the queue */
679 this->sendq = this->sendq.substr(n_sent);
680 /* update the user's stats counters */
681 this->bytes_out += n_sent;
683 if (n_sent != old_sendq_length)
684 this->ServerInstance->SE->WantWrite(this);
691 ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::FlushWriteBuf()");
694 if (this->sendq.empty())
696 FOREACH_MOD(I_OnBufferFlushed,OnBufferFlushed(this));
700 void User::SetWriteError(const std::string &error)
702 // don't try to set the error twice, its already set take the first string.
703 if (this->WriteError.empty())
704 this->WriteError = error;
707 const char* User::GetWriteError()
709 return this->WriteError.c_str();
712 void User::Oper(const std::string &opertype, const std::string &opername)
720 this->modes[UM_OPERATOR] = 1;
721 this->WriteServ("MODE %s :+o", this->nick.c_str());
722 FOREACH_MOD(I_OnOper, OnOper(this, opertype));
723 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());
724 this->oper.assign(opertype, 0, 512);
725 ServerInstance->Users->all_opers.push_back(this);
727 opertype_t::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper.c_str());
728 if (iter_opertype != ServerInstance->Config->opertypes.end())
731 if (AllowedOperCommands)
732 AllowedOperCommands->clear();
734 AllowedOperCommands = new std::map<std::string, bool>;
736 if (!AllowedChanModes)
737 AllowedChanModes = new bool[64];
739 if (!AllowedUserModes)
740 AllowedUserModes = new bool[64];
742 memset(AllowedUserModes, 0, 64);
743 memset(AllowedChanModes, 0, 64);
745 char* Classes = strdup(iter_opertype->second);
746 char* myclass = strtok_r(Classes," ",&savept);
749 operclass_t::iterator iter_operclass = ServerInstance->Config->operclass.find(myclass);
750 if (iter_operclass != ServerInstance->Config->operclass.end())
752 char* CommandList = strdup(iter_operclass->second.commandlist);
753 mycmd = strtok_r(CommandList," ",&savept2);
756 this->AllowedOperCommands->insert(std::make_pair(mycmd, true));
757 mycmd = strtok_r(NULL," ",&savept2);
760 this->AllowedUserModes['o' - 'A'] = true; // Call me paranoid if you want.
761 for (unsigned char* c = (unsigned char*)iter_operclass->second.umodelist; *c; ++c)
765 memset(this->AllowedUserModes, (int)(true), 64);
769 this->AllowedUserModes[*c - 'A'] = true;
772 for (unsigned char* c = (unsigned char*)iter_operclass->second.cmodelist; *c; ++c)
776 memset(this->AllowedChanModes, (int)(true), 64);
780 this->AllowedChanModes[*c - 'A'] = true;
784 myclass = strtok_r(NULL," ",&savept);
789 FOREACH_MOD(I_OnPostOper,OnPostOper(this, opertype, opername));
794 ServerInstance->Logs->Log("OPER", DEBUG,"Exception in User::Oper()");
802 /* Remove all oper only modes from the user when the deoper - Bug #466*/
803 std::string moderemove("-");
805 for (unsigned char letter = 'A'; letter <= 'z'; letter++)
809 ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_USER);
810 if (mh && mh->NeedsOper())
811 moderemove += letter;
815 std::vector<std::string> parameters;
816 parameters.push_back(this->nick);
817 parameters.push_back(moderemove);
819 ServerInstance->Parser->CallHandler("MODE", parameters, this);
821 /* unset their oper type (what IS_OPER checks), and remove +o */
823 this->modes[UM_OPERATOR] = 0;
825 /* remove the user from the oper list. Will remove multiple entries as a safeguard against bug #404 */
826 ServerInstance->Users->all_opers.remove(this);
828 if (AllowedOperCommands)
830 delete AllowedOperCommands;
831 AllowedOperCommands = NULL;
833 if (AllowedUserModes)
835 delete[] AllowedUserModes;
836 AllowedUserModes = NULL;
838 if (AllowedChanModes)
840 delete[] AllowedChanModes;
841 AllowedChanModes = NULL;
847 /* adds or updates an entry in the whowas list */
848 void User::AddToWhoWas()
850 Command* whowas_command = ServerInstance->Parser->GetHandler("WHOWAS");
853 std::deque<classbase*> params;
854 params.push_back(this);
855 whowas_command->HandleInternal(WHOWAS_ADD, params);
860 * Check class restrictions
862 void User::CheckClass()
864 ConnectClass* a = this->MyClass;
866 if ((!a) || (a->GetType() == CC_DENY))
868 ServerInstance->Users->QuitUser(this, "Unauthorised connection");
871 else if ((a->GetMaxLocal()) && (ServerInstance->Users->LocalCloneCount(this) > a->GetMaxLocal()))
873 ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (local)");
874 ServerInstance->SNO->WriteToSnoMask('A', "WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString());
877 else if ((a->GetMaxGlobal()) && (ServerInstance->Users->GlobalCloneCount(this) > a->GetMaxGlobal()))
879 ServerInstance->Users->QuitUser(this, "No more connections allowed from your host via this connect class (global)");
880 ServerInstance->SNO->WriteToSnoMask('A', "WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString());
884 this->nping = ServerInstance->Time() + a->GetPingTime() + ServerInstance->Config->dns_timeout;
885 this->timeout = ServerInstance->Time() + a->GetRegTimeout();
886 this->MaxChans = a->GetMaxChans();
889 bool User::CheckLines()
891 const char* check[] = { "G" , "K", NULL };
895 for (int n = 0; check[n]; ++n)
897 XLine *r = ServerInstance->XLines->MatchesLine(check[n], this);
910 void User::FullConnect()
912 ServerInstance->stats->statsConnects++;
913 this->idle_lastmsg = ServerInstance->Time();
916 * You may be thinking "wtf, we checked this in User::AddClient!" - and yes, we did, BUT.
917 * At the time AddClient is called, we don't have a resolved host, by here we probably do - which
918 * may put the user into a totally seperate class with different restrictions! so we *must* check again.
919 * Don't remove this! -- w00t
923 /* Check the password, if one is required by the user's connect class.
924 * This CANNOT be in CheckClass(), because that is called prior to PASS as well!
926 if (this->MyClass && !this->MyClass->GetPass().empty() && !this->haspassed)
928 ServerInstance->Users->QuitUser(this, "Invalid password");
932 if (this->CheckLines())
935 this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network);
936 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());
937 this->WriteNumeric(RPL_YOURHOSTIS, "%s :Your host is %s, running version InspIRCd-1.2",this->nick.c_str(),ServerInstance->Config->ServerName);
938 this->WriteNumeric(RPL_SERVERCREATED, "%s :This server was created %s %s", this->nick.c_str(), __TIME__, __DATE__);
939 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());
941 ServerInstance->Config->Send005(this);
942 this->WriteNumeric(RPL_YOURUUID, "%s %s :your unique ID", this->nick.c_str(), this->uuid.c_str());
948 if (ServerInstance->Users->unregistered_count)
949 ServerInstance->Users->unregistered_count--;
951 /* Trigger LUSERS output, give modules a chance too */
953 std::string command("LUSERS");
954 std::vector<std::string> parameters;
955 FOREACH_RESULT(I_OnPreCommand, OnPreCommand(command, parameters, this, true, "LUSERS"));
957 ServerInstance->CallCommandHandler(command, parameters, this);
960 * We don't set REG_ALL until triggering OnUserConnect, so some module events don't spew out stuff
961 * for a user that doesn't exist yet.
963 FOREACH_MOD(I_OnUserConnect,OnUserConnect(this));
965 this->registered = REG_ALL;
967 ServerInstance->PI->Introduce(this);
969 FOREACH_MOD(I_OnPostConnect,OnPostConnect(this));
971 ServerInstance->SNO->WriteToSnoMask('c',"Client connecting on port %d: %s!%s@%s [%s] [%s]", this->GetPort(), this->nick.c_str(), this->ident.c_str(), this->host.c_str(), this->GetIPString(), this->fullname.c_str());
972 ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCache: Adding NEGATIVE hit for %s", this->GetIPString());
973 ServerInstance->BanCache->AddHit(this->GetIPString(), "", "");
976 /** User::UpdateNick()
977 * re-allocates a nick in the user_hash after they change nicknames,
978 * returns a pointer to the new user as it may have moved
980 User* User::UpdateNickHash(const char* New)
982 //user_hash::iterator newnick;
983 user_hash::iterator oldnick = ServerInstance->Users->clientlist->find(this->nick);
985 if (!irc::string(this->nick.c_str()).compare(New))
986 return oldnick->second;
988 if (oldnick == ServerInstance->Users->clientlist->end())
989 return NULL; /* doesnt exist */
991 User* olduser = oldnick->second;
992 (*(ServerInstance->Users->clientlist))[New] = olduser;
993 ServerInstance->Users->clientlist->erase(oldnick);
997 void User::InvalidateCache()
999 /* Invalidate cache */
1000 cached_fullhost.clear();
1001 cached_hostip.clear();
1002 cached_makehost.clear();
1003 cached_fullrealhost.clear();
1006 bool User::ForceNickChange(const char* newnick)
1010 this->InvalidateCache();
1012 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(this, newnick));
1016 ServerInstance->stats->statsCollisions++;
1020 std::deque<classbase*> dummy;
1021 Command* nickhandler = ServerInstance->Parser->GetHandler("NICK");
1022 if (nickhandler) // wtfbbq, when would this not be here
1024 std::vector<std::string> parameters;
1025 nickhandler->HandleInternal(1, dummy);
1026 parameters.push_back(newnick);
1027 bool result = (ServerInstance->Parser->CallHandler("NICK", parameters, this) == CMD_SUCCESS);
1028 nickhandler->HandleInternal(0, dummy);
1032 // Unreachable, we hope
1036 void User::SetSockAddr(int protocol_family, const char* sip, int port)
1038 this->cachedip = "";
1040 switch (protocol_family)
1042 #ifdef SUPPORT_IP6LINKS
1045 sockaddr_in6* sin = new sockaddr_in6;
1046 sin->sin6_family = AF_INET6;
1047 sin->sin6_port = port;
1048 inet_pton(AF_INET6, sip, &sin->sin6_addr);
1049 this->ip = (sockaddr*)sin;
1055 sockaddr_in* sin = new sockaddr_in;
1056 sin->sin_family = AF_INET;
1057 sin->sin_port = port;
1058 inet_pton(AF_INET, sip, &sin->sin_addr);
1059 this->ip = (sockaddr*)sin;
1063 ServerInstance->Logs->Log("USERS",DEBUG,"Uh oh, I dont know protocol %d to be set on '%s'!", protocol_family, this->nick.c_str());
1070 if (this->ip == NULL)
1073 switch (this->GetProtocolFamily())
1075 #ifdef SUPPORT_IP6LINKS
1078 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1079 return sin->sin6_port;
1085 sockaddr_in* sin = (sockaddr_in*)this->ip;
1086 return sin->sin_port;
1095 int User::GetProtocolFamily()
1097 if (this->ip == NULL)
1100 sockaddr_in* sin = (sockaddr_in*)this->ip;
1101 return sin->sin_family;
1104 const char* User::GetCIDRMask(int range)
1106 static char buf[44];
1108 if (this->ip == NULL)
1112 throw "Negative range, sorry, no.";
1115 * Original code written by Oliver Lupton (Om).
1116 * Integrated by me. Thanks. :) -- w00t
1118 switch (this->GetProtocolFamily())
1120 #ifdef SUPPORT_IP6LINKS
1123 /* unsigned char s6_addr[16]; */
1126 int i, bytestozero, extrabits;
1130 throw "CIDR mask width greater than address width (IPv6, 128 bit)";
1132 /* Access the user's IP structure directly */
1133 sin = (sockaddr_in6*)this->ip;
1135 /* To create the CIDR mask we want to set all the bits after 'range' bits of the address
1136 * to zero. This means the last (128 - range) bits of the address must be set to zero.
1137 * Hence this number divided by 8 is the number of whole bytes from the end of the address
1138 * which must be set to zero.
1140 bytestozero = (128 - range) / 8;
1142 /* Some of the least significant bits of the next most significant byte may also have to
1143 * be zeroed. The number of bits is the remainder of the above division.
1145 extrabits = (128 - range) % 8;
1147 /* Populate our working struct with the parts of the user's IP which are required in the
1148 * final CIDR mask. Set all the subsequent bytes to zero.
1149 * (16 - bytestozero) is the number of bytes which must be populated with actual IP data.
1151 for(i = 0; i < (16 - bytestozero); i++)
1153 v6.s6_addr[i] = sin->sin6_addr.s6_addr[i];
1156 /* And zero all the remaining bytes in the IP. */
1162 /* And finally, zero the extra bits required. */
1163 v6.s6_addr[15 - bytestozero] = (v6.s6_addr[15 - bytestozero] >> extrabits) << extrabits;
1165 snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET6, &v6, buffer, 40), range);
1178 throw "CIDR mask width greater than address width (IPv4, 32 bit)";
1180 /* Users already have a sockaddr* pointer (User::ip) which contains either a v4 or v6 structure */
1181 sin = (sockaddr_in*)this->ip;
1182 v4.s_addr = sin->sin_addr.s_addr;
1184 /* To create the CIDR mask we want to set all the bits after 'range' bits of the address
1185 * to zero. This means the last (32 - range) bits of the address must be set to zero.
1186 * This is done by shifting the value right and then back left by (32 - range) bits.
1190 temp = ntohl(v4.s_addr);
1191 temp = (temp >> (32 - range)) << (32 - range);
1192 v4.s_addr = htonl(temp);
1196 /* a range of zero would cause a 32 bit value to be shifted by 32 bits.
1197 * this has undefined behaviour, but for CIDR purposes the resulting mask
1198 * from a.b.c.d/0 is 0.0.0.0/0
1203 snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET, &v4, buffer, 16), range);
1209 return ""; // unused, but oh well
1212 const char* User::GetIPString(bool translate4in6)
1214 static char buf[40];
1216 if (this->ip == NULL)
1219 if (!this->cachedip.empty())
1220 return this->cachedip.c_str();
1222 switch (this->GetProtocolFamily())
1224 #ifdef SUPPORT_IP6LINKS
1227 static char temp[1024];
1229 sockaddr_in6* sin = (sockaddr_in6*)this->ip;
1230 inet_ntop(sin->sin6_family, &sin->sin6_addr, buf, sizeof(buf));
1231 /* IP addresses starting with a : on irc are a Bad Thing (tm) */
1234 strlcpy(&temp[1], buf, sizeof(temp) - 1);
1236 if (translate4in6 && !strncmp(temp, "0::ffff:", 8))
1238 this->cachedip = temp + 8;
1242 this->cachedip = temp;
1246 this->cachedip = buf;
1253 sockaddr_in* sin = (sockaddr_in*)this->ip;
1254 inet_ntop(sin->sin_family, &sin->sin_addr, buf, sizeof(buf));
1255 this->cachedip = buf;
1263 // Unreachable, probably
1267 /** NOTE: We cannot pass a const reference to this method.
1268 * The string is changed by the workings of the method,
1269 * so that if we pass const ref, we end up copying it to
1270 * something we can change anyway. Makes sense to just let
1271 * the compiler do that copy for us.
1273 void User::Write(std::string text)
1275 if (!ServerInstance->SE->BoundsCheckFd(this))
1280 ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"C[%d] O %s", this->GetFd(), text.c_str());
1281 text.append("\r\n");
1285 ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"Exception in User::Write() std::string::append");
1291 /* XXX: The lack of buffering here is NOT a bug, modules implementing this interface have to
1292 * implement their own buffering mechanisms
1296 this->io->OnRawSocketWrite(this->fd, text.data(), text.length());
1298 catch (CoreException& modexcept)
1300 ServerInstance->Logs->Log("USEROUTPUT", DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
1305 this->AddWriteBuf(text);
1307 ServerInstance->stats->statsSent += text.length();
1308 this->ServerInstance->SE->WantWrite(this);
1313 void User::Write(const char *text, ...)
1316 char textbuffer[MAXBUF];
1318 va_start(argsPtr, text);
1319 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1322 this->Write(std::string(textbuffer));
1325 void User::WriteServ(const std::string& text)
1327 char textbuffer[MAXBUF];
1329 snprintf(textbuffer,MAXBUF,":%s %s",ServerInstance->Config->ServerName,text.c_str());
1330 this->Write(std::string(textbuffer));
1334 * Same as Write(), except `text' is prefixed with `:server.name '.
1336 void User::WriteServ(const char* text, ...)
1339 char textbuffer[MAXBUF];
1341 va_start(argsPtr, text);
1342 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1345 this->WriteServ(std::string(textbuffer));
1349 void User::WriteNumeric(unsigned int numeric, const char* text, ...)
1352 char textbuffer[MAXBUF];
1354 va_start(argsPtr, text);
1355 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1358 this->WriteNumeric(numeric, std::string(textbuffer));
1361 void User::WriteNumeric(unsigned int numeric, const std::string &text)
1363 char textbuffer[MAXBUF];
1366 FOREACH_RESULT(I_OnNumeric, OnNumeric(this, numeric, text));
1371 snprintf(textbuffer,MAXBUF,":%s %03u %s",ServerInstance->Config->ServerName, numeric, text.c_str());
1372 this->Write(std::string(textbuffer));
1375 void User::WriteFrom(User *user, const std::string &text)
1379 snprintf(tb,MAXBUF,":%s %s",user->GetFullHost().c_str(),text.c_str());
1381 this->Write(std::string(tb));
1385 /* write text from an originating user to originating user */
1387 void User::WriteFrom(User *user, const char* text, ...)
1390 char textbuffer[MAXBUF];
1392 va_start(argsPtr, text);
1393 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1396 this->WriteFrom(user, std::string(textbuffer));
1400 /* write text to an destination user from a source user (e.g. user privmsg) */
1402 void User::WriteTo(User *dest, const char *data, ...)
1404 char textbuffer[MAXBUF];
1407 va_start(argsPtr, data);
1408 vsnprintf(textbuffer, MAXBUF, data, argsPtr);
1411 this->WriteTo(dest, std::string(textbuffer));
1414 void User::WriteTo(User *dest, const std::string &data)
1416 dest->WriteFrom(this, data);
1420 void User::WriteCommon(const char* text, ...)
1422 char textbuffer[MAXBUF];
1425 if (this->registered != REG_ALL)
1428 va_start(argsPtr, text);
1429 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1432 this->WriteCommon(std::string(textbuffer));
1435 void User::WriteCommon(const std::string &text)
1437 bool sent_to_at_least_one = false;
1440 if (this->registered != REG_ALL)
1446 InitializeAlreadySent(ServerInstance->SE);
1448 /* We dont want to be doing this n times, just once */
1449 snprintf(tb,MAXBUF,":%s %s",this->GetFullHost().c_str(),text.c_str());
1450 std::string out = tb;
1452 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1454 CUList* ulist = v->first->GetUsers();
1455 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1457 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1459 already_sent[i->first->fd] = uniq_id;
1460 i->first->Write(out);
1461 sent_to_at_least_one = true;
1467 * if the user was not in any channels, no users will receive the text. Make sure the user
1468 * receives their OWN message for WriteCommon
1470 if (!sent_to_at_least_one)
1472 this->Write(std::string(tb));
1477 /* write a formatted string to all users who share at least one common
1478 * channel, NOT including the source user e.g. for use in QUIT
1481 void User::WriteCommonExcept(const char* text, ...)
1483 char textbuffer[MAXBUF];
1486 va_start(argsPtr, text);
1487 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1490 this->WriteCommonExcept(std::string(textbuffer));
1493 void User::WriteCommonQuit(const std::string &normal_text, const std::string &oper_text)
1498 if (this->registered != REG_ALL)
1504 InitializeAlreadySent(ServerInstance->SE);
1506 snprintf(tb1,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),normal_text.c_str());
1507 snprintf(tb2,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),oper_text.c_str());
1508 std::string out1 = tb1;
1509 std::string out2 = tb2;
1511 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1513 CUList *ulist = v->first->GetUsers();
1514 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1516 if (this != i->first)
1518 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1520 already_sent[i->first->fd] = uniq_id;
1521 i->first->Write(IS_OPER(i->first) ? out2 : out1);
1528 void User::WriteCommonExcept(const std::string &text)
1533 if (this->registered != REG_ALL)
1539 InitializeAlreadySent(ServerInstance->SE);
1541 snprintf(tb1,MAXBUF,":%s %s",this->GetFullHost().c_str(),text.c_str());
1544 for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
1546 CUList *ulist = v->first->GetUsers();
1547 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
1549 if (this != i->first)
1551 if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id))
1553 already_sent[i->first->fd] = uniq_id;
1554 i->first->Write(out1);
1562 void User::WriteWallOps(const std::string &text)
1564 if (!IS_LOCAL(this))
1567 std::string wallop("WALLOPS :");
1568 wallop.append(text);
1570 for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
1573 if (t->IsModeSet('w'))
1574 this->WriteTo(t,wallop);
1578 void User::WriteWallOps(const char* text, ...)
1580 if (!IS_LOCAL(this))
1583 char textbuffer[MAXBUF];
1586 va_start(argsPtr, text);
1587 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1590 this->WriteWallOps(std::string(textbuffer));
1593 /* return 0 or 1 depending if users u and u2 share one or more common channels
1594 * (used by QUIT, NICK etc which arent channel specific notices)
1596 * The old algorithm in 1.0 for this was relatively inefficient, iterating over
1597 * the first users channels then the second users channels within the outer loop,
1598 * therefore it was a maximum of x*y iterations (upon returning 0 and checking
1599 * all possible iterations). However this new function instead checks against the
1600 * channel's userlist in the inner loop which is a std::map<User*,User*>
1601 * and saves us time as we already know what pointer value we are after.
1602 * Don't quote me on the maths as i am not a mathematician or computer scientist,
1603 * but i believe this algorithm is now x+(log y) maximum iterations instead.
1605 bool User::SharesChannelWith(User *other)
1607 if ((!other) || (this->registered != REG_ALL) || (other->registered != REG_ALL))
1611 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1613 /* Eliminate the inner loop (which used to be ~equal in size to the outer loop)
1614 * by replacing it with a map::find which *should* be more efficient
1616 if (i->first->HasUser(other))
1622 bool User::ChangeName(const char* gecos)
1624 if (!this->fullname.compare(gecos))
1630 FOREACH_RESULT(I_OnChangeLocalUserGECOS,OnChangeLocalUserGECOS(this,gecos));
1633 FOREACH_MOD(I_OnChangeName,OnChangeName(this,gecos));
1635 this->fullname.assign(gecos, 0, ServerInstance->Config->Limits.MaxGecos);
1640 bool User::ChangeDisplayedHost(const char* shost)
1648 FOREACH_RESULT(I_OnChangeLocalUserHost,OnChangeLocalUserHost(this,shost));
1651 FOREACH_MOD(I_OnChangeHost,OnChangeHost(this,shost));
1654 if (this->ServerInstance->Config->CycleHosts)
1655 this->WriteCommonExcept("QUIT :Changing hosts");
1657 /* Fix by Om: User::dhost is 65 long, this was truncating some long hosts */
1658 this->dhost.assign(shost, 0, 64);
1660 this->InvalidateCache();
1662 if (this->ServerInstance->Config->CycleHosts)
1664 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1666 i->first->WriteAllExceptSender(this, false, 0, "JOIN %s", i->first->name.c_str());
1667 std::string n = this->ServerInstance->Modes->ModeString(this, i->first);
1669 i->first->WriteAllExceptSender(this, true, 0, "MODE %s +%s", i->first->name.c_str(), n.c_str());
1674 this->WriteNumeric(RPL_YOURDISPLAYEDHOST, "%s %s :is now your displayed host",this->nick.c_str(),this->dhost.c_str());
1679 bool User::ChangeIdent(const char* newident)
1681 if (!this->ident.compare(newident))
1684 if (this->ServerInstance->Config->CycleHosts)
1685 this->WriteCommonExcept("%s","QUIT :Changing ident");
1687 this->ident.assign(newident, 0, ServerInstance->Config->Limits.IdentMax + 1);
1689 this->InvalidateCache();
1691 if (this->ServerInstance->Config->CycleHosts)
1693 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1695 i->first->WriteAllExceptSender(this, false, 0, "JOIN %s", i->first->name.c_str());
1696 std::string n = this->ServerInstance->Modes->ModeString(this, i->first);
1698 i->first->WriteAllExceptSender(this, true, 0, "MODE %s +%s", i->first->name.c_str(), n.c_str());
1705 void User::SendAll(const char* command, const char* text, ...)
1707 char textbuffer[MAXBUF];
1708 char formatbuffer[MAXBUF];
1711 va_start(argsPtr, text);
1712 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
1715 snprintf(formatbuffer,MAXBUF,":%s %s $* :%s", this->GetFullHost().c_str(), command, textbuffer);
1716 std::string fmt = formatbuffer;
1718 for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
1725 std::string User::ChannelList(User* source)
1729 for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
1731 /* If the target is the same as the sender, let them see all their channels.
1732 * If the channel is NOT private/secret OR the user shares a common channel
1733 * If the user is an oper, and the <options:operspywhois> option is set.
1735 if ((source == this) || (IS_OPER(source) && ServerInstance->Config->OperSpyWhois) || (((!i->first->IsModeSet('p')) && (!i->first->IsModeSet('s'))) || (i->first->HasUser(source))))
1737 list.append(i->first->GetPrefixChar(this)).append(i->first->name).append(" ");
1744 void User::SplitChanList(User* dest, const std::string &cl)
1747 std::ostringstream prefix;
1748 std::string::size_type start, pos, length;
1750 prefix << this->nick << " " << dest->nick << " :";
1751 line = prefix.str();
1752 int namelen = strlen(ServerInstance->Config->ServerName) + 6;
1754 for (start = 0; (pos = cl.find(' ', start)) != std::string::npos; start = pos+1)
1756 length = (pos == std::string::npos) ? cl.length() : pos;
1758 if (line.length() + namelen + length - start > 510)
1760 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1761 line = prefix.str();
1764 if(pos == std::string::npos)
1766 line.append(cl.substr(start, length - start));
1771 line.append(cl.substr(start, length - start + 1));
1777 ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
1781 unsigned int User::GetMaxChans()
1783 return this->MaxChans;
1788 * Sets a user's connection class.
1789 * If the class name is provided, it will be used. Otherwise, the class will be guessed using host/ip/ident/etc.
1790 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1791 * then their ip will be taken as 'priority' anyway, so for example,
1792 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1794 ConnectClass* User::SetClass(const std::string &explicit_name)
1796 ConnectClass *found = NULL;
1798 if (!IS_LOCAL(this))
1801 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Setting connect class for UID %s", this->uuid.c_str());
1803 if (!explicit_name.empty())
1805 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1807 ConnectClass* c = *i;
1809 if (c->GetDisabled())
1810 continue; // can't possibly match, removed from conf
1812 if (explicit_name == c->GetName())
1814 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Explicitly set to %s", explicit_name.c_str());
1821 for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
1823 ConnectClass* c = *i;
1825 if (c->GetType() == CC_ALLOW)
1827 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "ALLOW %s %d %s", c->GetHost().c_str(), c->GetPort(), c->GetName().c_str());
1831 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "DENY %s %d %s", c->GetHost().c_str(), c->GetPort(), c->GetName().c_str());
1834 /* if it's disabled, we can't match this one. */
1835 if (c->GetDisabled())
1837 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Class disabled");
1841 /* check if host matches.. */
1842 if (((!match(this->GetIPString(),c->GetHost(),true)) && (!match(this->host,c->GetHost()))))
1844 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "No host match (for %s)", c->GetHost().c_str());
1849 * deny change if change will take class over the limit check it HERE, not after we found a matching class,
1850 * because we should attempt to find another class if this one doesn't match us. -- w00t
1852 if (c->limit && (c->RefCount + 1 >= c->limit))
1854 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "OOPS: Connect class limit (%lu) hit, denying", c->limit);
1858 /* if it requires a port ... */
1861 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Requires port (%d)", c->GetPort());
1863 /* and our port doesn't match, fail. */
1864 if (this->GetPort() != c->GetPort())
1866 ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Port match failed (%d)", this->GetPort());
1871 /* we stop at the first class that meets ALL critera. */
1878 * Okay, assuming we found a class that matches.. switch us into that class, keeping refcounts up to date.
1882 /* only fiddle with refcounts if they are already in a class .. */
1885 if (found == this->MyClass) // no point changing this shit :P
1886 return this->MyClass;
1887 this->MyClass->RefCount--;
1888 ServerInstance->Logs->Log("USERS", DEBUG, "Untying user from connect class -- refcount: %lu", this->MyClass->RefCount);
1891 this->MyClass = found;
1892 this->MyClass->RefCount++;
1893 ServerInstance->Logs->Log("USERS", DEBUG, "User tied to new class -- connect refcount now: %lu", this->MyClass->RefCount);
1896 return this->MyClass;
1899 /* looks up a users password for their connection class (<ALLOW>/<DENY> tags)
1900 * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
1901 * then their ip will be taken as 'priority' anyway, so for example,
1902 * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
1904 ConnectClass* User::GetClass()
1906 return this->MyClass;
1909 void User::PurgeEmptyChannels()
1911 std::vector<Channel*> to_delete;
1913 // firstly decrement the count on each channel
1914 for (UCListIter f = this->chans.begin(); f != this->chans.end(); f++)
1916 f->first->RemoveAllPrefixes(this);
1917 if (f->first->DelUser(this) == 0)
1919 /* No users left in here, mark it for deletion */
1922 to_delete.push_back(f->first);
1926 ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::PurgeEmptyChannels to_delete.push_back()");
1931 for (std::vector<Channel*>::iterator n = to_delete.begin(); n != to_delete.end(); n++)
1933 Channel* thischan = *n;
1934 chan_hash::iterator i2 = ServerInstance->chanlist->find(thischan->name);
1935 if (i2 != ServerInstance->chanlist->end())
1937 FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(i2->second));
1939 ServerInstance->chanlist->erase(i2);
1940 this->chans.erase(*n);
1947 void User::ShowMOTD()
1949 if (!ServerInstance->Config->MOTD.size())
1951 this->WriteNumeric(ERR_NOMOTD, "%s :Message of the day file is missing.",this->nick.c_str());
1954 this->WriteNumeric(RPL_MOTDSTART, "%s :%s message of the day", this->nick.c_str(), ServerInstance->Config->ServerName);
1956 for (file_cache::iterator i = ServerInstance->Config->MOTD.begin(); i != ServerInstance->Config->MOTD.end(); i++)
1957 this->WriteNumeric(RPL_MOTD, "%s :- %s",this->nick.c_str(),i->c_str());
1959 this->WriteNumeric(RPL_ENDOFMOTD, "%s :End of message of the day.", this->nick.c_str());
1962 void User::ShowRULES()
1964 if (!ServerInstance->Config->RULES.size())
1966 this->WriteNumeric(ERR_NORULES, "%s :RULES File is missing",this->nick.c_str());
1970 this->WriteNumeric(RPL_RULESTART, "%s :- %s Server Rules -",this->nick.c_str(),ServerInstance->Config->ServerName);
1972 for (file_cache::iterator i = ServerInstance->Config->RULES.begin(); i != ServerInstance->Config->RULES.end(); i++)
1973 this->WriteNumeric(RPL_RULES, "%s :- %s",this->nick.c_str(),i->c_str());
1975 this->WriteNumeric(RPL_RULESEND, "%s :End of RULES command.",this->nick.c_str());
1978 void User::HandleEvent(EventType et, int errornum)
1980 if (this->quitting) // drop everything, user is due to be quit
1983 /* WARNING: May delete this user! */
1984 int thisfd = this->GetFd();
1991 ServerInstance->ProcessUser(this);
1994 this->FlushWriteBuf();
1997 /** This should be safe, but dont DARE do anything after it -- Brain */
1998 this->SetWriteError(errornum ? strerror(errornum) : "EOF from client");
2004 ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::HandleEvent intercepted");
2007 /* If the user has raised an error whilst being processed, quit them now we're safe to */
2008 if ((ServerInstance->SE->GetRef(thisfd) == this))
2010 if (!WriteError.empty())
2012 ServerInstance->Users->QuitUser(this, GetWriteError());
2017 void User::SetOperQuit(const std::string &oquit)
2019 operquitmsg = oquit;
2022 const std::string& User::GetOperQuit()
2027 void User::IncreasePenalty(int increase)
2029 this->Penalty += increase;
2032 void User::DecreasePenalty(int decrease)
2034 this->Penalty -= decrease;
2045 bool VisData::VisibleTo(User* user)