mirror of
https://github.com/magefree/mage.git
synced 2025-12-29 23:12:10 -08:00
* Changed some server logging.
This commit is contained in:
parent
c22a75a6c3
commit
038b15f399
10 changed files with 89 additions and 62 deletions
|
|
@ -167,20 +167,21 @@ public class Main {
|
|||
public void handleConnectionException(Throwable throwable, Client client) {
|
||||
Session session = SessionManager.getInstance().getSession(client.getSessionId());
|
||||
if (session != null) {
|
||||
String sessionName;
|
||||
StringBuilder sessionInfo = new StringBuilder();
|
||||
User user = UserManager.getInstance().getUser(session.getUserId());
|
||||
if (user != null) {
|
||||
sessionName = user.getName() + " at " + session.getHost();
|
||||
sessionInfo.append(user.getName());
|
||||
} else {
|
||||
sessionName = session.getHost();
|
||||
sessionInfo.append("[user missing] ");
|
||||
}
|
||||
sessionInfo.append(" at ").append(session.getHost()).append(" sessionId: ").append(session.getId());
|
||||
if (throwable instanceof ClientDisconnectedException) {
|
||||
SessionManager.getInstance().disconnect(client.getSessionId(), true);
|
||||
logger.info("Client disconnected - " + sessionName);
|
||||
logger.debug("Client disconnected - " + sessionInfo);
|
||||
}
|
||||
else {
|
||||
SessionManager.getInstance().disconnect(client.getSessionId(), false);
|
||||
logger.info("Connection to client lost - " + sessionName);
|
||||
logger.info("Connection to client lost - " + sessionInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,12 +90,11 @@ public class Session {
|
|||
if (user.getHost().equals(host)) {
|
||||
if (user.getSessionId().isEmpty()) {
|
||||
logger.info("Reconnecting session for " + userName);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
//throw new MageException("This machine is already connected");
|
||||
//disconnect previous one
|
||||
logger.info("Disconnecting another user instance: " + userName);
|
||||
UserManager.getInstance().disconnect(user.getId());
|
||||
UserManager.getInstance().disconnect(user.getId(), User.DisconnectReason.ConnectingOtherInstance);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
@ -159,13 +158,13 @@ public class Session {
|
|||
return sessionId;
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
public void userLostConnection() {
|
||||
logger.info("session disconnected for user " + userId);
|
||||
UserManager.getInstance().disconnect(userId);
|
||||
UserManager.getInstance().disconnect(userId, User.DisconnectReason.LostConnection);
|
||||
}
|
||||
|
||||
public void kill() {
|
||||
logger.info("session killed for user " + userId);
|
||||
logger.debug("session removed for user " + userId);
|
||||
UserManager.getInstance().removeUser(userId, User.DisconnectReason.Disconnected);
|
||||
}
|
||||
|
||||
|
|
@ -175,7 +174,7 @@ public class Session {
|
|||
callbackHandler.handleCallbackOneway(new Callback(call));
|
||||
} catch (HandleCallbackException ex) {
|
||||
logger.fatal(new StringBuilder("Session of userId ").append(userId).append(" fireCallback error: ").append(ex.getMessage()).toString(), ex);
|
||||
disconnect();
|
||||
userLostConnection();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,31 +1,30 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. 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 BetaSteward_at_googlemail.com ``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 BetaSteward_at_googlemail.com 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.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. 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 BetaSteward_at_googlemail.com ``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 BetaSteward_at_googlemail.com 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.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.server;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
|
@ -38,7 +37,6 @@ import mage.view.UserDataView;
|
|||
import org.apache.log4j.Logger;
|
||||
import org.jboss.remoting.callback.InvokerCallbackHandler;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
|
@ -51,7 +49,6 @@ public class SessionManager {
|
|||
public static SessionManager getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private ConcurrentHashMap<String, Session> sessions = new ConcurrentHashMap<String, Session>();
|
||||
|
||||
public Session getSession(String sessionId) {
|
||||
|
|
@ -71,7 +68,10 @@ public class SessionManager {
|
|||
if (session != null) {
|
||||
session.registerUser(userName);
|
||||
LogServiceImpl.instance.log(LogKeys.KEY_USER_CONNECTED, userName, session.getHost(), sessionId);
|
||||
logger.info("User " + userName + " connected from " + session.getHost() + " sessionId: " + sessionId);
|
||||
logger.info(new StringBuilder("User: ").append(userName)
|
||||
.append(" userId: ").append(session.getUserId())
|
||||
.append(" connected from: ").append(session.getHost())
|
||||
.append(" sessionId: ").append(sessionId));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
@ -102,10 +102,12 @@ public class SessionManager {
|
|||
sessions.remove(sessionId);
|
||||
if (session != null) {
|
||||
if (voluntary) {
|
||||
// disconnected
|
||||
session.kill();
|
||||
LogServiceImpl.instance.log(LogKeys.KEY_SESSION_KILLED, sessionId);
|
||||
} else {
|
||||
session.disconnect();
|
||||
// lost connection
|
||||
session.userLostConnection();
|
||||
LogServiceImpl.instance.log(LogKeys.KEY_SESSION_DISCONNECTED, sessionId);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -116,7 +118,7 @@ public class SessionManager {
|
|||
public Map<String, Session> getSessions() {
|
||||
Map<String, Session> map = new HashMap<String, Session>();
|
||||
for (Map.Entry<String, Session> entry : sessions.entrySet()) {
|
||||
map.put(entry.getKey(), entry.getValue());
|
||||
map.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -314,7 +314,11 @@ public class TableController {
|
|||
match.updateDeck(playerId, deck);
|
||||
}
|
||||
else {
|
||||
TournamentManager.getInstance().updateDeck(tournament.getId(), playerId, deck);
|
||||
if (tournament != null) {
|
||||
TournamentManager.getInstance().updateDeck(tournament.getId(), playerId, deck);
|
||||
} else {
|
||||
logger.fatal("Tournament == null table: " + table.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -427,6 +431,8 @@ public class TableController {
|
|||
public synchronized void startMatch() {
|
||||
if (table.getState() == TableState.STARTING) {
|
||||
try {
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
logger.info(new StringBuilder("User (table controller) ").append(user.getName()).append(" starts match: ").append(match.getId()));
|
||||
match.startMatch();
|
||||
startGame(null);
|
||||
} catch (GameException ex) {
|
||||
|
|
@ -447,6 +453,7 @@ public class TableController {
|
|||
if (!match.getPlayer(entry.getValue()).hasQuit()) {
|
||||
User user = UserManager.getInstance().getUser(entry.getKey());
|
||||
if (user != null) {
|
||||
logger.info(new StringBuilder("User ").append(user.getName()).append(" game started - matchId ").append(match.getId()).append(" userId: ").append(user.getId()));
|
||||
user.gameStarted(match.getGame().getId(), entry.getValue());
|
||||
if (creator == null) {
|
||||
creator = user.getName();
|
||||
|
|
@ -493,6 +500,7 @@ public class TableController {
|
|||
for (Entry<UUID, UUID> entry: userPlayerMap.entrySet()) {
|
||||
User user = UserManager.getInstance().getUser(entry.getKey());
|
||||
if (user != null) {
|
||||
logger.info(new StringBuilder("User ").append(user.getName()).append(" tournament started: ").append(tournament.getId()).append(" userId: ").append(user.getId()));
|
||||
user.tournamentStarted(tournament.getId(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
|
@ -510,7 +518,13 @@ public class TableController {
|
|||
table.initDraft();
|
||||
DraftManager.getInstance().createDraftSession(draft, userPlayerMap, table.getId());
|
||||
for (Entry<UUID, UUID> entry: userPlayerMap.entrySet()) {
|
||||
UserManager.getInstance().getUser(entry.getKey()).draftStarted(draft.getId(), entry.getValue());
|
||||
User user = UserManager.getInstance().getUser(entry.getKey());
|
||||
if (user != null) {
|
||||
logger.info(new StringBuilder("User ").append(user.getName()).append(" draft started: ").append(match.getId()).append(" userId: ").append(user.getId()));
|
||||
user.draftStarted(draft.getId(), entry.getValue());
|
||||
} else {
|
||||
logger.fatal(new StringBuilder("Start draft user not found userId: ").append(entry.getKey()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ import java.util.Map;
|
|||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.constants.TableState;
|
||||
import mage.game.Table;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.players.net.UserData;
|
||||
|
|
@ -60,7 +59,7 @@ public class User {
|
|||
}
|
||||
|
||||
public enum DisconnectReason {
|
||||
LostConnection, Disconnected, CleaningUp;
|
||||
LostConnection, Disconnected, CleaningUp, ConnectingOtherInstance;
|
||||
}
|
||||
|
||||
private UUID userId = UUID.randomUUID();
|
||||
|
|
@ -105,10 +104,10 @@ public class User {
|
|||
this.sessionId = sessionId;
|
||||
if (sessionId.isEmpty()) {
|
||||
userState = UserState.Disconnected;
|
||||
logger.info(new StringBuilder("User ").append(userName).append(" disconnected - userId = ").append(userId.toString()).toString());
|
||||
logger.debug(new StringBuilder("User ").append(userName).append(" disconnected - userId = ").append(userId.toString()).toString());
|
||||
} else if (userState == UserState.Created) {
|
||||
userState = UserState.Connected;
|
||||
logger.info(new StringBuilder("User ").append(userName).append(" created - userId = ").append(userId.toString()).toString());
|
||||
logger.debug(new StringBuilder("User ").append(userName).append(" created - userId = ").append(userId.toString()).toString());
|
||||
} else {
|
||||
userState = UserState.Reconnected;
|
||||
reconnect();
|
||||
|
|
|
|||
|
|
@ -100,12 +100,12 @@ public class UserManager {
|
|||
return false;
|
||||
}
|
||||
|
||||
public void disconnect(UUID userId) {
|
||||
public void disconnect(UUID userId, User.DisconnectReason reason) {
|
||||
if (userId != null) {
|
||||
ChatManager.getInstance().removeUser(userId, User.DisconnectReason.Disconnected);
|
||||
ChatManager.getInstance().removeUser(userId, reason);
|
||||
if (users.containsKey(userId)) {
|
||||
User user = users.get(userId);
|
||||
logger.info(new StringBuilder("User ").append(user.getName()).append(" disconnected id:").append(userId).toString());
|
||||
logger.info(new StringBuilder("User ").append(user.getName()).append(" has lost connection userId:").append(userId));
|
||||
users.get(userId).setSessionId("");
|
||||
ChatManager.getInstance().broadcast(userId, "has lost connection", MessageColor.BLACK);
|
||||
}
|
||||
|
|
@ -120,12 +120,18 @@ public class UserManager {
|
|||
}
|
||||
|
||||
public void removeUser(UUID userId, User.DisconnectReason reason) {
|
||||
if (users.containsKey(userId)) {
|
||||
logger.info("Remove user " + users.get(userId).getName() + ": " + userId + " Reason: " + reason.toString());
|
||||
User user = users.get(userId);
|
||||
if (user != null) {
|
||||
logger.info(new StringBuilder("Remove user: ").append(user.getName())
|
||||
.append(" userId: ").append(userId)
|
||||
.append(" sessionId: ").append(user.getSessionId())
|
||||
.append(" Reason: ").append(reason.toString()));
|
||||
ChatManager.getInstance().removeUser(userId, reason);
|
||||
ChatManager.getInstance().broadcast(userId, new StringBuilder("has disconnected (").append(reason.toString()).append(")").toString(), MessageColor.BLACK);
|
||||
users.get(userId).kill(reason);
|
||||
users.remove(userId);
|
||||
} else {
|
||||
logger.warn(new StringBuilder("Trying to remove userId: ").append(userId).append(" but user does not exist."));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -142,7 +148,8 @@ public class UserManager {
|
|||
expired.add(Calendar.MINUTE, -3) ;
|
||||
for (User user: users.values()) {
|
||||
if (user.isExpired(expired.getTime())) {
|
||||
logger.info(user.getName() + " session expired " + user.getId());
|
||||
logger.info(new StringBuilder(user.getName()).append(" session expired userId: ").append(user.getId())
|
||||
.append(" sessionId: ").append(user.getSessionId()));
|
||||
user.kill(User.DisconnectReason.LostConnection);
|
||||
users.remove(user.getId());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package mage.server.challenge;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.constants.Zone;
|
||||
import mage.game.match.Match;
|
||||
|
||||
|
|
|
|||
|
|
@ -314,7 +314,7 @@ public class GameController implements GameCallback {
|
|||
}
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
if (user != null) {
|
||||
GameWatcher gameWatcher = new GameWatcher(userId, game);
|
||||
GameWatcher gameWatcher = new GameWatcher(userId, game, false);
|
||||
watchers.put(userId, gameWatcher);
|
||||
gameWatcher.init();
|
||||
ChatManager.getInstance().broadcast(chatId, user.getName(), " has started watching", MessageColor.BLUE);
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public class GameSession extends GameWatcher {
|
|||
private UserData userData;
|
||||
|
||||
public GameSession(Game game, UUID userId, UUID playerId, boolean useTimeout) {
|
||||
super(userId, game);
|
||||
super(userId, game, true);
|
||||
this.playerId = playerId;
|
||||
this.useTimeout = useTimeout;
|
||||
}
|
||||
|
|
@ -229,7 +229,7 @@ public class GameSession extends GameWatcher {
|
|||
public GameView getGameView() {
|
||||
Player player = game.getPlayer(playerId);
|
||||
player.setUserData(this.userData);
|
||||
GameView gameView = new GameView(game.getState(), game);
|
||||
GameView gameView = new GameView(game.getState(), game, this.isPlayer);
|
||||
gameView.setHand(new SimpleCardsView(player.getHand().getCards(game)));
|
||||
|
||||
if (player.getPlayersUnderYourControl().size() > 0) {
|
||||
|
|
|
|||
|
|
@ -52,10 +52,12 @@ public class GameWatcher {
|
|||
protected UUID userId;
|
||||
protected Game game;
|
||||
protected boolean killed = false;
|
||||
protected boolean isPlayer;
|
||||
|
||||
public GameWatcher(UUID userId, Game game) {
|
||||
public GameWatcher(UUID userId, Game game, boolean isPlayer) {
|
||||
this.userId = userId;
|
||||
this.game = game;
|
||||
this.isPlayer = isPlayer;
|
||||
}
|
||||
|
||||
public boolean init() {
|
||||
|
|
@ -124,11 +126,15 @@ public class GameWatcher {
|
|||
}
|
||||
|
||||
public GameView getGameView() {
|
||||
return new GameView(game.getState(), game);
|
||||
return new GameView(game.getState(), game, this.isPlayer);
|
||||
}
|
||||
|
||||
public GameEndView getGameEndView(UUID playerId, Match match) {
|
||||
return new GameEndView(game.getState(), game, playerId, match);
|
||||
}
|
||||
|
||||
public boolean isPlayer() {
|
||||
return isPlayer;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue