1 /*
2  * Copyright (c) 2003-2004 E. Will et al.
3  * Rights to this code are documented in doc/LICENSE.
4  *
5  * This file contains routines to handle the CService SET command.
6  *
7  */
8 
9 #include "atheme.h"
10 
11 DECLARE_MODULE_V1
12 (
13 	"chanserv/set_core", false, _modinit, _moddeinit,
14 	PACKAGE_STRING,
15 	VENDOR_STRING
16 );
17 
18 static void cs_help_set(sourceinfo_t *si, const char *subcmd);
19 static void cs_cmd_set(sourceinfo_t *si, int parc, char *parv[]);
20 
21 command_t cs_set = { "SET", N_("Sets various control flags."), AC_NONE, 3, cs_cmd_set, { .func = cs_help_set } };
22 
23 mowgli_patricia_t *cs_set_cmdtree;
24 
_modinit(module_t * m)25 void _modinit(module_t *m)
26 {
27 	service_named_bind_command("chanserv", &cs_set);
28 
29 	cs_set_cmdtree = mowgli_patricia_create(strcasecanon);
30 }
31 
_moddeinit(module_unload_intent_t intent)32 void _moddeinit(module_unload_intent_t intent)
33 {
34 	service_named_unbind_command("chanserv", &cs_set);
35 
36 	mowgli_patricia_destroy(cs_set_cmdtree, NULL, NULL);
37 }
38 
cs_help_set(sourceinfo_t * si,const char * subcmd)39 static void cs_help_set(sourceinfo_t *si, const char *subcmd)
40 {
41 	if (!subcmd)
42 	{
43 		command_success_nodata(si, _("***** \2%s Help\2 *****"), chansvs.me->disp);
44 		command_success_nodata(si, _("Help for \2SET\2:"));
45 		command_success_nodata(si, " ");
46 		command_success_nodata(si, _("SET allows you to set various control flags\n"
47 					"for channels that change the way certain\n"
48 					"operations are performed on them."));
49 		command_success_nodata(si, " ");
50 		command_help(si, cs_set_cmdtree);
51 		command_success_nodata(si, " ");
52 		command_success_nodata(si, _("For more specific help use \2/msg %s HELP SET \37command\37\2."), chansvs.me->disp);
53 		command_success_nodata(si, _("***** \2End of Help\2 *****"));
54 	}
55 	else
56 		help_display_as_subcmd(si, si->service, "SET", subcmd, cs_set_cmdtree);
57 }
58 
59 /* SET <#channel> <setting> <parameters> */
cs_cmd_set(sourceinfo_t * si,int parc,char * parv[])60 static void cs_cmd_set(sourceinfo_t *si, int parc, char *parv[])
61 {
62 	char *chan;
63 	char *cmd;
64 	command_t *c;
65 
66 	if (parc < 2)
67 	{
68 		command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "SET");
69 		command_fail(si, fault_needmoreparams, _("Syntax: SET <#channel> <setting> [parameters]"));
70 		return;
71 	}
72 
73 	if (parv[0][0] == '#')
74 		chan = parv[0], cmd = parv[1];
75 	else if (parv[1][0] == '#')
76 		cmd = parv[0], chan = parv[1];
77 	else
78 	{
79 		command_fail(si, fault_badparams, STR_INVALID_PARAMS, "SET");
80 		command_fail(si, fault_badparams, _("Syntax: SET <#channel> <setting> [parameters]"));
81 		return;
82 	}
83 
84 	c = command_find(cs_set_cmdtree, cmd);
85 	if (c == NULL)
86 	{
87 		command_fail(si, fault_badparams, _("Invalid command. Use \2/%s%s help\2 for a command listing."), (ircd->uses_rcommand == false) ? "msg " : "", chansvs.me->disp);
88 		return;
89 	}
90 
91 	parv[1] = chan;
92 	command_exec(si->service, si, c, parc - 1, parv + 1);
93 }
94 
95 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
96  * vim:ts=8
97  * vim:sw=8
98  * vim:noexpandtab
99  */
100