mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
integrated jboss remoting
This commit is contained in:
parent
34cd3bbcdc
commit
05be0a14ed
36 changed files with 1356 additions and 2061 deletions
124
Mage.Common/src/mage/interfaces/MageServer.java
Normal file
124
Mage.Common/src/mage/interfaces/MageServer.java
Normal file
|
@ -0,0 +1,124 @@
|
|||
/*
|
||||
* 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.interfaces;
|
||||
|
||||
import mage.game.match.MatchOptions;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.MageException;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.game.GameException;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.utils.MageVersion;
|
||||
import mage.view.DraftPickView;
|
||||
import mage.view.TableView;
|
||||
import mage.view.GameView;
|
||||
import mage.view.TournamentView;
|
||||
import mage.view.UserView;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public interface MageServer {
|
||||
|
||||
public boolean registerClient(String userName, String sessionId, MageVersion version) throws MageException;
|
||||
public boolean registerAdmin(String password, String sessionId, MageVersion version) throws MageException;
|
||||
public void deregisterClient(String sessionId) throws MageException;
|
||||
|
||||
public ServerState getServerState() throws MageException;
|
||||
|
||||
//table methods
|
||||
public TableView createTable(String sessionId, UUID roomId, MatchOptions matchOptions) throws MageException;
|
||||
public TableView createTournamentTable(String sessionId, UUID roomId, TournamentOptions tournamentOptions) throws MageException;
|
||||
public boolean joinTable(String sessionId, UUID roomId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException, GameException;
|
||||
public boolean joinTournamentTable(String sessionId, UUID roomId, UUID tableId, String name, String playerType, int skill) throws MageException, GameException;
|
||||
public boolean submitDeck(String sessionId, UUID tableId, DeckCardLists deckList) throws MageException, GameException;
|
||||
public boolean watchTable(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
public void leaveTable(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
public void swapSeats(String sessionId, UUID roomId, UUID tableId, int seatNum1, int seatNum2) throws MageException;
|
||||
public void removeTable(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
public boolean isTableOwner(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
public TableView getTable(UUID roomId, UUID tableId) throws MageException;
|
||||
public List<TableView> getTables(UUID roomId) throws MageException;
|
||||
public List<String> getConnectedPlayers(UUID roomId) throws MageException;
|
||||
|
||||
//chat methods
|
||||
public void sendChatMessage(UUID chatId, String userName, String message) throws MageException;
|
||||
public void joinChat(UUID chatId, String sessionId, String userName) throws MageException;
|
||||
public void leaveChat(UUID chatId, String sessionId) throws MageException;
|
||||
public UUID getTableChatId(UUID tableId) throws MageException;
|
||||
public UUID getGameChatId(UUID gameId) throws MageException;
|
||||
public UUID getRoomChatId(UUID roomId) throws MageException;
|
||||
public UUID getTournamentChatId(UUID tournamentId) throws MageException;
|
||||
|
||||
//room methods
|
||||
public UUID getMainRoomId() throws MageException;
|
||||
|
||||
//game methods
|
||||
public void startMatch(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
public void joinGame(UUID gameId, String sessionId) throws MageException;
|
||||
public void watchGame(UUID gameId, String sessionId) throws MageException;
|
||||
public void stopWatching(UUID gameId, String sessionId) throws MageException;
|
||||
public void sendPlayerUUID(UUID gameId, String sessionId, UUID data) throws MageException;
|
||||
public void sendPlayerString(UUID gameId, String sessionId, String data) throws MageException;
|
||||
public void sendPlayerBoolean(UUID gameId, String sessionId, Boolean data) throws MageException;
|
||||
public void sendPlayerInteger(UUID gameId, String sessionId, Integer data) throws MageException;
|
||||
public void concedeGame(UUID gameId, String sessionId) throws MageException;
|
||||
|
||||
//tournament methods
|
||||
public void startTournament(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
public void joinTournament(UUID draftId, String sessionId) throws MageException;
|
||||
public TournamentView getTournament(UUID tournamentId) throws MageException;
|
||||
|
||||
//draft methods
|
||||
public void joinDraft(UUID draftId, String sessionId) throws MageException;
|
||||
public DraftPickView sendCardPick(UUID draftId, String sessionId, UUID cardId) throws MageException;
|
||||
|
||||
//challenge methods
|
||||
public void startChallenge(String sessionId, UUID roomId, UUID tableId, UUID challengeId) throws MageException;
|
||||
|
||||
//replay methods
|
||||
public void replayGame(UUID gameId, String sessionId) throws MageException;
|
||||
public void startReplay(UUID gameId, String sessionId) throws MageException;
|
||||
public void stopReplay(UUID gameId, String sessionId) throws MageException;
|
||||
public void nextPlay(UUID gameId, String sessionId) throws MageException;
|
||||
public void previousPlay(UUID gameId, String sessionId) throws MageException;
|
||||
|
||||
//test methods
|
||||
public void cheat(UUID gameId, String sessionId, UUID playerId, DeckCardLists deckList) throws MageException;
|
||||
public boolean cheat(UUID gameId, String sessionId, UUID playerId, String cardName) throws MageException;
|
||||
public GameView getGameView(UUID gameId, String sessionId, UUID playerId) throws MageException;
|
||||
|
||||
//admin methods
|
||||
public List<UserView> getUsers(String sessionId) throws MageException;
|
||||
public void disconnectUser(String sessionId, String userSessionId) throws MageException;
|
||||
public void removeTable(String sessionId, UUID tableId) throws MageException;
|
||||
|
||||
}
|
|
@ -1,129 +0,0 @@
|
|||
/*
|
||||
* 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.interfaces;
|
||||
|
||||
import mage.game.match.MatchOptions;
|
||||
import java.rmi.Remote;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.MageException;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.game.GameException;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.interfaces.callback.CallbackServer;
|
||||
import mage.utils.MageVersion;
|
||||
import mage.view.DraftPickView;
|
||||
import mage.view.TableView;
|
||||
import mage.view.GameView;
|
||||
import mage.view.TournamentView;
|
||||
import mage.view.UserView;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public interface Server extends Remote, CallbackServer {
|
||||
|
||||
public UUID registerClient(String userName, UUID clientId, MageVersion version) throws RemoteException, MageException;
|
||||
public UUID registerAdmin(String password, MageVersion version) throws RemoteException, MageException;
|
||||
public void deregisterClient(UUID sessionId) throws RemoteException, MageException;
|
||||
public void ack(String message, UUID sessionId) throws RemoteException, MageException;
|
||||
public boolean ping(UUID sessionId) throws RemoteException, MageException;
|
||||
|
||||
public ServerState getServerState() throws RemoteException, MageException;
|
||||
|
||||
//table methods
|
||||
public TableView createTable(UUID sessionId, UUID roomId, MatchOptions matchOptions) throws RemoteException, MageException;
|
||||
public TableView createTournamentTable(UUID sessionId, UUID roomId, TournamentOptions tournamentOptions) throws RemoteException, MageException;
|
||||
public boolean joinTable(UUID sessionId, UUID roomId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws RemoteException, MageException, GameException;
|
||||
public boolean joinTournamentTable(UUID sessionId, UUID roomId, UUID tableId, String name, String playerType, int skill) throws RemoteException, MageException, GameException;
|
||||
public boolean submitDeck(UUID sessionId, UUID tableId, DeckCardLists deckList) throws RemoteException, MageException, GameException;
|
||||
public boolean watchTable(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
|
||||
public void leaveTable(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
|
||||
public void swapSeats(UUID sessionId, UUID roomId, UUID tableId, int seatNum1, int seatNum2) throws RemoteException, MageException;
|
||||
public void removeTable(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
|
||||
public boolean isTableOwner(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
|
||||
public TableView getTable(UUID roomId, UUID tableId) throws RemoteException, MageException;
|
||||
public List<TableView> getTables(UUID roomId) throws RemoteException, MageException;
|
||||
public List<String> getConnectedPlayers(UUID roomId) throws RemoteException, MageException;
|
||||
|
||||
//chat methods
|
||||
public void sendChatMessage(UUID chatId, String userName, String message) throws RemoteException, MageException;
|
||||
public void joinChat(UUID chatId, UUID sessionId, String userName) throws RemoteException, MageException;
|
||||
public void leaveChat(UUID chatId, UUID sessionId) throws RemoteException, MageException;
|
||||
public UUID getTableChatId(UUID tableId) throws RemoteException, MageException;
|
||||
public UUID getGameChatId(UUID gameId) throws RemoteException, MageException;
|
||||
public UUID getRoomChatId(UUID roomId) throws RemoteException, MageException;
|
||||
public UUID getTournamentChatId(UUID tournamentId) throws RemoteException, MageException;
|
||||
|
||||
//room methods
|
||||
public UUID getMainRoomId() throws RemoteException, MageException;
|
||||
|
||||
//game methods
|
||||
public void startMatch(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
|
||||
public void joinGame(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
public void watchGame(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
public void stopWatching(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
public void sendPlayerUUID(UUID gameId, UUID sessionId, UUID data) throws RemoteException, MageException;
|
||||
public void sendPlayerString(UUID gameId, UUID sessionId, String data) throws RemoteException, MageException;
|
||||
public void sendPlayerBoolean(UUID gameId, UUID sessionId, Boolean data) throws RemoteException, MageException;
|
||||
public void sendPlayerInteger(UUID gameId, UUID sessionId, Integer data) throws RemoteException, MageException;
|
||||
public void concedeGame(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
|
||||
//tournament methods
|
||||
public void startTournament(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
|
||||
public void joinTournament(UUID draftId, UUID sessionId) throws RemoteException, MageException;
|
||||
public TournamentView getTournament(UUID tournamentId) throws RemoteException, MageException;
|
||||
|
||||
//draft methods
|
||||
public void joinDraft(UUID draftId, UUID sessionId) throws RemoteException, MageException;
|
||||
public DraftPickView sendCardPick(UUID draftId, UUID sessionId, UUID cardId) throws RemoteException, MageException;
|
||||
|
||||
//challenge methods
|
||||
public void startChallenge(UUID sessionId, UUID roomId, UUID tableId, UUID challengeId) throws RemoteException, MageException;
|
||||
|
||||
//replay methods
|
||||
public void replayGame(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
public void startReplay(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
public void stopReplay(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
public void nextPlay(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
public void previousPlay(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
|
||||
//test methods
|
||||
public void cheat(UUID gameId, UUID sessionId, UUID playerId, DeckCardLists deckList) throws RemoteException, MageException;
|
||||
public boolean cheat(UUID gameId, UUID sessionId, UUID playerId, String cardName) throws RemoteException, MageException;
|
||||
public GameView getGameView(UUID gameId, UUID sessionId, UUID playerId) throws RemoteException, MageException;
|
||||
|
||||
//admin methods
|
||||
public List<UserView> getUsers(UUID sessionId) throws RemoteException, MageException;
|
||||
public void disconnectUser(UUID sessionId, UUID userSessionId) throws RemoteException, MageException;
|
||||
public void removeTable(UUID sessionId, UUID tableId) throws RemoteException, MageException;
|
||||
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* 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.interfaces.callback;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class CallbackClientDaemon extends Thread {
|
||||
|
||||
private final static Logger logger = Logger.getLogger(CallbackClientDaemon.class);
|
||||
|
||||
private static ExecutorService callbackExecutor = Executors.newCachedThreadPool();
|
||||
private final CallbackClient client;
|
||||
private final CallbackServer server;
|
||||
private final UUID id;
|
||||
|
||||
public CallbackClientDaemon(UUID id, CallbackClient client, CallbackServer server) {
|
||||
this.client = client;
|
||||
this.server = server;
|
||||
this.id = id;
|
||||
setDaemon(true);
|
||||
start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
while(true) {
|
||||
final ClientCallback callback = server.callback(id);
|
||||
callbackExecutor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (callback != null) {
|
||||
client.processCallback(callback);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
logger.fatal("CallbackClientDaemon error ", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
} catch(Exception ex) {
|
||||
logger.fatal("CallbackClientDaemon error ", ex);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* 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.interfaces.callback;
|
||||
|
||||
import mage.MageException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class CallbackException extends MageException {
|
||||
|
||||
public CallbackException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public CallbackException(Throwable t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* 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.interfaces.callback;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public interface CallbackServer {
|
||||
|
||||
public ClientCallback callback(UUID clientId) throws RemoteException;
|
||||
|
||||
}
|
|
@ -1,110 +0,0 @@
|
|||
/*
|
||||
* 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.interfaces.callback;
|
||||
|
||||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class CallbackServerSession {
|
||||
|
||||
private final static Logger logger = Logger.getLogger(CallbackServerSession.class);
|
||||
|
||||
private final ClientCallback callback = new ClientCallback();
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
private final Condition waiting = lock.newCondition();
|
||||
private final Condition callbackCalled = lock.newCondition();
|
||||
private boolean waitingForCallback;
|
||||
private boolean threadAlive = true;
|
||||
|
||||
/**
|
||||
*
|
||||
* blocks the thread until a callback is requested
|
||||
*
|
||||
* @return ClientCallback - the callback requested
|
||||
*/
|
||||
public ClientCallback callback() throws InterruptedException {
|
||||
callback.clear();
|
||||
lock.lock();
|
||||
try {
|
||||
waitingForCallback = true;
|
||||
waiting.signal();
|
||||
while (callback.getMethod() == null && threadAlive) {
|
||||
logger.trace("waiting for callback");
|
||||
callbackCalled.await();
|
||||
}
|
||||
waitingForCallback = false;
|
||||
logger.trace("callback called:" + callback.getMethod());
|
||||
return callback;
|
||||
}
|
||||
finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* requests a callback
|
||||
*
|
||||
* @param call - the callback to request
|
||||
*/
|
||||
public void setCallback(ClientCallback call) throws InterruptedException {
|
||||
lock.lock();
|
||||
try {
|
||||
while (!waitingForCallback) {
|
||||
logger.trace("waiting for callback state to call:" + call.getMethod());
|
||||
waiting.await();
|
||||
}
|
||||
callback.setMethod(call.getMethod());
|
||||
callback.setData(call.getData());
|
||||
callback.setObjectId(call.getObjectId());
|
||||
callback.setMessageId(call.getMessageId());
|
||||
callbackCalled.signal();
|
||||
}
|
||||
finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
lock.lock();
|
||||
try {
|
||||
threadAlive = false;
|
||||
callbackCalled.signal();
|
||||
}
|
||||
finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -28,10 +28,6 @@
|
|||
|
||||
package mage.remote;
|
||||
|
||||
import java.rmi.registry.LocateRegistry;
|
||||
import java.rmi.registry.Registry;
|
||||
import mage.interfaces.Server;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
@ -48,16 +44,6 @@ public class Connection {
|
|||
private String proxyUsername;
|
||||
private String proxyPassword;
|
||||
|
||||
// protected Server getServer() {
|
||||
// Server server = null;
|
||||
// try {
|
||||
// Registry reg = LocateRegistry.getRegistry(host, port);
|
||||
// server = (Server) reg.lookup("mage-server");
|
||||
// }
|
||||
// catch (Exception ignored) {}
|
||||
// return server;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (host + Integer.toString(port) + proxyType.toString()).hashCode();
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -39,10 +39,10 @@ public class UserView implements Serializable {
|
|||
|
||||
private String userName;
|
||||
private String host;
|
||||
private UUID sessionId;
|
||||
private String sessionId;
|
||||
private Date timeConnected;
|
||||
|
||||
public UserView(String userName, String host, UUID sessionId, Date timeConnected) {
|
||||
public UserView(String userName, String host, String sessionId, Date timeConnected) {
|
||||
this.userName = userName;
|
||||
this.host = host;
|
||||
this.sessionId = sessionId;
|
||||
|
@ -57,7 +57,7 @@ public class UserView implements Serializable {
|
|||
return host;
|
||||
}
|
||||
|
||||
public UUID getSessionId() {
|
||||
public String getSessionId() {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.1" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
|
||||
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
|
||||
<Properties>
|
||||
<Property name="title" type="java.lang.String" value="Connect"/>
|
||||
</Properties>
|
||||
|
@ -27,38 +27,48 @@
|
|||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="btnConnect" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="btnCancel" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Component id="lblPort" alignment="1" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblServer" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblUserName" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="txtPort" min="-2" pref="71" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="131" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="txtPassword" alignment="0" pref="276" max="32767" attributes="0"/>
|
||||
<Component id="chkAutoConnect" alignment="0" pref="276" max="32767" attributes="0"/>
|
||||
<Component id="chkUseProxy" alignment="0" pref="276" max="32767" attributes="0"/>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="txtServer" pref="205" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
<Component id="lblPort" alignment="1" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblServer" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblUserName" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="txtPort" min="-2" pref="71" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="131" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="txtUserName" alignment="0" pref="382" max="32767" attributes="0"/>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="txtServer" pref="311" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="lblProxyType" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="chkAutoConnect" alignment="0" pref="406" max="32767" attributes="0"/>
|
||||
<Component id="cbProxyType" alignment="0" min="-2" pref="126" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="lblStatus" pref="294" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="btnConnect" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="btnCancel" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="pnlProxySettings" alignment="0" max="32767" attributes="0"/>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace min="-2" pref="6" max="-2" attributes="0"/>
|
||||
<Component id="lblPassword" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="txtPassword" pref="382" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="pnlProxy" alignment="1" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
|
@ -78,21 +88,30 @@
|
|||
</Group>
|
||||
<EmptySpace min="-2" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="txtPassword" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="txtUserName" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblUserName" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="txtPassword" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblPassword" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Component id="chkAutoConnect" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" max="-2" attributes="0"/>
|
||||
<Component id="chkUseProxy" min="-2" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="cbProxyType" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblProxyType" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="-2" max="-2" attributes="0"/>
|
||||
<Component id="pnlProxy" max="32767" attributes="0"/>
|
||||
<Component id="pnlProxySettings" max="32767" attributes="0"/>
|
||||
<EmptySpace min="-2" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="btnCancel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="btnConnect" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblStatus" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
|
@ -121,14 +140,14 @@
|
|||
<EventHandler event="keyTyped" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="keyTyped"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="txtPassword">
|
||||
<Component class="javax.swing.JTextField" name="txtUserName">
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lblUserName">
|
||||
<Properties>
|
||||
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
|
||||
<ComponentRef name="txtPassword"/>
|
||||
<ComponentRef name="txtUserName"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="Password:"/>
|
||||
<Property name="text" type="java.lang.String" value="User Name:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="btnConnect">
|
||||
|
@ -155,77 +174,6 @@
|
|||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkAutoConnectActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JCheckBox" name="chkUseProxy">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Use Proxy"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkUseProxyActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Container class="javax.swing.JPanel" name="pnlProxy">
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Component id="lblProxyPort" alignment="1" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblProxyServer" alignment="1" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="txtProxyPort" min="-2" pref="71" max="-2" attributes="0"/>
|
||||
<Component id="txtProxyServer" alignment="0" pref="260" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="-2" pref="30" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="lblProxyServer" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="txtProxyServer" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="lblProxyPort" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="txtProxyPort" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JLabel" name="lblProxyServer">
|
||||
<Properties>
|
||||
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
|
||||
<ComponentRef name="txtServer"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="Server:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="txtProxyServer">
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lblProxyPort">
|
||||
<Properties>
|
||||
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
|
||||
<ComponentRef name="txtPort"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="Port:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="txtProxyPort">
|
||||
<Events>
|
||||
<EventHandler event="keyTyped" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="txtProxyPortkeyTyped"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Component class="javax.swing.JButton" name="jButton1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Find..."/>
|
||||
|
@ -233,8 +181,189 @@
|
|||
<Property name="name" type="java.lang.String" value="findServerBtn" noResource="true"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="findPublicServerActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JComboBox" name="cbProxyType">
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cbProxyTypeActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lblProxyType">
|
||||
<Properties>
|
||||
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
|
||||
<ComponentRef name="cbProxyType"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="Proxy:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Container class="javax.swing.JPanel" name="pnlProxySettings">
|
||||
<Properties>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="org.netbeans.modules.form.compat2.border.EtchedBorderInfo">
|
||||
<EtchetBorder/>
|
||||
</Border>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[0, 0]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="pnlProxy" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="pnlProxyAuth" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="pnlProxy" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<Component id="pnlProxyAuth" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Container class="javax.swing.JPanel" name="pnlProxy">
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace pref="28" max="32767" attributes="0"/>
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Component id="lblProxyPort" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblProxyServer" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="txtProxyPort" min="-2" pref="71" max="-2" attributes="0"/>
|
||||
<Component id="txtProxyServer" pref="360" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="txtProxyServer" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblProxyServer" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="lblProxyPort" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="txtProxyPort" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JLabel" name="lblProxyServer">
|
||||
<Properties>
|
||||
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
|
||||
<ComponentRef name="txtProxyServer"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="Server:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="txtProxyServer">
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lblProxyPort">
|
||||
<Properties>
|
||||
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
|
||||
<ComponentRef name="txtProxyPort"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="Port:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="txtProxyPort">
|
||||
<Events>
|
||||
<EventHandler event="keyTyped" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="txtProxyPortkeyTyped"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Container class="javax.swing.JPanel" name="pnlProxyAuth">
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="lblProxyPassword" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblProxyUserName" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="1" max="-2" attributes="0">
|
||||
<Component id="txtPasswordField" max="32767" attributes="1"/>
|
||||
<Component id="txtProxyUserName" alignment="1" pref="358" max="32767" attributes="1"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="txtProxyUserName" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblProxyUserName" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace pref="8" max="32767" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="txtPasswordField" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblProxyPassword" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JLabel" name="lblProxyUserName">
|
||||
<Properties>
|
||||
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
|
||||
<ComponentRef name="txtProxyUserName"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="User Name:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="txtProxyUserName">
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lblProxyPassword">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Password:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JPasswordField" name="txtPasswordField">
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="txtPasswordFieldActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Component class="javax.swing.JLabel" name="lblPassword">
|
||||
<Properties>
|
||||
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
|
||||
<ComponentRef name="txtPassword"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="Password:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JPasswordField" name="txtPassword">
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lblStatus">
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
|
|
|
@ -39,10 +39,18 @@ import java.io.BufferedReader;
|
|||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingWorker;
|
||||
|
||||
import mage.remote.Connection;
|
||||
import mage.remote.Connection.ProxyType;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
@ -53,22 +61,27 @@ import org.apache.log4j.Logger;
|
|||
public class ConnectDialog extends JDialog {
|
||||
|
||||
private final static Logger logger = Logger.getLogger(ConnectDialog.class);
|
||||
|
||||
private ConsoleFrame console;
|
||||
private Connection connection;
|
||||
private ConnectTask task;
|
||||
|
||||
/** Creates new form ConnectDialog */
|
||||
public ConnectDialog() {
|
||||
initComponents();
|
||||
cbProxyType.setModel(new DefaultComboBoxModel(Connection.ProxyType.values()));
|
||||
}
|
||||
|
||||
public void showDialog(ConsoleFrame console) {
|
||||
this.console = console;
|
||||
this.txtServer.setText(ConsoleFrame.getPreferences().get("serverAddress", ""));
|
||||
this.txtPort.setText(ConsoleFrame.getPreferences().get("serverPort", ""));
|
||||
this.txtServer.setText(ConsoleFrame.getPreferences().get("serverAddress", "localhost"));
|
||||
this.txtPort.setText(ConsoleFrame.getPreferences().get("serverPort", Integer.toString(17171)));
|
||||
this.txtUserName.setText(ConsoleFrame.getPreferences().get("userName", ""));
|
||||
this.chkAutoConnect.setSelected(Boolean.parseBoolean(ConsoleFrame.getPreferences().get("autoConnect", "false")));
|
||||
this.txtProxyServer.setText(ConsoleFrame.getPreferences().get("proxyAddress", ""));
|
||||
this.txtProxyPort.setText(ConsoleFrame.getPreferences().get("proxyPort", ""));
|
||||
this.chkUseProxy.setSelected(Boolean.parseBoolean(ConsoleFrame.getPreferences().get("useProxy", "false")));
|
||||
this.txtProxyServer.setText(ConsoleFrame.getPreferences().get("proxyAddress", "localhost"));
|
||||
this.txtProxyPort.setText(ConsoleFrame.getPreferences().get("proxyPort", Integer.toString(17171)));
|
||||
this.cbProxyType.setSelectedItem(Connection.ProxyType.valueOf(ConsoleFrame.getPreferences().get("proxyType", "NONE").toUpperCase()));
|
||||
this.txtProxyUserName.setText(ConsoleFrame.getPreferences().get("proxyUsername", ""));
|
||||
this.txtPasswordField.setText(ConsoleFrame.getPreferences().get("proxyPassword", ""));
|
||||
this.showProxySettings();
|
||||
this.setModal(true);
|
||||
this.setLocation(50, 50);
|
||||
|
@ -76,24 +89,37 @@ public class ConnectDialog extends JDialog {
|
|||
}
|
||||
|
||||
private void showProxySettings() {
|
||||
if (chkUseProxy.isSelected()) {
|
||||
if (cbProxyType.getSelectedItem() == Connection.ProxyType.SOCKS) {
|
||||
this.pnlProxy.setVisible(true);
|
||||
this.pnlProxyAuth.setVisible(false);
|
||||
this.pnlProxySettings.setVisible(true);
|
||||
}
|
||||
else {
|
||||
else if (cbProxyType.getSelectedItem() == Connection.ProxyType.HTTP) {
|
||||
this.pnlProxy.setVisible(true);
|
||||
this.pnlProxyAuth.setVisible(true);
|
||||
this.pnlProxySettings.setVisible(true);
|
||||
}
|
||||
else if (cbProxyType.getSelectedItem() == Connection.ProxyType.NONE) {
|
||||
this.pnlProxy.setVisible(false);
|
||||
this.pnlProxyAuth.setVisible(false);
|
||||
this.pnlProxySettings.setVisible(false);
|
||||
}
|
||||
this.pack();
|
||||
// this.revalidate();
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
private void saveSettings() {
|
||||
ConsoleFrame.getPreferences().put("serverAddress", txtServer.getText());
|
||||
ConsoleFrame.getPreferences().put("serverPort", txtPort.getText());
|
||||
ConsoleFrame.getPreferences().put("userName", txtUserName.getText());
|
||||
ConsoleFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected()));
|
||||
ConsoleFrame.getPreferences().put("proxyAddress", txtProxyServer.getText());
|
||||
ConsoleFrame.getPreferences().put("proxyPort", txtProxyPort.getText());
|
||||
ConsoleFrame.getPreferences().put("useProxy", Boolean.toString(chkUseProxy.isSelected()));
|
||||
ConsoleFrame.getPreferences().put("proxyType", cbProxyType.getSelectedItem().toString());
|
||||
ConsoleFrame.getPreferences().put("proxyUsername", txtProxyUserName.getText());
|
||||
char[] input = txtPasswordField.getPassword();
|
||||
ConsoleFrame.getPreferences().put("proxyPassword", new String(input));
|
||||
Arrays.fill(input, '0');
|
||||
}
|
||||
|
||||
/** This method is called from within the constructor to
|
||||
|
@ -109,18 +135,28 @@ public class ConnectDialog extends JDialog {
|
|||
lblServer = new javax.swing.JLabel();
|
||||
lblPort = new javax.swing.JLabel();
|
||||
txtPort = new javax.swing.JTextField();
|
||||
txtPassword = new javax.swing.JTextField();
|
||||
txtUserName = new javax.swing.JTextField();
|
||||
lblUserName = new javax.swing.JLabel();
|
||||
btnConnect = new javax.swing.JButton();
|
||||
btnCancel = new javax.swing.JButton();
|
||||
chkAutoConnect = new javax.swing.JCheckBox();
|
||||
chkUseProxy = new javax.swing.JCheckBox();
|
||||
jButton1 = new javax.swing.JButton();
|
||||
cbProxyType = new javax.swing.JComboBox();
|
||||
lblProxyType = new javax.swing.JLabel();
|
||||
pnlProxySettings = new javax.swing.JPanel();
|
||||
pnlProxy = new javax.swing.JPanel();
|
||||
lblProxyServer = new javax.swing.JLabel();
|
||||
txtProxyServer = new javax.swing.JTextField();
|
||||
lblProxyPort = new javax.swing.JLabel();
|
||||
txtProxyPort = new javax.swing.JTextField();
|
||||
jButton1 = new javax.swing.JButton();
|
||||
pnlProxyAuth = new javax.swing.JPanel();
|
||||
lblProxyUserName = new javax.swing.JLabel();
|
||||
txtProxyUserName = new javax.swing.JTextField();
|
||||
lblProxyPassword = new javax.swing.JLabel();
|
||||
txtPasswordField = new javax.swing.JPasswordField();
|
||||
lblPassword = new javax.swing.JLabel();
|
||||
txtPassword = new javax.swing.JPasswordField();
|
||||
lblStatus = new javax.swing.JLabel();
|
||||
|
||||
setTitle("Connect");
|
||||
|
||||
|
@ -136,8 +172,8 @@ public class ConnectDialog extends JDialog {
|
|||
}
|
||||
});
|
||||
|
||||
lblUserName.setLabelFor(txtPassword);
|
||||
lblUserName.setText("Password:");
|
||||
lblUserName.setLabelFor(txtUserName);
|
||||
lblUserName.setText("User Name:");
|
||||
|
||||
btnConnect.setText("Connect");
|
||||
btnConnect.addActionListener(new java.awt.event.ActionListener() {
|
||||
|
@ -160,17 +196,31 @@ public class ConnectDialog extends JDialog {
|
|||
}
|
||||
});
|
||||
|
||||
chkUseProxy.setText("Use Proxy");
|
||||
chkUseProxy.addActionListener(new java.awt.event.ActionListener() {
|
||||
jButton1.setText("Find...");
|
||||
jButton1.setToolTipText("Find public server");
|
||||
jButton1.setName("findServerBtn"); // NOI18N
|
||||
jButton1.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
chkUseProxyActionPerformed(evt);
|
||||
findPublicServerActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
lblProxyServer.setLabelFor(txtServer);
|
||||
cbProxyType.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
cbProxyTypeActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
lblProxyType.setLabelFor(cbProxyType);
|
||||
lblProxyType.setText("Proxy:");
|
||||
|
||||
pnlProxySettings.setBorder(javax.swing.BorderFactory.createEtchedBorder());
|
||||
pnlProxySettings.setMinimumSize(new java.awt.Dimension(0, 0));
|
||||
|
||||
lblProxyServer.setLabelFor(txtProxyServer);
|
||||
lblProxyServer.setText("Server:");
|
||||
|
||||
lblProxyPort.setLabelFor(txtPort);
|
||||
lblProxyPort.setLabelFor(txtProxyPort);
|
||||
lblProxyPort.setText("Port:");
|
||||
|
||||
txtProxyPort.addKeyListener(new java.awt.event.KeyAdapter() {
|
||||
|
@ -184,22 +234,22 @@ public class ConnectDialog extends JDialog {
|
|||
pnlProxyLayout.setHorizontalGroup(
|
||||
pnlProxyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(pnlProxyLayout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addContainerGap(28, Short.MAX_VALUE)
|
||||
.addGroup(pnlProxyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(lblProxyPort)
|
||||
.addComponent(lblProxyServer))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(pnlProxyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(txtProxyPort, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(txtProxyServer, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE))
|
||||
.addGap(30, 30, 30))
|
||||
.addComponent(txtProxyServer, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE))
|
||||
.addContainerGap())
|
||||
);
|
||||
pnlProxyLayout.setVerticalGroup(
|
||||
pnlProxyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(pnlProxyLayout.createSequentialGroup()
|
||||
.addGroup(pnlProxyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblProxyServer)
|
||||
.addComponent(txtProxyServer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addComponent(txtProxyServer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(lblProxyServer))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(pnlProxyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblProxyPort)
|
||||
|
@ -207,15 +257,64 @@ public class ConnectDialog extends JDialog {
|
|||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
);
|
||||
|
||||
jButton1.setText("Find...");
|
||||
jButton1.setToolTipText("Find public server");
|
||||
jButton1.setName("findServerBtn"); // NOI18N
|
||||
jButton1.addActionListener(new java.awt.event.ActionListener() {
|
||||
lblProxyUserName.setLabelFor(txtProxyUserName);
|
||||
lblProxyUserName.setText("User Name:");
|
||||
|
||||
lblProxyPassword.setText("Password:");
|
||||
|
||||
txtPasswordField.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton1ActionPerformed(evt);
|
||||
txtPasswordFieldActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout pnlProxyAuthLayout = new javax.swing.GroupLayout(pnlProxyAuth);
|
||||
pnlProxyAuth.setLayout(pnlProxyAuthLayout);
|
||||
pnlProxyAuthLayout.setHorizontalGroup(
|
||||
pnlProxyAuthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlProxyAuthLayout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(pnlProxyAuthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(lblProxyPassword)
|
||||
.addComponent(lblProxyUserName))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(pnlProxyAuthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
|
||||
.addComponent(txtPasswordField)
|
||||
.addComponent(txtProxyUserName, javax.swing.GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE))
|
||||
.addContainerGap())
|
||||
);
|
||||
pnlProxyAuthLayout.setVerticalGroup(
|
||||
pnlProxyAuthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlProxyAuthLayout.createSequentialGroup()
|
||||
.addGroup(pnlProxyAuthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(txtProxyUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(lblProxyUserName))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
|
||||
.addGroup(pnlProxyAuthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(txtPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(lblProxyPassword))
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
javax.swing.GroupLayout pnlProxySettingsLayout = new javax.swing.GroupLayout(pnlProxySettings);
|
||||
pnlProxySettings.setLayout(pnlProxySettingsLayout);
|
||||
pnlProxySettingsLayout.setHorizontalGroup(
|
||||
pnlProxySettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(pnlProxy, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(pnlProxyAuth, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
);
|
||||
pnlProxySettingsLayout.setVerticalGroup(
|
||||
pnlProxySettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(pnlProxySettingsLayout.createSequentialGroup()
|
||||
.addComponent(pnlProxy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(pnlProxyAuth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
lblPassword.setLabelFor(txtPassword);
|
||||
lblPassword.setText("Password:");
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
|
@ -225,29 +324,38 @@ public class ConnectDialog extends JDialog {
|
|||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(lblPort)
|
||||
.addComponent(lblServer)
|
||||
.addComponent(lblUserName))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(btnConnect)
|
||||
.addComponent(txtPort, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(131, 131, 131))
|
||||
.addComponent(txtUserName, javax.swing.GroupLayout.DEFAULT_SIZE, 382, Short.MAX_VALUE)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(txtServer, javax.swing.GroupLayout.DEFAULT_SIZE, 311, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(btnCancel))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(lblPort)
|
||||
.addComponent(lblServer)
|
||||
.addComponent(lblUserName))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(txtPort, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(131, 131, 131))
|
||||
.addComponent(txtPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)
|
||||
.addComponent(chkAutoConnect, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)
|
||||
.addComponent(chkUseProxy, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(txtServer, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jButton1)))))
|
||||
.addContainerGap())
|
||||
.addComponent(pnlProxy, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
|
||||
.addComponent(jButton1))))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(lblProxyType)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(chkAutoConnect, javax.swing.GroupLayout.DEFAULT_SIZE, 406, Short.MAX_VALUE)
|
||||
.addComponent(cbProxyType, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(lblStatus, javax.swing.GroupLayout.DEFAULT_SIZE, 294, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(btnConnect)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(btnCancel))
|
||||
.addComponent(pnlProxySettings, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(6, 6, 6)
|
||||
.addComponent(lblPassword)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(txtPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 382, Short.MAX_VALUE)))
|
||||
.addContainerGap())
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
|
@ -263,18 +371,25 @@ public class ConnectDialog extends JDialog {
|
|||
.addComponent(lblPort))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(txtUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(lblUserName))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(lblPassword))
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(chkAutoConnect)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(chkUseProxy)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(cbProxyType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(lblProxyType))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(pnlProxy, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(pnlProxySettings, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(btnCancel)
|
||||
.addComponent(btnConnect))
|
||||
.addComponent(btnConnect)
|
||||
.addComponent(lblStatus))
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
|
@ -283,13 +398,16 @@ public class ConnectDialog extends JDialog {
|
|||
|
||||
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
|
||||
ConsoleFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected()));
|
||||
this.setVisible(false);
|
||||
if (task != null && !task.isDone())
|
||||
task.cancel(true);
|
||||
else
|
||||
this.setVisible(false);
|
||||
}//GEN-LAST:event_btnCancelActionPerformed
|
||||
|
||||
private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConnectActionPerformed
|
||||
|
||||
if (txtPassword.getText().isEmpty()) {
|
||||
JOptionPane.showMessageDialog(rootPane, "Please provide a password");
|
||||
if (txtUserName.getText().isEmpty()) {
|
||||
JOptionPane.showMessageDialog(rootPane, "Please provide a user name");
|
||||
return;
|
||||
}
|
||||
if (txtServer.getText().trim().isEmpty()) {
|
||||
|
@ -302,31 +420,72 @@ public class ConnectDialog extends JDialog {
|
|||
}
|
||||
if (Integer.valueOf(txtPort.getText()) < 1 || Integer.valueOf(txtPort.getText()) > 65535 ) {
|
||||
JOptionPane.showMessageDialog(rootPane, "Invalid port number");
|
||||
txtPort.setText(ConsoleFrame.getPreferences().get("serverPort", ""));
|
||||
txtPort.setText(ConsoleFrame.getPreferences().get("serverPort", Integer.toString(17171)));
|
||||
return;
|
||||
}
|
||||
|
||||
char[] input = new char[0];
|
||||
try {
|
||||
setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
||||
if (chkUseProxy.isSelected()) {
|
||||
if (console.connect(txtPassword.getText(), txtServer.getText().trim(), Integer.valueOf(txtPort.getText()), txtProxyServer.getText().trim(), Integer.valueOf(txtProxyPort.getText()))) {
|
||||
this.saveSettings();
|
||||
this.setVisible(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (console.connect(txtPassword.getText(), txtServer.getText().trim(), Integer.valueOf(txtPort.getText()))) {
|
||||
this.saveSettings();
|
||||
this.setVisible(false);
|
||||
}
|
||||
}
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
connection = new Connection();
|
||||
connection.setHost(this.txtServer.getText());
|
||||
connection.setPort(Integer.valueOf(this.txtPort.getText()));
|
||||
connection.setUsername(this.txtUserName.getText());
|
||||
connection.setProxyType((ProxyType) this.cbProxyType.getSelectedItem());
|
||||
connection.setProxyHost(this.txtProxyServer.getText());
|
||||
connection.setProxyPort(Integer.valueOf(this.txtProxyPort.getText()));
|
||||
connection.setProxyUsername(this.txtProxyUserName.getText());
|
||||
input = txtPasswordField.getPassword();
|
||||
connection.setProxyPassword(new String(input));
|
||||
logger.debug("connecting: " + connection.getProxyType() + " " + connection.getProxyHost() + " " + connection.getProxyPort());
|
||||
task = new ConnectTask();
|
||||
task.execute();
|
||||
}
|
||||
finally {
|
||||
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
Arrays.fill(input, '0');
|
||||
}
|
||||
|
||||
}//GEN-LAST:event_btnConnectActionPerformed
|
||||
|
||||
private class ConnectTask extends SwingWorker<Boolean, Void> {
|
||||
|
||||
private boolean result = false;
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground() throws Exception {
|
||||
lblStatus.setText("Connecting...");
|
||||
btnConnect.setEnabled(false);
|
||||
result = console.connect(connection);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done() {
|
||||
try {
|
||||
get();
|
||||
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
btnConnect.setEnabled(true);
|
||||
if (result) {
|
||||
lblStatus.setText("");
|
||||
connected();
|
||||
}
|
||||
else {
|
||||
lblStatus.setText("Could not connect");
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
logger.fatal("Update Players Task error", ex);
|
||||
} catch (ExecutionException ex) {
|
||||
logger.fatal("Update Players Task error", ex);
|
||||
} catch (CancellationException ex) {}
|
||||
}
|
||||
}
|
||||
|
||||
private void connected() {
|
||||
this.saveSettings();
|
||||
this.setVisible(false);
|
||||
}
|
||||
|
||||
|
||||
private void keyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_keyTyped
|
||||
char c = evt.getKeyChar();
|
||||
if (!Character.isDigit(c))
|
||||
|
@ -342,23 +501,19 @@ public class ConnectDialog extends JDialog {
|
|||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_txtProxyPortkeyTyped
|
||||
|
||||
private void chkUseProxyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkUseProxyActionPerformed
|
||||
this.showProxySettings();
|
||||
}//GEN-LAST:event_chkUseProxyActionPerformed
|
||||
|
||||
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
|
||||
private void findPublicServerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
|
||||
BufferedReader in = null;
|
||||
try {
|
||||
URL serverListURL = new URL("http://mage.googlecode.com/files/server-list.txt");
|
||||
in = new BufferedReader(new InputStreamReader(serverListURL.openStream()));
|
||||
|
||||
|
||||
List<String> servers = new ArrayList<String>();
|
||||
String inputLine;
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
System.out.println("Found server: "+inputLine);
|
||||
servers.add(inputLine);
|
||||
}
|
||||
|
||||
|
||||
if (servers.size() == 0) {
|
||||
JOptionPane.showMessageDialog(null, "Couldn't find any server.");
|
||||
return;
|
||||
|
@ -384,27 +539,44 @@ public class ConnectDialog extends JDialog {
|
|||
} finally {
|
||||
if (in != null) try { in.close(); } catch (Exception e) {}
|
||||
}
|
||||
}//GEN-LAST:event_jButton1ActionPerformed
|
||||
|
||||
}//GEN-LAST:event_jButton1ActionPerformed
|
||||
private void cbProxyTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbProxyTypeActionPerformed
|
||||
this.showProxySettings();
|
||||
}//GEN-LAST:event_cbProxyTypeActionPerformed
|
||||
|
||||
private void txtPasswordFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPasswordFieldActionPerformed
|
||||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_txtPasswordFieldActionPerformed
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton btnCancel;
|
||||
private javax.swing.JButton btnConnect;
|
||||
private javax.swing.JComboBox cbProxyType;
|
||||
private javax.swing.JCheckBox chkAutoConnect;
|
||||
private javax.swing.JCheckBox chkUseProxy;
|
||||
private javax.swing.JButton jButton1;
|
||||
private javax.swing.JLabel lblPassword;
|
||||
private javax.swing.JLabel lblPort;
|
||||
private javax.swing.JLabel lblProxyPassword;
|
||||
private javax.swing.JLabel lblProxyPort;
|
||||
private javax.swing.JLabel lblProxyServer;
|
||||
private javax.swing.JLabel lblProxyType;
|
||||
private javax.swing.JLabel lblProxyUserName;
|
||||
private javax.swing.JLabel lblServer;
|
||||
private javax.swing.JLabel lblStatus;
|
||||
private javax.swing.JLabel lblUserName;
|
||||
private javax.swing.JPanel pnlProxy;
|
||||
private javax.swing.JTextField txtPassword;
|
||||
private javax.swing.JPanel pnlProxyAuth;
|
||||
private javax.swing.JPanel pnlProxySettings;
|
||||
private javax.swing.JPasswordField txtPassword;
|
||||
private javax.swing.JPasswordField txtPasswordField;
|
||||
private javax.swing.JTextField txtPort;
|
||||
private javax.swing.JTextField txtProxyPort;
|
||||
private javax.swing.JTextField txtProxyServer;
|
||||
private javax.swing.JTextField txtProxyUserName;
|
||||
private javax.swing.JTextField txtServer;
|
||||
private javax.swing.JTextField txtUserName;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
}
|
||||
|
|
|
@ -34,11 +34,16 @@
|
|||
|
||||
package mage.server.console;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.prefs.Preferences;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
import mage.server.console.remote.Session;
|
||||
import mage.interfaces.MageClient;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.remote.Connection;
|
||||
import mage.remote.Session;
|
||||
import mage.utils.MageVersion;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
@ -46,7 +51,7 @@ import org.apache.log4j.Logger;
|
|||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class ConsoleFrame extends javax.swing.JFrame {
|
||||
public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
|
||||
|
||||
private final static Logger logger = Logger.getLogger(ConsoleFrame.class);
|
||||
|
||||
|
@ -66,7 +71,8 @@ public class ConsoleFrame extends javax.swing.JFrame {
|
|||
return prefs;
|
||||
}
|
||||
|
||||
public static MageVersion getVersion() {
|
||||
@Override
|
||||
public MageVersion getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
|
@ -82,16 +88,9 @@ public class ConsoleFrame extends javax.swing.JFrame {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean connect(String password, String serverName, int port) {
|
||||
if (session.connect(password, serverName, port)) {
|
||||
this.consolePanel1.start();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean connect(String password, String serverName, int port, String proxyServer, int proxyPort) {
|
||||
if (session.connect(password, serverName, port, proxyServer, proxyPort)) {
|
||||
public boolean connect(Connection connection) {
|
||||
if (session.connect(connection)) {
|
||||
|
||||
this.consolePanel1.start();
|
||||
return true;
|
||||
}
|
||||
|
@ -168,7 +167,7 @@ public class ConsoleFrame extends javax.swing.JFrame {
|
|||
if (session.isConnected()) {
|
||||
if (JOptionPane.showConfirmDialog(this, "Are you sure you want to disconnect?", "Confirm disconnect", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
||||
this.consolePanel1.stop();
|
||||
session.disconnect();
|
||||
session.disconnect(false);
|
||||
}
|
||||
} else {
|
||||
connectDialog.showDialog(this);
|
||||
|
@ -185,6 +184,10 @@ public class ConsoleFrame extends javax.swing.JFrame {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
private ConsoleFrame getFrame() {
|
||||
return this;
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton btnConnect;
|
||||
|
@ -193,4 +196,77 @@ public class ConsoleFrame extends javax.swing.JFrame {
|
|||
private javax.swing.JLabel lblStatus;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
@Override
|
||||
public UUID getId() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connected(final String message) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
setStatusText(message);
|
||||
enableButtons();
|
||||
}
|
||||
else {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setStatusText(message);
|
||||
enableButtons();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected() {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
setStatusText("Not connected");
|
||||
disableButtons();
|
||||
}
|
||||
else {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setStatusText("Not connected");
|
||||
disableButtons();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMessage(final String message) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
JOptionPane.showMessageDialog(this, message);
|
||||
}
|
||||
else {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
JOptionPane.showMessageDialog(getFrame(), message);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showError(final String message) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
else {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
JOptionPane.showMessageDialog(getFrame(), message, "Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCallback(ClientCallback callback) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ import java.util.List;
|
|||
import java.util.UUID;
|
||||
import javax.swing.SwingWorker;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import mage.server.console.remote.Session;
|
||||
import mage.remote.Session;
|
||||
import mage.view.TableView;
|
||||
import mage.view.UserView;
|
||||
|
||||
|
@ -239,7 +239,7 @@ public class ConsolePanel extends javax.swing.JPanel {
|
|||
|
||||
private void btnDisconnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDisconnectActionPerformed
|
||||
int row = this.tblUsers.getSelectedRow();
|
||||
ConsoleFrame.getSession().disconnectUser((UUID)tableUserModel.getValueAt(row, 3));
|
||||
ConsoleFrame.getSession().disconnectUser((String)tableUserModel.getValueAt(row, 3));
|
||||
}//GEN-LAST:event_btnDisconnectActionPerformed
|
||||
|
||||
private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed
|
||||
|
|
|
@ -1,732 +0,0 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.server.console.remote;
|
||||
|
||||
import java.rmi.NotBoundException;
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.registry.LocateRegistry;
|
||||
import java.rmi.registry.Registry;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.swing.JOptionPane;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.game.GameException;
|
||||
import mage.MageException;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.interfaces.Server;
|
||||
import mage.interfaces.ServerState;
|
||||
import mage.server.console.ConsoleFrame;
|
||||
import mage.view.DraftPickView;
|
||||
import mage.view.GameTypeView;
|
||||
import mage.view.TableView;
|
||||
import mage.view.TournamentTypeView;
|
||||
import mage.view.TournamentView;
|
||||
import mage.view.UserView;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class Session {
|
||||
|
||||
private final static Logger logger = Logger.getLogger(Session.class);
|
||||
private static ScheduledExecutorService sessionExecutor = Executors.newScheduledThreadPool(1);
|
||||
|
||||
private UUID sessionId;
|
||||
private Server server;
|
||||
private ConsoleFrame frame;
|
||||
private ServerState serverState;
|
||||
private ScheduledFuture<?> future;
|
||||
|
||||
public Session(ConsoleFrame frame) {
|
||||
this.frame = frame;
|
||||
}
|
||||
public synchronized boolean connect(String password, String serverName, int port) {
|
||||
return connect(password, serverName, port, "", 0);
|
||||
}
|
||||
|
||||
public synchronized boolean connect(String password, String serverName, int port, String proxyServer, int proxyPort) {
|
||||
if (isConnected()) {
|
||||
disconnect();
|
||||
}
|
||||
try {
|
||||
System.setSecurityManager(null);
|
||||
if (proxyServer.length() > 0) {
|
||||
System.setProperty("socksProxyHost", proxyServer);
|
||||
System.setProperty("socksProxyPort", Integer.toString(proxyPort));
|
||||
}
|
||||
else {
|
||||
System.clearProperty("socksProxyHost");
|
||||
System.clearProperty("socksProxyPort");
|
||||
}
|
||||
Registry reg = LocateRegistry.getRegistry(serverName, port);
|
||||
this.server = (Server) reg.lookup("mage-server");
|
||||
sessionId = server.registerAdmin(password, frame.getVersion());
|
||||
serverState = server.getServerState();
|
||||
future = sessionExecutor.scheduleWithFixedDelay(new ServerPinger(), 5, 5, TimeUnit.SECONDS);
|
||||
logger.info("Connected to RMI server at " + serverName + ":" + port);
|
||||
frame.setStatusText("Connected to " + serverName + ":" + port + " ");
|
||||
frame.enableButtons();
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
logger.fatal("Unable to connect to server - ", ex);
|
||||
disconnect();
|
||||
JOptionPane.showMessageDialog(frame, "Unable to connect to server. " + ex.getMessage());
|
||||
} catch (NotBoundException ex) {
|
||||
logger.fatal("Unable to connect to server - ", ex);
|
||||
} catch (Exception ex) {
|
||||
logger.fatal("Unable to connect to server - ", ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public synchronized void disconnect() {
|
||||
|
||||
if (isConnected()) {
|
||||
try {
|
||||
server.deregisterClient(sessionId);
|
||||
} catch (RemoteException ex) {
|
||||
logger.fatal("Error disconnecting ...", ex);
|
||||
} catch (MageException ex) {
|
||||
logger.fatal("Error disconnecting ...", ex);
|
||||
}
|
||||
removeServer();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeServer() {
|
||||
if (future != null && !future.isDone())
|
||||
future.cancel(true);
|
||||
server = null;
|
||||
frame.setStatusText("Not connected");
|
||||
frame.disableButtons();
|
||||
logger.info("Disconnected ... ");
|
||||
JOptionPane.showMessageDialog(frame, "Disconnected.", "Disconnected", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
// public void ack(int messageId) {
|
||||
// try {
|
||||
// server.ack(messageId, sessionId);
|
||||
// } catch (RemoteException ex) {
|
||||
// handleRemoteException(ex);
|
||||
// } catch (MageException ex) {
|
||||
// handleMageException(ex);
|
||||
// }
|
||||
// }
|
||||
|
||||
public boolean ping() {
|
||||
try {
|
||||
return server.ping(sessionId);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return server != null;
|
||||
}
|
||||
|
||||
public String[] getPlayerTypes() {
|
||||
return serverState.getPlayerTypes();
|
||||
}
|
||||
|
||||
public List<GameTypeView> getGameTypes() {
|
||||
return serverState.getGameTypes();
|
||||
}
|
||||
|
||||
public String[] getDeckTypes() {
|
||||
return serverState.getDeckTypes();
|
||||
}
|
||||
|
||||
public List<TournamentTypeView> getTournamentTypes() {
|
||||
return serverState.getTournamentTypes();
|
||||
}
|
||||
|
||||
public boolean isTestMode() {
|
||||
if (serverState != null)
|
||||
return serverState.isTestMode();
|
||||
return false;
|
||||
}
|
||||
|
||||
public UUID getMainRoomId() {
|
||||
try {
|
||||
return server.getMainRoomId();
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public UUID getRoomChatId(UUID roomId) {
|
||||
try {
|
||||
return server.getRoomChatId(roomId);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public UUID getTableChatId(UUID tableId) {
|
||||
try {
|
||||
return server.getTableChatId(tableId);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public UUID getGameChatId(UUID gameId) {
|
||||
try {
|
||||
return server.getGameChatId(gameId);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public TableView getTable(UUID roomId, UUID tableId) {
|
||||
try {
|
||||
return server.getTable(roomId, tableId);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean watchTable(UUID roomId, UUID tableId) {
|
||||
try {
|
||||
server.watchTable(sessionId, roomId, tableId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean joinTable(UUID roomId, UUID tableId, String playerName, String playerType, int skill, DeckCardLists deckList) {
|
||||
try {
|
||||
return server.joinTable(sessionId, roomId, tableId, playerName, playerType, skill, deckList);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (GameException ex) {
|
||||
handleGameException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean joinTournamentTable(UUID roomId, UUID tableId, String playerName, String playerType, int skill) {
|
||||
try {
|
||||
return server.joinTournamentTable(sessionId, roomId, tableId, playerName, playerType, skill);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (GameException ex) {
|
||||
handleGameException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Collection<TableView> getTables(UUID roomId) throws Exception {
|
||||
try {
|
||||
return server.getTables(roomId);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
throw new Exception();
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
public TournamentView getTournament(UUID tournamentId) throws Exception {
|
||||
try {
|
||||
return server.getTournament(tournamentId);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
throw new Exception();
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
public UUID getTournamentChatId(UUID tournamentId) {
|
||||
try {
|
||||
return server.getTournamentChatId(tournamentId);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean sendPlayerUUID(UUID gameId, UUID data) {
|
||||
try {
|
||||
server.sendPlayerUUID(gameId, sessionId, data);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean sendPlayerBoolean(UUID gameId, boolean data) {
|
||||
try {
|
||||
server.sendPlayerBoolean(gameId, sessionId, data);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean sendPlayerInteger(UUID gameId, int data) {
|
||||
try {
|
||||
server.sendPlayerInteger(gameId, sessionId, data);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean sendPlayerString(UUID gameId, String data) {
|
||||
try {
|
||||
server.sendPlayerString(gameId, sessionId, data);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public DraftPickView sendCardPick(UUID draftId, UUID cardId) {
|
||||
try {
|
||||
return server.sendCardPick(draftId, sessionId, cardId);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean leaveChat(UUID chatId) {
|
||||
try {
|
||||
server.leaveChat(chatId, sessionId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean sendChatMessage(UUID chatId, String message) {
|
||||
try {
|
||||
server.sendChatMessage(chatId, "", message);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean joinGame(UUID gameId) {
|
||||
try {
|
||||
server.joinGame(gameId, sessionId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean joinDraft(UUID draftId) {
|
||||
try {
|
||||
server.joinDraft(draftId, sessionId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean joinTournament(UUID tournamentId) {
|
||||
try {
|
||||
server.joinTournament(tournamentId, sessionId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean watchGame(UUID gameId) {
|
||||
try {
|
||||
server.watchGame(gameId, sessionId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean replayGame(UUID gameId) {
|
||||
try {
|
||||
server.replayGame(gameId, sessionId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public TableView createTable(UUID roomId, MatchOptions matchOptions) {
|
||||
try {
|
||||
return server.createTable(sessionId, roomId, matchOptions);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public TableView createTournamentTable(UUID roomId, TournamentOptions tournamentOptions) {
|
||||
try {
|
||||
return server.createTournamentTable(sessionId, roomId, tournamentOptions);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isTableOwner(UUID roomId, UUID tableId) {
|
||||
try {
|
||||
return server.isTableOwner(sessionId, roomId, tableId);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean removeTable(UUID tableId) {
|
||||
try {
|
||||
server.removeTable(sessionId, tableId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean swapSeats(UUID roomId, UUID tableId, int seatNum1, int seatNum2) {
|
||||
try {
|
||||
server.swapSeats(sessionId, roomId, tableId, seatNum1, seatNum2);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean leaveTable(UUID roomId, UUID tableId) {
|
||||
try {
|
||||
server.leaveTable(sessionId, roomId, tableId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean startGame(UUID roomId, UUID tableId) {
|
||||
try {
|
||||
server.startMatch(sessionId, roomId, tableId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean startTournament(UUID roomId, UUID tableId) {
|
||||
try {
|
||||
server.startTournament(sessionId, roomId, tableId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean startChallenge(UUID roomId, UUID tableId, UUID challengeId) {
|
||||
try {
|
||||
server.startChallenge(sessionId, roomId, tableId, challengeId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean submitDeck(UUID tableId, DeckCardLists deck) {
|
||||
try {
|
||||
return server.submitDeck(sessionId, tableId, deck);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (GameException ex) {
|
||||
handleGameException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean concedeGame(UUID gameId) {
|
||||
try {
|
||||
server.concedeGame(gameId, sessionId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean stopWatching(UUID gameId) {
|
||||
try {
|
||||
server.stopWatching(gameId, sessionId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean startReplay(UUID gameId) {
|
||||
try {
|
||||
server.startReplay(gameId, sessionId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean stopReplay(UUID gameId) {
|
||||
try {
|
||||
server.stopReplay(gameId, sessionId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean nextPlay(UUID gameId) {
|
||||
try {
|
||||
server.nextPlay(gameId, sessionId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean previousPlay(UUID gameId) {
|
||||
try {
|
||||
server.previousPlay(gameId, sessionId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean cheat(UUID gameId, UUID playerId, DeckCardLists deckList) {
|
||||
try {
|
||||
server.cheat(gameId, sessionId, playerId, deckList);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<UserView> getUsers() {
|
||||
try {
|
||||
return server.getUsers(sessionId);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean disconnectUser(UUID userSessionId) {
|
||||
try {
|
||||
server.disconnectUser(sessionId, userSessionId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void handleRemoteException(RemoteException ex) {
|
||||
logger.fatal("Communication error", ex);
|
||||
if (ex instanceof java.rmi.ConnectException) {
|
||||
server = null;
|
||||
frame.setStatusText("Not connected");
|
||||
frame.disableButtons();
|
||||
JOptionPane.showMessageDialog(frame, "Communication error - disconnecting.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
else
|
||||
JOptionPane.showMessageDialog(frame, "Communication error.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
private void handleMageException(MageException ex) {
|
||||
logger.fatal("Server error", ex);
|
||||
JOptionPane.showMessageDialog(frame, "Critical server error. Disconnecting", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
disconnect();
|
||||
frame.disableButtons();
|
||||
}
|
||||
|
||||
private void handleGameException(GameException ex) {
|
||||
logger.fatal("Game error", ex);
|
||||
JOptionPane.showMessageDialog(frame, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
|
||||
public Server getServerRef() {
|
||||
return server;
|
||||
}
|
||||
|
||||
class ServerPinger implements Runnable {
|
||||
|
||||
private int missed = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!ping()) {
|
||||
missed++;
|
||||
if (missed > 10) {
|
||||
logger.info("Connection to server timed out");
|
||||
removeServer();
|
||||
}
|
||||
}
|
||||
else {
|
||||
missed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -54,11 +54,11 @@ public class ChatManager {
|
|||
return chatSession.getChatId();
|
||||
}
|
||||
|
||||
public void joinChat(UUID chatId, UUID sessionId, String userName) {
|
||||
public void joinChat(UUID chatId, String sessionId, String userName) {
|
||||
chatSessions.get(chatId).join(userName, sessionId);
|
||||
}
|
||||
|
||||
public void leaveChat(UUID chatId, UUID sessionId) {
|
||||
public void leaveChat(UUID chatId, String sessionId) {
|
||||
chatSessions.get(chatId).kill(sessionId);
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ public class ChatManager {
|
|||
chatSessions.get(chatId).broadcast(userName, message, color);
|
||||
}
|
||||
|
||||
void removeSession(UUID sessionId) {
|
||||
void removeSession(String sessionId) {
|
||||
for (ChatSession chat: chatSessions.values()) {
|
||||
chat.kill(sessionId);
|
||||
}
|
||||
|
|
|
@ -34,8 +34,6 @@ import java.util.Calendar;
|
|||
import java.util.GregorianCalendar;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import mage.MageException;
|
||||
import mage.interfaces.callback.CallbackException;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.view.ChatMessage;
|
||||
import mage.view.ChatMessage.MessageColor;
|
||||
|
@ -48,7 +46,7 @@ import org.apache.log4j.Logger;
|
|||
public class ChatSession {
|
||||
|
||||
private final static Logger logger = Logger.getLogger(ChatSession.class);
|
||||
private ConcurrentHashMap<UUID, String> clients = new ConcurrentHashMap<UUID, String>();
|
||||
private ConcurrentHashMap<String, String> clients = new ConcurrentHashMap<String, String>();
|
||||
private UUID chatId;
|
||||
private DateFormat timeFormatter = SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT);
|
||||
|
||||
|
@ -58,13 +56,13 @@ public class ChatSession {
|
|||
chatId = UUID.randomUUID();
|
||||
}
|
||||
|
||||
public void join(String userName, UUID sessionId) {
|
||||
public void join(String userName, String sessionId) {
|
||||
clients.put(sessionId, userName);
|
||||
broadcast(userName, " has joined", MessageColor.BLACK);
|
||||
logger.info(userName + " joined chat " + chatId);
|
||||
}
|
||||
|
||||
public void kill(UUID sessionId) {
|
||||
public void kill(String sessionId) {
|
||||
if (clients.containsKey(sessionId)) {
|
||||
String userName = clients.get(sessionId);
|
||||
clients.remove(sessionId);
|
||||
|
@ -79,7 +77,7 @@ public class ChatSession {
|
|||
final String time = timeFormatter.format(cal.getTime());
|
||||
final String username = userName;
|
||||
logger.debug("Broadcasting '" + msg + "' for " + chatId);
|
||||
for (UUID sessionId: clients.keySet()) {
|
||||
for (String sessionId: clients.keySet()) {
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null)
|
||||
session.fireCallback(new ClientCallback("chatMessage", chatId, new ChatMessage(username, msg, time, color)));
|
||||
|
|
|
@ -28,12 +28,6 @@
|
|||
|
||||
package mage.server;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.registry.LocateRegistry;
|
||||
import java.rmi.registry.Registry;
|
||||
import java.rmi.server.ExportException;
|
||||
import java.rmi.server.RemoteServer;
|
||||
import java.rmi.server.UnicastRemoteObject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
@ -43,9 +37,9 @@ import mage.cards.decks.DeckCardLists;
|
|||
import mage.game.GameException;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.interfaces.Server;
|
||||
import mage.interfaces.MageServer;
|
||||
//import mage.interfaces.Server;
|
||||
import mage.interfaces.ServerState;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.server.game.DeckValidatorFactory;
|
||||
import mage.server.draft.DraftManager;
|
||||
import mage.server.game.GameFactory;
|
||||
|
@ -69,94 +63,48 @@ import org.apache.log4j.Logger;
|
|||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class ServerImpl extends RemoteServer implements Server {
|
||||
public class MageServerImpl implements MageServer {
|
||||
|
||||
private final static Logger logger = Logger.getLogger("Mage Server");
|
||||
private static ExecutorService rmiExecutor = ThreadExecutor.getInstance().getRMIExecutor();
|
||||
|
||||
private boolean testMode;
|
||||
private String password;
|
||||
private boolean testMode;
|
||||
|
||||
public MageServerImpl(String password, boolean testMode) {
|
||||
this.password = password;
|
||||
this.testMode = testMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerClient(String userName, String sessionId, MageVersion version) throws MageException {
|
||||
|
||||
public ServerImpl(int port, String name, boolean testMode, String password) {
|
||||
try {
|
||||
System.setSecurityManager(null);
|
||||
Registry reg = LocateRegistry.createRegistry(port);
|
||||
Server stub = (Server) UnicastRemoteObject.exportObject(this, port);
|
||||
reg.rebind(name, stub);
|
||||
this.testMode = testMode;
|
||||
this.password = password;
|
||||
logger.info("Started MAGE server - listening on port " + port);
|
||||
if (testMode)
|
||||
logger.info("MAGE server running in test mode");
|
||||
} catch (ExportException ex) {
|
||||
logger.fatal("ERROR: Unable to start Mage Server - another server is likely running");
|
||||
} catch (RemoteException ex) {
|
||||
logger.fatal("Failed to start RMI server at port " + port, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isTestMode() {
|
||||
return testMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientCallback callback(UUID sessionId) {
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session == null) {
|
||||
return null;
|
||||
}
|
||||
return session.callback();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ack(String message, UUID sessionId) throws RemoteException, MageException {
|
||||
SessionManager.getInstance().getSession(sessionId).ack(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ping(UUID sessionId) {
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null) {
|
||||
session.ping();
|
||||
return true;
|
||||
if (version.compareTo(Main.getVersion()) != 0)
|
||||
throw new MageException("Wrong client version " + version + ", expecting version " + Main.getVersion());
|
||||
return SessionManager.getInstance().registerUser(sessionId, userName);
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID registerClient(String userName, UUID clientId, MageVersion version) throws MageException, RemoteException {
|
||||
|
||||
UUID sessionId = null;
|
||||
try {
|
||||
if (version.compareTo(Main.getVersion()) != 0)
|
||||
throw new MageException("Wrong client version " + version + ", expecting version " + Main.getVersion());
|
||||
sessionId = SessionManager.getInstance().createSession(userName, getClientHost(), clientId);
|
||||
logger.info("User " + userName + " connected from " + getClientHost());
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return sessionId;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID registerAdmin(String password, MageVersion version) throws RemoteException, MageException {
|
||||
UUID sessionId = null;
|
||||
public boolean registerAdmin(String password, String sessionId, MageVersion version) throws MageException {
|
||||
try {
|
||||
if (version.compareTo(Main.getVersion()) != 0)
|
||||
throw new MageException("Wrong client version " + version + ", expecting version " + Main.getVersion());
|
||||
if (!password.equals(this.password))
|
||||
throw new MageException("Wrong password");
|
||||
sessionId = SessionManager.getInstance().createSession(getClientHost());
|
||||
logger.info("Admin connected from " + getClientHost());
|
||||
return SessionManager.getInstance().registerAdmin(sessionId);
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return sessionId;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableView createTable(UUID sessionId, UUID roomId, MatchOptions options) throws MageException {
|
||||
public TableView createTable(String sessionId, UUID roomId, MatchOptions options) throws MageException {
|
||||
try {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTable(sessionId, options);
|
||||
|
@ -171,7 +119,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TableView createTournamentTable(UUID sessionId, UUID roomId, TournamentOptions options) throws MageException {
|
||||
public TableView createTournamentTable(String sessionId, UUID roomId, TournamentOptions options) throws MageException {
|
||||
try {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTournamentTable(sessionId, options);
|
||||
|
@ -186,7 +134,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void removeTable(final UUID sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
public void removeTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
|
@ -205,7 +153,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean joinTable(UUID sessionId, UUID roomId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException, GameException {
|
||||
public boolean joinTable(String sessionId, UUID roomId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException, GameException {
|
||||
try {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTable(sessionId, tableId, name, playerType, skill, deckList);
|
||||
|
@ -222,7 +170,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean joinTournamentTable(UUID sessionId, UUID roomId, UUID tableId, String name, String playerType, int skill) throws MageException, GameException {
|
||||
public boolean joinTournamentTable(String sessionId, UUID roomId, UUID tableId, String name, String playerType, int skill) throws MageException, GameException {
|
||||
try {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTournamentTable(sessionId, tableId, name, playerType, skill);
|
||||
|
@ -239,7 +187,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean submitDeck(UUID sessionId, UUID tableId, DeckCardLists deckList) throws MageException, GameException {
|
||||
public boolean submitDeck(String sessionId, UUID tableId, DeckCardLists deckList) throws MageException, GameException {
|
||||
try {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
boolean ret = TableManager.getInstance().submitDeck(sessionId, tableId, deckList);
|
||||
|
@ -293,7 +241,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void deregisterClient(final UUID sessionId) throws MageException {
|
||||
public void deregisterClient(final String sessionId) throws MageException {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
new Runnable() {
|
||||
|
@ -314,7 +262,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void startMatch(final UUID sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
public void startMatch(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
|
@ -333,7 +281,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void startChallenge(final UUID sessionId, final UUID roomId, final UUID tableId, final UUID challengeId) throws RemoteException, MageException {
|
||||
public void startChallenge(final String sessionId, final UUID roomId, final UUID tableId, final UUID challengeId) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
|
@ -352,7 +300,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void startTournament(final UUID sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
public void startTournament(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
|
@ -371,7 +319,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TournamentView getTournament(UUID tournamentId) throws RemoteException, MageException {
|
||||
public TournamentView getTournament(UUID tournamentId) throws MageException {
|
||||
try {
|
||||
return TournamentManager.getInstance().getTournamentView(tournamentId);
|
||||
}
|
||||
|
@ -399,7 +347,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void joinChat(final UUID chatId, final UUID sessionId, final String userName) throws MageException {
|
||||
public void joinChat(final UUID chatId, final String sessionId, final String userName) throws MageException {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
new Runnable() {
|
||||
|
@ -416,7 +364,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void leaveChat(final UUID chatId, final UUID sessionId) throws MageException {
|
||||
public void leaveChat(final UUID chatId, final String sessionId) throws MageException {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
new Runnable() {
|
||||
|
@ -455,7 +403,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isTableOwner(UUID sessionId, UUID roomId, UUID tableId) throws MageException {
|
||||
public boolean isTableOwner(String sessionId, UUID roomId, UUID tableId) throws MageException {
|
||||
try {
|
||||
return TableManager.getInstance().isTableOwner(tableId, sessionId);
|
||||
}
|
||||
|
@ -466,7 +414,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void swapSeats(final UUID sessionId, final UUID roomId, final UUID tableId, final int seatNum1, final int seatNum2) throws RemoteException, MageException {
|
||||
public void swapSeats(final String sessionId, final UUID roomId, final UUID tableId, final int seatNum1, final int seatNum2) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
|
@ -485,7 +433,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void leaveTable(final UUID sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
public void leaveTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
|
@ -515,7 +463,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void joinGame(final UUID gameId, final UUID sessionId) throws MageException {
|
||||
public void joinGame(final UUID gameId, final String sessionId) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
|
@ -534,7 +482,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void joinDraft(final UUID draftId, final UUID sessionId) throws MageException {
|
||||
public void joinDraft(final UUID draftId, final String sessionId) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
|
@ -553,7 +501,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void joinTournament(final UUID tournamentId, final UUID sessionId) throws MageException {
|
||||
public void joinTournament(final UUID tournamentId, final String sessionId) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
|
@ -594,7 +542,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void sendPlayerUUID(final UUID gameId, final UUID sessionId, final UUID data) throws MageException {
|
||||
public void sendPlayerUUID(final UUID gameId, final String sessionId, final UUID data) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
|
@ -613,7 +561,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void sendPlayerString(final UUID gameId, final UUID sessionId, final String data) throws MageException {
|
||||
public void sendPlayerString(final UUID gameId, final String sessionId, final String data) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
|
@ -632,7 +580,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void sendPlayerBoolean(final UUID gameId, final UUID sessionId, final Boolean data) throws MageException {
|
||||
public void sendPlayerBoolean(final UUID gameId, final String sessionId, final Boolean data) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
|
@ -651,7 +599,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void sendPlayerInteger(final UUID gameId, final UUID sessionId, final Integer data) throws RemoteException, MageException {
|
||||
public void sendPlayerInteger(final UUID gameId, final String sessionId, final Integer data) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
|
@ -670,7 +618,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public DraftPickView sendCardPick(final UUID draftId, final UUID sessionId, final UUID cardPick) throws MageException {
|
||||
public DraftPickView sendCardPick(final UUID draftId, final String sessionId, final UUID cardPick) throws MageException {
|
||||
try {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
return DraftManager.getInstance().sendCardPick(draftId, sessionId, cardPick);
|
||||
|
@ -683,7 +631,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void concedeGame(final UUID gameId, final UUID sessionId) throws MageException {
|
||||
public void concedeGame(final UUID gameId, final String sessionId) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
|
@ -702,7 +650,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean watchTable(UUID sessionId, UUID roomId, UUID tableId) throws MageException {
|
||||
public boolean watchTable(String sessionId, UUID roomId, UUID tableId) throws MageException {
|
||||
try {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
return GamesRoomManager.getInstance().getRoom(roomId).watchTable(sessionId, tableId);
|
||||
|
@ -715,7 +663,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void watchGame(final UUID gameId, final UUID sessionId) throws MageException {
|
||||
public void watchGame(final UUID gameId, final String sessionId) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
|
@ -734,7 +682,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void stopWatching(final UUID gameId, final UUID sessionId) throws MageException {
|
||||
public void stopWatching(final UUID gameId, final String sessionId) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
|
@ -753,7 +701,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void replayGame(final UUID gameId, final UUID sessionId) throws MageException {
|
||||
public void replayGame(final UUID gameId, final String sessionId) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
|
@ -772,7 +720,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void startReplay(final UUID gameId, final UUID sessionId) throws MageException {
|
||||
public void startReplay(final UUID gameId, final String sessionId) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
|
@ -791,7 +739,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void stopReplay(final UUID gameId, final UUID sessionId) throws MageException {
|
||||
public void stopReplay(final UUID gameId, final String sessionId) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
|
@ -810,7 +758,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void nextPlay(final UUID gameId, final UUID sessionId) throws MageException {
|
||||
public void nextPlay(final UUID gameId, final String sessionId) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
|
@ -829,7 +777,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void previousPlay(final UUID gameId, final UUID sessionId) throws MageException {
|
||||
public void previousPlay(final UUID gameId, final String sessionId) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
|
@ -848,7 +796,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ServerState getServerState() throws RemoteException, MageException {
|
||||
public ServerState getServerState() throws MageException {
|
||||
try {
|
||||
return new ServerState(
|
||||
GameFactory.getInstance().getGameTypes(),
|
||||
|
@ -865,7 +813,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void cheat(final UUID gameId, final UUID sessionId, final UUID playerId, final DeckCardLists deckList) throws MageException {
|
||||
public void cheat(final UUID gameId, final String sessionId, final UUID playerId, final DeckCardLists deckList) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
|
@ -885,7 +833,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean cheat(final UUID gameId, final UUID sessionId, final UUID playerId, final String cardName) throws MageException {
|
||||
public boolean cheat(final UUID gameId, final String sessionId, final UUID playerId, final String cardName) throws MageException {
|
||||
if (testMode) {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
return GameManager.getInstance().cheat(gameId, sessionId, playerId, cardName);
|
||||
|
@ -900,7 +848,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public GameView getGameView(final UUID gameId, final UUID sessionId, final UUID playerId) {
|
||||
public GameView getGameView(final UUID gameId, final String sessionId, final UUID playerId) {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
return GameManager.getInstance().getGameView(gameId, sessionId, playerId);
|
||||
}
|
||||
|
@ -908,7 +856,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<UserView> getUsers(UUID sessionId) throws RemoteException, MageException {
|
||||
public List<UserView> getUsers(String sessionId) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
return SessionManager.getInstance().getUsers(sessionId);
|
||||
}
|
||||
|
@ -916,7 +864,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void disconnectUser(final UUID sessionId, final UUID userSessionId) throws RemoteException, MageException {
|
||||
public void disconnectUser(final String sessionId, final String userSessionId) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
|
@ -935,7 +883,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void removeTable(final UUID sessionId, final UUID tableId) throws RemoteException, MageException {
|
||||
public void removeTable(final String sessionId, final UUID tableId) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
rmiExecutor.execute(
|
|
@ -37,8 +37,11 @@ import java.net.InterfaceAddress;
|
|||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Map;
|
||||
import javax.management.MBeanServer;
|
||||
import mage.game.match.MatchType;
|
||||
import mage.game.tournament.TournamentType;
|
||||
import mage.interfaces.MageServer;
|
||||
import mage.server.game.DeckValidatorFactory;
|
||||
import mage.server.game.GameFactory;
|
||||
import mage.server.game.PlayerFactory;
|
||||
|
@ -46,9 +49,17 @@ import mage.server.tournament.TournamentFactory;
|
|||
import mage.server.util.ConfigSettings;
|
||||
import mage.server.util.config.Plugin;
|
||||
import mage.server.util.config.GamePlugin;
|
||||
import mage.util.Copier;
|
||||
import mage.utils.MageVersion;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jboss.remoting.InvocationRequest;
|
||||
import org.jboss.remoting.InvokerLocator;
|
||||
import org.jboss.remoting.ServerInvocationHandler;
|
||||
import org.jboss.remoting.ServerInvoker;
|
||||
import org.jboss.remoting.callback.InvokerCallbackHandler;
|
||||
import org.jboss.remoting.callback.ServerInvokerCallbackHandler;
|
||||
import org.jboss.remoting.transport.Connector;
|
||||
import org.jboss.remoting.transporter.TransporterServer;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -61,11 +72,11 @@ public class Main {
|
|||
private final static String testModeArg = "-testMode=";
|
||||
private final static String adminPasswordArg = "-adminPassword=";
|
||||
private final static String pluginFolder = "plugins";
|
||||
private static MageVersion version = new MageVersion(0, 7, 4, "beta-2");
|
||||
private static MageVersion version = new MageVersion(0, 8, 0, "");
|
||||
|
||||
public static PluginClassLoader classLoader = new PluginClassLoader();
|
||||
public static ServerImpl server;
|
||||
|
||||
public static TransporterServer server;
|
||||
protected static boolean testMode;
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
|
@ -87,7 +98,6 @@ public class Main {
|
|||
for (Plugin plugin: config.getDeckTypes()) {
|
||||
DeckValidatorFactory.getInstance().addDeckType(plugin.getName(), loadPlugin(plugin));
|
||||
}
|
||||
boolean testMode = false;
|
||||
String adminPassword = "";
|
||||
for (String arg: args) {
|
||||
if (arg.startsWith(testModeArg)) {
|
||||
|
@ -97,44 +107,102 @@ public class Main {
|
|||
adminPassword = arg.replace(adminPasswordArg, "");
|
||||
}
|
||||
}
|
||||
Copier.setLoader(classLoader);
|
||||
setServerAddress(config.getServerAddress());
|
||||
server = new ServerImpl(config.getPort(), config.getServerName(), testMode, adminPassword);
|
||||
String host = getServerAddress();
|
||||
int port = config.getPort();
|
||||
String locatorURI = "bisocket://" + host + ":" + port;
|
||||
try {
|
||||
InvokerLocator serverLocator = new InvokerLocator(locatorURI);
|
||||
server = new MageTransporterServer(serverLocator, new MageServerImpl(adminPassword, testMode), MageServer.class.getName(), new MageServerInvocationHandler());
|
||||
server.start();
|
||||
logger.info("Started MAGE server - listening on " + host + ":" + port);
|
||||
if (testMode)
|
||||
logger.info("MAGE server running in test mode");
|
||||
|
||||
} catch (Exception ex) {
|
||||
logger.fatal("Failed to start server - " + host + ":" + port, ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void setServerAddress(String ip) {
|
||||
String ipParam = System.getProperty("server");
|
||||
if (ipParam != null) {
|
||||
ip = ipParam;
|
||||
static class MageTransporterServer extends TransporterServer {
|
||||
|
||||
Connector connector;
|
||||
|
||||
public MageTransporterServer(InvokerLocator locator, Object target, String subsystem, MageServerInvocationHandler callback) throws Exception {
|
||||
super(locator, target, subsystem);
|
||||
connector.addInvocationHandler("callback", callback);
|
||||
}
|
||||
if (ip.equals("localhost")) {
|
||||
|
||||
public Connector getConnector() throws Exception {
|
||||
return connector;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Connector getConnector(InvokerLocator locator, Map config, Element xmlConfig) throws Exception {
|
||||
Connector c = super.getConnector(locator, config, xmlConfig);
|
||||
this.connector = c;
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
static class MageServerInvocationHandler implements ServerInvocationHandler {
|
||||
|
||||
@Override
|
||||
public void setMBeanServer(MBeanServer server) {}
|
||||
|
||||
@Override
|
||||
public void setInvoker(ServerInvoker invoker) {}
|
||||
|
||||
@Override
|
||||
public Object invoke(final InvocationRequest invocation) throws Throwable {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(InvokerCallbackHandler callbackHandler) {
|
||||
ServerInvokerCallbackHandler handler = (ServerInvokerCallbackHandler) callbackHandler;
|
||||
try {
|
||||
String foundIP = "";
|
||||
for (Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); interfaces.hasMoreElements(); ) {
|
||||
NetworkInterface iface = interfaces.nextElement( );
|
||||
if (iface.isLoopback())
|
||||
continue;
|
||||
for (InterfaceAddress addr: iface.getInterfaceAddresses())
|
||||
{
|
||||
InetAddress iaddr = addr.getAddress();
|
||||
if (iaddr instanceof Inet4Address) {
|
||||
foundIP = iaddr.getHostAddress();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (foundIP.length() > 0)
|
||||
break;
|
||||
}
|
||||
if (foundIP.length() > 0)
|
||||
ip = foundIP;
|
||||
} catch (SocketException ex) {
|
||||
logger.warn("Could not get server address: ", ex);
|
||||
String sessionId = handler.getClientSessionId();
|
||||
InetAddress clientAddress = handler.getCallbackClient().getAddressSeenByServer();
|
||||
SessionManager.getInstance().createSession(sessionId, callbackHandler, clientAddress.getHostAddress());
|
||||
} catch (Throwable ex) {
|
||||
logger.fatal("", ex);
|
||||
}
|
||||
}
|
||||
System.setProperty("java.rmi.server.hostname", ip);
|
||||
System.setProperty("sun.rmi.transport.tcp.readTimeout", "30000");
|
||||
logger.info("MAGE server - using address " + ip);
|
||||
|
||||
@Override
|
||||
public void removeListener(InvokerCallbackHandler callbackHandler) {
|
||||
ServerInvokerCallbackHandler handler = (ServerInvokerCallbackHandler) callbackHandler;
|
||||
String sessionId = handler.getCallbackClient().getSessionId();
|
||||
SessionManager.getInstance().removeSession(sessionId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static String getServerAddress() {
|
||||
try {
|
||||
String foundIP = "";
|
||||
for (Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); interfaces.hasMoreElements(); ) {
|
||||
NetworkInterface iface = interfaces.nextElement( );
|
||||
if (iface.isLoopback())
|
||||
continue;
|
||||
for (InterfaceAddress addr: iface.getInterfaceAddresses())
|
||||
{
|
||||
InetAddress iaddr = addr.getAddress();
|
||||
if (iaddr instanceof Inet4Address) {
|
||||
foundIP = iaddr.getHostAddress();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (foundIP.length() > 0)
|
||||
break;
|
||||
}
|
||||
if (foundIP.length() > 0)
|
||||
return foundIP;
|
||||
} catch (SocketException ex) {
|
||||
logger.warn("Could not get server address: ", ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Class<?> loadPlugin(Plugin plugin) {
|
||||
|
@ -198,4 +266,7 @@ public class Main {
|
|||
return version;
|
||||
}
|
||||
|
||||
public static boolean isTestMode() {
|
||||
return testMode;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,11 +31,14 @@ package mage.server;
|
|||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.interfaces.callback.CallbackServerSession;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.server.game.GameManager;
|
||||
import mage.view.TableClientMessage;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jboss.remoting.callback.AsynchInvokerCallbackHandler;
|
||||
import org.jboss.remoting.callback.Callback;
|
||||
import org.jboss.remoting.callback.HandleCallbackException;
|
||||
import org.jboss.remoting.callback.InvokerCallbackHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -45,68 +48,46 @@ public class Session {
|
|||
|
||||
private final static Logger logger = Logger.getLogger(Session.class);
|
||||
|
||||
private UUID sessionId;
|
||||
private UUID clientId;
|
||||
private String sessionId;
|
||||
private String username;
|
||||
private String host;
|
||||
private int messageId = 0;
|
||||
private String ackMessage;
|
||||
private Date timeConnected;
|
||||
private long lastPing;
|
||||
private boolean isAdmin = false;
|
||||
private final CallbackServerSession callback = new CallbackServerSession();
|
||||
private AsynchInvokerCallbackHandler callbackHandler;
|
||||
|
||||
public Session(String userName, String host, UUID clientId) {
|
||||
sessionId = UUID.randomUUID();
|
||||
this.username = userName;
|
||||
public Session(String sessionId, InvokerCallbackHandler callbackHandler, String host) {
|
||||
this.sessionId = sessionId;
|
||||
this.callbackHandler = (AsynchInvokerCallbackHandler) callbackHandler;
|
||||
this.host = host;
|
||||
this.clientId = clientId;
|
||||
this.isAdmin = false;
|
||||
this.timeConnected = new Date();
|
||||
ping();
|
||||
}
|
||||
|
||||
public Session(String host) {
|
||||
sessionId = UUID.randomUUID();
|
||||
this.username = "Admin";
|
||||
this.host = host;
|
||||
|
||||
public void registerUser(String userName) {
|
||||
this.isAdmin = false;
|
||||
this.username = userName;
|
||||
}
|
||||
|
||||
public void registerAdmin() {
|
||||
this.isAdmin = true;
|
||||
this.timeConnected = new Date();
|
||||
ping();
|
||||
this.username = "Admin";
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
|
||||
public String getId() {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
public UUID getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public void kill() {
|
||||
callback.destroy();
|
||||
SessionManager.getInstance().removeSession(sessionId);
|
||||
TableManager.getInstance().removeSession(sessionId);
|
||||
GameManager.getInstance().removeSession(sessionId);
|
||||
ChatManager.getInstance().removeSession(sessionId);
|
||||
}
|
||||
|
||||
public ClientCallback callback() {
|
||||
try {
|
||||
return callback.callback();
|
||||
} catch (InterruptedException ex) {
|
||||
logger.fatal("Session callback error", ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public synchronized void fireCallback(final ClientCallback call) {
|
||||
call.setMessageId(messageId++);
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug(sessionId + " - " + call.getMessageId() + " - " + call.getMethod());
|
||||
try {
|
||||
callback.setCallback(call);
|
||||
} catch (InterruptedException ex) {
|
||||
callbackHandler.handleCallbackOneway(new Callback(call));
|
||||
} catch (HandleCallbackException ex) {
|
||||
logger.fatal("Session fireCallback error", ex);
|
||||
}
|
||||
}
|
||||
|
@ -139,32 +120,10 @@ public class Session {
|
|||
fireCallback(new ClientCallback("replayGame", gameId));
|
||||
}
|
||||
|
||||
public void ack(String message) {
|
||||
this.ackMessage = message;
|
||||
}
|
||||
|
||||
public String getAckMessage() {
|
||||
return ackMessage;
|
||||
}
|
||||
|
||||
public void clearAck() {
|
||||
this.ackMessage = "";
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void ping() {
|
||||
this.lastPing = System.currentTimeMillis();
|
||||
if (logger.isTraceEnabled())
|
||||
logger.trace("Ping received from" + username + ":" + sessionId);
|
||||
}
|
||||
|
||||
public boolean stillAlive() {
|
||||
return (System.currentTimeMillis() - lastPing) < 60000;
|
||||
}
|
||||
|
||||
public boolean isAdmin() {
|
||||
return isAdmin;
|
||||
}
|
||||
|
|
|
@ -32,14 +32,10 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import mage.MageException;
|
||||
import mage.view.UserView;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jboss.remoting.callback.InvokerCallbackHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -49,83 +45,67 @@ public class SessionManager {
|
|||
|
||||
private final static Logger logger = Logger.getLogger(SessionManager.class);
|
||||
private final static SessionManager INSTANCE = new SessionManager();
|
||||
private static ScheduledExecutorService sessionExecutor;
|
||||
|
||||
public static SessionManager getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
protected SessionManager() {
|
||||
sessionExecutor = Executors.newScheduledThreadPool(1);
|
||||
sessionExecutor.scheduleWithFixedDelay(new SessionChecker(), 30, 10, TimeUnit.SECONDS);
|
||||
}
|
||||
private ConcurrentHashMap<String, Session> sessions = new ConcurrentHashMap<String, Session>();
|
||||
|
||||
private ConcurrentHashMap<UUID, Session> sessions = new ConcurrentHashMap<UUID, Session>();
|
||||
|
||||
public Session getSession(UUID sessionId) {
|
||||
public Session getSession(String sessionId) {
|
||||
if (sessions == null || sessionId == null) return null;
|
||||
return sessions.get(sessionId);
|
||||
}
|
||||
|
||||
public UUID createSession(String userName, String host, UUID clientId) throws MageException {
|
||||
for (Session session: sessions.values()) {
|
||||
if (session.getUsername().equals(userName)) {
|
||||
if (session.getClientId().equals(clientId)) {
|
||||
logger.info("Reconnecting session " + session.getId() + " for " + userName);
|
||||
return session.getId();
|
||||
}
|
||||
else {
|
||||
throw new MageException("User name already in use");
|
||||
}
|
||||
}
|
||||
}
|
||||
Session session = new Session(userName, host, clientId);
|
||||
sessions.put(session.getId(), session);
|
||||
logger.info("Session " + session.getId() + " created for user " + userName);
|
||||
return session.getId();
|
||||
}
|
||||
|
||||
public UUID createSession(String host) throws MageException {
|
||||
Session session = new Session(host);
|
||||
sessions.put(session.getId(), session);
|
||||
logger.info("Admin session created");
|
||||
return session.getId();
|
||||
}
|
||||
|
||||
public void removeSession(UUID sessionId) {
|
||||
sessions.remove(sessionId);
|
||||
}
|
||||
|
||||
public void checkSessions() {
|
||||
logger.trace("Checking sessions");
|
||||
for (Session session: sessions.values()) {
|
||||
if (!session.stillAlive()) {
|
||||
logger.info("Client for user " + session.getUsername() + ":" + session.getId() + " timed out - releasing resources");
|
||||
session.kill();
|
||||
}
|
||||
}
|
||||
public void createSession(String sessionId, InvokerCallbackHandler callbackHandler, String host) {
|
||||
Session session = new Session(sessionId, callbackHandler, host);
|
||||
sessions.put(sessionId, session);
|
||||
}
|
||||
|
||||
public Map<UUID, Session> getSessions() {
|
||||
Map<UUID, Session> map = new HashMap<UUID, Session>();
|
||||
for (Map.Entry<UUID, Session> entry : sessions.entrySet()) {
|
||||
public boolean registerUser(String sessionId, String userName) {
|
||||
Session session = sessions.get(sessionId);
|
||||
if (session != null) {
|
||||
session.registerUser(userName);
|
||||
logger.info("User " + userName + " connected from " + session.getHost());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean registerAdmin(String sessionId) {
|
||||
Session session = sessions.get(sessionId);
|
||||
if (session != null) {
|
||||
session.registerAdmin();
|
||||
logger.info("Admin connected from " + session.getHost());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void removeSession(String sessionId) {
|
||||
sessions.remove(sessionId);
|
||||
}
|
||||
|
||||
public Map<String, Session> getSessions() {
|
||||
Map<String, Session> map = new HashMap<String, Session>();
|
||||
for (Map.Entry<String, Session> entry : sessions.entrySet()) {
|
||||
map.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
List<UserView> getUsers(UUID sessionId) {
|
||||
List<UserView> getUsers(String sessionId) {
|
||||
List<UserView> users = new ArrayList<UserView>();
|
||||
Session admin = sessions.get(sessionId);
|
||||
if (admin != null && admin.isAdmin()) {
|
||||
for (Session session: sessions.values()) {
|
||||
users.add(new UserView(session.getUsername(), session.getHost(), session.getId(), session.getConnectionTime()));
|
||||
users.add(new UserView(session.getUsername(), "", session.getId(), session.getConnectionTime()));
|
||||
}
|
||||
}
|
||||
return users;
|
||||
}
|
||||
|
||||
public void disconnectUser(UUID sessionId, UUID userSessionId) {
|
||||
public void disconnectUser(String sessionId, String userSessionId) {
|
||||
if (isAdmin(sessionId)) {
|
||||
Session session = sessions.get(userSessionId);
|
||||
if (session != null) {
|
||||
|
@ -134,7 +114,7 @@ public class SessionManager {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isAdmin(UUID sessionId) {
|
||||
public boolean isAdmin(String sessionId) {
|
||||
Session admin = sessions.get(sessionId);
|
||||
if (admin != null) {
|
||||
return admin.isAdmin();
|
||||
|
@ -142,19 +122,10 @@ public class SessionManager {
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean isValidSession(UUID sessionId) {
|
||||
public boolean isValidSession(String sessionId) {
|
||||
if (sessions.containsKey(sessionId))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
class SessionChecker implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
checkSessions();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -67,16 +67,16 @@ public class TableController {
|
|||
|
||||
private final static Logger logger = Logger.getLogger(TableController.class);
|
||||
|
||||
private UUID sessionId;
|
||||
private String sessionId;
|
||||
private UUID chatId;
|
||||
private String controllerName;
|
||||
private Table table;
|
||||
private Match match;
|
||||
private MatchOptions options;
|
||||
private Tournament tournament;
|
||||
private ConcurrentHashMap<UUID, UUID> sessionPlayerMap = new ConcurrentHashMap<UUID, UUID>();
|
||||
private ConcurrentHashMap<String, UUID> sessionPlayerMap = new ConcurrentHashMap<String, UUID>();
|
||||
|
||||
public TableController(UUID roomId, UUID sessionId, MatchOptions options) {
|
||||
public TableController(UUID roomId, String sessionId, MatchOptions options) {
|
||||
this.sessionId = sessionId;
|
||||
chatId = ChatManager.getInstance().createChatSession();
|
||||
this.options = options;
|
||||
|
@ -90,7 +90,7 @@ public class TableController {
|
|||
init();
|
||||
}
|
||||
|
||||
public TableController(UUID roomId, UUID sessionId, TournamentOptions options) {
|
||||
public TableController(UUID roomId, String sessionId, TournamentOptions options) {
|
||||
this.sessionId = sessionId;
|
||||
chatId = ChatManager.getInstance().createChatSession();
|
||||
tournament = TournamentFactory.getInstance().createTournament(options.getTournamentType(), options);
|
||||
|
@ -124,7 +124,7 @@ public class TableController {
|
|||
);
|
||||
}
|
||||
|
||||
public synchronized boolean joinTournament(UUID sessionId, String name, String playerType, int skill) throws GameException {
|
||||
public synchronized boolean joinTournament(String sessionId, String name, String playerType, int skill) throws GameException {
|
||||
if (table.getState() != TableState.WAITING) {
|
||||
return false;
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ public class TableController {
|
|||
return true;
|
||||
}
|
||||
|
||||
public synchronized boolean joinTable(UUID sessionId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException {
|
||||
public synchronized boolean joinTable(String sessionId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException {
|
||||
if (table.getState() != TableState.WAITING) {
|
||||
return false;
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ public class TableController {
|
|||
throw new GameException("No available seats.");
|
||||
}
|
||||
Deck deck = Deck.load(deckList);
|
||||
if (!Main.server.isTestMode() && !table.getValidator().validate(deck)) {
|
||||
if (!Main.isTestMode() && !table.getValidator().validate(deck)) {
|
||||
throw new InvalidDeckException(name + " has an invalid deck for this format", table.getValidator().getInvalid());
|
||||
}
|
||||
|
||||
|
@ -169,7 +169,7 @@ public class TableController {
|
|||
return true;
|
||||
}
|
||||
|
||||
public void addPlayer(UUID sessionId, Player player, String playerType, Deck deck) throws GameException {
|
||||
public void addPlayer(String sessionId, Player player, String playerType, Deck deck) throws GameException {
|
||||
if (table.getState() != TableState.WAITING) {
|
||||
return;
|
||||
}
|
||||
|
@ -183,29 +183,33 @@ public class TableController {
|
|||
sessionPlayerMap.put(sessionId, player.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean submitDeck(String sessionId, DeckCardLists deckList) throws MageException {
|
||||
return submitDeck(sessionPlayerMap.get(sessionId), deckList);
|
||||
}
|
||||
|
||||
public synchronized boolean submitDeck(UUID sessionId, DeckCardLists deckList) throws MageException {
|
||||
public synchronized boolean submitDeck(UUID playerId, DeckCardLists deckList) throws MageException {
|
||||
if (table.getState() != TableState.SIDEBOARDING && table.getState() != TableState.CONSTRUCTING) {
|
||||
return false;
|
||||
}
|
||||
Deck deck = Deck.load(deckList);
|
||||
if (!Main.server.isTestMode() && !table.getValidator().validate(deck)) {
|
||||
if (!Main.isTestMode() && !table.getValidator().validate(deck)) {
|
||||
throw new InvalidDeckException("Invalid deck for this format", table.getValidator().getInvalid());
|
||||
}
|
||||
submitDeck(sessionId, deck);
|
||||
submitDeck(playerId, deck);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void submitDeck(UUID sessionId, Deck deck) {
|
||||
private void submitDeck(UUID playerId, Deck deck) {
|
||||
if (table.getState() == TableState.SIDEBOARDING) {
|
||||
match.submitDeck(sessionPlayerMap.get(sessionId), deck);
|
||||
match.submitDeck(playerId, deck);
|
||||
}
|
||||
else {
|
||||
TournamentManager.getInstance().submitDeck(tournament.getId(), sessionId, deck);
|
||||
TournamentManager.getInstance().submitDeck(tournament.getId(), playerId, deck);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean watchTable(UUID sessionId) {
|
||||
public boolean watchTable(String sessionId) {
|
||||
if (table.getState() != TableState.DUELING) {
|
||||
return false;
|
||||
}
|
||||
|
@ -213,11 +217,11 @@ public class TableController {
|
|||
return true;
|
||||
}
|
||||
|
||||
public boolean replayTable(UUID sessionId) {
|
||||
public boolean replayTable(String sessionId) {
|
||||
if (table.getState() != TableState.FINISHED) {
|
||||
return false;
|
||||
}
|
||||
ReplayManager.getInstance().replayGame(sessionId, table.getId());
|
||||
ReplayManager.getInstance().replayGame(table.getId(), sessionId);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -233,18 +237,18 @@ public class TableController {
|
|||
return player;
|
||||
}
|
||||
|
||||
public synchronized void leaveTable(UUID sessionId) {
|
||||
public synchronized void leaveTable(String sessionId) {
|
||||
if (table.getState() == TableState.WAITING || table.getState() == TableState.STARTING)
|
||||
table.leaveTable(sessionPlayerMap.get(sessionId));
|
||||
}
|
||||
|
||||
public synchronized void startMatch(UUID sessionId) {
|
||||
public synchronized void startMatch(String sessionId) {
|
||||
if (sessionId.equals(this.sessionId)) {
|
||||
startMatch();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void startChallenge(UUID sessionId, UUID challengeId) {
|
||||
public synchronized void startChallenge(String sessionId, UUID challengeId) {
|
||||
if (sessionId.equals(this.sessionId)) {
|
||||
try {
|
||||
match.startMatch();
|
||||
|
@ -256,7 +260,7 @@ public class TableController {
|
|||
GameManager.getInstance().createGameSession(match.getGame(), sessionPlayerMap, table.getId(), null);
|
||||
ChallengeManager.getInstance().prepareChallenge(getPlayerId(), match);
|
||||
SessionManager sessionManager = SessionManager.getInstance();
|
||||
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
|
||||
for (Entry<String, UUID> entry: sessionPlayerMap.entrySet()) {
|
||||
sessionManager.getSession(entry.getKey()).gameStarted(match.getGame().getId(), entry.getValue());
|
||||
}
|
||||
} catch (GameException ex) {
|
||||
|
@ -267,7 +271,7 @@ public class TableController {
|
|||
|
||||
private UUID getPlayerId() throws GameException {
|
||||
UUID playerId = null;
|
||||
for (Entry<UUID, UUID> entry : sessionPlayerMap.entrySet()) {
|
||||
for (Entry<String, UUID> entry : sessionPlayerMap.entrySet()) {
|
||||
playerId = entry.getValue();
|
||||
break;
|
||||
}
|
||||
|
@ -294,7 +298,7 @@ public class TableController {
|
|||
table.initGame();
|
||||
GameManager.getInstance().createGameSession(match.getGame(), sessionPlayerMap, table.getId(), choosingPlayerId);
|
||||
SessionManager sessionManager = SessionManager.getInstance();
|
||||
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
|
||||
for (Entry<String, UUID> entry: sessionPlayerMap.entrySet()) {
|
||||
Session session = sessionManager.getSession(entry.getKey());
|
||||
if (session != null) {
|
||||
session.gameStarted(match.getGame().getId(), entry.getValue());
|
||||
|
@ -314,12 +318,12 @@ public class TableController {
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized void startTournament(UUID sessionId) {
|
||||
public synchronized void startTournament(String sessionId) {
|
||||
try {
|
||||
if (sessionId.equals(this.sessionId) && table.getState() == TableState.STARTING) {
|
||||
TournamentManager.getInstance().createTournamentSession(tournament, sessionPlayerMap, table.getId());
|
||||
SessionManager sessionManager = SessionManager.getInstance();
|
||||
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
|
||||
for (Entry<String, UUID> entry: sessionPlayerMap.entrySet()) {
|
||||
Session session = sessionManager.getSession(entry.getKey());
|
||||
session.tournamentStarted(tournament.getId(), entry.getValue());
|
||||
}
|
||||
|
@ -336,14 +340,14 @@ public class TableController {
|
|||
table.initDraft();
|
||||
DraftManager.getInstance().createDraftSession(draft, sessionPlayerMap, table.getId());
|
||||
SessionManager sessionManager = SessionManager.getInstance();
|
||||
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
|
||||
for (Entry<String, UUID> entry: sessionPlayerMap.entrySet()) {
|
||||
sessionManager.getSession(entry.getKey()).draftStarted(draft.getId(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
private void sideboard(UUID playerId, Deck deck, int timeout) throws MageException {
|
||||
SessionManager sessionManager = SessionManager.getInstance();
|
||||
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
|
||||
for (Entry<String, UUID> entry: sessionPlayerMap.entrySet()) {
|
||||
if (entry.getValue().equals(playerId)) {
|
||||
sessionManager.getSession(entry.getKey()).sideboard(deck, table.getId(), timeout);
|
||||
break;
|
||||
|
@ -395,7 +399,7 @@ public class TableController {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isOwner(UUID sessionId) {
|
||||
public boolean isOwner(String sessionId) {
|
||||
return sessionId.equals(this.sessionId);
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ public class TableManager {
|
|||
return INSTANCE;
|
||||
}
|
||||
|
||||
public Table createTable(UUID roomId, UUID sessionId, MatchOptions options) {
|
||||
public Table createTable(UUID roomId, String sessionId, MatchOptions options) {
|
||||
TableController tableController = new TableController(roomId, sessionId, options);
|
||||
controllers.put(tableController.getTable().getId(), tableController);
|
||||
tables.put(tableController.getTable().getId(), tableController.getTable());
|
||||
|
@ -68,13 +68,13 @@ public class TableManager {
|
|||
}
|
||||
|
||||
public Table createTable(UUID roomId, MatchOptions options) {
|
||||
TableController tableController = new TableController(roomId, UUID.randomUUID(), options);
|
||||
TableController tableController = new TableController(roomId, UUID.randomUUID().toString(), options);
|
||||
controllers.put(tableController.getTable().getId(), tableController);
|
||||
tables.put(tableController.getTable().getId(), tableController.getTable());
|
||||
return tableController.getTable();
|
||||
}
|
||||
|
||||
public Table createTournamentTable(UUID roomId, UUID sessionId, TournamentOptions options) {
|
||||
public Table createTournamentTable(UUID roomId, String sessionId, TournamentOptions options) {
|
||||
TableController tableController = new TableController(roomId, sessionId, options);
|
||||
controllers.put(tableController.getTable().getId(), tableController);
|
||||
tables.put(tableController.getTable().getId(), tableController.getTable());
|
||||
|
@ -95,35 +95,35 @@ public class TableManager {
|
|||
return tables.values();
|
||||
}
|
||||
|
||||
public boolean joinTable(UUID sessionId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException {
|
||||
public boolean joinTable(String sessionId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException {
|
||||
if (controllers.containsKey(tableId))
|
||||
return controllers.get(tableId).joinTable(sessionId, name, playerType, skill, deckList);
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean joinTournament(UUID sessionId, UUID tableId, String name, String playerType, int skill) throws GameException {
|
||||
public boolean joinTournament(String sessionId, UUID tableId, String name, String playerType, int skill) throws GameException {
|
||||
if (controllers.containsKey(tableId))
|
||||
return controllers.get(tableId).joinTournament(sessionId, name, playerType, skill);
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean submitDeck(UUID sessionId, UUID tableId, DeckCardLists deckList) throws MageException {
|
||||
public boolean submitDeck(String sessionId, UUID tableId, DeckCardLists deckList) throws MageException {
|
||||
if (controllers.containsKey(tableId))
|
||||
return controllers.get(tableId).submitDeck(sessionId, deckList);
|
||||
return false;
|
||||
}
|
||||
|
||||
public void removeSession(UUID sessionId) {
|
||||
public void removeSession(String sessionId) {
|
||||
// TODO: search through tables and remove session
|
||||
}
|
||||
|
||||
public boolean isTableOwner(UUID tableId, UUID sessionId) {
|
||||
public boolean isTableOwner(UUID tableId, String sessionId) {
|
||||
if (controllers.containsKey(tableId))
|
||||
return controllers.get(tableId).isOwner(sessionId);
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean removeTable(UUID sessionId, UUID tableId) {
|
||||
public boolean removeTable(String sessionId, UUID tableId) {
|
||||
if (isTableOwner(tableId, sessionId) || SessionManager.getInstance().isAdmin(sessionId)) {
|
||||
removeTable(tableId);
|
||||
return true;
|
||||
|
@ -131,7 +131,7 @@ public class TableManager {
|
|||
return false;
|
||||
}
|
||||
|
||||
public void leaveTable(UUID sessionId, UUID tableId) {
|
||||
public void leaveTable(String sessionId, UUID tableId) {
|
||||
if (controllers.containsKey(tableId))
|
||||
controllers.get(tableId).leaveTable(sessionId);
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ public class TableManager {
|
|||
return null;
|
||||
}
|
||||
|
||||
public void startMatch(UUID sessionId, UUID roomId, UUID tableId) {
|
||||
public void startMatch(String sessionId, UUID roomId, UUID tableId) {
|
||||
if (controllers.containsKey(tableId))
|
||||
controllers.get(tableId).startMatch(sessionId);
|
||||
}
|
||||
|
@ -152,12 +152,12 @@ public class TableManager {
|
|||
controllers.get(tableId).startMatch();
|
||||
}
|
||||
|
||||
public void startChallenge(UUID sessionId, UUID roomId, UUID tableId, UUID challengeId) {
|
||||
public void startChallenge(String sessionId, UUID roomId, UUID tableId, UUID challengeId) {
|
||||
if (controllers.containsKey(tableId))
|
||||
controllers.get(tableId).startChallenge(sessionId, challengeId);
|
||||
}
|
||||
|
||||
public void startTournament(UUID sessionId, UUID roomId, UUID tableId) {
|
||||
public void startTournament(String sessionId, UUID roomId, UUID tableId) {
|
||||
if (controllers.containsKey(tableId))
|
||||
controllers.get(tableId).startTournament(sessionId);
|
||||
}
|
||||
|
@ -167,13 +167,13 @@ public class TableManager {
|
|||
controllers.get(tableId).startDraft(draft);
|
||||
}
|
||||
|
||||
public boolean watchTable(UUID sessionId, UUID tableId) {
|
||||
public boolean watchTable(String sessionId, UUID tableId) {
|
||||
if (controllers.containsKey(tableId))
|
||||
return controllers.get(tableId).watchTable(sessionId);
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean replayTable(UUID sessionId, UUID tableId) {
|
||||
public boolean replayTable(String sessionId, UUID tableId) {
|
||||
if (controllers.containsKey(tableId))
|
||||
return controllers.get(tableId).replayTable(sessionId);
|
||||
return false;
|
||||
|
@ -189,7 +189,7 @@ public class TableManager {
|
|||
controllers.get(tableId).endDraft(draft);
|
||||
}
|
||||
|
||||
public void swapSeats(UUID tableId, UUID sessionId, int seatNum1, int seatNum2) {
|
||||
public void swapSeats(UUID tableId, String sessionId, int seatNum1, int seatNum2) {
|
||||
if (controllers.containsKey(tableId) && isTableOwner(tableId, sessionId)) {
|
||||
controllers.get(tableId).swapSeats(seatNum1, seatNum2);
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ public class TableManager {
|
|||
controllers.get(tableId).construct();
|
||||
}
|
||||
|
||||
public void addPlayer(UUID sessionId, UUID tableId, Player player, String playerType, Deck deck) throws GameException {
|
||||
public void addPlayer(String sessionId, UUID tableId, Player player, String playerType, Deck deck) throws GameException {
|
||||
if (controllers.containsKey(tableId))
|
||||
controllers.get(tableId).addPlayer(sessionId, player, playerType, deck);
|
||||
}
|
||||
|
|
|
@ -56,12 +56,12 @@ public class DraftController {
|
|||
public static final String INIT_FILE_PATH = "config" + File.separator + "init.txt";
|
||||
|
||||
private ConcurrentHashMap<UUID, DraftSession> draftSessions = new ConcurrentHashMap<UUID, DraftSession>();
|
||||
private ConcurrentHashMap<UUID, UUID> sessionPlayerMap;
|
||||
private ConcurrentHashMap<String, UUID> sessionPlayerMap;
|
||||
private UUID draftSessionId;
|
||||
private Draft draft;
|
||||
private UUID tableId;
|
||||
|
||||
public DraftController(Draft draft, ConcurrentHashMap<UUID, UUID> sessionPlayerMap, UUID tableId) {
|
||||
public DraftController(Draft draft, ConcurrentHashMap<String, UUID> sessionPlayerMap, UUID tableId) {
|
||||
draftSessionId = UUID.randomUUID();
|
||||
this.sessionPlayerMap = sessionPlayerMap;
|
||||
this.draft = draft;
|
||||
|
@ -116,11 +116,11 @@ public class DraftController {
|
|||
checkStart();
|
||||
}
|
||||
|
||||
private UUID getPlayerId(UUID sessionId) {
|
||||
private UUID getPlayerId(String sessionId) {
|
||||
return sessionPlayerMap.get(sessionId);
|
||||
}
|
||||
|
||||
public void join(UUID sessionId) {
|
||||
public void join(String sessionId) {
|
||||
UUID playerId = sessionPlayerMap.get(sessionId);
|
||||
DraftSession draftSession = new DraftSession(draft, sessionId, playerId);
|
||||
draftSessions.put(playerId, draftSession);
|
||||
|
@ -163,7 +163,7 @@ public class DraftController {
|
|||
return true;
|
||||
}
|
||||
|
||||
private void leave(UUID sessionId) {
|
||||
private void leave(String sessionId) {
|
||||
draft.leave(getPlayerId(sessionId));
|
||||
}
|
||||
|
||||
|
@ -174,7 +174,7 @@ public class DraftController {
|
|||
TableManager.getInstance().endDraft(tableId, draft);
|
||||
}
|
||||
|
||||
public void kill(UUID sessionId) {
|
||||
public void kill(String sessionId) {
|
||||
if (sessionPlayerMap.containsKey(sessionId)) {
|
||||
draftSessions.get(sessionPlayerMap.get(sessionId)).setKilled();
|
||||
draftSessions.remove(sessionPlayerMap.get(sessionId));
|
||||
|
@ -183,7 +183,7 @@ public class DraftController {
|
|||
}
|
||||
}
|
||||
|
||||
public void timeout(UUID sessionId) {
|
||||
public void timeout(String sessionId) {
|
||||
if (sessionPlayerMap.containsKey(sessionId)) {
|
||||
draft.autoPick(sessionPlayerMap.get(sessionId));
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ public class DraftController {
|
|||
return this.draftSessionId;
|
||||
}
|
||||
|
||||
public DraftPickView sendCardPick(UUID sessionId, UUID cardId) {
|
||||
public DraftPickView sendCardPick(String sessionId, UUID cardId) {
|
||||
if (draftSessions.get(sessionPlayerMap.get(sessionId)).sendCardPick(cardId)) {
|
||||
return getDraftPickView(sessionPlayerMap.get(sessionId), 0);
|
||||
}
|
||||
|
|
|
@ -48,13 +48,13 @@ public class DraftManager {
|
|||
|
||||
private ConcurrentHashMap<UUID, DraftController> draftControllers = new ConcurrentHashMap<UUID, DraftController>();
|
||||
|
||||
public UUID createDraftSession(Draft draft, ConcurrentHashMap<UUID, UUID> sessionPlayerMap, UUID tableId) {
|
||||
public UUID createDraftSession(Draft draft, ConcurrentHashMap<String, UUID> sessionPlayerMap, UUID tableId) {
|
||||
DraftController draftController = new DraftController(draft, sessionPlayerMap, tableId);
|
||||
draftControllers.put(draft.getId(), draftController);
|
||||
return draftController.getSessionId();
|
||||
}
|
||||
|
||||
public void joinDraft(UUID draftId, UUID sessionId) {
|
||||
public void joinDraft(UUID draftId, String sessionId) {
|
||||
draftControllers.get(draftId).join(sessionId);
|
||||
}
|
||||
|
||||
|
@ -62,21 +62,21 @@ public class DraftManager {
|
|||
draftControllers.remove(gameId);
|
||||
}
|
||||
|
||||
public DraftPickView sendCardPick(UUID draftId, UUID sessionId, UUID cardId) {
|
||||
public DraftPickView sendCardPick(UUID draftId, String sessionId, UUID cardId) {
|
||||
return draftControllers.get(draftId).sendCardPick(sessionId, cardId);
|
||||
}
|
||||
|
||||
public void removeSession(UUID sessionId) {
|
||||
public void removeSession(String sessionId) {
|
||||
for (DraftController controller: draftControllers.values()) {
|
||||
controller.kill(sessionId);
|
||||
}
|
||||
}
|
||||
|
||||
public void kill(UUID draftId, UUID sessionId) {
|
||||
public void kill(UUID draftId, String sessionId) {
|
||||
draftControllers.get(draftId).kill(sessionId);
|
||||
}
|
||||
|
||||
public void timeout(UUID gameId, UUID sessionId) {
|
||||
public void timeout(UUID gameId, String sessionId) {
|
||||
draftControllers.get(gameId).timeout(sessionId);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,12 +32,8 @@ import java.rmi.RemoteException;
|
|||
import java.util.UUID;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import mage.game.draft.Draft;
|
||||
import mage.MageException;
|
||||
import mage.interfaces.callback.CallbackException;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.server.Session;
|
||||
import mage.server.SessionManager;
|
||||
|
@ -55,7 +51,7 @@ public class DraftSession {
|
|||
|
||||
protected final static Logger logger = Logger.getLogger(DraftSession.class);
|
||||
|
||||
protected UUID sessionId;
|
||||
protected String sessionId;
|
||||
protected UUID playerId;
|
||||
protected Draft draft;
|
||||
protected boolean killed = false;
|
||||
|
@ -63,7 +59,7 @@ public class DraftSession {
|
|||
private ScheduledFuture<?> futureTimeout;
|
||||
protected static ScheduledExecutorService timeoutExecutor = ThreadExecutor.getInstance().getTimeoutExecutor();
|
||||
|
||||
public DraftSession(Draft draft, UUID sessionId, UUID playerId) {
|
||||
public DraftSession(Draft draft, String sessionId, UUID playerId) {
|
||||
this.sessionId = sessionId;
|
||||
this.draft = draft;
|
||||
this.playerId = playerId;
|
||||
|
@ -143,7 +139,6 @@ public class DraftSession {
|
|||
private synchronized void cancelTimeout() {
|
||||
if (futureTimeout != null) {
|
||||
futureTimeout.cancel(false);
|
||||
((ThreadPoolExecutor)timeoutExecutor).getQueue().remove(futureTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -81,8 +81,8 @@ public class GameController implements GameCallback {
|
|||
public static final String INIT_FILE_PATH = "config" + File.separator + "init.txt";
|
||||
|
||||
private ConcurrentHashMap<UUID, GameSession> gameSessions = new ConcurrentHashMap<UUID, GameSession>();
|
||||
private ConcurrentHashMap<UUID, GameWatcher> watchers = new ConcurrentHashMap<UUID, GameWatcher>();
|
||||
private ConcurrentHashMap<UUID, UUID> sessionPlayerMap;
|
||||
private ConcurrentHashMap<String, GameWatcher> watchers = new ConcurrentHashMap<String, GameWatcher>();
|
||||
private ConcurrentHashMap<String, UUID> sessionPlayerMap;
|
||||
private UUID gameSessionId;
|
||||
private Game game;
|
||||
private UUID chatId;
|
||||
|
@ -91,7 +91,7 @@ public class GameController implements GameCallback {
|
|||
private Future<?> gameFuture;
|
||||
|
||||
|
||||
public GameController(Game game, ConcurrentHashMap<UUID, UUID> sessionPlayerMap, UUID tableId, UUID choosingPlayerId) {
|
||||
public GameController(Game game, ConcurrentHashMap<String, UUID> sessionPlayerMap, UUID tableId, UUID choosingPlayerId) {
|
||||
gameSessionId = UUID.randomUUID();
|
||||
this.sessionPlayerMap = sessionPlayerMap;
|
||||
chatId = ChatManager.getInstance().createChatSession();
|
||||
|
@ -180,11 +180,11 @@ public class GameController implements GameCallback {
|
|||
checkStart();
|
||||
}
|
||||
|
||||
private UUID getPlayerId(UUID sessionId) {
|
||||
private UUID getPlayerId(String sessionId) {
|
||||
return sessionPlayerMap.get(sessionId);
|
||||
}
|
||||
|
||||
public void join(UUID sessionId) {
|
||||
public void join(String sessionId) {
|
||||
UUID playerId = sessionPlayerMap.get(sessionId);
|
||||
GameSession gameSession = new GameSession(game, sessionId, playerId);
|
||||
gameSessions.put(playerId, gameSession);
|
||||
|
@ -228,27 +228,27 @@ public class GameController implements GameCallback {
|
|||
return true;
|
||||
}
|
||||
|
||||
public void watch(UUID sessionId) {
|
||||
public void watch(String sessionId) {
|
||||
GameWatcher gameWatcher = new GameWatcher(sessionId, game.getId());
|
||||
watchers.put(sessionId, gameWatcher);
|
||||
gameWatcher.init(getGameView());
|
||||
ChatManager.getInstance().broadcast(chatId, "", " has started watching", MessageColor.BLACK);
|
||||
}
|
||||
|
||||
public void stopWatching(UUID sessionId) {
|
||||
public void stopWatching(String sessionId) {
|
||||
watchers.remove(sessionId);
|
||||
ChatManager.getInstance().broadcast(chatId, "", " has stopped watching", MessageColor.BLACK);
|
||||
}
|
||||
|
||||
public void concede(UUID sessionId) {
|
||||
public void concede(String sessionId) {
|
||||
game.concede(getPlayerId(sessionId));
|
||||
}
|
||||
|
||||
private void leave(UUID sessionId) {
|
||||
private void leave(String sessionId) {
|
||||
game.quit(getPlayerId(sessionId));
|
||||
}
|
||||
|
||||
public void cheat(UUID sessionId, UUID playerId, DeckCardLists deckList) {
|
||||
public void cheat(String sessionId, UUID playerId, DeckCardLists deckList) {
|
||||
Deck deck;
|
||||
try {
|
||||
deck = Deck.load(deckList);
|
||||
|
@ -263,7 +263,7 @@ public class GameController implements GameCallback {
|
|||
updateGame();
|
||||
}
|
||||
|
||||
public boolean cheat(UUID sessionId, UUID playerId, String cardName) {
|
||||
public boolean cheat(String sessionId, UUID playerId, String cardName) {
|
||||
Card card = Sets.findCard(cardName, true);
|
||||
if (card != null) {
|
||||
Set<Card> cards = new HashSet<Card>();
|
||||
|
@ -276,10 +276,9 @@ public class GameController implements GameCallback {
|
|||
}
|
||||
}
|
||||
|
||||
public void kill(UUID sessionId) {
|
||||
public void kill(String sessionId) {
|
||||
if (sessionPlayerMap.containsKey(sessionId)) {
|
||||
GameSession session = gameSessions.get(sessionPlayerMap.get(sessionId));
|
||||
session.destroy();
|
||||
gameSessions.get(sessionPlayerMap.get(sessionId)).setKilled();
|
||||
gameSessions.remove(sessionPlayerMap.get(sessionId));
|
||||
leave(sessionId);
|
||||
sessionPlayerMap.remove(sessionId);
|
||||
|
@ -290,7 +289,7 @@ public class GameController implements GameCallback {
|
|||
}
|
||||
}
|
||||
|
||||
public void timeout(UUID sessionId) {
|
||||
public void timeout(String sessionId) {
|
||||
if (sessionPlayerMap.containsKey(sessionId)) {
|
||||
ChatManager.getInstance().broadcast(chatId, "", game.getPlayer(sessionPlayerMap.get(sessionId)).getName() + " has timed out. Auto concede.", MessageColor.BLACK);
|
||||
concede(sessionId);
|
||||
|
@ -315,19 +314,19 @@ public class GameController implements GameCallback {
|
|||
return chatId;
|
||||
}
|
||||
|
||||
public void sendPlayerUUID(UUID sessionId, UUID data) {
|
||||
public void sendPlayerUUID(String sessionId, UUID data) {
|
||||
gameSessions.get(sessionPlayerMap.get(sessionId)).sendPlayerUUID(data);
|
||||
}
|
||||
|
||||
public void sendPlayerString(UUID sessionId, String data) {
|
||||
public void sendPlayerString(String sessionId, String data) {
|
||||
gameSessions.get(sessionPlayerMap.get(sessionId)).sendPlayerString(data);
|
||||
}
|
||||
|
||||
public void sendPlayerBoolean(UUID sessionId, Boolean data) {
|
||||
public void sendPlayerBoolean(String sessionId, Boolean data) {
|
||||
gameSessions.get(sessionPlayerMap.get(sessionId)).sendPlayerBoolean(data);
|
||||
}
|
||||
|
||||
public void sendPlayerInteger(UUID sessionId, Integer data) {
|
||||
public void sendPlayerInteger(String sessionId, Integer data) {
|
||||
gameSessions.get(sessionPlayerMap.get(sessionId)).sendPlayerInteger(data);
|
||||
}
|
||||
|
||||
|
|
|
@ -50,13 +50,13 @@ public class GameManager {
|
|||
|
||||
private ConcurrentHashMap<UUID, GameController> gameControllers = new ConcurrentHashMap<UUID, GameController>();
|
||||
|
||||
public UUID createGameSession(Game game, ConcurrentHashMap<UUID, UUID> sessionPlayerMap, UUID tableId, UUID choosingPlayerId) {
|
||||
public UUID createGameSession(Game game, ConcurrentHashMap<String, UUID> sessionPlayerMap, UUID tableId, UUID choosingPlayerId) {
|
||||
GameController gameController = new GameController(game, sessionPlayerMap, tableId, choosingPlayerId);
|
||||
gameControllers.put(game.getId(), gameController);
|
||||
return gameController.getSessionId();
|
||||
}
|
||||
|
||||
public void joinGame(UUID gameId, UUID sessionId) {
|
||||
public void joinGame(UUID gameId, String sessionId) {
|
||||
if (gameControllers.containsKey(gameId))
|
||||
gameControllers.get(gameId).join(sessionId);
|
||||
}
|
||||
|
@ -71,64 +71,64 @@ public class GameManager {
|
|||
return null;
|
||||
}
|
||||
|
||||
public void sendPlayerUUID(UUID gameId, UUID sessionId, UUID data) {
|
||||
public void sendPlayerUUID(UUID gameId, String sessionId, UUID data) {
|
||||
if (gameControllers.containsKey(gameId))
|
||||
gameControllers.get(gameId).sendPlayerUUID(sessionId, data);
|
||||
}
|
||||
|
||||
public void sendPlayerString(UUID gameId, UUID sessionId, String data) {
|
||||
public void sendPlayerString(UUID gameId, String sessionId, String data) {
|
||||
if (gameControllers.containsKey(gameId))
|
||||
gameControllers.get(gameId).sendPlayerString(sessionId, data);
|
||||
}
|
||||
|
||||
public void sendPlayerBoolean(UUID gameId, UUID sessionId, Boolean data) {
|
||||
public void sendPlayerBoolean(UUID gameId, String sessionId, Boolean data) {
|
||||
if (gameControllers.containsKey(gameId))
|
||||
gameControllers.get(gameId).sendPlayerBoolean(sessionId, data);
|
||||
}
|
||||
|
||||
public void sendPlayerInteger(UUID gameId, UUID sessionId, Integer data) {
|
||||
public void sendPlayerInteger(UUID gameId, String sessionId, Integer data) {
|
||||
if (gameControllers.containsKey(gameId))
|
||||
gameControllers.get(gameId).sendPlayerInteger(sessionId, data);
|
||||
}
|
||||
|
||||
public void concedeGame(UUID gameId, UUID sessionId) {
|
||||
public void concedeGame(UUID gameId, String sessionId) {
|
||||
if (gameControllers.containsKey(gameId))
|
||||
gameControllers.get(gameId).concede(sessionId);
|
||||
}
|
||||
|
||||
public void watchGame(UUID gameId, UUID sessionId) {
|
||||
public void watchGame(UUID gameId, String sessionId) {
|
||||
if (gameControllers.containsKey(gameId))
|
||||
gameControllers.get(gameId).watch(sessionId);
|
||||
}
|
||||
|
||||
public void stopWatching(UUID gameId, UUID sessionId) {
|
||||
public void stopWatching(UUID gameId, String sessionId) {
|
||||
if (gameControllers.containsKey(gameId))
|
||||
gameControllers.get(gameId).stopWatching(sessionId);
|
||||
}
|
||||
|
||||
public void removeSession(UUID sessionId) {
|
||||
public void removeSession(String sessionId) {
|
||||
for (GameController controller: gameControllers.values()) {
|
||||
controller.kill(sessionId);
|
||||
}
|
||||
}
|
||||
|
||||
public void kill(UUID gameId, UUID sessionId) {
|
||||
public void kill(UUID gameId, String sessionId) {
|
||||
if (gameControllers.containsKey(gameId))
|
||||
gameControllers.get(gameId).kill(sessionId);
|
||||
}
|
||||
|
||||
public void cheat(UUID gameId, UUID sessionId, UUID playerId, DeckCardLists deckList) {
|
||||
public void cheat(UUID gameId, String sessionId, UUID playerId, DeckCardLists deckList) {
|
||||
if (gameControllers.containsKey(gameId))
|
||||
gameControllers.get(gameId).cheat(sessionId, playerId, deckList);
|
||||
}
|
||||
|
||||
public boolean cheat(UUID gameId, UUID sessionId, UUID playerId, String cardName) {
|
||||
public boolean cheat(UUID gameId, String sessionId, UUID playerId, String cardName) {
|
||||
if (gameControllers.containsKey(gameId))
|
||||
return gameControllers.get(gameId).cheat(sessionId, playerId, cardName);
|
||||
return false;
|
||||
}
|
||||
|
||||
public void timeout(UUID gameId, UUID sessionId) {
|
||||
public void timeout(UUID gameId, String sessionId) {
|
||||
if (gameControllers.containsKey(gameId))
|
||||
gameControllers.get(gameId).timeout(sessionId);
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ public class GameManager {
|
|||
gameControllers.get(gameId).saveGame();
|
||||
}
|
||||
|
||||
public GameView getGameView(UUID gameId, UUID sessionId, UUID playerId) {
|
||||
public GameView getGameView(UUID gameId, String sessionId, UUID playerId) {
|
||||
if (gameControllers.containsKey(gameId))
|
||||
return gameControllers.get(gameId).getGameView(playerId);
|
||||
return null;
|
||||
|
|
|
@ -34,11 +34,8 @@ import java.util.Set;
|
|||
import java.util.UUID;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import mage.game.Game;
|
||||
import mage.MageException;
|
||||
import mage.interfaces.callback.CallbackException;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.server.Session;
|
||||
import mage.server.SessionManager;
|
||||
|
@ -61,7 +58,7 @@ public class GameSession extends GameWatcher {
|
|||
private ScheduledFuture<?> futureTimeout;
|
||||
protected static ScheduledExecutorService timeoutExecutor = ThreadExecutor.getInstance().getTimeoutExecutor();
|
||||
|
||||
public GameSession(Game game, UUID sessionId, UUID playerId) {
|
||||
public GameSession(Game game, String sessionId, UUID playerId) {
|
||||
super(sessionId, game.getId());
|
||||
this.game = game;
|
||||
this.playerId = playerId;
|
||||
|
@ -173,8 +170,6 @@ public class GameSession extends GameWatcher {
|
|||
private synchronized void cancelTimeout() {
|
||||
if (futureTimeout != null) {
|
||||
futureTimeout.cancel(false);
|
||||
((ThreadPoolExecutor)timeoutExecutor).getQueue().remove(futureTimeout);
|
||||
//System.out.println("tasks:"+ ((ThreadPoolExecutor)timeoutExecutor).getTaskCount());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -197,9 +192,4 @@ public class GameSession extends GameWatcher {
|
|||
cancelTimeout();
|
||||
game.getPlayer(playerId).setResponseInteger(data);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
cancelTimeout();
|
||||
setKilled();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,9 +30,6 @@ package mage.server.game;
|
|||
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import mage.MageException;
|
||||
import mage.interfaces.callback.CallbackException;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.server.Session;
|
||||
import mage.server.SessionManager;
|
||||
|
@ -48,11 +45,11 @@ public class GameWatcher {
|
|||
|
||||
protected final static Logger logger = Logger.getLogger(GameWatcher.class);
|
||||
|
||||
protected UUID sessionId;
|
||||
protected String sessionId;
|
||||
protected UUID gameId;
|
||||
protected boolean killed = false;
|
||||
|
||||
public GameWatcher(UUID sessionId, UUID gameId) {
|
||||
public GameWatcher(String sessionId, UUID gameId) {
|
||||
this.sessionId = sessionId;
|
||||
this.gameId = gameId;
|
||||
}
|
||||
|
|
|
@ -45,14 +45,14 @@ import mage.view.TableView;
|
|||
public interface GamesRoom extends Room {
|
||||
|
||||
public List<TableView> getTables();
|
||||
public boolean joinTable(UUID sessionId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException;
|
||||
public boolean joinTournamentTable(UUID sessionId, UUID tableId, String name, String playerType, int skill) throws GameException;
|
||||
public TableView createTable(UUID sessionId, MatchOptions options);
|
||||
public TableView createTournamentTable(UUID sessionId, TournamentOptions options);
|
||||
public void removeTable(UUID sessionId, UUID tableId);
|
||||
public boolean joinTable(String sessionId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException;
|
||||
public boolean joinTournamentTable(String sessionId, UUID tableId, String name, String playerType, int skill) throws GameException;
|
||||
public TableView createTable(String sessionId, MatchOptions options);
|
||||
public TableView createTournamentTable(String sessionId, TournamentOptions options);
|
||||
public void removeTable(String sessionId, UUID tableId);
|
||||
public void removeTable(UUID tableId);
|
||||
public TableView getTable(UUID tableId);
|
||||
public void leaveTable(UUID sessionId, UUID tableId);
|
||||
public boolean watchTable(UUID sessionId, UUID tableId) throws MageException;
|
||||
public void leaveTable(String sessionId, UUID tableId);
|
||||
public boolean watchTable(String sessionId, UUID tableId) throws MageException;
|
||||
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean joinTable(UUID sessionId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException {
|
||||
public boolean joinTable(String sessionId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException {
|
||||
if (tables.containsKey(tableId)) {
|
||||
return TableManager.getInstance().joinTable(sessionId, tableId, name, playerType, skill, deckList);
|
||||
} else {
|
||||
|
@ -73,14 +73,14 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TableView createTable(UUID sessionId, MatchOptions options) {
|
||||
public TableView createTable(String sessionId, MatchOptions options) {
|
||||
Table table = TableManager.getInstance().createTable(this.getRoomId(), sessionId, options);
|
||||
tables.put(table.getId(), table);
|
||||
return new TableView(table);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean joinTournamentTable(UUID sessionId, UUID tableId, String name, String playerType, int skill) throws GameException {
|
||||
public boolean joinTournamentTable(String sessionId, UUID tableId, String name, String playerType, int skill) throws GameException {
|
||||
if (tables.containsKey(tableId)) {
|
||||
return TableManager.getInstance().joinTournament(sessionId, tableId, name, playerType, skill);
|
||||
} else {
|
||||
|
@ -89,7 +89,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TableView createTournamentTable(UUID sessionId, TournamentOptions options) {
|
||||
public TableView createTournamentTable(String sessionId, TournamentOptions options) {
|
||||
Table table = TableManager.getInstance().createTournamentTable(this.getRoomId(), sessionId, options);
|
||||
tables.put(table.getId(), table);
|
||||
return new TableView(table);
|
||||
|
@ -103,7 +103,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void removeTable(UUID sessionId, UUID tableId) {
|
||||
public void removeTable(String sessionId, UUID tableId) {
|
||||
tables.remove(tableId);
|
||||
}
|
||||
|
||||
|
@ -115,12 +115,12 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void leaveTable(UUID sessionId, UUID tableId) {
|
||||
public void leaveTable(String sessionId, UUID tableId) {
|
||||
TableManager.getInstance().leaveTable(sessionId, tableId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean watchTable(UUID sessionId, UUID tableId) throws MageException {
|
||||
public boolean watchTable(String sessionId, UUID tableId) throws MageException {
|
||||
return TableManager.getInstance().watchTable(sessionId, tableId);
|
||||
}
|
||||
|
||||
|
|
|
@ -48,25 +48,25 @@ public class ReplayManager {
|
|||
|
||||
private ConcurrentHashMap<String, ReplaySession> replaySessions = new ConcurrentHashMap<String, ReplaySession>();
|
||||
|
||||
public void replayGame(UUID gameId, UUID sessionId) {
|
||||
public void replayGame(UUID gameId, String sessionId) {
|
||||
ReplaySession replaySession = new ReplaySession(gameId, sessionId);
|
||||
replaySessions.put(gameId.toString() + sessionId.toString(), replaySession);
|
||||
SessionManager.getInstance().getSession(sessionId).replayGame(gameId);
|
||||
}
|
||||
|
||||
public void startReplay(UUID gameId, UUID sessionId) {
|
||||
public void startReplay(UUID gameId, String sessionId) {
|
||||
replaySessions.get(gameId.toString() + sessionId.toString()).replay();
|
||||
}
|
||||
|
||||
public void stopReplay(UUID gameId, UUID sessionId) {
|
||||
public void stopReplay(UUID gameId, String sessionId) {
|
||||
replaySessions.get(gameId.toString() + sessionId.toString()).stop();
|
||||
}
|
||||
|
||||
public void nextPlay(UUID gameId, UUID sessionId) {
|
||||
public void nextPlay(UUID gameId, String sessionId) {
|
||||
replaySessions.get(gameId.toString() + sessionId.toString()).next();
|
||||
}
|
||||
|
||||
public void previousPlay(UUID gameId, UUID sessionId) {
|
||||
public void previousPlay(UUID gameId, String sessionId) {
|
||||
replaySessions.get(gameId.toString() + sessionId.toString()).previous();
|
||||
}
|
||||
|
||||
|
|
|
@ -31,8 +31,6 @@ package mage.server.game;
|
|||
import java.util.UUID;
|
||||
import mage.game.Game;
|
||||
import mage.game.GameState;
|
||||
import mage.MageException;
|
||||
import mage.interfaces.callback.CallbackException;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.server.Session;
|
||||
import mage.server.SessionManager;
|
||||
|
@ -47,9 +45,9 @@ public class ReplaySession implements GameCallback {
|
|||
|
||||
private final static Logger logger = Logger.getLogger(ReplaySession.class);
|
||||
private GameReplay replay;
|
||||
protected UUID sessionId;
|
||||
protected String sessionId;
|
||||
|
||||
ReplaySession(UUID gameId, UUID sessionId) {
|
||||
ReplaySession(UUID gameId, String sessionId) {
|
||||
this.replay = new GameReplay(gameId);
|
||||
this.sessionId = sessionId;
|
||||
}
|
||||
|
|
|
@ -64,10 +64,10 @@ public class TournamentController {
|
|||
private UUID chatId;
|
||||
private UUID tableId;
|
||||
private Tournament tournament;
|
||||
private ConcurrentHashMap<UUID, UUID> sessionPlayerMap = new ConcurrentHashMap<UUID, UUID>();
|
||||
private ConcurrentHashMap<String, UUID> sessionPlayerMap = new ConcurrentHashMap<String, UUID>();
|
||||
private ConcurrentHashMap<UUID, TournamentSession> tournamentSessions = new ConcurrentHashMap<UUID, TournamentSession>();
|
||||
|
||||
public TournamentController(Tournament tournament, ConcurrentHashMap<UUID, UUID> sessionPlayerMap, UUID tableId) {
|
||||
public TournamentController(Tournament tournament, ConcurrentHashMap<String, UUID> sessionPlayerMap, UUID tableId) {
|
||||
sessionId = UUID.randomUUID();
|
||||
this.sessionPlayerMap = sessionPlayerMap;
|
||||
chatId = ChatManager.getInstance().createChatSession();
|
||||
|
@ -128,7 +128,7 @@ public class TournamentController {
|
|||
checkStart();
|
||||
}
|
||||
|
||||
public synchronized void join(UUID sessionId) {
|
||||
public synchronized void join(String sessionId) {
|
||||
UUID playerId = sessionPlayerMap.get(sessionId);
|
||||
TournamentSession tournamentSession = new TournamentSession(tournament, sessionId, tableId, playerId);
|
||||
tournamentSessions.put(playerId, tournamentSession);
|
||||
|
@ -196,16 +196,16 @@ public class TournamentController {
|
|||
TableManager.getInstance().construct(tableId);
|
||||
}
|
||||
|
||||
private void construct(UUID sessionId, Deck deck, int timeout) throws MageException {
|
||||
if (tournamentSessions.containsKey(sessionId))
|
||||
tournamentSessions.get(sessionId).construct(deck, timeout);
|
||||
private void construct(UUID playerId, Deck deck, int timeout) throws MageException {
|
||||
if (tournamentSessions.containsKey(playerId))
|
||||
tournamentSessions.get(playerId).construct(deck, timeout);
|
||||
}
|
||||
|
||||
public void submitDeck(UUID sessionId, Deck deck) {
|
||||
tournamentSessions.get(sessionPlayerMap.get(sessionId)).submitDeck(deck);
|
||||
public void submitDeck(UUID playerId, Deck deck) {
|
||||
tournamentSessions.get(playerId).submitDeck(deck);
|
||||
}
|
||||
|
||||
public void timeout(UUID sessionId) {
|
||||
public void timeout(String sessionId) {
|
||||
if (sessionPlayerMap.containsKey(sessionId)) {
|
||||
TournamentPlayer player = tournament.getPlayer(sessionPlayerMap.get(sessionId));
|
||||
tournament.autoSubmit(sessionPlayerMap.get(sessionId), player.getDeck());
|
||||
|
@ -220,7 +220,7 @@ public class TournamentController {
|
|||
return chatId;
|
||||
}
|
||||
|
||||
public void kill(UUID sessionId) {
|
||||
public void kill(String sessionId) {
|
||||
if (sessionPlayerMap.containsKey(sessionId)) {
|
||||
tournamentSessions.get(sessionPlayerMap.get(sessionId)).setKilled();
|
||||
tournamentSessions.remove(sessionPlayerMap.get(sessionId));
|
||||
|
@ -229,16 +229,16 @@ public class TournamentController {
|
|||
}
|
||||
}
|
||||
|
||||
private void leave(UUID sessionId) {
|
||||
private void leave(String sessionId) {
|
||||
tournament.leave(getPlayerId(sessionId));
|
||||
}
|
||||
|
||||
private UUID getPlayerId(UUID sessionId) {
|
||||
private UUID getPlayerId(String sessionId) {
|
||||
return sessionPlayerMap.get(sessionId);
|
||||
}
|
||||
|
||||
private UUID getPlayerSessionId(UUID playerId) {
|
||||
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
|
||||
private String getPlayerSessionId(UUID playerId) {
|
||||
for (Entry<String, UUID> entry: sessionPlayerMap.entrySet()) {
|
||||
if (entry.getValue().equals(playerId))
|
||||
return entry.getKey();
|
||||
}
|
||||
|
|
|
@ -48,26 +48,26 @@ public class TournamentManager {
|
|||
return INSTANCE;
|
||||
}
|
||||
|
||||
public UUID createTournamentSession(Tournament tournament, ConcurrentHashMap<UUID, UUID> sessionPlayerMap, UUID tableId) {
|
||||
public UUID createTournamentSession(Tournament tournament, ConcurrentHashMap<String, UUID> sessionPlayerMap, UUID tableId) {
|
||||
TournamentController tournamentController = new TournamentController(tournament, sessionPlayerMap, tableId);
|
||||
controllers.put(tournament.getId(), tournamentController);
|
||||
return tournamentController.getSessionId();
|
||||
}
|
||||
|
||||
public void joinTournament(UUID tournamentId, UUID sessionId) {
|
||||
public void joinTournament(UUID tournamentId, String sessionId) {
|
||||
controllers.get(tournamentId).join(sessionId);
|
||||
}
|
||||
|
||||
public void kill(UUID tournamentId, UUID sessionId) {
|
||||
public void kill(UUID tournamentId, String sessionId) {
|
||||
controllers.get(tournamentId).kill(sessionId);
|
||||
}
|
||||
|
||||
public void timeout(UUID tournamentId, UUID sessionId) {
|
||||
public void timeout(UUID tournamentId, String sessionId) {
|
||||
controllers.get(tournamentId).timeout(sessionId);
|
||||
}
|
||||
|
||||
public void submitDeck(UUID tournamentId, UUID sessionId, Deck deck) {
|
||||
controllers.get(tournamentId).submitDeck(sessionId, deck);
|
||||
public void submitDeck(UUID tournamentId, UUID playerId, Deck deck) {
|
||||
controllers.get(tournamentId).submitDeck(playerId, deck);
|
||||
}
|
||||
|
||||
public TournamentView getTournamentView(UUID tournamentId) {
|
||||
|
|
|
@ -32,13 +32,10 @@ import java.rmi.RemoteException;
|
|||
import java.util.UUID;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.game.tournament.Tournament;
|
||||
import mage.MageException;
|
||||
import mage.interfaces.callback.CallbackException;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.server.Session;
|
||||
import mage.server.SessionManager;
|
||||
|
@ -53,7 +50,7 @@ import org.apache.log4j.Logger;
|
|||
public class TournamentSession {
|
||||
protected final static Logger logger = Logger.getLogger(TournamentSession.class);
|
||||
|
||||
protected UUID sessionId;
|
||||
protected String sessionId;
|
||||
protected UUID playerId;
|
||||
protected UUID tableId;
|
||||
protected Tournament tournament;
|
||||
|
@ -62,7 +59,7 @@ public class TournamentSession {
|
|||
private ScheduledFuture<?> futureTimeout;
|
||||
protected static ScheduledExecutorService timeoutExecutor = ThreadExecutor.getInstance().getTimeoutExecutor();
|
||||
|
||||
public TournamentSession(Tournament tournament, UUID sessionId, UUID tableId, UUID playerId) {
|
||||
public TournamentSession(Tournament tournament, String sessionId, UUID tableId, UUID playerId) {
|
||||
this.sessionId = sessionId;
|
||||
this.tournament = tournament;
|
||||
this.playerId = playerId;
|
||||
|
@ -147,7 +144,6 @@ public class TournamentSession {
|
|||
private synchronized void cancelTimeout() {
|
||||
if (futureTimeout != null) {
|
||||
futureTimeout.cancel(false);
|
||||
((ThreadPoolExecutor)timeoutExecutor).getQueue().remove(futureTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue