| 1 |
/************************************************************************ |
| 2 |
* IRC - Internet Relay Chat, doc/example_module.c |
| 3 |
* Copyright (C) 2001 Hybrid Development Team |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 1, or (at your option) |
| 8 |
* any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program; if not, write to the Free Software |
| 17 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 |
* |
| 19 |
* $Id: example_module.c,v 1.13 2005/10/01 14:29:47 michael Exp $ |
| 20 |
*/ |
| 21 |
|
| 22 |
/* List of ircd includes from ../include/ |
| 23 |
* These ones are necessary to build THIS module... |
| 24 |
*/ |
| 25 |
|
| 26 |
#include "stdinc.h" /* includes setup.h, for STATIC_MODULES */ |
| 27 |
|
| 28 |
#include "client.h" /* Required for IsClient, etc. */ |
| 29 |
|
| 30 |
#include "send.h" /* sendto_one, most useful function of all time */ |
| 31 |
|
| 32 |
#include "modules.h" /* includes msg.h; use for the msgtab */ |
| 33 |
|
| 34 |
#include "handlers.h" /* m_ignore */ |
| 35 |
|
| 36 |
/* OTHER USEFUL INCLUDES: |
| 37 |
* |
| 38 |
* #include "handlers.h" <-- include this file to be able to use default |
| 39 |
* functions in place of your own 'Access Denied' kind of function |
| 40 |
* |
| 41 |
* #include "numeric.h" <-- include this file to be able to use form_str, |
| 42 |
* standard message formats (see messages.tab and *.lang in messages/) |
| 43 |
* Examples are strewn all across the ircd code, so just grep a bit to |
| 44 |
* find one! |
| 45 |
* |
| 46 |
* #include "irc_string.h" <-- best to include this if you use *any* |
| 47 |
* string comparison or parsing functions, although they may be available |
| 48 |
* natively for your OS the prototypes in irc_string.h may be required for |
| 49 |
* others. */ |
| 50 |
|
| 51 |
/* Declare the void's initially up here, as modules don't have an |
| 52 |
* include file, we will normally have client_p, source_p, parc |
| 53 |
* and parv[] where: |
| 54 |
* |
| 55 |
* client_p == client issuing command |
| 56 |
* source_p == where the command came from |
| 57 |
* parc == the number of parameters |
| 58 |
* parv == an array of the parameters |
| 59 |
*/ |
| 60 |
static void mr_test(struct Client *, struct Client *, int, char *[]); |
| 61 |
static void m_test(struct Client *, struct Client *, int, char *[]); |
| 62 |
static void ms_test(struct Client *, struct Client *, int, char *[]); |
| 63 |
static void mo_test(struct Client *, struct Client *, int, char *[]); |
| 64 |
|
| 65 |
/* |
| 66 |
* Show the commands this module can handle in a msgtab |
| 67 |
* and give the msgtab a name, here its test_msgtab |
| 68 |
*/ |
| 69 |
struct Message test_msgtab = { |
| 70 |
|
| 71 |
/* Fields are in order: |
| 72 |
*-> "COMMAND", 0, 0, parc_count, maxparc, MFLG_SLOW, 0, |
| 73 |
* |
| 74 |
* where: |
| 75 |
* COMMAND == the /command you want |
| 76 |
* parc_count == the number of parameters needed |
| 77 |
* (the clients name is one param, parv[0]) |
| 78 |
* maxparc == the maximum parameters we allow |
| 79 |
* the 0's and MFLG_SLOW should not be changed.. |
| 80 |
*/ |
| 81 |
|
| 82 |
/* This would add the command "TEST" which requires no additional |
| 83 |
* parameters |
| 84 |
*/ |
| 85 |
"TEST", 0, 0, 1, 0, MFLG_SLOW, 0, |
| 86 |
|
| 87 |
/* Fields are in order: |
| 88 |
*-> {unregged, regged, remote, encap, oper, dummy} |
| 89 |
* |
| 90 |
* where: |
| 91 |
* unregged == function to call for unregistered clients |
| 92 |
* regged == function to call for normal users |
| 93 |
* remote == function to call for servers/remote users |
| 94 |
* encap == function to call for encap'd server/remote commands |
| 95 |
* oper == function to call for operators |
| 96 |
* dummy == function called when client is quarantined |
| 97 |
* |
| 98 |
* There are also some pre-coded functions for use: |
| 99 |
* m_unregistered: prevent the client using this if unregistered |
| 100 |
* m_not_oper: tell the client it requires being an operator |
| 101 |
* m_ignore: ignore the command when it comes from certain types |
| 102 |
* m_error: give an error when the command comes from certain types |
| 103 |
*/ |
| 104 |
{ mr_test, m_test, ms_test, m_ignore, mo_test, m_ignore } |
| 105 |
|
| 106 |
/* It is normal for unregistered functions to be prefixed with mr_ |
| 107 |
* " " normal users to be prefixed with m_ |
| 108 |
* " " remote clients to be prefixed with ms_ |
| 109 |
* " " operators to be prefixed with mo_ |
| 110 |
*/ |
| 111 |
}; |
| 112 |
/* That's the msgtab finished */ |
| 113 |
|
| 114 |
#ifndef STATIC_MODULES |
| 115 |
/* Here we tell it what to do when the module is loaded */ |
| 116 |
void |
| 117 |
_modinit(void) |
| 118 |
{ |
| 119 |
/* This will add the commands in test_msgtab (which is above) */ |
| 120 |
mod_add_cmd(&test_msgtab); |
| 121 |
} |
| 122 |
|
| 123 |
/* here we tell it what to do when the module is unloaded */ |
| 124 |
void |
| 125 |
_moddeinit(void) |
| 126 |
{ |
| 127 |
/* This will remove the commands in test_msgtab (which is above) */ |
| 128 |
mod_del_cmd(&test_msgtab); |
| 129 |
} |
| 130 |
|
| 131 |
/* When we last modified the file (shown in /modlist), this is usually: |
| 132 |
*/ |
| 133 |
const char *_version = "$Revision: 1.13 $"; |
| 134 |
#endif |
| 135 |
|
| 136 |
/* |
| 137 |
* mr_test |
| 138 |
* parv[0] = sender prefix |
| 139 |
* parv[1] = parameter |
| 140 |
*/ |
| 141 |
|
| 142 |
/* Here we have the functions themselves that we declared above, |
| 143 |
* and the fairly normal C coding |
| 144 |
*/ |
| 145 |
static void |
| 146 |
mr_test(struct Client *client_p, struct Client *source_p, |
| 147 |
int parc, char *parv[]) |
| 148 |
{ |
| 149 |
if (parc == 1) |
| 150 |
sendto_one(source_p, ":%s NOTICE %s :You are unregistered and sent no parameters", |
| 151 |
me.name, source_p->name); |
| 152 |
else |
| 153 |
sendto_one(source_p, ":%s NOTICE %s :You are unregistered and sent parameter: %s", |
| 154 |
me.name, source_p->name, parv[1]); |
| 155 |
} |
| 156 |
|
| 157 |
/* |
| 158 |
* m_test |
| 159 |
* parv[0] = sender prefix |
| 160 |
* parv[1] = parameter |
| 161 |
*/ |
| 162 |
static void |
| 163 |
m_test(struct Client *client_p, struct Client *source_p, |
| 164 |
int parc, char *parv[]) |
| 165 |
{ |
| 166 |
if (parc == 1) |
| 167 |
sendto_one(source_p, ":%s NOTICE %s :You are a normal user, and sent no parameters", |
| 168 |
me.name, source_p->name); |
| 169 |
else |
| 170 |
sendto_one(source_p, ":%s NOTICE %s :You are a normal user, and send parameters: %s", |
| 171 |
me.name, source_p->name, parv[1]); |
| 172 |
} |
| 173 |
|
| 174 |
/* |
| 175 |
* ms_test |
| 176 |
* parv[0] = sender prefix |
| 177 |
* parv[1] = parameter |
| 178 |
*/ |
| 179 |
static void |
| 180 |
ms_test(struct Client *client_p, struct Client *source_p, |
| 181 |
int parc, char *parv[]) |
| 182 |
{ |
| 183 |
if (parc == 1) |
| 184 |
{ |
| 185 |
if (IsServer(source_p)) |
| 186 |
sendto_one(source_p, ":%s NOTICE %s :You are a server, and sent no parameters", |
| 187 |
me.name, source_p->name); |
| 188 |
else |
| 189 |
sendto_one(source_p, ":%s NOTICE %s :You are a remote client, and sent no parameters", |
| 190 |
me.name, source_p->name); |
| 191 |
} |
| 192 |
else |
| 193 |
{ |
| 194 |
if (IsServer(source_p)) |
| 195 |
sendto_one(source_p, ":%s NOTICE %s :You are a server, and sent parameters: %s", |
| 196 |
me.name, source_p->name, parv[1]); |
| 197 |
else |
| 198 |
sendto_one(source_p, ":%s NOTICE %s :You are a remote client, and sent parameters: %s", |
| 199 |
me.name, source_p->name, parv[1]); |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
/* |
| 204 |
* mo_test |
| 205 |
* parv[0] = sender prefix |
| 206 |
* parv[1] = parameter |
| 207 |
*/ |
| 208 |
static void |
| 209 |
mo_test(struct Client *client_p, struct Client *source_p, |
| 210 |
int parc, char *parv[]) |
| 211 |
{ |
| 212 |
if (parc == 1) |
| 213 |
sendto_one(source_p, ":%s NOTICE %s :You are an operator, and sent no parameters", |
| 214 |
me.name, source_p->name); |
| 215 |
else |
| 216 |
sendto_one(source_p, ":%s NOTICE %s :You are an operator, and sent parameters: %s", |
| 217 |
me.name, source_p->name, parv[1]); |
| 218 |
} |
| 219 |
|
| 220 |
/* END OF EXAMPLE MODULE */ |