mirror of
https://github.com/magefree/mage.git
synced 2025-12-27 14:02:05 -08:00
Fixed CardInfo and ExpansionInfo compare with server. Fixed UserData update.
This commit is contained in:
parent
c8b092c758
commit
78a3e649bc
22 changed files with 2409 additions and 2180 deletions
|
|
@ -1,30 +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.client;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
|
|
@ -374,7 +374,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
private void setWindowTitle() {
|
||||
setTitle(TITLE_NAME + " Client: "
|
||||
+ version == null ? "<not available>" : version.toString() + " Server: "
|
||||
+ ((client != null && client.isConnected()) ? serverState.getVersion().toString():"<not connected>"));
|
||||
+ ((client != null && client.isConnected()) ? serverState.getVersion().toString() : "<not connected>"));
|
||||
}
|
||||
|
||||
private void addTooltipContainer() {
|
||||
|
|
@ -653,7 +653,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
for(Component component :desktopPane.getComponents()) {
|
||||
for (Component component : desktopPane.getComponents()) {
|
||||
if (component instanceof GamePane
|
||||
&& ((GamePane) component).getGameId().equals(gameId)) {
|
||||
setActive((GamePane) component);
|
||||
|
|
@ -722,9 +722,9 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
for(Component component :desktopPane.getComponents()) {
|
||||
if (component instanceof TournamentPane &&
|
||||
((TournamentPane) component).getTournamentId().equals(tournamentId)) {
|
||||
for (Component component : desktopPane.getComponents()) {
|
||||
if (component instanceof TournamentPane
|
||||
&& ((TournamentPane) component).getTournamentId().equals(tournamentId)) {
|
||||
setActive((TournamentPane) component);
|
||||
return;
|
||||
}
|
||||
|
|
@ -776,24 +776,24 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
private void updateDatabase(boolean forceDBComparison, ServerState serverState) {
|
||||
long cardDBVersion = CardRepository.instance.getContentVersionFromDB();
|
||||
if (forceDBComparison || serverState.getCardsContentVersion() > cardDBVersion) {
|
||||
List<String> classNames = client.getCards(); //CardRepository.instance.getClassNames();
|
||||
List<CardInfo> cards = CardRepository.instance.getMissingCards(classNames);
|
||||
CardRepository.instance.addCards(cards);
|
||||
List<String> classNames = CardRepository.instance.getClassNames();
|
||||
List<CardInfo> cardInfoList = client.getMissingCardsData(classNames);
|
||||
CardRepository.instance.addCards(cardInfoList);
|
||||
CardRepository.instance.setContentVersion(serverState.getCardsContentVersion());
|
||||
logger.info("Updating client cards DB - existing cards: " + classNames.size() + " new cards: " + cards.size() +
|
||||
" content versions - server: " + serverState.getCardsContentVersion() + " client: " + cardDBVersion);
|
||||
logger.info("Updating client cards DB - existing cards: " + classNames.size() + " new cards: " + cardInfoList.size()
|
||||
+ " content versions - server: " + serverState.getCardsContentVersion() + " client: " + cardDBVersion);
|
||||
}
|
||||
|
||||
long expansionDBVersion = ExpansionRepository.instance.getContentVersionFromDB();
|
||||
if (forceDBComparison || serverState.getExpansionsContentVersion() > expansionDBVersion) {
|
||||
List<String> setCodes = ExpansionRepository.instance.getSetCodes();
|
||||
List<ExpansionInfo> expansions = getMissingExpansionData(setCodes);
|
||||
List<ExpansionInfo> expansions = client.getMissingExpansionsData(setCodes);
|
||||
for (ExpansionInfo expansion : expansions) {
|
||||
ExpansionRepository.instance.add(expansion);
|
||||
}
|
||||
ExpansionRepository.instance.setContentVersion(serverState.getExpansionsContentVersion());
|
||||
logger.info("Updating client expansions DB - existing sets: " + setCodes.size() + " new sets: " + expansions.size()+
|
||||
" content versions - server: " + serverState.getExpansionsContentVersion() + " client: " + expansionDBVersion);
|
||||
logger.info("Updating client expansions DB - existing sets: " + setCodes.size() + " new sets: " + expansions.size()
|
||||
+ " content versions - server: " + serverState.getExpansionsContentVersion() + " client: " + expansionDBVersion);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -841,7 +841,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
setUserPrefsToConnection(connection);
|
||||
|
||||
logger.debug("connecting (auto): " + proxyType + " " + proxyServer + " " + proxyPort + " " + proxyUsername);
|
||||
if (connect(connection)) {
|
||||
if (connect(connection)) {
|
||||
return true;
|
||||
} else {
|
||||
showMessage("Error Connecting", "Unable to connect to server");
|
||||
|
|
@ -1109,7 +1109,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
this.tablesPane.hideTables();
|
||||
}
|
||||
|
||||
public void showGames(final boolean setActive) {
|
||||
public void showGames(final boolean setActive) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
@ -1125,7 +1125,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
if (topPanebefore != null) {
|
||||
setActive(topPanebefore);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -1399,20 +1399,20 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
|
||||
@Override
|
||||
public void disconnected(final boolean errorCall) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setStatusText("Not connected");
|
||||
disableButtons();
|
||||
hideGames();
|
||||
hideTables();
|
||||
if (errorCall && JOptionPane.showConfirmDialog(MageFrame.this, "The connection to server was lost. Reconnect?", "Warning", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
||||
if (performConnect()) {
|
||||
enableButtons();
|
||||
}
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setStatusText("Not connected");
|
||||
disableButtons();
|
||||
hideGames();
|
||||
hideTables();
|
||||
if (errorCall && JOptionPane.showConfirmDialog(MageFrame.this, "The connection to server was lost. Reconnect?", "Warning", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
||||
if (performConnect()) {
|
||||
enableButtons();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void showMessage(final String title, final String message) {
|
||||
|
|
@ -1437,8 +1437,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
public void inform(String title, String message, MessageType type) {
|
||||
if (type == MessageType.ERROR) {
|
||||
showError(title, message);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
showMessage(title, message);
|
||||
}
|
||||
}
|
||||
|
|
@ -1698,14 +1697,13 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
sideboard(deck, tableId, time);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void construct(UUID tableId, DeckView deckView, int time) {
|
||||
Deck deck = DeckUtil.construct(deckView);
|
||||
construct(deck, tableId, time);
|
||||
}
|
||||
|
||||
|
||||
protected void sideboard(Deck deck, UUID tableId, int time) {
|
||||
showDeckEditor(DeckEditorMode.SIDEBOARDING, deck, tableId, time);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,6 @@ import mage.players.net.UserGroup;
|
|||
import mage.players.net.UserSkipPrioritySteps;
|
||||
import mage.remote.Connection;
|
||||
import mage.remote.Connection.ProxyType;
|
||||
import mage.view.UserDataView;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
|
|
@ -2722,8 +2721,8 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
}
|
||||
}
|
||||
|
||||
public static UserDataView getUserData() {
|
||||
return new UserDataView(UserGroup.PLAYER,
|
||||
public static UserData getUserData() {
|
||||
return new UserData(UserGroup.PLAYER,
|
||||
PreferencesDialog.selectedAvatarId,
|
||||
PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_ABILITY_PICKER_FORCED, "true").equals("true"),
|
||||
PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS, "true").equals("true"),
|
||||
|
|
|
|||
|
|
@ -34,8 +34,7 @@ import java.net.InterfaceAddress;
|
|||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Enumeration;
|
||||
import mage.players.net.UserSkipPrioritySteps;
|
||||
import mage.view.UserDataView;
|
||||
import mage.players.net.UserData;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -56,7 +55,7 @@ public class Connection implements Serializable {
|
|||
private int clientCardDatabaseVersion;
|
||||
private boolean forceDBComparison;
|
||||
|
||||
private UserDataView userData;
|
||||
private UserData userData;
|
||||
|
||||
// private int avatarId;
|
||||
// private boolean showAbilityPickerForced;
|
||||
|
|
@ -64,8 +63,6 @@ public class Connection implements Serializable {
|
|||
// private boolean confirmEmptyManaPool;
|
||||
// private String flagName;
|
||||
// private UserSkipPrioritySteps userSkipPrioritySteps;
|
||||
|
||||
|
||||
public ProxyType getProxyType() {
|
||||
return proxyType;
|
||||
}
|
||||
|
|
@ -118,11 +115,11 @@ public class Connection implements Serializable {
|
|||
public boolean isSSL() {
|
||||
return this.ssl;
|
||||
}
|
||||
|
||||
|
||||
public void setSSL(boolean ssl) {
|
||||
this.ssl = ssl;
|
||||
}
|
||||
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
|
@ -189,11 +186,11 @@ public class Connection implements Serializable {
|
|||
return null;
|
||||
}
|
||||
|
||||
public void setUserData(UserDataView userData) {
|
||||
this.userData= userData;
|
||||
public void setUserData(UserData userData) {
|
||||
this.userData = userData;
|
||||
}
|
||||
|
||||
public UserDataView getUserData() {
|
||||
|
||||
public UserData getUserData() {
|
||||
return userData;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,102 +1,102 @@
|
|||
/*
|
||||
* 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.utils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class MageVersion implements Serializable, Comparable<MageVersion> {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final static int MAGE_VERSION_MAJOR = 1;
|
||||
public final static int MAGE_VERSION_MINOR = 4;
|
||||
public final static int MAGE_VERSION_PATCH = 4;
|
||||
public final static String MAGE_VERSION_MINOR_PATCH = "v7";
|
||||
public final static String MAGE_VERSION_INFO = "";
|
||||
|
||||
private final int major;
|
||||
private final int minor;
|
||||
private final int patch;
|
||||
private final String minorPatch; // doesn't matter for compatibility
|
||||
|
||||
private String info = "";
|
||||
private static MageVersion currentVersion = new MageVersion(MAGE_VERSION_MAJOR, MAGE_VERSION_MINOR, MAGE_VERSION_PATCH, MAGE_VERSION_MINOR_PATCH, MAGE_VERSION_INFO);
|
||||
|
||||
public MageVersion(int major, int minor, int patch, String minorPatch, String info) {
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
this.patch = patch;
|
||||
this.minorPatch = minorPatch;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public static MageVersion getCurrent() {
|
||||
return currentVersion;
|
||||
}
|
||||
|
||||
public int getMajor() {
|
||||
return major;
|
||||
}
|
||||
|
||||
public int getMinor() {
|
||||
return minor;
|
||||
}
|
||||
|
||||
public int getPatch() {
|
||||
return patch;
|
||||
}
|
||||
|
||||
public String getMinorPatch() {
|
||||
return minorPatch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return major + "." + minor + "." + patch + info + minorPatch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(MageVersion o) {
|
||||
if (major != o.major) {
|
||||
return major - o.major;
|
||||
}
|
||||
if (minor != o.minor) {
|
||||
return minor - o.minor;
|
||||
}
|
||||
if (patch != o.patch) {
|
||||
return patch - o.patch;
|
||||
}
|
||||
return info.compareTo(o.info);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* 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.utils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class MageVersion implements Serializable, Comparable<MageVersion> {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final static int MAGE_VERSION_MAJOR = 1;
|
||||
public final static int MAGE_VERSION_MINOR = 4;
|
||||
public final static int MAGE_VERSION_PATCH = 5;
|
||||
public final static String MAGE_VERSION_MINOR_PATCH = "v0";
|
||||
public final static String MAGE_VERSION_INFO = "";
|
||||
|
||||
private final int major;
|
||||
private final int minor;
|
||||
private final int patch;
|
||||
private final String minorPatch; // doesn't matter for compatibility
|
||||
|
||||
private String info = "";
|
||||
private static MageVersion currentVersion = new MageVersion(MAGE_VERSION_MAJOR, MAGE_VERSION_MINOR, MAGE_VERSION_PATCH, MAGE_VERSION_MINOR_PATCH, MAGE_VERSION_INFO);
|
||||
|
||||
public MageVersion(int major, int minor, int patch, String minorPatch, String info) {
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
this.patch = patch;
|
||||
this.minorPatch = minorPatch;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public static MageVersion getCurrent() {
|
||||
return currentVersion;
|
||||
}
|
||||
|
||||
public int getMajor() {
|
||||
return major;
|
||||
}
|
||||
|
||||
public int getMinor() {
|
||||
return minor;
|
||||
}
|
||||
|
||||
public int getPatch() {
|
||||
return patch;
|
||||
}
|
||||
|
||||
public String getMinorPatch() {
|
||||
return minorPatch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return major + "." + minor + "." + patch + info + minorPatch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(MageVersion o) {
|
||||
if (major != o.major) {
|
||||
return major - o.major;
|
||||
}
|
||||
if (minor != o.minor) {
|
||||
return minor - o.minor;
|
||||
}
|
||||
if (patch != o.patch) {
|
||||
return patch - o.patch;
|
||||
}
|
||||
return info.compareTo(o.info);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,18 +19,20 @@ import java.util.Set;
|
|||
import java.util.UUID;
|
||||
import javax.net.ssl.SSLException;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import mage.cards.repository.ExpansionInfo;
|
||||
import mage.constants.ManaType;
|
||||
import mage.constants.PlayerAction;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.interfaces.ServerState;
|
||||
import mage.players.net.UserData;
|
||||
import mage.remote.Connection;
|
||||
import mage.utils.MageVersion;
|
||||
import mage.view.DraftPickView;
|
||||
import mage.view.RoomView;
|
||||
import mage.view.TableView;
|
||||
import mage.view.TournamentView;
|
||||
import mage.view.UserDataView;
|
||||
import mage.view.UserView;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.mage.network.handlers.PingMessageHandler;
|
||||
|
|
@ -46,9 +48,9 @@ import org.mage.network.messages.MessageType;
|
|||
* @author BetaSteward
|
||||
*/
|
||||
public class Client {
|
||||
|
||||
|
||||
private static final Logger logger = Logger.getLogger(Client.class);
|
||||
|
||||
|
||||
private static final int IDLE_PING_TIME = 30;
|
||||
private static final int IDLE_TIMEOUT = 60;
|
||||
|
||||
|
|
@ -56,9 +58,9 @@ public class Client {
|
|||
// private final MessageHandler h;
|
||||
private final ClientMessageHandler clientMessageHandler;
|
||||
private final ClientRegisteredMessageHandler clientRegisteredMessageHandler;
|
||||
|
||||
|
||||
private final ClientExceptionHandler exceptionHandler;
|
||||
|
||||
|
||||
private SslContext sslCtx;
|
||||
private Channel channel;
|
||||
private String username;
|
||||
|
|
@ -66,18 +68,18 @@ public class Client {
|
|||
private int port;
|
||||
|
||||
private static final EventLoopGroup group = new NioEventLoopGroup();
|
||||
|
||||
|
||||
public Client(MageClient client) {
|
||||
this.client = client;
|
||||
// h = new MessageHandler();
|
||||
clientMessageHandler = new ClientMessageHandler(client);
|
||||
clientRegisteredMessageHandler = new ClientRegisteredMessageHandler();
|
||||
|
||||
|
||||
exceptionHandler = new ClientExceptionHandler(this);
|
||||
}
|
||||
|
||||
|
||||
public boolean connect(Connection connection, MageVersion version) {
|
||||
|
||||
|
||||
this.username = connection.getUsername();
|
||||
this.host = connection.getHost();
|
||||
this.port = connection.getPort();
|
||||
|
|
@ -88,21 +90,20 @@ public class Client {
|
|||
} else {
|
||||
sslCtx = null;
|
||||
}
|
||||
Bootstrap b = new Bootstrap();
|
||||
b.group(group)
|
||||
.channel(NioSocketChannel.class)
|
||||
.handler(new ClientInitializer());
|
||||
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
bootstrap.group(group)
|
||||
.channel(NioSocketChannel.class)
|
||||
.handler(new ClientInitializer());
|
||||
|
||||
clientRegisteredMessageHandler.setConnection(connection);
|
||||
clientRegisteredMessageHandler.setVersion(version);
|
||||
channel = b.connect(host, port).sync().channel();
|
||||
channel = bootstrap.connect(host, port).sync().channel();
|
||||
ServerState state = clientRegisteredMessageHandler.registerClient();
|
||||
if (state.isValid()) {
|
||||
client.clientRegistered(state);
|
||||
client.connected(connection.getUsername() + "@" + host + ":" + port + " ");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
disconnect(false);
|
||||
}
|
||||
} catch (SSLException | InterruptedException ex) {
|
||||
|
|
@ -117,13 +118,12 @@ public class Client {
|
|||
|
||||
@Override
|
||||
public void initChannel(SocketChannel ch) throws Exception {
|
||||
|
||||
|
||||
if (sslCtx != null) {
|
||||
ch.pipeline().addLast(sslCtx.newHandler(ch.alloc(), host, port));
|
||||
}
|
||||
ch.pipeline().addLast(new ObjectDecoder(ClassResolvers.cacheDisabled(null)));
|
||||
ch.pipeline().addLast(new ObjectDecoder(10 * 1024 * 1024, ClassResolvers.cacheDisabled(null)));
|
||||
ch.pipeline().addLast(new ObjectEncoder());
|
||||
|
||||
ch.pipeline().addLast("idleStateHandler", new IdleStateHandler(IDLE_TIMEOUT, IDLE_PING_TIME, 0));
|
||||
ch.pipeline().addLast("heartbeatHandler", new HeartbeatHandler());
|
||||
ch.pipeline().addLast("pingMessageHandler", new PingMessageHandler());
|
||||
|
|
@ -135,27 +135,27 @@ public class Client {
|
|||
ch.pipeline().addLast("exceptionHandler", exceptionHandler);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void disconnect(boolean error) {
|
||||
|
||||
|
||||
try {
|
||||
channel.disconnect().sync();
|
||||
client.disconnected(error);
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
} catch (InterruptedException ex) {
|
||||
logger.fatal("Error disconnecting", ex);
|
||||
}
|
||||
}
|
||||
// finally {
|
||||
// group.shutdownGracefully();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
public boolean isConnected() {
|
||||
if (channel != null)
|
||||
if (channel != null) {
|
||||
return channel.isActive();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void sendChatMessage(UUID chatId, String message) {
|
||||
clientMessageHandler.sendMessage(chatId, message);
|
||||
}
|
||||
|
|
@ -163,7 +163,7 @@ public class Client {
|
|||
public void joinChat(UUID chatId) {
|
||||
clientMessageHandler.joinChat(chatId);
|
||||
}
|
||||
|
||||
|
||||
public void leaveChat(UUID chatId) {
|
||||
clientMessageHandler.leaveChat(chatId);
|
||||
}
|
||||
|
|
@ -205,6 +205,24 @@ public class Client {
|
|||
return null;
|
||||
}
|
||||
|
||||
public List<CardInfo> getMissingCardsData(List<String> cards) {
|
||||
try {
|
||||
return clientMessageHandler.getMissingCardsData(cards);
|
||||
} catch (Exception ex) {
|
||||
logger.error("Error getting missing card data from server", ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ExpansionInfo> getMissingExpansionsData(List<String> setCodes) {
|
||||
try {
|
||||
return clientMessageHandler.getMissingExpansionData(setCodes);
|
||||
} catch (Exception ex) {
|
||||
logger.error("Error getting missing expansion set data", ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean submitDeck(UUID tableId, DeckCardLists deckCardLists) {
|
||||
try {
|
||||
return clientMessageHandler.submitDeck(tableId, deckCardLists);
|
||||
|
|
@ -280,9 +298,9 @@ public class Client {
|
|||
return null;
|
||||
}
|
||||
|
||||
public void setPreferences(UserDataView view) {
|
||||
public void setPreferences(UserData userData) {
|
||||
try {
|
||||
clientMessageHandler.setPreferences(view);
|
||||
clientMessageHandler.setPreferences(userData);
|
||||
} catch (Exception ex) {
|
||||
logger.error("Error updating preferences", ex);
|
||||
}
|
||||
|
|
@ -373,7 +391,7 @@ public class Client {
|
|||
logger.error("Error quitting tournament", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public TournamentView getTournament(UUID tournamentId) {
|
||||
try {
|
||||
return clientMessageHandler.getTournament(tournamentId);
|
||||
|
|
|
|||
|
|
@ -81,15 +81,15 @@ import org.mage.network.messages.callback.WatchGameCallback;
|
|||
* @author BetaSteward
|
||||
*/
|
||||
public class Server {
|
||||
|
||||
|
||||
private static final Logger logger = Logger.getLogger(Server.class);
|
||||
|
||||
private static final int IDLE_PING_TIME = 30;
|
||||
private static final int IDLE_TIMEOUT = 60;
|
||||
// private static final PingMessage ping = new PingMessage();
|
||||
|
||||
|
||||
public static final ChannelGroup clients = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
|
||||
|
||||
|
||||
private SslContext sslCtx;
|
||||
|
||||
private final MageServer server;
|
||||
|
|
@ -97,34 +97,34 @@ public class Server {
|
|||
private final PingMessageHandler pingMessageHandler = new PingMessageHandler();
|
||||
private final EventExecutorGroup handlersExecutor = new DefaultEventExecutorGroup(Runtime.getRuntime().availableProcessors() * 2);
|
||||
private final ServerRequestHandler serverMessageHandler;
|
||||
|
||||
|
||||
private final ServerExceptionHandler exceptionHandler;
|
||||
|
||||
|
||||
public Server(MageServer server) {
|
||||
this.server = server;
|
||||
// h = new MessageHandler();
|
||||
serverMessageHandler = new ServerRequestHandler(server);
|
||||
exceptionHandler = new ServerExceptionHandler(server);
|
||||
}
|
||||
|
||||
|
||||
public void start(int port, boolean ssl) throws Exception {
|
||||
|
||||
|
||||
if (ssl) {
|
||||
SelfSignedCertificate ssc = new SelfSignedCertificate();
|
||||
sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey());
|
||||
} else {
|
||||
sslCtx = null;
|
||||
}
|
||||
|
||||
|
||||
EventLoopGroup bossGroup = new NioEventLoopGroup();
|
||||
EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||
|
||||
|
||||
try {
|
||||
ServerBootstrap b = new ServerBootstrap();
|
||||
b.group(bossGroup, workerGroup)
|
||||
.channel(NioServerSocketChannel.class)
|
||||
.handler(new LoggingHandler(LogLevel.INFO))
|
||||
.childHandler(new ServerInitializer());
|
||||
.channel(NioServerSocketChannel.class)
|
||||
.handler(new LoggingHandler(LogLevel.INFO))
|
||||
.childHandler(new ServerInitializer());
|
||||
|
||||
b.bind(port).sync().channel().closeFuture().sync();
|
||||
} catch (InterruptedException ex) {
|
||||
|
|
@ -133,22 +133,23 @@ public class Server {
|
|||
bossGroup.shutdownGracefully();
|
||||
workerGroup.shutdownGracefully();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private class ServerInitializer extends ChannelInitializer<SocketChannel> {
|
||||
|
||||
|
||||
@Override
|
||||
public void initChannel(SocketChannel ch) throws Exception {
|
||||
|
||||
|
||||
if (sslCtx != null) {
|
||||
ch.pipeline().addLast(sslCtx.newHandler(ch.alloc()));
|
||||
ch.pipeline().addLast(sslCtx.newHandler(ch.alloc()));
|
||||
}
|
||||
ch.pipeline().addLast(new ObjectDecoder(ClassResolvers.cacheDisabled(null)));
|
||||
ch.pipeline().addLast(new ObjectDecoder(10 * 1024 * 1024, ClassResolvers.cacheDisabled(null)));
|
||||
ch.pipeline().addLast(new ObjectEncoder());
|
||||
|
||||
// ch.pipeline().addLast("h", h);
|
||||
ch.pipeline().addLast("idleStateHandler", new IdleStateHandler(IDLE_TIMEOUT, IDLE_PING_TIME, 0));
|
||||
|
||||
ch.pipeline().addLast(handlersExecutor, "heartbeatHandler", new HeartbeatHandler(server));
|
||||
ch.pipeline().addLast("pingMessageHandler", pingMessageHandler);
|
||||
|
||||
|
|
@ -157,10 +158,10 @@ public class Server {
|
|||
ch.pipeline().addLast("exceptionHandler", exceptionHandler);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Channel findChannel(String sessionId) {
|
||||
for (Channel channel: clients) {
|
||||
for (Channel channel : clients) {
|
||||
if (channel.id().asLongText().equals(sessionId)) {
|
||||
return channel;
|
||||
}
|
||||
|
|
@ -170,14 +171,16 @@ public class Server {
|
|||
|
||||
public void sendChatMessage(String sessionId, UUID chatId, ChatMessage message) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new ChatMessageCallback(chatId, message)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void informClient(String sessionId, String title, String message, MessageType type) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new InformClientCallback(title, message, type)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void informClients(String title, String message, MessageType type) {
|
||||
|
|
@ -187,183 +190,212 @@ public class Server {
|
|||
public void pingClient(String sessionId) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null) {
|
||||
HeartbeatHandler heartbeatHandler = (HeartbeatHandler)ch.pipeline().get("heartbeatHandler");
|
||||
HeartbeatHandler heartbeatHandler = (HeartbeatHandler) ch.pipeline().get("heartbeatHandler");
|
||||
heartbeatHandler.pingClient();
|
||||
}
|
||||
}
|
||||
|
||||
public void joinedTable(String sessionId, UUID roomId, UUID tableId, UUID chatId, boolean owner, boolean tournament) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new JoinedTableCallback(roomId, tableId, chatId, owner, tournament)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void gameStarted(String sessionId, UUID gameId, UUID playerId) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new GameStartedCallback(gameId, playerId)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void initGame(String sessionId, UUID gameId, GameView gameView) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new GameInitCallback(gameId, gameView)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void gameAsk(String sessionId, UUID gameId, GameView gameView, String question, Map<String, Serializable> options) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new GameAskCallback(gameId, gameView, question, options)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void gameTarget(String sessionId, UUID gameId, GameView gameView, String question, CardsView cardView, Set<UUID> targets, boolean required, Map<String, Serializable> options) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new GameTargetCallback(gameId, gameView, question, cardView, targets, required, options)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void gameSelect(String sessionId, UUID gameId, GameView gameView, String message, Map<String, Serializable> options) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new GameSelectCallback(gameId, gameView, message, options)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void gameChooseAbility(String sessionId, UUID gameId, AbilityPickerView abilities) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new GameChooseAbilityCallback(gameId, abilities)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void gameChoosePile(String sessionId, UUID gameId, String message, CardsView pile1, CardsView pile2) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new GameChoosePileCallback(gameId, message, pile1, pile2)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void gameChooseChoice(String sessionId, UUID gameId, Choice choice) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new GameChooseChoiceCallback(gameId, choice)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void gamePlayMana(String sessionId, UUID gameId, GameView gameView, String message, Map<String, Serializable> options) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new GamePlayManaCallback(gameId, gameView, message, options)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void gamePlayXMana(String sessionId, UUID gameId, GameView gameView, String message) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new GamePlayXManaCallback(gameId, gameView, message)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void gameSelectAmount(String sessionId, UUID gameId, String message, int min, int max) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new GameSelectAmountCallback(gameId, message, min, max)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void endGameInfo(String sessionId, UUID gameId, GameEndView view) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new GameEndInfoCallback(gameId, view)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void userRequestDialog(String sessionId, UUID gameId, UserRequestMessage userRequestMessage) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new UserRequestDialogCallback(gameId, userRequestMessage)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void gameUpdate(String sessionId, UUID gameId, GameView view) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new GameUpdateCallback(gameId, view)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void gameInform(String sessionId, UUID gameId, GameClientMessage message) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new GameInformCallback(gameId, message)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void gameInformPersonal(String sessionId, UUID gameId, GameClientMessage message) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new GameInformPersonalCallback(gameId, message)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void gameOver(String sessionId, UUID gameId, String message) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new GameOverCallback(gameId, message)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void gameError(String sessionId, UUID gameId, String message) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new GameErrorCallback(gameId, message)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void startDraft(String sessionId, UUID draftId, UUID playerId) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new StartDraftCallback(draftId, playerId)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void draftInit(String sessionId, UUID draftId, DraftPickView draftPickView) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new DraftInitCallback(draftId, draftPickView)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void draftUpdate(String sessionId, UUID draftId, DraftView draftView) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new DraftUpdateCallback(draftId, draftView)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void draftOver(String sessionId, UUID draftId) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new DraftOverCallback(draftId)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void draftPick(String sessionId, UUID draftId, DraftPickView draftPickView) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new DraftPickCallback(draftId, draftPickView)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void sideboard(String sessionId, UUID tableId, DeckView deck, int time, boolean limited) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new SideboardCallback(tableId, deck, time, limited)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void construct(String sessionId, UUID tableId, DeckView deck, int time) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new ConstructCallback(tableId, deck, time)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void tournamentStarted(String sessionId, UUID tournamentId, UUID playerId) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new TournamentStartedCallback(tournamentId, playerId)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void showTournament(String sessionId, UUID tournamentId) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new ShowTournamentCallback(tournamentId)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void watchGame(String sessionId, UUID gameId, UUID chatId, GameView game) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
if (ch != null) {
|
||||
ch.writeAndFlush(new WatchGameCallback(gameId, chatId, game)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public void replayGame(String sessionId, UUID gameId) {
|
||||
|
|
|
|||
|
|
@ -9,15 +9,17 @@ import java.util.UUID;
|
|||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import mage.cards.repository.ExpansionInfo;
|
||||
import mage.constants.ManaType;
|
||||
import mage.constants.PlayerAction;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.players.net.UserData;
|
||||
import mage.view.DraftPickView;
|
||||
import mage.view.RoomView;
|
||||
import mage.view.TableView;
|
||||
import mage.view.TournamentView;
|
||||
import mage.view.UserDataView;
|
||||
import org.mage.network.handlers.WriteListener;
|
||||
import org.mage.network.interfaces.MageClient;
|
||||
import org.mage.network.messages.ClientMessage;
|
||||
|
|
@ -26,7 +28,9 @@ import org.mage.network.messages.requests.ChatRoomIdRequest;
|
|||
import org.mage.network.messages.requests.CheatRequest;
|
||||
import org.mage.network.messages.requests.CreateTableRequest;
|
||||
import org.mage.network.messages.requests.CreateTournamentRequest;
|
||||
import org.mage.network.messages.requests.GetCardInfoRequest;
|
||||
import org.mage.network.messages.requests.GetCardsRequest;
|
||||
import org.mage.network.messages.requests.GetExpansionInfoRequest;
|
||||
import org.mage.network.messages.requests.GetRoomRequest;
|
||||
import org.mage.network.messages.requests.GetTournamentChatIdRequest;
|
||||
import org.mage.network.messages.requests.GetTournamentRequest;
|
||||
|
|
@ -68,7 +72,7 @@ import org.mage.network.messages.requests.WatchTournamentTableRequest;
|
|||
* @author BetaSteward
|
||||
*/
|
||||
public class ClientMessageHandler extends SimpleChannelInboundHandler<ClientMessage> {
|
||||
|
||||
|
||||
private final MageClient client;
|
||||
private ChannelHandlerContext ctx;
|
||||
private final BlockingQueue<Boolean> booleanQueue = new LinkedBlockingQueue<>();
|
||||
|
|
@ -78,8 +82,10 @@ public class ClientMessageHandler extends SimpleChannelInboundHandler<ClientMess
|
|||
private final BlockingQueue<TournamentView> tournamentViewQueue = new LinkedBlockingQueue<>();
|
||||
private final BlockingQueue<DraftPickView> draftPickViewQueue = new LinkedBlockingQueue<>();
|
||||
private final BlockingQueue<List<String>> stringListQueue = new LinkedBlockingQueue<>();
|
||||
private final BlockingQueue<List<CardInfo>> cardInfoListQueue = new LinkedBlockingQueue<>();
|
||||
private final BlockingQueue<List<ExpansionInfo>> expansionInfoListQueue = new LinkedBlockingQueue<>();
|
||||
|
||||
public ClientMessageHandler (MageClient client) {
|
||||
public ClientMessageHandler(MageClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
|
|
@ -87,13 +93,13 @@ public class ClientMessageHandler extends SimpleChannelInboundHandler<ClientMess
|
|||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
this.ctx = ctx;
|
||||
super.channelActive(ctx);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageReceived(ChannelHandlerContext ctx, ClientMessage msg) {
|
||||
msg.handleMessage(this);
|
||||
}
|
||||
|
||||
|
||||
public List<String> getServerMessages() throws Exception {
|
||||
stringListQueue.clear();
|
||||
ctx.writeAndFlush(new ServerMessagesRequest()).addListener(WriteListener.getInstance());
|
||||
|
|
@ -106,6 +112,18 @@ public class ClientMessageHandler extends SimpleChannelInboundHandler<ClientMess
|
|||
return stringListQueue.take();
|
||||
}
|
||||
|
||||
public List<CardInfo> getMissingCardsData(List<String> cards) throws Exception {
|
||||
cardInfoListQueue.clear();
|
||||
ctx.writeAndFlush(new GetCardInfoRequest(cards)).addListener(WriteListener.getInstance());
|
||||
return cardInfoListQueue.take();
|
||||
}
|
||||
|
||||
public List<ExpansionInfo> getMissingExpansionData(List<String> setCodes) throws Exception {
|
||||
expansionInfoListQueue.clear();
|
||||
ctx.writeAndFlush(new GetExpansionInfoRequest(setCodes)).addListener(WriteListener.getInstance());
|
||||
return expansionInfoListQueue.take();
|
||||
}
|
||||
|
||||
public UUID getChatRoomId(UUID roomId) throws Exception {
|
||||
uuidQueue.clear();
|
||||
ctx.writeAndFlush(new ChatRoomIdRequest(roomId)).addListener(WriteListener.getInstance());
|
||||
|
|
@ -129,13 +147,13 @@ public class ClientMessageHandler extends SimpleChannelInboundHandler<ClientMess
|
|||
ctx.writeAndFlush(new TableWaitingRequest(roomId, tableId)).addListener(WriteListener.getInstance());
|
||||
return tableViewQueue.take();
|
||||
}
|
||||
|
||||
|
||||
public boolean joinTable(UUID roomId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList, String password) throws Exception {
|
||||
booleanQueue.clear();
|
||||
ctx.writeAndFlush(new JoinTableRequest(roomId, tableId, name, playerType, skill, deckList, password)).addListener(WriteListener.getInstance());
|
||||
return booleanQueue.take();
|
||||
}
|
||||
|
||||
|
||||
public boolean joinTournamentTable(UUID roomId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList, String password) throws Exception {
|
||||
booleanQueue.clear();
|
||||
ctx.writeAndFlush(new JoinTournamentTableRequest(roomId, tableId, name, playerType, skill, deckList, password)).addListener(WriteListener.getInstance());
|
||||
|
|
@ -197,11 +215,11 @@ public class ClientMessageHandler extends SimpleChannelInboundHandler<ClientMess
|
|||
public void joinChat(UUID chatId) {
|
||||
ctx.writeAndFlush(new JoinChatRequest(chatId)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
|
||||
|
||||
public void leaveChat(UUID chatId) {
|
||||
ctx.writeAndFlush(new LeaveChatRequest(chatId)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
|
||||
|
||||
public void sendMessage(UUID chatId, String message) {
|
||||
ctx.writeAndFlush(new ChatMessageRequest(chatId, message)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
|
|
@ -213,11 +231,11 @@ public class ClientMessageHandler extends SimpleChannelInboundHandler<ClientMess
|
|||
public void swapSeats(UUID roomId, UUID tableId, int seatNum1, int seatNum2) throws Exception {
|
||||
ctx.writeAndFlush(new SwapSeatRequest(roomId, tableId, seatNum1, seatNum2)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
|
||||
|
||||
public MageClient getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
|
||||
public void receiveBoolean(boolean b) {
|
||||
booleanQueue.offer(b);
|
||||
}
|
||||
|
|
@ -233,12 +251,11 @@ public class ClientMessageHandler extends SimpleChannelInboundHandler<ClientMess
|
|||
public void receiveTableView(TableView view) {
|
||||
if (view == null) {
|
||||
tableViewQueue.offer(TableView.emptyTableView);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
tableViewQueue.offer(view);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void receiveTournamentView(TournamentView view) {
|
||||
tournamentViewQueue.offer(view);
|
||||
}
|
||||
|
|
@ -251,6 +268,14 @@ public class ClientMessageHandler extends SimpleChannelInboundHandler<ClientMess
|
|||
stringListQueue.offer(list);
|
||||
}
|
||||
|
||||
public void receiveCardInfoList(List<CardInfo> list) {
|
||||
cardInfoListQueue.offer(list);
|
||||
}
|
||||
|
||||
public void receiveExpansionInfoList(List<ExpansionInfo> list) {
|
||||
expansionInfoListQueue.offer(list);
|
||||
}
|
||||
|
||||
public void sendPlayerUUID(UUID gameId, UUID id) {
|
||||
ctx.writeAndFlush(new SendPlayerUUIDRequest(gameId, id)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
|
|
@ -275,8 +300,8 @@ public class ClientMessageHandler extends SimpleChannelInboundHandler<ClientMess
|
|||
ctx.writeAndFlush(new PlayerActionRequest(action, gameId, data)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
|
||||
public void setPreferences(UserDataView view) {
|
||||
ctx.writeAndFlush(new SetPreferencesRequest(view)).addListener(WriteListener.getInstance());
|
||||
public void setPreferences(UserData userData) {
|
||||
ctx.writeAndFlush(new SetPreferencesRequest(userData)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
|
||||
public TableView createTournamentTable(UUID roomId, TournamentOptions options) throws Exception {
|
||||
|
|
|
|||
|
|
@ -5,11 +5,14 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import mage.cards.repository.ExpansionInfo;
|
||||
import mage.constants.ManaType;
|
||||
import mage.constants.PlayerAction;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.interfaces.ServerState;
|
||||
import mage.players.net.UserData;
|
||||
import mage.remote.Connection;
|
||||
import mage.remote.DisconnectReason;
|
||||
import mage.utils.MageVersion;
|
||||
|
|
@ -17,69 +20,107 @@ import mage.view.DraftPickView;
|
|||
import mage.view.RoomView;
|
||||
import mage.view.TableView;
|
||||
import mage.view.TournamentView;
|
||||
import mage.view.UserDataView;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward
|
||||
*/
|
||||
public interface MageServer {
|
||||
|
||||
|
||||
boolean registerClient(Connection connection, String sessionId, MageVersion version, String host);
|
||||
|
||||
void disconnect(String sessionId, DisconnectReason reason);
|
||||
void setPreferences(String sessionId, UserDataView userDataView);
|
||||
|
||||
void setPreferences(String sessionId, UserData userData);
|
||||
|
||||
void sendFeedbackMessage(String sessionId, String title, String type, String message, String email);
|
||||
|
||||
void receiveChatMessage(UUID chatId, String sessionId, String message);
|
||||
|
||||
void joinChat(UUID chatId, String sessionId);
|
||||
|
||||
void leaveChat(UUID chatId, String sessionId);
|
||||
|
||||
UUID getRoomChatId(UUID roomId);
|
||||
|
||||
void receiveBroadcastMessage(String title, String message, String sessionId);
|
||||
|
||||
|
||||
ServerState getServerState();
|
||||
|
||||
List<String> getServerMessages();
|
||||
|
||||
List<String> getCards();
|
||||
|
||||
List<CardInfo> getMissingCardData(List<String> cards);
|
||||
|
||||
List<ExpansionInfo> getMissingExpansionData(List<String> setCodes);
|
||||
|
||||
RoomView getRoom(UUID roomId);
|
||||
|
||||
TableView createTable(String sessionId, UUID roomId, MatchOptions options);
|
||||
|
||||
boolean joinTable(String sessionId, UUID roomId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList, String password);
|
||||
|
||||
TableView getTable(UUID roomId, UUID tableId);
|
||||
|
||||
boolean leaveTable(String sessionId, UUID roomId, UUID tableId);
|
||||
|
||||
void removeTable(String sessionId, UUID roomId, UUID tableId);
|
||||
|
||||
void swapSeats(String sessionId, UUID roomId, UUID tableId, int seatNum1, int seatNum2);
|
||||
|
||||
boolean joinTournamentTable(String sessionId, UUID roomId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList, String password);
|
||||
|
||||
|
||||
boolean startMatch(String sessionId, UUID roomId, UUID tableId);
|
||||
|
||||
void quitMatch(UUID gameId, String sessionId);
|
||||
|
||||
UUID joinGame(UUID gameId, String sessionId);
|
||||
|
||||
void sendPlayerUUID(UUID gameId, String sessionId, UUID data);
|
||||
|
||||
void sendPlayerString(UUID gameId, String sessionId, String data);
|
||||
|
||||
void sendPlayerManaType(UUID gameId, UUID playerId, String sessionId, ManaType data);
|
||||
|
||||
void sendPlayerBoolean(UUID gameId, String sessionId, Boolean data);
|
||||
|
||||
void sendPlayerInteger(UUID gameId, String sessionId, Integer data);
|
||||
|
||||
void sendPlayerAction(PlayerAction playerAction, UUID gameId, String sessionId, Serializable data);
|
||||
|
||||
|
||||
boolean submitDeck(String sessionId, UUID tableId, DeckCardLists deckList);
|
||||
|
||||
void updateDeck(String sessionId, UUID tableId, DeckCardLists deckList);
|
||||
|
||||
|
||||
boolean joinDraft(UUID draftId, String sessionId);
|
||||
|
||||
void quitDraft(UUID draftId, String sessionId);
|
||||
|
||||
void markCard(UUID draftId, String sessionId, UUID cardPick);
|
||||
|
||||
DraftPickView pickCard(UUID draftId, String sessionId, UUID cardPick, Set<UUID> hiddenCards);
|
||||
|
||||
TableView createTournamentTable(String sessionId, UUID roomId, TournamentOptions options);
|
||||
|
||||
boolean startTournament(String sessionId, UUID roomId, UUID tableId);
|
||||
|
||||
UUID getTournamentChatId(UUID tournamentId);
|
||||
|
||||
TournamentView getTournament(UUID tournamentId);
|
||||
|
||||
boolean joinTournament(UUID tournamentId, String sessionId);
|
||||
|
||||
void quitTournament(UUID tournamentId, String sessionId);
|
||||
|
||||
void watchTable(String sessionId, UUID roomId, UUID tableId);
|
||||
|
||||
void watchTournamentTable(String sessionId, UUID tableId);
|
||||
|
||||
void stopWatching(UUID gameId, String sessionId);
|
||||
|
||||
|
||||
void pingTime(long milliSeconds, String sessionId);
|
||||
|
||||
|
||||
void cheat(UUID gameId, String sessionId, UUID playerId, DeckCardLists deckList);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@ import org.mage.network.messages.responses.UUIDResponse;
|
|||
* @author BetaSteward
|
||||
*/
|
||||
public class ChatRoomIdRequest extends ServerRequest {
|
||||
|
||||
private UUID roomId;
|
||||
|
||||
|
||||
private final UUID roomId;
|
||||
|
||||
public ChatRoomIdRequest(UUID roomId) {
|
||||
this.roomId = roomId;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.mage.network.messages.requests;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.util.List;
|
||||
import org.mage.network.handlers.WriteListener;
|
||||
import org.mage.network.interfaces.MageServer;
|
||||
import org.mage.network.messages.responses.GetCardInfoResponse;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class GetCardInfoRequest extends ServerRequest {
|
||||
|
||||
List<String> cards;
|
||||
|
||||
public GetCardInfoRequest(List<String> cards) {
|
||||
this.cards = cards;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(MageServer server, ChannelHandlerContext ctx) {
|
||||
ctx.writeAndFlush(new GetCardInfoResponse(server.getMissingCardData(cards))).addListener(WriteListener.getInstance());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.mage.network.messages.requests;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.util.List;
|
||||
import org.mage.network.handlers.WriteListener;
|
||||
import org.mage.network.interfaces.MageServer;
|
||||
import org.mage.network.messages.responses.GetExpansionInfoResponse;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class GetExpansionInfoRequest extends ServerRequest {
|
||||
|
||||
List<String> setCodes;
|
||||
|
||||
public GetExpansionInfoRequest(List<String> setCodes) {
|
||||
this.setCodes = setCodes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(MageServer server, ChannelHandlerContext ctx) {
|
||||
ctx.writeAndFlush(new GetExpansionInfoResponse(server.getMissingExpansionData(setCodes))).addListener(WriteListener.getInstance());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package org.mage.network.messages.requests;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import mage.view.UserDataView;
|
||||
import mage.players.net.UserData;
|
||||
import org.mage.network.interfaces.MageServer;
|
||||
|
||||
/**
|
||||
|
|
@ -9,15 +9,16 @@ import org.mage.network.interfaces.MageServer;
|
|||
* @author BetaSteward
|
||||
*/
|
||||
public class SetPreferencesRequest extends ServerRequest {
|
||||
private final UserDataView view;
|
||||
|
||||
public SetPreferencesRequest(UserDataView view) {
|
||||
this.view = view;
|
||||
private final UserData userData;
|
||||
|
||||
public SetPreferencesRequest(UserData userData) {
|
||||
this.userData = userData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(MageServer server, ChannelHandlerContext ctx) {
|
||||
server.setPreferences(getSessionId(ctx), view);
|
||||
server.setPreferences(getSessionId(ctx), userData);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.mage.network.messages.responses;
|
||||
|
||||
import java.util.List;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import org.mage.network.handlers.client.ClientMessageHandler;
|
||||
import org.mage.network.messages.ClientMessage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class GetCardInfoResponse extends ClientMessage {
|
||||
|
||||
private final List<CardInfo> cardInfo;
|
||||
|
||||
public GetCardInfoResponse(List<CardInfo> cardInfo) {
|
||||
this.cardInfo = cardInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(ClientMessageHandler handler) {
|
||||
handler.receiveCardInfoList(cardInfo);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -9,16 +9,16 @@ import org.mage.network.messages.ClientMessage;
|
|||
* @author BetaSteward
|
||||
*/
|
||||
public class GetCardsResponse extends ClientMessage {
|
||||
|
||||
private List<String> cards;
|
||||
|
||||
|
||||
private final List<String> cards;
|
||||
|
||||
public GetCardsResponse(List<String> cards) {
|
||||
this.cards = cards;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleMessage(ClientMessageHandler handler) {
|
||||
handler.receiveStringList(cards);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.mage.network.messages.responses;
|
||||
|
||||
import java.util.List;
|
||||
import mage.cards.repository.ExpansionInfo;
|
||||
import org.mage.network.handlers.client.ClientMessageHandler;
|
||||
import org.mage.network.messages.ClientMessage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class GetExpansionInfoResponse extends ClientMessage {
|
||||
|
||||
private final List<ExpansionInfo> expansionInfo;
|
||||
|
||||
public GetExpansionInfoResponse(List<ExpansionInfo> expansionInfo) {
|
||||
this.expansionInfo = expansionInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(ClientMessageHandler handler) {
|
||||
handler.receiveExpansionInfoList(expansionInfo);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ import mage.cards.decks.DeckCardLists;
|
|||
import mage.choices.Choice;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.interfaces.ServerState;
|
||||
import mage.players.net.UserData;
|
||||
import mage.players.net.UserGroup;
|
||||
import mage.players.net.UserSkipPrioritySteps;
|
||||
import mage.remote.Connection;
|
||||
|
|
@ -24,7 +25,6 @@ import mage.view.GameEndView;
|
|||
import mage.view.GameView;
|
||||
import mage.view.RoomView;
|
||||
import mage.view.TableView;
|
||||
import mage.view.UserDataView;
|
||||
import mage.view.UserRequestMessage;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.mage.network.Client;
|
||||
|
|
@ -38,16 +38,16 @@ import org.mage.network.messages.MessageType;
|
|||
public class TestClient implements MageClient {
|
||||
|
||||
protected static final Logger logger = Logger.getLogger(TestClient.class);
|
||||
|
||||
|
||||
private Client client;
|
||||
private ServerState serverState;
|
||||
private String userName;
|
||||
private boolean joinedTableFired = false;
|
||||
|
||||
|
||||
public TestClient() {
|
||||
client = new Client(this);
|
||||
}
|
||||
|
||||
|
||||
public boolean connect(String userName) {
|
||||
this.userName = userName;
|
||||
Connection connection = new Connection();
|
||||
|
|
@ -56,18 +56,18 @@ public class TestClient implements MageClient {
|
|||
connection.setSSL(true);
|
||||
connection.setUsername(userName);
|
||||
connection.setForceDBComparison(false);
|
||||
connection.setUserData(new UserDataView(UserGroup.PLAYER, 51, false, false, false, new UserSkipPrioritySteps(), "world", false, false, false, false, false, false));
|
||||
connection.setUserData(new UserData(UserGroup.PLAYER, 10, false, false, false, new UserSkipPrioritySteps(), "world", false, false, false, false, false, false));
|
||||
return client.connect(connection, MageVersion.getCurrent());
|
||||
}
|
||||
|
||||
|
||||
public void disconnect(boolean error) {
|
||||
client.disconnect(error);
|
||||
}
|
||||
|
||||
|
||||
public boolean isConnected() {
|
||||
return client.isConnected();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void connected(String message) {
|
||||
}
|
||||
|
|
@ -86,7 +86,7 @@ public class TestClient implements MageClient {
|
|||
UUID mainRoomId = client.getServerState().getMainRoomId();
|
||||
client.joinChat(client.getRoomChatId(mainRoomId));
|
||||
}
|
||||
|
||||
|
||||
public void sendChatMessage(UUID chatId, String message) {
|
||||
client.sendChatMessage(chatId, message);
|
||||
}
|
||||
|
|
@ -115,7 +115,7 @@ public class TestClient implements MageClient {
|
|||
public void joinedTable(UUID roomId, UUID tableId, UUID chatId, boolean owner, boolean tournament) {
|
||||
joinedTableFired = true;
|
||||
}
|
||||
|
||||
|
||||
public boolean isJoinedTableFired() {
|
||||
return joinedTableFired;
|
||||
}
|
||||
|
|
@ -188,19 +188,19 @@ public class TestClient implements MageClient {
|
|||
public List<String> getServerMessages() {
|
||||
return client.getServerMessages();
|
||||
}
|
||||
|
||||
|
||||
public UUID getMainRoomId() {
|
||||
return serverState.getMainRoomId();
|
||||
}
|
||||
|
||||
|
||||
public RoomView getRoom(UUID roomId) {
|
||||
return client.getRoom(roomId);
|
||||
}
|
||||
|
||||
|
||||
public TableView createTable(UUID roomId, MatchOptions options) {
|
||||
return client.createTable(roomId, options);
|
||||
}
|
||||
|
||||
|
||||
public boolean joinTable(UUID roomId, UUID tableId, String playerName, String playerType, int skill, DeckCardLists deck, String password) {
|
||||
return client.joinTable(roomId, tableId, playerName, playerType, skill, deck, password);
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -43,7 +43,6 @@ import mage.remote.Connection;
|
|||
import mage.remote.DisconnectReason;
|
||||
import mage.server.game.GamesRoomManager;
|
||||
import mage.server.util.ConfigSettings;
|
||||
import mage.view.UserDataView;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
|
|
@ -155,17 +154,9 @@ public class Session {
|
|||
this.userId = user.getId();
|
||||
}
|
||||
|
||||
public boolean setUserData(User user, UserDataView userDataView) {
|
||||
public boolean setUserData(User user, UserData userData) {
|
||||
if (user != null) {
|
||||
UserData userData = user.getUserData();
|
||||
if (user.getUserData() == null || user.getUserData().getGroupId() == UserGroup.DEFAULT.getGroupId()) {
|
||||
userData = new UserData(UserGroup.PLAYER, userDataView.getAvatarId(),
|
||||
userDataView.isShowAbilityPickerForced(), userDataView.isAllowRequestShowHandCards(),
|
||||
userDataView.confirmEmptyManaPool(), userDataView.getUserSkipPrioritySteps(),
|
||||
userDataView.getFlagName(), userDataView.askMoveToGraveOrder(),
|
||||
userDataView.isManaPoolAutomatic(), userDataView.isAllowRequestShowHandCards(),
|
||||
userDataView.isPassPriorityCast(), userDataView.isPassPriorityActivation(),
|
||||
userDataView.isAutoOrderTrigger());
|
||||
user.setUserData(userData);
|
||||
} else {
|
||||
user.getUserData().update(userData);
|
||||
|
|
|
|||
|
|
@ -27,14 +27,14 @@
|
|||
*/
|
||||
package mage.server;
|
||||
|
||||
import mage.remote.DisconnectReason;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import mage.players.net.UserData;
|
||||
import mage.remote.Connection;
|
||||
import mage.remote.DisconnectReason;
|
||||
import mage.server.services.LogKeys;
|
||||
import mage.server.services.impl.LogServiceImpl;
|
||||
import mage.view.UserDataView;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.mage.network.messages.MessageType;
|
||||
|
||||
|
|
@ -70,18 +70,18 @@ public class SessionManager {
|
|||
Session session = new Session(sessionId);
|
||||
sessions.put(sessionId, session);
|
||||
session.setHost(host);
|
||||
String returnMessage = session.registerUser(connection);
|
||||
if (returnMessage == null) {
|
||||
LogServiceImpl.instance.log(LogKeys.KEY_USER_CONNECTED, connection.getUsername(), session.getHost(), sessionId);
|
||||
String returnMessage = session.registerUser(connection);
|
||||
if (returnMessage == null) {
|
||||
LogServiceImpl.instance.log(LogKeys.KEY_USER_CONNECTED, connection.getUsername(), session.getHost(), sessionId);
|
||||
|
||||
logger.info(connection.getUsername() + " joined server");
|
||||
logger.debug("- userId: " + session.getUserId());
|
||||
logger.debug("- sessionId: " + sessionId);
|
||||
logger.debug("- host: " + session.getHost());
|
||||
return true;
|
||||
}
|
||||
logger.debug(connection.getUsername() + " not registered: " + returnMessage);
|
||||
ServerMain.getInstance().informClient(sessionId, "Connection Error", returnMessage, MessageType.ERROR);
|
||||
logger.info(connection.getUsername() + " joined server");
|
||||
logger.debug("- userId: " + session.getUserId());
|
||||
logger.debug("- sessionId: " + sessionId);
|
||||
logger.debug("- host: " + session.getHost());
|
||||
return true;
|
||||
}
|
||||
logger.debug(connection.getUsername() + " not registered: " + returnMessage);
|
||||
ServerMain.getInstance().informClient(sessionId, "Connection Error", returnMessage, MessageType.ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -96,10 +96,10 @@ public class SessionManager {
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean setUserData(String sessionId, UserDataView userDataView) {
|
||||
public boolean setUserData(String sessionId, UserData userData) {
|
||||
Session session = sessions.get(sessionId);
|
||||
if (session != null) {
|
||||
session.setUserData(UserManager.getInstance().getUser(session.getUserId()), userDataView);
|
||||
session.setUserData(UserManager.getInstance().getUser(session.getUserId()), userData);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -1,329 +1,327 @@
|
|||
/*
|
||||
* 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.cards.repository;
|
||||
|
||||
import com.j256.ormlite.field.DataType;
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Rarity;
|
||||
import mage.ObjectColor;
|
||||
import mage.abilities.SpellAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.mock.MockCard;
|
||||
import mage.cards.mock.MockSplitCard;
|
||||
import mage.constants.SpellAbilityType;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author North
|
||||
*/
|
||||
@DatabaseTable(tableName = "card")
|
||||
public class CardInfo {
|
||||
|
||||
private static final int MAX_RULE_LENGTH = 700;
|
||||
|
||||
private static final String SEPARATOR = "@@@";
|
||||
@DatabaseField(indexName = "name_index")
|
||||
protected String name;
|
||||
@DatabaseField(indexName = "setCode_cardNumber_index")
|
||||
protected int cardNumber;
|
||||
@DatabaseField(indexName = "setCode_cardNumber_index")
|
||||
protected String setCode;
|
||||
@DatabaseField(unique = true, indexName = "className_index")
|
||||
protected String className;
|
||||
@DatabaseField
|
||||
protected String power;
|
||||
@DatabaseField
|
||||
protected String toughness;
|
||||
@DatabaseField
|
||||
protected int convertedManaCost;
|
||||
@DatabaseField(dataType = DataType.ENUM_STRING)
|
||||
protected Rarity rarity;
|
||||
@DatabaseField
|
||||
protected String types;
|
||||
@DatabaseField
|
||||
protected String subtypes;
|
||||
@DatabaseField
|
||||
protected String supertypes;
|
||||
@DatabaseField
|
||||
protected String manaCosts;
|
||||
@DatabaseField(dataType = DataType.STRING, width = MAX_RULE_LENGTH)
|
||||
protected String rules;
|
||||
@DatabaseField
|
||||
protected boolean black;
|
||||
@DatabaseField
|
||||
protected boolean blue;
|
||||
@DatabaseField
|
||||
protected boolean green;
|
||||
@DatabaseField
|
||||
protected boolean red;
|
||||
@DatabaseField
|
||||
protected boolean white;
|
||||
@DatabaseField
|
||||
protected boolean splitCard;
|
||||
@DatabaseField
|
||||
protected boolean splitCardHalf;
|
||||
@DatabaseField
|
||||
protected boolean flipCard;
|
||||
@DatabaseField
|
||||
protected boolean doubleFaced;
|
||||
@DatabaseField(indexName = "name_index")
|
||||
protected boolean nightCard;
|
||||
@DatabaseField
|
||||
protected String flipCardName;
|
||||
@DatabaseField
|
||||
protected String secondSideName;
|
||||
|
||||
public CardInfo() {
|
||||
}
|
||||
|
||||
public CardInfo(Card card) {
|
||||
this.name = card.getName();
|
||||
this.cardNumber = card.getCardNumber();
|
||||
this.setCode = card.getExpansionSetCode();
|
||||
this.className = card.getClass().getCanonicalName();
|
||||
this.power = card.getPower().toString();
|
||||
this.toughness = card.getToughness().toString();
|
||||
this.convertedManaCost = card.getManaCost().convertedManaCost();
|
||||
this.rarity = card.getRarity();
|
||||
this.splitCard = card.isSplitCard();
|
||||
|
||||
this.flipCard = card.isFlipCard();
|
||||
this.flipCardName = card.getFlipCardName();
|
||||
|
||||
this.doubleFaced = card.canTransform() && card.getSecondCardFace() != null;
|
||||
this.nightCard = card.isNightCard();
|
||||
Card secondSide = card.getSecondCardFace();
|
||||
if (secondSide != null) {
|
||||
this.secondSideName = secondSide.getName();
|
||||
}
|
||||
|
||||
this.blue = card.getColor(null).isBlue();
|
||||
this.black = card.getColor(null).isBlack();
|
||||
this.green = card.getColor(null).isGreen();
|
||||
this.red = card.getColor(null).isRed();
|
||||
this.white = card.getColor(null).isWhite();
|
||||
|
||||
this.setTypes(card.getCardType());
|
||||
this.setSubtypes(card.getSubtype());
|
||||
this.setSuperTypes(card.getSupertype());
|
||||
this.setManaCosts(card.getManaCost().getSymbols());
|
||||
|
||||
int length = 0;
|
||||
for (String rule :card.getRules()) {
|
||||
length += rule.length();
|
||||
}
|
||||
if (length > MAX_RULE_LENGTH) {
|
||||
length = 0;
|
||||
ArrayList<String> shortRules = new ArrayList<>();
|
||||
for (String rule :card.getRules()) {
|
||||
if (length + rule.length() + 3 <= MAX_RULE_LENGTH) {
|
||||
shortRules.add(rule);
|
||||
length += rule.length() + 3;
|
||||
} else {
|
||||
shortRules.add(rule.substring(0, MAX_RULE_LENGTH - (length + 3)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
Logger.getLogger(CardInfo.class).warn("Card rule text was cut - cardname: " + card.getName());
|
||||
this.setRules(shortRules);
|
||||
} else {
|
||||
this.setRules(card.getRules());
|
||||
}
|
||||
|
||||
SpellAbility spellAbility = card.getSpellAbility();
|
||||
if (spellAbility != null) {
|
||||
SpellAbilityType spellAbilityType = spellAbility.getSpellAbilityType();
|
||||
if (spellAbilityType == SpellAbilityType.SPLIT_LEFT || spellAbilityType == SpellAbilityType.SPLIT_RIGHT) {
|
||||
this.className = this.setCode + "." + this.name;
|
||||
this.splitCardHalf = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Card getCard() {
|
||||
return CardImpl.createCard(className);
|
||||
}
|
||||
|
||||
public Card getMockCard() {
|
||||
if (this.splitCard) {
|
||||
return new MockSplitCard(this);
|
||||
} else {
|
||||
return new MockCard(this);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean usesVariousArt() {
|
||||
return Character.isDigit(className.charAt(className.length() - 1));
|
||||
}
|
||||
|
||||
public ObjectColor getColor() {
|
||||
ObjectColor color = new ObjectColor();
|
||||
color.setBlack(black);
|
||||
color.setBlue(blue);
|
||||
color.setGreen(green);
|
||||
color.setRed(red);
|
||||
color.setWhite(white);
|
||||
return color;
|
||||
}
|
||||
|
||||
private String joinList(List<String> items) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Object item : items) {
|
||||
sb.append(item.toString()).append(SEPARATOR);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private List<String> parseList(String list) {
|
||||
if (list.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return Arrays.asList(list.split(SEPARATOR));
|
||||
}
|
||||
|
||||
public final List<CardType> getTypes() {
|
||||
ArrayList<CardType> list = new ArrayList<>();
|
||||
for (String type : this.types.split(SEPARATOR)) {
|
||||
try {
|
||||
list.add(CardType.valueOf(type));
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public final void setTypes(List<CardType> types) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (CardType item : types) {
|
||||
sb.append(item.name()).append(SEPARATOR);
|
||||
}
|
||||
this.types = sb.toString();
|
||||
}
|
||||
|
||||
public int getConvertedManaCost() {
|
||||
return convertedManaCost;
|
||||
}
|
||||
|
||||
public final List<String> getManaCosts() {
|
||||
return parseList(manaCosts);
|
||||
}
|
||||
|
||||
public final void setManaCosts(List<String> manaCosts) {
|
||||
this.manaCosts = joinList(manaCosts);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getPower() {
|
||||
return power;
|
||||
}
|
||||
|
||||
public Rarity getRarity() {
|
||||
return rarity;
|
||||
}
|
||||
|
||||
public final List<String> getRules() {
|
||||
return parseList(rules);
|
||||
}
|
||||
|
||||
public final void setRules(List<String> rules) {
|
||||
this.rules = joinList(rules);
|
||||
}
|
||||
|
||||
public final List<String> getSubTypes() {
|
||||
return parseList(subtypes);
|
||||
}
|
||||
|
||||
public final void setSubtypes(List<String> subtypes) {
|
||||
this.subtypes = joinList(subtypes);
|
||||
}
|
||||
|
||||
public final List<String> getSupertypes() {
|
||||
return parseList(supertypes);
|
||||
}
|
||||
|
||||
public final void setSuperTypes(List<String> superTypes) {
|
||||
this.supertypes = joinList(superTypes);
|
||||
}
|
||||
|
||||
public String getToughness() {
|
||||
return toughness;
|
||||
}
|
||||
|
||||
public String getSetCode() {
|
||||
return setCode;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
public int getCardNumber() {
|
||||
return cardNumber;
|
||||
}
|
||||
|
||||
public boolean isSplitCard() {
|
||||
return splitCard;
|
||||
}
|
||||
|
||||
public boolean isSplitCardHalf() {
|
||||
return splitCardHalf;
|
||||
}
|
||||
|
||||
public boolean isFlipCard() {
|
||||
return flipCard;
|
||||
}
|
||||
|
||||
public String getFlipCardName() {
|
||||
return flipCardName;
|
||||
}
|
||||
|
||||
public boolean isDoubleFaced() {
|
||||
return doubleFaced;
|
||||
}
|
||||
|
||||
public boolean isNightCard() {
|
||||
return nightCard;
|
||||
}
|
||||
|
||||
public String getSecondSideName() {
|
||||
return secondSideName;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.cards.repository;
|
||||
|
||||
import com.j256.ormlite.field.DataType;
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import mage.ObjectColor;
|
||||
import mage.abilities.SpellAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.mock.MockCard;
|
||||
import mage.cards.mock.MockSplitCard;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Rarity;
|
||||
import mage.constants.SpellAbilityType;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author North
|
||||
*/
|
||||
@DatabaseTable(tableName = "card")
|
||||
public class CardInfo implements Serializable {
|
||||
|
||||
private static final int MAX_RULE_LENGTH = 700;
|
||||
|
||||
private static final String SEPARATOR = "@@@";
|
||||
@DatabaseField(indexName = "name_index")
|
||||
protected String name;
|
||||
@DatabaseField(indexName = "setCode_cardNumber_index")
|
||||
protected int cardNumber;
|
||||
@DatabaseField(indexName = "setCode_cardNumber_index")
|
||||
protected String setCode;
|
||||
@DatabaseField(unique = true, indexName = "className_index")
|
||||
protected String className;
|
||||
@DatabaseField
|
||||
protected String power;
|
||||
@DatabaseField
|
||||
protected String toughness;
|
||||
@DatabaseField
|
||||
protected int convertedManaCost;
|
||||
@DatabaseField(dataType = DataType.ENUM_STRING)
|
||||
protected Rarity rarity;
|
||||
@DatabaseField
|
||||
protected String types;
|
||||
@DatabaseField
|
||||
protected String subtypes;
|
||||
@DatabaseField
|
||||
protected String supertypes;
|
||||
@DatabaseField
|
||||
protected String manaCosts;
|
||||
@DatabaseField(dataType = DataType.STRING, width = MAX_RULE_LENGTH)
|
||||
protected String rules;
|
||||
@DatabaseField
|
||||
protected boolean black;
|
||||
@DatabaseField
|
||||
protected boolean blue;
|
||||
@DatabaseField
|
||||
protected boolean green;
|
||||
@DatabaseField
|
||||
protected boolean red;
|
||||
@DatabaseField
|
||||
protected boolean white;
|
||||
@DatabaseField
|
||||
protected boolean splitCard;
|
||||
@DatabaseField
|
||||
protected boolean splitCardHalf;
|
||||
@DatabaseField
|
||||
protected boolean flipCard;
|
||||
@DatabaseField
|
||||
protected boolean doubleFaced;
|
||||
@DatabaseField(indexName = "name_index")
|
||||
protected boolean nightCard;
|
||||
@DatabaseField
|
||||
protected String flipCardName;
|
||||
@DatabaseField
|
||||
protected String secondSideName;
|
||||
|
||||
public CardInfo() {
|
||||
}
|
||||
|
||||
public CardInfo(Card card) {
|
||||
this.name = card.getName();
|
||||
this.cardNumber = card.getCardNumber();
|
||||
this.setCode = card.getExpansionSetCode();
|
||||
this.className = card.getClass().getCanonicalName();
|
||||
this.power = card.getPower().toString();
|
||||
this.toughness = card.getToughness().toString();
|
||||
this.convertedManaCost = card.getManaCost().convertedManaCost();
|
||||
this.rarity = card.getRarity();
|
||||
this.splitCard = card.isSplitCard();
|
||||
|
||||
this.flipCard = card.isFlipCard();
|
||||
this.flipCardName = card.getFlipCardName();
|
||||
|
||||
this.doubleFaced = card.canTransform() && card.getSecondCardFace() != null;
|
||||
this.nightCard = card.isNightCard();
|
||||
Card secondSide = card.getSecondCardFace();
|
||||
if (secondSide != null) {
|
||||
this.secondSideName = secondSide.getName();
|
||||
}
|
||||
|
||||
this.blue = card.getColor(null).isBlue();
|
||||
this.black = card.getColor(null).isBlack();
|
||||
this.green = card.getColor(null).isGreen();
|
||||
this.red = card.getColor(null).isRed();
|
||||
this.white = card.getColor(null).isWhite();
|
||||
|
||||
this.setTypes(card.getCardType());
|
||||
this.setSubtypes(card.getSubtype());
|
||||
this.setSuperTypes(card.getSupertype());
|
||||
this.setManaCosts(card.getManaCost().getSymbols());
|
||||
|
||||
int length = 0;
|
||||
for (String rule : card.getRules()) {
|
||||
length += rule.length();
|
||||
}
|
||||
if (length > MAX_RULE_LENGTH) {
|
||||
length = 0;
|
||||
ArrayList<String> shortRules = new ArrayList<>();
|
||||
for (String rule : card.getRules()) {
|
||||
if (length + rule.length() + 3 <= MAX_RULE_LENGTH) {
|
||||
shortRules.add(rule);
|
||||
length += rule.length() + 3;
|
||||
} else {
|
||||
shortRules.add(rule.substring(0, MAX_RULE_LENGTH - (length + 3)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
Logger.getLogger(CardInfo.class).warn("Card rule text was cut - cardname: " + card.getName());
|
||||
this.setRules(shortRules);
|
||||
} else {
|
||||
this.setRules(card.getRules());
|
||||
}
|
||||
|
||||
SpellAbility spellAbility = card.getSpellAbility();
|
||||
if (spellAbility != null) {
|
||||
SpellAbilityType spellAbilityType = spellAbility.getSpellAbilityType();
|
||||
if (spellAbilityType == SpellAbilityType.SPLIT_LEFT || spellAbilityType == SpellAbilityType.SPLIT_RIGHT) {
|
||||
this.className = this.setCode + "." + this.name;
|
||||
this.splitCardHalf = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Card getCard() {
|
||||
return CardImpl.createCard(className);
|
||||
}
|
||||
|
||||
public Card getMockCard() {
|
||||
if (this.splitCard) {
|
||||
return new MockSplitCard(this);
|
||||
} else {
|
||||
return new MockCard(this);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean usesVariousArt() {
|
||||
return Character.isDigit(className.charAt(className.length() - 1));
|
||||
}
|
||||
|
||||
public ObjectColor getColor() {
|
||||
ObjectColor color = new ObjectColor();
|
||||
color.setBlack(black);
|
||||
color.setBlue(blue);
|
||||
color.setGreen(green);
|
||||
color.setRed(red);
|
||||
color.setWhite(white);
|
||||
return color;
|
||||
}
|
||||
|
||||
private String joinList(List<String> items) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Object item : items) {
|
||||
sb.append(item.toString()).append(SEPARATOR);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private List<String> parseList(String list) {
|
||||
if (list.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return Arrays.asList(list.split(SEPARATOR));
|
||||
}
|
||||
|
||||
public final List<CardType> getTypes() {
|
||||
ArrayList<CardType> list = new ArrayList<>();
|
||||
for (String type : this.types.split(SEPARATOR)) {
|
||||
try {
|
||||
list.add(CardType.valueOf(type));
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public final void setTypes(List<CardType> types) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (CardType item : types) {
|
||||
sb.append(item.name()).append(SEPARATOR);
|
||||
}
|
||||
this.types = sb.toString();
|
||||
}
|
||||
|
||||
public int getConvertedManaCost() {
|
||||
return convertedManaCost;
|
||||
}
|
||||
|
||||
public final List<String> getManaCosts() {
|
||||
return parseList(manaCosts);
|
||||
}
|
||||
|
||||
public final void setManaCosts(List<String> manaCosts) {
|
||||
this.manaCosts = joinList(manaCosts);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getPower() {
|
||||
return power;
|
||||
}
|
||||
|
||||
public Rarity getRarity() {
|
||||
return rarity;
|
||||
}
|
||||
|
||||
public final List<String> getRules() {
|
||||
return parseList(rules);
|
||||
}
|
||||
|
||||
public final void setRules(List<String> rules) {
|
||||
this.rules = joinList(rules);
|
||||
}
|
||||
|
||||
public final List<String> getSubTypes() {
|
||||
return parseList(subtypes);
|
||||
}
|
||||
|
||||
public final void setSubtypes(List<String> subtypes) {
|
||||
this.subtypes = joinList(subtypes);
|
||||
}
|
||||
|
||||
public final List<String> getSupertypes() {
|
||||
return parseList(supertypes);
|
||||
}
|
||||
|
||||
public final void setSuperTypes(List<String> superTypes) {
|
||||
this.supertypes = joinList(superTypes);
|
||||
}
|
||||
|
||||
public String getToughness() {
|
||||
return toughness;
|
||||
}
|
||||
|
||||
public String getSetCode() {
|
||||
return setCode;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
public int getCardNumber() {
|
||||
return cardNumber;
|
||||
}
|
||||
|
||||
public boolean isSplitCard() {
|
||||
return splitCard;
|
||||
}
|
||||
|
||||
public boolean isSplitCardHalf() {
|
||||
return splitCardHalf;
|
||||
}
|
||||
|
||||
public boolean isFlipCard() {
|
||||
return flipCard;
|
||||
}
|
||||
|
||||
public String getFlipCardName() {
|
||||
return flipCardName;
|
||||
}
|
||||
|
||||
public boolean isDoubleFaced() {
|
||||
return doubleFaced;
|
||||
}
|
||||
|
||||
public boolean isNightCard() {
|
||||
return nightCard;
|
||||
}
|
||||
|
||||
public String getSecondSideName() {
|
||||
return secondSideName;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,78 +1,79 @@
|
|||
package mage.cards.repository;
|
||||
|
||||
import com.j256.ormlite.field.DataType;
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
import java.util.Date;
|
||||
import mage.cards.ExpansionSet;
|
||||
import mage.constants.SetType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author North
|
||||
*/
|
||||
@DatabaseTable(tableName = "expansion")
|
||||
public class ExpansionInfo {
|
||||
|
||||
@DatabaseField(unique = true)
|
||||
protected String name;
|
||||
@DatabaseField(unique = true)
|
||||
protected String code;
|
||||
@DatabaseField
|
||||
protected String blockName;
|
||||
@DatabaseField
|
||||
protected Date releaseDate;
|
||||
@DatabaseField(dataType = DataType.ENUM_STRING)
|
||||
protected SetType type;
|
||||
@DatabaseField
|
||||
protected boolean boosters;
|
||||
@DatabaseField
|
||||
protected boolean basicLands;
|
||||
|
||||
public ExpansionInfo() {
|
||||
}
|
||||
|
||||
public ExpansionInfo(ExpansionSet expansionSet) {
|
||||
this.name = expansionSet.getName();
|
||||
this.code = expansionSet.getCode();
|
||||
this.blockName = expansionSet.getBlockName();
|
||||
this.releaseDate = expansionSet.getReleaseDate();
|
||||
this.type = expansionSet.getSetType();
|
||||
this.boosters = expansionSet.hasBoosters();
|
||||
this.basicLands = expansionSet.hasBasicLands();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getBlockName() {
|
||||
return blockName;
|
||||
}
|
||||
|
||||
public Date getReleaseDate() {
|
||||
return releaseDate;
|
||||
}
|
||||
|
||||
public SetType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public boolean hasBoosters() {
|
||||
return boosters;
|
||||
}
|
||||
|
||||
public boolean hasBasicLands() {
|
||||
return basicLands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
package mage.cards.repository;
|
||||
|
||||
import com.j256.ormlite.field.DataType;
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import mage.cards.ExpansionSet;
|
||||
import mage.constants.SetType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author North
|
||||
*/
|
||||
@DatabaseTable(tableName = "expansion")
|
||||
public class ExpansionInfo implements Serializable {
|
||||
|
||||
@DatabaseField(unique = true)
|
||||
protected String name;
|
||||
@DatabaseField(unique = true)
|
||||
protected String code;
|
||||
@DatabaseField
|
||||
protected String blockName;
|
||||
@DatabaseField
|
||||
protected Date releaseDate;
|
||||
@DatabaseField(dataType = DataType.ENUM_STRING)
|
||||
protected SetType type;
|
||||
@DatabaseField
|
||||
protected boolean boosters;
|
||||
@DatabaseField
|
||||
protected boolean basicLands;
|
||||
|
||||
public ExpansionInfo() {
|
||||
}
|
||||
|
||||
public ExpansionInfo(ExpansionSet expansionSet) {
|
||||
this.name = expansionSet.getName();
|
||||
this.code = expansionSet.getCode();
|
||||
this.blockName = expansionSet.getBlockName();
|
||||
this.releaseDate = expansionSet.getReleaseDate();
|
||||
this.type = expansionSet.getSetType();
|
||||
this.boosters = expansionSet.hasBoosters();
|
||||
this.basicLands = expansionSet.hasBasicLands();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getBlockName() {
|
||||
return blockName;
|
||||
}
|
||||
|
||||
public Date getReleaseDate() {
|
||||
return releaseDate;
|
||||
}
|
||||
|
||||
public SetType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public boolean hasBoosters() {
|
||||
return boosters;
|
||||
}
|
||||
|
||||
public boolean hasBasicLands() {
|
||||
return basicLands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,186 +1,197 @@
|
|||
package mage.cards.repository;
|
||||
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.dao.DaoManager;
|
||||
import com.j256.ormlite.jdbc.JdbcConnectionSource;
|
||||
import com.j256.ormlite.stmt.QueryBuilder;
|
||||
import com.j256.ormlite.stmt.SelectArg;
|
||||
import com.j256.ormlite.support.ConnectionSource;
|
||||
import com.j256.ormlite.table.TableUtils;
|
||||
import java.io.File;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author North
|
||||
*/
|
||||
public enum ExpansionRepository {
|
||||
|
||||
instance;
|
||||
|
||||
private static final Logger logger = Logger.getLogger(ExpansionRepository.class);
|
||||
|
||||
private static final String JDBC_URL = "jdbc:h2:file:./db/cards.h2;AUTO_SERVER=TRUE";
|
||||
private static final String VERSION_ENTITY_NAME = "expansion";
|
||||
private static final long EXPANSION_DB_VERSION = 5;
|
||||
private static final long EXPANSION_CONTENT_VERSION = 9;
|
||||
|
||||
private Dao<ExpansionInfo, Object> expansionDao;
|
||||
|
||||
private ExpansionRepository() {
|
||||
File file = new File("db");
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
try {
|
||||
ConnectionSource connectionSource = new JdbcConnectionSource(JDBC_URL);
|
||||
boolean obsolete = RepositoryUtil.isDatabaseObsolete(connectionSource, VERSION_ENTITY_NAME, EXPANSION_DB_VERSION);
|
||||
|
||||
if (obsolete) {
|
||||
TableUtils.dropTable(connectionSource, ExpansionInfo.class, true);
|
||||
}
|
||||
|
||||
TableUtils.createTableIfNotExists(connectionSource, ExpansionInfo.class);
|
||||
expansionDao = DaoManager.createDao(connectionSource, ExpansionInfo.class);
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void add(ExpansionInfo expansion) {
|
||||
try {
|
||||
expansionDao.create(expansion);
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getSetCodes() {
|
||||
List<String> setCodes = new ArrayList<>();
|
||||
try {
|
||||
List<ExpansionInfo> expansions = expansionDao.queryForAll();
|
||||
for (ExpansionInfo expansion : expansions) {
|
||||
setCodes.add(expansion.getCode());
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
logger.error("Can't get the expansion set codes from database.", ex);
|
||||
return setCodes;
|
||||
}
|
||||
return setCodes;
|
||||
}
|
||||
|
||||
public ExpansionInfo[] getWithBoostersSortedByReleaseDate() {
|
||||
ExpansionInfo[] sets = new ExpansionInfo[0];
|
||||
try {
|
||||
QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
|
||||
qb.orderBy("releaseDate", false);
|
||||
qb.where().eq("boosters", new SelectArg(true));
|
||||
List<ExpansionInfo> expansions = expansionDao.query(qb.prepare());
|
||||
sets = expansions.toArray(new ExpansionInfo[0]);
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
return sets;
|
||||
}
|
||||
|
||||
public List<ExpansionInfo> getSetsWithBasicLandsByReleaseDate() {
|
||||
List<ExpansionInfo> sets = new LinkedList<>();
|
||||
try {
|
||||
QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
|
||||
qb.orderBy("releaseDate", false);
|
||||
qb.where().eq("basicLands", new SelectArg(true));
|
||||
sets = expansionDao.query(qb.prepare());
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
return sets;
|
||||
}
|
||||
|
||||
public List<ExpansionInfo> getSetsFromBlock(String blockName) {
|
||||
List<ExpansionInfo> sets = new LinkedList<>();
|
||||
try {
|
||||
QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
|
||||
qb.where().eq("blockName", new SelectArg(blockName));
|
||||
return expansionDao.query(qb.prepare());
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
return sets;
|
||||
}
|
||||
|
||||
public ExpansionInfo getSetByCode(String setCode) {
|
||||
ExpansionInfo set = null;
|
||||
try {
|
||||
QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
|
||||
qb.where().eq("code", new SelectArg(setCode));
|
||||
List<ExpansionInfo> expansions = expansionDao.query(qb.prepare());
|
||||
if (expansions.size() > 0) {
|
||||
set = expansions.get(0);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
public ExpansionInfo getSetByName(String setName) {
|
||||
ExpansionInfo set = null;
|
||||
try {
|
||||
QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
|
||||
qb.where().eq("name", new SelectArg(setName));
|
||||
List<ExpansionInfo> expansions = expansionDao.query(qb.prepare());
|
||||
if (expansions.size() > 0) {
|
||||
set = expansions.get(0);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
public List<ExpansionInfo> getAll() {
|
||||
try {
|
||||
QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
|
||||
qb.orderBy("releaseDate", true);
|
||||
return expansionDao.query(qb.prepare());
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public List<String> getAllSetNames() {
|
||||
try {
|
||||
QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
|
||||
qb.orderBy("releaseDate", true);
|
||||
List<ExpansionInfo> expansions = expansionDao.query(qb.prepare());
|
||||
List<String> setNames = new LinkedList<>();
|
||||
for (ExpansionInfo expansionInfo : expansions) {
|
||||
setNames.add(expansionInfo.getName());
|
||||
}
|
||||
return setNames;
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public long getContentVersionFromDB() {
|
||||
try {
|
||||
ConnectionSource connectionSource = new JdbcConnectionSource(JDBC_URL);
|
||||
return RepositoryUtil.getDatabaseVersion(connectionSource, VERSION_ENTITY_NAME + "Content");
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setContentVersion(long version) {
|
||||
try {
|
||||
ConnectionSource connectionSource = new JdbcConnectionSource(JDBC_URL);
|
||||
RepositoryUtil.updateVersion(connectionSource, VERSION_ENTITY_NAME + "Content", version);
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public long getContentVersionConstant() {
|
||||
return EXPANSION_CONTENT_VERSION;
|
||||
}
|
||||
}
|
||||
package mage.cards.repository;
|
||||
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.dao.DaoManager;
|
||||
import com.j256.ormlite.jdbc.JdbcConnectionSource;
|
||||
import com.j256.ormlite.stmt.QueryBuilder;
|
||||
import com.j256.ormlite.stmt.SelectArg;
|
||||
import com.j256.ormlite.support.ConnectionSource;
|
||||
import com.j256.ormlite.table.TableUtils;
|
||||
import java.io.File;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author North
|
||||
*/
|
||||
public enum ExpansionRepository {
|
||||
|
||||
instance;
|
||||
|
||||
private static final Logger logger = Logger.getLogger(ExpansionRepository.class);
|
||||
|
||||
private static final String JDBC_URL = "jdbc:h2:file:./db/cards.h2;AUTO_SERVER=TRUE";
|
||||
private static final String VERSION_ENTITY_NAME = "expansion";
|
||||
private static final long EXPANSION_DB_VERSION = 5;
|
||||
private static final long EXPANSION_CONTENT_VERSION = 9;
|
||||
|
||||
private Dao<ExpansionInfo, Object> expansionDao;
|
||||
|
||||
private ExpansionRepository() {
|
||||
File file = new File("db");
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
try {
|
||||
ConnectionSource connectionSource = new JdbcConnectionSource(JDBC_URL);
|
||||
boolean obsolete = RepositoryUtil.isDatabaseObsolete(connectionSource, VERSION_ENTITY_NAME, EXPANSION_DB_VERSION);
|
||||
|
||||
if (obsolete) {
|
||||
TableUtils.dropTable(connectionSource, ExpansionInfo.class, true);
|
||||
}
|
||||
|
||||
TableUtils.createTableIfNotExists(connectionSource, ExpansionInfo.class);
|
||||
expansionDao = DaoManager.createDao(connectionSource, ExpansionInfo.class);
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void add(ExpansionInfo expansion) {
|
||||
try {
|
||||
expansionDao.create(expansion);
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getSetCodes() {
|
||||
List<String> setCodes = new ArrayList<>();
|
||||
try {
|
||||
List<ExpansionInfo> expansions = expansionDao.queryForAll();
|
||||
for (ExpansionInfo expansion : expansions) {
|
||||
setCodes.add(expansion.getCode());
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
logger.error("Can't get the expansion set codes from database.", ex);
|
||||
return setCodes;
|
||||
}
|
||||
return setCodes;
|
||||
}
|
||||
|
||||
public ExpansionInfo[] getWithBoostersSortedByReleaseDate() {
|
||||
ExpansionInfo[] sets = new ExpansionInfo[0];
|
||||
try {
|
||||
QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
|
||||
qb.orderBy("releaseDate", false);
|
||||
qb.where().eq("boosters", new SelectArg(true));
|
||||
List<ExpansionInfo> expansions = expansionDao.query(qb.prepare());
|
||||
sets = expansions.toArray(new ExpansionInfo[0]);
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
return sets;
|
||||
}
|
||||
|
||||
public List<ExpansionInfo> getSetsWithBasicLandsByReleaseDate() {
|
||||
List<ExpansionInfo> sets = new LinkedList<>();
|
||||
try {
|
||||
QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
|
||||
qb.orderBy("releaseDate", false);
|
||||
qb.where().eq("basicLands", new SelectArg(true));
|
||||
sets = expansionDao.query(qb.prepare());
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
return sets;
|
||||
}
|
||||
|
||||
public List<ExpansionInfo> getSetsFromBlock(String blockName) {
|
||||
List<ExpansionInfo> sets = new LinkedList<>();
|
||||
try {
|
||||
QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
|
||||
qb.where().eq("blockName", new SelectArg(blockName));
|
||||
return expansionDao.query(qb.prepare());
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
return sets;
|
||||
}
|
||||
|
||||
public ExpansionInfo getSetByCode(String setCode) {
|
||||
ExpansionInfo set = null;
|
||||
try {
|
||||
QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
|
||||
qb.where().eq("code", new SelectArg(setCode));
|
||||
List<ExpansionInfo> expansions = expansionDao.query(qb.prepare());
|
||||
if (expansions.size() > 0) {
|
||||
set = expansions.get(0);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
public ExpansionInfo getSetByName(String setName) {
|
||||
ExpansionInfo set = null;
|
||||
try {
|
||||
QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
|
||||
qb.where().eq("name", new SelectArg(setName));
|
||||
List<ExpansionInfo> expansions = expansionDao.query(qb.prepare());
|
||||
if (expansions.size() > 0) {
|
||||
set = expansions.get(0);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
public List<ExpansionInfo> getAll() {
|
||||
try {
|
||||
QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
|
||||
qb.orderBy("releaseDate", true);
|
||||
return expansionDao.query(qb.prepare());
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public List<ExpansionInfo> getMissingExpansions(List<String> setCodes) {
|
||||
try {
|
||||
QueryBuilder<ExpansionInfo, Object> queryBuilder = expansionDao.queryBuilder();
|
||||
queryBuilder.where().not().in("code", setCodes);
|
||||
|
||||
return expansionDao.query(queryBuilder.prepare());
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public List<String> getAllSetNames() {
|
||||
try {
|
||||
QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
|
||||
qb.orderBy("releaseDate", true);
|
||||
List<ExpansionInfo> expansions = expansionDao.query(qb.prepare());
|
||||
List<String> setNames = new LinkedList<>();
|
||||
for (ExpansionInfo expansionInfo : expansions) {
|
||||
setNames.add(expansionInfo.getName());
|
||||
}
|
||||
return setNames;
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public long getContentVersionFromDB() {
|
||||
try {
|
||||
ConnectionSource connectionSource = new JdbcConnectionSource(JDBC_URL);
|
||||
return RepositoryUtil.getDatabaseVersion(connectionSource, VERSION_ENTITY_NAME + "Content");
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setContentVersion(long version) {
|
||||
try {
|
||||
ConnectionSource connectionSource = new JdbcConnectionSource(JDBC_URL);
|
||||
RepositoryUtil.updateVersion(connectionSource, VERSION_ENTITY_NAME + "Content", version);
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public long getContentVersionConstant() {
|
||||
return EXPANSION_CONTENT_VERSION;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue