From 71af5514da064162a85609345b404235cf3c67e4 Mon Sep 17 00:00:00 2001 From: Jamie Doornbos Date: Fri, 14 Nov 2008 01:49:58 +0000 Subject: [PATCH] Be nicely behaved if the user manages to close the client before the socket is opened * Use _writer != null iff the socket is open and the authrequest has been sent * Warn when posting messages prior to socket connect * Clear the outgoing queue prior to sending the auth request, the servers authing connection expects this * If a logoff is encountered prior to the socket opening, just shut down without sending auth request * Driveby unused variable removal This should fix the log warning "AuthingConnection$1: Received non-authreq message during authentication process" git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5548 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../presents/client/Communicator.as | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/as/com/threerings/presents/client/Communicator.as b/src/as/com/threerings/presents/client/Communicator.as index bfe0e969b..1f24b0f91 100644 --- a/src/as/com/threerings/presents/client/Communicator.as +++ b/src/as/com/threerings/presents/client/Communicator.as @@ -62,10 +62,6 @@ public class Communicator _outStream = new ObjectOutputStream(_outBuffer); _inStream = new ObjectInputStream(); - // create our message writer - _writer = new Timer(1); - _writer.addEventListener(TimerEvent.TIMER, sendPendingMessages); - _portIdx = 0; logonToPort(); } @@ -80,6 +76,9 @@ public class Communicator public function postMessage (msg :UpstreamMessage) :void { + if (_writer == null) { + log.warning("Posting message prior to opening socket", "msg", msg); + } _outq.push(msg); } @@ -114,7 +113,6 @@ public class Communicator } var host :String = _client.getHostname(); - var pportKey :String = host + ".preferred_port"; var pport :int = ports[0]; var ppidx :int = Math.max(0, ports.indexOf(pport)); var port :int = (ports[(_portIdx + ppidx) % ports.length] as int); @@ -276,12 +274,28 @@ public class Communicator { logonToPort(true); + // check for a logoff message + for each (var message :UpstreamMessage in _outq) { + if (message is LogoffRequest) { + // don't bother authing, just bail + log.info("Logged off prior to socket opening, shutting down"); + shutdown(null); + return; + } + } + + // kick off our writer thread now that we know we're ready to write + _writer = new Timer(1); + _writer.addEventListener(TimerEvent.TIMER, sendPendingMessages); + _writer.start(); + + // clear the queue, the server doesn't like anything sent prior to auth + _outq.length = 0; + // well that's great! let's logon + log.info("Posting auth request"); postMessage(new AuthRequest(_client.getCredentials(), _client.getVersion(), _client.getBootGroups())); - - // start up our writer thread now that we know we're ready to write - _writer.start(); } /**