1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
17 #include "inspircd_config.h"
19 #include "connection.h"
20 #include "inspstring.h"
28 #define STATUS_VOICE 1
29 #define STATUS_NORMAL 0
34 /** Holds a channel name to which a user has been invited.
36 class Invited : public classbase
39 char channel[CHANMAX];
43 /** Holds information relevent to <connect allow> and <connect deny> tags in the config file.
45 class ConnectClass : public classbase
48 /** Type of line, either CC_ALLOW or CC_DENY
51 /** Max time to register the connection in seconds
53 int registration_timeout;
54 /** Number of lines in buffer before excess flood is triggered
57 /** Host mask for this line
60 /** Number of seconds between pings for this line
63 /** (Optional) Password for this line
67 /** Threshold value for flood disconnect
71 /** Maximum size of sendq for users in this class (bytes)
75 /** Maximum size of recvq for users in this class (bytes)
81 registration_timeout = 0;
87 strlcpy(host,"",MAXBUF);
88 strlcpy(pass,"",MAXBUF);
92 /** Holds a complete list of all channels to which a user has been invited and has not yet joined.
94 typedef std::vector<Invited> InvitedList;
98 /** Holds a complete list of all allow and deny tags from the configuration file (connection classes)
100 typedef std::vector<ConnectClass> ClassVector;
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
108 class userrec : public connection
112 /** A list of channels the user has a pending invite to.
117 /** The users nickname.
118 * An invalid nickname indicates an unregistered connection prior to the NICK command.
123 /** The users ident reply.
125 char ident[MAXIDENT+1];
127 /** The host displayed to non-opers (used for cloaking etc).
128 * This usually matches the value of userrec::host.
132 /** The users full name.
134 char fullname[MAXGECOS+1];
136 /** The user's mode string.
137 * This may contain any of the following RFC characters: o, w, s, i
138 * Your module may define other mode characters as it sees fit.
142 ucrec chans[MAXCHANS];
144 /** The server the user is connected to.
148 /** The user's away message.
149 * If this string is empty, the user is not marked as away.
151 char awaymsg[MAXAWAY+1];
153 /** Number of lines the user can place into the buffer
154 * (up to the global NetBufferSize bytes) before they
155 * are disconnected for excess flood
159 /** Number of seconds this user is given to send USER/NICK
160 * If they do not send their details in this time limit they
161 * will be disconnected
163 unsigned int timeout;
165 /** The oper type they logged in as, if they are an oper.
166 * This is used to check permissions in operclasses, so that
167 * we can say 'yay' or 'nay' to any commands they issue.
168 * The value of this is the value of a valid 'type name=' tag.
172 /** True when DNS lookups are completed.
176 /** Number of seconds between PINGs for this user (set from <connect:allow> tag
178 unsigned int pingmax;
180 /** Password specified by the user when they registered.
181 * This is stored even if the <connect> block doesnt need a password, so that
182 * modules may check it.
184 char password[MAXBUF];
186 /** User's receive queue.
187 * Lines from the IRCd awaiting processing are stored here.
188 * Upgraded april 2005, old system a bit hairy.
192 /** User's send queue.
193 * Lines waiting to be sent are stored here until their buffer is flushed.
203 /* Write error string
205 std::string WriteError;
207 /** Maximum size this user's sendq can become
211 /** Maximum size this user's recvq can become
217 virtual ~userrec() { }
219 /** Returns the full displayed host of the user
220 * This member function returns the hostname of the user as seen by other users
221 * on the server, in nick!ident&at;host form.
223 virtual char* GetFullHost();
225 /** Returns the full real host of the user
226 * This member function returns the hostname of the user as seen by other users
227 * on the server, in nick!ident&at;host form. If any form of hostname cloaking is in operation,
228 * e.g. through a module, then this method will ignore it and return the true hostname.
230 virtual char* GetFullRealHost();
232 /** Returns true if a user is invited to a channel.
234 virtual bool IsInvited(char* channel);
236 /** Adds a channel to a users invite list (invites them to a channel)
238 virtual void InviteTo(char* channel);
240 /** Removes a channel from a users invite list.
241 * This member function is called on successfully joining an invite only channel
242 * to which the user has previously been invited, to clear the invitation.
244 virtual void RemoveInvite(char* channel);
246 /** Returns true or false for if a user can execute a privilaged oper command.
247 * This is done by looking up their oper type from userrec::oper, then referencing
248 * this to their oper classes and checking the commands they can execute.
250 bool HasPermission(char* command);
252 /** Calls read() to read some data for this user using their fd.
254 int ReadData(void* buffer, size_t size);
256 /** This method adds data to the buffer of the user.
257 * The buffer can grow to any size within limits of the available memory,
258 * managed by the size of a std::string, however if any individual line in
259 * the buffer grows over 600 bytes in length (which is 88 chars over the
260 * RFC-specified limit per line) then the method will return false and the
261 * text will not be inserted.
263 bool AddBuffer(std::string a);
265 /** This method returns true if the buffer contains at least one carriage return
266 * character (e.g. one complete line may be read)
268 bool BufferIsReady();
270 /** This function clears the entire buffer by setting it to an empty string.
274 /** This method returns the first available string at the tail end of the buffer
275 * and advances the tail end of the buffer past the string. This means it is
276 * a one way operation in a similar way to strtok(), and multiple calls return
277 * multiple lines if they are available. The results of this function if there
278 * are no lines to be read are unknown, always use BufferIsReady() to check if
279 * it is ok to read the buffer before calling GetBuffer().
281 std::string GetBuffer();
283 /** Sets the write error for a connection. This is done because the actual disconnect
284 * of a client may occur at an inopportune time such as half way through /LIST output.
285 * The WriteErrors of clients are checked at a more ideal time (in the mainloop) and
286 * errored clients purged.
288 void SetWriteError(std::string error);
290 /** Returns the write error which last occured on this connection or an empty string
293 std::string GetWriteError();
295 /** Adds to the user's write buffer.
296 * You may add any amount of text up to this users sendq value, if you exceed the
297 * sendq value, SetWriteError() will be called to set the users error string to
298 * "SendQ exceeded", and further buffer adds will be dropped.
300 void AddWriteBuf(std::string data);
302 /** Flushes as much of the user's buffer to the file descriptor as possible.
303 * This function may not always flush the entire buffer, rather instead as much of it
304 * as it possibly can. If the send() call fails to send the entire buffer, the buffer
305 * position is advanced forwards and the rest of the data sent at the next call to
308 void FlushWriteBuf();
310 /** Returns the list of channels this user has been invited to but has not yet joined.
312 InvitedList* GetInviteList();
314 /** Shuts down and closes the user's socket
319 /** A lightweight userrec used by WHOWAS