fixed some collisions with older commits
[ircu2.10.12-pk.git] / ircd / s_misc.c
1 /*
2  * IRC - Internet Relay Chat, ircd/s_misc.c (formerly ircd/date.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 /** @file
24  * @brief Miscellaneous support functions.
25  * @version $Id: s_misc.c 1818 2007-07-14 02:40:01Z isomer $
26  */
27 #include "config.h"
28
29 #include "s_misc.h"
30 #include "IPcheck.h"
31 #include "channel.h"
32 #include "client.h"
33 #include "hash.h"
34 #include "ircd.h"
35 #include "ircd_alloc.h"
36 #include "ircd_features.h"
37 #include "ircd_log.h"
38 #include "ircd_reply.h"
39 #include "ircd_snprintf.h"
40 #include "ircd_string.h"
41 #include "list.h"
42 #include "match.h"
43 #include "msg.h"
44 #include "numeric.h"
45 #include "numnicks.h"
46 #include "parse.h"
47 #include "querycmds.h"
48 #include "res.h"
49 #include "s_auth.h"
50 #include "s_bsd.h"
51 #include "s_conf.h"
52 #include "s_debug.h"
53 #include "s_stats.h"
54 #include "s_user.h"
55 #include "send.h"
56 #include "struct.h"
57 #include "sys.h"
58 #include "uping.h"
59 #include "userload.h"
60
61 /* #include <assert.h> -- Now using assert in ircd_log.h */
62 #include <fcntl.h>
63 #include <netdb.h>
64 #include <stdio.h>
65 #include <string.h>
66 #include <sys/stat.h>
67 #include <unistd.h>
68
69 /** Array of English month names (0 = January). */
70 static char *months[] = {
71   "January", "February", "March", "April",
72   "May", "June", "July", "August",
73   "September", "October", "November", "December"
74 };
75
76 /** Array of English day names (0 = Sunday). */
77 static char *weekdays[] = {
78   "Sunday", "Monday", "Tuesday", "Wednesday",
79   "Thursday", "Friday", "Saturday"
80 };
81
82 /*
83  * stats stuff
84  */
85 /** Global statistics structure. */
86 static struct ServerStatistics ircst;
87 /** Public pointer to global statistics structure. */
88 struct ServerStatistics* ServerStats = &ircst;
89
90 /** Formats a Unix time as a readable string.
91  * @param clock Unix time to format (0 means #CurrentTime).
92  * @return Pointer to a static buffer containing something like
93  * "Sunday January 1 2000 -- 09:30 +01:00"
94  */
95 char *date(time_t clock)
96 {
97   static char buf[80], plus;
98   struct tm *lt, *gm;
99   struct tm gmbuf;
100   int minswest;
101
102   if (!clock)
103     clock = CurrentTime;
104   gm = gmtime(&clock);
105   memcpy(&gmbuf, gm, sizeof(gmbuf));
106   gm = &gmbuf;
107   lt = localtime(&clock);
108
109   /* There is unfortunately no clean portable way to extract time zone
110    * offset information, so do ugly things.
111    */
112   minswest = (gm->tm_hour - lt->tm_hour) * 60 + (gm->tm_min - lt->tm_min);
113   if (lt->tm_yday != gm->tm_yday)
114   {
115     if ((lt->tm_yday > gm->tm_yday && lt->tm_year == gm->tm_year) ||
116         (lt->tm_yday < gm->tm_yday && lt->tm_year != gm->tm_year))
117       minswest -= 24 * 60;
118     else
119       minswest += 24 * 60;
120   }
121
122   plus = (minswest > 0) ? '-' : '+';
123   if (minswest < 0)
124     minswest = -minswest;
125
126   sprintf(buf, "%s %s %d %d -- %02d:%02d %c%02d:%02d",
127       weekdays[lt->tm_wday], months[lt->tm_mon], lt->tm_mday,
128       1900 + lt->tm_year, lt->tm_hour, lt->tm_min,
129       plus, minswest / 60, minswest % 60);
130
131   return buf;
132 }
133
134 /** Like ctime() but with no trailing newline. Also, it takes
135  * the time value as parameter, instead of pointer to it.
136  * @param value Unix time to format.
137  * @return Pointer to a static buffer containing formatted time.
138  */
139 char *myctime(time_t value)
140 {
141   /* Use a secondary buffer in case ctime() would not replace an
142    * overwritten newline.
143    */
144   static char buf[28];
145   char *p;
146
147   strcpy(buf, ctime(&value));
148   if ((p = strchr(buf, '\n')) != NULL)
149     *p = '\0';
150
151   return buf;
152 }
153
154 /** Return the name of the client for various tracking and admin
155  * purposes. The main purpose of this function is to return the
156  * "socket host" name of the client, if that differs from the
157  * advertised name (other than case).  But, this can be used on any
158  * client structure.
159  * @param sptr Client to operate on.
160  * @param showip If non-zero, append [username\@text-ip] to name.
161  * @return Either cli_name(\a sptr) or a static buffer.
162  */
163 const char* get_client_name(const struct Client* sptr, int showip)
164 {
165   static char nbuf[HOSTLEN * 2 + USERLEN + 5];
166
167   if (!MyConnect(sptr) || !showip)
168     return cli_name(sptr);
169   ircd_snprintf(0, nbuf, sizeof(nbuf), "%s[%s@%s]", cli_name(sptr),
170                 IsIdented(sptr) ? cli_username(sptr) : "",
171                 cli_sock_ip(sptr));
172   return nbuf;
173 }
174
175 /**
176  * Exit one client, local or remote. Assuming for local client that
177  * all dependents already have been removed, and socket is closed.
178  * @param bcptr Client being (s)quitted.
179  * @param comment The QUIT comment to send.
180  */
181 /* Rewritten by Run - 24 sept 94 */
182 static void exit_one_client(struct Client* bcptr, const char* comment)
183 {
184   struct SLink *lp;
185   struct Ban *bp;
186
187   if (cli_serv(bcptr) && cli_serv(bcptr)->client_list)  /* Was SetServerYXX called ? */
188     ClearServerYXX(bcptr);      /* Removes server from server_list[] */
189   if (IsUser(bcptr)) {
190     /*
191      * clear out uping requests
192      */
193     if (IsUPing(bcptr))
194       uping_cancel(bcptr, 0);
195     /*
196      * Stop a running /LIST clean
197      */
198     if (MyUser(bcptr) && cli_listing(bcptr)) {
199       MyFree(cli_listing(bcptr));
200       cli_listing(bcptr) = NULL;
201     }
202     /*
203      * If a person is on a channel, send a QUIT notice
204      * to every client (person) on the same channel (so
205      * that the client can show the "**signoff" message).
206      * (Note: The notice is to the local clients *only*)
207      */
208      
209     sendcmdto_common_channels_butone_audit(bcptr, CMD_QUIT, NULL, ":%s", comment);
210
211     remove_user_from_all_channels(bcptr);
212
213     /* Clean up invitefield */
214     while ((lp = cli_user(bcptr)->invited))
215       del_invite(bcptr, lp->value.chptr);
216
217     /* Clean up silencefield */
218     while ((bp = cli_user(bcptr)->silence)) {
219       cli_user(bcptr)->silence = bp->next;
220       free_ban(bp);
221     }
222
223     /* Clean up snotice lists */
224     if (MyUser(bcptr))
225       set_snomask(bcptr, ~0, SNO_DEL);
226
227     if (IsInvisible(bcptr)) {
228       assert(UserStats.inv_clients > 0);
229       --UserStats.inv_clients;
230     }
231     if (IsOper(bcptr)) {
232       assert(UserStats.opers > 0);
233       --UserStats.opers;
234     }
235     if (MyConnect(bcptr))
236       Count_clientdisconnects(bcptr, UserStats);
237     else
238       Count_remoteclientquits(UserStats, bcptr);
239   }
240   else if (IsServer(bcptr))
241   {
242     /* Remove downlink list node of uplink */
243     remove_dlink(&(cli_serv(cli_serv(bcptr)->up))->down, cli_serv(bcptr)->updown);
244     cli_serv(bcptr)->updown = 0;
245
246     if (MyConnect(bcptr))
247       Count_serverdisconnects(UserStats);
248     else
249       Count_remoteserverquits(UserStats);
250   }
251   else if (IsMe(bcptr))
252   {
253     sendto_opmask_butone(0, SNO_OLDSNO, "ERROR: tried to exit me! : %s",
254                          comment);
255     return;                     /* ...must *never* exit self! */
256   }
257   else if (IsUnknown(bcptr) || IsConnecting(bcptr) || IsHandshake(bcptr))
258     Count_unknowndisconnects(UserStats);
259
260   /*
261    * Update IPregistry
262    */
263   if (IsIPChecked(bcptr))
264     IPcheck_disconnect(bcptr);
265
266   /* 
267    * Remove from serv->client_list
268    * NOTE: user is *always* NULL if this is a server
269    */
270   if (cli_user(bcptr)) {
271     assert(!IsServer(bcptr));
272     /* bcptr->user->server->serv->client_list[IndexYXX(bcptr)] = NULL; */
273     RemoveYXXClient(cli_user(bcptr)->server, cli_yxx(bcptr));
274   }
275
276   /* Remove bcptr from the client list */
277 #ifdef DEBUGMODE
278   if (hRemClient(bcptr) != 0)
279     Debug((DEBUG_ERROR, "%p !in tab %s[%s] %p %p %p %d %d %p",
280           bcptr, cli_name(bcptr), cli_from(bcptr) ? cli_sockhost(cli_from(bcptr)) : "??host",
281           cli_from(bcptr), cli_next(bcptr), cli_prev(bcptr), cli_fd(bcptr),
282           cli_status(bcptr), cli_user(bcptr)));
283 #else
284   hRemClient(bcptr);
285 #endif
286   remove_client_from_list(bcptr);
287 }
288
289 /* exit_downlinks - added by Run 25-9-94 */
290 /**
291  * Removes all clients and downlinks (+clients) of any server
292  * QUITs are generated and sent to local users.
293  * @param cptr server that must have all dependents removed
294  * @param sptr source who thought that this was a good idea
295  * @param comment comment sent as sign off message to local clients
296  */
297 static void exit_downlinks(struct Client *cptr, struct Client *sptr, char *comment)
298 {
299   struct Client *acptr;
300   struct DLink *next;
301   struct DLink *lp;
302   struct Client **acptrp;
303   int i;
304
305   /* Run over all its downlinks */
306   for (lp = cli_serv(cptr)->down; lp; lp = next)
307   {
308     next = lp->next;
309     acptr = lp->value.cptr;
310     /* Remove the downlinks and client of the downlink */
311     exit_downlinks(acptr, sptr, comment);
312     /* Remove the downlink itself */
313     exit_one_client(acptr, cli_name(&me));
314   }
315   /* Remove all clients of this server */
316   acptrp = cli_serv(cptr)->client_list;
317   for (i = 0; i <= cli_serv(cptr)->nn_mask; ++acptrp, ++i) {
318     if (*acptrp)
319       exit_one_client(*acptrp, comment);
320   }
321 }
322
323 /**
324  * Marks a local client as disconnected, and close its link if it is a local client.
325  *
326  * @param cptr server that notified us
327  * @param killer origin of decision to zombie \a victim
328  * @param victim zombied client
329  */
330 void zombie_client(struct Client *cptr, struct Client *killer, struct Client *victim)
331 {
332   assert(IsServer(cptr) || IsMe(cptr));
333   assert(IsServer(killer) || IsMe(killer));
334   assert(IsUser(victim));
335
336   /*
337    * Stop a running /LIST clean
338    */
339   if (MyUser(victim) && cli_listing(victim)) {
340     MyFree(cli_listing(victim));
341     cli_listing(victim) = NULL;
342   }
343
344   if (MyConnect(victim))
345     close_connection(victim);
346   /* need this so that main loop doesn't exit the client */
347   ClrFlag(victim, FLAG_DEADSOCKET);
348
349   SetNotConn(victim);
350   sendcmdto_serv_butone(killer, CMD_ZOMBIE, cptr, "%C", victim);
351 }
352
353 /**
354  * Attaches a client to a zombied client, removing the superfluous client in the process.
355  *
356  * @param cptr server that notified us
357  * @param sptr origin server of unzombie operation
358  * @param acptr client that is attaching to \a victim
359  * @param victim zombied client that someone is attaching to
360  */
361 void unzombie_client(struct Client *cptr, struct Client *sptr, struct Client *acptr, struct Client *victim)
362 {
363   assert(IsServer(cptr) || IsMe(cptr));
364   assert(IsServer(sptr) || IsMe(sptr));
365   assert(IsUser(acptr));
366   assert(IsNotConn(victim));
367
368   if (MyConnect(acptr))
369     connection_switch_to_client(acptr, victim);
370
371   ClearOper(victim);
372   ClearNotConn(victim);
373
374   if (MyConnect(victim)) {
375     /* inform client about "new" modes */
376     struct Flags setflags = cli_flags(acptr);
377     struct Membership *chan;
378     sendcmdto_one(acptr, CMD_NICK, victim, "%C", victim);
379     send_umode(victim, victim, &setflags, ALL_UMODES, 0);
380
381     /*
382      * mark current client as zombie on all channels so that it does not show
383      * up in the memberships we'll resend below
384      */
385     for (chan = cli_user(acptr)->channel; chan; chan = chan->next_channel) {
386       SetZombie(chan);
387     }
388
389     /* resend channel memberships */
390     for (chan = cli_user(victim)->channel; chan; chan = chan->next_channel) {
391       struct Channel *chptr = chan->channel;
392       /* pretty unlikely to happen but let's handle this anyway */
393       if (IsZombie(chan))
394         continue;
395       sendcmdto_one(victim, CMD_JOIN, victim, ":%H", chptr);
396       if (chptr->topic[0]) {
397         send_reply(victim, RPL_TOPIC, chptr->chname, chptr->topic);
398         send_reply(victim, RPL_TOPICWHOTIME, chptr->chname, chptr->topic_nick,
399                    chptr->topic_time);
400       }
401       do_names(victim, chptr, NAMES_ALL|NAMES_EON); /* send /names list */
402     }
403   }
404
405   sendcmdto_serv_butone(sptr, CMD_UNZOMBIE, cptr, "%C %C", acptr, victim);
406 }
407
408 /* exit_client, rewritten 25-9-94 by Run */
409 /**
410  * Exits a client of *any* type (user, server, etc)
411  * from this server. Also, this generates all necessary prototol
412  * messages that this exit may cause.
413  *
414  * This function implicitly exits all other clients depending on
415  * this connection.
416  *
417  * For convenience, this function returns a suitable value for
418  * m_function return value:
419  *
420  *   CPTR_KILLED     if (cptr == bcptr)
421  *   0                if (cptr != bcptr)
422  *
423  * This function can be called in two ways:
424  * 1) From before or in parse(), exiting the 'cptr', in which case it was
425  *    invoked as exit_client(cptr, cptr, &me,...), causing it to always
426  *    return CPTR_KILLED.
427  * 2) Via parse from a m_function call, in which case it was invoked as
428  *    exit_client(cptr, acptr, sptr, ...). Here 'sptr' is known; the client
429  *    that generated the message in a way that we can assume he already
430  *    did remove acptr from memory himself (or in other cases we don't mind
431  *    because he will be delinked.) Or invoked as:
432  *    exit_client(cptr, acptr/sptr, &me, ...) when WE decide this one should
433  *    be removed.
434  * In general: No generated SQUIT or QUIT should be sent to source link
435  * sptr->from. And CPTR_KILLED should be returned if cptr got removed (too).
436  *
437  * --Run
438  * @param cptr Connection currently being handled by read_message.
439  * @param victim Client being killed.
440  * @param killer Client that made the decision to remove \a victim.
441  * @param comment Reason for the exit.
442  * @return CPTR_KILLED if cptr == bcptr, else 0.
443  */
444 int exit_client(struct Client *cptr,
445     struct Client* victim,
446     struct Client* killer,
447     const char* comment)
448 {
449   struct Client* acptr = 0;
450   struct DLink *dlp;
451   time_t on_for;
452
453   char comment1[HOSTLEN + HOSTLEN + 2];
454   assert(killer);
455   if (MyConnect(victim))
456   {
457     SetFlag(victim, FLAG_CLOSING);
458
459     if (feature_bool(FEAT_CONNEXIT_NOTICES) && IsUser(victim))
460       sendto_opmask_butone(0, SNO_CONNEXIT,
461                            "Client exiting: %s (%s@%s) [%s] [%s] <%s%s>",
462                            cli_name(victim), cli_user(victim)->username,
463                            cli_user(victim)->host, comment,
464                            ircd_ntoa(&cli_ip(victim)),
465                            NumNick(victim) /* two %s's */);
466     update_load();
467
468     on_for = CurrentTime - cli_firsttime(victim);
469
470     if (IsUser(victim) || IsUserPort(victim))
471       auth_send_exit(victim);
472
473     if (IsUser(victim))
474       log_write(LS_USER, L_TRACE, 0, "%Tu %i %s@%s %s %s %s%s %s :%s",
475                 cli_firsttime(victim), on_for,
476                 cli_user(victim)->username, cli_sockhost(victim),
477                 ircd_ntoa(&cli_ip(victim)),
478                 IsAccount(victim) ? cli_username(victim) : "0",
479                 NumNick(victim), /* two %s's */
480                 cli_name(victim), cli_info(victim));
481
482     if (victim != cli_from(killer)  /* The source knows already */
483         && IsClient(victim))    /* Not a Ping struct or Log file */
484     {
485       if (IsServer(victim) || IsHandshake(victim))
486         sendcmdto_one(killer, CMD_SQUIT, victim, "%s 0 :%s", cli_name(&me), comment);
487       else if (!IsConnecting(victim)) {
488         if (!IsDead(victim)) {
489           if (IsServer(victim))
490             sendcmdto_one(killer, CMD_ERROR, victim,
491                           ":Closing Link: %s by %s (%s)", cli_name(victim),
492                           cli_name(killer), comment);
493           else
494             sendrawto_one(victim, MSG_ERROR " :Closing Link: %s by %s (%s)",
495                           cli_name(victim),
496                           cli_name(IsServer(killer) ? &his : killer),
497                           comment);
498         }
499       }
500       if ((IsServer(victim) || IsHandshake(victim) || IsConnecting(victim)) &&
501           (killer == &me || (IsServer(killer) &&
502           (strncmp(comment, "Leaf-only link", 14) ||
503           strncmp(comment, "Non-Hub link", 12)))))
504       {
505         /*
506          * Note: check user == user needed to make sure we have the same
507          * client
508          */
509         if (cli_serv(victim)->user && *(cli_serv(victim))->by &&
510             (acptr = findNUser(cli_serv(victim)->by))) {
511           if (cli_user(acptr) == cli_serv(victim)->user) {
512             sendcmdto_one(&me, CMD_NOTICE, acptr,
513                           "%C :Link with %s canceled: %s", acptr,
514                           cli_name(victim), comment);
515           }
516           else {
517             /*
518              * not right client, set by to empty string
519              */
520             acptr = 0;
521             *(cli_serv(victim))->by = '\0';
522           }
523         }
524         if (killer == &me)
525           sendto_opmask_butone(acptr, SNO_OLDSNO, "Link with %s canceled: %s",
526                                cli_name(victim), comment);
527       }
528     }
529     /*
530      *  Close the Client connection first.
531      */
532     close_connection(victim);
533   }
534
535   if (IsServer(victim))
536   {
537     if (feature_bool(FEAT_HIS_NETSPLIT))
538       strcpy(comment1, "*.net *.split");
539     else
540     {
541       strcpy(comment1, cli_name(cli_serv(victim)->up));
542       strcat(comment1, " ");
543       strcat(comment1, cli_name(victim));
544     }
545
546     if (IsUser(killer))
547       sendto_opmask_butone(killer, SNO_OLDSNO, "%s SQUIT by %s [%s]:",
548                            (cli_user(killer)->server == victim ||
549                             cli_user(killer)->server == cli_serv(victim)->up) ?
550                            "Local" : "Remote",
551                            get_client_name(killer, HIDE_IP),
552                            cli_name(cli_user(killer)->server));
553     else if (killer != &me && cli_serv(victim)->up != killer)
554       sendto_opmask_butone(0, SNO_OLDSNO, "Received SQUIT %s from %s :",
555                            cli_name(victim), IsServer(killer) ? cli_name(killer) :
556                            get_client_name(killer, HIDE_IP));
557     sendto_opmask_butone(0, SNO_NETWORK, "Net break: %C %C (%s)",
558                          cli_serv(victim)->up, victim, comment);
559   }
560
561   /*
562    * First generate the needed protocol for the other server links
563    * except the source:
564    */
565   for (dlp = cli_serv(&me)->down; dlp; dlp = dlp->next) {
566     if (dlp->value.cptr != cli_from(killer) && dlp->value.cptr != victim)
567     {
568       if (IsServer(victim))
569         sendcmdto_one(killer, CMD_SQUIT, dlp->value.cptr, "%s %Tu :%s",
570                       cli_name(victim), cli_serv(victim)->timestamp, comment);
571       else if (IsUser(victim) && !HasFlag(victim, FLAG_KILLED))
572         sendcmdto_one(victim, CMD_QUIT, dlp->value.cptr, ":%s", comment);
573     }
574   }
575   /* Then remove the client structures */
576   if (IsServer(victim))
577     exit_downlinks(victim, killer, comment1);
578   exit_one_client(victim, comment);
579
580   /*
581    *  cptr can only have been killed if it was cptr itself that got killed here,
582    *  because cptr can never have been a dependent of victim    --Run
583    */
584   return (cptr == victim) ? CPTR_KILLED : 0;
585 }
586
587 /**
588  * Exit client with formatted va_list message.
589  * Thin wrapper around exit_client().
590  * @param cptr Connection being processed.
591  * @param bcptr Connection being closed.
592  * @param sptr Connection who asked to close the victim.
593  * @param pattern Format string for message.
594  * @param vl Stdargs argument list.
595  * @return Has a tail call to exit_client().
596  */
597 /* added 25-9-94 by Run */
598 int vexit_client_msg(struct Client *cptr, struct Client *bcptr, struct Client *sptr,
599     const char *pattern, va_list vl)
600 {
601   char msgbuf[1024];
602   ircd_vsnprintf(0, msgbuf, sizeof(msgbuf), pattern, vl);
603   return exit_client(cptr, bcptr, sptr, msgbuf);
604 }
605
606 /**
607  * Exit client with formatted message using a variable-length argument list.
608  * Thin wrapper around exit_client().
609  * @param cptr Connection being processed.
610  * @param bcptr Connection being closed.
611  * @param sptr Connection who asked to close the victim.
612  * @param pattern Format string for message.
613  * @return Has a tail call to exit_client().
614  */
615 int exit_client_msg(struct Client *cptr, struct Client *bcptr,
616     struct Client *sptr, const char *pattern, ...)
617 {
618   va_list vl;
619   char msgbuf[1024];
620
621   va_start(vl, pattern);
622   ircd_vsnprintf(0, msgbuf, sizeof(msgbuf), pattern, vl);
623   va_end(vl);
624
625   return exit_client(cptr, bcptr, sptr, msgbuf);
626 }
627
628 /** Initialize global server statistics. */
629 /* (Kind of pointless since C guarantees it's already zero'ed, but... */
630 void initstats(void)
631 {
632   memset(&ircst, 0, sizeof(ircst));
633 }
634
635 /** Report server statistics to a client.
636  * @param cptr Client who wants statistics.
637  * @param sd StatDesc structure being looked up (unused).
638  * @param param Extra parameter passed by user (unused).
639  */
640 void tstats(struct Client *cptr, const struct StatDesc *sd, char *param)
641 {
642   struct Client *acptr;
643   int i;
644   struct ServerStatistics *sp;
645   struct ServerStatistics tmp;
646
647   sp = &tmp;
648   memcpy(sp, ServerStats, sizeof(struct ServerStatistics));
649   for (i = 0; i < MAXCONNECTIONS; i++)
650   {
651     if (!(acptr = LocalClientArray[i]))
652       continue;
653     if (IsServer(acptr))
654     {
655       sp->is_sbs += cli_sendB(acptr);
656       sp->is_sbr += cli_receiveB(acptr);
657       sp->is_sti += CurrentTime - cli_firsttime(acptr);
658       sp->is_sv++;
659     }
660     else if (IsUser(acptr))
661     {
662       sp->is_cbs += cli_sendB(acptr);
663       sp->is_cbr += cli_receiveB(acptr);
664       sp->is_cti += CurrentTime - cli_firsttime(acptr);
665       sp->is_cl++;
666     }
667     else if (IsUnknown(acptr))
668       sp->is_ni++;
669   }
670
671   send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":accepts %u refused %u",
672              sp->is_ac, sp->is_ref);
673   send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
674              ":unknown commands %u prefixes %u", sp->is_unco, sp->is_unpf);
675   send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
676              ":nick collisions %u unknown closes %u", sp->is_kill, sp->is_ni);
677   send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
678              ":wrong direction %u empty %u", sp->is_wrdi, sp->is_empt);
679   send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
680              ":numerics seen %u mode fakes %u", sp->is_num, sp->is_fake);
681   send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
682              ":auth successes %u fails %u", sp->is_asuc, sp->is_abad);
683   send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":local connections %u",
684              sp->is_loc);
685   send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Client server");
686   send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":connected %u %u",
687              sp->is_cl, sp->is_sv);
688   send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":bytes sent %Lu %Lu",
689              sp->is_cbs, sp->is_sbs);
690   send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":bytes recv %Lu %Lu",
691              sp->is_cbr, sp->is_sbr);
692   send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":time connected %Lu %Lu",
693              sp->is_cti, sp->is_sti);
694 }