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