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

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * m_services.c: SVS commands and Services support
4     *
5     * Copyright (C) 2005 by the past and present ircd coders, and others.
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     *
22 knight 31 * $Id$
23 adx 30 */
24     /*
25     *
26     * With code from 'bane' the URL following is valid as of this date.
27     * http://hybserv2.net/file/trunk/contrib/hybrid_services.c
28     *
29     *
30     * Copyright (C) 2002, 2003, 2004, 2005 by Dragan 'bane' Dosen and the
31     * Hybrid Development Team.
32     *
33     * Based on m_services.c, originally from bahamut ircd.
34     *
35     * Contact info:
36     *
37     * E-mail : bane@idolnet.org
38     * IRC : (*) bane, idolNET, irc.idolnet.org, #twilight_zone
39     */
40    
41     /* MODULE CONFIGURATION FOLLOWS -- please read!! */
42    
43     /* Change this to the name of your services server
44     * otherwise the services aliases will not work!
45     */
46     #define SERVICES_NAME "services.yournet.net"
47    
48     /* END OF MODULE CONFIGURATION */
49    
50     #include "stdinc.h"
51     #include "handlers.h"
52     #include "client.h"
53     #include "hash.h"
54     #include "ircd.h"
55     #include "numeric.h"
56     #include "s_conf.h"
57     #include "s_stats.h"
58     #include "s_user.h"
59     #include "whowas.h"
60     #include "s_serv.h"
61     #include "send.h"
62     #include "channel.h"
63     #include "resv.h"
64     #include "msg.h"
65     #include "parse.h"
66     #include "modules.h"
67     #include "common.h"
68     #include "packet.h"
69    
70     /* Custom Macros */
71     #define services_function(a,b,c) static void a(struct Client *client_p,\
72     struct Client *source_p, int parc,\
73     char *parv[]) \
74     { deliver_services_msg(b, c, client_p, source_p, parc, parv); }
75    
76     static void mo_svsnick(struct Client *, struct Client *, int, char *[]);
77    
78     static void m_botserv(struct Client *, struct Client *, int, char *[]);
79     static void m_chanserv(struct Client *, struct Client *, int, char *[]);
80     static void m_global(struct Client *, struct Client *, int, char *[]);
81     static void m_helpserv(struct Client *, struct Client *, int, char *[]);
82     static void m_hostserv(struct Client *, struct Client *, int, char *[]);
83     static void m_identify(struct Client *, struct Client *, int, char *[]);
84     static void m_memoserv(struct Client *, struct Client *, int, char *[]);
85     static void m_nickserv(struct Client *, struct Client *, int, char *[]);
86     static void m_operserv(struct Client *, struct Client *, int, char *[]);
87     static void m_seenserv(struct Client *, struct Client *, int, char *[]);
88     static void m_statserv(struct Client *, struct Client *, int, char *[]);
89    
90     static void get_string(int, char *[], char *);
91     static int clean_nick_name(char *, int);
92     static void deliver_services_msg(const char *, const char *, struct Client *,
93     struct Client *, int, char *[]);
94    
95     /* SVS commands */
96     struct Message svsnick_msgtab = {
97     "SVSNICK", 0, 0, 3, 0, MFLG_SLOW, 0,
98     {m_unregistered, m_not_oper, mo_svsnick, mo_svsnick, mo_svsnick, m_ignore}
99     };
100    
101     /* Services */
102     struct Message botserv_msgtab = {
103     "BOTSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
104     {m_unregistered, m_botserv, m_ignore, m_ignore, m_botserv, m_ignore}
105     };
106    
107     struct Message chanserv_msgtab = {
108     "CHANSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
109     {m_unregistered, m_chanserv, m_ignore, m_ignore, m_chanserv, m_ignore}
110     };
111    
112     struct Message global_msgtab = {
113     "GLOBAL", 0, 0, 1, 0, MFLG_SLOW, 0,
114     {m_unregistered, m_global, m_ignore, m_ignore, m_global, m_ignore}
115     };
116    
117     struct Message helpserv_msgtab = {
118     "HELPSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
119     {m_unregistered, m_helpserv, m_ignore, m_ignore, m_helpserv, m_ignore}
120     };
121    
122     struct Message hostserv_msgtab = {
123     "HOSTSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
124     {m_unregistered, m_hostserv, m_ignore, m_ignore, m_hostserv, m_ignore}
125     };
126    
127     struct Message memoserv_msgtab = {
128     "MEMOSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
129     {m_unregistered, m_memoserv, m_ignore, m_ignore, m_memoserv, m_ignore}
130     };
131    
132     struct Message nickserv_msgtab = {
133     "NICKSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
134     {m_unregistered, m_nickserv, m_ignore, m_ignore, m_nickserv, m_ignore}
135     };
136    
137     struct Message operserv_msgtab = {
138     "OPERSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
139     {m_unregistered, m_operserv, m_ignore, m_ignore, m_operserv, m_ignore}
140     };
141    
142     struct Message seenserv_msgtab = {
143     "SEENSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
144     {m_unregistered, m_seenserv, m_ignore, m_ignore, m_seenserv, m_ignore}
145     };
146    
147     struct Message statserv_msgtab = {
148     "STATSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
149     {m_unregistered, m_statserv, m_ignore, m_ignore, m_statserv, m_ignore}
150     };
151    
152     /* Short-hand aliases for NickServ, ChanServ, MemoServ and OperServ */
153     struct Message cs_msgtab = {
154     "CS", 0, 0, 1, 0, MFLG_SLOW, 0,
155     {m_unregistered, m_chanserv, m_ignore, m_ignore, m_chanserv, m_ignore}
156     };
157    
158     struct Message identify_msgtab = {
159     "IDENTIFY", 0, 0, 0, 2, MFLG_SLOW, 0,
160     {m_unregistered, m_identify, m_ignore, m_ignore, m_identify, m_ignore}
161     };
162    
163     struct Message ms_msgtab = {
164     "MS", 0, 0, 1, 0, MFLG_SLOW, 0,
165     {m_unregistered, m_memoserv, m_ignore, m_ignore, m_memoserv, m_ignore}
166     };
167    
168     struct Message ns_msgtab = {
169     "NS", 0, 0, 1, 0, MFLG_SLOW, 0,
170     {m_unregistered, m_nickserv, m_ignore, m_ignore, m_nickserv, m_ignore}
171     };
172    
173     struct Message os_msgtab = {
174     "OS", 0, 0, 1, 0, MFLG_SLOW, 0,
175     {m_unregistered, m_operserv, m_ignore, m_ignore, m_operserv, m_ignore}
176     };
177    
178     #ifndef STATIC_MODULES
179     void
180     _modinit(void)
181     {
182     mod_add_cmd(&svsnick_msgtab);
183     mod_add_cmd(&botserv_msgtab);
184     mod_add_cmd(&chanserv_msgtab);
185     mod_add_cmd(&global_msgtab);
186     mod_add_cmd(&helpserv_msgtab);
187     mod_add_cmd(&hostserv_msgtab);
188     mod_add_cmd(&identify_msgtab);
189     mod_add_cmd(&memoserv_msgtab);
190     mod_add_cmd(&nickserv_msgtab);
191     mod_add_cmd(&operserv_msgtab);
192     mod_add_cmd(&seenserv_msgtab);
193     mod_add_cmd(&statserv_msgtab);
194     mod_add_cmd(&ns_msgtab);
195     mod_add_cmd(&cs_msgtab);
196     mod_add_cmd(&ms_msgtab);
197     mod_add_cmd(&os_msgtab);
198     }
199    
200     void
201     _moddeinit(void)
202     {
203     mod_del_cmd(&svsnick_msgtab);
204     mod_del_cmd(&botserv_msgtab);
205     mod_del_cmd(&chanserv_msgtab);
206     mod_del_cmd(&global_msgtab);
207     mod_del_cmd(&helpserv_msgtab);
208     mod_del_cmd(&hostserv_msgtab);
209     mod_del_cmd(&identify_msgtab);
210     mod_del_cmd(&memoserv_msgtab);
211     mod_del_cmd(&nickserv_msgtab);
212     mod_del_cmd(&operserv_msgtab);
213     mod_del_cmd(&seenserv_msgtab);
214     mod_del_cmd(&statserv_msgtab);
215     mod_del_cmd(&ns_msgtab);
216     mod_del_cmd(&cs_msgtab);
217     mod_del_cmd(&ms_msgtab);
218     mod_del_cmd(&os_msgtab);
219     }
220    
221 knight 31 const char *_version = "$Revision$";
222 adx 30 #endif
223    
224     /*
225     * mo_svsnick()
226     *
227     * parv[0] = sender prefix
228     * parv[1] = user to force
229     * parv[2] = nick to force them to
230     */
231     static void
232     mo_svsnick(struct Client *client_p, struct Client *source_p,
233     int parc, char *parv[])
234     {
235     char newnick[NICKLEN];
236     struct Client *target_p = NULL;
237    
238     if (MyClient(source_p) && !IsOperAdmin(source_p))
239     {
240     sendto_one(source_p, form_str(ERR_NOPRIVS),
241     me.name, parv[0], "SVSNICK");
242     return;
243     }
244    
245     if (parc < 3 || *parv[2] == '\0')
246     {
247     sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
248     me.name, parv[0], "SVSNICK");
249     return;
250     }
251    
252     if ((target_p = find_person(client_p, parv[1])) == NULL)
253     {
254     sendto_one(source_p, form_str(ERR_NOSUCHNICK),
255     me.name, parv[0], parv[1]);
256     return;
257     }
258    
259     /* terminate nick to NICKLEN */
260     strlcpy(newnick, parv[2], sizeof(newnick));
261    
262     if (!clean_nick_name(newnick, 1))
263     {
264     if (IsClient(source_p))
265     sendto_one(source_p, ":%s NOTICE %s :*** Notice -- Invalid new ",
266     "nickname: %s", me.name, parv[0], newnick);
267     return;
268     }
269    
270     if (find_client(newnick) != NULL)
271     {
272     if (IsClient(source_p))
273     sendto_one(source_p, ":%s NOTICE %s :*** Notice -- Nickname %s is "
274     "already in use", me.name, parv[0], newnick);
275     return;
276     }
277    
278     if (MyConnect(target_p))
279     change_local_nick(&me, target_p, newnick);
280     else
281     sendto_one(target_p, ":%s ENCAP %s SVSNICK %s %s",
282     me.name, target_p->servptr->name, ID(target_p), newnick);
283     }
284    
285     /*
286     * These generate the services functions through
287     * a macro.
288     */
289     services_function(m_botserv, "BotServ", "BOTSERV" )
290     services_function(m_chanserv, "ChanServ", "CHANSERV")
291     services_function(m_global, "Global", "GLOBAL" )
292     services_function(m_helpserv, "HelpServ", "HELPSERV")
293     services_function(m_hostserv, "HostServ", "HOSTSERV")
294     services_function(m_memoserv, "MemoServ", "MEMOSERV")
295     services_function(m_nickserv, "NickServ", "NICKSERV")
296     services_function(m_operserv, "OperServ", "OPERSERV")
297     services_function(m_seenserv, "SeenServ", "SEENSERV")
298     services_function(m_statserv, "StatServ", "STATSERV")
299    
300     /*
301     * get_string()
302     *
303     * Reverse the array parv back into a normal string assuming
304     * there are "parc" indicies in the array.
305     *
306     * Originally GetString() written by sidewndr.
307     * Modified by Michael for use with hybrid-7.
308     */
309     static void
310     get_string(int parc, char *parv[], char *buf)
311     {
312     int ii = 0;
313     int bw = 0;
314    
315     for (; ii < parc; ++ii)
316     bw += ircsprintf(buf+bw, "%s ", parv[ii]);
317     buf[bw-1] = '\0';
318     }
319    
320     /*
321     * clean_nick_name()
322     *
323     * input - nickname
324     * output - none
325     * side effects - walks through the nickname, returning 0 if erroneous
326     */
327     static int
328     clean_nick_name(char *nick, int local)
329     {
330     assert(nick);
331    
332     /* nicks can't start with a digit or - or be 0 length */
333     /* This closer duplicates behaviour of hybrid-6 */
334    
335     if (*nick == '-' || (IsDigit(*nick) && local) || *nick == '\0')
336     return 0;
337    
338     for (; *nick; ++nick)
339     if (!IsNickChar(*nick))
340     return 0;
341    
342     return 1;
343     }
344    
345     /*
346     * m_identify()
347     *
348     * parv[0] = sender prefix
349     * parv[1] = NickServ Password or Channel
350     * parv[2] = ChanServ Password
351     */
352     static void
353     m_identify(struct Client *client_p, struct Client *source_p,
354     int parc, char *parv[])
355     {
356     struct Client *target_p = NULL;
357    
358     switch (parc)
359     {
360     case 2:
361     if (!(target_p = find_server(SERVICES_NAME)))
362     sendto_one(source_p, form_str(ERR_SERVICESDOWN),
363     me.name, source_p->name);
364     else
365     sendto_one(target_p, ":%s PRIVMSG NickServ@%s :IDENTIFY %s",
366     source_p->name, SERVICES_NAME, parv[1]);
367     break;
368    
369     case 3:
370     if (!(target_p = find_server(SERVICES_NAME)))
371     sendto_one(source_p, form_str(ERR_SERVICESDOWN),
372     me.name, source_p->name);
373     else
374     sendto_one(target_p, ":%s PRIVMSG ChanServ@%s :IDENTIFY %s %s",
375     source_p->name, SERVICES_NAME, parv[1], parv[2]);
376     break;
377    
378     default:
379     sendto_one(source_p, ":%s NOTICE %s :Syntax: IDENTIFY <password> "
380     "- for nickname", me.name, source_p->name);
381     sendto_one(source_p, ":%s NOTICE %s :Syntax: IDENTIFY <channel> "
382     "<password> - for channel", me.name, source_p->name);
383     break;
384     }
385     }
386    
387     /*
388     * deliver_services_msg()
389     *
390     * parv[0] = sender prefix
391     * servmsg = message for services (utilising GetString())
392     *
393     * Borrowed from HybServ -- knight-
394     */
395     static void
396     deliver_services_msg(const char *service, const char *command,
397     struct Client *client_p,
398     struct Client *source_p, int parc, char *parv[])
399     {
400     struct Client *target_p = NULL;
401     char buf[IRCD_BUFSIZE] = { '\0' };
402    
403     if (parc < 2 || *parv[1] == '\0')
404     {
405     sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
406     me.name, source_p->name, command);
407     return;
408     }
409    
410     if (!(target_p = find_server(SERVICES_NAME)))
411     sendto_one(source_p, form_str(ERR_SERVICESDOWN),
412     me.name, source_p->name);
413     else
414     {
415     get_string(parc - 1, parv + 1, buf);
416     sendto_one(target_p, ":%s PRIVMSG %s@%s :%s",
417     source_p->name, service, SERVICES_NAME, buf);
418     }
419     }

Properties

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