summaryrefslogtreecommitdiff
path: root/modules/m_whowas.c
diff options
context:
space:
mode:
Diffstat (limited to 'modules/m_whowas.c')
-rw-r--r--modules/m_whowas.c175
1 files changed, 175 insertions, 0 deletions
diff --git a/modules/m_whowas.c b/modules/m_whowas.c
new file mode 100644
index 0000000..2f6da27
--- /dev/null
+++ b/modules/m_whowas.c
@@ -0,0 +1,175 @@
+/*
+ * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
+ * m_whois.c: Shows who a user was.
+ *
+ * Copyright (C) 2002 by the past and present ircd coders, and others.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ *
+ * $Id$
+ */
+
+#include "stdinc.h"
+#include "list.h"
+#include "whowas.h"
+#include "client.h"
+#include "hash.h"
+#include "irc_string.h"
+#include "ircd.h"
+#include "ircd_defs.h"
+#include "numeric.h"
+#include "s_serv.h"
+#include "s_user.h"
+#include "send.h"
+#include "conf.h"
+#include "parse.h"
+#include "modules.h"
+
+
+static void
+whowas_do(struct Client *client_p, struct Client *source_p,
+ int parc, char *parv[])
+{
+ int cur = 0;
+ int max = -1;
+ char *p = NULL, *nick = NULL;
+ const dlink_node *ptr = NULL;
+
+ if (parc > 2)
+ {
+ max = atoi(parv[2]);
+
+ if (!MyConnect(source_p) && max > 20)
+ max = 20;
+ }
+
+ if (parc > 3)
+ if (hunt_server(client_p, source_p, ":%s WHOWAS %s %s :%s", 3,
+ parc, parv) != HUNTED_ISME)
+ return;
+
+ nick = parv[1];
+ while (*nick == ',')
+ nick++;
+ if ((p = strchr(nick,',')) != NULL)
+ *p = '\0';
+ if (*nick == '\0')
+ return;
+
+ DLINK_FOREACH(ptr, WHOWASHASH[strhash(nick)].head)
+ {
+ const struct Whowas *temp = ptr->data;
+
+ if (!irccmp(nick, temp->name))
+ {
+ sendto_one(source_p, form_str(RPL_WHOWASUSER),
+ me.name, source_p->name, temp->name,
+ temp->username, temp->hostname,
+ temp->realname);
+
+ if (ConfigServerHide.hide_servers && !HasUMode(source_p, UMODE_OPER))
+ sendto_one(source_p, form_str(RPL_WHOISSERVER),
+ me.name, source_p->name, temp->name,
+ ServerInfo.network_name, myctime(temp->logoff));
+ else
+ sendto_one(source_p, form_str(RPL_WHOISSERVER),
+ me.name, source_p->name, temp->name,
+ temp->servername, myctime(temp->logoff));
+ ++cur;
+ }
+
+ if (max > 0 && cur >= max)
+ break;
+ }
+
+ if (!cur)
+ sendto_one(source_p, form_str(ERR_WASNOSUCHNICK),
+ me.name, source_p->name, nick);
+
+ sendto_one(source_p, form_str(RPL_ENDOFWHOWAS),
+ me.name, source_p->name, parv[1]);
+}
+
+/*
+** m_whowas
+** parv[0] = sender prefix
+** parv[1] = nickname queried
+*/
+static void
+m_whowas(struct Client *client_p, struct Client *source_p,
+ int parc, char *parv[])
+{
+ static time_t last_used = 0;
+
+ if (parc < 2 || EmptyString(parv[1]))
+ {
+ sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN),
+ me.name, source_p->name);
+ return;
+ }
+
+ if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
+ {
+ sendto_one(source_p,form_str(RPL_LOAD2HI),
+ me.name, source_p->name);
+ return;
+ }
+
+ last_used = CurrentTime;
+
+ whowas_do(client_p, source_p, parc, parv);
+}
+
+static void
+mo_whowas(struct Client *client_p, struct Client *source_p,
+ int parc, char *parv[])
+{
+ if (parc < 2 || EmptyString(parv[1]))
+ {
+ sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN),
+ me.name, source_p->name);
+ return;
+ }
+
+ whowas_do(client_p, source_p, parc, parv);
+}
+
+static struct Message whowas_msgtab = {
+ "WHOWAS", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
+ { m_unregistered, m_whowas, mo_whowas, m_ignore, mo_whowas, m_ignore }
+};
+
+static void
+module_init(void)
+{
+ mod_add_cmd(&whowas_msgtab);
+}
+
+static void
+module_exit(void)
+{
+ mod_del_cmd(&whowas_msgtab);
+}
+
+struct module module_entry = {
+ .node = { NULL, NULL, NULL },
+ .name = NULL,
+ .version = "$Revision$",
+ .handle = NULL,
+ .modinit = module_init,
+ .modexit = module_exit,
+ .flags = 0
+};