Redo DISABLE_ACCOUNTS handling

Only check it where absolutely necessary, and ensure in User that we
don't set accounts if we don't support them. This lets us ensure that
account is always None when account support is disabled, which means
that the existing None checks handle that without additional conditions.
This commit is contained in:
skizzerz 2018-04-13 17:09:42 -05:00
parent 41094a2cbc
commit 94cdfc0a55
4 changed files with 30 additions and 47 deletions

View File

@ -1094,7 +1094,7 @@ class MaelstromMode(GameMode):
if user.is_fake:
return
if not var.DISABLE_ACCOUNTS:
if user.account is not None:
self.DEAD_ACCOUNTS.add(user.lower().account)
if not var.ACCOUNTS_ONLY:

View File

@ -186,7 +186,7 @@ class User(IRCContext):
self._ident = ident
self._host = host
self.realname = realname
self.account = account
self.account = account if not var.DISABLE_ACCOUNTS else None
self.channels = {}
self.timestamp = time.time()
self.sets = []
@ -199,7 +199,7 @@ class User(IRCContext):
self.ident = ident
self.host = host
self.realname = realname
self.account = account
self.account = account if not var.DISABLE_ACCOUNTS else None
self.timestamp = time.time()
elif ident is not None and host is not None:
@ -330,7 +330,7 @@ class User(IRCContext):
hosts = set(botconfig.OWNERS)
accounts = set(botconfig.OWNERS_ACCOUNTS)
if not var.DISABLE_ACCOUNTS and self.account is not None:
if self.account is not None:
for pattern in accounts:
if fnmatch.fnmatch(lower(self.account), lower(pattern)):
return True
@ -352,7 +352,7 @@ class User(IRCContext):
hosts = set(botconfig.ADMINS)
accounts = set(botconfig.ADMINS_ACCOUNTS)
if not var.DISABLE_ACCOUNTS and self.account is not None:
if self.account is not None:
for pattern in accounts:
if fnmatch.fnmatch(lower(self.account), lower(pattern)):
return True
@ -417,11 +417,10 @@ class User(IRCContext):
def get_pingif_count(self):
temp = self.lower()
if not var.DISABLE_ACCOUNTS and temp.account is not None:
if temp.account in var.PING_IF_PREFS_ACCS:
return var.PING_IF_PREFS_ACCS[temp.account]
if temp.account in var.PING_IF_PREFS_ACCS:
return var.PING_IF_PREFS_ACCS[temp.account]
elif not var.ACCOUNTS_ONLY:
if not var.ACCOUNTS_ONLY:
for hostmask, pref in var.PING_IF_PREFS.items():
if temp.match_hostmask(hostmask):
return pref
@ -432,14 +431,13 @@ class User(IRCContext):
temp = self.lower()
if not value:
if not var.DISABLE_ACCOUNTS and temp.account:
if temp.account in var.PING_IF_PREFS_ACCS:
del var.PING_IF_PREFS_ACCS[temp.account]
db.set_pingif(0, temp.account, None)
if old is not None:
with var.WARNING_LOCK:
if old in var.PING_IF_NUMS_ACCS:
var.PING_IF_NUMS_ACCS[old].discard(temp.account)
if temp.account in var.PING_IF_PREFS_ACCS:
del var.PING_IF_PREFS_ACCS[temp.account]
db.set_pingif(0, temp.account, None)
if old is not None:
with var.WARNING_LOCK:
if old in var.PING_IF_NUMS_ACCS:
var.PING_IF_NUMS_ACCS[old].discard(temp.account)
if not var.ACCOUNTS_ONLY:
for hostmask in list(var.PING_IF_PREFS):
@ -453,7 +451,7 @@ class User(IRCContext):
var.PING_IF_NUMS[old].discard(temp.host)
else:
if not var.DISABLE_ACCOUNTS and temp.account:
if temp.account is not None:
var.PING_IF_PREFS_ACCS[temp.account] = value
db.set_pingif(value, temp.account, None)
with var.WARNING_LOCK:
@ -491,11 +489,7 @@ class User(IRCContext):
def stasis_count(self):
"""Return the number of games the user is in stasis for."""
temp = self.lower()
amount = 0
if not var.DISABLE_ACCOUNTS:
amount = var.STASISED_ACCS.get(temp.account, 0)
amount = var.STASISED_ACCS.get(temp.account, 0)
amount = max(amount, var.STASISED.get(temp.userhost, 0))
return amount
@ -552,7 +546,7 @@ class User(IRCContext):
@account.setter
def account(self, account):
if account in ("0", "*"):
if account in ("0", "*") or var.DISABLE_ACCOUNTS:
account = None
self._account = account

