2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
6 * Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
7 * Copyright (C) 2003-2007 Craig Edwards <craigedwards@brainbox.cc>
8 * Copyright (C) 2007 Burlex <???@???>
9 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
11 * This file is part of InspIRCd. InspIRCd is free software: you can
12 * redistribute it and/or modify it under the terms of the GNU General Public
13 * License as published by the Free Software Foundation, version 2.
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 #include "inspsocket.h"
33 /** connect class types
40 /** named connect block (for opers, etc) */
44 /** RFC1459 channel modes
47 /** +s: Server notice mask */
48 UM_SNOMASK = 's' - 65,
50 UM_WALLOPS = 'w' - 65,
52 UM_INVISIBLE = 'i' - 65,
54 UM_OPERATOR = 'o' - 65
57 /** Registration state of a user, e.g.
58 * have they sent USER, NICK, PASS yet?
60 enum RegistrationState {
62 #ifndef WIN32 // Burlex: This is already defined in win32, luckily it is still 0.
63 REG_NONE = 0, /* Has sent nothing */
66 REG_USER = 1, /* Has sent USER */
67 REG_NICK = 2, /* Has sent NICK */
68 REG_NICKUSER = 3, /* Bitwise combination of REG_NICK and REG_USER */
69 REG_ALL = 7 /* REG_NICKUSER plus next bit along */
78 /** Holds information relevent to <connect allow> and <connect deny> tags in the config file.
80 struct CoreExport ConnectClass : public refcountbase
82 reference<ConfigTag> config;
83 /** Type of line, either CC_ALLOW or CC_DENY
87 /** True if this class uses fake lag to manage flood, false if it kills */
90 /** Connect class name
94 /** Max time to register the connection in seconds
96 unsigned int registration_timeout;
98 /** Host mask for this line
102 /** Number of seconds between pings for this line
104 unsigned int pingtime;
106 /** Maximum size of sendq for users in this class (bytes)
107 * Users cannot send commands if they go over this limit
109 unsigned long softsendqmax;
111 /** Maximum size of sendq for users in this class (bytes)
112 * Users are killed if they go over this limit
114 unsigned long hardsendqmax;
116 /** Maximum size of recvq for users in this class (bytes)
118 unsigned long recvqmax;
120 /** Seconds worth of penalty before penalty system activates
122 unsigned int penaltythreshold;
124 /** Maximum rate of commands (units: millicommands per second) */
125 unsigned int commandrate;
127 /** Local max when connecting by this connection class
129 unsigned long maxlocal;
131 /** Global max when connecting by this connection class
133 unsigned long maxglobal;
135 /** True if max connections for this class is hit and a warning is wanted
139 /** Max channels for this class
141 unsigned int maxchans;
143 /** How many users may be in this connect class before they are refused?
144 * (0 = no limit = default)
148 /** Create a new connect class with no settings.
150 ConnectClass(ConfigTag* tag, char type, const std::string& mask);
151 /** Create a new connect class with inherited settings.
153 ConnectClass(ConfigTag* tag, char type, const std::string& mask, const ConnectClass& parent);
155 /** Update the settings in this block to match the given block */
156 void Update(const ConnectClass* newSettings);
158 const std::string& GetName() { return name; }
159 const std::string& GetHost() { return host; }
161 /** Returns the registration timeout
163 time_t GetRegTimeout()
165 return (registration_timeout ? registration_timeout : 90);
168 /** Returns the ping frequency
170 unsigned int GetPingTime()
172 return (pingtime ? pingtime : 120);
175 /** Returns the maximum sendq value (soft limit)
176 * Note that this is in addition to internal OS buffers
178 unsigned long GetSendqSoftMax()
180 return (softsendqmax ? softsendqmax : 4096);
183 /** Returns the maximum sendq value (hard limit)
185 unsigned long GetSendqHardMax()
187 return (hardsendqmax ? hardsendqmax : 0x100000);
190 /** Returns the maximum recvq value
192 unsigned long GetRecvqMax()
194 return (recvqmax ? recvqmax : 4096);
197 /** Returns the penalty threshold value
199 unsigned int GetPenaltyThreshold()
201 return penaltythreshold ? penaltythreshold : (fakelag ? 10 : 20);
204 unsigned int GetCommandRate()
206 return commandrate ? commandrate : 1000;
209 /** Return the maximum number of local sessions
211 unsigned long GetMaxLocal()
216 /** Returns the maximum number of global sessions
218 unsigned long GetMaxGlobal()
224 /** Holds all information about a user
225 * This class stores all information about a user connected to the irc server. Everything about a
226 * connection is stored here primarily, from the user's socket ID (file descriptor) through to the
227 * user's nickname and hostname.
229 class CoreExport User : public Extensible
232 /** Cached nick!ident@dhost value using the displayed hostname
234 std::string cached_fullhost;
236 /** Cached ident@ip value using the real IP address
238 std::string cached_hostip;
240 /** Cached ident@realhost value using the real hostname
242 std::string cached_makehost;
244 /** Cached nick!ident@realhost value using the real hostname
246 std::string cached_fullrealhost;
248 /** Set by GetIPString() to avoid constantly re-grabbing IP via sockets voodoo.
250 std::string cachedip;
254 /** Hostname of connection.
255 * This should be valid as per RFC1035.
259 /** Time that the object was instantiated (used for TS calculation etc)
263 /** Time the connection was created, set in the constructor. This
264 * may be different from the time the user's classbase object was
269 /** Time that the connection last sent a message, used to calculate idle time
273 /** Client address that the user is connected from.
274 * Do not modify this value directly, use SetClientIP() to change it.
275 * Port is not valid for remote users.
277 irc::sockets::sockaddrs client_sa;
279 /** The users nickname.
280 * An invalid nickname indicates an unregistered connection prior to the NICK command.
281 * Use InspIRCd::IsNick() to validate nicknames.
285 /** The user's unique identifier.
286 * This is the unique identifier which the user has across the network.
288 const std::string uuid;
290 /** The users ident reply.
291 * Two characters are added to the user-defined limit to compensate for the tilde etc.
295 /** The host displayed to non-opers (used for cloaking etc).
296 * This usually matches the value of User::host.
300 /** The users full name (GECOS).
302 std::string fullname;
304 /** The user's mode list.
305 * NOT a null terminated string.
307 * Much love to the STL for giving us an easy to use bitset, saving us RAM.
308 * if (modes[modeletter-65]) is set, then the mode is
309 * set, for example, to work out if mode +s is set, we check the field
310 * User::modes['s'-65] != 0.
311 * The following RFC characters o, w, s, i have constants defined via an
312 * enum, such as UM_SERVERNOTICE and UM_OPETATOR.
314 std::bitset<64> modes;
316 /** What snomasks are set on this user.
317 * This functions the same as the above modes.
319 std::bitset<64> snomasks;
321 /** Channels this user is on
325 /** The server the user is connected to.
327 const std::string server;
329 /** The user's away message.
330 * If this string is empty, the user is not marked as away.
334 /** Time the user last went away.
335 * This is ONLY RELIABLE if user IS_AWAY()!
339 /** The oper type they logged in as, if they are an oper.
341 reference<OperInfo> oper;
343 /** Used by User to indicate the registration status of the connection
344 * It is a bitfield of the REG_NICK, REG_USER and REG_ALL bits to indicate
345 * the connection state.
347 unsigned int registered:3;
349 /** True when DNS lookups are completed.
350 * The UserResolver classes res_forward and res_reverse will
351 * set this value once they complete.
353 unsigned int dns_done:1;
355 /** Whether or not to send an snotice about this user's quitting
357 unsigned int quietquit:1;
359 /** If this is set to true, then all socket operations for the user
360 * are dropped into the bit-bucket.
361 * This value is set by QuitUser, and is not needed seperately from that call.
362 * Please note that setting this value alone will NOT cause the user to quit.
364 unsigned int quitting:1;
366 /** Recursion fix: user is out of SendQ and will be quit as soon as possible.
367 * This can't be handled normally because QuitUser itself calls Write on other
368 * users, which could trigger their SendQ to overrun.
370 unsigned int quitting_sendq:1;
372 /** This is true if the user matched an exception (E:Line). It is used to save time on ban checks.
374 unsigned int exempt:1;
376 /** has the user responded to their previous ping?
378 unsigned int lastping:1;
380 /** What type of user is this? */
381 const unsigned int usertype:2;
383 /** Get client IP string from sockaddr, using static internal buffer
384 * @return The IP string
386 const char* GetIPString();
388 /** Get CIDR mask, using default range, for this user
390 irc::sockets::cidr_mask GetCIDRMask();
392 /** Sets the client IP for this user
393 * @return true if the conversion was successful
395 bool SetClientIP(const char* sip);
397 /** Sets the client IP for this user
398 * @return true always
400 bool SetClientIP(irc::sockets::sockaddrs *sa);
403 * @throw CoreException if the UID allocated to the user already exists
405 User(const std::string &uid, const std::string& srv, int objtype);
407 /** Check if the user matches a G or K line, and disconnect them if they do.
408 * @param doZline True if ZLines should be checked (if IP has changed since initial connect)
409 * Returns true if the user matched a ban, false else.
411 bool CheckLines(bool doZline = false);
413 /** Returns the full displayed host of the user
414 * This member function returns the hostname of the user as seen by other users
415 * on the server, in nick!ident&at;host form.
416 * @return The full masked host of the user
418 virtual const std::string& GetFullHost();
420 /** Returns the full real host of the user
421 * This member function returns the hostname of the user as seen by other users
422 * on the server, in nick!ident&at;host form. If any form of hostname cloaking is in operation,
423 * e.g. through a module, then this method will ignore it and return the true hostname.
424 * @return The full real host of the user
426 virtual const std::string& GetFullRealHost();
428 /** This clears any cached results that are used for GetFullRealHost() etc.
429 * The results of these calls are cached as generating them can be generally expensive.
431 void InvalidateCache();
433 /** Create a displayable mode string for this users snomasks
434 * @return The notice mask character sequence
436 const char* FormatNoticeMasks();
438 /** Process a snomask modifier string, e.g. +abc-de
439 * @param sm A sequence of notice mask characters
440 * @return The cleaned mode sequence which can be output,
441 * e.g. in the above example if masks c and e are not
442 * valid, this function will return +ab-d
444 std::string ProcessNoticeMasks(const char *sm);
446 /** Returns true if a notice mask is set
447 * @param sm A notice mask character to check
448 * @return True if the notice mask is set
450 bool IsNoticeMaskSet(unsigned char sm);
452 /** Changed a specific notice mask value
453 * @param sm The server notice mask to change
454 * @param value An on/off value for this mask
456 void SetNoticeMask(unsigned char sm, bool value);
458 /** Create a displayable mode string for this users umodes
459 * @param The mode string
461 const char* FormatModes(bool showparameters = false);
463 /** Returns true if a specific mode is set
464 * @param m The user mode
465 * @return True if the mode is set
467 bool IsModeSet(unsigned char m);
469 /** Set a specific usermode to on or off
470 * @param m The user mode
471 * @param value On or off setting of the mode
473 void SetMode(unsigned char m, bool value);
475 /** Returns true or false for if a user can execute a privilaged oper command.
476 * This is done by looking up their oper type from User::oper, then referencing
477 * this to their oper classes and checking the commands they can execute.
478 * @param command A command (should be all CAPS)
479 * @return True if this user can execute the command
481 virtual bool HasPermission(const std::string &command);
483 /** Returns true if a user has a given permission.
484 * This is used to check whether or not users may perform certain actions which admins may not wish to give to
485 * all operators, yet are not commands. An example might be oper override, mass messaging (/notice $*), etc.
487 * @param privstr The priv to chec, e.g. "users/override/topic". These are loaded free-form from the config file.
488 * @param noisy If set to true, the user is notified that they do not have the specified permission where applicable. If false, no notification is sent.
489 * @return True if this user has the permission in question.
491 virtual bool HasPrivPermission(const std::string &privstr, bool noisy = false);
493 /** Returns true or false if a user can set a privileged user or channel mode.
494 * This is done by looking up their oper type from User::oper, then referencing
495 * this to their oper classes, and checking the modes they can set.
496 * @param mode The mode the check
497 * @param type ModeType (MODETYPE_CHANNEL or MODETYPE_USER).
498 * @return True if the user can set or unset this mode.
500 virtual bool HasModePermission(unsigned char mode, ModeType type);
502 /** Creates a wildcard host.
503 * Takes a buffer to use and fills the given buffer with the host in the format *!*@hostname
504 * @return The wildcarded hostname in *!*@host form
506 char* MakeWildHost();
508 /** Creates a usermask with real host.
509 * Takes a buffer to use and fills the given buffer with the hostmask in the format user@host
510 * @return the usermask in the format user@host
512 const std::string& MakeHost();
514 /** Creates a usermask with real ip.
515 * Takes a buffer to use and fills the given buffer with the ipmask in the format user@ip
516 * @return the usermask in the format user@ip
518 const std::string& MakeHostIP();
520 /** Add the user to WHOWAS system
524 /** Oper up the user using the given opertype.
525 * This will also give the +o usermode.
527 void Oper(OperInfo* info);
529 /** Force a nickname change.
530 * If the nickname change fails (for example, because the nick in question
531 * already exists) this function will return false, and you must then either
532 * output an error message, or quit the user for nickname collision.
533 * @param newnick The nickname to change to
534 * @return True if the nickchange was successful.
536 inline bool ForceNickChange(const char* newnick) { return ChangeNick(newnick, true); }
539 * This will clear the +o usermode and unset the user's oper type
543 /** Write text to this user, appending CR/LF. Works on local users only.
544 * @param text A std::string to send to the user
546 virtual void Write(const std::string &text);
548 /** Write text to this user, appending CR/LF.
549 * Works on local users only.
550 * @param text The format string for text to send to the user
551 * @param ... POD-type format arguments
553 virtual void Write(const char *text, ...) CUSTOM_PRINTF(2, 3);
555 /** Write text to this user, appending CR/LF and prepending :server.name
556 * Works on local users only.
557 * @param text A std::string to send to the user
559 void WriteServ(const std::string& text);
561 /** Write text to this user, appending CR/LF and prepending :server.name
562 * Works on local users only.
563 * @param text The format string for text to send to the user
564 * @param ... POD-type format arguments
566 void WriteServ(const char* text, ...) CUSTOM_PRINTF(2, 3);
568 void WriteNumeric(unsigned int numeric, const char* text, ...) CUSTOM_PRINTF(3, 4);
570 void WriteNumeric(unsigned int numeric, const std::string &text);
572 /** Write text to this user, appending CR/LF and prepending :nick!user@host of the user provided in the first parameter.
573 * @param user The user to prepend the :nick!user@host of
574 * @param text A std::string to send to the user
576 void WriteFrom(User *user, const std::string &text);
578 /** Write text to this user, appending CR/LF and prepending :nick!user@host of the user provided in the first parameter.
579 * @param user The user to prepend the :nick!user@host of
580 * @param text The format string for text to send to the user
581 * @param ... POD-type format arguments
583 void WriteFrom(User *user, const char* text, ...) CUSTOM_PRINTF(3, 4);
585 /** Write text to the user provided in the first parameter, appending CR/LF, and prepending THIS user's :nick!user@host.
586 * @param dest The user to route the message to
587 * @param text A std::string to send to the user
589 void WriteTo(User *dest, const std::string &data);
591 /** Write text to the user provided in the first parameter, appending CR/LF, and prepending THIS user's :nick!user@host.
592 * @param dest The user to route the message to
593 * @param text The format string for text to send to the user
594 * @param ... POD-type format arguments
596 void WriteTo(User *dest, const char *data, ...) CUSTOM_PRINTF(3, 4);
598 /** Write to all users that can see this user (including this user in the list), appending CR/LF
599 * @param text A std::string to send to the users
601 void WriteCommonRaw(const std::string &line, bool include_self = true);
603 /** Write to all users that can see this user (including this user in the list), appending CR/LF
604 * @param text The format string for text to send to the users
605 * @param ... POD-type format arguments
607 void WriteCommon(const char* text, ...) CUSTOM_PRINTF(2, 3);
609 /** Write to all users that can see this user (not including this user in the list), appending CR/LF
610 * @param text The format string for text to send to the users
611 * @param ... POD-type format arguments
613 void WriteCommonExcept(const char* text, ...) CUSTOM_PRINTF(2, 3);
615 /** Write a quit message to all common users, as in User::WriteCommonExcept but with a specific
616 * quit message for opers only.
617 * @param normal_text Normal user quit message
618 * @param oper_text Oper only quit message
620 void WriteCommonQuit(const std::string &normal_text, const std::string &oper_text);
622 /** Dump text to a user target, splitting it appropriately to fit
623 * @param LinePrefix text to prefix each complete line with
624 * @param TextStream the text to send to the user
626 void SendText(const std::string &LinePrefix, std::stringstream &TextStream);
628 /** Write to the user, routing the line if the user is remote.
630 virtual void SendText(const std::string& line) = 0;
632 /** Write to the user, routing the line if the user is remote.
634 void SendText(const char* text, ...) CUSTOM_PRINTF(2, 3);
636 /** Return true if the user shares at least one channel with another user
637 * @param other The other user to compare the channel list against
638 * @return True if the given user shares at least one channel with this user
640 bool SharesChannelWith(User *other);
642 /** Send fake quit/join messages for host or ident cycle.
643 * Run this after the item in question has changed.
644 * You should not need to use this function, call ChangeDisplayedHost instead
646 * @param The entire QUIT line, including the source using the old value
648 void DoHostCycle(const std::string &quitline);
650 /** Change the displayed host of a user.
651 * ALWAYS use this function, rather than writing User::dhost directly,
652 * as this triggers module events allowing the change to be syncronized to
653 * remote servers. This will also emulate a QUIT and rejoin (where configured)
654 * before setting their host field.
655 * @param host The new hostname to set
656 * @return True if the change succeeded, false if it didn't
658 bool ChangeDisplayedHost(const char* host);
660 /** Change the ident (username) of a user.
661 * ALWAYS use this function, rather than writing User::ident directly,
662 * as this correctly causes the user to seem to quit (where configured)
663 * before setting their ident field.
664 * @param host The new ident to set
665 * @return True if the change succeeded, false if it didn't
667 bool ChangeIdent(const char* newident);
669 /** Change a users realname field.
670 * ALWAYS use this function, rather than writing User::fullname directly,
671 * as this triggers module events allowing the change to be syncronized to
673 * @param gecos The user's new realname
674 * @return True if the change succeeded, false if otherwise
676 bool ChangeName(const char* gecos);
678 /** Change a user's nick
679 * @param newnick The new nick
680 * @param force True if the change is being forced (should not be blocked by modes like +N)
681 * @return True if the change succeeded
683 bool ChangeNick(const std::string& newnick, bool force = false);
685 /** Send a command to all local users from this user
686 * The command given must be able to send text with the
687 * first parameter as a servermask (e.g. $*), so basically
688 * you should use PRIVMSG or NOTICE.
689 * @param command the command to send
690 * @param text The text format string to send
691 * @param ... Format arguments
693 void SendAll(const char* command, const char* text, ...) CUSTOM_PRINTF(3, 4);
695 /** Compile a channel list for this user. Used internally by WHOIS
696 * @param source The user to prepare the channel list for
697 * @param spy Whether to return the spy channel list rather than the normal one
698 * @return This user's channel list
700 std::string ChannelList(User* source, bool spy);
702 /** Split the channel list in cl which came from dest, and spool it to this user
703 * Used internally by WHOIS
704 * @param dest The user the original channel list came from
705 * @param cl The channel list as a string obtained from User::ChannelList()
707 void SplitChanList(User* dest, const std::string &cl);
709 /** Remove this user from all channels they are on, and delete any that are now empty.
710 * This is used by QUIT, and will not send part messages!
712 void PurgeEmptyChannels();
714 /** Get the connect class which this user belongs to. NULL for remote users.
715 * @return A pointer to this user's connect class.
717 virtual ConnectClass* GetClass();
719 /** Default destructor
722 virtual CullResult cull();
725 class CoreExport UserIOHandler : public StreamSocket
728 LocalUser* const user;
729 UserIOHandler(LocalUser* me) : user(me) {}
731 void OnError(BufferedSocketError error);
733 /** Adds to the user's write buffer.
734 * You may add any amount of text up to this users sendq value, if you exceed the
735 * sendq value, the user will be removed, and further buffer adds will be dropped.
736 * @param data The data to add to the write buffer
738 void AddWriteBuf(const std::string &data);
741 typedef unsigned int already_sent_t;
743 class CoreExport LocalUser : public User
745 /** A list of channels the user has a pending invite to.
746 * Upon INVITE channels are added, and upon JOIN, the
747 * channels are removed from this list.
752 LocalUser(int fd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
757 /** Stats counter for bytes inbound
761 /** Stats counter for bytes outbound
765 /** Stats counter for commands inbound
769 /** Stats counter for commands outbound
773 /** Password specified by the user when they registered (if any).
774 * This is stored even if the <connect> block doesnt need a password, so that
775 * modules may check it.
777 std::string password;
779 /** Contains a pointer to the connect class a user is on from
781 reference<ConnectClass> MyClass;
783 ConnectClass* GetClass();
785 /** Call this method to find the matching <connect> for a user, and to check them against it.
789 /** Server address and port that this user is connected to.
791 irc::sockets::sockaddrs server_sa;
794 * @return The port number of this user.
798 /** Used by PING checking code
802 /** This value contains how far into the penalty threshold the user is.
803 * This is used either to enable fake lag or for excess flood quits
805 unsigned int CommandFloodPenalty;
807 static already_sent_t already_sent_id;
808 already_sent_t already_sent;
810 /** Stored reverse lookup from res_forward. Should not be used after resolution.
812 std::string stored_host;
814 /** Starts a DNS lookup of the user's IP.
815 * This will cause two UserResolver classes to be instantiated.
816 * When complete, these objects set User::dns_done to true.
818 void StartDNSLookup();
820 /** Use this method to fully connect a user.
821 * This will send the message of the day, check G/K/E lines, etc.
825 /** Set the connect class to which this user belongs to.
826 * @param explicit_name Set this string to tie the user to a specific class name. Otherwise, the class is fitted by checking <connect> tags from the configuration file.
827 * @return A reference to this user's current connect class.
829 void SetClass(const std::string &explicit_name = "");
831 void SendText(const std::string& line);
832 void Write(const std::string& text);
833 void Write(const char*, ...) CUSTOM_PRINTF(2, 3);
835 /** Returns the list of channels this user has been invited to but has not yet joined.
836 * @return A list of channels the user is invited to
838 InvitedList* GetInviteList();
840 /** Returns true if a user is invited to a channel.
841 * @param channel A channel name to look up
842 * @return True if the user is invited to the given channel
844 bool IsInvited(const irc::string &channel);
846 /** Adds a channel to a users invite list (invites them to a channel)
847 * @param channel A channel name to add
848 * @param timeout When the invite should expire (0 == never)
850 void InviteTo(const irc::string &channel, time_t timeout);
852 /** Removes a channel from a users invite list.
853 * This member function is called on successfully joining an invite only channel
854 * to which the user has previously been invited, to clear the invitation.
855 * @param channel The channel to remove the invite to
857 void RemoveInvite(const irc::string &channel);
859 /** Returns true or false for if a user can execute a privilaged oper command.
860 * This is done by looking up their oper type from User::oper, then referencing
861 * this to their oper classes and checking the commands they can execute.
862 * @param command A command (should be all CAPS)
863 * @return True if this user can execute the command
865 bool HasPermission(const std::string &command);
867 /** Returns true if a user has a given permission.
868 * This is used to check whether or not users may perform certain actions which admins may not wish to give to
869 * all operators, yet are not commands. An example might be oper override, mass messaging (/notice $*), etc.
871 * @param privstr The priv to chec, e.g. "users/override/topic". These are loaded free-form from the config file.
872 * @param noisy If set to true, the user is notified that they do not have the specified permission where applicable. If false, no notification is sent.
873 * @return True if this user has the permission in question.
875 bool HasPrivPermission(const std::string &privstr, bool noisy = false);
877 /** Returns true or false if a user can set a privileged user or channel mode.
878 * This is done by looking up their oper type from User::oper, then referencing
879 * this to their oper classes, and checking the modes they can set.
880 * @param mode The mode the check
881 * @param type ModeType (MODETYPE_CHANNEL or MODETYPE_USER).
882 * @return True if the user can set or unset this mode.
884 bool HasModePermission(unsigned char mode, ModeType type);
887 class CoreExport RemoteUser : public User
890 RemoteUser(const std::string& uid, const std::string& srv) : User(uid, srv, USERTYPE_REMOTE)
893 virtual void SendText(const std::string& line);
896 class CoreExport FakeUser : public User
899 FakeUser(const std::string &uid, const std::string& srv) : User(uid, srv, USERTYPE_SERVER)
904 virtual CullResult cull();
905 virtual void SendText(const std::string& line);
906 virtual const std::string& GetFullHost();
907 virtual const std::string& GetFullRealHost();
910 /* Faster than dynamic_cast */
911 /** Is a local user */
912 inline LocalUser* IS_LOCAL(User* u)
914 return u->usertype == USERTYPE_LOCAL ? static_cast<LocalUser*>(u) : NULL;
916 /** Is a remote user */
917 inline RemoteUser* IS_REMOTE(User* u)
919 return u->usertype == USERTYPE_REMOTE ? static_cast<RemoteUser*>(u) : NULL;
921 /** Is a server fakeuser */
922 inline FakeUser* IS_SERVER(User* u)
924 return u->usertype == USERTYPE_SERVER ? static_cast<FakeUser*>(u) : NULL;
927 #define IS_OPER(x) (x->oper)
929 #define IS_AWAY(x) (!x->awaymsg.empty())
931 /** Derived from Resolver, and performs user forward/reverse lookups.
933 class CoreExport UserResolver : public Resolver
936 /** UUID we are looking up */
938 /** True if the lookup is forward, false if is a reverse lookup
942 /** Create a resolver.
943 * @param Instance The creating instance
944 * @param user The user to begin lookup on
945 * @param to_resolve The IP or host to resolve
946 * @param qt The query type
947 * @param cache Modified by the constructor if the result was cached
949 UserResolver(LocalUser* user, std::string to_resolve, QueryType qt, bool &cache);
951 /** Called on successful lookup
952 * @param result Result string
953 * @param ttl Time to live for result
954 * @param cached True if the result was found in the cache
956 void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached);
958 /** Called on failed lookup
959 * @param e Error code
960 * @param errormessage Error message string
962 void OnError(ResolverError e, const std::string &errormessage);