ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/contrib/example_module.c
Revision: 812
Committed: Thu Sep 7 09:41:54 2006 UTC (17 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 6914 byte(s)
Log Message:
- Imported contrib/

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: example_module.c 677 2006-06-13 17:12:38Z adx $
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" /* 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 */
98 { mr_test, m_test, ms_test, m_ignore, mo_test, m_ignore }
99
100 /* It is normal for unregistered functions to be prefixed with mr_
101 * " " normal users to be prefixed with m_
102 * " " remote clients to be prefixed with ms_
103 * " " operators to be prefixed with mo_
104 */
105 };
106 /* That's the msgtab finished */
107
108 /* Here we tell it what to do when the module is loaded */
109 INIT_MODULE(example_module, "$Revision: 33 $")
110 {
111 /* This will add the commands in test_msgtab (which is above) */
112 mod_add_cmd(&test_msgtab);
113 }
114
115 /* here we tell it what to do when the module is unloaded */
116 CLEANUP_MODULE
117 {
118 /* This will remove the commands in test_msgtab (which is above) */
119 mod_del_cmd(&test_msgtab);
120 }
121
122 /*
123 * mr_test
124 * parv[0] = sender prefix
125 * parv[1] = parameter
126 */
127
128 /* Here we have the functions themselves that we declared above,
129 * and the fairly normal C coding
130 */
131 static void
132 mr_test(struct Client *client_p, struct Client *source_p,
133 int parc, char *parv[])
134 {
135 if (parc == 1)
136 sendto_one(source_p, ":%s NOTICE %s :You are unregistered and sent no parameters",
137 me.name, source_p->name);
138 else
139 sendto_one(source_p, ":%s NOTICE %s :You are unregistered and sent parameter: %s",
140 me.name, source_p->name, parv[1]);
141 }
142
143 /*
144 * m_test
145 * parv[0] = sender prefix
146 * parv[1] = parameter
147 */
148 static void
149 m_test(struct Client *client_p, struct Client *source_p,
150 int parc, char *parv[])
151 {
152 if (parc == 1)
153 sendto_one(source_p, ":%s NOTICE %s :You are a normal user, and sent no parameters",
154 me.name, source_p->name);
155 else
156 sendto_one(source_p, ":%s NOTICE %s :You are a normal user, and send parameters: %s",
157 me.name, source_p->name, parv[1]);
158 }
159
160 /*
161 * ms_test
162 * parv[0] = sender prefix
163 * parv[1] = parameter
164 */
165 static void
166 ms_test(struct Client *client_p, struct Client *source_p,
167 int parc, char *parv[])
168 {
169 if (parc == 1)
170 {
171 if (IsServer(source_p))
172 sendto_one(source_p, ":%s NOTICE %s :You are a server, and sent no parameters",
173 me.name, source_p->name);
174 else
175 sendto_one(source_p, ":%s NOTICE %s :You are a remote client, and sent no parameters",
176 me.name, source_p->name);
177 }
178 else
179 {
180 if (IsServer(source_p))
181 sendto_one(source_p, ":%s NOTICE %s :You are a server, and sent parameters: %s",
182 me.name, source_p->name, parv[1]);
183 else
184 sendto_one(source_p, ":%s NOTICE %s :You are a remote client, and sent parameters: %s",
185 me.name, source_p->name, parv[1]);
186 }
187 }
188
189 /*
190 * mo_test
191 * parv[0] = sender prefix
192 * parv[1] = parameter
193 */
194 static void
195 mo_test(struct Client *client_p, struct Client *source_p,
196 int parc, char *parv[])
197 {
198 if (parc == 1)
199 sendto_one(source_p, ":%s NOTICE %s :You are an operator, and sent no parameters",
200 me.name, source_p->name);
201 else
202 sendto_one(source_p, ":%s NOTICE %s :You are an operator, and sent parameters: %s",
203 me.name, source_p->name, parv[1]);
204 }
205
206 /* END OF EXAMPLE MODULE */

Properties

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