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/>.
28 #include "inspsocket.h"
30 #include "membership.h"
32 /** connect class types
39 /** named connect block (for opers, etc) */
43 /** Registration state of a user, e.g.
44 * have they sent USER, NICK, PASS yet?
46 enum RegistrationState {
48 #ifndef _WIN32 // Burlex: This is already defined in win32, luckily it is still 0.
49 REG_NONE = 0, /* Has sent nothing */
52 REG_USER = 1, /* Has sent USER */
53 REG_NICK = 2, /* Has sent NICK */
54 REG_NICKUSER = 3, /* Bitwise combination of REG_NICK and REG_USER */
55 REG_ALL = 7 /* REG_NICKUSER plus next bit along */
64 /** Holds information relevent to <connect allow> and <connect deny> tags in the config file.
66 struct CoreExport ConnectClass : public refcountbase
68 reference<ConfigTag> config;
69 /** Type of line, either CC_ALLOW or CC_DENY
73 /** True if this class uses fake lag to manage flood, false if it kills */
76 /** Connect class name
80 /** Max time to register the connection in seconds
82 unsigned int registration_timeout;
84 /** Host mask for this line
88 /** Number of seconds between pings for this line
90 unsigned int pingtime;
92 /** Maximum size of sendq for users in this class (bytes)
93 * Users cannot send commands if they go over this limit
95 unsigned long softsendqmax;
97 /** Maximum size of sendq for users in this class (bytes)
98 * Users are killed if they go over this limit
100 unsigned long hardsendqmax;
102 /** Maximum size of recvq for users in this class (bytes)
104 unsigned long recvqmax;
106 /** Seconds worth of penalty before penalty system activates
108 unsigned int penaltythreshold;
110 /** Maximum rate of commands (units: millicommands per second) */
111 unsigned int commandrate;
113 /** Local max when connecting by this connection class
115 unsigned long maxlocal;
117 /** Global max when connecting by this connection class
119 unsigned long maxglobal;
121 /** True if max connections for this class is hit and a warning is wanted
125 /** Max channels for this class
127 unsigned int maxchans;
129 /** How many users may be in this connect class before they are refused?
130 * (0 = no limit = default)
134 /** If set to true, no user DNS lookups are to be performed
136 bool resolvehostnames;
139 * If non-empty the server ports which this user has to be using
141 insp::flat_set<int> ports;
143 /** Create a new connect class with no settings.
145 ConnectClass(ConfigTag* tag, char type, const std::string& mask);
146 /** Create a new connect class with inherited settings.
148 ConnectClass(ConfigTag* tag, char type, const std::string& mask, const ConnectClass& parent);
150 /** Update the settings in this block to match the given block */
151 void Update(const ConnectClass* newSettings);
153 const std::string& GetName() { return name; }
154 const std::string& GetHost() { return host; }
156 /** Returns the registration timeout
158 time_t GetRegTimeout()
160 return (registration_timeout ? registration_timeout : 90);
163 /** Returns the ping frequency
165 unsigned int GetPingTime()
167 return (pingtime ? pingtime : 120);
170 /** Returns the maximum sendq value (soft limit)
171 * Note that this is in addition to internal OS buffers
173 unsigned long GetSendqSoftMax()
175 return (softsendqmax ? softsendqmax : 4096);
178 /** Returns the maximum sendq value (hard limit)
180 unsigned long GetSendqHardMax()
182 return (hardsendqmax ? hardsendqmax : 0x100000);
185 /** Returns the maximum recvq value
187 unsigned long GetRecvqMax()
189 return (recvqmax ? recvqmax : 4096);
192 /** Returns the penalty threshold value
194 unsigned int GetPenaltyThreshold()
196 return penaltythreshold ? penaltythreshold : (fakelag ? 10 : 20);
199 unsigned int GetCommandRate()
201 return commandrate ? commandrate : 1000;
204 /** Return the maximum number of local sessions
206 unsigned long GetMaxLocal()
211 /** Returns the maximum number of global sessions
213 unsigned long GetMaxGlobal()
219 /** Holds all information about a user
220 * This class stores all information about a user connected to the irc server. Everything about a
221 * connection is stored here primarily, from the user's socket ID (file descriptor) through to the
222 * user's nickname and hostname.
224 class CoreExport User : public Extensible
227 /** Cached nick!ident@dhost value using the displayed hostname
229 std::string cached_fullhost;
231 /** Cached ident@ip value using the real IP address
233 std::string cached_hostip;
235 /** Cached ident@realhost value using the real hostname
237 std::string cached_makehost;
239 /** Cached nick!ident@realhost value using the real hostname
241 std::string cached_fullrealhost;
243 /** Set by GetIPString() to avoid constantly re-grabbing IP via sockets voodoo.
245 std::string cachedip;
247 /** If set then the hostname which is displayed to users. */
248 std::string displayhost;
250 /** The real hostname of this user. */
251 std::string realhost;
253 /** The user's mode list.
254 * Much love to the STL for giving us an easy to use bitset, saving us RAM.
255 * if (modes[modeid]) is set, then the mode is set.
256 * For example, to work out if mode +i is set, we check the field
257 * User::modes[invisiblemode->modeid] == true.
259 std::bitset<ModeParser::MODEID_MAX> modes;
262 /** To execute a function for each local neighbor of a user, inherit from this class and
263 * pass an instance of it to User::ForEachNeighbor().
265 class ForEachNeighborHandler
268 /** Method to execute for each local neighbor of a user.
269 * Derived classes must implement this.
270 * @param user Current neighbor
272 virtual void Execute(LocalUser* user) = 0;
275 /** List of Memberships for this user
277 typedef insp::intrusive_list<Membership> ChanList;
279 /** Time that the object was instantiated (used for TS calculation etc)
283 /** Time the connection was created, set in the constructor. This
284 * may be different from the time the user's classbase object was
289 /** Client address that the user is connected from.
290 * Do not modify this value directly, use SetClientIP() to change it.
291 * Port is not valid for remote users.
293 irc::sockets::sockaddrs client_sa;
295 /** The users nickname.
296 * An invalid nickname indicates an unregistered connection prior to the NICK command.
297 * Use InspIRCd::IsNick() to validate nicknames.
301 /** The user's unique identifier.
302 * This is the unique identifier which the user has across the network.
304 const std::string uuid;
306 /** The users ident reply.
307 * Two characters are added to the user-defined limit to compensate for the tilde etc.
311 /** The users full name (GECOS).
313 std::string fullname;
315 /** What snomasks are set on this user.
316 * This functions the same as the above modes.
318 std::bitset<64> snomasks;
320 /** Channels this user is on
324 /** The server the user is connected to.
328 /** The user's away message.
329 * If this string is empty, the user is not marked as away.
333 /** Time the user last went away.
334 * This is ONLY RELIABLE if user IsAway()!
338 /** The oper type they logged in as, if they are an oper.
340 reference<OperInfo> oper;
342 /** Used by User to indicate the registration status of the connection
343 * It is a bitfield of the REG_NICK, REG_USER and REG_ALL bits to indicate
344 * the connection state.
346 unsigned int registered:3;
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 /** What type of user is this? */
356 const unsigned int usertype:2;
358 /** Get client IP string from sockaddr, using static internal buffer
359 * @return The IP string
361 const std::string& GetIPString();
363 /** Retrieves this user's hostname.
364 * @param uncloak If true then return the real host; otherwise, the display host.
366 const std::string& GetHost(bool uncloak) const;
368 /** Retrieves this user's displayed hostname. */
369 const std::string& GetDisplayedHost() const;
371 /** Retrieves this user's real hostname. */
372 const std::string& GetRealHost() const;
374 /** Get CIDR mask, using default range, for this user
376 irc::sockets::cidr_mask GetCIDRMask();
378 /** Sets the client IP for this user
379 * @return true if the conversion was successful
381 virtual bool SetClientIP(const std::string& address, bool recheck_eline = true);
383 virtual void SetClientIP(const irc::sockets::sockaddrs& sa, bool recheck_eline = true);
386 * @throw CoreException if the UID allocated to the user already exists
388 User(const std::string& uid, Server* srv, int objtype);
390 /** Returns the full displayed host of the user
391 * This member function returns the hostname of the user as seen by other users
392 * on the server, in nick!ident\@host form.
393 * @return The full masked host of the user
395 virtual const std::string& GetFullHost();
397 /** Returns the full real 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\@host form. If any form of hostname cloaking is in operation,
400 * e.g. through a module, then this method will ignore it and return the true hostname.
401 * @return The full real host of the user
403 virtual const std::string& GetFullRealHost();
405 /** This clears any cached results that are used for GetFullRealHost() etc.
406 * The results of these calls are cached as generating them can be generally expensive.
408 void InvalidateCache();
410 /** Returns whether this user is currently away or not. If true,
411 * further information can be found in User::awaymsg and User::awaytime
412 * @return True if the user is away, false otherwise
414 bool IsAway() const { return (!awaymsg.empty()); }
416 /** Returns whether this user is an oper or not. If true,
417 * oper information can be obtained from User::oper
418 * @return True if the user is an oper, false otherwise
420 bool IsOper() const { return oper; }
422 /** Returns true if a notice mask is set
423 * @param sm A notice mask character to check
424 * @return True if the notice mask is set
426 bool IsNoticeMaskSet(unsigned char sm);
428 /** Get the mode letters of modes set on the user as a string.
429 * @param includeparams True to get the parameters of the modes as well. Defaults to false.
430 * @return Mode letters of modes set on the user and optionally the parameters of those modes, if any.
431 * The returned string always begins with a '+' character. If the user has no modes set, "+" is returned.
433 std::string GetModeLetters(bool includeparams = false) const;
435 /** Returns true if a specific mode is set
436 * @param m The user mode
437 * @return True if the mode is set
439 bool IsModeSet(unsigned char m) const;
440 bool IsModeSet(const ModeHandler* mh) const;
441 bool IsModeSet(const ModeHandler& mh) const { return IsModeSet(&mh); }
442 bool IsModeSet(UserModeReference& moderef) const;
444 /** Set a specific usermode to on or off
445 * @param mh The user mode
446 * @param value On or off setting of the mode
448 void SetMode(ModeHandler* mh, bool value);
449 void SetMode(ModeHandler& mh, bool value) { SetMode(&mh, value); }
451 /** Returns true or false for if a user can execute a privilaged oper command.
452 * This is done by looking up their oper type from User::oper, then referencing
453 * this to their oper classes and checking the commands they can execute.
454 * @param command A command (should be all CAPS)
455 * @return True if this user can execute the command
457 virtual bool HasPermission(const std::string &command);
459 /** Returns true if a user has a given permission.
460 * This is used to check whether or not users may perform certain actions which admins may not wish to give to
461 * all operators, yet are not commands. An example might be oper override, mass messaging (/notice $*), etc.
463 * @param privstr The priv to chec, e.g. "users/override/topic". These are loaded free-form from the config file.
464 * @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.
465 * @return True if this user has the permission in question.
467 virtual bool HasPrivPermission(const std::string &privstr, bool noisy = false);
469 /** Returns true or false if a user can set a privileged user or channel mode.
470 * This is done by looking up their oper type from User::oper, then referencing
471 * this to their oper classes, and checking the modes they can set.
472 * @param mh Mode to check
473 * @return True if the user can set or unset this mode.
475 virtual bool HasModePermission(const ModeHandler* mh) const;
477 /** Creates a usermask with real host.
478 * Takes a buffer to use and fills the given buffer with the hostmask in the format user\@host
479 * @return the usermask in the format user\@host
481 const std::string& MakeHost();
483 /** Creates a usermask with real ip.
484 * Takes a buffer to use and fills the given buffer with the ipmask in the format user\@ip
485 * @return the usermask in the format user\@ip
487 const std::string& MakeHostIP();
489 /** Oper up the user using the given opertype.
490 * This will also give the +o usermode.
492 void Oper(OperInfo* info);
495 * This will clear the +o usermode and unset the user's oper type
499 /** Write text to this user, appending CR/LF. Works on local users only.
500 * @param text A std::string to send to the user
502 virtual void Write(const std::string &text);
504 /** Write text to this user, appending CR/LF.
505 * Works on local users only.
506 * @param text The format string for text to send to the user
507 * @param ... POD-type format arguments
509 virtual void Write(const char *text, ...) CUSTOM_PRINTF(2, 3);
511 /** Write text to this user, appending CR/LF and prepending :server.name
512 * Works on local users only.
513 * @param text A std::string to send to the user
515 void WriteServ(const std::string& text);
517 /** Write text to this user, appending CR/LF and prepending :server.name
518 * Works on local users only.
519 * @param text The format string for text to send to the user
520 * @param ... POD-type format arguments
522 void WriteServ(const char* text, ...) CUSTOM_PRINTF(2, 3);
524 /** Sends a command to this user.
525 * @param command The command to be sent.
526 * @param text The message to send.
528 void WriteCommand(const char* command, const std::string& text);
530 /** Sends a server notice to this user.
531 * @param text The contents of the message to send.
533 void WriteNotice(const std::string& text) { this->WriteCommand("NOTICE", ":" + text); }
535 /** Send a NOTICE message from the local server to the user.
536 * @param text Text to send
538 virtual void WriteRemoteNotice(const std::string& text);
540 virtual void WriteRemoteNumeric(const Numeric::Numeric& numeric);
542 template <typename T1>
543 void WriteRemoteNumeric(unsigned int numeric, T1 p1)
545 Numeric::Numeric n(numeric);
547 WriteRemoteNumeric(n);
550 template <typename T1, typename T2>
551 void WriteRemoteNumeric(unsigned int numeric, T1 p1, T2 p2)
553 Numeric::Numeric n(numeric);
556 WriteRemoteNumeric(n);
559 template <typename T1, typename T2, typename T3>
560 void WriteRemoteNumeric(unsigned int numeric, T1 p1, T2 p2, T3 p3)
562 Numeric::Numeric n(numeric);
566 WriteRemoteNumeric(n);
569 template <typename T1, typename T2, typename T3, typename T4>
570 void WriteRemoteNumeric(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4)
572 Numeric::Numeric n(numeric);
577 WriteRemoteNumeric(n);
580 template <typename T1, typename T2, typename T3, typename T4, typename T5>
581 void WriteRemoteNumeric(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5)
583 Numeric::Numeric n(numeric);
589 WriteRemoteNumeric(n);
592 void WriteNumeric(const Numeric::Numeric& numeric);
594 template <typename T1>
595 void WriteNumeric(unsigned int numeric, T1 p1)
597 Numeric::Numeric n(numeric);
602 template <typename T1, typename T2>
603 void WriteNumeric(unsigned int numeric, T1 p1, T2 p2)
605 Numeric::Numeric n(numeric);
611 template <typename T1, typename T2, typename T3>
612 void WriteNumeric(unsigned int numeric, T1 p1, T2 p2, T3 p3)
614 Numeric::Numeric n(numeric);
621 template <typename T1, typename T2, typename T3, typename T4>
622 void WriteNumeric(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4)
624 Numeric::Numeric n(numeric);
632 template <typename T1, typename T2, typename T3, typename T4, typename T5>
633 void WriteNumeric(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5)
635 Numeric::Numeric n(numeric);
644 /** Write text to this user, appending CR/LF and prepending :nick!user\@host of the user provided in the first parameter.
645 * @param user The user to prepend the :nick!user\@host of
646 * @param text A std::string to send to the user
648 void WriteFrom(User *user, const std::string &text);
650 /** Write text to this user, appending CR/LF and prepending :nick!user\@host of the user provided in the first parameter.
651 * @param user The user to prepend the :nick!user\@host of
652 * @param text The format string for text to send to the user
653 * @param ... POD-type format arguments
655 void WriteFrom(User *user, const char* text, ...) CUSTOM_PRINTF(3, 4);
657 /** Write to all users that can see this user (including this user in the list if include_self is true), appending CR/LF
658 * @param line A std::string to send to the users
659 * @param include_self Should the message be sent back to the author?
661 void WriteCommonRaw(const std::string &line, bool include_self = true);
663 /** Write to all users that can see this user (including this user in the list), appending CR/LF
664 * @param text The format string for text to send to the users
665 * @param ... POD-type format arguments
667 void WriteCommon(const char* text, ...) CUSTOM_PRINTF(2, 3);
669 /** Execute a function once for each local neighbor of this user. By default, the neighbors of a user are the users
670 * who have at least one common channel with the user. Modules are allowed to alter the set of neighbors freely.
671 * This function is used for example to send something conditionally to neighbors, or to send different messages
672 * to different users depending on their oper status.
673 * @param handler Function object to call, inherited from ForEachNeighborHandler.
674 * @param include_self True to include this user in the set of neighbors, false otherwise.
675 * Modules may override this. Has no effect if this user is not local.
677 void ForEachNeighbor(ForEachNeighborHandler& handler, bool include_self = true);
679 /** Return true if the user shares at least one channel with another user
680 * @param other The other user to compare the channel list against
681 * @return True if the given user shares at least one channel with this user
683 bool SharesChannelWith(User *other);
685 /** Change the displayed hostname of this user.
686 * @param host The new displayed hostname of this user.
687 * @return True if the hostname was changed successfully; otherwise, false.
689 bool ChangeDisplayedHost(const std::string& host);
691 /** Change the real hostname of this user.
692 * @param host The new real hostname of this user.
693 * @param resetdisplay Whether to reset the display host to this value.
695 void ChangeRealHost(const std::string& host, bool resetdisplay);
697 /** Change the ident (username) of a user.
698 * ALWAYS use this function, rather than writing User::ident directly,
699 * as this triggers module events allowing the change to be syncronized to
701 * @param newident The new ident to set
702 * @return True if the change succeeded, false if it didn't
704 bool ChangeIdent(const std::string& newident);
706 /** Change a users realname field.
707 * ALWAYS use this function, rather than writing User::fullname directly,
708 * as this triggers module events allowing the change to be syncronized to
710 * @param gecos The user's new realname
711 * @return True if the change succeeded, false if otherwise
713 bool ChangeName(const std::string& gecos);
715 /** Change a user's nick
716 * @param newnick The new nick. If equal to the users uuid, the nick change always succeeds.
717 * @param newts The time at which this nick change happened.
718 * @return True if the change succeeded
720 bool ChangeNick(const std::string& newnick, time_t newts = 0);
722 /** Remove this user from all channels they are on, and delete any that are now empty.
723 * This is used by QUIT, and will not send part messages!
725 void PurgeEmptyChannels();
727 /** Default destructor
730 virtual CullResult cull() CXX11_OVERRIDE;
733 class CoreExport UserIOHandler : public StreamSocket
736 LocalUser* const user;
737 UserIOHandler(LocalUser* me) : user(me) {}
739 void OnError(BufferedSocketError error);
741 /** Adds to the user's write buffer.
742 * You may add any amount of text up to this users sendq value, if you exceed the
743 * sendq value, the user will be removed, and further buffer adds will be dropped.
744 * @param data The data to add to the write buffer
746 void AddWriteBuf(const std::string &data);
749 typedef unsigned int already_sent_t;
751 class CoreExport LocalUser : public User, public insp::intrusive_list_node<LocalUser>
754 LocalUser(int fd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
755 CullResult cull() CXX11_OVERRIDE;
759 /** Stats counter for bytes inbound
761 unsigned int bytes_in;
763 /** Stats counter for bytes outbound
765 unsigned int bytes_out;
767 /** Stats counter for commands inbound
769 unsigned int cmds_in;
771 /** Stats counter for commands outbound
773 unsigned int cmds_out;
775 /** Password specified by the user when they registered (if any).
776 * This is stored even if the \<connect> block doesnt need a password, so that
777 * modules may check it.
779 std::string password;
781 /** Contains a pointer to the connect class a user is on from
783 reference<ConnectClass> MyClass;
785 /** Get the connect class which this user belongs to.
786 * @return A pointer to this user's connect class.
788 ConnectClass* GetClass() const { return MyClass; }
790 /** Call this method to find the matching \<connect> for a user, and to check them against it.
792 void CheckClass(bool clone_count = true);
794 /** Server address and port that this user is connected to.
796 irc::sockets::sockaddrs server_sa;
799 * @return The port number of this user.
803 /** Recursion fix: user is out of SendQ and will be quit as soon as possible.
804 * This can't be handled normally because QuitUser itself calls Write on other
805 * users, which could trigger their SendQ to overrun.
807 unsigned int quitting_sendq:1;
809 /** has the user responded to their previous ping?
811 unsigned int lastping:1;
813 /** This is true if the user matched an exception (E:Line). It is used to save time on ban checks.
815 unsigned int exempt:1;
817 /** Used by PING checking code
821 /** Time that the connection last sent a message, used to calculate idle time
825 /** This value contains how far into the penalty threshold the user is.
826 * This is used either to enable fake lag or for excess flood quits
828 unsigned int CommandFloodPenalty;
830 already_sent_t already_sent;
832 /** Check if the user matches a G or K line, and disconnect them if they do.
833 * @param doZline True if ZLines should be checked (if IP has changed since initial connect)
834 * Returns true if the user matched a ban, false else.
836 bool CheckLines(bool doZline = false);
838 /** Use this method to fully connect a user.
839 * This will send the message of the day, check G/K/E lines, etc.
843 /** Set the connect class to which this user belongs to.
844 * @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.
845 * @return A reference to this user's current connect class.
847 void SetClass(const std::string &explicit_name = "");
849 bool SetClientIP(const std::string& address, bool recheck_eline = true) CXX11_OVERRIDE;
851 void SetClientIP(const irc::sockets::sockaddrs& sa, bool recheck_eline = true) CXX11_OVERRIDE;
853 void Write(const std::string& text) CXX11_OVERRIDE;
854 void Write(const char*, ...) CXX11_OVERRIDE CUSTOM_PRINTF(2, 3);
856 /** Send a NOTICE message from the local server to the user.
857 * The message will be sent even if the user is connected to a remote server.
858 * @param text Text to send
860 void WriteRemoteNotice(const std::string& text) CXX11_OVERRIDE;
862 /** Returns true or false for if a user can execute a privilaged oper command.
863 * This is done by looking up their oper type from User::oper, then referencing
864 * this to their oper classes and checking the commands they can execute.
865 * @param command A command (should be all CAPS)
866 * @return True if this user can execute the command
868 bool HasPermission(const std::string &command) CXX11_OVERRIDE;
870 /** Returns true if a user has a given permission.
871 * This is used to check whether or not users may perform certain actions which admins may not wish to give to
872 * all operators, yet are not commands. An example might be oper override, mass messaging (/notice $*), etc.
874 * @param privstr The priv to chec, e.g. "users/override/topic". These are loaded free-form from the config file.
875 * @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.
876 * @return True if this user has the permission in question.
878 bool HasPrivPermission(const std::string &privstr, bool noisy = false) CXX11_OVERRIDE;
880 /** Returns true or false if a user can set a privileged user or channel mode.
881 * This is done by looking up their oper type from User::oper, then referencing
882 * this to their oper classes, and checking the modes they can set.
883 * @param mh Mode to check
884 * @return True if the user can set or unset this mode.
886 bool HasModePermission(const ModeHandler* mh) const CXX11_OVERRIDE;
888 /** Change nick to uuid, unset REG_NICK and send a nickname overruled numeric.
889 * This is called when another user (either local or remote) needs the nick of this user and this user
895 class RemoteUser : public User
898 RemoteUser(const std::string& uid, Server* srv) : User(uid, srv, USERTYPE_REMOTE)
903 class CoreExport FakeUser : public User
906 FakeUser(const std::string& uid, Server* srv) : User(uid, srv, USERTYPE_SERVER)
908 nick = srv->GetName();
911 FakeUser(const std::string& uid, const std::string& sname, const std::string& sdesc)
912 : User(uid, new Server(sname, sdesc), USERTYPE_SERVER)
917 virtual CullResult cull() CXX11_OVERRIDE;
918 virtual const std::string& GetFullHost() CXX11_OVERRIDE;
919 virtual const std::string& GetFullRealHost() CXX11_OVERRIDE;
922 /* Faster than dynamic_cast */
923 /** Is a local user */
924 inline LocalUser* IS_LOCAL(User* u)
926 return u->usertype == USERTYPE_LOCAL ? static_cast<LocalUser*>(u) : NULL;
928 /** Is a remote user */
929 inline RemoteUser* IS_REMOTE(User* u)
931 return u->usertype == USERTYPE_REMOTE ? static_cast<RemoteUser*>(u) : NULL;
933 /** Is a server fakeuser */
934 inline FakeUser* IS_SERVER(User* u)
936 return u->usertype == USERTYPE_SERVER ? static_cast<FakeUser*>(u) : NULL;
939 inline bool User::IsModeSet(const ModeHandler* mh) const
941 return (modes[mh->GetId()]);
944 inline bool User::IsModeSet(UserModeReference& moderef) const
948 return IsModeSet(*moderef);
951 inline void User::SetMode(ModeHandler* mh, bool value)
953 modes[mh->GetId()] = value;