1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 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 "inspsocket.h"
22 /** connect class types
29 /** named connect block (for opers, etc) */
33 /** RFC1459 channel modes
36 /** +s: Server notice mask */
37 UM_SNOMASK = 's' - 65,
39 UM_WALLOPS = 'w' - 65,
41 UM_INVISIBLE = 'i' - 65,
43 UM_OPERATOR = 'o' - 65
46 /** Registration state of a user, e.g.
47 * have they sent USER, NICK, PASS yet?
49 enum RegistrationState {
51 #ifndef WIN32 // Burlex: This is already defined in win32, luckily it is still 0.
52 REG_NONE = 0, /* Has sent nothing */
55 REG_USER = 1, /* Has sent USER */
56 REG_NICK = 2, /* Has sent NICK */
57 REG_NICKUSER = 3, /* Bitwise combination of REG_NICK and REG_USER */
58 REG_ALL = 7 /* REG_NICKUSER plus next bit along */
67 /** Holds information relevent to <connect allow> and <connect deny> tags in the config file.
69 struct CoreExport ConnectClass : public refcountbase
71 reference<ConfigTag> config;
72 /** Type of line, either CC_ALLOW or CC_DENY
76 /** True if this class uses fake lag to manage flood, false if it kills */
79 /** Connect class name
83 /** Max time to register the connection in seconds
85 unsigned int registration_timeout;
87 /** Host mask for this line
91 /** Number of seconds between pings for this line
93 unsigned int pingtime;
95 /** Maximum size of sendq for users in this class (bytes)
96 * Users cannot send commands if they go over this limit
98 unsigned long softsendqmax;
100 /** Maximum size of sendq for users in this class (bytes)
101 * Users are killed if they go over this limit
103 unsigned long hardsendqmax;
105 /** Maximum size of recvq for users in this class (bytes)
107 unsigned long recvqmax;
109 /** Seconds worth of penalty before penalty system activates
111 unsigned int penaltythreshold;
113 /** Maximum rate of commands (units: millicommands per second) */
114 unsigned int commandrate;
116 /** Local max when connecting by this connection class
118 unsigned long maxlocal;
120 /** Global max when connecting by this connection class
122 unsigned long maxglobal;
124 /** Max channels for this class
126 unsigned int maxchans;
128 /** How many users may be in this connect class before they are refused?
129 * (0 = no limit = default)
133 /** Create a new connect class with no settings.
135 ConnectClass(ConfigTag* tag, char type, const std::string& mask);
136 /** Create a new connect class with inherited settings.
138 ConnectClass(ConfigTag* tag, char type, const std::string& mask, const ConnectClass& parent);
140 /** Update the settings in this block to match the given block */
141 void Update(const ConnectClass* newSettings);
143 const std::string& GetName() { return name; }
144 const std::string& GetHost() { return host; }
146 /** Returns the registration timeout
148 time_t GetRegTimeout()
150 return (registration_timeout ? registration_timeout : 90);
153 /** Returns the ping frequency
155 unsigned int GetPingTime()
157 return (pingtime ? pingtime : 120);
160 /** Returns the maximum sendq value (soft limit)
161 * Note that this is in addition to internal OS buffers
163 unsigned long GetSendqSoftMax()
165 return (softsendqmax ? softsendqmax : 4096);
168 /** Returns the maximum sendq value (hard limit)
170 unsigned long GetSendqHardMax()
172 return (hardsendqmax ? hardsendqmax : 0x100000);
175 /** Returns the maximum recvq value
177 unsigned long GetRecvqMax()
179 return (recvqmax ? recvqmax : 4096);
182 /** Returns the penalty threshold value
184 unsigned int GetPenaltyThreshold()
186 return penaltythreshold ? penaltythreshold : (fakelag ? 10 : 20);
189 unsigned int GetCommandRate()
191 return commandrate ? commandrate : 1000;
194 /** Return the maximum number of local sessions
196 unsigned long GetMaxLocal()
201 /** Returns the maximum number of global sessions
203 unsigned long GetMaxGlobal()
209 /** Holds all information about a user
210 * This class stores all information about a user connected to the irc server. Everything about a
211 * connection is stored here primarily, from the user's socket ID (file descriptor) through to the
212 * user's nickname and hostname.
214 class CoreExport User : public Extensible
217 /** Cached nick!ident@dhost value using the displayed hostname
219 std::string cached_fullhost;
221 /** Cached ident@ip value using the real IP address
223 std::string cached_hostip;
225 /** Cached ident@realhost value using the real hostname
227 std::string cached_makehost;
229 /** Cached nick!ident@realhost value using the real hostname
231 std::string cached_fullrealhost;
233 /** Set by GetIPString() to avoid constantly re-grabbing IP via sockets voodoo.
235 std::string cachedip;
239 /** Hostname of connection.
240 * This should be valid as per RFC1035.
244 /** Time that the object was instantiated (used for TS calculation etc)
248 /** Time the connection was created, set in the constructor. This
249 * may be different from the time the user's classbase object was
254 /** Time that the connection last sent a message, used to calculate idle time
258 /** Client address that the user is connected from.
259 * Do not modify this value directly, use SetClientIP() to change it.
260 * Port is not valid for remote users.
262 irc::sockets::sockaddrs client_sa;
264 /** The users nickname.
265 * An invalid nickname indicates an unregistered connection prior to the NICK command.
266 * Use InspIRCd::IsNick() to validate nicknames.
270 /** The user's unique identifier.
271 * This is the unique identifier which the user has across the network.
273 const std::string uuid;
275 /** The users ident reply.
276 * Two characters are added to the user-defined limit to compensate for the tilde etc.
280 /** The host displayed to non-opers (used for cloaking etc).
281 * This usually matches the value of User::host.
285 /** The users full name (GECOS).
287 std::string fullname;
289 /** The user's mode list.
290 * NOT a null terminated string.
292 * Much love to the STL for giving us an easy to use bitset, saving us RAM.
293 * if (modes[modeletter-65]) is set, then the mode is
294 * set, for example, to work out if mode +s is set, we check the field
295 * User::modes['s'-65] != 0.
296 * The following RFC characters o, w, s, i have constants defined via an
297 * enum, such as UM_SERVERNOTICE and UM_OPETATOR.
299 std::bitset<64> modes;
301 /** What snomasks are set on this user.
302 * This functions the same as the above modes.
304 std::bitset<64> snomasks;
306 /** Channels this user is on
310 /** The server the user is connected to.
312 const std::string server;
314 /** The user's away message.
315 * If this string is empty, the user is not marked as away.
319 /** Time the user last went away.
320 * This is ONLY RELIABLE if user IS_AWAY()!
324 /** The oper type they logged in as, if they are an oper.
326 reference<OperInfo> oper;
328 /** Used by User to indicate the registration status of the connection
329 * It is a bitfield of the REG_NICK, REG_USER and REG_ALL bits to indicate
330 * the connection state.
332 unsigned int registered:3;
334 /** True when DNS lookups are completed.
335 * The UserResolver classes res_forward and res_reverse will
336 * set this value once they complete.
338 unsigned int dns_done:1;
340 /** Whether or not to send an snotice about this user's quitting
342 unsigned int quietquit:1;
344 /** If this is set to true, then all socket operations for the user
345 * are dropped into the bit-bucket.
346 * This value is set by QuitUser, and is not needed seperately from that call.
347 * Please note that setting this value alone will NOT cause the user to quit.
349 unsigned int quitting:1;
351 /** This is true if the user matched an exception (E:Line). It is used to save time on ban checks.
353 unsigned int exempt:1;
355 /** has the user responded to their previous ping?
357 unsigned int lastping:1;
359 /** What type of user is this? */
360 const unsigned int usertype:2;
362 /** Get client IP string from sockaddr, using static internal buffer
363 * @return The IP string
365 const char* GetIPString();
367 /** Get CIDR mask, using default range, for this user
369 irc::sockets::cidr_mask GetCIDRMask();
371 /** Sets the client IP for this user
372 * @return true if the conversion was successful
374 bool SetClientIP(const char* sip);
377 * @throw CoreException if the UID allocated to the user already exists
379 User(const std::string &uid, const std::string& srv, int objtype);
381 /** Check if the user matches a G or K line, and disconnect them if they do.
382 * @param doZline True if ZLines should be checked (if IP has changed since initial connect)
383 * Returns true if the user matched a ban, false else.
385 bool CheckLines(bool doZline = false);
387 /** Returns the full displayed host of the user
388 * This member function returns the hostname of the user as seen by other users
389 * on the server, in nick!ident&at;host form.
390 * @return The full masked host of the user
392 virtual const std::string& GetFullHost();
394 /** Returns the full real host of the user
395 * This member function returns the hostname of the user as seen by other users
396 * on the server, in nick!ident&at;host form. If any form of hostname cloaking is in operation,
397 * e.g. through a module, then this method will ignore it and return the true hostname.
398 * @return The full real host of the user
400 virtual const std::string& GetFullRealHost();
402 /** This clears any cached results that are used for GetFullRealHost() etc.
403 * The results of these calls are cached as generating them can be generally expensive.
405 void InvalidateCache();
407 /** Create a displayable mode string for this users snomasks
408 * @return The notice mask character sequence
410 const char* FormatNoticeMasks();
412 /** Process a snomask modifier string, e.g. +abc-de
413 * @param sm A sequence of notice mask characters
414 * @return The cleaned mode sequence which can be output,
415 * e.g. in the above example if masks c and e are not
416 * valid, this function will return +ab-d
418 std::string ProcessNoticeMasks(const char *sm);
420 /** Returns true if a notice mask is set
421 * @param sm A notice mask character to check
422 * @return True if the notice mask is set
424 bool IsNoticeMaskSet(unsigned char sm);
426 /** Changed a specific notice mask value
427 * @param sm The server notice mask to change
428 * @param value An on/off value for this mask
430 void SetNoticeMask(unsigned char sm, bool value);
432 /** Create a displayable mode string for this users umodes
433 * @param The mode string
435 const char* FormatModes(bool showparameters = false);
437 /** Returns true if a specific mode is set
438 * @param m The user mode
439 * @return True if the mode is set
441 bool IsModeSet(unsigned char m);
443 /** Set a specific usermode to on or off
444 * @param m The user mode
445 * @param value On or off setting of the mode
447 void SetMode(unsigned char m, bool value);
449 /** Returns true or false for if a user can execute a privilaged oper command.
450 * This is done by looking up their oper type from User::oper, then referencing
451 * this to their oper classes and checking the commands they can execute.
452 * @param command A command (should be all CAPS)
453 * @return True if this user can execute the command
455 virtual bool HasPermission(const std::string &command);
457 /** Returns true if a user has a given permission.
458 * This is used to check whether or not users may perform certain actions which admins may not wish to give to
459 * all operators, yet are not commands. An example might be oper override, mass messaging (/notice $*), etc.
461 * @param privstr The priv to chec, e.g. "users/override/topic". These are loaded free-form from the config file.
462 * @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.
463 * @return True if this user has the permission in question.
465 virtual bool HasPrivPermission(const std::string &privstr, bool noisy = false);
467 /** Returns true or false if a user can set a privileged user or channel mode.
468 * This is done by looking up their oper type from User::oper, then referencing
469 * this to their oper classes, and checking the modes they can set.
470 * @param mode The mode the check
471 * @param type ModeType (MODETYPE_CHANNEL or MODETYPE_USER).
472 * @return True if the user can set or unset this mode.
474 virtual bool HasModePermission(unsigned char mode, ModeType type);
476 /** Creates a wildcard host.
477 * Takes a buffer to use and fills the given buffer with the host in the format *!*@hostname
478 * @return The wildcarded hostname in *!*@host form
480 char* MakeWildHost();
482 /** Creates a usermask with real host.
483 * Takes a buffer to use and fills the given buffer with the hostmask in the format user@host
484 * @return the usermask in the format user@host
486 const std::string& MakeHost();
488 /** Creates a usermask with real ip.
489 * Takes a buffer to use and fills the given buffer with the ipmask in the format user@ip
490 * @return the usermask in the format user@ip
492 const std::string& MakeHostIP();
494 /** Add the user to WHOWAS system
498 /** Oper up the user using the given opertype.
499 * This will also give the +o usermode.
501 void Oper(OperInfo* info);
503 /** Force a nickname change.
504 * If the nickname change fails (for example, because the nick in question
505 * already exists) this function will return false, and you must then either
506 * output an error message, or quit the user for nickname collision.
507 * @param newnick The nickname to change to
508 * @return True if the nickchange was successful.
510 inline bool ForceNickChange(const char* newnick) { return ChangeNick(newnick, true); }
513 * This will clear the +o usermode and unset the user's oper type
517 /** Write text to this user, appending CR/LF. Works on local users only.
518 * @param text A std::string to send to the user
520 virtual void Write(const std::string &text);
522 /** Write text to this user, appending CR/LF.
523 * Works on local users only.
524 * @param text The format string for text to send to the user
525 * @param ... POD-type format arguments
527 virtual void Write(const char *text, ...) CUSTOM_PRINTF(2, 3);
529 /** Write text to this user, appending CR/LF and prepending :server.name
530 * Works on local users only.
531 * @param text A std::string to send to the user
533 void WriteServ(const std::string& text);
535 /** Write text to this user, appending CR/LF and prepending :server.name
536 * Works on local users only.
537 * @param text The format string for text to send to the user
538 * @param ... POD-type format arguments
540 void WriteServ(const char* text, ...) CUSTOM_PRINTF(2, 3);
542 void WriteNumeric(unsigned int numeric, const char* text, ...) CUSTOM_PRINTF(3, 4);
544 void WriteNumeric(unsigned int numeric, const std::string &text);
546 /** Write text to this user, appending CR/LF and prepending :nick!user@host of the user provided in the first parameter.
547 * @param user The user to prepend the :nick!user@host of
548 * @param text A std::string to send to the user
550 void WriteFrom(User *user, const std::string &text);
552 /** Write text to this user, appending CR/LF and prepending :nick!user@host of the user provided in the first parameter.
553 * @param user The user to prepend the :nick!user@host of
554 * @param text The format string for text to send to the user
555 * @param ... POD-type format arguments
557 void WriteFrom(User *user, const char* text, ...) CUSTOM_PRINTF(3, 4);
559 /** Write text to the user provided in the first parameter, appending CR/LF, and prepending THIS user's :nick!user@host.
560 * @param dest The user to route the message to
561 * @param text A std::string to send to the user
563 void WriteTo(User *dest, const std::string &data);
565 /** Write text to the user provided in the first parameter, appending CR/LF, and prepending THIS user's :nick!user@host.
566 * @param dest The user to route the message to
567 * @param text The format string for text to send to the user
568 * @param ... POD-type format arguments
570 void WriteTo(User *dest, const char *data, ...) CUSTOM_PRINTF(3, 4);
572 /** Write to all users that can see this user (including this user in the list), appending CR/LF
573 * @param text A std::string to send to the users
575 void WriteCommonRaw(const std::string &line, bool include_self = true);
577 /** Write to all users that can see this user (including this user in the list), appending CR/LF
578 * @param text The format string for text to send to the users
579 * @param ... POD-type format arguments
581 void WriteCommon(const char* text, ...) CUSTOM_PRINTF(2, 3);
583 /** Write to all users that can see this user (not including this user in the list), appending CR/LF
584 * @param text The format string for text to send to the users
585 * @param ... POD-type format arguments
587 void WriteCommonExcept(const char* text, ...) CUSTOM_PRINTF(2, 3);
589 /** Write a quit message to all common users, as in User::WriteCommonExcept but with a specific
590 * quit message for opers only.
591 * @param normal_text Normal user quit message
592 * @param oper_text Oper only quit message
594 void WriteCommonQuit(const std::string &normal_text, const std::string &oper_text);
596 /** Dump text to a user target, splitting it appropriately to fit
597 * @param LinePrefix text to prefix each complete line with
598 * @param TextStream the text to send to the user
600 void SendText(const std::string &LinePrefix, std::stringstream &TextStream);
602 /** Write to the user, routing the line if the user is remote.
604 virtual void SendText(const std::string& line) = 0;
606 /** Write to the user, routing the line if the user is remote.
608 void SendText(const char* text, ...) CUSTOM_PRINTF(2, 3);
610 /** Return true if the user shares at least one channel with another user
611 * @param other The other user to compare the channel list against
612 * @return True if the given user shares at least one channel with this user
614 bool SharesChannelWith(User *other);
616 /** Send fake quit/join messages for host or ident cycle.
617 * Run this after the item in question has changed.
618 * You should not need to use this function, call ChangeDisplayedHost instead
620 * @param The entire QUIT line, including the source using the old value
622 void DoHostCycle(const std::string &quitline);
624 /** Change the displayed host of a user.
625 * ALWAYS use this function, rather than writing User::dhost directly,
626 * as this triggers module events allowing the change to be syncronized to
627 * remote servers. This will also emulate a QUIT and rejoin (where configured)
628 * before setting their host field.
629 * @param host The new hostname to set
630 * @return True if the change succeeded, false if it didn't
632 bool ChangeDisplayedHost(const char* host);
634 /** Change the ident (username) of a user.
635 * ALWAYS use this function, rather than writing User::ident directly,
636 * as this correctly causes the user to seem to quit (where configured)
637 * before setting their ident field.
638 * @param host The new ident to set
639 * @return True if the change succeeded, false if it didn't
641 bool ChangeIdent(const char* newident);
643 /** Change a users realname field.
644 * ALWAYS use this function, rather than writing User::fullname directly,
645 * as this triggers module events allowing the change to be syncronized to
647 * @param gecos The user's new realname
648 * @return True if the change succeeded, false if otherwise
650 bool ChangeName(const char* gecos);
652 /** Change a user's nick
653 * @param newnick The new nick
654 * @param force True if the change is being forced (should not be blocked by modes like +N)
655 * @return True if the change succeeded
657 bool ChangeNick(const std::string& newnick, bool force = false);
659 /** Send a command to all local users from this user
660 * The command given must be able to send text with the
661 * first parameter as a servermask (e.g. $*), so basically
662 * you should use PRIVMSG or NOTICE.
663 * @param command the command to send
664 * @param text The text format string to send
665 * @param ... Format arguments
667 void SendAll(const char* command, const char* text, ...) CUSTOM_PRINTF(3, 4);
669 /** Compile a channel list for this user. Used internally by WHOIS
670 * @param source The user to prepare the channel list for
671 * @param spy Whether to return the spy channel list rather than the normal one
672 * @return This user's channel list
674 std::string ChannelList(User* source, bool spy);
676 /** Split the channel list in cl which came from dest, and spool it to this user
677 * Used internally by WHOIS
678 * @param dest The user the original channel list came from
679 * @param cl The channel list as a string obtained from User::ChannelList()
681 void SplitChanList(User* dest, const std::string &cl);
683 /** Remove this user from all channels they are on, and delete any that are now empty.
684 * This is used by QUIT, and will not send part messages!
686 void PurgeEmptyChannels();
688 /** Get the connect class which this user belongs to. NULL for remote users.
689 * @return A pointer to this user's connect class.
691 virtual ConnectClass* GetClass();
693 /** Default destructor
696 virtual CullResult cull();
699 class CoreExport UserIOHandler : public StreamSocket
702 LocalUser* const user;
703 UserIOHandler(LocalUser* me) : user(me) {}
705 void OnError(BufferedSocketError error);
707 /** Adds to the user's write buffer.
708 * You may add any amount of text up to this users sendq value, if you exceed the
709 * sendq value, the user will be removed, and further buffer adds will be dropped.
710 * @param data The data to add to the write buffer
712 void AddWriteBuf(const std::string &data);
715 typedef unsigned int already_sent_t;
717 class CoreExport LocalUser : public User
719 /** A list of channels the user has a pending invite to.
720 * Upon INVITE channels are added, and upon JOIN, the
721 * channels are removed from this list.
726 LocalUser(int fd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
731 /** Stats counter for bytes inbound
735 /** Stats counter for bytes outbound
739 /** Stats counter for commands inbound
743 /** Stats counter for commands outbound
747 /** Password specified by the user when they registered (if any).
748 * This is stored even if the <connect> block doesnt need a password, so that
749 * modules may check it.
751 std::string password;
753 /** Contains a pointer to the connect class a user is on from
755 reference<ConnectClass> MyClass;
757 ConnectClass* GetClass();
759 /** Call this method to find the matching <connect> for a user, and to check them against it.
763 /** Server address and port that this user is connected to.
765 irc::sockets::sockaddrs server_sa;
768 * @return The port number of this user.
772 /** Used by PING checking code
776 /** This value contains how far into the penalty threshold the user is.
777 * This is used either to enable fake lag or for excess flood quits
779 unsigned int CommandFloodPenalty;
781 static already_sent_t already_sent_id;
782 already_sent_t already_sent;
784 /** Stored reverse lookup from res_forward. Should not be used after resolution.
786 std::string stored_host;
788 /** Starts a DNS lookup of the user's IP.
789 * This will cause two UserResolver classes to be instantiated.
790 * When complete, these objects set User::dns_done to true.
792 void StartDNSLookup();
794 /** Use this method to fully connect a user.
795 * This will send the message of the day, check G/K/E lines, etc.
799 /** Set the connect class to which this user belongs to.
800 * @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.
801 * @return A reference to this user's current connect class.
803 void SetClass(const std::string &explicit_name = "");
805 void SendText(const std::string& line);
806 void Write(const std::string& text);
807 void Write(const char*, ...) CUSTOM_PRINTF(2, 3);
809 /** Returns the list of channels this user has been invited to but has not yet joined.
810 * @return A list of channels the user is invited to
812 InvitedList* GetInviteList();
814 /** Returns true if a user is invited to a channel.
815 * @param channel A channel name to look up
816 * @return True if the user is invited to the given channel
818 bool IsInvited(const irc::string &channel);
820 /** Adds a channel to a users invite list (invites them to a channel)
821 * @param channel A channel name to add
822 * @param timeout When the invite should expire (0 == never)
824 void InviteTo(const irc::string &channel, time_t timeout);
826 /** Removes a channel from a users invite list.
827 * This member function is called on successfully joining an invite only channel
828 * to which the user has previously been invited, to clear the invitation.
829 * @param channel The channel to remove the invite to
831 void RemoveInvite(const irc::string &channel);
833 /** Returns true or false for if a user can execute a privilaged oper command.
834 * This is done by looking up their oper type from User::oper, then referencing
835 * this to their oper classes and checking the commands they can execute.
836 * @param command A command (should be all CAPS)
837 * @return True if this user can execute the command
839 bool HasPermission(const std::string &command);
841 /** Returns true if a user has a given permission.
842 * This is used to check whether or not users may perform certain actions which admins may not wish to give to
843 * all operators, yet are not commands. An example might be oper override, mass messaging (/notice $*), etc.
845 * @param privstr The priv to chec, e.g. "users/override/topic". These are loaded free-form from the config file.
846 * @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.
847 * @return True if this user has the permission in question.
849 bool HasPrivPermission(const std::string &privstr, bool noisy = false);
851 /** Returns true or false if a user can set a privileged user or channel mode.
852 * This is done by looking up their oper type from User::oper, then referencing
853 * this to their oper classes, and checking the modes they can set.
854 * @param mode The mode the check
855 * @param type ModeType (MODETYPE_CHANNEL or MODETYPE_USER).
856 * @return True if the user can set or unset this mode.
858 bool HasModePermission(unsigned char mode, ModeType type);
861 class CoreExport RemoteUser : public User
864 RemoteUser(const std::string& uid, const std::string& srv) : User(uid, srv, USERTYPE_REMOTE)
867 virtual void SendText(const std::string& line);
870 class CoreExport FakeUser : public User
873 FakeUser(const std::string &uid, const std::string& srv) : User(uid, srv, USERTYPE_SERVER)
878 virtual CullResult cull();
879 virtual void SendText(const std::string& line);
880 virtual const std::string& GetFullHost();
881 virtual const std::string& GetFullRealHost();
884 /* Faster than dynamic_cast */
885 /** Is a local user */
886 inline LocalUser* IS_LOCAL(User* u)
888 return u->usertype == USERTYPE_LOCAL ? static_cast<LocalUser*>(u) : NULL;
890 /** Is a remote user */
891 inline RemoteUser* IS_REMOTE(User* u)
893 return u->usertype == USERTYPE_REMOTE ? static_cast<RemoteUser*>(u) : NULL;
895 /** Is a server fakeuser */
896 inline FakeUser* IS_SERVER(User* u)
898 return u->usertype == USERTYPE_SERVER ? static_cast<FakeUser*>(u) : NULL;
901 #define IS_OPER(x) (x->oper)
903 #define IS_AWAY(x) (!x->awaymsg.empty())
905 /** Derived from Resolver, and performs user forward/reverse lookups.
907 class CoreExport UserResolver : public Resolver
910 /** UUID we are looking up */
912 /** True if the lookup is forward, false if is a reverse lookup
916 /** Create a resolver.
917 * @param Instance The creating instance
918 * @param user The user to begin lookup on
919 * @param to_resolve The IP or host to resolve
920 * @param qt The query type
921 * @param cache Modified by the constructor if the result was cached
923 UserResolver(LocalUser* user, std::string to_resolve, QueryType qt, bool &cache);
925 /** Called on successful lookup
926 * @param result Result string
927 * @param ttl Time to live for result
928 * @param cached True if the result was found in the cache
930 void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached);
932 /** Called on failed lookup
933 * @param e Error code
934 * @param errormessage Error message string
936 void OnError(ResolverError e, const std::string &errormessage);