3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-17 23:52:49 +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,19 +327,22 @@ 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))
if localentry:
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
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)
return
try: try:
entry = db[(remotenet, channel)] entry = db[(remotenet, channel)]
except KeyError: except KeyError:
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,24 +370,24 @@ 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 remotenet is None:
if (irc.name, channel) in db: # We own this channel utils.msg(irc, source, "Error: you must select a network to delink, or use the 'destroy' command no remove this relay entirely.")
if remotenet is None: return
utils.msg(irc, source, "Error: you must select a network to delink, or use the 'destroy' command no remove this relay entirely.") else:
return for entry in db.values():
for link in entry['links'].copy():
if link[0] == remotenet:
entry['links'].remove(link)
removeChannel(utils.networkobjects[remotenet], link[1])
else: else:
for entry in db.values(): db[entry]['links'].remove((irc.name, channel))
for link in entry['links'].copy(): removeChannel(irc, channel)
if link[0] == remotenet: utils.msg(irc, source, 'Done.')
entry['links'].remove(link)
removeChannel(utils.networkobjects[remotenet], link[1])
else: else:
entry['links'].remove((irc.name, channel)) utils.msg(irc, source, 'Error: no such relay %r.' % channel)
removeChannel(irc, channel)
utils.msg(irc, source, 'Done.')
def initializeAll(irc): def initializeAll(irc):
utils.started.wait() utils.started.wait()