00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "stdinc.h"
00026 #include "client.h"
00027 #include "modules.h"
00028 #include "handlers.h"
00029 #include "numeric.h"
00030 #include "send.h"
00031 #include "s_conf.h"
00032 #include "ircd.h"
00033 #include "irc_string.h"
00034 #include "sprintf_irc.h"
00035
00036 static void m_map(struct Client *, struct Client *, int, char *[]);
00037 static void mo_map(struct Client *, struct Client *, int, char *[]);
00038 static void dump_map(struct Client *, struct Client *, int, char *);
00039
00040 struct Message map_msgtab = {
00041 "MAP", 0, 0, 0, 0, MFLG_SLOW, 0,
00042 {m_unregistered, m_map, m_ignore, m_ignore, mo_map, m_ignore}
00043 };
00044
00045 #ifndef STATIC_MODULES
00046 void _modinit(void)
00047 {
00048 mod_add_cmd(&map_msgtab);
00049 }
00050
00051 void _moddeinit(void)
00052 {
00053 mod_del_cmd(&map_msgtab);
00054 }
00055
00056 const char *_version = "$Revision: 268 $";
00057 #endif
00058
00059 static char buf[IRCD_BUFSIZE];
00060
00061
00062
00063
00064 static void
00065 m_map(struct Client *client_p, struct Client *source_p,
00066 int parc, char *parv[])
00067 {
00068 static time_t last_used = 0;
00069
00070 if (!ConfigServerHide.flatten_links)
00071 {
00072 if (!IsOper(source_p))
00073 {
00074 if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
00075 {
00076
00077 sendto_one(source_p, form_str(RPL_LOAD2HI),
00078 me.name, source_p->name);
00079 return;
00080 }
00081 else
00082 last_used = CurrentTime;
00083 }
00084
00085 dump_map(client_p, &me, 0, buf);
00086 sendto_one(client_p, form_str(RPL_MAPEND), me.name, client_p->name);
00087 return;
00088 }
00089
00090 m_not_oper(client_p, source_p, parc, parv);
00091 }
00092
00093
00094
00095
00096 static void
00097 mo_map(struct Client *client_p, struct Client *source_p,
00098 int parc, char *parv[])
00099 {
00100 dump_map(client_p, &me, 0, buf);
00101 sendto_one(client_p, form_str(RPL_MAPEND), me.name, client_p->name);
00102 }
00103
00104
00105
00106
00107 static void
00108 dump_map(struct Client *client_p, struct Client *root_p, int start_len,
00109 char *pbuf)
00110 {
00111 int cnt = 0, i = 0, l = 0, len = start_len;
00112 int users, dashes;
00113 dlink_node *ptr;
00114 struct Client *server_p;
00115 char *pb;
00116
00117 *pbuf= '\0';
00118 pb = pbuf;
00119
00120 l = ircsprintf(pb, "%s", root_p->name);
00121 pb += l;
00122 len += l;
00123
00124
00125 if (IsOper(client_p))
00126 {
00127 if (root_p->id[0] != '\0')
00128 {
00129 l = ircsprintf(pb, "[%s]", root_p->id);
00130 pb += l;
00131 len += l;
00132 }
00133 }
00134
00135 *pb++ = ' ';
00136 len++;
00137 dashes = 50 - len;
00138 for(i = 0; i < dashes; i++)
00139 {
00140 *pb++ = '-';
00141 }
00142 *pb++ = ' ';
00143 *pb++ = '|';
00144
00145 users = dlink_list_length(&root_p->serv->users);
00146
00147 sprintf(pb, " Users: %5d (%1.1f%%)", users,
00148 100 * (float)users / (float)Count.total);
00149
00150 sendto_one(client_p, form_str(RPL_MAP), me.name, client_p->name, buf);
00151
00152 if (root_p->serv->servers.head)
00153 {
00154 cnt += dlink_list_length(&root_p->serv->servers);
00155
00156 if (cnt)
00157 {
00158 if (pbuf > buf + 3)
00159 {
00160 pbuf[-2] = ' ';
00161
00162 if (pbuf[-3] == '`')
00163 pbuf[-3] = ' ';
00164 }
00165 }
00166 }
00167
00168 i = 1;
00169
00170 DLINK_FOREACH(ptr, root_p->serv->servers.head)
00171 {
00172 server_p = ptr->data;
00173
00174 *pbuf = ' ';
00175 if (i < cnt)
00176 *(pbuf + 1) = '|';
00177 else
00178 *(pbuf + 1) = '`';
00179
00180 *(pbuf + 2) = '-';
00181 *(pbuf + 3) = ' ';
00182 dump_map(client_p, server_p, start_len+4, pbuf+4);
00183
00184 ++i;
00185 }
00186 }