From 0669b78c4bb443fbc6642eddcbe6778cfd124d6f Mon Sep 17 00:00:00 2001 From: Michael Poole Date: Tue, 1 Nov 2005 00:23:14 +0000 Subject: [PATCH] Handle default oplevels. src/chanserv.c (cmd_mode): Calculate base oplevel as 1 plus one point for each access level below owner. (chan_opt_modes): Add new argument for mod_chanmode_parse(). (chanserv_conf_read): Likewise. (chanserv_channel_read): Likewise. src/hash.c (AddChannel): Likewise. (AddChannelUser): Set oplevel by default. src/hash.h (MAXOPLEVEL): New define value. (modeNode): Shrink modes and oplevel fields. src/opserv.c (cmd_chaninfo): Fix indentation; show oplevel after nickname rather than before it. src/proto.h (mod_chanmode_parse): Declare new parameter. src/proto-bahamut.c (mod_chanmode_parse): Add new parameter (and ignore it). src/proto-common.c (mod_chanmode): Find the default oplevels for parsing the mode change. src/proto-p10.c (create_desc): Remove oplevel field. (join_helper): Do not try to set oplevel for new modeNode. (parse_foreach): Do not bother parsing oplevels in JOIN, since they are no longer used. (mod_chanmode_parse): Add new parameter and use it to determine the oplevel to set when a valid oplevel one is not specified. git-archimport-id: srvx@srvx.net--2005-srvx/srvx--devo--1.3--patch-31 --- ChangeLog | 43 ++++++++++++++++++++++++++++++++++++++++ src/chanserv.c | 20 ++++++++++++++----- src/hash.c | 5 +++-- src/hash.h | 5 +++-- src/opserv.c | 17 +++++++--------- src/proto-bahamut.c | 3 ++- src/proto-common.c | 8 +++++++- src/proto-p10.c | 48 ++++++++++++--------------------------------- src/proto.h | 2 +- 9 files changed, 93 insertions(+), 58 deletions(-) diff --git a/ChangeLog b/ChangeLog index deed89c..3f306c1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,49 @@ # arch-tag: automatic-ChangeLog--srvx@srvx.net--2005-srvx/srvx--devo--1.3 # +2005-11-01 00:23:14 GMT Michael Poole patch-31 + + Summary: + Handle default oplevels. + Revision: + srvx--devo--1.3--patch-31 + + src/chanserv.c (cmd_mode): Calculate base oplevel as 1 plus one point + for each access level below owner. + (chan_opt_modes): Add new argument for mod_chanmode_parse(). + (chanserv_conf_read): Likewise. + (chanserv_channel_read): Likewise. + + src/hash.c (AddChannel): Likewise. + (AddChannelUser): Set oplevel by default. + + src/hash.h (MAXOPLEVEL): New define value. + (modeNode): Shrink modes and oplevel fields. + + src/opserv.c (cmd_chaninfo): Fix indentation; show oplevel after + nickname rather than before it. + + src/proto.h (mod_chanmode_parse): Declare new parameter. + + src/proto-bahamut.c (mod_chanmode_parse): Add new parameter (and + ignore it). + + src/proto-common.c (mod_chanmode): Find the default oplevels for + parsing the mode change. + + src/proto-p10.c (create_desc): Remove oplevel field. + (join_helper): Do not try to set oplevel for new modeNode. + (parse_foreach): Do not bother parsing oplevels in JOIN, since they + are no longer used. + (mod_chanmode_parse): Add new parameter and use it to determine the + oplevel to set when a valid oplevel one is not specified. + + modified files: + ChangeLog src/chanserv.c src/hash.c src/hash.h src/opserv.c + src/proto-bahamut.c src/proto-common.c src/proto-p10.c + src/proto.h + + 2005-10-13 02:20:55 GMT Michael Poole patch-30 Summary: diff --git a/src/chanserv.c b/src/chanserv.c index 1d7bff9..d9fc2a2 100644 --- a/src/chanserv.c +++ b/src/chanserv.c @@ -3768,8 +3768,10 @@ static CHANSERV_FUNC(cmd_topic) static CHANSERV_FUNC(cmd_mode) { + struct userData *uData; struct mod_chanmode *change; - + short base_oplevel; + if(argc < 2) { change = &channel->channel_info->modes; @@ -3781,7 +3783,14 @@ static CHANSERV_FUNC(cmd_mode) return 1; } - change = mod_chanmode_parse(channel, argv+1, argc-1, MCP_KEY_FREE|MCP_REGISTERED); + uData = GetChannelUser(channel->channel_info, user->handle_info); + if (!uData) + base_oplevel = MAXOPLEVEL; + else if (uData->access >= UL_OWNER) + 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); if(!change) { reply("MSG_INVALID_MODES", unsplit_string(argv+1, argc-1, NULL)); @@ -4905,7 +4914,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))) + else if(!(new_modes = mod_chanmode_parse(channel, argv+1, argc-1, MCP_KEY_FREE|MCP_REGISTERED, 0))) { reply("CSMSG_INVALID_MODE_LOCK", unsplit_string(argv+1, argc-1, NULL)); return 0; @@ -6450,7 +6459,8 @@ chanserv_conf_read(void) 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)) && (change->argc < 2)) + if((change = mod_chanmode_parse(NULL, modes, ii, MCP_KEY_FREE, 0)) + && (change->argc < 2)) { chanserv_conf.default_modes = *change; mod_chanmode_free(change); @@ -6817,7 +6827,7 @@ chanserv_channel_read(const char *key, struct record_data *hir) 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))) { + && (modes = mod_chanmode_parse(cNode, argv, argc, MCP_KEY_FREE, 0))) { cData->modes = *modes; if(off_channel > 0) cData->modes.modes_set |= MODE_REGISTERED; diff --git a/src/hash.c b/src/hash.c index eff19d1..4680865 100644 --- a/src/hash.c +++ b/src/hash.c @@ -365,7 +365,7 @@ AddChannel(const char *name, time_t time_, const char *modes, char *banlist) strcpy(cNode->name, name); banList_init(&cNode->banlist); modeList_init(&cNode->members); - mod_chanmode(NULL, cNode, argv, nn, 0); + mod_chanmode(NULL, cNode, argv, nn, MCP_FROM_SERVER); dict_insert(channels, cNode->name, cNode); cNode->timestamp = time_; rel_age = 1; @@ -373,7 +373,7 @@ AddChannel(const char *name, time_t time_, const char *modes, char *banlist) wipeout_channel(cNode, time_, argv, nn); rel_age = 1; } else if (cNode->timestamp == time_) { - mod_chanmode(NULL, cNode, argv, nn, 0); + mod_chanmode(NULL, cNode, argv, nn, MCP_FROM_SERVER); rel_age = 0; } else { rel_age = -1; @@ -471,6 +471,7 @@ AddChannelUser(struct userNode *user, struct chanNode* channel) mNode->channel = channel; mNode->user = user; mNode->modes = 0; + mNode->oplevel = -1; mNode->idle_since = now; /* Add modeNode to channel and to user. diff --git a/src/hash.h b/src/hash.h index 2ecd749..656926a 100644 --- a/src/hash.h +++ b/src/hash.h @@ -86,6 +86,7 @@ #define REALLEN 50 #define TOPICLEN 250 #define CHANNELLEN 200 +#define MAXOPLEVEL 999 #define MAXMODEPARAMS 6 #define MAXBANS 45 @@ -155,8 +156,8 @@ struct banNode { struct modeNode { struct chanNode *channel; struct userNode *user; - long modes; - int oplevel; + unsigned short modes; + short oplevel; time_t idle_since; }; diff --git a/src/opserv.c b/src/opserv.c index f745756..acfee7c 100644 --- a/src/opserv.c +++ b/src/opserv.c @@ -457,15 +457,12 @@ static MODCMD_FUNC(cmd_chaninfo) } reply("OSMSG_CHANINFO_USER_COUNT", channel->members.used); for (n=0; nmembers.used; n++) { - moden = channel->members.list[n]; - if (moden->modes & MODE_CHANOP) - { - if (moden->oplevel >= 0) - { - send_message_type(4, user, cmd->parent->bot, " (%d)@%s (%s@%s)", moden->oplevel, moden->user->nick, moden->user->ident, moden->user->hostname); - } else { - send_message_type(4, user, cmd->parent->bot, " @%s (%s@%s)", moden->user->nick, moden->user->ident, moden->user->hostname); - } + moden = channel->members.list[n]; + if (moden->modes & MODE_CHANOP) { + if (moden->oplevel >= 0) + send_message_type(4, user, cmd->parent->bot, " @%s:%d (%s@%s)", moden->user->nick, moden->oplevel, moden->user->ident, moden->user->hostname); + else + send_message_type(4, user, cmd->parent->bot, " @%s (%s@%s)", moden->user->nick, moden->user->ident, moden->user->hostname); } } for (n=0; nmembers.used; n++) { @@ -1077,7 +1074,7 @@ static MODCMD_FUNC(cmd_kickbanall) if (!inchan) DelChannelUser(bot, channel, "My work here is done", 0); reply("OSMSG_KICKALL_DONE", channel->name); - return 1; + return 1; } static MODCMD_FUNC(cmd_part) diff --git a/src/proto-bahamut.c b/src/proto-bahamut.c index 4f950ae..d63aef0 100644 --- a/src/proto-bahamut.c +++ b/src/proto-bahamut.c @@ -1225,7 +1225,7 @@ void mod_usermode(struct userNode *user, const char *mode_change) { } struct mod_chanmode * -mod_chanmode_parse(struct chanNode *channel, char **modes, unsigned int argc, unsigned int flags) +mod_chanmode_parse(struct chanNode *channel, char **modes, unsigned int argc, unsigned int flags, short base_oplevel) { struct mod_chanmode *change; unsigned int ii, in_arg, ch_arg, add; @@ -1334,6 +1334,7 @@ mod_chanmode_parse(struct chanNode *channel, char **modes, unsigned int argc, un error: mod_chanmode_free(change); return NULL; + (void)base_oplevel; } struct chanmode_buffer { diff --git a/src/proto-common.c b/src/proto-common.c index b7b9bc2..6ddd23f 100644 --- a/src/proto-common.c +++ b/src/proto-common.c @@ -628,12 +628,18 @@ mod_chanmode_free(struct mod_chanmode *change) int mod_chanmode(struct userNode *who, struct chanNode *channel, char **modes, unsigned int argc, unsigned int flags) { + struct modeNode *member; struct mod_chanmode *change; unsigned int ii; + short base_oplevel; if (!modes || !modes[0]) return 0; - if (!(change = mod_chanmode_parse(channel, modes, argc, flags))) + if (who && (member = GetUserMode(channel, who))) + base_oplevel = member->oplevel; + else + base_oplevel = MAXOPLEVEL; + if (!(change = mod_chanmode_parse(channel, modes, argc, flags, base_oplevel))) return 0; if (flags & MC_ANNOUNCE) mod_chanmode_announce(who, channel, change); diff --git a/src/proto-p10.c b/src/proto-p10.c index ec34a8d..c5ce032 100644 --- a/src/proto-p10.c +++ b/src/proto-p10.c @@ -983,7 +983,6 @@ static CMD_FUNC(cmd_error_nick) struct create_desc { struct userNode *user; - int oplevel; time_t when; }; @@ -991,12 +990,7 @@ static void join_helper(struct chanNode *chan, void *data) { struct create_desc *cd = data; - struct modeNode *mNode; - - mNode = AddChannelUser(cd->user, chan); - mNode->oplevel = cd->oplevel; - if (mNode->oplevel >= 0) - mNode->modes |= MODE_CHANOP; + AddChannelUser(cd->user, chan); } static void @@ -1728,8 +1722,6 @@ static void parse_foreach(char *target_list, foreach_chanfunc cf, foreach_nonchan nc, foreach_userfunc uf, foreach_nonuser nu, void *data) { char *j, old; - char *cPos, *hPos; - int oplevel; do { j = target_list; @@ -1738,28 +1730,10 @@ parse_foreach(char *target_list, foreach_chanfunc cf, foreach_nonchan nc, foreac old = *j; *j = 0; - hPos = strchr(target_list,'#'); - cPos = strchr(target_list,':'); - - /* - * Check if both a '#' and a ':' is in the target's name - * and if cPos < hPos. - * If that's the case, voila, we've found a join with an oplevel - */ - if (hPos && cPos && (cPos < hPos)) - { - oplevel = parse_oplevel(target_list); - target_list = hPos + 1; - } - else - oplevel = -1; - if (IsChannelName(target_list) || (target_list[0] == '0' && target_list[1] == '\0')) { struct chanNode *chan = GetChannel(target_list); - struct create_desc *cd = (struct create_desc*) data; - cd->oplevel = oplevel; if (chan) { if (cf) cf(chan, data); @@ -2168,7 +2142,7 @@ void mod_usermode(struct userNode *user, const char *mode_change) { } struct mod_chanmode * -mod_chanmode_parse(struct chanNode *channel, char **modes, unsigned int argc, unsigned int flags) +mod_chanmode_parse(struct chanNode *channel, char **modes, unsigned int argc, unsigned int flags, short base_oplevel) { struct mod_chanmode *change; unsigned int ii, in_arg, ch_arg, add; @@ -2282,21 +2256,23 @@ mod_chanmode_parse(struct chanNode *channel, char **modes, unsigned int argc, un int oplevel; oplevel_str = strchr(modes[in_arg], ':'); - - /* XXYYY M #channel +o XXYYY: */ if (oplevel_str) { - oplevel = parse_oplevel(oplevel_str+1); - *oplevel_str = 0; + /* XXYYY M #channel +o XXYYY: */ + *oplevel_str++ = '\0'; + oplevel = parse_oplevel(oplevel_str); + if (oplevel <= base_oplevel && !(flags & MCP_FROM_SERVER)) + oplevel = base_oplevel + 1; } else if (channel->modes & MODE_UPASS) - { - /* TODO: need to set oplevel based on issuer's oplevel */ - oplevel = -1; - } + oplevel = base_oplevel + 1; else oplevel = -1; + /* Check that oplevel is within bounds. */ + if (oplevel > MAXOPLEVEL) + oplevel = MAXOPLEVEL; + if (!(flags & MCP_ALLOW_OVB)) goto error; if (in_arg >= argc) diff --git a/src/proto.h b/src/proto.h index 9f0f77a..16d546d 100644 --- a/src/proto.h +++ b/src/proto.h @@ -218,7 +218,7 @@ struct mod_chanmode { struct mod_chanmode *mod_chanmode_alloc(unsigned int argc); struct mod_chanmode *mod_chanmode_dup(struct mod_chanmode *orig, unsigned int extra); -struct mod_chanmode *mod_chanmode_parse(struct chanNode *channel, char **modes, unsigned int argc, unsigned int flags); +struct mod_chanmode *mod_chanmode_parse(struct chanNode *channel, char **modes, unsigned int argc, unsigned int flags, short base_oplevel); void mod_chanmode_apply(struct userNode *who, struct chanNode *channel, struct mod_chanmode *change); void mod_chanmode_announce(struct userNode *who, struct chanNode *channel, struct mod_chanmode *change); char *mod_chanmode_format(struct mod_chanmode *desc, char *buffer); -- 2.20.1