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