mirror of
https://github.com/correl/mage.git
synced 2024-12-24 03:00:14 +00:00
...
This commit is contained in:
parent
01d5a3cbed
commit
2f32d2e6cf
3 changed files with 73 additions and 3 deletions
|
@ -93,6 +93,9 @@ public class GameController implements GameCallback {
|
|||
ChatManager.getInstance().broadcast(chatId, "", event.getMessage());
|
||||
logger.finest(game.getId() + " " + event.getMessage());
|
||||
break;
|
||||
case REVEAL:
|
||||
revealCards(event.getMessage(), event.getCards());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
64
Mage.Server/src/mage/server/game/GameReplay.java
Normal file
64
Mage.Server/src/mage/server/game/GameReplay.java
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* 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.game;
|
||||
|
||||
import mage.game.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class GameReplay {
|
||||
|
||||
private GameStates savedGame;
|
||||
private int stateIndex;
|
||||
|
||||
public GameReplay(GameStates savedGame) {
|
||||
this.savedGame = savedGame;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
this.stateIndex = 0;
|
||||
}
|
||||
|
||||
public GameState next() {
|
||||
if (this.stateIndex < savedGame.getSize()) {
|
||||
return savedGame.get(stateIndex++);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public GameState previous() {
|
||||
if (this.stateIndex > 0) {
|
||||
return savedGame.get(--stateIndex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -36,7 +36,6 @@ import java.io.FileOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutput;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
|
@ -46,6 +45,8 @@ import java.util.UUID;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
import mage.Constants.TableState;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
|
@ -57,6 +58,7 @@ import mage.players.Player;
|
|||
import mage.server.ChatManager;
|
||||
import mage.server.Main;
|
||||
import mage.server.SessionManager;
|
||||
import mage.util.CopierObjectInputStream;
|
||||
import mage.util.Logging;
|
||||
|
||||
/**
|
||||
|
@ -170,7 +172,7 @@ public class TableController {
|
|||
//use buffering
|
||||
OutputStream file = new FileOutputStream("saved/" + game.getId().toString() + ".game");
|
||||
OutputStream buffer = new BufferedOutputStream(file);
|
||||
ObjectOutput output = new ObjectOutputStream(buffer);
|
||||
ObjectOutput output = new ObjectOutputStream(new GZIPOutputStream(buffer));
|
||||
try {
|
||||
output.writeObject(game.getGameStates());
|
||||
}
|
||||
|
@ -189,7 +191,8 @@ public class TableController {
|
|||
//use buffering
|
||||
InputStream file = new FileInputStream("saved/" + gameId.toString() + ".game");
|
||||
InputStream buffer = new BufferedInputStream(file);
|
||||
ObjectInput input = new ObjectInputStream(buffer);
|
||||
ObjectInput input = new CopierObjectInputStream(Main.classLoader, new GZIPInputStream(buffer));
|
||||
//ObjectInput input = new ObjectInputStream(buffer);
|
||||
try {
|
||||
//deserialize the List
|
||||
GameStates gameStates = (GameStates)input.readObject();
|
||||
|
|
Loading…
Reference in a new issue