]>
jfr.im git - solanum.git/blob - modules/m_map.c
2 * ircd-ratbox: A slightly useful ircd.
3 * m_map.c: Sends an Undernet compatible map to a user.
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
31 #define USER_COL 50 /* display | Users: %d at col 50 */
33 static int m_map(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
34 static int mo_map(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
36 struct Message map_msgtab
= {
38 {mg_unreg
, {m_map
, 0}, mg_ignore
, mg_ignore
, mg_ignore
, {mo_map
, 0}}
41 mapi_clist_av1 map_clist
[] = { &map_msgtab
, NULL
};
43 static const char map_desc
[] = "Provides the MAP command to view network topology information";
45 DECLARE_MODULE_AV2(map
, NULL
, NULL
, map_clist
, NULL
, NULL
, NULL
, NULL
, map_clist
);
47 static void dump_map(struct Client
*client_p
, struct Client
*root
, char *pbuf
);
48 static void flattened_map(struct Client
*client_p
);
50 static char buf
[BUFSIZE
];
55 m_map(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
57 if((!IsExemptShide(source_p
) && ConfigServerHide
.flatten_links
) ||
58 ConfigFileEntry
.map_oper_only
)
60 flattened_map(client_p
);
61 sendto_one_numeric(client_p
, RPL_MAPEND
, form_str(RPL_MAPEND
));
65 dump_map(client_p
, &me
, buf
);
66 sendto_one_numeric(client_p
, RPL_MAPEND
, form_str(RPL_MAPEND
));
74 mo_map(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
76 dump_map(client_p
, &me
, buf
);
77 scache_send_missing(client_p
);
78 sendto_one_numeric(client_p
, RPL_MAPEND
, form_str(RPL_MAPEND
));
85 ** dumps server map, called recursively.
88 dump_map(struct Client
*client_p
, struct Client
*root_p
, char *pbuf
)
90 int cnt
= 0, i
= 0, len
, frac
;
91 struct Client
*server_p
;
95 rb_strlcat(pbuf
, root_p
->name
, BUFSIZE
);
98 rb_strlcat(pbuf
, "[", BUFSIZE
);
99 rb_strlcat(pbuf
, root_p
->id
, BUFSIZE
);
100 rb_strlcat(pbuf
, "]", BUFSIZE
);
107 for (i
= len
+ 1; i
< USER_COL
; i
++)
113 frac
= (1000 * rb_dlink_list_length(&root_p
->serv
->users
) + Count
.total
/ 2) / Count
.total
;
114 snprintf(buf
+ USER_COL
, BUFSIZE
- USER_COL
,
115 " | Users: %5lu (%2d.%1d%%)", rb_dlink_list_length(&root_p
->serv
->users
),
116 frac
/ 10, frac
% 10);
118 sendto_one_numeric(client_p
, RPL_MAP
, form_str(RPL_MAP
), buf
);
120 if(root_p
->serv
->servers
.head
!= NULL
)
122 cnt
+= rb_dlink_list_length(&root_p
->serv
->servers
);
135 RB_DLINK_FOREACH(ptr
, root_p
->serv
->servers
.head
)
137 server_p
= ptr
->data
;
146 dump_map(client_p
, server_p
, pbuf
+ 4);
153 * flattened_map - display a version of map that doesn't give away routing
154 * information to users when flattened links is enabled.
157 flattened_map(struct Client
*client_p
)
161 struct Client
*target_p
;
165 /* First display me as the root */
166 rb_strlcpy(buf
, me
.name
, BUFSIZE
);
172 for (i
= len
+ 1; i
< USER_COL
; i
++)
178 snprintf(buf
+ USER_COL
, BUFSIZE
- USER_COL
,
179 " | Users: %5lu (%4.1f%%)", rb_dlink_list_length(&me
.serv
->users
),
180 100 * (float) rb_dlink_list_length(&me
.serv
->users
) / (float) Count
.total
);
182 sendto_one_numeric(client_p
, RPL_MAP
, form_str(RPL_MAP
), buf
);
184 /* Next, we run through every other server and list them */
185 RB_DLINK_FOREACH(ptr
, global_serv_list
.head
)
187 target_p
= ptr
->data
;
191 /* Skip ourselves, it's already counted */
195 /* if we're hidden, go on to the next leaf */
196 if(!ConfigServerHide
.disable_hidden
&& IsHidden(target_p
))
199 if (cnt
== rb_dlink_list_length(&global_serv_list
))
200 rb_strlcpy(buf
, " `- ", BUFSIZE
);
202 rb_strlcpy(buf
, " |- ", BUFSIZE
);
204 rb_strlcat(buf
, target_p
->name
, BUFSIZE
);
210 for (i
= len
+ 1; i
< USER_COL
; i
++)
216 snprintf(buf
+ USER_COL
, BUFSIZE
- USER_COL
,
217 " | Users: %5lu (%4.1f%%)", rb_dlink_list_length(&target_p
->serv
->users
),
218 100 * (float) rb_dlink_list_length(&target_p
->serv
->users
) / (float) Count
.total
);
220 sendto_one_numeric(client_p
, RPL_MAP
, form_str(RPL_MAP
), buf
);