22 /** Low level definition of a FileReader classes file cache area
24 typedef deque<string> file_cache;
27 // This #define allows us to call a method in all
28 // loaded modules in a readable simple way, e.g.:
29 // 'FOREACH_MOD OnConnect(user);'
31 #define FOREACH_MOD for (int i = 0; i <= MODCOUNT; i++) modules[i]->
33 // class Version holds the version information of a Module, returned
34 // by Module::GetVersion (thanks RD)
36 /** Holds a module's Version information
37 * The four members (set by the constructor only) indicate details as to the version number
38 * of a module. A class of type Version is returned by the GetVersion method of the Module class.
40 class Version : public classbase
43 const int Major, Minor, Revision, Build;
44 Version(int major, int minor, int revision, int build);
49 * This class contains the admin details of the local server. It is constructed by class Server,
50 * and has three read-only values, Name, Email and Nick that contain the specified values for the
51 * server where the module is running.
53 class Admin : public classbase
56 const string Name, Email, Nick;
57 Admin(string name,string email,string nick);
60 /** Base class for all InspIRCd modules
61 * This class is the base class for InspIRCd modules. All modules must inherit from this class,
62 * its methods will be called when irc server events occur. class inherited from module must be
63 * instantiated by the ModuleFactory class (see relevent section) for the plugin to be initialised.
65 class Module : public classbase
68 /** Default constructor
69 * creates a module class
72 /** Default destructor
73 * destroys a module class
76 /** Returns the version number of a Module.
77 * The method should return a Version object with its version information assigned via
80 virtual Version GetVersion();
81 /** Called when a user connects.
82 * The details of the connecting user are available to you in the parameter userrec *user
84 virtual void OnUserConnect(userrec* user);
85 /** Called when a user quits.
86 * The details of the exiting user are available to you in the parameter userrec *user
88 virtual void OnUserQuit(userrec* user);
89 /** Called when a user joins a channel.
90 * The details of the joining user are available to you in the parameter userrec *user,
91 * and the details of the channel they have joined is available in the variable chanrec *channel
93 virtual void OnUserJoin(userrec* user, chanrec* channel);
94 /** Called when a user parts a channel.
95 * The details of the leaving user are available to you in the parameter userrec *user,
96 * and the details of the channel they have left is available in the variable chanrec *channel
98 virtual void OnUserPart(userrec* user, chanrec* channel);
101 virtual void Module::OnPacketTransmit(char *p);
102 virtual void Module::OnPacketReceive(char *p);
103 virtual void OnRehash();
108 /** Allows server output and query functions
109 * This class contains methods which allow a module to query the state of the irc server, and produce
110 * output to users and other servers. All modules should instantiate at least one copy of this class,
111 * and use its member functions to perform their tasks.
113 class Server : public classbase
116 /** Default constructor.
117 * Creates a Server object.
120 /** Default destructor.
121 * Destroys a Server object.
125 /** Sends text to all opers.
126 * This method sends a server notice to all opers with the usermode +s.
128 virtual void SendOpers(string s);
129 /** Writes a log string.
130 * This method writes a line of text to the log. If the level given is lower than the
131 * level given in the configuration, this command has no effect.
133 virtual void Log(int level, string s);
134 /** Sends a line of text down a TCP/IP socket.
135 * This method writes a line of text to an established socket, cutting it to 510 characters
136 * plus a carriage return and linefeed if required.
138 virtual void Send(int Socket, string s);
139 /** Sends text from the server to a socket.
140 * This method writes a line of text to an established socket, with the servername prepended
141 * as used by numerics (see RFC 1459)
143 virtual void SendServ(int Socket, string s);
144 /** Sends text from a user to a socket.
145 * This method writes a line of text to an established socket, with the given user's nick/ident
146 * /host combination prepended, as used in PRIVSG etc commands (see RFC 1459)
148 virtual void SendFrom(int Socket, userrec* User, string s);
149 /** Sends text from a user to another user.
150 * This method writes a line of text to a user, with a user's nick/ident
151 * /host combination prepended, as used in PRIVMSG etc commands (see RFC 1459)
153 virtual void SendTo(userrec* Source, userrec* Dest, string s);
154 /** Sends text from a user to a channel (mulicast).
155 * This method writes a line of text to a channel, with the given user's nick/ident
156 * /host combination prepended, as used in PRIVMSG etc commands (see RFC 1459). If the
157 * IncludeSender flag is set, then the text is also sent back to the user from which
158 * it originated, as seen in MODE (see RFC 1459).
160 virtual void SendChannel(userrec* User, chanrec* Channel, string s,bool IncludeSender);
161 /** Returns true if two users share a common channel.
162 * This method is used internally by the NICK and QUIT commands, and the Server::SendCommon
165 virtual bool CommonChannels(userrec* u1, userrec* u2);
166 /** Sends text from a user to one or more channels (mulicast).
167 * This method writes a line of text to all users which share a common channel with a given
168 * user, with the user's nick/ident/host combination prepended, as used in PRIVMSG etc
169 * commands (see RFC 1459). If the IncludeSender flag is set, then the text is also sent
170 * back to the user from which it originated, as seen in NICK (see RFC 1459). Otherwise, it
171 * is only sent to the other recipients, as seen in QUIT.
173 virtual void SendCommon(userrec* User, string text,bool IncludeSender);
174 /** Sends a WALLOPS message.
175 * This method writes a WALLOPS message to all users with the +w flag, originating from the
178 virtual void SendWallops(userrec* User, string text);
180 /** Returns true if a nick is valid.
181 * Nicks for unregistered connections will return false.
183 virtual bool IsNick(string nick);
184 /** Attempts to look up a nick and return a pointer to it.
185 * This function will return NULL if the nick does not exist.
187 virtual userrec* FindNick(string nick);
188 /** Attempts to look up a channel and return a pointer to it.
189 * This function will return NULL if the channel does not exist.
191 virtual chanrec* FindChannel(string channel);
192 /** Attempts to look up a user's privilages on a channel.
193 * This function will return a string containing either @, %, +, or an empty string,
194 * representing the user's privilages upon the channel you specify.
196 virtual string ChanMode(userrec* User, chanrec* Chan);
197 /** Returns the server name of the server where the module is loaded.
199 virtual string GetServerName();
200 /** Returns the network name, global to all linked servers.
202 virtual string GetNetworkName();
203 /** Returns the information of the server as returned by the /ADMIN command.
204 * See the Admin class for further information of the return value. The members
205 * Admin::Nick, Admin::Email and Admin::Name contain the information for the
206 * server where the module is loaded.
208 virtual Admin GetAdmin();
212 /** Allows reading of values from configuration files
213 * This class allows a module to read from either the main configuration file (inspircd.conf) or from
214 * a module-specified configuration file. It may either be instantiated with one parameter or none.
215 * Constructing the class using one parameter allows you to specify a path to your own configuration
216 * file, otherwise, inspircd.conf is read.
218 class ConfigReader : public classbase
221 /** The filename of the configuration file, as set by the constructor.
225 /** Default constructor.
226 * This constructor initialises the ConfigReader class to read the inspircd.conf file
227 * as specified when running ./configure.
229 ConfigReader(); // default constructor reads ircd.conf
230 /** Overloaded constructor.
231 * This constructor initialises the ConfigReader class to read a user-specified config file
233 ConfigReader(string filename); // read a module-specific config
234 /** Default destructor.
235 * This method destroys the ConfigReader class.
238 /** Retrieves a value from the config file.
239 * This method retrieves a value from the config file. Where multiple copies of the tag
240 * exist in the config file, index indicates which of the values to retrieve.
242 string ReadValue(string tag, string name, int index);
243 /** Counts the number of times a given tag appears in the config file.
244 * This method counts the number of times a tag appears in a config file, for use where
245 * there are several tags of the same kind, e.g. with opers and connect types. It can be
246 * used with the index value of ConfigReader::ReadValue to loop through all copies of a
247 * multiple instance tag.
249 int Enumerate(string tag);
250 /** Returns true if a config file is valid.
251 * This method is unimplemented and will always return true.
258 /** Caches a text file into memory and can be used to retrieve lines from it.
259 * This class contains methods for read-only manipulation of a text file in memory.
260 * Either use the constructor type with one parameter to load a file into memory
261 * at construction, or use the LoadFile method to load a file.
263 class FileReader : public classbase
267 /** Default constructor.
268 * This method does not load any file into memory, you must use the LoadFile method
269 * after constructing the class this way.
272 /** Secondary constructor.
273 * This method initialises the class with a file loaded into it ready for GetLine and
274 * and other methods to be called. If the file could not be loaded, FileReader::FileSize
277 FileReader(string filename);
278 /** Default destructor.
279 * This deletes the memory allocated to the file.
282 /** Used to load a file.
283 * This method loads a file into the class ready for GetLine and
284 * and other methods to be called. If the file could not be loaded, FileReader::FileSize
287 void LoadFile(string filename);
288 /** Retrieve one line from the file.
289 * This method retrieves one line from the text file. If an empty non-NULL string is returned,
290 * the index was out of bounds, or the line had no data on it.
292 string GetLine(int x);
293 /** Returns the size of the file in lines.
294 * This method returns the number of lines in the read file. If it is 0, no lines have been
295 * read into memory, either because the file is empty or it does not exist, or cannot be
296 * opened due to permission problems.
302 /** Instantiates classes inherited from Module
303 * This class creates a class inherited from type Module, using new. This is to allow for modules
304 * to create many different variants of Module, dependent on architecture, configuration, etc.
305 * In most cases, the simple class shown in the example module m_foobar.so will suffice for most
308 class ModuleFactory : public classbase
312 virtual ~ModuleFactory() { }
313 /** Creates a new module.
314 * Your inherited class of ModuleFactory must return a pointer to your Module class
317 virtual Module * CreateModule() = 0;
321 typedef DLLFactory<ModuleFactory> ircd_module;