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