Remove cruft left behind by removed stats_p_hook.
[seven-1.x.git] / modules / m_pong.c
blob7b01a96292b733ad798734a6dba7c9d884e2e914
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_pong.c: The reply to a ping message.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
25 #include "stdinc.h"
26 #include "ircd.h"
27 #include "s_user.h"
28 #include "client.h"
29 #include "hash.h" /* for find_client() */
30 #include "hook.h"
31 #include "numeric.h"
32 #include "s_conf.h"
33 #include "send.h"
34 #include "channel.h"
35 #include "irc_string.h"
36 #include "msg.h"
37 #include "parse.h"
38 #include "hash.h"
39 #include "modules.h"
41 static int mr_pong(struct Client *, struct Client *, int, const char **);
42 static int ms_pong(struct Client *, struct Client *, int, const char **);
44 struct Message pong_msgtab = {
45 "PONG", 0, 0, 0, MFLG_SLOW | MFLG_UNREG,
46 {{mr_pong, 0}, mg_ignore, mg_ignore, {ms_pong, 2}, mg_ignore, mg_ignore}
49 mapi_clist_av1 pong_clist[] = { &pong_msgtab, NULL };
50 DECLARE_MODULE_AV1(pong, NULL, NULL, pong_clist, NULL, NULL, "$Revision: 108 $");
52 static int
53 ms_pong(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
55 struct Client *target_p;
56 const char *destination;
58 destination = parv[2];
59 source_p->flags &= ~FLAGS_PINGSENT;
61 /* Now attempt to route the PONG, comstud pointed out routable PING
62 * is used for SPING. routable PING should also probably be left in
63 * -Dianora
64 * That being the case, we will route, but only for registered clients (a
65 * case can be made to allow them only from servers). -Shadowfax
67 if(!EmptyString(destination) && !match(destination, me.name) &&
68 irccmp(destination, me.id))
70 if((target_p = find_client(destination)) ||
71 (target_p = find_server(NULL, destination)))
72 sendto_one(target_p, ":%s PONG %s %s",
73 get_id(source_p, target_p), parv[1],
74 get_id(target_p, target_p));
75 else
77 if(!IsDigit(*destination))
78 sendto_one_numeric(source_p, ERR_NOSUCHSERVER,
79 form_str(ERR_NOSUCHSERVER), destination);
80 return 0;
84 /* destination is us, emulate EOB */
85 if(IsServer(source_p) && !HasSentEob(source_p))
87 if(MyConnect(source_p))
88 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
89 "End of burst (emulated) from %s (%d seconds)",
90 source_p->name,
91 (signed int) (CurrentTime - source_p->localClient->firsttime));
92 SetEob(source_p);
93 eob_count++;
94 call_hook(h_server_eob, source_p);
97 return 0;
100 static int
101 mr_pong(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
103 if(parc == 2 && !EmptyString(parv[1]))
105 if(ConfigFileEntry.ping_cookie && source_p->user && source_p->name[0])
107 unsigned long incoming_ping = strtoul(parv[1], NULL, 16);
108 if(incoming_ping)
110 if(source_p->localClient->random_ping == incoming_ping)
112 char buf[USERLEN + 1];
113 strlcpy(buf, source_p->username, sizeof(buf));
114 source_p->flags2 |= FLAGS2_PING_COOKIE;
115 register_local_user(client_p, source_p, buf);
117 else
119 sendto_one(source_p, form_str(ERR_WRONGPONG),
120 me.name, source_p->name,
121 source_p->localClient->random_ping);
122 return 0;
128 else
129 sendto_one(source_p, form_str(ERR_NOORIGIN), me.name, parv[0]);
131 source_p->flags &= ~FLAGS_PINGSENT;
133 return 0;