<commit_before>//
// $Id: TestClient.java,v 1.8 2001/11/18 04:09:21 mdb Exp $

package com.threerings.whirled;

import com.samskivert.util.Config;
import com.samskivert.util.Queue;

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

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

import com.threerings.whirled.client.SceneDirector;
import com.threerings.whirled.client.DefaultDisplaySceneFactory;
import com.threerings.whirled.client.persist.SceneRepository;
import com.threerings.whirled.util.WhirledContext;

public class TestClient
    implements Client.Invoker, ClientObserver, LocationObserver
{
    public TestClient (Credentials creds)
    {
        // create our context
        _ctx = new WhirledContextImpl();

        // create the handles for our various services
        _config = new Config();
        _client = new Client(creds, this);
        _screp = new DummyClientSceneRepository();
        _occmgr = new OccupantManager(_ctx);
        _scdir = new SceneDirector(
            _ctx, _screp, new DefaultDisplaySceneFactory());

        // we want to know about logon/logoff
        _client.addObserver(this);

        // we want to know about location changes
        _scdir.addLocationObserver(this);

        // for test purposes, hardcode the server info
        _client.setServer("localhost", 4007);
    }

    public void run ()
    {
        // log on
        _client.logon();

        // loop over our queue, running the runnables
        while (true) {
            Runnable run = (Runnable)_queue.get();
            run.run();
        }
    }

    public void invokeLater (Runnable run)
    {
        // queue it on up
        _queue.append(run);
    }

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

        // request to move to scene 0
        _ctx.getSceneDirector().moveTo(0);
    }

    public void clientFailedToLogon (Client client, Exception cause)
    {
        Log.info("Client failed to logon [client=" + client +
                 ", cause=" + cause + "].");
    }

    public void clientConnectionFailed (Client client, Exception cause)
    {
        Log.info("Client connection failed [client=" + client +
                 ", cause=" + cause + "].");
    }

    public boolean clientWillLogoff (Client client)
    {
        Log.info("Client will logoff [client=" + client + "].");
        return true;
    }

    public void clientDidLogoff (Client client)
    {
        Log.info("Client did logoff [client=" + client + "].");
        System.exit(0);
    }

    public boolean locationMayChange (int placeId)
    {
        // we're easy
        return true;
    }

    public void locationDidChange (PlaceObject place)
    {
        Log.info("At new location [plobj=" + place +
                 ", scene=" + _scdir.getScene() + "].");
    }

    public void locationChangeFailed (int placeId, String reason)
    {
        Log.warning("Location change failed [plid=" + placeId +
                    ", reason=" + reason + "].");
    }

    public static void main (String[] args)
    {
        UsernamePasswordCreds creds =
            new UsernamePasswordCreds("test", "test");
        // create our test client
        TestClient tclient = new TestClient(creds);
        // start it running
        tclient.run();
    }

    protected class WhirledContextImpl implements WhirledContext
    {
        public Config getConfig ()
        {
            return _config;
        }

        public Client getClient ()
        {
            return _client;
        }

        public DObjectManager getDObjectManager ()
        {
            return _client.getDObjectManager();
        }

        public LocationDirector getLocationDirector ()
        {
            return _scdir;
        }

        public OccupantManager getOccupantManager ()
        {
            return _occmgr;
        }

        public void setPlaceView (PlaceView view)
        {
            // nothing to do because we don't create views
        }

        public SceneDirector getSceneDirector ()
        {
            return _scdir;
        }
    }

    protected Config _config;
    protected Client _client;
    protected SceneDirector _scdir;
    protected OccupantManager _occmgr;
    protected SceneRepository _screp;
    protected WhirledContext _ctx;

    protected Queue _queue = new Queue();
}<commit_msg>Updated to deal with new director organization.<commit_after>//
// $Id: TestClient.java,v 1.9 2001/12/17 03:36:36 mdb Exp $

package com.threerings.whirled;

