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