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