| 1 |
pippijn |
1.5 |
/** |
| 2 |
|
|
* namegen.C: Name generator. |
| 3 |
|
|
* |
| 4 |
|
|
* Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team |
| 5 |
|
|
* Rights to this code are as documented in COPYING. |
| 6 |
|
|
* |
| 7 |
|
|
* |
| 8 |
|
|
* Portions of this file were derived from sources bearing the following license: |
| 9 |
pippijn |
1.4 |
* Copyright © 2005-2006 William Pitcock <nenolod@nenolod.net> et al |
| 10 |
pippijn |
1.2 |
* Rights to this code are documented in doc/pod/license.pod. |
| 11 |
pippijn |
1.1 |
* |
| 12 |
pippijn |
1.6 |
* $Id: namegen.C,v 1.5 2007-09-16 18:54:43 pippijn Exp $ |
| 13 |
pippijn |
1.1 |
*/ |
| 14 |
|
|
|
| 15 |
|
|
#include "atheme.h" |
| 16 |
pippijn |
1.4 |
#include <ermyth/module.h> |
| 17 |
pippijn |
1.1 |
#include "namegen_tab.h" |
| 18 |
pippijn |
1.6 |
#include <util/random.h> |
| 19 |
pippijn |
1.1 |
|
| 20 |
pippijn |
1.6 |
static char const rcsid[] = "$Id: namegen.C,v 1.5 2007-09-16 18:54:43 pippijn Exp $"; |
| 21 |
pippijn |
1.1 |
|
| 22 |
pippijn |
1.6 |
REGISTER_MODULE ("gameserv/namegen", false, "The Ermyth Team <http://ermyth.xinutec.org>"); |
| 23 |
pippijn |
1.1 |
|
| 24 |
|
|
static void command_namegen (sourceinfo_t *si, int parc, char *parv[]); |
| 25 |
|
|
|
| 26 |
pippijn |
1.4 |
command_t const cmd_namegen = { "NAMEGEN", N_("Generates some names to ponder."), AC_NONE, 0, command_namegen }; |
| 27 |
pippijn |
1.1 |
|
| 28 |
pippijn |
1.4 |
E cmdvec gs_cmdtree; |
| 29 |
|
|
E cmdvec cs_cmdtree; |
| 30 |
pippijn |
1.1 |
|
| 31 |
pippijn |
1.4 |
E helpvec gs_helptree; |
| 32 |
|
|
E helpvec cs_helptree; |
| 33 |
pippijn |
1.1 |
|
| 34 |
pippijn |
1.4 |
bool |
| 35 |
|
|
_modinit (module *m) |
| 36 |
pippijn |
1.1 |
{ |
| 37 |
|
|
gs_cmdtree << cmd_namegen; |
| 38 |
|
|
cs_cmdtree << cmd_namegen; |
| 39 |
|
|
|
| 40 |
|
|
help_addentry (gs_helptree, "NAMEGEN", "help/gameserv/namegen", NULL); |
| 41 |
|
|
help_addentry (cs_helptree, "NAMEGEN", "help/gameserv/namegen", NULL); |
| 42 |
pippijn |
1.4 |
|
| 43 |
|
|
return true; |
| 44 |
pippijn |
1.1 |
} |
| 45 |
|
|
|
| 46 |
|
|
void |
| 47 |
|
|
_moddeinit () |
| 48 |
|
|
{ |
| 49 |
|
|
gs_cmdtree >> cmd_namegen; |
| 50 |
|
|
cs_cmdtree >> cmd_namegen; |
| 51 |
|
|
|
| 52 |
|
|
help_delentry (gs_helptree, "NAMEGEN"); |
| 53 |
|
|
help_delentry (cs_helptree, "NAMEGEN"); |
| 54 |
|
|
} |
| 55 |
|
|
|
| 56 |
|
|
/* |
| 57 |
|
|
* Handle reporting for both fantasy commands and normal commands in GameServ |
| 58 |
|
|
* quickly and easily. Of course, sourceinfo has a vtable that can be manipulated, |
| 59 |
|
|
* but this is quicker and easier... -- nenolod |
| 60 |
|
|
*/ |
| 61 |
|
|
static void |
| 62 |
pippijn |
1.4 |
gs_command_report (sourceinfo_t *si, char const * const fmt, ...) |
| 63 |
pippijn |
1.1 |
{ |
| 64 |
|
|
va_list args; |
| 65 |
|
|
char buf[BUFSIZE]; |
| 66 |
|
|
|
| 67 |
|
|
va_start (args, fmt); |
| 68 |
|
|
vsnprintf (buf, BUFSIZE, fmt, args); |
| 69 |
|
|
va_end (args); |
| 70 |
|
|
|
| 71 |
|
|
if (si->c != NULL) |
| 72 |
pippijn |
1.4 |
phandler->privmsg (chansvs.nick, si->c->name, "%s", buf); |
| 73 |
pippijn |
1.1 |
else |
| 74 |
|
|
command_success_nodata (si, "%s", buf); |
| 75 |
|
|
} |
| 76 |
|
|
|
| 77 |
|
|
static void |
| 78 |
|
|
command_namegen (sourceinfo_t *si, int parc, char *parv[]) |
| 79 |
|
|
{ |
| 80 |
|
|
unsigned int iter; |
| 81 |
|
|
unsigned int amt = 20; |
| 82 |
|
|
char buf[BUFSIZE]; |
| 83 |
|
|
|
| 84 |
|
|
*buf = '\0'; |
| 85 |
|
|
|
| 86 |
|
|
for (iter = 0; iter < amt; iter++) |
| 87 |
|
|
{ |
| 88 |
|
|
char namebuf[BUFSIZE]; |
| 89 |
|
|
unsigned int medial_iter; |
| 90 |
|
|
|
| 91 |
|
|
/* Here we generate the name. */ |
| 92 |
pippijn |
1.4 |
strlcpy (namebuf, begin_sym[gen_rand32 () % BEGIN_SYM_SZ], BUFSIZE); |
| 93 |
pippijn |
1.1 |
|
| 94 |
pippijn |
1.4 |
for (medial_iter = gen_rand32 () % 3; medial_iter > 0; medial_iter--) |
| 95 |
|
|
strlcat (namebuf, medial_sym[gen_rand32 () % MEDIAL_SYM_SZ], BUFSIZE); |
| 96 |
pippijn |
1.1 |
|
| 97 |
pippijn |
1.4 |
strlcat (namebuf, end_sym[gen_rand32 () % END_SYM_SZ], BUFSIZE); |
| 98 |
pippijn |
1.1 |
|
| 99 |
|
|
if (iter == 0) |
| 100 |
|
|
strlcpy (buf, namebuf, BUFSIZE); |
| 101 |
|
|
else |
| 102 |
|
|
strlcat (buf, namebuf, BUFSIZE); |
| 103 |
|
|
|
| 104 |
|
|
strlcat (buf, iter + 1 < amt ? ", " : ".", BUFSIZE); |
| 105 |
|
|
} |
| 106 |
|
|
|
| 107 |
|
|
gs_command_report (si, "Some names to ponder: %s", buf); |
| 108 |
|
|
} |