@@ -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