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
|
// from EZGameProvider
|
||||||
public void getCookie (ClientObject caller, final int playerId,
|
public void getCookie (ClientObject caller, final int playerOid,
|
||||||
InvocationService.InvocationListener listener)
|
InvocationService.InvocationListener listener)
|
||||||
throws InvocationException
|
throws InvocationException
|
||||||
{
|
{
|
||||||
GameCookieManager gcm = getCookieManager();
|
GameCookieManager gcm = getCookieManager();
|
||||||
if (_gameObj.userCookies.containsKey(playerId)) {
|
if (_gameObj.userCookies.containsKey(playerOid)) {
|
||||||
// already loaded: we do nothing
|
// already loaded: we do nothing
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_cookieLookups == null) {
|
|
||||||
_cookieLookups = new ArrayIntSet();
|
|
||||||
}
|
|
||||||
// we only start looking up the cookie if nobody else already is
|
// we only start looking up the cookie if nobody else already is
|
||||||
if (!_cookieLookups.contains(playerId)) {
|
if (_cookieLookups.contains(playerOid)) {
|
||||||
BodyObject body = getOccupantByOid(playerId);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BodyObject body = getOccupantByOid(playerOid);
|
||||||
if (body == null) {
|
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);
|
throw new InvocationException(INTERNAL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// indicate that we're looking up a cookie
|
||||||
|
_cookieLookups.add(playerOid);
|
||||||
|
|
||||||
gcm.getCookie(_gameconfig.getGameId(), body, new ResultListener<byte[]>() {
|
gcm.getCookie(_gameconfig.getGameId(), body, new ResultListener<byte[]>() {
|
||||||
public void requestCompleted (byte[] result) {
|
public void requestCompleted (byte[] result) {
|
||||||
// Result may be null: that's ok, it means we've looked up the user's
|
// note that we're done with this lookup
|
||||||
// nonexistant cookie. Only set the cookie if the playerIndex is still in the
|
_cookieLookups.remove(playerOid);
|
||||||
// lookup set, otherwise they left!
|
// result may be null: that's ok, it means we've looked up the user's nonexistent
|
||||||
if (_cookieLookups.remove(playerId) && _gameObj.isActive()) {
|
// cookie; also only set the cookie if the player is still in the room
|
||||||
_gameObj.addToUserCookies(new UserCookie(playerId, result));
|
if (_gameObj.occupants.contains(playerOid) && _gameObj.isActive()) {
|
||||||
|
_gameObj.addToUserCookies(new UserCookie(playerOid, result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,10 +372,6 @@ public class EZGameManager extends GameManager
|
|||||||
requestCompleted(null);
|
requestCompleted(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// indicate that we're looking up a cookie
|
|
||||||
_cookieLookups.add(playerId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// from EZGameProvider
|
// from EZGameProvider
|
||||||
@@ -389,7 +389,7 @@ public class EZGameManager extends GameManager
|
|||||||
_gameObj.addToUserCookies(cookie);
|
_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
|
* Helper method to send a private message to the specified player oid (must already be
|
||||||
* verified).
|
* verified).
|
||||||
*/
|
*/
|
||||||
protected void sendPrivateMessage (
|
protected void sendPrivateMessage (int playerOid, String msg, Object data)
|
||||||
int playerId, String msg, Object data)
|
|
||||||
throws InvocationException
|
throws InvocationException
|
||||||
{
|
{
|
||||||
BodyObject target = getPlayerByOid(playerId);
|
BodyObject target = getPlayerByOid(playerOid);
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
// TODO: this code has no corresponding translation
|
// TODO: this code has no corresponding translation
|
||||||
throw new InvocationException("m.player_not_around");
|
throw new InvocationException("m.player_not_around");
|
||||||
@@ -566,6 +565,11 @@ public class EZGameManager extends GameManager
|
|||||||
if (bodyOid == _gameObj.controllerOid) {
|
if (bodyOid == _gameObj.controllerOid) {
|
||||||
_gameObj.setControllerOid(getControllerOid());
|
_gameObj.setControllerOid(getControllerOid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nix any of this player's cookies
|
||||||
|
if (_gameObj.userCookies != null && _gameObj.userCookies.containsKey(bodyOid)) {
|
||||||
|
_gameObj.removeFromUserCookies(bodyOid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -585,21 +589,6 @@ public class EZGameManager extends GameManager
|
|||||||
super.gameDidEnd();
|
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
|
@Override
|
||||||
protected void assignWinners (boolean[] winners)
|
protected void assignWinners (boolean[] winners)
|
||||||
{
|
{
|
||||||
@@ -701,7 +690,7 @@ public class EZGameManager extends GameManager
|
|||||||
protected HashMap<String, Ticker> _tickers;
|
protected HashMap<String, Ticker> _tickers;
|
||||||
|
|
||||||
/** Tracks which cookies are currently being retrieved from the db. */
|
/** Tracks which cookies are currently being retrieved from the db. */
|
||||||
protected ArrayIntSet _cookieLookups;
|
protected ArrayIntSet _cookieLookups = new ArrayIntSet();
|
||||||
|
|
||||||
// /** User tokens, lazy-initialized. */
|
// /** User tokens, lazy-initialized. */
|
||||||
// protected HashIntMap<HashSet<String>> _tokens;
|
// protected HashIntMap<HashSet<String>> _tokens;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import com.samskivert.jdbc.RepositoryListenerUnit;
|
|||||||
import com.samskivert.util.Invoker;
|
import com.samskivert.util.Invoker;
|
||||||
import com.samskivert.util.ResultListener;
|
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.crowd.server.CrowdServer;
|
||||||
import com.threerings.ezgame.server.persist.GameCookieRepository;
|
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
|
/** 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). */
|
* 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.
|
* 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) {
|
if (userId == 0) {
|
||||||
rl.requestCompleted(null);
|
rl.requestCompleted(null);
|
||||||
return;
|
return;
|
||||||
@@ -105,9 +105,9 @@ public class GameCookieManager
|
|||||||
/**
|
/**
|
||||||
* Set the specified user's cookie.
|
* 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) {
|
if (userId == 0) {
|
||||||
// fail to save, silently
|
// fail to save, silently
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user