X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2Fchanserv.c;h=44f6d9d5f1488f88c0b24d06260e0fce960e1eb9;hb=58d823d306b690515fbc6f671636d4ec152b867a;hp=971fbd8c66ac188b78ed72a421446b8a36096a94;hpb=57d6297a35f52a61a803bb042eb64011333ef8ad;p=srvx.git diff --git a/src/chanserv.c b/src/chanserv.c index 971fbd8..44f6d9d 100644 --- a/src/chanserv.c +++ b/src/chanserv.c @@ -1,5 +1,5 @@ /* chanserv.c - Channel service bot - * Copyright 2000-2006 srvx Development Team + * Copyright 2000-2007 srvx Development Team * * This file is part of srvx. * @@ -22,8 +22,10 @@ #include "conf.h" #include "global.h" #include "modcmd.h" -#include "opserv.h" /* for opserv_bad_channel() */ +#include "opserv.h" /* for opserv_bad_channel() and devnull management */ +#include "nickserv.h" /* for oper_outranks() */ #include "saxdb.h" +#include "spamserv.h" #include "timeq.h" #define CHANSERV_CONF_NAME "services/chanserv" @@ -41,6 +43,7 @@ #define KEY_DNR_EXPIRE_FREQ "dnr_expire_freq" #define KEY_MAX_CHAN_USERS "max_chan_users" #define KEY_MAX_CHAN_BANS "max_chan_bans" +#define KEY_MIN_TIME_BANS "min_time_bans" #define KEY_NICK "nick" #define KEY_OLD_CHANSERV_NAME "old_chanserv_name" #define KEY_8BALL_RESPONSES "8ball" @@ -55,6 +58,11 @@ #define KEY_NODELETE_LEVEL "nodelete_level" #define KEY_MAX_USERINFO_LENGTH "max_userinfo_length" #define KEY_GIVEOWNERSHIP_PERIOD "giveownership_timeout" +#define KEY_INVITED_INTERVAL "invite_timeout" +#define KEY_REVOKE_MODE_A "revoke_mode_a" +#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" @@ -88,6 +96,11 @@ #define KEY_REVOKED "revoked" #define KEY_SUSPEND_EXPIRES "suspend_expires" #define KEY_SUSPEND_REASON "suspend_reason" +#define KEY_GIVEOWNERSHIP "giveownership" +#define KEY_STAFF_ISSUER "staff_issuer" +#define KEY_OLD_OWNER "old_owner" +#define KEY_TARGET "target" +#define KEY_TARGET_ACCESS "target_access" #define KEY_VISITED "visited" #define KEY_TOPIC "topic" #define KEY_GREETING "greeting" @@ -98,15 +111,28 @@ #define KEY_USERS "users" #define KEY_BANS "bans" #define KEY_MAX "max" +#define KEY_MAX_TIME "max_time" #define KEY_NOTES "notes" #define KEY_TOPIC_MASK "topic_mask" +#define KEY_ADVTOPIC_ENTRIES "adv_topic" #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" @@ -130,6 +156,7 @@ static const struct message_entry msgtab[] = { { "CSMSG_MUST_BE_OPPED", "You must be a channel operator in $b%s$b to register it." }, { "CSMSG_PROXY_FORBIDDEN", "You may not register a channel for someone else." }, { "CSMSG_OWN_TOO_MANY", "%s already owns enough channels (at least %d); use FORCE to override." }, + { "CMSG_ALERT_REGISTERED" "%s registered to %s by %s." }, /* Do-not-register channels */ { "CSMSG_NOT_DNR", "$b%s$b is not a valid channel name or *account." }, @@ -152,6 +179,7 @@ static const struct message_entry msgtab[] = { { "CSMSG_UNREG_NODELETE", "$b%s$b is protected from unregistration." }, { "CSMSG_CHAN_SUSPENDED", "$b$C$b access to $b%s$b has been temporarily suspended (%s)." }, { "CSMSG_CONFIRM_UNREG", "To confirm this unregistration, you must use 'unregister %s'." }, + { "CMSG_ALERT_UNREGISTERED" "%s %s" }, /* Channel moving */ { "CSMSG_MOVE_SUCCESS", "Channel registration has been moved to $b%s$b." }, @@ -180,6 +208,7 @@ static const struct message_entry msgtab[] = { { "CSMSG_ALREADY_VOICED", "You are already voiced in $b%s$b." }, { "CSMSG_ALREADY_DOWN", "You are not opped or voiced in $b%s$b." }, { "CSMSG_ALREADY_OPCHANNED", "There has been no net.join since the last opchan in $b%s$b." }, + { "CSMSG_OUT_OF_CHANNEL", "For some reason I don't seem to be in $b%s$b." }, { "CSMSG_OPCHAN_DONE", "I have (re-)opped myself in $b%s$b." }, /* Removing yourself from a channel. */ @@ -190,7 +219,7 @@ static const struct message_entry msgtab[] = { /* User management */ { "CSMSG_ADDED_USER", "Added %s to the %s user list with access %d." }, { "CSMSG_DELETED_USER", "Deleted %s (with access %d) from the %s user list." }, - { "CSMSG_BAD_RANGE", "Invalid access range; minimum (%d) must be greater than maximum (%d)." }, + { "CSMSG_BAD_RANGE", "Invalid access range; minimum (%d) must be lower than maximum (%d)." }, { "CSMSG_DELETED_USERS", "Deleted accounts matching $b%s$b with access from $b%d$b to $b%d$b from the %s user list." }, { "CSMSG_TRIMMED_USERS", "Trimmed $b%d users$b with access from %d to %d from the %s user list who were inactive for at least %s." }, { "CSMSG_INCORRECT_ACCESS", "%s has access $b%d$b, not %s." }, @@ -237,6 +266,7 @@ static const struct message_entry msgtab[] = { { "CSMSG_TOPIC_LOCKED", "The %s topic is locked." }, { "CSMSG_MASK_BUT_NO_TOPIC", "Warning: $b%s$b does not have a default topic, but you just set the topic mask." }, { "CSMSG_TOPIC_MISMATCH", "Warning: The default topic for $b%s$b does not match the topic mask; changing it anyway." }, + { "CSMSG_ADVTOPIC_INVALID_ID", "%d is an invalid advtopic id." }, { "CSMSG_MODES_SET", "Channel modes are now $b%s$b." }, { "CSMSG_DEFAULTED_MODES", "Channel modes for $b%s$b are set to their defaults." }, @@ -254,6 +284,7 @@ static const struct message_entry msgtab[] = { { "CSMSG_INVALID_NUMERIC", "$b%d$b is not a valid choice. Choose one:" }, { "CSMSG_SET_DEFAULT_TOPIC", "$bDefaultTopic$b %s" }, { "CSMSG_SET_TOPICMASK", "$bTopicMask $b %s" }, + { "CSMSG_SET_ADVTOPIC", "$bAdvTopic $b %s" }, { "CSMSG_SET_GREETING", "$bGreeting $b %s" }, { "CSMSG_SET_USERGREETING", "$bUserGreeting$b %s" }, { "CSMSG_SET_MODES", "$bModes $b %s" }, @@ -263,6 +294,7 @@ static const struct message_entry msgtab[] = { { "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" }, @@ -276,6 +308,8 @@ static const struct message_entry msgtab[] = { { "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" }, @@ -310,7 +344,7 @@ static const struct message_entry msgtab[] = { { "CSMSG_INVITING_YOU", "$b%s$b invites you to join %s." }, { "CSMSG_ALREADY_PRESENT", "%s is already in $b%s$b." }, { "CSMSG_YOU_ALREADY_PRESENT", "You are already in $b%s$b." }, - { "CSMSG_LOW_CHANNEL_ACCESS", "You lack sufficient access in %s to use this command." }, + { "CSMSG_LOW_CHANNEL_ACCESS", "You lack sufficient access in %s for $S to invite you." }, { "CSMSG_INFOLINE_TOO_LONG", "Your infoline may not exceed %u characters." }, { "CSMSG_BAD_INFOLINE", "You may not use the character \\%03o in your infoline." }, @@ -323,6 +357,7 @@ static const struct message_entry msgtab[] = { { "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:" }, @@ -365,6 +400,9 @@ static const struct message_entry msgtab[] = { { "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." }, @@ -382,6 +420,7 @@ static const struct message_entry msgtab[] = { { "CSMSG_CHANNEL_MODES", "$bMode Lock: $b%s" }, { "CSMSG_CHANNEL_NOTE", "$b%s:%*s$b%s" }, { "CSMSG_CHANNEL_MAX", "$bRecord Visitors: $b%i" }, + { "CSMSG_CHANNEL_MAX_TIME", "$bRecord Visitors: $b%i (%s ago.)" }, { "CSMSG_CHANNEL_OWNER", "$bOwner: $b%s" }, { "CSMSG_CHANNEL_BANS", "$bBan Count: $b%i" }, { "CSMSG_CHANNEL_USERS", "$bTotal User Count: $b%i" }, @@ -399,10 +438,15 @@ static const struct message_entry msgtab[] = { { "CSMSG_CHANNEL_REGISTERED", "$bRegistered: $b%s ago." }, { "CSMSG_CHANNEL_VISITED", "$bVisited: $b%s ago." }, + { "CSMSG_CHANNEL_OWNERSHIP_HISTORY", "Ownership transfer history for %s" }, + { "CSMSG_CHANNEL_OWNERSHIP_STAFF_REASON", " from %s to %s (%d access) by %s on %s (Reason: %s)" }, + { "CSMSG_CHANNEL_OWNERSHIP_STAFF", " from %s to %s (%d access) by %s on %s" }, + { "CSMSG_CHANNEL_OWNERSHIP_NORMAL", " from %s to %s (%d access) on %s" }, + { "CSMSG_PEEK_INFO", "$b%s$b Status:" }, { "CSMSG_PEEK_TOPIC", "$bTopic: $b%s" }, { "CSMSG_PEEK_MODES", "$bModes: $b%s" }, - { "CSMSG_PEEK_USERS", "$bTotal users: $b%d" }, + { "CSMSG_PEEK_USERS", "$bTotal users: $b%d (%d ops, %d voices, %d regulars)" }, { "CSMSG_PEEK_OPS", "$bOps:$b" }, { "CSMSG_PEEK_NO_OPS", "$bOps: $bNone present" }, @@ -436,7 +480,7 @@ static const struct message_entry msgtab[] = { /* User settings */ { "CSMSG_USER_OPTIONS", "User Options:" }, - { "CSMSG_USER_PROTECTED", "That user is protected." }, + { "CSMSG_USER_PROTECTED_2", "That user is protected." }, /* Toys */ { "CSMSG_UNF_RESPONSE", "I don't want to be part of your sick fantasies!" }, @@ -450,6 +494,32 @@ static const struct message_entry msgtab[] = { { "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", "%i: %s (%i votes)" }, + { "CSMSG_STARTVOTE_TOP", "%s has started a voting:" }, + { "CSMSG_STARTVOTE_QUESTION", "Question: %s" }, + { "CSMSG_STARTVOTE_OPTION", "%i: %s" }, + { "CSMSG_STARTVOTE_ACCESS", "All channel users with at least %i access can vote." }, + { "CSMSG_STARTVOTE_HOWTO", "To vote for an option, use vote ID. To see the available options and the current votes, use vote 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 } @@ -480,6 +550,9 @@ static const struct message_entry msgtab[] = { DECLARE_LIST(dnrList, struct do_not_register *); DEFINE_LIST(dnrList, struct do_not_register *) +#define chanserv_notice(target, format...) send_message(target , chanserv , ## format) +#define chanserv_oper_message(format...) do { if(chanserv_conf.oper_channel) send_channel_message(chanserv_conf.oper_channel , chanserv , ## format); } while(0) + static int eject_user(struct userNode *user, struct chanNode *channel, unsigned int argc, char *argv[], struct svccmd *cmd, int action); struct userNode *chanserv; @@ -496,6 +569,8 @@ static struct unsigned long db_backup_frequency; unsigned long channel_expire_frequency; unsigned long dnr_expire_frequency; + + unsigned long invited_timeout; unsigned long info_delay; unsigned long adjust_delay; @@ -512,7 +587,10 @@ static struct unsigned int max_owned; unsigned int max_chan_users; unsigned int max_chan_bans; + unsigned int min_time_bans; unsigned int max_userinfo_length; + + unsigned int revoke_mode_a; struct string_list *set_shows; struct string_list *eightball; @@ -524,6 +602,12 @@ static struct 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; + + struct chanNode *oper_channel; } chanserv_conf; struct listData @@ -538,6 +622,12 @@ struct listData struct helpfile_table table; }; +struct ChanUser +{ + struct userNode *user; + struct chanNode *chan; +}; + enum note_access_type { NOTE_SET_CHANNEL_ACCESS, @@ -607,7 +697,8 @@ static const struct { { "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 { @@ -654,9 +745,9 @@ struct chanData *channelList; static struct module *chanserv_module; static unsigned int userCount; -#define GetChannelUser(channel, handle) _GetChannelUser(channel, handle, 1, 0) #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) @@ -848,6 +939,15 @@ chanserv_create_note_type(const char *name) 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) { @@ -1015,6 +1115,65 @@ static MODCMD_FUNC(cmd_removenote) { 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) { @@ -1082,6 +1241,7 @@ register_channel(struct chanNode *cNode, char *registrar) struct chanData *channel; enum levelOption lvlOpt; enum charOption chOpt; + int i; channel = calloc(1, sizeof(struct chanData)); @@ -1098,6 +1258,8 @@ register_channel(struct chanNode *cNode, char *registrar) channel->lvlOpts[lvlOpt] = levelOptions[lvlOpt].default_value; for(chOpt = 0; chOpt < NUM_CHAR_OPTIONS; ++chOpt) channel->chOpts[chOpt] = charOptions[chOpt].default_value; + for(i = 0; i < MAXADVTOPICENTRIES; i++) + channel->advtopic[i] = NULL; channel->prev = NULL; channel->next = channelList; @@ -1110,23 +1272,25 @@ register_channel(struct chanNode *cNode, char *registrar) channel->channel = cNode; LockChannel(cNode); cNode->channel_info = channel; + + channel->vote = NULL; return channel; } static struct userData* -add_channel_user(struct chanData *channel, struct handle_info *handle, unsigned short access, unsigned long seen, const char *info) +add_channel_user(struct chanData *channel, struct handle_info *handle, unsigned short access_level, unsigned long seen, const char *info) { struct userData *ud; - if(access > UL_OWNER) + if(access_level > UL_OWNER) return NULL; ud = calloc(1, sizeof(*ud)); ud->channel = channel; ud->handle = handle; ud->seen = seen; - ud->access = access; + ud->access = access_level; ud->info = info ? strdup(info) : NULL; ud->prev = NULL; @@ -1147,8 +1311,6 @@ add_channel_user(struct chanData *channel, struct handle_info *handle, unsigned return ud; } -static void unregister_channel(struct chanData *channel, const char *reason); - void del_channel_user(struct userData *user, int do_gc) { @@ -1173,13 +1335,15 @@ del_channel_user(struct userData *user, int do_gc) free(user->info); free(user); - if(do_gc && !channel->users && !IsProtected(channel)) + if(do_gc && !channel->users && !IsProtected(channel)) { + spamserv_cs_unregister(NULL, channel->channel, lost_all_users, NULL); unregister_channel(channel, "lost all users."); + } } static void expire_ban(void *data); -static struct banData* +struct banData* add_channel_ban(struct chanData *channel, const char *mask, char *owner, unsigned long set, unsigned long triggered, unsigned long expires, char *reason) { struct banData *bd; @@ -1287,6 +1451,7 @@ unregister_channel(struct chanData *channel, const char *reason) { struct mod_chanmode change; char msgbuf[MAXLEN]; + int i; /* After channel unregistration, the following must be cleaned up: @@ -1302,11 +1467,13 @@ unregister_channel(struct chanData *channel, const char *reason) timeq_del(0, NULL, channel, TIMEQ_IGNORE_FUNC | TIMEQ_IGNORE_WHEN); - if(off_channel > 0) - { - mod_chanmode_init(&change); - change.modes_clear |= MODE_REGISTERED; - mod_chanmode_announce(chanserv, channel->channel, &change); + if(off_channel > 0 || chanserv_conf.revoke_mode_a) { + mod_chanmode_init(&change); + if(off_channel > 0) + change.modes_clear |= MODE_REGISTERED; + if(chanserv_conf.revoke_mode_a) + change.modes_clear |= MODE_ACCESS; + mod_chanmode_announce(chanserv, channel->channel, &change); } while(channel->users) @@ -1320,6 +1487,11 @@ unregister_channel(struct chanData *channel, const char *reason) free(channel->greeting); free(channel->user_greeting); free(channel->topic_mask); + + for(i = 0; i < MAXADVTOPICENTRIES; i++) { + if(channel->advtopic[i]) + free(channel->advtopic[i]); + } if(channel->prev) channel->prev->next = channel->next; @@ -1347,20 +1519,21 @@ unregister_channel(struct chanData *channel, const char *reason) 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); - sprintf(msgbuf, "%s %s", channel->channel->name, reason); if(!IsSuspended(channel)) DelChannelUser(chanserv, channel->channel, msgbuf, 0); - global_message(MESSAGE_RECIPIENT_OPERS | MESSAGE_RECIPIENT_HELPERS, msgbuf); + chanserv_oper_message(CSMSGL_CHANNEL_UNREGISTERED, channel->channel->name, reason); UnlockChannel(channel->channel); free(channel); registered_channels--; } static void -expire_channels(UNUSED_ARG(void *data)) +expire_channels(void *data) { struct chanData *channel, *next; struct userData *user; @@ -1380,17 +1553,18 @@ expire_channels(UNUSED_ARG(void *data)) /* Make sure there are no high-ranking users still in the channel. */ for(user=channel->users; user; user=user->next) - if(user->present && (user->access >= UL_PRESENT)) + if(user->present && (user->access >= UL_PRESENT) && !HANDLE_FLAGGED(user->handle, BOT)) break; if(user) continue; /* Unregister the channel */ log_module(CS_LOG, LOG_INFO, "(%s) Channel registration expired.", channel->channel->name); + spamserv_cs_unregister(NULL, channel->channel, expire, NULL); unregister_channel(channel, "registration expired."); } - if(chanserv_conf.channel_expire_frequency) + if(chanserv_conf.channel_expire_frequency && !data) timeq_add(now + chanserv_conf.channel_expire_frequency, expire_channels, NULL); } @@ -2096,14 +2270,14 @@ static CHANSERV_FUNC(cmd_register) /* Initialize the channel's max user record. */ cData->max = channel->members.used; + cData->max_time = 0; if(handle != user->handle_info) reply("CSMSG_PROXY_SUCCESS", handle->handle, channel->name); else reply("CSMSG_REG_SUCCESS", channel->name); - sprintf(reason, "%s registered to %s by %s.", channel->name, handle->handle, user->handle_info->handle); - global_message(MESSAGE_RECIPIENT_OPERS | MESSAGE_RECIPIENT_HELPERS, reason); + chanserv_oper_message(CSMSG_ALERT_REGISTERED, channel->name, handle->handle, user->handle_info->handle); return 1; } @@ -2145,7 +2319,7 @@ static CHANSERV_FUNC(cmd_unregister) return 0; } - if(IsProtected(cData)) + if(IsProtected(cData) && !IsOper(user)) { reply("CSMSG_UNREG_NODELETE", channel->name); return 0; @@ -2170,11 +2344,39 @@ static CHANSERV_FUNC(cmd_unregister) sprintf(reason, "unregistered by %s.", user->handle_info->handle); name = strdup(channel->name); unregister_channel(cData, reason); + spamserv_cs_unregister(user, channel, manually, "unregistered"); reply("CSMSG_UNREG_SUCCESS", name); free(name); return 1; } +static void +ss_cs_join_channel(struct chanNode *channel, int spamserv_join) +{ + extern struct userNode *spamserv; + struct mod_chanmode *change; + + if(spamserv && spamserv_join && get_chanInfo(channel->name)) + { + change = mod_chanmode_alloc(2); + change->argc = 2; + change->args[0].mode = MODE_CHANOP; + change->args[0].u.member = AddChannelUser(chanserv, channel); + change->args[1].mode = MODE_CHANOP; + change->args[1].u.member = AddChannelUser(spamserv, channel); + } + else + { + change = mod_chanmode_alloc(1); + change->argc = 1; + change->args[0].mode = MODE_CHANOP; + change->args[0].u.member = AddChannelUser(chanserv, channel); + } + + mod_chanmode_announce(chanserv, channel, change); + mod_chanmode_free(change); +} + static CHANSERV_FUNC(cmd_move) { struct mod_chanmode change; @@ -2183,6 +2385,7 @@ static CHANSERV_FUNC(cmd_move) struct userData *uData; char reason[MAXLEN]; struct do_not_register *dnr; + int chanserv_join = 0, spamserv_join; REQUIRE_PARAMS(2); @@ -2224,7 +2427,7 @@ static CHANSERV_FUNC(cmd_move) { target = AddChannel(argv[1], now, NULL, NULL); if(!IsSuspended(channel->channel_info)) - AddChannelUser(chanserv, target); + chanserv_join = 1; } else if(target->channel_info) { @@ -2238,12 +2441,7 @@ static CHANSERV_FUNC(cmd_move) return 0; } else if(!IsSuspended(channel->channel_info)) - { - change.argc = 1; - change.args[0].mode = MODE_CHANOP; - change.args[0].u.member = AddChannelUser(chanserv, target); - mod_chanmode_announce(chanserv, target, &change); - } + chanserv_join = 1; if(off_channel > 0) { @@ -2263,7 +2461,14 @@ static CHANSERV_FUNC(cmd_move) target->channel_info->channel = target; channel->channel_info = NULL; - reply("CSMSG_MOVE_SUCCESS", target->name); + /* Check whether users are present in the new channel. */ + for(uData = target->channel_info->users; uData; uData = uData->next) + scan_user_presence(uData, NULL); + + spamserv_join = spamserv_cs_move_merge(user, channel, target, 1); + + if(chanserv_join) + ss_cs_join_channel(target, spamserv_join); sprintf(reason, "%s moved to %s by %s.", channel->name, target->name, user->handle_info->handle); if(!IsSuspended(target->channel_info)) @@ -2275,6 +2480,7 @@ static CHANSERV_FUNC(cmd_move) UnlockChannel(channel); LockChannel(target); global_message(MESSAGE_RECIPIENT_OPERS | MESSAGE_RECIPIENT_HELPERS, reason); + reply("CSMSG_MOVE_SUCCESS", target->name); return 1; } @@ -2313,6 +2519,11 @@ merge_users(struct chanData *source, struct chanData *target) choice = (suData->seen > tuData->seen) ? suData : tuData; else /* Otherwise, keep the higher access level. */ choice = (suData->access > tuData->access) ? suData : tuData; + /* Use the later seen time. */ + if(suData->seen < tuData->seen) + suData->seen = tuData->seen; + else + tuData->seen = suData->seen; /* Remove the user that wasn't picked. */ if(choice == tuData) @@ -2341,6 +2552,9 @@ merge_users(struct chanData *source, struct chanData *target) /* Update the user counts for the target channel; the source counts are left alone. */ target->userCount++; + + /* Check whether the user is in the target channel. */ + scan_user_presence(suData, NULL); } /* Possible to assert (source->users == NULL) here. */ @@ -2447,8 +2661,10 @@ merge_data(struct chanData *source, struct chanData *target) target->ownerTransfer = source->ownerTransfer; if(source->may_opchan) target->may_opchan = 1; - if(source->max > target->max) + if(source->max > target->max) { target->max = source->max; + target->max_time = source->max_time; + } } static void @@ -2508,6 +2724,7 @@ static CHANSERV_FUNC(cmd_merge) /* Merge the channel structures and associated data. */ merge_channel(channel->channel_info, target->channel_info); + spamserv_cs_move_merge(user, channel, target, 0); sprintf(reason, "merged into %s by %s.", target->name, user->handle_info->handle); unregister_channel(channel->channel_info, reason); reply("CSMSG_MERGE_SUCCESS", target->name); @@ -2527,6 +2744,11 @@ static CHANSERV_FUNC(cmd_opchan) change.argc = 1; change.args[0].mode = MODE_CHANOP; change.args[0].u.member = GetUserMode(channel, chanserv); + if(!change.args[0].u.member) + { + reply("CSMSG_OUT_OF_CHANNEL", channel->name); + return 0; + } mod_chanmode_announce(chanserv, channel, &change); reply("CSMSG_OPCHAN_DONE", channel->name); return 1; @@ -2537,7 +2759,7 @@ static CHANSERV_FUNC(cmd_adduser) struct userData *actee; struct userData *actor, *real_actor; struct handle_info *handle; - unsigned short access, override = 0; + unsigned short access_level, override = 0; REQUIRE_PARAMS(3); @@ -2547,8 +2769,8 @@ static CHANSERV_FUNC(cmd_adduser) return 0; } - access = user_level_from_name(argv[2], UL_OWNER); - if(!access) + access_level = user_level_from_name(argv[2], UL_OWNER); + if(!access_level) { reply("CSMSG_INVALID_ACCESS", argv[2]); return 0; @@ -2557,14 +2779,14 @@ static CHANSERV_FUNC(cmd_adduser) actor = GetChannelUser(channel->channel_info, user->handle_info); real_actor = GetChannelAccess(channel->channel_info, user->handle_info); - if(actor->access <= access) + if(actor->access <= access_level) { reply("CSMSG_NO_BUMP_ACCESS"); return 0; } /* Trying to add someone with equal/more access? */ - if (!real_actor || real_actor->access <= access) + if (!real_actor || real_actor->access <= access_level) override = CMD_LOG_OVERRIDE; if(!(handle = modcmd_get_handle_info(user, argv[1]))) @@ -2576,9 +2798,9 @@ static CHANSERV_FUNC(cmd_adduser) return 0; } - actee = add_channel_user(channel->channel_info, handle, access, 0, NULL); + actee = add_channel_user(channel->channel_info, handle, access_level, 0, NULL); scan_user_presence(actee, NULL); - reply("CSMSG_ADDED_USER", handle->handle, channel->name, access); + reply("CSMSG_ADDED_USER", handle->handle, channel->name, access_level); return 1 | override; } @@ -2650,7 +2872,7 @@ static CHANSERV_FUNC(cmd_deluser) struct handle_info *handle; struct userData *victim; struct userData *actor, *real_actor; - unsigned short access, override = 0; + unsigned short access_level, override = 0; char *chan_name; REQUIRE_PARAMS(2); @@ -2669,13 +2891,13 @@ static CHANSERV_FUNC(cmd_deluser) if(argc > 2) { - access = user_level_from_name(argv[1], UL_OWNER); - if(!access) + access_level = user_level_from_name(argv[1], UL_OWNER); + if(!access_level) { reply("CSMSG_INVALID_ACCESS", argv[1]); return 0; } - if(access != victim->access) + if(access_level != victim->access) { reply("CSMSG_INCORRECT_ACCESS", handle->handle, victim->access, argv[1]); return 0; @@ -2683,7 +2905,7 @@ static CHANSERV_FUNC(cmd_deluser) } else { - access = victim->access; + access_level = victim->access; } if((actor->access <= victim->access) && !IsHelping(user)) @@ -2700,7 +2922,7 @@ static CHANSERV_FUNC(cmd_deluser) chan_name = strdup(channel->name); del_channel_user(victim, 1); - reply("CSMSG_DELETED_USER", handle->handle, access, chan_name); + reply("CSMSG_DELETED_USER", handle->handle, access_level, chan_name); free(chan_name); return 1 | override; } @@ -2720,7 +2942,7 @@ cmd_mdel_user(struct userNode *user, struct chanNode *channel, unsigned short mi return 0; } - if((actor->access <= max_access) && !IsHelping(user)) + if(actor->access <= max_access) { reply("CSMSG_NO_ACCESS"); return 0; @@ -2802,7 +3024,7 @@ cmd_trim_users(struct userNode *user, struct chanNode *channel, unsigned short m unsigned int count; unsigned long limit; - actor = GetChannelAccess(channel->channel_info, user->handle_info); + actor = GetChannelUser(channel->channel_info, user->handle_info); if(min_access > max_access) { send_message(user, chanserv, "CSMSG_BAD_RANGE", min_access, max_access); @@ -3048,6 +3270,44 @@ static CHANSERV_FUNC(cmd_devoice) return modify_users(CSFUNC_ARGS, NULL, MODE_REMOVE|MODE_VOICE, "CSMSG_DEVOICED_USERS"); } +static CHANSERV_FUNC(cmd_opme) +{ + struct mod_chanmode change; + const char *errmsg; + + mod_chanmode_init(&change); + change.argc = 1; + change.args[0].u.member = GetUserMode(channel, user); + if(!change.args[0].u.member) + { + if(argc) + reply("MSG_CHANNEL_ABSENT", channel->name); + return 0; + } + + struct devnull_class *devnull; + if(user->handle_info->devnull && (devnull = devnull_get(user->handle_info->devnull)) && (devnull->modes & DEVNULL_MODE_OPME)) + { + change.args[0].mode = MODE_CHANOP; + errmsg = "CSMSG_ALREADY_OPPED"; + } + else + { + if(argc) + reply("CSMSG_NO_ACCESS"); + return 0; + } + change.args[0].mode &= ~change.args[0].u.member->modes; + if(!change.args[0].mode) + { + if(argc) + reply(errmsg, channel->name); + return 0; + } + modcmd_chanmode_announce(&change); + return 1; +} + static int bad_channel_ban(struct chanNode *channel, struct userNode *user, const char *ban, unsigned int *victimCount, struct modeNode **victims) { @@ -3085,6 +3345,20 @@ eject_user(struct userNode *user, struct chanNode *channel, unsigned int argc, c 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); @@ -3132,6 +3406,7 @@ eject_user(struct userNode *user, struct chanNode *channel, unsigned int argc, c else if(!is_ircmask(argv[1]) && (*argv[1] == '*')) { struct handle_info *hi; + extern const char *titlehost_suffix; char banmask[NICKLEN + USERLEN + HOSTLEN + 3]; const char *accountname = argv[1] + 1; @@ -3141,7 +3416,7 @@ eject_user(struct userNode *user, struct chanNode *channel, unsigned int argc, c return 0; } - snprintf(banmask, sizeof(banmask), "*!*@%s.*", hi->handle); + snprintf(banmask, sizeof(banmask), "*!*@%s.*.%s", hi->handle, titlehost_suffix); victims = alloca(sizeof(victims[0]) * channel->members.used); if(bad_channel_ban(channel, user, banmask, &victimCount, victims)) @@ -3208,7 +3483,7 @@ eject_user(struct userNode *user, struct chanNode *channel, unsigned int argc, c { duration = ParseInterval(argv[2]); - if(duration < 15) + if(duration < chanserv_conf.min_time_bans) { reply("CSMSG_DURATION_TOO_LOW"); free(ban); @@ -3420,7 +3695,7 @@ static CHANSERV_FUNC(cmd_addtimedban) 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; @@ -3617,10 +3892,12 @@ static CHANSERV_FUNC(cmd_myaccess) 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; - else if(!IsHelping(user)) + else if(!IsStaff(user)) { reply("CSMSG_MYACCESS_SELF_ONLY", argv[0]); return 0; @@ -3628,6 +3905,9 @@ static CHANSERV_FUNC(cmd_myaccess) else if(!(target_handle = modcmd_get_handle_info(user, argv[1]))) return 0; + if(!oper_outranks(user, target_handle)) + return 0; + if(!target_handle->channels) { reply("CSMSG_SQUAT_ACCESS", target_handle->handle); @@ -3638,17 +3918,22 @@ static CHANSERV_FUNC(cmd_myaccess) for(uData = target_handle->channels; uData; uData = uData->u_next) { struct chanData *cData = uData->channel; + ccount++; + unsigned int base_len; 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)) + && !GetTrueChannelAccess(cData, user->handle_info) + && !IsNetworkHelper(user)) continue; sbuf.used = 0; - string_buffer_append_printf(&sbuf, "[%s (%d", cData->channel->name, uData->access); - if(uData->flags != USER_AUTO_OP) - string_buffer_append(&sbuf, ','); + string_buffer_append_printf(&sbuf, "[%s (%d,", cData->channel->name, uData->access); + base_len = sbuf.used; if(IsUserSuspended(uData)) string_buffer_append(&sbuf, 's'); if(IsUserAutoOp(uData)) @@ -3660,6 +3945,8 @@ static CHANSERV_FUNC(cmd_myaccess) } if(IsUserAutoInvite(uData) && (uData->access >= cData->lvlOpts[lvlInviteMe])) string_buffer_append(&sbuf, 'i'); + if(sbuf.used==base_len) + sbuf.used--; if(uData->info) string_buffer_append_printf(&sbuf, ")] %s", uData->info); else @@ -3668,6 +3955,12 @@ static CHANSERV_FUNC(cmd_myaccess) 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; } @@ -3793,56 +4086,6 @@ static CHANSERV_FUNC(cmd_access) return 1; } -static void -zoot_list(struct listData *list) -{ - struct userData *uData; - unsigned int start, curr, highest, lowest; - struct helpfile_table tmp_table; - const char **temp, *msg; - - if(list->table.length == 1) - { - if(list->search) - send_message(list->user, list->bot, "CSMSG_ACCESS_SEARCH_HEADER", list->channel->name, list->lowest, list->highest, list->search); - else - send_message(list->user, list->bot, "CSMSG_ACCESS_ALL_HEADER", list->channel->name, list->lowest, list->highest); - msg = user_find_message(list->user, "MSG_NONE"); - send_message_type(4, list->user, list->bot, " %s", msg); - } - tmp_table.width = list->table.width; - tmp_table.flags = list->table.flags; - list->table.contents[0][0] = " "; - highest = list->highest; - if(list->lowest != 0) - lowest = list->lowest; - else if(highest < 100) - lowest = 1; - else - lowest = highest - 100; - for(start = curr = 1; curr < list->table.length; ) - { - uData = list->users[curr-1]; - list->table.contents[curr++][0] = " "; - if((curr == list->table.length) || (list->users[curr-1]->access < lowest)) - { - if(list->search) - send_message(list->user, list->bot, "CSMSG_ACCESS_SEARCH_HEADER", list->channel->name, lowest, highest, list->search); - else - send_message(list->user, list->bot, "CSMSG_ACCESS_ALL_HEADER", list->channel->name, lowest, highest); - temp = list->table.contents[--start]; - list->table.contents[start] = list->table.contents[0]; - tmp_table.contents = list->table.contents + start; - tmp_table.length = curr - start; - table_send(list->bot, list->user->nick, 0, NULL, tmp_table); - list->table.contents[start] = temp; - start = curr; - highest = lowest - 1; - lowest = (highest < 100) ? 0 : (highest - 99); - } - } -} - static void def_list(struct listData *list) { @@ -3888,7 +4131,6 @@ cmd_list_users(struct userNode *user, struct chanNode *channel, unsigned int arg lData.highest = highest; lData.search = (argc > 1) ? argv[1] : NULL; send_list = def_list; - (void)zoot_list; /* since it doesn't show user levels */ if(user->handle_info) { @@ -3923,15 +4165,17 @@ cmd_list_users(struct userNode *user, struct chanNode *channel, unsigned int arg ary[3] = "Status"; for(matches = 1; matches < lData.table.length; ++matches) { - struct userData *uData = lData.users[matches-1]; char seen[INTERVALLEN]; + uData = lData.users[matches-1]; ary = malloc(lData.table.width*sizeof(**lData.table.contents)); lData.table.contents[matches] = ary; ary[0] = strtab(uData->access); ary[1] = uData->handle->handle; if(uData->present) ary[2] = "Here"; + else if(HANDLE_FLAGGED(uData->handle, NETWORK)) + ary[2] = "Here"; else if(!uData->seen) ary[2] = "Never"; else @@ -3939,8 +4183,16 @@ cmd_list_users(struct userNode *user, struct chanNode *channel, unsigned int arg ary[2] = strdup(ary[2]); if(IsUserSuspended(uData)) ary[3] = "Suspended"; + else if(HANDLE_FLAGGED(uData->handle, OPER)) + ary[3] = "Operator"; + else if(HANDLE_FLAGGED(uData->handle, HELPING)) + ary[3] = "Staff"; + else if(HANDLE_FLAGGED(uData->handle, NETWORK)) + ary[3] = "Network"; else if(HANDLE_FLAGGED(uData->handle, FROZEN)) ary[3] = "Vacation"; + else if(HANDLE_FLAGGED(uData->handle, BOT)) + ary[3] = "Bot"; else ary[3] = "Normal"; } @@ -3952,6 +4204,7 @@ cmd_list_users(struct userNode *user, struct chanNode *channel, unsigned int arg } free(lData.table.contents[0]); free(lData.table.contents); + reply("CSMSG_TOTAL_USERS",(lData.table.length - 1),channel->name); return 1; } @@ -4097,8 +4350,34 @@ bad_topic(struct chanNode *channel, struct userNode *user, const char *new_topic struct chanData *cData = channel->channel_info; if(check_user_level(channel, user, lvlEnfTopic, 1, 0)) return 0; - if(cData->topic_mask) - return !match_ircglob(new_topic, cData->topic_mask); + if(cData->topic_mask) + { + if(cData->flags & CHANNEL_ADVTOPIC) + { + //this implementation is a little bit dirty but i haven't found a better, faster solution, yet... + char topicmask[TOPICLEN]; + int skipnum, topicpos = 0; + char *ptr = cData->topic_mask; + for(;*ptr;ptr++) { //replace all the %[0-9]* variables with * + switch(*ptr) { + case '%': + for(skipnum = 0; isdigit(ptr[1]) && skipnum < 3; ptr++, skipnum++) {} //skip up to 3 numbers + if(skipnum) + topicmask[topicpos++] = '*'; + else + topicmask[topicpos++] = *ptr; + break; + default: + topicmask[topicpos++] = *ptr; + break; + } + } + topicmask[topicpos] = 0; + return !match_ircglob(new_topic, topicmask); + } + else + return !match_ircglob(new_topic, cData->topic_mask); + } else if(cData->topic) return irccasecmp(new_topic, cData->topic); else @@ -4136,30 +4415,96 @@ static CHANSERV_FUNC(cmd_topic) char new_topic[TOPICLEN+1], tchar; int pos=0, starpos=-1, dpos=0, len; - while((tchar = topic_mask[pos++]) && (dpos <= TOPICLEN)) + if(cData->flags & CHANNEL_ADVTOPIC) { - switch(tchar) + //first check if there is a leading 'modifier id' + int advtopic_index = 0; + char numbuf[4]; + int numpos; + for(; topic[pos]; pos++) { - case '*': - if(starpos != -1) - goto bad_mask; - len = strlen(topic); - if((dpos + len) > TOPICLEN) - len = TOPICLEN + 1 - dpos; - memcpy(new_topic+dpos, topic, len); - dpos += len; - starpos = pos; - break; - case '\\': tchar = topic_mask[pos++]; /* and fall through */ - default: new_topic[dpos++] = tchar; break; + if(topic[pos] == ' ') + { + //leading number found, cut off and store value in advtopic_index + topic[pos] = 0; + advtopic_index = atoi(topic) - 1; //no zerobase + topic = &topic[pos+1]; + /* If they say "!topic 2 *", unset advtopic id 2. */ + if((topic[0] == '*') && (topic[1] == 0)) + topic[0] = 0; + } + if(!isdigit(topic[pos])) + break; + } + if(advtopic_index < 0 || advtopic_index >= MAXADVTOPICENTRIES) + { + //invalid id! + reply("CSMSG_ADVTOPIC_INVALID_ID", advtopic_index+1); + return 0; + } + if(cData->advtopic[advtopic_index]) + free(cData->advtopic[advtopic_index]); + cData->advtopic[advtopic_index] = (topic[0] ? strdup(topic) : NULL); + char *ptr = topic_mask; + while(*ptr && (dpos <= TOPICLEN)) + { + switch(*ptr) + { + case '%': + ptr++; + for(numpos = 0; isdigit(*ptr) && numpos < 3; ptr++) { + numbuf[numpos++] = *ptr; + } + numbuf[numpos] = 0; + if(!numpos || (advtopic_index = atoi(numbuf)) <= 0 || advtopic_index > MAXADVTOPICENTRIES) { + ptr -= numpos+1; + new_topic[dpos++] = *ptr; //is % again + break; + } + advtopic_index--; //no zero base + if(!cData->advtopic[advtopic_index]) + break; //just leave it empty + len = strlen(cData->advtopic[advtopic_index]); + if((dpos + len) > TOPICLEN) + len = TOPICLEN + 1 - dpos; + memcpy(new_topic+dpos, cData->advtopic[advtopic_index], len); + dpos += len; + break; + case '\\': + ptr++; /* and fall through */ + if(!*ptr) break; + default: + new_topic[dpos++] = *ptr; + ptr++; + break; + } + } + } else { + while((tchar = topic_mask[pos++]) && (dpos <= TOPICLEN)) + { + switch(tchar) + { + case '*': + if(starpos != -1) + goto bad_mask; + len = strlen(topic); + if((dpos + len) > TOPICLEN) + len = TOPICLEN + 1 - dpos; + memcpy(new_topic+dpos, topic, len); + dpos += len; + starpos = pos; + break; + case '\\': tchar = topic_mask[pos++]; /* and fall through */ + default: new_topic[dpos++] = tchar; break; + } + } + if((dpos > TOPICLEN) || tchar) + { + bad_mask: + reply("CSMSG_TOPICMASK_CONFLICT1", channel->name, topic_mask); + reply("CSMSG_TOPICMASK_CONFLICT2", TOPICLEN); + return 0; } - } - if((dpos > TOPICLEN) || tchar) - { - bad_mask: - reply("CSMSG_TOPICMASK_CONFLICT1", channel->name, topic_mask); - reply("CSMSG_TOPICMASK_CONFLICT2", TOPICLEN); - return 0; } new_topic[dpos] = 0; SetChannelTopic(channel, chanserv, new_topic, 1); @@ -4186,6 +4531,7 @@ static CHANSERV_FUNC(cmd_mode) struct userData *uData; struct mod_chanmode *change; short base_oplevel; + char fmt[MAXLEN]; if(argc < 2) { @@ -4205,7 +4551,7 @@ static CHANSERV_FUNC(cmd_mode) 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, 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)); @@ -4222,17 +4568,33 @@ static CHANSERV_FUNC(cmd_mode) } modcmd_chanmode_announce(change); + mod_chanmode_format(change, fmt); mod_chanmode_free(change); - reply("CSMSG_MODES_SET", unsplit_string(argv+1, argc-1, NULL)); + reply("CSMSG_MODES_SET", fmt); return 1; } +static void +chanserv_del_invite_mark(void *data) +{ + struct ChanUser *chanuser = data; + struct chanNode *channel = chanuser->chan; + unsigned int i; + if(!channel) return; + for(i = 0; i < channel->invited.used; i++) + { + if(channel->invited.list[i] == chanuser->user) { + userList_remove(&channel->invited, chanuser->user); + } + } + free(chanuser); +} + static CHANSERV_FUNC(cmd_invite) { - struct userData *uData; struct userNode *invite; - - uData = GetChannelUser(channel->channel_info, user->handle_info); + struct ChanUser *chanuser; + unsigned int i; if(argc > 1) { @@ -4250,6 +4612,14 @@ static CHANSERV_FUNC(cmd_invite) reply("CSMSG_ALREADY_PRESENT", invite->nick, channel->name); return 0; } + + for(i = 0; i < channel->invited.used; i++) + { + if(channel->invited.list[i] == invite) { + reply("CSMSG_ALREADY_INVITED", invite->nick, channel->name); + return 0; + } + } if(user != invite) { @@ -4265,6 +4635,12 @@ static CHANSERV_FUNC(cmd_invite) if(argc > 1) reply("CSMSG_INVITED_USER", argv[1], channel->name); + userList_append(&channel->invited, invite); + chanuser = calloc(1, sizeof(*chanuser)); + chanuser->user=invite; + chanuser->chan=channel; + timeq_add(now + chanserv_conf.invited_timeout, chanserv_del_invite_mark, chanuser); + return 1; } @@ -4285,6 +4661,28 @@ static CHANSERV_FUNC(cmd_inviteme) 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) { @@ -4340,6 +4738,30 @@ show_suspension_info(struct svccmd *cmd, struct userNode *user, struct suspended } } +static void +show_giveownership_info(struct svccmd *cmd, struct userNode *user, struct giveownership *giveownership) +{ + char buf[MAXLEN]; + const char *fmt = "%a %b %d %H:%M %Y"; + strftime(buf, sizeof(buf), fmt, localtime(&giveownership->issued)); + + if(giveownership->staff_issuer) + { + if(giveownership->reason) + reply("CSMSG_CHANNEL_OWNERSHIP_STAFF_REASON", giveownership->old_owner, + giveownership->target, giveownership->target_access, + giveownership->staff_issuer, buf, giveownership->reason); + else + reply("CSMSG_CHANNEL_OWNERSHIP_STAFF", giveownership->old_owner, + giveownership->target, giveownership->target_access, + giveownership->staff_issuer, buf); + } + else + { + reply("CSMSG_CHANNEL_OWNERSHIP_NORMAL", giveownership->old_owner, giveownership->target, giveownership->target_access, buf); + } +} + static CHANSERV_FUNC(cmd_info) { char modes[MAXLEN], buffer[INTERVALLEN]; @@ -4373,7 +4795,11 @@ static CHANSERV_FUNC(cmd_info) reply("CSMSG_CHANNEL_NOTE", iter_key(it), padding > 0 ? padding : 1, "", note->note); } - reply("CSMSG_CHANNEL_MAX", cData->max); + if(cData->max_time) { + reply("CSMSG_CHANNEL_MAX_TIME", cData->max, intervalString(buffer, now - cData->max_time, user->handle_info)); + } else { + reply("CSMSG_CHANNEL_MAX", cData->max); + } for(owner = cData->users; owner; owner = owner->next) if(owner->access == UL_OWNER) reply("CSMSG_CHANNEL_OWNER", owner->handle->handle); @@ -4402,6 +4828,14 @@ static CHANSERV_FUNC(cmd_info) reply("CSMSG_CHANNEL_SUSPENDED", channel->name); show_suspension_info(cmd, user, cData->suspended); } + + if(cData->giveownership && ((uData && (uData->access >= UL_COOWNER)) || IsStaff(user))) + { + struct giveownership *giveownership; + reply("CSMSG_CHANNEL_OWNERSHIP_HISTORY", channel->name); + for(giveownership = cData->giveownership; giveownership; giveownership = giveownership->previous) + show_giveownership_info(cmd, user, giveownership); + } return 1; } @@ -4442,6 +4876,8 @@ send_staff_list(struct userNode *to, struct userList *list, int skip_flags) continue; if(IsBot(user)) continue; + if(IsInvi(user)) + continue; table.contents[table.length] = alloca(table.width*sizeof(**table.contents)); if(IsAway(user)) { @@ -4484,13 +4920,13 @@ static CHANSERV_FUNC(cmd_peek) char modes[MODELEN]; unsigned int n; struct helpfile_table table; + int opcount = 0, voicecount = 0, srvcount = 0; irc_make_chanmode(channel, modes); reply("CSMSG_PEEK_INFO", channel->name); reply("CSMSG_PEEK_TOPIC", channel->topic); reply("CSMSG_PEEK_MODES", modes); - reply("CSMSG_PEEK_USERS", channel->members.used); table.length = 0; table.width = 1; @@ -4499,12 +4935,23 @@ static CHANSERV_FUNC(cmd_peek) for(n = 0; n < channel->members.used; n++) { mn = channel->members.list[n]; + if(IsLocal(mn->user)) + srvcount++; + else if(mn->modes & MODE_CHANOP) + opcount++; + else if(mn->modes & MODE_VOICE) + voicecount++; + if(!(mn->modes & MODE_CHANOP) || IsLocal(mn->user)) continue; table.contents[table.length] = alloca(sizeof(**table.contents)); table.contents[table.length][0] = mn->user->nick; table.length++; } + + reply("CSMSG_PEEK_USERS", channel->members.used, opcount, voicecount, + (channel->members.used - opcount - voicecount - srvcount)); + if(table.length) { reply("CSMSG_PEEK_OPS"); @@ -4566,8 +5013,16 @@ static CHANSERV_FUNC(cmd_resync) { 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] @@ -4578,7 +5033,7 @@ static CHANSERV_FUNC(cmd_resync) 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; @@ -4922,7 +5377,7 @@ chanserv_support_channels(void) static CHANSERV_FUNC(cmd_expire) { int channel_count = registered_channels; - expire_channels(NULL); + expire_channels(chanserv); reply("CSMSG_CHANNELS_EXPIRED", channel_count - registered_channels); return 1; } @@ -4932,20 +5387,31 @@ chanserv_expire_suspension(void *data) { struct suspended *suspended = data; struct chanNode *channel; + unsigned int ii; + /* Update the channel registration data structure. */ if(!suspended->expires || (now < suspended->expires)) suspended->revoked = now; channel = suspended->cData->channel; suspended->cData->channel = channel; suspended->cData->flags &= ~CHANNEL_SUSPENDED; + + /* If appropriate, re-join ChanServ to the channel. */ if(!IsOffChannel(suspended->cData)) { - struct mod_chanmode change; - mod_chanmode_init(&change); - change.argc = 1; - change.args[0].mode = MODE_CHANOP; - change.args[0].u.member = AddChannelUser(chanserv, channel); - mod_chanmode_announce(chanserv, channel, &change); + spamserv_cs_suspend(channel, 0, 0, NULL); + ss_cs_join_channel(channel, 1); + } + + /* Mark everyone currently in the channel as present. */ + for(ii = 0; ii < channel->members.used; ++ii) + { + struct userData *uData = GetChannelAccess(suspended->cData, channel->members.list[ii]->user->handle_info); + if(uData) + { + uData->present = 1; + uData->seen = now; + } } } @@ -5020,6 +5486,7 @@ static CHANSERV_FUNC(cmd_csuspend) /* Mark the channel as suspended, then part. */ channel->channel_info->flags |= CHANNEL_SUSPENDED; + spamserv_cs_suspend(channel, expiry, 1, suspended->reason); DelChannelUser(chanserv, channel, suspended->reason, 0); reply("CSMSG_SUSPENDED", channel->name); sprintf(reason, "%s suspended by %s.", channel->name, suspended->suspender); @@ -5356,7 +5823,7 @@ static MODCMD_FUNC(chan_opt_usergreeting) static MODCMD_FUNC(chan_opt_modes) { struct mod_chanmode *new_modes; - char modes[MODELEN]; + char modes[MAXLEN]; if(argc > 1) { @@ -5369,7 +5836,7 @@ static MODCMD_FUNC(chan_opt_modes) { 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, 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; @@ -5451,6 +5918,11 @@ static MODCMD_FUNC(chan_opt_dynlimit) CHANNEL_BINARY_OPTION("CSMSG_SET_DYNLIMIT", CHANNEL_DYNAMIC_LIMIT); } +static MODCMD_FUNC(chan_opt_advtopic) +{ + CHANNEL_BINARY_OPTION("CSMSG_SET_ADVTOPIC", CHANNEL_ADVTOPIC); +} + static MODCMD_FUNC(chan_opt_offchannel) { struct chanData *cData = channel->channel_info; @@ -5697,6 +6169,11 @@ static MODCMD_FUNC(chan_opt_topicsnarf) 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); @@ -5706,31 +6183,31 @@ static int channel_multiple_option(enum charOption option, struct userNode *user, struct chanNode *channel, int argc, char *argv[], struct svccmd *cmd) { struct chanData *cData = channel->channel_info; - int count = charOptions[option].count, index; + int count = charOptions[option].count, idx; if(argc > 1) { - index = atoi(argv[1]); + idx = atoi(argv[1]); - if(!isdigit(argv[1][0]) || (index < 0) || (index >= count)) + if(!isdigit(argv[1][0]) || (idx < 0) || (idx >= count)) { - reply("CSMSG_INVALID_NUMERIC", index); + reply("CSMSG_INVALID_NUMERIC", idx); /* Show possible values. */ - for(index = 0; index < count; index++) - reply(charOptions[option].format_name, index, user_find_message(user, charOptions[option].values[index].format_name)); + for(idx = 0; idx < count; idx++) + reply(charOptions[option].format_name, idx, user_find_message(user, charOptions[option].values[idx].format_name)); return 0; } - cData->chOpts[option] = charOptions[option].values[index].value; + cData->chOpts[option] = charOptions[option].values[idx].value; } else { /* Find current option value. */ find_value: - for(index = 0; - (index < count) && (cData->chOpts[option] != charOptions[option].values[index].value); - index++); - if(index == count) + for(idx = 0; + (idx < count) && (cData->chOpts[option] != charOptions[option].values[idx].value); + idx++); + if(idx == count) { /* Somehow, the option value is corrupt; reset it to the default. */ cData->chOpts[option] = charOptions[option].default_value; @@ -5738,7 +6215,7 @@ channel_multiple_option(enum charOption option, struct userNode *user, struct ch } } - reply(charOptions[option].format_name, index, user_find_message(user, charOptions[option].values[index].format_name)); + reply(charOptions[option].format_name, idx, user_find_message(user, charOptions[option].values[idx].format_name)); return 1; } @@ -5881,6 +6358,10 @@ static MODCMD_FUNC(user_opt_noautoop) static MODCMD_FUNC(user_opt_autoinvite) { + if((argc > 1) && !check_user_level(channel, user, lvlInviteMe, 1, 0)) + { + reply("CSMSG_LOW_CHANNEL_ACCESS", channel->name); + } return user_binary_option("CSMSG_USET_AUTOINVITE", USER_AUTO_INVITE, CSFUNC_ARGS); } @@ -5993,13 +6474,21 @@ static CHANSERV_FUNC(cmd_giveownership) struct chanData *cData = channel->channel_info; struct do_not_register *dnr; const char *confirm; - unsigned int force; - unsigned short co_access; - char reason[MAXLEN]; + struct giveownership *giveownership; + unsigned int force, override; + unsigned short co_access, new_owner_old_access; + char reason[MAXLEN], transfer_reason[MAXLEN]; REQUIRE_PARAMS(2); curr_user = GetChannelAccess(cData, user->handle_info); force = IsHelping(user) && (argc > 2) && !irccasecmp(argv[2], "force"); + + struct userData *uData = _GetChannelUser(channel->channel_info, user->handle_info, 1, 0); + override = ((cmd->effective_flags & MODCMD_REQUIRE_CHANUSER) + && (uData->access > 500) + && (!(uData = _GetChannelUser(channel->channel_info, user->handle_info, 0, 0)) + || uData->access < 500)); + if(!curr_user || (curr_user->access != UL_OWNER)) { struct userData *owner = NULL; @@ -6067,6 +6556,7 @@ static CHANSERV_FUNC(cmd_giveownership) return 0; } } + new_owner_old_access = new_owner->access; if(new_owner->access >= UL_COOWNER) co_access = new_owner->access; else @@ -6075,28 +6565,55 @@ static CHANSERV_FUNC(cmd_giveownership) if(curr_user) curr_user->access = co_access; cData->ownerTransfer = now; - reply("CSMSG_OWNERSHIP_GIVEN", channel->name, new_owner_hi->handle); + giveownership = calloc(1, sizeof(*giveownership)); + giveownership->issued = now; + giveownership->old_owner = curr_user->handle->handle; + giveownership->target = new_owner_hi->handle; + giveownership->target_access = new_owner_old_access; + if(override) + { + if(argc > (2 + force)) + { + unsplit_string(argv + 2 + force, argc - 2 - force, transfer_reason); + giveownership->reason = strdup(transfer_reason); + } + giveownership->staff_issuer = strdup(user->handle_info->handle); + } + + giveownership->previous = channel->channel_info->giveownership; + channel->channel_info->giveownership = giveownership; + reply("CSMSG_OWNERSHIP_GIVEN", channel->name, new_owner_hi->handle); sprintf(reason, "%s ownership transferred to %s by %s.", channel->name, new_owner_hi->handle, user->handle_info->handle); global_message(MESSAGE_RECIPIENT_OPERS | MESSAGE_RECIPIENT_HELPERS, reason); return 1; } +static void +chanserv_expire_user_suspension(void *data) +{ + struct userData *target = data; + + target->expires = 0; + target->flags &= ~USER_SUSPENDED; +} + static CHANSERV_FUNC(cmd_suspend) { struct handle_info *hi; - struct userData *self, *real_self, *target; + struct userData *actor, *real_actor, *target; unsigned int override = 0; + time_t expiry; - REQUIRE_PARAMS(2); + REQUIRE_PARAMS(3); if(!(hi = modcmd_get_handle_info(user, argv[1]))) return 0; - self = GetChannelUser(channel->channel_info, user->handle_info); - real_self = GetChannelAccess(channel->channel_info, user->handle_info); + actor = GetChannelUser(channel->channel_info, user->handle_info); + real_actor = GetChannelAccess(channel->channel_info, user->handle_info); if(!(target = GetTrueChannelAccess(channel->channel_info, hi))) { reply("CSMSG_NO_CHAN_USER", hi->handle, channel->name); return 0; } - if(target->access >= self->access) + if(target->access >= actor->access) { reply("MSG_USER_OUTRANKED", hi->handle); return 0; @@ -6111,8 +6628,26 @@ static CHANSERV_FUNC(cmd_suspend) target->present = 0; target->seen = now; } - if(!real_self || target->access >= real_self->access) + if(!real_actor || target->access >= real_actor->access) override = CMD_LOG_OVERRIDE; + if(!strcmp(argv[2], "0")) + expiry = 0; + else + { + unsigned int duration; + if(!(duration = ParseInterval(argv[2]))) + { + reply("MSG_INVALID_DURATION", argv[2]); + return 0; + } + expiry = now + duration; + } + + target->expires = expiry; + + if(target->expires) + timeq_add(target->expires, chanserv_expire_user_suspension, target); + target->flags |= USER_SUSPENDED; reply("CSMSG_USER_SUSPENDED", hi->handle, channel->name); return 1 | override; @@ -6121,19 +6656,19 @@ static CHANSERV_FUNC(cmd_suspend) static CHANSERV_FUNC(cmd_unsuspend) { struct handle_info *hi; - struct userData *self, *real_self, *target; + struct userData *actor, *real_actor, *target; unsigned int override = 0; REQUIRE_PARAMS(2); if(!(hi = modcmd_get_handle_info(user, argv[1]))) return 0; - self = GetChannelUser(channel->channel_info, user->handle_info); - real_self = GetChannelAccess(channel->channel_info, user->handle_info); + actor = GetChannelUser(channel->channel_info, user->handle_info); + real_actor = GetChannelAccess(channel->channel_info, user->handle_info); if(!(target = GetTrueChannelAccess(channel->channel_info, hi))) { reply("CSMSG_NO_CHAN_USER", hi->handle, channel->name); return 0; } - if(target->access >= self->access) + if(target->access >= actor->access) { reply("MSG_USER_OUTRANKED", hi->handle); return 0; @@ -6143,8 +6678,9 @@ static CHANSERV_FUNC(cmd_unsuspend) reply("CSMSG_NOT_SUSPENDED", hi->handle); return 0; } - if(!real_self || target->access >= real_self->access) + if(!real_actor || target->access >= real_actor->access) override = CMD_LOG_OVERRIDE; + timeq_del(target->expires, chanserv_expire_user_suspension, target, 0); target->flags &= ~USER_SUSPENDED; scan_user_presence(target, NULL); reply("CSMSG_USER_UNSUSPENDED", hi->handle, channel->name); @@ -6156,7 +6692,7 @@ static MODCMD_FUNC(cmd_deleteme) struct handle_info *hi; struct userData *target; const char *confirm_string; - unsigned short access; + unsigned short access_level; char *channel_name; hi = user->handle_info; @@ -6176,18 +6712,375 @@ static MODCMD_FUNC(cmd_deleteme) reply("CSMSG_CONFIRM_DELETEME", confirm_string); return 0; } - access = target->access; + access_level = target->access; channel_name = strdup(channel->name); del_channel_user(target, 1); - reply("CSMSG_DELETED_YOU", access, channel_name); + reply("CSMSG_DELETED_YOU", access_level, channel_name); free(channel_name); 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)) { - unsigned int refresh_num = (now - self->link) / chanserv_conf.refresh_period; + unsigned int refresh_num = (now - self->link_time) / chanserv_conf.refresh_period; struct chanData *cData; char opt; @@ -6384,6 +7277,16 @@ handle_new_channel(struct chanNode *channel) 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 @@ -6398,13 +7301,23 @@ handle_join(struct modeNode *mNode) 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; cData = channel->channel_info; - if(channel->members.used > cData->max) + if(channel->members.used > cData->max) { cData->max = channel->members.used; + cData->max_time = now; + } + + for(i = 0; i < channel->invited.used; i++) + { + if(channel->invited.list[i] == user) { + userList_remove(&channel->invited, user); + } + } /* Check for bans. If they're joining through a ban, one of two * cases applies: @@ -6469,11 +7382,9 @@ handle_join(struct modeNode *mNode) } } - /* ChanServ will not modify the limits in join-flooded channels. - It will also skip DynLimit processing when the user (or srvx) - is bursting in, because there are likely more incoming. */ + /* ChanServ will not modify the limits in join-flooded channels, + or when there are enough slots left below the limit. */ if((cData->flags & CHANNEL_DYNAMIC_LIMIT) - && !user->uplink->burst && !channel->join_flooded && (channel->limit - channel->members.used) < chanserv_conf.adjust_threshold) { @@ -6524,7 +7435,7 @@ handle_join(struct modeNode *mNode) else if(uData->access >= cData->lvlOpts[lvlGiveVoice]) modes |= MODE_VOICE; } - if(uData->access >= UL_PRESENT) + if(uData->access >= UL_PRESENT && !HANDLE_FLAGGED(uData->handle, BOT)) cData->visited = now; if(cData->user_greeting) greeting = cData->user_greeting; @@ -6553,7 +7464,7 @@ handle_join(struct modeNode *mNode) } if(greeting) send_message_type(4, user, chanserv, "(%s) %s", channel->name, greeting); - if(uData && info) + if(uData && info && (modes || !(channel->modes & MODE_DELAYJOINS))) send_target_message(5, channel->name, chanserv, "[%s] %s", user->nick, uData->info); } return 0; @@ -6592,7 +7503,7 @@ handle_auth(struct userNode *user, UNUSED_ARG(struct handle_info *old_handle)) continue; } - if(channel->access >= UL_PRESENT) + if(channel->access >= UL_PRESENT && !HANDLE_FLAGGED(channel->handle, BOT)) channel->channel->visited = now; if(IsUserAutoOp(channel)) @@ -6614,28 +7525,28 @@ handle_auth(struct userNode *user, UNUSED_ARG(struct handle_info *old_handle)) for(ii = 0; ii < user->channels.used; ++ii) { - struct chanNode *channel = user->channels.list[ii]->channel; + struct chanNode *chan = user->channels.list[ii]->channel; struct banData *ban; if((user->channels.list[ii]->modes & (MODE_CHANOP|MODE_VOICE)) - || !channel->channel_info - || IsSuspended(channel->channel_info)) + || !chan->channel_info + || IsSuspended(chan->channel_info)) continue; - for(jj = 0; jj < channel->banlist.used; ++jj) - if(user_matches_glob(user, channel->banlist.list[jj]->ban, MATCH_USENICK)) + for(jj = 0; jj < chan->banlist.used; ++jj) + if(user_matches_glob(user, chan->banlist.list[jj]->ban, MATCH_USENICK)) break; - if(jj < channel->banlist.used) + if(jj < chan->banlist.used) continue; - for(ban = channel->channel_info->bans; ban; ban = ban->next) + for(ban = chan->channel_info->bans; ban; ban = ban->next) { char kick_reason[MAXLEN]; if(!user_matches_glob(user, ban->mask, MATCH_USENICK | MATCH_VISIBLE)) continue; change.args[0].mode = MODE_BAN; change.args[0].u.hostmask = ban->mask; - mod_chanmode_announce(chanserv, channel, &change); + mod_chanmode_announce(chanserv, chan, &change); sprintf(kick_reason, "(%s) %s", ban->owner, ban->reason); - KickChannelUser(user, channel, chanserv, kick_reason); + KickChannelUser(user, chan, chanserv, kick_reason); ban->triggered = now; break; } @@ -6679,19 +7590,23 @@ handle_part(struct modeNode *mn, UNUSED_ARG(const char *reason)) { scan_user_presence(uData, mn->user); uData->seen = now; - if (uData->access >= UL_PRESENT) + if (uData->access >= UL_PRESENT && !HANDLE_FLAGGED(uData->handle, BOT)) cData->visited = now; } if(IsHelping(mn->user) && IsSupportHelper(mn->user)) { - unsigned int ii, jj; - for(ii = 0; ii < chanserv_conf.support_channels.used; ++ii) - { - for(jj = 0; jj < mn->user->channels.used; ++jj) - if(mn->user->channels.list[jj]->channel == chanserv_conf.support_channels.list[ii]) - break; - if(jj < mn->user->channels.used) + unsigned int ii; + for(ii = 0; ii < chanserv_conf.support_channels.used; ++ii) { + struct chanNode *channel; + struct userNode *exclude; + /* When looking at the channel that is being /part'ed, we + * have to skip over the client that is leaving. For + * other channels, we must not do that. + */ + channel = chanserv_conf.support_channels.list[ii]; + exclude = (channel == mn->channel) ? mn->user : NULL; + if(find_handle_in_channel(channel, mn->user->handle_info, exclude)) break; } if(ii == chanserv_conf.support_channels.used) @@ -6711,7 +7626,7 @@ handle_kick(struct userNode *kicker, struct userNode *victim, struct chanNode *c if(protect_user(victim, kicker, channel->channel_info)) { - const char *reason = user_find_message(kicker, "CSMSG_USER_PROTECTED"); + const char *reason = user_find_message(kicker, "CSMSG_USER_PROTECTED_2"); KickChannelUser(kicker, channel, chanserv, reason); } @@ -6968,12 +7883,18 @@ chanserv_conf_read(void) chanserv_conf.channel_expire_delay = str ? ParseInterval(str) : 86400*30; str = database_get_data(conf_node, KEY_DNR_EXPIRE_FREQ, RECDB_QSTRING); chanserv_conf.dnr_expire_frequency = str ? ParseInterval(str) : 3600; + str = database_get_data(conf_node, KEY_INVITED_INTERVAL, RECDB_QSTRING); + chanserv_conf.invited_timeout = str ? ParseInterval(str) : 600*2; + str = database_get_data(conf_node, KEY_REVOKE_MODE_A, RECDB_QSTRING); + chanserv_conf.revoke_mode_a = str ? atoi(str) : 1; str = database_get_data(conf_node, KEY_NODELETE_LEVEL, RECDB_QSTRING); chanserv_conf.nodelete_level = str ? atoi(str) : 1; str = database_get_data(conf_node, KEY_MAX_CHAN_USERS, RECDB_QSTRING); chanserv_conf.max_chan_users = str ? atoi(str) : 512; str = database_get_data(conf_node, KEY_MAX_CHAN_BANS, RECDB_QSTRING); chanserv_conf.max_chan_bans = str ? atoi(str) : 512; + str = database_get_data(conf_node, KEY_MIN_TIME_BANS, RECDB_QSTRING); + chanserv_conf.min_time_bans = str ? atoi(str) : 5; str = database_get_data(conf_node, KEY_MAX_USERINFO_LENGTH, RECDB_QSTRING); chanserv_conf.max_userinfo_length = str ? atoi(str) : 400; str = database_get_data(conf_node, KEY_NICK, RECDB_QSTRING); @@ -6995,12 +7916,18 @@ chanserv_conf_read(void) 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) ? str : NULL; + str = database_get_data(conf_node, KEY_NEW_CHANNEL_UNAUTHED, RECDB_QSTRING); + chanserv_conf.new_channel_unauthed = (str && *str) ? str : NULL; + str = database_get_data(conf_node, KEY_NEW_CHANNEL_MSG, RECDB_QSTRING); + chanserv_conf.new_channel_msg = (str && *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, 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; @@ -7021,11 +7948,10 @@ chanserv_conf_read(void) /* multiple choice options */ "CtcpReaction", "Protect", "Toys", "TopicRefresh", /* binary options */ - "DynLimit", "NoDelete", + "DynLimit", "NoDelete", "expire", "Vote", /* 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])); @@ -7059,6 +7985,16 @@ chanserv_conf_read(void) chanserv_conf.old_ban_names = strlist; str = database_get_data(conf_node, "off_channel", RECDB_QSTRING); off_channel = str ? atoi(str) : 0; + + str = database_get_data(conf_node, "oper_chan", RECDB_QSTRING); + if(str) + { + chanserv_conf.oper_channel = AddChannel(str, now, "+tinms", NULL); + } + else + { + chanserv_conf.oper_channel = NULL; + } } static void @@ -7117,14 +8053,35 @@ chanserv_note_type_read(const char *key, struct record_data *rd) 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, *expires; unsigned long last_seen; - unsigned short access; + unsigned short access_level; if(rd->type != RECDB_OBJECT || !dict_size(rd->d.object)) { @@ -7132,8 +8089,8 @@ user_read_helper(const char *key, struct record_data *rd, struct chanData *chan) return; } - access = atoi(database_get_data(rd->d.object, KEY_LEVEL, RECDB_QSTRING)); - if(access > UL_OWNER) + access_level = atoi(database_get_data(rd->d.object, KEY_LEVEL, RECDB_QSTRING)); + if(access_level > UL_OWNER) { log_module(CS_LOG, LOG_ERROR, "Invalid access level for %s in %s.", key, chan->channel->name); return; @@ -7143,6 +8100,9 @@ user_read_helper(const char *key, struct record_data *rd, struct chanData *chan) 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); + expires = database_get_data(rd->d.object, KEY_EXPIRES, 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) { @@ -7150,14 +8110,29 @@ user_read_helper(const char *key, struct record_data *rd, struct chanData *chan) return; } - uData = add_channel_user(chan, handle, access, last_seen, inf); + uData = add_channel_user(chan, handle, access_level, last_seen, inf); uData->flags = flags ? strtoul(flags, NULL, 0) : 0; + uData->expires = expires ? (signed)strtoul(expires, NULL, 0) : 0; + + if((uData->flags & USER_SUSPENDED) && uData->expires) + { + if(uData->expires > now) + timeq_add(uData->expires, chanserv_expire_user_suspension, uData); + else + uData->flags &= ~USER_SUSPENDED; + } + 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 ban_read_helper(const char *key, struct record_data *rd, struct chanData *chan) { - struct banData *bData; char *set, *triggered, *s_duration, *s_expires, *reason, *owner; unsigned long set_time, triggered_time, expires_time; @@ -7188,7 +8163,7 @@ ban_read_helper(const char *key, struct record_data *rd, struct chanData *chan) if(!reason || (expires_time && (expires_time < now))) return; - bData = add_channel_ban(chan, key, owner, set_time, triggered_time, expires_time, reason); + add_channel_ban(chan, key, owner, set_time, triggered_time, expires_time, reason); } static struct suspended * @@ -7211,10 +8186,36 @@ chanserv_read_suspended(dict_t obj) return suspended; } +static struct giveownership * +chanserv_read_giveownership(dict_t obj) +{ + struct giveownership *giveownership = calloc(1, sizeof(*giveownership)); + char *str; + dict_t previous; + + str = database_get_data(obj, KEY_STAFF_ISSUER, RECDB_QSTRING); + giveownership->staff_issuer = str ? strdup(str) : NULL; + + giveownership->old_owner = strdup(database_get_data(obj, KEY_OLD_OWNER, RECDB_QSTRING)); + + giveownership->target = strdup(database_get_data(obj, KEY_TARGET, RECDB_QSTRING)); + giveownership->target_access = atoi(database_get_data(obj, KEY_TARGET_ACCESS, RECDB_QSTRING)); + + str = database_get_data(obj, KEY_REASON, RECDB_QSTRING); + giveownership->reason = str ? strdup(str) : NULL; + str = database_get_data(obj, KEY_ISSUED, RECDB_QSTRING); + giveownership->issued = str ? (time_t)strtoul(str, NULL, 0) : 0; + + previous = database_get_data(obj, KEY_PREVIOUS, RECDB_OBJECT); + giveownership->previous = previous ? chanserv_read_giveownership(previous) : NULL; + return giveownership; +} + static int chanserv_channel_read(const char *key, struct record_data *hir) { struct suspended *suspended; + struct giveownership *giveownership; struct mod_chanmode *modes; struct chanNode *cNode; struct chanData *cData; @@ -7304,6 +8305,20 @@ chanserv_channel_read(const char *key, struct record_data *hir) 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); @@ -7339,6 +8354,12 @@ chanserv_channel_read(const char *key, struct record_data *hir) cData->flags &= ~CHANNEL_SUSPENDED; } + if((obj = database_get_data(hir->d.object, KEY_GIVEOWNERSHIP, RECDB_OBJECT))) + { + giveownership = chanserv_read_giveownership(obj); + cData->giveownership = giveownership; + } + if((!off_channel || !IsOffChannel(cData)) && !IsSuspended(cData)) { struct mod_chanmode change; mod_chanmode_init(&change); @@ -7356,6 +8377,8 @@ chanserv_channel_read(const char *key, struct record_data *hir) cData->ownerTransfer = str ? strtoul(str, NULL, 0) : 0; str = database_get_data(channel, KEY_MAX, RECDB_QSTRING); cData->max = str ? atoi(str) : 0; + str = database_get_data(channel, KEY_MAX_TIME, RECDB_QSTRING); + cData->max_time = str ? atoi(str) : 0; str = database_get_data(channel, KEY_GREETING, RECDB_QSTRING); cData->greeting = str ? strdup(str) : NULL; str = database_get_data(channel, KEY_USER_GREETING, RECDB_QSTRING); @@ -7365,10 +8388,34 @@ chanserv_channel_read(const char *key, struct record_data *hir) 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); + } + } + + obj = database_get_data(channel, KEY_ADVTOPIC_ENTRIES, RECDB_OBJECT); + for(it = dict_first(obj); it; it = iter_next(it)) + { + struct record_data *rd = iter_data(it); + if(rd->type != RECDB_QSTRING) continue; + int advtopic_index = atoi(iter_key(it)); + if(advtopic_index < 0 || advtopic_index >= MAXADVTOPICENTRIES) continue; + cData->advtopic[advtopic_index] = (rd ? strdup(rd->d.qstring) : NULL); + } + 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, 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; @@ -7484,13 +8531,19 @@ chanserv_write_users(struct saxdb_context *ctx, struct userData *uData) saxdb_start_record(ctx, KEY_USERS, 1); for(; uData; uData = uData->next) { - if((uData->access >= UL_PRESENT) && uData->present) + if((uData->access >= UL_PRESENT) && uData->present && !HANDLE_FLAGGED(uData->handle, BOT)) high_present = 1; saxdb_start_record(ctx, uData->handle->handle, 0); saxdb_write_int(ctx, KEY_LEVEL, uData->access); saxdb_write_int(ctx, KEY_SEEN, uData->seen); if(uData->flags) saxdb_write_int(ctx, KEY_FLAGS, uData->flags); + if(uData->expires) + saxdb_write_int(ctx, KEY_EXPIRES, uData->expires); + 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); @@ -7539,6 +8592,27 @@ chanserv_write_suspended(struct saxdb_context *ctx, const char *name, struct sus saxdb_end_record(ctx); } +static void +chanserv_write_giveownership(struct saxdb_context *ctx, const char *name, struct giveownership *giveownership) +{ + saxdb_start_record(ctx, name, 0); + if(giveownership->staff_issuer) + saxdb_write_string(ctx, KEY_STAFF_ISSUER, giveownership->staff_issuer); + if(giveownership->old_owner) + saxdb_write_string(ctx, KEY_OLD_OWNER, giveownership->old_owner); + if(giveownership->target) + saxdb_write_string(ctx, KEY_TARGET, giveownership->target); + if(giveownership->target_access) + saxdb_write_int(ctx, KEY_TARGET_ACCESS, giveownership->target_access); + if(giveownership->reason) + saxdb_write_string(ctx, KEY_REASON, giveownership->reason); + if(giveownership->issued) + saxdb_write_int(ctx, KEY_ISSUED, giveownership->issued); + if(giveownership->previous) + chanserv_write_giveownership(ctx, KEY_PREVIOUS, giveownership->previous); + saxdb_end_record(ctx); +} + static void chanserv_write_channel(struct saxdb_context *ctx, struct chanData *channel) { @@ -7546,11 +8620,13 @@ chanserv_write_channel(struct saxdb_context *ctx, struct chanData *channel) int high_present; enum levelOption lvlOpt; enum charOption chOpt; + dict_iterator_t it; saxdb_start_record(ctx, channel->channel->name, 1); saxdb_write_int(ctx, KEY_REGISTERED, channel->registered); saxdb_write_int(ctx, KEY_MAX, channel->max); + saxdb_write_int(ctx, KEY_MAX_TIME, channel->max_time); if(channel->topic) saxdb_write_string(ctx, KEY_TOPIC, channel->topic); if(channel->registrar) @@ -7563,6 +8639,31 @@ chanserv_write_channel(struct saxdb_context *ctx, struct chanData *channel) saxdb_write_string(ctx, KEY_TOPIC_MASK, channel->topic_mask); if(channel->suspended) chanserv_write_suspended(ctx, "suspended", channel->suspended); + if(channel->giveownership) + chanserv_write_giveownership(ctx, "giveownership", channel->giveownership); + 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); @@ -7585,6 +8686,16 @@ chanserv_write_channel(struct saxdb_context *ctx, struct chanData *channel) high_present = chanserv_write_users(ctx, channel->users); chanserv_write_bans(ctx, channel->bans); + if(channel->flags & CHANNEL_ADVTOPIC) { + saxdb_start_record(ctx, KEY_ADVTOPIC_ENTRIES, 0); + int advtopic_index; + for(advtopic_index = 0; advtopic_index < MAXADVTOPICENTRIES; advtopic_index++) { + if(channel->advtopic[advtopic_index]) + saxdb_write_string(ctx, strtab(advtopic_index), channel->advtopic[advtopic_index]); + } + saxdb_end_record(ctx); + } + if(dict_size(channel->notes)) { dict_iterator_t it; @@ -7807,6 +8918,7 @@ init_chanserv(const char *nick) 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); @@ -7850,10 +8962,21 @@ init_chanserv(const char *nick) DEFINE_COMMAND(unf, 1, 0, "flags", "+nolog,+toy,+acceptchan", NULL); DEFINE_COMMAND(ping, 1, 0, "flags", "+nolog,+toy,+acceptchan", NULL); DEFINE_COMMAND(wut, 1, 0, "flags", "+nolog,+toy,+acceptchan", NULL); - DEFINE_COMMAND(8ball, 1, 0, "flags", "+nolog,+toy,+acceptchan", NULL); - DEFINE_COMMAND(d, 1, 0, "flags", "+nolog,+toy,+acceptchan", NULL); + DEFINE_COMMAND(8ball, 2, 0, "flags", "+nolog,+toy,+acceptchan", NULL); + DEFINE_COMMAND(d, 2, 0, "flags", "+nolog,+toy,+acceptchan", NULL); DEFINE_COMMAND(huggle, 1, 0, "flags", "+nolog,+toy,+acceptchan", NULL); - + + DEFINE_COMMAND(addvote, 1, MODCMD_REQUIRE_AUTHED | MODCMD_REQUIRE_REGCHAN, NULL); + DEFINE_COMMAND(delvote, 1, MODCMD_REQUIRE_AUTHED | MODCMD_REQUIRE_REGCHAN, NULL); + DEFINE_COMMAND(addoption, 1, MODCMD_REQUIRE_AUTHED | MODCMD_REQUIRE_REGCHAN, NULL); + DEFINE_COMMAND(deloption, 1, MODCMD_REQUIRE_AUTHED | MODCMD_REQUIRE_REGCHAN, NULL); + DEFINE_COMMAND(vote, 1, MODCMD_REQUIRE_AUTHED | MODCMD_REQUIRE_REGCHAN, NULL); + DEFINE_COMMAND(startvote, 1, MODCMD_REQUIRE_AUTHED | MODCMD_REQUIRE_REGCHAN, NULL); + DEFINE_COMMAND(endvote, 1, MODCMD_REQUIRE_AUTHED | MODCMD_REQUIRE_REGCHAN, NULL); + DEFINE_COMMAND(voteresults, 1, MODCMD_REQUIRE_AUTHED | MODCMD_REQUIRE_REGCHAN, NULL); + + DEFINE_COMMAND(opme, 1, MODCMD_REQUIRE_AUTHED|MODCMD_REQUIRE_CHANNEL, NULL); + /* Channel options */ DEFINE_CHANNEL_OPTION(defaulttopic); DEFINE_CHANNEL_OPTION(topicmask); @@ -7870,6 +8993,7 @@ init_chanserv(const char *nick) 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); @@ -7877,7 +9001,9 @@ init_chanserv(const char *nick) DEFINE_CHANNEL_OPTION(ctcpusers); DEFINE_CHANNEL_OPTION(ctcpreaction); DEFINE_CHANNEL_OPTION(inviteme); + DEFINE_CHANNEL_OPTION(advtopic); 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)