]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/users.h
d945116602e0d17990743390a819088cc1645566
[user/henk/code/inspircd.git] / include / users.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #ifndef __USERS_H__ 
18 #define __USERS_H__ 
19
20 #include <string>
21 #include "inspircd_config.h" 
22 #include "socket.h"
23 #include "channels.h"
24 #include "inspstring.h"
25 #include "connection.h"
26 #include "hashcomp.h"
27 #include "dns.h"
28 #include "cull_list.h"
29
30 enum ChanStatus {
31         STATUS_OP     = 4,
32         STATUS_HOP    = 2,
33         STATUS_VOICE  = 1,
34         STATUS_NORMAL = 0
35 };
36
37 enum ClassTypes {
38         CC_ALLOW = 0,
39         CC_DENY  = 1
40 };
41
42 /** RFC1459 channel modes
43  *  */
44 enum UserModes {
45         UM_SERVERNOTICE = 's'-65,
46         UM_WALLOPS = 'w'-65,
47         UM_INVISIBLE = 'i'-65,
48         UM_OPERATOR = 'o'-65,
49         UM_SNOMASK = 'n'-65,
50 };
51
52 enum RegistrationState {
53         REG_NONE = 0,           /* Has sent nothing */
54         REG_USER = 1,           /* Has sent USER */
55         REG_NICK = 2,           /* Has sent NICK */
56         REG_NICKUSER = 3,       /* Bitwise combination of REG_NICK and REG_USER */
57         REG_ALL = 7             /* REG_NICKUSER plus next bit along */
58 };
59
60 /** Holds a channel name to which a user has been invited.
61  */
62 class Invited : public classbase
63 {
64  public:
65          irc::string channel;
66 };
67
68 class InspIRCd;
69
70 /** Derived from Resolver, and performs user forward/reverse lookups.
71  */
72 class UserResolver : public Resolver
73 {
74  private:
75         /** User this class is 'attached' to.
76          */
77         userrec* bound_user;
78         int bound_fd;
79         bool fwd;
80  public:
81         UserResolver(InspIRCd* Instance, userrec* user, std::string to_resolve, QueryType qt);
82
83         void OnLookupComplete(const std::string &result);
84         void OnError(ResolverError e, const std::string &errormessage);
85 };
86
87
88 /** Holds information relevent to &lt;connect allow&gt; and &lt;connect deny&gt; tags in the config file.
89  */
90 class ConnectClass : public classbase
91 {
92  public:
93         /** Type of line, either CC_ALLOW or CC_DENY
94          */
95         char type;
96         /** Max time to register the connection in seconds
97          */
98         int registration_timeout;
99         /** Number of lines in buffer before excess flood is triggered
100          */
101         int flood;
102         /** Host mask for this line
103          */
104         std::string host;
105         /** Number of seconds between pings for this line
106          */
107         int pingtime;
108         /** (Optional) Password for this line
109          */
110         std::string pass;
111
112         /** Threshold value for flood disconnect
113          */
114         int threshold;
115
116         /** Maximum size of sendq for users in this class (bytes)
117          */
118         long sendqmax;
119
120         /** Maximum size of recvq for users in this class (bytes)
121          */
122         long recvqmax;
123
124         /** Local max when connecting by this connection class
125          */
126         long maxlocal;
127
128         /** Global max when connecting by this connection class
129          */
130         long maxglobal;
131         
132         ConnectClass() : registration_timeout(0), flood(0), host(""), pingtime(0), pass(""), threshold(0), sendqmax(0), recvqmax(0)
133         {
134         }
135 };
136
137 /** Holds a complete list of all channels to which a user has been invited and has not yet joined.
138  */
139 typedef std::vector<Invited> InvitedList;
140
141
142
143 /** Holds a complete list of all allow and deny tags from the configuration file (connection classes)
144  */
145 typedef std::vector<ConnectClass> ClassVector;
146
147 /** Typedef for the list of user-channel records for a user
148  */
149 typedef std::vector<ucrec*> UserChanList;
150
151 /** Holds all information about a user
152  * This class stores all information about a user connected to the irc server. Everything about a
153  * connection is stored here primarily, from the user's socket ID (file descriptor) through to the
154  * user's nickname and hostname. Use the FindNick method of the InspIRCd class to locate a specific user
155  * by nickname, or the FindDescriptor method of the InspIRCd class to find a specific user by their
156  * file descriptor value.
157  */
158 class userrec : public connection
159 {
160  private:
161         /** Pointer to creator.
162          * This is required to make use of core functions
163          * from within the userrec class.
164          */
165         InspIRCd* ServerInstance;
166
167         /** A list of channels the user has a pending invite to.
168          * Upon INVITE channels are added, and upon JOIN, the
169          * channels are removed from this list.
170          */
171         InvitedList invites;
172
173         /** Number of channels this user is currently on
174          */
175         unsigned int ChannelCount;
176  public:
177         /** Resolvers for looking up this users IP address
178          * This will occur if and when res_reverse completes.
179          * When this class completes its lookup, userrec::dns_done
180          * will be set from false to true.
181          */
182         UserResolver* res_forward;
183
184         /** Resolvers for looking up this users hostname
185          * This is instantiated by userrec::StartDNSLookup(),
186          * and on success, instantiates userrec::res_reverse.
187          */
188         UserResolver* res_reverse;
189
190         /** Stored reverse lookup from res_forward
191          */
192         std::string stored_host;
193
194         /** Starts a DNS lookup of the user's IP.
195          * This will cause two UserResolver classes to be instantiated.
196          * When complete, these objects set userrec::dns_done to true.
197          */
198         void StartDNSLookup();
199         
200         /** The users nickname.
201          * An invalid nickname indicates an unregistered connection prior to the NICK command.
202          * Use InspIRCd::IsNick() to validate nicknames.
203          */
204         char nick[NICKMAX];
205         
206         /** The users ident reply.
207          * Two characters are added to the user-defined limit to compensate for the tilde etc.
208          */
209         char ident[IDENTMAX+2];
210
211         /** The host displayed to non-opers (used for cloaking etc).
212          * This usually matches the value of userrec::host.
213          */
214         char dhost[65];
215         
216         /** The users full name (GECOS).
217          */
218         char fullname[MAXGECOS+1];
219         
220         /** The user's mode list.
221          * This is NOT a null terminated string! In the 1.1 version of InspIRCd
222          * this is an array of values in a similar way to channel modes.
223          * A value of 1 in field (modeletter-65) indicates that the mode is
224          * set, for example, to work out if mode +s is set, we  check the field
225          * userrec::modes['s'-65] != 0.
226          * The following RFC characters o, w, s, i have constants defined via an
227          * enum, such as UM_SERVERNOTICE and UM_OPETATOR.
228          */
229         char modes[64];
230
231         /** What snomasks are set on this user.
232          * This functions the same as the above modes.
233          */
234         char snomasks[64];
235
236         /** Channels this user is on, and the permissions they have there
237          */
238         UserChanList chans;
239         
240         /** The server the user is connected to.
241          */
242         const char* server;
243         
244         /** The user's away message.
245          * If this string is empty, the user is not marked as away.
246          */
247         char awaymsg[MAXAWAY+1];
248         
249         /** Number of lines the user can place into the buffer
250          * (up to the global NetBufferSize bytes) before they
251          * are disconnected for excess flood
252          */
253         int flood;
254         
255         /** Number of seconds this user is given to send USER/NICK
256          * If they do not send their details in this time limit they
257          * will be disconnected
258          */
259         unsigned int timeout;
260         
261         /** The oper type they logged in as, if they are an oper.
262          * This is used to check permissions in operclasses, so that
263          * we can say 'yay' or 'nay' to any commands they issue.
264          * The value of this is the value of a valid 'type name=' tag.
265          */
266         char oper[NICKMAX];
267
268         /** True when DNS lookups are completed.
269          * The UserResolver classes res_forward and res_reverse will
270          * set this value once they complete.
271          */
272         bool dns_done;
273
274         /** Number of seconds between PINGs for this user (set from &lt;connect:allow&gt; tag
275          */
276         unsigned int pingmax;
277
278         /** Password specified by the user when they registered.
279          * This is stored even if the <connect> block doesnt need a password, so that
280          * modules may check it.
281          */
282         char password[64];
283
284         /** User's receive queue.
285          * Lines from the IRCd awaiting processing are stored here.
286          * Upgraded april 2005, old system a bit hairy.
287          */
288         std::string recvq;
289
290         /** User's send queue.
291          * Lines waiting to be sent are stored here until their buffer is flushed.
292          */
293         std::string sendq;
294
295         /** Flood counters - lines received
296          */
297         int lines_in;
298
299         /** Flood counters - time lines_in is due to be reset
300          */
301         time_t reset_due;
302
303         /** Flood counters - Highest value lines_in may reach before the user gets disconnected
304          */
305         long threshold;
306
307         /** IPV4 or IPV6 ip address
308          */
309         sockaddr* ip;
310
311         /** Initialize the clients sockaddr
312          * @param protocol_family The protocol family of the IP address, AF_INET or AF_INET6
313          * @param ip A human-readable IP address for this user matching the protcol_family
314          * @param port The port number of this user or zero for a remote user
315          */
316         void SetSockAddr(int protocol_family, const char* ip, int port);
317
318         /** Get port number from sockaddr
319          * @return The port number of this user.
320          */
321         int GetPort();
322
323         /** Get protocol family from sockaddr
324          * @return The protocol family of this user, either AF_INET or AF_INET6
325          */
326         int GetProtocolFamily();
327
328         /** Get IP string from sockaddr, using static internal buffer
329          * @return The IP string
330          */
331         const char* GetIPString();
332
333         /** Get IP string from sockaddr, using caller-specified buffer
334          * @param buf A buffer to use
335          * @return The IP string
336          */
337         const char* GetIPString(char* buf);
338
339         /* Write error string
340          */
341         std::string WriteError;
342
343         /** Maximum size this user's sendq can become
344          */
345         long sendqmax;
346
347         /** Maximum size this user's recvq can become
348          */
349         long recvqmax;
350
351         /** Default constructor
352          * @throw Nothing at present
353          */
354         userrec(InspIRCd* Instance);
355         
356         /** Returns the full displayed host of the user
357          * This member function returns the hostname of the user as seen by other users
358          * on the server, in nick!ident&at;host form.
359          * @return The full masked host of the user
360          */
361         virtual char* GetFullHost();
362         
363         /** Returns the full real host of the user
364          * This member function returns the hostname of the user as seen by other users
365          * on the server, in nick!ident&at;host form. If any form of hostname cloaking is in operation,
366          * e.g. through a module, then this method will ignore it and return the true hostname.
367          * @return The full real host of the user
368          */
369         virtual char* GetFullRealHost();
370
371         /** Create a displayable mode string for this users snomasks
372          * @return The notice mask character sequence
373          */
374         const char* FormatNoticeMasks();
375
376         /** Process a snomask modifier string, e.g. +abc-de
377          * @param sm A sequence of notice mask characters
378          * @return The cleaned mode sequence which can be output,
379          * e.g. in the above example if masks c and e are not
380          * valid, this function will return +ab-d
381          */
382         std::string ProcessNoticeMasks(const char *sm);
383
384         /** Returns true if a notice mask is set
385          * @param sm A notice mask character to check
386          * @return True if the notice mask is set
387          */
388         bool IsNoticeMaskSet(unsigned char sm);
389
390         /** Changed a specific notice mask value
391          * @param sm The server notice mask to change
392          * @param value An on/off value for this mask
393          */
394         void SetNoticeMask(unsigned char sm, bool value);
395
396         /** Create a displayable mode string for this users umodes
397          * @param The mode string
398          */
399         const char* FormatModes();
400
401         /** Returns true if a specific mode is set
402          * @param m The user mode
403          * @return True if the mode is set
404          */
405         bool IsModeSet(unsigned char m);
406
407         /** Set a specific usermode to on or off
408          * @param m The user mode
409          * @param value On or off setting of the mode
410          */
411         void SetMode(unsigned char m, bool value);
412         
413         /** Returns true if a user is invited to a channel.
414          * @param channel A channel name to look up
415          * @return True if the user is invited to the given channel
416          */
417         virtual bool IsInvited(irc::string &channel);
418         
419         /** Adds a channel to a users invite list (invites them to a channel)
420          * @param channel A channel name to add
421          */
422         virtual void InviteTo(irc::string &channel);
423         
424         /** Removes a channel from a users invite list.
425          * This member function is called on successfully joining an invite only channel
426          * to which the user has previously been invited, to clear the invitation.
427          * @param channel The channel to remove the invite to
428          */
429         virtual void RemoveInvite(irc::string &channel);
430         
431         /** Returns true or false for if a user can execute a privilaged oper command.
432          * This is done by looking up their oper type from userrec::oper, then referencing
433          * this to their oper classes and checking the commands they can execute.
434          * @param command A command (should be all CAPS)
435          * @return True if this user can execute the command
436          */
437         bool HasPermission(const std::string &command);
438
439         /** Calls read() to read some data for this user using their fd.
440          * @param buffer The buffer to read into
441          * @param size The size of data to read
442          * @return The number of bytes read, or -1 if an error occured.
443          */
444         int ReadData(void* buffer, size_t size);
445
446         /** This method adds data to the read buffer of the user.
447          * The buffer can grow to any size within limits of the available memory,
448          * managed by the size of a std::string, however if any individual line in
449          * the buffer grows over 600 bytes in length (which is 88 chars over the
450          * RFC-specified limit per line) then the method will return false and the
451          * text will not be inserted.
452          * @param a The string to add to the users read buffer
453          * @return True if the string was successfully added to the read buffer
454          */
455         bool AddBuffer(std::string a);
456
457         /** This method returns true if the buffer contains at least one carriage return
458          * character (e.g. one complete line may be read)
459          * @return True if there is at least one complete line in the users buffer
460          */
461         bool BufferIsReady();
462
463         /** This function clears the entire buffer by setting it to an empty string.
464          */
465         void ClearBuffer();
466
467         /** This method returns the first available string at the tail end of the buffer
468          * and advances the tail end of the buffer past the string. This means it is
469          * a one way operation in a similar way to strtok(), and multiple calls return
470          * multiple lines if they are available. The results of this function if there
471          * are no lines to be read are unknown, always use BufferIsReady() to check if
472          * it is ok to read the buffer before calling GetBuffer().
473          * @return The string at the tail end of this users buffer
474          */
475         std::string GetBuffer();
476
477         /** Sets the write error for a connection. This is done because the actual disconnect
478          * of a client may occur at an inopportune time such as half way through /LIST output.
479          * The WriteErrors of clients are checked at a more ideal time (in the mainloop) and
480          * errored clients purged.
481          * @param error The error string to set.
482          */
483         void SetWriteError(const std::string &error);
484
485         /** Returns the write error which last occured on this connection or an empty string
486          * if none occured.
487          * @return The error string which has occured for this user
488          */
489         const char* GetWriteError();
490
491         /** Adds to the user's write buffer.
492          * You may add any amount of text up to this users sendq value, if you exceed the
493          * sendq value, SetWriteError() will be called to set the users error string to
494          * "SendQ exceeded", and further buffer adds will be dropped.
495          * @param data The data to add to the write buffer
496          */
497         void AddWriteBuf(const std::string &data);
498
499         /** Flushes as much of the user's buffer to the file descriptor as possible.
500          * This function may not always flush the entire buffer, rather instead as much of it
501          * as it possibly can. If the send() call fails to send the entire buffer, the buffer
502          * position is advanced forwards and the rest of the data sent at the next call to
503          * this method.
504          */
505         void FlushWriteBuf();
506
507         /** Returns the list of channels this user has been invited to but has not yet joined.
508          * @return A list of channels the user is invited to
509          */
510         InvitedList* GetInviteList();
511
512         /** Creates a wildcard host.
513          * Takes a buffer to use and fills the given buffer with the host in the format *!*@hostname
514          * @return The wildcarded hostname in *!*@host form
515          */
516         char* MakeWildHost();
517
518         /** Creates a usermask with real host.
519          * Takes a buffer to use and fills the given buffer with the hostmask in the format user@host
520          * @return the usermask in the format user@host
521          */
522         char* MakeHost();
523
524         /** Creates a usermask with real ip.
525          * Takes a buffer to use and fills the given buffer with the ipmask in the format user@ip
526          * @return the usermask in the format user@ip
527          */
528         char* MakeHostIP();
529
530         /** Shuts down and closes the user's socket
531          * This will not cause the user to be deleted. Use InspIRCd::QuitUser for this,
532          * which will call CloseSocket() for you.
533          */
534         void CloseSocket();
535
536         /** Disconnect a user gracefully
537          * @param user The user to remove
538          * @param r The quit reason
539          * @return Although this function has no return type, on exit the user provided will no longer exist.
540          */
541         static void QuitUser(InspIRCd* Instance, userrec *user, const std::string &r);
542
543         /** Add the user to WHOWAS system
544          */
545         void AddToWhoWas();
546
547         /** Oper up the user using the given opertype.
548          * This will also give the +o usermode.
549          * @param opertype The oper type to oper as
550          */
551         void Oper(const std::string &opertype);
552
553         /** Use this method to fully connect a user.
554          * This will send the message of the day, check G/K/E lines, etc.
555          * @param Goners If the user is disconnected by this method call, the
556          * value of 'this' will be pushed onto this CullList. This is used by
557          * the core to connect many users in rapid succession without invalidating
558          * iterators.
559          * @param Goners a CullList to use for failed connections
560          */
561         void FullConnect(CullList* Goners);
562
563         /** Change this users hash key to a new string.
564          * You should not call this function directly. It is used by the core
565          * to update the users hash entry on a nickchange.
566          * @param New new user_hash key
567          * @return Pointer to userrec in hash (usually 'this')
568          */
569         userrec* UpdateNickHash(const char* New);
570
571         /** Force a nickname change.
572          * If the nickname change fails (for example, because the nick in question
573          * already exists) this function will return false, and you must then either
574          * output an error message, or quit the user for nickname collision.
575          * @param newnick The nickname to change to
576          * @return True if the nickchange was successful.
577          */
578         bool ForceNickChange(const char* newnick);
579
580         /** Add a client to the system.
581          * This will create a new userrec, insert it into the user_hash,
582          * initialize it as not yet registered, and add it to the socket engine.
583          * @param Instance a pointer to the server instance
584          * @param socket The socket id (file descriptor) this user is on
585          * @param port The port number this user connected on
586          * @param iscached This variable is reserved for future use
587          * @param ip The IP address of the user
588          * @return This function has no return value, but a call to AddClient may remove the user.
589          */
590         static void AddClient(InspIRCd* Instance, int socket, int port, bool iscached, insp_inaddr ip);
591
592         /** Oper down.
593          * This will clear the +o usermode and unset the user's oper type
594          */
595         void UnOper();
596
597         /** Return the number of global clones of this user
598          * @return The global clone count of this user
599          */
600         long GlobalCloneCount();
601
602         /** Return the number of local clones of this user
603          * @return The local clone count of this user
604          */
605         long LocalCloneCount();
606
607         /** Write text to this user, appending CR/LF.
608          * @param text A std::string to send to the user
609          */
610         void Write(std::string text);
611
612         /** Write text to this user, appending CR/LF.
613          * @param text The format string for text to send to the user
614          * @param ... POD-type format arguments
615          */
616         void Write(const char *text, ...);
617
618         /** Write text to this user, appending CR/LF and prepending :server.name
619          * @param text A std::string to send to the user
620          */
621         void WriteServ(const std::string& text);
622
623         /** Write text to this user, appending CR/LF and prepending :server.name
624          * @param text The format string for text to send to the user
625          * @param ... POD-type format arguments
626          */
627         void WriteServ(const char* text, ...);
628
629         /** Write text to this user, appending CR/LF and prepending :nick!user@host of the user provided in the first parameter.
630          * @param user The user to prepend the :nick!user@host of
631          * @param text A std::string to send to the user
632          */
633         void WriteFrom(userrec *user, const std::string &text);
634
635         /** Write text to this user, appending CR/LF and prepending :nick!user@host of the user provided in the first parameter.
636          * @param user The user to prepend the :nick!user@host of
637          * @param text The format string for text to send to the user
638          * @param ... POD-type format arguments
639          */
640         void WriteFrom(userrec *user, const char* text, ...);
641
642         /** Write text to the user provided in the first parameter, appending CR/LF, and prepending THIS user's :nick!user@host.
643          * @param dest The user to route the message to
644          * @param text A std::string to send to the user
645          */
646         void WriteTo(userrec *dest, const std::string &data);
647
648         /** Write text to the user provided in the first parameter, appending CR/LF, and prepending THIS user's :nick!user@host.
649          * @param dest The user to route the message to
650          * @param text The format string for text to send to the user
651          * @param ... POD-type format arguments
652          */
653         void WriteTo(userrec *dest, const char *data, ...);
654
655         /** Write to all users that can see this user (including this user in the list), appending CR/LF
656          * @param text A std::string to send to the users
657          */
658         void WriteCommon(const std::string &text);
659
660         /** Write to all users that can see this user (including this user in the list), appending CR/LF
661          * @param text The format string for text to send to the users
662          * @param ... POD-type format arguments
663          */
664         void WriteCommon(const char* text, ...);
665
666         /** Write to all users that can see this user (not including this user in the list), appending CR/LF
667          * @param text The format string for text to send to the users
668          * @param ... POD-type format arguments
669          */
670         void WriteCommonExcept(const char* text, ...);
671
672         /** Write to all users that can see this user (not including this user in the list), appending CR/LF
673          * @param text A std::string to send to the users
674          */
675         void WriteCommonExcept(const std::string &text);
676
677         /** Write a WALLOPS message from this user to all local opers.
678          * If this user is not opered, the function will return without doing anything.
679          * @param text The format string to send in the WALLOPS message
680          * @param ... Format arguments
681          */
682         void WriteWallOps(const char* text, ...);
683
684         /** Write a WALLOPS message from this user to all local opers.
685          * If this user is not opered, the function will return without doing anything.
686          * @param text The text to send in the WALLOPS message
687          */
688         void WriteWallOps(const std::string &text);
689
690         /** Return true if the user shares at least one channel with another user
691          * @param other The other user to compare the channel list against
692          * @return True if the given user shares at least one channel with this user
693          */
694         bool SharesChannelWith(userrec *other);
695
696         /** Change the displayed host of a user.
697          * ALWAYS use this function, rather than writing userrec::dhost directly,
698          * as this triggers module events allowing the change to be syncronized to
699          * remote servers. This will also emulate a QUIT and rejoin (where configured)
700          * before setting their host field.
701          * @param host The new hostname to set
702          * @return True if the change succeeded, false if it didn't
703          */
704         bool ChangeDisplayedHost(const char* host);
705
706         /** Change the ident (username) of a user.
707          * ALWAYS use this function, rather than writing userrec::ident directly,
708          * as this correctly causes the user to seem to quit (where configured)
709          * before setting their ident field.
710          * @param host The new ident to set
711          * @return True if the change succeeded, false if it didn't
712          */
713         bool ChangeIdent(const char* newident);
714
715         /** Change a users realname field.
716          * ALWAYS use this function, rather than writing userrec::fullname directly,
717          * as this triggers module events allowing the change to be syncronized to
718          * remote servers.
719          * @param gecos The user's new realname
720          * @return True if the change succeeded, false if otherwise
721          */
722         bool ChangeName(const char* gecos);
723
724         /** Return the total number of channels this user is on.
725          * @return The number of channels the user is on
726          */
727         int CountChannels();
728
729         /** Modify the number of channels this user is on (used by CountChannels).
730          * Pass a positive number to increment the counter, or a negative number
731          * to decrement it.
732          */
733         void ModChannelCount(int n);
734
735         /** Send a notice to all local users from this user
736          * @param text The text format string to send
737          * @param ... Format arguments
738          */
739         void NoticeAll(char* text, ...);
740
741         /** Compile a channel list for this user, and send it to the user 'source'
742          * Used internally by WHOIS
743          * @param The user to send the channel list to if it is not too long
744          * @return This user's channel list
745          */
746         std::string ChannelList(userrec* source);
747
748         /** Split the channel list in cl which came from dest, and spool it to this user
749          * Used internally by WHOIS
750          * @param dest The user the original channel list came from
751          * @param cl The  channel list as a string obtained from userrec::ChannelList()
752          */
753         void SplitChanList(userrec* dest, const std::string &cl);
754
755         /** Remove this user from all channels they are on, and delete any that are now empty.
756          * This is used by QUIT, and will not send part messages!
757          */
758         void PurgeEmptyChannels();
759
760         /** Get the connect class which matches this user's host or IP address
761          * @return A reference to this user's connect class
762          */
763         ConnectClass& GetClass();
764
765         /** Show the message of the day to this user
766          */
767         void ShowMOTD();
768
769         /** Show the server RULES file to this user
770          */
771         void ShowRULES();
772
773         /** Handle socket event.
774          * From EventHandler class.
775          */
776         void HandleEvent(EventType et, int errornum = 0);
777
778         /** Default destructor
779          */
780         virtual ~userrec();
781 };
782
783
784 namespace irc
785 {
786         /** Holds whowas related functions and classes
787          */
788         namespace whowas
789         {
790
791                 /** Used to hold WHOWAS information
792                  */
793                 class WhoWasGroup : public classbase
794                 {
795                  public:
796                         /** Real host
797                          */
798                         char* host;
799                         /** Displayed host
800                          */
801                         char* dhost;
802                         /** Ident
803                          */
804                         char* ident;
805                         /** Server name
806                          */
807                         const char* server;
808                         /** Fullname (GECOS)
809                          */
810                         char* gecos;
811                         /** Signon time
812                          */
813                         time_t signon;
814         
815                         /** Initialize this WhoQasFroup with a user
816                          */
817                         WhoWasGroup(userrec* user);
818                         /** Destructor
819                          */
820                         ~WhoWasGroup();
821                 };
822
823                 /** A group of users related by nickname
824                  */
825                 typedef std::deque<WhoWasGroup*> whowas_set;
826
827                 /** Sets of users in the whowas system
828                  */
829                 typedef std::map<irc::string,whowas_set*> whowas_users;
830
831                 /** Sets of time and users in whowas list
832                  */
833                 typedef std::map<time_t,irc::string> whowas_users_fifo;
834
835                 /** Called every hour by the core to remove expired entries
836                  */
837                 void MaintainWhoWas(InspIRCd* ServerInstance, time_t TIME);
838
839                 /** Prune for WhoWasGroupSize, WhoWasMaxGroups and
840                  *  WhoWasMaxKeep on rehash
841                  */
842                 void PruneWhoWas(InspIRCd* ServerInstance, time_t TIME);
843         };
844 };
845
846 /* Configuration callbacks */
847 class ServerConfig;
848 bool InitTypes(ServerConfig* conf, const char* tag);
849 bool InitClasses(ServerConfig* conf, const char* tag);
850 bool DoType(ServerConfig* conf, const char* tag, char** entries, void** values, int* types);
851 bool DoClass(ServerConfig* conf, const char* tag, char** entries, void** values, int* types);
852 bool DoneClassesAndTypes(ServerConfig* conf, const char* tag);
853
854 #endif