22import logging
33from uuid import uuid4
44import sys
5+ import socket
56
67import construct
78from 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-
438439class 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
567568if __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