//
// $Id: ClientController.java,v 1.5 2002/03/11 19:51:24 mdb Exp $

package com.threerings.micasa.simulator.client;

import java.awt.event.ActionEvent;
import com.samskivert.swing.Controller;
import com.samskivert.util.StringUtil;

import com.threerings.presents.dobj.*;
import com.threerings.presents.client.*;

import com.threerings.crowd.client.*;
import com.threerings.crowd.data.*;

import com.threerings.parlor.game.GameConfig;
import com.threerings.parlor.util.ParlorContext;

import com.threerings.micasa.Log;
import com.threerings.micasa.simulator.data.SimulatorInfo;

/**
 * Responsible for top-level control of the client user interface.
 */
public class ClientController extends Controller
    implements SessionObserver
{
    /**
     * Creates a new client controller. The controller will set everything
     * up in preparation for logging on.
     */
    public ClientController (ParlorContext ctx, SimulatorFrame frame,
                             SimulatorInfo info)
    {
        // we'll want to keep these around
        _ctx = ctx;
        _frame = frame;
        _info = info;

        // we want to know about logon/logoff
        _ctx.getClient().addClientObserver(this);
    }

    // documentation inherited
    public boolean handleAction (ActionEvent action)
    {
	String cmd = action.getActionCommand();

        if (cmd.equals("logoff")) {
            // request that we logoff
            _ctx.getClient().logoff(true);
            return true;
        }

        Log.info("Unhandled action: " + action);
        return false;
    }

    // documentation inherited
    public void clientDidLogon (Client client)
    {
        Log.info("Client did logon [client=" + client + "].");

        // keep the body object around for stuff
        _body = (BodyObject)client.getClientObject();

        GameConfig config = null;
        try {
            // create the game config object
            config = (GameConfig)
                Class.forName(_info.gameConfigClass).newInstance();

            // send the game creation request
            SimulatorDirector.createGame(
                client, config, _info.simClass, _info.playerCount);

            // our work here is done, as the location manager will move us
            // into the game room straightaway

        } catch (Exception e) {
            Log.warning("Failed to instantiate game config " +
                        "[class=" + _info.gameConfigClass +
                        ", error=" + e + "].");
        }
    }

    // documentation inherited
    public void clientDidLogoff (Client client)
    {
        Log.info("Client did logoff [client=" + client + "].");
    }

    protected ParlorContext _ctx;
    protected SimulatorFrame _frame;
    protected SimulatorInfo _info;
    protected BodyObject _body;
}

@@ -34,33 +34,36 @@
 v 1.
-5
+6
  2002/0
-3/11 19:51:24 mdb
+5/17 21:22:46 shaper
  Exp
@@ -733,16 +733,122 @@
 erver%0A%7B%0A
+    /** Command constant used to logoff the client. */%0A    public static final String LOGOFF = %22logoff%22;%0A%0A
     /**%0A
@@ -1464,24 +1464,22 @@
 .equals(
-%22logoff%22
+LOGOFF
 )) %7B%0A   

Made the logoff command a constant.