#define KEY_MAX_USERINFO_LENGTH "max_userinfo_length"
#define KEY_GIVEOWNERSHIP_PERIOD "giveownership_timeout"
#define KEY_INVITED_INTERVAL "invite_timeout"
+#define KEY_NEW_CHANNEL_AUTHED "new_channel_authed_join"
+#define KEY_NEW_CHANNEL_UNAUTHED "new_channel_unauthed_join"
+#define KEY_NEW_CHANNEL_MSG "new_channel_message"
/* ChanServ database */
#define KEY_CHANNELS "channels"
#define KEY_NOTES "notes"
#define KEY_TOPIC_MASK "topic_mask"
#define KEY_OWNER_TRANSFER "owner_transfer"
+#define KEY_EXPIRE "expire"
/* User data */
#define KEY_LEVEL "level"
#define KEY_INFO "info"
#define KEY_SEEN "seen"
+/* Votes */
+#define KEY_VOTE "vote"
+#define KEY_VOTE_START "votestart"
+#define KEY_VOTE_OPTIONS "voptions"
+#define KEY_VOTE_OPTION_NAME "voptionname"
+#define KEY_VOTE_VOTED "vvoted"
+#define KEY_VOTE_VOTEDFOR "vvotefor"
+#define KEY_VOTE_OPTION_ID "voptionid"
+#define KEY_VOTE_OPTION_VOTED "voptionvoted"
+
/* Ban data */
#define KEY_OWNER "owner"
#define KEY_REASON "reason"
{ "CSMSG_SET_USERINFO", "$bUserInfo $b %d" },
{ "CSMSG_SET_GIVE_VOICE", "$bGiveVoice $b %d" },
{ "CSMSG_SET_TOPICSNARF", "$bTopicSnarf $b %d" },
+ { "CSMSG_SET_VOTE", "$bVote $b %d" },
{ "CSMSG_SET_INVITEME", "$bInviteMe $b %d" },
{ "CSMSG_SET_ENFOPS", "$bEnfOps $b %d" },
{ "CSMSG_SET_GIVE_OPS", "$bGiveOps $b %d" },
{ "CSMSG_SET_CTCPREACTION", "$bCTCPReaction$b %d - %s" },
{ "CSMSG_SET_TOPICREFRESH", "$bTopicRefresh$b %d - %s" },
{ "CSMSG_SET_UNREVIEWED", "$bUnreviewed $b %s" },
+ { "CSMSG_SET_EXPIRE", "$bExpire $b %s" },
+ { "CSMSG_SET_EXPIRE_OFF", "$bExpire $b off" },
{ "CSMSG_USET_NOAUTOOP", "$bNoAutoOp $b %s" },
{ "CSMSG_USET_NOAUTOVOICE", "$bNoAutoVoice $b %s" },
{ "CSMSG_USET_AUTOINVITE", "$bAutoInvite $b %s" },
{ "CSMSG_ACCESS_SEARCH_HEADER", "%s users from level %d to %d matching %s:" },
{ "CSMSG_INVALID_ACCESS", "$b%s$b is an invalid access level." },
{ "CSMSG_CHANGED_ACCESS", "%s now has access $b%d$b in %s." },
+ { "CSMSG_TOTAL_USERS", "There are $b%d$b users in %s." },
/* Channel note list */
{ "CSMSG_NOTELIST_HEADER", "Notes for $b%s$b:" },
{ "CSMSG_UC_H_TITLE", "network helper" },
{ "CSMSG_LC_H_TITLE", "support helper" },
{ "CSMSG_LAME_SMURF_TARGET", "%s is an IRC operator." },
+ { "CSMSG_MYACCESS_COUNT", "%s has access in $b%d$b channels and is owner of $b%d$b channel(s)." },
+ { "CSMSG_MYACCESS_COUNT_1", "%s has access in $b%d$b channel and is owner of $b%d$b channel(s)." },
+
/* Seen information */
{ "CSMSG_NEVER_SEEN", "%s has never been seen in $b%s$b." },
{ "CSMSG_HUGGLES_HIM", "\001ACTION huggles %s\001" },
{ "CSMSG_HUGGLES_YOU", "\001ACTION huggles you\001" },
+/* Vote */
+ { "CSMSG_ADDVOTE_DONE", "Vote added. Use $baddoption$b to add at least 2 vote options and then $bstartvote$b to start the voting." },
+ { "CSMSG_ADDVOTE_FULL", "There is already a vote in this channel. Use $bdelvote$b to delete it." },
+ { "CSMSG_DELVOTE_DONE", "Vote deleted." },
+ { "CSMSG_NO_VOTE", "There is no vote in this channel." },
+ { "CSMSG_ADDOPTION_DONE", "Vote option added with id %i (%i - %i)." },
+ { "CSMSG_DELOPTION_DONE", "Vote option deleted." },
+ { "CSMSG_DELOPTION_NONE", "Vote option does not exist." },
+ { "CSMSG_VOTE_NEED_OPTIONS", "There must be at least 2 options in a vote." },
+ { "CSMSG_VOTE_NOT_STARTED", "The vote is not started. Use $bstartvote$b to allow voting." },
+ { "CSMSG_VOTE_QUESTION", "Question: %s" },
+ { "CSMSG_VOTE_OPTION", "$b%i$b: %s ($b%i$b votes)" },
+ { "CSMSG_VOTERES_QUESTION", "Question: %s" },
+ { "CSMSG_VOTERES_OPTION", "\ 2%i\ 2: %s (\ 2%i\ 2 votes)" },
+ { "CSMSG_STARTVOTE_TOP", "\ 2%s\ 2 has started a voting:" },
+ { "CSMSG_STARTVOTE_QUESTION", "\ 2Question:\ 2 %s" },
+ { "CSMSG_STARTVOTE_OPTION", "\ 2%i:\ 2 %s" },
+ { "CSMSG_STARTVOTE_ACCESS", "All channel users with at least \ 2%i\ 2 access can vote." },
+ { "CSMSG_STARTVOTE_HOWTO", "To vote for an option, use \ 2vote ID\ 2. To see the available options and the current votes, use \ 2vote\ 2 without parameters." },
+ { "CSMSG_STARTVOTE_RUNNING", "The vote is already running." },
+ { "CSMSG_VOTE_VOTED", "You have already voted." },
+ { "CSMSG_VOTE_INVALID", "Vote option does not exist." },
+ { "CSMSG_VOTE_DONE", "You voted for $b%s$b." },
+ { "CSMSG_ENDVOTE_DONE", "The vote has been finished." },
+ { "CSMSG_ENDVOTE_STOPPED", "The vote is not running." },
+
/* Other things */
{ "CSMSG_EVENT_SEARCH_RESULTS", "The following channel events were found:" },
{ NULL, NULL }
const char *irc_operator_epithet;
const char *network_helper_epithet;
const char *support_helper_epithet;
+
+ const char *new_channel_authed;
+ const char *new_channel_unauthed;
+ const char *new_channel_msg;
} chanserv_conf;
struct listData
{ "CSMSG_SET_CTCPUSERS", "ctcpusers", 0, 9, 0, 0 },
{ "CSMSG_SET_USERINFO", "userinfo", 1, ~0, CHANNEL_INFO_LINES, 1 },
{ "CSMSG_SET_INVITEME", "inviteme", 1, ~0, CHANNEL_PEON_INVITE, 200 },
- { "CSMSG_SET_TOPICSNARF", "topicsnarf", 501, ~0, CHANNEL_TOPIC_SNARF, 1 }
+ { "CSMSG_SET_TOPICSNARF", "topicsnarf", 501, ~0, CHANNEL_TOPIC_SNARF, 1 },
+ { "CSMSG_SET_VOTE", "vote", 100, ~0, 0, 0 }
};
struct charOptionValues {
#define GetChannelAccess(channel, handle) _GetChannelUser(channel, handle, 0, 0)
#define GetTrueChannelAccess(channel, handle) _GetChannelUser(channel, handle, 0, 1)
+static void unregister_channel(struct chanData *channel, const char *reason);
unsigned short
user_level_from_name(const char *name, unsigned short clamp_level)
return ntype;
}
+static void
+free_vote_options(void *data)
+{
+ struct vote_option *vOpt = data;
+ free(vOpt->name);
+ free(vOpt->option_str);
+ free(vOpt);
+}
+
static void
chanserv_deref_note_type(void *data)
{
return 1;
}
+static void
+chanserv_expire_channel(void *data)
+{
+ struct chanData *channel = data;
+ char reason[MAXLEN];
+ sprintf(reason, "channel expired.");
+ channel->expiry = 0;
+ spamserv_cs_unregister(NULL, channel->channel, expire, NULL);
+ unregister_channel(channel, reason);
+}
+
+static MODCMD_FUNC(chan_opt_expire)
+{
+ struct chanData *cData = channel->channel_info;
+ unsigned long value = cData->expiry;
+
+ if(argc > 1)
+ {
+ if((!IsOper(user) || !user->handle_info || (user->handle_info->opserv_level < chanserv_conf.nodelete_level)))
+ {
+ reply("MSG_SETTING_PRIVILEGED", argv[0]);
+ return 0;
+ }
+ unsigned long expiry,duration;
+
+ /* The two directions can have different ACLs. */
+ if(!strcmp(argv[1], "0"))
+ expiry = 0;
+ else if((duration = ParseInterval(argv[1])))
+ expiry = now + duration;
+ else
+ {
+ reply("MSG_INVALID_DURATION", argv[1]);
+ return 0;
+ }
+
+ if (expiry != value)
+ {
+ if(value) {
+ //unset old timer
+ timeq_del(value, chanserv_expire_channel, cData, 0);
+ }
+ value = expiry;
+ cData->expiry = value;
+ if(value > 0) {
+ //New timer!
+ timeq_add(expiry, chanserv_expire_channel, cData);
+ }
+ }
+ }
+
+ if(cData->expiry > now) {
+ char expirestr[INTERVALLEN];
+ reply("CSMSG_SET_EXPIRE", intervalString(expirestr, cData->expiry - now, user->handle_info));
+ } else
+ reply("CSMSG_SET_EXPIRE_OFF");
+ return 1;
+}
+
static int
mode_lock_violated(const struct mod_chanmode *orig, const struct mod_chanmode *change)
{
channel->channel = cNode;
LockChannel(cNode);
cNode->channel_info = channel;
+
+ channel->vote = NULL;
return channel;
}
return ud;
}
-static void unregister_channel(struct chanData *channel, const char *reason);
-
void
del_channel_user(struct userData *user, int do_gc)
{
if(cNode)
cNode->channel_info = NULL;
}
+ if(channel->expiry)
+ timeq_del(channel->expiry, chanserv_expire_channel, channel, 0);
channel->channel->channel_info = NULL;
dict_delete(channel->notes);
offset = (action & ACTION_ADD_TIMED_BAN) ? 3 : 2;
REQUIRE_PARAMS(offset);
+ if(argc > offset && IsNetServ(user))
+ {
+ if(*argv[offset] == '$') {
+ struct userNode *hib;
+ const char *accountnameb = argv[offset] + 1;
+ if(!(hib = GetUserH(accountnameb)))
+ {
+ reply("MSG_HANDLE_UNKNOWN", accountnameb);
+ return 0;
+ }
+ user=hib;
+ offset++;
+ }
+ }
if(argc > offset)
{
reason = unsplit_string(argv + offset, argc - offset, NULL);
return eject_user(CSFUNC_ARGS, ACTION_KICK | ACTION_BAN | ACTION_ADD_BAN | ACTION_ADD_TIMED_BAN);
}
-static struct mod_chanmode *
+struct mod_chanmode *
find_matching_bans(struct banList *bans, struct userNode *actee, const char *mask)
{
struct mod_chanmode *change;
static struct string_buffer sbuf;
struct handle_info *target_handle;
struct userData *uData;
+ int ccount = 0;
+ int ocount = 0;
if(argc < 2)
target_handle = user->handle_info;
for(uData = target_handle->channels; uData; uData = uData->u_next)
{
struct chanData *cData = uData->channel;
+ ccount++;
if(uData->access > UL_OWNER)
continue;
+ if(uData->access == UL_OWNER)
+ ocount++;
+
if(IsProtected(cData)
&& (target_handle != user->handle_info)
&& !GetTrueChannelAccess(cData, user->handle_info))
send_message_type(4, user, cmd->parent->bot, "%s", sbuf.list);
}
+ if(ccount == 1) {
+ reply("CSMSG_MYACCESS_COUNT_1", target_handle->handle, ccount, ocount);
+ } else {
+ reply("CSMSG_MYACCESS_COUNT", target_handle->handle, ccount, ocount);
+ }
+
return 1;
}
}
free(lData.table.contents[0]);
free(lData.table.contents);
+ reply("CSMSG_TOTAL_USERS",(lData.table.length - 1),channel->name);
return 1;
}
base_oplevel = 1;
else
base_oplevel = 1 + UL_OWNER - uData->access;
- change = mod_chanmode_parse(channel, argv+1, argc-1, MCP_KEY_FREE|MCP_REGISTERED|MCP_NO_APASS, base_oplevel);
+ change = mod_chanmode_parse(channel, user, argv+1, argc-1, MCP_KEY_FREE|MCP_IGN_REGISTERED|MCP_NO_APASS, base_oplevel);
if(!change)
{
reply("MSG_INVALID_MODES", unsplit_string(argv+1, argc-1, NULL));
return 1;
}
+static CHANSERV_FUNC(cmd_invitemeall)
+{
+ struct handle_info *target = user->handle_info;
+ struct userData *uData;
+
+ if(!target->channels)
+ {
+ reply("CSMSG_SQUAT_ACCESS", target->handle);
+ return 1;
+ }
+
+ for(uData = target->channels; uData; uData = uData->u_next)
+ {
+ struct chanData *cData = uData->channel;
+ if(uData->access >= cData->lvlOpts[lvlInviteMe])
+ {
+ irc_invite(cmd->parent->bot, user, cData->channel);
+ }
+ }
+ return 1;
+}
+
static void
show_suspension_info(struct svccmd *cmd, struct userNode *user, struct suspended *suspended)
{
continue;
if(IsBot(user))
continue;
+ if(IsInvi(user))
+ continue;
table.contents[table.length] = alloca(table.width*sizeof(**table.contents));
if(IsAway(user))
{
{
if(!(mn->modes & MODE_CHANOP))
{
- changes->args[used].mode = MODE_CHANOP;
- changes->args[used++].u.member = mn;
+ if(!uData || IsUserAutoOp(uData))
+ {
+ changes->args[used].mode = MODE_CHANOP;
+ changes->args[used++].u.member = mn;
+ if(!(mn->modes & MODE_VOICE))
+ {
+ changes->args[used].mode = MODE_VOICE;
+ changes->args[used++].u.member = mn;
+ }
+ }
}
}
else if(!cData->lvlOpts[lvlGiveVoice]
changes->args[used].mode = MODE_REMOVE | (mn->modes & ~MODE_VOICE);
changes->args[used++].u.member = mn;
}
- if(!(mn->modes & MODE_VOICE))
+ if(!(mn->modes & MODE_VOICE) && (!uData || IsUserAutoOp(uData)))
{
changes->args[used].mode = MODE_VOICE;
changes->args[used++].u.member = mn;
{
memset(&channel->channel_info->modes, 0, sizeof(channel->channel_info->modes));
}
- else if(!(new_modes = mod_chanmode_parse(channel, argv+1, argc-1, MCP_KEY_FREE|MCP_REGISTERED|MCP_NO_APASS, 0)))
+ else if(!(new_modes = mod_chanmode_parse(channel, user, argv+1, argc-1, MCP_KEY_FREE|MCP_IGN_REGISTERED|MCP_NO_APASS|(IsOper(user) && IsHelping(user) ? MCP_OPERMODE : 0), 0)))
{
reply("CSMSG_INVALID_MODE_LOCK", unsplit_string(argv+1, argc-1, NULL));
return 0;
return channel_level_option(lvlTopicSnarf, CSFUNC_ARGS);
}
+static MODCMD_FUNC(chan_opt_vote)
+{
+ return channel_level_option(lvlVote, CSFUNC_ARGS);
+}
+
static MODCMD_FUNC(chan_opt_inviteme)
{
return channel_level_option(lvlInviteMe, CSFUNC_ARGS);
return 1;
}
+static CHANSERV_FUNC(cmd_addvote)
+{
+ struct chanData *cData = channel->channel_info;
+ struct userData *uData, *target;
+ struct handle_info *hi;
+ if (!cData) return 0;
+ REQUIRE_PARAMS(2);
+ hi = user->handle_info;
+ if(!(target = GetTrueChannelAccess(channel->channel_info, hi)))
+ {
+ reply("CSMSG_NO_CHAN_USER", hi->handle, channel->name);
+ return 0;
+ }
+ if(target->access < 300) {
+ reply("CSMSG_NO_ACCESS");
+ return 0;
+ }
+ if (cData->vote) {
+ reply("CSMSG_ADDVOTE_FULL");
+ return 0;
+ }
+ char *msg;
+ msg = unsplit_string(argv + 1, argc - 1, NULL);
+ cData->vote = strdup(msg);
+ cData->vote_start=0;
+ dict_delete(cData->vote_options);
+ cData->vote_options = dict_new();
+ dict_set_free_data(cData->vote_options, free_vote_options);
+ for(uData = channel->channel_info->users; uData; uData = uData->next)
+ {
+ uData->voted = 0;
+ uData->votefor = 0;
+ }
+ reply("CSMSG_ADDVOTE_DONE");
+ return 1;
+}
+
+static CHANSERV_FUNC(cmd_delvote)
+{
+ struct chanData *cData = channel->channel_info;
+ struct userData *target;
+ struct handle_info *hi;
+ if (!cData) return 0;
+ hi = user->handle_info;
+ if(!(target = GetTrueChannelAccess(channel->channel_info, hi)))
+ {
+ reply("CSMSG_NO_CHAN_USER", hi->handle, channel->name);
+ return 0;
+ }
+ if(target->access < 300) {
+ reply("CSMSG_NO_ACCESS");
+ return 0;
+ }
+ if (!cData->vote) {
+ reply("CSMSG_NO_VOTE");
+ return 0;
+ }
+ free(cData->vote);
+ cData->vote = NULL;
+ reply("CSMSG_DELVOTE_DONE");
+ return 1;
+}
+
+static CHANSERV_FUNC(cmd_addoption)
+{
+ struct chanData *cData = channel->channel_info;
+ struct userData *target;
+ struct handle_info *hi;
+ if (!cData) return 0;
+ REQUIRE_PARAMS(2);
+ hi = user->handle_info;
+ if(!(target = GetTrueChannelAccess(channel->channel_info, hi)))
+ {
+ reply("CSMSG_NO_CHAN_USER", hi->handle, channel->name);
+ return 0;
+ }
+ if(target->access < 300) {
+ reply("CSMSG_NO_ACCESS");
+ return 0;
+ }
+ if (!cData->vote) {
+ reply("CSMSG_NO_VOTE");
+ return 0;
+ }
+
+ char *msg;
+
+ msg = unsplit_string(argv + 1, argc - 1, NULL);
+
+ dict_iterator_t it;
+ unsigned int lastid = 1;
+ for (it = dict_first(cData->vote_options); it; it = iter_next(it)) {
+ struct vote_option *cvOpt = iter_data(it);
+ if(cvOpt->option_id > lastid)
+ lastid = cvOpt->option_id;
+ }
+ struct vote_option *vOpt;
+ vOpt = calloc(1, sizeof(*vOpt));
+ vOpt->name = strdup(msg);
+ vOpt->option_id = (lastid + 1);
+ char str[50];
+ sprintf(str,"%i",(lastid + 1));
+ vOpt->option_str = strdup(str);
+ vOpt->voted = 0;
+ dict_insert(cData->vote_options,vOpt->option_str,vOpt);
+
+ reply("CSMSG_ADDOPTION_DONE",dict_size(cData->vote_options),lastid,(lastid + 1));
+ return 1;
+}
+
+static CHANSERV_FUNC(cmd_deloption)
+{
+ struct chanData *cData = channel->channel_info;
+ struct userData *uData, *target;
+ struct handle_info *hi;
+ if (!cData) return 0;
+ REQUIRE_PARAMS(2);
+ hi = user->handle_info;
+ if(!(target = GetTrueChannelAccess(channel->channel_info, hi)))
+ {
+ reply("CSMSG_NO_CHAN_USER", hi->handle, channel->name);
+ return 0;
+ }
+ if(target->access < 300) {
+ reply("CSMSG_NO_ACCESS");
+ return 0;
+ }
+ if (!cData->vote) {
+ reply("CSMSG_NO_VOTE");
+ return 0;
+ }
+ if(cData->vote_start) {
+ if(dict_size(cData->vote_options) < 3) {
+ reply("CSMSG_VOTE_NEED_OPTIONS");
+ return 0;
+ }
+ }
+
+ int find_id = atoi(argv[1]);
+ int ii = 0;
+ unsigned int found = 0;
+ dict_iterator_t it;
+
+ for (it = dict_first(cData->vote_options); it; it = iter_next(it)) {
+ ii++;
+ if (find_id == ii) {
+ struct vote_option *vOpt = iter_data(it);
+ found = vOpt->option_id;
+ char str[50];
+ sprintf(str,"%i",vOpt->option_id);
+ dict_remove(cData->vote_options, str);
+ }
+ }
+
+ if(found > 0) {
+ for(uData = channel->channel_info->users; uData; uData = uData->next) {
+ if(uData->votefor == found) {
+ uData->voted = 0;
+ uData->votefor = 0;
+ }
+ }
+ reply("CSMSG_DELOPTION_DONE");
+ return 1;
+ } else {
+ reply("CSMSG_DELOPTION_NONE");
+ return 0;
+ }
+}
+
+static CHANSERV_FUNC(cmd_vote)
+{
+ struct chanData *cData = channel->channel_info;
+ struct userData *target;
+ struct handle_info *hi;
+ unsigned int votedfor = 0;
+ char *votedfor_str = NULL;
+
+ if (!cData || !cData->vote) {
+ reply("CSMSG_NO_VOTE");
+ return 0;
+ }
+ if(argc > 1 && cData->vote_start) {
+ hi = user->handle_info;
+ if(!(target = GetTrueChannelAccess(channel->channel_info, hi)))
+ {
+ reply("CSMSG_NO_CHAN_USER", hi->handle, channel->name);
+ return 0;
+ }
+ if(!check_user_level(channel, user, lvlVote, 1, 0)) {
+ reply("CSMSG_NO_ACCESS");
+ return 0;
+ }
+ if(target->voted) {
+ reply("CSMSG_VOTE_VOTED");
+ return 0;
+ }
+ int find_id = atoi(argv[1]);
+ int ii = 0;
+ dict_iterator_t it;
+ for (it = dict_first(cData->vote_options); it; it = iter_next(it)) {
+ ii++;
+ if (find_id == ii) {
+ struct vote_option *vOpt = iter_data(it);
+ vOpt->voted++;
+ target->voted = 1;
+ target->votefor = vOpt->option_id;
+ votedfor = vOpt->option_id;
+ votedfor_str = vOpt->name;
+ }
+ }
+ if(votedfor == 0) {
+ reply("CSMSG_VOTE_INVALID");
+ return 0;
+ }
+ }
+ if (!cData->vote_start) {
+ reply("CSMSG_VOTE_NOT_STARTED");
+ }
+ reply("CSMSG_VOTE_QUESTION",cData->vote);
+
+ unsigned int voteid = 0;
+ dict_iterator_t it;
+
+ for (it = dict_first(cData->vote_options); it; it = iter_next(it)) {
+ struct vote_option *vOpt = iter_data(it);
+ voteid++;
+ reply("CSMSG_VOTE_OPTION",voteid,vOpt->name,vOpt->voted);
+ }
+ if(argc > 1 && cData->vote_start && votedfor_str) {
+ reply("CSMSG_VOTE_DONE",votedfor_str);
+ }
+ return 1;
+}
+
+static CHANSERV_FUNC(cmd_startvote)
+{
+ struct chanData *cData = channel->channel_info;
+ struct userData *target;
+ struct handle_info *hi;
+ if (!cData) return 0;
+ hi = user->handle_info;
+ if(!(target = GetTrueChannelAccess(channel->channel_info, hi)))
+ {
+ reply("CSMSG_NO_CHAN_USER", hi->handle, channel->name);
+ return 0;
+ }
+ if(target->access < 300) {
+ reply("CSMSG_NO_ACCESS");
+ return 0;
+ }
+ if (!cData->vote) {
+ reply("CSMSG_NO_VOTE");
+ return 0;
+ }
+ if(cData->vote_start) {
+ reply("CSMSG_STARTVOTE_RUNNING");
+ return 0;
+ }
+ if(dict_size(cData->vote_options) < 2) {
+ reply("CSMSG_VOTE_NEED_OPTIONS");
+ return 0;
+ }
+ cData->vote_start = 1;
+ char response[MAXLEN];
+ sprintf(response, user_find_message(user, "CSMSG_STARTVOTE_TOP"), user->nick);
+ irc_privmsg(cmd->parent->bot, channel->name, response);
+ sprintf(response, user_find_message(user, "CSMSG_STARTVOTE_QUESTION"), cData->vote);
+ irc_privmsg(cmd->parent->bot, channel->name, response);
+ unsigned int voteid = 0;
+ dict_iterator_t it;
+ for (it = dict_first(cData->vote_options); it; it = iter_next(it)) {
+ struct vote_option *vOpt = iter_data(it);
+ voteid++;
+ sprintf(response, user_find_message(user, "CSMSG_STARTVOTE_OPTION"), voteid, vOpt->name);
+ irc_privmsg(cmd->parent->bot, channel->name, response);
+ }
+ sprintf(response, user_find_message(user, "CSMSG_STARTVOTE_ACCESS"), cData->lvlOpts[lvlVote]); //Todo
+ irc_privmsg(cmd->parent->bot, channel->name, response);
+ sprintf(response, user_find_message(user, "CSMSG_STARTVOTE_HOWTO")); //Todo
+ irc_privmsg(cmd->parent->bot, channel->name, response);
+ return 1;
+}
+
+static CHANSERV_FUNC(cmd_endvote)
+{
+ struct chanData *cData = channel->channel_info;
+ struct userData *target;
+ struct handle_info *hi;
+ if (!cData) return 0;
+ hi = user->handle_info;
+ if(!(target = GetTrueChannelAccess(channel->channel_info, hi)))
+ {
+ reply("CSMSG_NO_CHAN_USER", hi->handle, channel->name);
+ return 0;
+ }
+ if(target->access < 300) {
+ reply("CSMSG_NO_ACCESS");
+ return 0;
+ }
+ if (!cData->vote) {
+ reply("CSMSG_NO_VOTE");
+ return 0;
+ }
+ if(!cData->vote_start) {
+ reply("CSMSG_ENDVOTE_STOPPED");
+ return 0;
+ }
+ cData->vote_start = 0;
+ reply("CSMSG_ENDVOTE_DONE");
+ return 1;
+}
+
+static CHANSERV_FUNC(cmd_voteresults)
+{
+ struct chanData *cData = channel->channel_info;
+ struct userData *target;
+ struct handle_info *hi;
+ if (!cData) return 0;
+ if (!cData->vote) {
+ reply("CSMSG_NO_VOTE");
+ return 0;
+ }
+ if (argc > 1 && !irccasecmp(argv[1], "*")) {
+ hi = user->handle_info;
+ if(!(target = GetTrueChannelAccess(channel->channel_info, hi)))
+ {
+ reply("CSMSG_NO_CHAN_USER", hi->handle, channel->name);
+ return 0;
+ }
+ if(target->access < 300) {
+ reply("CSMSG_NO_ACCESS");
+ return 0;
+ }
+ char response[MAXLEN];
+ sprintf(response, user_find_message(user, "CSMSG_VOTERES_QUESTION"), cData->vote);
+ irc_privmsg(cmd->parent->bot, channel->name, response);
+ unsigned int voteid = 0;
+ dict_iterator_t it;
+ for (it = dict_first(cData->vote_options); it; it = iter_next(it)) {
+ struct vote_option *vOpt = iter_data(it);
+ voteid++;
+ sprintf(response, user_find_message(user, "CSMSG_VOTERES_OPTION"), voteid, vOpt->name, vOpt->voted);
+ irc_privmsg(cmd->parent->bot, channel->name, response);
+ }
+ } else {
+ reply("CSMSG_VOTE_QUESTION",cData->vote);
+ unsigned int voteid = 0;
+ dict_iterator_t it;
+ for (it = dict_first(cData->vote_options); it; it = iter_next(it)) {
+ struct vote_option *vOpt = iter_data(it);
+ voteid++;
+ reply("CSMSG_VOTE_OPTION",voteid,vOpt->name,vOpt->voted);
+ }
+ }
+ return 1;
+}
+
static void
chanserv_refresh_topics(UNUSED_ARG(void *data))
{
SetChannelTopic(channel, chanserv, channel->channel_info->topic, 1);
}
+void handle_new_channel_created(char *chan, struct userNode *user) {
+ if(user->handle_info && chanserv_conf.new_channel_authed) {
+ send_target_message(5, chan, chanserv, "%s", chanserv_conf.new_channel_authed);
+ } else if(!user->handle_info && chanserv_conf.new_channel_unauthed) {
+ send_target_message(5, chan, chanserv, "%s", chanserv_conf.new_channel_unauthed);
+ }
+ if(chanserv_conf.new_channel_msg)
+ send_target_message(5, chan, chanserv, "%s", chanserv_conf.new_channel_msg);
+}
+
/* Welcome to my worst nightmare. Warning: Read (or modify)
the code below at your own risk. */
static int
struct handle_info *handle;
unsigned int modes = 0, info = 0;
char *greeting;
+ unsigned int i = 0;
if(IsLocal(user) || !channel->channel_info || IsSuspended(channel->channel_info))
return 0;
chanserv_conf.network_helper_epithet = str ? str : "a wannabe tyrant";
str = database_get_data(conf_node, KEY_SUPPORT_HELPER_EPITHET, RECDB_QSTRING);
chanserv_conf.support_helper_epithet = str ? str : "a wannabe tyrant";
+ str = database_get_data(conf_node, KEY_NEW_CHANNEL_AUTHED, RECDB_QSTRING);
+ chanserv_conf.new_channel_authed = str ? str : NULL;
+ str = database_get_data(conf_node, KEY_NEW_CHANNEL_UNAUTHED, RECDB_QSTRING);
+ chanserv_conf.new_channel_unauthed = str ? str : NULL;
+ str = database_get_data(conf_node, KEY_NEW_CHANNEL_MSG, RECDB_QSTRING);
+ chanserv_conf.new_channel_msg = str ? str : NULL;
str = database_get_data(conf_node, "default_modes", RECDB_QSTRING);
if(!str)
str = "+nt";
safestrncpy(mode_line, str, sizeof(mode_line));
ii = split_line(mode_line, 0, ArrayLength(modes), modes);
- if((change = mod_chanmode_parse(NULL, modes, ii, MCP_KEY_FREE|MCP_NO_APASS, 0))
+ if((change = mod_chanmode_parse(NULL, NULL, modes, ii, MCP_KEY_FREE|MCP_NO_APASS, 0))
&& (change->argc < 2))
{
chanserv_conf.default_modes = *change;
/* multiple choice options */
"CtcpReaction", "Protect", "Toys", "TopicRefresh",
/* binary options */
- "DynLimit", "NoDelete",
+ "DynLimit", "NoDelete", "expire", "Vote",
/* delimiter */
NULL
};
ntype->max_length = str ? strtoul(str, NULL, 0) : 400;
}
+static void
+vote_option_read_helper(const char *key, struct record_data *rd, struct chanData *chan)
+{
+ struct vote_option *vOpt;
+ char *str;
+
+ if(rd->type != RECDB_OBJECT || !dict_size(rd->d.object))
+ {
+ log_module(CS_LOG, LOG_ERROR, "Invalid vote option in %s.", chan->channel->name);
+ return;
+ }
+
+ vOpt = calloc(1, sizeof(*vOpt));
+ vOpt->name = strdup(database_get_data(rd->d.object, KEY_VOTE_OPTION_NAME, RECDB_QSTRING));
+ str = database_get_data(rd->d.object, KEY_VOTE_OPTION_VOTED, RECDB_QSTRING);
+ vOpt->voted = str ? atoi(str) : 0;
+ vOpt->option_id = str ? atoi(key) : 0;
+ vOpt->option_str = strdup(key);
+ dict_insert(chan->vote_options,vOpt->option_str,vOpt);
+}
+
static void
user_read_helper(const char *key, struct record_data *rd, struct chanData *chan)
{
struct handle_info *handle;
struct userData *uData;
- char *seen, *inf, *flags;
+ char *seen, *inf, *flags, *voted, *votefor;
unsigned long last_seen;
unsigned short access_level;
seen = database_get_data(rd->d.object, KEY_SEEN, RECDB_QSTRING);
last_seen = seen ? strtoul(seen, NULL, 0) : now;
flags = database_get_data(rd->d.object, KEY_FLAGS, RECDB_QSTRING);
+ voted = database_get_data(rd->d.object, KEY_VOTE_VOTED, RECDB_QSTRING);
+ votefor = database_get_data(rd->d.object, KEY_VOTE_VOTEDFOR, RECDB_QSTRING);
handle = get_handle_info(key);
if(!handle)
{
uData = add_channel_user(chan, handle, access_level, last_seen, inf);
uData->flags = flags ? strtoul(flags, NULL, 0) : 0;
+ if(chan->vote) {
+ uData->voted = voted ? strtoul(voted, NULL, 0) : 0;
+ uData->votefor = votefor ? strtoul(votefor, NULL, 0) : 0;
+ } else {
+ uData->voted = 0;
+ uData->votefor = 0;
+ }
}
static void
cData->chOpts[chOpt] = ((count <= charOptions[chOpt].old_idx) ? str : CHANNEL_DEFAULT_OPTIONS)[charOptions[chOpt].old_idx];
}
+ if((str = database_get_data(hir->d.object, KEY_EXPIRE, RECDB_QSTRING)))
+ {
+ cData->expiry = atoi(str);
+ if(cData->expiry > 0) {
+ if(cData->expiry > now) {
+ timeq_add(cData->expiry, chanserv_expire_channel, cData);
+ } else {
+ timeq_add(1, chanserv_expire_channel, cData);
+ }
+ }
+ } else {
+ cData->expiry = 0;
+ }
+
if((obj = database_get_data(hir->d.object, KEY_SUSPENDED, RECDB_OBJECT)))
{
suspended = chanserv_read_suspended(obj);
str = database_get_data(channel, KEY_TOPIC, RECDB_QSTRING);
cData->topic = str ? strdup(str) : NULL;
+ str = database_get_data(channel, KEY_VOTE, RECDB_QSTRING);
+ if(str) {
+ cData->vote = str ? strdup(str) : NULL;
+ dict_delete(cData->vote_options);
+ cData->vote_options = dict_new();
+ dict_set_free_data(cData->vote_options, free_vote_options);
+ str = database_get_data(channel, KEY_VOTE_START, RECDB_QSTRING);
+ cData->vote_start = str ? atoi(str) : 0;
+ obj = database_get_data(channel, KEY_VOTE_OPTIONS, RECDB_OBJECT);
+ for(it = dict_first(obj); it; it = iter_next(it)) {
+ vote_option_read_helper(iter_key(it), iter_data(it), cData);
+ }
+ }
+
if(!IsSuspended(cData)
&& (str = database_get_data(channel, KEY_MODES, RECDB_QSTRING))
&& (argc = split_line(str, 0, ArrayLength(argv), argv))
- && (modes = mod_chanmode_parse(cNode, argv, argc, MCP_KEY_FREE|MCP_NO_APASS, 0))) {
+ && (modes = mod_chanmode_parse(cNode, NULL, argv, argc, MCP_KEY_FREE|MCP_NO_APASS, 0))) {
cData->modes = *modes;
if(off_channel > 0)
cData->modes.modes_set |= MODE_REGISTERED;
saxdb_write_int(ctx, KEY_SEEN, uData->seen);
if(uData->flags)
saxdb_write_int(ctx, KEY_FLAGS, uData->flags);
+ if(uData->channel->vote && uData->voted)
+ saxdb_write_int(ctx, KEY_VOTE_VOTED, uData->voted);
+ if(uData->channel->vote && uData->votefor)
+ saxdb_write_int(ctx, KEY_VOTE_VOTEDFOR, uData->votefor);
if(uData->info)
saxdb_write_string(ctx, KEY_INFO, uData->info);
saxdb_end_record(ctx);
int high_present;
enum levelOption lvlOpt;
enum charOption chOpt;
+ dict_iterator_t it;
saxdb_start_record(ctx, channel->channel->name, 1);
saxdb_write_string(ctx, KEY_TOPIC_MASK, channel->topic_mask);
if(channel->suspended)
chanserv_write_suspended(ctx, "suspended", channel->suspended);
+ if(channel->expiry)
+ saxdb_write_int(ctx, KEY_EXPIRE, channel->expiry);
+
+ if(channel->vote) {
+ saxdb_write_string(ctx, KEY_VOTE, channel->vote);
+ if(channel->vote_start)
+ saxdb_write_int(ctx, KEY_VOTE_START, channel->vote_start);
+ if (dict_size(channel->vote_options)) {
+ saxdb_start_record(ctx, KEY_VOTE_OPTIONS, 1);
+ for (it = dict_first(channel->vote_options); it; it = iter_next(it)) {
+ struct vote_option *vOpt = iter_data(it);
+ char str[50];
+ sprintf(str,"%i",vOpt->option_id);
+ saxdb_start_record(ctx, str, 0);
+ if(vOpt->voted)
+ saxdb_write_int(ctx, KEY_VOTE_OPTION_VOTED, vOpt->voted);
+ if(vOpt->name)
+ saxdb_write_string(ctx, KEY_VOTE_OPTION_NAME, vOpt->name);
+ saxdb_end_record(ctx);
+ }
+ saxdb_end_record(ctx);
+ }
+ }
saxdb_start_record(ctx, KEY_OPTIONS, 0);
saxdb_write_int(ctx, KEY_FLAGS, channel->flags);
DEFINE_COMMAND(topic, 1, MODCMD_REQUIRE_REGCHAN, "template", "op", "flags", "+never_csuspend", NULL);
DEFINE_COMMAND(mode, 1, MODCMD_REQUIRE_REGCHAN, "template", "op", NULL);
DEFINE_COMMAND(inviteme, 1, MODCMD_REQUIRE_CHANNEL, "access", "1", NULL);
+ DEFINE_COMMAND(invitemeall, 1, MODCMD_REQUIRE_AUTHED, NULL);
DEFINE_COMMAND(invite, 1, MODCMD_REQUIRE_CHANNEL, "access", "master", NULL);
DEFINE_COMMAND(set, 1, MODCMD_REQUIRE_CHANUSER, "access", "op", NULL);
DEFINE_COMMAND(wipeinfo, 2, MODCMD_REQUIRE_CHANUSER, "access", "master", NULL);
DEFINE_COMMAND(8ball, 1, 0, "flags", "+nolog,+toy,+acceptchan", NULL);
DEFINE_COMMAND(d, 1, 0, "flags", "+nolog,+toy,+acceptchan", NULL);
DEFINE_COMMAND(huggle, 1, 0, "flags", "+nolog,+toy,+acceptchan", NULL);
+
+ DEFINE_COMMAND(addvote, 1, MODCMD_REQUIRE_AUTHED, NULL);
+ DEFINE_COMMAND(delvote, 1, MODCMD_REQUIRE_AUTHED, NULL);
+ DEFINE_COMMAND(addoption, 1, MODCMD_REQUIRE_AUTHED, NULL);
+ DEFINE_COMMAND(deloption, 1, MODCMD_REQUIRE_AUTHED, NULL);
+ DEFINE_COMMAND(vote, 1, MODCMD_REQUIRE_AUTHED, NULL);
+ DEFINE_COMMAND(startvote, 1, MODCMD_REQUIRE_AUTHED, NULL);
+ DEFINE_COMMAND(endvote, 1, MODCMD_REQUIRE_AUTHED, NULL);
+ DEFINE_COMMAND(voteresults, 1, MODCMD_REQUIRE_AUTHED, NULL);
/* Channel options */
DEFINE_CHANNEL_OPTION(defaulttopic);
DEFINE_CHANNEL_OPTION(userinfo);
DEFINE_CHANNEL_OPTION(dynlimit);
DEFINE_CHANNEL_OPTION(topicsnarf);
+ DEFINE_CHANNEL_OPTION(vote);
DEFINE_CHANNEL_OPTION(nodelete);
DEFINE_CHANNEL_OPTION(toys);
DEFINE_CHANNEL_OPTION(setters);
DEFINE_CHANNEL_OPTION(ctcpreaction);
DEFINE_CHANNEL_OPTION(inviteme);
DEFINE_CHANNEL_OPTION(unreviewed);
+ modcmd_register(chanserv_module, "set expire", chan_opt_expire, 1, 0, "flags", "+helping", NULL);
modcmd_register(chanserv_module, "set unreviewed on", NULL, 0, 0, "flags", "+helping", NULL);
modcmd_register(chanserv_module, "set unreviewed off", NULL, 0, 0, "flags", "+oper", NULL);
if(off_channel > 1)