Track more accurately whether or not we're switching servers and publish that

in the ClientEvent that is sent out with all will/didLogon and will/didLogoff
notifications.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5681 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2009-03-05 23:56:02 +00:00
parent 5bd1ef9d8c
commit d67bcc5e01
2 changed files with 32 additions and 15 deletions
+16 -12
View File
@@ -179,17 +179,6 @@ public class Client extends EventDispatcher
return _invdir;
}
/**
* Returns true if we're in the process of switching servers, false if we're not. This will
* only return true following the call to {@link #switchServers}, through the did logoff
* notification and the did clear notification. During the did logon notification for the new
* server or logon failure for same, we will not show as switching.
*/
public function isSwitchingServers () :Boolean
{
return _switcher != null;
}
/**
* Returns the set of bootstrap service groups needed by this client.
*/
@@ -308,9 +297,15 @@ public class Client extends EventDispatcher
return true;
}
// if this is an externally initiated logoff request, clear our active session status
if (_switcher == null) {
_activeSession = false;
}
// if the request is abortable, let's run it past the observers. if any of them call
// preventDefault() then the logoff will be cancelled
if (abortable && !notifyObservers(ClientEvent.CLIENT_WILL_LOGOFF)) {
_activeSession = true; // restore our active session status
return false;
}
@@ -378,6 +373,10 @@ public class Client extends EventDispatcher
}
notifyObservers(ClientEvent.CLIENT_DID_LOGON);
// now that we've logged on at least once, we're in the middle of an active session and
// will remain so until we receive an externally initiated logoff request
_activeSession = true;
}
/**
@@ -405,7 +404,7 @@ public class Client extends EventDispatcher
*/
public function notifyObservers (evtCode :String, cause :Error = null) :Boolean
{
return dispatchEvent(new ClientEvent(evtCode, this, cause));
return dispatchEvent(new ClientEvent(evtCode, this, _activeSession, cause));
}
/**
@@ -498,6 +497,11 @@ public class Client extends EventDispatcher
/** Ticks. */
protected var _tickInterval :Timer;
/** This flag is used to distinguish our *first* willLogon/didLogon and a caller-initiated
* willLogoff/didLogoff from similar events generated during server switches. Thus it is true
* for most of a normal client session. */
protected var _activeSession :Boolean;
/** Used to temporarily track our server switcher so that we can tell when we're logging off
* whether or not we're switching servers or actually ending our session. */
protected var _switcher :ServerSwitcher;
@@ -36,11 +36,12 @@ public class ClientEvent extends Event
public static const CLIENT_DID_LOGOFF :String = "clientDidLogoff";
public static const CLIENT_DID_CLEAR :String = "clientDidClear";
public function ClientEvent (type :String, client :Client,
cause :Error = null)
public function ClientEvent (
type :String, client :Client, isSwitching :Boolean, cause :Error = null)
{
super(type, false, (type === CLIENT_WILL_LOGOFF));
_client = client;
_isSwitching = isSwitching;
_cause = cause;
}
@@ -54,14 +55,26 @@ public class ClientEvent extends Event
return _cause;
}
/**
* Returns true if the client is currently switching servers rather than starting a fresh
* session or ending a session due to user requested logoff.
*/
public function isSwitchingServers () :Boolean
{
return _isSwitching;
}
override public function clone () :Event
{
return new ClientEvent(type, _client, _cause);
return new ClientEvent(type, _client, _isSwitching, _cause);
}
/** The client that generated this client event. */
protected var _client :Client;
/** Whether or not we're currently switching servers. */
protected var _isSwitching :Boolean;
/** The error that caused this event, if applicable. */
protected var _cause :Error;
}