import com.samskivert.util.Config;
import com.samskivert.util.Queue;

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

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

import com.threerings.whirled.client.SceneDirector;
import com.threerings.whirled.client.DefaultDisplaySceneFactory;
import com.threerings.whirled.client.persist.SceneRepository;
import com.threerings.whirled.util.WhirledContext;

public class TestClient
    implements Client.Invoker, ClientObserver, LocationObserver
{
    public TestClient (Credentials creds)
    {
        // create our context
        _ctx = new WhirledContextImpl();

        // create the handles for our various services
        _config = new Config();
        _client = new Client(creds, this);
        _screp = new DummyClientSceneRepository();
        _occmgr = new OccupantManager(_ctx);
        _locdir = new LocationDirector(_ctx);
        _scdir = new SceneDirector(
            _ctx, _locdir, _screp, new DefaultDisplaySceneFactory());

        // we want to know about logon/logoff
        _client.addObserver(this);

        // we want to know about location changes
        _locdir.addLocationObserver(this);

        // for test purposes, hardcode the server info
        _client.setServer("localhost", 4007);
    }

    public void run ()
    {
        // log on
        _client.logon();

        // loop over our queue, running the runnables
        while (true) {
            Runnable run = (Runnable)_queue.get();
            run.run();
        }
    }

    public void invokeLater (Runnable run)
    {
        // queue it on up
        _queue.append(run);
    }

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

        // request to move to scene 0
        _ctx.getSceneDirector().moveTo(0);
    }

    public void clientFailedToLogon (Client client, Exception cause)
    {
        Log.info("Client failed to logon [client=" + client +
                 ", cause=" + cause + "].");
    }

    public void clientConnectionFailed (Client client, Exception cause)
    {
        Log.info("Client connection failed [client=" + client +
                 ", cause=" + cause + "].");
    }

    public boolean clientWillLogoff (Client client)
    {
        Log.info("Client will logoff [client=" + client + "].");
        return true;
    }

    public void clientDidLogoff (Client client)
    {
        Log.info("Client did logoff [client=" + client + "].");
        System.exit(0);
    }

    public boolean locationMayChange (int placeId)
    {
        // we're easy
        return true;
    }

    public void locationDidChange (PlaceObject place)
    {
        Log.info("At new location [plobj=" + place +
                 ", scene=" + _scdir.getScene() + "].");
    }

    public void locationChangeFailed (int placeId, String reason)
    {
        Log.warning("Location change failed [plid=" + placeId +
                    ", reason=" + reason + "].");
    }

    public static void main (String[] args)
    {
        UsernamePasswordCreds creds =
            new UsernamePasswordCreds("test", "test");
        // create our test client
        TestClient tclient = new TestClient(creds);
        // start it running
        tclient.run();
    }

    protected class WhirledContextImpl implements WhirledContext
    {
        public Config getConfig ()
        {
            return _config;
        }

        public Client getClient ()
        {
            return _client;
        }

        public DObjectManager getDObjectManager ()
        {
            return _client.getDObjectManager();
        }

        public LocationDirector getLocationDirector ()
        {
            return _locdir;
        }

        public OccupantManager getOccupantManager ()
        {
            return _occmgr;
        }

        public void setPlaceView (PlaceView view)
        {
            // nothing to do because we don't create views
        }

        public SceneDirector getSceneDirector ()
        {
            return _scdir;
        }
    }

    protected Config _config;
    protected Client _client;
    protected LocationDirector _locdir;
    protected SceneDirector _scdir;
    protected OccupantManager _occmgr;
    protected SceneRepository _screp;
    protected WhirledContext _ctx;

    protected Queue _queue = new Queue();
}
{'fraction_non_alphanumeric': 0.09643128321943811, 'fraction_numerical': 0.004989695194706584, 'mean_word_length': 2.1467576791808876, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2491325', 'n_tokens_mistral': 2688, 'n_tokens_neox': 2534, 'n_words': 671}