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 /** RFC1459 channel modes
46 /** +s: Server notice mask */
47 UM_SNOMASK = 's' - 65,
49 UM_WALLOPS = 'w' - 65,
51 UM_INVISIBLE = 'i' - 65,
53 UM_OPERATOR = 'o' - 65
56 /** Registration state of a user, e.g.
57 * have they sent USER, NICK, PASS yet?
59 enum RegistrationState {
61 #ifndef _WIN32 // Burlex: This is already defined in win32, luckily it is still 0.
62 REG_NONE = 0, /* Has sent nothing */
65 REG_USER = 1, /* Has sent USER */
66 REG_NICK = 2, /* Has sent NICK */
67 REG_NICKUSER = 3, /* Bitwise combination of REG_NICK and REG_USER */
68 REG_ALL = 7 /* REG_NICKUSER plus next bit along */
77 /** Holds information relevent to <connect allow> and <connect deny> tags in the config file.
79 struct CoreExport ConnectClass : public refcountbase
81 reference<ConfigTag> config;
82 /** Type of line, either CC_ALLOW or CC_DENY
86 /** True if this class uses fake lag to manage flood, false if it kills */
89 /** Connect class name
93 /** Max time to register the connection in seconds
95 unsigned int registration_timeout;
97 /** Host mask for this line
101 /** Number of seconds between pings for this line
103 unsigned int pingtime;
105 /** Maximum size of sendq for users in this class (bytes)
106 * Users cannot send commands if they go over this limit
108 unsigned long softsendqmax;
110 /** Maximum size of sendq for users in this class (bytes)
111 * Users are killed if they go over this limit
113 unsigned long hardsendqmax;
115 /** Maximum size of recvq for users in this class (bytes)
117 unsigned long recvqmax;
119 /** Seconds worth of penalty before penalty system activates
121 unsigned int penaltythreshold;
123 /** Maximum rate of commands (units: millicommands per second) */
124 unsigned int commandrate;
126 /** Local max when connecting by this connection class
128 unsigned long maxlocal;
130 /** Global max when connecting by this connection class
132 unsigned long maxglobal;
134 /** True if max connections for this class is hit and a warning is wanted
138 /** Max channels for this class
140 unsigned int maxchans;
142 /** How many users may be in this connect class before they are refused?
143 * (0 = no limit = default)
147 /** If set to true, no user DNS lookups are to be performed
151 /** Create a new connect class with no settings.
153 ConnectClass(ConfigTag* tag, char type, const std::string& mask);
154 /** Create a new connect class with inherited settings.
156 ConnectClass(ConfigTag* tag, char type, const std::string& mask, const ConnectClass& parent);
158 /** Update the settings in this block to match the given block */
159 void Update(const ConnectClass* newSettings);
161 const std::string& GetName() { return name; }
162 const std::string& GetHost() { return host; }
164 /** Returns the registration timeout
166 time_t GetRegTimeout()
168 return (registration_timeout ? registration_timeout : 90);
171 /** Returns the ping frequency
173 unsigned int GetPingTime()
175 return (pingtime ? pingtime : 120);
178 /** Returns the maximum sendq value (soft limit)
179 * Note that this is in addition to internal OS buffers
181 unsigned long GetSendqSoftMax()
183 return (softsendqmax ? softsendqmax : 4096);
186 /** Returns the maximum sendq value (hard limit)
188 unsigned long GetSendqHardMax()
190 return (hardsendqmax ? hardsendqmax : 0x100000);
193 /** Returns the maximum recvq value
195 unsigned long GetRecvqMax()
197 return (recvqmax ? recvqmax : 4096);
200 /** Returns the penalty threshold value
202 unsigned int GetPenaltyThreshold()
204 return penaltythreshold ? penaltythreshold : (fakelag ? 10 : 20);
207 unsigned int GetCommandRate()
209 return commandrate ? commandrate : 1000;
212 /** Return the maximum number of local sessions
214 unsigned long GetMaxLocal()
219 /** Returns the maximum number of global sessions
221 unsigned long GetMaxGlobal()
227 /** Holds all information about a user
228 * This class stores all information about a user connected to the irc server. Everything about a
229 * connection is stored here primarily, from the user's socket ID (file descriptor) through to the
230 * user's nickname and hostname.
232 class CoreExport User : public Extensible
235 /** Cached nick!ident@dhost value using the displayed hostname
237 std::string cached_fullhost;
239 /** Cached ident@ip value using the real IP address
241 std::string cached_hostip;
243 /** Cached ident@realhost value using the real hostname
245 std::string cached_makehost;
247 /** Cached nick!ident@realhost value using the real hostname
249 std::string cached_fullrealhost;
251 /** Set by GetIPString() to avoid constantly re-grabbing IP via sockets voodoo.
253 std::string cachedip;
257 /** Hostname of connection.
258 * This should be valid as per RFC1035.
262 /** Time that the object was instantiated (used for TS calculation etc)
266 /** Time the connection was created, set in the constructor. This
267 * may be different from the time the user's classbase object was
272 /** Client address that the user is connected from.
273 * Do not modify this value directly, use SetClientIP() to change it.
274 * Port is not valid for remote users.
276 irc::sockets::sockaddrs client_sa;
278 /** The users nickname.
279 * An invalid nickname indicates an unregistered connection prior to the NICK command.
280 * Use InspIRCd::IsNick() to validate nicknames.
284 /** The user's unique identifier.
285 * This is the unique identifier which the user has across the network.
287 const std::string uuid;
289 /** The users ident reply.
290 * Two characters are added to the user-defined limit to compensate for the tilde etc.
294 /** The host displayed to non-opers (used for cloaking etc).
295 * This usually matches the value of User::host.
299 /** The users full name (GECOS).
301 std::string fullname;
303 /** The user's mode list.
304 * NOT a null terminated string.
306 * Much love to the STL for giving us an easy to use bitset, saving us RAM.
307 * if (modes[modeletter-65]) is set, then the mode is
308 * set, for example, to work out if mode +s is set, we check the field
309 * User::modes['s'-65] != 0.
310 * The following RFC characters o, w, s, i have constants defined via an
311 * enum, such as UM_SERVERNOTICE and UM_OPETATOR.
313 std::bitset<64> modes;
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.
326 const std::string server;
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 /** Whether or not to send an snotice about this user's quitting
350 unsigned int quietquit:1;
352 /** If this is set to true, then all socket operations for the user
353 * are dropped into the bit-bucket.
354 * This value is set by QuitUser, and is not needed seperately from that call.
355 * Please note that setting this value alone will NOT cause the user to quit.
357 unsigned int quitting:1;
359 /** What type of user is this? */
360 const unsigned int usertype:2;
362 /** Get client IP string from sockaddr, using static internal buffer
363 * @return The IP string
365 const std::string& GetIPString();
367 /** Get CIDR mask, using default range, for this user
369 irc::sockets::cidr_mask GetCIDRMask();
371 /** Sets the client IP for this user
372 * @return true if the conversion was successful
374 virtual bool SetClientIP(const char* sip, bool recheck_eline = true);
376 virtual void SetClientIP(const irc::sockets::sockaddrs& sa, bool recheck_eline = true);
379 * @throw CoreException if the UID allocated to the user already exists
381 User(const std::string &uid, const std::string& srv, int objtype);
383 /** Returns the full displayed host of the user
384 * This member function returns the hostname of the user as seen by other users
385 * on the server, in nick!ident\@host form.
386 * @return The full masked host of the user
388 virtual const std::string& GetFullHost();
390 /** Returns the full real 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. If any form of hostname cloaking is in operation,
393 * e.g. through a module, then this method will ignore it and return the true hostname.
394 * @return The full real host of the user
396 virtual const std::string& GetFullRealHost();
398 /** This clears any cached results that are used for GetFullRealHost() etc.
399 * The results of these calls are cached as generating them can be generally expensive.
401 void InvalidateCache();
403 /** Create a displayable mode string for this users snomasks
404 * @return The notice mask character sequence
406 const char* FormatNoticeMasks();
408 /** Process a snomask modifier string, e.g. +abc-de
409 * @param sm A sequence of notice mask characters
410 * @return The cleaned mode sequence which can be output,
411 * e.g. in the above example if masks c and e are not
412 * valid, this function will return +ab-d
414 std::string ProcessNoticeMasks(const char *sm);
416 /** Returns whether this user is currently away or not. If true,
417 * further information can be found in User::awaymsg and User::awaytime
418 * @return True if the user is away, false otherwise
420 bool IsAway() const { return (!awaymsg.empty()); }
422 /** Returns whether this user is an oper or not. If true,
423 * oper information can be obtained from User::oper
424 * @return True if the user is an oper, false otherwise
426 bool IsOper() const { return oper; }
428 /** Returns true if a notice mask is set
429 * @param sm A notice mask character to check
430 * @return True if the notice mask is set
432 bool IsNoticeMaskSet(unsigned char sm);
434 /** Changed a specific notice mask value
435 * @param sm The server notice mask to change
436 * @param value An on/off value for this mask
438 void SetNoticeMask(unsigned char sm, bool value);
440 /** Create a displayable mode string for this users umodes
441 * @param showparameters The mode string
443 const char* FormatModes(bool showparameters = false);
445 /** Returns true if a specific mode is set
446 * @param m The user mode
447 * @return True if the mode is set
449 bool IsModeSet(unsigned char m);
451 /** Set a specific usermode to on or off
452 * @param m The user mode
453 * @param value On or off setting of the mode
455 void SetMode(unsigned char m, bool value);
457 /** Returns true or false for if a user can execute a privilaged oper command.
458 * This is done by looking up their oper type from User::oper, then referencing
459 * this to their oper classes and checking the commands they can execute.
460 * @param command A command (should be all CAPS)
461 * @return True if this user can execute the command
463 virtual bool HasPermission(const std::string &command);
465 /** Returns true if a user has a given permission.
466 * This is used to check whether or not users may perform certain actions which admins may not wish to give to
467 * all operators, yet are not commands. An example might be oper override, mass messaging (/notice $*), etc.
469 * @param privstr The priv to chec, e.g. "users/override/topic". These are loaded free-form from the config file.
470 * @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.
471 * @return True if this user has the permission in question.
473 virtual bool HasPrivPermission(const std::string &privstr, bool noisy = false);
475 /** Returns true or false if a user can set a privileged user or channel mode.
476 * This is done by looking up their oper type from User::oper, then referencing
477 * this to their oper classes, and checking the modes they can set.
478 * @param mode The mode the check
479 * @param type ModeType (MODETYPE_CHANNEL or MODETYPE_USER).
480 * @return True if the user can set or unset this mode.
482 virtual bool HasModePermission(unsigned char mode, ModeType type);
484 /** Creates a wildcard host.
485 * Takes a buffer to use and fills the given buffer with the host in the format *!*\@hostname
486 * @return The wildcarded hostname in *!*\@host form
488 char* MakeWildHost();
490 /** Creates a usermask with real host.
491 * Takes a buffer to use and fills the given buffer with the hostmask in the format user\@host
492 * @return the usermask in the format user\@host
494 const std::string& MakeHost();
496 /** Creates a usermask with real ip.
497 * Takes a buffer to use and fills the given buffer with the ipmask in the format user\@ip
498 * @return the usermask in the format user\@ip
500 const std::string& MakeHostIP();
502 /** Oper up the user using the given opertype.
503 * This will also give the +o usermode.
505 void Oper(OperInfo* info);
507 /** Force a nickname change.
508 * If the nickname change fails (for example, because the nick in question
509 * already exists) this function will return false, and you must then either
510 * output an error message, or quit the user for nickname collision.
511 * @param newnick The nickname to change to
512 * @return True if the nickchange was successful.
514 bool ForceNickChange(const std::string& newnick) { return ChangeNick(newnick, true); }
517 * This will clear the +o usermode and unset the user's oper type
521 /** Write text to this user, appending CR/LF. Works on local users only.
522 * @param text A std::string to send to the user
524 virtual void Write(const std::string &text);
526 /** Write text to this user, appending CR/LF.
527 * Works on local users only.
528 * @param text The format string for text to send to the user
529 * @param ... POD-type format arguments
531 virtual void Write(const char *text, ...) CUSTOM_PRINTF(2, 3);
533 /** Write text to this user, appending CR/LF and prepending :server.name
534 * Works on local users only.
535 * @param text A std::string to send to the user
537 void WriteServ(const std::string& text);
539 /** Write text to this user, appending CR/LF and prepending :server.name
540 * Works on local users only.
541 * @param text The format string for text to send to the user
542 * @param ... POD-type format arguments
544 void WriteServ(const char* text, ...) CUSTOM_PRINTF(2, 3);
546 /** Sends a server notice to this user.
547 * @param text The contents of the message to send.
549 void WriteNotice(const std::string& text);
551 void WriteNumeric(unsigned int numeric, const char* text, ...) CUSTOM_PRINTF(3, 4);
553 void WriteNumeric(unsigned int numeric, const std::string &text);
555 /** Write text to this user, appending CR/LF and prepending :nick!user\@host of the user provided in the first parameter.
556 * @param user The user to prepend the :nick!user\@host of
557 * @param text A std::string to send to the user
559 void WriteFrom(User *user, const std::string &text);
561 /** Write text to this user, appending CR/LF and prepending :nick!user\@host of the user provided in the first parameter.
562 * @param user The user to prepend the :nick!user\@host of
563 * @param text The format string for text to send to the user
564 * @param ... POD-type format arguments
566 void WriteFrom(User *user, const char* text, ...) CUSTOM_PRINTF(3, 4);
568 /** Write text to the user provided in the first parameter, appending CR/LF, and prepending THIS user's :nick!user\@host.
569 * @param dest The user to route the message to
570 * @param data A std::string to send to the user
572 void WriteTo(User *dest, const std::string &data);
574 /** Write text to the user provided in the first parameter, appending CR/LF, and prepending THIS user's :nick!user\@host.
575 * @param dest The user to route the message to
576 * @param data The format string for text to send to the user
577 * @param ... POD-type format arguments
579 void WriteTo(User *dest, const char *data, ...) CUSTOM_PRINTF(3, 4);
581 /** Write to all users that can see this user (including this user in the list if include_self is true), appending CR/LF
582 * @param line A std::string to send to the users
583 * @param include_self Should the message be sent back to the author?
585 void WriteCommonRaw(const std::string &line, bool include_self = true);
587 /** Write to all users that can see this user (including this user in the list), appending CR/LF
588 * @param text The format string for text to send to the users
589 * @param ... POD-type format arguments
591 void WriteCommon(const char* text, ...) CUSTOM_PRINTF(2, 3);
593 /** Write to all users that can see this user (not including this user in the list), appending CR/LF
594 * @param text The format string for text to send to the users
595 * @param ... POD-type format arguments
597 void WriteCommonExcept(const char* text, ...) CUSTOM_PRINTF(2, 3);
599 /** Write a quit message to all common users, as in User::WriteCommonExcept but with a specific
600 * quit message for opers only.
601 * @param normal_text Normal user quit message
602 * @param oper_text Oper only quit message
604 void WriteCommonQuit(const std::string &normal_text, const std::string &oper_text);
606 /** Dump text to a user target, splitting it appropriately to fit
607 * @param LinePrefix text to prefix each complete line with
608 * @param TextStream the text to send to the user
610 void SendText(const std::string &LinePrefix, std::stringstream &TextStream);
612 /** Write to the user, routing the line if the user is remote.
614 virtual void SendText(const std::string& line) = 0;
616 /** Write to the user, routing the line if the user is remote.
618 void SendText(const char* text, ...) CUSTOM_PRINTF(2, 3);
620 /** Return true if the user shares at least one channel with another user
621 * @param other The other user to compare the channel list against
622 * @return True if the given user shares at least one channel with this user
624 bool SharesChannelWith(User *other);
626 /** Send fake quit/join messages for host or ident cycle.
627 * Run this after the item in question has changed.
628 * You should not need to use this function, call ChangeDisplayedHost instead
630 * @param quitline The entire QUIT line, including the source using the old value
632 void DoHostCycle(const std::string &quitline);
634 /** Change the displayed host of a user.
635 * ALWAYS use this function, rather than writing User::dhost directly,
636 * as this triggers module events allowing the change to be syncronized to
637 * remote servers. This will also emulate a QUIT and rejoin (where configured)
638 * before setting their host field.
639 * @param host The new hostname to set
640 * @return True if the change succeeded, false if it didn't
642 bool ChangeDisplayedHost(const char* host);
644 /** Change the ident (username) of a user.
645 * ALWAYS use this function, rather than writing User::ident directly,
646 * as this correctly causes the user to seem to quit (where configured)
647 * before setting their ident field.
648 * @param newident The new ident to set
649 * @return True if the change succeeded, false if it didn't
651 bool ChangeIdent(const char* newident);
653 /** Change a users realname field.
654 * ALWAYS use this function, rather than writing User::fullname directly,
655 * as this triggers module events allowing the change to be syncronized to
657 * @param gecos The user's new realname
658 * @return True if the change succeeded, false if otherwise
660 bool ChangeName(const char* gecos);
662 /** Change a user's nick
663 * @param newnick The new nick
664 * @param force True if the change is being forced (should not be blocked by modes like +N)
665 * @return True if the change succeeded
667 bool ChangeNick(const std::string& newnick, bool force = false);
669 /** Send a command to all local users from this user
670 * The command given must be able to send text with the
671 * first parameter as a servermask (e.g. $*), so basically
672 * you should use PRIVMSG or NOTICE.
673 * @param command the command to send
674 * @param text The text format string to send
675 * @param ... Format arguments
677 void SendAll(const char* command, const char* text, ...) CUSTOM_PRINTF(3, 4);
679 /** 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 /** Get the connect class which this user belongs to. NULL for remote users.
685 * @return A pointer to this user's connect class.
687 virtual ConnectClass* GetClass();
689 /** Default destructor
692 virtual CullResult cull();
695 class CoreExport UserIOHandler : public StreamSocket
698 LocalUser* const user;
699 UserIOHandler(LocalUser* me) : user(me) {}
701 void OnError(BufferedSocketError error);
703 /** Adds to the user's write buffer.
704 * You may add any amount of text up to this users sendq value, if you exceed the
705 * sendq value, the user will be removed, and further buffer adds will be dropped.
706 * @param data The data to add to the write buffer
708 void AddWriteBuf(const std::string &data);
711 typedef unsigned int already_sent_t;
713 class CoreExport LocalUser : public User, public InviteBase
716 LocalUser(int fd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
721 /** Position in UserManager::local_users
723 LocalUserList::iterator localuseriter;
725 /** Stats counter for bytes inbound
727 unsigned int bytes_in;
729 /** Stats counter for bytes outbound
731 unsigned int bytes_out;
733 /** Stats counter for commands inbound
735 unsigned int cmds_in;
737 /** Stats counter for commands outbound
739 unsigned int cmds_out;
741 /** Password specified by the user when they registered (if any).
742 * This is stored even if the \<connect> block doesnt need a password, so that
743 * modules may check it.
745 std::string password;
747 /** Contains a pointer to the connect class a user is on from
749 reference<ConnectClass> MyClass;
751 ConnectClass* GetClass();
753 /** Call this method to find the matching \<connect> for a user, and to check them against it.
757 /** Server address and port that this user is connected to.
759 irc::sockets::sockaddrs server_sa;
762 * @return The port number of this user.
766 /** Recursion fix: user is out of SendQ and will be quit as soon as possible.
767 * This can't be handled normally because QuitUser itself calls Write on other
768 * users, which could trigger their SendQ to overrun.
770 unsigned int quitting_sendq:1;
772 /** has the user responded to their previous ping?
774 unsigned int lastping:1;
776 /** This is true if the user matched an exception (E:Line). It is used to save time on ban checks.
778 unsigned int exempt:1;
780 /** Used by PING checking code
784 /** Time that the connection last sent a message, used to calculate idle time
788 /** This value contains how far into the penalty threshold the user is.
789 * This is used either to enable fake lag or for excess flood quits
791 unsigned int CommandFloodPenalty;
793 static already_sent_t already_sent_id;
794 already_sent_t already_sent;
796 /** Check if the user matches a G or K line, and disconnect them if they do.
797 * @param doZline True if ZLines should be checked (if IP has changed since initial connect)
798 * Returns true if the user matched a ban, false else.
800 bool CheckLines(bool doZline = false);
802 /** Use this method to fully connect a user.
803 * This will send the message of the day, check G/K/E lines, etc.
807 /** Set the connect class to which this user belongs to.
808 * @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.
809 * @return A reference to this user's current connect class.
811 void SetClass(const std::string &explicit_name = "");
813 bool SetClientIP(const char* sip, bool recheck_eline = true);
815 void SetClientIP(const irc::sockets::sockaddrs& sa, bool recheck_eline = true);
817 void SendText(const std::string& line);
818 void Write(const std::string& text);
819 void Write(const char*, ...) CUSTOM_PRINTF(2, 3);
821 /** Returns the list of channels this user has been invited to but has not yet joined.
822 * @return A list of channels the user is invited to
824 InviteList& GetInviteList();
826 /** Returns true if a user is invited to a channel.
827 * @param channel A channel to look up
828 * @return True if the user is invited to the given channel
830 bool IsInvited(Channel* chan) { return (Invitation::Find(chan, this) != NULL); }
832 /** Removes a channel from a users invite list.
833 * This member function is called on successfully joining an invite only channel
834 * to which the user has previously been invited, to clear the invitation.
835 * @param channel The channel to remove the invite to
836 * @return True if the user was invited to the channel and the invite was erased, false if the user wasn't invited
838 bool RemoveInvite(Channel* chan);
840 void RemoveExpiredInvites();
842 /** Returns true or false for if a user can execute a privilaged oper command.
843 * This is done by looking up their oper type from User::oper, then referencing
844 * this to their oper classes and checking the commands they can execute.
845 * @param command A command (should be all CAPS)
846 * @return True if this user can execute the command
848 bool HasPermission(const std::string &command);
850 /** Returns true if a user has a given permission.
851 * This is used to check whether or not users may perform certain actions which admins may not wish to give to
852 * all operators, yet are not commands. An example might be oper override, mass messaging (/notice $*), etc.
854 * @param privstr The priv to chec, e.g. "users/override/topic". These are loaded free-form from the config file.
855 * @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.
856 * @return True if this user has the permission in question.
858 bool HasPrivPermission(const std::string &privstr, bool noisy = false);
860 /** Returns true or false if a user can set a privileged user or channel mode.
861 * This is done by looking up their oper type from User::oper, then referencing
862 * this to their oper classes, and checking the modes they can set.
863 * @param mode The mode the check
864 * @param type ModeType (MODETYPE_CHANNEL or MODETYPE_USER).
865 * @return True if the user can set or unset this mode.
867 bool HasModePermission(unsigned char mode, ModeType type);
870 class CoreExport RemoteUser : public User
873 RemoteUser(const std::string& uid, const std::string& srv) : User(uid, srv, USERTYPE_REMOTE)
876 virtual void SendText(const std::string& line);
879 class CoreExport FakeUser : public User
882 FakeUser(const std::string &uid, const std::string& srv) : User(uid, srv, USERTYPE_SERVER)
887 virtual CullResult cull();
888 virtual void SendText(const std::string& line);
889 virtual const std::string& GetFullHost();
890 virtual const std::string& GetFullRealHost();
893 /* Faster than dynamic_cast */
894 /** Is a local user */
895 inline LocalUser* IS_LOCAL(User* u)
897 return u->usertype == USERTYPE_LOCAL ? static_cast<LocalUser*>(u) : NULL;
899 /** Is a remote user */
900 inline RemoteUser* IS_REMOTE(User* u)
902 return u->usertype == USERTYPE_REMOTE ? static_cast<RemoteUser*>(u) : NULL;
904 /** Is a server fakeuser */
905 inline FakeUser* IS_SERVER(User* u)
907 return u->usertype == USERTYPE_SERVER ? static_cast<FakeUser*>(u) : NULL;