ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/contrib/example_module.c
Revision: 1121
Committed: Sun Jan 9 11:03:03 2011 UTC (15 years, 9 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.3/contrib/example_module.c
File size: 7132 byte(s)
Log Message:
- removed all instances of STATIC_MODULES since we don't have
  static modules anymore
- removed m_mkpasswd module from contrib

File Contents

# User Rev Content
1 adx 30 /************************************************************************
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 knight 31 * $Id$
20 adx 30 */
21    
22     /* List of ircd includes from ../include/
23     * These ones are necessary to build THIS module...
24     */
25    
26 michael 1121 #include "stdinc.h" /* includes setup.h */
27 adx 30
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 michael 946 * rfc1459_command_send_error: give an error when the command comes from certain types
103 adx 30 */
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     /* Here we tell it what to do when the module is loaded */
115     void
116     _modinit(void)
117     {
118     /* This will add the commands in test_msgtab (which is above) */
119     mod_add_cmd(&test_msgtab);
120     }
121    
122     /* here we tell it what to do when the module is unloaded */
123     void
124     _moddeinit(void)
125     {
126     /* This will remove the commands in test_msgtab (which is above) */
127     mod_del_cmd(&test_msgtab);
128     }
129    
130     /* When we last modified the file (shown in /modlist), this is usually:
131     */
132 knight 31 const char *_version = "$Revision$";
133 adx 30
134     /*
135     * mr_test
136     * parv[0] = sender prefix
137     * parv[1] = parameter
138     */
139    
140     /* Here we have the functions themselves that we declared above,
141     * and the fairly normal C coding
142     */
143     static void
144     mr_test(struct Client *client_p, struct Client *source_p,
145     int parc, char *parv[])
146     {
147     if (parc == 1)
148     sendto_one(source_p, ":%s NOTICE %s :You are unregistered and sent no parameters",
149     me.name, source_p->name);
150     else
151     sendto_one(source_p, ":%s NOTICE %s :You are unregistered and sent parameter: %s",
152     me.name, source_p->name, parv[1]);
153     }
154    
155     /*
156     * m_test
157     * parv[0] = sender prefix
158     * parv[1] = parameter
159     */
160     static void
161     m_test(struct Client *client_p, struct Client *source_p,
162     int parc, char *parv[])
163     {
164     if (parc == 1)
165     sendto_one(source_p, ":%s NOTICE %s :You are a normal user, and sent no parameters",
166     me.name, source_p->name);
167     else
168     sendto_one(source_p, ":%s NOTICE %s :You are a normal user, and send parameters: %s",
169     me.name, source_p->name, parv[1]);
170     }
171    
172     /*
173     * ms_test
174     * parv[0] = sender prefix
175     * parv[1] = parameter
176     */
177     static void
178     ms_test(struct Client *client_p, struct Client *source_p,
179     int parc, char *parv[])
180     {
181     if (parc == 1)
182     {
183     if (IsServer(source_p))
184     sendto_one(source_p, ":%s NOTICE %s :You are a server, and sent no parameters",
185     me.name, source_p->name);
186     else
187     sendto_one(source_p, ":%s NOTICE %s :You are a remote client, and sent no parameters",
188     me.name, source_p->name);
189     }
190     else
191     {
192     if (IsServer(source_p))
193     sendto_one(source_p, ":%s NOTICE %s :You are a server, and sent parameters: %s",
194     me.name, source_p->name, parv[1]);
195     else
196     sendto_one(source_p, ":%s NOTICE %s :You are a remote client, and sent parameters: %s",
197     me.name, source_p->name, parv[1]);
198     }
199     }
200    
201     /*
202     * mo_test
203     * parv[0] = sender prefix
204     * parv[1] = parameter
205     */
206     static void
207     mo_test(struct Client *client_p, struct Client *source_p,
208     int parc, char *parv[])
209     {
210     if (parc == 1)
211     sendto_one(source_p, ":%s NOTICE %s :You are an operator, and sent no parameters",
212     me.name, source_p->name);
213     else
214     sendto_one(source_p, ":%s NOTICE %s :You are an operator, and sent parameters: %s",
215     me.name, source_p->name, parv[1]);
216     }
217    
218     /* END OF EXAMPLE MODULE */

Properties

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