Author: Bleep <tomh@inxpress.net>
[ircu2.10.12-pk.git] / ircd / opercmds.c
1 /*
2  * IRC - Internet Relay Chat, ircd/opercmds.c (formerly ircd/s_serv.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 #include "opercmds.h"
26 #include "class.h"
27 #include "client.h"
28 #include "crule.h"
29 #include "ircd.h"
30 #include "ircd_chattr.h"
31 #include "ircd_reply.h"
32 #include "ircd_string.h"
33 #include "listener.h"
34 #include "match.h"
35 #include "msg.h"
36 #include "numeric.h"
37 #include "numnicks.h"
38 #include "s_conf.h"
39 #include "send.h"
40 #include "struct.h"
41
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <sys/time.h>
45
46 /*
47  * m_stats/stats_conf
48  *
49  * Report N/C-configuration lines from this server. This could
50  * report other configuration lines too, but converting the
51  * status back to "char" is a bit akward--not worth the code
52  * it needs...
53  *
54  * Note: The info is reported in the order the server uses
55  *       it--not reversed as in ircd.conf!
56  */
57
58 static unsigned int report_array[17][3] = {
59   {CONF_SERVER, RPL_STATSCLINE, 'C'},
60   {CONF_CLIENT, RPL_STATSILINE, 'I'},
61   {CONF_KILL, RPL_STATSKLINE, 'K'},
62   {CONF_IPKILL, RPL_STATSKLINE, 'k'},
63   {CONF_LEAF, RPL_STATSLLINE, 'L'},
64   {CONF_OPERATOR, RPL_STATSOLINE, 'O'},
65   {CONF_HUB, RPL_STATSHLINE, 'H'},
66   {CONF_LOCOP, RPL_STATSOLINE, 'o'},
67   {CONF_CRULEALL, RPL_STATSDLINE, 'D'},
68   {CONF_CRULEAUTO, RPL_STATSDLINE, 'd'},
69   {CONF_UWORLD, RPL_STATSULINE, 'U'},
70   {CONF_TLINES, RPL_STATSTLINE, 'T'},
71   {0, 0}
72 };
73
74 void report_configured_links(struct Client *sptr, int mask)
75 {
76   static char null[] = "<NULL>";
77   struct ConfItem *tmp;
78   unsigned int *p;
79   unsigned short int port;
80   char c, *host, *pass, *name;
81
82   for (tmp = GlobalConfList; tmp; tmp = tmp->next) {
83     if ((tmp->status & mask))
84     {
85       for (p = &report_array[0][0]; *p; p += 3)
86         if (*p == tmp->status)
87           break;
88       if (!*p)
89         continue;
90       c = (char)*(p + 2);
91       host = BadPtr(tmp->host) ? null : tmp->host;
92       pass = BadPtr(tmp->passwd) ? null : tmp->passwd;
93       name = BadPtr(tmp->name) ? null : tmp->name;
94       port = tmp->port;
95       /*
96        * On K line the passwd contents can be
97        * displayed on STATS reply.    -Vesa
98        */
99       /* Special-case 'k' or 'K' lines as appropriate... -Kev */
100       if ((tmp->status & CONF_KLINE))
101         sendto_one(sptr, rpl_str(p[1]), me.name,
102             sptr->name, c, host, pass, name, port, get_conf_class(tmp));
103       /*
104        * connect rules are classless
105        */
106       else if ((tmp->status & CONF_CRULE))
107         sendto_one(sptr, rpl_str(p[1]), me.name, sptr->name, c, host, name);
108       else if ((tmp->status & CONF_TLINES))
109         sendto_one(sptr, rpl_str(p[1]), me.name, sptr->name, c, host, pass);
110       else if ((tmp->status & CONF_UWORLD))
111         sendto_one(sptr, rpl_str(p[1]),
112             me.name, sptr->name, c, host, pass, name, port,
113             get_conf_class(tmp));
114       else if ((tmp->status & CONF_SERVER))
115         sendto_one(sptr, rpl_str(p[1]), me.name, sptr->name, c, "*", name,
116             port, get_conf_class(tmp));
117       else
118         sendto_one(sptr, rpl_str(p[1]), me.name, sptr->name, c, host, name,
119             port, get_conf_class(tmp));
120     }
121   }
122 }
123
124 char *militime(char* sec, char* usec)
125 {
126   struct timeval tv;
127   static char timebuf[18];
128
129   gettimeofday(&tv, NULL);
130   if (sec && usec)
131     sprintf(timebuf, "%ld",
132         (tv.tv_sec - atoi(sec)) * 1000 + (tv.tv_usec - atoi(usec)) / 1000);
133   else
134     sprintf(timebuf, "%ld %ld", tv.tv_sec, tv.tv_usec);
135   return timebuf;
136 }
137