The PuzzleService was superfluous. The ParlorService can handle starting

single player games and indeed should because it's useful outside the
context of puzzles and their ilk.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3359 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2005-02-19 22:38:06 +00:00
parent 4036d12121
commit 41fb0b1b80
11 changed files with 81 additions and 296 deletions
@@ -1,5 +1,5 @@
//
// $Id: ParlorDirector.java,v 1.21 2004/08/27 02:20:12 mdb Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -28,6 +28,7 @@ import com.threerings.util.Name;
import com.threerings.presents.client.BasicDirector;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationService;
import com.threerings.parlor.Log;
import com.threerings.parlor.data.ParlorCodes;
@@ -119,6 +120,20 @@ public class ParlorDirector extends BasicDirector
return invite;
}
/**
* Requests that the specified single player game be started.
*
* @param config the configuration of the single player game to be
* started.
* @param listener a listener to be informed of failure if the game
* cannot be started.
*/
public void startSolitaire (
GameConfig config, InvocationService.ConfirmListener listener)
{
_pservice.startSolitaire(_ctx.getClient(), config, listener);
}
// documentation inherited
public void clientDidLogoff (Client client)
{
@@ -1,5 +1,5 @@
//
// $Id: ParlorService.java,v 1.16 2004/08/27 02:20:12 mdb Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -151,4 +151,11 @@ public interface ParlorService extends InvocationService
*/
public void leaveTable (Client client, int lobbyOid, int tableId,
InvocationListener listener);
/**
* Requests to start a single player game with the specified game
* configuration.
*/
public void startSolitaire (Client client, GameConfig config,
ConfirmListener listener);
}
@@ -1,5 +1,5 @@
//
// $Id: ParlorCodes.java,v 1.5 2004/08/27 02:20:13 mdb Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -179,4 +179,17 @@ public class ParlorMarshaller extends InvocationMarshaller
});
}
/** The method id used to dispatch {@link #startSolitaire} requests. */
public static final int START_SOLITAIRE = 7;
// documentation inherited from interface
public void startSolitaire (Client arg1, GameConfig arg2, InvocationService.ConfirmListener arg3)
{
InvocationMarshaller.ConfirmMarshaller listener3 = new InvocationMarshaller.ConfirmMarshaller();
listener3.listener = arg3;
sendRequest(arg1, START_SOLITAIRE, new Object[] {
arg2, listener3
});
}
}
@@ -100,6 +100,13 @@ public class ParlorDispatcher extends InvocationDispatcher
);
return;
case ParlorMarshaller.START_SOLITAIRE:
((ParlorProvider)provider).startSolitaire(
source,
(GameConfig)args[0], (InvocationService.ConfirmListener)args[1]
);
return;
default:
super.dispatchRequest(source, methodId, args);
}
@@ -23,6 +23,7 @@ package com.threerings.parlor.server;
import com.threerings.util.Name;
import com.threerings.presents.client.InvocationService;
import com.threerings.presents.client.InvocationService.InvocationListener;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.server.InvocationException;
@@ -37,6 +38,7 @@ import com.threerings.parlor.client.ParlorService.InviteListener;
import com.threerings.parlor.client.ParlorService.TableListener;
import com.threerings.parlor.data.ParlorCodes;
import com.threerings.parlor.game.GameConfig;
import com.threerings.parlor.game.GameManager;
/**
* The parlor provider handles the server side of the various Parlor
@@ -160,6 +162,40 @@ public class ParlorProvider
// themselves removed from the table they just left
}
/**
* Handles a {@link ParlorService#startSolitaire} request.
*/
public void startSolitaire (ClientObject caller, GameConfig config,
InvocationService.ConfirmListener listener)
throws InvocationException
{
BodyObject user = (BodyObject)caller;
Log.debug("Processing start puzzle [caller=" + user.who() +
", config=" + config + "].");
try {
// just this fellow will be playing
config.players = new Name[] { user.username };
// create the game manager and begin its initialization
// process
GameManager gmgr = (GameManager)
CrowdServer.plreg.createPlace(config, null);
// the game manager will take care of notifying the player
// that the game has been created once it has been started up;
// but we let the caller know that we processed their request
listener.requestProcessed();
} catch (InstantiationException ie) {
Log.warning("Error instantiating game manager " +
"[for=" + caller.who() + ", config=" + config + "].");
Log.logStackTrace(ie);
throw new InvocationException(INTERNAL_ERROR);
}
}
/**
* Looks up the place manager associated with the supplied lobby oid,
* casts it to a table lobby manager and obtains the associated table
@@ -1,41 +0,0 @@
//
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.puzzle.client;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationService;
import com.threerings.puzzle.data.SolitairePuzzleConfig;
/**
* The puzzle services provide a mechanism by which the client can enter
* and leave puzzles.
*/
public interface PuzzleService extends InvocationService
{
/**
* Requests that this client start up the specified single-player
* puzzle.
*/
public void startPuzzle (Client client, SolitairePuzzleConfig config,
ConfirmListener listener);
}
@@ -1,54 +0,0 @@
//
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.puzzle.data;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationService;
import com.threerings.presents.data.InvocationMarshaller;
import com.threerings.presents.dobj.InvocationResponseEvent;
import com.threerings.puzzle.client.PuzzleService;
import com.threerings.puzzle.data.SolitairePuzzleConfig;
/**
* Provides the implementation of the {@link PuzzleService} interface
* that marshalls the arguments and delivers the request to the provider
* on the server. Also provides an implementation of the response listener
* interfaces that marshall the response arguments and deliver them back
* to the requesting client.
*/
public class PuzzleMarshaller extends InvocationMarshaller
implements PuzzleService
{
/** The method id used to dispatch {@link #startPuzzle} requests. */
public static final int START_PUZZLE = 1;
// documentation inherited from interface
public void startPuzzle (Client arg1, SolitairePuzzleConfig arg2, InvocationService.ConfirmListener arg3)
{
InvocationMarshaller.ConfirmMarshaller listener3 = new InvocationMarshaller.ConfirmMarshaller();
listener3.listener = arg3;
sendRequest(arg1, START_PUZZLE, new Object[] {
arg2, listener3
});
}
}
@@ -1,29 +0,0 @@
//
// $Id: SolitairePuzzleConfig.java,v 1.2 2004/08/27 02:20:28 mdb Exp $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.puzzle.data;
/**
* Restricts regular puzzle configuration for single player puzzles.
*/
public abstract class SolitairePuzzleConfig extends PuzzleConfig
{
}
@@ -1,71 +0,0 @@
//
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.puzzle.server;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationService;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.data.InvocationMarshaller;
import com.threerings.presents.server.InvocationDispatcher;
import com.threerings.presents.server.InvocationException;
import com.threerings.puzzle.client.PuzzleService;
import com.threerings.puzzle.data.PuzzleMarshaller;
import com.threerings.puzzle.data.SolitairePuzzleConfig;
/**
* Dispatches requests to the {@link PuzzleProvider}.
*/
public class PuzzleDispatcher extends InvocationDispatcher
{
/**
* Creates a dispatcher that may be registered to dispatch invocation
* service requests for the specified provider.
*/
public PuzzleDispatcher (PuzzleProvider provider)
{
this.provider = provider;
}
// documentation inherited
public InvocationMarshaller createMarshaller ()
{
return new PuzzleMarshaller();
}
// documentation inherited
public void dispatchRequest (
ClientObject source, int methodId, Object[] args)
throws InvocationException
{
switch (methodId) {
case PuzzleMarshaller.START_PUZZLE:
((PuzzleProvider)provider).startPuzzle(
source,
(SolitairePuzzleConfig)args[0], (InvocationService.ConfirmListener)args[1]
);
return;
default:
super.dispatchRequest(source, methodId, args);
}
}
}
@@ -1,98 +0,0 @@
//
// $Id: PuzzleProvider.java,v 1.7 2004/10/21 02:54:44 mdb Exp $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.puzzle.server;
import com.threerings.util.Name;
import com.threerings.presents.client.InvocationService;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.dobj.RootDObjectManager;
import com.threerings.presents.server.InvocationException;
import com.threerings.presents.server.InvocationProvider;
import com.threerings.crowd.data.BodyObject;
import com.threerings.crowd.data.PlaceConfig;
import com.threerings.crowd.data.PlaceObject;
import com.threerings.crowd.server.PlaceRegistry;
import com.threerings.parlor.game.GameManager;
import com.threerings.puzzle.Log;
import com.threerings.puzzle.data.PuzzleCodes;
import com.threerings.puzzle.data.PuzzleObject;
import com.threerings.puzzle.data.SolitairePuzzleConfig;
/**
* Handles the server end of the puzzle services.
*/
public class PuzzleProvider
implements InvocationProvider, PuzzleCodes
{
/**
* Constructs a puzzle provider instance.
*/
public PuzzleProvider (RootDObjectManager omgr, PlaceRegistry plreg)
{
_omgr = omgr;
_plreg = plreg;
}
/**
* Processes a request from a client to start a puzzle.
*/
public void startPuzzle (
ClientObject caller, SolitairePuzzleConfig config,
InvocationService.ConfirmListener listener)
throws InvocationException
{
BodyObject user = (BodyObject)caller;
Log.debug("Processing start puzzle [caller=" + user.who() +
", config=" + config + "].");
try {
// just this fellow will be playing
config.players = new Name[] { user.username };
// create the game manager and begin its initialization
// process
GameManager gmgr = (GameManager)_plreg.createPlace(config, null);
// the game manager will take care of notifying the player
// that the game has been created once it has been started up;
// but we let the caller know that we processed their request
listener.requestProcessed();
} catch (InstantiationException ie) {
Log.warning("Error instantiating puzzle manager " +
"[for=" + caller.who() + ", config=" + config + "].");
Log.logStackTrace(ie);
throw new InvocationException(INTERNAL_ERROR);
}
}
/** The distributed object manager with which we interoperate. */
protected RootDObjectManager _omgr;
/** The place registry with which we interoperate. */
protected PlaceRegistry _plreg;
}