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 * ---------------------------------------------------
26 #include "inspircd_config.h"
29 #include "inspstring.h"
30 #include "connection.h"
32 #include "cull_list.h"
46 /** Holds a channel name to which a user has been invited.
48 class Invited : public classbase
55 /** Holds information relevent to <connect allow> and <connect deny> tags in the config file.
57 class ConnectClass : public classbase
60 /** Type of line, either CC_ALLOW or CC_DENY
63 /** Max time to register the connection in seconds
65 int registration_timeout;
66 /** Number of lines in buffer before excess flood is triggered
69 /** Host mask for this line
72 /** Number of seconds between pings for this line
75 /** (Optional) Password for this line
79 /** Threshold value for flood disconnect
83 /** Maximum size of sendq for users in this class (bytes)
87 /** Maximum size of recvq for users in this class (bytes)
91 /** Local max when connecting by this connection class
95 /** Global max when connecting by this connection class
99 ConnectClass() : registration_timeout(0), flood(0), host(""), pingtime(0), pass(""), threshold(0), sendqmax(0), recvqmax(0)
104 /** Holds a complete list of all channels to which a user has been invited and has not yet joined.
106 typedef std::vector<Invited> InvitedList;
110 /** Holds a complete list of all allow and deny tags from the configuration file (connection classes)
112 typedef std::vector<ConnectClass> ClassVector;
114 /** Typedef for the list of user-channel records for a user
116 typedef std::vector<ucrec*> UserChanList;
118 /** Holds all information about a user
119 * This class stores all information about a user connected to the irc server. Everything about a
120 * connection is stored here primarily, from the user's socket ID (file descriptor) through to the
121 * user's nickname and hostname. Use the Find method of the server class to locate a specific user
124 class userrec : public connection
128 /** A list of channels the user has a pending invite to.
133 /** The users nickname.
134 * An invalid nickname indicates an unregistered connection prior to the NICK command.
139 /** The users ident reply.
140 * Two characters are added to the user-defined limit to compensate for the tilde etc.
142 char ident[IDENTMAX+2];
144 /** The host displayed to non-opers (used for cloaking etc).
145 * This usually matches the value of userrec::host.
149 /** The users full name.
151 char fullname[MAXGECOS+1];
153 /** The user's mode string.
154 * This may contain any of the following RFC characters: o, w, s, i
155 * Your module may define other mode characters as it sees fit.
156 * it is limited to length 54, as there can only be a maximum of 52
157 * user modes (26 upper, 26 lower case) a null terminating char, and
158 * an optional + character.
162 /** This contains a bitmask of the RFC modes +swi,
163 * which can be used for fast lookup when iterating all the users.
164 * It is maintained by the mode parser and matches the character
165 * modes stored in 'modes'.
171 /** The server the user is connected to.
175 /** The user's away message.
176 * If this string is empty, the user is not marked as away.
178 char awaymsg[MAXAWAY+1];
180 /** Number of lines the user can place into the buffer
181 * (up to the global NetBufferSize bytes) before they
182 * are disconnected for excess flood
186 /** Number of seconds this user is given to send USER/NICK
187 * If they do not send their details in this time limit they
188 * will be disconnected
190 unsigned int timeout;
192 /** The oper type they logged in as, if they are an oper.
193 * This is used to check permissions in operclasses, so that
194 * we can say 'yay' or 'nay' to any commands they issue.
195 * The value of this is the value of a valid 'type name=' tag.
199 /** True when DNS lookups are completed.
203 /** Number of seconds between PINGs for this user (set from <connect:allow> tag
205 unsigned int pingmax;
207 /** Password specified by the user when they registered.
208 * This is stored even if the <connect> block doesnt need a password, so that
209 * modules may check it.
213 /** User's receive queue.
214 * Lines from the IRCd awaiting processing are stored here.
215 * Upgraded april 2005, old system a bit hairy.
219 /** User's send queue.
220 * Lines waiting to be sent are stored here until their buffer is flushed.
234 /* Write error string
236 std::string WriteError;
238 /** Maximum size this user's sendq can become
242 /** Maximum size this user's recvq can become
246 /** Default constructor
250 /** Returns the full displayed host of the user
251 * This member function returns the hostname of the user as seen by other users
252 * on the server, in nick!ident&at;host form.
254 virtual char* GetFullHost();
256 /** Returns the full real host of the user
257 * This member function returns the hostname of the user as seen by other users
258 * on the server, in nick!ident&at;host form. If any form of hostname cloaking is in operation,
259 * e.g. through a module, then this method will ignore it and return the true hostname.
261 virtual char* GetFullRealHost();
263 /** Returns true if a user is invited to a channel.
265 virtual bool IsInvited(irc::string &channel);
267 /** Adds a channel to a users invite list (invites them to a channel)
269 virtual void InviteTo(irc::string &channel);
271 /** Removes a channel from a users invite list.
272 * This member function is called on successfully joining an invite only channel
273 * to which the user has previously been invited, to clear the invitation.
275 virtual void RemoveInvite(irc::string &channel);
277 /** Returns true or false for if a user can execute a privilaged oper command.
278 * This is done by looking up their oper type from userrec::oper, then referencing
279 * this to their oper classes and checking the commands they can execute.
281 bool HasPermission(const std::string &command);
283 /** Calls read() to read some data for this user using their fd.
285 int ReadData(void* buffer, size_t size);
287 /** This method adds data to the buffer of the user.
288 * The buffer can grow to any size within limits of the available memory,
289 * managed by the size of a std::string, however if any individual line in
290 * the buffer grows over 600 bytes in length (which is 88 chars over the
291 * RFC-specified limit per line) then the method will return false and the
292 * text will not be inserted.
294 bool AddBuffer(const std::string &a);
296 /** This method returns true if the buffer contains at least one carriage return
297 * character (e.g. one complete line may be read)
299 bool BufferIsReady();
301 /** This function clears the entire buffer by setting it to an empty string.
305 /** This method returns the first available string at the tail end of the buffer
306 * and advances the tail end of the buffer past the string. This means it is
307 * a one way operation in a similar way to strtok(), and multiple calls return
308 * multiple lines if they are available. The results of this function if there
309 * are no lines to be read are unknown, always use BufferIsReady() to check if
310 * it is ok to read the buffer before calling GetBuffer().
312 std::string GetBuffer();
314 /** Sets the write error for a connection. This is done because the actual disconnect
315 * of a client may occur at an inopportune time such as half way through /LIST output.
316 * The WriteErrors of clients are checked at a more ideal time (in the mainloop) and
317 * errored clients purged.
319 void SetWriteError(const std::string &error);
321 /** Returns the write error which last occured on this connection or an empty string
324 const char* GetWriteError();
326 /** Adds to the user's write buffer.
327 * You may add any amount of text up to this users sendq value, if you exceed the
328 * sendq value, SetWriteError() will be called to set the users error string to
329 * "SendQ exceeded", and further buffer adds will be dropped.
331 void AddWriteBuf(const std::string &data);
333 /** Flushes as much of the user's buffer to the file descriptor as possible.
334 * This function may not always flush the entire buffer, rather instead as much of it
335 * as it possibly can. If the send() call fails to send the entire buffer, the buffer
336 * position is advanced forwards and the rest of the data sent at the next call to
339 void FlushWriteBuf();
341 /** Returns the list of channels this user has been invited to but has not yet joined.
343 InvitedList* GetInviteList();
345 /** Creates a wildcard host.
346 * Takes a buffer to use and fills the given buffer with the host in the format *!*@hostname
348 char* MakeWildHost();
351 * Takes a buffer to use and fills the given buffer with the host in the format nick!user@host
353 void MakeHost(char* nhost);
355 /** Shuts down and closes the user's socket
359 /** Default destructor
364 /** Thread used for threaded lookups
370 /** Used to hold WHOWAS information
382 WhoWasGroup(userrec* user);
386 typedef std::deque<WhoWasGroup*> whowas_set;
387 typedef std::map<irc::string,whowas_set*> whowas_users;
389 void AddOper(userrec* user);
390 void DeleteOper(userrec* user);
391 void kill_link(userrec *user,const char* r);
392 void kill_link_silent(userrec *user,const char* r);
393 void AddWhoWas(userrec* u);
394 void MaintainWhoWas(time_t TIME);
395 void AddClient(int socket, int port, bool iscached, in_addr ip4);
396 void FullConnectUser(userrec* user, CullList* Goners);
397 userrec* ReHashNick(char* Old, char* New);
398 void force_nickchange(userrec* user,const char* newnick);
400 /* Configuration callbacks */
401 bool InitTypes(const char* tag);
402 bool InitClasses(const char* tag);
403 bool DoType(const char* tag, char** entries, void** values, int* types);
404 bool DoClass(const char* tag, char** entries, void** values, int* types);
405 bool DoneClassesAndTypes(const char* tag);
407 long FindMatchingGlobal(userrec* user);
408 long FindMatchingLocal(userrec* user);