ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/gameserv/namegen.C
Revision: 1.6
Committed: Sat Sep 22 14:27:27 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +4 -4 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

# Content
1 /**
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 * Copyright © 2005-2006 William Pitcock <nenolod@nenolod.net> et al
10 * Rights to this code are documented in doc/pod/license.pod.
11 *
12 * $Id: namegen.C,v 1.5 2007-09-16 18:54:43 pippijn Exp $
13 */
14
15 #include "atheme.h"
16 #include <ermyth/module.h>
17 #include "namegen_tab.h"
18 #include <util/random.h>
19
20 static char const rcsid[] = "$Id: namegen.C,v 1.5 2007-09-16 18:54:43 pippijn Exp $";
21
22 REGISTER_MODULE ("gameserv/namegen", false, "The Ermyth Team <http://ermyth.xinutec.org>");
23
24 static void command_namegen (sourceinfo_t *si, int parc, char *parv[]);
25
26 command_t const cmd_namegen = { "NAMEGEN", N_("Generates some names to ponder."), AC_NONE, 0, command_namegen };
27
28 E cmdvec gs_cmdtree;
29 E cmdvec cs_cmdtree;
30
31 E helpvec gs_helptree;
32 E helpvec cs_helptree;
33
34 bool
35 _modinit (module *m)
36 {
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
43 return true;
44 }
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 gs_command_report (sourceinfo_t *si, char const * const fmt, ...)
63 {
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 phandler->privmsg (chansvs.nick, si->c->name, "%s", buf);
73 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 strlcpy (namebuf, begin_sym[gen_rand32 () % BEGIN_SYM_SZ], BUFSIZE);
93
94 for (medial_iter = gen_rand32 () % 3; medial_iter > 0; medial_iter--)
95 strlcat (namebuf, medial_sym[gen_rand32 () % MEDIAL_SYM_SZ], BUFSIZE);
96
97 strlcat (namebuf, end_sym[gen_rand32 () % END_SYM_SZ], BUFSIZE);
98
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 }