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