2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2019 linuxdaemon <linuxdaemon.irc@gmail.com>
5 * Copyright (C) 2019 Matt Schatz <genius3000@g3k.solutions>
6 * Copyright (C) 2013 Daniel Vassdal <shutter@canternet.org>
7 * Copyright (C) 2012-2016, 2018 Attila Molnar <attilamolnar@hush.com>
8 * Copyright (C) 2012-2013, 2016-2019 Sadie Powell <sadie@witchery.services>
9 * Copyright (C) 2012, 2018-2019 Robby <robby@chatbelgie.be>
10 * Copyright (C) 2012 DjSlash <djslash@djslash.org>
11 * Copyright (C) 2012 ChrisTX <xpipe@hotmail.de>
12 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
13 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
14 * Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
15 * Copyright (C) 2008 John Brooks <special@inspircd.org>
16 * Copyright (C) 2007-2009 Robin Burchell <robin+git@viroteck.net>
17 * Copyright (C) 2007, 2009 Dennis Friis <peavey@inspircd.org>
18 * Copyright (C) 2006-2008 Craig Edwards <brain@inspircd.org>
20 * This file is part of InspIRCd. InspIRCd is free software: you can
21 * redistribute it and/or modify it under the terms of the GNU General Public
22 * License as published by the Free Software Foundation, version 2.
24 * This program is distributed in the hope that it will be useful, but WITHOUT
25 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
26 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
37 #include "inspsocket.h"
39 #include "membership.h"
41 /** connect class types
48 /** named connect block (for opers, etc) */
52 /** Registration state of a user, e.g.
53 * have they sent USER, NICK, PASS yet?
55 enum RegistrationState {
57 #ifndef _WIN32 // Burlex: This is already defined in win32, luckily it is still 0.
58 REG_NONE = 0, /* Has sent nothing */
61 REG_USER = 1, /* Has sent USER */
62 REG_NICK = 2, /* Has sent NICK */
63 REG_NICKUSER = 3, /* Bitwise combination of REG_NICK and REG_USER */
64 REG_ALL = 7 /* REG_NICKUSER plus next bit along */
73 /** Holds information relevent to <connect allow> and <connect deny> tags in the config file.
75 struct CoreExport ConnectClass : public refcountbase
77 reference<ConfigTag> config;
78 /** Type of line, either CC_ALLOW or CC_DENY
82 /** True if this class uses fake lag to manage flood, false if it kills */
85 /** Connect class name
89 /** Max time to register the connection in seconds
91 unsigned int registration_timeout;
93 /** Host mask for this line
97 /** Number of seconds between pings for this line
99 unsigned int pingtime;
101 /** Maximum size of sendq for users in this class (bytes)
102 * Users cannot send commands if they go over this limit
104 unsigned long softsendqmax;
106 /** Maximum size of sendq for users in this class (bytes)
107 * Users are killed if they go over this limit
109 unsigned long hardsendqmax;
111 /** Maximum size of recvq for users in this class (bytes)
113 unsigned long recvqmax;
115 /** Seconds worth of penalty before penalty system activates
117 unsigned int penaltythreshold;
119 /** Maximum rate of commands (units: millicommands per second) */
120 unsigned int commandrate;
122 /** Local max when connecting by this connection class
124 unsigned long maxlocal;
126 /** Global max when connecting by this connection class
128 unsigned long maxglobal;
130 /** True if max connections for this class is hit and a warning is wanted
134 /** Max channels for this class
136 unsigned int maxchans;
138 /** How many users may be in this connect class before they are refused?
139 * (0 = no limit = default)
143 /** If set to true, no user DNS lookups are to be performed
145 bool resolvehostnames;
148 * If non-empty the server ports which this user has to be using
150 insp::flat_set<int> ports;
152 /** Create a new connect class with no settings.
154 ConnectClass(ConfigTag* tag, char type, const std::string& mask);
155 /** Create a new connect class with inherited settings.
157 ConnectClass(ConfigTag* tag, char type, const std::string& mask, const ConnectClass& parent);
159 /** Update the settings in this block to match the given block */
160 void Update(const ConnectClass* newSettings);
162 const std::string& GetName() { return name; }
163 const std::string& GetHost() { return host; }
165 /** Returns the registration timeout
167 time_t GetRegTimeout()
169 return (registration_timeout ? registration_timeout : 90);
172 /** Returns the ping frequency
174 unsigned int GetPingTime()
176 return (pingtime ? pingtime : 120);
179 /** Returns the maximum sendq value (soft limit)
180 * Note that this is in addition to internal OS buffers
182 unsigned long GetSendqSoftMax()
184 return (softsendqmax ? softsendqmax : 4096);
187 /** Returns the maximum sendq value (hard limit)
189 unsigned long GetSendqHardMax()
191 return (hardsendqmax ? hardsendqmax : 0x100000);
194 /** Returns the maximum recvq value
196 unsigned long GetRecvqMax()
198 return (recvqmax ? recvqmax : 4096);
201 /** Returns the penalty threshold value
203 unsigned int GetPenaltyThreshold()
205 return penaltythreshold ? penaltythreshold : (fakelag ? 10 : 20);
208 unsigned int GetCommandRate()
210 return commandrate ? commandrate : 1000;
213 /** Return the maximum number of local sessions
215 unsigned long GetMaxLocal()
220 /** Returns the maximum number of global sessions
222 unsigned long GetMaxGlobal()
228 /** Holds all information about a user
229 * This class stores all information about a user connected to the irc server. Everything about a
230 * connection is stored here primarily, from the user's socket ID (file descriptor) through to the
231 * user's nickname and hostname.
233 class CoreExport User : public Extensible
236 /** Cached nick!ident@dhost value using the displayed hostname
238 std::string cached_fullhost;
240 /** Cached ident@ip value using the real IP address
242 std::string cached_hostip;
244 /** Cached ident@realhost value using the real hostname
246 std::string cached_makehost;
248 /** Cached nick!ident@realhost value using the real hostname
250 std::string cached_fullrealhost;
252 /** Set by GetIPString() to avoid constantly re-grabbing IP via sockets voodoo.
254 std::string cachedip;
256 /** If set then the hostname which is displayed to users. */
257 std::string displayhost;
259 /** The real hostname of this user. */
260 std::string realhost;
262 /** The real name of this user. */
263 std::string realname;
265 /** The user's mode list.
266 * Much love to the STL for giving us an easy to use bitset, saving us RAM.
267 * if (modes[modeid]) is set, then the mode is set.
268 * For example, to work out if mode +i is set, we check the field
269 * User::modes[invisiblemode->modeid] == true.
271 std::bitset<ModeParser::MODEID_MAX> modes;
274 /** To execute a function for each local neighbor of a user, inherit from this class and
275 * pass an instance of it to User::ForEachNeighbor().
277 class ForEachNeighborHandler
280 /** Method to execute for each local neighbor of a user.
281 * Derived classes must implement this.
282 * @param user Current neighbor
284 virtual void Execute(LocalUser* user) = 0;
287 /** List of Memberships for this user
289 typedef insp::intrusive_list<Membership> ChanList;
291 /** Time that the object was instantiated (used for TS calculation etc)
295 /** Time the connection was created, set in the constructor. This
296 * may be different from the time the user's classbase object was
301 /** Client address that the user is connected from.
302 * Do not modify this value directly, use SetClientIP() to change it.
303 * Port is not valid for remote users.
305 irc::sockets::sockaddrs client_sa;
307 /** The users nickname.
308 * An invalid nickname indicates an unregistered connection prior to the NICK command.
309 * Use InspIRCd::IsNick() to validate nicknames.
313 /** The user's unique identifier.
314 * This is the unique identifier which the user has across the network.
316 const std::string uuid;
318 /** The users ident reply.
319 * Two characters are added to the user-defined limit to compensate for the tilde etc.
323 /** What snomasks are set on this user.
324 * This functions the same as the above modes.
326 std::bitset<64> snomasks;
328 /** Channels this user is on
332 /** The server the user is connected to.
336 /** The user's away message.
337 * If this string is empty, the user is not marked as away.
341 /** Time the user last went away.
342 * This is ONLY RELIABLE if user IsAway()!
346 /** The oper type they logged in as, if they are an oper.
348 reference<OperInfo> oper;
350 /** Used by User to indicate the registration status of the connection
351 * It is a bitfield of the REG_NICK, REG_USER and REG_ALL bits to indicate
352 * the connection state.
354 unsigned int registered:3;
356 /** If this is set to true, then all socket operations for the user
357 * are dropped into the bit-bucket.
358 * This value is set by QuitUser, and is not needed seperately from that call.
359 * Please note that setting this value alone will NOT cause the user to quit.
361 unsigned int quitting:1;
363 /** What type of user is this? */
364 const UserType usertype:2;
366 /** Get client IP string from sockaddr, using static internal buffer
367 * @return The IP string
369 const std::string& GetIPString();
371 /** Retrieves this user's hostname.
372 * @param uncloak If true then return the real host; otherwise, the display host.
374 const std::string& GetHost(bool uncloak) const;
376 /** Retrieves this user's displayed hostname. */
377 const std::string& GetDisplayedHost() const;
379 /** Retrieves this user's real hostname. */
380 const std::string& GetRealHost() const;
382 /** Retrieves this user's real name. */
383 const std::string& GetRealName() const;
385 /** Get CIDR mask, using default range, for this user
387 irc::sockets::cidr_mask GetCIDRMask();
389 /** Sets the client IP for this user
390 * @return true if the conversion was successful
392 virtual bool SetClientIP(const std::string& address);
394 virtual void SetClientIP(const irc::sockets::sockaddrs& sa);
397 * @throw CoreException if the UID allocated to the user already exists
399 User(const std::string& uid, Server* srv, UserType objtype);
401 /** Returns the full displayed host of the user
402 * This member function returns the hostname of the user as seen by other users
403 * on the server, in nick!ident\@host form.
404 * @return The full masked host of the user
406 virtual const std::string& GetFullHost();
408 /** Returns the full real host of the user
409 * This member function returns the hostname of the user as seen by other users
410 * on the server, in nick!ident\@host form. If any form of hostname cloaking is in operation,
411 * e.g. through a module, then this method will ignore it and return the true hostname.
412 * @return The full real host of the user
414 virtual const std::string& GetFullRealHost();
416 /** This clears any cached results that are used for GetFullRealHost() etc.
417 * The results of these calls are cached as generating them can be generally expensive.
419 void InvalidateCache();
421 /** Returns whether this user is currently away or not. If true,
422 * further information can be found in User::awaymsg and User::awaytime
423 * @return True if the user is away, false otherwise
425 bool IsAway() const { return (!awaymsg.empty()); }
427 /** Returns whether this user is an oper or not. If true,
428 * oper information can be obtained from User::oper
429 * @return True if the user is an oper, false otherwise
431 bool IsOper() const { return oper; }
433 /** Returns true if a notice mask is set
434 * @param sm A notice mask character to check
435 * @return True if the notice mask is set
437 bool IsNoticeMaskSet(unsigned char sm);
439 /** Get the mode letters of modes set on the user as a string.
440 * @param includeparams True to get the parameters of the modes as well. Defaults to false.
441 * @return Mode letters of modes set on the user and optionally the parameters of those modes, if any.
442 * The returned string always begins with a '+' character. If the user has no modes set, "+" is returned.
444 std::string GetModeLetters(bool includeparams = false) const;
446 /** Returns true if a specific mode is set
447 * @param m The user mode
448 * @return True if the mode is set
450 bool IsModeSet(unsigned char m) const;
451 bool IsModeSet(const ModeHandler* mh) const;
452 bool IsModeSet(const ModeHandler& mh) const { return IsModeSet(&mh); }
453 bool IsModeSet(UserModeReference& moderef) const;
455 /** Set a specific usermode to on or off
456 * @param mh The user mode
457 * @param value On or off setting of the mode
459 void SetMode(ModeHandler* mh, bool value);
460 void SetMode(ModeHandler& mh, bool value) { SetMode(&mh, value); }
462 /** Returns true or false for if a user can execute a privilaged oper command.
463 * This is done by looking up their oper type from User::oper, then referencing
464 * this to their oper classes and checking the commands they can execute.
465 * @param command A command (should be all CAPS)
466 * @return True if this user can execute the command
468 virtual bool HasCommandPermission(const std::string& command);
470 /** Returns true if a user has a given permission.
471 * This is used to check whether or not users may perform certain actions which admins may not wish to give to
472 * all operators, yet are not commands. An example might be oper override, mass messaging (/notice $*), etc.
474 * @param privstr The priv to chec, e.g. "users/override/topic". These are loaded free-form from the config file.
475 * @return True if this user has the permission in question.
477 virtual bool HasPrivPermission(const std::string& privstr);
479 /** Returns true or false if a user can set a privileged user or channel mode.
480 * This is done by looking up their oper type from User::oper, then referencing
481 * this to their oper classes, and checking the modes they can set.
482 * @param mh Mode to check
483 * @return True if the user can set or unset this mode.
485 virtual bool HasModePermission(const ModeHandler* mh) const;
487 /** Creates a usermask with real host.
488 * Takes a buffer to use and fills the given buffer with the hostmask in the format user\@host
489 * @return the usermask in the format user\@host
491 const std::string& MakeHost();
493 /** Creates a usermask with real ip.
494 * Takes a buffer to use and fills the given buffer with the ipmask in the format user\@ip
495 * @return the usermask in the format user\@ip
497 const std::string& MakeHostIP();
499 /** Oper up the user using the given opertype.
500 * This will also give the +o usermode.
502 void Oper(OperInfo* info);
505 * This will clear the +o usermode and unset the user's oper type
509 /** Sends a server notice to this user.
510 * @param text The contents of the message to send.
512 void WriteNotice(const std::string& text);
514 /** Send a NOTICE message from the local server to the user.
515 * @param text Text to send
517 virtual void WriteRemoteNotice(const std::string& text);
519 virtual void WriteRemoteNumeric(const Numeric::Numeric& numeric);
521 template <typename T1>
522 void WriteRemoteNumeric(unsigned int numeric, T1 p1)
524 Numeric::Numeric n(numeric);
526 WriteRemoteNumeric(n);
529 template <typename T1, typename T2>
530 void WriteRemoteNumeric(unsigned int numeric, T1 p1, T2 p2)
532 Numeric::Numeric n(numeric);
535 WriteRemoteNumeric(n);
538 template <typename T1, typename T2, typename T3>
539 void WriteRemoteNumeric(unsigned int numeric, T1 p1, T2 p2, T3 p3)
541 Numeric::Numeric n(numeric);
545 WriteRemoteNumeric(n);
548 template <typename T1, typename T2, typename T3, typename T4>
549 void WriteRemoteNumeric(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4)
551 Numeric::Numeric n(numeric);
556 WriteRemoteNumeric(n);
559 template <typename T1, typename T2, typename T3, typename T4, typename T5>
560 void WriteRemoteNumeric(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5)
562 Numeric::Numeric n(numeric);
568 WriteRemoteNumeric(n);
571 void WriteNumeric(const Numeric::Numeric& numeric);
573 template <typename T1>
574 void WriteNumeric(unsigned int numeric, T1 p1)
576 Numeric::Numeric n(numeric);
581 template <typename T1, typename T2>
582 void WriteNumeric(unsigned int numeric, T1 p1, T2 p2)
584 Numeric::Numeric n(numeric);
590 template <typename T1, typename T2, typename T3>
591 void WriteNumeric(unsigned int numeric, T1 p1, T2 p2, T3 p3)
593 Numeric::Numeric n(numeric);
600 template <typename T1, typename T2, typename T3, typename T4>
601 void WriteNumeric(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4)
603 Numeric::Numeric n(numeric);
611 template <typename T1, typename T2, typename T3, typename T4, typename T5>
612 void WriteNumeric(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5)
614 Numeric::Numeric n(numeric);
623 /** Write to all users that can see this user (including this user in the list if include_self is true), appending CR/LF
624 * @param protoev Protocol event to send, may contain any number of messages.
625 * @param include_self Should the message be sent back to the author?
627 void WriteCommonRaw(ClientProtocol::Event& protoev, bool include_self = true);
629 /** Execute a function once for each local neighbor of this user. By default, the neighbors of a user are the users
630 * who have at least one common channel with the user. Modules are allowed to alter the set of neighbors freely.
631 * This function is used for example to send something conditionally to neighbors, or to send different messages
632 * to different users depending on their oper status.
633 * @param handler Function object to call, inherited from ForEachNeighborHandler.
634 * @param include_self True to include this user in the set of neighbors, false otherwise.
635 * Modules may override this. Has no effect if this user is not local.
637 void ForEachNeighbor(ForEachNeighborHandler& handler, bool include_self = true);
639 /** Return true if the user shares at least one channel with another user
640 * @param other The other user to compare the channel list against
641 * @return True if the given user shares at least one channel with this user
643 bool SharesChannelWith(User *other);
645 /** Change the displayed hostname of this user.
646 * @param host The new displayed hostname of this user.
647 * @return True if the hostname was changed successfully; otherwise, false.
649 bool ChangeDisplayedHost(const std::string& host);
651 /** Change the real hostname of this user.
652 * @param host The new real hostname of this user.
653 * @param resetdisplay Whether to reset the display host to this value.
655 void ChangeRealHost(const std::string& host, bool resetdisplay);
657 /** Change the ident (username) of a user.
658 * ALWAYS use this function, rather than writing User::ident directly,
659 * as this triggers module events allowing the change to be syncronized to
661 * @param newident The new ident to set
662 * @return True if the change succeeded, false if it didn't
664 bool ChangeIdent(const std::string& newident);
666 /** Change a users realname field.
667 * @param real The user's new real name
668 * @return True if the change succeeded, false if otherwise
670 bool ChangeRealName(const std::string& real);
672 /** Change a user's nick
673 * @param newnick The new nick. If equal to the users uuid, the nick change always succeeds.
674 * @param newts The time at which this nick change happened.
675 * @return True if the change succeeded
677 bool ChangeNick(const std::string& newnick, time_t newts = 0);
679 /** Remove this user from all channels they are on, and delete any that are now empty.
680 * This is used by QUIT, and will not send part messages!
682 void PurgeEmptyChannels();
684 /** Default destructor
687 CullResult cull() CXX11_OVERRIDE;
689 /** @copydoc Serializable::Deserialize. */
690 bool Deserialize(Data& data) CXX11_OVERRIDE;
692 /** @copydoc Serializable::Deserialize. */
693 bool Serialize(Serializable::Data& data) CXX11_OVERRIDE;
696 class CoreExport UserIOHandler : public StreamSocket
699 size_t checked_until;
701 LocalUser* const user;
702 UserIOHandler(LocalUser* me)
703 : StreamSocket(StreamSocket::SS_USER)
708 void OnDataReady() CXX11_OVERRIDE;
709 bool OnSetEndPoint(const irc::sockets::sockaddrs& local, const irc::sockets::sockaddrs& remote) CXX11_OVERRIDE;
710 void OnError(BufferedSocketError error) CXX11_OVERRIDE;
712 /** Adds to the user's write buffer.
713 * You may add any amount of text up to this users sendq value, if you exceed the
714 * sendq value, the user will be removed, and further buffer adds will be dropped.
715 * @param data The data to add to the write buffer
717 void AddWriteBuf(const std::string &data);
719 /** Swaps the internals of this UserIOHandler with another one.
720 * @param other A UserIOHandler to swap internals with.
722 void SwapInternals(UserIOHandler& other);
725 typedef unsigned int already_sent_t;
727 class CoreExport LocalUser : public User, public insp::intrusive_list_node<LocalUser>
729 /** Add a serialized message to the send queue of the user.
730 * @param serialized Bytes to add.
732 void Write(const ClientProtocol::SerializedMessage& serialized);
734 /** Send a protocol event to the user, consisting of one or more messages.
735 * @param protoev Event to send, may contain any number of messages.
736 * @param msglist Message list used temporarily internally to pass to hooks and store messages
739 void Send(ClientProtocol::Event& protoev, ClientProtocol::MessageList& msglist);
741 /** Message list, can be passed to the two parameter Send().
743 static ClientProtocol::MessageList sendmsglist;
746 LocalUser(int fd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
747 LocalUser(int fd, const std::string& uuid, Serializable::Data& data);
749 CullResult cull() CXX11_OVERRIDE;
753 /** Serializer to use when communicating with the user
755 ClientProtocol::Serializer* serializer;
757 /** Stats counter for bytes inbound
759 unsigned int bytes_in;
761 /** Stats counter for bytes outbound
763 unsigned int bytes_out;
765 /** Stats counter for commands inbound
767 unsigned int cmds_in;
769 /** Stats counter for commands outbound
771 unsigned int cmds_out;
773 /** Password specified by the user when they registered (if any).
774 * This is stored even if the \<connect> block doesnt need a password, so that
775 * modules may check it.
777 std::string password;
779 /** Contains a pointer to the connect class a user is on from
781 reference<ConnectClass> MyClass;
783 /** Get the connect class which this user belongs to.
784 * @return A pointer to this user's connect class.
786 ConnectClass* GetClass() const { return MyClass; }
788 /** Call this method to find the matching \<connect> for a user, and to check them against it.
790 void CheckClass(bool clone_count = true);
792 /** Server address and port that this user is connected to.
794 irc::sockets::sockaddrs server_sa;
796 /** Recursion fix: user is out of SendQ and will be quit as soon as possible.
797 * This can't be handled normally because QuitUser itself calls Write on other
798 * users, which could trigger their SendQ to overrun.
800 unsigned int quitting_sendq:1;
802 /** has the user responded to their previous ping?
804 unsigned int lastping:1;
806 /** This is true if the user matched an exception (E-line). It is used to save time on ban checks.
808 unsigned int exempt:1;
810 /** The time at which this user should be pinged next. */
813 /** Time that the connection last sent a message, used to calculate idle time
817 /** This value contains how far into the penalty threshold the user is.
818 * This is used either to enable fake lag or for excess flood quits
820 unsigned int CommandFloodPenalty;
822 already_sent_t already_sent;
824 /** Check if the user matches a G- or K-line, and disconnect them if they do.
825 * @param doZline True if Z-lines should be checked (if IP has changed since initial connect)
826 * Returns true if the user matched a ban, false else.
828 bool CheckLines(bool doZline = false);
830 /** Use this method to fully connect a user.
831 * This will send the message of the day, check G/K/E-lines, etc.
835 /** Set the connect class to which this user belongs to.
836 * @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.
837 * @return A reference to this user's current connect class.
839 void SetClass(const std::string &explicit_name = "");
841 bool SetClientIP(const std::string& address) CXX11_OVERRIDE;
843 void SetClientIP(const irc::sockets::sockaddrs& sa) CXX11_OVERRIDE;
845 /** Send a NOTICE message from the local server to the user.
846 * The message will be sent even if the user is connected to a remote server.
847 * @param text Text to send
849 void WriteRemoteNotice(const std::string& text) CXX11_OVERRIDE;
851 /** Returns true or false for if a user can execute a privilaged oper command.
852 * This is done by looking up their oper type from User::oper, then referencing
853 * this to their oper classes and checking the commands they can execute.
854 * @param command A command (should be all CAPS)
855 * @return True if this user can execute the command
857 bool HasCommandPermission(const std::string& command) CXX11_OVERRIDE;
859 /** Returns true if a user has a given permission.
860 * This is used to check whether or not users may perform certain actions which admins may not wish to give to
861 * all operators, yet are not commands. An example might be oper override, mass messaging (/notice $*), etc.
863 * @param privstr The priv to chec, e.g. "users/override/topic". These are loaded free-form from the config file.
864 * @return True if this user has the permission in question.
866 bool HasPrivPermission(const std::string& privstr) CXX11_OVERRIDE;
868 /** Returns true or false if a user can set a privileged user or channel mode.
869 * This is done by looking up their oper type from User::oper, then referencing
870 * this to their oper classes, and checking the modes they can set.
871 * @param mh Mode to check
872 * @return True if the user can set or unset this mode.
874 bool HasModePermission(const ModeHandler* mh) const CXX11_OVERRIDE;
876 /** Change nick to uuid, unset REG_NICK and send a nickname overruled numeric.
877 * This is called when another user (either local or remote) needs the nick of this user and this user
882 /** Send a protocol event to the user, consisting of one or more messages.
883 * @param protoev Event to send, may contain any number of messages.
885 void Send(ClientProtocol::Event& protoev);
887 /** Send a single message to the user.
888 * @param protoevprov Protocol event provider.
889 * @param msg Message to send.
891 void Send(ClientProtocol::EventProvider& protoevprov, ClientProtocol::Message& msg);
893 /** @copydoc Serializable::Deserialize. */
894 bool Deserialize(Data& data) CXX11_OVERRIDE;
896 /** @copydoc Serializable::Deserialize. */
897 bool Serialize(Serializable::Data& data) CXX11_OVERRIDE;
900 class RemoteUser : public User
903 RemoteUser(const std::string& uid, Server* srv) : User(uid, srv, USERTYPE_REMOTE)
908 class CoreExport FakeUser : public User
911 FakeUser(const std::string& uid, Server* srv)
912 : User(uid, srv, USERTYPE_SERVER)
914 nick = srv->GetName();
917 FakeUser(const std::string& uid, const std::string& sname, const std::string& sdesc)
918 : User(uid, new Server(uid, sname, sdesc), USERTYPE_SERVER)
923 CullResult cull() CXX11_OVERRIDE;
924 const std::string& GetFullHost() CXX11_OVERRIDE;
925 const std::string& GetFullRealHost() CXX11_OVERRIDE;
928 /* Faster than dynamic_cast */
929 /** Is a local user */
930 inline LocalUser* IS_LOCAL(User* u)
932 return (u != NULL && u->usertype == USERTYPE_LOCAL) ? static_cast<LocalUser*>(u) : NULL;
934 /** Is a remote user */
935 inline RemoteUser* IS_REMOTE(User* u)
937 return (u != NULL && u->usertype == USERTYPE_REMOTE) ? static_cast<RemoteUser*>(u) : NULL;
939 /** Is a server fakeuser */
940 inline FakeUser* IS_SERVER(User* u)
942 return (u != NULL && u->usertype == USERTYPE_SERVER) ? static_cast<FakeUser*>(u) : NULL;
945 inline bool User::IsModeSet(const ModeHandler* mh) const
947 return ((mh->GetId() != ModeParser::MODEID_MAX) && (modes[mh->GetId()]));
950 inline bool User::IsModeSet(UserModeReference& moderef) const
954 return IsModeSet(*moderef);
957 inline void User::SetMode(ModeHandler* mh, bool value)
959 if (mh && mh->GetId() != ModeParser::MODEID_MAX)
960 modes[mh->GetId()] = value;