irssi-import / bugs.irssi.org

bugs.irssi.org archive
https://github.com/irssi/irssi/issues
0 stars 0 forks source link

Support for owner(~) and admin(&) modes #742

Open irssibot opened 14 years ago

irssibot commented 14 years ago

Support for owner and admin modes would be nice.

Add to the selection of nicks to show in the names list: Currently the names lists can be filtered on what types of nicks to show (op/halfop/voice/normal) and owner and admin types are treated as normal. The should be given their own filters and treated as their own type.

Add to summary of names list: Right now owners and admins are counted as normal users. Should have their own categories added.

Add to the nick item: Currently you can only test for op/halfop/voice on a nick, which can cause problems when the owners and admins don't have +o set as well, or when irssi doesn't see them given +o. owner and admin fields should be added and exported into the perl scripting interface.

Add to the theming: Currently each type of user (op/halfof/voice/normal) can be themed differently in the names list. This should also apply to the owner and admin types.

I have already implemented all the features based on the 0.8.14 code and have attached the patch file.

irssibot commented 14 years ago

irssi.patch

diff -r -U3 -p irssi-0.8.14/colorless.theme irssi-0.8.14n/colorless.theme
--- irssi-0.8.14/colorless.theme    2009-07-22 02:48:30.000000000 +0800
+++ irssi-0.8.14n/colorless.theme   2010-03-21 13:06:15.613276023 +0800
@@ -222,6 +222,8 @@ abstracts = {
   # /names list
   names_prefix = "";
   names_nick = "[$0$1-] ";
+  names_nick_owner = "{names_nick $*}";
+  names_nick_admin = "{names_nick $*}";
   names_nick_op = "{names_nick $*}";
   names_nick_halfop = "{names_nick $*}";
   names_nick_voice = "{names_nick $*}";
diff -r -U3 -p irssi-0.8.14/default.theme irssi-0.8.14n/default.theme
--- irssi-0.8.14/default.theme  2009-07-22 02:48:30.000000000 +0800
+++ irssi-0.8.14n/default.theme 2010-03-21 13:00:01.743250221 +0800
@@ -222,6 +222,8 @@ abstracts = {
   # /names list
   names_prefix = "";
   names_nick = "[%_$0%_$1-] ";
+  names_nick_owner = "{names_nick $*}";
+  names_nick_admin = "{names_nick $*}";
   names_nick_op = "{names_nick $*}";
   names_nick_halfop = "{names_nick $*}";
   names_nick_voice = "{names_nick $*}";
diff -r -U3 -p irssi-0.8.14/src/core/nick-rec.h irssi-0.8.14n/src/core/nick-rec.h
--- irssi-0.8.14/src/core/nick-rec.h    2009-07-22 02:48:05.000000000 +0800
+++ irssi-0.8.14n/src/core/nick-rec.h   2010-03-21 12:51:46.263310730 +0800
@@ -16,6 +16,8 @@ unsigned int serverop:1;

 /* status in channel */
 unsigned int send_massjoin:1; /* Waiting to be sent in massjoin signal */
+unsigned int owner:1;
+unsigned int admin:1;
 unsigned int op:1;
 unsigned int halfop:1;
 unsigned int voice:1;
diff -r -U3 -p irssi-0.8.14/src/fe-common/core/fe-channels.c irssi-0.8.14n/src/fe-common/core/fe-channels.c
--- irssi-0.8.14/src/fe-common/core/fe-channels.c   2009-07-22 02:47:59.000000000 +0800
+++ irssi-0.8.14n/src/fe-common/core/fe-channels.c  2010-03-21 12:52:05.713327215 +0800
@@ -412,7 +412,9 @@ static void display_sorted_nicks(CHANNEL
        linebuf[columns[col]-item_extra] = '\0';
        memcpy(linebuf, rec->nick, strlen(rec->nick));

-       formatnum = rec->op ? TXT_NAMES_NICK_OP :
+       formatnum = rec->owner ? TXT_NAMES_NICK_OWNER :
+           rec->admin ? TXT_NAMES_NICK_ADMIN :
+           rec->op ? TXT_NAMES_NICK_OP :
            rec->halfop ? TXT_NAMES_NICK_HALFOP :
            rec->voice ? TXT_NAMES_NICK_VOICE :
                         TXT_NAMES_NICK;
@@ -452,10 +454,10 @@ void fe_channels_nicklist(CHANNEL_REC *c
 {
    NICK_REC *nick;
    GSList *tmp, *nicklist, *sorted;
-   int nicks, normal, voices, halfops, ops;
+   int nicks, normal, voices, halfops, ops, admins, owners;
    const char *nick_flags;

-   nicks = normal = voices = halfops = ops = 0;
+   nicks = normal = voices = halfops = ops = admins = owners = 0;
    nicklist = nicklist_getnicks(channel);
    sorted = NULL;
    nick_flags = channel->server->get_nick_flags(channel->server);
@@ -465,7 +467,15 @@ void fe_channels_nicklist(CHANNEL_REC *c
        nick = tmp->data;

        nicks++;
-       if (nick->op) {
+       if (nick->owner) {
+           owners++;
+           if ((flags & CHANNEL_NICKLIST_FLAG_OWNERS) == 0)
+                                continue;
+       } else if (nick->admin) {
+           admins++;
+           if ((flags & CHANNEL_NICKLIST_FLAG_ADMINS) == 0)
+                                continue;
+       } else if (nick->op) {
            ops++;
            if ((flags & CHANNEL_NICKLIST_FLAG_OPS) == 0)
                                 continue;
@@ -495,14 +505,14 @@ void fe_channels_nicklist(CHANNEL_REC *c
        printformat(channel->server, channel->visible_name,
                MSGLEVEL_CLIENTCRAP, TXT_NAMES,
                channel->visible_name,
-               nicks, ops, halfops, voices, normal);
+               nicks, owners, admins, ops, halfops, voices, normal);
        display_sorted_nicks(channel, sorted);
    }
    g_slist_free(sorted);

    printformat(channel->server, channel->visible_name,
            MSGLEVEL_CLIENTNOTICE, TXT_ENDOFNAMES,
-           channel->visible_name, nicks, ops, halfops, voices, normal);
+           channel->visible_name, nicks, owners, admins, ops, halfops, voices, normal);
 }

 /* SYNTAX: NAMES [-count | -ops -halfops -voices -normal] [<channels> | **] */
diff -r -U3 -p irssi-0.8.14/src/fe-common/core/fe-channels.h irssi-0.8.14n/src/fe-common/core/fe-channels.h
--- irssi-0.8.14/src/fe-common/core/fe-channels.h   2009-07-22 02:47:59.000000000 +0800
+++ irssi-0.8.14n/src/fe-common/core/fe-channels.h  2010-03-21 12:52:30.570849330 +0800
@@ -1,12 +1,14 @@
 #ifndef __FE_CHANNELS_H
 #define __FE_CHANNELS_H

-#define CHANNEL_NICKLIST_FLAG_OPS       0x01
-#define CHANNEL_NICKLIST_FLAG_HALFOPS   0x02
-#define CHANNEL_NICKLIST_FLAG_VOICES    0x04
-#define CHANNEL_NICKLIST_FLAG_NORMAL    0x08
-#define CHANNEL_NICKLIST_FLAG_ALL       0x0f
-#define CHANNEL_NICKLIST_FLAG_COUNT     0x10
+#define CHANNEL_NICKLIST_FLAG_OWNERS    0x01
+#define CHANNEL_NICKLIST_FLAG_ADMINS    0x02
+#define CHANNEL_NICKLIST_FLAG_OPS       0x04
+#define CHANNEL_NICKLIST_FLAG_HALFOPS   0x08
+#define CHANNEL_NICKLIST_FLAG_VOICES    0x10
+#define CHANNEL_NICKLIST_FLAG_NORMAL    0x20
+#define CHANNEL_NICKLIST_FLAG_ALL       0x3f
+#define CHANNEL_NICKLIST_FLAG_COUNT     0x40

 void fe_channels_nicklist(CHANNEL_REC *channel, int flags);

diff -r -U3 -p irssi-0.8.14/src/fe-common/core/module-formats.c irssi-0.8.14n/src/fe-common/core/module-formats.c
--- irssi-0.8.14/src/fe-common/core/module-formats.c    2009-07-22 02:47:59.000000000 +0800
+++ irssi-0.8.14n/src/fe-common/core/module-formats.c   2010-03-21 12:52:52.310793441 +0800
@@ -108,13 +108,15 @@ FORMAT_REC fecommon_core_formats[] = {
    { "talking_in", "You are now talking in {channel $0}", 1, { 0 } },
    { "not_in_channels", "You are not on any channels", 0 },
    { "current_channel", "Current channel {channel $0}", 1, { 0 } },
-   { "names", "{names_users Users {names_channel $0}}", 6, { 0, 1, 1, 1, 1, 1 } },
+   { "names", "{names_users Users {names_channel $0}}", 8, { 0, 1, 1, 1, 1, 1, 1, 1 } },
    { "names_prefix", "%#{names_prefix $0}", 1, { 0 } },
+        { "names_nick_owner", "{names_nick_owner $0 $1}", 2, { 0, 0 } },
+        { "names_nick_admin", "{names_nick_admin $0 $1}", 2, { 0, 0 } },
         { "names_nick_op", "{names_nick_op $0 $1}", 2, { 0, 0 } },
         { "names_nick_halfop", "{names_nick_halfop $0 $1}", 2, { 0, 0 } },
         { "names_nick_voice", "{names_nick_voice $0 $1}", 2, { 0, 0 } },
         { "names_nick", "{names_nick $0 $1}", 2, { 0, 0 } },
-        { "endofnames", "{channel $0}: Total of {hilight $1} nicks {comment {hilight $2} ops, {hilight $3} halfops, {hilight $4} voices, {hilight $5} normal}", 6, { 0, 1, 1, 1, 1, 1 } },
+        { "endofnames", "{channel $0}: Total of {hilight $1} nicks {comment {hilight $2} owners, {hilight $3} admins, {hilight $4} ops, {hilight $5} halfops, {hilight $6} voices, {hilight $7} normal}", 8, { 0, 1, 1, 1, 1, 1, 1, 1 } },
    { "chanlist_header", "%#You are on the following channels:", 0 },
    { "chanlist_line", "%#{channel $[-10]0} %|+$1 ($2): $3", 4, { 0, 0, 0, 0 } },
    { "chansetup_not_found", "Channel {channel $0} not found", 2, { 0, 0 } },
diff -r -U3 -p irssi-0.8.14/src/fe-common/core/module-formats.h irssi-0.8.14n/src/fe-common/core/module-formats.h
--- irssi-0.8.14/src/fe-common/core/module-formats.h    2009-07-22 02:47:59.000000000 +0800
+++ irssi-0.8.14n/src/fe-common/core/module-formats.h   2010-03-21 12:53:34.270829912 +0800
@@ -86,6 +86,8 @@ enum {
    TXT_CURRENT_CHANNEL,
    TXT_NAMES,
    TXT_NAMES_PREFIX,
+   TXT_NAMES_NICK_OWNER,
+   TXT_NAMES_NICK_ADMIN,
    TXT_NAMES_NICK_OP,
    TXT_NAMES_NICK_HALFOP,
    TXT_NAMES_NICK_VOICE,
diff -r -U3 -p irssi-0.8.14/src/irc/core/irc-nicklist.c irssi-0.8.14n/src/irc/core/irc-nicklist.c
--- irssi-0.8.14/src/irc/core/irc-nicklist.c    2009-07-22 02:48:25.000000000 +0800
+++ irssi-0.8.14n/src/irc/core/irc-nicklist.c   2010-03-21 12:53:50.870774247 +0800
@@ -31,7 +31,8 @@

 /* Add new nick to list */
 NICK_REC *irc_nicklist_insert(IRC_CHANNEL_REC *channel, const char *nick,
-                 int op, int halfop, int voice, int send_massjoin)
+                 int owner, int admin, int op, int halfop, 
+                 int voice, int send_massjoin)
 {
    NICK_REC *rec;

@@ -41,6 +42,8 @@ NICK_REC *irc_nicklist_insert(IRC_CHANNE
    rec = g_new0(NICK_REC, 1);
    rec->nick = g_strdup(nick);

+   if (owner) rec->owner = TRUE;
+   if (admin) rec->admin = TRUE;
    if (op) rec->op = TRUE;
    if (halfop) rec->halfop = TRUE;
    if (voice) rec->voice = TRUE;
@@ -99,7 +102,7 @@ static void event_names_list(IRC_SERVER_
    IRC_CHANNEL_REC *chanrec;
    NICK_REC *rec;
    char *params, *type, *channel, *names, *ptr;
-        int op, halfop, voice;
+        int owner, admin, op, halfop, voice;
    char prefixes[MAX_USER_PREFIXES+1];

    g_return_if_fail(data != NULL);
@@ -139,11 +142,17 @@ static void event_names_list(IRC_SERVER_
           showing "@+nick" and since none of these chars are valid
           nick chars, just check them until a non-nickflag char is
           found. */
-       op = halfop = voice = FALSE;
+       owner = admin = op = halfop = voice = FALSE;
        prefixes[0] = '\0';
        while (isnickflag(server, *ptr)) {
            prefix_add(prefixes, *ptr, (SERVER_REC *) server);
            switch (*ptr) {
+           case '~':
+                                owner = TRUE;
+                                break;
+           case '&':
+                                admin = TRUE;
+                                break;
            case '@':
                                 op = TRUE;
                                 break;
@@ -158,8 +167,8 @@ static void event_names_list(IRC_SERVER_
        }

        if (nicklist_find((CHANNEL_REC *) chanrec, ptr) == NULL) {
-           rec = irc_nicklist_insert(chanrec, ptr, op, halfop,
-                         voice, FALSE);
+           rec = irc_nicklist_insert(chanrec, ptr, owner, admin,
+                         op, halfop, voice, FALSE);
            memcpy(rec->prefixes, prefixes, sizeof(rec->prefixes));
        }
    }
@@ -186,8 +195,8 @@ static void event_end_of_names(IRC_SERVE
               if channel is empty */
            nicks = g_hash_table_size(chanrec->nicks);
            ownnick = irc_nicklist_insert(chanrec, server->nick,
-                             nicks == 0, FALSE,
-                             FALSE, FALSE);
+                             nicks == 0, FALSE, FALSE,
+                             FALSE, FALSE, FALSE);
        }
        nicklist_set_own(CHANNEL(chanrec), ownnick);
                 chanrec->chanop = chanrec->ownnick->op;
diff -r -U3 -p irssi-0.8.14/src/irc/core/irc-nicklist.h irssi-0.8.14n/src/irc/core/irc-nicklist.h
--- irssi-0.8.14/src/irc/core/irc-nicklist.h    2009-07-22 02:48:25.000000000 +0800
+++ irssi-0.8.14n/src/irc/core/irc-nicklist.h   2010-03-21 12:54:24.700774922 +0800
@@ -5,7 +5,8 @@

 /* Add new nick to list */
 NICK_REC *irc_nicklist_insert(IRC_CHANNEL_REC *channel, const char *nick,
-                 int op, int halfop, int voice, int send_massjoin);
+                 int owner, int admin, int op, int halfop, 
+                 int voice, int send_massjoin);

 /* Remove all "extra" characters from `nick'. Like _nick_ -> nick */
 char *irc_nick_strip(const char *nick);
diff -r -U3 -p irssi-0.8.14/src/irc/core/irc-session.c irssi-0.8.14n/src/irc/core/irc-session.c
--- irssi-0.8.14/src/irc/core/irc-session.c 2009-07-22 02:48:25.000000000 +0800
+++ irssi-0.8.14n/src/irc/core/irc-session.c    2010-03-21 12:54:45.340845793 +0800
@@ -114,7 +114,7 @@ static void sig_session_restore_nick(IRC
                     CONFIG_NODE *node)
 {
    const char *nick, *prefixes;
-        int op, halfop, voice;
+        int owner, admin, op, halfop, voice;
         NICK_REC *nickrec;
    char newprefixes[MAX_USER_PREFIXES + 1];
    int i;
@@ -126,10 +126,12 @@ static void sig_session_restore_nick(IRC
    if (nick == NULL)
                 return;

+   owner = config_node_get_bool(node, "owner", FALSE);
+   admin = config_node_get_bool(node, "admin", FALSE);
    op = config_node_get_bool(node, "op", FALSE);
         voice = config_node_get_bool(node, "voice", FALSE);
         halfop = config_node_get_bool(node, "halfop", FALSE);
-   nickrec = irc_nicklist_insert(channel, nick, op, halfop, voice, FALSE);
+   nickrec = irc_nicklist_insert(channel, nick, owner, admin, op, halfop, voice, FALSE);
    prefixes = config_node_get_str(node, "prefixes", NULL);
    if (prefixes == NULL || *prefixes == '\0') {
        /* upgrading from old irssi or from an in-between
@@ -137,6 +139,10 @@ static void sig_session_restore_nick(IRC
         * op/voice/halfop, restore prefixes
         */
        i = 0;
+       if (owner)
+           newprefixes[i++] = '~';
+       if (admin)
+           newprefixes[i++] = '&';
        if (op)
            newprefixes[i++] = '@';
        if (halfop)
diff -r -U3 -p irssi-0.8.14/src/irc/core/massjoin.c irssi-0.8.14n/src/irc/core/massjoin.c
--- irssi-0.8.14/src/irc/core/massjoin.c    2009-07-22 02:48:25.000000000 +0800
+++ irssi-0.8.14n/src/irc/core/massjoin.c   2010-03-21 12:55:20.660846524 +0800
@@ -65,7 +65,8 @@ static void event_join(IRC_SERVER_REC *s
    }

    /* add user to nicklist */
-   nickrec = irc_nicklist_insert(chanrec, nick, FALSE, FALSE, FALSE, TRUE);
+   nickrec = irc_nicklist_insert(chanrec, nick, FALSE, FALSE, 
+                     FALSE, FALSE, FALSE, TRUE);
         nicklist_set_host(CHANNEL(chanrec), nickrec, address);

    if (chanrec->massjoins == 0) {
diff -r -U3 -p irssi-0.8.14/src/irc/core/modes.c irssi-0.8.14n/src/irc/core/modes.c
--- irssi-0.8.14/src/irc/core/modes.c   2009-07-22 02:48:25.000000000 +0800
+++ irssi-0.8.14n/src/irc/core/modes.c  2010-03-21 12:55:49.220828308 +0800
@@ -44,6 +44,8 @@ static void nick_mode_change(IRC_CHANNEL
    if (nickrec == NULL) return; /* No /names list got yet */

    if (mode == '@') nickrec->op = type == '+';
+   else if (mode == '~') nickrec->owner = type == '+';
+   else if (mode == '&') nickrec->admin = type == '+';
    else if (mode == '+') nickrec->voice = type == '+';
    else if (mode == '%') nickrec->halfop = type == '+';
    if (channel->server->prefix[(unsigned char) mode] != '\0') {
diff -r -U3 -p irssi-0.8.14/src/perl/irc/Channel.xs irssi-0.8.14n/src/perl/irc/Channel.xs
--- irssi-0.8.14/src/perl/irc/Channel.xs    2009-07-22 02:48:00.000000000 +0800
+++ irssi-0.8.14n/src/perl/irc/Channel.xs   2010-03-21 12:56:11.950774986 +0800
@@ -50,14 +50,16 @@ PPCODE:
    }

 Irssi::Irc::Nick
-irc_nick_insert(channel, nick, op, halfop, voice, send_massjoin)
+irc_nick_insert(channel, nick, owner, admin, op, halfop, voice, send_massjoin)
    Irssi::Irc::Channel channel
    char *nick
+   int owner
+   int admin
    int op
    int halfop
    int voice
    int send_massjoin
 CODE:
-   RETVAL = irc_nicklist_insert(channel, nick, op, halfop, voice, send_massjoin);
+   RETVAL = irc_nicklist_insert(channel, nick, owner, admin, op, halfop, voice, send_massjoin);
 OUTPUT:
    RETVAL
diff -r -U3 -p irssi-0.8.14/src/perl/perl-common.c irssi-0.8.14n/src/perl/perl-common.c
--- irssi-0.8.14/src/perl/perl-common.c 2009-07-22 02:48:01.000000000 +0800
+++ irssi-0.8.14n/src/perl/perl-common.c    2010-03-21 12:56:37.010774514 +0800
@@ -429,6 +429,8 @@ void perl_nick_fill_hash(HV *hv, NICK_RE
    hv_store(hv, "gone", 4, newSViv(nick->gone), 0);
    hv_store(hv, "serverop", 8, newSViv(nick->serverop), 0);

+   hv_store(hv, "owner", 5, newSViv(nick->owner), 0);
+   hv_store(hv, "admin", 5, newSViv(nick->admin), 0);
    hv_store(hv, "op", 2, newSViv(nick->op), 0);
    hv_store(hv, "halfop", 6, newSViv(nick->halfop), 0);
    hv_store(hv, "voice", 5, newSViv(nick->voice), 0);
irssibot commented 14 years ago

Greetings,

I've had a look at your patch, and here are some issues that would maybe have to be resolved before it could be accepted. Note that I'm not part of the irssi team, and I've got exactly zero lines of code in the irssi code base. (I've written a patch that addressed this issue before, though it was much simpler, and pretty much boiled down to counting anything "above" operators as operators in the output of /names -count. My patch got discarded because an ircd called inspircd requires that a user have +o for operator privileges. Anything above that alone does not confer operator privileges there.) Your patch calls +a'ds admins and +q'ds owners. I'm not sure if this nomenclature is 100% correct; I think it's more common to call +a'd people protected. Then there's another problem, in the following code: while (isnickflag(server, ptr)) { prefix_add(prefixes, ptr, (SERVER_REC ) server); switch (*ptr) {

irssibot commented 14 years ago

There is already code that tries to deal with every "non-standard" mode. we don't like more modes being added to the "standard" set, because they just aren't standard; as sneep says, they can differ from ircd to ircd. Changing the endofnames to be a huge message everywhere (even on servers that don't support any of those modes) is also something many users won't like.

Fixes or improvements to the generic handling of other modes would be most welcome. For example for the /names command, maybe a "/names -mode a" or "/names -mode ~" or something like that. For scripts, the other modes are already exposed as the 'other' attribute on a nick object.