Include some creation times in responses.

Server startup time is included in first load response, and game creation time is included in game info. IRC bridge uses these, and perhaps a way to see them in the web client will be added too.
This commit is contained in:
Andy Janata 2018-03-26 16:57:40 -07:00
parent 0678272f29
commit 988f63887b
4 changed files with 15 additions and 1 deletions

View File

@ -62,6 +62,7 @@ cah.$.AjaxResponse.CONNECTED_AT = "ca";
cah.$.AjaxResponse.WHITE_CARDS = "wc";
cah.$.AjaxResponse.HAND = "h";
cah.$.AjaxResponse.ERROR_CODE = "ec";
cah.$.AjaxResponse.SERVER_STARTED = "SS";
cah.$.AjaxResponse.NEXT = "next";
cah.$.AjaxResponse.GAME_INFO = "gi";
cah.$.AjaxResponse.ERROR = "e";
@ -226,6 +227,7 @@ cah.$.GameInfo = function() {
};
cah.$.GameInfo.prototype.dummyForAutocomplete = undefined;
cah.$.GameInfo.GAME_OPTIONS = "go";
cah.$.GameInfo.CREATED = "gca";
cah.$.GameInfo.PLAYERS = "P";
cah.$.GameInfo.SPECTATORS = "V";
cah.$.GameInfo.HOST = "H";

View File

@ -301,6 +301,8 @@ public class Constants {
@DuplicationAllowed
@GoDataType("int")
SERIAL(AjaxRequest.SERIAL),
@GoDataType("int64")
SERVER_STARTED("SS"),
@GoDataType("[]int")
WHITE_CARDS("wc");
@ -735,6 +737,8 @@ public class Constants {
*/
@GoStruct
public enum GameInfo {
@GoDataType("int64")
CREATED("gca"),
HOST("H"),
@DuplicationAllowed
@GoDataType("int")

View File

@ -112,6 +112,7 @@ public class Game {
private final GameOptions options = new GameOptions();
private final Set<String> cardcastDeckIds = Collections.synchronizedSet(new HashSet<String>());
private final Metrics metrics;
private final long created = System.currentTimeMillis();
private int judgeIndex = 0;
@ -536,6 +537,7 @@ public class Game {
if (null == host) {
return null;
}
info.put(GameInfo.CREATED, created);
info.put(GameInfo.HOST, host.getUser().getNickname());
info.put(GameInfo.STATE, state.toString());
info.put(GameInfo.GAME_OPTIONS, options.serialize(includePassword));

View File

@ -24,6 +24,7 @@
package net.socialgamer.cah.handlers;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -40,6 +41,7 @@ import com.google.inject.Provider;
import net.socialgamer.cah.CahModule.BanList;
import net.socialgamer.cah.CahModule.IncludeInactiveCardsets;
import net.socialgamer.cah.CahModule.ServerStarted;
import net.socialgamer.cah.Constants.AjaxOperation;
import net.socialgamer.cah.Constants.AjaxResponse;
import net.socialgamer.cah.Constants.CardSetData;
@ -66,13 +68,16 @@ public class FirstLoadHandler extends Handler {
private final Set<String> banList;
private final Session hibernateSession;
private final Provider<Boolean> includeInactiveCardsetsProvider;
private final Date serverStarted;
@Inject
public FirstLoadHandler(final Session hibernateSession, @BanList final Set<String> banList,
@IncludeInactiveCardsets final Provider<Boolean> includeInactiveCardsetsProvider) {
@IncludeInactiveCardsets final Provider<Boolean> includeInactiveCardsetsProvider,
@ServerStarted final Date serverStarted) {
this.banList = banList;
this.hibernateSession = hibernateSession;
this.includeInactiveCardsetsProvider = includeInactiveCardsetsProvider;
this.serverStarted = serverStarted;
}
@Override
@ -123,6 +128,7 @@ public class FirstLoadHandler extends Handler {
} finally {
hibernateSession.close();
}
ret.put(AjaxResponse.SERVER_STARTED, serverStarted.getTime());
return ret;
}