forked from atheme/atheme-contrib-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgs_roulette.c
73 lines (58 loc) · 1.83 KB
/
gs_roulette.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* Copyright (c) 2005-2006 William Pitcock <[email protected]> et al
* Rights to this code are documented in doc/LICENSE.
*
* Russian Roulette game. Will actually /KILL the user that gets "shot".
*
*/
#include "atheme-compat.h"
DECLARE_MODULE_V1
(
"contrib/gs_roulette", false, _modinit, _moddeinit,
PACKAGE_STRING,
VENDOR_STRING
);
static void command_roulette(sourceinfo_t *si, int parc, char *parv[]);
command_t cmd_roulette = { "ROULETTE", N_("A game of Russian Roulette."), AC_NONE, 2, command_roulette, { .path = "contrib/roulette" } };
void _modinit(module_t * m)
{
service_named_bind_command("gameserv", &cmd_roulette);
service_named_bind_command("chanserv", &cmd_roulette);
}
void _moddeinit(module_unload_intent_t intent)
{
service_named_unbind_command("gameserv", &cmd_roulette);
service_named_unbind_command("chanserv", &cmd_roulette);
}
/*
* Handle reporting for both fantasy commands and normal commands in GameServ
* quickly and easily. Of course, sourceinfo has a vtable that can be manipulated,
* but this is quicker and easier... -- nenolod
*/
static void gs_command_report(sourceinfo_t *si, const char *fmt, ...)
{
va_list args;
char buf[BUFSIZE];
va_start(args, fmt);
vsnprintf(buf, BUFSIZE, fmt, args);
va_end(args);
if (si->c != NULL)
msg(chansvs.nick, si->c->name, "%s", buf);
else
command_success_nodata(si, "%s", buf);
if (!strcasecmp(buf, "*BANG*"))
kill_user(si->service->me, si->su, "Lost at Russian Roulette.");
}
static void command_roulette(sourceinfo_t *si, int parc, char *parv[])
{
static const char *roulette_responses[2] = {
N_("*CLICK*"),
N_("*BANG*")
};
gs_command_report(si, "%s", roulette_responses[rand() % 6 == 0]);
}
/* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
* vim:ts=8
* vim:sw=8
* vim:noexpandtab
*/