View File

@ -21,9 +21,8 @@ def is_user_stasised(nick):
else:
return -1
amount = 0
if not var.DISABLE_ACCOUNTS and acc and acc != "*":
if acc in var.STASISED_ACCS:
amount = var.STASISED_ACCS[acc]
if acc in var.STASISED_ACCS:
amount = var.STASISED_ACCS[acc]
for hostmask in var.STASISED:
if match_hostmask(hostmask, nick, ident, host):
amount = max(amount, var.STASISED[hostmask])
@ -57,8 +56,6 @@ def expire_tempbans():
def parse_warning_target(target, lower=False):
if target[0] == "=":
if var.DISABLE_ACCOUNTS:
return (None, None)
tacc = target[1:]
thm = None
if lower:
@ -79,13 +76,11 @@ def parse_warning_target(target, lower=False):
if lower:
hml, hmr = thm.split("@", 1)
thm = irc_lower(hml) + "@" + hmr.lower()
elif not var.DISABLE_ACCOUNTS:
else:
tacc = target
thm = None
if lower:
tacc = irc_lower(tacc)
else:
return (None, None)
return (tacc, thm)
def _get_auto_sanctions(sanctions, prev, cur):
@ -281,13 +276,9 @@ def fstasis(var, wrapper, message):
elif var.STASISED or var.STASISED_ACCS:
stasised = {}
for hostmask in var.STASISED:
if var.DISABLE_ACCOUNTS:
stasised[hostmask] = var.STASISED[hostmask]
else:
stasised[hostmask+" (Host)"] = var.STASISED[hostmask]
if not var.DISABLE_ACCOUNTS:
for acc in var.STASISED_ACCS:
stasised[acc+" (Account)"] = var.STASISED_ACCS[acc]
stasised[hostmask+" (Host)"] = var.STASISED[hostmask]
for acc in var.STASISED_ACCS:
stasised[acc+" (Account)"] = var.STASISED_ACCS[acc]
msg = messages["currently_stasised"].format(", ".join(
"\u0002{0}\u0002 ({1})".format(usr, number)
for usr, number in stasised.items()))

View File

@ -170,7 +170,7 @@ def connect_callback():
if request is channels.Main:
if "WHOX" not in hooks.Features:
if not var.DISABLE_ACCOUNTS:
plog("IRCd does not support accounts, disabling account-related features.")
plog("IRCd does not support WHOX, disabling account-related features.")
var.DISABLE_ACCOUNTS = True
var.ACCOUNTS_ONLY = False
@ -703,11 +703,10 @@ def join_timer_handler(var):
return
temp = user.lower()
if not var.DISABLE_ACCOUNTS and temp.account is not None:
if temp.account in chk_acc:
to_ping.append(temp)
var.PINGED_ALREADY_ACCS.add(temp.account)
return
if temp.account in chk_acc:
to_ping.append(temp)
var.PINGED_ALREADY_ACCS.add(temp.account)
return
if not var.ACCOUNTS_ONLY:
if temp.userhost in checker:
@ -2096,8 +2095,7 @@ def stop_game(winner="", abort=False, additional_winners=None, log=True):
"dced": False}
if plr in var.DCED_LOSERS:
pentry["dced"] = True
if not var.DISABLE_ACCOUNTS:
pentry["account"] = plr.account
pentry["account"] = plr.account
pentry["nick"] = plr.nick
pentry["ident"] = plr.ident
pentry["host"] = plr.host