ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/contrib/example_module.c
Revision: 76
Committed: Tue Oct 4 19:38:49 2005 UTC (21 years ago) by adx
Content type: text/x-csrc
File size: 7106 byte(s)
Log Message:
- fixed contrib #includes

File Contents

# User Rev Content
1 knight 75 /************************************************************************
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" /* 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     * string comparison or parsing functions, although they may be available
47     * natively for your OS the prototypes in irc_string.h may be required for
48     * others. */
49    
50     /* Declare the void's initially up here, as modules don't have an
51     * include file, we will normally have client_p, source_p, parc
52     * and parv[] where:
53     *
54     * client_p == client issuing command
55     * source_p == where the command came from
56     * parc == the number of parameters
57     * parv == an array of the parameters
58     */
59     static void mr_test(struct Client *, struct Client *, int, char *[]);
60     static void m_test(struct Client *, struct Client *, int, char *[]);
61     static void ms_test(struct Client *, struct Client *, int, char *[]);
62     static void mo_test(struct Client *, struct Client *, int, char *[]);
63    
64     /*
65     * Show the commands this module can handle in a msgtab
66     * and give the msgtab a name, here its test_msgtab
67     */
68     struct Message test_msgtab = {
69    
70     /* Fields are in order:
71     *-> "COMMAND", 0, 0, parc_count, maxparc, MFLG_SLOW, 0,
72     *
73     * where:
74     * COMMAND == the /command you want
75     * parc_count == the number of parameters needed
76     * (the clients name is one param, parv[0])
77     * maxparc == the maximum parameters we allow
78     * the 0's and MFLG_SLOW should not be changed..
79     */
80    
81     /* This would add the command "TEST" which requires no additional
82     * parameters
83     */
84     "TEST", 0, 0, 1, 0, MFLG_SLOW, 0,
85    
86     /* Fields are in order:
87     *-> {unregged, regged, remote, encap, oper, dummy}
88     *
89     * where:
90     * unregged == function to call for unregistered clients
91     * regged == function to call for normal users
92     * remote == function to call for servers/remote users
93     * encap == function to call for encap'd server/remote commands
94     * oper == function to call for operators
95     * dummy == function called when client is quarantined
96     *
97     * There are also some pre-coded functions for use:
98     * m_unregistered: prevent the client using this if unregistered
99     * m_not_oper: tell the client it requires being an operator
100     * m_ignore: ignore the command when it comes from certain types
101     * m_error: give an error when the command comes from certain types
102     */
103     { mr_test, m_test, ms_test, m_ignore, mo_test, m_ignore }
104    
105     /* It is normal for unregistered functions to be prefixed with mr_
106     * " " normal users to be prefixed with m_
107     * " " remote clients to be prefixed with ms_
108     * " " operators to be prefixed with mo_
109     */
110     };
111     /* That's the msgtab finished */
112    
113     #ifndef STATIC_MODULES
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     const char *_version = "$Revision: 33 $";
133     #endif
134    
135     /*
136     * mr_test
137     * parv[0] = sender prefix
138     * parv[1] = parameter
139     */
140    
141     /* Here we have the functions themselves that we declared above,
142     * and the fairly normal C coding
143     */
144     static void
145     mr_test(struct Client *client_p, struct Client *source_p,
146     int parc, char *parv[])
147     {
148     if (parc == 1)
149     sendto_one(source_p, ":%s NOTICE %s :You are unregistered and sent no parameters",
150     me.name, source_p->name);
151     else
152     sendto_one(source_p, ":%s NOTICE %s :You are unregistered and sent parameter: %s",
153     me.name, source_p->name, parv[1]);
154     }
155    
156     /*
157     * m_test
158     * parv[0] = sender prefix
159     * parv[1] = parameter
160     */
161     static void
162     m_test(struct Client *client_p, struct Client *source_p,
163     int parc, char *parv[])
164     {
165     if (parc == 1)
166     sendto_one(source_p, ":%s NOTICE %s :You are a normal user, and sent no parameters",
167     me.name, source_p->name);
168     else
169     sendto_one(source_p, ":%s NOTICE %s :You are a normal user, and send parameters: %s",
170     me.name, source_p->name, parv[1]);
171     }
172    
173     /*
174     * ms_test
175     * parv[0] = sender prefix
176     * parv[1] = parameter
177     */
178     static void
179     ms_test(struct Client *client_p, struct Client *source_p,
180     int parc, char *parv[])
181     {
182     if (parc == 1)
183     {
184     if (IsServer(source_p))
185     sendto_one(source_p, ":%s NOTICE %s :You are a server, and sent no parameters",
186     me.name, source_p->name);
187     else
188     sendto_one(source_p, ":%s NOTICE %s :You are a remote client, and sent no parameters",
189     me.name, source_p->name);
190     }
191     else
192     {
193     if (IsServer(source_p))
194     sendto_one(source_p, ":%s NOTICE %s :You are a server, and sent parameters: %s",
195     me.name, source_p->name, parv[1]);
196     else
197     sendto_one(source_p, ":%s NOTICE %s :You are a remote client, and sent parameters: %s",
198     me.name, source_p->name, parv[1]);
199     }
200     }
201    
202     /*
203     * mo_test
204     * parv[0] = sender prefix
205     * parv[1] = parameter
206     */
207     static void
208     mo_test(struct Client *client_p, struct Client *source_p,
209     int parc, char *parv[])
210     {
211     if (parc == 1)
212     sendto_one(source_p, ":%s NOTICE %s :You are an operator, and sent no parameters",
213     me.name, source_p->name);
214     else
215     sendto_one(source_p, ":%s NOTICE %s :You are an operator, and sent parameters: %s",
216     me.name, source_p->name, parv[1]);
217     }
218    
219     /* END OF EXAMPLE MODULE */

Properties

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