mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 20:41:58 -08:00
Some changes to userData handling. Added country flag to some dialogs. Saved and restored some more table columns width and order information.
This commit is contained in:
parent
cb3b5f895b
commit
87f3978589
32 changed files with 1982 additions and 1699 deletions
|
|
@ -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.ArrayList;
|
||||
|
|
@ -52,6 +51,7 @@ import mage.interfaces.ActionWithResult;
|
|||
import mage.interfaces.MageServer;
|
||||
import mage.interfaces.ServerState;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.players.net.UserData;
|
||||
import mage.remote.MageVersionException;
|
||||
import mage.server.draft.CubeFactory;
|
||||
import mage.server.draft.DraftManager;
|
||||
|
|
@ -83,7 +83,6 @@ import mage.view.MatchView;
|
|||
import mage.view.RoomUsersView;
|
||||
import mage.view.TableView;
|
||||
import mage.view.TournamentView;
|
||||
import mage.view.UserDataView;
|
||||
import mage.view.UserView;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
|
@ -117,7 +116,7 @@ public class MageServerImpl implements MageServer {
|
|||
return SessionManager.getInstance().registerUser(sessionId, userName);
|
||||
} catch (MageException ex) {
|
||||
if (ex instanceof MageVersionException) {
|
||||
throw (MageVersionException)ex;
|
||||
throw (MageVersionException) ex;
|
||||
}
|
||||
handleException(ex);
|
||||
}
|
||||
|
|
@ -125,11 +124,11 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean setUserData(final String userName, final String sessionId, final UserDataView userDataView) throws MageException {
|
||||
public boolean setUserData(final String userName, final String sessionId, final UserData userData) throws MageException {
|
||||
return executeWithResult("setUserData", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
return SessionManager.getInstance().setUserData(userName, sessionId, userDataView);
|
||||
return SessionManager.getInstance().setUserData(userName, sessionId, userData);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -162,7 +161,7 @@ public class MageServerImpl implements MageServer {
|
|||
if (user != null) {
|
||||
logger.debug("TABLE created - tableId: " + table.getTableId() + " " + table.getTableName());
|
||||
logger.debug("- " + user.getName() + " userId: " + user.getId());
|
||||
logger.debug("- chatId: " + TableManager.getInstance().getChatId(table.getTableId()));
|
||||
logger.debug("- chatId: " + TableManager.getInstance().getChatId(table.getTableId()));
|
||||
}
|
||||
}
|
||||
LogServiceImpl.instance.log(LogKeys.KEY_TABLE_CREATED, sessionId, userId.toString(), table.getTableId().toString());
|
||||
|
|
@ -229,7 +228,7 @@ public class MageServerImpl implements MageServer {
|
|||
if (userId == null) {
|
||||
logger.fatal("Got no userId from sessionId" + sessionId + " tableId" + tableId);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTable(userId, tableId, name, playerType, skill, deckList, password);
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -247,11 +246,11 @@ public class MageServerImpl implements MageServer {
|
|||
if (user != null) {
|
||||
logger.trace("join tourn. tableId: " + tableId + " " + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (userId == null) {
|
||||
logger.fatal("Got no userId from sessionId" + sessionId + " tableId" + tableId);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTournamentTable(userId, tableId, name, playerType, skill, deckList, password);
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -293,8 +292,7 @@ public class MageServerImpl implements MageServer {
|
|||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return null;
|
||||
|
|
@ -310,8 +308,7 @@ public class MageServerImpl implements MageServer {
|
|||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return null;
|
||||
|
|
@ -326,8 +323,7 @@ public class MageServerImpl implements MageServer {
|
|||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return null;
|
||||
|
|
@ -343,8 +339,7 @@ public class MageServerImpl implements MageServer {
|
|||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return null;
|
||||
|
|
@ -365,7 +360,6 @@ public class MageServerImpl implements MageServer {
|
|||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
@Override
|
||||
public boolean startMatch(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
if (!TableManager.getInstance().getController(tableId).changeTableState(TableState.STARTING)) {
|
||||
|
|
@ -391,7 +385,6 @@ public class MageServerImpl implements MageServer {
|
|||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
@Override
|
||||
public boolean startTournament(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
if (!TableManager.getInstance().getController(tableId).changeTableState(TableState.STARTING)) {
|
||||
|
|
@ -412,8 +405,7 @@ public class MageServerImpl implements MageServer {
|
|||
public TournamentView getTournament(UUID tournamentId) throws MageException {
|
||||
try {
|
||||
return TournamentManager.getInstance().getTournamentView(tournamentId);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return null;
|
||||
|
|
@ -424,15 +416,14 @@ public class MageServerImpl implements MageServer {
|
|||
public void sendChatMessage(final UUID chatId, final String userName, final String message) throws MageException {
|
||||
try {
|
||||
callExecutor.execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ChatManager.getInstance().broadcast(chatId, userName, StringEscapeUtils.escapeHtml4(message), MessageColor.BLUE);
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ChatManager.getInstance().broadcast(chatId, userName, StringEscapeUtils.escapeHtml4(message), MessageColor.BLUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
}
|
||||
|
|
@ -464,8 +455,7 @@ public class MageServerImpl implements MageServer {
|
|||
public UUID getMainRoomId() throws MageException {
|
||||
try {
|
||||
return GamesRoomManager.getInstance().getMainRoomId();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return null;
|
||||
|
|
@ -476,8 +466,7 @@ public class MageServerImpl implements MageServer {
|
|||
public UUID getRoomChatId(UUID roomId) throws MageException {
|
||||
try {
|
||||
return GamesRoomManager.getInstance().getRoom(roomId).getChatId();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return null;
|
||||
|
|
@ -527,8 +516,7 @@ public class MageServerImpl implements MageServer {
|
|||
public UUID getTableChatId(UUID tableId) throws MageException {
|
||||
try {
|
||||
return TableManager.getInstance().getChatId(tableId);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return null;
|
||||
|
|
@ -572,8 +560,7 @@ public class MageServerImpl implements MageServer {
|
|||
public UUID getGameChatId(UUID gameId) throws MageException {
|
||||
try {
|
||||
return GameManager.getInstance().getChatId(gameId);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return null;
|
||||
|
|
@ -584,8 +571,7 @@ public class MageServerImpl implements MageServer {
|
|||
public UUID getTournamentChatId(UUID tournamentId) throws MageException {
|
||||
try {
|
||||
return TournamentManager.getInstance().getChatId(tournamentId);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return null;
|
||||
|
|
@ -602,7 +588,7 @@ public class MageServerImpl implements MageServer {
|
|||
user.sendPlayerUUID(gameId, data);
|
||||
} else {
|
||||
logger.warn("Your session expired: gameId=" + gameId + ", sessionId=" + sessionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -617,7 +603,7 @@ public class MageServerImpl implements MageServer {
|
|||
user.sendPlayerString(gameId, data);
|
||||
} else {
|
||||
logger.warn("Your session expired: gameId=" + gameId + ", sessionId=" + sessionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -647,7 +633,7 @@ public class MageServerImpl implements MageServer {
|
|||
user.sendPlayerBoolean(gameId, data);
|
||||
} else {
|
||||
logger.warn("Your session expired: gameId=" + gameId + ", sessionId=" + sessionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -675,8 +661,8 @@ public class MageServerImpl implements MageServer {
|
|||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null) {
|
||||
return DraftManager.getInstance().sendCardPick(draftId, session.getUserId(), cardPick, hiddenCards);
|
||||
} else{
|
||||
logger.error("Session not found sessionId: "+ sessionId + " draftId:" + draftId);
|
||||
} else {
|
||||
logger.error("Session not found sessionId: " + sessionId + " draftId:" + draftId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
@ -691,8 +677,8 @@ public class MageServerImpl implements MageServer {
|
|||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null) {
|
||||
DraftManager.getInstance().sendCardMark(draftId, session.getUserId(), cardPick);
|
||||
} else{
|
||||
logger.error("Session not found sessionId: "+ sessionId + " draftId:" + draftId);
|
||||
} else {
|
||||
logger.error("Session not found sessionId: " + sessionId + " draftId:" + draftId);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -706,8 +692,8 @@ public class MageServerImpl implements MageServer {
|
|||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null) {
|
||||
GameManager.getInstance().quitMatch(gameId, session.getUserId());
|
||||
} else{
|
||||
logger.error("Session not found sessionId: "+ sessionId + " gameId:" +gameId);
|
||||
} else {
|
||||
logger.error("Session not found sessionId: " + sessionId + " gameId:" + gameId);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -721,8 +707,8 @@ public class MageServerImpl implements MageServer {
|
|||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null) {
|
||||
TournamentManager.getInstance().quit(tournamentId, session.getUserId());
|
||||
}else{
|
||||
logger.error("Session not found sessionId: "+ sessionId + " tournamentId:" + tournamentId);
|
||||
} else {
|
||||
logger.error("Session not found sessionId: " + sessionId + " tournamentId:" + tournamentId);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -735,7 +721,7 @@ public class MageServerImpl implements MageServer {
|
|||
public void execute() {
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session == null) {
|
||||
logger.error("Session not found sessionId: "+ sessionId + " draftId:" + draftId);
|
||||
logger.error("Session not found sessionId: " + sessionId + " draftId:" + draftId);
|
||||
return;
|
||||
}
|
||||
UUID tableId = DraftManager.getInstance().getControllerByDraftId(draftId).getTableId();
|
||||
|
|
@ -755,14 +741,14 @@ public class MageServerImpl implements MageServer {
|
|||
public void execute() {
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session == null) {
|
||||
logger.error("Session not found sessionId: "+ sessionId + " gameId:" + gameId);
|
||||
logger.error("Session not found sessionId: " + sessionId + " gameId:" + gameId);
|
||||
return;
|
||||
}
|
||||
GameManager.getInstance().sendPlayerAction(playerAction, gameId, session.getUserId(), data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean watchTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
return executeWithResult("setUserData", sessionId, new ActionWithBooleanResult() {
|
||||
|
|
@ -893,8 +879,7 @@ public class MageServerImpl implements MageServer {
|
|||
CardRepository.instance.getContentVersionConstant(),
|
||||
ExpansionRepository.instance.getContentVersionConstant()
|
||||
);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return null;
|
||||
|
|
@ -925,7 +910,7 @@ public class MageServerImpl implements MageServer {
|
|||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void handleException(Exception ex) throws MageException {
|
||||
if (!ex.getMessage().equals("No message")) {
|
||||
|
|
@ -936,12 +921,12 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
public GameView getGameView(final UUID gameId, final String sessionId, final UUID playerId) throws MageException {
|
||||
return executeWithResult("getGameView", sessionId, new ActionWithNullNegativeResult<GameView>() {
|
||||
@Override
|
||||
public GameView execute() throws MageException {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
return GameManager.getInstance().getGameView(gameId, userId, playerId);
|
||||
}
|
||||
return executeWithResult("getGameView", sessionId, new ActionWithNullNegativeResult<GameView>() {
|
||||
@Override
|
||||
public GameView execute() throws MageException {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
return GameManager.getInstance().getGameView(gameId, userId, playerId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -988,11 +973,11 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
/**
|
||||
* Admin console - Remove table
|
||||
*
|
||||
* Admin console - Remove table
|
||||
*
|
||||
* @param sessionId
|
||||
* @param tableId
|
||||
* @throws MageException
|
||||
* @throws MageException
|
||||
*/
|
||||
@Override
|
||||
public void removeTable(final String sessionId, final UUID tableId) throws MageException {
|
||||
|
|
@ -1009,9 +994,9 @@ public class MageServerImpl implements MageServer {
|
|||
public Object getServerMessagesCompressed(String sessionId) throws MageException {
|
||||
return executeWithResult("getGameView", sessionId, new ActionWithNullNegativeResult<Object>() {
|
||||
@Override
|
||||
public Object execute() throws MageException {
|
||||
return CompressUtil.compress(ServerMessagesUtil.getInstance().getMessages());
|
||||
}
|
||||
public Object execute() throws MageException {
|
||||
return CompressUtil.compress(ServerMessagesUtil.getInstance().getMessages());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -1028,7 +1013,7 @@ public class MageServerImpl implements MageServer {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void sendBroadcastMessage(final String sessionId, final String message) throws MageException {
|
||||
if (message != null) {
|
||||
|
|
@ -1061,23 +1046,22 @@ public class MageServerImpl implements MageServer {
|
|||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
callExecutor.execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
action.execute();
|
||||
} catch (MageException me) {
|
||||
throw new RuntimeException(me);
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
action.execute();
|
||||
} catch (MageException me) {
|
||||
throw new RuntimeException(me);
|
||||
}
|
||||
} else {
|
||||
LogServiceImpl.instance.log(LogKeys.KEY_NOT_VALID_SESSION_INTERNAL, actionName, sessionId);
|
||||
}
|
||||
} else {
|
||||
LogServiceImpl.instance.log(LogKeys.KEY_NOT_VALID_SESSION_INTERNAL, actionName, sessionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -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.Date;
|
||||
|
|
@ -42,7 +41,6 @@ import mage.players.net.UserData;
|
|||
import mage.players.net.UserGroup;
|
||||
import mage.server.game.GamesRoomManager;
|
||||
import mage.server.util.ConfigSettings;
|
||||
import mage.view.UserDataView;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jboss.remoting.callback.AsynchInvokerCallbackHandler;
|
||||
import org.jboss.remoting.callback.Callback;
|
||||
|
|
@ -124,7 +122,7 @@ public class Session {
|
|||
}
|
||||
if (!UserManager.getInstance().connectToSession(sessionId, user.getId())) {
|
||||
return new StringBuilder("Error connecting ").append(userName).toString();
|
||||
}
|
||||
}
|
||||
this.userId = user.getId();
|
||||
if (reconnect) { // must be connected to receive the message
|
||||
UUID chatId = GamesRoomManager.getInstance().getRoom(GamesRoomManager.getInstance().getMainRoomId()).getChatId();
|
||||
|
|
@ -132,7 +130,7 @@ public class Session {
|
|||
ChatManager.getInstance().joinChat(chatId, userId);
|
||||
}
|
||||
ChatManager.getInstance().sendReconnectMessage(userId);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -144,75 +142,45 @@ public class Session {
|
|||
}
|
||||
user.setUserData(new UserData(UserGroup.ADMIN, 0, false, false, false, null, "world.png", false));
|
||||
if (!UserManager.getInstance().connectToSession(sessionId, user.getId())) {
|
||||
logger.info("Error connecting Admin!");
|
||||
}
|
||||
logger.info("Error connecting Admin!");
|
||||
}
|
||||
this.userId = user.getId();
|
||||
}
|
||||
|
||||
public boolean setUserData(String userName, UserDataView userDataView) {
|
||||
public boolean setUserData(String userName, UserData userData) {
|
||||
User user = UserManager.getInstance().findUser(userName);
|
||||
if (user != null) {
|
||||
UserData userData = user.getUserData();
|
||||
if (userData == null) {
|
||||
userData = new UserData(UserGroup.PLAYER, userDataView.getAvatarId(),
|
||||
userDataView.isShowAbilityPickerForced(), userDataView.allowRequestShowHandCards(),
|
||||
userDataView.confirmEmptyManaPool(), userDataView.getUserSkipPrioritySteps(),
|
||||
userDataView.getFlagName(), userDataView.askMoveToGraveOrder());
|
||||
if (user.getUserData() == null || user.getUserData().getGroupId() == UserGroup.DEFAULT.getGroupId()) {
|
||||
user.setUserData(userData);
|
||||
} else {
|
||||
if (userDataView.getAvatarId() == 51) { // Update special avatar if first avatar is selected
|
||||
updateAvatar(userName, userData);
|
||||
}
|
||||
userData.setAvatarId(userDataView.getAvatarId());
|
||||
userData.setShowAbilityPickerForced(userDataView.isShowAbilityPickerForced());
|
||||
userData.setAllowRequestShowHandCards(userDataView.allowRequestShowHandCards());
|
||||
userData.setUserSkipPrioritySteps(userDataView.getUserSkipPrioritySteps());
|
||||
userData.setConfirmEmptyManaPool(userDataView.confirmEmptyManaPool());
|
||||
userData.setAskMoveToGraveOrder(userDataView.askMoveToGraveOrder());
|
||||
user.getUserData().update(userData);
|
||||
}
|
||||
if (user.getUserData().getAvatarId() == 51) {
|
||||
user.getUserData().setAvatarId(updateAvatar(user.getName()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void updateAvatar(String userName, UserData userData) {
|
||||
private int updateAvatar(String userName) {
|
||||
//TODO: move to separate class
|
||||
//TODO: add for checking for private key
|
||||
switch (userName) {
|
||||
case "nantuko":
|
||||
userData.setAvatarId(1000);
|
||||
break;
|
||||
case "i_no_k":
|
||||
userData.setAvatarId(1002);
|
||||
break;
|
||||
case "Askael":
|
||||
userData.setAvatarId(1004);
|
||||
break;
|
||||
return 1000;
|
||||
case "North":
|
||||
userData.setAvatarId(1006);
|
||||
break;
|
||||
return 1006;
|
||||
case "BetaSteward":
|
||||
userData.setAvatarId(1008);
|
||||
break;
|
||||
case "Arching":
|
||||
userData.setAvatarId(1010);
|
||||
break;
|
||||
return 1008;
|
||||
case "loki":
|
||||
userData.setAvatarId(1012);
|
||||
break;
|
||||
case "Alive":
|
||||
userData.setAvatarId(1014);
|
||||
break;
|
||||
case "Rahan":
|
||||
userData.setAvatarId(1016);
|
||||
break;
|
||||
return 1012;
|
||||
case "Ayrat":
|
||||
userData.setAvatarId(1018);
|
||||
break;
|
||||
return 1018;
|
||||
case "Bandit":
|
||||
userData.setAvatarId(1020);
|
||||
break;
|
||||
return 1020;
|
||||
}
|
||||
return 51;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
|
|
@ -220,10 +188,10 @@ public class Session {
|
|||
}
|
||||
|
||||
// because different threads can activate this
|
||||
public void userLostConnection() {
|
||||
public void userLostConnection() {
|
||||
boolean lockSet = false;
|
||||
try {
|
||||
if(lock.tryLock(5000, TimeUnit.MILLISECONDS)) {
|
||||
if (lock.tryLock(5000, TimeUnit.MILLISECONDS)) {
|
||||
lockSet = true;
|
||||
logger.debug("SESSION LOCK SET sessionId: " + sessionId);
|
||||
} else {
|
||||
|
|
@ -243,9 +211,8 @@ public class Session {
|
|||
|
||||
} catch (InterruptedException ex) {
|
||||
logger.error("SESSION LOCK lost connection - userId: " + userId, ex);
|
||||
}
|
||||
finally {
|
||||
if (lockSet) {
|
||||
} finally {
|
||||
if (lockSet) {
|
||||
lock.unlock();
|
||||
logger.trace("SESSION LOCK UNLOCK sessionId: " + sessionId);
|
||||
}
|
||||
|
|
@ -256,18 +223,17 @@ public class Session {
|
|||
public void kill(DisconnectReason reason) {
|
||||
boolean lockSet = false;
|
||||
try {
|
||||
if(lock.tryLock(5000, TimeUnit.MILLISECONDS)) {
|
||||
if (lock.tryLock(5000, TimeUnit.MILLISECONDS)) {
|
||||
lockSet = true;
|
||||
logger.debug("SESSION LOCK SET sessionId: " + sessionId);
|
||||
logger.debug("SESSION LOCK SET sessionId: " + sessionId);
|
||||
} else {
|
||||
logger.error("SESSION LOCK - kill: userId " + userId);
|
||||
}
|
||||
UserManager.getInstance().removeUser(userId, reason);
|
||||
} catch (InterruptedException ex) {
|
||||
logger.error("SESSION LOCK - kill: userId " + userId, ex);
|
||||
}
|
||||
finally {
|
||||
if (lockSet) {
|
||||
} finally {
|
||||
if (lockSet) {
|
||||
lock.unlock();
|
||||
logger.debug("SESSION LOCK UNLOCK sessionId: " + sessionId);
|
||||
|
||||
|
|
@ -282,7 +248,7 @@ public class Session {
|
|||
callbackHandler.handleCallbackOneway(new Callback(call));
|
||||
} catch (HandleCallbackException ex) {
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
logger.warn("SESSION CALLBACK EXCEPTION - " + (user != null ? user.getName():"") + " userId " + userId);
|
||||
logger.warn("SESSION CALLBACK EXCEPTION - " + (user != null ? user.getName() : "") + " userId " + userId);
|
||||
logger.warn(" - method: " + call.getMethod());
|
||||
logger.warn(" - cause: " + getBasicCause(ex).toString());
|
||||
logger.trace("Stack trace:", ex);
|
||||
|
|
|
|||
|
|
@ -31,9 +31,9 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import mage.MageException;
|
||||
import mage.players.net.UserData;
|
||||
import mage.server.services.LogKeys;
|
||||
import mage.server.services.impl.LogServiceImpl;
|
||||
import mage.view.UserDataView;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jboss.remoting.callback.InvokerCallbackHandler;
|
||||
|
||||
|
|
@ -73,7 +73,7 @@ public class SessionManager {
|
|||
public boolean registerUser(String sessionId, String userName) throws MageException {
|
||||
Session session = sessions.get(sessionId);
|
||||
if (session != null) {
|
||||
String returnMessage = session.registerUser(userName);
|
||||
String returnMessage = session.registerUser(userName);
|
||||
if (returnMessage == null) {
|
||||
LogServiceImpl.instance.log(LogKeys.KEY_USER_CONNECTED, userName, session.getHost(), sessionId);
|
||||
|
||||
|
|
@ -102,24 +102,24 @@ public class SessionManager {
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean setUserData(String userName, String sessionId, UserDataView userDataView) throws MageException {
|
||||
public boolean setUserData(String userName, String sessionId, UserData userData) throws MageException {
|
||||
Session session = sessions.get(sessionId);
|
||||
if (session != null) {
|
||||
session.setUserData(userName, userDataView);
|
||||
session.setUserData(userName, userData);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void disconnect(String sessionId, DisconnectReason reason) {
|
||||
Session session = sessions.get(sessionId);
|
||||
Session session = sessions.get(sessionId);
|
||||
if (session != null) {
|
||||
if (!reason.equals(DisconnectReason.AdminDisconnect)) {
|
||||
if (!sessions.containsKey(sessionId)) {
|
||||
// session was removed meanwhile by another thread so we can return
|
||||
return;
|
||||
}
|
||||
logger.debug("DISCONNECT " + reason.toString() + " - sessionId: "+ sessionId);
|
||||
logger.debug("DISCONNECT " + reason.toString() + " - sessionId: " + sessionId);
|
||||
sessions.remove(sessionId);
|
||||
switch (reason) {
|
||||
case Disconnected:
|
||||
|
|
@ -135,13 +135,13 @@ public class SessionManager {
|
|||
LogServiceImpl.instance.log(LogKeys.KEY_SESSION_DISCONNECTED, sessionId);
|
||||
break;
|
||||
default:
|
||||
logger.error("endSession: unexpected reason " + reason.toString() + " - sessionId: "+ sessionId);
|
||||
logger.error("endSession: unexpected reason " + reason.toString() + " - sessionId: " + sessionId);
|
||||
}
|
||||
} else {
|
||||
sessions.remove(sessionId);
|
||||
session.kill(reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -155,6 +155,7 @@ public class SessionManager {
|
|||
|
||||
/**
|
||||
* Admin requested the disconnect of a user
|
||||
*
|
||||
* @param sessionId
|
||||
* @param userSessionId
|
||||
*/
|
||||
|
|
@ -163,12 +164,12 @@ public class SessionManager {
|
|||
User userAdmin, user;
|
||||
if ((userAdmin = getUserFromSession(sessionId)) != null) {
|
||||
if ((user = getUserFromSession(userSessionId)) != null) {
|
||||
user.showUserMessage("Admin operation","Your session was disconnected by Admin.");
|
||||
user.showUserMessage("Admin operation", "Your session was disconnected by Admin.");
|
||||
userAdmin.showUserMessage("Admin action", "User" + user.getName() + " was disconnected.");
|
||||
disconnect(userSessionId, DisconnectReason.AdminDisconnect);
|
||||
LogServiceImpl.instance.log(LogKeys.KEY_SESSION_DISCONNECTED_BY_ADMIN, sessionId, userSessionId);
|
||||
} else {
|
||||
userAdmin.showUserMessage("Admin operation","User with sessionId " + userSessionId + " could not be found!");
|
||||
userAdmin.showUserMessage("Admin operation", "User with sessionId " + userSessionId + " could not be found!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -203,7 +204,7 @@ public class SessionManager {
|
|||
|
||||
public User getUser(String sessionId) {
|
||||
Session session = sessions.get(sessionId);
|
||||
if (session != null) {
|
||||
if (session != null) {
|
||||
return UserManager.getInstance().getUser(sessions.get(sessionId).getUserId());
|
||||
}
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -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.Map;
|
||||
|
|
@ -91,7 +90,7 @@ public class TableController {
|
|||
private Match match;
|
||||
private MatchOptions options;
|
||||
private Tournament tournament;
|
||||
|
||||
|
||||
private ScheduledFuture<?> futureTimeout;
|
||||
protected static ScheduledExecutorService timeoutExecutor = ThreadExecutor.getInstance().getTimeoutExecutor();
|
||||
|
||||
|
|
@ -103,12 +102,11 @@ public class TableController {
|
|||
User user = UserManager.getInstance().getUser(userId);
|
||||
// TODO: Handle if user == null
|
||||
controllerName = user.getName();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
controllerName = "System";
|
||||
}
|
||||
table = new Table(roomId, options.getGameType(), options.getName(), controllerName, DeckValidatorFactory.getInstance().createDeckValidator(options.getDeckType()), options.getPlayerTypes(), match);
|
||||
chatId = ChatManager.getInstance().createChatSession("Match Table " + table.getId());
|
||||
chatId = ChatManager.getInstance().createChatSession("Match Table " + table.getId());
|
||||
init();
|
||||
}
|
||||
|
||||
|
|
@ -123,30 +121,29 @@ public class TableController {
|
|||
} else {
|
||||
controllerName = user.getName();
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
controllerName = "System";
|
||||
}
|
||||
table = new Table(roomId, options.getTournamentType(), options.getName(), controllerName, DeckValidatorFactory.getInstance().createDeckValidator(options.getMatchOptions().getDeckType()), options.getPlayerTypes(), tournament);
|
||||
chatId = ChatManager.getInstance().createChatSession("Tourn. table " + table.getId());
|
||||
chatId = ChatManager.getInstance().createChatSession("Tourn. table " + table.getId());
|
||||
}
|
||||
|
||||
private void init() {
|
||||
match.addTableEventListener(
|
||||
new Listener<TableEvent> () {
|
||||
@Override
|
||||
public void event(TableEvent event) {
|
||||
try {
|
||||
switch (event.getEventType()) {
|
||||
case SIDEBOARD:
|
||||
sideboard(event.getPlayerId(), event.getDeck());
|
||||
break;
|
||||
new Listener<TableEvent>() {
|
||||
@Override
|
||||
public void event(TableEvent event) {
|
||||
try {
|
||||
switch (event.getEventType()) {
|
||||
case SIDEBOARD:
|
||||
sideboard(event.getPlayerId(), event.getDeck());
|
||||
break;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
logger.fatal("Table event listener error", ex);
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
logger.fatal("Table event listener error", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -171,13 +168,13 @@ public class TableController {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
if (userPlayerMap.containsKey(userId) && playerType.equals("Human")){
|
||||
if (userPlayerMap.containsKey(userId) && playerType.equals("Human")) {
|
||||
user.showUserMessage("Join Table", new StringBuilder("You can join a table only one time.").toString());
|
||||
return false;
|
||||
}
|
||||
Deck deck = null;
|
||||
if (!table.getTournament().getTournamentType().isLimited()) {
|
||||
if (deckList != null) {
|
||||
if (deckList != null) {
|
||||
deck = Deck.load(deckList, false, false);
|
||||
} else {
|
||||
user.showUserMessage("Join Table", "No valid deck selected!");
|
||||
|
|
@ -208,9 +205,9 @@ public class TableController {
|
|||
TournamentPlayer tournamentPlayer = tournament.getPlayer(player.getId());
|
||||
if (deck != null && tournamentPlayer != null) {
|
||||
tournamentPlayer.submitDeck(deck);
|
||||
}
|
||||
table.joinTable(player, seat);
|
||||
logger.debug("Player " + player.getName() + " id: "+ player.getId() + " joined tableId: " + table.getId());
|
||||
}
|
||||
table.joinTable(player, seat);
|
||||
logger.debug("Player " + player.getName() + " id: " + player.getId() + " joined tableId: " + table.getId());
|
||||
//only inform human players and add them to sessionPlayerMap
|
||||
if (seat.getPlayer().isHuman()) {
|
||||
seat.getPlayer().setUserData(user.getUserData());
|
||||
|
|
@ -235,12 +232,12 @@ public class TableController {
|
|||
return false;
|
||||
}
|
||||
TournamentPlayer oldTournamentPlayer = tournament.getPlayer(oldPlayer.getId());
|
||||
tournament.removePlayer(oldPlayer.getId());
|
||||
tournament.removePlayer(oldPlayer.getId());
|
||||
tournament.addPlayer(newPlayer, playerType);
|
||||
|
||||
TournamentPlayer newTournamentPlayer = tournament.getPlayer(newPlayer.getId());
|
||||
TournamentPlayer newTournamentPlayer = tournament.getPlayer(newPlayer.getId());
|
||||
newTournamentPlayer.setState(oldTournamentPlayer.getState());
|
||||
|
||||
|
||||
DraftManager.getInstance().getController(table.getId()).replacePlayer(oldPlayer, newPlayer);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -250,7 +247,7 @@ public class TableController {
|
|||
if (user == null) {
|
||||
return false;
|
||||
}
|
||||
if (userPlayerMap.containsKey(userId) && playerType.equals("Human")){
|
||||
if (userPlayerMap.containsKey(userId) && playerType.equals("Human")) {
|
||||
user.showUserMessage("Join Table", new StringBuilder("You can join a table only one time.").toString());
|
||||
return false;
|
||||
}
|
||||
|
|
@ -289,7 +286,7 @@ public class TableController {
|
|||
if (player == null) {
|
||||
String message = new StringBuilder("Could not create player ").append(name).append(" of type ").append(seat.getPlayerType()).toString();
|
||||
logger.warn(new StringBuilder("User: ").append(user.getName()).append(" => ").append(message).toString());
|
||||
user.showUserMessage("Join Table",message);
|
||||
user.showUserMessage("Join Table", message);
|
||||
return false;
|
||||
}
|
||||
logger.debug("DECK validated: " + table.getValidator().getName() + " " + player.getName() + " " + deck.getName());
|
||||
|
|
@ -312,7 +309,7 @@ public class TableController {
|
|||
return true;
|
||||
}
|
||||
|
||||
public void addPlayer(UUID userId, Player player, String playerType, Deck deck) throws GameException {
|
||||
public void addPlayer(UUID userId, Player player, String playerType, Deck deck) throws GameException {
|
||||
if (table.getState() != TableState.WAITING) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -378,8 +375,7 @@ public class TableController {
|
|||
if (table.getState() == TableState.SIDEBOARDING) {
|
||||
match.submitDeck(playerId, deck);
|
||||
UserManager.getInstance().getUser(userId).removeSideboarding(table.getId());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
TournamentManager.getInstance().submitDeck(tournament.getId(), playerId, deck);
|
||||
UserManager.getInstance().getUser(userId).removeConstructing(playerId);
|
||||
}
|
||||
|
|
@ -390,7 +386,7 @@ public class TableController {
|
|||
if (tournament != null) {
|
||||
TournamentManager.getInstance().updateDeck(tournament.getId(), playerId, deck);
|
||||
} else {
|
||||
logger.fatal("Tournament == null table: " + table.getId() +" userId: " + userId);
|
||||
logger.fatal("Tournament == null table: " + table.getId() + " userId: " + userId);
|
||||
}
|
||||
} else {
|
||||
if (TableState.SIDEBOARDING.equals(table.getState())) {
|
||||
|
|
@ -427,13 +423,11 @@ public class TableController {
|
|||
// ReplayManager.getInstance().replayGame(table.getId(), userId);
|
||||
// return true;
|
||||
// }
|
||||
|
||||
private Player createPlayer(String name, String playerType, int skill) {
|
||||
Player player;
|
||||
if (options == null) {
|
||||
player = PlayerFactory.getInstance().createPlayer(playerType, name, RangeOfInfluence.ALL, skill);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
player = PlayerFactory.getInstance().createPlayer(playerType, name, options.getRange(), skill);
|
||||
}
|
||||
if (player != null) {
|
||||
|
|
@ -443,12 +437,12 @@ public class TableController {
|
|||
}
|
||||
|
||||
public void leaveTableAll() {
|
||||
for (UUID leavingUserId: userPlayerMap.keySet()) {
|
||||
for (UUID leavingUserId : userPlayerMap.keySet()) {
|
||||
leaveTable(leavingUserId);
|
||||
}
|
||||
closeTable();
|
||||
}
|
||||
|
||||
|
||||
public synchronized void leaveTable(UUID userId) {
|
||||
if (table == null) {
|
||||
logger.error("No table object - userId: " + userId);
|
||||
|
|
@ -488,19 +482,19 @@ public class TableController {
|
|||
if (table.isTournament()) {
|
||||
logger.debug("Quit tournament sub tables for userId: " + userId);
|
||||
TableManager.getInstance().userQuitTournamentSubTables(tournament.getId(), userId);
|
||||
logger.debug("Quit tournament Id: " + table.getTournament().getId() + "(" +table.getTournament().getTournamentState() + ")");
|
||||
logger.debug("Quit tournament Id: " + table.getTournament().getId() + "(" + table.getTournament().getTournamentState() + ")");
|
||||
TournamentManager.getInstance().quit(tournament.getId(), userId);
|
||||
} else {
|
||||
MatchPlayer matchPlayer = match.getPlayer(playerId);
|
||||
if (matchPlayer != null && !match.hasEnded() && !matchPlayer.hasQuit()) {
|
||||
Game game = match.getGame();
|
||||
if (game != null && !game.hasEnded()){
|
||||
if (game != null && !game.hasEnded()) {
|
||||
Player player = match.getPlayer(playerId).getPlayer();
|
||||
if (player != null && player.isInGame()) {
|
||||
GameManager.getInstance().quitMatch(game.getId(), userId);
|
||||
}
|
||||
match.quitMatch(playerId);
|
||||
} else {
|
||||
} else {
|
||||
if (table.getState().equals(TableState.SIDEBOARDING)) {
|
||||
if (!matchPlayer.isDoneSideboarding()) {
|
||||
// submit deck to finish sideboarding and trigger match start / end
|
||||
|
|
@ -520,7 +514,7 @@ public class TableController {
|
|||
|
||||
/**
|
||||
* Used from non tournament match to start
|
||||
*
|
||||
*
|
||||
* @param userId owner of the tabel
|
||||
*/
|
||||
public synchronized void startMatch(UUID userId) {
|
||||
|
|
@ -536,7 +530,7 @@ public class TableController {
|
|||
logger.info("Tourn. match started id:" + match.getId() + " tournId: " + table.getTournament().getId());
|
||||
} else {
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
logger.info("MATCH started [" + match.getName() + "] " + match.getId() + "(" + user.getName() +")");
|
||||
logger.info("MATCH started [" + match.getName() + "] " + match.getId() + "(" + user.getName() + ")");
|
||||
logger.debug("- " + match.getOptions().getGameType() + " - " + match.getOptions().getDeckType());
|
||||
}
|
||||
match.startMatch();
|
||||
|
|
@ -558,12 +552,12 @@ public class TableController {
|
|||
GameManager.getInstance().createGameSession(match.getGame(), userPlayerMap, table.getId(), choosingPlayerId, gameOptions);
|
||||
String creator = null;
|
||||
StringBuilder opponent = new StringBuilder();
|
||||
for (Entry<UUID, UUID> entry: userPlayerMap.entrySet()) { // no AI players
|
||||
for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) { // no AI players
|
||||
if (!match.getPlayer(entry.getValue()).hasQuit()) {
|
||||
User user = UserManager.getInstance().getUser(entry.getKey());
|
||||
if (user != null) {
|
||||
user.ccGameStarted(match.getGame().getId(), entry.getValue());
|
||||
|
||||
|
||||
if (creator == null) {
|
||||
creator = user.getName();
|
||||
} else {
|
||||
|
|
@ -582,7 +576,7 @@ public class TableController {
|
|||
}
|
||||
}
|
||||
// Append AI opponents to the log file
|
||||
for (MatchPlayer mPlayer :match.getPlayers()) {
|
||||
for (MatchPlayer mPlayer : match.getPlayers()) {
|
||||
if (!mPlayer.getPlayer().isHuman()) {
|
||||
if (opponent.length() > 0) {
|
||||
opponent.append(" - ");
|
||||
|
|
@ -592,9 +586,8 @@ public class TableController {
|
|||
}
|
||||
ServerMessagesUtil.getInstance().incGamesStarted();
|
||||
|
||||
|
||||
// log about game started
|
||||
logger.info("GAME started " + match.getGame().getId() + " [" + match.getName() +"] "+ creator + " - " + opponent.toString());
|
||||
logger.info("GAME started " + match.getGame().getId() + " [" + match.getName() + "] " + creator + " - " + opponent.toString());
|
||||
logger.debug("- matchId: " + match.getId() + " [" + match.getName() + "]");
|
||||
if (match.getGame() != null) {
|
||||
logger.debug("- chatId: " + GameManager.getInstance().getChatId(match.getGame().getId()));
|
||||
|
|
@ -602,8 +595,7 @@ public class TableController {
|
|||
logger.debug("- no valid game object");
|
||||
}
|
||||
LogServiceImpl.instance.log(LogKeys.KEY_GAME_STARTED, String.valueOf(userPlayerMap.size()), creator, opponent.toString());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
logger.fatal("Error starting game", ex);
|
||||
if (table != null) {
|
||||
TableManager.getInstance().removeTable(table.getId());
|
||||
|
|
@ -618,11 +610,11 @@ public class TableController {
|
|||
}
|
||||
|
||||
public synchronized void startTournament(UUID userId) {
|
||||
try {
|
||||
try {
|
||||
if (userId.equals(this.userId) && table.getState().equals(TableState.STARTING)) {
|
||||
tournament.setStartTime();
|
||||
TournamentManager.getInstance().createTournamentSession(tournament, userPlayerMap, table.getId());
|
||||
for (Entry<UUID, UUID> entry: userPlayerMap.entrySet()) {
|
||||
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()));
|
||||
|
|
@ -631,8 +623,7 @@ public class TableController {
|
|||
}
|
||||
ServerMessagesUtil.getInstance().incTournamentsStarted();
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
logger.fatal("Error starting tournament", ex);
|
||||
TableManager.getInstance().removeTable(table.getId());
|
||||
TournamentManager.getInstance().quit(tournament.getId(), userId);
|
||||
|
|
@ -642,7 +633,7 @@ public class TableController {
|
|||
public void startDraft(Draft draft) {
|
||||
table.initDraft();
|
||||
DraftManager.getInstance().createDraftSession(draft, userPlayerMap, table.getId());
|
||||
for (Entry<UUID, UUID> entry: userPlayerMap.entrySet()) {
|
||||
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(" draft started: ").append(draft.getId()).append(" userId: ").append(user.getId()));
|
||||
|
|
@ -654,7 +645,7 @@ public class TableController {
|
|||
}
|
||||
|
||||
private void sideboard(UUID playerId, Deck deck) throws MageException {
|
||||
for (Entry<UUID, UUID> entry: userPlayerMap.entrySet()) {
|
||||
for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) {
|
||||
if (entry.getValue().equals(playerId)) {
|
||||
User user = UserManager.getInstance().getUser(entry.getKey());
|
||||
int remaining = (int) futureTimeout.getDelay(TimeUnit.SECONDS);
|
||||
|
|
@ -668,7 +659,7 @@ public class TableController {
|
|||
|
||||
public int getRemainingTime() {
|
||||
return (int) futureTimeout.getDelay(TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
public void construct() {
|
||||
table.construct();
|
||||
|
|
@ -715,8 +706,7 @@ public class TableController {
|
|||
} else {
|
||||
closeTable();
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
closeTable();
|
||||
}
|
||||
} catch (GameException ex) {
|
||||
|
|
@ -729,7 +719,7 @@ public class TableController {
|
|||
table.sideboard();
|
||||
setupTimeout(Match.SIDEBOARD_TIME);
|
||||
if (table.isTournamentSubTable()) {
|
||||
for (MatchPlayer matchPlayer :match.getPlayers()) {
|
||||
for (MatchPlayer matchPlayer : match.getPlayers()) {
|
||||
if (!matchPlayer.hasQuit()) {
|
||||
TournamentPlayer tournamentPlayer = table.getTournament().getPlayer(matchPlayer.getPlayer().getId());
|
||||
if (tournamentPlayer != null) {
|
||||
|
|
@ -741,7 +731,7 @@ public class TableController {
|
|||
match.sideboard();
|
||||
cancelTimeout();
|
||||
if (table.isTournamentSubTable()) {
|
||||
for (MatchPlayer matchPlayer :match.getPlayers()) {
|
||||
for (MatchPlayer matchPlayer : match.getPlayers()) {
|
||||
TournamentPlayer tournamentPlayer = table.getTournament().getPlayer(matchPlayer.getPlayer().getId());
|
||||
if (tournamentPlayer != null && tournamentPlayer.getStateInfo().equals("sideboarding")) {
|
||||
tournamentPlayer.setStateInfo("");
|
||||
|
|
@ -749,10 +739,11 @@ public class TableController {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tables of normal matches or tournament sub tables are no longer
|
||||
* needed, if the match ends.
|
||||
*
|
||||
* Tables of normal matches or tournament sub tables are no longer needed,
|
||||
* if the match ends.
|
||||
*
|
||||
*/
|
||||
private void closeTable() {
|
||||
this.matchEnd();
|
||||
|
|
@ -761,11 +752,11 @@ public class TableController {
|
|||
|
||||
private void matchEnd() {
|
||||
if (match != null) {
|
||||
for (Entry<UUID, UUID> entry: userPlayerMap.entrySet()) {
|
||||
for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) {
|
||||
MatchPlayer matchPlayer = match.getPlayer(entry.getValue());
|
||||
// opponent(s) left during sideboarding
|
||||
if (matchPlayer != null) {
|
||||
if(!matchPlayer.hasQuit()) {
|
||||
if (!matchPlayer.hasQuit()) {
|
||||
User user = UserManager.getInstance().getUser(entry.getKey());
|
||||
if (user != null) {
|
||||
if (table.getState().equals(TableState.SIDEBOARDING)) {
|
||||
|
|
@ -801,13 +792,13 @@ public class TableController {
|
|||
cancelTimeout();
|
||||
if (seconds > 0) {
|
||||
futureTimeout = timeoutExecutor.schedule(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
autoSideboard();
|
||||
}
|
||||
},
|
||||
seconds, TimeUnit.SECONDS
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
autoSideboard();
|
||||
}
|
||||
},
|
||||
seconds, TimeUnit.SECONDS
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -819,7 +810,7 @@ public class TableController {
|
|||
}
|
||||
|
||||
private void autoSideboard() {
|
||||
for (MatchPlayer player: match.getPlayers()) {
|
||||
for (MatchPlayer player : match.getPlayers()) {
|
||||
if (!player.isDoneSideboarding()) {
|
||||
match.submitDeck(player.getPlayer().getId(), player.generateDeck());
|
||||
}
|
||||
|
|
@ -828,7 +819,7 @@ public class TableController {
|
|||
|
||||
public void endDraft(Draft draft) {
|
||||
if (!draft.isAbort()) {
|
||||
for (DraftPlayer player: draft.getPlayers()) {
|
||||
for (DraftPlayer player : draft.getPlayers()) {
|
||||
player.prepareDeck();
|
||||
tournament.getPlayer(player.getPlayer().getId()).setDeck(player.getDeck());
|
||||
}
|
||||
|
|
@ -871,7 +862,7 @@ public class TableController {
|
|||
|
||||
public boolean isTournamentStillValid() {
|
||||
if (table.getTournament() != null) {
|
||||
if (!table.getState().equals(TableState.WAITING) && !table.getState().equals(TableState.READY_TO_START) && !table.getState().equals(TableState.STARTING) ) {
|
||||
if (!table.getState().equals(TableState.WAITING) && !table.getState().equals(TableState.READY_TO_START) && !table.getState().equals(TableState.STARTING)) {
|
||||
TournamentController tournamentController = TournamentManager.getInstance().getTournamentController(table.getTournament().getId());
|
||||
if (tournamentController != null) {
|
||||
return tournamentController.isTournamentStillValid(table.getState());
|
||||
|
|
@ -888,7 +879,7 @@ public class TableController {
|
|||
}
|
||||
|
||||
public UUID getUserId(UUID playerId) {
|
||||
for (Map.Entry<UUID, UUID> entry: userPlayerMap.entrySet()) {
|
||||
for (Map.Entry<UUID, UUID> entry : userPlayerMap.entrySet()) {
|
||||
if (entry.getValue().equals(playerId)) {
|
||||
return entry.getKey();
|
||||
}
|
||||
|
|
@ -900,7 +891,7 @@ public class TableController {
|
|||
// check only normal match table with state != Finished
|
||||
if (!table.isTournament()) {
|
||||
int humanPlayers = 0;
|
||||
int aiPlayers = 0 ;
|
||||
int aiPlayers = 0;
|
||||
int validHumanPlayers = 0;
|
||||
if (!(table.getState().equals(TableState.WAITING) || table.getState().equals(TableState.STARTING) || table.getState().equals(TableState.READY_TO_START))) {
|
||||
if (match == null) {
|
||||
|
|
@ -917,7 +908,7 @@ public class TableController {
|
|||
}
|
||||
}
|
||||
// check for active players
|
||||
for(Map.Entry<UUID, UUID> userPlayerEntry: userPlayerMap.entrySet()) {
|
||||
for (Map.Entry<UUID, UUID> userPlayerEntry : userPlayerMap.entrySet()) {
|
||||
MatchPlayer matchPlayer = match.getPlayer(userPlayerEntry.getValue());
|
||||
if (matchPlayer == null) {
|
||||
logger.debug("- Match player not found:");
|
||||
|
|
@ -927,12 +918,12 @@ public class TableController {
|
|||
continue;
|
||||
}
|
||||
if (matchPlayer.getPlayer().isHuman()) {
|
||||
humanPlayers++;
|
||||
if ((table.getState().equals(TableState.WAITING) ||
|
||||
table.getState().equals(TableState.STARTING) ||
|
||||
table.getState().equals(TableState.READY_TO_START)) ||
|
||||
!match.isDoneSideboarding() ||
|
||||
(!matchPlayer.hasQuit() && match.getGame() != null && matchPlayer.getPlayer().isInGame())) {
|
||||
humanPlayers++;
|
||||
if ((table.getState().equals(TableState.WAITING)
|
||||
|| table.getState().equals(TableState.STARTING)
|
||||
|| table.getState().equals(TableState.READY_TO_START))
|
||||
|| !match.isDoneSideboarding()
|
||||
|| (!matchPlayer.hasQuit() && match.getGame() != null && matchPlayer.getPlayer().isInGame())) {
|
||||
User user = UserManager.getInstance().getUser(userPlayerEntry.getKey());
|
||||
if (user == null) {
|
||||
logger.debug("- Active user of match is missing: " + matchPlayer.getName());
|
||||
|
|
@ -953,10 +944,10 @@ public class TableController {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void cleanUp() {
|
||||
if (!table.isTournamentSubTable()) {
|
||||
for(Map.Entry<UUID, UUID> entry: userPlayerMap.entrySet()) {
|
||||
for (Map.Entry<UUID, UUID> entry : userPlayerMap.entrySet()) {
|
||||
User user = UserManager.getInstance().getUser(entry.getKey());
|
||||
if (user != null) {
|
||||
user.removeTable(entry.getValue());
|
||||
|
|
@ -969,11 +960,11 @@ public class TableController {
|
|||
public synchronized TableState getTableState() {
|
||||
return getTable().getState();
|
||||
}
|
||||
|
||||
|
||||
public synchronized boolean changeTableState(TableState newTableState) {
|
||||
switch (newTableState) {
|
||||
case WAITING:
|
||||
if (getTable().getState().equals(TableState.STARTING)){
|
||||
if (getTable().getState().equals(TableState.STARTING)) {
|
||||
// tournament already started
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,8 +104,6 @@ public class User {
|
|||
this.watchedGames = new ArrayList<>();
|
||||
this.tablesToDelete = new ArrayList<>();
|
||||
this.sessionId = "";
|
||||
// default these to avaiod NPE -> will be updated from client short after
|
||||
this.userData = new UserData(UserGroup.PLAYER, 0, false, false, false, null, "world.png", false);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
|
@ -393,10 +391,17 @@ public class User {
|
|||
}
|
||||
|
||||
public void setUserData(UserData userData) {
|
||||
this.userData = userData;
|
||||
if (this.userData != null) {
|
||||
this.userData.update(userData);
|
||||
} else {
|
||||
this.userData = userData;
|
||||
}
|
||||
}
|
||||
|
||||
public UserData getUserData() {
|
||||
if (userData == null) {// default these to avaiod NPE -> will be updated from client short after
|
||||
return new UserData(UserGroup.DEFAULT, 0, false, false, false, null, "world.png", false);
|
||||
}
|
||||
return this.userData;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,31 +1,30 @@
|
|||
/*
|
||||
* Copyright 2011 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 2011 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.tournament;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
|
@ -63,7 +62,6 @@ import mage.view.ChatMessage.SoundToPlay;
|
|||
import mage.view.TournamentView;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
|
@ -89,57 +87,57 @@ public class TournamentController {
|
|||
|
||||
private void init() {
|
||||
tournament.addTableEventListener(
|
||||
new Listener<TableEvent> () {
|
||||
@Override
|
||||
public void event(TableEvent event) {
|
||||
switch (event.getEventType()) {
|
||||
case CHECK_STATE_PLAYERS:
|
||||
checkPlayersState();
|
||||
break;
|
||||
case INFO:
|
||||
ChatManager.getInstance().broadcast(chatId, "", event.getMessage(), MessageColor.BLACK, true, MessageType.STATUS);
|
||||
logger.debug(tournament.getId() + " " + event.getMessage());
|
||||
break;
|
||||
case START_DRAFT:
|
||||
startDraft(event.getDraft());
|
||||
break;
|
||||
case CONSTRUCT:
|
||||
if (!isAbort()) {
|
||||
construct();
|
||||
} else {
|
||||
endTournament();
|
||||
}
|
||||
break;
|
||||
case START_MATCH:
|
||||
if (!isAbort()) {
|
||||
initTournament(); // set state
|
||||
startMatch(event.getPair(), event.getMatchOptions());
|
||||
}
|
||||
break;
|
||||
case END:
|
||||
endTournament();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
tournament.addPlayerQueryEventListener(
|
||||
new Listener<PlayerQueryEvent> () {
|
||||
@Override
|
||||
public void event(PlayerQueryEvent event) {
|
||||
try {
|
||||
switch (event.getQueryType()) {
|
||||
new Listener<TableEvent>() {
|
||||
@Override
|
||||
public void event(TableEvent event) {
|
||||
switch (event.getEventType()) {
|
||||
case CHECK_STATE_PLAYERS:
|
||||
checkPlayersState();
|
||||
break;
|
||||
case INFO:
|
||||
ChatManager.getInstance().broadcast(chatId, "", event.getMessage(), MessageColor.BLACK, true, MessageType.STATUS);
|
||||
logger.debug(tournament.getId() + " " + event.getMessage());
|
||||
break;
|
||||
case START_DRAFT:
|
||||
startDraft(event.getDraft());
|
||||
break;
|
||||
case CONSTRUCT:
|
||||
construct(event.getPlayerId(), event.getMax());
|
||||
if (!isAbort()) {
|
||||
construct();
|
||||
} else {
|
||||
endTournament();
|
||||
}
|
||||
break;
|
||||
case START_MATCH:
|
||||
if (!isAbort()) {
|
||||
initTournament(); // set state
|
||||
startMatch(event.getPair(), event.getMatchOptions());
|
||||
}
|
||||
break;
|
||||
case END:
|
||||
endTournament();
|
||||
break;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
logger.fatal("Player event listener error", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
for (TournamentPlayer player: tournament.getPlayers()) {
|
||||
tournament.addPlayerQueryEventListener(
|
||||
new Listener<PlayerQueryEvent>() {
|
||||
@Override
|
||||
public void event(PlayerQueryEvent event) {
|
||||
try {
|
||||
switch (event.getQueryType()) {
|
||||
case CONSTRUCT:
|
||||
construct(event.getPlayerId(), event.getMax());
|
||||
break;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
logger.fatal("Player event listener error", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
for (TournamentPlayer player : tournament.getPlayers()) {
|
||||
if (!player.getPlayer().isHuman()) {
|
||||
player.setJoined();
|
||||
logger.debug("player " + player.getPlayer().getId() + " has joined tournament " + tournament.getId());
|
||||
|
|
@ -163,7 +161,7 @@ public class TournamentController {
|
|||
if (tournamentSessions.containsKey(playerId)) {
|
||||
logger.debug("player reopened tournament panel userId: " + userId + " tournamentId: " + tournament.getId());
|
||||
return;
|
||||
}
|
||||
}
|
||||
// first join of player
|
||||
TournamentSession tournamentSession = new TournamentSession(tournament, userId, tableId, playerId);
|
||||
tournamentSessions.put(playerId, tournamentSession);
|
||||
|
|
@ -172,22 +170,22 @@ public class TournamentController {
|
|||
user.addTournament(playerId, tournament.getId());
|
||||
TournamentPlayer player = tournament.getPlayer(playerId);
|
||||
player.setJoined();
|
||||
logger.debug("player " +player.getPlayer().getName() + " - client has joined tournament " + tournament.getId());
|
||||
logger.debug("player " + player.getPlayer().getName() + " - client has joined tournament " + tournament.getId());
|
||||
ChatManager.getInstance().broadcast(chatId, "", player.getPlayer().getLogName() + " has joined the tournament", MessageColor.BLACK, true, MessageType.STATUS);
|
||||
checkStart();
|
||||
} else {
|
||||
logger.error("User not found userId: " + userId + " tournamentId: " + tournament.getId());
|
||||
logger.error("User not found userId: " + userId + " tournamentId: " + tournament.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public void rejoin(UUID playerId) {
|
||||
TournamentSession tournamentSession = tournamentSessions.get(playerId);
|
||||
if (tournamentSession == null) {
|
||||
logger.fatal("Tournament session not found - playerId:" + playerId + " tournamentId " + tournament.getId());
|
||||
logger.fatal("Tournament session not found - playerId:" + playerId + " tournamentId " + tournament.getId());
|
||||
return;
|
||||
}
|
||||
if (!tournamentSession.init()) {
|
||||
logger.fatal("Unable to initialize client userId: " + tournamentSession.userId + " tournamentId " + tournament.getId());
|
||||
logger.fatal("Unable to initialize client userId: " + tournamentSession.userId + " tournamentId " + tournament.getId());
|
||||
return;
|
||||
}
|
||||
tournamentSession.update();
|
||||
|
|
@ -196,12 +194,12 @@ public class TournamentController {
|
|||
private void checkStart() {
|
||||
if (!started && allJoined()) {
|
||||
ThreadExecutor.getInstance().getCallExecutor().execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startTournament();
|
||||
}
|
||||
});
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startTournament();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -209,7 +207,7 @@ public class TournamentController {
|
|||
if (!tournament.allJoined()) {
|
||||
return false;
|
||||
}
|
||||
for (TournamentPlayer player: tournament.getPlayers()) {
|
||||
for (TournamentPlayer player : tournament.getPlayers()) {
|
||||
if (player.getPlayer().isHuman() && tournamentSessions.get(player.getPlayer().getId()) == null) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -218,9 +216,9 @@ public class TournamentController {
|
|||
}
|
||||
|
||||
private synchronized void startTournament() {
|
||||
for (final TournamentSession tournamentSession: tournamentSessions.values()) {
|
||||
for (final TournamentSession tournamentSession : tournamentSessions.values()) {
|
||||
if (!tournamentSession.init()) {
|
||||
logger.fatal("Unable to initialize client userId: " + tournamentSession.userId + " tournamentId " + tournament.getId());
|
||||
logger.fatal("Unable to initialize client userId: " + tournamentSession.userId + " tournamentId " + tournament.getId());
|
||||
//TODO: generate client error message
|
||||
return;
|
||||
}
|
||||
|
|
@ -231,10 +229,10 @@ public class TournamentController {
|
|||
}
|
||||
|
||||
private void endTournament() {
|
||||
for (TournamentPlayer player: tournament.getPlayers()) {
|
||||
for (TournamentPlayer player : tournament.getPlayers()) {
|
||||
player.setStateAtTournamentEnd();
|
||||
}
|
||||
for (final TournamentSession tournamentSession: tournamentSessions.values()) {
|
||||
for (final TournamentSession tournamentSession : tournamentSessions.values()) {
|
||||
tournamentSession.tournamentOver();
|
||||
}
|
||||
this.tournamentSessions.clear();
|
||||
|
|
@ -296,8 +294,8 @@ public class TournamentController {
|
|||
TournamentPlayer player = tournament.getPlayer(playerId);
|
||||
if (player != null && !player.hasQuit()) {
|
||||
tournamentSessions.get(playerId).submitDeck(deck);
|
||||
ChatManager.getInstance().broadcast(chatId, "", player.getPlayer().getLogName() + " has submitted his tournament deck", MessageColor.BLACK, true, MessageType.STATUS, SoundToPlay.PlayerSubmittedDeck);
|
||||
}
|
||||
ChatManager.getInstance().broadcast(chatId, "", player.getPlayer().getLogName() + " has submitted his tournament deck", MessageColor.BLACK, true, MessageType.STATUS, SoundToPlay.PlayerSubmittedDeck);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -387,7 +385,7 @@ public class TournamentController {
|
|||
private boolean checkToReplaceDraftPlayerByAi(UUID userId, TournamentPlayer leavingPlayer) {
|
||||
|
||||
int humans = 0;
|
||||
for (TournamentPlayer tPlayer :tournament.getPlayers()) {
|
||||
for (TournamentPlayer tPlayer : tournament.getPlayers()) {
|
||||
if (tPlayer.getPlayer().isHuman()) {
|
||||
humans++;
|
||||
}
|
||||
|
|
@ -415,7 +413,7 @@ public class TournamentController {
|
|||
}
|
||||
|
||||
private UUID getPlayerUserId(UUID playerId) {
|
||||
for (Entry<UUID, UUID> entry: userPlayerMap.entrySet()) {
|
||||
for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) {
|
||||
if (entry.getValue().equals(playerId)) {
|
||||
return entry.getKey();
|
||||
}
|
||||
|
|
@ -437,7 +435,7 @@ public class TournamentController {
|
|||
}
|
||||
|
||||
private void checkPlayersState() {
|
||||
for (TournamentPlayer tournamentPlayer: tournament.getPlayers()) {
|
||||
for (TournamentPlayer tournamentPlayer : tournament.getPlayers()) {
|
||||
if (!tournamentPlayer.isEliminated() && tournamentPlayer.getPlayer().isHuman()) {
|
||||
if (tournamentSessions.containsKey(tournamentPlayer.getPlayer().getId())) {
|
||||
if (tournamentSessions.get(tournamentPlayer.getPlayer().getId()).isKilled()) {
|
||||
|
|
@ -452,22 +450,22 @@ public class TournamentController {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void cleanUpOnRemoveTournament() {
|
||||
ChatManager.getInstance().destroyChatSession(chatId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check tournaments that are not already finished, if they are in a still valid state
|
||||
* Check tournaments that are not already finished, if they are in a still
|
||||
* valid state
|
||||
*
|
||||
* @param tableState state of the tournament table
|
||||
* @return true - if tournament is valid
|
||||
* false - if tournament is not valid and should be removed
|
||||
* @return true - if tournament is valid false - if tournament is not valid
|
||||
* and should be removed
|
||||
*/
|
||||
|
||||
public boolean isTournamentStillValid(TableState tableState) {
|
||||
int activePlayers = 0;
|
||||
for (Entry<UUID, UUID> entry: userPlayerMap.entrySet()) {
|
||||
for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) {
|
||||
TournamentPlayer tournamentPlayer = tournament.getPlayer(entry.getValue());
|
||||
if (tournamentPlayer != null) {
|
||||
if (!tournamentPlayer.hasQuit()) {
|
||||
|
|
@ -480,14 +478,14 @@ public class TournamentController {
|
|||
} else {
|
||||
activePlayers++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// tournament player is missing
|
||||
logger.debug("Tournament player is missing - tournamentId: " + tournament.getId() + " state: " + tableState.toString());
|
||||
}
|
||||
}
|
||||
for(TournamentPlayer tournamentPlayer: tournament.getPlayers()) {
|
||||
for (TournamentPlayer tournamentPlayer : tournament.getPlayers()) {
|
||||
if (!tournamentPlayer.getPlayer().isHuman()) {
|
||||
if (!tournamentPlayer.hasQuit()) {
|
||||
activePlayers++;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue