/** * info.C: This file contains code for the ChanServ INFO functions. * * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team * Rights to this code are as documented in COPYING. * * * Portions of this file were derived from sources bearing the following license: * Copyright © 2005 William Pitcock, et al. * Rights to this code are as documented in doc/pod/license.pod. * * $Id: info.C,v 1.9 2007/09/22 14:27:27 pippijn Exp $ */ #include "atheme.h" #include #include #include #include #include #include #include static char const rcsid[] = "$Id: info.C,v 1.9 2007/09/22 14:27:27 pippijn Exp $"; REGISTER_MODULE ("chanserv/info", false, "The Ermyth Team "); static void cs_cmd_info (sourceinfo_t *si, int parc, char *parv[]); command_t const cs_info = { "INFO", N_("Displays information on registrations."), AC_NONE, 1, cs_cmd_info }; E cmdvec cs_cmdtree; E helpvec cs_helptree; bool _modinit (module *m) { cs_cmdtree << cs_info; help_addentry (cs_helptree, "INFO", "help/chanserv/info", NULL); return true; } void _moddeinit () { cs_cmdtree >> cs_info; help_delentry (cs_helptree, "INFO"); } static void cs_cmd_info (sourceinfo_t *si, int parc, char *parv[]) { mychan_t *mc; char *name = parv[0]; char buf[BUFSIZE], strfbuf[32]; struct tm tm; metadata *md; char *p, *q, *qq; int dir; if (!name) { command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "INFO"); command_fail (si, fault::needmoreparams, _("Syntax: INFO <#channel>")); return; } if (*name != '#') { command_fail (si, fault::badparams, STR_INVALID_PARAMS, "INFO"); command_fail (si, fault::badparams, _("Syntax: INFO <#channel>")); return; } if (!(mc = mychan_t::find (name))) { command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), name); return; } if (!has_priv (si, PRIV_CHAN_AUSPEX) && (md = mc->find_metadata ("private:close:closer"))) { command_fail (si, fault::noprivs, _("\2%s\2 has been closed down by the %s administration."), mc->name, me.netname); return; } tm = *localtime (&mc->registered); strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm); command_success_nodata (si, _("Information on \2%s\2:"), mc->name); command_success_nodata (si, _("Founder : %s"), mc->founder_names ()); command_success_nodata (si, _("Registered : %s (%s ago)"), strfbuf, time_ago (mc->registered)); if (NOW - mc->used >= 86400) { tm = *localtime (&mc->used); strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm); command_success_nodata (si, _("Last used : %s (%s ago)"), strfbuf, time_ago (mc->used)); } md = mc->find_metadata ("private:mlockext"); if (mc->mlock_on || mc->mlock_off || mc->mlock_limit || mc->mlock_key || md) { char params[BUFSIZE]; if (md != NULL && strlen (md->value) > 450) { /* Be safe */ command_success_nodata (si, _("Mode lock is too long, not entirely shown")); md = NULL; } *buf = 0; *params = 0; dir = MTYPE_NUL; if (mc->mlock_on) { if (dir != MTYPE_ADD) dir = MTYPE_ADD, strcat (buf, "+"); strcat (buf, flags_to_string (mc->mlock_on)); } if (mc->mlock_limit) { if (dir != MTYPE_ADD) dir = MTYPE_ADD, strcat (buf, "+"); strcat (buf, "l"); strcat (params, " "); strcat (params, itoa (mc->mlock_limit)); } if (mc->mlock_key) { if (dir != MTYPE_ADD) dir = MTYPE_ADD, strcat (buf, "+"); strcat (buf, "k"); strcat (params, " *"); } if (md) { p = md->value; q = buf + strlen (buf); while (*p != '\0') { if (p[1] != ' ' && p[1] != '\0') { if (dir != MTYPE_ADD) dir = MTYPE_ADD, *q++ = '+'; *q++ = *p++; strcat (params, " "); qq = params + strlen (params); while (*p != '\0' && *p != ' ') *qq++ = *p++; *qq = '\0'; } else { p++; while (*p != '\0' && *p != ' ') p++; } while (*p == ' ') p++; } *q = '\0'; } if (mc->mlock_off) { if (dir != MTYPE_DEL) dir = MTYPE_DEL, strcat (buf, "-"); strcat (buf, flags_to_string (mc->mlock_off)); if (mc->mlock_off & CMODE_LIMIT) strcat (buf, "l"); if (mc->mlock_off & CMODE_KEY) strcat (buf, "k"); } if (md) { p = md->value; q = buf + strlen (buf); while (*p != '\0') { if (p[1] == ' ' || p[1] == '\0') { if (dir != MTYPE_DEL) dir = MTYPE_DEL, *q++ = '-'; *q++ = *p; } p++; while (*p != '\0' && *p != ' ') p++; while (*p == ' ') p++; } *q = '\0'; } if (*buf) command_success_nodata (si, _("Mode lock : %s%s"), buf, params); } if ((md = mc->find_metadata ("url"))) command_success_nodata (si, "URL : %s", md->value); if ((md = mc->find_metadata ("email"))) command_success_nodata (si, "Email : %s", md->value); *buf = '\0'; if (MC_HOLD & mc->flags) strcat (buf, "HOLD"); if (MC_SECURE & mc->flags) { if (*buf) strcat (buf, " "); strcat (buf, "SECURE"); } if (MC_VERBOSE & mc->flags) { if (*buf) strcat (buf, " "); strcat (buf, "VERBOSE"); } if (MC_VERBOSE_OPS & mc->flags) { if (*buf) strcat (buf, " "); strcat (buf, "VERBOSE_OPS"); } if (MC_STAFFONLY & mc->flags) { if (*buf) strcat (buf, " "); strcat (buf, "STAFFONLY"); } if (MC_KEEPTOPIC & mc->flags) { if (*buf) strcat (buf, " "); strcat (buf, "KEEPTOPIC"); } if (MC_TOPICLOCK & mc->flags) { if (*buf) strcat (buf, " "); strcat (buf, "TOPICLOCK"); } if (MC_GUARD & mc->flags) { if (*buf) strcat (buf, " "); strcat (buf, "GUARD"); if (chansvs.fantasy && !mc->find_metadata ("disable_fantasy")) strcat (buf, " FANTASY"); } if (*buf) command_success_nodata (si, _("Flags : %s"), buf); if (has_priv (si, PRIV_CHAN_AUSPEX) && (md = mc->find_metadata ("private:mark:setter"))) { char const * const setter = md->value; time_t ts; md = mc->find_metadata ("private:mark:reason"); char const * const reason = md != NULL ? md->value : "unknown"; md = mc->find_metadata ("private:mark:timestamp"); ts = md != NULL ? atoi (md->value) : 0; tm = *localtime (&ts); strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm); command_success_nodata (si, _("%s was \2MARKED\2 by %s on %s (%s)"), mc->name, setter, strfbuf, reason); } if (has_priv (si, PRIV_CHAN_AUSPEX) && (MC_INHABIT & mc->flags)) command_success_nodata (si, _("%s is temporarily holding this channel."), chansvs.nick); if (has_priv (si, PRIV_CHAN_AUSPEX) && (md = mc->find_metadata ("private:close:closer"))) { char const * const setter = md->value; time_t ts; md = mc->find_metadata ("private:close:reason"); char const * const reason = md != NULL ? md->value : "unknown"; md = mc->find_metadata ("private:close:timestamp"); ts = md != NULL ? atoi (md->value) : 0; tm = *localtime (&ts); strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm); command_success_nodata (si, _("%s was \2CLOSED\2 by %s on %s (%s)"), mc->name, setter, strfbuf, reason); } mc->callback.info (mc, si); command_success_nodata (si, _("\2*** End of Info ***\2")); logcommand (si, CMDLOG_GET, "%s INFO", mc->name); }