ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/gameserv/namegen.C
Revision: 1.2
Committed: Sat Jul 21 01:29:09 2007 UTC (19 years, 3 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.1: +3 -3 lines
Log Message:
- moved to new documentation system
- fixed small build error

File Contents

# User Rev Content
1 pippijn 1.1 /*
2     * Copyright © 2005-2006 William Pitcock <nenolod@nenolod.net> et al
3 pippijn 1.2 * Rights to this code are documented in doc/pod/license.pod.
4 pippijn 1.1 *
5     * Name generator.
6     *
7 pippijn 1.2 * $Id: namegen.C,v 1.1 2007-07-19 08:24:53 pippijn Exp $
8 pippijn 1.1 */
9    
10     #include "atheme.h"
11     #include "namegen_tab.h"
12    
13     static char const rcsid[] = "$Id";
14    
15     struct gs_dice_listeners : callback::has_listeners
16     {
17     };
18    
19     gs_dice_listeners listeners;
20    
21 pippijn 1.2 DECLARE_MODULE_V1 ("gameserv/namegen", false, _modinit, _moddeinit, "$Id: namegen.C,v 1.1 2007-07-19 08:24:53 pippijn Exp $", "The Ermyth Team <http://ermyth.schmorp.de>");
22 pippijn 1.1
23     static void command_namegen (sourceinfo_t *si, int parc, char *parv[]);
24    
25     command_t cmd_namegen = { "NAMEGEN", N_("Generates some names to ponder."), AC_NONE, 0, command_namegen };
26    
27     cmdvec *gs_cmdtree;
28     cmdvec *cs_cmdtree;
29    
30     helpvec *gs_helptree;
31     helpvec *cs_helptree;
32    
33     void
34     _modinit (module_t *m)
35     {
36     MODULE_USE_SYMBOL_T (gs_cmdtree, cmdvec, "gameserv/main", "gs_cmdtree");
37     MODULE_USE_SYMBOL_T (cs_cmdtree, cmdvec, "chanserv/main", "cs_cmdtree"); /* fantasy commands */
38     MODULE_USE_SYMBOL_T (gs_helptree, helpvec, "gameserv/main", "gs_helptree");
39     MODULE_USE_SYMBOL_T (cs_helptree, helpvec, "chanserv/main", "cs_helptree"); /* fantasy commands */
40    
41     gs_cmdtree << cmd_namegen;
42     cs_cmdtree << cmd_namegen;
43    
44     help_addentry (gs_helptree, "NAMEGEN", "help/gameserv/namegen", NULL);
45     help_addentry (cs_helptree, "NAMEGEN", "help/gameserv/namegen", NULL);
46     }
47    
48     void
49     _moddeinit ()
50     {
51     gs_cmdtree >> cmd_namegen;
52     cs_cmdtree >> cmd_namegen;
53    
54     help_delentry (gs_helptree, "NAMEGEN");
55     help_delentry (cs_helptree, "NAMEGEN");
56     }
57    
58     /*
59     * Handle reporting for both fantasy commands and normal commands in GameServ
60     * quickly and easily. Of course, sourceinfo has a vtable that can be manipulated,
61     * but this is quicker and easier... -- nenolod
62     */
63     static void
64     gs_command_report (sourceinfo_t *si, char *fmt, ...)
65     {
66     va_list args;
67     char buf[BUFSIZE];
68    
69     va_start (args, fmt);
70     vsnprintf (buf, BUFSIZE, fmt, args);
71     va_end (args);
72    
73     if (si->c != NULL)
74     msg (chansvs.nick, si->c->name, "%s", buf);
75     else
76     command_success_nodata (si, "%s", buf);
77     }
78    
79     static void
80     command_namegen (sourceinfo_t *si, int parc, char *parv[])
81     {
82     unsigned int iter;
83     unsigned int amt = 20;
84     char buf[BUFSIZE];
85    
86     *buf = '\0';
87    
88     for (iter = 0; iter < amt; iter++)
89     {
90     char namebuf[BUFSIZE];
91     unsigned int medial_iter;
92    
93     /* Here we generate the name. */
94     strlcpy (namebuf, begin_sym[rand () % BEGIN_SYM_SZ], BUFSIZE);
95    
96     for (medial_iter = rand () % 3; medial_iter > 0; medial_iter--)
97     strlcat (namebuf, medial_sym[rand () % MEDIAL_SYM_SZ], BUFSIZE);
98    
99     strlcat (namebuf, end_sym[rand () % END_SYM_SZ], BUFSIZE);
100    
101     if (iter == 0)
102     strlcpy (buf, namebuf, BUFSIZE);
103     else
104     strlcat (buf, namebuf, BUFSIZE);
105    
106     strlcat (buf, iter + 1 < amt ? ", " : ".", BUFSIZE);
107     }
108    
109     gs_command_report (si, "Some names to ponder: %s", buf);
110     }
111    
112     /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
113     * vim:ts=8
114     * vim:sw=8
115     * vim:noexpandtab
116     */