| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
* m_map.c: Sends an Undernet compatible map to a user. |
| 4 |
* |
| 5 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
| 6 |
* |
| 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. |
| 11 |
* |
| 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. |
| 16 |
* |
| 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 |
| 20 |
* USA |
| 21 |
* |
| 22 |
* $Id$ |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "stdinc.h" |
| 26 |
#include "client.h" |
| 27 |
#include "modules.h" |
| 28 |
#include "handlers.h" |
| 29 |
#include "numeric.h" |
| 30 |
#include "send.h" |
| 31 |
#include "s_conf.h" |
| 32 |
#include "ircd.h" |
| 33 |
#include "irc_string.h" |
| 34 |
#include "sprintf_irc.h" |
| 35 |
|
| 36 |
static void m_map(struct Client *, struct Client *, int, char *[]); |
| 37 |
static void mo_map(struct Client *, struct Client *, int, char *[]); |
| 38 |
static void dump_map(struct Client *, struct Client *, int, char *); |
| 39 |
|
| 40 |
struct Message map_msgtab = { |
| 41 |
"MAP", 0, 0, 0, 0, MFLG_SLOW, 0, |
| 42 |
{m_unregistered, m_map, m_ignore, m_ignore, mo_map, m_ignore} |
| 43 |
}; |
| 44 |
|
| 45 |
#ifndef STATIC_MODULES |
| 46 |
void _modinit(void) |
| 47 |
{ |
| 48 |
mod_add_cmd(&map_msgtab); |
| 49 |
} |
| 50 |
|
| 51 |
void _moddeinit(void) |
| 52 |
{ |
| 53 |
mod_del_cmd(&map_msgtab); |
| 54 |
} |
| 55 |
|
| 56 |
const char *_version = "$Revision$"; |
| 57 |
#endif |
| 58 |
|
| 59 |
static char buf[IRCD_BUFSIZE]; |
| 60 |
|
| 61 |
/* m_map() |
| 62 |
* parv[0] = sender prefix |
| 63 |
*/ |
| 64 |
static void |
| 65 |
m_map(struct Client *client_p, struct Client *source_p, |
| 66 |
int parc, char *parv[]) |
| 67 |
{ |
| 68 |
if (!ConfigServerHide.flatten_links) |
| 69 |
{ |
| 70 |
dump_map(client_p, &me, 0, buf); |
| 71 |
sendto_one(client_p, form_str(RPL_MAPEND), me.name, client_p->name); |
| 72 |
return; |
| 73 |
} |
| 74 |
|
| 75 |
m_not_oper(client_p, source_p, parc, parv); |
| 76 |
} |
| 77 |
|
| 78 |
/* mo_map() |
| 79 |
* parv[0] = sender prefix |
| 80 |
*/ |
| 81 |
static void |
| 82 |
mo_map(struct Client *client_p, struct Client *source_p, |
| 83 |
int parc, char *parv[]) |
| 84 |
{ |
| 85 |
dump_map(client_p, &me, 0, buf); |
| 86 |
sendto_one(client_p, form_str(RPL_MAPEND), me.name, client_p->name); |
| 87 |
} |
| 88 |
|
| 89 |
/* dump_map() |
| 90 |
* dumps server map, called recursively. |
| 91 |
*/ |
| 92 |
static void |
| 93 |
dump_map(struct Client *client_p, struct Client *root_p, int start_len, |
| 94 |
char *pbuf) |
| 95 |
{ |
| 96 |
int cnt = 0, i = 0, l = 0, len = start_len; |
| 97 |
int users, dashes; |
| 98 |
dlink_node *ptr; |
| 99 |
struct Client *server_p; |
| 100 |
char *pb; |
| 101 |
|
| 102 |
*pbuf= '\0'; |
| 103 |
pb = pbuf; |
| 104 |
|
| 105 |
l = ircsprintf(pb, "%s", root_p->name); |
| 106 |
pb += l; |
| 107 |
len += l; |
| 108 |
|
| 109 |
/* IsOper isn't called *that* often. */ |
| 110 |
if (IsOper(client_p)) |
| 111 |
{ |
| 112 |
if (root_p->id[0] != '\0') |
| 113 |
{ |
| 114 |
l = ircsprintf(pb, "[%s]", root_p->id); |
| 115 |
pb += l; |
| 116 |
len += l; |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
*pb++ = ' '; |
| 121 |
len++; |
| 122 |
dashes = 50 - len; |
| 123 |
for(i = 0; i < dashes; i++) |
| 124 |
{ |
| 125 |
*pb++ = '-'; |
| 126 |
} |
| 127 |
*pb++ = ' '; |
| 128 |
*pb++ = '|'; |
| 129 |
|
| 130 |
users = dlink_list_length(&root_p->serv->users); |
| 131 |
|
| 132 |
sprintf(pb, " Users: %5d (%1.1f%%)", users, |
| 133 |
100 * (float)users / (float)Count.total); |
| 134 |
|
| 135 |
sendto_one(client_p, form_str(RPL_MAP), me.name, client_p->name, buf); |
| 136 |
|
| 137 |
if (root_p->serv->servers.head) |
| 138 |
{ |
| 139 |
cnt += dlink_list_length(&root_p->serv->servers); |
| 140 |
|
| 141 |
if (cnt) |
| 142 |
{ |
| 143 |
if (pbuf > buf + 3) |
| 144 |
{ |
| 145 |
pbuf[-2] = ' '; |
| 146 |
|
| 147 |
if (pbuf[-3] == '`') |
| 148 |
pbuf[-3] = ' '; |
| 149 |
} |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
i = 1; |
| 154 |
|
| 155 |
DLINK_FOREACH(ptr, root_p->serv->servers.head) |
| 156 |
{ |
| 157 |
server_p = ptr->data; |
| 158 |
|
| 159 |
*pbuf = ' '; |
| 160 |
if (i < cnt) |
| 161 |
*(pbuf + 1) = '|'; |
| 162 |
else |
| 163 |
*(pbuf + 1) = '`'; |
| 164 |
|
| 165 |
*(pbuf + 2) = '-'; |
| 166 |
*(pbuf + 3) = ' '; |
| 167 |
dump_map(client_p, server_p, start_len+4, pbuf+4); |
| 168 |
|
| 169 |
++i; |
| 170 |
} |
| 171 |
} |