Commit ecf22cb4 authored by louiz’'s avatar louiz’
Browse files

Fix all the connect() reconnect() stuff

The /reconnect command should now properly work everytime.
parent a404195a
......@@ -807,6 +807,9 @@ def command_quit(self, arg=''):
"""
/quit
"""
if not self.xmpp.is_connected():
self.exit()
return
if len(arg.strip()) != 0:
msg = arg
else:
......@@ -820,8 +823,7 @@ def command_quit(self, arg=''):
self.save_config()
self.plugin_manager.disable_plugins()
self.disconnect(msg)
self.running = False
self.reset_curses()
self.xmpp.add_event_handler("disconnected", self.exit, disposable=True)
def command_destroy_room(self, arg=''):
"""
......
......@@ -9,6 +9,7 @@ import logging
log = logging.getLogger(__name__)
import asyncio
import collections
import curses
import os
......@@ -189,6 +190,7 @@ class Core(object):
# Add handlers
self.xmpp.add_event_handler('connected', self.on_connected)
self.xmpp.add_event_handler('connection_failed', self.on_failed_connection)
self.xmpp.add_event_handler('disconnected', self.on_disconnected)
self.xmpp.add_event_handler('failed_auth', self.on_failed_auth)
self.xmpp.add_event_handler('no_auth', self.on_no_auth)
......@@ -427,13 +429,8 @@ class Core(object):
if config.get('enable_user_gaming', True):
self.xmpp.plugin['xep_0196'].stop(block=False)
self.plugin_manager.disable_plugins()
self.disconnect('')
self.running = False
try:
self.reset_curses()
except: # too bad
pass
sys.exit()
self.disconnect('%s received' % signals.get(sig))
self.xmpp.add_event_handler("disconnected", self.exit, disposable=True)
def autoload_plugins(self):
"""
......@@ -470,6 +467,10 @@ class Core(object):
self.refresh_window()
self.xmpp.plugin['xep_0012'].begin_idle(jid=self.xmpp.boundjid)
def exit(self, event=None):
log.debug("exit(%s)" % (event,))
asyncio.get_event_loop().stop()
def on_exception(self, typ, value, trace):
"""
When an exception is raised, just reset curses and call
......@@ -786,7 +787,9 @@ class Core(object):
tab.command_part(msg)
self.xmpp.disconnect()
if reconnect:
self.xmpp.start()
# Add a one-time event to reconnect as soon as we are
# effectively disconnected
self.xmpp.add_event_handler('disconnected', lambda event: self.xmpp.connect(), disposable=True)
def send_message(self, msg):
"""
......
......@@ -812,11 +812,11 @@ def on_groupchat_presence(self, presence):
### Connection-related handlers ###
def on_failed_connection(self):
def on_failed_connection(self, error):
"""
We cannot contact the remote server
"""
self.information(_("Connection to remote server failed"), _('Error'))
self.information(_("Connection to remote server failed: %s" % (error,)), _('Error'))
def on_disconnected(self, event):
"""
......
......@@ -241,7 +241,10 @@ class RosterInfoTab(Tab):
"""
/reconnect
"""
self.core.disconnect(reconnect=True)
if self.core.xmpp.is_connected():
self.core.disconnect(reconnect=True)
else:
self.core.xmpp.connect()
def command_disconnect(self, args=None):
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment