ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.3/contrib/m_services.c
Revision: 512
Committed: Sat Mar 4 16:21:54 2006 UTC (20 years, 5 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/contrib/m_services.c
File size: 12405 byte(s)
Log Message:
- Fixed static build for m_cap()  (fix doesn't need to get
  forward-ported to HEAD)
- Added BS alias for BOTSERV

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 "fdlist.h"
55     #include "irc_string.h"
56     #include "ircd.h"
57     #include "numeric.h"
58     #include "s_conf.h"
59     #include "s_stats.h"
60     #include "s_user.h"
61     #include "whowas.h"
62     #include "s_serv.h"
63     #include "send.h"
64     #include "list.h"
65     #include "channel.h"
66     #include "s_log.h"
67     #include "resv.h"
68     #include "msg.h"
69     #include "parse.h"
70     #include "modules.h"
71     #include "common.h"
72     #include "packet.h"
73     #include "sprintf_irc.h"
74    
75     /* Custom Macros */
76     #define services_function(a,b,c) static void a(struct Client *client_p,\
77     struct Client *source_p, int parc,\
78     char *parv[]) \
79     { deliver_services_msg(b, c, client_p, source_p, parc, parv); }
80    
81     static void mo_svsnick(struct Client *, struct Client *, int, char *[]);
82    
83     static void m_botserv(struct Client *, struct Client *, int, char *[]);
84     static void m_chanserv(struct Client *, struct Client *, int, char *[]);
85     static void m_global(struct Client *, struct Client *, int, char *[]);
86     static void m_helpserv(struct Client *, struct Client *, int, char *[]);
87     static void m_hostserv(struct Client *, struct Client *, int, char *[]);
88     static void m_identify(struct Client *, struct Client *, int, char *[]);
89     static void m_memoserv(struct Client *, struct Client *, int, char *[]);
90     static void m_nickserv(struct Client *, struct Client *, int, char *[]);
91     static void m_operserv(struct Client *, struct Client *, int, char *[]);
92     static void m_seenserv(struct Client *, struct Client *, int, char *[]);
93     static void m_statserv(struct Client *, struct Client *, int, char *[]);
94    
95     static void get_string(int, char *[], char *);
96     static int clean_nick_name(char *, int);
97     static void deliver_services_msg(const char *, const char *, struct Client *,
98     struct Client *, int, char *[]);
99    
100     /* SVS commands */
101     struct Message svsnick_msgtab = {
102     "SVSNICK", 0, 0, 3, 0, MFLG_SLOW, 0,
103     {m_unregistered, m_not_oper, mo_svsnick, mo_svsnick, mo_svsnick, m_ignore}
104     };
105    
106     /* Services */
107     struct Message botserv_msgtab = {
108     "BOTSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
109     {m_unregistered, m_botserv, m_ignore, m_ignore, m_botserv, m_ignore}
110     };
111    
112     struct Message chanserv_msgtab = {
113     "CHANSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
114     {m_unregistered, m_chanserv, m_ignore, m_ignore, m_chanserv, m_ignore}
115     };
116    
117     struct Message global_msgtab = {
118     "GLOBAL", 0, 0, 1, 0, MFLG_SLOW, 0,
119     {m_unregistered, m_global, m_ignore, m_ignore, m_global, m_ignore}
120     };
121    
122     struct Message helpserv_msgtab = {
123     "HELPSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
124     {m_unregistered, m_helpserv, m_ignore, m_ignore, m_helpserv, m_ignore}
125     };
126    
127     struct Message hostserv_msgtab = {
128     "HOSTSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
129     {m_unregistered, m_hostserv, m_ignore, m_ignore, m_hostserv, m_ignore}
130     };
131    
132     struct Message memoserv_msgtab = {
133     "MEMOSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
134     {m_unregistered, m_memoserv, m_ignore, m_ignore, m_memoserv, m_ignore}
135     };
136    
137     struct Message nickserv_msgtab = {
138     "NICKSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
139     {m_unregistered, m_nickserv, m_ignore, m_ignore, m_nickserv, m_ignore}
140     };
141    
142     struct Message operserv_msgtab = {
143     "OPERSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
144     {m_unregistered, m_operserv, m_ignore, m_ignore, m_operserv, m_ignore}
145     };
146    
147     struct Message seenserv_msgtab = {
148     "SEENSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
149     {m_unregistered, m_seenserv, m_ignore, m_ignore, m_seenserv, m_ignore}
150     };
151    
152     struct Message statserv_msgtab = {
153     "STATSERV", 0, 0, 1, 0, MFLG_SLOW, 0,
154     {m_unregistered, m_statserv, m_ignore, m_ignore, m_statserv, m_ignore}
155     };
156    
157     /* Short-hand aliases for NickServ, ChanServ, MemoServ and OperServ */
158     struct Message cs_msgtab = {
159     "CS", 0, 0, 1, 0, MFLG_SLOW, 0,
160     {m_unregistered, m_chanserv, m_ignore, m_ignore, m_chanserv, m_ignore}
161     };
162    
163     struct Message identify_msgtab = {
164     "IDENTIFY", 0, 0, 0, 2, MFLG_SLOW, 0,
165     {m_unregistered, m_identify, m_ignore, m_ignore, m_identify, m_ignore}
166     };
167    
168     struct Message ms_msgtab = {
169     "MS", 0, 0, 1, 0, MFLG_SLOW, 0,
170     {m_unregistered, m_memoserv, m_ignore, m_ignore, m_memoserv, m_ignore}
171     };
172    
173     struct Message ns_msgtab = {
174     "NS", 0, 0, 1, 0, MFLG_SLOW, 0,
175     {m_unregistered, m_nickserv, m_ignore, m_ignore, m_nickserv, m_ignore}
176     };
177    
178     struct Message os_msgtab = {
179     "OS", 0, 0, 1, 0, MFLG_SLOW, 0,
180     {m_unregistered, m_operserv, m_ignore, m_ignore, m_operserv, m_ignore}
181     };
182    
183 michael 512 struct Message bs_msgtab = {
184     "BS", 0, 0, 1, 0, MFLG_SLOW, 0,
185     {m_unregistered, m_botserv, m_ignore, m_ignore, m_botserv, m_ignore}
186     };
187    
188 adx 30 #ifndef STATIC_MODULES
189     void
190     _modinit(void)
191     {
192     mod_add_cmd(&svsnick_msgtab);
193     mod_add_cmd(&botserv_msgtab);
194     mod_add_cmd(&chanserv_msgtab);
195     mod_add_cmd(&global_msgtab);
196     mod_add_cmd(&helpserv_msgtab);
197     mod_add_cmd(&hostserv_msgtab);
198     mod_add_cmd(&identify_msgtab);
199     mod_add_cmd(&memoserv_msgtab);
200     mod_add_cmd(&nickserv_msgtab);
201     mod_add_cmd(&operserv_msgtab);
202     mod_add_cmd(&seenserv_msgtab);
203     mod_add_cmd(&statserv_msgtab);
204 michael 512 mod_add_cmd(&bs_msgtab);
205 adx 30 mod_add_cmd(&ns_msgtab);
206     mod_add_cmd(&cs_msgtab);
207     mod_add_cmd(&ms_msgtab);
208     mod_add_cmd(&os_msgtab);
209     }
210    
211     void
212     _moddeinit(void)
213     {
214     mod_del_cmd(&svsnick_msgtab);
215     mod_del_cmd(&botserv_msgtab);
216     mod_del_cmd(&chanserv_msgtab);
217     mod_del_cmd(&global_msgtab);
218     mod_del_cmd(&helpserv_msgtab);
219     mod_del_cmd(&hostserv_msgtab);
220     mod_del_cmd(&identify_msgtab);
221     mod_del_cmd(&memoserv_msgtab);
222     mod_del_cmd(&nickserv_msgtab);
223     mod_del_cmd(&operserv_msgtab);
224     mod_del_cmd(&seenserv_msgtab);
225     mod_del_cmd(&statserv_msgtab);
226 michael 512 mod_del_cmd(&bs_msgtab);
227 adx 30 mod_del_cmd(&ns_msgtab);
228     mod_del_cmd(&cs_msgtab);
229     mod_del_cmd(&ms_msgtab);
230     mod_del_cmd(&os_msgtab);
231     }
232    
233 knight 31 const char *_version = "$Revision$";
234 adx 30 #endif
235    
236     /*
237     * mo_svsnick()
238     *
239     * parv[0] = sender prefix
240     * parv[1] = user to force
241     * parv[2] = nick to force them to
242     */
243     static void
244     mo_svsnick(struct Client *client_p, struct Client *source_p,
245     int parc, char *parv[])
246     {
247     char newnick[NICKLEN];
248     struct Client *target_p = NULL;
249    
250     if (MyClient(source_p) && !IsOperAdmin(source_p))
251     {
252     sendto_one(source_p, form_str(ERR_NOPRIVS),
253     me.name, parv[0], "SVSNICK");
254     return;
255     }
256    
257     if (parc < 3 || *parv[2] == '\0')
258     {
259     sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
260     me.name, parv[0], "SVSNICK");
261     return;
262     }
263    
264     if ((target_p = find_person(client_p, parv[1])) == NULL)
265     {
266     sendto_one(source_p, form_str(ERR_NOSUCHNICK),
267     me.name, parv[0], parv[1]);
268     return;
269     }
270    
271     /* terminate nick to NICKLEN */
272     strlcpy(newnick, parv[2], sizeof(newnick));
273    
274     if (!clean_nick_name(newnick, 1))
275     {
276     if (IsClient(source_p))
277     sendto_one(source_p, ":%s NOTICE %s :*** Notice -- Invalid new ",
278     "nickname: %s", me.name, parv[0], newnick);
279     return;
280     }
281    
282     if (find_client(newnick) != NULL)
283     {
284     if (IsClient(source_p))
285     sendto_one(source_p, ":%s NOTICE %s :*** Notice -- Nickname %s is "
286     "already in use", me.name, parv[0], newnick);
287     return;
288     }
289    
290     if (MyConnect(target_p))
291     change_local_nick(&me, target_p, newnick);
292     else
293     sendto_one(target_p, ":%s ENCAP %s SVSNICK %s %s",
294     me.name, target_p->servptr->name, ID(target_p), newnick);
295     }
296    
297     /*
298     * These generate the services functions through
299     * a macro.
300     */
301     services_function(m_botserv, "BotServ", "BOTSERV" )
302     services_function(m_chanserv, "ChanServ", "CHANSERV")
303     services_function(m_global, "Global", "GLOBAL" )
304     services_function(m_helpserv, "HelpServ", "HELPSERV")
305     services_function(m_hostserv, "HostServ", "HOSTSERV")
306     services_function(m_memoserv, "MemoServ", "MEMOSERV")
307     services_function(m_nickserv, "NickServ", "NICKSERV")
308     services_function(m_operserv, "OperServ", "OPERSERV")
309     services_function(m_seenserv, "SeenServ", "SEENSERV")
310     services_function(m_statserv, "StatServ", "STATSERV")
311    
312     /*
313     * get_string()
314     *
315     * Reverse the array parv back into a normal string assuming
316     * there are "parc" indicies in the array.
317     *
318     * Originally GetString() written by sidewndr.
319     * Modified by Michael for use with hybrid-7.
320     */
321     static void
322     get_string(int parc, char *parv[], char *buf)
323     {
324     int ii = 0;
325     int bw = 0;
326    
327     for (; ii < parc; ++ii)
328     bw += ircsprintf(buf+bw, "%s ", parv[ii]);
329     buf[bw-1] = '\0';
330     }
331    
332     /*
333     * clean_nick_name()
334     *
335     * input - nickname
336     * output - none
337     * side effects - walks through the nickname, returning 0 if erroneous
338     */
339     static int
340     clean_nick_name(char *nick, int local)
341     {
342     assert(nick);
343    
344     /* nicks can't start with a digit or - or be 0 length */
345     /* This closer duplicates behaviour of hybrid-6 */
346    
347     if (*nick == '-' || (IsDigit(*nick) && local) || *nick == '\0')
348     return 0;
349    
350     for (; *nick; ++nick)
351     if (!IsNickChar(*nick))
352     return 0;
353    
354     return 1;
355     }
356    
357     /*
358     * m_identify()
359     *
360     * parv[0] = sender prefix
361     * parv[1] = NickServ Password or Channel
362     * parv[2] = ChanServ Password
363     */
364     static void
365     m_identify(struct Client *client_p, struct Client *source_p,
366     int parc, char *parv[])
367     {
368     struct Client *target_p = NULL;
369    
370     switch (parc)
371     {
372     case 2:
373     if (!(target_p = find_server(SERVICES_NAME)))
374     sendto_one(source_p, form_str(ERR_SERVICESDOWN),
375     me.name, source_p->name);
376     else
377     sendto_one(target_p, ":%s PRIVMSG NickServ@%s :IDENTIFY %s",
378     source_p->name, SERVICES_NAME, parv[1]);
379     break;
380    
381     case 3:
382     if (!(target_p = find_server(SERVICES_NAME)))
383     sendto_one(source_p, form_str(ERR_SERVICESDOWN),
384     me.name, source_p->name);
385     else
386     sendto_one(target_p, ":%s PRIVMSG ChanServ@%s :IDENTIFY %s %s",
387     source_p->name, SERVICES_NAME, parv[1], parv[2]);
388     break;
389    
390     default:
391     sendto_one(source_p, ":%s NOTICE %s :Syntax: IDENTIFY <password> "
392     "- for nickname", me.name, source_p->name);
393     sendto_one(source_p, ":%s NOTICE %s :Syntax: IDENTIFY <channel> "
394     "<password> - for channel", me.name, source_p->name);
395     break;
396     }
397     }
398    
399     /*
400     * deliver_services_msg()
401     *
402     * parv[0] = sender prefix
403     * servmsg = message for services (utilising GetString())
404     *
405     * Borrowed from HybServ -- knight-
406     */
407     static void
408     deliver_services_msg(const char *service, const char *command,
409     struct Client *client_p,
410     struct Client *source_p, int parc, char *parv[])
411     {
412     struct Client *target_p = NULL;
413     char buf[IRCD_BUFSIZE] = { '\0' };
414    
415     if (parc < 2 || *parv[1] == '\0')
416     {
417     sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
418     me.name, source_p->name, command);
419     return;
420     }
421    
422     if (!(target_p = find_server(SERVICES_NAME)))
423     sendto_one(source_p, form_str(ERR_SERVICESDOWN),
424     me.name, source_p->name);
425     else
426     {
427     get_string(parc - 1, parv + 1, buf);
428     sendto_one(target_p, ":%s PRIVMSG %s@%s :%s",
429     source_p->name, service, SERVICES_NAME, buf);
430     }
431     }

Properties

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