Debian Codegraph @

modules/contrib/src/gs_roulette.c

raw
1 /*
2 * Copyright (c) 2005-2006 William Pitcock <[email protected]> et al
3 * Rights to this code are documented in doc/LICENSE.
4 *
5 * Russian Roulette game. Will actually /KILL the user that gets "shot".
6 */
7
8 #include "atheme-compat.h"
9
10 /*
11 * Handle reporting for both fantasy commands and normal commands in GameServ
12 * quickly and easily. Of course, sourceinfo has a vtable that can be manipulated,
13 * but this is quicker and easier... -- nenolod
14 */
15 static void
16 gs_command_report(sourceinfo_t *si, const char *fmt, ...)
17 {
18 va_list args;
19 char buf[BUFSIZE];
20
21 va_start(args, fmt);
22 vsnprintf(buf, BUFSIZE, fmt, args);
23 va_end(args);
24
25 if (si->c != NULL)
26 msg(chansvs.nick, si->c->name, "%s", buf);
27 else
28 command_success_nodata(si, "%s", buf);
29
30 if (!strcasecmp(buf, "*BANG*"))
31 kill_user(si->service->me, si->su, "Lost at Russian Roulette.");
32 }
33
34 static void
35 command_roulette(sourceinfo_t *si, int parc, char *parv[])
36 {
37 static const char *roulette_responses[2] = {
38 N_("*CLICK*"),
39 N_("*BANG*")
40 };
41
42 gs_command_report(si, "%s", roulette_responses[rand() % 6 == 0]);
43 }
44
45 static command_t cmd_roulette = {
46 .name = "ROULETTE",
47 .desc = N_("A game of Russian Roulette."),
48 .access = AC_NONE,
49 .maxparc = 2,
50 .cmd = &command_roulette,
51 .help = { .path = "contrib/roulette" },
52 };
53
54 static void
55 mod_init(module_t *const restrict m)
56 {
57 service_named_bind_command("gameserv", &cmd_roulette);
58 service_named_bind_command("chanserv", &cmd_roulette);
59 }
60
61 static void
62 mod_deinit(const module_unload_intent_t intent)
63 {
64 service_named_unbind_command("gameserv", &cmd_roulette);
65 service_named_unbind_command("chanserv", &cmd_roulette);
66 }
67
68 SIMPLE_DECLARE_MODULE_V1("contrib/gs_roulette", MODULE_UNLOAD_CAPABILITY_OK)