ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_pong.c
Revision: 1230
Committed: Thu Sep 22 19:41:19 2011 UTC (15 years ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_pong.c
File size: 3693 byte(s)
Log Message:
- cleanup module loader. Make module api more flexible

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * m_pong.c: The reply to a ping message.
4     *
5     * Copyright (C) 2002 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     #include "stdinc.h"
26 michael 1011 #include "list.h"
27 adx 30 #include "ircd.h"
28     #include "handlers.h"
29     #include "s_user.h"
30     #include "client.h"
31     #include "hash.h" /* for find_client() */
32     #include "numeric.h"
33     #include "s_conf.h"
34     #include "send.h"
35     #include "irc_string.h"
36     #include "msg.h"
37     #include "parse.h"
38     #include "modules.h"
39    
40    
41     static void
42     ms_pong(struct Client *client_p, struct Client *source_p,
43     int parc, char *parv[])
44     {
45     struct Client *target_p;
46     const char *origin, *destination;
47    
48 michael 1121 if (parc < 2 || EmptyString(parv[1]))
49 adx 30 {
50     sendto_one(source_p, form_str(ERR_NOORIGIN),
51 michael 1230 me.name, source_p->name);
52 adx 30 return;
53     }
54    
55     origin = parv[1];
56     destination = parv[2];
57    
58     /* Now attempt to route the PONG, comstud pointed out routable PING
59     * is used for SPING. routable PING should also probably be left in
60     * -Dianora
61     * That being the case, we will route, but only for registered clients (a
62     * case can be made to allow them only from servers). -Shadowfax
63     */
64     if (!EmptyString(destination) && !match(destination, me.name) &&
65     irccmp(destination, me.id))
66     {
67 michael 1169 if ((target_p = hash_find_client(destination)) ||
68     (target_p = hash_find_server(destination)))
69     sendto_one(target_p, ":%s PONG %s %s",
70 michael 1230 source_p->name, origin, destination);
71 michael 1169 else
72     {
73     sendto_one(source_p, form_str(ERR_NOSUCHSERVER),
74 michael 1230 me.name, source_p->name, destination);
75 michael 1169 return;
76     }
77 adx 30 }
78     }
79    
80     static void
81     mr_pong(struct Client *client_p, struct Client *source_p,
82     int parc, char *parv[])
83     {
84 michael 503 assert(source_p == client_p);
85    
86 adx 30 if (parc == 2 && *parv[1] != '\0')
87     {
88 michael 503 if (ConfigFileEntry.ping_cookie && !source_p->localClient->registration)
89 adx 30 {
90 michael 982 unsigned int incoming_ping = strtoul(parv[1], NULL, 10);
91 michael 503
92     if (incoming_ping)
93     {
94     if (source_p->localClient->random_ping == incoming_ping)
95     {
96     SetPingCookie(source_p);
97 michael 1080 register_local_user(source_p);
98 michael 503 }
99     else
100     {
101     sendto_one(source_p, form_str(ERR_WRONGPONG), me.name,
102     source_p->name, source_p->localClient->random_ping);
103     return;
104     }
105 adx 30 }
106     }
107 michael 503 }
108 adx 30 else
109 michael 1230 sendto_one(source_p, form_str(ERR_NOORIGIN),
110     me.name, source_p->name);
111 adx 30 }
112 michael 1230
113     static struct Message pong_msgtab = {
114     "PONG", 0, 0, 1, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
115     {mr_pong, m_ignore, ms_pong, m_ignore, m_ignore, m_ignore}
116     };
117    
118     static void
119     module_init(void)
120     {
121     mod_add_cmd(&pong_msgtab);
122     }
123    
124     static void
125     module_exit(void)
126     {
127     mod_del_cmd(&pong_msgtab);
128     }
129    
130     struct module module_entry = {
131     .node = { NULL, NULL, NULL },
132     .name = NULL,
133     .version = "$Revision$",
134     .handle = NULL,
135     .modinit = module_init,
136     .modexit = module_exit,
137     .flags = 0
138     };

Properties

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