]>
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
22 * $Id: m_map.c 3368 2007-04-03 10:11:06Z nenolod $
33 #define USER_COL 50 /* display | Users: %d at col 50 */
35 static int m_map(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
36 static int mo_map(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
38 struct Message map_msgtab
= {
39 "MAP", 0, 0, 0, MFLG_SLOW
,
40 {mg_unreg
, {m_map
, 0}, mg_ignore
, mg_ignore
, mg_ignore
, {mo_map
, 0}}
43 mapi_clist_av1 map_clist
[] = { &map_msgtab
, NULL
};
44 DECLARE_MODULE_AV1(map
, NULL
, NULL
, map_clist
, NULL
, NULL
, "$Revision: 3368 $");
46 static void dump_map(struct Client
*client_p
, struct Client
*root
, char *pbuf
);
48 static char buf
[BUFSIZE
];
53 m_map(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
55 if((!IsExemptShide(source_p
) && ConfigServerHide
.flatten_links
) ||
56 ConfigFileEntry
.map_oper_only
)
58 m_not_oper(client_p
, source_p
, parc
, parv
);
62 dump_map(client_p
, &me
, buf
);
63 sendto_one_numeric(client_p
, RPL_MAPEND
, form_str(RPL_MAPEND
));
71 mo_map(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
73 dump_map(client_p
, &me
, buf
);
74 scache_send_missing(client_p
);
75 sendto_one_numeric(client_p
, RPL_MAPEND
, form_str(RPL_MAPEND
));
82 ** dumps server map, called recursively.
85 dump_map(struct Client
*client_p
, struct Client
*root_p
, char *pbuf
)
87 int cnt
= 0, i
= 0, len
, frac
;
88 struct Client
*server_p
;
92 rb_strlcat(pbuf
, root_p
->name
, BUFSIZE
);
95 rb_strlcat(pbuf
, "[", BUFSIZE
);
96 rb_strlcat(pbuf
, root_p
->id
, BUFSIZE
);
97 rb_strlcat(pbuf
, "]", BUFSIZE
);
104 for (i
= len
+ 1; i
< USER_COL
; i
++)
110 frac
= (1000 * rb_dlink_list_length(&root_p
->serv
->users
) + Count
.total
/ 2) / Count
.total
;
111 rb_snprintf(buf
+ USER_COL
, BUFSIZE
- USER_COL
,
112 " | Users: %5lu (%2d.%1d%%)", rb_dlink_list_length(&root_p
->serv
->users
),
113 frac
/ 10, frac
% 10);
115 sendto_one_numeric(client_p
, RPL_MAP
, form_str(RPL_MAP
), buf
);
117 if(root_p
->serv
->servers
.head
!= NULL
)
119 cnt
+= rb_dlink_list_length(&root_p
->serv
->servers
);
132 RB_DLINK_FOREACH(ptr
, root_p
->serv
->servers
.head
)
134 server_p
= ptr
->data
;
143 dump_map(client_p
, server_p
, pbuf
+ 4);