2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2019-2020 Matt Schatz <genius3000@g3k.solutions>
5 * Copyright (C) 2019 linuxdaemon <linuxdaemon.irc@gmail.com>
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-2020 Sadie Powell <sadie@witchery.services>
9 * Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
10 * Copyright (C) 2012 DjSlash <djslash@djslash.org>
11 * Copyright (C) 2012 ChrisTX <xpipe@hotmail.de>
12 * Copyright (C) 2011 jackmcbarn <jackmcbarn@inspircd.org>
13 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
14 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
15 * Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
16 * Copyright (C) 2008 John Brooks <special@inspircd.org>
17 * Copyright (C) 2007, 2009 Dennis Friis <peavey@inspircd.org>
18 * Copyright (C) 2006-2009 Robin Burchell <robin+git@viroteck.net>
19 * Copyright (C) 2003-2008 Craig Edwards <brain@inspircd.org>
21 * This file is part of InspIRCd. InspIRCd is free software: you can
22 * redistribute it and/or modify it under the terms of the GNU General Public
23 * License as published by the Free Software Foundation, version 2.
25 * This program is distributed in the hope that it will be useful, but WITHOUT
26 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
27 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
30 * You should have received a copy of the GNU General Public License
31 * along with this program. If not, see <http://www.gnu.org/licenses/>.
38 #include "inspsocket.h"
40 #include "membership.h"
42 /** connect class types
49 /** named connect block (for opers, etc) */
53 /** Registration state of a user, e.g.
54 * have they sent USER, NICK, PASS yet?
56 enum RegistrationState {
58 #ifndef _WIN32 // Burlex: This is already defined in win32, luckily it is still 0.
59 REG_NONE = 0, /* Has sent nothing */
62 REG_USER = 1, /* Has sent USER */
63 REG_NICK = 2, /* Has sent NICK */
64 REG_NICKUSER = 3, /* Bitwise combination of REG_NICK and REG_USER */
65 REG_ALL = 7 /* REG_NICKUSER plus next bit along */
74 /** Holds information relevant to <connect allow> and <connect deny> tags in the config file.
76 struct CoreExport ConnectClass : public refcountbase
78 reference<ConfigTag> config;
79 /** Type of line, either CC_ALLOW or CC_DENY
83 /** True if this class uses fake lag to manage flood, false if it kills */
86 /** Connect class name
90 /** Max time to register the connection in seconds
92 unsigned int registration_timeout;
94 /** Host mask for this line
98 /** Number of seconds between pings for this line
100 unsigned int pingtime;
102 /** Maximum size of sendq for users in this class (bytes)
103 * Users cannot send commands if they go over this limit
105 unsigned long softsendqmax;
107 /** Maximum size of sendq for users in this class (bytes)
108 * Users are killed if they go over this limit
110 unsigned long hardsendqmax;
112 /** Maximum size of recvq for users in this class (bytes)
114 unsigned long recvqmax;
116 /** Seconds worth of penalty before penalty system activates
118 unsigned int penaltythreshold;
120 /** Maximum rate of commands (units: millicommands per second) */
121 unsigned int commandrate;
123 /** Local max when connecting by this connection class
125 unsigned long maxlocal;
127 /** Global max when connecting by this connection class
129 unsigned long maxglobal;
131 /** True if max connections for this class is hit and a warning is wanted
135 /** Max channels for this class
137 unsigned int maxchans;
139 /** How many users may be in this connect class before they are refused?
140 * (0 = no limit = default)
144 /** If set to true, no user DNS lookups are to be performed
146 bool resolvehostnames;
149 * If non-empty the server ports which this user has to be using
151 insp::flat_set<int> ports;
153 /** If non-empty then the password a user must specify in PASS to be assigned to this class. */
154 std::string password;
156 /** If non-empty then the hash algorithm that the password field is hashed with. */
157 std::string passwordhash;
159 /** Create a new connect class with no settings.
161 ConnectClass(ConfigTag* tag, char type, const std::string& mask);
162 /** Create a new connect class with inherited settings.
164 ConnectClass(ConfigTag* tag, char type, const std::string& mask, const ConnectClass& parent);
166 /** Update the settings in this block to match the given block */
167 void Update(const ConnectClass* newSettings);
169 const std::string& GetName() { return name; }
170 const std::string& GetHost() { return host; }
172 /** Returns the registration timeout
174 time_t GetRegTimeout()
176 return (registration_timeout ? registration_timeout : 90);
179 /** Returns the ping frequency
181 unsigned int GetPingTime()
183 return (pingtime ? pingtime : 120);
186 /** Returns the maximum sendq value (soft limit)
187 * Note that this is in addition to internal OS buffers
189 unsigned long GetSendqSoftMax()
191 return (softsendqmax ? softsendqmax : 4096);
194 /** Returns the maximum sendq value (hard limit)
196 unsigned long GetSendqHardMax()
198 return (hardsendqmax ? hardsendqmax : 0x100000);
201 /** Returns the maximum recvq value
203 unsigned long GetRecvqMax()
205 return (recvqmax ? recvqmax : 4096);
208 /** Returns the penalty threshold value
210 unsigned int GetPenaltyThreshold()
212 return penaltythreshold ? penaltythreshold : (fakelag ? 10 : 20);
215 unsigned int GetCommandRate()
217 return commandrate ? commandrate : 1000;
220 /** Return the maximum number of local sessions
222 unsigned long GetMaxLocal()
227 /** Returns the maximum number of global sessions
229 unsigned long GetMaxGlobal()
235 /** Holds all information about a user
236 * This class stores all information about a user connected to the irc server. Everything about a
237 * connection is stored here primarily, from the user's socket ID (file descriptor) through to the
238 * user's nickname and hostname.
240 class CoreExport User : public Extensible
243 /** Cached nick!ident@dhost value using the displayed hostname
245 std::string cached_fullhost;
247 /** Cached ident@ip value using the real IP address
249 std::string cached_hostip;
251 /** Cached ident@realhost value using the real hostname
253 std::string cached_makehost;
255 /** Cached nick!ident@realhost value using the real hostname
257 std::string cached_fullrealhost;
259 /** Set by GetIPString() to avoid constantly re-grabbing IP via sockets voodoo.
261 std::string cachedip;
263 /** If set then the hostname which is displayed to users. */
264 std::string displayhost;
266 /** The real hostname of this user. */
267 std::string realhost;
269 /** The real name of this user. */
270 std::string realname;
272 /** The user's mode list.
273 * Much love to the STL for giving us an easy to use bitset, saving us RAM.
274 * if (modes[modeid]) is set, then the mode is set.
275 * For example, to work out if mode +i is set, we check the field
276 * User::modes[invisiblemode->modeid] == true.
278 std::bitset<ModeParser::MODEID_MAX> modes;
281 /** To execute a function for each local neighbor of a user, inherit from this class and
282 * pass an instance of it to User::ForEachNeighbor().
284 class ForEachNeighborHandler
287 /** Method to execute for each local neighbor of a user.
288 * Derived classes must implement this.
289 * @param user Current neighbor
291 virtual void Execute(LocalUser* user) = 0;
294 /** List of Memberships for this user
296 typedef insp::intrusive_list<Membership> ChanList;
298 /** Time that the object was instantiated (used for TS calculation etc)
302 /** Time the connection was created, set in the constructor. This
303 * may be different from the time the user's classbase object was
308 /** Client address that the user is connected from.
309 * Do not modify this value directly, use SetClientIP() to change it.
310 * Port is not valid for remote users.
312 irc::sockets::sockaddrs client_sa;
314 /** The users nickname.
315 * An invalid nickname indicates an unregistered connection prior to the NICK command.
316 * Use InspIRCd::IsNick() to validate nicknames.
320 /** The user's unique identifier.
321 * This is the unique identifier which the user has across the network.
323 const std::string uuid;
325 /** The users ident reply.
326 * Two characters are added to the user-defined limit to compensate for the tilde etc.
330 /** What snomasks are set on this user.
331 * This functions the same as the above modes.
333 std::bitset<64> snomasks;
335 /** Channels this user is on
339 /** The server the user is connected to.
343 /** The user's away message.
344 * If this string is empty, the user is not marked as away.
348 /** Time the user last went away.
349 * This is ONLY RELIABLE if user IsAway()!
353 /** The oper type they logged in as, if they are an oper.
355 reference<OperInfo> oper;
357 /** Used by User to indicate the registration status of the connection
358 * It is a bitfield of the REG_NICK, REG_USER and REG_ALL bits to indicate
359 * the connection state.
361 unsigned int registered:3;
363 /** If this is set to true, then all socket operations for the user
364 * are dropped into the bit-bucket.
365 * This value is set by QuitUser, and is not needed separately from that call.
366 * Please note that setting this value alone will NOT cause the user to quit.
368 unsigned int quitting:1;
370 /** What type of user is this? */
371 const unsigned int usertype:2;
373 /** Get client IP string from sockaddr, using static internal buffer
374 * @return The IP string
376 const std::string& GetIPString();
378 /** Retrieves this user's hostname.
379 * @param uncloak If true then return the real host; otherwise, the display host.
381 const std::string& GetHost(bool uncloak) const;
383 /** Retrieves this user's displayed hostname. */
384 const std::string& GetDisplayedHost() const;
386 /** Retrieves this user's real hostname. */
387 const std::string& GetRealHost() const;
389 /** Retrieves this user's real name. */
390 const std::string& GetRealName() const;
392 /** Get CIDR mask, using default range, for this user
394 irc::sockets::cidr_mask GetCIDRMask();
396 /** Sets the client IP for this user
397 * @return true if the conversion was successful
399 virtual bool SetClientIP(const std::string& address);
401 virtual void SetClientIP(const irc::sockets::sockaddrs& sa);
404 * @throw CoreException if the UID allocated to the user already exists
406 User(const std::string& uid, Server* srv, UserType objtype);
408 /** Returns the full displayed 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.
411 * @return The full masked host of the user
413 virtual const std::string& GetFullHost();
415 /** Returns the full real host of the user
416 * This member function returns the hostname of the user as seen by other users
417 * on the server, in nick!ident\@host form. If any form of hostname cloaking is in operation,
418 * e.g. through a module, then this method will ignore it and return the true hostname.
419 * @return The full real host of the user
421 virtual const std::string& GetFullRealHost();
423 /** This clears any cached results that are used for GetFullRealHost() etc.
424 * The results of these calls are cached as generating them can be generally expensive.
426 void InvalidateCache();
428 /** Returns whether this user is currently away or not. If true,
429 * further information can be found in User::awaymsg and User::awaytime
430 * @return True if the user is away, false otherwise
432 bool IsAway() const { return (!awaymsg.empty()); }
434 /** Returns whether this user is an oper or not. If true,
435 * oper information can be obtained from User::oper
436 * @return True if the user is an oper, false otherwise
438 bool IsOper() const { return oper; }
440 /** Returns true if a notice mask is set
441 * @param sm A notice mask character to check
442 * @return True if the notice mask is set
444 bool IsNoticeMaskSet(unsigned char sm);
446 /** Get the mode letters of modes set on the user as a string.
447 * @param includeparams True to get the parameters of the modes as well. Defaults to false.
448 * @return Mode letters of modes set on the user and optionally the parameters of those modes, if any.
449 * The returned string always begins with a '+' character. If the user has no modes set, "+" is returned.
451 std::string GetModeLetters(bool includeparams = false) const;
453 /** Returns true if a specific mode is set
454 * @param m The user mode
455 * @return True if the mode is set
457 bool IsModeSet(unsigned char m) const;
458 bool IsModeSet(const ModeHandler* mh) const;
459 bool IsModeSet(const ModeHandler& mh) const { return IsModeSet(&mh); }
460 bool IsModeSet(UserModeReference& moderef) const;
462 /** Set a specific usermode to on or off
463 * @param mh The user mode
464 * @param value On or off setting of the mode
466 void SetMode(ModeHandler* mh, bool value);
467 void SetMode(ModeHandler& mh, bool value) { SetMode(&mh, value); }
469 /** Returns true or false for if a user can execute a privilaged oper command.
470 * This is done by looking up their oper type from User::oper, then referencing
471 * this to their oper classes and checking the commands they can execute.
472 * @param command A command (should be all CAPS)
473 * @return True if this user can execute the command
475 virtual bool HasCommandPermission(const std::string& command);
477 /** Returns true if a user has a given permission.
478 * This is used to check whether or not users may perform certain actions which admins may not wish to give to
479 * all operators, yet are not commands. An example might be oper override, mass messaging (/notice $*), etc.
481 * @param privstr The priv to chec, e.g. "users/override/topic". These are loaded free-form from the config file.
482 * @return True if this user has the permission in question.
484 virtual bool HasPrivPermission(const std::string& privstr);
486 /** Returns true or false if a user can set a privileged user or channel mode.
487 * This is done by looking up their oper type from User::oper, then referencing
488 * this to their oper classes, and checking the modes they can set.
489 * @param mh Mode to check
490 * @return True if the user can set or unset this mode.
492 virtual bool HasModePermission(const ModeHandler* mh) const;
494 /** Determines whether this user can set the specified snomask.
495 * @param chr The server notice mask character to look up.
496 * @return True if the user can set the specified snomask; otherwise, false.
498 virtual bool HasSnomaskPermission(char chr) const;
500 /** Creates a usermask with real host.
501 * Takes a buffer to use and fills the given buffer with the hostmask in the format user\@host
502 * @return the usermask in the format user\@host
504 const std::string& MakeHost();
506 /** Creates a usermask with real ip.
507 * Takes a buffer to use and fills the given buffer with the ipmask in the format user\@ip
508 * @return the usermask in the format user\@ip
510 const std::string& MakeHostIP();
512 /** Oper up the user using the given opertype.
513 * This will also give the +o usermode.
515 void Oper(OperInfo* info);
518 * This will clear the +o usermode and unset the user's oper type
522 /** Sends a server notice to this user.
523 * @param text The contents of the message to send.
525 void WriteNotice(const std::string& text);
527 /** Send a NOTICE message from the local server to the user.
528 * @param text Text to send
530 virtual void WriteRemoteNotice(const std::string& text);
532 virtual void WriteRemoteNumeric(const Numeric::Numeric& numeric);
534 template <typename T1>
535 void WriteRemoteNumeric(unsigned int numeric, T1 p1)
537 Numeric::Numeric n(numeric);
539 WriteRemoteNumeric(n);
542 template <typename T1, typename T2>
543 void WriteRemoteNumeric(unsigned int numeric, T1 p1, T2 p2)
545 Numeric::Numeric n(numeric);
548 WriteRemoteNumeric(n);
551 template <typename T1, typename T2, typename T3>
552 void WriteRemoteNumeric(unsigned int numeric, T1 p1, T2 p2, T3 p3)
554 Numeric::Numeric n(numeric);
558 WriteRemoteNumeric(n);
561 template <typename T1, typename T2, typename T3, typename T4>
562 void WriteRemoteNumeric(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4)
564 Numeric::Numeric n(numeric);
569 WriteRemoteNumeric(n);
572 template <typename T1, typename T2, typename T3, typename T4, typename T5>
573 void WriteRemoteNumeric(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5)
575 Numeric::Numeric n(numeric);
581 WriteRemoteNumeric(n);
584 void WriteNumeric(const Numeric::Numeric& numeric);
586 template <typename T1>
587 void WriteNumeric(unsigned int numeric, T1 p1)
589 Numeric::Numeric n(numeric);
594 template <typename T1, typename T2>
595 void WriteNumeric(unsigned int numeric, T1 p1, T2 p2)
597 Numeric::Numeric n(numeric);
603 template <typename T1, typename T2, typename T3>
604 void WriteNumeric(unsigned int numeric, T1 p1, T2 p2, T3 p3)
606 Numeric::Numeric n(numeric);
613 template <typename T1, typename T2, typename T3, typename T4>
614 void WriteNumeric(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4)
616 Numeric::Numeric n(numeric);
624 template <typename T1, typename T2, typename T3, typename T4, typename T5>
625 void WriteNumeric(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5)
627 Numeric::Numeric n(numeric);
636 /** Write to all users that can see this user (including this user in the list if include_self is true), appending CR/LF
637 * @param protoev Protocol event to send, may contain any number of messages.
638 * @param include_self Should the message be sent back to the author?
640 void WriteCommonRaw(ClientProtocol::Event& protoev, bool include_self = true);
642 /** Execute a function once for each local neighbor of this user. By default, the neighbors of a user are the users
643 * who have at least one common channel with the user. Modules are allowed to alter the set of neighbors freely.
644 * This function is used for example to send something conditionally to neighbors, or to send different messages
645 * to different users depending on their oper status.
646 * @param handler Function object to call, inherited from ForEachNeighborHandler.
647 * @param include_self True to include this user in the set of neighbors, false otherwise.
648 * Modules may override this. Has no effect if this user is not local.
650 void ForEachNeighbor(ForEachNeighborHandler& handler, bool include_self = true);
652 /** Return true if the user shares at least one channel with another user
653 * @param other The other user to compare the channel list against
654 * @return True if the given user shares at least one channel with this user
656 bool SharesChannelWith(User *other);
658 /** Change the displayed hostname of this user.
659 * @param host The new displayed hostname of this user.
660 * @return True if the hostname was changed successfully; otherwise, false.
662 bool ChangeDisplayedHost(const std::string& host);
664 /** Change the real hostname of this user.
665 * @param host The new real hostname of this user.
666 * @param resetdisplay Whether to reset the display host to this value.
668 void ChangeRealHost(const std::string& host, bool resetdisplay);
670 /** Change the ident (username) of a user.
671 * ALWAYS use this function, rather than writing User::ident directly,
672 * as this triggers module events allowing the change to be syncronized to
674 * @param newident The new ident to set
675 * @return True if the change succeeded, false if it didn't
677 bool ChangeIdent(const std::string& newident);
679 /** Change a users realname field.
680 * @param real The user's new real name
681 * @return True if the change succeeded, false if otherwise
683 bool ChangeRealName(const std::string& real);
685 /** Change a user's nick
686 * @param newnick The new nick. If equal to the users uuid, the nick change always succeeds.
687 * @param newts The time at which this nick change happened.
688 * @return True if the change succeeded
690 bool ChangeNick(const std::string& newnick, time_t newts = 0);
692 /** Remove this user from all channels they are on, and delete any that are now empty.
693 * This is used by QUIT, and will not send part messages!
695 void PurgeEmptyChannels();
697 /** Default destructor
700 CullResult cull() CXX11_OVERRIDE;
702 /** @copydoc Serializable::Deserialize */
703 bool Deserialize(Data& data) CXX11_OVERRIDE;
705 /** @copydoc Serializable::Deserialize */
706 bool Serialize(Serializable::Data& data) CXX11_OVERRIDE;
709 class CoreExport UserIOHandler : public StreamSocket
712 size_t checked_until;
714 LocalUser* const user;
715 UserIOHandler(LocalUser* me)
716 : StreamSocket(StreamSocket::SS_USER)
721 void OnDataReady() CXX11_OVERRIDE;
722 bool OnSetEndPoint(const irc::sockets::sockaddrs& local, const irc::sockets::sockaddrs& remote) CXX11_OVERRIDE;
723 void OnError(BufferedSocketError error) CXX11_OVERRIDE;
725 /** Adds to the user's write buffer.
726 * You may add any amount of text up to this users sendq value, if you exceed the
727 * sendq value, the user will be removed, and further buffer adds will be dropped.
728 * @param data The data to add to the write buffer
730 void AddWriteBuf(const std::string &data);
732 /** Swaps the internals of this UserIOHandler with another one.
733 * @param other A UserIOHandler to swap internals with.
735 void SwapInternals(UserIOHandler& other);
738 typedef unsigned int already_sent_t;
740 class CoreExport LocalUser : public User, public insp::intrusive_list_node<LocalUser>
742 /** Add a serialized message to the send queue of the user.
743 * @param serialized Bytes to add.
745 void Write(const ClientProtocol::SerializedMessage& serialized);
747 /** Send a protocol event to the user, consisting of one or more messages.
748 * @param protoev Event to send, may contain any number of messages.
749 * @param msglist Message list used temporarily internally to pass to hooks and store messages
752 void Send(ClientProtocol::Event& protoev, ClientProtocol::MessageList& msglist);
754 /** Message list, can be passed to the two parameter Send().
756 static ClientProtocol::MessageList sendmsglist;
759 LocalUser(int fd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
760 LocalUser(int fd, const std::string& uuid, Serializable::Data& data);
762 CullResult cull() CXX11_OVERRIDE;
766 /** Serializer to use when communicating with the user
768 ClientProtocol::Serializer* serializer;
770 /** Stats counter for bytes inbound
772 unsigned int bytes_in;
774 /** Stats counter for bytes outbound
776 unsigned int bytes_out;
778 /** Stats counter for commands inbound
780 unsigned int cmds_in;
782 /** Stats counter for commands outbound
784 unsigned int cmds_out;
786 /** Password specified by the user when they registered (if any).
787 * This is stored even if the \<connect> block doesnt need a password, so that
788 * modules may check it.
790 std::string password;
792 /** Contains a pointer to the connect class a user is on from
794 reference<ConnectClass> MyClass;
796 /** Get the connect class which this user belongs to.
797 * @return A pointer to this user's connect class.
799 ConnectClass* GetClass() const { return MyClass; }
801 /** Call this method to find the matching \<connect> for a user, and to check them against it.
803 void CheckClass(bool clone_count = true);
805 /** Server address and port that this user is connected to.
807 irc::sockets::sockaddrs server_sa;
809 /** Recursion fix: user is out of SendQ and will be quit as soon as possible.
810 * This can't be handled normally because QuitUser itself calls Write on other
811 * users, which could trigger their SendQ to overrun.
813 unsigned int quitting_sendq:1;
815 /** has the user responded to their previous ping?
817 unsigned int lastping:1;
819 /** This is true if the user matched an exception (E-line). It is used to save time on ban checks.
821 unsigned int exempt:1;
823 /** The time at which this user should be pinged next. */
826 /** Time that the connection last sent a message, used to calculate idle time
830 /** This value contains how far into the penalty threshold the user is.
831 * This is used either to enable fake lag or for excess flood quits
833 unsigned int CommandFloodPenalty;
835 already_sent_t already_sent;
837 /** Check if the user matches a G- or K-line, and disconnect them if they do.
838 * @param doZline True if Z-lines should be checked (if IP has changed since initial connect)
839 * Returns true if the user matched a ban, false else.
841 bool CheckLines(bool doZline = false);
843 /** Use this method to fully connect a user.
844 * This will send the message of the day, check G/K/E-lines, etc.
848 /** Set the connect class to which this user belongs to.
849 * @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.
850 * @return A reference to this user's current connect class.
852 void SetClass(const std::string &explicit_name = "");
854 bool SetClientIP(const std::string& address) CXX11_OVERRIDE;
856 void SetClientIP(const irc::sockets::sockaddrs& sa) CXX11_OVERRIDE;
858 /** Send a NOTICE message from the local server to the user.
859 * The message will be sent even if the user is connected to a remote server.
860 * @param text Text to send
862 void WriteRemoteNotice(const std::string& text) CXX11_OVERRIDE;
864 /** Returns true or false for if a user can execute a privilaged oper command.
865 * This is done by looking up their oper type from User::oper, then referencing
866 * this to their oper classes and checking the commands they can execute.
867 * @param command A command (should be all CAPS)
868 * @return True if this user can execute the command
870 bool HasCommandPermission(const std::string& command) CXX11_OVERRIDE;
872 /** Returns true if a user has a given permission.
873 * This is used to check whether or not users may perform certain actions which admins may not wish to give to
874 * all operators, yet are not commands. An example might be oper override, mass messaging (/notice $*), etc.
876 * @param privstr The priv to chec, e.g. "users/override/topic". These are loaded free-form from the config file.
877 * @return True if this user has the permission in question.
879 bool HasPrivPermission(const std::string& privstr) CXX11_OVERRIDE;
881 /** Returns true or false if a user can set a privileged user or channel mode.
882 * This is done by looking up their oper type from User::oper, then referencing
883 * this to their oper classes, and checking the modes they can set.
884 * @param mh Mode to check
885 * @return True if the user can set or unset this mode.
887 bool HasModePermission(const ModeHandler* mh) const CXX11_OVERRIDE;
889 /** @copydoc User::HasSnomaskPermission */
890 bool HasSnomaskPermission(char chr) const CXX11_OVERRIDE;
892 /** Change nick to uuid, unset REG_NICK and send a nickname overruled numeric.
893 * This is called when another user (either local or remote) needs the nick of this user and this user
898 /** Send a protocol event to the user, consisting of one or more messages.
899 * @param protoev Event to send, may contain any number of messages.
901 void Send(ClientProtocol::Event& protoev);
903 /** Send a single message to the user.
904 * @param protoevprov Protocol event provider.
905 * @param msg Message to send.
907 void Send(ClientProtocol::EventProvider& protoevprov, ClientProtocol::Message& msg);
909 /** @copydoc Serializable::Deserialize */
910 bool Deserialize(Data& data) CXX11_OVERRIDE;
912 /** @copydoc Serializable::Deserialize */
913 bool Serialize(Serializable::Data& data) CXX11_OVERRIDE;
916 class RemoteUser : public User
919 RemoteUser(const std::string& uid, Server* srv) : User(uid, srv, USERTYPE_REMOTE)
924 class CoreExport FakeUser : public User
927 FakeUser(const std::string& uid, Server* srv)
928 : User(uid, srv, USERTYPE_SERVER)
930 nick = srv->GetName();
933 FakeUser(const std::string& uid, const std::string& sname, const std::string& sdesc)
934 : User(uid, new Server(uid, sname, sdesc), USERTYPE_SERVER)
939 CullResult cull() CXX11_OVERRIDE;
940 const std::string& GetFullHost() CXX11_OVERRIDE;
941 const std::string& GetFullRealHost() CXX11_OVERRIDE;
944 /* Faster than dynamic_cast */
945 /** Is a local user */
946 inline LocalUser* IS_LOCAL(User* u)
948 return (u != NULL && u->usertype == USERTYPE_LOCAL) ? static_cast<LocalUser*>(u) : NULL;
950 /** Is a remote user */
951 inline RemoteUser* IS_REMOTE(User* u)
953 return (u != NULL && u->usertype == USERTYPE_REMOTE) ? static_cast<RemoteUser*>(u) : NULL;
955 /** Is a server fakeuser */
956 inline FakeUser* IS_SERVER(User* u)
958 return (u != NULL && u->usertype == USERTYPE_SERVER) ? static_cast<FakeUser*>(u) : NULL;
961 inline bool User::IsModeSet(const ModeHandler* mh) const
963 return ((mh->GetId() != ModeParser::MODEID_MAX) && (modes[mh->GetId()]));
966 inline bool User::IsModeSet(UserModeReference& moderef) const
970 return IsModeSet(*moderef);
973 inline void User::SetMode(ModeHandler* mh, bool value)
975 if (mh && mh->GetId() != ModeParser::MODEID_MAX)
976 modes[mh->GetId()] = value;