From 9c781457c685cb7727e19bccd6ffaab99380e780 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 25 Oct 2001 23:21:32 +0000 Subject: [PATCH] Revamped logon and logoff handling so that the driver is responsible for either exiting or closing the window when we logoff rather than the client or the client controller which don't know if we're in an applet or an application or something else. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@569 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../micasa/client/ClientController.java | 3 +-- .../threerings/micasa/client/MiCasaApp.java | 18 ++++++++++++++++-- .../micasa/client/MiCasaApplet.java | 19 ++++++++++++++++--- .../micasa/client/MiCasaClient.java | 4 +--- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/java/com/threerings/micasa/client/ClientController.java b/src/java/com/threerings/micasa/client/ClientController.java index 11f026303..b36de14f8 100644 --- a/src/java/com/threerings/micasa/client/ClientController.java +++ b/src/java/com/threerings/micasa/client/ClientController.java @@ -1,5 +1,5 @@ // -// $Id: ClientController.java,v 1.9 2001/10/25 23:02:57 mdb Exp $ +// $Id: ClientController.java,v 1.10 2001/10/25 23:21:32 mdb Exp $ package com.threerings.micasa.client; @@ -126,7 +126,6 @@ public class ClientController public void clientDidLogoff (Client client) { Log.info("Client did logoff [client=" + client + "]."); - System.exit(0); } protected MiCasaContext _ctx; diff --git a/src/java/com/threerings/micasa/client/MiCasaApp.java b/src/java/com/threerings/micasa/client/MiCasaApp.java index f3c004d39..f70654312 100644 --- a/src/java/com/threerings/micasa/client/MiCasaApp.java +++ b/src/java/com/threerings/micasa/client/MiCasaApp.java @@ -1,5 +1,5 @@ // -// $Id: MiCasaApp.java,v 1.2 2001/10/25 23:03:29 mdb Exp $ +// $Id: MiCasaApp.java,v 1.3 2001/10/25 23:21:32 mdb Exp $ package com.threerings.micasa.client; @@ -7,6 +7,7 @@ import java.io.IOException; import com.samskivert.swing.util.SwingUtil; import com.threerings.presents.client.Client; +import com.threerings.presents.client.ClientAdapter; import com.threerings.presents.net.Credentials; import com.threerings.presents.net.UsernamePasswordCreds; @@ -36,14 +37,27 @@ public class MiCasaApp SwingUtil.centerWindow(_frame); _frame.show(); + Client client = _client.getContext().getClient(); + + // we want to exit when we logged off or failed to log on + client.addObserver(new ClientAdapter() { + public void clientFailedToLogon (Client c, Exception cause) { + System.exit(0); + } + public void clientDidLogoff (Client c) { + System.exit(0); + } + }); + // configure the client with some credentials and logon String username = System.getProperty("username"); if (username == null) { username = "bob" + ((int)(Math.random() * Integer.MAX_VALUE) % 500); } + + // create and set our credentials Credentials creds = new UsernamePasswordCreds(username, "test"); - Client client = _client.getContext().getClient(); client.setCredentials(creds); client.logon(); } diff --git a/src/java/com/threerings/micasa/client/MiCasaApplet.java b/src/java/com/threerings/micasa/client/MiCasaApplet.java index a2acb9a1f..6741bebc4 100644 --- a/src/java/com/threerings/micasa/client/MiCasaApplet.java +++ b/src/java/com/threerings/micasa/client/MiCasaApplet.java @@ -1,5 +1,5 @@ // -// $Id: MiCasaApplet.java,v 1.1 2001/10/25 23:03:48 mdb Exp $ +// $Id: MiCasaApplet.java,v 1.2 2001/10/25 23:21:32 mdb Exp $ package com.threerings.micasa.client; @@ -7,7 +7,10 @@ import java.applet.Applet; import java.io.IOException; import com.samskivert.swing.util.SwingUtil; +import com.threerings.presents.client.Client; +import com.threerings.presents.client.ClientAdapter; import com.threerings.presents.net.UsernamePasswordCreds; + import com.threerings.micasa.Log; /** @@ -37,10 +40,20 @@ public class MiCasaApplet extends Applet throw new IOException("Missing authkey parameter."); } - // create our credentials - _client.getContext().getClient().setCredentials( + Client client = _client.getContext().getClient(); + + // create and set our credentials + client.setCredentials( new UsernamePasswordCreds(username, authkey)); + // we want to hide the client frame when we logoff + client.addObserver(new ClientAdapter() { + public void clientDidLogoff (Client c) + { + _frame.setVisible(false); + } + }); + } catch (IOException ioe) { Log.warning("Unable to create client."); Log.logStackTrace(ioe); diff --git a/src/java/com/threerings/micasa/client/MiCasaClient.java b/src/java/com/threerings/micasa/client/MiCasaClient.java index 860077217..6cb33db8d 100644 --- a/src/java/com/threerings/micasa/client/MiCasaClient.java +++ b/src/java/com/threerings/micasa/client/MiCasaClient.java @@ -1,5 +1,5 @@ // -// $Id: MiCasaClient.java,v 1.5 2001/10/18 18:39:40 mdb Exp $ +// $Id: MiCasaClient.java,v 1.6 2001/10/25 23:21:32 mdb Exp $ package com.threerings.micasa.client; @@ -62,8 +62,6 @@ public class MiCasaClient // if we're logged on, log off if (_client.loggedOn()) { _client.logoff(true); - } else { - System.exit(0); } } });