Add a /whois command.

Cleaned up some synchronization around ConnectedUsers.users while I was in there. The list itself wasn't synchronized, which could have been a slight problem.
This commit is contained in:
Andy Janata 2018-03-06 00:15:05 -08:00
parent 1fb621e175
commit e1578532e3
11 changed files with 405 additions and 245 deletions

View File

@ -1,5 +1,5 @@
/**
* Copyright (c) 2012-2017, Andy Janata
* Copyright (c) 2012-2018, Andy Janata
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
@ -646,3 +646,8 @@ dfn {
#tweetbox {
float: right;
}
.gamelink {
cursor: pointer;
text-decoration: underline;
}

View File

@ -304,3 +304,40 @@ cah.ajax.SuccessHandlers[cah.$.AjaxOperation.CARDCAST_LIST_CARDSETS] = function(
game.listCardcastDecks(data[cah.$.AjaxResponse.CARD_SETS]);
}
};
cah.ajax.SuccessHandlers[cah.$.AjaxOperation.WHOIS] = function(data) {
var nick = data[cah.$.AjaxResponse.NICKNAME];
var sigil = data[cah.$.AjaxResponse.SIGIL];
cah.log.status("Whois information for " + sigil + nick + ":");
if (cah.$.Sigil.ADMIN == sigil) {
cah.log.status("* <strong>Is an administrator</strong>", null, true);
}
if (data[cah.$.AjaxResponse.ID_CODE] != "") {
cah.log.status("* Identification code: " + data[cah.$.AjaxResponse.ID_CODE]);
}
if (data[cah.$.AjaxResponse.IP_ADDRESS]) {
cah.log.status("* Hostname: " + data[cah.$.AjaxResponse.IP_ADDRESS]);
}
if (data[cah.$.AjaxResponse.CLIENT_NAME]) {
cah.log.status("* Client: " + data[cah.$.AjaxResponse.CLIENT_NAME]);
}
var gameId = data[cah.$.AjaxResponse.GAME_ID];
if (undefined !== gameId) {
var gameInfo = data[cah.$.AjaxResponse.GAME_INFO];
var stateMsg = cah.$.GameState_msg[gameInfo[cah.$.GameInfo.STATE]];
for (var i = 0; i < gameInfo[cah.$.GameInfo.SPECTATORS].length; i++) {
if (gameInfo[cah.$.GameInfo.SPECTATORS] == nick) {
stateMsg += ", Spectating";
break;
}
}
cah.log.status("* Game: <a onclick='$(\"#filter_games\").val(\"" + nick
+ "\").keyup()' class='gamelink'>#" + gameId + "</a>, " + stateMsg, null, true);
}
cah.log.status("* Connected at "
+ new Date(data[cah.$.AjaxResponse.CONNECTED_AT]).toLocaleString());
var idle = new Date(data[cah.$.AjaxResponse.IDLE]);
cah.log.status("* Idle " + idle.getUTCHours() + " hours " + idle.getUTCMinutes() + " mins "
+ idle.getUTCSeconds() + " secs");
cah.log.status("End of whois information");
};

View File

@ -236,6 +236,9 @@ function chatsubmit_click(game_id, parent_element) {
cah.log.error("This command only works in a game.");
}
break;
case 'whois':
ajax = cah.Ajax.build(cah.$.AjaxOperation.WHOIS).withNickname(text.split(' ')[0]);
break;
default:
cah.log.error("Invalid command.");
}

View File

@ -2,81 +2,95 @@
cah.$ = {};
cah.$.GamePlayerStatus = function() {
cah.$.AjaxOperation = function() {
// Dummy constructor to make Eclipse auto-complete.
};
cah.$.GamePlayerStatus.prototype.dummyForAutocomplete = undefined;
cah.$.GamePlayerStatus.SPECTATOR = "sv";
cah.$.GamePlayerStatus.WINNER = "sw";
cah.$.GamePlayerStatus.IDLE = "si";
cah.$.GamePlayerStatus.HOST = "sh";
cah.$.GamePlayerStatus.JUDGING = "sjj";
cah.$.GamePlayerStatus.JUDGE = "sj";
cah.$.GamePlayerStatus.PLAYING = "sp";
cah.$.GamePlayerStatus_msg = {};
cah.$.GamePlayerStatus_msg['sjj'] = "Selecting";
cah.$.GamePlayerStatus_msg['sv'] = "Spectator";
cah.$.GamePlayerStatus_msg['sw'] = "Winner!";
cah.$.GamePlayerStatus_msg['sh'] = "Host";
cah.$.GamePlayerStatus_msg['si'] = "";
cah.$.GamePlayerStatus_msg['sj'] = "Card Czar";
cah.$.GamePlayerStatus_msg['sp'] = "Playing";
cah.$.GamePlayerStatus_msg_2 = {};
cah.$.GamePlayerStatus_msg_2['sjj'] = "Select a winning card.";
cah.$.GamePlayerStatus_msg_2['sv'] = "You are just spectating.";
cah.$.GamePlayerStatus_msg_2['sw'] = "You have won!";
cah.$.GamePlayerStatus_msg_2['sh'] = "Wait for players then click Start Game.";
cah.$.GamePlayerStatus_msg_2['si'] = "Waiting for players...";
cah.$.GamePlayerStatus_msg_2['sj'] = "You are the Card Czar.";
cah.$.GamePlayerStatus_msg_2['sp'] = "Select a card to play.";
cah.$.AjaxOperation.prototype.dummyForAutocomplete = undefined;
cah.$.AjaxOperation.NAMES = "gn";
cah.$.AjaxOperation.SCORE = "SC";
cah.$.AjaxOperation.LEAVE_GAME = "lg";
cah.$.AjaxOperation.JOIN_GAME = "jg";
cah.$.AjaxOperation.CHAT = "c";
cah.$.AjaxOperation.GAME_LIST = "ggl";
cah.$.AjaxOperation.CARDCAST_ADD_CARDSET = "cac";
cah.$.AjaxOperation.CARDCAST_LIST_CARDSETS = "clc";
cah.$.AjaxOperation.PLAY_CARD = "pc";
cah.$.AjaxOperation.CHANGE_GAME_OPTIONS = "cgo";
cah.$.AjaxOperation.GET_GAME_INFO = "ggi";
cah.$.AjaxOperation.GET_CARDS = "gc";
cah.$.AjaxOperation.ADMIN_SET_VERBOSE_LOG = "svl";
cah.$.AjaxOperation.REGISTER = "r";
cah.$.AjaxOperation.CARDCAST_REMOVE_CARDSET = "crc";
cah.$.AjaxOperation.WHOIS = "Wi";
cah.$.AjaxOperation.KICK = "K";
cah.$.AjaxOperation.FIRST_LOAD = "fl";
cah.$.AjaxOperation.START_GAME = "sg";
cah.$.AjaxOperation.LOG_OUT = "lo";
cah.$.AjaxOperation.BAN = "b";
cah.$.AjaxOperation.CREATE_GAME = "cg";
cah.$.AjaxOperation.STOP_GAME = "Sg";
cah.$.AjaxOperation.GAME_CHAT = "GC";
cah.$.AjaxOperation.SPECTATE_GAME = "vg";
cah.$.AjaxOperation.JUDGE_SELECT = "js";
cah.$.GamePlayerInfo = function() {
cah.$.AjaxRequest = function() {
// Dummy constructor to make Eclipse auto-complete.
};
cah.$.GamePlayerInfo.prototype.dummyForAutocomplete = undefined;
cah.$.GamePlayerInfo.STATUS = "st";
cah.$.GamePlayerInfo.SCORE = "sc";
cah.$.GamePlayerInfo.NAME = "N";
cah.$.AjaxRequest.prototype.dummyForAutocomplete = undefined;
cah.$.AjaxRequest.SERIAL = "s";
cah.$.AjaxRequest.OP = "o";
cah.$.AjaxRequest.WALL = "wall";
cah.$.AjaxRequest.PERSISTENT_ID = "pid";
cah.$.AjaxRequest.EMOTE = "me";
cah.$.AjaxRequest.CARDCAST_ID = "cci";
cah.$.AjaxRequest.GAME_ID = "gid";
cah.$.AjaxRequest.GAME_OPTIONS = "go";
cah.$.AjaxRequest.MESSAGE = "m";
cah.$.AjaxRequest.NICKNAME = "n";
cah.$.AjaxRequest.PASSWORD = "pw";
cah.$.AjaxRequest.CARD_ID = "cid";
cah.$.AjaxRequest.ID_CODE = "idc";
cah.$.GameOptionData = function() {
cah.$.AjaxResponse = function() {
// Dummy constructor to make Eclipse auto-complete.
};
cah.$.GameOptionData.prototype.dummyForAutocomplete = undefined;
cah.$.GameOptionData.TIMER_MULTIPLIER = "tm";
cah.$.GameOptionData.PASSWORD = "pw";
cah.$.GameOptionData.SPECTATOR_LIMIT = "vL";
cah.$.GameOptionData.SCORE_LIMIT = "sl";
cah.$.GameOptionData.BLANKS_LIMIT = "bl";
cah.$.GameOptionData.PLAYER_LIMIT = "pL";
cah.$.GameOptionData.CARD_SETS = "css";
cah.$.AjaxResponse.prototype.dummyForAutocomplete = undefined;
cah.$.AjaxResponse.NAMES = "nl";
cah.$.AjaxResponse.CLIENT_NAME = "cn";
cah.$.AjaxResponse.PLAYER_INFO = "pi";
cah.$.AjaxResponse.CONNECTED_AT = "ca";
cah.$.AjaxResponse.WHITE_CARDS = "wc";
cah.$.AjaxResponse.HAND = "h";
cah.$.AjaxResponse.ERROR_CODE = "ec";
cah.$.AjaxResponse.NEXT = "next";
cah.$.AjaxResponse.GAME_INFO = "gi";
cah.$.AjaxResponse.ERROR = "e";
cah.$.AjaxResponse.GAME_STATE_DESCRIPTION = "gss";
cah.$.AjaxResponse.ID_CODE = "idc";
cah.$.AjaxResponse.CARD_SETS = "css";
cah.$.AjaxResponse.SERIAL = "s";
cah.$.AjaxResponse.PERSISTENT_ID = "pid";
cah.$.AjaxResponse.GAMES = "gl";
cah.$.AjaxResponse.SIGIL = "?";
cah.$.AjaxResponse.GAME_ID = "gid";
cah.$.AjaxResponse.MAX_GAMES = "mg";
cah.$.AjaxResponse.IN_PROGRESS = "ip";
cah.$.AjaxResponse.GAME_OPTIONS = "go";
cah.$.AjaxResponse.NICKNAME = "n";
cah.$.AjaxResponse.BLACK_CARD = "bc";
cah.$.AjaxResponse.IDLE = "idl";
cah.$.AjaxResponse.CARD_ID = "cid";
cah.$.AjaxResponse.IP_ADDRESS = "IP";
cah.$.GameInfo = function() {
cah.$.BlackCardData = function() {
// Dummy constructor to make Eclipse auto-complete.
};
cah.$.GameInfo.prototype.dummyForAutocomplete = undefined;
cah.$.GameInfo.GAME_OPTIONS = "go";
cah.$.GameInfo.PLAYERS = "P";
cah.$.GameInfo.SPECTATORS = "V";
cah.$.GameInfo.HOST = "H";
cah.$.GameInfo.STATE = "S";
cah.$.GameInfo.ID = "gid";
cah.$.GameInfo.HAS_PASSWORD = "hp";
cah.$.GameState = function() {
// Dummy constructor to make Eclipse auto-complete.
};
cah.$.GameState.prototype.dummyForAutocomplete = undefined;
cah.$.GameState.ROUND_OVER = "ro";
cah.$.GameState.LOBBY = "l";
cah.$.GameState.DEALING = "d";
cah.$.GameState.JUDGING = "j";
cah.$.GameState.PLAYING = "p";
cah.$.GameState_msg = {};
cah.$.GameState_msg['p'] = "In Progress";
cah.$.GameState_msg['d'] = "In Progress";
cah.$.GameState_msg['j'] = "In Progress";
cah.$.GameState_msg['l'] = "Not Started";
cah.$.GameState_msg['ro'] = "In Progress";
cah.$.BlackCardData.prototype.dummyForAutocomplete = undefined;
cah.$.BlackCardData.DRAW = "D";
cah.$.BlackCardData.PICK = "PK";
cah.$.BlackCardData.TEXT = "T";
cah.$.BlackCardData.ID = "cid";
cah.$.BlackCardData.WATERMARK = "W";
cah.$.CardSetData = function() {
// Dummy constructor to make Eclipse auto-complete.
@ -90,93 +104,15 @@ cah.$.CardSetData.BASE_DECK = "bd";
cah.$.CardSetData.ID = "cid";
cah.$.CardSetData.WEIGHT = "w";
cah.$.BlackCardData = function() {
cah.$.DisconnectReason = function() {
// Dummy constructor to make Eclipse auto-complete.
};
cah.$.BlackCardData.prototype.dummyForAutocomplete = undefined;
cah.$.BlackCardData.DRAW = "D";
cah.$.BlackCardData.PICK = "PK";
cah.$.BlackCardData.TEXT = "T";
cah.$.BlackCardData.ID = "cid";
cah.$.BlackCardData.WATERMARK = "W";
cah.$.WhiteCardData = function() {
// Dummy constructor to make Eclipse auto-complete.
};
cah.$.WhiteCardData.prototype.dummyForAutocomplete = undefined;
cah.$.WhiteCardData.WRITE_IN = "wi";
cah.$.WhiteCardData.TEXT = "T";
cah.$.WhiteCardData.ID = "cid";
cah.$.WhiteCardData.WATERMARK = "W";
cah.$.Sigil = function() {
// Dummy constructor to make Eclipse auto-complete.
};
cah.$.Sigil.prototype.dummyForAutocomplete = undefined;
cah.$.Sigil.NORMAL_USER = "";
cah.$.Sigil.ADMIN = "@";
cah.$.Sigil.ID_CODE = "+";
cah.$.LongPollResponse = function() {
// Dummy constructor to make Eclipse auto-complete.
};
cah.$.LongPollResponse.prototype.dummyForAutocomplete = undefined;
cah.$.LongPollResponse.PLAY_TIMER = "Pt";
cah.$.LongPollResponse.PLAYER_INFO = "pi";
cah.$.LongPollResponse.FROM = "f";
cah.$.LongPollResponse.WHITE_CARDS = "wc";
cah.$.LongPollResponse.EVENT = "E";
cah.$.LongPollResponse.HAND = "h";
cah.$.LongPollResponse.ERROR_CODE = "ec";
cah.$.LongPollResponse.MESSAGE = "m";
cah.$.LongPollResponse.WINNING_CARD = "WC";
cah.$.LongPollResponse.FROM_ADMIN = "fa";
cah.$.LongPollResponse.TIMESTAMP = "ts";
cah.$.LongPollResponse.GAME_INFO = "gi";
cah.$.LongPollResponse.ERROR = "e";
cah.$.LongPollResponse.ID_CODE = "idc";
cah.$.LongPollResponse.REASON = "qr";
cah.$.LongPollResponse.WALL = "wall";
cah.$.LongPollResponse.ROUND_WINNER = "rw";
cah.$.LongPollResponse.SIGIL = "?";
cah.$.LongPollResponse.EMOTE = "me";
cah.$.LongPollResponse.CARDCAST_DECK_INFO = "cdi";
cah.$.LongPollResponse.GAME_ID = "gid";
cah.$.LongPollResponse.NICKNAME = "n";
cah.$.LongPollResponse.BLACK_CARD = "bc";
cah.$.LongPollResponse.GAME_STATE = "gs";
cah.$.LongPollResponse.INTERMISSION = "i";
cah.$.LongPollEvent = function() {
// Dummy constructor to make Eclipse auto-complete.
};
cah.$.LongPollEvent.prototype.dummyForAutocomplete = undefined;
cah.$.LongPollEvent.GAME_ROUND_COMPLETE = "grc";
cah.$.LongPollEvent.BANNED = "B&";
cah.$.LongPollEvent.NOOP = "_";
cah.$.LongPollEvent.CHAT = "c";
cah.$.LongPollEvent.GAME_PLAYER_INFO_CHANGE = "gpic";
cah.$.LongPollEvent.HAND_DEAL = "hd";
cah.$.LongPollEvent.CARDCAST_ADD_CARDSET = "cac";
cah.$.LongPollEvent.PLAYER_LEAVE = "pl";
cah.$.LongPollEvent.GAME_BLACK_RESHUFFLE = "gbr";
cah.$.LongPollEvent.GAME_JUDGE_SKIPPED = "gjs";
cah.$.LongPollEvent.GAME_LIST_REFRESH = "glr";
cah.$.LongPollEvent.NEW_PLAYER = "np";
cah.$.LongPollEvent.GAME_PLAYER_SKIPPED = "gps";
cah.$.LongPollEvent.GAME_PLAYER_JOIN = "gpj";
cah.$.LongPollEvent.GAME_WHITE_RESHUFFLE = "gwr";
cah.$.LongPollEvent.CARDCAST_REMOVE_CARDSET = "crc";
cah.$.LongPollEvent.GAME_OPTIONS_CHANGED = "goc";
cah.$.LongPollEvent.GAME_PLAYER_KICKED_IDLE = "gpki";
cah.$.LongPollEvent.GAME_SPECTATOR_LEAVE = "gvl";
cah.$.LongPollEvent.GAME_PLAYER_LEAVE = "gpl";
cah.$.LongPollEvent.GAME_SPECTATOR_JOIN = "gvj";
cah.$.LongPollEvent.HURRY_UP = "hu";
cah.$.LongPollEvent.GAME_JUDGE_LEFT = "gjl";
cah.$.LongPollEvent.KICKED = "k";
cah.$.LongPollEvent.KICKED_FROM_GAME_IDLE = "kfgi";
cah.$.LongPollEvent.GAME_STATE_CHANGE = "gsc";
cah.$.DisconnectReason.prototype.dummyForAutocomplete = undefined;
cah.$.DisconnectReason.PING_TIMEOUT = "pt";
cah.$.DisconnectReason.BANNED = "B&";
cah.$.DisconnectReason.IDLE_TIMEOUT = "it";
cah.$.DisconnectReason.KICKED = "k";
cah.$.DisconnectReason.MANUAL = "man";
cah.$.ErrorCode = function() {
// Dummy constructor to make Eclipse auto-complete.
@ -271,79 +207,142 @@ cah.$.ErrorInformation.WHITE_CARDS_REQUIRED = "wcr";
cah.$.ErrorInformation.BLACK_CARDS_REQUIRED = "bcr";
cah.$.ErrorInformation.BLACK_CARDS_PRESENT = "bcp";
cah.$.AjaxResponse = function() {
cah.$.GameInfo = function() {
// Dummy constructor to make Eclipse auto-complete.
};
cah.$.AjaxResponse.prototype.dummyForAutocomplete = undefined;
cah.$.AjaxResponse.SERIAL = "s";
cah.$.AjaxResponse.NAMES = "nl";
cah.$.AjaxResponse.PERSISTENT_ID = "pid";
cah.$.AjaxResponse.GAMES = "gl";
cah.$.AjaxResponse.SIGIL = "?";
cah.$.AjaxResponse.PLAYER_INFO = "pi";
cah.$.AjaxResponse.GAME_ID = "gid";
cah.$.AjaxResponse.WHITE_CARDS = "wc";
cah.$.AjaxResponse.HAND = "h";
cah.$.AjaxResponse.ERROR_CODE = "ec";
cah.$.AjaxResponse.MAX_GAMES = "mg";
cah.$.AjaxResponse.IN_PROGRESS = "ip";
cah.$.AjaxResponse.GAME_OPTIONS = "go";
cah.$.AjaxResponse.NICKNAME = "n";
cah.$.AjaxResponse.BLACK_CARD = "bc";
cah.$.AjaxResponse.NEXT = "next";
cah.$.AjaxResponse.GAME_INFO = "gi";
cah.$.AjaxResponse.CARD_ID = "cid";
cah.$.AjaxResponse.ERROR = "e";
cah.$.AjaxResponse.ID_CODE = "idc";
cah.$.AjaxResponse.CARD_SETS = "css";
cah.$.GameInfo.prototype.dummyForAutocomplete = undefined;
cah.$.GameInfo.GAME_OPTIONS = "go";
cah.$.GameInfo.PLAYERS = "P";
cah.$.GameInfo.SPECTATORS = "V";
cah.$.GameInfo.HOST = "H";
cah.$.GameInfo.STATE = "S";
cah.$.GameInfo.ID = "gid";
cah.$.GameInfo.HAS_PASSWORD = "hp";
cah.$.AjaxRequest = function() {
cah.$.GameOptionData = function() {
// Dummy constructor to make Eclipse auto-complete.
};
cah.$.AjaxRequest.prototype.dummyForAutocomplete = undefined;
cah.$.AjaxRequest.SERIAL = "s";
cah.$.AjaxRequest.OP = "o";
cah.$.AjaxRequest.WALL = "wall";
cah.$.AjaxRequest.PERSISTENT_ID = "pid";
cah.$.AjaxRequest.EMOTE = "me";
cah.$.AjaxRequest.CARDCAST_ID = "cci";
cah.$.AjaxRequest.GAME_ID = "gid";
cah.$.AjaxRequest.GAME_OPTIONS = "go";
cah.$.AjaxRequest.MESSAGE = "m";
cah.$.AjaxRequest.NICKNAME = "n";
cah.$.AjaxRequest.PASSWORD = "pw";
cah.$.AjaxRequest.CARD_ID = "cid";
cah.$.AjaxRequest.ID_CODE = "idc";
cah.$.GameOptionData.prototype.dummyForAutocomplete = undefined;
cah.$.GameOptionData.TIMER_MULTIPLIER = "tm";
cah.$.GameOptionData.PASSWORD = "pw";
cah.$.GameOptionData.SPECTATOR_LIMIT = "vL";
cah.$.GameOptionData.SCORE_LIMIT = "sl";
cah.$.GameOptionData.BLANKS_LIMIT = "bl";
cah.$.GameOptionData.PLAYER_LIMIT = "pL";
cah.$.GameOptionData.CARD_SETS = "css";
cah.$.AjaxOperation = function() {
cah.$.GamePlayerInfo = function() {
// Dummy constructor to make Eclipse auto-complete.
};
cah.$.AjaxOperation.prototype.dummyForAutocomplete = undefined;
cah.$.AjaxOperation.NAMES = "gn";
cah.$.AjaxOperation.SCORE = "SC";
cah.$.AjaxOperation.LEAVE_GAME = "lg";
cah.$.AjaxOperation.JOIN_GAME = "jg";
cah.$.AjaxOperation.CHAT = "c";
cah.$.AjaxOperation.GAME_LIST = "ggl";
cah.$.AjaxOperation.CARDCAST_ADD_CARDSET = "cac";
cah.$.AjaxOperation.CARDCAST_LIST_CARDSETS = "clc";
cah.$.AjaxOperation.PLAY_CARD = "pc";
cah.$.AjaxOperation.CHANGE_GAME_OPTIONS = "cgo";
cah.$.AjaxOperation.GET_GAME_INFO = "ggi";
cah.$.AjaxOperation.GET_CARDS = "gc";
cah.$.AjaxOperation.ADMIN_SET_VERBOSE_LOG = "svl";
cah.$.AjaxOperation.REGISTER = "r";
cah.$.AjaxOperation.CARDCAST_REMOVE_CARDSET = "crc";
cah.$.AjaxOperation.KICK = "K";
cah.$.AjaxOperation.FIRST_LOAD = "fl";
cah.$.AjaxOperation.START_GAME = "sg";
cah.$.AjaxOperation.LOG_OUT = "lo";
cah.$.AjaxOperation.BAN = "b";
cah.$.AjaxOperation.CREATE_GAME = "cg";
cah.$.AjaxOperation.STOP_GAME = "Sg";
cah.$.AjaxOperation.GAME_CHAT = "GC";
cah.$.AjaxOperation.SPECTATE_GAME = "vg";
cah.$.AjaxOperation.JUDGE_SELECT = "js";
cah.$.GamePlayerInfo.prototype.dummyForAutocomplete = undefined;
cah.$.GamePlayerInfo.STATUS = "st";
cah.$.GamePlayerInfo.SCORE = "sc";
cah.$.GamePlayerInfo.NAME = "N";
cah.$.GamePlayerStatus = function() {
// Dummy constructor to make Eclipse auto-complete.
};
cah.$.GamePlayerStatus.prototype.dummyForAutocomplete = undefined;
cah.$.GamePlayerStatus.SPECTATOR = "sv";
cah.$.GamePlayerStatus.WINNER = "sw";
cah.$.GamePlayerStatus.IDLE = "si";
cah.$.GamePlayerStatus.HOST = "sh";
cah.$.GamePlayerStatus.JUDGING = "sjj";
cah.$.GamePlayerStatus.JUDGE = "sj";
cah.$.GamePlayerStatus.PLAYING = "sp";
cah.$.GamePlayerStatus_msg = {};
cah.$.GamePlayerStatus_msg['sjj'] = "Selecting";
cah.$.GamePlayerStatus_msg['sv'] = "Spectator";
cah.$.GamePlayerStatus_msg['sw'] = "Winner!";
cah.$.GamePlayerStatus_msg['sh'] = "Host";
cah.$.GamePlayerStatus_msg['si'] = "";
cah.$.GamePlayerStatus_msg['sj'] = "Card Czar";
cah.$.GamePlayerStatus_msg['sp'] = "Playing";
cah.$.GamePlayerStatus_msg_2 = {};
cah.$.GamePlayerStatus_msg_2['sjj'] = "Select a winning card.";
cah.$.GamePlayerStatus_msg_2['sv'] = "You are just spectating.";
cah.$.GamePlayerStatus_msg_2['sw'] = "You have won!";
cah.$.GamePlayerStatus_msg_2['sh'] = "Wait for players then click Start Game.";
cah.$.GamePlayerStatus_msg_2['si'] = "Waiting for players...";
cah.$.GamePlayerStatus_msg_2['sj'] = "You are the Card Czar.";
cah.$.GamePlayerStatus_msg_2['sp'] = "Select a card to play.";
cah.$.GameState = function() {
// Dummy constructor to make Eclipse auto-complete.
};
cah.$.GameState.prototype.dummyForAutocomplete = undefined;
cah.$.GameState.ROUND_OVER = "ro";
cah.$.GameState.LOBBY = "l";
cah.$.GameState.DEALING = "d";
cah.$.GameState.JUDGING = "j";
cah.$.GameState.PLAYING = "p";
cah.$.GameState_msg = {};
cah.$.GameState_msg['p'] = "In Progress";
cah.$.GameState_msg['d'] = "In Progress";
cah.$.GameState_msg['j'] = "In Progress";
cah.$.GameState_msg['l'] = "Not Started";
cah.$.GameState_msg['ro'] = "In Progress";
cah.$.LongPollEvent = function() {
// Dummy constructor to make Eclipse auto-complete.
};
cah.$.LongPollEvent.prototype.dummyForAutocomplete = undefined;
cah.$.LongPollEvent.GAME_ROUND_COMPLETE = "grc";
cah.$.LongPollEvent.BANNED = "B&";
cah.$.LongPollEvent.NOOP = "_";
cah.$.LongPollEvent.CHAT = "c";
cah.$.LongPollEvent.GAME_PLAYER_INFO_CHANGE = "gpic";
cah.$.LongPollEvent.HAND_DEAL = "hd";
cah.$.LongPollEvent.CARDCAST_ADD_CARDSET = "cac";
cah.$.LongPollEvent.PLAYER_LEAVE = "pl";
cah.$.LongPollEvent.GAME_BLACK_RESHUFFLE = "gbr";
cah.$.LongPollEvent.GAME_JUDGE_SKIPPED = "gjs";
cah.$.LongPollEvent.GAME_LIST_REFRESH = "glr";
cah.$.LongPollEvent.NEW_PLAYER = "np";
cah.$.LongPollEvent.GAME_PLAYER_SKIPPED = "gps";
cah.$.LongPollEvent.GAME_PLAYER_JOIN = "gpj";
cah.$.LongPollEvent.GAME_WHITE_RESHUFFLE = "gwr";
cah.$.LongPollEvent.CARDCAST_REMOVE_CARDSET = "crc";
cah.$.LongPollEvent.GAME_OPTIONS_CHANGED = "goc";
cah.$.LongPollEvent.GAME_PLAYER_KICKED_IDLE = "gpki";
cah.$.LongPollEvent.GAME_SPECTATOR_LEAVE = "gvl";
cah.$.LongPollEvent.GAME_PLAYER_LEAVE = "gpl";
cah.$.LongPollEvent.GAME_SPECTATOR_JOIN = "gvj";
cah.$.LongPollEvent.HURRY_UP = "hu";
cah.$.LongPollEvent.GAME_JUDGE_LEFT = "gjl";
cah.$.LongPollEvent.KICKED = "k";
cah.$.LongPollEvent.KICKED_FROM_GAME_IDLE = "kfgi";
cah.$.LongPollEvent.GAME_STATE_CHANGE = "gsc";
cah.$.LongPollResponse = function() {
// Dummy constructor to make Eclipse auto-complete.
};
cah.$.LongPollResponse.prototype.dummyForAutocomplete = undefined;
cah.$.LongPollResponse.PLAY_TIMER = "Pt";
cah.$.LongPollResponse.PLAYER_INFO = "pi";
cah.$.LongPollResponse.FROM = "f";
cah.$.LongPollResponse.WHITE_CARDS = "wc";
cah.$.LongPollResponse.EVENT = "E";
cah.$.LongPollResponse.HAND = "h";
cah.$.LongPollResponse.ERROR_CODE = "ec";
cah.$.LongPollResponse.MESSAGE = "m";
cah.$.LongPollResponse.WINNING_CARD = "WC";
cah.$.LongPollResponse.FROM_ADMIN = "fa";
cah.$.LongPollResponse.TIMESTAMP = "ts";
cah.$.LongPollResponse.GAME_INFO = "gi";
cah.$.LongPollResponse.ERROR = "e";
cah.$.LongPollResponse.ID_CODE = "idc";
cah.$.LongPollResponse.REASON = "qr";
cah.$.LongPollResponse.WALL = "wall";
cah.$.LongPollResponse.ROUND_WINNER = "rw";
cah.$.LongPollResponse.SIGIL = "?";
cah.$.LongPollResponse.EMOTE = "me";
cah.$.LongPollResponse.CARDCAST_DECK_INFO = "cdi";
cah.$.LongPollResponse.GAME_ID = "gid";
cah.$.LongPollResponse.NICKNAME = "n";
cah.$.LongPollResponse.BLACK_CARD = "bc";
cah.$.LongPollResponse.GAME_STATE = "gs";
cah.$.LongPollResponse.INTERMISSION = "i";
cah.$.ReconnectNextAction = function() {
// Dummy constructor to make Eclipse auto-complete.
@ -352,13 +351,20 @@ cah.$.ReconnectNextAction.prototype.dummyForAutocomplete = undefined;
cah.$.ReconnectNextAction.GAME = "game";
cah.$.ReconnectNextAction.NONE = "none";
cah.$.DisconnectReason = function() {
cah.$.Sigil = function() {
// Dummy constructor to make Eclipse auto-complete.
};
cah.$.DisconnectReason.prototype.dummyForAutocomplete = undefined;
cah.$.DisconnectReason.PING_TIMEOUT = "pt";
cah.$.DisconnectReason.BANNED = "B&";
cah.$.DisconnectReason.IDLE_TIMEOUT = "it";
cah.$.DisconnectReason.KICKED = "k";
cah.$.DisconnectReason.MANUAL = "man";
cah.$.Sigil.prototype.dummyForAutocomplete = undefined;
cah.$.Sigil.NORMAL_USER = "";
cah.$.Sigil.ADMIN = "@";
cah.$.Sigil.ID_CODE = "+";
cah.$.WhiteCardData = function() {
// Dummy constructor to make Eclipse auto-complete.
};
cah.$.WhiteCardData.prototype.dummyForAutocomplete = undefined;
cah.$.WhiteCardData.WRITE_IN = "wi";
cah.$.WhiteCardData.TEXT = "T";
cah.$.WhiteCardData.ID = "cid";
cah.$.WhiteCardData.WATERMARK = "W";

View File

@ -48,9 +48,13 @@ cah.log.init = function() {
* escaped automatically.
* @param {string}
* opt_class Optional CSS class to use for this message.
* @param {boolean}
* opt_allow_html Allow HTML to be used.
* @param {string}
* opt_title Optional title text for span.
*/
cah.log.status = function(text, opt_class) {
cah.log.status_with_game(null, text, opt_class);
cah.log.status = function(text, opt_class, opt_allow_html, opt_title) {
cah.log.status_with_game(null, text, opt_class, opt_allow_html, opt_title);
};
/**
@ -220,4 +224,4 @@ cah.log.getTitleForIdCode = function(idcode) {
} else {
return null;
}
}
};

View File

@ -192,7 +192,8 @@ public class Constants {
REGISTER("r"),
SCORE("SC"),
START_GAME("sg"),
STOP_GAME("Sg");
STOP_GAME("Sg"),
WHOIS("Wi");
private final String op;
@ -244,6 +245,8 @@ public class Constants {
@DuplicationAllowed
CARD_ID(AjaxRequest.CARD_ID),
CARD_SETS("css"),
CLIENT_NAME("cn"),
CONNECTED_AT("ca"),
ERROR("e"),
ERROR_CODE("ec"),
@DuplicationAllowed
@ -251,10 +254,13 @@ public class Constants {
GAME_INFO("gi"),
@DuplicationAllowed
GAME_OPTIONS(AjaxRequest.GAME_OPTIONS),
GAME_STATE_DESCRIPTION("gss"),
GAMES("gl"),
HAND("h"),
@DuplicationAllowed
ID_CODE(AjaxRequest.ID_CODE),
IDLE("idl"),
IP_ADDRESS("IP"),
/**
* Whether this client is reconnecting or not.
*/

View File

@ -1,5 +1,5 @@
/**
* Copyright (c) 2012, Andy Janata
* Copyright (c) 2012-2018, Andy Janata
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
@ -51,7 +51,7 @@ public class UpdateHandlerList {
* @param args
*/
public static void main(final String[] args) throws Exception {
final String dir = "src/net/socialgamer/cah/handlers/";
final String dir = "src/main/java/net/socialgamer/cah/handlers/";
final File outFile = new File(dir + "Handlers.java");
assert outFile.canWrite();
assert outFile.delete();

View File

@ -27,6 +27,7 @@ import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@ -35,13 +36,6 @@ import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.apache.log4j.Logger;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import com.maxmind.geoip2.model.CityResponse;
import net.socialgamer.cah.CahModule.BroadcastConnectsAndDisconnects;
import net.socialgamer.cah.CahModule.MaxUsers;
import net.socialgamer.cah.Constants.DisconnectReason;
@ -53,6 +47,13 @@ import net.socialgamer.cah.data.QueuedMessage.MessageType;
import net.socialgamer.cah.metrics.GeoIP;
import net.socialgamer.cah.metrics.Metrics;
import org.apache.log4j.Logger;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import com.maxmind.geoip2.model.CityResponse;
/**
* Class that holds all users connected to the server, and provides functions to operate on said
@ -78,7 +79,7 @@ public class ConnectedUsers {
/**
* Key (username) must be stored in lower-case to facilitate case-insensitivity in nicks.
*/
private final Map<String, User> users = new HashMap<String, User>();
private final Map<String, User> users = Collections.synchronizedMap(new HashMap<>());
final Provider<Boolean> broadcastConnectsAndDisconnectsProvider;
final Provider<Integer> maxUsersProvider;
@ -267,7 +268,6 @@ public class ConnectedUsers {
*/
public void broadcastToList(final Collection<User> broadcastTo, final MessageType type,
final HashMap<ReturnableData, Object> masterData) {
// TODO I think this synchronized block is pointless.
synchronized (users) {
for (final User u : broadcastTo) {
@SuppressWarnings("unchecked")

View File

@ -26,20 +26,21 @@ package net.socialgamer.cah.data;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.PriorityBlockingQueue;
import javax.annotation.Nullable;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import net.sf.uadetector.ReadableUserAgent;
import net.sf.uadetector.service.UADetectorServiceFactory;
import net.socialgamer.cah.CahModule.UniqueId;
import net.socialgamer.cah.Constants.Sigil;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
/**
* A user connected to the server.
@ -60,6 +61,8 @@ public class User {
private long lastUserAction = 0;
private final long connectedAt = new Date().getTime();
private Game currentGame;
private final String hostname;
@ -277,6 +280,13 @@ public class User {
return lastUserAction;
}
/**
* @return The UNIX timestamp at which this user connected, in milliseconds.
*/
public long getConnectedAt() {
return connectedAt;
}
/**
* @return False when this user object is no longer valid, probably because it pinged out.
*/

View File

@ -35,5 +35,6 @@ public class Handlers {
LIST.put(SpectateGameHandler.OP, SpectateGameHandler.class);
LIST.put(StartGameHandler.OP, StartGameHandler.class);
LIST.put(StopGameHandler.OP, StopGameHandler.class);
LIST.put(WhoisHandler.OP, WhoisHandler.class);
}
}

View File

@ -0,0 +1,88 @@
/**
* Copyright (c) 2012-2018, Andy Janata
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.socialgamer.cah.handlers;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpSession;
import net.socialgamer.cah.Constants.AjaxOperation;
import net.socialgamer.cah.Constants.AjaxRequest;
import net.socialgamer.cah.Constants.AjaxResponse;
import net.socialgamer.cah.Constants.ErrorCode;
import net.socialgamer.cah.Constants.ReturnableData;
import net.socialgamer.cah.Constants.SessionAttribute;
import net.socialgamer.cah.RequestWrapper;
import net.socialgamer.cah.data.ConnectedUsers;
import net.socialgamer.cah.data.Game;
import net.socialgamer.cah.data.User;
import com.google.inject.Inject;
public class WhoisHandler extends Handler {
public static final String OP = AjaxOperation.WHOIS.toString();
private final ConnectedUsers users;
@Inject
public WhoisHandler(final ConnectedUsers users) {
this.users = users;
}
@Override
public Map<ReturnableData, Object> handle(final RequestWrapper request, final HttpSession session) {
final User requestingUser = (User) session.getAttribute(SessionAttribute.USER);
assert (requestingUser != null);
final Map<ReturnableData, Object> ret = new HashMap<>();
final String nick = request.getParameter(AjaxRequest.NICKNAME);
if (null == nick || nick.trim().isEmpty()) {
return error(ErrorCode.NO_NICK_SPECIFIED);
}
final User user = users.getUser(nick);
if (null == user) {
return error(ErrorCode.NO_SUCH_USER);
}
ret.put(AjaxResponse.NICKNAME, user.getNickname());
ret.put(AjaxResponse.SIGIL, user.getSigil().toString());
ret.put(AjaxResponse.ID_CODE, user.getIdCode());
ret.put(AjaxResponse.CONNECTED_AT, user.getConnectedAt());
ret.put(AjaxResponse.IDLE,
TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - user.getLastUserAction()));
final Game game = user.getGame();
if (null != game) {
ret.put(AjaxResponse.GAME_ID, game.getId());
// overkill but has multiple pieces of information we want
ret.put(AjaxResponse.GAME_INFO, game.getInfo());
}
if (requestingUser.isAdmin()) {
ret.put(AjaxResponse.IP_ADDRESS, user.getHostname());
ret.put(AjaxResponse.CLIENT_NAME, user.getAgentName() + " on " + user.getAgentOs());
}
return ret;
}
}