Class GameServerSide
java.lang.Object
net.sf.colossus.game.Game
net.sf.colossus.server.GameServerSide
- Direct Known Subclasses:
GameServerSideTestAccess
Class Game gets and holds high-level data about a Titan game.
This is the old design with the game information in the server. Some
of the functionality here is supposed to be moved into the
Game
class which then can be shared between server and clients (the class, not the instances).
Other parts should be moved into the Server class or elsewhere.- Author:
- David Ripton, Bruce Sherrod, Romain Dolbeau
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) classWrap the complexity of phase advancing. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate intprivate booleanprivate final BattleStrikeServerSideprivate final LinkedList<Player> private List<PlayerColor> private Playerprivate Stringprivate Stringprivate static intprivate final Stringprivate final GameSavingThe object that handles the Game Saving procedureprivate Historyprivate Stringprivate booleanprivate PrintWriterThe file where to send the spectator messages.private booleanFrom the very first autosave file name, we derive the file where to store all the messages that are sent to the internal spectator client.private intprivate booleanprivate static final Loggerprivate final MovementServerSideprivate INotifyWebServerprivate final Optionsprivate booleanprivate final PhaseAdvancerprivate intprivate booleanprivate booleanprivate Server(package private) booleanprivate WebClientprivate booleanprivate int(package private) Objectprivate final WhatNextManagerprivate LegionFields inherited from class Game
battle, phase, players, turnNumber -
Constructor Summary
ConstructorsConstructorDescriptionGameServerSide(WhatNextManager whatNextMgr, Options serverOptions, Variant variant) The normal constructor to be used everywhere -
Method Summary
Modifier and TypeMethodDescriptionvoidacquireMaybe(LegionServerSide legion, int scoreBeforeAdd, int pointsToAdd) If the legion can acquire (height invalid input: '<' 7), find out which acquirable it might get for the pointsToAdd, and fire off the askAcquirable messages.voidactOnWaitForClientsCompleted(boolean gotAll) (package private) voidaddCreatureEvent(AddCreatureAction event, String reason) private void(package private) voidadvancePhase(Phase oldPhase, Player player) Advance to the next phase, only if the passed oldPhase and playerName are current.private voidannounceGameOver(boolean disposeFollows) private booleananonymousRecruitLegal(Legion legion, CreatureType recruit) Return true if this legion can recruit this recruit without disclosing a recruiter.(package private) voidaskAcquireAngel(PlayerServerSide player, Legion legion, List<CreatureType> recruits) (package private) voidassignColor(Player player, PlayerColor color) private voidprivate voidRandomize towers by rolling dice and rerolling ties.(package private) voidautoSave()private void(package private) voidprivate voidprivate void(package private) void(package private) PlayerServerSidecreateAndAddPlayer(String name, String shortTypeName) voidcreateBattle(Legion attacker, Legion defender, BattleServerSide.LegionTags activeLegionTag, MasterHex engagementHex, BattlePhase battlePhase) private voidprivate voidcreateLocalClient(PlayerServerSide player, boolean createGUI, String type) void(package private) voidcreateSummonAngel(Legion attacker) (package private) voiddispose()(package private) StringdoMove(Legion legion, MasterHex hex, EntrySide entrySide, boolean teleport, CreatureType teleportingLord) Move the legion to the hex if legal.(package private) void(package private) void(package private) voiddoNotConcede(Legion legion) Used only for pre-battle attacker concession.(package private) void(package private) voiddoRecruit(Legion legion, CreatureType recruit, CreatureType recruiter) Add recruit to legion.(package private) booleandoSplit(Legion parent, String childId, List<CreatureType> creaturesToSplit) Return true and call Server.didSplit() if the split succeeded.(package private) voidHandles summoning of a creature.voideditModeAddCreature(String markerId, String creatureName) voideditModeRelocateLegion(String markerId, String hexLabel) voideditModeRemoveCreature(String markerId, String creatureName) (package private) voidprivate voidprivate void(package private) voidprivate List<CreatureType> findEligibleRecruiters(Legion legion, String recruitName) Return a list of eligible recruiter creatures.(package private) List<CreatureType> findEligibleRecruits(Legion legion, MasterHex hex) Return a list of eligible recruits, as Creatures.(package private) PlayerfindNetworkPlayer(String playerName) Find a Player for a new remote client.(package private) voidfinishBattle(MasterHex masterHex, boolean attackerEntered, int points, int turnDone) (package private) voidboolean(package private) Player(package private) intgetBalancedTowers(int numPlayers, List<MasterHex> towerList) Return a list with a balanced order of numPlayer towers chosen from towerList, which must hold numeric strings.(package private) BattleServerSide(package private) History(package private) intgetIntOption(String optname) getLegionByMarkerId(String markerId) int(package private) Player(package private) INotifyWebServer(package private) boolean(package private) IOptionsgetPlayerByMarkerId(String markerId) (package private) PlayergetPlayerByName(String playerName) Resolve playerName into Player object.(package private) PlayergetPlayerByNameIgnoreNull(String playerName) Resolve playerName into Player object.(package private) PlayergetPlayerByShortColor(String shortColor) NOTE: to be used only during loading a Game! Client side has a more sophisticated version that takes slain players and their inherited markers into account.private PlayergetPlayerUsingColor(String shortColor) private intgetPort()(package private) Serverprivate LegionServerSidegetStartingLegion(String markerId, MasterHex hex, Player player) (package private) StringgetUniqueName(String name, Player player) If the name is taken, add random digits to the end.private Playerprivate voidhandleConcession(Legion loser, Legion winner, boolean fled) private voidhandleNegotiation(Proposal results) (package private) voidhandlePlayerWithdrawal(Player player) A player requested he wants to withdraw (or connection was lost, and server socket handling does withdraw then).booleanhasConventionalMove(LegionServerSide legion, MasterHex hex, int roll, boolean ignoreFriends) private voidprivate voidprivate booleanSo far, we do autosave only at begin of each players turn, i.e.(package private) boolean(package private) boolean(package private) booleanvoid(package private) voidlegionMoveEvent(Legion legion, MasterHex newHex, EntrySide entrySide, boolean teleport, CreatureType lord) (package private) voidlegionUndoMoveEvent(Legion legion) booleanloadGame(org.jdom.Element root) (package private) booleanbooleanloadGameAndWaitUntilOver(org.jdom.Element root) private voidprivate StringmakeNameByType(String templateName, String type) (package private) static GameServerSidemakeNewGameServerSide(Variant variant) Shortcut for UnitTests, to create a Game with dummy input objects on the fly.(package private) voidmakeProposal(String playerName, String proposalString) playerName offers proposal.(package private) voidmergeEvent(String splitoffId, String survivorId) (package private) voidmovementRollEvent(Player player, int roll) (package private) intmulligan()private booleannameIsTaken(String name, Player checkedPlayer) (package private) booleanStart a new game.(package private) voidnewGame2()private voidnewGame3()Done picking player colors; proceed to start game.static GameServerSidenewGameServerSide(WhatNextManager whatNextMgr, Options serverOptions, Variant variant) For more complicated functional tests(package private) voidprotected voidprivate voidplaceInitialLegion(PlayerServerSide player, String markerId) (package private) voidplayerElimEvent(Player player, Player slayer) private voidreadLegion(org.jdom.Element leg, PlayerServerSide player) (package private) voidrecruitEvent(Legion legion, CreatureType recruit, CreatureType recruiter) (package private) voidCalled locally and from Battle.(package private) voidremoveCreatureEvent(Legion legion, CreatureType creature, String reason) private boolean(package private) voidrevealEvent(boolean allPlayers, List<Player> players, Legion legion, List<CreatureType> creatureNames, String reason) (package private) voidsaveGameWithErrorHandling(String filename, boolean autoSave) private voidsetEngagementResult(String aResult, Legion winner, int aPoints, int aTurn) voidsetFlagFilename(String flagFilename) voidsetGameOver(boolean gameOver, String message) private voidprivate voidprivate voidprivate voidprivate voidprivate voidTemporary solution ...(package private) voidsplitEvent(Legion parent, Legion child, List<CreatureType> splitoffs) booleanstartNewGameAndWaitUntilOver(String hostingPlayer) private booleanvoidprotected voidstoreLocalClient(String playerName, Client c) private voidSend all current game option values to all clients.(package private) void(package private) voidundoRecruitEvent(Legion legion) voidUpdate the dead and available counts for all creature types on all clients.private voidUpdate the dead and available counts for a creature type on all clients.protected voidMethods inherited from class Game
addPlayer, clearEngagementData, containsOpposingLegions, createEngagement, findEngagements, findLegionsWithSummonables, getAllLegions, getAttacker, getBattle, getBattleActiveLegion, getBattleSite, getBattleStrike, getBattleTurnNumber, getCaretaker, getDefender, getEnemyLegions, getEnemyLegions, getEngagement, getFirstEnemyLegion, getFirstFriendlyLegion, getFirstLegion, getFriendlyLegions, getGameOverMessage, getLegionsByHex, getNumEnemyLegions, getNumFriendlyLegions, getNumHumansRemaining, getNumLegions, getNumLivingCreatures, getNumLivingPlayers, getNumPlayers, getNumRemoteRemaining, getPhase, getPlayers, getPreliminaryPlayerNames, getTurnNumber, getVariant, isEngagementInProgress, isEngagementOngoing, isGameOver, isOccupied, isPhase, onlyAIsRemain, setMovementRoll, setPhase, setTurnNumber
-
Field Details
-
LOGGER
-
activePlayerNum
private int activePlayerNum -
lastRecruitTurnNumber
private int lastRecruitTurnNumber -
battleInProgress
private boolean battleInProgress -
summoning
private boolean summoning -
reinforcing
private boolean reinforcing -
acquiring
private boolean acquiring -
pointsScored
private int pointsScored -
turnCombatFinished
private int turnCombatFinished -
winner
-
engagementResult
-
pendingAdvancePhase
private boolean pendingAdvancePhase -
loadingGame
private boolean loadingGame -
replayOngoing
private boolean replayOngoing -
server
-
attackerProposals
-
defenderProposals
-
colorPickOrder
-
colorsLeft
-
phaseAdvancer
-
options
-
hostingPlayerName
-
flagFilename
-
notifyWebServer
-
startingWebClient
-
whatNextManager
-
history
-
battleStrikeSS
-
movementSS
-
gameSaver
The object that handles the Game Saving procedure -
isFirstAutoSave
private boolean isFirstAutoSaveFrom the very first autosave file name, we derive the file where to store all the messages that are sent to the internal spectator client. -
iscMessages
The file where to send the spectator messages. Might/will be null when autosave disabled. -
gameCounter
private static int gameCounter -
gameId
-
hotSeatMode
private boolean hotSeatMode -
cvbPlayer
-
waitForClientsMutex
Object waitForClientsMutex -
serverGotAll
boolean serverGotAll
-
-
Constructor Details
-
GameServerSide
The normal constructor to be used everywhere- Parameters:
whatNextMgr- A WhatNextManager object which manages the main control flow which thing to do 'next' when this game is over.serverOptions- The server side options, initialized from the GetPlayers dialog and/or command line options.variant- Variant of this game
-
-
Method Details
-
makeNewGameServerSide
Shortcut for UnitTests, to create a Game with dummy input objects on the fly. -
newGameServerSide
public static GameServerSide newGameServerSide(WhatNextManager whatNextMgr, Options serverOptions, Variant variant) For more complicated functional tests- Parameters:
whatNextMgr-serverOptions-variant-- Returns:
-
setFlagFilename
-
getHostingPlayer
-
getPort
private int getPort() -
initServer
private void initServer() -
actOnWaitForClientsCompleted
public void actOnWaitForClientsCompleted(boolean gotAll) -
startServerAndWaitUntilNotifiedThatWaitForClientsCompleted
private boolean startServerAndWaitUntilNotifiedThatWaitForClientsCompleted() -
createLocalClients
public void createLocalClients() -
createLocalClient
-
createInternalDummyClient
private void createInternalDummyClient() -
storeLocalClient
-
updateCaretakerDisplaysFor
Update the dead and available counts for a creature type on all clients. -
updateCaretakerDisplays
public void updateCaretakerDisplays()Update the dead and available counts for all creature types on all clients. -
waitUntilGameFinishes
protected void waitUntilGameFinishes() -
cleanupWhenGameOver
private void cleanupWhenGameOver() -
clearFlags
private void clearFlags() -
addPlayersFromOptions
private void addPlayersFromOptions() -
startNewGameAndWaitUntilOver
-
newGame
Start a new game. -
newGame2
void newGame2() -
sortPlayersDescendingTower
private void sortPlayersDescendingTower()Temporary solution ... I do not know a better way how to do the sorting on players (type List) itself. I don't want to pull up the Comparator predicate, because ClientSide might have totally different idea of the right "order"... -
nameIsTaken
-
getUniqueName
-
findNetworkPlayer
-
syncOptions
private void syncOptions()Send all current game option values to all clients. -
assignColors
private void assignColors() -
nextPickColor
void nextPickColor() -
makeNameByType
-
assignColor
-
getNextColorPicker
Player getNextColorPicker() -
newGame3
private void newGame3()Done picking player colors; proceed to start game. -
assignTowers
private void assignTowers()Randomize towers by rolling dice and rerolling ties. -
getBalancedTowers
-
getServer
Server getServer() -
createAndAddPlayer
-
getActivePlayerNum
int getActivePlayerNum() -
getActivePlayer
Player getActivePlayer() -
makeMovementRoll
private void makeMovementRoll() -
getMovementRoll
public int getMovementRoll()- Overrides:
getMovementRollin classGame
-
getPlayerByNameIgnoreNull
-
getPlayerByName
Resolve playerName into Player object. Name must not be null. If no player for given name found, it would throw IllegalArgumentException (well, did earlier, at the moment (03/2012) replace with SEVERE error; exception would totally throw server thread out of the orbit...)- Parameters:
playerName-- Returns:
- Player object for given name.
-
getPlayerByShortColor
-
handlePlayerWithdrawal
A player requested he wants to withdraw (or connection was lost, and server socket handling does withdraw then).- Parameters:
player- The player that wishes to withdraw from the game TODO Notify all players.
-
getWinner
-
checkForVictory
void checkForVictory() -
announceGameOver
private void announceGameOver(boolean disposeFollows) -
isLoadingGame
boolean isLoadingGame() -
isReplayOngoing
boolean isReplayOngoing() -
stopAllDueToFunctionalTestCompleted
public void stopAllDueToFunctionalTestCompleted() -
kickstartGame
public void kickstartGame() -
notifyTestCaseGameIsUpNow
protected void notifyTestCaseGameIsUpNow() -
advancePhase
-
setGameOver
- Overrides:
setGameOverin classGame
-
setupPhase
private void setupPhase() -
setupSplit
private void setupSplit() -
hotSeatModeChangeBoards
private void hotSeatModeChangeBoards() -
setupMove
private void setupMove() -
setupFight
private void setupFight() -
setupMuster
private void setupMuster() -
isAutoSavePoint
private boolean isAutoSavePoint()So far, we do autosave only at begin of each players turn, i.e. when a split phase was just set up.- Returns:
- Whether now is a time when autosave is due.
-
autoSave
void autoSave() -
getIscMessageFile
-
saveGameWithErrorHandling
-
loadGameAndWaitUntilOver
public boolean loadGameAndWaitUntilOver(org.jdom.Element root) -
loadGame
public boolean loadGame(org.jdom.Element root) -
createBattle
public void createBattle(Legion attacker, Legion defender, BattleServerSide.LegionTags activeLegionTag, MasterHex engagementHex, BattlePhase battlePhase) -
readLegion
private void readLegion(org.jdom.Element leg, PlayerServerSide player) throws org.jdom.DataConversionException - Throws:
org.jdom.DataConversionException
-
loadGame2
boolean loadGame2() -
resyncBackupData
private boolean resyncBackupData() -
findEligibleRecruits
Return a list of eligible recruits, as Creatures. TODO second parameter is probably superfluous -
findEligibleRecruiters
Return a list of eligible recruiter creatures. -
anonymousRecruitLegal
Return true if this legion can recruit this recruit without disclosing a recruiter. -
doRecruit
Add recruit to legion. -
editModeAddCreature
-
editModeRemoveCreature
-
editModeRelocateLegion
-
acquireMaybe
If the legion can acquire (height invalid input: '<' 7), find out which acquirable it might get for the pointsToAdd, and fire off the askAcquirable messages.- Parameters:
legion- Legion which earned the points and thus is entitled to get the acqirablescoreBeforeAdd- Score from which to startpointsToAdd- How many points were earned
-
dispose
void dispose() -
placeInitialLegion
-
hasConventionalMove
public boolean hasConventionalMove(LegionServerSide legion, MasterHex hex, int roll, boolean ignoreFriends) -
createSummonAngel
-
reinforce
Called locally and from Battle. -
doneReinforcing
void doneReinforcing() -
doSummon
Handles summoning of a creature.- Parameters:
event- The summoning event (or null if summoning is to be skipped) TODO get rid of downcasts
-
getBattleSS
BattleServerSide getBattleSS() -
isBattleInProgress
boolean isBattleInProgress() -
getHistory
History getHistory() -
finishBattle
-
doSplit
Return true and call Server.didSplit() if the split succeeded. Return false if it failed. -
doMove
String doMove(Legion legion, MasterHex hex, EntrySide entrySide, boolean teleport, CreatureType teleportingLord) Move the legion to the hex if legal. Return a string telling the reason why it is illegal, or null if ok and move was done. -
undoMove
-
engage
-
engage2
-
engage3
-
flee
-
concede
-
doNotFlee
-
doNotConcede
Used only for pre-battle attacker concession. -
makeProposal
-
fight
-
handleConcession
-
handleNegotiation
-
askAcquireAngel
-
doneAcquiringAngels
void doneAcquiringAngels() -
setEngagementResult
-
checkEngagementDone
private void checkEngagementDone() -
gameShouldContinue
public boolean gameShouldContinue() -
getLegionByMarkerId
- Overrides:
getLegionByMarkerIdin classGame
-
getPlayerByMarkerId
-
getPlayerUsingColor
-
getStartingLegion
-
mulligan
int mulligan() -
getOptions
IOptions getOptions() -
getOption
-
getIntOption
-
addCreatureEvent
-
removeCreatureEvent
-
splitEvent
-
mergeEvent
-
revealEvent
-
playerElimEvent
-
movementRollEvent
-
legionMoveEvent
void legionMoveEvent(Legion legion, MasterHex newHex, EntrySide entrySide, boolean teleport, CreatureType lord) -
legionUndoMoveEvent
-
recruitEvent
-
undoRecruitEvent
-
getNotifyWebServer
INotifyWebServer getNotifyWebServer() -
getBattleStrikeSS
-