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