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

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
Conflicts:
	server.py
  • Loading branch information
AMorporkian committed Feb 3, 2014
2 parents cbb52aa + d826215 commit eeae11c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
9 changes: 6 additions & 3 deletions plugins/announcer_plugin/announcer_plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from base_plugin import BasePlugin
from packets import connect_response


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

def after_connect_response(self, data):
try:
self.factory.broadcast(
self.protocol.player.colored_name(self.config.colors) + " joined.", 0, "", "Announcer")
c = connect_response().parse(data.data)
if c.success:
self.factory.broadcast(
self.protocol.player.colored_name(self.config.colors) + " joined.", 0, "", "Announcer")
except AttributeError:
self.logger.debug("Attribute error in after_connect_response.")
return
Expand All @@ -23,7 +26,7 @@ def after_connect_response(self, data):
raise

def on_client_disconnect(self, data):
if not self.protocol.player.logged_in:
if self.protocol.player is not None:
self.factory.broadcast(self.protocol.player.colored_name(self.config.colors) + " left.", 0,
"", "Announcer")

2 changes: 1 addition & 1 deletion plugins/core/player_manager/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def after_world_start(self, data):
self.protocol.player.on_ship = True

def on_client_disconnect(self, player):
if self.protocol.player.logged_in:
if self.protocol.player is not None and self.protocol.player.logged_in:
self.logger.info("Player disconnected: %s", self.protocol.player.name)
self.protocol.player.logged_in = False

Expand Down
37 changes: 16 additions & 21 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import datetime

import construct
import twisted
from twisted.internet import reactor
from twisted.internet.error import CannotListenError
from twisted.internet.protocol import ClientFactory, ServerFactory, Protocol, connectionDone, DatagramProtocol
Expand Down Expand Up @@ -110,7 +109,7 @@ def connectionMade(self):
self.plugin_manager = self.factory.plugin_manager
self.packet_stream = PacketStream(self)
self.packet_stream.direction = packets.Direction.CLIENT
logger.info("Connection established from IP: %s" % self.transport.getPeer().host)
logger.info("Connection established from IP: %s", self.transport.getPeer().host)
reactor.connectTCP(self.config.upstream_hostname, self.config.upstream_port,
StarboundClientFactory(self), timeout=self.config.server_connect_timeout)

Expand Down Expand Up @@ -431,32 +430,28 @@ def connectionLost(self, reason=connectionDone):
:return: None
"""
try:
x = build_packet(packets.Packets.CLIENT_DISCONNECT,
if self.client_protocol is not None:
x = build_packet(packets.Packets.CLIENT_DISCONNECT,
packets.client_disconnect().build(Container(data=0)))

if hasattr(self, "protocol") and self.protocol is not None:
if self.player is not None:
if self.player is not None and self.player.logged_in:
self.client_disconnect(x)
self.player.logged_in = False
self.player.protocol = None
if self.client_protocol is not None:
self.player = None
self.client_protocol.transport.write(x)
del self.client_protocol
except twisted.internet.error.ConnectionDone:
logger.debug("Connection was closed cleanly.")
except Exception as e:
logger.error("Couldn't disconnect protocol. %s", str(e))
self.client_protocol.transport.abortConnection()
except:
logger.error("Couldn't disconnect protocol.")
finally:
self.die()
try:
self.factory.protocols.pop(self.id)
except:
self.logger.trace("Protocol was not in factory list. This should not happen.")
finally:
logger.info("Lost connection from IP: %s", self.transport.getPeer().host)
self.transport.abortConnection()

def die(self):
if self.player is not None and self.player.protocol is not None:
self.transport.abortConnection()
self.factory.protocols.pop(self.id)
try:
self.client_protocol.transport.abortConnection()
except AttributeError:
pass
self.connectionLost()

def connectionFailed(self, *args, **kwargs):
self.connectionLost()
Expand Down

0 comments on commit eeae11c

Please sign in to comment.