Handle default oplevels.
authorMichael Poole <mdpoole@troilus.org>
Tue, 1 Nov 2005 00:23:14 +0000 (00:23 +0000)
committerMichael Poole <mdpoole@troilus.org>
Tue, 1 Nov 2005 00:23:14 +0000 (00:23 +0000)
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
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

index deed89ccc20a5de822437a30a20508d3bc9b09d5..3f306c1499e8839c8f520f55ccb75ad8af555975 100644 (file)
--- 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 <mdpoole@troilus.org>     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 <mdpoole@troilus.org>     patch-30
 
     Summary:
index 1d7bff97dfec4fea33cfbc3ae752e56d55104cb4..d9fc2a25749d3e3a216dc8648a5ce09dbac9a14a 100644 (file)
@@ -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;
index eff19d1e28a70f4c9635221403984863a759e198..468086588b60978e87af67908e296f5c85615a8b 100644 (file)
@@ -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.
index 2ecd74981c3002b6a6c81233db95b6f0f86fe258..656926a349b63c6581fa1759c470d930af08c659 100644 (file)
@@ -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;
 };
 
index f7457565dd1d381c202e959ece7b526e3349f1f6..acfee7c0a53cb9124826b1f7e10817b66dccefac 100644 (file)
@@ -457,15 +457,12 @@ static MODCMD_FUNC(cmd_chaninfo)
     }
     reply("OSMSG_CHANINFO_USER_COUNT", channel->members.used);
     for (n=0; n<channel->members.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; n<channel->members.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)
index 4f950aee745559caf5d6fca3980248d1566ce04a..d63aef01a2cc7fae8710b62aa0b12336c519dd0f 100644 (file)
@@ -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 {
index b7b9bc22d09665618ba8f479a5aa4b38e1d4c3cf..6ddd23f4a7b1bb6e5f29d9bd65ad1888658b78c7 100644 (file)
@@ -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);
index ec34a8dd3d62304a56a3b11c9cb95d8f6bf3141b..c5ce032d4c001072bdcc4635e1f2513f81064bd8 100644 (file)
@@ -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:<oplevel> */
             if (oplevel_str)
             {
-                oplevel = parse_oplevel(oplevel_str+1);
-                *oplevel_str = 0;
+                /* XXYYY M #channel +o XXYYY:<oplevel> */
+                *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)
index 9f0f77a18f7b26539a4dea5be49012913ca9a5f1..16d546d716866ae1df3ea6a72fc4faa88d0995d1 100644 (file)
@@ -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);