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
This commit is contained in:
Michael Bayne
2001-10-25 23:21:32 +00:00
parent 264a71ddd5
commit 9c781457c6
4 changed files with 34 additions and 10 deletions
@@ -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();
}