| 1 |
adx |
30 |
/* |
| 2 |
michael |
2820 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
adx |
30 |
* |
| 4 |
michael |
2820 |
* Copyright (c) 2001-2014 ircd-hybrid development team |
| 5 |
adx |
30 |
* |
| 6 |
|
|
* This program is free software; you can redistribute it and/or modify |
| 7 |
|
|
* it under the terms of the GNU General Public License as published by |
| 8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
|
|
* (at your option) any later version. |
| 10 |
|
|
* |
| 11 |
|
|
* This program is distributed in the hope that it will be useful, |
| 12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
|
|
* GNU General Public License for more details. |
| 15 |
|
|
* |
| 16 |
|
|
* You should have received a copy of the GNU General Public License |
| 17 |
|
|
* along with this program; if not, write to the Free Software |
| 18 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 19 |
|
|
* USA |
| 20 |
|
|
*/ |
| 21 |
|
|
|
| 22 |
michael |
2820 |
/*! \file m_map.c |
| 23 |
|
|
* \brief Includes required functions for processing the MAP command. |
| 24 |
|
|
* \version $Id$ |
| 25 |
|
|
*/ |
| 26 |
|
|
|
| 27 |
adx |
30 |
#include "stdinc.h" |
| 28 |
|
|
#include "client.h" |
| 29 |
|
|
#include "modules.h" |
| 30 |
|
|
#include "numeric.h" |
| 31 |
|
|
#include "send.h" |
| 32 |
michael |
1309 |
#include "conf.h" |
| 33 |
adx |
30 |
#include "ircd.h" |
| 34 |
|
|
#include "irc_string.h" |
| 35 |
michael |
1243 |
#include "parse.h" |
| 36 |
michael |
1851 |
#include "s_user.h" |
| 37 |
adx |
30 |
|
| 38 |
michael |
889 |
|
| 39 |
adx |
30 |
|
| 40 |
michael |
1851 |
static void dump_map(struct Client *client, |
| 41 |
|
|
struct Client *server, |
| 42 |
|
|
unsigned int prompt_length) |
| 43 |
adx |
30 |
{ |
| 44 |
michael |
1851 |
dlink_node *ptr = NULL; |
| 45 |
|
|
struct Client *target_p = NULL; |
| 46 |
|
|
static char prompt[64]; |
| 47 |
|
|
char *p = prompt + prompt_length; |
| 48 |
|
|
int cnt = 0; |
| 49 |
adx |
30 |
|
| 50 |
michael |
1851 |
*p = '\0'; |
| 51 |
adx |
30 |
|
| 52 |
michael |
1851 |
if (prompt_length > 60) |
| 53 |
|
|
sendto_one(client, form_str(RPL_MAPMORE), me.name, |
| 54 |
|
|
client->name, prompt, server->name); |
| 55 |
|
|
else |
| 56 |
adx |
30 |
{ |
| 57 |
michael |
1851 |
char buf[IRC_MAXSID + 3] = ""; /* +3 for [, ], \0 */ |
| 58 |
adx |
30 |
|
| 59 |
michael |
1851 |
if (HasUMode(client, UMODE_OPER) && server->id[0]) |
| 60 |
|
|
snprintf(buf, sizeof(buf), "[%s]", server->id); |
| 61 |
michael |
889 |
|
| 62 |
michael |
1851 |
sendto_one(client, form_str(RPL_MAP), me.name, client->name, |
| 63 |
|
|
prompt, server->name, buf, |
| 64 |
|
|
dlink_list_length(&server->serv->client_list), |
| 65 |
|
|
dlink_list_length(&server->serv->client_list) * 100 / Count.total); |
| 66 |
|
|
} |
| 67 |
michael |
889 |
|
| 68 |
michael |
1851 |
if (prompt_length > 0) |
| 69 |
|
|
{ |
| 70 |
|
|
*(p - 1) = ' '; |
| 71 |
adx |
30 |
|
| 72 |
michael |
1851 |
if (*(p - 2) == '`') |
| 73 |
|
|
*(p - 2) = ' '; |
| 74 |
|
|
} |
| 75 |
adx |
30 |
|
| 76 |
michael |
1851 |
if (prompt_length > 60) |
| 77 |
|
|
return; |
| 78 |
|
|
strcpy(p, "|-"); |
| 79 |
adx |
30 |
|
| 80 |
michael |
1851 |
DLINK_FOREACH(ptr, server->serv->server_list.head) |
| 81 |
adx |
30 |
{ |
| 82 |
michael |
1851 |
target_p = ptr->data; |
| 83 |
adx |
30 |
|
| 84 |
michael |
2751 |
if (IsHidden(target_p) && !HasUMode(client, UMODE_OPER)) |
| 85 |
|
|
continue; |
| 86 |
|
|
|
| 87 |
michael |
1851 |
if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services) |
| 88 |
|
|
if (!HasUMode(client, UMODE_OPER)) |
| 89 |
|
|
continue; |
| 90 |
adx |
30 |
|
| 91 |
michael |
1851 |
++cnt; |
| 92 |
adx |
30 |
} |
| 93 |
|
|
|
| 94 |
michael |
1851 |
DLINK_FOREACH(ptr, server->serv->server_list.head) |
| 95 |
adx |
30 |
{ |
| 96 |
michael |
1851 |
target_p = ptr->data; |
| 97 |
adx |
30 |
|
| 98 |
michael |
2751 |
if (IsHidden(target_p) && !HasUMode(client, UMODE_OPER)) |
| 99 |
|
|
continue; |
| 100 |
|
|
|
| 101 |
michael |
1851 |
if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services) |
| 102 |
|
|
if (!HasUMode(client, UMODE_OPER)) |
| 103 |
|
|
continue; |
| 104 |
michael |
889 |
|
| 105 |
michael |
1851 |
if (--cnt == 0) |
| 106 |
|
|
*p = '`'; |
| 107 |
|
|
dump_map(client, target_p, prompt_length + 2); |
| 108 |
|
|
} |
| 109 |
michael |
889 |
|
| 110 |
michael |
1851 |
if (prompt_length > 0) |
| 111 |
|
|
*(p - 1) = '-'; |
| 112 |
adx |
30 |
} |
| 113 |
michael |
1230 |
|
| 114 |
|
|
/* m_map() |
| 115 |
|
|
* parv[0] = sender prefix |
| 116 |
|
|
*/ |
| 117 |
michael |
2820 |
static int |
| 118 |
michael |
1230 |
m_map(struct Client *client_p, struct Client *source_p, |
| 119 |
|
|
int parc, char *parv[]) |
| 120 |
|
|
{ |
| 121 |
|
|
static time_t last_used = 0; |
| 122 |
|
|
|
| 123 |
|
|
if (ConfigServerHide.flatten_links) |
| 124 |
michael |
2820 |
return m_not_oper(client_p, source_p, parc, parv); |
| 125 |
michael |
1230 |
|
| 126 |
|
|
if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime) |
| 127 |
|
|
{ |
| 128 |
|
|
/* safe enough to give this on a local connect only */ |
| 129 |
michael |
1834 |
sendto_one(source_p, form_str(RPL_LOAD2HI), |
| 130 |
michael |
1230 |
me.name, source_p->name); |
| 131 |
michael |
2820 |
return 0; |
| 132 |
michael |
1230 |
} |
| 133 |
|
|
|
| 134 |
|
|
last_used = CurrentTime; |
| 135 |
|
|
|
| 136 |
michael |
1851 |
dump_map(source_p, &me, 0); |
| 137 |
michael |
1834 |
sendto_one(source_p, form_str(RPL_MAPEND), me.name, source_p->name); |
| 138 |
michael |
2820 |
return 0; |
| 139 |
michael |
1230 |
} |
| 140 |
|
|
|
| 141 |
|
|
/* mo_map() |
| 142 |
|
|
* parv[0] = sender prefix |
| 143 |
|
|
*/ |
| 144 |
michael |
2820 |
static int |
| 145 |
michael |
1230 |
mo_map(struct Client *client_p, struct Client *source_p, |
| 146 |
|
|
int parc, char *parv[]) |
| 147 |
|
|
{ |
| 148 |
michael |
1851 |
dump_map(source_p, &me, 0); |
| 149 |
michael |
1834 |
sendto_one(source_p, form_str(RPL_MAPEND), me.name, source_p->name); |
| 150 |
michael |
2820 |
return 0; |
| 151 |
michael |
1230 |
} |
| 152 |
|
|
|
| 153 |
michael |
2820 |
static struct Message map_msgtab = |
| 154 |
|
|
{ |
| 155 |
michael |
1230 |
"MAP", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
| 156 |
|
|
{ m_unregistered, m_map, m_ignore, m_ignore, mo_map, m_ignore } |
| 157 |
|
|
}; |
| 158 |
|
|
|
| 159 |
|
|
static void |
| 160 |
|
|
module_init(void) |
| 161 |
|
|
{ |
| 162 |
|
|
mod_add_cmd(&map_msgtab); |
| 163 |
|
|
} |
| 164 |
|
|
|
| 165 |
|
|
static void |
| 166 |
|
|
module_exit(void) |
| 167 |
|
|
{ |
| 168 |
|
|
mod_del_cmd(&map_msgtab); |
| 169 |
|
|
} |
| 170 |
|
|
|
| 171 |
michael |
2820 |
struct module module_entry = |
| 172 |
|
|
{ |
| 173 |
michael |
1230 |
.node = { NULL, NULL, NULL }, |
| 174 |
|
|
.name = NULL, |
| 175 |
|
|
.version = "$Revision$", |
| 176 |
|
|
.handle = NULL, |
| 177 |
|
|
.modinit = module_init, |
| 178 |
|
|
.modexit = module_exit, |
| 179 |
|
|
.flags = 0 |
| 180 |
|
|
}; |