+
+ // 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++;
+ }