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: if user.is_fake:
return return
if not var.DISABLE_ACCOUNTS: if user.account is not None:
self.DEAD_ACCOUNTS.add(user.lower().account) self.DEAD_ACCOUNTS.add(user.lower().account)
if not var.ACCOUNTS_ONLY: if not var.ACCOUNTS_ONLY:

View File

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

View File

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

View File

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