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

Commit d826215

Browse files
committed
Simplified disconnection logic. I believe this *should* fix the player full message.
1 parent 4d092d6 commit d826215

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

plugins/announcer_plugin/announcer_plugin.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from base_plugin import BasePlugin
2+
from packets import connect_response
23

34

45
class Announcer(BasePlugin):
@@ -13,8 +14,10 @@ def activate(self):
1314

1415
def after_connect_response(self, data):
1516
try:
16-
self.factory.broadcast(
17-
self.protocol.player.colored_name(self.config.colors) + " joined.", 0, "", "Announcer")
17+
c = connect_response().parse(data.data)
18+
if c.success:
19+
self.factory.broadcast(
20+
self.protocol.player.colored_name(self.config.colors) + " joined.", 0, "", "Announcer")
1821
except AttributeError:
1922
self.logger.debug("Attribute error in after_connect_response.")
2023
return
@@ -23,7 +26,7 @@ def after_connect_response(self, data):
2326
raise
2427

2528
def on_client_disconnect(self, data):
26-
if not self.protocol.player.logged_in:
29+
if self.protocol.player is not None:
2730
self.factory.broadcast(self.protocol.player.colored_name(self.config.colors) + " left.", 0,
2831
"", "Announcer")
2932

plugins/core/player_manager/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def after_world_start(self, data):
100100
self.protocol.player.on_ship = True
101101

102102
def on_client_disconnect(self, player):
103-
if self.protocol.player.logged_in:
103+
if self.protocol.player is not None and self.protocol.player.logged_in:
104104
self.logger.info("Player disconnected: %s", self.protocol.player.name)
105105
self.protocol.player.logged_in = False
106106

server.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def connectionMade(self):
109109
self.plugin_manager = self.factory.plugin_manager
110110
self.packet_stream = PacketStream(self)
111111
self.packet_stream.direction = packets.Direction.CLIENT
112-
logger.info("Connection established from IP: %s" % self.transport.getPeer().host)
112+
logger.info("Connection established from IP: %s", self.transport.getPeer().host)
113113
reactor.connectTCP(self.config.upstream_hostname, self.config.upstream_port,
114114
StarboundClientFactory(self), timeout=self.config.server_connect_timeout)
115115

@@ -402,7 +402,8 @@ def send_chat_message(self, text, channel=0, world='', name=''):
402402
for line in lines:
403403
self.send_chat_message(line)
404404
return
405-
logger.trace("Calling send_chat_message from player %s on channel %d on world '%s' with reported username of %s with message: %s", self.player.name, channel, world, name, text)
405+
if self.player is not None:
406+
logger.trace("Calling send_chat_message from player %s on channel %d on world '%s' with reported username of %s with message: %s", self.player.name, channel, world, name, text)
406407
chat_data = packets.chat_received().build(Container(chat_channel=channel,
407408
world=world,
408409
client_id=0,
@@ -429,27 +430,28 @@ def connectionLost(self, reason=connectionDone):
429430
:return: None
430431
"""
431432
try:
432-
x = build_packet(packets.Packets.CLIENT_DISCONNECT,
433+
if self.client_protocol is not None:
434+
x = build_packet(packets.Packets.CLIENT_DISCONNECT,
433435
packets.client_disconnect().build(Container(data=0)))
434-
435-
if self.player is not None:
436-
if self.protocol is None:
436+
if self.player is not None and self.player.logged_in:
437437
self.client_disconnect(x)
438-
self.player.logged_in = False
439438
self.player.protocol = None
440-
self.client_protocol.transport.write(x)
439+
self.player = None
440+
self.client_protocol.transport.write(x)
441+
self.client_protocol.transport.abortConnection()
441442
except:
442443
logger.error("Couldn't disconnect protocol.")
443444
finally:
444-
self.die()
445+
try:
446+
self.factory.protocols.pop(self.id)
447+
except:
448+
self.logger.trace("Protocol was not in factory list. This should not happen.")
449+
finally:
450+
logger.info("Lost connection from IP: %s", self.transport.getPeer().host)
451+
self.transport.abortConnection()
445452

446453
def die(self):
447-
self.transport.abortConnection()
448-
self.factory.protocols.pop(self.id)
449-
try:
450-
self.client_protocol.transport.abortConnection()
451-
except AttributeError:
452-
pass
454+
self.connectionLost()
453455

454456
def connectionFailed(self, *args, **kwargs):
455457
self.connectionLost()

0 commit comments

Comments
 (0)