4 Revision 1.2 2003/01/26 23:52:59 brain
5 Modified documentation for base classes
8 Revision 1.1.1.1 2003/01/23 19:45:58 brain
9 InspIRCd second source tree
11 Revision 1.12 2003/01/22 20:59:10 brain
12 Added FileReader class documentation
14 Revision 1.11 2003/01/22 20:49:16 brain
15 Added FileReader file-caching class
16 Changed m_randquote to use FileReader class
18 Revision 1.10 2003/01/22 00:57:27 brain
19 Changes to documentation
21 Revision 1.9 2003/01/22 00:44:26 brain
22 Added documentation comments
24 Revision 1.8 2003/01/21 20:31:24 brain
25 Modified to add documentation
26 Added ConfigReader class for modules
28 Revision 1.7 2003/01/15 22:47:44 brain
29 Changed user and channel structs to classes (finally)
31 Revision 1.6 2003/01/13 22:30:50 brain
32 Added Admin class (holds /admin info for modules)
33 Added methods to Server class
47 /** Low level definition of a FileReader classes file cache area
49 typedef deque<string> file_cache;
52 // This #define allows us to call a method in all
53 // loaded modules in a readable simple way, e.g.:
54 // 'FOREACH_MOD OnConnect(user);'
56 #define FOREACH_MOD for (int i = 0; i <= MODCOUNT; i++) modules[i]->
58 // class Version holds the version information of a Module, returned
59 // by Module::GetVersion (thanks RD)
61 /** Holds a module's Version information
62 * The four members (set by the constructor only) indicate details as to the version number
63 * of a module. A class of type Version is returned by the GetVersion method of the Module class.
65 class Version : public classbase
68 const int Major, Minor, Revision, Build;
69 Version(int major, int minor, int revision, int build);
74 * This class contains the admin details of the local server. It is constructed by class Server,
75 * and has three read-only values, Name, Email and Nick that contain the specified values for the
76 * server where the module is running.
78 class Admin : public classbase
81 const string Name, Email, Nick;
82 Admin(string name,string email,string nick);
85 /** Base class for all InspIRCd modules
86 * This class is the base class for InspIRCd modules. All modules must inherit from this class,
87 * its methods will be called when irc server events occur. class inherited from module must be
88 * instantiated by the ModuleFactory class (see relevent section) for the plugin to be initialised.
90 class Module : public classbase
93 /** Default constructor
94 * creates a module class
97 /** Default destructor
98 * destroys a module class
101 /** Returns the version number of a Module.
102 * The method should return a Version object with its version information assigned via
105 virtual Version GetVersion();
106 /** Called when a user connects.
107 * The details of the connecting user are available to you in the parameter userrec *user
109 virtual void OnUserConnect(userrec* user);
110 /** Called when a user quits.
111 * The details of the exiting user are available to you in the parameter userrec *user
113 virtual void OnUserQuit(userrec* user);
114 /** Called when a user joins a channel.
115 * The details of the joining user are available to you in the parameter userrec *user,
116 * and the details of the channel they have joined is available in the variable chanrec *channel
118 virtual void OnUserJoin(userrec* user, chanrec* channel);
119 /** Called when a user parts a channel.
120 * The details of the leaving user are available to you in the parameter userrec *user,
121 * and the details of the channel they have left is available in the variable chanrec *channel
123 virtual void OnUserPart(userrec* user, chanrec* channel);
127 /** Allows server output and query functions
128 * This class contains methods which allow a module to query the state of the irc server, and produce
129 * output to users and other servers. All modules should instantiate at least one copy of this class,
130 * and use its member functions to perform their tasks.
132 class Server : public classbase
135 /** Default constructor.
136 * Creates a Server object.
139 /** Default destructor.
140 * Destroys a Server object.
144 /** Sends text to all opers.
145 * This method sends a server notice to all opers with the usermode +s.
147 virtual void SendOpers(string s);
148 /** Sends a debug string.
149 * This method writes a line of text to the debug log. If debugging is disabled
150 * in the configuration, this command has no effect.
152 virtual void Debug(string s);
153 /** Sends a line of text down a TCP/IP socket.
154 * This method writes a line of text to an established socket, cutting it to 510 characters
155 * plus a carriage return and linefeed if required.
157 virtual void Send(int Socket, string s);
158 /** Sends text from the server to a socket.
159 * This method writes a line of text to an established socket, with the servername prepended
160 * as used by numerics (see RFC 1459)
162 virtual void SendServ(int Socket, string s);
163 /** Sends text from a user to a socket.
164 * This method writes a line of text to an established socket, with the given user's nick/ident
165 * /host combination prepended, as used in PRIVSG etc commands (see RFC 1459)
167 virtual void SendFrom(int Socket, userrec* User, string s);
168 /** Sends text from a user to another user.
169 * This method writes a line of text to a user, with a user's nick/ident
170 * /host combination prepended, as used in PRIVMSG etc commands (see RFC 1459)
172 virtual void SendTo(userrec* Source, userrec* Dest, string s);
173 /** Sends text from a user to a channel (mulicast).
174 * This method writes a line of text to a channel, with the given user's nick/ident
175 * /host combination prepended, as used in PRIVMSG etc commands (see RFC 1459). If the
176 * IncludeSender flag is set, then the text is also sent back to the user from which
177 * it originated, as seen in MODE (see RFC 1459).
179 virtual void SendChannel(userrec* User, chanrec* Channel, string s,bool IncludeSender);
180 /** Returns true if two users share a common channel.
181 * This method is used internally by the NICK and QUIT commands, and the Server::SendCommon
184 virtual bool CommonChannels(userrec* u1, userrec* u2);
185 /** Sends text from a user to one or more channels (mulicast).
186 * This method writes a line of text to all users which share a common channel with a given
187 * user, with the user's nick/ident/host combination prepended, as used in PRIVMSG etc
188 * commands (see RFC 1459). If the IncludeSender flag is set, then the text is also sent
189 * back to the user from which it originated, as seen in NICK (see RFC 1459). Otherwise, it
190 * is only sent to the other recipients, as seen in QUIT.
192 virtual void SendCommon(userrec* User, string text,bool IncludeSender);
193 /** Sends a WALLOPS message.
194 * This method writes a WALLOPS message to all users with the +w flag, originating from the
197 virtual void SendWallops(userrec* User, string text);
199 /** Returns true if a nick is valid.
200 * Nicks for unregistered connections will return false.
202 virtual bool IsNick(string nick);
203 /** Attempts to look up a nick and return a pointer to it.
204 * This function will return NULL if the nick does not exist.
206 virtual userrec* FindNick(string nick);
207 /** Attempts to look up a channel and return a pointer to it.
208 * This function will return NULL if the channel does not exist.
210 virtual chanrec* FindChannel(string channel);
211 /** Attempts to look up a user's privilages on a channel.
212 * This function will return a string containing either @, %, +, or an empty string,
213 * representing the user's privilages upon the channel you specify.
215 virtual string ChanMode(userrec* User, chanrec* Chan);
216 /** Returns the server name of the server where the module is loaded.
218 virtual string GetServerName();
219 /** Returns the network name, global to all linked servers.
221 virtual string GetNetworkName();
222 /** Returns the information of the server as returned by the /ADMIN command.
223 * See the Admin class for further information of the return value. The members
224 * Admin::Nick, Admin::Email and Admin::Name contain the information for the
225 * server where the module is loaded.
227 virtual Admin GetAdmin();
231 /** Allows reading of values from configuration files
232 * This class allows a module to read from either the main configuration file (inspircd.conf) or from
233 * a module-specified configuration file. It may either be instantiated with one parameter or none.
234 * Constructing the class using one parameter allows you to specify a path to your own configuration
235 * file, otherwise, inspircd.conf is read.
237 class ConfigReader : public classbase
240 /** The filename of the configuration file, as set by the constructor.
244 /** Default constructor.
245 * This constructor initialises the ConfigReader class to read the inspircd.conf file
246 * as specified when running ./configure.
248 ConfigReader(); // default constructor reads ircd.conf
249 /** Overloaded constructor.
250 * This constructor initialises the ConfigReader class to read a user-specified config file
252 ConfigReader(string filename); // read a module-specific config
253 /** Default destructor.
254 * This method destroys the ConfigReader class.
257 /** Retrieves a value from the config file.
258 * This method retrieves a value from the config file. Where multiple copies of the tag
259 * exist in the config file, index indicates which of the values to retrieve.
261 string ReadValue(string tag, string name, int index);
262 /** Counts the number of times a given tag appears in the config file.
263 * This method counts the number of times a tag appears in a config file, for use where
264 * there are several tags of the same kind, e.g. with opers and connect types. It can be
265 * used with the index value of ConfigReader::ReadValue to loop through all copies of a
266 * multiple instance tag.
268 int Enumerate(string tag);
269 /** Returns true if a config file is valid.
270 * This method is unimplemented and will always return true.
277 /** Caches a text file into memory and can be used to retrieve lines from it.
278 * This class contains methods for read-only manipulation of a text file in memory.
279 * Either use the constructor type with one parameter to load a file into memory
280 * at construction, or use the LoadFile method to load a file.
282 class FileReader : public classbase
286 /** Default constructor.
287 * This method does not load any file into memory, you must use the LoadFile method
288 * after constructing the class this way.
291 /** Secondary constructor.
292 * This method initialises the class with a file loaded into it ready for GetLine and
293 * and other methods to be called. If the file could not be loaded, FileReader::FileSize
296 FileReader(string filename);
297 /** Default destructor.
298 * This deletes the memory allocated to the file.
301 /** Used to load a file.
302 * This method loads a file into the class ready for GetLine and
303 * and other methods to be called. If the file could not be loaded, FileReader::FileSize
306 void LoadFile(string filename);
307 /** Retrieve one line from the file.
308 * This method retrieves one line from the text file. If an empty non-NULL string is returned,
309 * the index was out of bounds, or the line had no data on it.
311 string GetLine(int x);
312 /** Returns the size of the file in lines.
313 * This method returns the number of lines in the read file. If it is 0, no lines have been
314 * read into memory, either because the file is empty or it does not exist, or cannot be
315 * opened due to permission problems.
321 /** Instantiates classes inherited from Module
322 * This class creates a class inherited from type Module, using new. This is to allow for modules
323 * to create many different variants of Module, dependent on architecture, configuration, etc.
324 * In most cases, the simple class shown in the example module m_foobar.so will suffice for most
327 class ModuleFactory : public classbase
331 virtual ~ModuleFactory() { }
332 /** Creates a new module.
333 * Your inherited class of ModuleFactory must return a pointer to your Module class
336 virtual Module * CreateModule() = 0;