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