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