/** * namegen.C: Name generator. * * 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-2006 William Pitcock et al * Rights to this code are documented in doc/pod/license.pod. * * $Id: namegen.C,v 1.6 2007/09/22 14:27:27 pippijn Exp $ */ #include "atheme.h" #include #include "namegen_tab.h" #include static char const rcsid[] = "$Id: namegen.C,v 1.6 2007/09/22 14:27:27 pippijn Exp $"; REGISTER_MODULE ("gameserv/namegen", false, "The Ermyth Team "); static void command_namegen (sourceinfo_t *si, int parc, char *parv[]); command_t const cmd_namegen = { "NAMEGEN", N_("Generates some names to ponder."), AC_NONE, 0, command_namegen }; E cmdvec gs_cmdtree; E cmdvec cs_cmdtree; E helpvec gs_helptree; E helpvec cs_helptree; bool _modinit (module *m) { gs_cmdtree << cmd_namegen; cs_cmdtree << cmd_namegen; help_addentry (gs_helptree, "NAMEGEN", "help/gameserv/namegen", NULL); help_addentry (cs_helptree, "NAMEGEN", "help/gameserv/namegen", NULL); return true; } void _moddeinit () { gs_cmdtree >> cmd_namegen; cs_cmdtree >> cmd_namegen; help_delentry (gs_helptree, "NAMEGEN"); help_delentry (cs_helptree, "NAMEGEN"); } /* * Handle reporting for both fantasy commands and normal commands in GameServ * quickly and easily. Of course, sourceinfo has a vtable that can be manipulated, * but this is quicker and easier... -- nenolod */ static void gs_command_report (sourceinfo_t *si, char const * const fmt, ...) { va_list args; char buf[BUFSIZE]; va_start (args, fmt); vsnprintf (buf, BUFSIZE, fmt, args); va_end (args); if (si->c != NULL) phandler->privmsg (chansvs.nick, si->c->name, "%s", buf); else command_success_nodata (si, "%s", buf); } static void command_namegen (sourceinfo_t *si, int parc, char *parv[]) { unsigned int iter; unsigned int amt = 20; char buf[BUFSIZE]; *buf = '\0'; for (iter = 0; iter < amt; iter++) { char namebuf[BUFSIZE]; unsigned int medial_iter; /* Here we generate the name. */ strlcpy (namebuf, begin_sym[gen_rand32 () % BEGIN_SYM_SZ], BUFSIZE); for (medial_iter = gen_rand32 () % 3; medial_iter > 0; medial_iter--) strlcat (namebuf, medial_sym[gen_rand32 () % MEDIAL_SYM_SZ], BUFSIZE); strlcat (namebuf, end_sym[gen_rand32 () % END_SYM_SZ], BUFSIZE); if (iter == 0) strlcpy (buf, namebuf, BUFSIZE); else strlcat (buf, namebuf, BUFSIZE); strlcat (buf, iter + 1 < amt ? ", " : ".", BUFSIZE); } gs_command_report (si, "Some names to ponder: %s", buf); }