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 /** True if max connections for this class is hit and a warning is wanted
128 /** Max channels for this class
130 unsigned int maxchans;
132 /** How many users may be in this connect class before they are refused?
133 * (0 = no limit = default)
137 /** Create a new connect class with no settings.
139 ConnectClass(ConfigTag* tag, char type, const std::string& mask);
140 /** Create a new connect class with inherited settings.
142 ConnectClass(ConfigTag* tag, char type, const std::string& mask, const ConnectClass& parent);
144 /** Update the settings in this block to match the given block */
145 void Update(const ConnectClass* newSettings);
147 const std::string& GetName() { return name; }
148 const std::string& GetHost() { return host; }
150 /** Returns the registration timeout
152 time_t GetRegTimeout()
154 return (registration_timeout ? registration_timeout : 90);
157 /** Returns the ping frequency
159 unsigned int GetPingTime()
161 return (pingtime ? pingtime : 120);
164 /** Returns the maximum sendq value (soft limit)
165 * Note that this is in addition to internal OS buffers
167 unsigned long GetSendqSoftMax()
169 return (softsendqmax ? softsendqmax : 4096);
172 /** Returns the maximum sendq value (hard limit)
174 unsigned long GetSendqHardMax()
176 return (hardsendqmax ? hardsendqmax : 0x100000);
179 /** Returns the maximum recvq value
181 unsigned long GetRecvqMax()
183 return (recvqmax ? recvqmax : 4096);
186 /** Returns the penalty threshold value
188 unsigned int GetPenaltyThreshold()
190 return penaltythreshold ? penaltythreshold : (fakelag ? 10 : 20);
193 unsigned int GetCommandRate()
195 return commandrate ? commandrate : 1000;
198 /** Return the maximum number of local sessions
200 unsigned long GetMaxLocal()
205 /** Returns the maximum number of global sessions
207 unsigned long GetMaxGlobal()
213 /** Holds all information about a user
214 * This class stores all information about a user connected to the irc server. Everything about a
215 * connection is stored here primarily, from the user's socket ID (file descriptor) through to the
216 * user's nickname and hostname.
218 class CoreExport User : public Extensible
221 /** Cached nick!ident@dhost value using the displayed hostname
223 std::string cached_fullhost;
225 /** Cached ident@ip value using the real IP address
227 std::string cached_hostip;
229 /** Cached ident@realhost value using the real hostname
231 std::string cached_makehost;
233 /** Cached nick!ident@realhost value using the real hostname
235 std::string cached_fullrealhost;
237 /** Set by GetIPString() to avoid constantly re-grabbing IP via sockets voodoo.
239 std::string cachedip;
243 /** Hostname of connection.
244 * This should be valid as per RFC1035.
248 /** Time that the object was instantiated (used for TS calculation etc)
252 /** Time the connection was created, set in the constructor. This
253 * may be different from the time the user's classbase object was
258 /** Time that the connection last sent a message, used to calculate idle time
262 /** Client address that the user is connected from.
263 * Do not modify this value directly, use SetClientIP() to change it.
264 * Port is not valid for remote users.
266 irc::sockets::sockaddrs client_sa;
268 /** The users nickname.
269 * An invalid nickname indicates an unregistered connection prior to the NICK command.
270 * Use InspIRCd::IsNick() to validate nicknames.
274 /** The user's unique identifier.
275 * This is the unique identifier which the user has across the network.
277 const std::string uuid;
279 /** The users ident reply.
280 * Two characters are added to the user-defined limit to compensate for the tilde etc.
284 /** The host displayed to non-opers (used for cloaking etc).
285 * This usually matches the value of User::host.
289 /** The users full name (GECOS).
291 std::string fullname;
293 /** The user's mode list.
294 * NOT a null terminated string.
296 * Much love to the STL for giving us an easy to use bitset, saving us RAM.
297 * if (modes[modeletter-65]) is set, then the mode is
298 * set, for example, to work out if mode +s is set, we check the field
299 * User::modes['s'-65] != 0.
300 * The following RFC characters o, w, s, i have constants defined via an
301 * enum, such as UM_SERVERNOTICE and UM_OPETATOR.
303 std::bitset<64> modes;
305 /** What snomasks are set on this user.
306 * This functions the same as the above modes.
308 std::bitset<64> snomasks;
310 /** Channels this user is on
314 /** The server the user is connected to.
316 const std::string server;
318 /** The user's away message.
319 * If this string is empty, the user is not marked as away.
323 /** Time the user last went away.
324 * This is ONLY RELIABLE if user IS_AWAY()!
328 /** The oper type they logged in as, if they are an oper.
330 reference<OperInfo> oper;
332 /** Used by User to indicate the registration status of the connection
333 * It is a bitfield of the REG_NICK, REG_USER and REG_ALL bits to indicate
334 * the connection state.
336 unsigned int registered:3;
338 /** True when DNS lookups are completed.
339 * The UserResolver classes res_forward and res_reverse will
340 * set this value once they complete.
342 unsigned int dns_done:1;
344 /** Whether or not to send an snotice about this user's quitting
346 unsigned int quietquit:1;
348 /** If this is set to true, then all socket operations for the user
349 * are dropped into the bit-bucket.
350 * This value is set by QuitUser, and is not needed seperately from that call.
351 * Please note that setting this value alone will NOT cause the user to quit.
353 unsigned int quitting:1;
355 /** Recursion fix: user is out of SendQ and will be quit as soon as possible.
356 * This can't be handled normally because QuitUser itself calls Write on other
357 * users, which could trigger their SendQ to overrun.
359 unsigned int quitting_sendq:1;
361 /** This is true if the user matched an exception (E:Line). It is used to save time on ban checks.
363 unsigned int exempt:1;
365 /** has the user responded to their previous ping?
367 unsigned int lastping:1;
369 /** What type of user is this? */
370 const unsigned int usertype:2;
372 /** Get client IP string from sockaddr, using static internal buffer
373 * @return The IP string
375 const char* GetIPString();
377 /** Get CIDR mask, using default range, for this user
379 irc::sockets::cidr_mask GetCIDRMask();
381 /** Sets the client IP for this user
382 * @return true if the conversion was successful
384 bool SetClientIP(const char* sip);
387 * @throw CoreException if the UID allocated to the user already exists
389 User(const std::string &uid, const std::string& srv, int objtype);
391 /** Check if the user matches a G or K line, and disconnect them if they do.
392 * @param doZline True if ZLines should be checked (if IP has changed since initial connect)
393 * Returns true if the user matched a ban, false else.
395 bool CheckLines(bool doZline = false);
397 /** Returns the full displayed host of the user
398 * This member function returns the hostname of the user as seen by other users
399 * on the server, in nick!ident&at;host form.
400 * @return The full masked host of the user
402 virtual const std::string& GetFullHost();
404 /** Returns the full real host of the user
405 * This member function returns the hostname of the user as seen by other users
406 * on the server, in nick!ident&at;host form. If any form of hostname cloaking is in operation,
407 * e.g. through a module, then this method will ignore it and return the true hostname.
408 * @return The full real host of the user
410 virtual const std::string& GetFullRealHost();
412 /** This clears any cached results that are used for GetFullRealHost() etc.
413 * The results of these calls are cached as generating them can be generally expensive.
415 void InvalidateCache();
417 /** Create a displayable mode string for this users snomasks
418 * @return The notice mask character sequence
420 const char* FormatNoticeMasks();
422 /** Process a snomask modifier string, e.g. +abc-de
423 * @param sm A sequence of notice mask characters
424 * @return The cleaned mode sequence which can be output,
425 * e.g. in the above example if masks c and e are not
426 * valid, this function will return +ab-d
428 std::string ProcessNoticeMasks(const char *sm);
430 /** Returns true if a notice mask is set
431 * @param sm A notice mask character to check
432 * @return True if the notice mask is set
434 bool IsNoticeMaskSet(unsigned char sm);
436 /** Changed a specific notice mask value
437 * @param sm The server notice mask to change
438 * @param value An on/off value for this mask
440 void SetNoticeMask(unsigned char sm, bool value);
442 /** Create a displayable mode string for this users umodes
443 * @param The mode string
445 const char* FormatModes(bool showparameters = false);
447 /** Returns true if a specific mode is set
448 * @param m The user mode
449 * @return True if the mode is set
451 bool IsModeSet(unsigned char m);
453 /** Set a specific usermode to on or off
454 * @param m The user mode
455 * @param value On or off setting of the mode
457 void SetMode(unsigned char m, bool value);
459 /** Returns true or false for if a user can execute a privilaged oper command.
460 * This is done by looking up their oper type from User::oper, then referencing
461 * this to their oper classes and checking the commands they can execute.
462 * @param command A command (should be all CAPS)
463 * @return True if this user can execute the command
465 virtual bool HasPermission(const std::string &command);
467 /** Returns true if a user has a given permission.
468 * This is used to check whether or not users may perform certain actions which admins may not wish to give to
469 * all operators, yet are not commands. An example might be oper override, mass messaging (/notice $*), etc.
471 * @param privstr The priv to chec, e.g. "users/override/topic". These are loaded free-form from the config file.
472 * @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.
473 * @return True if this user has the permission in question.
475 virtual bool HasPrivPermission(const std::string &privstr, bool noisy = false);
477 /** Returns true or false if a user can set a privileged user or channel mode.
478 * This is done by looking up their oper type from User::oper, then referencing
479 * this to their oper classes, and checking the modes they can set.
480 * @param mode The mode the check
481 * @param type ModeType (MODETYPE_CHANNEL or MODETYPE_USER).
482 * @return True if the user can set or unset this mode.
484 virtual bool HasModePermission(unsigned char mode, ModeType type);
486 /** Creates a wildcard host.
487 * Takes a buffer to use and fills the given buffer with the host in the format *!*@hostname
488 * @return The wildcarded hostname in *!*@host form
490 char* MakeWildHost();
492 /** Creates a usermask with real host.
493 * Takes a buffer to use and fills the given buffer with the hostmask in the format user@host
494 * @return the usermask in the format user@host
496 const std::string& MakeHost();
498 /** Creates a usermask with real ip.
499 * Takes a buffer to use and fills the given buffer with the ipmask in the format user@ip
500 * @return the usermask in the format user@ip
502 const std::string& MakeHostIP();
504 /** Add the user to WHOWAS system
508 /** Oper up the user using the given opertype.
509 * This will also give the +o usermode.
511 void Oper(OperInfo* info);
513 /** Force a nickname change.
514 * If the nickname change fails (for example, because the nick in question
515 * already exists) this function will return false, and you must then either
516 * output an error message, or quit the user for nickname collision.
517 * @param newnick The nickname to change to
518 * @return True if the nickchange was successful.
520 inline bool ForceNickChange(const char* newnick) { return ChangeNick(newnick, true); }
523 * This will clear the +o usermode and unset the user's oper type
527 /** Write text to this user, appending CR/LF. Works on local users only.
528 * @param text A std::string to send to the user
530 virtual void Write(const std::string &text);
532 /** Write text to this user, appending CR/LF.
533 * Works on local users only.
534 * @param text The format string for text to send to the user
535 * @param ... POD-type format arguments
537 virtual void Write(const char *text, ...) CUSTOM_PRINTF(2, 3);
539 /** Write text to this user, appending CR/LF and prepending :server.name
540 * Works on local users only.
541 * @param text A std::string to send to the user
543 void WriteServ(const std::string& text);
545 /** Write text to this user, appending CR/LF and prepending :server.name
546 * Works on local users only.
547 * @param text The format string for text to send to the user
548 * @param ... POD-type format arguments
550 void WriteServ(const char* text, ...) CUSTOM_PRINTF(2, 3);
552 void WriteNumeric(unsigned int numeric, const char* text, ...) CUSTOM_PRINTF(3, 4);
554 void WriteNumeric(unsigned int numeric, const std::string &text);
556 /** Write text to this user, appending CR/LF and prepending :nick!user@host of the user provided in the first parameter.
557 * @param user The user to prepend the :nick!user@host of
558 * @param text A std::string to send to the user
560 void WriteFrom(User *user, const std::string &text);
562 /** Write text to this user, appending CR/LF and prepending :nick!user@host of the user provided in the first parameter.
563 * @param user The user to prepend the :nick!user@host of
564 * @param text The format string for text to send to the user
565 * @param ... POD-type format arguments
567 void WriteFrom(User *user, const char* text, ...) CUSTOM_PRINTF(3, 4);
569 /** Write text to the user provided in the first parameter, appending CR/LF, and prepending THIS user's :nick!user@host.
570 * @param dest The user to route the message to
571 * @param text A std::string to send to the user
573 void WriteTo(User *dest, const std::string &data);
575 /** Write text to the user provided in the first parameter, appending CR/LF, and prepending THIS user's :nick!user@host.
576 * @param dest The user to route the message to
577 * @param text The format string for text to send to the user
578 * @param ... POD-type format arguments
580 void WriteTo(User *dest, const char *data, ...) CUSTOM_PRINTF(3, 4);
582 /** Write to all users that can see this user (including this user in the list), appending CR/LF
583 * @param text A std::string to send to the users
585 void WriteCommonRaw(const std::string &line, bool include_self = true);
587 /** Write to all users that can see this user (including this user in the list), appending CR/LF
588 * @param text The format string for text to send to the users
589 * @param ... POD-type format arguments
591 void WriteCommon(const char* text, ...) CUSTOM_PRINTF(2, 3);
593 /** Write to all users that can see this user (not including this user in the list), appending CR/LF
594 * @param text The format string for text to send to the users
595 * @param ... POD-type format arguments
597 void WriteCommonExcept(const char* text, ...) CUSTOM_PRINTF(2, 3);
599 /** Write a quit message to all common users, as in User::WriteCommonExcept but with a specific
600 * quit message for opers only.
601 * @param normal_text Normal user quit message
602 * @param oper_text Oper only quit message
604 void WriteCommonQuit(const std::string &normal_text, const std::string &oper_text);
606 /** Dump text to a user target, splitting it appropriately to fit
607 * @param LinePrefix text to prefix each complete line with
608 * @param TextStream the text to send to the user
610 void SendText(const std::string &LinePrefix, std::stringstream &TextStream);
612 /** Write to the user, routing the line if the user is remote.
614 virtual void SendText(const std::string& line) = 0;
616 /** Write to the user, routing the line if the user is remote.
618 void SendText(const char* text, ...) CUSTOM_PRINTF(2, 3);
620 /** Return true if the user shares at least one channel with another user
621 * @param other The other user to compare the channel list against
622 * @return True if the given user shares at least one channel with this user
624 bool SharesChannelWith(User *other);
626 /** Send fake quit/join messages for host or ident cycle.
627 * Run this after the item in question has changed.
628 * You should not need to use this function, call ChangeDisplayedHost instead
630 * @param The entire QUIT line, including the source using the old value
632 void DoHostCycle(const std::string &quitline);
634 /** Change the displayed host of a user.
635 * ALWAYS use this function, rather than writing User::dhost directly,
636 * as this triggers module events allowing the change to be syncronized to
637 * remote servers. This will also emulate a QUIT and rejoin (where configured)
638 * before setting their host field.
639 * @param host The new hostname to set
640 * @return True if the change succeeded, false if it didn't
642 bool ChangeDisplayedHost(const char* host);
644 /** Change the ident (username) of a user.
645 * ALWAYS use this function, rather than writing User::ident directly,
646 * as this correctly causes the user to seem to quit (where configured)
647 * before setting their ident field.
648 * @param host The new ident to set
649 * @return True if the change succeeded, false if it didn't
651 bool ChangeIdent(const char* newident);
653 /** Change a users realname field.
654 * ALWAYS use this function, rather than writing User::fullname directly,
655 * as this triggers module events allowing the change to be syncronized to
657 * @param gecos The user's new realname
658 * @return True if the change succeeded, false if otherwise
660 bool ChangeName(const char* gecos);
662 /** Change a user's nick
663 * @param newnick The new nick
664 * @param force True if the change is being forced (should not be blocked by modes like +N)
665 * @return True if the change succeeded
667 bool ChangeNick(const std::string& newnick, bool force = false);
669 /** Send a command to all local users from this user
670 * The command given must be able to send text with the
671 * first parameter as a servermask (e.g. $*), so basically
672 * you should use PRIVMSG or NOTICE.
673 * @param command the command to send
674 * @param text The text format string to send
675 * @param ... Format arguments
677 void SendAll(const char* command, const char* text, ...) CUSTOM_PRINTF(3, 4);
679 /** Compile a channel list for this user. Used internally by WHOIS
680 * @param source The user to prepare the channel list for
681 * @param spy Whether to return the spy channel list rather than the normal one
682 * @return This user's channel list
684 std::string ChannelList(User* source, bool spy);
686 /** Split the channel list in cl which came from dest, and spool it to this user
687 * Used internally by WHOIS
688 * @param dest The user the original channel list came from
689 * @param cl The channel list as a string obtained from User::ChannelList()
691 void SplitChanList(User* dest, const std::string &cl);
693 /** Remove this user from all channels they are on, and delete any that are now empty.
694 * This is used by QUIT, and will not send part messages!
696 void PurgeEmptyChannels();
698 /** Get the connect class which this user belongs to. NULL for remote users.
699 * @return A pointer to this user's connect class.
701 virtual ConnectClass* GetClass();
703 /** Default destructor
706 virtual CullResult cull();
709 class CoreExport UserIOHandler : public StreamSocket
712 LocalUser* const user;
713 UserIOHandler(LocalUser* me) : user(me) {}
715 void OnError(BufferedSocketError error);
717 /** Adds to the user's write buffer.
718 * You may add any amount of text up to this users sendq value, if you exceed the
719 * sendq value, the user will be removed, and further buffer adds will be dropped.
720 * @param data The data to add to the write buffer
722 void AddWriteBuf(const std::string &data);
725 typedef unsigned int already_sent_t;
727 class CoreExport LocalUser : public User
729 /** A list of channels the user has a pending invite to.
730 * Upon INVITE channels are added, and upon JOIN, the
731 * channels are removed from this list.
736 LocalUser(int fd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
741 /** Stats counter for bytes inbound
745 /** Stats counter for bytes outbound
749 /** Stats counter for commands inbound
753 /** Stats counter for commands outbound
757 /** Password specified by the user when they registered (if any).
758 * This is stored even if the <connect> block doesnt need a password, so that
759 * modules may check it.
761 std::string password;
763 /** Contains a pointer to the connect class a user is on from
765 reference<ConnectClass> MyClass;
767 ConnectClass* GetClass();
769 /** Call this method to find the matching <connect> for a user, and to check them against it.
773 /** Server address and port that this user is connected to.
775 irc::sockets::sockaddrs server_sa;
778 * @return The port number of this user.
782 /** Used by PING checking code
786 /** This value contains how far into the penalty threshold the user is.
787 * This is used either to enable fake lag or for excess flood quits
789 unsigned int CommandFloodPenalty;
791 static already_sent_t already_sent_id;
792 already_sent_t already_sent;
794 /** Stored reverse lookup from res_forward. Should not be used after resolution.
796 std::string stored_host;
798 /** Starts a DNS lookup of the user's IP.
799 * This will cause two UserResolver classes to be instantiated.
800 * When complete, these objects set User::dns_done to true.
802 void StartDNSLookup();
804 /** Use this method to fully connect a user.
805 * This will send the message of the day, check G/K/E lines, etc.
809 /** Set the connect class to which this user belongs to.
810 * @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.
811 * @return A reference to this user's current connect class.
813 void SetClass(const std::string &explicit_name = "");
815 void SendText(const std::string& line);
816 void Write(const std::string& text);
817 void Write(const char*, ...) CUSTOM_PRINTF(2, 3);
819 /** Returns the list of channels this user has been invited to but has not yet joined.
820 * @return A list of channels the user is invited to
822 InvitedList* GetInviteList();
824 /** Returns true if a user is invited to a channel.
825 * @param channel A channel name to look up
826 * @return True if the user is invited to the given channel
828 bool IsInvited(const irc::string &channel);
830 /** Adds a channel to a users invite list (invites them to a channel)
831 * @param channel A channel name to add
832 * @param timeout When the invite should expire (0 == never)
834 void InviteTo(const irc::string &channel, time_t timeout);
836 /** Removes a channel from a users invite list.
837 * This member function is called on successfully joining an invite only channel
838 * to which the user has previously been invited, to clear the invitation.
839 * @param channel The channel to remove the invite to
841 void RemoveInvite(const irc::string &channel);
843 /** Returns true or false for if a user can execute a privilaged oper command.
844 * This is done by looking up their oper type from User::oper, then referencing
845 * this to their oper classes and checking the commands they can execute.
846 * @param command A command (should be all CAPS)
847 * @return True if this user can execute the command
849 bool HasPermission(const std::string &command);
851 /** Returns true if a user has a given permission.
852 * This is used to check whether or not users may perform certain actions which admins may not wish to give to
853 * all operators, yet are not commands. An example might be oper override, mass messaging (/notice $*), etc.
855 * @param privstr The priv to chec, e.g. "users/override/topic". These are loaded free-form from the config file.
856 * @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.
857 * @return True if this user has the permission in question.
859 bool HasPrivPermission(const std::string &privstr, bool noisy = false);
861 /** Returns true or false if a user can set a privileged user or channel mode.
862 * This is done by looking up their oper type from User::oper, then referencing
863 * this to their oper classes, and checking the modes they can set.
864 * @param mode The mode the check
865 * @param type ModeType (MODETYPE_CHANNEL or MODETYPE_USER).
866 * @return True if the user can set or unset this mode.
868 bool HasModePermission(unsigned char mode, ModeType type);
871 class CoreExport RemoteUser : public User
874 RemoteUser(const std::string& uid, const std::string& srv) : User(uid, srv, USERTYPE_REMOTE)
877 virtual void SendText(const std::string& line);
880 class CoreExport FakeUser : public User
883 FakeUser(const std::string &uid, const std::string& srv) : User(uid, srv, USERTYPE_SERVER)
888 virtual CullResult cull();
889 virtual void SendText(const std::string& line);
890 virtual const std::string& GetFullHost();
891 virtual const std::string& GetFullRealHost();
894 /* Faster than dynamic_cast */
895 /** Is a local user */
896 inline LocalUser* IS_LOCAL(User* u)
898 return u->usertype == USERTYPE_LOCAL ? static_cast<LocalUser*>(u) : NULL;
900 /** Is a remote user */
901 inline RemoteUser* IS_REMOTE(User* u)
903 return u->usertype == USERTYPE_REMOTE ? static_cast<RemoteUser*>(u) : NULL;
905 /** Is a server fakeuser */
906 inline FakeUser* IS_SERVER(User* u)
908 return u->usertype == USERTYPE_SERVER ? static_cast<FakeUser*>(u) : NULL;
911 #define IS_OPER(x) (x->oper)
913 #define IS_AWAY(x) (!x->awaymsg.empty())
915 /** Derived from Resolver, and performs user forward/reverse lookups.
917 class CoreExport UserResolver : public Resolver
920 /** UUID we are looking up */
922 /** True if the lookup is forward, false if is a reverse lookup
926 /** Create a resolver.
927 * @param Instance The creating instance
928 * @param user The user to begin lookup on
929 * @param to_resolve The IP or host to resolve
930 * @param qt The query type
931 * @param cache Modified by the constructor if the result was cached
933 UserResolver(LocalUser* user, std::string to_resolve, QueryType qt, bool &cache);
935 /** Called on successful lookup
936 * @param result Result string
937 * @param ttl Time to live for result
938 * @param cached True if the result was found in the cache
940 void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached);
942 /** Called on failed lookup
943 * @param e Error code
944 * @param errormessage Error message string
946 void OnError(ResolverError e, const std::string &errormessage);