]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/users.h
Replace hardcoded mode letters, part 3
[user/henk/code/inspircd.git] / include / users.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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>
10  *
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.
14  *
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
18  * details.
19  *
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/>.
22  */
23
24
25 #pragma once
26
27 #include "socket.h"
28 #include "inspsocket.h"
29 #include "mode.h"
30 #include "membership.h"
31
32 /** connect class types
33  */
34 enum ClassTypes {
35         /** connect:allow */
36         CC_ALLOW = 0,
37         /** connect:deny */
38         CC_DENY  = 1,
39         /** named connect block (for opers, etc) */
40         CC_NAMED = 2
41 };
42
43 /** RFC1459 channel modes
44  */
45 enum UserModes {
46         /** +s: Server notice mask */
47         UM_SNOMASK = 's' - 65,
48         /** +w: WALLOPS */
49         UM_WALLOPS = 'w' - 65,
50         /** +i: Invisible */
51         UM_INVISIBLE = 'i' - 65,
52         /** +o: Operator */
53         UM_OPERATOR = 'o' - 65
54 };
55
56 /** Registration state of a user, e.g.
57  * have they sent USER, NICK, PASS yet?
58  */
59 enum RegistrationState {
60
61 #ifndef _WIN32   // Burlex: This is already defined in win32, luckily it is still 0.
62         REG_NONE = 0,           /* Has sent nothing */
63 #endif
64
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 */
69 };
70
71 enum UserType {
72         USERTYPE_LOCAL = 1,
73         USERTYPE_REMOTE = 2,
74         USERTYPE_SERVER = 3
75 };
76
77 /** Holds information relevent to &lt;connect allow&gt; and &lt;connect deny&gt; tags in the config file.
78  */
79 struct CoreExport ConnectClass : public refcountbase
80 {
81         reference<ConfigTag> config;
82         /** Type of line, either CC_ALLOW or CC_DENY
83          */
84         char type;
85
86         /** True if this class uses fake lag to manage flood, false if it kills */
87         bool fakelag;
88
89         /** Connect class name
90          */
91         std::string name;
92
93         /** Max time to register the connection in seconds
94          */
95         unsigned int registration_timeout;
96
97         /** Host mask for this line
98          */
99         std::string host;
100
101         /** Number of seconds between pings for this line
102          */
103         unsigned int pingtime;
104
105         /** Maximum size of sendq for users in this class (bytes)
106          * Users cannot send commands if they go over this limit
107          */
108         unsigned long softsendqmax;
109
110         /** Maximum size of sendq for users in this class (bytes)
111          * Users are killed if they go over this limit
112          */
113         unsigned long hardsendqmax;
114
115         /** Maximum size of recvq for users in this class (bytes)
116          */
117         unsigned long recvqmax;
118
119         /** Seconds worth of penalty before penalty system activates
120          */
121         unsigned int penaltythreshold;
122
123         /** Maximum rate of commands (units: millicommands per second) */
124         unsigned int commandrate;
125
126         /** Local max when connecting by this connection class
127          */
128         unsigned long maxlocal;
129
130         /** Global max when connecting by this connection class
131          */
132         unsigned long maxglobal;
133
134         /** True if max connections for this class is hit and a warning is wanted
135          */
136         bool maxconnwarn;
137
138         /** Max channels for this class
139          */
140         unsigned int maxchans;
141
142         /** How many users may be in this connect class before they are refused?
143          * (0 = no limit = default)
144          */
145         unsigned long limit;
146
147         /** If set to true, no user DNS lookups are to be performed
148          */
149         bool nouserdns;
150
151         /** Create a new connect class with no settings.
152          */
153         ConnectClass(ConfigTag* tag, char type, const std::string& mask);
154         /** Create a new connect class with inherited settings.
155          */
156         ConnectClass(ConfigTag* tag, char type, const std::string& mask, const ConnectClass& parent);
157
158         /** Update the settings in this block to match the given block */
159         void Update(const ConnectClass* newSettings);
160
161         const std::string& GetName() { return name; }
162         const std::string& GetHost() { return host; }
163
164         /** Returns the registration timeout
165          */
166         time_t GetRegTimeout()
167         {
168                 return (registration_timeout ? registration_timeout : 90);
169         }
170
171         /** Returns the ping frequency
172          */
173         unsigned int GetPingTime()
174         {
175                 return (pingtime ? pingtime : 120);
176         }
177
178         /** Returns the maximum sendq value (soft limit)
179          * Note that this is in addition to internal OS buffers
180          */
181         unsigned long GetSendqSoftMax()
182         {
183                 return (softsendqmax ? softsendqmax : 4096);
184         }
185
186         /** Returns the maximum sendq value (hard limit)
187          */
188         unsigned long GetSendqHardMax()
189         {
190                 return (hardsendqmax ? hardsendqmax : 0x100000);
191         }
192
193         /** Returns the maximum recvq value
194          */
195         unsigned long GetRecvqMax()
196         {
197                 return (recvqmax ? recvqmax : 4096);
198         }
199
200         /** Returns the penalty threshold value
201          */
202         unsigned int GetPenaltyThreshold()
203         {
204                 return penaltythreshold ? penaltythreshold : (fakelag ? 10 : 20);
205         }
206
207         unsigned int GetCommandRate()
208         {
209                 return commandrate ? commandrate : 1000;
210         }
211
212         /** Return the maximum number of local sessions
213          */
214         unsigned long GetMaxLocal()
215         {
216                 return maxlocal;
217         }
218
219         /** Returns the maximum number of global sessions
220          */
221         unsigned long GetMaxGlobal()
222         {
223                 return maxglobal;
224         }
225 };
226
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.
231  */
232 class CoreExport User : public Extensible
233 {
234  private:
235         /** Cached nick!ident@dhost value using the displayed hostname
236          */
237         std::string cached_fullhost;
238
239         /** Cached ident@ip value using the real IP address
240          */
241         std::string cached_hostip;
242
243         /** Cached ident@realhost value using the real hostname
244          */
245         std::string cached_makehost;
246
247         /** Cached nick!ident@realhost value using the real hostname
248          */
249         std::string cached_fullrealhost;
250
251         /** Set by GetIPString() to avoid constantly re-grabbing IP via sockets voodoo.
252          */
253         std::string cachedip;
254
255  public:
256
257         /** Hostname of connection.
258          * This should be valid as per RFC1035.
259          */
260         std::string host;
261
262         /** Time that the object was instantiated (used for TS calculation etc)
263         */
264         time_t age;
265
266         /** Time the connection was created, set in the constructor. This
267          * may be different from the time the user's classbase object was
268          * created.
269          */
270         time_t signon;
271
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.
275          */
276         irc::sockets::sockaddrs client_sa;
277
278         /** The users nickname.
279          * An invalid nickname indicates an unregistered connection prior to the NICK command.
280          * Use InspIRCd::IsNick() to validate nicknames.
281          */
282         std::string nick;
283
284         /** The user's unique identifier.
285          * This is the unique identifier which the user has across the network.
286          */
287         const std::string uuid;
288
289         /** The users ident reply.
290          * Two characters are added to the user-defined limit to compensate for the tilde etc.
291          */
292         std::string ident;
293
294         /** The host displayed to non-opers (used for cloaking etc).
295          * This usually matches the value of User::host.
296          */
297         std::string dhost;
298
299         /** The users full name (GECOS).
300          */
301         std::string fullname;
302
303         /** The user's mode list.
304          * NOT a null terminated string.
305          * Also NOT an array.
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.
312          */
313         std::bitset<64> modes;
314
315         /** What snomasks are set on this user.
316          * This functions the same as the above modes.
317          */
318         std::bitset<64> snomasks;
319
320         /** Channels this user is on
321          */
322         UserChanList chans;
323
324         /** The server the user is connected to.
325          */
326         const std::string server;
327
328         /** The user's away message.
329          * If this string is empty, the user is not marked as away.
330          */
331         std::string awaymsg;
332
333         /** Time the user last went away.
334          * This is ONLY RELIABLE if user IsAway()!
335          */
336         time_t awaytime;
337
338         /** The oper type they logged in as, if they are an oper.
339          */
340         reference<OperInfo> oper;
341
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.
345          */
346         unsigned int registered:3;
347
348         /** Whether or not to send an snotice about this user's quitting
349          */
350         unsigned int quietquit:1;
351
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.
356          */
357         unsigned int quitting:1;
358
359         /** What type of user is this? */
360         const unsigned int usertype:2;
361
362         /** Get client IP string from sockaddr, using static internal buffer
363          * @return The IP string
364          */
365         const std::string& GetIPString();
366
367         /** Get CIDR mask, using default range, for this user
368          */
369         irc::sockets::cidr_mask GetCIDRMask();
370
371         /** Sets the client IP for this user
372          * @return true if the conversion was successful
373          */
374         virtual bool SetClientIP(const char* sip, bool recheck_eline = true);
375
376         virtual void SetClientIP(const irc::sockets::sockaddrs& sa, bool recheck_eline = true);
377
378         /** Constructor
379          * @throw CoreException if the UID allocated to the user already exists
380          */
381         User(const std::string &uid, const std::string& srv, int objtype);
382
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
387          */
388         virtual const std::string& GetFullHost();
389
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
395          */
396         virtual const std::string& GetFullRealHost();
397
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.
400          */
401         void InvalidateCache();
402
403         /** Returns whether this user is currently away or not. If true,
404          * further information can be found in User::awaymsg and User::awaytime
405          * @return True if the user is away, false otherwise
406          */
407         bool IsAway() const { return (!awaymsg.empty()); }
408
409         /** Returns whether this user is an oper or not. If true,
410          * oper information can be obtained from User::oper
411          * @return True if the user is an oper, false otherwise
412          */
413         bool IsOper() const { return oper; }
414
415         /** Returns true if a notice mask is set
416          * @param sm A notice mask character to check
417          * @return True if the notice mask is set
418          */
419         bool IsNoticeMaskSet(unsigned char sm);
420
421         /** Create a displayable mode string for this users umodes
422          * @param showparameters The mode string
423          */
424         const char* FormatModes(bool showparameters = false);
425
426         /** Returns true if a specific mode is set
427          * @param m The user mode
428          * @return True if the mode is set
429          */
430         bool IsModeSet(unsigned char m);
431         bool IsModeSet(ModeHandler* mh);
432         bool IsModeSet(ModeHandler& mh) { return IsModeSet(&mh); }
433         bool IsModeSet(UserModeReference& moderef);
434
435         /** Set a specific usermode to on or off
436          * @param m The user mode
437          * @param value On or off setting of the mode
438          */
439         void SetMode(ModeHandler* mh, bool value);
440         void SetMode(ModeHandler& mh, bool value) { SetMode(&mh, value); }
441
442         /** Returns true or false for if a user can execute a privilaged oper command.
443          * This is done by looking up their oper type from User::oper, then referencing
444          * this to their oper classes and checking the commands they can execute.
445          * @param command A command (should be all CAPS)
446          * @return True if this user can execute the command
447          */
448         virtual bool HasPermission(const std::string &command);
449
450         /** Returns true if a user has a given permission.
451          * This is used to check whether or not users may perform certain actions which admins may not wish to give to
452          * all operators, yet are not commands. An example might be oper override, mass messaging (/notice $*), etc.
453          *
454          * @param privstr The priv to chec, e.g. "users/override/topic". These are loaded free-form from the config file.
455          * @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.
456          * @return True if this user has the permission in question.
457          */
458         virtual bool HasPrivPermission(const std::string &privstr, bool noisy = false);
459
460         /** Returns true or false if a user can set a privileged user or channel mode.
461          * This is done by looking up their oper type from User::oper, then referencing
462          * this to their oper classes, and checking the modes they can set.
463          * @param mode The mode the check
464          * @param type ModeType (MODETYPE_CHANNEL or MODETYPE_USER).
465          * @return True if the user can set or unset this mode.
466          */
467         virtual bool HasModePermission(unsigned char mode, ModeType type);
468
469         /** Creates a usermask with real host.
470          * Takes a buffer to use and fills the given buffer with the hostmask in the format user\@host
471          * @return the usermask in the format user\@host
472          */
473         const std::string& MakeHost();
474
475         /** Creates a usermask with real ip.
476          * Takes a buffer to use and fills the given buffer with the ipmask in the format user\@ip
477          * @return the usermask in the format user\@ip
478          */
479         const std::string& MakeHostIP();
480
481         /** Oper up the user using the given opertype.
482          * This will also give the +o usermode.
483          */
484         void Oper(OperInfo* info);
485
486         /** Force a nickname change.
487          * If the nickname change fails (for example, because the nick in question
488          * already exists) this function will return false, and you must then either
489          * output an error message, or quit the user for nickname collision.
490          * @param newnick The nickname to change to
491          * @return True if the nickchange was successful.
492          */
493         bool ForceNickChange(const std::string& newnick) { return ChangeNick(newnick, true); }
494
495         /** Oper down.
496          * This will clear the +o usermode and unset the user's oper type
497          */
498         void UnOper();
499
500         /** Write text to this user, appending CR/LF. Works on local users only.
501          * @param text A std::string to send to the user
502          */
503         virtual void Write(const std::string &text);
504
505         /** Write text to this user, appending CR/LF.
506          * Works on local users only.
507          * @param text The format string for text to send to the user
508          * @param ... POD-type format arguments
509          */
510         virtual void Write(const char *text, ...) CUSTOM_PRINTF(2, 3);
511
512         /** Write text to this user, appending CR/LF and prepending :server.name
513          * Works on local users only.
514          * @param text A std::string to send to the user
515          */
516         void WriteServ(const std::string& text);
517
518         /** Write text to this user, appending CR/LF and prepending :server.name
519          * Works on local users only.
520          * @param text The format string for text to send to the user
521          * @param ... POD-type format arguments
522          */
523         void WriteServ(const char* text, ...) CUSTOM_PRINTF(2, 3);
524
525         /** Sends a server notice to this user.
526          * @param text The contents of the message to send.
527          */
528         void WriteNotice(const std::string& text);
529
530         void WriteNumeric(unsigned int numeric, const char* text, ...) CUSTOM_PRINTF(3, 4);
531
532         void WriteNumeric(unsigned int numeric, const std::string &text);
533
534         /** Write text to this user, appending CR/LF and prepending :nick!user\@host of the user provided in the first parameter.
535          * @param user The user to prepend the :nick!user\@host of
536          * @param text A std::string to send to the user
537          */
538         void WriteFrom(User *user, const std::string &text);
539
540         /** Write text to this user, appending CR/LF and prepending :nick!user\@host of the user provided in the first parameter.
541          * @param user The user to prepend the :nick!user\@host of
542          * @param text The format string for text to send to the user
543          * @param ... POD-type format arguments
544          */
545         void WriteFrom(User *user, const char* text, ...) CUSTOM_PRINTF(3, 4);
546
547         /** Write text to the user provided in the first parameter, appending CR/LF, and prepending THIS user's :nick!user\@host.
548          * @param dest The user to route the message to
549          * @param data A std::string to send to the user
550          */
551         void WriteTo(User *dest, const std::string &data);
552
553         /** Write text to the user provided in the first parameter, appending CR/LF, and prepending THIS user's :nick!user\@host.
554          * @param dest The user to route the message to
555          * @param data The format string for text to send to the user
556          * @param ... POD-type format arguments
557          */
558         void WriteTo(User *dest, const char *data, ...) CUSTOM_PRINTF(3, 4);
559
560         /** Write to all users that can see this user (including this user in the list if include_self is true), appending CR/LF
561          * @param line A std::string to send to the users
562          * @param include_self Should the message be sent back to the author?
563          */
564         void WriteCommonRaw(const std::string &line, bool include_self = true);
565
566         /** Write to all users that can see this user (including this user in the list), appending CR/LF
567          * @param text The format string for text to send to the users
568          * @param ... POD-type format arguments
569          */
570         void WriteCommon(const char* text, ...) CUSTOM_PRINTF(2, 3);
571
572         /** Write to all users that can see this user (not including this user in the list), appending CR/LF
573          * @param text The format string for text to send to the users
574          * @param ... POD-type format arguments
575          */
576         void WriteCommonExcept(const char* text, ...) CUSTOM_PRINTF(2, 3);
577
578         /** Write a quit message to all common users, as in User::WriteCommonExcept but with a specific
579          * quit message for opers only.
580          * @param normal_text Normal user quit message
581          * @param oper_text Oper only quit message
582          */
583         void WriteCommonQuit(const std::string &normal_text, const std::string &oper_text);
584
585         /** Dump text to a user target, splitting it appropriately to fit
586          * @param linePrefix text to prefix each complete line with
587          * @param textStream the text to send to the user
588          */
589         void SendText(const std::string& linePrefix, std::stringstream& textStream);
590
591         /** Write to the user, routing the line if the user is remote.
592          */
593         virtual void SendText(const std::string& line) = 0;
594
595         /** Write to the user, routing the line if the user is remote.
596          */
597         void SendText(const char* text, ...) CUSTOM_PRINTF(2, 3);
598
599         /** Return true if the user shares at least one channel with another user
600          * @param other The other user to compare the channel list against
601          * @return True if the given user shares at least one channel with this user
602          */
603         bool SharesChannelWith(User *other);
604
605         /** Send fake quit/join messages for host or ident cycle.
606          * Run this after the item in question has changed.
607          * You should not need to use this function, call ChangeDisplayedHost instead
608          *
609          * @param quitline The entire QUIT line, including the source using the old value
610          */
611         void DoHostCycle(const std::string &quitline);
612
613         /** Change the displayed host of a user.
614          * ALWAYS use this function, rather than writing User::dhost directly,
615          * as this triggers module events allowing the change to be syncronized to
616          * remote servers. This will also emulate a QUIT and rejoin (where configured)
617          * before setting their host field.
618          * @param host The new hostname to set
619          * @return True if the change succeeded, false if it didn't
620          */
621         bool ChangeDisplayedHost(const char* host);
622
623         /** Change the ident (username) of a user.
624          * ALWAYS use this function, rather than writing User::ident directly,
625          * as this correctly causes the user to seem to quit (where configured)
626          * before setting their ident field.
627          * @param newident The new ident to set
628          * @return True if the change succeeded, false if it didn't
629          */
630         bool ChangeIdent(const char* newident);
631
632         /** Change a users realname field.
633          * ALWAYS use this function, rather than writing User::fullname directly,
634          * as this triggers module events allowing the change to be syncronized to
635          * remote servers.
636          * @param gecos The user's new realname
637          * @return True if the change succeeded, false if otherwise
638          */
639         bool ChangeName(const char* gecos);
640
641         /** Change a user's nick
642          * @param newnick The new nick
643          * @param force True if the change is being forced (should not be blocked by modes like +N)
644          * @return True if the change succeeded
645          */
646         bool ChangeNick(const std::string& newnick, bool force = false);
647
648         /** Send a command to all local users from this user
649          * The command given must be able to send text with the
650          * first parameter as a servermask (e.g. $*), so basically
651          * you should use PRIVMSG or NOTICE.
652          * @param command the command to send
653          * @param text The text format string to send
654          * @param ... Format arguments
655          */
656         void SendAll(const char* command, const char* text, ...) CUSTOM_PRINTF(3, 4);
657
658         /** Remove this user from all channels they are on, and delete any that are now empty.
659          * This is used by QUIT, and will not send part messages!
660          */
661         void PurgeEmptyChannels();
662
663         /** Get the connect class which this user belongs to. NULL for remote users.
664          * @return A pointer to this user's connect class.
665          */
666         virtual ConnectClass* GetClass();
667
668         /** Default destructor
669          */
670         virtual ~User();
671         virtual CullResult cull();
672 };
673
674 class CoreExport UserIOHandler : public StreamSocket
675 {
676  public:
677         LocalUser* const user;
678         UserIOHandler(LocalUser* me) : user(me) {}
679         void OnDataReady();
680         void OnError(BufferedSocketError error);
681
682         /** Adds to the user's write buffer.
683          * You may add any amount of text up to this users sendq value, if you exceed the
684          * sendq value, the user will be removed, and further buffer adds will be dropped.
685          * @param data The data to add to the write buffer
686          */
687         void AddWriteBuf(const std::string &data);
688 };
689
690 typedef unsigned int already_sent_t;
691
692 class CoreExport LocalUser : public User, public InviteBase
693 {
694  public:
695         LocalUser(int fd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
696         CullResult cull();
697
698         UserIOHandler eh;
699
700         /** Position in UserManager::local_users
701          */
702         LocalUserList::iterator localuseriter;
703
704         /** Stats counter for bytes inbound
705          */
706         unsigned int bytes_in;
707
708         /** Stats counter for bytes outbound
709          */
710         unsigned int bytes_out;
711
712         /** Stats counter for commands inbound
713          */
714         unsigned int cmds_in;
715
716         /** Stats counter for commands outbound
717          */
718         unsigned int cmds_out;
719
720         /** Password specified by the user when they registered (if any).
721          * This is stored even if the \<connect> block doesnt need a password, so that
722          * modules may check it.
723          */
724         std::string password;
725
726         /** Contains a pointer to the connect class a user is on from
727          */
728         reference<ConnectClass> MyClass;
729
730         ConnectClass* GetClass();
731
732         /** Call this method to find the matching \<connect> for a user, and to check them against it.
733          */
734         void CheckClass(bool clone_count = true);
735
736         /** Server address and port that this user is connected to.
737          */
738         irc::sockets::sockaddrs server_sa;
739
740         /**
741          * @return The port number of this user.
742          */
743         int GetServerPort();
744
745         /** Recursion fix: user is out of SendQ and will be quit as soon as possible.
746          * This can't be handled normally because QuitUser itself calls Write on other
747          * users, which could trigger their SendQ to overrun.
748          */
749         unsigned int quitting_sendq:1;
750
751         /** has the user responded to their previous ping?
752          */
753         unsigned int lastping:1;
754
755         /** This is true if the user matched an exception (E:Line). It is used to save time on ban checks.
756          */
757         unsigned int exempt:1;
758
759         /** Used by PING checking code
760          */
761         time_t nping;
762
763         /** Time that the connection last sent a message, used to calculate idle time
764          */
765         time_t idle_lastmsg;
766
767         /** This value contains how far into the penalty threshold the user is.
768          * This is used either to enable fake lag or for excess flood quits
769          */
770         unsigned int CommandFloodPenalty;
771
772         static already_sent_t already_sent_id;
773         already_sent_t already_sent;
774
775         /** Check if the user matches a G or K line, and disconnect them if they do.
776          * @param doZline True if ZLines should be checked (if IP has changed since initial connect)
777          * Returns true if the user matched a ban, false else.
778          */
779         bool CheckLines(bool doZline = false);
780
781         /** Use this method to fully connect a user.
782          * This will send the message of the day, check G/K/E lines, etc.
783          */
784         void FullConnect();
785
786         /** Set the connect class to which this user belongs to.
787          * @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.
788          * @return A reference to this user's current connect class.
789          */
790         void SetClass(const std::string &explicit_name = "");
791
792         bool SetClientIP(const char* sip, bool recheck_eline = true);
793
794         void SetClientIP(const irc::sockets::sockaddrs& sa, bool recheck_eline = true);
795
796         void SendText(const std::string& line);
797         void Write(const std::string& text);
798         void Write(const char*, ...) CUSTOM_PRINTF(2, 3);
799
800         /** Returns the list of channels this user has been invited to but has not yet joined.
801          * @return A list of channels the user is invited to
802          */
803         InviteList& GetInviteList();
804
805         /** Returns true if a user is invited to a channel.
806          * @param chan A channel to look up
807          * @return True if the user is invited to the given channel
808          */
809         bool IsInvited(Channel* chan) { return (Invitation::Find(chan, this) != NULL); }
810
811         /** Removes a channel from a users invite list.
812          * This member function is called on successfully joining an invite only channel
813          * to which the user has previously been invited, to clear the invitation.
814          * @param chan The channel to remove the invite to
815          * @return True if the user was invited to the channel and the invite was erased, false if the user wasn't invited
816          */
817         bool RemoveInvite(Channel* chan);
818
819         void RemoveExpiredInvites();
820
821         /** Returns true or false for if a user can execute a privilaged oper command.
822          * This is done by looking up their oper type from User::oper, then referencing
823          * this to their oper classes and checking the commands they can execute.
824          * @param command A command (should be all CAPS)
825          * @return True if this user can execute the command
826          */
827         bool HasPermission(const std::string &command);
828
829         /** Returns true if a user has a given permission.
830          * This is used to check whether or not users may perform certain actions which admins may not wish to give to
831          * all operators, yet are not commands. An example might be oper override, mass messaging (/notice $*), etc.
832          *
833          * @param privstr The priv to chec, e.g. "users/override/topic". These are loaded free-form from the config file.
834          * @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.
835          * @return True if this user has the permission in question.
836          */
837         bool HasPrivPermission(const std::string &privstr, bool noisy = false);
838
839         /** Returns true or false if a user can set a privileged user or channel mode.
840          * This is done by looking up their oper type from User::oper, then referencing
841          * this to their oper classes, and checking the modes they can set.
842          * @param mode The mode the check
843          * @param type ModeType (MODETYPE_CHANNEL or MODETYPE_USER).
844          * @return True if the user can set or unset this mode.
845          */
846         bool HasModePermission(unsigned char mode, ModeType type);
847 };
848
849 class CoreExport RemoteUser : public User
850 {
851  public:
852         RemoteUser(const std::string& uid, const std::string& srv) : User(uid, srv, USERTYPE_REMOTE)
853         {
854         }
855         virtual void SendText(const std::string& line);
856 };
857
858 class CoreExport FakeUser : public User
859 {
860  public:
861         FakeUser(const std::string &uid, const std::string& srv) : User(uid, srv, USERTYPE_SERVER)
862         {
863                 nick = srv;
864         }
865
866         virtual CullResult cull();
867         virtual void SendText(const std::string& line);
868         virtual const std::string& GetFullHost();
869         virtual const std::string& GetFullRealHost();
870 };
871
872 /* Faster than dynamic_cast */
873 /** Is a local user */
874 inline LocalUser* IS_LOCAL(User* u)
875 {
876         return u->usertype == USERTYPE_LOCAL ? static_cast<LocalUser*>(u) : NULL;
877 }
878 /** Is a remote user */
879 inline RemoteUser* IS_REMOTE(User* u)
880 {
881         return u->usertype == USERTYPE_REMOTE ? static_cast<RemoteUser*>(u) : NULL;
882 }
883 /** Is a server fakeuser */
884 inline FakeUser* IS_SERVER(User* u)
885 {
886         return u->usertype == USERTYPE_SERVER ? static_cast<FakeUser*>(u) : NULL;
887 }
888
889 inline bool User::IsModeSet(ModeHandler* mh)
890 {
891         char m = mh->GetModeChar();
892         return (modes[m-65]);
893 }
894
895 inline bool User::IsModeSet(UserModeReference& moderef)
896 {
897         if (!moderef)
898                 return false;
899         return IsModeSet(*moderef);
900 }
901
902 inline void User::SetMode(ModeHandler* mh, bool value)
903 {
904         char m = mh->GetModeChar();
905         modes[m-65] = value;
906 }