1Eggdrop Module Information
2Last revised: Jul 25, 2016
3
4==========================
5Eggdrop Module Information
6==========================
7
8The purpose of this document is to show you how to download, install, create,
9and submit modules.
10
11-----------------
12What are modules?
13-----------------
14
15Modules are portions of code which are loaded separately to the bot itself
16and provide extra services. For example, the filesys module provides the
17entire file system.
18
19----------------
20Why use modules?
21----------------
22
23Modules allow C coders to add their own enhancements to the bot while
24keeping them optional and without increasing the size of the Eggdrop core.
25
26-----------------------
27How to install a module
28-----------------------
29
30Please note that these are only basic instructions for compiling and
31installing a module. Please read any and all directions included with
32the module you wish to install.
33
34  1. Download and un-tar the Eggdrop source code.
35
36  2. Place the new module in its own directory (in the format of
37     (modulename).mod) in src/mod.
38
39  3. Run ./configure (from eggdrop1.8.x/).
40
41  4. Type 'make config' or 'make iconfig'.
42
43  5. Type 'make'.
44
45  6. Copy the compiled module file (modulename.so) into your bot's
46     modules folder.
47
48  7. Add 'loadmodule modulename' to your eggdrop.conf file (do not
49     add the .so suffix).
50
51  8. Rehash or restart your bot.
52
53To view your currently loaded modules, type '.module'.
54
55-----------------------------
56Modules included with Eggdrop
57-----------------------------
58
59  :ref:`assoc`
60    This module provides assoc support, i.e. naming channels on the
61    botnet.
62
63  :ref:`blowfish`
64    Eggdrop can encrypt your userfile, so users can have secure
65    passwords. Please note that when you change your encryption
66    method later (i.e. using other modules like a md5 module),
67    you can't use your current userfile anymore. Eggdrop will not
68    start without an encryption module.
69
70  :ref:`channels`
71    This module provides channel related support for the bot.
72    Without it, you won't be able to make the bot join a channel
73    or save channel specific userfile information.
74
75  :ref:`compress`
76    This module provides support for file compression. This
77    allows the bot to transfer compressed user files and, therefore,
78    save a significant amount of bandwidth.
79
80  :ref:`console`
81    This module provides storage of console settings when you exit
82    the bot or type .store on the partyline.
83
84  :ref:`ctcp`
85    This module provides the normal ctcp replies that you'd expect.
86    Without it loaded, CTCP CHAT will not work.
87
88  :ref:`dns`
89    This module provides asynchronous dns support. This will avoid
90    long periods where the bot just hangs there, waiting for a
91    hostname to resolve, which will often let it timeout on all
92    other connections.
93
94  :ref:`filesys`
95    This module provides an area within the bot where users can store
96    and manage files. With this module, the bot is usable as a file
97    server.
98
99  :ref:`irc`
100    This module provides basic IRC support for your bot. You have to
101    load this if you want your bot to come on IRC.
102
103  :ref:`notes`
104    This module provides support for storing of notes for users from
105    each other. Note sending between currently online users is
106    supported in the core, this is only for storing the notes for
107    later retrieval.
108
109  :ref:`seen`
110    This module provides very basic seen commands via msg, on channel
111    or via dcc. This module works only for users in the bot's
112    userlist. If you are looking for a better and more advanced seen
113    module, try the gseen module by G'Quann. You can find it at
114    http://www.kreativrauschen.com/gseen.mod/.
115
116  :ref:`server`
117    This module provides the core server support. You have to load
118    this if you want your bot to come on IRC. Not loading this is
119    equivalent to the old NO_IRC define.
120
121  :ref:`share`
122    This module provides userfile sharing support between two
123    directly linked bots.
124
125  :ref:`transfer`
126    The transfer module provides DCC SEND/GET support and userfile
127    transfer support for userfile sharing.
128
129  :ref:`uptime`
130    This module reports uptime statistics to the uptime contest
131    web site at http://uptime.eggheads.org. Go look and see what
132    your uptime is! It takes about 9 hours to show up, so if your
133    bot isn't listed, try again later. See doc/settings/mod.uptime
134    for more information, including details on what information is
135    sent to the uptime server.
136
137  :ref:`woobie`
138    This is for demonstrative purposes only. If you are looking for
139    starting point in writing modules, woobie is the right thing.
140
141-------------------
142Programming modules
143-------------------
144
145WARNING: This section is very likely to be out of date.
146
147Note: This is for a simple module of 1 source file. If you're doing a
148multiple source file module, you shouldn't need to read this anyway.
149
150  1. Create a src/mod/MODULE.mod directory in your Eggdrop directory (where
151     MODULE is the module name) and cd to it.
152
153  2. Copy the file 'Makefile' from src/mod/woobie.mod and replace all
154     occurrences of 'woobie' with your module name. This should ensure
155     that your module gets compiled.
156
157  3. Next, you want to create a file called MODULE.c (MODULE is the module
158     name again).
159
160  4. You MUST include the following in your source code::
161
162      #define MODULE_NAME "module-name"
163
164    This should be defined to the same name you will be using when you load
165    your module.
166
167    ::
168
169      #define MAKING_MODULENAME
170
171    MODULENAME is the name of your module (MODULE_NAME), but in all caps.
172
173    ::
174
175      #include "../module.h"
176
177    This provides access to Eggdrop's global function table. Examine
178    src/mod/module.h closely to find a list of functions available.
179
180    ::
181
182      #include any other standard c header files you might need.
183
184    Note that stdio.h, string.h, stdlib.h, and sys/types.h are already included.
185
186    ::
187
188      Function *global;
189
190    This variable provides access to all the Eggdrop functions; without it,
191    you can't call any Eggdrop functions (the module won't even load).
192
193-------------------
194Module requirements
195-------------------
196
197In most modules, all functions/variables (except global and MODULE_start)
198should be static. This will drastically reduce the size of modules on
199decent systems.
200
201Throughout this step, MODULE refers to the module name. Note that
202  "MODULE_NAME" should literally be "MODULE_NAME".
203
204^^^^^^^^^^^^
205MODULE_start
206^^^^^^^^^^^^
207::
208
209  char *MODULE_start(Function *func_table)
210
211  This function is called when the module is first loaded. There are
212  several things that need to be done in this function
213
214::
215
216  global = func_table;
217
218  This allows you to make calls to the global function table.
219
220::
221
222  module_register(MODULE_NAME, MODULE_table, MAJOR, MINOR);
223
224  This records details about the module for other modules and Eggdrop
225  itself to access. MAJOR and MINOR are ints, where MAJOR is the
226  module's major version number and MINOR is a minor version number.
227  MODULE_table is a function table (see below).
228
229::
230
231  module_depend(MODULE_NAME, "another-module", MAJOR, MINOR);
232
233  This lets Eggdrop know that your module NEEDS "another-module" of
234  major version 'MAJOR' and at least minor version 'MINOR' to run,
235  and hence should try to load it if it's not already loaded. This
236  will return 1 on success, or 0 if it can't be done (at which stage
237  you should return an error).
238
239Any other initialization stuff you desire should also be included in
240this function. See below for various things you can do.
241
242You also will need to return a value. Returning NULL implies the
243module loaded successfully. Returning a non-NULL STRING is an error
244message. The module (and any other dependent modules) will stop
245loading and an error will be returned.
246
247^^^^^^^^^^^^
248MODULE_table
249^^^^^^^^^^^^
250
251::
252
253  static Function *MODULE_table = {
254         MODULE_start,
255         MODULE_close,
256         MODULE_expmem,
257         MODULE_report,
258         any_other_functions,
259         you_want_to_export
260  };
261
262  This is a table of functions which any other module can access. The
263  first 4 functions are FIXED. You MUST have them; they provide important
264  module information.
265
266^^^^^^^^^^^^^^^
267MODULE_close ()
268^^^^^^^^^^^^^^^
269::
270
271  static char *MODULE_close ()
272
273  This is called when the module is unloaded. Apart from tidying any
274  relevant data (I suggest you be thorough, we don't want any trailing
275  garbage from modules), you MUST do the following:
276
277::
278
279  module_undepend(MODULE_NAME);
280
281  This lets Eggdrop know your module no longer depends on any other
282  modules.
283
284  Return a value. NULL implies success; any non-NULL STRING implies
285  that the module cannot be unloaded for some reason, and hence the
286  bot should not unload it (see the blowfish module for an example).
287
288^^^^^^^^^^^^^
289MODULE_expmem
290^^^^^^^^^^^^^
291
292::
293
294  static int MODULE_expmem ()
295
296  This should tally all memory you allocate/deallocate within the module
297  (using nmalloc, nfree, etc) in bytes. It's used by memory debugging to
298  track memory faults, and it is used by .status to total up memory usage.
299
300^^^^^^^^^^^^^
301MODULE_report
302^^^^^^^^^^^^^
303
304::
305
306  static void MODULE_report (int idx)
307
308  This should provide a relatively short report of the module's status
309  (for the module and status commands).
310
311These functions are available to modules. MANY more available functions
312can be found in src/mod/module.h.
313
314^^^^^^^^^^^^^^^^^^^^
315Additional functions
316^^^^^^^^^^^^^^^^^^^^
317
318::
319
320  void *nmalloc(int j);
321
322  This allocates j bytes of memory.
323
324::
325
326  void nfree(void *a);
327
328  This frees an nmalloc'd block of memory.
329
330::
331
332  Context;
333
334  Actually a macro -- records the current position in execution (for
335  debugging). Using Context is no longer recommended, because it uses
336  too many resources and a core file provides much more information.
337
338::
339
340  void dprintf(int idx, char *format, ...)
341
342  This acts like a normal printf() function, but it outputs to
343  log/socket/idx.
344
345  idx is a normal dcc idx, or if < 0 is a sock number.
346
347  Other destinations:
348    DP_LOG    - send to log file
349    DP_STDOUT - send to stdout
350    DP_MODE   - send via mode queue to the server
351    DP_SERVER - send via normal queue to the server
352    DP_HELP   - send via help queue to server
353
354::
355
356  const module_entry *module_find(char *module_name, int major, int minor);
357
358    Searches for a loaded module (matching major, >= minor), and returns
359    info about it.
360
361    Members of module_entry:
362      char *name;      - module name
363      int major;       - real major version
364      int minor;       - real minor version
365      Function *funcs; - function table (see above)
366
367  void module_rename(char *old_module_name, char *new_module_name)
368
369    This renames a module frim old_module_name to new_module_name.
370
371  void add_hook(int hook_num, Function *funcs)
372  void del_hook(int hook_num, Function *funcs)
373
374   These are used for adding or removing hooks to/from Eggdrop code that
375   are triggered on various events. Valid hooks are:
376     HOOK_SECONDLY   - called every second
377     HOOK_MINUTELY   - called every minute
378     HOOK_5MINUTELY  - called every 5 minutes
379     HOOK_HOURLY     - called every hour (hourly-updates minutes past)
380     HOOK_DAILY      - called when the logfiles are switched
381
382     HOOK_READ_USERFILE - called when the userfile is read
383     HOOK_USERFILE      - called when the userfile is written
384     HOOK_PRE_REHASH    - called just before a rehash
385     HOOK_REHASH        - called just after a rehash
386     HOOK_IDLE          - called whenever the dcc connections have been
387                          idle for a whole second
388     HOOK_BACKUP        - called when a user/channel file backup is done
389     HOOK_LOADED        - called when Eggdrop is first loaded
390     HOOK_DIE           - called when Eggdrop is about to die
391
392  char *module_unload (char *module_name);
393  char *module_load (char *module_name);
394
395    Tries to load or unload the specified module; returns 0 on success, or
396    an error message.
397
398  void add_tcl_commands(tcl_cmds *tab);
399  void rem_tcl_commands(tcl_cmds *tab);
400
401    Provides a quick way to create and remove a table of Tcl commands. The
402    table is in the form of:
403
404      {char *func_name, Function *function_to_call}
405
406    Use { NULL, NULL } to indicate the end of the list.
407
408  void add_tcl_ints(tcl_ints *);
409  void rem_tcl_ints(tcl_ints *);
410
411    Provides a quick way to create and remove a table of links from C
412    int variables to Tcl variables (add_tcl_ints checks to see if the Tcl
413    variable exists and copies it over the C one). The format of table is:
414
415      {char *variable_name, int *variable, int readonly}
416
417    Use {NULL, NULL, 0} to indicate the end of the list.
418
419  void add_tcl_strings(tcl_strings *);
420  void rem_tcl_strings(tcl_strings *);
421
422    Provides a quick way to create and remove a table of links from C
423    string variables to Tcl variables (add_tcl_ints checks to see if the
424    Tcl variable exists and copies it over the C one). The format of table
425    is:
426
427      {char *variable_name, char *string, int length, int flags}
428
429    Use {NULL, NULL, 0, 0} to indicate the end of the list. Use 0 for
430    length if you want a const string. Use STR_DIR for flags if you want a
431    '/' constantly appended; use STR_PROTECT if you want the variable set
432    in the config file, but not during normal usage.
433
434  void add_builtins(p_tcl_hash_list table, cmd_t *cc);
435  void rem_builtins(p_tcl_hash_list table, cmd_t *cc);
436
437    This adds binds to one of Eggdrop's bind tables. The format of the
438    table is:
439
440      {char *command, char *flags, Function *function, char *displayname}
441
442    Use {NULL, NULL, NULL, NULL} to indicate the end of the list.
443
444    This works EXACTLY like the Tcl 'bind' command. displayname is what Tcl
445    sees this function's proc name as (in .binds all).
446
447    function is called with exactly the same args as a Tcl binding is with
448    type conversion taken into account (e.g. idx's are ints). Return values
449    are much the same as Tcl bindings. Use int 0/1 for those which require
450    0/1, or char * for those which require a string (auch as filt). Return
451    nothing if no return value is required.
452
453  void putlog (int logmode, char *channel, char *format, ...)
454
455    Adds text to a logfile (determined by logmode and channel). This text
456    will also output to any users' consoles if they have the specified
457    console mode enabled.
458
459-------------------------
460What to do with a module?
461-------------------------
462
463   If you have written a module and feel that you wish to share it with the
464   rest of the Eggdrop community, upload it to the incoming directory on
465   incoming.eggheads.org (/incoming/modules/1.8). Place a nice descriptive
466   text (modulename.desc) with it, and it'll make its way to the modules
467   directory on ftp.eggheads.org. Don't forget to mention in your text file
468   which version Eggdrop the module is written for.
469
470Copyright (C) 1999 - 2021 Eggheads Development Team
471