]> jfr.im git - irc/quakenet/snircd.git/blob - ircd/m_asll.c
Update my e-mail address.
[irc/quakenet/snircd.git] / ircd / m_asll.c
1 /*
2 * IRC - Internet Relay Chat, ircd/m_asll.c
3 * Copyright (C) 2002 Alex Badea <vampire@p16.pub.ro>
4 *
5 * See file AUTHORS in IRC package for additional names of
6 * the programmers.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 1, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 * $Id: m_asll.c,v 1.3.2.1 2007/03/28 04:04:32 entrope Exp $
23 */
24
25 /*
26 * m_functions execute protocol messages on this server:
27 *
28 * cptr is always NON-NULL, pointing to a *LOCAL* client
29 * structure (with an open socket connected!). This
30 * identifies the physical socket where the message
31 * originated (or which caused the m_function to be
32 * executed--some m_functions may call others...).
33 *
34 * sptr is the source of the message, defined by the
35 * prefix part of the message if present. If not
36 * or prefix not found, then sptr==cptr.
37 *
38 * (!IsServer(cptr)) => (cptr == sptr), because
39 * prefixes are taken *only* from servers...
40 *
41 * (IsServer(cptr))
42 * (sptr == cptr) => the message didn't
43 * have the prefix.
44 *
45 * (sptr != cptr && IsServer(sptr) means
46 * the prefix specified servername. (?)
47 *
48 * (sptr != cptr && !IsServer(sptr) means
49 * that message originated from a remote
50 * user (not local).
51 *
52 * combining
53 *
54 * (!IsServer(sptr)) means that, sptr can safely
55 * taken as defining the target structure of the
56 * message in this server.
57 *
58 * *Always* true (if 'parse' and others are working correct):
59 *
60 * 1) sptr->from == cptr (note: cptr->from == cptr)
61 *
62 * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
63 * *cannot* be a local connection, unless it's
64 * actually cptr!). [MyConnect(x) should probably
65 * be defined as (x == x->from) --msa ]
66 *
67 * parc number of variable parameter strings (if zero,
68 * parv is allowed to be NULL)
69 *
70 * parv a NULL terminated list of parameter pointers,
71 *
72 * parv[0], sender (prefix string), if not present
73 * this points to an empty string.
74 * parv[1]...parv[parc-1]
75 * pointers to additional parameters
76 * parv[parc] == NULL, *always*
77 *
78 * note: it is guaranteed that parv[0]..parv[parc-1] are all
79 * non-NULL pointers.
80 */
81 #include "config.h"
82
83 #include "client.h"
84 #include "hash.h"
85 #include "ircd.h"
86 #include "ircd_log.h"
87 #include "ircd_reply.h"
88 #include "ircd_string.h"
89 #include "numeric.h"
90 #include "numnicks.h"
91 #include "match.h"
92 #include "msg.h"
93 #include "send.h"
94 #include "s_bsd.h"
95 #include "s_user.h"
96
97 /* #include <assert.h> -- Now using assert in ircd_log.h */
98 #include <stdlib.h>
99
100 static int send_asll_reply(struct Client *from, struct Client *to, char *server,
101 int rtt, int up, int down)
102 {
103 sendcmdto_one(from, CMD_NOTICE, to,
104 (up || down) ? "%C :AsLL for %s -- RTT: %ims Upstream: %ims Downstream: %ims" :
105 rtt ? "%C :AsLL for %s -- RTT: %ims [no asymm info]" :
106 "%C :AsLL for %s -- [unknown]",
107 to, server, rtt, up, down);
108 return 0;
109 }
110
111 /*
112 * ms_asll - server message handler
113 */
114 int ms_asll(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
115 {
116 char *mask;
117 struct Client *acptr;
118 int hits;
119 int i;
120
121 if (parc < 2)
122 return need_more_params(sptr, "ASLL");
123
124 if (parc > 5) {
125 if (!(acptr = findNUser(parv[1])))
126 return 0;
127 if (MyUser(acptr))
128 send_asll_reply(sptr, acptr, parv[2], atoi(parv[3]), atoi(parv[4]), atoi(parv[5]));
129 else
130 sendcmdto_prio_one(sptr, CMD_ASLL, acptr, "%C %s %s %s %s",
131 acptr, parv[2], parv[3], parv[4], parv[5]);
132 return 0;
133 }
134
135 if (hunt_server_prio_cmd(sptr, CMD_ASLL, cptr, 1, "%s %C", 2, parc, parv) != HUNTED_ISME)
136 return 0;
137 mask = parv[1];
138
139 for (i = hits = 0; i <= HighestFd; i++) {
140 acptr = LocalClientArray[i];
141 if (!acptr || !IsServer(acptr) || !MyConnect(acptr) || match(mask, cli_name(acptr)))
142 continue;
143 sendcmdto_prio_one(&me, CMD_ASLL, sptr, "%C %s %i %i %i", sptr,
144 cli_name(acptr), cli_serv(acptr)->asll_rtt,
145 cli_serv(acptr)->asll_to, cli_serv(acptr)->asll_from);
146 hits++;
147 }
148 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :AsLL for %s: %d local servers matched", sptr, mask, hits);
149 return 0;
150 }
151
152 /*
153 * mo_asll - oper message handler
154 */
155 int mo_asll(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
156 {
157 char *mask;
158 struct Client *acptr;
159 int hits;
160 int i;
161
162 if (parc < 2)
163 return need_more_params(sptr, "ASLL");
164
165 if (parc == 2 && MyUser(sptr))
166 parv[parc++] = cli_name(&me);
167
168 if (hunt_server_prio_cmd(sptr, CMD_ASLL, cptr, 1, "%s %C", 2, parc, parv) != HUNTED_ISME)
169 return 0;
170 mask = parv[1];
171
172 for (i = hits = 0; i <= HighestFd; i++) {
173 acptr = LocalClientArray[i];
174 if (!acptr || !IsServer(acptr) || !MyConnect(acptr) || match(mask, cli_name(acptr)))
175 continue;
176 send_asll_reply(&me, sptr, cli_name(acptr), cli_serv(acptr)->asll_rtt,
177 cli_serv(acptr)->asll_to, cli_serv(acptr)->asll_from);
178 hits++;
179 }
180 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :AsLL for %s: %d local servers matched", sptr, mask, hits);
181 return 0;
182 }