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"
32 #include "membership.h"
34 /** connect class types
41 /** named connect block (for opers, etc) */
45 /** RFC1459 channel modes
48 /** +s: Server notice mask */
49 UM_SNOMASK = 's' - 65,
51 UM_WALLOPS = 'w' - 65,
53 UM_INVISIBLE = 'i' - 65,
55 UM_OPERATOR = 'o' - 65
58 /** Registration state of a user, e.g.
59 * have they sent USER, NICK, PASS yet?
61 enum RegistrationState {
63 #ifndef WIN32 // Burlex: This is already defined in win32, luckily it is still 0.
64 REG_NONE = 0, /* Has sent nothing */
67 REG_USER = 1, /* Has sent USER */
68 REG_NICK = 2, /* Has sent NICK */
69 REG_NICKUSER = 3, /* Bitwise combination of REG_NICK and REG_USER */
70 REG_ALL = 7 /* REG_NICKUSER plus next bit along */
79 /** Holds information relevent to <connect allow> and <connect deny> tags in the config file.
81 struct CoreExport ConnectClass : public refcountbase
83 reference<ConfigTag> config;
84 /** Type of line, either CC_ALLOW or CC_DENY
88 /** True if this class uses fake lag to manage flood, false if it kills */
91 /** Connect class name
95 /** Max time to register the connection in seconds
97 unsigned int registration_timeout;
99 /** Host mask for this line
103 /** Number of seconds between pings for this line
105 unsigned int pingtime;
107 /** Maximum size of sendq for users in this class (bytes)
108 * Users cannot send commands if they go over this limit
110 unsigned long softsendqmax;
112 /** Maximum size of sendq for users in this class (bytes)
113 * Users are killed if they go over this limit
115 unsigned long hardsendqmax;
117 /** Maximum size of recvq for users in this class (bytes)
119 unsigned long recvqmax;
121 /** Seconds worth of penalty before penalty system activates
123 unsigned int penaltythreshold;
125 /** Maximum rate of commands (units: millicommands per second) */
126 unsigned int commandrate;
128 /** Local max when connecting by this connection class
130 unsigned long maxlocal;
132 /** Global max when connecting by this connection class
134 unsigned long maxglobal;
136 /** True if max connections for this class is hit and a warning is wanted
140 /** Max channels for this class
142 unsigned int maxchans;
144 /** How many users may be in this connect class before they are refused?
145 * (0 = no limit = default)
149 /** Create a new connect class with no settings.
151 ConnectClass(ConfigTag* tag, char type, const std::string& mask);
152 /** Create a new connect class with inherited settings.
154 ConnectClass(ConfigTag* tag, char type, const std::string& mask, const ConnectClass& parent);
156 /** Update the settings in this block to match the given block */
157 void Update(const ConnectClass* newSettings);
159 const std::string& GetName() { return name; }
160 const std::string& GetHost() { return host; }
162 /** Returns the registration timeout
164 time_t GetRegTimeout()
166 return (registration_timeout ? registration_timeout : 90);
169 /** Returns the ping frequency
171 unsigned int GetPingTime()
173 return (pingtime ? pingtime : 120);
176 /** Returns the maximum sendq value (soft limit)
177 * Note that this is in addition to internal OS buffers
179 unsigned long GetSendqSoftMax()
181 return (softsendqmax ? softsendqmax : 4096);
184 /** Returns the maximum sendq value (hard limit)
186 unsigned long GetSendqHardMax()
188 return (hardsendqmax ? hardsendqmax : 0x100000);
191 /** Returns the maximum recvq value
193 unsigned long GetRecvqMax()
195 return (recvqmax ? recvqmax : 4096);
198 /** Returns the penalty threshold value
200 unsigned int GetPenaltyThreshold()
202 return penaltythreshold ? penaltythreshold : (fakelag ? 10 : 20);
205 unsigned int GetCommandRate()
207 return commandrate ? commandrate : 1000;
210 /** Return the maximum number of local sessions
212 unsigned long GetMaxLocal()
217 /** Returns the maximum number of global sessions
219 unsigned long GetMaxGlobal()
225 /** Holds all information about a user
226 * This class stores all information about a user connected to the irc server. Everything about a
227 * connection is stored here primarily, from the user's socket ID (file descriptor) through to the
228 * user's nickname and hostname.
230 class CoreExport User : public Extensible
233 /** Cached nick!ident@dhost value using the displayed hostname
235 std::string cached_fullhost;
237 /** Cached ident@ip value using the real IP address
239 std::string cached_hostip;
241 /** Cached ident@realhost value using the real hostname
243 std::string cached_makehost;
245 /** Cached nick!ident@realhost value using the real hostname
247 std::string cached_fullrealhost;
249 /** Set by GetIPString() to avoid constantly re-grabbing IP via sockets voodoo.
251 std::string cachedip;
255 /** Hostname of connection.
256 * This should be valid as per RFC1035.
260 /** Time that the object was instantiated (used for TS calculation etc)
264 /** Time the connection was created, set in the constructor. This
265 * may be different from the time the user's classbase object was
270 /** Time that the connection last sent a message, used to calculate idle time
274 /** Client address that the user is connected from.
275 * Do not modify this value directly, use SetClientIP() to change it.
276 * Port is not valid for remote users.
278 irc::sockets::sockaddrs client_sa;
280 /** The users nickname.
281 * An invalid nickname indicates an unregistered connection prior to the NICK command.
282 * Use InspIRCd::IsNick() to validate nicknames.
286 /** The user's unique identifier.
287 * This is the unique identifier which the user has across the network.
289 const std::string uuid;
291 /** The users ident reply.
292 * Two characters are added to the user-defined limit to compensate for the tilde etc.
296 /** The host displayed to non-opers (used for cloaking etc).
297 * This usually matches the value of User::host.
301 /** The users full name (GECOS).
303 std::string fullname;
305 /** The user's mode list.
306 * NOT a null terminated string.
308 * Much love to the STL for giving us an easy to use bitset, saving us RAM.
309 * if (modes[modeletter-65]) is set, then the mode is
310 * set, for example, to work out if mode +s is set, we check the field
311 * User::modes['s'-65] != 0.
312 * The following RFC characters o, w, s, i have constants defined via an
313 * enum, such as UM_SERVERNOTICE and UM_OPETATOR.
315 std::bitset<64> modes;
317 /** What snomasks are set on this user.
318 * This functions the same as the above modes.
320 std::bitset<64> snomasks;
322 /** Channels this user is on
326 /** The server the user is connected to.
328 const std::string server;
330 /** The user's away message.
331 * If this string is empty, the user is not marked as away.
335 /** Time the user last went away.
336 * This is ONLY RELIABLE if user IS_AWAY()!
340 /** The oper type they logged in as, if they are an oper.
342 reference<OperInfo> oper;
344 /** Used by User to indicate the registration status of the connection
345 * It is a bitfield of the REG_NICK, REG_USER and REG_ALL bits to indicate
346 * the connection state.
348 unsigned int registered:3;
350 /** True when DNS lookups are completed.
351 * The UserResolver classes res_forward and res_reverse will
352 * set this value once they complete.
354 unsigned int dns_done:1;
356 /** Whether or not to send an snotice about this user's quitting
358 unsigned int quietquit:1;
360 /** If this is set to true, then all socket operations for the user
361 * are dropped into the bit-bucket.
362 * This value is set by QuitUser, and is not needed seperately from that call.
363 * Please note that setting this value alone will NOT cause the user to quit.
365 unsigned int quitting:1;
367 /** Recursion fix: user is out of SendQ and will be quit as soon as possible.
368 * This can't be handled normally because QuitUser itself calls Write on other
369 * users, which could trigger their SendQ to overrun.
371 unsigned int quitting_sendq:1;
373 /** This is true if the user matched an exception (E:Line). It is used to save time on ban checks.
375 unsigned int exempt:1;
377 /** has the user responded to their previous ping?
379 unsigned int lastping:1;
381 /** What type of user is this? */
382 const unsigned int usertype:2;
384 /** Get client IP string from sockaddr, using static internal buffer
385 * @return The IP string
387 const char* GetIPString();
389 /** Get CIDR mask, using default range, for this user
391 irc::sockets::cidr_mask GetCIDRMask();
393 /** Sets the client IP for this user
394 * @return true if the conversion was successful
396 bool SetClientIP(const char* sip);
398 /** Sets the client IP for this user
399 * @return true always
401 bool SetClientIP(irc::sockets::sockaddrs *sa);
404 * @throw CoreException if the UID allocated to the user already exists
406 User(const std::string &uid, const std::string& srv, int objtype);
408 /** Check if the user matches a G or K line, and disconnect them if they do.
409 * @param doZline True if ZLines should be checked (if IP has changed since initial connect)
410 * Returns true if the user matched a ban, false else.
412 bool CheckLines(bool doZline = false);
414 /** Returns the full displayed host of the user
415 * This member function returns the hostname of the user as seen by other users
416 * on the server, in nick!ident&at;host form.
417 * @return The full masked host of the user
419 virtual const std::string& GetFullHost();
421 /** Returns the full real host of the user
422 * This member function returns the hostname of the user as seen by other users
423 * on the server, in nick!ident&at;host form. If any form of hostname cloaking is in operation,
424 * e.g. through a module, then this method will ignore it and return the true hostname.
425 * @return The full real host of the user
427 virtual const std::string& GetFullRealHost();
429 /** This clears any cached results that are used for GetFullRealHost() etc.
430 * The results of these calls are cached as generating them can be generally expensive.
432 void InvalidateCache();
434 /** Create a displayable mode string for this users snomasks
435 * @return The notice mask character sequence
437 const char* FormatNoticeMasks();
439 /** Process a snomask modifier string, e.g. +abc-de
440 * @param sm A sequence of notice mask characters
441 * @return The cleaned mode sequence which can be output,
442 * e.g. in the above example if masks c and e are not
443 * valid, this function will return +ab-d
445 std::string ProcessNoticeMasks(const char *sm);
447 /** Returns true if a notice mask is set
448 * @param sm A notice mask character to check
449 * @return True if the notice mask is set
451 bool IsNoticeMaskSet(unsigned char sm);
453 /** Changed a specific notice mask value
454 * @param sm The server notice mask to change
455 * @param value An on/off value for this mask
457 void SetNoticeMask(unsigned char sm, bool value);
459 /** Create a displayable mode string for this users umodes
460 * @param The mode string
462 const char* FormatModes(bool showparameters = false);
464 /** Returns true if a specific mode is set
465 * @param m The user mode
466 * @return True if the mode is set
468 bool IsModeSet(unsigned char m);
470 /** Set a specific usermode to on or off
471 * @param m The user mode
472 * @param value On or off setting of the mode
474 void SetMode(unsigned char m, bool value);
476 /** Returns true or false for if a user can execute a privilaged oper command.
477 * This is done by looking up their oper type from User::oper, then referencing
478 * this to their oper classes and checking the commands they can execute.
479 * @param command A command (should be all CAPS)
480 * @return True if this user can execute the command
482 virtual bool HasPermission(const std::string &command);
484 /** Returns true if a user has a given permission.
485 * This is used to check whether or not users may perform certain actions which admins may not wish to give to
486 * all operators, yet are not commands. An example might be oper override, mass messaging (/notice $*), etc.
488 * @param privstr The priv to chec, e.g. "users/override/topic". These are loaded free-form from the config file.
489 * @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.
490 * @return True if this user has the permission in question.
492 virtual bool HasPrivPermission(const std::string &privstr, bool noisy = false);
494 /** Returns true or false if a user can set a privileged user or channel mode.
495 * This is done by looking up their oper type from User::oper, then referencing
496 * this to their oper classes, and checking the modes they can set.
497 * @param mode The mode the check
498 * @param type ModeType (MODETYPE_CHANNEL or MODETYPE_USER).
499 * @return True if the user can set or unset this mode.
501 virtual bool HasModePermission(unsigned char mode, ModeType type);
503 /** Creates a wildcard host.
504 * Takes a buffer to use and fills the given buffer with the host in the format *!*@hostname
505 * @return The wildcarded hostname in *!*@host form
507 char* MakeWildHost();
509 /** Creates a usermask with real host.
510 * Takes a buffer to use and fills the given buffer with the hostmask in the format user@host
511 * @return the usermask in the format user@host
513 const std::string& MakeHost();
515 /** Creates a usermask with real ip.
516 * Takes a buffer to use and fills the given buffer with the ipmask in the format user@ip
517 * @return the usermask in the format user@ip
519 const std::string& MakeHostIP();
521 /** Add the user to WHOWAS system
525 /** Oper up the user using the given opertype.
526 * This will also give the +o usermode.
528 void Oper(OperInfo* info);
530 /** Force a nickname change.
531 * If the nickname change fails (for example, because the nick in question
532 * already exists) this function will return false, and you must then either
533 * output an error message, or quit the user for nickname collision.
534 * @param newnick The nickname to change to
535 * @return True if the nickchange was successful.
537 inline bool ForceNickChange(const char* newnick) { return ChangeNick(newnick, true); }
540 * This will clear the +o usermode and unset the user's oper type
544 /** Write text to this user, appending CR/LF. Works on local users only.
545 * @param text A std::string to send to the user
547 virtual void Write(const std::string &text);
549 /** Write text to this user, appending CR/LF.
550 * Works on local users only.
551 * @param text The format string for text to send to the user
552 * @param ... POD-type format arguments
554 virtual void Write(const char *text, ...) CUSTOM_PRINTF(2, 3);
556 /** Write text to this user, appending CR/LF and prepending :server.name
557 * Works on local users only.
558 * @param text A std::string to send to the user
560 void WriteServ(const std::string& text);
562 /** Write text to this user, appending CR/LF and prepending :server.name
563 * Works on local users only.
564 * @param text The format string for text to send to the user
565 * @param ... POD-type format arguments
567 void WriteServ(const char* text, ...) CUSTOM_PRINTF(2, 3);
569 void WriteNumeric(unsigned int numeric, const char* text, ...) CUSTOM_PRINTF(3, 4);
571 void WriteNumeric(unsigned int numeric, const std::string &text);
573 /** Write text to this user, appending CR/LF and prepending :nick!user@host of the user provided in the first parameter.
574 * @param user The user to prepend the :nick!user@host of
575 * @param text A std::string to send to the user
577 void WriteFrom(User *user, const std::string &text);
579 /** Write text to this user, appending CR/LF and prepending :nick!user@host of the user provided in the first parameter.
580 * @param user The user to prepend the :nick!user@host of
581 * @param text The format string for text to send to the user
582 * @param ... POD-type format arguments
584 void WriteFrom(User *user, const char* text, ...) CUSTOM_PRINTF(3, 4);
586 /** Write text to the user provided in the first parameter, appending CR/LF, and prepending THIS user's :nick!user@host.
587 * @param dest The user to route the message to
588 * @param text A std::string to send to the user
590 void WriteTo(User *dest, const std::string &data);
592 /** Write text to the user provided in the first parameter, appending CR/LF, and prepending THIS user's :nick!user@host.
593 * @param dest The user to route the message to
594 * @param text The format string for text to send to the user
595 * @param ... POD-type format arguments
597 void WriteTo(User *dest, const char *data, ...) CUSTOM_PRINTF(3, 4);
599 /** Write to all users that can see this user (including this user in the list), appending CR/LF
600 * @param text A std::string to send to the users
602 void WriteCommonRaw(const std::string &line, bool include_self = true);
604 /** Write to all users that can see this user (including this user in the list), appending CR/LF
605 * @param text The format string for text to send to the users
606 * @param ... POD-type format arguments
608 void WriteCommon(const char* text, ...) CUSTOM_PRINTF(2, 3);
610 /** Write to all users that can see this user (not including this user in the list), appending CR/LF
611 * @param text The format string for text to send to the users
612 * @param ... POD-type format arguments
614 void WriteCommonExcept(const char* text, ...) CUSTOM_PRINTF(2, 3);
616 /** Write a quit message to all common users, as in User::WriteCommonExcept but with a specific
617 * quit message for opers only.
618 * @param normal_text Normal user quit message
619 * @param oper_text Oper only quit message
621 void WriteCommonQuit(const std::string &normal_text, const std::string &oper_text);
623 /** Dump text to a user target, splitting it appropriately to fit
624 * @param LinePrefix text to prefix each complete line with
625 * @param TextStream the text to send to the user
627 void SendText(const std::string &LinePrefix, std::stringstream &TextStream);
629 /** Write to the user, routing the line if the user is remote.
631 virtual void SendText(const std::string& line) = 0;
633 /** Write to the user, routing the line if the user is remote.
635 void SendText(const char* text, ...) CUSTOM_PRINTF(2, 3);
637 /** Return true if the user shares at least one channel with another user
638 * @param other The other user to compare the channel list against
639 * @return True if the given user shares at least one channel with this user
641 bool SharesChannelWith(User *other);
643 /** Send fake quit/join messages for host or ident cycle.
644 * Run this after the item in question has changed.
645 * You should not need to use this function, call ChangeDisplayedHost instead
647 * @param The entire QUIT line, including the source using the old value
649 void DoHostCycle(const std::string &quitline);
651 /** Change the displayed host of a user.
652 * ALWAYS use this function, rather than writing User::dhost directly,
653 * as this triggers module events allowing the change to be syncronized to
654 * remote servers. This will also emulate a QUIT and rejoin (where configured)
655 * before setting their host field.
656 * @param host The new hostname to set
657 * @return True if the change succeeded, false if it didn't
659 bool ChangeDisplayedHost(const char* host);
661 /** Change the ident (username) of a user.
662 * ALWAYS use this function, rather than writing User::ident directly,
663 * as this correctly causes the user to seem to quit (where configured)
664 * before setting their ident field.
665 * @param host The new ident to set
666 * @return True if the change succeeded, false if it didn't
668 bool ChangeIdent(const char* newident);
670 /** Change a users realname field.
671 * ALWAYS use this function, rather than writing User::fullname directly,
672 * as this triggers module events allowing the change to be syncronized to
674 * @param gecos The user's new realname
675 * @return True if the change succeeded, false if otherwise
677 bool ChangeName(const char* gecos);
679 /** Change a user's nick
680 * @param newnick The new nick
681 * @param force True if the change is being forced (should not be blocked by modes like +N)
682 * @return True if the change succeeded
684 bool ChangeNick(const std::string& newnick, bool force = false);
686 /** Send a command to all local users from this user
687 * The command given must be able to send text with the
688 * first parameter as a servermask (e.g. $*), so basically
689 * you should use PRIVMSG or NOTICE.
690 * @param command the command to send
691 * @param text The text format string to send
692 * @param ... Format arguments
694 void SendAll(const char* command, const char* text, ...) CUSTOM_PRINTF(3, 4);
696 /** Compile a channel list for this user. Used internally by WHOIS
697 * @param source The user to prepare the channel list for
698 * @param spy Whether to return the spy channel list rather than the normal one
699 * @return This user's channel list
701 std::string ChannelList(User* source, bool spy);
703 /** Split the channel list in cl which came from dest, and spool it to this user
704 * Used internally by WHOIS
705 * @param dest The user the original channel list came from
706 * @param cl The channel list as a string obtained from User::ChannelList()
708 void SplitChanList(User* dest, const std::string &cl);
710 /** Remove this user from all channels they are on, and delete any that are now empty.
711 * This is used by QUIT, and will not send part messages!
713 void PurgeEmptyChannels();
715 /** Get the connect class which this user belongs to. NULL for remote users.
716 * @return A pointer to this user's connect class.
718 virtual ConnectClass* GetClass();
720 /** Default destructor
723 virtual CullResult cull();
726 class CoreExport UserIOHandler : public StreamSocket
729 LocalUser* const user;
730 UserIOHandler(LocalUser* me) : user(me) {}
732 void OnError(BufferedSocketError error);
734 /** Adds to the user's write buffer.
735 * You may add any amount of text up to this users sendq value, if you exceed the
736 * sendq value, the user will be removed, and further buffer adds will be dropped.
737 * @param data The data to add to the write buffer
739 void AddWriteBuf(const std::string &data);
742 typedef unsigned int already_sent_t;
744 class CoreExport LocalUser : public User, public InviteBase
747 LocalUser(int fd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
752 /** Stats counter for bytes inbound
756 /** Stats counter for bytes outbound
760 /** Stats counter for commands inbound
764 /** Stats counter for commands outbound
768 /** Password specified by the user when they registered (if any).
769 * This is stored even if the <connect> block doesnt need a password, so that
770 * modules may check it.
772 std::string password;
774 /** Contains a pointer to the connect class a user is on from
776 reference<ConnectClass> MyClass;
778 ConnectClass* GetClass();
780 /** Call this method to find the matching <connect> for a user, and to check them against it.
784 /** Server address and port that this user is connected to.
786 irc::sockets::sockaddrs server_sa;
789 * @return The port number of this user.
793 /** Used by PING checking code
797 /** This value contains how far into the penalty threshold the user is.
798 * This is used either to enable fake lag or for excess flood quits
800 unsigned int CommandFloodPenalty;
802 static already_sent_t already_sent_id;
803 already_sent_t already_sent;
805 /** Stored reverse lookup from res_forward. Should not be used after resolution.
807 std::string stored_host;
809 /** Starts a DNS lookup of the user's IP.
810 * This will cause two UserResolver classes to be instantiated.
811 * When complete, these objects set User::dns_done to true.
813 void StartDNSLookup();
815 /** Use this method to fully connect a user.
816 * This will send the message of the day, check G/K/E lines, etc.
820 /** Set the connect class to which this user belongs to.
821 * @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.
822 * @return A reference to this user's current connect class.
824 void SetClass(const std::string &explicit_name = "");
826 void SendText(const std::string& line);
827 void Write(const std::string& text);
828 void Write(const char*, ...) CUSTOM_PRINTF(2, 3);
830 /** Returns the list of channels this user has been invited to but has not yet joined.
831 * @return A list of channels the user is invited to
833 InviteList& GetInviteList();
835 /** Returns true if a user is invited to a channel.
836 * @param channel A channel name to look up
837 * @return True if the user is invited to the given channel
839 bool IsInvited(const irc::string &channel);
841 /** Adds a channel to a users invite list (invites them to a channel)
842 * @param channel A channel name to add
843 * @param timeout When the invite should expire (0 == never)
845 void InviteTo(const irc::string &channel, time_t timeout);
847 /** Removes a channel from a users invite list.
848 * This member function is called on successfully joining an invite only channel
849 * to which the user has previously been invited, to clear the invitation.
850 * @param channel The channel to remove the invite to
852 void RemoveInvite(const irc::string &channel);
854 void RemoveExpiredInvites();
856 /** Returns true or false for if a user can execute a privilaged oper command.
857 * This is done by looking up their oper type from User::oper, then referencing
858 * this to their oper classes and checking the commands they can execute.
859 * @param command A command (should be all CAPS)
860 * @return True if this user can execute the command
862 bool HasPermission(const std::string &command);
864 /** Returns true if a user has a given permission.
865 * This is used to check whether or not users may perform certain actions which admins may not wish to give to
866 * all operators, yet are not commands. An example might be oper override, mass messaging (/notice $*), etc.
868 * @param privstr The priv to chec, e.g. "users/override/topic". These are loaded free-form from the config file.
869 * @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.
870 * @return True if this user has the permission in question.
872 bool HasPrivPermission(const std::string &privstr, bool noisy = false);
874 /** Returns true or false if a user can set a privileged user or channel mode.
875 * This is done by looking up their oper type from User::oper, then referencing
876 * this to their oper classes, and checking the modes they can set.
877 * @param mode The mode the check
878 * @param type ModeType (MODETYPE_CHANNEL or MODETYPE_USER).
879 * @return True if the user can set or unset this mode.
881 bool HasModePermission(unsigned char mode, ModeType type);
884 class CoreExport RemoteUser : public User
887 RemoteUser(const std::string& uid, const std::string& srv) : User(uid, srv, USERTYPE_REMOTE)
890 virtual void SendText(const std::string& line);
893 class CoreExport FakeUser : public User
896 FakeUser(const std::string &uid, const std::string& srv) : User(uid, srv, USERTYPE_SERVER)
901 virtual CullResult cull();
902 virtual void SendText(const std::string& line);
903 virtual const std::string& GetFullHost();
904 virtual const std::string& GetFullRealHost();
907 /* Faster than dynamic_cast */
908 /** Is a local user */
909 inline LocalUser* IS_LOCAL(User* u)
911 return u->usertype == USERTYPE_LOCAL ? static_cast<LocalUser*>(u) : NULL;
913 /** Is a remote user */
914 inline RemoteUser* IS_REMOTE(User* u)
916 return u->usertype == USERTYPE_REMOTE ? static_cast<RemoteUser*>(u) : NULL;
918 /** Is a server fakeuser */
919 inline FakeUser* IS_SERVER(User* u)
921 return u->usertype == USERTYPE_SERVER ? static_cast<FakeUser*>(u) : NULL;
924 #define IS_OPER(x) (x->oper)
926 #define IS_AWAY(x) (!x->awaymsg.empty())
928 /** Derived from Resolver, and performs user forward/reverse lookups.
930 class CoreExport UserResolver : public Resolver
933 /** UUID we are looking up */
935 /** True if the lookup is forward, false if is a reverse lookup
939 /** Create a resolver.
940 * @param Instance The creating instance
941 * @param user The user to begin lookup on
942 * @param to_resolve The IP or host to resolve
943 * @param qt The query type
944 * @param cache Modified by the constructor if the result was cached
946 UserResolver(LocalUser* user, std::string to_resolve, QueryType qt, bool &cache);
948 /** Called on successful lookup
949 * @param result Result string
950 * @param ttl Time to live for result
951 * @param cached True if the result was found in the cache
953 void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached);
955 /** Called on failed lookup
956 * @param e Error code
957 * @param errormessage Error message string
959 void OnError(ResolverError e, const std::string &errormessage);