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 /** RFC1459 channel modes
49 UM_SERVERNOTICE = 's'-65,
51 UM_INVISIBLE = 'i'-65,
55 /** Holds a channel name to which a user has been invited.
57 class Invited : public classbase
64 /** Holds information relevent to <connect allow> and <connect deny> tags in the config file.
66 class ConnectClass : public classbase
69 /** Type of line, either CC_ALLOW or CC_DENY
72 /** Max time to register the connection in seconds
74 int registration_timeout;
75 /** Number of lines in buffer before excess flood is triggered
78 /** Host mask for this line
81 /** Number of seconds between pings for this line
84 /** (Optional) Password for this line
88 /** Threshold value for flood disconnect
92 /** Maximum size of sendq for users in this class (bytes)
96 /** Maximum size of recvq for users in this class (bytes)
100 /** Local max when connecting by this connection class
104 /** Global max when connecting by this connection class
108 ConnectClass() : registration_timeout(0), flood(0), host(""), pingtime(0), pass(""), threshold(0), sendqmax(0), recvqmax(0)
113 /** Holds a complete list of all channels to which a user has been invited and has not yet joined.
115 typedef std::vector<Invited> InvitedList;
119 /** Holds a complete list of all allow and deny tags from the configuration file (connection classes)
121 typedef std::vector<ConnectClass> ClassVector;
123 /** Typedef for the list of user-channel records for a user
125 typedef std::vector<ucrec*> UserChanList;
127 /** Holds all information about a user
128 * This class stores all information about a user connected to the irc server. Everything about a
129 * connection is stored here primarily, from the user's socket ID (file descriptor) through to the
130 * user's nickname and hostname. Use the Find method of the server class to locate a specific user
133 class userrec : public connection
137 /** A list of channels the user has a pending invite to.
142 /** The users nickname.
143 * An invalid nickname indicates an unregistered connection prior to the NICK command.
148 /** The users ident reply.
149 * Two characters are added to the user-defined limit to compensate for the tilde etc.
151 char ident[IDENTMAX+2];
153 /** The host displayed to non-opers (used for cloaking etc).
154 * This usually matches the value of userrec::host.
158 /** The users full name.
160 char fullname[MAXGECOS+1];
162 /** The user's mode list.
163 * This is NOT a null terminated string! In the 1.1 version of InspIRCd
164 * this is an array of values in a similar way to channel modes.
165 * A value of 1 in field (modeletter-65) indicates that the mode is
166 * set, for example, to work out if mode +s is set, we check the field
167 * userrec::modes['s'-65] != 0.
168 * The following RFC characters o, w, s, i have constants defined via an
169 * enum, such as UM_SERVERNOTICE and UM_OPETATOR.
175 /** The server the user is connected to.
179 /** The user's away message.
180 * If this string is empty, the user is not marked as away.
182 char awaymsg[MAXAWAY+1];
184 /** Number of lines the user can place into the buffer
185 * (up to the global NetBufferSize bytes) before they
186 * are disconnected for excess flood
190 /** Number of seconds this user is given to send USER/NICK
191 * If they do not send their details in this time limit they
192 * will be disconnected
194 unsigned int timeout;
196 /** The oper type they logged in as, if they are an oper.
197 * This is used to check permissions in operclasses, so that
198 * we can say 'yay' or 'nay' to any commands they issue.
199 * The value of this is the value of a valid 'type name=' tag.
203 /** True when DNS lookups are completed.
207 /** Number of seconds between PINGs for this user (set from <connect:allow> tag
209 unsigned int pingmax;
211 /** Password specified by the user when they registered.
212 * This is stored even if the <connect> block doesnt need a password, so that
213 * modules may check it.
217 /** User's receive queue.
218 * Lines from the IRCd awaiting processing are stored here.
219 * Upgraded april 2005, old system a bit hairy.
223 /** User's send queue.
224 * Lines waiting to be sent are stored here until their buffer is flushed.
238 /* Write error string
240 std::string WriteError;
242 /** Maximum size this user's sendq can become
246 /** Maximum size this user's recvq can become
250 /** Default constructor
254 /** Returns the full displayed host of the user
255 * This member function returns the hostname of the user as seen by other users
256 * on the server, in nick!ident&at;host form.
258 virtual char* GetFullHost();
260 /** Returns the full real host of the user
261 * This member function returns the hostname of the user as seen by other users
262 * on the server, in nick!ident&at;host form. If any form of hostname cloaking is in operation,
263 * e.g. through a module, then this method will ignore it and return the true hostname.
265 virtual char* GetFullRealHost();
268 * Create a displayable mode string for this users umodes
270 const char* FormatModes();
272 bool IsModeSet(unsigned char m);
274 void SetMode(unsigned char m, bool value);
276 /** Returns true if a user is invited to a channel.
278 virtual bool IsInvited(irc::string &channel);
280 /** Adds a channel to a users invite list (invites them to a channel)
282 virtual void InviteTo(irc::string &channel);
284 /** Removes a channel from a users invite list.
285 * This member function is called on successfully joining an invite only channel
286 * to which the user has previously been invited, to clear the invitation.
288 virtual void RemoveInvite(irc::string &channel);
290 /** Returns true or false for if a user can execute a privilaged oper command.
291 * This is done by looking up their oper type from userrec::oper, then referencing
292 * this to their oper classes and checking the commands they can execute.
294 bool HasPermission(const std::string &command);
296 /** Calls read() to read some data for this user using their fd.
298 int ReadData(void* buffer, size_t size);
300 /** This method adds data to the buffer of the user.
301 * The buffer can grow to any size within limits of the available memory,
302 * managed by the size of a std::string, however if any individual line in
303 * the buffer grows over 600 bytes in length (which is 88 chars over the
304 * RFC-specified limit per line) then the method will return false and the
305 * text will not be inserted.
307 bool AddBuffer(const std::string &a);
309 /** This method returns true if the buffer contains at least one carriage return
310 * character (e.g. one complete line may be read)
312 bool BufferIsReady();
314 /** This function clears the entire buffer by setting it to an empty string.
318 /** This method returns the first available string at the tail end of the buffer
319 * and advances the tail end of the buffer past the string. This means it is
320 * a one way operation in a similar way to strtok(), and multiple calls return
321 * multiple lines if they are available. The results of this function if there
322 * are no lines to be read are unknown, always use BufferIsReady() to check if
323 * it is ok to read the buffer before calling GetBuffer().
325 std::string GetBuffer();
327 /** Sets the write error for a connection. This is done because the actual disconnect
328 * of a client may occur at an inopportune time such as half way through /LIST output.
329 * The WriteErrors of clients are checked at a more ideal time (in the mainloop) and
330 * errored clients purged.
332 void SetWriteError(const std::string &error);
334 /** Returns the write error which last occured on this connection or an empty string
337 const char* GetWriteError();
339 /** Adds to the user's write buffer.
340 * You may add any amount of text up to this users sendq value, if you exceed the
341 * sendq value, SetWriteError() will be called to set the users error string to
342 * "SendQ exceeded", and further buffer adds will be dropped.
344 void AddWriteBuf(const std::string &data);
346 /** Flushes as much of the user's buffer to the file descriptor as possible.
347 * This function may not always flush the entire buffer, rather instead as much of it
348 * as it possibly can. If the send() call fails to send the entire buffer, the buffer
349 * position is advanced forwards and the rest of the data sent at the next call to
352 void FlushWriteBuf();
354 /** Returns the list of channels this user has been invited to but has not yet joined.
356 InvitedList* GetInviteList();
358 /** Creates a wildcard host.
359 * Takes a buffer to use and fills the given buffer with the host in the format *!*@hostname
361 char* MakeWildHost();
364 * Takes a buffer to use and fills the given buffer with the host in the format nick!user@host
366 void MakeHost(char* nhost);
368 /** Shuts down and closes the user's socket
372 /** Default destructor
377 /** Thread used for threaded lookups
383 /** Used to hold WHOWAS information
395 WhoWasGroup(userrec* user);
399 typedef std::deque<WhoWasGroup*> whowas_set;
400 typedef std::map<irc::string,whowas_set*> whowas_users;
402 void AddOper(userrec* user);
403 void DeleteOper(userrec* user);
404 void kill_link(userrec *user,const char* r);
405 void kill_link_silent(userrec *user,const char* r);
406 void AddWhoWas(userrec* u);
407 void MaintainWhoWas(time_t TIME);
408 void AddClient(int socket, int port, bool iscached, in_addr ip4);
409 void FullConnectUser(userrec* user, CullList* Goners);
410 userrec* ReHashNick(char* Old, char* New);
411 void force_nickchange(userrec* user,const char* newnick);
413 /* Configuration callbacks */
414 bool InitTypes(const char* tag);
415 bool InitClasses(const char* tag);
416 bool DoType(const char* tag, char** entries, void** values, int* types);
417 bool DoClass(const char* tag, char** entries, void** values, int* types);
418 bool DoneClassesAndTypes(const char* tag);
420 long FindMatchingGlobal(userrec* user);
421 long FindMatchingLocal(userrec* user);