]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * m_pong.c: The reply to a ping message. | |
4 | * | |
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 | |
8 | * | |
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. | |
13 | * | |
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. | |
18 | * | |
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 | |
212380e3 AC |
23 | */ |
24 | ||
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" | |
4562c604 | 35 | #include "match.h" |
212380e3 AC |
36 | #include "msg.h" |
37 | #include "parse.h" | |
38 | #include "hash.h" | |
39 | #include "modules.h" | |
40 | ||
eeabf33a EM |
41 | static const char pong_desc[] = "Provides the PONG command to respond to a PING message"; |
42 | ||
3c7d6fcc EM |
43 | static void mr_pong(struct MsgBuf *, struct Client *, struct Client *, int, const char **); |
44 | static void ms_pong(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
212380e3 AC |
45 | |
46 | struct Message pong_msgtab = { | |
7baa37a9 | 47 | "PONG", 0, 0, 0, 0, |
212380e3 AC |
48 | {{mr_pong, 0}, mg_ignore, mg_ignore, {ms_pong, 2}, mg_ignore, mg_ignore} |
49 | }; | |
50 | ||
51 | mapi_clist_av1 pong_clist[] = { &pong_msgtab, NULL }; | |
eeabf33a | 52 | |
d5d35409 | 53 | DECLARE_MODULE_AV2(pong, NULL, NULL, pong_clist, NULL, NULL, NULL, NULL, pong_desc); |
212380e3 | 54 | |
3c7d6fcc | 55 | static void |
428ca87b | 56 | ms_pong(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
57 | { |
58 | struct Client *target_p; | |
59 | const char *destination; | |
60 | ||
61 | destination = parv[2]; | |
62 | source_p->flags &= ~FLAGS_PINGSENT; | |
63 | ||
64 | /* Now attempt to route the PONG, comstud pointed out routable PING | |
65 | * is used for SPING. routable PING should also probably be left in | |
66 | * -Dianora | |
67 | * That being the case, we will route, but only for registered clients (a | |
68 | * case can be made to allow them only from servers). -Shadowfax | |
69 | */ | |
70 | if(!EmptyString(destination) && !match(destination, me.name) && | |
71 | irccmp(destination, me.id)) | |
72 | { | |
e26e2b19 | 73 | if((target_p = find_client(destination))) |
55abcbb2 KB |
74 | sendto_one(target_p, ":%s PONG %s %s", |
75 | get_id(source_p, target_p), parv[1], | |
212380e3 AC |
76 | get_id(target_p, target_p)); |
77 | else | |
78 | { | |
79 | if(!IsDigit(*destination)) | |
80 | sendto_one_numeric(source_p, ERR_NOSUCHSERVER, | |
81 | form_str(ERR_NOSUCHSERVER), destination); | |
3c7d6fcc | 82 | return; |
212380e3 AC |
83 | } |
84 | } | |
85 | ||
86 | /* destination is us, emulate EOB */ | |
87 | if(IsServer(source_p) && !HasSentEob(source_p)) | |
88 | { | |
89 | if(MyConnect(source_p)) | |
90 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
91 | "End of burst (emulated) from %s (%d seconds)", | |
92 | source_p->name, | |
e3354945 | 93 | (signed int) (rb_current_time() - source_p->localClient->firsttime)); |
212380e3 AC |
94 | SetEob(source_p); |
95 | eob_count++; | |
96 | call_hook(h_server_eob, source_p); | |
97 | } | |
212380e3 AC |
98 | } |
99 | ||
3c7d6fcc | 100 | static void |
428ca87b | 101 | mr_pong(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
102 | { |
103 | if(parc == 2 && !EmptyString(parv[1])) | |
104 | { | |
3102dbdc | 105 | if(ConfigFileEntry.ping_cookie && source_p->flags & FLAGS_SENTUSER && source_p->name[0]) |
212380e3 | 106 | { |
da20854e | 107 | uint32_t incoming_ping = strtoul(parv[1], NULL, 16); |
212380e3 AC |
108 | if(incoming_ping) |
109 | { | |
110 | if(source_p->localClient->random_ping == incoming_ping) | |
111 | { | |
095328a7 | 112 | source_p->flags |= FLAGS_PING_COOKIE; |
21251822 | 113 | register_local_user(client_p, source_p); |
212380e3 AC |
114 | } |
115 | else | |
116 | { | |
117 | sendto_one(source_p, form_str(ERR_WRONGPONG), | |
118 | me.name, source_p->name, | |
119 | source_p->localClient->random_ping); | |
3c7d6fcc | 120 | return; |
212380e3 AC |
121 | } |
122 | } | |
123 | } | |
124 | ||
125 | } | |
126 | else | |
3dfaa671 | 127 | sendto_one(source_p, form_str(ERR_NOORIGIN), me.name, source_p->name); |
212380e3 AC |
128 | |
129 | source_p->flags &= ~FLAGS_PINGSENT; | |
212380e3 | 130 | } |