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 "handlers.h"
00027 #include "client.h"
00028 #include "irc_string.h"
00029 #include "ircd.h"
00030 #include "numeric.h"
00031 #include "s_serv.h"
00032 #include "send.h"
00033 #include "s_conf.h"
00034 #include "msg.h"
00035 #include "motd.h"
00036 #include "parse.h"
00037 #include "modules.h"
00038 #include "hook.h"
00039
00040 static void do_links(struct Client *, int, char **);
00041 static void m_links(struct Client*, struct Client*, int, char**);
00042 static void mo_links(struct Client*, struct Client*, int, char**);
00043 static void ms_links(struct Client*, struct Client*, int, char**);
00044
00045 struct Message links_msgtab = {
00046 "LINKS", 0, 0, 0, 0, MFLG_SLOW, 0,
00047 {m_unregistered, m_links, ms_links, m_ignore, mo_links, m_ignore}
00048 };
00049
00050 #ifndef STATIC_MODULES
00051 const char *_version = "$Revision: 575 $";
00052 static struct Callback *links_cb;
00053
00054 static void *
00055 va_links(va_list args)
00056 {
00057 struct Client *source_p = va_arg(args, struct Client *);
00058 int parc = va_arg(args, int);
00059 char **parv = va_arg(args, char **);
00060
00061 do_links(source_p, parc, parv);
00062 return NULL;
00063 }
00064
00065 void
00066 _modinit(void)
00067 {
00068 links_cb = register_callback("doing_links", va_links);
00069 mod_add_cmd(&links_msgtab);
00070 }
00071
00072 void
00073 _moddeinit(void)
00074 {
00075 mod_del_cmd(&links_msgtab);
00076 uninstall_hook(links_cb, va_links);
00077 }
00078
00079 #endif
00080
00081 static void
00082 do_links(struct Client *source_p, int parc, char **parv)
00083 {
00084 if (IsOper(source_p) || !ConfigServerHide.flatten_links)
00085 {
00086 char *mask = (parc > 2 ? parv[2] : parv[1]);
00087 const char *me_name, *nick, *p;
00088 struct Client *target_p;
00089 char clean_mask[2 * HOSTLEN + 4];
00090 dlink_node *ptr;
00091
00092 if (!EmptyString(mask))
00093 mask = collapse(clean_string(clean_mask, (const unsigned char*) mask, 2 * HOSTLEN));
00094
00095 me_name = ID_or_name(&me, source_p->from);
00096 nick = ID_or_name(source_p, source_p->from);
00097
00098 DLINK_FOREACH(ptr, global_serv_list.head)
00099 {
00100 target_p = ptr->data;
00101
00102 if (!EmptyString(mask) && !match(mask, target_p->name))
00103 continue;
00104
00105 if (target_p->info[0])
00106 {
00107 if ((p = strchr(target_p->info, ']')))
00108 p += 2;
00109 else
00110 p = target_p->info;
00111 }
00112 else
00113 p = "(Unknown Location)";
00114
00115
00116
00117
00118 sendto_one(source_p, form_str(RPL_LINKS),
00119 me_name, nick,
00120 target_p->name, target_p->servptr->name,
00121 target_p->hopcount, p);
00122 }
00123
00124 sendto_one(source_p, form_str(RPL_ENDOFLINKS),
00125 me_name, nick,
00126 EmptyString(mask) ? "*" : mask);
00127 }
00128 else {
00129
00130
00131
00132
00133 sendto_one(source_p, form_str(RPL_LINKS),
00134 ID_or_name(&me, source_p->from),
00135 ID_or_name(source_p, source_p->from),
00136 me.name, me.name, 0, me.info);
00137 send_message_file(source_p, &ConfigFileEntry.linksfile);
00138 sendto_one(source_p, form_str(RPL_ENDOFLINKS),
00139 ID_or_name(&me, source_p->from),
00140 ID_or_name(source_p, source_p->from), "*");
00141 }
00142 }
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 static void
00154 m_links(struct Client *client_p, struct Client *source_p,
00155 int parc, char *parv[])
00156 {
00157 static time_t last_used = 0;
00158
00159 if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
00160 {
00161 sendto_one(source_p, form_str(RPL_LOAD2HI),
00162 me.name, source_p->name);
00163 return;
00164 }
00165 else
00166 last_used = CurrentTime;
00167
00168 if (!ConfigServerHide.flatten_links)
00169 {
00170 mo_links(client_p, source_p, parc, parv);
00171 return;
00172 }
00173
00174 #ifdef STATIC_MODULES
00175 do_links(source_p, parc, parv);
00176 #else
00177 execute_callback(links_cb, source_p, parc, parv);
00178 #endif
00179 }
00180
00181 static void
00182 mo_links(struct Client *client_p, struct Client *source_p,
00183 int parc, char *parv[])
00184 {
00185 if (parc > 2)
00186 if (!ConfigFileEntry.disable_remote || IsOper(source_p))
00187 {
00188 if (hunt_server(client_p, source_p, ":%s LINKS %s :%s", 1, parc, parv)
00189 != HUNTED_ISME)
00190 return;
00191 }
00192
00193 #ifdef STATIC_MODULES
00194 do_links(source_p, parc, parv);
00195 #else
00196 execute_callback(links_cb, source_p, parc, parv);
00197 #endif
00198 }
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209 static void
00210 ms_links(struct Client *client_p, struct Client *source_p,
00211 int parc, char *parv[])
00212 {
00213 if (hunt_server(client_p, source_p, ":%s LINKS %s :%s", 1, parc, parv)
00214 != HUNTED_ISME)
00215 return;
00216
00217 if (IsClient(source_p))
00218 m_links(client_p, source_p, parc, parv);
00219 }