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

View File

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

View File

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

View File

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