ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_pong.c
Revision: 4565
Committed: Sun Aug 24 10:27:40 2014 UTC (11 years ago) by michael
Content type: text/x-csrc
File size: 4420 byte(s)
Log Message:
- Update GPL 2 license headers

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 2820 * Copyright (c) 1997-2014 ircd-hybrid development team
5 adx 30 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 2820 /*! \file m_pong.c
23     * \brief Includes required functions for processing the PONG command.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28     #include "ircd.h"
29 michael 3347 #include "user.h"
30 adx 30 #include "client.h"
31 michael 2820 #include "hash.h"
32 adx 30 #include "numeric.h"
33 michael 1309 #include "conf.h"
34 adx 30 #include "send.h"
35     #include "irc_string.h"
36     #include "parse.h"
37     #include "modules.h"
38    
39    
40 michael 3346 /*! \brief PONG command handler
41     *
42     * \param source_p Pointer to allocated Client struct from which the message
43     * originally comes from. This can be a local or remote client.
44     * \param parc Integer holding the number of supplied arguments.
45     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
46     * pointers.
47     * \note Valid arguments for this command are:
48     * - parv[0] = command
49     * - parv[1] = origin
50     * - parv[2] = destination
51     */
52 michael 2820 static int
53 michael 3156 ms_pong(struct Client *source_p, int parc, char *parv[])
54 adx 30 {
55     struct Client *target_p;
56     const char *origin, *destination;
57    
58 michael 1121 if (parc < 2 || EmptyString(parv[1]))
59 adx 30 {
60 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOORIGIN);
61 michael 2820 return 0;
62 adx 30 }
63    
64     origin = parv[1];
65     destination = parv[2];
66    
67     /* Now attempt to route the PONG, comstud pointed out routable PING
68     * is used for SPING. routable PING should also probably be left in
69     * -Dianora
70     * That being the case, we will route, but only for registered clients (a
71     * case can be made to allow them only from servers). -Shadowfax
72     */
73 michael 1652 if (!EmptyString(destination) && match(destination, me.name) &&
74 adx 30 irccmp(destination, me.id))
75     {
76 michael 1169 if ((target_p = hash_find_client(destination)) ||
77     (target_p = hash_find_server(destination)))
78     sendto_one(target_p, ":%s PONG %s %s",
79 michael 1230 source_p->name, origin, destination);
80 michael 1169 else
81 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOSUCHSERVER, destination);
82 adx 30 }
83 michael 2820
84     return 0;
85 adx 30 }
86    
87 michael 3346 /*! \brief PONG command handler
88     *
89     * \param source_p Pointer to allocated Client struct from which the message
90     * originally comes from. This can be a local or remote client.
91     * \param parc Integer holding the number of supplied arguments.
92     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
93     * pointers.
94     * \note Valid arguments for this command are:
95     * - parv[0] = command
96     * - parv[1] = origin/ping cookie
97     */
98 michael 2820 static int
99 michael 3156 mr_pong(struct Client *source_p, int parc, char *parv[])
100 adx 30 {
101 michael 3156 assert(MyConnect(source_p));
102 michael 503
103 michael 3331 if (parc == 2 && !EmptyString(parv[1]))
104 adx 30 {
105 michael 4340 if (ConfigGeneral.ping_cookie && !source_p->localClient->registration)
106 adx 30 {
107 michael 982 unsigned int incoming_ping = strtoul(parv[1], NULL, 10);
108 michael 503
109     if (incoming_ping)
110     {
111     if (source_p->localClient->random_ping == incoming_ping)
112     {
113     SetPingCookie(source_p);
114 michael 1080 register_local_user(source_p);
115 michael 503 }
116     else
117 michael 3109 sendto_one_numeric(source_p, &me, ERR_WRONGPONG,
118     source_p->localClient->random_ping);
119 adx 30 }
120     }
121 michael 503 }
122 adx 30 else
123 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOORIGIN);
124    
125 michael 2820 return 0;
126 adx 30 }
127 michael 1230
128 michael 2820 static struct Message pong_msgtab =
129     {
130 michael 4545 "PONG", NULL, 0, 0, 1, MAXPARA, MFLG_SLOW, 0,
131 michael 2820 { mr_pong, m_ignore, ms_pong, m_ignore, m_ignore, m_ignore }
132 michael 1230 };
133    
134     static void
135     module_init(void)
136     {
137     mod_add_cmd(&pong_msgtab);
138     }
139    
140     static void
141     module_exit(void)
142     {
143     mod_del_cmd(&pong_msgtab);
144     }
145    
146 michael 2820 struct module module_entry =
147     {
148 michael 1230 .node = { NULL, NULL, NULL },
149     .name = NULL,
150     .version = "$Revision$",
151     .handle = NULL,
152     .modinit = module_init,
153     .modexit = module_exit,
154     .flags = 0
155     };

Properties

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