Fix RPL_ISUPPORT parsing
Instead of trying to guess what format a token is based on its content, hardcode a list of known tokens and what formats their parameters take. Any unknown token will therefore be kept as a string, instead of potentially blowing up parsing due to unexpected values (such as multiple colons). Also fix parsing for colon-separated lists. MAXLIST=beI:100 is *VERY* different from MAXLIST=b:100,e:100,I:100 but our previous processing made the two identical in terms of what the structure looked like.
This commit is contained in:
parent
5a0a519d27
commit
68109a12ae
37
src/hooks.py
37
src/hooks.py
@ -209,35 +209,42 @@ def get_features(cli, rawnick, *features):
|
||||
|
||||
"""
|
||||
|
||||
# features with params (key:value, possibly multiple separated by comma)
|
||||
comma_param_features = ("CHANLIMIT", "MAXLIST", "TARGMAX", "IDCHAN")
|
||||
# features with a prefix in parens
|
||||
prefix_features = ("PREFIX",)
|
||||
# features which take multiple arguments separated by comma (but are not params)
|
||||
# Note: CMDS is specific to UnrealIRCD
|
||||
comma_list_features = ("CHANMODES", "EXTBAN", "CMDS")
|
||||
# features which take multiple argumenst separated by semicolon (but are not params)
|
||||
# Note: SSL is specific to InspIRCD
|
||||
semi_list_features = ("SSL",)
|
||||
|
||||
for feature in features:
|
||||
if "=" in feature:
|
||||
name, data = feature.split("=")
|
||||
if ":" in data:
|
||||
if name in comma_param_features:
|
||||
Features[name] = {}
|
||||
for param in data.split(","):
|
||||
param, value = param.split(":")
|
||||
if param.isupper():
|
||||
settings = [param]
|
||||
else:
|
||||
settings = param
|
||||
if value.isdigit():
|
||||
value = int(value)
|
||||
elif not value:
|
||||
value = None
|
||||
Features[name][param] = value
|
||||
|
||||
for setting in settings:
|
||||
res = value
|
||||
if res.isdigit():
|
||||
res = int(res)
|
||||
elif not res:
|
||||
res = None
|
||||
Features[name][setting] = res
|
||||
|
||||
elif "(" in data and ")" in data:
|
||||
elif name in prefix_features:
|
||||
gen = (x for y in data.split("(") for x in y.split(")") if x)
|
||||
# Reverse the order
|
||||
value = next(gen)
|
||||
Features[name] = dict(zip(next(gen), value))
|
||||
|
||||
elif "," in data:
|
||||
elif name in comma_list_features:
|
||||
Features[name] = data.split(",")
|
||||
|
||||
elif name in semi_list_features:
|
||||
Features[name] = data.split(";")
|
||||
|
||||
else:
|
||||
if data.isdigit():
|
||||
data = int(data)
|
||||
|
Loading…
x
Reference in New Issue
Block a user