Remove the cookie when the player leaves the room, not necessarily when their
game ends. We may need their when the game is not in play. playerGameDidEnd() was removing based on player index rather than playerOId which was is correct. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@341 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -332,34 +332,38 @@ public class EZGameManager extends GameManager
|
||||
}
|
||||
|
||||
// from EZGameProvider
|
||||
public void getCookie (ClientObject caller, final int playerId,
|
||||
public void getCookie (ClientObject caller, final int playerOid,
|
||||
InvocationService.InvocationListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
GameCookieManager gcm = getCookieManager();
|
||||
if (_gameObj.userCookies.containsKey(playerId)) {
|
||||
if (_gameObj.userCookies.containsKey(playerOid)) {
|
||||
// already loaded: we do nothing
|
||||
return;
|
||||
}
|
||||
|
||||
if (_cookieLookups == null) {
|
||||
_cookieLookups = new ArrayIntSet();
|
||||
}
|
||||
// we only start looking up the cookie if nobody else already is
|
||||
if (!_cookieLookups.contains(playerId)) {
|
||||
BodyObject body = getOccupantByOid(playerId);
|
||||
if (_cookieLookups.contains(playerOid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
BodyObject body = getOccupantByOid(playerOid);
|
||||
if (body == null) {
|
||||
log.fine("getCookie() called with invalid occupant [occupantId=" + playerId + "].");
|
||||
log.fine("getCookie() called with invalid occupant [occupantId=" + playerOid + "].");
|
||||
throw new InvocationException(INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
// indicate that we're looking up a cookie
|
||||
_cookieLookups.add(playerOid);
|
||||
|
||||
gcm.getCookie(_gameconfig.getGameId(), body, new ResultListener<byte[]>() {
|
||||
public void requestCompleted (byte[] result) {
|
||||
// Result may be null: that's ok, it means we've looked up the user's
|
||||
// nonexistant cookie. Only set the cookie if the playerIndex is still in the
|
||||
// lookup set, otherwise they left!
|
||||
if (_cookieLookups.remove(playerId) && _gameObj.isActive()) {
|
||||
_gameObj.addToUserCookies(new UserCookie(playerId, result));
|
||||
// note that we're done with this lookup
|
||||
_cookieLookups.remove(playerOid);
|
||||
// result may be null: that's ok, it means we've looked up the user's nonexistent
|
||||
// cookie; also only set the cookie if the player is still in the room
|
||||
if (_gameObj.occupants.contains(playerOid) && _gameObj.isActive()) {
|
||||
_gameObj.addToUserCookies(new UserCookie(playerOid, result));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,10 +372,6 @@ public class EZGameManager extends GameManager
|
||||
requestCompleted(null);
|
||||
}
|
||||
});
|
||||
|
||||
// indicate that we're looking up a cookie
|
||||
_cookieLookups.add(playerId);
|
||||
}
|
||||
}
|
||||
|
||||
// from EZGameProvider
|
||||
@@ -389,7 +389,7 @@ public class EZGameManager extends GameManager
|
||||
_gameObj.addToUserCookies(cookie);
|
||||
}
|
||||
|
||||
gcm.setCookie(_gameconfig.getGameId(), caller, value);
|
||||
gcm.setCookie(_gameconfig.getGameId(), (BodyObject)caller, value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -415,11 +415,10 @@ public class EZGameManager extends GameManager
|
||||
* Helper method to send a private message to the specified player oid (must already be
|
||||
* verified).
|
||||
*/
|
||||
protected void sendPrivateMessage (
|
||||
int playerId, String msg, Object data)
|
||||
protected void sendPrivateMessage (int playerOid, String msg, Object data)
|
||||
throws InvocationException
|
||||
{
|
||||
BodyObject target = getPlayerByOid(playerId);
|
||||
BodyObject target = getPlayerByOid(playerOid);
|
||||
if (target == null) {
|
||||
// TODO: this code has no corresponding translation
|
||||
throw new InvocationException("m.player_not_around");
|
||||
@@ -566,6 +565,11 @@ public class EZGameManager extends GameManager
|
||||
if (bodyOid == _gameObj.controllerOid) {
|
||||
_gameObj.setControllerOid(getControllerOid());
|
||||
}
|
||||
|
||||
// nix any of this player's cookies
|
||||
if (_gameObj.userCookies != null && _gameObj.userCookies.containsKey(bodyOid)) {
|
||||
_gameObj.removeFromUserCookies(bodyOid);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -585,21 +589,6 @@ public class EZGameManager extends GameManager
|
||||
super.gameDidEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void playerGameDidEnd (int pidx)
|
||||
{
|
||||
super.playerGameDidEnd(pidx);
|
||||
|
||||
// kill any of their cookies
|
||||
if (_gameObj.userCookies != null && _gameObj.userCookies.containsKey(pidx)) {
|
||||
_gameObj.removeFromUserCookies(pidx);
|
||||
}
|
||||
// halt the loading of their cookie, if in progress
|
||||
if (_cookieLookups != null) {
|
||||
_cookieLookups.remove(pidx);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assignWinners (boolean[] winners)
|
||||
{
|
||||
@@ -701,7 +690,7 @@ public class EZGameManager extends GameManager
|
||||
protected HashMap<String, Ticker> _tickers;
|
||||
|
||||
/** Tracks which cookies are currently being retrieved from the db. */
|
||||
protected ArrayIntSet _cookieLookups;
|
||||
protected ArrayIntSet _cookieLookups = new ArrayIntSet();
|
||||
|
||||
// /** User tokens, lazy-initialized. */
|
||||
// protected HashIntMap<HashSet<String>> _tokens;
|
||||
|
||||
@@ -29,7 +29,7 @@ import com.samskivert.jdbc.RepositoryListenerUnit;
|
||||
import com.samskivert.util.Invoker;
|
||||
import com.samskivert.util.ResultListener;
|
||||
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import com.threerings.crowd.data.BodyObject;
|
||||
import com.threerings.crowd.server.CrowdServer;
|
||||
import com.threerings.ezgame.server.persist.GameCookieRepository;
|
||||
|
||||
@@ -47,7 +47,7 @@ public class GameCookieManager
|
||||
{
|
||||
/** Return the persistent user id for the specified player, or 0 if they're not a valid
|
||||
* user, or a guest, or something like that (they'll have no cookies). */
|
||||
public int getUserId (ClientObject clientObj);
|
||||
public int getUserId (BodyObject bodyObj);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,9 +81,9 @@ public class GameCookieManager
|
||||
/**
|
||||
* Get the specified user's cookie.
|
||||
*/
|
||||
public void getCookie (final int gameId, ClientObject cliObj, ResultListener<byte[]> rl)
|
||||
public void getCookie (final int gameId, BodyObject bobj, ResultListener<byte[]> rl)
|
||||
{
|
||||
final int userId = _identifier.getUserId(cliObj);
|
||||
final int userId = _identifier.getUserId(bobj);
|
||||
if (userId == 0) {
|
||||
rl.requestCompleted(null);
|
||||
return;
|
||||
@@ -105,9 +105,9 @@ public class GameCookieManager
|
||||
/**
|
||||
* Set the specified user's cookie.
|
||||
*/
|
||||
public void setCookie (final int gameId, ClientObject cliObj, final byte[] cookie)
|
||||
public void setCookie (final int gameId, BodyObject bobj, final byte[] cookie)
|
||||
{
|
||||
final int userId = _identifier.getUserId(cliObj);
|
||||
final int userId = _identifier.getUserId(bobj);
|
||||
if (userId == 0) {
|
||||
// fail to save, silently
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user