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

Commit ae87c2f

Browse files
committed
Added existence check for the Starbound port at startup. This should help debug issues with users who aren't starting up the starbound server.
1 parent 54501d6 commit ae87c2f

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

server.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
from uuid import uuid4
44
import sys
5+
import socket
56

67
import construct
78
from twisted.internet import reactor
@@ -415,7 +416,8 @@ def connectionLost(self, reason=connectionDone):
415416
:return: None
416417
"""
417418
try:
418-
x = build_packet(packets.Packets.CLIENT_DISCONNECT, packets.client_disconnect().build(Container(data=0)))
419+
x = build_packet(packets.Packets.CLIENT_DISCONNECT,
420+
packets.client_disconnect().build(Container(data=0)))
419421

420422
if self.player and self.player.logged_in:
421423
self.client_disconnect(x)
@@ -434,7 +436,6 @@ def die(self):
434436
pass
435437

436438

437-
438439
class ClientProtocol(Protocol):
439440
"""
440441
The protocol class which handles the connection to the Starbound server.
@@ -565,6 +566,14 @@ def buildProtocol(self, address):
565566

566567

567568
if __name__ == '__main__':
569+
config = ConfigurationManager()
570+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
571+
sock.settimeout(1)
572+
result = sock.connect_ex((config.server_hostname, config.server_port))
573+
if result != 0:
574+
print "The starbound server is not connectable at the address %s:%d." % (config.server_hostname, config.server_port)
575+
print "Please ensure that you are running starbound_server on the correct port and that is reflected in the StarryPy configuration."
576+
sys.exit()
568577
logger = logging.getLogger('starrypy')
569578
logger.setLevel(logging.DEBUG)
570579
fh_d = logging.FileHandler("debug.log")
@@ -583,6 +592,7 @@ def buildProtocol(self, address):
583592
logger.addHandler(fh_w)
584593
logger.debug("test")
585594
logger.info("Started server.")
595+
586596
factory = StarryPyServerFactory()
587597
reactor.listenTCP(21025, factory)
588598
reactor.run()

0 commit comments

Comments
 (0)