Boot by Name instead of table position

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@730 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Bruno Garcia
2008-08-15 23:37:46 +00:00
parent e149bbb05b
commit a72c810193
10 changed files with 39 additions and 21 deletions
@@ -23,6 +23,7 @@ package com.threerings.parlor.client {
import com.threerings.util.ArrayUtil; import com.threerings.util.ArrayUtil;
import com.threerings.util.Log; import com.threerings.util.Log;
import com.threerings.util.Name;
import com.threerings.util.ObserverList; import com.threerings.util.ObserverList;
import com.threerings.util.Util; import com.threerings.util.Util;
@@ -246,15 +247,15 @@ public class TableDirector extends BasicDirector
/** /**
* Sends a request to boot a player from a table. * Sends a request to boot a player from a table.
*/ */
public function bootPlayer (tableId :int, bodyId :int) :void public function bootPlayer (tableId :int, target :Name) :void
{ {
if (_tlobj == null) { if (_tlobj == null) {
log.warning("Requesting to boot a player from a table we're not currently in " + log.warning("Requesting to boot a player from a table we're not currently in " +
"[tableId=" + tableId + ", target=" + bodyId + "]."); "[tableId=" + tableId + ", target=" + target + "].");
return; return;
} }
_tlobj.getTableService().bootPlayer(_ctx.getClient(), tableId, bodyId, this); _tlobj.getTableService().bootPlayer(_ctx.getClient(), tableId, target, this);
} }
// documentation inherited // documentation inherited
@@ -27,6 +27,7 @@ import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationService; import com.threerings.presents.client.InvocationService;
import com.threerings.presents.client.InvocationService_InvocationListener; import com.threerings.presents.client.InvocationService_InvocationListener;
import com.threerings.presents.client.InvocationService_ResultListener; import com.threerings.presents.client.InvocationService_ResultListener;
import com.threerings.util.Name;
/** /**
* An ActionScript version of the Java TableService interface. * An ActionScript version of the Java TableService interface.
@@ -34,7 +35,7 @@ import com.threerings.presents.client.InvocationService_ResultListener;
public interface TableService extends InvocationService public interface TableService extends InvocationService
{ {
// from Java interface TableService // from Java interface TableService
function bootPlayer (arg1 :Client, arg2 :int, arg3 :int, arg4 :InvocationService_InvocationListener) :void; function bootPlayer (arg1 :Client, arg2 :int, arg3 :Name, arg4 :InvocationService_InvocationListener) :void;
// from Java interface TableService // from Java interface TableService
function createTable (arg1 :Client, arg2 :TableConfig, arg3 :GameConfig, arg4 :InvocationService_ResultListener) :void; function createTable (arg1 :Client, arg2 :TableConfig, arg3 :GameConfig, arg4 :InvocationService_ResultListener) :void;
@@ -30,6 +30,7 @@ import com.threerings.presents.data.InvocationMarshaller;
import com.threerings.presents.data.InvocationMarshaller_ListenerMarshaller; import com.threerings.presents.data.InvocationMarshaller_ListenerMarshaller;
import com.threerings.presents.data.InvocationMarshaller_ResultMarshaller; import com.threerings.presents.data.InvocationMarshaller_ResultMarshaller;
import com.threerings.util.Integer; import com.threerings.util.Integer;
import com.threerings.util.Name;
/** /**
* Provides the implementation of the <code>TableService</code> interface * Provides the implementation of the <code>TableService</code> interface
@@ -45,12 +46,12 @@ public class TableMarshaller extends InvocationMarshaller
public static const BOOT_PLAYER :int = 1; public static const BOOT_PLAYER :int = 1;
// from interface TableService // from interface TableService
public function bootPlayer (arg1 :Client, arg2 :int, arg3 :int, arg4 :InvocationService_InvocationListener) :void public function bootPlayer (arg1 :Client, arg2 :int, arg3 :Name, arg4 :InvocationService_InvocationListener) :void
{ {
var listener4 :InvocationMarshaller_ListenerMarshaller = new InvocationMarshaller_ListenerMarshaller(); var listener4 :InvocationMarshaller_ListenerMarshaller = new InvocationMarshaller_ListenerMarshaller();
listener4.listener = arg4; listener4.listener = arg4;
sendRequest(arg1, BOOT_PLAYER, [ sendRequest(arg1, BOOT_PLAYER, [
Integer.valueOf(arg2), Integer.valueOf(arg3), listener4 Integer.valueOf(arg2), arg3, listener4
]); ]);
} }
@@ -23,6 +23,7 @@ package com.threerings.parlor.client;
import com.samskivert.util.ObjectUtil; import com.samskivert.util.ObjectUtil;
import com.samskivert.util.ObserverList; import com.samskivert.util.ObserverList;
import com.threerings.util.Name;
import com.threerings.presents.client.BasicDirector; import com.threerings.presents.client.BasicDirector;
import com.threerings.presents.client.Client; import com.threerings.presents.client.Client;
@@ -222,15 +223,15 @@ public class TableDirector extends BasicDirector
/** /**
* Sends a request to boot a player from a table. * Sends a request to boot a player from a table.
*/ */
public void bootPlayer (int tableId, int bodyId) public void bootPlayer (int tableId, Name target)
{ {
if (_tlobj == null) { if (_tlobj == null) {
log.warning("Requesting to boot a player from a table we're not currently in " + log.warning("Requesting to boot a player from a table we're not currently in " +
"[tableId=" + tableId + ", target=" + bodyId + "]."); "[tableId=" + tableId + ", target=" + target + "].");
return; return;
} }
_tlobj.getTableService().bootPlayer(_ctx.getClient(), tableId, bodyId, this); _tlobj.getTableService().bootPlayer(_ctx.getClient(), tableId, target, this);
} }
@Override @Override
@@ -21,6 +21,8 @@
package com.threerings.parlor.client; package com.threerings.parlor.client;
import com.threerings.util.Name;
import com.threerings.presents.client.Client; import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationService; import com.threerings.presents.client.InvocationService;
@@ -72,5 +74,5 @@ public interface TableService extends InvocationService
/** /**
* Requests that another user be booted from the specified table. * Requests that another user be booted from the specified table.
*/ */
public void bootPlayer (Client client, int tableId, int bodyId, InvocationListener listener); public void bootPlayer (Client client, int tableId, Name target, InvocationListener listener);
} }
@@ -253,13 +253,13 @@ public class Table
* Indicate to this table that a user was booted and should * Indicate to this table that a user was booted and should
* be prevented from rejoining. * be prevented from rejoining.
*/ */
public void addBannedUser (int position) public void addBannedUser (Name player)
{ {
if (_bannedUsers == null) { if (_bannedUsers == null) {
_bannedUsers = new HashSet<Name>(); _bannedUsers = new HashSet<Name>();
} }
_bannedUsers.add(players[position]); _bannedUsers.add(player);
} }
/** /**
@@ -26,6 +26,7 @@ import com.threerings.parlor.game.data.GameConfig;
import com.threerings.presents.client.Client; import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationService; import com.threerings.presents.client.InvocationService;
import com.threerings.presents.data.InvocationMarshaller; import com.threerings.presents.data.InvocationMarshaller;
import com.threerings.util.Name;
/** /**
* Provides the implementation of the {@link TableService} interface * Provides the implementation of the {@link TableService} interface
@@ -41,12 +42,12 @@ public class TableMarshaller extends InvocationMarshaller
public static final int BOOT_PLAYER = 1; public static final int BOOT_PLAYER = 1;
// from interface TableService // from interface TableService
public void bootPlayer (Client arg1, int arg2, int arg3, InvocationService.InvocationListener arg4) public void bootPlayer (Client arg1, int arg2, Name arg3, InvocationService.InvocationListener arg4)
{ {
ListenerMarshaller listener4 = new ListenerMarshaller(); ListenerMarshaller listener4 = new ListenerMarshaller();
listener4.listener = arg4; listener4.listener = arg4;
sendRequest(arg1, BOOT_PLAYER, new Object[] { sendRequest(arg1, BOOT_PLAYER, new Object[] {
Integer.valueOf(arg2), Integer.valueOf(arg3), listener4 Integer.valueOf(arg2), arg3, listener4
}); });
} }
@@ -28,6 +28,7 @@ import com.threerings.presents.client.InvocationService;
import com.threerings.presents.data.ClientObject; import com.threerings.presents.data.ClientObject;
import com.threerings.presents.server.InvocationDispatcher; import com.threerings.presents.server.InvocationDispatcher;
import com.threerings.presents.server.InvocationException; import com.threerings.presents.server.InvocationException;
import com.threerings.util.Name;
/** /**
* Dispatches requests to the {@link TableProvider}. * Dispatches requests to the {@link TableProvider}.
@@ -57,7 +58,7 @@ public class TableDispatcher extends InvocationDispatcher<TableMarshaller>
switch (methodId) { switch (methodId) {
case TableMarshaller.BOOT_PLAYER: case TableMarshaller.BOOT_PLAYER:
((TableProvider)provider).bootPlayer( ((TableProvider)provider).bootPlayer(
source, ((Integer)args[0]).intValue(), ((Integer)args[1]).intValue(), (InvocationService.InvocationListener)args[2] source, ((Integer)args[0]).intValue(), (Name)args[1], (InvocationService.InvocationListener)args[2]
); );
return; return;
@@ -23,6 +23,9 @@ package com.threerings.parlor.server;
import com.samskivert.util.IntMap; import com.samskivert.util.IntMap;
import com.samskivert.util.IntMaps; import com.samskivert.util.IntMaps;
import com.samskivert.util.ListUtil;
import com.threerings.util.Name;
import com.threerings.presents.data.ClientObject; import com.threerings.presents.data.ClientObject;
import com.threerings.presents.dobj.AttributeChangeListener; import com.threerings.presents.dobj.AttributeChangeListener;
import com.threerings.presents.dobj.AttributeChangedEvent; import com.threerings.presents.dobj.AttributeChangedEvent;
@@ -282,7 +285,7 @@ public class TableManager
} }
// from interface TableProvider // from interface TableProvider
public void bootPlayer (ClientObject caller, int tableId, int position, public void bootPlayer (ClientObject caller, int tableId, Name target,
TableService.InvocationListener listener) TableService.InvocationListener listener)
throws InvocationException throws InvocationException
{ {
@@ -291,15 +294,21 @@ public class TableManager
if (table == null) { if (table == null) {
throw new InvocationException(NO_SUCH_TABLE); throw new InvocationException(NO_SUCH_TABLE);
} else if (position == 0 || booter.getOid() != table.bodyOids[0]) {
// Must be head of the table, and can't self-boot
throw new InvocationException(INVALID_TABLE_POSITION);
} else if ( ! _allowBooting) { } else if ( ! _allowBooting) {
throw new InvocationException(INTERNAL_ERROR); throw new InvocationException(INTERNAL_ERROR);
} }
int position = ListUtil.indexOf(table.players, target);
if (position < 0) {
throw new InvocationException(NOT_AT_TABLE);
} else if (booter.getOid() != table.bodyOids[0] ||
booter.getOid() == table.bodyOids[position]) {
// Must be head of the table, and can't self-boot
throw new InvocationException(INVALID_TABLE_POSITION);
}
// Remember to keep him banned // Remember to keep him banned
table.addBannedUser(position); table.addBannedUser(target);
// Remove the player from the table // Remove the player from the table
if (notePlayerRemoved(table.bodyOids[position]) == null) { if (notePlayerRemoved(table.bodyOids[position]) == null) {
@@ -28,6 +28,7 @@ import com.threerings.presents.client.InvocationService;
import com.threerings.presents.data.ClientObject; import com.threerings.presents.data.ClientObject;
import com.threerings.presents.server.InvocationException; import com.threerings.presents.server.InvocationException;
import com.threerings.presents.server.InvocationProvider; import com.threerings.presents.server.InvocationProvider;
import com.threerings.util.Name;
/** /**
* Defines the server-side of the {@link TableService}. * Defines the server-side of the {@link TableService}.
@@ -37,7 +38,7 @@ public interface TableProvider extends InvocationProvider
/** /**
* Handles a {@link TableService#bootPlayer} request. * Handles a {@link TableService#bootPlayer} request.
*/ */
void bootPlayer (ClientObject caller, int arg1, int arg2, InvocationService.InvocationListener arg3) void bootPlayer (ClientObject caller, int arg1, Name arg2, InvocationService.InvocationListener arg3)
throws InvocationException; throws InvocationException;
/** /**