X-Git-Url: https://jfr.im/git/irc/evilnet/x3.git/blobdiff_plain/5aa400d2612f104275d7f6b466a71f3139b4375b..964a842d8f29eb5767e64d2028a36cc40ccec911:/src/chanserv.c diff --git a/src/chanserv.c b/src/chanserv.c index 1363b68..50625ea 100644 --- a/src/chanserv.c +++ b/src/chanserv.c @@ -5,7 +5,7 @@ * * x3 is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -111,6 +111,7 @@ #define KEY_NOTES "notes" #define KEY_TOPIC_MASK "topic_mask" #define KEY_OWNER_TRANSFER "owner_transfer" +#define KEY_MAXSETINFO "maxsetinfo" /* User data */ #define KEY_LEVEL "level" @@ -236,7 +237,7 @@ static const struct message_entry msgtab[] = { { "CSMSG_BAN_DONE", "Banned $b%s$b from %s." }, { "CSMSG_REASON_CHANGE", "Reason for LAMER $b%s$b changed." }, { "CSMSG_LAMER_EXTENDED", "Extended LAMER for $b%s$b, now expires in %s." }, - { "CSMSG_BAN_REMOVED", "Matching ban(s) and LAMER(s) in $b%s$b were removed." }, + { "CSMSG_BAN_REMOVED", "Ban(s) and LAMER(s) matching $b%s$b were removed." }, { "CSMSG_TRIMMED_LAMERS", "Trimmed $b%d LAMERs$b from the %s LAMER list that were inactive for at least %s." }, { "CSMSG_REDUNDANT_BAN", "$b%s$b is already banned in %s." }, { "CSMSG_REDUNDANT_LAMER", "$b%s$b is already LAMER'd in %s." }, @@ -299,6 +300,7 @@ static const struct message_entry msgtab[] = { { "CSMSG_SET_TOPICREFRESH", "$bTopicRefresh$b %d - %s" }, { "CSMSG_SET_RESYNC", "$bResync $b %d - %s" }, { "CSMSG_SET_BANTIMEOUT", "$bBanTimeout $b %d - %s" }, + { "CSMSG_SET_MAXSETINFO", "$bMaxSetInfo $b %d - maximum characters in a setinfo line." }, { "CSMSG_USET_AUTOOP", "$bAutoOp $b %s" }, { "CSMSG_USET_AUTOVOICE", "$bAutoVoice $b %s" }, @@ -2239,6 +2241,7 @@ static CHANSERV_FUNC(cmd_register) /* Initialize the channel's max user record. */ cData->max = channel->members.used; + cData->maxsetinfo = chanserv_conf.max_userinfo_length; if(handle != user->handle_info) reply("CSMSG_PROXY_SUCCESS", handle->handle, channel->name); @@ -2877,12 +2880,13 @@ static CHANSERV_FUNC(cmd_deluser) if(argc > 2) { access = user_level_from_name(argv[1], UL_OWNER); + char *useraccess = user_level_name_from_level(victim->access); if(!access) { reply("CSMSG_INVALID_ACCESS", argv[1]); return 0; } - if(access != victim->access) + if(strcasecmp(argv[1], useraccess)) { reply("CSMSG_INCORRECT_ACCESS", handle->handle, user_level_name_from_level(victim->access), argv[1]); return 0; @@ -6018,6 +6022,20 @@ static MODCMD_FUNC(chan_opt_usergreeting) return opt_greeting_common(user, cmd, argc, argv, "CSMSG_SET_USERGREETING", &channel->channel_info->user_greeting); } +static MODCMD_FUNC(chan_opt_maxsetinfo) +{ + unsigned int charmax; + + if(argc > 1) { + charmax = atoi(argv[1]); + if ((charmax > 0) && (charmax < chanserv_conf.max_userinfo_length)) + channel->channel_info->maxsetinfo = charmax; + } + + reply("CSMSG_SET_MAXSETINFO", channel->channel_info->maxsetinfo); + return 1; +} + static MODCMD_FUNC(chan_opt_modes) { struct mod_chanmode *new_modes; @@ -6528,9 +6546,9 @@ static MODCMD_FUNC(user_opt_info) { size_t bp; infoline = unsplit_string(argv + 1, argc - 1, NULL); - if(strlen(infoline) > chanserv_conf.max_userinfo_length) + if(strlen(infoline) > channel->channel_info->maxsetinfo) { - reply("CSMSG_INFOLINE_TOO_LONG", chanserv_conf.max_userinfo_length); + reply("CSMSG_INFOLINE_TOO_LONG", channel->channel_info->maxsetinfo); return 0; } bp = strcspn(infoline, "\001"); @@ -6704,8 +6722,8 @@ static CHANSERV_FUNC(cmd_giveownership) giveownership = calloc(1, sizeof(*giveownership)); giveownership->issued = now; - giveownership->old_owner = curr_user->handle->handle; - giveownership->target = new_owner_hi->handle; + giveownership->old_owner = strdup(curr_user->handle->handle); + giveownership->target = strdup(new_owner_hi->handle); giveownership->target_access = new_owner_old_access; if(override) { @@ -7263,20 +7281,22 @@ handle_new_channel(struct chanNode *channel) int trace_check_bans(struct userNode *user, struct chanNode *chan) { - struct chanData *cData; struct banData *bData; + struct mod_chanmode *change; - if(!(cData = chan->channel_info)) - return 0; + change = find_matching_bans(&chan->banlist, user, NULL); + if (change) + return 1; - if(chan->banlist.used < MAXBANS) - { - for(bData = cData->bans; - bData && !user_matches_glob(user, bData->mask, MATCH_USENICK); - bData = bData->next); + /* lamer list */ + if (chan->channel_info) { + for(bData = chan->channel_info->bans; bData; bData = bData->next) { - if(bData) { - return 1; + if(!user_matches_glob(user, bData->mask, MATCH_USENICK)) + continue; + + if(bData) + return 1; } } @@ -7340,6 +7360,18 @@ check_bans(struct userNode *user, const char *channel) return 0; } +int +channel_user_is_exempt(struct userNode *user, struct chanNode *channel) +{ + unsigned int ii; + for(ii = 0; ii < channel->exemptlist.used; ii++) + { + if(user_matches_glob(user, channel->exemptlist.list[ii]->exempt, MATCH_USENICK)) + return true; + } + return false; +} + /* Welcome to my worst nightmare. Warning: Read (or modify) the code below at your own risk. */ @@ -7356,7 +7388,7 @@ handle_join(struct modeNode *mNode) unsigned int modes = 0, info = 0; char *greeting; - if(IsLocal(user) || !channel->channel_info || IsSuspended(channel->channel_info)) + if(IsLocal(user) || !channel || !channel->channel_info || IsSuspended(channel->channel_info)) return 0; cData = channel->channel_info; @@ -7404,7 +7436,7 @@ handle_join(struct modeNode *mNode) /* TODO: maybe only people above inviteme level? -Rubin */ /* We don't kick people with access */ - if(!uData) + if(!uData && !channel_user_is_exempt(user, channel)) { if(channel->banlist.used < MAXBANS) { @@ -8491,6 +8523,9 @@ 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_MAXSETINFO, RECDB_QSTRING); + cData->maxsetinfo = str ? strtoul(str, NULL, 0) : chanserv_conf.max_userinfo_length; + if(!IsSuspended(cData) && (str = database_get_data(channel, KEY_MODES, RECDB_QSTRING)) && (argc = split_line(str, 0, ArrayLength(argv), argv)) @@ -8739,6 +8774,9 @@ chanserv_write_channel(struct saxdb_context *ctx, struct chanData *channel) } saxdb_end_record(ctx); + if (channel->maxsetinfo) + saxdb_write_int(ctx, KEY_MAXSETINFO, channel->maxsetinfo); + if(channel->modes.modes_set || channel->modes.modes_clear) { mod_chanmode_format(&channel->modes, buf); @@ -9046,6 +9084,7 @@ init_chanserv(const char *nick) DEFINE_CHANNEL_OPTION(ctcpreaction); DEFINE_CHANNEL_OPTION(bantimeout); DEFINE_CHANNEL_OPTION(inviteme); + DEFINE_CHANNEL_OPTION(maxsetinfo); if(off_channel > 1) DEFINE_CHANNEL_OPTION(offchannel); modcmd_register(chanserv_module, "set defaults", chan_opt_defaults, 1, 0, "access", "owner", NULL);