3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-27 21:19:31 +01:00

Merge branch 'wip/relay/better-normalizehost' into devel

Conflicts:
	plugins/relay.py
This commit is contained in:
James Lu 2016-12-19 00:01:16 -08:00
commit 1765d61973

View File

@ -176,21 +176,19 @@ def normalize_host(irc, host):
"""Creates a normalized hostname for the given host suitable for
introduction to a remote network (as a relay client)."""
log.debug('(%s) relay.normalize_host: IRCd=%s, host=%s', irc.name, irc.protoname, host)
if irc.protoname not in ('inspircd', 'ts6', 'clientbot', 'nefarious'):
# UnrealIRCd and IRCd-Hybrid don't allow slashes in hostnames
host = host.replace('/', '.')
if irc.protoname in ('ts6', 'ratbox'):
# TS6 doesn't allow _ in hosts.
host = host.replace('_', '.')
host = host.replace('\x03', '') # Strip colours
host = host.replace('\x02', '') # Strip bold
host = host.replace('\x1f', '') # Strip underline
host = host.replace('\x1d', '') # Strip italic
host = host.replace('\x0f', '') # Strip color reset
host = host.replace('\x16', '') # Strip reverse color
# And no, I'm not supporting colours in hosts. Screw your IRCd-breaking patches if you think
# this is cool. -GL
allowed_chars = string.ascii_letters + string.digits + '-.:'
if irc.protoname in ('inspircd', 'ts6', 'clientbot', 'nefarious'):
# UnrealIRCd and IRCd-Hybrid don't allow slashes in hostnames
allowed_chars += '/'
if irc.protoname in ('inspircd', 'clientbot', 'nefarious', 'unreal'):
# The above IRCds allow _ in hostnames, while TS6-like IRCds do not.
allowed_chars += '_'
for char in host:
if char not in allowed_chars:
host = host.replace(char, '-')
return host[:63] # Limit hosts to 63 chars for best compatibility