]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/users.h
Document dns caching, add a "bool cached" to OnLookupComplete method in Resolver...
[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, bool &cache);
71
72         void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached);
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
235         /** When we erase the user (in the destructor),
236          * we call this method to subtract one from all
237          * mode characters this user is making use of.
238          */
239         void DecrementModes();
240  public:
241         /** Resolvers for looking up this users IP address
242          * This will occur if and when res_reverse completes.
243          * When this class completes its lookup, userrec::dns_done
244          * will be set from false to true.
245          */
246         UserResolver* res_forward;
247
248         /** Resolvers for looking up this users hostname
249          * This is instantiated by userrec::StartDNSLookup(),
250          * and on success, instantiates userrec::res_reverse.
251          */
252         UserResolver* res_reverse;
253
254         /** Stored reverse lookup from res_forward
255          */
256         std::string stored_host;
257
258         /** Starts a DNS lookup of the user's IP.
259          * This will cause two UserResolver classes to be instantiated.
260          * When complete, these objects set userrec::dns_done to true.
261          */
262         void StartDNSLookup();
263         
264         /** The users nickname.
265          * An invalid nickname indicates an unregistered connection prior to the NICK command.
266          * Use InspIRCd::IsNick() to validate nicknames.
267          */
268         char nick[NICKMAX];
269         
270         /** The users ident reply.
271          * Two characters are added to the user-defined limit to compensate for the tilde etc.
272          */
273         char ident[IDENTMAX+2];
274
275         /** The host displayed to non-opers (used for cloaking etc).
276          * This usually matches the value of userrec::host.
277          */
278         char dhost[65];
279         
280         /** The users full name (GECOS).
281          */
282         char fullname[MAXGECOS+1];
283         
284         /** The user's mode list.
285          * This is NOT a null terminated string! In the 1.1 version of InspIRCd
286          * this is an array of values in a similar way to channel modes.
287          * A value of 1 in field (modeletter-65) indicates that the mode is
288          * set, for example, to work out if mode +s is set, we  check the field
289          * userrec::modes['s'-65] != 0.
290          * The following RFC characters o, w, s, i have constants defined via an
291          * enum, such as UM_SERVERNOTICE and UM_OPETATOR.
292          */
293         char modes[64];
294
295         /** What snomasks are set on this user.
296          * This functions the same as the above modes.
297          */
298         char snomasks[64];
299
300         /** Channels this user is on, and the permissions they have there
301          */
302         UserChanList chans;
303         
304         /** The server the user is connected to.
305          */
306         const char* server;
307         
308         /** The user's away message.
309          * If this string is empty, the user is not marked as away.
310          */
311         char awaymsg[MAXAWAY+1];
312         
313         /** Number of lines the user can place into the buffer
314          * (up to the global NetBufferSize bytes) before they
315          * are disconnected for excess flood
316          */
317         int flood;
318         
319         /** Timestamp of current time + connection class timeout.
320          * This user must send USER/NICK before this timestamp is
321          * reached or they will be disconnected.
322          */
323         time_t timeout;
324         
325         /** The oper type they logged in as, if they are an oper.
326          * This is used to check permissions in operclasses, so that
327          * we can say 'yay' or 'nay' to any commands they issue.
328          * The value of this is the value of a valid 'type name=' tag.
329          */
330         char oper[NICKMAX];
331
332         /** True when DNS lookups are completed.
333          * The UserResolver classes res_forward and res_reverse will
334          * set this value once they complete.
335          */
336         bool dns_done;
337
338         /** Number of seconds between PINGs for this user (set from &lt;connect:allow&gt; tag
339          */
340         unsigned int pingmax;
341
342         /** Password specified by the user when they registered.
343          * This is stored even if the <connect> block doesnt need a password, so that
344          * modules may check it.
345          */
346         char password[64];
347
348         /** User's receive queue.
349          * Lines from the IRCd awaiting processing are stored here.
350          * Upgraded april 2005, old system a bit hairy.
351          */
352         std::string recvq;
353
354         /** User's send queue.
355          * Lines waiting to be sent are stored here until their buffer is flushed.
356          */
357         std::string sendq;
358
359         /** Flood counters - lines received
360          */
361         int lines_in;
362
363         /** Flood counters - time lines_in is due to be reset
364          */
365         time_t reset_due;
366
367         /** Flood counters - Highest value lines_in may reach before the user gets disconnected
368          */
369         long threshold;
370
371         /** IPV4 or IPV6 ip address
372          */
373         sockaddr* ip;
374
375         /** Initialize the clients sockaddr
376          * @param protocol_family The protocol family of the IP address, AF_INET or AF_INET6
377          * @param ip A human-readable IP address for this user matching the protcol_family
378          * @param port The port number of this user or zero for a remote user
379          */
380         void SetSockAddr(int protocol_family, const char* ip, int port);
381
382         /** Get port number from sockaddr
383          * @return The port number of this user.
384          */
385         int GetPort();
386
387         /** Get protocol family from sockaddr
388          * @return The protocol family of this user, either AF_INET or AF_INET6
389          */
390         int GetProtocolFamily();
391
392         /** Get IP string from sockaddr, using static internal buffer
393          * @return The IP string
394          */
395         const char* GetIPString();
396
397         /** Get IP string from sockaddr, using caller-specified buffer
398          * @param buf A buffer to use
399          * @return The IP string
400          */
401         const char* GetIPString(char* buf);
402
403         /* Write error string
404          */
405         std::string WriteError;
406
407         /** Maximum size this user's sendq can become
408          */
409         long sendqmax;
410
411         /** Maximum size this user's recvq can become
412          */
413         long recvqmax;
414
415         /** This is true if the user matched an exception when they connected to the ircd.
416          * It isnt valid after this point, and you should not attempt to do anything with it
417          * after this point, because the eline might be removed at a later time, and/or no
418          * longer be applicable to this user. It is only used to save doing the eline lookup
419          * twice (instead we do it once and set this value).
420          */
421         bool exempt;
422
423         /** Default constructor
424          * @throw Nothing at present
425          */
426         userrec(InspIRCd* Instance);
427         
428         /** Returns the full displayed host of the user
429          * This member function returns the hostname of the user as seen by other users
430          * on the server, in nick!ident&at;host form.
431          * @return The full masked host of the user
432          */
433         virtual char* GetFullHost();
434         
435         /** Returns the full real host of the user
436          * This member function returns the hostname of the user as seen by other users
437          * on the server, in nick!ident&at;host form. If any form of hostname cloaking is in operation,
438          * e.g. through a module, then this method will ignore it and return the true hostname.
439          * @return The full real host of the user
440          */
441         virtual char* GetFullRealHost();
442
443         /** This clears any cached results that are used for GetFullRealHost() etc.
444          * The results of these calls are cached as generating them can be generally expensive.
445          */
446         void InvalidateCache();
447
448         /** Create a displayable mode string for this users snomasks
449          * @return The notice mask character sequence
450          */
451         const char* FormatNoticeMasks();
452
453         /** Process a snomask modifier string, e.g. +abc-de
454          * @param sm A sequence of notice mask characters
455          * @return The cleaned mode sequence which can be output,
456          * e.g. in the above example if masks c and e are not
457          * valid, this function will return +ab-d
458          */
459         std::string ProcessNoticeMasks(const char *sm);
460
461         /** Returns true if a notice mask is set
462          * @param sm A notice mask character to check
463          * @return True if the notice mask is set
464          */
465         bool IsNoticeMaskSet(unsigned char sm);
466
467         /** Changed a specific notice mask value
468          * @param sm The server notice mask to change
469          * @param value An on/off value for this mask
470          */
471         void SetNoticeMask(unsigned char sm, bool value);
472
473         /** Create a displayable mode string for this users umodes
474          * @param The mode string
475          */
476         const char* FormatModes();
477
478         /** Returns true if a specific mode is set
479          * @param m The user mode
480          * @return True if the mode is set
481          */
482         bool IsModeSet(unsigned char m);
483
484         /** Set a specific usermode to on or off
485          * @param m The user mode
486          * @param value On or off setting of the mode
487          */
488         void SetMode(unsigned char m, bool value);
489         
490         /** Returns true if a user is invited to a channel.
491          * @param channel A channel name to look up
492          * @return True if the user is invited to the given channel
493          */
494         virtual bool IsInvited(const irc::string &channel);
495         
496         /** Adds a channel to a users invite list (invites them to a channel)
497          * @param channel A channel name to add
498          */
499         virtual void InviteTo(const irc::string &channel);
500         
501         /** Removes a channel from a users invite list.
502          * This member function is called on successfully joining an invite only channel
503          * to which the user has previously been invited, to clear the invitation.
504          * @param channel The channel to remove the invite to
505          */
506         virtual void RemoveInvite(const irc::string &channel);
507         
508         /** Returns true or false for if a user can execute a privilaged oper command.
509          * This is done by looking up their oper type from userrec::oper, then referencing
510          * this to their oper classes and checking the commands they can execute.
511          * @param command A command (should be all CAPS)
512          * @return True if this user can execute the command
513          */
514         bool HasPermission(const std::string &command);
515
516         /** Calls read() to read some data for this user using their fd.
517          * @param buffer The buffer to read into
518          * @param size The size of data to read
519          * @return The number of bytes read, or -1 if an error occured.
520          */
521         int ReadData(void* buffer, size_t size);
522
523         /** This method adds data to the read buffer of the user.
524          * The buffer can grow to any size within limits of the available memory,
525          * managed by the size of a std::string, however if any individual line in
526          * the buffer grows over 600 bytes in length (which is 88 chars over the
527          * RFC-specified limit per line) then the method will return false and the
528          * text will not be inserted.
529          * @param a The string to add to the users read buffer
530          * @return True if the string was successfully added to the read buffer
531          */
532         bool AddBuffer(std::string a);
533
534         /** This method returns true if the buffer contains at least one carriage return
535          * character (e.g. one complete line may be read)
536          * @return True if there is at least one complete line in the users buffer
537          */
538         bool BufferIsReady();
539
540         /** This function clears the entire buffer by setting it to an empty string.
541          */
542         void ClearBuffer();
543
544         /** This method returns the first available string at the tail end of the buffer
545          * and advances the tail end of the buffer past the string. This means it is
546          * a one way operation in a similar way to strtok(), and multiple calls return
547          * multiple lines if they are available. The results of this function if there
548          * are no lines to be read are unknown, always use BufferIsReady() to check if
549          * it is ok to read the buffer before calling GetBuffer().
550          * @return The string at the tail end of this users buffer
551          */
552         std::string GetBuffer();
553
554         /** Sets the write error for a connection. This is done because the actual disconnect
555          * of a client may occur at an inopportune time such as half way through /LIST output.
556          * The WriteErrors of clients are checked at a more ideal time (in the mainloop) and
557          * errored clients purged.
558          * @param error The error string to set.
559          */
560         void SetWriteError(const std::string &error);
561
562         /** Returns the write error which last occured on this connection or an empty string
563          * if none occured.
564          * @return The error string which has occured for this user
565          */
566         const char* GetWriteError();
567
568         /** Adds to the user's write buffer.
569          * You may add any amount of text up to this users sendq value, if you exceed the
570          * sendq value, SetWriteError() will be called to set the users error string to
571          * "SendQ exceeded", and further buffer adds will be dropped.
572          * @param data The data to add to the write buffer
573          */
574         void AddWriteBuf(const std::string &data);
575
576         /** Flushes as much of the user's buffer to the file descriptor as possible.
577          * This function may not always flush the entire buffer, rather instead as much of it
578          * as it possibly can. If the send() call fails to send the entire buffer, the buffer
579          * position is advanced forwards and the rest of the data sent at the next call to
580          * this method.
581          */
582         void FlushWriteBuf();
583
584         /** Returns the list of channels this user has been invited to but has not yet joined.
585          * @return A list of channels the user is invited to
586          */
587         InvitedList* GetInviteList();
588
589         /** Creates a wildcard host.
590          * Takes a buffer to use and fills the given buffer with the host in the format *!*@hostname
591          * @return The wildcarded hostname in *!*@host form
592          */
593         char* MakeWildHost();
594
595         /** Creates a usermask with real host.
596          * Takes a buffer to use and fills the given buffer with the hostmask in the format user@host
597          * @return the usermask in the format user@host
598          */
599         char* MakeHost();
600
601         /** Creates a usermask with real ip.
602          * Takes a buffer to use and fills the given buffer with the ipmask in the format user@ip
603          * @return the usermask in the format user@ip
604          */
605         char* MakeHostIP();
606
607         /** Shuts down and closes the user's socket
608          * This will not cause the user to be deleted. Use InspIRCd::QuitUser for this,
609          * which will call CloseSocket() for you.
610          */
611         void CloseSocket();
612
613         /** Disconnect a user gracefully
614          * @param user The user to remove
615          * @param r The quit reason
616          * @return Although this function has no return type, on exit the user provided will no longer exist.
617          */
618         static void QuitUser(InspIRCd* Instance, userrec *user, const std::string &r);
619
620         /** Add the user to WHOWAS system
621          */
622         void AddToWhoWas();
623
624         /** Oper up the user using the given opertype.
625          * This will also give the +o usermode.
626          * @param opertype The oper type to oper as
627          */
628         void Oper(const std::string &opertype);
629
630         /** Use this method to fully connect a user.
631          * This will send the message of the day, check G/K/E lines, etc.
632          * @param Goners If the user is disconnected by this method call, the
633          * value of 'this' will be pushed onto this CullList. This is used by
634          * the core to connect many users in rapid succession without invalidating
635          * iterators.
636          * @param Goners a CullList to use for failed connections
637          */
638         void FullConnect(CullList* Goners);
639
640         /** Change this users hash key to a new string.
641          * You should not call this function directly. It is used by the core
642          * to update the users hash entry on a nickchange.
643          * @param New new user_hash key
644          * @return Pointer to userrec in hash (usually 'this')
645          */
646         userrec* UpdateNickHash(const char* New);
647
648         /** Force a nickname change.
649          * If the nickname change fails (for example, because the nick in question
650          * already exists) this function will return false, and you must then either
651          * output an error message, or quit the user for nickname collision.
652          * @param newnick The nickname to change to
653          * @return True if the nickchange was successful.
654          */
655         bool ForceNickChange(const char* newnick);
656
657         /** Add a client to the system.
658          * This will create a new userrec, insert it into the user_hash,
659          * initialize it as not yet registered, and add it to the socket engine.
660          * @param Instance a pointer to the server instance
661          * @param socket The socket id (file descriptor) this user is on
662          * @param port The port number this user connected on
663          * @param iscached This variable is reserved for future use
664          * @param ip The IP address of the user
665          * @return This function has no return value, but a call to AddClient may remove the user.
666          */
667         static void AddClient(InspIRCd* Instance, int socket, int port, bool iscached, insp_inaddr ip);
668
669         /** Oper down.
670          * This will clear the +o usermode and unset the user's oper type
671          */
672         void UnOper();
673
674         /** Return the number of global clones of this user
675          * @return The global clone count of this user
676          */
677         unsigned long GlobalCloneCount();
678
679         /** Return the number of local clones of this user
680          * @return The local clone count of this user
681          */
682         unsigned long LocalCloneCount();
683
684         /** Write text to this user, appending CR/LF.
685          * @param text A std::string to send to the user
686          */
687         void Write(std::string text);
688
689         /** Write text to this user, appending CR/LF.
690          * @param text The format string for text to send to the user
691          * @param ... POD-type format arguments
692          */
693         void Write(const char *text, ...);
694
695         /** Write text to this user, appending CR/LF and prepending :server.name
696          * @param text A std::string to send to the user
697          */
698         void WriteServ(const std::string& text);
699
700         /** Write text to this user, appending CR/LF and prepending :server.name
701          * @param text The format string for text to send to the user
702          * @param ... POD-type format arguments
703          */
704         void WriteServ(const char* 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 A std::string to send to the user
709          */
710         void WriteFrom(userrec *user, const std::string &text);
711
712         /** Write text to this user, appending CR/LF and prepending :nick!user@host of the user provided in the first parameter.
713          * @param user The user to prepend the :nick!user@host of
714          * @param text The format string for text to send to the user
715          * @param ... POD-type format arguments
716          */
717         void WriteFrom(userrec *user, const char* text, ...);
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 A std::string to send to the user
722          */
723         void WriteTo(userrec *dest, const std::string &data);
724
725         /** Write text to the user provided in the first parameter, appending CR/LF, and prepending THIS user's :nick!user@host.
726          * @param dest The user to route the message to
727          * @param text The format string for text to send to the user
728          * @param ... POD-type format arguments
729          */
730         void WriteTo(userrec *dest, const char *data, ...);
731
732         /** Write to all users that can see this user (including this user in the list), appending CR/LF
733          * @param text A std::string to send to the users
734          */
735         void WriteCommon(const std::string &text);
736
737         /** Write to all users that can see this user (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 WriteCommon(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 The format string for text to send to the users
745          * @param ... POD-type format arguments
746          */
747         void WriteCommonExcept(const char* text, ...);
748
749         /** Write to all users that can see this user (not including this user in the list), appending CR/LF
750          * @param text A std::string to send to the users
751          */
752         void WriteCommonExcept(const std::string &text);
753
754         /** Write a WALLOPS message from this user to all local opers.
755          * If this user is not opered, the function will return without doing anything.
756          * @param text The format string to send in the WALLOPS message
757          * @param ... Format arguments
758          */
759         void WriteWallOps(const char* text, ...);
760
761         /** Write a WALLOPS message from this user to all local opers.
762          * If this user is not opered, the function will return without doing anything.
763          * @param text The text to send in the WALLOPS message
764          */
765         void WriteWallOps(const std::string &text);
766
767         /** Return true if the user shares at least one channel with another user
768          * @param other The other user to compare the channel list against
769          * @return True if the given user shares at least one channel with this user
770          */
771         bool SharesChannelWith(userrec *other);
772
773         /** Change the displayed host of a user.
774          * ALWAYS use this function, rather than writing userrec::dhost directly,
775          * as this triggers module events allowing the change to be syncronized to
776          * remote servers. This will also emulate a QUIT and rejoin (where configured)
777          * before setting their host field.
778          * @param host The new hostname to set
779          * @return True if the change succeeded, false if it didn't
780          */
781         bool ChangeDisplayedHost(const char* host);
782
783         /** Change the ident (username) of a user.
784          * ALWAYS use this function, rather than writing userrec::ident directly,
785          * as this correctly causes the user to seem to quit (where configured)
786          * before setting their ident field.
787          * @param host The new ident to set
788          * @return True if the change succeeded, false if it didn't
789          */
790         bool ChangeIdent(const char* newident);
791
792         /** Change a users realname field.
793          * ALWAYS use this function, rather than writing userrec::fullname directly,
794          * as this triggers module events allowing the change to be syncronized to
795          * remote servers.
796          * @param gecos The user's new realname
797          * @return True if the change succeeded, false if otherwise
798          */
799         bool ChangeName(const char* gecos);
800
801         /** Send a notice to all local users from this user
802          * @param text The text format string to send
803          * @param ... Format arguments
804          */
805         void NoticeAll(char* text, ...);
806
807         /** Compile a channel list for this user, and send it to the user 'source'
808          * Used internally by WHOIS
809          * @param The user to send the channel list to if it is not too long
810          * @return This user's channel list
811          */
812         std::string ChannelList(userrec* source);
813
814         /** Split the channel list in cl which came from dest, and spool it to this user
815          * Used internally by WHOIS
816          * @param dest The user the original channel list came from
817          * @param cl The  channel list as a string obtained from userrec::ChannelList()
818          */
819         void SplitChanList(userrec* dest, const std::string &cl);
820
821         /** Remove this user from all channels they are on, and delete any that are now empty.
822          * This is used by QUIT, and will not send part messages!
823          */
824         void PurgeEmptyChannels();
825
826         /** Get the connect class which matches this user's host or IP address
827          * @return A reference to this user's connect class
828          */
829         ConnectClass* GetClass();
830
831         /** Show the message of the day to this user
832          */
833         void ShowMOTD();
834
835         /** Show the server RULES file to this user
836          */
837         void ShowRULES();
838
839         /** Handle socket event.
840          * From EventHandler class.
841          */
842         void HandleEvent(EventType et, int errornum = 0);
843
844         /** Default destructor
845          */
846         virtual ~userrec();
847 };
848
849 /* Configuration callbacks */
850 class ServerConfig;
851
852 #endif