* Server: added /pings chat command to show players and watchers ping info;

This commit is contained in:
Oleg Agafonov 2020-01-31 22:30:31 +04:00
parent 17cf3cd129
commit 2079065af3
3 changed files with 48 additions and 3 deletions

View file

@ -433,7 +433,8 @@ public class CallbackClientImpl implements CallbackClient {
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_TOGGLE_MACRO))) .append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_TOGGLE_MACRO)))
.append("</b> - Toggle recording a sequence of actions to repeat. Will not pause if interrupted and can fail if a selected card changes such as when scrying top card to bottom.") .append("</b> - Toggle recording a sequence of actions to repeat. Will not pause if interrupted and can fail if a selected card changes such as when scrying top card to bottom.")
.append("<br/><b>").append(System.getProperty("os.name").contains("Mac OS X") ? "Cmd" : "Ctrl").append(" + click</b> - Hold priority while casting a spell or activating an ability") .append("<br/><b>").append(System.getProperty("os.name").contains("Mac OS X") ? "Cmd" : "Ctrl").append(" + click</b> - Hold priority while casting a spell or activating an ability")
.append("<br/>").append("Type <b>/FIX</b> message in chat to fix freezed game") .append("<br/>").append("Type <b>/fix</b> message in chat to fix freezed game")
.append("<br/>").append("Type <b>/pings</b> message in chat to show players and watchers ping")
.toString(), .toString(),
null, MessageType.USER_INFO, ChatMessage.MessageColor.BLUE); null, MessageType.USER_INFO, ChatMessage.MessageColor.BLUE);
break; break;

View file

@ -201,7 +201,7 @@ public enum ChatManager {
return true; return true;
} }
if (command.startsWith("GAME")) { if (command.startsWith("GAME")) {
message += "<br/>" + GameManager.instance.getChatId(chatId); message += "<br/>";
ChatSession session = chatSessions.get(chatId); ChatSession session = chatSessions.get(chatId);
if (session != null && session.getInfo() != null) { if (session != null && session.getInfo() != null) {
String gameId = session.getInfo(); String gameId = session.getInfo();
@ -222,7 +222,7 @@ public enum ChatManager {
return true; return true;
} }
if (command.startsWith("FIX")) { if (command.startsWith("FIX")) {
message += "<br/>" + GameManager.instance.getChatId(chatId); message += "<br/>";
ChatSession session = chatSessions.get(chatId); ChatSession session = chatSessions.get(chatId);
if (session != null && session.getInfo() != null) { if (session != null && session.getInfo() != null) {
String gameId = session.getInfo(); String gameId = session.getInfo();
@ -242,6 +242,27 @@ public enum ChatManager {
} }
return true; return true;
} }
if (command.equals("PINGS")) {
message += "<br/>";
ChatSession session = chatSessions.get(chatId);
if (session != null && session.getInfo() != null) {
String gameId = session.getInfo();
if (gameId.startsWith("Game ")) {
UUID id = java.util.UUID.fromString(gameId.substring(5));
for (Entry<UUID, GameController> entry : GameManager.instance.getGameController().entrySet()) {
if (entry.getKey().equals(id)) {
GameController controller = entry.getValue();
if (controller != null) {
message += controller.getPingsInfo();
chatSessions.get(chatId).broadcastInfoToUser(user, message);
}
}
}
}
}
return true;
}
if (command.startsWith("CARD ")) { if (command.startsWith("CARD ")) {
Matcher matchPattern = getCardTextPattern.matcher(message.toLowerCase(Locale.ENGLISH)); Matcher matchPattern = getCardTextPattern.matcher(message.toLowerCase(Locale.ENGLISH));
if (matchPattern.find()) { if (matchPattern.find()) {

View file

@ -1188,6 +1188,29 @@ public class GameController implements GameCallback {
return player != null ? player.getName() : "-"; return player != null ? player.getName() : "-";
} }
public String getPingsInfo() {
List<String> usersInfo = new ArrayList<>();
for (Map.Entry<UUID, UUID> entry : userPlayerMap.entrySet()) {
Optional<User> user = UserManager.instance.getUser(entry.getKey());
user.ifPresent(u -> usersInfo.add(u.getName() + ": " + u.getPingInfo()));
}
Collections.sort(usersInfo);
usersInfo.add(0, "Players ping:");
List<String> watchersinfo = new ArrayList<>();
for (Map.Entry<UUID, GameSessionWatcher> entry : watchers.entrySet()) {
Optional<User> user = UserManager.instance.getUser(entry.getValue().userId);
user.ifPresent(u -> watchersinfo.add(u.getName() + ": " + u.getPingInfo()));
}
Collections.sort(watchersinfo);
if (watchersinfo.size() > 0) {
watchersinfo.add(0, "Watchers ping:");
}
usersInfo.addAll(watchersinfo);
return String.join("<br>", usersInfo);
}
public String attemptToFixGame() { public String attemptToFixGame() {
// try to fix disconnects // try to fix disconnects