Made webclient aware of the server dropping (both websocket and AJAX). The server currently reacts to the websocket client dropping but not to the AJAX one (the latter forms ghost players)
This commit is contained in:
parent
c46e115901
commit
d5b3b59eb7
8 changed files with 51 additions and 37 deletions
|
|
@ -168,6 +168,8 @@ class Portal(object):
|
|||
# we get here due to us calling reactor.stop below. No need
|
||||
# to do the shutdown procedure again.
|
||||
return
|
||||
for session in self.sessions.itervalues():
|
||||
session.disconnect()
|
||||
self.set_restart_mode(restart)
|
||||
if os.name == 'nt' and os.path.exists(PORTAL_PIDFILE):
|
||||
# for Windows we need to remove pid files manually
|
||||
|
|
|
|||
|
|
@ -206,7 +206,6 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
|
|||
|
||||
def _write(self, data):
|
||||
"hook overloading the one used in plain telnet"
|
||||
print "Activated GMCP"
|
||||
data = data.replace('\n', '\r\n').replace('\r\r\n', '\r\n')
|
||||
#data = data.replace('\n', '\r\n')
|
||||
super(TelnetProtocol, self)._write(mccp_compress(self, data))
|
||||
|
|
@ -246,8 +245,7 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
|
|||
reason (str): Reason for disconnecting.
|
||||
|
||||
"""
|
||||
if reason:
|
||||
self.data_out(text=[[reason], {}])
|
||||
self.data_out(connection_close=((reason or "",), {}))
|
||||
self.connectionLost(reason)
|
||||
|
||||
def data_in(self, **kwargs):
|
||||
|
|
|
|||
|
|
@ -105,7 +105,6 @@ class TelnetOOB(object):
|
|||
"""
|
||||
# no msdp, check GMCP
|
||||
self.protocol.handshake_done()
|
||||
print "No MSDP."
|
||||
|
||||
def do_msdp(self, option):
|
||||
"""
|
||||
|
|
@ -118,7 +117,6 @@ class TelnetOOB(object):
|
|||
self.MSDP = True
|
||||
self.protocol.protocol_flags['OOB'] = True
|
||||
self.protocol.handshake_done()
|
||||
print "Activated MSDP"
|
||||
|
||||
def no_gmcp(self, option):
|
||||
"""
|
||||
|
|
@ -130,7 +128,6 @@ class TelnetOOB(object):
|
|||
|
||||
"""
|
||||
self.protocol.handshake_done()
|
||||
print "No GMCP."
|
||||
|
||||
def do_gmcp(self, option):
|
||||
"""
|
||||
|
|
@ -143,7 +140,6 @@ class TelnetOOB(object):
|
|||
self.GMCP = True
|
||||
self.protocol.protocol_flags['OOB'] = True
|
||||
self.protocol.handshake_done()
|
||||
print "Activated GMCP"
|
||||
|
||||
# encoders
|
||||
|
||||
|
|
@ -177,7 +173,7 @@ class TelnetOOB(object):
|
|||
if not (args or kwargs):
|
||||
return msdp_cmdname
|
||||
|
||||
print "encode_msdp in:", cmdname, args, kwargs
|
||||
#print "encode_msdp in:", cmdname, args, kwargs
|
||||
|
||||
msdp_args = ''
|
||||
if args:
|
||||
|
|
@ -210,7 +206,7 @@ class TelnetOOB(object):
|
|||
|
||||
msdp_string = msdp_args + msdp_kwargs
|
||||
|
||||
print "msdp_string:", msdp_string
|
||||
#print "msdp_string:", msdp_string
|
||||
return msdp_string
|
||||
|
||||
def encode_gmcp(self, cmdname, *args, **kwargs):
|
||||
|
|
@ -246,7 +242,7 @@ class TelnetOOB(object):
|
|||
else: # only kwargs
|
||||
gmcp_string = "%s %s" % (cmdname, json.dumps(kwargs))
|
||||
|
||||
print "gmcp string", gmcp_string
|
||||
#print "gmcp string", gmcp_string
|
||||
return gmcp_string
|
||||
|
||||
def decode_msdp(self, data):
|
||||
|
|
@ -276,7 +272,7 @@ class TelnetOOB(object):
|
|||
if hasattr(data, "__iter__"):
|
||||
data = "".join(data)
|
||||
|
||||
print "decode_msdp in:", data
|
||||
#print "decode_msdp in:", data
|
||||
|
||||
tables = {}
|
||||
arrays = {}
|
||||
|
|
@ -331,7 +327,7 @@ class TelnetOOB(object):
|
|||
for key, var in variables.iteritems():
|
||||
cmds[key] = [[var], {}]
|
||||
|
||||
print "msdp data in:", cmds
|
||||
#print "msdp data in:", cmds
|
||||
self.protocol.data_in(**cmds)
|
||||
|
||||
|
||||
|
|
@ -358,7 +354,7 @@ class TelnetOOB(object):
|
|||
if hasattr(data, "__iter__"):
|
||||
data = "".join(data)
|
||||
|
||||
print "decode_gmcp in:", data
|
||||
#print "decode_gmcp in:", data
|
||||
if data:
|
||||
try:
|
||||
cmdname, structure = data.split(None, 1)
|
||||
|
|
@ -398,7 +394,7 @@ class TelnetOOB(object):
|
|||
if self.MSDP:
|
||||
msdp_cmdname = cmdname
|
||||
encoded_oob = self.encode_msdp(msdp_cmdname, *args, **kwargs)
|
||||
print "sending MSDP:", encoded_oob
|
||||
#print "sending MSDP:", encoded_oob
|
||||
self.protocol._write(IAC + SB + MSDP + encoded_oob + IAC + SE)
|
||||
|
||||
if self.GMCP:
|
||||
|
|
@ -408,5 +404,5 @@ class TelnetOOB(object):
|
|||
gmcp_cmdname = "Custom.Cmd"
|
||||
kwargs["cmdname"] = cmdname
|
||||
encoded_oob = self.encode_gmcp(gmcp_cmdname, *args, **kwargs)
|
||||
print "sending GMCP:", encoded_oob
|
||||
#print "sending GMCP:", encoded_oob
|
||||
self.protocol._write(IAC + SB + GMCP + encoded_oob + IAC + SE)
|
||||
|
|
|
|||
|
|
@ -64,8 +64,7 @@ class WebSocketClient(Protocol, Session):
|
|||
reason (str): Motivation for the disconnection.
|
||||
|
||||
"""
|
||||
if reason:
|
||||
self.data_out(text=[[reason],{}])
|
||||
self.data_out(connection_close=((reason or "",), {}))
|
||||
self.connectionLost(reason)
|
||||
|
||||
def connectionLost(self, reason):
|
||||
|
|
@ -123,7 +122,6 @@ class WebSocketClient(Protocol, Session):
|
|||
if "websocket_close" in kwargs:
|
||||
self.disconnect()
|
||||
return
|
||||
print "websocket in:", kwargs
|
||||
self.sessionhandler.data_in(self, **kwargs)
|
||||
|
||||
def data_out(self, **kwargs):
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ from twisted.web import server, resource
|
|||
from django.utils.functional import Promise
|
||||
from django.utils.encoding import force_unicode
|
||||
from django.conf import settings
|
||||
from evennia.utils import utils, logger
|
||||
from evennia.utils import utils
|
||||
from evennia.utils.text2html import parse_html
|
||||
from evennia.server import session
|
||||
|
||||
|
|
@ -245,15 +245,14 @@ class WebClientSession(session.Session):
|
|||
This represents a session running in a webclient.
|
||||
"""
|
||||
|
||||
def disconnect(self, reason=None):
|
||||
def disconnect(self, reason="Server disconnected."):
|
||||
"""
|
||||
Disconnect from server.
|
||||
|
||||
Args:
|
||||
reason (str): Motivation for the disconnect.
|
||||
"""
|
||||
if reason:
|
||||
self.client.lineSend(self.suid, ["text", [reason], {}])
|
||||
self.client.lineSend(self.suid, ["connection_close", [reason], {}])
|
||||
self.client.client_disconnect(self.suid)
|
||||
|
||||
def data_out(self, **kwargs):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue