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