3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-18 08:02:51 +01:00

relay: fix bugs with removing nonexistant channels in DELINK, and linking a channel multiple times in LINK

This commit is contained in:
James Lu 2015-07-13 22:54:51 -07:00
parent 1cbcec1001
commit 310a9201e2

View File

@ -327,11 +327,8 @@ def link(irc, source, args):
if remotenet not in utils.networkobjects: if remotenet not in utils.networkobjects:
utils.msg(irc, source, 'Error: no network named %r exists.' % remotenet) utils.msg(irc, source, 'Error: no network named %r exists.' % remotenet)
return return
if (irc.name, localchan) in db: localentry = findRelay((irc.name, localchan))
utils.msg(irc, source, 'Error: channel %r is already part of a relay.' % localchan) if localentry:
return
for dbentry in db.values():
if (irc.name, localchan) in dbentry['links']:
utils.msg(irc, source, 'Error: channel %r is already part of a relay.' % localchan) utils.msg(irc, source, 'Error: channel %r is already part of a relay.' % localchan)
return return
try: try:
@ -340,6 +337,12 @@ def link(irc, source, args):
utils.msg(irc, source, 'Error: no such relay %r exists.' % channel) utils.msg(irc, source, 'Error: no such relay %r exists.' % channel)
return return
else: else:
for link in entry['links']:
if link[0] == irc.name:
utils.msg(irc, source, "Error: remote channel '%s%s' is already"
" linked here as %r." % (remotenet,
channel, link[1]))
return
entry['links'].add((irc.name, localchan)) entry['links'].add((irc.name, localchan))
initializeChannel(irc, localchan) initializeChannel(irc, localchan)
utils.msg(irc, source, 'Done.') utils.msg(irc, source, 'Done.')
@ -367,11 +370,9 @@ def delink(irc, source, args):
if not utils.isChannel(channel): if not utils.isChannel(channel):
utils.msg(irc, source, 'Error: invalid channel %r.' % channel) utils.msg(irc, source, 'Error: invalid channel %r.' % channel)
return return
for dbentry in db.values(): entry = findRelay((irc.name, channel))
if (irc.name, channel) in dbentry['links']: if entry:
entry = dbentry if entry[0] == irc.name: # We own this channel.
break
if (irc.name, channel) in db: # We own this channel
if remotenet is None: if remotenet is None:
utils.msg(irc, source, "Error: you must select a network to delink, or use the 'destroy' command no remove this relay entirely.") utils.msg(irc, source, "Error: you must select a network to delink, or use the 'destroy' command no remove this relay entirely.")
return return
@ -382,9 +383,11 @@ def delink(irc, source, args):
entry['links'].remove(link) entry['links'].remove(link)
removeChannel(utils.networkobjects[remotenet], link[1]) removeChannel(utils.networkobjects[remotenet], link[1])
else: else:
entry['links'].remove((irc.name, channel)) db[entry]['links'].remove((irc.name, channel))
removeChannel(irc, channel) removeChannel(irc, channel)
utils.msg(irc, source, 'Done.') utils.msg(irc, source, 'Done.')
else:
utils.msg(irc, source, 'Error: no such relay %r.' % channel)
def initializeAll(irc): def initializeAll(irc):
utils.started.wait() utils.started.wait()