mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 01:09:22 +01:00
Make sure the PyLink client rejoins all relay channels on KILL
This adds a new internal hook, 'PYLINK_SPAWNMAIN', which is triggered whenever Irc().spawnMain() is called.
This commit is contained in:
parent
f93349ae1f
commit
821f546f12
@ -7,7 +7,7 @@ from log import log
|
||||
def handle_kill(irc, source, command, args):
|
||||
if args['target'] == irc.pseudoclient.uid:
|
||||
irc.spawnMain()
|
||||
utils.add_hook(handle_kill, 'KILL')
|
||||
utils.add_hook(handle_kill, 'KILL')
|
||||
|
||||
# Handle KICKs to the PyLink client, rejoining the channels
|
||||
def handle_kick(irc, source, command, args):
|
||||
@ -15,7 +15,7 @@ def handle_kick(irc, source, command, args):
|
||||
channel = args['channel']
|
||||
if kicked == irc.pseudoclient.uid:
|
||||
irc.proto.joinClient(irc, irc.pseudoclient.uid, channel)
|
||||
utils.add_hook(handle_kick, 'KICK')
|
||||
utils.add_hook(handle_kick, 'KICK')
|
||||
|
||||
# Handle commands sent to the PyLink client (PRIVMSG)
|
||||
def handle_commands(irc, source, command, args):
|
||||
|
8
main.py
8
main.py
@ -19,9 +19,10 @@ import coreplugin
|
||||
class Irc():
|
||||
|
||||
def initVars(self):
|
||||
# Server, channel, and user indexes to be populated by our protocol module
|
||||
self.pseudoclient = None
|
||||
self.connected = threading.Event()
|
||||
self.lastping = time.time()
|
||||
# Server, channel, and user indexes to be populated by our protocol module
|
||||
self.servers = {self.sid: classes.IrcServer(None, self.serverdata['hostname'], internal=True)}
|
||||
self.users = {}
|
||||
self.channels = defaultdict(classes.IrcChannel)
|
||||
@ -162,6 +163,7 @@ class Irc():
|
||||
self.pingTimer.cancel()
|
||||
except: # Socket timed out during creation; ignore
|
||||
pass
|
||||
# Internal hook signifying that a network has disconnected.
|
||||
self.callHooks([None, 'PYLINK_DISCONNECT', {}])
|
||||
|
||||
def run(self):
|
||||
@ -244,9 +246,13 @@ class Irc():
|
||||
ident = self.botdata.get('ident') or 'pylink'
|
||||
host = self.serverdata["hostname"]
|
||||
log.info('(%s) Connected! Spawning main client %s.', self.name, nick)
|
||||
olduserobj = self.pseudoclient
|
||||
self.pseudoclient = self.proto.spawnClient(self, nick, ident, host, modes={("+o", None)})
|
||||
for chan in self.serverdata['channels']:
|
||||
self.proto.joinClient(self, self.pseudoclient.uid, chan)
|
||||
# PyLink internal hook called when spawnMain is called and the
|
||||
# contents of Irc().pseudoclient change.
|
||||
self.callHooks([self.sid, 'PYLINK_SPAWNMAIN', {'olduser': olduserobj}])
|
||||
|
||||
if __name__ == '__main__':
|
||||
log.info('PyLink starting...')
|
||||
|
@ -256,11 +256,10 @@ def handle_join(irc, numeric, command, args):
|
||||
utils.add_hook(handle_join, 'JOIN')
|
||||
|
||||
def handle_quit(irc, numeric, command, args):
|
||||
ouruser = numeric
|
||||
for netname, user in relayusers[(irc.name, numeric)].copy().items():
|
||||
remoteirc = utils.networkobjects[netname]
|
||||
remoteirc.proto.quitClient(remoteirc, user, args['text'])
|
||||
del relayusers[(irc.name, ouruser)]
|
||||
del relayusers[(irc.name, numeric)]
|
||||
utils.add_hook(handle_quit, 'QUIT')
|
||||
|
||||
def handle_squit(irc, numeric, command, args):
|
||||
@ -621,13 +620,13 @@ def handle_kill(irc, numeric, command, args):
|
||||
# client and rejoin it to its channels.
|
||||
del relayusers[realuser][irc.name]
|
||||
remoteirc = utils.networkobjects[realuser[0]]
|
||||
for channel in remoteirc.channels:
|
||||
remotechan = findRemoteChan(remoteirc, irc, channel)
|
||||
if remotechan:
|
||||
modes = getPrefixModes(remoteirc, irc, remotechan, realuser[1])
|
||||
for remotechan in remoteirc.channels:
|
||||
localchan = findRemoteChan(remoteirc, irc, remotechan)
|
||||
if localchan:
|
||||
modes = getPrefixModes(remoteirc, irc, localchan, realuser[1])
|
||||
log.debug('(%s) relay handle_kill: userpair: %s, %s', irc.name, modes, realuser)
|
||||
client = getRemoteUser(remoteirc, irc, realuser[1])
|
||||
irc.proto.sjoinServer(irc, irc.sid, remotechan, [(modes, client)])
|
||||
irc.proto.sjoinServer(irc, irc.sid, localchan, [(modes, client)])
|
||||
if userdata and numeric in irc.users:
|
||||
utils.msg(irc, numeric, "Your kill to %s has been blocked "
|
||||
"because PyLink does not allow killing"
|
||||
@ -947,3 +946,10 @@ def handle_away(irc, numeric, command, args):
|
||||
remoteirc = utils.networkobjects[netname]
|
||||
remoteirc.proto.awayClient(remoteirc, user, args['text'])
|
||||
utils.add_hook(handle_away, 'AWAY')
|
||||
|
||||
def handle_spawnmain(irc, numeric, command, args):
|
||||
if args['olduser']:
|
||||
# Kills to the main PyLink client force reinitialization; this makes sure
|
||||
# it joins all the relay channels like it's supposed to.
|
||||
initializeAll(irc)
|
||||
utils.add_hook(handle_spawnmain, 'PYLINK_SPAWNMAIN')
|
||||
|
Loading…
Reference in New Issue
Block a user