From 7d75f0c760913e436a4121082436c970247e2a50 Mon Sep 17 00:00:00 2001 From: Bruno Garcia Date: Wed, 6 Aug 2008 22:52:41 +0000 Subject: [PATCH] - Ban booted players from a table - Boot by sitting position, not oid git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@713 c613c5cb-e716-0410-b11b-feb51c14d237 --- .../threerings/parlor/data/ParlorCodes.java | 5 ++++- .../com/threerings/parlor/data/Table.java | 21 +++++++++++++++++++ .../parlor/server/TableManager.java | 18 +++++++++------- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/java/com/threerings/parlor/data/ParlorCodes.java b/src/java/com/threerings/parlor/data/ParlorCodes.java index fd588b76..3caee617 100644 --- a/src/java/com/threerings/parlor/data/ParlorCodes.java +++ b/src/java/com/threerings/parlor/data/ParlorCodes.java @@ -55,11 +55,14 @@ public interface ParlorCodes extends InvocationCodes * occupied. */ public static final String TABLE_POSITION_OCCUPIED = "m.table_position_occupied"; - /** An error code returned when a user requests to creat or join a table but they're already + /** An error code returned when a user requests to create or join a table but they're already * sitting at another table. */ public static final String ALREADY_AT_TABLE = "m.already_at_table"; /** An error code returned when a user requests to leave a table that they were not sitting at * in the first place. */ public static final String NOT_AT_TABLE = "m.not_at_table"; + + /** An error code returned when a user requests to join a table they've been banned from. */ + public static final String BANNED_FROM_TABLE = "m.banned_from_table"; } diff --git a/src/java/com/threerings/parlor/data/Table.java b/src/java/com/threerings/parlor/data/Table.java index bc08f396..0824e110 100644 --- a/src/java/com/threerings/parlor/data/Table.java +++ b/src/java/com/threerings/parlor/data/Table.java @@ -22,6 +22,7 @@ package com.threerings.parlor.data; import java.util.List; +import java.util.HashSet; import com.google.common.collect.Lists; @@ -228,6 +229,10 @@ public class Table return TABLE_POSITION_OCCUPIED; } + if (_bannedUsers != null && _bannedUsers.contains(player.username)) { + return BANNED_FROM_TABLE; + } + // otherwise all is well, stick 'em in setPlayerPos(position, player); return null; @@ -244,6 +249,19 @@ public class Table bodyOids[position] = player.getOid(); } + /** + * Indicate to this table that a user was booted and should + * be prevented from rejoining. + */ + public void addBannedUser (Name username) + { + if (_bannedUsers == null) { + _bannedUsers = new HashSet(); + } + + _bannedUsers.add(username); + } + /** * Requests that the specified user be removed from their seat at this table. * @@ -423,4 +441,7 @@ public class Table /** A counter for assigning table ids. */ protected static int _tableIdCounter = 0; + + /** On the server, the usernames that have been banned from this table. */ + protected transient HashSet _bannedUsers; } diff --git a/src/java/com/threerings/parlor/server/TableManager.java b/src/java/com/threerings/parlor/server/TableManager.java index 22672a65..df89af42 100644 --- a/src/java/com/threerings/parlor/server/TableManager.java +++ b/src/java/com/threerings/parlor/server/TableManager.java @@ -282,7 +282,7 @@ public class TableManager } // from interface TableProvider - public void bootPlayer (ClientObject caller, int tableId, int bodyId, + public void bootPlayer (ClientObject caller, int tableId, int position, TableService.InvocationListener listener) throws InvocationException { @@ -291,20 +291,24 @@ public class TableManager if (table == null) { throw new InvocationException(NO_SUCH_TABLE); - } else if (booter.getOid() != table.bodyOids[0]) { + } 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); } + // Remember to keep him banned + table.addBannedUser(table.players[position]); + // Remove the player from the table - if ( ! table.clearPlayerByOid(bodyId)) { - throw new InvocationException(NOT_AT_TABLE); - } - if (notePlayerRemoved(bodyId) == null) { - log.warning("No body to table mapping to clear? [bodyId=" + bodyId + + table.clearPlayerPos(position); + if (notePlayerRemoved(table.bodyOids[position]) == null) { + log.warning("No body to table mapping to clear? [position=" + position + ", table=" + table + "]."); } + + _tlobj.updateTables(table); } /**