[srvx-commits] CVS: services/src chanserv.c,1.285,1.286
Brought to you by:
entrope
|
From: Entrope <en...@us...> - 2002-09-18 14:51:35
|
Update of /cvsroot/srvx/services/src
In directory usw-pr-cvs1:/tmp/cvs-serv3577/src
Modified Files:
chanserv.c
Log Message:
allow ChanServ to import set options from other modules
make the list and order of options shown by !set configurable
Index: chanserv.c
===================================================================
RCS file: /cvsroot/srvx/services/src/chanserv.c,v
retrieving revision 1.285
retrieving revision 1.286
diff -C2 -r1.285 -r1.286
*** chanserv.c 16 Sep 2002 19:28:10 -0000 1.285
--- chanserv.c 18 Sep 2002 14:51:30 -0000 1.286
***************
*** 410,414 ****
struct userNode *chanserv;
- static dict_t set_func_dict;
dict_t note_types;
static dict_t sChannels;
--- 410,413 ----
***************
*** 436,439 ****
--- 435,439 ----
unsigned int max_chan_users;
unsigned int max_chan_bans;
+ struct string_list *set_shows;
struct string_list *eightball;
***************
*** 4979,4983 ****
static OPTION_FUNC(opt_defaulttopic)
{
! if(argc > 0)
{
char *topic;
--- 4979,4983 ----
static OPTION_FUNC(opt_defaulttopic)
{
! if(argc > 1)
{
char *topic;
***************
*** 4989,4993 ****
}
! topic = unsplit_string(argv, argc, NULL);
if(topic[0] == '*' && topic[1] == 0)
--- 4989,4993 ----
}
! topic = unsplit_string(argv+1, argc-1, NULL);
if(topic[0] == '*' && topic[1] == 0)
***************
*** 5013,5017 ****
static OPTION_FUNC(opt_topicmask)
{
! if(argc > 0)
{
struct chanData *cData = channel->channel_info;
--- 5013,5017 ----
static OPTION_FUNC(opt_topicmask)
{
! if(argc > 1)
{
struct chanData *cData = channel->channel_info;
***************
*** 5024,5028 ****
}
! mask = unsplit_string(argv, argc, NULL);
if(cData->topic_mask) free(cData->topic_mask);
--- 5024,5028 ----
}
! mask = unsplit_string(argv+1, argc-1, NULL);
if(cData->topic_mask) free(cData->topic_mask);
***************
*** 5053,5059 ****
(void)channel;
! if(argc > 0)
{
! char *greeting = unsplit_string(argv, argc, NULL);
if(greeting[0] == '*' && greeting[1] == 0)
--- 5053,5059 ----
(void)channel;
! if(argc > 1)
{
! char *greeting = unsplit_string(argv+1, argc-1, NULL);
if(greeting[0] == '*' && greeting[1] == 0)
***************
*** 5097,5101 ****
char modes[MODELEN];
! if(argc > 0)
{
if(!check_user_level(user, channel, channel->channel_info->options[optEnfModes], 1, 0))
--- 5097,5101 ----
char modes[MODELEN];
! if(argc > 1)
{
if(!check_user_level(user, channel, channel->channel_info->options[optEnfModes], 1, 0))
***************
*** 5104,5108 ****
return 0;
}
! if(argv[0][0] == '*' && argv[0][1] == 0)
{
channel->channel_info->mode_on = 0;
--- 5104,5108 ----
return 0;
}
! if(argv[1][0] == '*' && argv[1][1] == 0)
{
channel->channel_info->mode_on = 0;
***************
*** 5112,5118 ****
else
{
! if(!parse_mode_lock(argv, argc, channel->channel_info))
{
! chanserv_notice(user, CSMSG_INVALID_STR_SET, argv[0], "mode lock");
return 0;
}
--- 5112,5118 ----
else
{
! if(!parse_mode_lock(argv+1, argc-1, channel->channel_info))
{
! chanserv_notice(user, CSMSG_INVALID_STR_SET, argv[1], "mode lock");
return 0;
}
***************
*** 5145,5157 ****
(void)cmd;
! if(argc > 0)
{
/* Set flag according to value. */
! if(enabled_string(argv[0]))
{
cData->flags |= mask;
value = 1;
}
! else if(disabled_string(argv[0]))
{
cData->flags &= ~mask;
--- 5145,5157 ----
(void)cmd;
! if(argc > 1)
{
/* Set flag according to value. */
! if(enabled_string(argv[1]))
{
cData->flags |= mask;
value = 1;
}
! else if(disabled_string(argv[1]))
{
cData->flags &= ~mask;
***************
*** 5160,5164 ****
else
{
! chanserv_notice(user, MSG_INVALID_BINARY, argv[0]);
return 0;
}
--- 5160,5164 ----
else
{
! chanserv_notice(user, MSG_INVALID_BINARY, argv[1]);
return 0;
}
***************
*** 5181,5185 ****
(void)cmd;
! if(argc > 0)
{
/* Set flag according to value. */
--- 5181,5185 ----
(void)cmd;
! if(argc > 1)
{
/* Set flag according to value. */
***************
*** 5190,5194 ****
}
! index = atoi(argv[0]);
if(index < 0 || index >= count)
--- 5190,5194 ----
}
! index = atoi(argv[1]);
if(index < 0 || index >= count)
***************
*** 5223,5229 ****
static OPTION_FUNC(opt_nodelete)
{
! if((argc > 0) && !IsOper(user))
{
! chanserv_notice(user, MSG_SETTING_PRIVILEGED, argv[-1]);
return 0;
}
--- 5223,5229 ----
static OPTION_FUNC(opt_nodelete)
{
! if((argc > 1) && !IsOper(user))
{
! chanserv_notice(user, MSG_SETTING_PRIVILEGED, argv[0]);
return 0;
}
***************
*** 5413,5460 ****
}
static CHANSERV_FUNC(cmd_set)
{
! modcmd_func_t *opt;
! if(argc < 2)
{
! unsigned int i = 0;
! modcmd_func_t *set_display[] = {
! /* multiple-choice options */
! opt_defaulttopic, opt_topicmask, opt_greeting,
! opt_usergreeting, opt_modes, opt_pubcmd, opt_strictop,
! opt_autoop, opt_enfmodes, opt_enftopic, opt_protect,
! opt_toys, opt_setters, opt_topicrefresh, opt_ctcpusers,
! opt_ctcpreaction,
! /* binary options */
! opt_voice, opt_userinfo, opt_dynlimit, opt_topicsnarf,
! opt_nodelete
! };
chanserv_notice(user, CSMSG_CHANNEL_OPTIONS);
-
/* Do this so options are presented in a consistent order. */
! while(i < ArrayLength(set_display))
! {
! set_display[i++](user, channel, 0, NULL, NULL);
! }
!
return 1;
}
! if(!(opt = dict_find(set_func_dict, argv[1], NULL)))
{
! chanserv_notice(user, CSMSG_INVALID_OPTION, argv[1]);
! return 0;
}
-
if((argc > 2)
&& !check_user_level(user, channel, channel->channel_info->options[optSetters], 1, 0))
{
! chanserv_notice(user, CSMSG_NO_ACCESS);
return 0;
}
! return opt(user, channel, argc - 2, argv + 2, NULL);
}
--- 5413,5472 ----
}
+ static struct svccmd_list set_shows_list;
+
static CHANSERV_FUNC(cmd_set)
{
! struct svccmd *subcmd;
! char buf[MAXLEN];
! unsigned int ii;
! /* Check if we need to (re-)initialize set_shows_list. */
! if(!set_shows_list.used)
{
! if(!set_shows_list.size)
! {
! set_shows_list.size = chanserv_conf.set_shows->used;
! set_shows_list.list = calloc(set_shows_list.size, sizeof(set_shows_list.list[0]));
! }
! for(ii = 0; ii < chanserv_conf.set_shows->used; ii++)
! {
! const char *name = chanserv_conf.set_shows->list[ii];
! sprintf(buf, "%s %s", argv[0], name);
! subcmd = dict_find(cmd->parent->commands, buf, NULL);
! if(!subcmd)
! {
! log(CS_LOG, LOG_ERROR, "Unable to find set option %s.\n", name);
! continue;
! }
! svccmd_list_append(&set_shows_list, subcmd);
! }
! }
+ if(argc < 2)
+ {
chanserv_notice(user, CSMSG_CHANNEL_OPTIONS);
/* Do this so options are presented in a consistent order. */
! for(ii = 0; ii < set_shows_list.used; ii++)
! {
! set_shows_list.list[ii]->command->func(user, channel, 1, argv+1, set_shows_list.list[ii]);
! }
return 1;
}
! sprintf(buf, "%s %s", argv[0], argv[1]);
! subcmd = dict_find(cmd->parent->commands, buf, NULL);
! if(!subcmd)
{
! reply(CSMSG_INVALID_OPTION, argv[1]);
! return 0;
}
if((argc > 2)
&& !check_user_level(user, channel, channel->channel_info->options[optSetters], 1, 0))
{
! reply(CSMSG_NO_ACCESS);
return 0;
}
! return subcmd->command->func(user, channel, argc - 1, argv + 1, subcmd);
}
***************
*** 6242,6245 ****
--- 6254,6287 ----
str = database_get_data(conf_node, KEY_MAX_OWNED, RECDB_QSTRING);
chanserv_conf.max_owned = str ? atoi(str) : 5;
+ free_string_list(chanserv_conf.set_shows);
+ strlist = database_get_data(conf_node, "set_shows", RECDB_STRING_LIST);
+ if(strlist)
+ {
+ strlist = string_list_copy(strlist);
+ }
+ else
+ {
+ static const char *list[] = {
+ /* multiple choice options */
+ "DefaultTopic", "TopicMask", "Greeting", "UserGreeting", "Modes",
+ "PubCmd", "StrictOp", "AutoOp", "EnfModes", "EnfTopic", "Protect",
+ "Toys", "Setters", "TopicRefresh", "CtcpUsers", "CtcpReaction",
+ /* binary options */
+ "Voice", "UserInfo", "DynLimit", "TopicSnarf", "NoDelete",
+ /* delimiter */
+ NULL };
+ unsigned int ii;
+ strlist = alloc_string_list(ArrayLength(list)-1);
+ for(ii=0; list[ii]; ii++)
+ {
+ string_list_append(strlist, strdup(list[ii]));
+ }
+ }
+ chanserv_conf.set_shows = strlist;
+ /* We don't look things up now, in case the list refers to options
+ * defined by modules initialized after this point. Just mark the
+ * function list as invalid, so it will be initialized.
+ */
+ set_shows_list.used = 0;
free_string_list(chanserv_conf.eightball);
strlist = database_get_data(conf_node, KEY_8BALL_RESPONSES, RECDB_STRING_LIST);
***************
*** 6835,6839 ****
dict_delete(sChannels);
while(channelList) unregister_channel(channelList);
- dict_delete(set_func_dict);
dict_delete(handle_dnrs);
dict_delete(plain_dnrs);
--- 6877,6880 ----
***************
*** 6841,6848 ****
dict_delete(note_types);
if(chanserv_conf.eightball) free_string_list(chanserv_conf.eightball);
}
#define DEFINE_COMMAND(NAME, MIN_ARGC, FLAGS, OPTIONS...) modcmd_register(chanserv_module, #NAME, cmd_##NAME, MIN_ARGC, FLAGS, ## OPTIONS)
! #define DEFINE_OPTION(NAME) dict_insert(set_func_dict, #NAME, opt_##NAME)
void
--- 6882,6891 ----
dict_delete(note_types);
if(chanserv_conf.eightball) free_string_list(chanserv_conf.eightball);
+ if(chanserv_conf.set_shows) free_string_list(chanserv_conf.set_shows);
+ if(set_shows_list.list) free(set_shows_list.list);
}
#define DEFINE_COMMAND(NAME, MIN_ARGC, FLAGS, OPTIONS...) modcmd_register(chanserv_module, #NAME, cmd_##NAME, MIN_ARGC, FLAGS, ## OPTIONS)
! #define DEFINE_OPTION(NAME) modcmd_register(chanserv_module, "set "#NAME, opt_##NAME, 1, 0, NULL)
void
***************
*** 6967,6971 ****
DEFINE_COMMAND(huggle, 1, 0, "flags", "+nolog,+toy,+acceptchan", NULL);
- set_func_dict = dict_new();
DEFINE_OPTION(defaulttopic);
DEFINE_OPTION(topicmask);
--- 7010,7013 ----
***************
*** 6990,6994 ****
DEFINE_OPTION(ctcpreaction);
/* compatability alias.. */
! dict_insert(set_func_dict, "topic", opt_defaulttopic);
note_types = dict_new();
--- 7032,7036 ----
DEFINE_OPTION(ctcpreaction);
/* compatability alias.. */
! modcmd_register(chanserv_module, "set topic", opt_defaulttopic, 1, 0, NULL);
note_types = dict_new();
|