f06aaa90b20e779a413f0dcb6923aa0823716f68
[ircu2.10.12-pk.git] / ircd / m_trace.c
1 /*
2  * IRC - Internet Relay Chat, ircd/m_trace.c
3  * Copyright (C) 1990 Jarkko Oikarinen and
4  *                    University of Oulu, Computing Center
5  *
6  * See file AUTHORS in IRC package for additional names of
7  * the programmers.
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 1, or (at your option)
12  * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *
23  * $Id$
24  */
25
26 /*
27  * m_functions execute protocol messages on this server:
28  *
29  *    cptr    is always NON-NULL, pointing to a *LOCAL* client
30  *            structure (with an open socket connected!). This
31  *            identifies the physical socket where the message
32  *            originated (or which caused the m_function to be
33  *            executed--some m_functions may call others...).
34  *
35  *    sptr    is the source of the message, defined by the
36  *            prefix part of the message if present. If not
37  *            or prefix not found, then sptr==cptr.
38  *
39  *            (!IsServer(cptr)) => (cptr == sptr), because
40  *            prefixes are taken *only* from servers...
41  *
42  *            (IsServer(cptr))
43  *                    (sptr == cptr) => the message didn't
44  *                    have the prefix.
45  *
46  *                    (sptr != cptr && IsServer(sptr) means
47  *                    the prefix specified servername. (?)
48  *
49  *                    (sptr != cptr && !IsServer(sptr) means
50  *                    that message originated from a remote
51  *                    user (not local).
52  *
53  *            combining
54  *
55  *            (!IsServer(sptr)) means that, sptr can safely
56  *            taken as defining the target structure of the
57  *            message in this server.
58  *
59  *    *Always* true (if 'parse' and others are working correct):
60  *
61  *    1)      sptr->from == cptr  (note: cptr->from == cptr)
62  *
63  *    2)      MyConnect(sptr) <=> sptr == cptr (e.g. sptr
64  *            *cannot* be a local connection, unless it's
65  *            actually cptr!). [MyConnect(x) should probably
66  *            be defined as (x == x->from) --msa ]
67  *
68  *    parc    number of variable parameter strings (if zero,
69  *            parv is allowed to be NULL)
70  *
71  *    parv    a NULL terminated list of parameter pointers,
72  *
73  *                    parv[0], sender (prefix string), if not present
74  *                            this points to an empty string.
75  *                    parv[1]...parv[parc-1]
76  *                            pointers to additional parameters
77  *                    parv[parc] == NULL, *always*
78  *
79  *            note:   it is guaranteed that parv[0]..parv[parc-1] are all
80  *                    non-NULL pointers.
81  */
82 #include "config.h"
83
84 #if 0
85 /*
86  * No need to include handlers.h here the signatures must match
87  * and we don't need to force a rebuild of all the handlers everytime
88  * we add a new one to the list. --Bleep
89  */
90 #include "handlers.h"
91 #endif /* 0 */
92 #include "class.h"
93 #include "client.h"
94 #include "hash.h"
95 #include "ircd.h"
96 #include "ircd_reply.h"
97 #include "ircd_string.h"
98 #include "match.h"
99 #include "msg.h"
100 #include "numeric.h"
101 #include "numnicks.h"
102 #include "s_bsd.h"
103 #include "s_conf.h"
104 #include "s_user.h"
105 #include "send.h"
106 #include "version.h"
107
108 #include <assert.h>
109 #include <string.h>
110
111 /*
112  * m_trace - generic message handler
113  *
114  * parv[0] = sender prefix
115  * parv[1] = nick or servername
116  * parv[2] = 'target' servername
117  */
118 int m_trace(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
119 {
120   int i;
121   struct Client *acptr;
122   const struct ConnectionClass* cl;
123   char* tname;
124   int doall;
125   int link_s[MAXCONNECTIONS];
126   int link_u[MAXCONNECTIONS];
127   int cnt = 0;
128   int wilds;
129   int dow;
130
131   if (parc < 2 || BadPtr(parv[1])) {
132     /* just "TRACE" without parameters. Must be from local client */
133     parc = 1;
134     acptr = &me;
135     tname = cli_name(&me);
136     i = HUNTED_ISME;
137   } else if (parc < 3 || BadPtr(parv[2])) {
138     /* No target specified. Make one before propagating. */
139     parc = 2;
140     tname = parv[1];
141     if ((acptr = find_match_server(parv[1])) ||
142         ((acptr = FindClient(parv[1])) && !MyUser(acptr))) {
143       if (IsUser(acptr))
144         parv[2] = cli_name(cli_user(acptr)->server);
145       else
146         parv[2] = cli_name(acptr);
147       parc = 3;
148       parv[3] = 0;
149       if ((i = hunt_server_cmd(sptr, CMD_TRACE, cptr, IsServer(acptr),
150                                "%s :%C", 2, parc, parv)) == HUNTED_NOSUCH)
151         return 0;
152     } else
153       i = HUNTED_ISME;
154   } else {
155     /* Got "TRACE <tname> :<target>" */
156     parc = 3;
157     if (MyUser(sptr) || Protocol(cptr) < 10)
158       acptr = find_match_server(parv[2]);
159     else
160       acptr = FindNServer(parv[2]);
161     if ((i = hunt_server_cmd(sptr, CMD_TRACE, cptr, 0, "%s :%C", 2, parc,
162                              parv)) == HUNTED_NOSUCH)
163       return 0;
164     tname = parv[1];
165   }
166
167   if (i == HUNTED_PASS) {
168     if (!acptr)
169       acptr = next_client(GlobalClientList, tname);
170     else
171       acptr = cli_from(acptr);
172     send_reply(sptr, RPL_TRACELINK,
173                version, debugmode, tname,
174                acptr ? cli_name(cli_from(acptr)) : "<No_match>");
175     return 0;
176   }
177
178   doall = (parv[1] && (parc > 1)) ? !match(tname, cli_name(&me)) : 1;
179   wilds = !parv[1] || strchr(tname, '*') || strchr(tname, '?');
180   dow = wilds || doall;
181
182   /* Don't give (long) remote listings to lusers */
183   if (dow && !MyConnect(sptr) && !IsAnOper(sptr))
184     return 0;
185
186   for (i = 0; i < MAXCONNECTIONS; i++)
187     link_s[i] = 0, link_u[i] = 0;
188
189   if (doall) {
190     for (acptr = GlobalClientList; acptr; acptr = cli_next(acptr)) {
191       if (IsUser(acptr))
192         link_u[cli_fd(cli_from(acptr))]++;
193       else if (IsServer(acptr))
194         link_s[cli_fd(cli_from(acptr))]++;
195     }
196   }
197
198   /* report all direct connections */
199
200   for (i = 0; i <= HighestFd; i++) {
201     unsigned int conClass;
202
203     if (!(acptr = LocalClientArray[i])) /* Local Connection? */
204       continue;
205     if (IsInvisible(acptr) && dow && !(MyConnect(sptr) && IsOper(sptr)) &&
206         !IsAnOper(acptr) && (acptr != sptr))
207       continue;
208     if (!doall && wilds && match(tname, cli_name(acptr)))
209       continue;
210     if (!dow && 0 != ircd_strcmp(tname, cli_name(acptr)))
211       continue;
212
213     conClass = get_client_class(acptr);
214
215     switch (cli_status(acptr)) {
216       case STAT_CONNECTING:
217         send_reply(sptr, RPL_TRACECONNECTING, conClass, cli_name(acptr));
218         cnt++;
219         break;
220       case STAT_HANDSHAKE:
221         send_reply(sptr, RPL_TRACEHANDSHAKE, conClass, cli_name(acptr));
222         cnt++;
223         break;
224       case STAT_ME:
225         break;
226       case STAT_UNKNOWN:
227       case STAT_UNKNOWN_USER:
228         send_reply(sptr, RPL_TRACEUNKNOWN, conClass,
229                    get_client_name(acptr, HIDE_IP));
230         cnt++;
231         break;
232       case STAT_UNKNOWN_SERVER:
233         send_reply(sptr, RPL_TRACEUNKNOWN, conClass, "Unknown Server");
234         cnt++;
235         break;
236       case STAT_USER:
237         /* Only opers see users if there is a wildcard
238            but anyone can see all the opers. */
239         if ((IsAnOper(sptr) && (MyUser(sptr) ||
240             !(dow && IsInvisible(acptr)))) || !dow || IsAnOper(acptr)) {
241           if (IsAnOper(acptr))
242             send_reply(sptr, RPL_TRACEOPERATOR, conClass,
243                        get_client_name(acptr, SHOW_IP),
244                        CurrentTime - cli_lasttime(acptr));
245           else
246             send_reply(sptr, RPL_TRACEUSER, conClass,
247                        get_client_name(acptr, SHOW_IP),
248                        CurrentTime - cli_lasttime(acptr));
249           cnt++;
250         }
251         break;
252         /*
253          * Connection is a server
254          *
255          * Serv <class> <nS> <nC> <name> <ConnBy> <last> <age>
256          *
257          * class        Class the server is in
258          * nS           Number of servers reached via this link
259          * nC           Number of clients reached via this link
260          * name         Name of the server linked
261          * ConnBy       Who established this link
262          * last         Seconds since we got something from this link
263          * age          Seconds this link has been alive
264          *
265          * Additional comments etc......        -Cym-<cym@acrux.net>
266          */
267
268       case STAT_SERVER:
269         if (cli_serv(acptr)->user)
270           send_reply(sptr, RPL_TRACESERVER, conClass, link_s[i],
271                      link_u[i], cli_name(acptr),
272                      (*(cli_serv(acptr))->by) ? cli_serv(acptr)->by : "*",
273                      cli_serv(acptr)->user->username, cli_serv(acptr)->user->host,
274                      CurrentTime - cli_lasttime(acptr),
275                      CurrentTime - cli_serv(acptr)->timestamp);
276         else
277           send_reply(sptr, RPL_TRACESERVER, conClass, link_s[i],
278                      link_u[i], cli_name(acptr),
279                      (*(cli_serv(acptr))->by) ?  cli_serv(acptr)->by : "*", "*",
280                      cli_name(&me), CurrentTime - cli_lasttime(acptr),
281                      CurrentTime - cli_serv(acptr)->timestamp);
282         cnt++;
283         break;
284       default:                  /* We actually shouldn't come here, -msa */
285         send_reply(sptr, RPL_TRACENEWTYPE, get_client_name(acptr, HIDE_IP));
286         cnt++;
287         break;
288     }
289   }
290   /*
291    * Add these lines to summarize the above which can get rather long
292    * and messy when done remotely - Avalon
293    */
294   if (!IsAnOper(sptr) || !cnt) {
295     if (!cnt)
296       /* let the user have some idea that its at the end of the trace */
297       send_reply(sptr, RPL_TRACESERVER, 0, link_s[cli_fd(&me)],
298                  link_u[cli_fd(&me)], "<No_match>", *(cli_serv(&me)->by) ?
299                  cli_serv(&me)->by : "*", "*", cli_name(&me), 0, 0);
300     return 0;
301   }
302   if (doall) {
303     for (cl = get_class_list(); cl; cl = cl->next) {
304       if (Links(cl) > 0)
305        send_reply(sptr, RPL_TRACECLASS, ConClass(cl), Links(cl));
306     }
307   }
308   return 0;
309 }
310
311 /*
312  * ms_trace - server message handler
313  *
314  * parv[0] = sender prefix
315  * parv[1] = nick or servername
316  * parv[2] = 'target' servername
317  */
318 int ms_trace(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
319 {
320   int i;
321   struct Client *acptr;
322   const struct ConnectionClass* cl;
323   char *tname;
324   int doall;
325   int link_s[MAXCONNECTIONS];
326   int link_u[MAXCONNECTIONS];
327   int cnt = 0;
328   int wilds;
329   int dow;
330
331   if (parc < 2 || BadPtr(parv[1])) {
332     /* just "TRACE" without parameters. Must be from local client */
333     parc = 1;
334     acptr = &me;
335     tname = cli_name(&me);
336     i = HUNTED_ISME;
337   } else if (parc < 3 || BadPtr(parv[2])) {
338     /* No target specified. Make one before propagating. */
339     parc = 2;
340     tname = parv[1];
341     if ((acptr = find_match_server(parv[1])) ||
342         ((acptr = FindClient(parv[1])) && !MyUser(acptr))) {
343       if (IsUser(acptr))
344         parv[2] = cli_name(cli_user(acptr)->server);
345       else
346         parv[2] = cli_name(acptr);
347       parc = 3;
348       parv[3] = 0;
349
350       if ((i = hunt_server_cmd(sptr, CMD_TRACE, cptr, IsServer(acptr),
351                                "%s :%C", 2, parc, parv)) == HUNTED_NOSUCH)
352         return 0;
353     } else
354       i = HUNTED_ISME;
355   } else {
356     /* Got "TRACE <tname> :<target>" */
357     parc = 3;
358     if (MyUser(sptr) || Protocol(cptr) < 10)
359       acptr = find_match_server(parv[2]);
360     else
361       acptr = FindNServer(parv[2]);
362     if ((i = hunt_server_cmd(sptr, CMD_TRACE, cptr, 0, "%s :%C", 2, parc,
363                              parv)) == HUNTED_NOSUCH)
364       return 0;
365     tname = parv[1];
366   }
367
368   if (i == HUNTED_PASS) {
369     if (!acptr)
370       acptr = next_client(GlobalClientList, tname);
371     else
372       acptr = cli_from(acptr);
373     send_reply(sptr, RPL_TRACELINK,
374                version, debugmode, tname,
375                acptr ? cli_name(cli_from(acptr)) : "<No_match>");
376     return 0;
377   }
378
379   doall = (parv[1] && (parc > 1)) ? !match(tname, cli_name(&me)) : 1;
380   wilds = !parv[1] || strchr(tname, '*') || strchr(tname, '?');
381   dow = wilds || doall;
382
383   /* Don't give (long) remote listings to lusers */
384   if (dow && !MyConnect(sptr) && !IsAnOper(sptr))
385     return 0;
386
387   for (i = 0; i < MAXCONNECTIONS; i++)
388     link_s[i] = 0, link_u[i] = 0;
389
390   if (doall) {
391     for (acptr = GlobalClientList; acptr; acptr = cli_next(acptr)) {
392       if (IsUser(acptr))
393         link_u[cli_fd(cli_from(acptr))]++;
394       else if (IsServer(acptr))
395         link_s[cli_fd(cli_from(acptr))]++;
396     }
397   }
398
399   /* report all direct connections */
400
401   for (i = 0; i <= HighestFd; i++) {
402     unsigned int conClass;
403
404     if (!(acptr = LocalClientArray[i])) /* Local Connection? */
405       continue;
406     if (IsInvisible(acptr) && dow && !(MyConnect(sptr) && IsOper(sptr)) &&
407         !IsAnOper(acptr) && (acptr != sptr))
408       continue;
409     if (!doall && wilds && match(tname, cli_name(acptr)))
410       continue;
411     if (!dow && 0 != ircd_strcmp(tname, cli_name(acptr)))
412       continue;
413     conClass = get_client_class(acptr);
414
415     switch (cli_status(acptr)) {
416       case STAT_CONNECTING:
417         send_reply(sptr, RPL_TRACECONNECTING, conClass, cli_name(acptr));
418         cnt++;
419         break;
420       case STAT_HANDSHAKE:
421         send_reply(sptr, RPL_TRACEHANDSHAKE, conClass, cli_name(acptr));
422         cnt++;
423         break;
424       case STAT_ME:
425         break;
426       case STAT_UNKNOWN:
427       case STAT_UNKNOWN_USER:
428         send_reply(sptr, RPL_TRACEUNKNOWN, conClass,
429                    get_client_name(acptr, HIDE_IP));
430         cnt++;
431         break;
432       case STAT_UNKNOWN_SERVER:
433         send_reply(sptr, RPL_TRACEUNKNOWN, conClass, "Unknown Server");
434         cnt++;
435         break;
436       case STAT_USER:
437         /* Only opers see users if there is a wildcard
438            but anyone can see all the opers. */
439         if ((IsAnOper(sptr) && (MyUser(sptr) ||
440             !(dow && IsInvisible(acptr)))) || !dow || IsAnOper(acptr)) {
441           if (IsAnOper(acptr))
442             send_reply(sptr, RPL_TRACEOPERATOR, conClass,
443                        get_client_name(acptr, SHOW_IP),
444                        CurrentTime - cli_lasttime(acptr));
445           else
446             send_reply(sptr, RPL_TRACEUSER, conClass,
447                        get_client_name(acptr, SHOW_IP),
448                        CurrentTime - cli_lasttime(acptr));
449           cnt++;
450         }
451         break;
452         /*
453          * Connection is a server
454          *
455          * Serv <class> <nS> <nC> <name> <ConnBy> <last> <age>
456          *
457          * class        Class the server is in
458          * nS           Number of servers reached via this link
459          * nC           Number of clients reached via this link
460          * name         Name of the server linked
461          * ConnBy       Who established this link
462          * last         Seconds since we got something from this link
463          * age          Seconds this link has been alive
464          *
465          * Additional comments etc......        -Cym-<cym@acrux.net>
466          */
467
468       case STAT_SERVER:
469         if (cli_serv(acptr)->user)
470           send_reply(sptr, RPL_TRACESERVER, conClass, link_s[i],
471                      link_u[i], cli_name(acptr),
472                      (*(cli_serv(acptr))->by) ? cli_serv(acptr)->by : "*",
473                      cli_serv(acptr)->user->username, cli_serv(acptr)->user->host,
474                      CurrentTime - cli_lasttime(acptr),
475                      CurrentTime - cli_serv(acptr)->timestamp);
476         else
477           send_reply(sptr, RPL_TRACESERVER, conClass, link_s[i],
478                      link_u[i], cli_name(acptr),
479                      (*(cli_serv(acptr))->by) ? cli_serv(acptr)->by : "*", "*",
480                      cli_name(&me), CurrentTime - cli_lasttime(acptr),
481                      CurrentTime - cli_serv(acptr)->timestamp);
482         cnt++;
483         break;
484       default:                  /* We actually shouldn't come here, -msa */
485         send_reply(sptr, RPL_TRACENEWTYPE, get_client_name(acptr, HIDE_IP));
486         cnt++;
487         break;
488     }
489   }
490   /*
491    * Add these lines to summarize the above which can get rather long
492    * and messy when done remotely - Avalon
493    */
494   if (!IsAnOper(sptr) || !cnt) {
495     if (!cnt)
496       /* let the user have some idea that its at the end of the trace */
497       send_reply(sptr, RPL_TRACESERVER, 0, link_s[cli_fd(&me)],
498           link_u[cli_fd(&me)], "<No_match>", *(cli_serv(&me)->by) ?
499           cli_serv(&me)->by : "*", "*", cli_name(&me), 0, 0);
500     return 0;
501   }
502   if (doall) {
503     for (cl = get_class_list(); cl; cl = cl->next) {
504       if (Links(cl) > 0)
505         send_reply(sptr, RPL_TRACECLASS, ConClass(cl), Links(cl));
506     }
507   }
508   return 0;
509 }
510
511 /*
512  * mo_trace - oper message handler
513  *
514  * parv[0] = sender prefix
515  * parv[1] = nick or servername
516  * parv[2] = 'target' servername
517  */
518 int mo_trace(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
519 {
520   int               i;
521   struct Client*    acptr;
522   const struct ConnectionClass* cl;
523   char*             tname;
524   int doall;
525   int link_s[MAXCONNECTIONS];
526   int link_u[MAXCONNECTIONS];
527   int cnt = 0;
528   int wilds;
529   int dow;
530
531   if (parc < 2 || BadPtr(parv[1])) {
532     /* just "TRACE" without parameters. Must be from local client */
533     parc = 1;
534     acptr = &me;
535     tname = cli_name(&me);
536     i = HUNTED_ISME;
537   } else if (parc < 3 || BadPtr(parv[2])) {
538     /* No target specified. Make one before propagating. */
539     parc = 2;
540     tname = parv[1];
541     if ((acptr = find_match_server(parv[1])) ||
542         ((acptr = FindClient(parv[1])) && !MyUser(acptr))) {
543       if (IsUser(acptr))
544         parv[2] = cli_name(cli_user(acptr)->server);
545       else
546         parv[2] = cli_name(acptr);
547       parc = 3;
548       parv[3] = 0;
549       if ((i = hunt_server_cmd(sptr, CMD_TRACE, cptr, IsServer(acptr),
550                                "%s :%C", 2, parc, parv)) == HUNTED_NOSUCH)
551         return 0;
552     } else
553       i = HUNTED_ISME;
554   } else {
555     /* Got "TRACE <tname> :<target>" */
556     parc = 3;
557     if (MyUser(sptr) || Protocol(cptr) < 10)
558       acptr = find_match_server(parv[2]);
559     else
560       acptr = FindNServer(parv[2]);
561     if ((i = hunt_server_cmd(sptr, CMD_TRACE, cptr, 0, "%s :%C", 2, parc,
562                              parv)) == HUNTED_NOSUCH)
563       return 0;
564     tname = parv[1];
565   }
566
567   if (i == HUNTED_PASS) {
568     if (!acptr)
569       acptr = next_client(GlobalClientList, tname);
570     else
571       acptr = cli_from(acptr);
572     send_reply(sptr, RPL_TRACELINK,
573                version, debugmode, tname,
574                acptr ? cli_name(cli_from(acptr)) : "<No_match>");
575     return 0;
576   }
577
578   doall = (parv[1] && (parc > 1)) ? !match(tname, cli_name(&me)) : 1;
579   wilds = !parv[1] || strchr(tname, '*') || strchr(tname, '?');
580   dow = wilds || doall;
581
582   /* Don't give (long) remote listings to lusers */
583   if (dow && !MyConnect(sptr) && !IsAnOper(sptr))
584     return 0;
585
586   for (i = 0; i < MAXCONNECTIONS; i++)
587     link_s[i] = 0, link_u[i] = 0;
588
589   if (doall) {
590     for (acptr = GlobalClientList; acptr; acptr = cli_next(acptr)) {
591       if (IsUser(acptr))
592         link_u[cli_fd(cli_from(acptr))]++;
593       else if (IsServer(acptr))
594         link_s[cli_fd(cli_from(acptr))]++;
595     }
596   }
597
598   /* report all direct connections */
599
600   for (i = 0; i <= HighestFd; i++) {
601     unsigned int conClass;
602
603     if (!(acptr = LocalClientArray[i])) /* Local Connection? */
604       continue;
605     if (IsInvisible(acptr) && dow && !(MyConnect(sptr) && IsOper(sptr)) &&
606         !IsAnOper(acptr) && (acptr != sptr))
607       continue;
608     if (!doall && wilds && match(tname, cli_name(acptr)))
609       continue;
610     if (!dow && 0 != ircd_strcmp(tname, cli_name(acptr)))
611       continue;
612     conClass = get_client_class(acptr);
613
614     switch (cli_status(acptr)) {
615       case STAT_CONNECTING:
616         send_reply(sptr, RPL_TRACECONNECTING, conClass, cli_name(acptr));
617         cnt++;
618         break;
619       case STAT_HANDSHAKE:
620         send_reply(sptr, RPL_TRACEHANDSHAKE, conClass, cli_name(acptr));
621         cnt++;
622         break;
623       case STAT_ME:
624         break;
625       case STAT_UNKNOWN:
626       case STAT_UNKNOWN_USER:
627         send_reply(sptr, RPL_TRACEUNKNOWN, conClass,
628                    get_client_name(acptr, HIDE_IP));
629         cnt++;
630         break;
631       case STAT_UNKNOWN_SERVER:
632         send_reply(sptr, RPL_TRACEUNKNOWN, conClass, "Unknown Server");
633         cnt++;
634         break;
635       case STAT_USER:
636         /* Only opers see users if there is a wildcard
637            but anyone can see all the opers. */
638         if ((IsAnOper(sptr) && (MyUser(sptr) ||
639             !(dow && IsInvisible(acptr)))) || !dow || IsAnOper(acptr)) {
640           if (IsAnOper(acptr))
641             send_reply(sptr, RPL_TRACEOPERATOR, conClass,
642                        get_client_name(acptr, SHOW_IP),
643                        CurrentTime - cli_lasttime(acptr));
644           else
645             send_reply(sptr, RPL_TRACEUSER, conClass,
646                        get_client_name(acptr, SHOW_IP),
647                        CurrentTime - cli_lasttime(acptr));
648           cnt++;
649         }
650         break;
651         /*
652          * Connection is a server
653          *
654          * Serv <class> <nS> <nC> <name> <ConnBy> <last> <age>
655          *
656          * class        Class the server is in
657          * nS           Number of servers reached via this link
658          * nC           Number of clients reached via this link
659          * name         Name of the server linked
660          * ConnBy       Who established this link
661          * last         Seconds since we got something from this link
662          * age          Seconds this link has been alive
663          *
664          * Additional comments etc......        -Cym-<cym@acrux.net>
665          */
666
667       case STAT_SERVER:
668         if (cli_serv(acptr)->user)
669           send_reply(sptr, RPL_TRACESERVER, conClass, link_s[i],
670                      link_u[i], cli_name(acptr),
671                      (*(cli_serv(acptr))->by) ? cli_serv(acptr)->by : "*",
672                      cli_serv(acptr)->user->username, cli_serv(acptr)->user->host,
673                      CurrentTime - cli_lasttime(acptr),
674                      CurrentTime - cli_serv(acptr)->timestamp);
675         else
676           send_reply(sptr, RPL_TRACESERVER, conClass, link_s[i],
677                      link_u[i], cli_name(acptr),
678                      (*(cli_serv(acptr))->by) ? cli_serv(acptr)->by : "*", "*",
679                      cli_name(&me), CurrentTime - cli_lasttime(acptr),
680                      CurrentTime - cli_serv(acptr)->timestamp);
681         cnt++;
682         break;
683       default:                  /* We actually shouldn't come here, -msa */
684         send_reply(sptr, RPL_TRACENEWTYPE, get_client_name(acptr, HIDE_IP));
685         cnt++;
686         break;
687     }
688   }
689   /*
690    * Add these lines to summarize the above which can get rather long
691    * and messy when done remotely - Avalon
692    */
693   if (!IsAnOper(sptr) || !cnt) {
694     if (!cnt)
695       /* let the user have some idea that its at the end of the trace */
696       send_reply(sptr, RPL_TRACESERVER, 0, link_s[cli_fd(&me)],
697                  link_u[cli_fd(&me)], "<No_match>", *(cli_serv(&me)->by) ?
698                  cli_serv(&me)->by : "*", "*", cli_name(&me), 0, 0);
699     return 0;
700   }
701   if (doall) {
702     for (cl = get_class_list(); cl; cl = cl->next) {
703       if (Links(cl) > 0)
704         send_reply(sptr, RPL_TRACECLASS, ConClass(cl), Links(cl));
705     }
706   }
707   return 0;
708 }
709
710