/[svn]/ircd-hybrid/contrib/example_module.c
ViewVC logotype

Contents of /ircd-hybrid/contrib/example_module.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 843 - (show annotations)
Fri Feb 9 22:05:55 2007 UTC (13 years, 7 months ago) by bear
File MIME type: text/x-chdr
File size: 6927 byte(s)
make example_module compile

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$
20 */
21
22 /* List of ircd includes from ../include/
23 * These ones are necessary to build THIS module...
24 */
25
26 #include "stdinc.h"
27 #include "client.h" /* Required for IsClient, etc. */
28 #include "send.h" /* sendto_one, most useful function of all time */
29 #include "conf/modules.h" /* some #define's */
30 #include "handlers.h" /* m_ignore */
31 #include "msg.h" /* msgtab */
32 #include "parse.h" /* mod_{add,del}_cmd */
33
34 /* OTHER USEFUL INCLUDES:
35 *
36 * #include "handlers.h" <-- include this file to be able to use default
37 * functions in place of your own 'Access Denied' kind of function
38 *
39 * #include "numeric.h" <-- include this file to be able to use form_str,
40 * standard message formats (see messages.tab and *.lang in messages/)
41 * Examples are strewn all across the ircd code, so just grep a bit to
42 * find one!
43 *
44 * string comparison or parsing functions, although they may be available
45 * natively for your OS the prototypes in irc_string.h may be required for
46 * others. */
47
48 /* Declare the void's initially up here, as modules don't have an
49 * include file, we will normally have client_p, source_p, parc
50 * and parv[] where:
51 *
52 * client_p == client issuing command
53 * source_p == where the command came from
54 * parc == the number of parameters
55 * parv == an array of the parameters
56 */
57 static void mr_test(struct Client *, struct Client *, int, char *[]);
58 static void m_test(struct Client *, struct Client *, int, char *[]);
59 static void ms_test(struct Client *, struct Client *, int, char *[]);
60 static void mo_test(struct Client *, struct Client *, int, char *[]);
61
62 /*
63 * Show the commands this module can handle in a msgtab
64 * and give the msgtab a name, here its test_msgtab
65 */
66 struct Message test_msgtab = {
67
68 /* Fields are in order:
69 *-> "COMMAND", 0, 0, parc_count, maxparc, MFLG_SLOW, 0,
70 *
71 * where:
72 * COMMAND == the /command you want
73 * parc_count == the number of parameters needed
74 * (the clients name is one param, parv[0])
75 * maxparc == the maximum parameters we allow
76 * the 0's and MFLG_SLOW should not be changed..
77 */
78
79 /* This would add the command "TEST" which requires no additional
80 * parameters
81 */
82 "TEST", 0, 0, 1, 0, MFLG_SLOW, 0,
83
84 /* Fields are in order:
85 *-> {unregged, regged, remote, encap, oper, dummy}
86 *
87 * where:
88 * unregged == function to call for unregistered clients
89 * regged == function to call for normal users
90 * remote == function to call for servers/remote users
91 * encap == function to call for encap'd server/remote commands
92 * oper == function to call for operators
93 * dummy == function called when client is quarantined
94 *
95 * There are also some pre-coded functions for use:
96 * m_unregistered: prevent the client using this if unregistered
97 * m_not_oper: tell the client it requires being an operator
98 * m_ignore: ignore the command when it comes from certain types
99 */
100 { mr_test, m_test, ms_test, m_ignore, mo_test, m_ignore }
101
102 /* It is normal for unregistered functions to be prefixed with mr_
103 * " " normal users to be prefixed with m_
104 * " " remote clients to be prefixed with ms_
105 * " " operators to be prefixed with mo_
106 */
107 };
108 /* That's the msgtab finished */
109
110 /* Here we tell it what to do when the module is loaded */
111 INIT_MODULE(example_module, "$Revision: 33 $")
112 {
113 /* This will add the commands in test_msgtab (which is above) */
114 mod_add_cmd(&test_msgtab);
115 }
116
117 /* here we tell it what to do when the module is unloaded */
118 CLEANUP_MODULE
119 {
120 /* This will remove the commands in test_msgtab (which is above) */
121 mod_del_cmd(&test_msgtab);
122 }
123
124 /*
125 * mr_test
126 * parv[0] = sender prefix
127 * parv[1] = parameter
128 */
129
130 /* Here we have the functions themselves that we declared above,
131 * and the fairly normal C coding
132 */
133 static void
134 mr_test(struct Client *client_p, struct Client *source_p,
135 int parc, char *parv[])
136 {
137 if (parc == 1)
138 sendto_one(source_p, ":%s NOTICE %s :You are unregistered and sent no parameters",
139 me.name, source_p->name);
140 else
141 sendto_one(source_p, ":%s NOTICE %s :You are unregistered and sent parameter: %s",
142 me.name, source_p->name, parv[1]);
143 }
144
145 /*
146 * m_test
147 * parv[0] = sender prefix
148 * parv[1] = parameter
149 */
150 static void
151 m_test(struct Client *client_p, struct Client *source_p,
152 int parc, char *parv[])
153 {
154 if (parc == 1)
155 sendto_one(source_p, ":%s NOTICE %s :You are a normal user, and sent no parameters",
156 me.name, source_p->name);
157 else
158 sendto_one(source_p, ":%s NOTICE %s :You are a normal user, and send parameters: %s",
159 me.name, source_p->name, parv[1]);
160 }
161
162 /*
163 * ms_test
164 * parv[0] = sender prefix
165 * parv[1] = parameter
166 */
167 static void
168 ms_test(struct Client *client_p, struct Client *source_p,
169 int parc, char *parv[])
170 {
171 if (parc == 1)
172 {
173 if (IsServer(source_p))
174 sendto_one(source_p, ":%s NOTICE %s :You are a server, and sent no parameters",
175 me.name, source_p->name);
176 else
177 sendto_one(source_p, ":%s NOTICE %s :You are a remote client, and sent no parameters",
178 me.name, source_p->name);
179 }
180 else
181 {
182 if (IsServer(source_p))
183 sendto_one(source_p, ":%s NOTICE %s :You are a server, and sent parameters: %s",
184 me.name, source_p->name, parv[1]);
185 else
186 sendto_one(source_p, ":%s NOTICE %s :You are a remote client, and sent parameters: %s",
187 me.name, source_p->name, parv[1]);
188 }
189 }
190
191 /*
192 * mo_test
193 * parv[0] = sender prefix
194 * parv[1] = parameter
195 */
196 static void
197 mo_test(struct Client *client_p, struct Client *source_p,
198 int parc, char *parv[])
199 {
200 if (parc == 1)
201 sendto_one(source_p, ":%s NOTICE %s :You are an operator, and sent no parameters",
202 me.name, source_p->name);
203 else
204 sendto_one(source_p, ":%s NOTICE %s :You are an operator, and sent parameters: %s",
205 me.name, source_p->name, parv[1]);
206 }
207
208 /* END OF EXAMPLE MODULE */

Properties

Name Value
svn:eol-style native
svn:keywords "Author Date Id Revision"

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28