From: Matthew Beeching Date: Wed, 16 Jul 2014 21:30:18 +0000 (+0100) Subject: Updated ChanServ.netinfo oper count to only include opers who do not have user modes... X-Git-Url: https://jfr.im/git/irc/evilnet/x3.git/commitdiff_plain/dc92ef7c98f927c3f3ede840d6510a968467df99 Updated ChanServ.netinfo oper count to only include opers who do not have user modes +H, +k or +B --- diff --git a/src/chanserv.c b/src/chanserv.c index e8b349d..5c54290 100644 --- a/src/chanserv.c +++ b/src/chanserv.c @@ -5534,7 +5534,7 @@ static CHANSERV_FUNC(cmd_netinfo) reply("CSMSG_NETWORK_INFO"); reply("CSMSG_NETWORK_SERVERS", dict_size(servers)); reply("CSMSG_NETWORK_USERS", dict_size(clients)); - reply("CSMSG_NETWORK_OPERS", curr_opers.used); + reply("CSMSG_NETWORK_OPERS", count_opers); reply("CSMSG_NETWORK_CHANNELS", registered_channels); reply("CSMSG_NETWORK_LAMERS", banCount); reply("CSMSG_NETWORK_CHANUSERS", userCount); @@ -5579,14 +5579,14 @@ send_staff_list(struct userNode *to, struct userList *list, int skip_flags) static CHANSERV_FUNC(cmd_ircops) { reply("CSMSG_STAFF_OPERS"); - send_staff_list(user, &curr_opers, FLAGS_SERVICE); + send_staff_list(user, &curr_opers, FLAGS_SERVICE | FLAGS_BOT); return 1; } static CHANSERV_FUNC(cmd_helpers) { reply("CSMSG_STAFF_HELPERS"); - send_staff_list(user, &curr_helpers, FLAGS_OPER); + send_staff_list(user, &curr_helpers, FLAGS_OPER | FLAGS_SERVICE | FLAGS_BOT); return 1; } diff --git a/src/hash.c b/src/hash.c index 1adfeca..492599d 100644 --- a/src/hash.c +++ b/src/hash.c @@ -38,6 +38,7 @@ dict_t servers; unsigned int max_clients, invis_clients; time_t max_clients_time; struct userList curr_opers; +unsigned int count_opers; static void hash_cleanup(void *extra); @@ -47,6 +48,7 @@ void init_structs(void) clients = dict_new(); servers = dict_new(); userList_init(&curr_opers); + count_opers = 0; reg_exit_func(hash_cleanup, NULL); } @@ -1056,6 +1058,7 @@ hash_cleanup(UNUSED_ARG(void *extra)) dict_delete(clients); dict_delete(servers); userList_clean(&curr_opers); + count_opers = 0; free(slf_list); free(slf_list_extra); diff --git a/src/hash.h b/src/hash.h index 66e9419..2e81f25 100644 --- a/src/hash.h +++ b/src/hash.h @@ -392,6 +392,8 @@ extern unsigned int max_clients, invis_clients; extern time_t max_clients_time; extern struct userList curr_opers, curr_helpers; +extern unsigned int count_opers; + struct server* GetServerH(const char *name); /* using full name */ struct userNode* GetUserH(const char *nick); /* using nick */ struct chanNode* GetChannel(const char *name); diff --git a/src/proto-p10.c b/src/proto-p10.c index ff115ba..c36a920 100644 --- a/src/proto-p10.c +++ b/src/proto-p10.c @@ -3250,8 +3250,11 @@ DelUser(struct userNode* user, struct userNode *killer, int announce, const char user->uplink->clients--; user->uplink->users[user->num_local] = NULL; - if (IsOper(user)) + if (IsOper(user)) { userList_remove(&curr_opers, user); + if (count_opers > 0 && !IsBotM(user) && !IsService(user) && !IsHideOper(user)) + count_opers--; + } /* remove from global dictionary, but not if after a collide */ if (user == dict_find(clients, user->nick, NULL)) dict_remove(clients, user->nick); @@ -3316,6 +3319,8 @@ static void call_oper_funcs(struct userNode *user); void mod_usermode(struct userNode *user, const char *mode_change) { int add = 1; + long setmodes = 0; + int donemodes = 0; const char *word = mode_change; if (!user || !mode_change) @@ -3323,12 +3328,16 @@ void mod_usermode(struct userNode *user, const char *mode_change) { call_user_mode_funcs(user, mode_change); + setmodes = user->modes; + while (*word != ' ' && *word) word++; while (*word == ' ') word++; - while (1) { + while (!donemodes) { #define do_user_mode(FLAG) do { if (add) user->modes |= FLAG; else user->modes &= ~FLAG; } while (0) switch (*mode_change++) { - case 0: case ' ': return; + case 0: case ' ': + donemodes = 1; + break; case '+': add = 1; break; case '-': add = 0; break; case 'o': @@ -3431,6 +3440,37 @@ void mod_usermode(struct userNode *user, const char *mode_change) { } #undef do_user_mode } + + // Set user mode +o + if (!(setmodes & FLAGS_OPER) && IsOper(user)) { + if (!IsBotM(user) && !IsService(user) && !IsHideOper(user)) + count_opers++; + } + + // Set user mode -o + if ((setmodes & FLAGS_OPER) && !IsOper(user)) { + if (count_opers > 1 && !(setmodes & FLAGS_BOT) && + !(setmodes & FLAGS_SERVICE) && !(setmodes & FLAGS_HIDEOPER)) + count_opers--; + } + + // Set +H, +k or +B + if (!(setmodes & FLAGS_HIDEOPER) && + !(setmodes & FLAGS_SERVICE) && + !(setmodes & FLAGS_BOT) && + (IsHideOper(user) || IsService(user) || IsBotM(user))) { + if ((setmodes & FLAGS_OPER) && IsOper(user) && count_opers > 0) + count_opers--; + } + + // Set -H, -k or -B + if (((setmodes & FLAGS_HIDEOPER) || + (setmodes & FLAGS_SERVICE) || + (setmodes & FLAGS_BOT)) && + !IsHideOper(user) && !IsService(user) && !IsBotM(user)) { + if ((setmodes & FLAGS_OPER) && IsOper(user)) + count_opers++; + } } static int