mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 12:42:34 +01:00
Fix some bugs I introduced with the conversion to utils.getSocket and improve
DCC's error checking.
This commit is contained in:
parent
1383da0f1a
commit
847227622f
@ -61,13 +61,12 @@ class DCC(callbacks.Privmsg):
|
||||
try:
|
||||
host = ircutils.hostFromHostmask(irc.prefix)
|
||||
try:
|
||||
inet = utils.getSocket(host)
|
||||
sock = utils.getSocket(host)
|
||||
except socket.error, e:
|
||||
s = 'Error connecting to %s: %s'
|
||||
self.log.warning(s, host, e)
|
||||
irc.replyError()
|
||||
return
|
||||
sock = socket.socket(inet, socket.SOCK_STREAM)
|
||||
sock.settimeout(60)
|
||||
if conf.supybot.externalIP():
|
||||
ip = conf.supybot.externalIP()
|
||||
@ -81,21 +80,32 @@ class DCC(callbacks.Privmsg):
|
||||
irc.replyError()
|
||||
return
|
||||
i = ircutils.dccIP(ip)
|
||||
sock.bind((host, 0))
|
||||
try:
|
||||
sock.bind((host, 0))
|
||||
except socket.error, e:
|
||||
irc.error('Unable to initiate DCC CHAT.')
|
||||
return
|
||||
port = sock.getsockname()[1]
|
||||
self.log.info('DCC CHAT port opened at (%s, %s)', host, port)
|
||||
sock.listen(1)
|
||||
irc.queueMsg(ircmsgs.privmsg(msg.nick,
|
||||
'\x01DCC CHAT chat %s %s\x01' % \
|
||||
(i, port)))
|
||||
(realSock, addr) = sock.accept()
|
||||
try:
|
||||
(realSock, addr) = sock.accept()
|
||||
except socket.timeout:
|
||||
self.log.info('DCC CHAT timed out.')
|
||||
return
|
||||
self.log.info('DCC CHAT accepted from %s', addr)
|
||||
for line in textwrap.wrap(text, 80):
|
||||
realSock.send(line)
|
||||
realSock.send('\n')
|
||||
finally:
|
||||
self.log.info('Finally closing sock and realSock.')
|
||||
sock.close()
|
||||
try:
|
||||
sock.close()
|
||||
except UnboundLocalError:
|
||||
pass
|
||||
try:
|
||||
realSock.close()
|
||||
except UnboundLocalError:
|
||||
@ -104,7 +114,7 @@ class DCC(callbacks.Privmsg):
|
||||
world.threadsSpawned += 1
|
||||
t.setDaemon(True)
|
||||
t.start()
|
||||
|
||||
|
||||
|
||||
|
||||
Class = DCC
|
||||
|
@ -140,12 +140,11 @@ class SocketDriver(drivers.IrcDriver):
|
||||
return
|
||||
self.irc.reset()
|
||||
try:
|
||||
inet = utils.getSocket(self.server[0])
|
||||
self.conn = utils.getSocket(self.server[0])
|
||||
except socket.error, e:
|
||||
log.warning('Error connecting to %s: %s', self.server[0], e)
|
||||
self.reconnect(wait=True)
|
||||
return
|
||||
self.conn = socket.socket(inet, socket.SOCK_STREAM)
|
||||
# We allow more time for the connect here, since it might take longer.
|
||||
# At least 10 seconds.
|
||||
self.conn.settimeout(max(10, conf.supybot.drivers.poll()*10))
|
||||
|
@ -564,9 +564,9 @@ def getSocket(host):
|
||||
except socket.error:
|
||||
raise
|
||||
if isIP(host):
|
||||
return socket.socket(socket.INET, socket.SOCK_STREAM)
|
||||
return socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
elif isIPV6(host):
|
||||
return socket.socket(socket.INET6, socket.SOCK_STREAM)
|
||||
return socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
|
||||
else:
|
||||
raise socket.error, 'Something wonky happened.'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user