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