ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_pong.c
Revision: 4588
Committed: Tue Aug 26 15:59:07 2014 UTC (11 years ago) by michael
Content type: text/x-csrc
File size: 4417 byte(s)
Log Message:
- Renamed 'localClient' Client structure member to just 'connection'

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2014 ircd-hybrid development team
5 *
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 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file m_pong.c
23 * \brief Includes required functions for processing the PONG command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "ircd.h"
29 #include "user.h"
30 #include "client.h"
31 #include "hash.h"
32 #include "numeric.h"
33 #include "conf.h"
34 #include "send.h"
35 #include "irc_string.h"
36 #include "parse.h"
37 #include "modules.h"
38
39
40 /*! \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 static int
53 ms_pong(struct Client *source_p, int parc, char *parv[])
54 {
55 struct Client *target_p;
56 const char *origin, *destination;
57
58 if (parc < 2 || EmptyString(parv[1]))
59 {
60 sendto_one_numeric(source_p, &me, ERR_NOORIGIN);
61 return 0;
62 }
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 if (!EmptyString(destination) && match(destination, me.name) &&
74 irccmp(destination, me.id))
75 {
76 if ((target_p = hash_find_client(destination)) ||
77 (target_p = hash_find_server(destination)))
78 sendto_one(target_p, ":%s PONG %s %s",
79 source_p->name, origin, destination);
80 else
81 sendto_one_numeric(source_p, &me, ERR_NOSUCHSERVER, destination);
82 }
83
84 return 0;
85 }
86
87 /*! \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 static int
99 mr_pong(struct Client *source_p, int parc, char *parv[])
100 {
101 assert(MyConnect(source_p));
102
103 if (parc == 2 && !EmptyString(parv[1]))
104 {
105 if (ConfigGeneral.ping_cookie && !source_p->connection->registration)
106 {
107 unsigned int incoming_ping = strtoul(parv[1], NULL, 10);
108
109 if (incoming_ping)
110 {
111 if (source_p->connection->random_ping == incoming_ping)
112 {
113 SetPingCookie(source_p);
114 register_local_user(source_p);
115 }
116 else
117 sendto_one_numeric(source_p, &me, ERR_WRONGPONG,
118 source_p->connection->random_ping);
119 }
120 }
121 }
122 else
123 sendto_one_numeric(source_p, &me, ERR_NOORIGIN);
124
125 return 0;
126 }
127
128 static struct Message pong_msgtab =
129 {
130 "PONG", NULL, 0, 0, 1, MAXPARA, MFLG_SLOW, 0,
131 { mr_pong, m_ignore, ms_pong, m_ignore, m_ignore, m_ignore }
132 };
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 struct module module_entry =
147 {
148 .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