Skip to content
This repository was archived by the owner on Apr 27, 2019. It is now read-only.

Commit a1f73f6

Browse files
committed
Got rid of logging errors where it would say the connection did not close cleanly but it actually did.
1 parent e6395f9 commit a1f73f6

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

server.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import datetime
88

99
import construct
10+
import twisted
1011
from twisted.internet import reactor
1112
from twisted.internet.error import CannotListenError
1213
from twisted.internet.protocol import ClientFactory, ServerFactory, Protocol, connectionDone, DatagramProtocol
@@ -432,19 +433,24 @@ def connectionLost(self, reason=connectionDone):
432433
x = build_packet(packets.Packets.CLIENT_DISCONNECT,
433434
packets.client_disconnect().build(Container(data=0)))
434435

435-
if self.player is not None:
436-
if self.protocol is not None:
436+
if hasattr(self, "protocol") and self.protocol is not None:
437+
if self.player is not None:
437438
self.client_disconnect(x)
438439
self.player.logged_in = False
439440
self.player.protocol = None
440-
self.client_protocol.transport.write(x)
441-
except:
442-
logger.error("Couldn't disconnect protocol.")
441+
if self.client_protocol is not None:
442+
self.client_protocol.transport.write(x)
443+
del self.client_protocol
444+
except twisted.internet.error.ConnectionDone:
445+
logger.debug("Connection was closed cleanly.")
446+
except Exception as e:
447+
logger.error("Couldn't disconnect protocol. %s", str(e))
443448
finally:
444449
self.die()
445450

446451
def die(self):
447-
self.transport.abortConnection()
452+
if self.player.protocol is not None:
453+
self.transport.abortConnection()
448454
self.factory.protocols.pop(self.id)
449455
try:
450456
self.client_protocol.transport.abortConnection()

0 commit comments

Comments
 (0)