| 1 |
/* |
| 2 |
* Copyright (c) 2005-2006 William Pitcock <[email protected]> et al |
| 3 |
* Rights to this code are documented in doc/LICENSE. |
| 4 |
* |
| 5 |
* Name generator. |
| 6 |
* |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "atheme.h" |
| 10 |
#include "gameserv_common.h" |
| 11 |
#include "namegen_tab.h" |
| 12 |
|
| 13 |
DECLARE_MODULE_V1 |
| 14 |
( |
| 15 |
"gameserv/namegen", false, _modinit, _moddeinit, |
| 16 |
PACKAGE_STRING, |
| 17 |
VENDOR_STRING |
| 18 |
); |
| 19 |
|
| 20 |
static void command_namegen(sourceinfo_t *si, int parc, char *parv[]); |
| 21 |
|
| 22 |
command_t cmd_namegen = { "NAMEGEN", N_("Generates some names to ponder."), AC_NONE, 2, command_namegen, { .path = "gameserv/namegen" } }; |
| 23 |
|
| 24 |
void _modinit(module_t * m) |
| 25 |
{ |
| 26 |
service_named_bind_command("gameserv", &cmd_namegen); |
| 27 |
|
| 28 |
service_named_bind_command("chanserv", &cmd_namegen); |
| 29 |
} |
| 30 |
|
| 31 |
void _moddeinit(module_unload_intent_t intent) |
| 32 |
{ |
| 33 |
service_named_unbind_command("gameserv", &cmd_namegen); |
| 34 |
|
| 35 |
service_named_unbind_command("chanserv", &cmd_namegen); |
| 36 |
} |
| 37 |
|
| 38 |
static void command_namegen(sourceinfo_t *si, int parc, char *parv[]) |
| 39 |
{ |
| 40 |
unsigned int iter; |
| 41 |
unsigned int amt = 20; |
| 42 |
char buf[BUFSIZE]; |
| 43 |
mychan_t *mc; |
| 44 |
|
| 45 |
if (!gs_do_parameters(si, &parc, &parv, &mc)) |
| 46 |
return; |
| 47 |
|
| 48 |
if (parv[0]) |
| 49 |
amt = atoi(parv[0]); |
| 50 |
|
| 51 |
|
| 52 |
/* limit to 20 */ |
| 53 |
if (amt > 20) |
| 54 |
amt = 20; |
| 55 |
|
| 56 |
*buf = '\0'; |
| 57 |
|
| 58 |
for (iter = 0; iter < amt; iter++) |
| 59 |
{ |
| 60 |
char namebuf[BUFSIZE]; |
| 61 |
unsigned int medial_iter; |
| 62 |
|
| 63 |
/* Here we generate the name. */ |
| 64 |
mowgli_strlcpy(namebuf, begin_sym[rand() % BEGIN_SYM_SZ], BUFSIZE); |
| 65 |
|
| 66 |
for (medial_iter = rand() % 3; medial_iter > 0; medial_iter--) |
| 67 |
mowgli_strlcat(namebuf, medial_sym[rand() % MEDIAL_SYM_SZ], BUFSIZE); |
| 68 |
|
| 69 |
mowgli_strlcat(namebuf, end_sym[rand() % END_SYM_SZ], BUFSIZE); |
| 70 |
|
| 71 |
if (iter == 0) |
| 72 |
mowgli_strlcpy(buf, namebuf, BUFSIZE); |
| 73 |
else |
| 74 |
mowgli_strlcat(buf, namebuf, BUFSIZE); |
| 75 |
|
| 76 |
mowgli_strlcat(buf, iter + 1 < amt ? ", " : ".", BUFSIZE); |
| 77 |
} |
| 78 |
|
| 79 |
gs_command_report(si, _("Some names to ponder: %s"), buf); |
| 80 |
} |
| 81 |
|
| 82 |
/* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs |
| 83 |
* vim:ts=8 |
| 84 |
* vim:sw=8 |
| 85 |
* vim:noexpandtab |
| 86 |
*/ |