3
0
mirror of https://github.com/jlu5/PyLink.git synced 2025-02-02 23:54:08 +01:00

make Irc.connected a threaded event object, setting it to True ONLY when we receive server capabilities from our uplink

The previous behavior set this to True as soon as we ran connect(), but this caused problems because the default capabilities (i.e. nicklen)
that Irc() initializes won't match the real value of the network.
This commit is contained in:
James Lu 2015-07-15 13:49:12 -07:00
parent 8d914720b3
commit 6e37e1c05d
2 changed files with 6 additions and 4 deletions

View File

@ -16,7 +16,7 @@ import utils
class Irc(): class Irc():
def __init__(self, netname, proto, conf): def __init__(self, netname, proto, conf):
# Initialize some variables # Initialize some variables
self.connected = False self.connected = threading.Event()
self.name = netname.lower() self.name = netname.lower()
self.conf = conf self.conf = conf
# Server, channel, and user indexes to be populated by our protocol module # 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', log.error('(%s) Failed to connect to IRC: %s: %s',
self.name, type(e).__name__, str(e)) self.name, type(e).__name__, str(e))
self.disconnect() self.disconnect()
self.connected = True
self.run() self.run()
def disconnect(self): def disconnect(self):
self.connected = False self.connected.clear()
self.socket.close() self.socket.close()
autoconnect = self.serverdata.get('autoconnect') autoconnect = self.serverdata.get('autoconnect')
if autoconnect is not None and autoconnect >= 0: if autoconnect is not None and autoconnect >= 0:
@ -77,7 +76,7 @@ class Irc():
def run(self): def run(self):
buf = "" buf = ""
data = "" data = ""
while self.connected: while True:
try: try:
data = self.socket.recv(2048).decode("utf-8") data = self.socket.recv(2048).decode("utf-8")
buf += data buf += data
@ -91,6 +90,7 @@ class Irc():
log.error('(%s) Disconnected from IRC: %s: %s', log.error('(%s) Disconnected from IRC: %s: %s',
self.name, type(e).__name__, str(e)) self.name, type(e).__name__, str(e))
self.disconnect() self.disconnect()
break
def send(self, data): def send(self, data):
# Safeguard against newlines in input!! Otherwise, each line gets # Safeguard against newlines in input!! Otherwise, each line gets

View File

@ -540,6 +540,8 @@ def handle_events(irc, data):
irc.umodes['*A'], irc.umodes['*B'], irc.umodes['*C'], irc.umodes['*D'] \ irc.umodes['*A'], irc.umodes['*B'], irc.umodes['*C'], irc.umodes['*D'] \
= caps['USERMODES'].split(',') = caps['USERMODES'].split(',')
irc.prefixmodes = re.search(r'\((.*?)\)', caps['PREFIX']).group(1) 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: try:
real_args = [] real_args = []
for arg in args: for arg in args: