mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 01:09:22 +01:00
relay: make separator a per-network config option
This commit is contained in:
parent
2bc0a65128
commit
ad34f6c4f9
@ -43,6 +43,9 @@ servers:
|
||||
# When more than two consecutive pings are missed, PyLink will disconnect with a ping timeout.
|
||||
pingfreq: 30
|
||||
|
||||
# Separator character (used by relay)
|
||||
separator: "/"
|
||||
|
||||
# Plugins to load (omit the .py extension)
|
||||
plugins:
|
||||
- commands
|
||||
|
@ -15,12 +15,15 @@ from log import log
|
||||
dbname = "pylinkrelay.db"
|
||||
relayusers = defaultdict(dict)
|
||||
|
||||
def normalizeNick(irc, netname, nick, separator="/"):
|
||||
def normalizeNick(irc, netname, nick, separator=None):
|
||||
# Block until we know the IRC network's nick length (after capabilities
|
||||
# are sent)
|
||||
log.debug('(%s) normalizeNick: waiting for irc.connected', irc.name)
|
||||
irc.connected.wait(1)
|
||||
|
||||
separator = separator or irc.serverdata.get('separator') or "/"
|
||||
log.debug('(%s) normalizeNick: using %r as separator.', irc.name, separator)
|
||||
|
||||
orig_nick = nick
|
||||
protoname = irc.proto.__name__
|
||||
maxnicklen = irc.maxnicklen
|
||||
@ -45,7 +48,7 @@ def normalizeNick(irc, netname, nick, separator="/"):
|
||||
|
||||
nick = nick[:allowedlength]
|
||||
nick += suffix
|
||||
# TODO: factorize
|
||||
# FIXME: factorize
|
||||
while utils.nickToUid(irc, nick) and not utils.isInternalClient(irc, utils.nickToUid(irc, nick)):
|
||||
# The nick we want exists? Darn, create another one then, but only if
|
||||
# the target isn't an internal client!
|
||||
@ -53,6 +56,7 @@ def normalizeNick(irc, netname, nick, separator="/"):
|
||||
# but couldn't be created due to a nick conflict.
|
||||
# This can happen when someone steals a relay user's nick.
|
||||
new_sep = separator + separator[-1]
|
||||
log.debug('(%s) normalizeNick: using %r as new_sep.', irc.name, separator)
|
||||
nick = normalizeNick(irc, netname, orig_nick, separator=new_sep)
|
||||
finalLength = len(nick)
|
||||
assert finalLength <= maxnicklen, "Normalized nick %r went over max " \
|
||||
|
Loading…
Reference in New Issue
Block a user