ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/branches/ircd-hybrid-newconf/contrib/example_module.c
Revision: 444
Committed: Sun Feb 12 00:15:24 2006 UTC (20 years, 6 months ago) by adx
Content type: text/x-csrc
Original Path: ircd-hybrid/contrib/example_module.c
File size: 6937 byte(s)
Log Message:
+ STATIC_MODULES is no longer meaningful so byebye

File Contents

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

Properties

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