X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2Fchanserv.c;h=771b6169f462c676c2ae0d1dd3fed6408c001c00;hb=093f707afd62edb079b5f64d165ee128f912e71f;hp=7a620326a28578406bd18700c63f054a011acb1d;hpb=6714c5d0a17782895f5662fea81774a27362bd2b;p=srvx.git diff --git a/src/chanserv.c b/src/chanserv.c index 7a62032..771b616 100644 --- a/src/chanserv.c +++ b/src/chanserv.c @@ -141,7 +141,7 @@ #define KEY_EXPIRES "expires" #define KEY_TRIGGERED "triggered" -#define CHANNEL_DEFAULT_FLAGS (CHANNEL_OFFCHANNEL | CHANNEL_UNREVIEWED) +#define CHANNEL_DEFAULT_FLAGS (CHANNEL_UNREVIEWED) #define CHANNEL_PRESERVED_FLAGS (CHANNEL_UNREVIEWED) #define CHANNEL_DEFAULT_OPTIONS "lmoooanpcnat" @@ -399,7 +399,7 @@ static const struct message_entry msgtab[] = { { "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)." }, + { "CSMSG_MYACCESS_COUNT_1", "%s has access in $b%d$b channel and is owner of $b%d$b channel(s)." }, /* Seen information */ @@ -483,6 +483,7 @@ static const struct message_entry msgtab[] = { /* Toys */ { "CSMSG_UNF_RESPONSE", "I don't want to be part of your sick fantasies!" }, { "CSMSG_PING_RESPONSE", "Pong!" }, + { "CSMSG_PONG_RESPONSE", "Ping!" }, { "CSMSG_WUT_RESPONSE", "wut" }, { "CSMSG_BAD_NUMBER", "$b%s$b is an invalid number. Please use a number greater than 1 with this command." }, { "CSMSG_BAD_DIE_FORMAT", "I do not understand $b%s$b. Please use either a single number or standard 4d6+3 format." }, @@ -523,6 +524,9 @@ static const struct message_entry msgtab[] = { { NULL, NULL } }; +#define CSMSG_ALERT_REGISTERED "%s registered to %s by %s." +#define CSMSG_ALERT_UNREGISTERED "%s %s" + /* eject_user and unban_user flags */ #define ACTION_KICK 0x0001 #define ACTION_BAN 0x0002 @@ -548,6 +552,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; @@ -601,6 +608,8 @@ static struct const char *new_channel_authed; const char *new_channel_unauthed; const char *new_channel_msg; + + struct chanNode *oper_channel; } chanserv_conf; struct listData @@ -1515,12 +1524,12 @@ unregister_channel(struct chanData *channel, const char *reason) 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); + dict_delete(channel->notes); if(!IsSuspended(channel)) DelChannelUser(chanserv, channel->channel, msgbuf, 0); - global_message(MESSAGE_RECIPIENT_OPERS | MESSAGE_RECIPIENT_HELPERS, msgbuf); + + chanserv_oper_message(CSMSG_ALERT_UNREGISTERED, channel->channel->name, reason); UnlockChannel(channel->channel); free(channel); registered_channels--; @@ -2160,7 +2169,6 @@ static CHANSERV_FUNC(cmd_register) struct handle_info *handle; struct chanData *cData; struct modeNode *mn; - char reason[MAXLEN]; char *chan_name; unsigned int new_channel, force=0; struct do_not_register *dnr; @@ -2271,8 +2279,7 @@ static CHANSERV_FUNC(cmd_register) 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; } @@ -3280,8 +3287,7 @@ static CHANSERV_FUNC(cmd_opme) return 0; } - struct devnull_class *devnull; - if(user->handle_info->devnull && (devnull = devnull_get(user->handle_info->devnull)) && (devnull->modes & DEVNULL_MODE_OPME)) + if(devnull_user_has_priv(user->handle_info, DEVNULL_MODE_OPME)) { change.args[0].mode = MODE_CHANOP; errmsg = "CSMSG_ALREADY_OPPED"; @@ -6583,13 +6589,23 @@ static CHANSERV_FUNC(cmd_giveownership) 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 *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; actor = GetChannelUser(channel->channel_info, user->handle_info); real_actor = GetChannelAccess(channel->channel_info, user->handle_info); @@ -6615,6 +6631,24 @@ static CHANSERV_FUNC(cmd_suspend) } 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; @@ -6647,6 +6681,7 @@ static CHANSERV_FUNC(cmd_unsuspend) } 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); @@ -7094,6 +7129,20 @@ static CHANSERV_FUNC(cmd_ping) return 1; } +static CHANSERV_FUNC(cmd_pong) +{ + if(channel) + { + char response[MAXLEN]; + const char *fmt = user_find_message(user, "CSMSG_PONG_RESPONSE"); + sprintf(response, "%s: %s", user->nick, fmt); + irc_privmsg(cmd->parent->bot, channel->name, response); + } + else + reply("CSMSG_PONG_RESPONSE"); + return 1; +} + static CHANSERV_FUNC(cmd_wut) { if(channel) @@ -7951,6 +8000,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_channel", RECDB_QSTRING); + if(str) + { + chanserv_conf.oper_channel = AddChannel(str, now, "+tinms", NULL); + } + else + { + chanserv_conf.oper_channel = NULL; + } } static void @@ -8035,7 +8094,7 @@ user_read_helper(const char *key, struct record_data *rd, struct chanData *chan) { struct handle_info *handle; struct userData *uData; - char *seen, *inf, *flags, *voted, *votefor; + char *seen, *inf, *flags, *voted, *votefor, *expires; unsigned long last_seen; unsigned short access_level; @@ -8056,6 +8115,7 @@ 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); @@ -8067,6 +8127,15 @@ user_read_helper(const char *key, struct record_data *rd, struct chanData *chan) 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; @@ -8484,6 +8553,8 @@ chanserv_write_users(struct saxdb_context *ctx, struct userData *uData) 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) @@ -8905,6 +8976,7 @@ 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(pong, 1, 0, "flags", "+nolog,+toy,+acceptchan", NULL); DEFINE_COMMAND(wut, 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);