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