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 /** Recursion fix: user is out of SendQ and will be quit as soon as possible.
352 * This can't be handled normally because QuitUser itself calls Write on other
353 * users, which could trigger their SendQ to overrun.
355 unsigned int quitting_sendq:1;
357 /** This is true if the user matched an exception (E:Line). It is used to save time on ban checks.
359 unsigned int exempt:1;
361 /** has the user responded to their previous ping?
363 unsigned int lastping:1;
365 /** What type of user is this? */
366 const unsigned int usertype:2;
368 /** Get client IP string from sockaddr, using static internal buffer
369 * @return The IP string
371 const char* GetIPString();
373 /** Get CIDR mask, using default range, for this user
375 irc::sockets::cidr_mask GetCIDRMask();
377 /** Sets the client IP for this user
378 * @return true if the conversion was successful
380 bool SetClientIP(const char* sip);
383 * @throw CoreException if the UID allocated to the user already exists
385 User(const std::string &uid, const std::string& srv, int objtype);
387 /** Check if the user matches a G or K line, and disconnect them if they do.
388 * @param doZline True if ZLines should be checked (if IP has changed since initial connect)
389 * Returns true if the user matched a ban, false else.
391 bool CheckLines(bool doZline = false);
393 /** Returns the full displayed host of the user
394 * This member function returns the hostname of the user as seen by other users
395 * on the server, in nick!ident&at;host form.
396 * @return The full masked host of the user
398 virtual const std::string& GetFullHost();
400 /** Returns the full real host of the user
401 * This member function returns the hostname of the user as seen by other users
402 * on the server, in nick!ident&at;host form. If any form of hostname cloaking is in operation,
403 * e.g. through a module, then this method will ignore it and return the true hostname.
404 * @return The full real host of the user
406 virtual const std::string& GetFullRealHost();
408 /** This clears any cached results that are used for GetFullRealHost() etc.
409 * The results of these calls are cached as generating them can be generally expensive.
411 void InvalidateCache();
413 /** Create a displayable mode string for this users snomasks
414 * @return The notice mask character sequence
416 const char* FormatNoticeMasks();
418 /** Process a snomask modifier string, e.g. +abc-de
419 * @param sm A sequence of notice mask characters
420 * @return The cleaned mode sequence which can be output,
421 * e.g. in the above example if masks c and e are not
422 * valid, this function will return +ab-d
424 std::string ProcessNoticeMasks(const char *sm);
426 /** Returns true if a notice mask is set
427 * @param sm A notice mask character to check
428 * @return True if the notice mask is set
430 bool IsNoticeMaskSet(unsigned char sm);
432 /** Changed a specific notice mask value
433 * @param sm The server notice mask to change
434 * @param value An on/off value for this mask
436 void SetNoticeMask(unsigned char sm, bool value);
438 /** Create a displayable mode string for this users umodes
439 * @param The mode string
441 const char* FormatModes(bool showparameters = false);
443 /** Returns true if a specific mode is set
444 * @param m The user mode
445 * @return True if the mode is set
447 bool IsModeSet(unsigned char m);
449 /** Set a specific usermode to on or off
450 * @param m The user mode
451 * @param value On or off setting of the mode
453 void SetMode(unsigned char m, bool value);
455 /** Returns true or false for if a user can execute a privilaged oper command.
456 * This is done by looking up their oper type from User::oper, then referencing
457 * this to their oper classes and checking the commands they can execute.
458 * @param command A command (should be all CAPS)
459 * @return True if this user can execute the command
461 virtual bool HasPermission(const std::string &command);
463 /** Returns true if a user has a given permission.
464 * This is used to check whether or not users may perform certain actions which admins may not wish to give to
465 * all operators, yet are not commands. An example might be oper override, mass messaging (/notice $*), etc.
467 * @param privstr The priv to chec, e.g. "users/override/topic". These are loaded free-form from the config file.
468 * @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.
469 * @return True if this user has the permission in question.
471 virtual bool HasPrivPermission(const std::string &privstr, bool noisy = false);
473 /** Returns true or false if a user can set a privileged user or channel mode.
474 * This is done by looking up their oper type from User::oper, then referencing
475 * this to their oper classes, and checking the modes they can set.
476 * @param mode The mode the check
477 * @param type ModeType (MODETYPE_CHANNEL or MODETYPE_USER).
478 * @return True if the user can set or unset this mode.
480 virtual bool HasModePermission(unsigned char mode, ModeType type);
482 /** Creates a wildcard host.
483 * Takes a buffer to use and fills the given buffer with the host in the format *!*@hostname
484 * @return The wildcarded hostname in *!*@host form
486 char* MakeWildHost();
488 /** Creates a usermask with real host.
489 * Takes a buffer to use and fills the given buffer with the hostmask in the format user@host
490 * @return the usermask in the format user@host
492 const std::string& MakeHost();
494 /** Creates a usermask with real ip.
495 * Takes a buffer to use and fills the given buffer with the ipmask in the format user@ip
496 * @return the usermask in the format user@ip
498 const std::string& MakeHostIP();
500 /** Add the user to WHOWAS system
504 /** Oper up the user using the given opertype.
505 * This will also give the +o usermode.
507 void Oper(OperInfo* info);
509 /** Force a nickname change.
510 * If the nickname change fails (for example, because the nick in question
511 * already exists) this function will return false, and you must then either
512 * output an error message, or quit the user for nickname collision.
513 * @param newnick The nickname to change to
514 * @return True if the nickchange was successful.
516 inline bool ForceNickChange(const char* newnick) { return ChangeNick(newnick, true); }
519 * This will clear the +o usermode and unset the user's oper type
523 /** Write text to this user, appending CR/LF. Works on local users only.
524 * @param text A std::string to send to the user
526 virtual void Write(const std::string &text);
528 /** Write text to this user, appending CR/LF.
529 * Works on local users only.
530 * @param text The format string for text to send to the user
531 * @param ... POD-type format arguments
533 virtual void Write(const char *text, ...) CUSTOM_PRINTF(2, 3);
535 /** Write text to this user, appending CR/LF and prepending :server.name
536 * Works on local users only.
537 * @param text A std::string to send to the user
539 void WriteServ(const std::string& text);
541 /** Write text to this user, appending CR/LF and prepending :server.name
542 * Works on local users only.
543 * @param text The format string for text to send to the user
544 * @param ... POD-type format arguments
546 void WriteServ(const char* text, ...) CUSTOM_PRINTF(2, 3);
548 void WriteNumeric(unsigned int numeric, const char* text, ...) CUSTOM_PRINTF(3, 4);
550 void WriteNumeric(unsigned int numeric, 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 A std::string to send to the user
556 void WriteFrom(User *user, const std::string &text);
558 /** Write text to this user, appending CR/LF and prepending :nick!user@host of the user provided in the first parameter.
559 * @param user The user to prepend the :nick!user@host of
560 * @param text The format string for text to send to the user
561 * @param ... POD-type format arguments
563 void WriteFrom(User *user, const char* text, ...) CUSTOM_PRINTF(3, 4);
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 A std::string to send to the user
569 void WriteTo(User *dest, const std::string &data);
571 /** Write text to the user provided in the first parameter, appending CR/LF, and prepending THIS user's :nick!user@host.
572 * @param dest The user to route the message to
573 * @param text The format string for text to send to the user
574 * @param ... POD-type format arguments
576 void WriteTo(User *dest, const char *data, ...) CUSTOM_PRINTF(3, 4);
578 /** Write to all users that can see this user (including this user in the list), appending CR/LF
579 * @param text A std::string to send to the users
581 void WriteCommonRaw(const std::string &line, bool include_self = true);
583 /** Write to all users that can see this user (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 WriteCommon(const char* text, ...) CUSTOM_PRINTF(2, 3);
589 /** Write to all users that can see this user (not including this user in the list), appending CR/LF
590 * @param text The format string for text to send to the users
591 * @param ... POD-type format arguments
593 void WriteCommonExcept(const char* text, ...) CUSTOM_PRINTF(2, 3);
595 /** Write a quit message to all common users, as in User::WriteCommonExcept but with a specific
596 * quit message for opers only.
597 * @param normal_text Normal user quit message
598 * @param oper_text Oper only quit message
600 void WriteCommonQuit(const std::string &normal_text, const std::string &oper_text);
602 /** Dump text to a user target, splitting it appropriately to fit
603 * @param LinePrefix text to prefix each complete line with
604 * @param TextStream the text to send to the user
606 void SendText(const std::string &LinePrefix, std::stringstream &TextStream);
608 /** Write to the user, routing the line if the user is remote.
610 virtual void SendText(const std::string& line) = 0;
612 /** Write to the user, routing the line if the user is remote.
614 void SendText(const char* text, ...) CUSTOM_PRINTF(2, 3);
616 /** Return true if the user shares at least one channel with another user
617 * @param other The other user to compare the channel list against
618 * @return True if the given user shares at least one channel with this user
620 bool SharesChannelWith(User *other);
622 /** Send fake quit/join messages for host or ident cycle.
623 * Run this after the item in question has changed.
624 * You should not need to use this function, call ChangeDisplayedHost instead
626 * @param The entire QUIT line, including the source using the old value
628 void DoHostCycle(const std::string &quitline);
630 /** Change the displayed host of a user.
631 * ALWAYS use this function, rather than writing User::dhost directly,
632 * as this triggers module events allowing the change to be syncronized to
633 * remote servers. This will also emulate a QUIT and rejoin (where configured)
634 * before setting their host field.
635 * @param host The new hostname to set
636 * @return True if the change succeeded, false if it didn't
638 bool ChangeDisplayedHost(const char* host);
640 /** Change the ident (username) of a user.
641 * ALWAYS use this function, rather than writing User::ident directly,
642 * as this correctly causes the user to seem to quit (where configured)
643 * before setting their ident field.
644 * @param host The new ident to set
645 * @return True if the change succeeded, false if it didn't
647 bool ChangeIdent(const char* newident);
649 /** Change a users realname field.
650 * ALWAYS use this function, rather than writing User::fullname directly,
651 * as this triggers module events allowing the change to be syncronized to
653 * @param gecos The user's new realname
654 * @return True if the change succeeded, false if otherwise
656 bool ChangeName(const char* gecos);
658 /** Change a user's nick
659 * @param newnick The new nick
660 * @param force True if the change is being forced (should not be blocked by modes like +N)
661 * @return True if the change succeeded
663 bool ChangeNick(const std::string& newnick, bool force = false);
665 /** Send a command to all local users from this user
666 * The command given must be able to send text with the
667 * first parameter as a servermask (e.g. $*), so basically
668 * you should use PRIVMSG or NOTICE.
669 * @param command the command to send
670 * @param text The text format string to send
671 * @param ... Format arguments
673 void SendAll(const char* command, const char* text, ...) CUSTOM_PRINTF(3, 4);
675 /** Compile a channel list for this user. Used internally by WHOIS
676 * @param source The user to prepare the channel list for
677 * @param spy Whether to return the spy channel list rather than the normal one
678 * @return This user's channel list
680 std::string ChannelList(User* source, bool spy);
682 /** Split the channel list in cl which came from dest, and spool it to this user
683 * Used internally by WHOIS
684 * @param dest The user the original channel list came from
685 * @param cl The channel list as a string obtained from User::ChannelList()
687 void SplitChanList(User* dest, const std::string &cl);
689 /** Remove this user from all channels they are on, and delete any that are now empty.
690 * This is used by QUIT, and will not send part messages!
692 void PurgeEmptyChannels();
694 /** Get the connect class which this user belongs to. NULL for remote users.
695 * @return A pointer to this user's connect class.
697 virtual ConnectClass* GetClass();
699 /** Default destructor
702 virtual CullResult cull();
705 class CoreExport UserIOHandler : public StreamSocket
708 LocalUser* const user;
709 UserIOHandler(LocalUser* me) : user(me) {}
711 void OnError(BufferedSocketError error);
713 /** Adds to the user's write buffer.
714 * You may add any amount of text up to this users sendq value, if you exceed the
715 * sendq value, the user will be removed, and further buffer adds will be dropped.
716 * @param data The data to add to the write buffer
718 void AddWriteBuf(const std::string &data);
721 typedef unsigned int already_sent_t;
723 class CoreExport LocalUser : public User
725 /** A list of channels the user has a pending invite to.
726 * Upon INVITE channels are added, and upon JOIN, the
727 * channels are removed from this list.
732 LocalUser(int fd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
737 /** Stats counter for bytes inbound
741 /** Stats counter for bytes outbound
745 /** Stats counter for commands inbound
749 /** Stats counter for commands outbound
753 /** Password specified by the user when they registered (if any).
754 * This is stored even if the <connect> block doesnt need a password, so that
755 * modules may check it.
757 std::string password;
759 /** Contains a pointer to the connect class a user is on from
761 reference<ConnectClass> MyClass;
763 ConnectClass* GetClass();
765 /** Call this method to find the matching <connect> for a user, and to check them against it.
769 /** Server address and port that this user is connected to.
771 irc::sockets::sockaddrs server_sa;
774 * @return The port number of this user.
778 /** Used by PING checking code
782 /** This value contains how far into the penalty threshold the user is.
783 * This is used either to enable fake lag or for excess flood quits
785 unsigned int CommandFloodPenalty;
787 static already_sent_t already_sent_id;
788 already_sent_t already_sent;
790 /** Stored reverse lookup from res_forward. Should not be used after resolution.
792 std::string stored_host;
794 /** Starts a DNS lookup of the user's IP.
795 * This will cause two UserResolver classes to be instantiated.
796 * When complete, these objects set User::dns_done to true.
798 void StartDNSLookup();
800 /** Use this method to fully connect a user.
801 * This will send the message of the day, check G/K/E lines, etc.
805 /** Set the connect class to which this user belongs to.
806 * @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.
807 * @return A reference to this user's current connect class.
809 void SetClass(const std::string &explicit_name = "");
811 void SendText(const std::string& line);
812 void Write(const std::string& text);
813 void Write(const char*, ...) CUSTOM_PRINTF(2, 3);
815 /** Returns the list of channels this user has been invited to but has not yet joined.
816 * @return A list of channels the user is invited to
818 InvitedList* GetInviteList();
820 /** Returns true if a user is invited to a channel.
821 * @param channel A channel name to look up
822 * @return True if the user is invited to the given channel
824 bool IsInvited(const irc::string &channel);
826 /** Adds a channel to a users invite list (invites them to a channel)
827 * @param channel A channel name to add
828 * @param timeout When the invite should expire (0 == never)
830 void InviteTo(const irc::string &channel, time_t timeout);
832 /** Removes a channel from a users invite list.
833 * This member function is called on successfully joining an invite only channel
834 * to which the user has previously been invited, to clear the invitation.
835 * @param channel The channel to remove the invite to
837 void RemoveInvite(const irc::string &channel);
839 /** Returns true or false for if a user can execute a privilaged oper command.
840 * This is done by looking up their oper type from User::oper, then referencing
841 * this to their oper classes and checking the commands they can execute.
842 * @param command A command (should be all CAPS)
843 * @return True if this user can execute the command
845 bool HasPermission(const std::string &command);
847 /** Returns true if a user has a given permission.
848 * This is used to check whether or not users may perform certain actions which admins may not wish to give to
849 * all operators, yet are not commands. An example might be oper override, mass messaging (/notice $*), etc.
851 * @param privstr The priv to chec, e.g. "users/override/topic". These are loaded free-form from the config file.
852 * @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.
853 * @return True if this user has the permission in question.
855 bool HasPrivPermission(const std::string &privstr, bool noisy = false);
857 /** Returns true or false if a user can set a privileged user or channel mode.
858 * This is done by looking up their oper type from User::oper, then referencing
859 * this to their oper classes, and checking the modes they can set.
860 * @param mode The mode the check
861 * @param type ModeType (MODETYPE_CHANNEL or MODETYPE_USER).
862 * @return True if the user can set or unset this mode.
864 bool HasModePermission(unsigned char mode, ModeType type);
867 class CoreExport RemoteUser : public User
870 RemoteUser(const std::string& uid, const std::string& srv) : User(uid, srv, USERTYPE_REMOTE)
873 virtual void SendText(const std::string& line);
876 class CoreExport FakeUser : public User
879 FakeUser(const std::string &uid, const std::string& srv) : User(uid, srv, USERTYPE_SERVER)
884 virtual CullResult cull();
885 virtual void SendText(const std::string& line);
886 virtual const std::string& GetFullHost();
887 virtual const std::string& GetFullRealHost();
890 /* Faster than dynamic_cast */
891 /** Is a local user */
892 inline LocalUser* IS_LOCAL(User* u)
894 return u->usertype == USERTYPE_LOCAL ? static_cast<LocalUser*>(u) : NULL;
896 /** Is a remote user */
897 inline RemoteUser* IS_REMOTE(User* u)
899 return u->usertype == USERTYPE_REMOTE ? static_cast<RemoteUser*>(u) : NULL;
901 /** Is a server fakeuser */
902 inline FakeUser* IS_SERVER(User* u)
904 return u->usertype == USERTYPE_SERVER ? static_cast<FakeUser*>(u) : NULL;
907 #define IS_OPER(x) (x->oper)
909 #define IS_AWAY(x) (!x->awaymsg.empty())
911 /** Derived from Resolver, and performs user forward/reverse lookups.
913 class CoreExport UserResolver : public Resolver
916 /** UUID we are looking up */
918 /** True if the lookup is forward, false if is a reverse lookup
922 /** Create a resolver.
923 * @param Instance The creating instance
924 * @param user The user to begin lookup on
925 * @param to_resolve The IP or host to resolve
926 * @param qt The query type
927 * @param cache Modified by the constructor if the result was cached
929 UserResolver(LocalUser* user, std::string to_resolve, QueryType qt, bool &cache);
931 /** Called on successful lookup
932 * @param result Result string
933 * @param ttl Time to live for result
934 * @param cached True if the result was found in the cache
936 void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached);
938 /** Called on failed lookup
939 * @param e Error code
940 * @param errormessage Error message string
942 void OnError(ResolverError e, const std::string &errormessage);