]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/users.h
Remove an extern, partly because it's unused, partly because it then gets shadowed...
[user/henk/code/inspircd.git] / include / users.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #ifndef __USERS_H__ 
18 #define __USERS_H__ 
19
20 #include <string>
21
22 #ifdef THREADED_DNS
23 #include <pthread.h>
24 #endif
25
26 #include "inspircd_config.h" 
27 #include "socket.h"
28 #include "channels.h"
29 #include "inspstring.h"
30 #include "connection.h"
31 #include "hashcomp.h"
32 #include "cull_list.h"
33
34 enum ChanStatus {
35         STATUS_OP     = 4,
36         STATUS_HOP    = 2,
37         STATUS_VOICE  = 1,
38         STATUS_NORMAL = 0
39 };
40
41 enum ClassTypes {
42         CC_ALLOW = 0,
43         CC_DENY  = 1
44 };
45
46 /** Holds a channel name to which a user has been invited.
47  */
48 class Invited : public classbase
49 {
50  public:
51          irc::string channel;
52 };
53
54
55 /** Holds information relevent to &lt;connect allow&gt; and &lt;connect deny&gt; tags in the config file.
56  */
57 class ConnectClass : public classbase
58 {
59  public:
60         /** Type of line, either CC_ALLOW or CC_DENY
61          */
62         char type;
63         /** Max time to register the connection in seconds
64          */
65         int registration_timeout;
66         /** Number of lines in buffer before excess flood is triggered
67          */
68         int flood;
69         /** Host mask for this line
70          */
71         std::string host;
72         /** Number of seconds between pings for this line
73          */
74         int pingtime;
75         /** (Optional) Password for this line
76          */
77         std::string pass;
78
79         /** Threshold value for flood disconnect
80          */
81         int threshold;
82
83         /** Maximum size of sendq for users in this class (bytes)
84          */
85         long sendqmax;
86
87         /** Maximum size of recvq for users in this class (bytes)
88          */
89         long recvqmax;
90
91         /** Local max when connecting by this connection class
92          */
93         long maxlocal;
94
95         /** Global max when connecting by this connection class
96          */
97         long maxglobal;
98         
99         ConnectClass() : registration_timeout(0), flood(0), host(""), pingtime(0), pass(""), threshold(0), sendqmax(0), recvqmax(0)
100         {
101         }
102 };
103
104 /** Holds a complete list of all channels to which a user has been invited and has not yet joined.
105  */
106 typedef std::vector<Invited> InvitedList;
107
108
109
110 /** Holds a complete list of all allow and deny tags from the configuration file (connection classes)
111  */
112 typedef std::vector<ConnectClass> ClassVector;
113
114 /** Typedef for the list of user-channel records for a user
115  */
116 typedef std::vector<ucrec*> UserChanList;
117
118 /** Holds all information about a user
119  * This class stores all information about a user connected to the irc server. Everything about a
120  * connection is stored here primarily, from the user's socket ID (file descriptor) through to the
121  * user's nickname and hostname. Use the Find method of the server class to locate a specific user
122  * by nickname.
123  */
124 class userrec : public connection
125 {
126  private:
127
128         /** A list of channels the user has a pending invite to.
129          */
130         InvitedList invites;
131  public:
132         
133         /** The users nickname.
134          * An invalid nickname indicates an unregistered connection prior to the NICK command.
135          */
136         
137         char nick[NICKMAX];
138         
139         /** The users ident reply.
140          * Two characters are added to the user-defined limit to compensate for the tilde etc.
141          */
142         char ident[IDENTMAX+2];
143
144         /** The host displayed to non-opers (used for cloaking etc).
145          * This usually matches the value of userrec::host.
146          */
147         char dhost[64];
148         
149         /** The users full name.
150          */
151         char fullname[MAXGECOS+1];
152         
153         /** The user's mode string.
154          * This may contain any of the following RFC characters: o, w, s, i
155          * Your module may define other mode characters as it sees fit.
156          * it is limited to length 54, as there can only be a maximum of 52
157          * user modes (26 upper, 26 lower case) a null terminating char, and
158          * an optional + character.
159          */
160         char modes[54];
161
162         /** This contains a bitmask of the RFC modes +swi,
163          * which can be used for fast lookup when iterating all the users.
164          * It is maintained by the mode parser and matches the character
165          * modes stored in 'modes'.
166          */
167         char modebits;
168         
169         UserChanList chans;
170         
171         /** The server the user is connected to.
172          */
173         char* server;
174         
175         /** The user's away message.
176          * If this string is empty, the user is not marked as away.
177          */
178         char awaymsg[MAXAWAY+1];
179         
180         /** Number of lines the user can place into the buffer
181          * (up to the global NetBufferSize bytes) before they
182          * are disconnected for excess flood
183          */
184         int flood;
185         
186         /** Number of seconds this user is given to send USER/NICK
187          * If they do not send their details in this time limit they
188          * will be disconnected
189          */
190         unsigned int timeout;
191         
192         /** The oper type they logged in as, if they are an oper.
193          * This is used to check permissions in operclasses, so that
194          * we can say 'yay' or 'nay' to any commands they issue.
195          * The value of this is the value of a valid 'type name=' tag.
196          */
197         char oper[NICKMAX];
198
199         /** True when DNS lookups are completed.
200          */
201         bool dns_done;
202
203         /** Number of seconds between PINGs for this user (set from &lt;connect:allow&gt; tag
204          */
205         unsigned int pingmax;
206
207         /** Password specified by the user when they registered.
208          * This is stored even if the <connect> block doesnt need a password, so that
209          * modules may check it.
210          */
211         char password[64];
212
213         /** User's receive queue.
214          * Lines from the IRCd awaiting processing are stored here.
215          * Upgraded april 2005, old system a bit hairy.
216          */
217         std::string recvq;
218
219         /** User's send queue.
220          * Lines waiting to be sent are stored here until their buffer is flushed.
221          */
222         std::string sendq;
223
224         /** Flood counters
225          */
226         int lines_in;
227         time_t reset_due;
228         long threshold;
229
230         /** IPV4 ip address
231          */
232         in_addr ip4;
233
234         /* Write error string
235          */
236         std::string WriteError;
237
238         /** Maximum size this user's sendq can become
239          */
240         long sendqmax;
241
242         /** Maximum size this user's recvq can become
243          */
244         long recvqmax;
245
246         /** Default constructor
247          */
248         userrec();
249         
250         /** Returns the full displayed host of the user
251          * This member function returns the hostname of the user as seen by other users
252          * on the server, in nick!ident&at;host form.
253          */
254         virtual char* GetFullHost();
255         
256         /** Returns the full real host of the user
257          * This member function returns the hostname of the user as seen by other users
258          * on the server, in nick!ident&at;host form. If any form of hostname cloaking is in operation,
259          * e.g. through a module, then this method will ignore it and return the true hostname.
260          */
261         virtual char* GetFullRealHost();
262         
263         /** Returns true if a user is invited to a channel.
264          */
265         virtual bool IsInvited(irc::string &channel);
266         
267         /** Adds a channel to a users invite list (invites them to a channel)
268          */
269         virtual void InviteTo(irc::string &channel);
270         
271         /** Removes a channel from a users invite list.
272          * This member function is called on successfully joining an invite only channel
273          * to which the user has previously been invited, to clear the invitation.
274          */
275         virtual void RemoveInvite(irc::string &channel);
276         
277         /** Returns true or false for if a user can execute a privilaged oper command.
278          * This is done by looking up their oper type from userrec::oper, then referencing
279          * this to their oper classes and checking the commands they can execute.
280          */
281         bool HasPermission(const std::string &command);
282
283         /** Calls read() to read some data for this user using their fd.
284          */
285         int ReadData(void* buffer, size_t size);
286
287         /** This method adds data to the buffer of the user.
288          * The buffer can grow to any size within limits of the available memory,
289          * managed by the size of a std::string, however if any individual line in
290          * the buffer grows over 600 bytes in length (which is 88 chars over the
291          * RFC-specified limit per line) then the method will return false and the
292          * text will not be inserted.
293          */
294         bool AddBuffer(const std::string &a);
295
296         /** This method returns true if the buffer contains at least one carriage return
297          * character (e.g. one complete line may be read)
298          */
299         bool BufferIsReady();
300
301         /** This function clears the entire buffer by setting it to an empty string.
302          */
303         void ClearBuffer();
304
305         /** This method returns the first available string at the tail end of the buffer
306          * and advances the tail end of the buffer past the string. This means it is
307          * a one way operation in a similar way to strtok(), and multiple calls return
308          * multiple lines if they are available. The results of this function if there
309          * are no lines to be read are unknown, always use BufferIsReady() to check if
310          * it is ok to read the buffer before calling GetBuffer().
311          */
312         std::string GetBuffer();
313
314         /** Sets the write error for a connection. This is done because the actual disconnect
315          * of a client may occur at an inopportune time such as half way through /LIST output.
316          * The WriteErrors of clients are checked at a more ideal time (in the mainloop) and
317          * errored clients purged.
318          */
319         void SetWriteError(const std::string &error);
320
321         /** Returns the write error which last occured on this connection or an empty string
322          * if none occured.
323          */
324         const char* GetWriteError();
325
326         /** Adds to the user's write buffer.
327          * You may add any amount of text up to this users sendq value, if you exceed the
328          * sendq value, SetWriteError() will be called to set the users error string to
329          * "SendQ exceeded", and further buffer adds will be dropped.
330          */
331         void AddWriteBuf(const std::string &data);
332
333         /** Flushes as much of the user's buffer to the file descriptor as possible.
334          * This function may not always flush the entire buffer, rather instead as much of it
335          * as it possibly can. If the send() call fails to send the entire buffer, the buffer
336          * position is advanced forwards and the rest of the data sent at the next call to
337          * this method.
338          */
339         void FlushWriteBuf();
340
341         /** Returns the list of channels this user has been invited to but has not yet joined.
342          */
343         InvitedList* GetInviteList();
344
345         /** Creates a wildcard host.
346          * Takes a buffer to use and fills the given buffer with the host in the format *!*@hostname
347          */
348         char* MakeWildHost();
349
350         /** Creates a host.
351          * Takes a buffer to use and fills the given buffer with the host in the format nick!user@host
352          */
353         void MakeHost(char* nhost);
354
355         /** Shuts down and closes the user's socket
356          */
357         void CloseSocket();
358
359         /** Default destructor
360          */
361         virtual ~userrec();
362
363 #ifdef THREADED_DNS
364         /** Thread used for threaded lookups
365          */
366         pthread_t dnsthread;
367 #endif
368 };
369
370 /** Used to hold WHOWAS information
371  */
372 class WhoWasGroup
373 {
374  public:
375         char* host;
376         char* dhost;
377         char* ident;
378         char* server;
379         char* gecos;
380         time_t signon;
381
382         WhoWasGroup(userrec* user);
383         ~WhoWasGroup();
384 };
385
386 typedef std::deque<WhoWasGroup*> whowas_set;
387 typedef std::map<irc::string,whowas_set*> whowas_users;
388
389 void AddOper(userrec* user);
390 void DeleteOper(userrec* user);
391 void kill_link(userrec *user,const char* r);
392 void kill_link_silent(userrec *user,const char* r);
393 void AddWhoWas(userrec* u);
394 void MaintainWhoWas(time_t TIME);
395 void AddClient(int socket, int port, bool iscached, in_addr ip4);
396 void FullConnectUser(userrec* user, CullList* Goners);
397 userrec* ReHashNick(char* Old, char* New);
398 void force_nickchange(userrec* user,const char* newnick);
399
400 /* Configuration callbacks */
401 bool InitTypes(const char* tag);
402 bool InitClasses(const char* tag);
403 bool DoType(const char* tag, char** entries, void** values, int* types);
404 bool DoClass(const char* tag, char** entries, void** values, int* types);
405 bool DoneClassesAndTypes(const char* tag);
406
407 #endif