From a72c8101939bdd5af45711b6e5565eb926b7383c Mon Sep 17 00:00:00 2001 From: Bruno Garcia Date: Fri, 15 Aug 2008 23:37:46 +0000 Subject: [PATCH] Boot by Name instead of table position git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@730 c613c5cb-e716-0410-b11b-feb51c14d237 --- .../threerings/parlor/client/TableDirector.as | 7 ++++--- .../threerings/parlor/client/TableService.as | 3 ++- .../threerings/parlor/data/TableMarshaller.as | 5 +++-- .../parlor/client/TableDirector.java | 7 ++++--- .../parlor/client/TableService.java | 4 +++- .../com/threerings/parlor/data/Table.java | 4 ++-- .../parlor/data/TableMarshaller.java | 5 +++-- .../parlor/server/TableDispatcher.java | 3 ++- .../parlor/server/TableManager.java | 19 ++++++++++++++----- .../parlor/server/TableProvider.java | 3 ++- 10 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/as/com/threerings/parlor/client/TableDirector.as b/src/as/com/threerings/parlor/client/TableDirector.as index eab63f7d..4f22f1a3 100644 --- a/src/as/com/threerings/parlor/client/TableDirector.as +++ b/src/as/com/threerings/parlor/client/TableDirector.as @@ -23,6 +23,7 @@ package com.threerings.parlor.client { import com.threerings.util.ArrayUtil; import com.threerings.util.Log; +import com.threerings.util.Name; import com.threerings.util.ObserverList; import com.threerings.util.Util; @@ -246,15 +247,15 @@ public class TableDirector extends BasicDirector /** * 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) { log.warning("Requesting to boot a player from a table we're not currently in " + - "[tableId=" + tableId + ", target=" + bodyId + "]."); + "[tableId=" + tableId + ", target=" + target + "]."); return; } - _tlobj.getTableService().bootPlayer(_ctx.getClient(), tableId, bodyId, this); + _tlobj.getTableService().bootPlayer(_ctx.getClient(), tableId, target, this); } // documentation inherited diff --git a/src/as/com/threerings/parlor/client/TableService.as b/src/as/com/threerings/parlor/client/TableService.as index 33726f8a..29060a01 100644 --- a/src/as/com/threerings/parlor/client/TableService.as +++ b/src/as/com/threerings/parlor/client/TableService.as @@ -27,6 +27,7 @@ import com.threerings.presents.client.Client; import com.threerings.presents.client.InvocationService; import com.threerings.presents.client.InvocationService_InvocationListener; import com.threerings.presents.client.InvocationService_ResultListener; +import com.threerings.util.Name; /** * An ActionScript version of the Java TableService interface. @@ -34,7 +35,7 @@ import com.threerings.presents.client.InvocationService_ResultListener; public interface TableService extends InvocationService { // 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 function createTable (arg1 :Client, arg2 :TableConfig, arg3 :GameConfig, arg4 :InvocationService_ResultListener) :void; diff --git a/src/as/com/threerings/parlor/data/TableMarshaller.as b/src/as/com/threerings/parlor/data/TableMarshaller.as index 45fe25d5..5fd2ecb3 100644 --- a/src/as/com/threerings/parlor/data/TableMarshaller.as +++ b/src/as/com/threerings/parlor/data/TableMarshaller.as @@ -30,6 +30,7 @@ import com.threerings.presents.data.InvocationMarshaller; import com.threerings.presents.data.InvocationMarshaller_ListenerMarshaller; import com.threerings.presents.data.InvocationMarshaller_ResultMarshaller; import com.threerings.util.Integer; +import com.threerings.util.Name; /** * Provides the implementation of the TableService interface @@ -45,12 +46,12 @@ public class TableMarshaller extends InvocationMarshaller public static const BOOT_PLAYER :int = 1; // 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(); listener4.listener = arg4; sendRequest(arg1, BOOT_PLAYER, [ - Integer.valueOf(arg2), Integer.valueOf(arg3), listener4 + Integer.valueOf(arg2), arg3, listener4 ]); } diff --git a/src/java/com/threerings/parlor/client/TableDirector.java b/src/java/com/threerings/parlor/client/TableDirector.java index 007b8120..09d0f0e0 100644 --- a/src/java/com/threerings/parlor/client/TableDirector.java +++ b/src/java/com/threerings/parlor/client/TableDirector.java @@ -23,6 +23,7 @@ package com.threerings.parlor.client; import com.samskivert.util.ObjectUtil; import com.samskivert.util.ObserverList; +import com.threerings.util.Name; import com.threerings.presents.client.BasicDirector; 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. */ - public void bootPlayer (int tableId, int bodyId) + public void bootPlayer (int tableId, Name target) { if (_tlobj == null) { log.warning("Requesting to boot a player from a table we're not currently in " + - "[tableId=" + tableId + ", target=" + bodyId + "]."); + "[tableId=" + tableId + ", target=" + target + "]."); return; } - _tlobj.getTableService().bootPlayer(_ctx.getClient(), tableId, bodyId, this); + _tlobj.getTableService().bootPlayer(_ctx.getClient(), tableId, target, this); } @Override diff --git a/src/java/com/threerings/parlor/client/TableService.java b/src/java/com/threerings/parlor/client/TableService.java index bd3387b5..a23e9cf1 100644 --- a/src/java/com/threerings/parlor/client/TableService.java +++ b/src/java/com/threerings/parlor/client/TableService.java @@ -21,6 +21,8 @@ package com.threerings.parlor.client; +import com.threerings.util.Name; + import com.threerings.presents.client.Client; 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. */ - public void bootPlayer (Client client, int tableId, int bodyId, InvocationListener listener); + public void bootPlayer (Client client, int tableId, Name target, InvocationListener listener); } diff --git a/src/java/com/threerings/parlor/data/Table.java b/src/java/com/threerings/parlor/data/Table.java index df7aea5f..2f6a7231 100644 --- a/src/java/com/threerings/parlor/data/Table.java +++ b/src/java/com/threerings/parlor/data/Table.java @@ -253,13 +253,13 @@ public class Table * Indicate to this table that a user was booted and should * be prevented from rejoining. */ - public void addBannedUser (int position) + public void addBannedUser (Name player) { if (_bannedUsers == null) { _bannedUsers = new HashSet(); } - _bannedUsers.add(players[position]); + _bannedUsers.add(player); } /** diff --git a/src/java/com/threerings/parlor/data/TableMarshaller.java b/src/java/com/threerings/parlor/data/TableMarshaller.java index a533f9b2..14481182 100644 --- a/src/java/com/threerings/parlor/data/TableMarshaller.java +++ b/src/java/com/threerings/parlor/data/TableMarshaller.java @@ -26,6 +26,7 @@ import com.threerings.parlor.game.data.GameConfig; import com.threerings.presents.client.Client; import com.threerings.presents.client.InvocationService; import com.threerings.presents.data.InvocationMarshaller; +import com.threerings.util.Name; /** * Provides the implementation of the {@link TableService} interface @@ -41,12 +42,12 @@ public class TableMarshaller extends InvocationMarshaller public static final int BOOT_PLAYER = 1; // 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(); listener4.listener = arg4; sendRequest(arg1, BOOT_PLAYER, new Object[] { - Integer.valueOf(arg2), Integer.valueOf(arg3), listener4 + Integer.valueOf(arg2), arg3, listener4 }); } diff --git a/src/java/com/threerings/parlor/server/TableDispatcher.java b/src/java/com/threerings/parlor/server/TableDispatcher.java index 6d4d5b05..61edf7b4 100644 --- a/src/java/com/threerings/parlor/server/TableDispatcher.java +++ b/src/java/com/threerings/parlor/server/TableDispatcher.java @@ -28,6 +28,7 @@ import com.threerings.presents.client.InvocationService; import com.threerings.presents.data.ClientObject; import com.threerings.presents.server.InvocationDispatcher; import com.threerings.presents.server.InvocationException; +import com.threerings.util.Name; /** * Dispatches requests to the {@link TableProvider}. @@ -57,7 +58,7 @@ public class TableDispatcher extends InvocationDispatcher switch (methodId) { case TableMarshaller.BOOT_PLAYER: ((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; diff --git a/src/java/com/threerings/parlor/server/TableManager.java b/src/java/com/threerings/parlor/server/TableManager.java index ceca9fac..74609230 100644 --- a/src/java/com/threerings/parlor/server/TableManager.java +++ b/src/java/com/threerings/parlor/server/TableManager.java @@ -23,6 +23,9 @@ package com.threerings.parlor.server; import com.samskivert.util.IntMap; 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.dobj.AttributeChangeListener; import com.threerings.presents.dobj.AttributeChangedEvent; @@ -282,7 +285,7 @@ public class TableManager } // from interface TableProvider - public void bootPlayer (ClientObject caller, int tableId, int position, + public void bootPlayer (ClientObject caller, int tableId, Name target, TableService.InvocationListener listener) throws InvocationException { @@ -291,15 +294,21 @@ public class TableManager if (table == null) { 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) { 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 - table.addBannedUser(position); + table.addBannedUser(target); // Remove the player from the table if (notePlayerRemoved(table.bodyOids[position]) == null) { diff --git a/src/java/com/threerings/parlor/server/TableProvider.java b/src/java/com/threerings/parlor/server/TableProvider.java index efaa0a40..0fe495e5 100644 --- a/src/java/com/threerings/parlor/server/TableProvider.java +++ b/src/java/com/threerings/parlor/server/TableProvider.java @@ -28,6 +28,7 @@ import com.threerings.presents.client.InvocationService; import com.threerings.presents.data.ClientObject; import com.threerings.presents.server.InvocationException; import com.threerings.presents.server.InvocationProvider; +import com.threerings.util.Name; /** * Defines the server-side of the {@link TableService}. @@ -37,7 +38,7 @@ public interface TableProvider extends InvocationProvider /** * 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; /**