diff --git a/main.py b/main.py index c6edd6b..515a946 100755 --- a/main.py +++ b/main.py @@ -16,7 +16,7 @@ import utils class Irc(): def __init__(self, netname, proto, conf): # Initialize some variables - self.connected = False + self.connected = threading.Event() self.name = netname.lower() self.conf = conf # Server, channel, and user indexes to be populated by our protocol module @@ -62,11 +62,10 @@ class Irc(): log.error('(%s) Failed to connect to IRC: %s: %s', self.name, type(e).__name__, str(e)) self.disconnect() - self.connected = True self.run() def disconnect(self): - self.connected = False + self.connected.clear() self.socket.close() autoconnect = self.serverdata.get('autoconnect') if autoconnect is not None and autoconnect >= 0: @@ -77,7 +76,7 @@ class Irc(): def run(self): buf = "" data = "" - while self.connected: + while True: try: data = self.socket.recv(2048).decode("utf-8") buf += data @@ -91,6 +90,7 @@ class Irc(): log.error('(%s) Disconnected from IRC: %s: %s', self.name, type(e).__name__, str(e)) self.disconnect() + break def send(self, data): # Safeguard against newlines in input!! Otherwise, each line gets diff --git a/protocols/inspircd.py b/protocols/inspircd.py index 261ba70..11bd14c 100644 --- a/protocols/inspircd.py +++ b/protocols/inspircd.py @@ -540,6 +540,8 @@ def handle_events(irc, data): irc.umodes['*A'], irc.umodes['*B'], irc.umodes['*C'], irc.umodes['*D'] \ = caps['USERMODES'].split(',') irc.prefixmodes = re.search(r'\((.*?)\)', caps['PREFIX']).group(1) + # Sanity check: set this AFTER we fetch the capabilities for the network! + irc.connected.set() try: real_args = [] for arg in args: