Server: ignore connection problem logs if user don't have game sessions;

This commit is contained in:
Oleg Agafonov 2020-01-16 21:26:39 +04:00
parent d08e54f6fc
commit cdce5c2c82
2 changed files with 18 additions and 7 deletions

View file

@ -20,6 +20,7 @@ import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* @author BetaSteward_at_googlemail.com
@ -320,13 +321,24 @@ public enum ChatManager {
UserManager.instance.getUser(userId).ifPresent(user -> sendMessageToUserChats(userId, user.getName() + " " + reason.getMessage()));
}
/**
* Send message to all active waiting/tourney/game chats (but not in main lobby)
*
* @param userId
* @param message
*/
public void sendMessageToUserChats(UUID userId, String message) {
UserManager.instance.getUser(userId).ifPresent(user
-> getChatSessions()
.stream()
UserManager.instance.getUser(userId).ifPresent(user -> {
List<ChatSession> chatSessions = getChatSessions().stream()
.filter(chat -> !chat.getChatId().equals(GamesRoomManager.instance.getMainChatId())) // ignore main lobby
.filter(chat -> chat.hasUser(userId))
.forEach(chatSession -> chatSession.broadcast(null, message, MessageColor.BLUE, true, MessageType.STATUS, null)));
.collect(Collectors.toList());
if (chatSessions.size() > 0) {
logger.info("INFORM OPPONENTS by " + user.getName() + ": " + message);
chatSessions.forEach(chatSession -> chatSession.broadcast(null, message, MessageColor.BLUE, true, MessageType.STATUS, null));
}
});
}
public void removeUser(UUID userId, DisconnectReason reason) {

View file

@ -152,7 +152,6 @@ public enum UserManager {
-> USER_EXECUTOR.execute(
() -> {
try {
logger.info("INFORM OPPONENTS by " + user.getName() + ": " + message);
ChatManager.instance.sendMessageToUserChats(user.getId(), message);
} catch (Exception ex) {
handleException(ex);