]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/users.h
Added basic sendq stuff - WARNING, there is no configuration yet, this CVS allows...
[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 "connection.h"
20 #include "inspstring.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         int 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         long threshold;
70         
71         ConnectClass()
72         {
73                 registration_timeout = 0;
74                 flood = 0;
75                 pingtime = 0;
76                 threshold = 0;
77                 strlcpy(host,"",MAXBUF);
78                 strlcpy(pass,"",MAXBUF);
79         }
80 };
81
82 /** Holds a complete list of all channels to which a user has been invited and has not yet joined.
83  */
84 typedef std::vector<Invited> InvitedList;
85
86
87
88 /** Holds a complete list of all allow and deny tags from the configuration file (connection classes)
89  */
90 typedef std::vector<ConnectClass> ClassVector;
91
92 /** Holds all information about a user
93  * This class stores all information about a user connected to the irc server. Everything about a
94  * connection is stored here primarily, from the user's socket ID (file descriptor) through to the
95  * user's nickname and hostname. Use the Find method of the server class to locate a specific user
96  * by nickname.
97  */
98 class userrec : public connection
99 {
100  private:
101
102         /** A list of channels the user has a pending invite to.
103          */
104         InvitedList invites;
105  public:
106         
107         /** The users nickname.
108          * An invalid nickname indicates an unregistered connection prior to the NICK command.
109          */
110         
111         char nick[NICKMAX];
112         
113         /** The users ident reply.
114          */
115         char ident[64];
116
117         /** The host displayed to non-opers (used for cloaking etc).
118          * This usually matches the value of userrec::host.
119          */
120         char dhost[256];
121         
122         /** The users full name.
123          */
124         char fullname[128];
125         
126         /** The user's mode string.
127          * This may contain any of the following RFC characters: o, w, s, i
128          * Your module may define other mode characters as it sees fit.
129          */
130         char modes[MAXBUF];
131         
132         ucrec chans[MAXCHANS];
133         
134         /** The server the user is connected to.
135          */
136         char server[256];
137         
138         /** The user's away message.
139          * If this string is empty, the user is not marked as away.
140          */
141         char awaymsg[512];
142         
143         /** Stores the result of the last GetFullHost or GetRealHost call.
144          * You may use this to increase the speed of use of this class.
145          */
146         char result[256];
147         
148         /** Number of lines the user can place into the buffer
149          * (up to the global NetBufferSize bytes) before they
150          * are disconnected for excess flood
151          */
152         int flood;
153         
154         /** Number of seconds this user is given to send USER/NICK
155          * If they do not send their details in this time limit they
156          * will be disconnected
157          */
158         unsigned long timeout;
159         
160         /** The oper type they logged in as, if they are an oper.
161          * This is used to check permissions in operclasses, so that
162          * we can say 'yay' or 'nay' to any commands they issue.
163          * The value of this is the value of a valid 'type name=' tag.
164          */
165         char oper[NICKMAX];
166
167         /** True when DNS lookups are completed.
168          */
169         bool dns_done;
170
171         /** Number of seconds between PINGs for this user (set from &lt;connect:allow&gt; tag
172          */
173         unsigned long pingmax;
174
175         /** Password specified by the user when they registered.
176          * This is stored even if the <connect> block doesnt need a password, so that
177          * modules may check it.
178          */
179         char password[MAXBUF];
180
181         /** User's receive queue.
182          * Lines from the IRCd awaiting processing are stored here.
183          * Upgraded april 2005, old system a bit hairy.
184          */
185         std::string recvq;
186
187         /** User's send queue.
188          * Lines waiting to be sent are stored here until their buffer is flushed.
189          */
190         std::string sendq;
191
192         /** Flood counters
193          */
194         long lines_in;
195         time_t reset_due;
196         long threshold;
197
198         /* Write error string
199          */
200         std::string WriteError;
201
202         userrec();
203         
204         virtual ~userrec() {  }
205         
206         /** Returns the full displayed host of the user
207          * This member function returns the hostname of the user as seen by other users
208          * on the server, in nick!ident&at;host form.
209          */
210         virtual char* GetFullHost();
211         
212         /** Returns the full real host of the user
213          * This member function returns the hostname of the user as seen by other users
214          * on the server, in nick!ident&at;host form. If any form of hostname cloaking is in operation,
215          * e.g. through a module, then this method will ignore it and return the true hostname.
216          */
217         virtual char* GetFullRealHost();
218         
219         /** Returns true if a user is invited to a channel.
220          */
221         virtual bool IsInvited(char* channel);
222         
223         /** Adds a channel to a users invite list (invites them to a channel)
224          */
225         virtual void InviteTo(char* channel);
226         
227         /** Removes a channel from a users invite list.
228          * This member function is called on successfully joining an invite only channel
229          * to which the user has previously been invited, to clear the invitation.
230          */
231         virtual void RemoveInvite(char* channel);
232         
233         /** Returns true or false for if a user can execute a privilaged oper command.
234          * This is done by looking up their oper type from userrec::oper, then referencing
235          * this to their oper classes and checking the commands they can execute.
236          */
237         bool HasPermission(char* command);
238
239         /** This method adds data to the buffer of the user.
240          * The buffer can grow to any size within limits of the available memory,
241          * managed by the size of a std::string, however if any individual line in
242          * the buffer grows over 600 bytes in length (which is 88 chars over the
243          * RFC-specified limit per line) then the method will return false and the
244          * text will not be inserted.
245          */
246         bool AddBuffer(std::string a);
247
248         /** This method returns true if the buffer contains at least one carriage return
249          * character (e.g. one complete line may be read)
250          */
251         bool BufferIsReady();
252
253         /** This function clears the entire buffer by setting it to an empty string.
254          */
255         void ClearBuffer();
256
257         /** This method returns the first available string at the tail end of the buffer
258          * and advances the tail end of the buffer past the string. This means it is
259          * a one way operation in a similar way to strtok(), and multiple calls return
260          * multiple lines if they are available. The results of this function if there
261          * are no lines to be read are unknown, always use BufferIsReady() to check if
262          * it is ok to read the buffer before calling GetBuffer().
263          */
264         std::string GetBuffer();
265
266         /** Sets the write error for a connection. This is done because the actual disconnect
267          * of a client may occur at an inopportune time such as half way through /LIST output.
268          * The WriteErrors of clients are checked at a more ideal time (in the mainloop) and
269          * errored clients purged.
270          */
271         void SetWriteError(std::string error);
272
273         /** Returns the write error which last occured on this connection or an empty string
274          * if none occured.
275          */
276         std::string GetWriteError();
277
278         void AddWriteBuf(std::string data);
279         void FlushWriteBuf();
280
281 };
282
283
284 #endif