From 5d0a86c6986be6827772881eb82fbb9fa8e9f2a4 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 19 Mar 2009 23:40:03 +0000 Subject: [PATCH] If we never dispatched a DID_LOGON, then don't dispatch a DID_LOGOFF. Dispatch a FAILED_TO_LOGON instead. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5688 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../com/threerings/presents/client/ClientEvent.as | 3 +-- .../com/threerings/presents/client/Communicator.as | 14 +++++++++++--- src/as/com/threerings/presents/data/AuthCodes.as | 14 ++++++++------ 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/as/com/threerings/presents/client/ClientEvent.as b/src/as/com/threerings/presents/client/ClientEvent.as index 38a058852..8b14cef35 100644 --- a/src/as/com/threerings/presents/client/ClientEvent.as +++ b/src/as/com/threerings/presents/client/ClientEvent.as @@ -30,8 +30,7 @@ public class ClientEvent extends Event public static const CLIENT_FAILED_TO_LOGON :String = "clientFailedLogon"; public static const CLIENT_OBJECT_CHANGED :String = "clobjChanged"; public static const CLIENT_CONNECTION_FAILED :String = "clientConnFailed"; - /** The logoff itself can be cancelled if a listener calls - * preventDefault() on this event. */ + /** The logoff itself can be cancelled if a listener calls preventDefault() on this event. */ public static const CLIENT_WILL_LOGOFF :String = "clientWillLogoff"; public static const CLIENT_DID_LOGOFF :String = "clientDidLogoff"; public static const CLIENT_DID_CLEAR :String = "clientDidClear"; diff --git a/src/as/com/threerings/presents/client/Communicator.as b/src/as/com/threerings/presents/client/Communicator.as index 8036662a4..710ad2c20 100644 --- a/src/as/com/threerings/presents/client/Communicator.as +++ b/src/as/com/threerings/presents/client/Communicator.as @@ -152,7 +152,12 @@ public class Communicator _writer = null; } - _client.notifyObservers(ClientEvent.CLIENT_DID_LOGOFF, null); + // if we never got our client object, we never dispatched a DID_LOGON and therefore we + // don't want to dispatch a DID_LOGOFF, the observers basically never know anything ever + // happened + if (_client.getClientObject() != null) { + _client.notifyObservers(ClientEvent.CLIENT_DID_LOGOFF, null); + } _client.cleanup(logonError); } @@ -306,7 +311,7 @@ public class Communicator // total failure log.warning("Socket error: " + event, "target", event.target); Log.dumpStack(); - shutdown(new Error("Socket closed unexpectedly.")); + shutdown(new Error(AuthCodes.NETWORK_ERROR)); } /** @@ -316,7 +321,10 @@ public class Communicator { log.info("Socket was closed: " + event); _client.notifyObservers(ClientEvent.CLIENT_CONNECTION_FAILED); - shutdown(null); + // if we hadn't loaded our client object yet, behave as if this was a logon failure because + // we failed before we dispatched a DID_LOGON + var wasLoggedOn :Boolean = (_client.getClientObject() != null); + shutdown(wasLoggedOn ? null : new LogonError(AuthCodes.NETWORK_ERROR)); } /** diff --git a/src/as/com/threerings/presents/data/AuthCodes.as b/src/as/com/threerings/presents/data/AuthCodes.as index 1e7cd7bb0..6d1f30b1a 100644 --- a/src/as/com/threerings/presents/data/AuthCodes.as +++ b/src/as/com/threerings/presents/data/AuthCodes.as @@ -26,22 +26,24 @@ package com.threerings.presents.data { */ public class AuthCodes { - /** A code indicating that no user exists with the specified - * username. */ + /** A code indicating that no user exists with the specified username. */ public static const NO_SUCH_USER :String = "m.no_such_user"; /** A code indicating that the supplied password was invalid. */ public static const INVALID_PASSWORD :String = "m.invalid_password"; - /** A code indicating that an internal server error occurred while - * trying to log the user on. */ + /** A code indicating that an internal server error occurred while trying to log the user + * on. */ public static const SERVER_ERROR :String = "m.server_error"; + /** A code indicating that a network error occurred while trying to log the user on. */ + public static const NETWORK_ERROR :String = "m.network_error"; + /** A code indicating that the server is not available at the moment. */ public static const SERVER_UNAVAILABLE :String = "m.server_unavailable"; - /** A code indicating that we failed to connect to the server on a port and - * are trying the next port in the list. */ + /** A code indicating that we failed to connect to the server on a port and are trying the next + * port in the list. */ public static const TRYING_NEXT_PORT :String = "m.trying_next_port"; } }