1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 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 "inspstring.h"
20 #include "connection.h"
30 #include "cull_list.h"
34 #define STATUS_VOICE 1
35 #define STATUS_NORMAL 0
40 template<typename T> string ConvToStr(const T &in);
42 /** Holds a channel name to which a user has been invited.
44 class Invited : public classbase
51 /** Holds information relevent to <connect allow> and <connect deny> tags in the config file.
53 class ConnectClass : public classbase
56 /** Type of line, either CC_ALLOW or CC_DENY
59 /** Max time to register the connection in seconds
61 int registration_timeout;
62 /** Number of lines in buffer before excess flood is triggered
65 /** Host mask for this line
68 /** Number of seconds between pings for this line
71 /** (Optional) Password for this line
75 /** Threshold value for flood disconnect
79 /** Maximum size of sendq for users in this class (bytes)
83 /** Maximum size of recvq for users in this class (bytes)
87 /** Local max when connecting by this connection class
91 /** Global max when connecting by this connection class
95 ConnectClass() : registration_timeout(0), flood(0), host(""), pingtime(0), pass(""), threshold(0), sendqmax(0), recvqmax(0)
100 /** Holds a complete list of all channels to which a user has been invited and has not yet joined.
102 typedef std::vector<Invited> InvitedList;
106 /** Holds a complete list of all allow and deny tags from the configuration file (connection classes)
108 typedef std::vector<ConnectClass> ClassVector;
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
116 class userrec : public connection
120 /** A list of channels the user has a pending invite to.
125 /** The users nickname.
126 * An invalid nickname indicates an unregistered connection prior to the NICK command.
131 /** The users ident reply.
132 * Two characters are added to the user-defined limit to compensate for the tilde etc.
134 char ident[IDENTMAX+2];
136 /** The host displayed to non-opers (used for cloaking etc).
137 * This usually matches the value of userrec::host.
141 /** The users full name.
143 char fullname[MAXGECOS+1];
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.
154 /** This contains a bitmask of the RFC modes +swi,
155 * which can be used for fast lookup when iterating all the users.
156 * It is maintained by the mode parser and matches the character
157 * modes stored in 'modes'.
161 std::vector<ucrec*> chans;
163 /** The server the user is connected to.
167 /** The user's away message.
168 * If this string is empty, the user is not marked as away.
170 char awaymsg[MAXAWAY+1];
172 /** Number of lines the user can place into the buffer
173 * (up to the global NetBufferSize bytes) before they
174 * are disconnected for excess flood
178 /** Number of seconds this user is given to send USER/NICK
179 * If they do not send their details in this time limit they
180 * will be disconnected
182 unsigned int timeout;
184 /** The oper type they logged in as, if they are an oper.
185 * This is used to check permissions in operclasses, so that
186 * we can say 'yay' or 'nay' to any commands they issue.
187 * The value of this is the value of a valid 'type name=' tag.
191 /** True when DNS lookups are completed.
195 /** Number of seconds between PINGs for this user (set from <connect:allow> tag
197 unsigned int pingmax;
199 /** Password specified by the user when they registered.
200 * This is stored even if the <connect> block doesnt need a password, so that
201 * modules may check it.
205 /** User's receive queue.
206 * Lines from the IRCd awaiting processing are stored here.
207 * Upgraded april 2005, old system a bit hairy.
211 /** User's send queue.
212 * Lines waiting to be sent are stored here until their buffer is flushed.
226 /* Write error string
228 std::string WriteError;
230 /** Maximum size this user's sendq can become
234 /** Maximum size this user's recvq can become
240 /** Returns the full displayed host of the user
241 * This member function returns the hostname of the user as seen by other users
242 * on the server, in nick!ident&at;host form.
244 virtual char* GetFullHost();
246 /** Returns the full real host of the user
247 * This member function returns the hostname of the user as seen by other users
248 * on the server, in nick!ident&at;host form. If any form of hostname cloaking is in operation,
249 * e.g. through a module, then this method will ignore it and return the true hostname.
251 virtual char* GetFullRealHost();
253 /** Returns true if a user is invited to a channel.
255 virtual bool IsInvited(irc::string &channel);
257 /** Adds a channel to a users invite list (invites them to a channel)
259 virtual void InviteTo(irc::string &channel);
261 /** Removes a channel from a users invite list.
262 * This member function is called on successfully joining an invite only channel
263 * to which the user has previously been invited, to clear the invitation.
265 virtual void RemoveInvite(irc::string &channel);
267 /** Returns true or false for if a user can execute a privilaged oper command.
268 * This is done by looking up their oper type from userrec::oper, then referencing
269 * this to their oper classes and checking the commands they can execute.
271 bool HasPermission(const std::string &command);
273 /** Calls read() to read some data for this user using their fd.
275 int ReadData(void* buffer, size_t size);
277 /** This method adds data to the buffer of the user.
278 * The buffer can grow to any size within limits of the available memory,
279 * managed by the size of a std::string, however if any individual line in
280 * the buffer grows over 600 bytes in length (which is 88 chars over the
281 * RFC-specified limit per line) then the method will return false and the
282 * text will not be inserted.
284 bool AddBuffer(const std::string &a);
286 /** This method returns true if the buffer contains at least one carriage return
287 * character (e.g. one complete line may be read)
289 bool BufferIsReady();
291 /** This function clears the entire buffer by setting it to an empty string.
295 /** This method returns the first available string at the tail end of the buffer
296 * and advances the tail end of the buffer past the string. This means it is
297 * a one way operation in a similar way to strtok(), and multiple calls return
298 * multiple lines if they are available. The results of this function if there
299 * are no lines to be read are unknown, always use BufferIsReady() to check if
300 * it is ok to read the buffer before calling GetBuffer().
302 std::string GetBuffer();
304 /** Sets the write error for a connection. This is done because the actual disconnect
305 * of a client may occur at an inopportune time such as half way through /LIST output.
306 * The WriteErrors of clients are checked at a more ideal time (in the mainloop) and
307 * errored clients purged.
309 void SetWriteError(const std::string &error);
311 /** Returns the write error which last occured on this connection or an empty string
314 const char* GetWriteError();
316 /** Adds to the user's write buffer.
317 * You may add any amount of text up to this users sendq value, if you exceed the
318 * sendq value, SetWriteError() will be called to set the users error string to
319 * "SendQ exceeded", and further buffer adds will be dropped.
321 void AddWriteBuf(const std::string &data);
323 /** Flushes as much of the user's buffer to the file descriptor as possible.
324 * This function may not always flush the entire buffer, rather instead as much of it
325 * as it possibly can. If the send() call fails to send the entire buffer, the buffer
326 * position is advanced forwards and the rest of the data sent at the next call to
329 void FlushWriteBuf();
331 /** Returns the list of channels this user has been invited to but has not yet joined.
333 InvitedList* GetInviteList();
335 void MakeHost(char* nhost);
337 char* MakeWildHost();
339 /** Shuts down and closes the user's socket
360 WhoWasGroup(userrec* user);
364 typedef std::deque<WhoWasGroup*> whowas_set;
365 typedef std::map<irc::string,whowas_set*> whowas_users;
367 /** A lightweight userrec used by WHOWAS
370 void AddOper(userrec* user);
371 void DeleteOper(userrec* user);
372 void kill_link(userrec *user,const char* r);
373 void kill_link_silent(userrec *user,const char* r);
374 void AddWhoWas(userrec* u);
375 void MaintainWhoWas(time_t TIME);
376 void AddClient(int socket, int port, bool iscached, in_addr ip4);
377 void FullConnectUser(userrec* user, CullList* Goners);
378 userrec* ReHashNick(char* Old, char* New);
379 void force_nickchange(userrec* user,const char* newnick);
380 void ReadClassesAndTypes();