/[svn]/ircd-hybrid/modules/m_pong.c
ViewVC logotype

Contents of /ircd-hybrid/modules/m_pong.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 442 - (show annotations)
Sat Feb 11 23:14:21 2006 UTC (15 years, 4 months ago) by adx
File MIME type: text/x-chdr
File size: 3552 byte(s)
+ massive rewrite of module init/deinit/version headers,
  we are introducing a new module manager which deals with static
  and dynamic modules exactly the same way. (New possibilities
  include loading/unloading statically compiled modules and
  mixing static/dynamic ones in one build.)

1 /*
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 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "ircd.h"
27 #include "handlers.h"
28 #include "s_conf.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 "msg.h"
36 #include "parse.h"
37 #include "modules.h"
38
39 static void mr_pong(struct Client *, struct Client *, int, char **);
40 static void ms_pong(struct Client *, struct Client *, int, char **);
41
42 struct Message pong_msgtab = {
43 "PONG", 0, 0, 1, 0, MFLG_SLOW | MFLG_UNREG, 0,
44 {mr_pong, m_ignore, ms_pong, m_ignore, m_ignore, m_ignore}
45 };
46
47 INIT_MODULE(m_pong, "$Revision$")
48 {
49 mod_add_cmd(&pong_msgtab);
50 }
51
52 CLEANUP_MODULE
53 {
54 mod_del_cmd(&pong_msgtab);
55 }
56
57 static void
58 ms_pong(struct Client *client_p, struct Client *source_p,
59 int parc, char *parv[])
60 {
61 struct Client *target_p;
62 const char *origin, *destination;
63
64 if (parc < 2 || *parv[1] == '\0')
65 {
66 sendto_one(source_p, form_str(ERR_NOORIGIN),
67 me.name, parv[0]);
68 return;
69 }
70
71 origin = parv[1];
72 destination = parv[2];
73
74 /* Now attempt to route the PONG, comstud pointed out routable PING
75 * is used for SPING. routable PING should also probably be left in
76 * -Dianora
77 * That being the case, we will route, but only for registered clients (a
78 * case can be made to allow them only from servers). -Shadowfax
79 */
80 if (!EmptyString(destination) && !match(destination, me.name) &&
81 irccmp(destination, me.id))
82 {
83 if ((target_p = find_client(destination)) ||
84 (target_p = find_server(destination)))
85 sendto_one(target_p,":%s PONG %s %s",
86 parv[0], origin, destination);
87 else
88 {
89 sendto_one(source_p, form_str(ERR_NOSUCHSERVER),
90 me.name, parv[0], destination);
91 return;
92 }
93 }
94 }
95
96 static void
97 mr_pong(struct Client *client_p, struct Client *source_p,
98 int parc, char *parv[])
99 {
100 if (parc == 2 && *parv[1] != '\0')
101 {
102 if(ConfigFileEntry.ping_cookie && (source_p->flags&FLAGS_GOTUSER) && source_p->name[0])
103 {
104 unsigned long incoming_ping = strtoul(parv[1], NULL, 10);
105 if(incoming_ping)
106 {
107 if(source_p->localClient->random_ping == incoming_ping)
108 {
109 char buf[USERLEN+1];
110 strlcpy(buf, source_p->username, sizeof(buf));
111 SetPingCookie(source_p);
112 register_local_user(client_p, source_p, source_p->name, buf);
113 }
114 else
115 {
116 sendto_one(source_p, form_str(ERR_WRONGPONG), me.name,
117 source_p->name, source_p->localClient->random_ping);
118 return;
119 }
120 }
121 }
122
123 }
124 else
125 sendto_one(source_p, form_str(ERR_NOORIGIN), me.name, parv[0]);
126 }
127

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28