1 |
/* Copyright (C) 2003 Stephane Thiell |
2 |
* |
3 |
* This file is part of pxyservd (from pxys) |
4 |
* |
5 |
* This program is free software; you can redistribute it and/or |
6 |
* modify it under the terms of the GNU General Public License |
7 |
* as published by the Free Software Foundation; either version 2 |
8 |
* of the License, or (at your option) any later version. |
9 |
* |
10 |
* This program is distributed in the hope that it will be useful, |
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
* GNU General Public License for more details. |
14 |
* |
15 |
* You should have received a copy of the GNU General Public License |
16 |
* along with this program; if not, write to the Free Software |
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
* |
19 |
*/ |
20 |
#define RCSID "$Id: cmd_servers.c,v 1.1.1.1 2003/12/30 17:09:29 mbuna Exp $" |
21 |
|
22 |
#include "irc_cmd.h" |
23 |
#include "irc_msg.h" |
24 |
#include "irc_send.h" |
25 |
#include "cfgloader.h" |
26 |
|
27 |
#include "irc_membership.h" |
28 |
#include "irc_channel.h" |
29 |
#include "irc_client.h" |
30 |
#include "irc_userbase.h" |
31 |
#include "scan.h" |
32 |
#include "session.h" |
33 |
|
34 |
#include <assert.h> |
35 |
#include <string.h> |
36 |
#include <peak/dict.h> |
37 |
|
38 |
static void |
39 |
servers_end_map(const char *dst) |
40 |
{ |
41 |
int total, hubs, services, leaves; |
42 |
|
43 |
total = irc_network_get_server_count(); |
44 |
hubs = irc_network_get_server_count_flagged(SERVER_FLAG_HUB); |
45 |
services = irc_network_get_server_count_flagged(SERVER_FLAG_SERVICE); |
46 |
leaves = total - irc_network_get_server_count_flagged(SERVER_FLAG_HUB |
47 |
|SERVER_FLAG_SERVICE); |
48 |
|
49 |
send_client_to_one(dst, "End of map (%d servers: %d hubs, %d services, " |
50 |
"%d leaves)", total, hubs, services, leaves); |
51 |
} |
52 |
|
53 |
void |
54 |
cmd_servers(struct Client *cptr, toktabptr ttab) |
55 |
{ |
56 |
const char *dst = ttab->tok[0]; |
57 |
char prompt[64]; |
58 |
char *p = prompt; |
59 |
struct Server *sptr, *sstart, *s, *s2; |
60 |
int i, nolast = 0, ccnt, details = 0; |
61 |
unsigned int cnt; |
62 |
struct Client **cptr_p; |
63 |
struct Server **ssp; /* Downlink server stack pointer */ |
64 |
struct Server *sst[256]; |
65 |
|
66 |
if (irc_network_get_server_count() > 256) /* bah */ |
67 |
return; |
68 |
|
69 |
for (i = 4; i <= 5; i++) |
70 |
{ |
71 |
if (ttab->size <= i) |
72 |
break; |
73 |
|
74 |
if (!strcmp(ttab->tok[i], "-info")) |
75 |
details |= 2; |
76 |
else if (!strcmp(ttab->tok[i], "-scan")) |
77 |
details |= 1; |
78 |
} |
79 |
|
80 |
/* Servers tree map display. |
81 |
*/ |
82 |
ssp = sst; |
83 |
sptr = sstart = &gMe; |
84 |
if (details) |
85 |
send_client_to_one(dst, "%u:%s", sptr->nserv, sptr->name); |
86 |
else |
87 |
send_client_to_one(dst, "%s", sptr->name); |
88 |
*p = '\0'; |
89 |
|
90 |
for (;;) |
91 |
{ |
92 |
sstart = sstart->next; |
93 |
|
94 |
for (s = sstart; s; s = s->next) |
95 |
{ |
96 |
if (s->uplink == sptr) |
97 |
{ |
98 |
int noscan = 1; |
99 |
|
100 |
for (s2 = s->next; s2; s2 = s2->next) |
101 |
{ |
102 |
if (s2->uplink == sptr) |
103 |
{ |
104 |
nolast = 1; |
105 |
break; |
106 |
} |
107 |
} |
108 |
|
109 |
*ssp++ = sptr = s; |
110 |
|
111 |
if (nolast) |
112 |
p[0] = '|', p[1] = '-'; |
113 |
else |
114 |
p[0] = '`', p[1] = '-'; |
115 |
p[2] = '\0'; |
116 |
|
117 |
if (details & 2) |
118 |
{ |
119 |
cnt = 0; |
120 |
cptr_p = sptr->cliT; |
121 |
for (ccnt = sptr->clients; ccnt > 0; cptr_p++) |
122 |
{ |
123 |
if (*cptr_p != NULL) |
124 |
{ |
125 |
cnt += irc_userbase_count_channels(*cptr_p); |
126 |
ccnt--; |
127 |
} |
128 |
} |
129 |
|
130 |
if (details & 1) |
131 |
noscan = scan_check_noscan_server(sptr); |
132 |
|
133 |
send_client_to_one(dst, "%s%u:%s%s%s [%u clients] [%u chanrefs]", |
134 |
prompt, sptr->nserv, noscan ? "" : "\2", |
135 |
sptr->name, noscan ? "" : "\2", |
136 |
sptr->clients, cnt); |
137 |
} |
138 |
else |
139 |
{ |
140 |
|
141 |
if (details & 1) |
142 |
noscan = scan_check_noscan_server(sptr); |
143 |
|
144 |
send_client_to_one(dst, "%s%s%s%s", prompt, noscan ? "" : "\2", |
145 |
sptr->name, noscan ? "" : "\2"); |
146 |
} |
147 |
|
148 |
if (!nolast) |
149 |
p[0] = ' '; |
150 |
else |
151 |
nolast = 0; |
152 |
p[1] = ' '; |
153 |
if (p - prompt > sizeof(prompt) - 4) |
154 |
return; |
155 |
p += 2; |
156 |
s = &gMe; |
157 |
} |
158 |
} |
159 |
|
160 |
if (ssp == sst) |
161 |
break; |
162 |
|
163 |
sstart = *--ssp; |
164 |
sptr = sstart->uplink; |
165 |
*(p -= 2) = '\0'; |
166 |
} |
167 |
servers_end_map(dst); |
168 |
} |