Package net.sf.colossus.server
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) class
Wrap the complexity of phase advancing. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private int
private boolean
private final BattleStrikeServerSide
private final LinkedList
<Player> private List
<PlayerColor> private Player
private String
private String
private static int
private final String
private final GameSaving
The object that handles the Game Saving procedureprivate History
private String
private boolean
private PrintWriter
The file where to send the spectator messages.private boolean
From 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 int
private boolean
private static final Logger
private final MovementServerSide
private INotifyWebServer
private final Options
private boolean
private final PhaseAdvancer
private int
private boolean
private boolean
private Server
(package private) boolean
private WebClient
private boolean
private int
(package private) Object
private final WhatNextManager
private Legion
Fields inherited from class net.sf.colossus.game.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 TypeMethodDescriptionvoid
acquireMaybe
(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.void
actOnWaitForClientsCompleted
(boolean gotAll) (package private) void
addCreatureEvent
(AddCreatureAction event, String reason) private void
(package private) void
advancePhase
(Phase oldPhase, Player player) Advance to the next phase, only if the passed oldPhase and playerName are current.private void
announceGameOver
(boolean disposeFollows) private boolean
anonymousRecruitLegal
(Legion legion, CreatureType recruit) Return true if this legion can recruit this recruit without disclosing a recruiter.(package private) void
askAcquireAngel
(PlayerServerSide player, Legion legion, List<CreatureType> recruits) (package private) void
assignColor
(Player player, PlayerColor color) private void
private void
Randomize towers by rolling dice and rerolling ties.(package private) void
autoSave()
private void
(package private) void
private void
private void
(package private) void
(package private) PlayerServerSide
createAndAddPlayer
(String name, String shortTypeName) void
createBattle
(Legion attacker, Legion defender, BattleServerSide.LegionTags activeLegionTag, MasterHex engagementHex, BattlePhase battlePhase) private void
private void
createLocalClient
(PlayerServerSide player, boolean createGUI, String type) void
(package private) void
createSummonAngel
(Legion attacker) (package private) void
dispose()
(package private) String
doMove
(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) void
doNotConcede
(Legion legion) Used only for pre-battle attacker concession.(package private) void
(package private) void
doRecruit
(Legion legion, CreatureType recruit, CreatureType recruiter) Add recruit to legion.(package private) boolean
doSplit
(Legion parent, String childId, List<CreatureType> creaturesToSplit) Return true and call Server.didSplit() if the split succeeded.(package private) void
Handles summoning of a creature.void
editModeAddCreature
(String markerId, String creatureName) void
editModeRelocateLegion
(String markerId, String hexLabel) void
editModeRemoveCreature
(String markerId, String creatureName) (package private) void
private void
private void
(package private) void
private 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) Player
findNetworkPlayer
(String playerName) Find a Player for a new remote client.(package private) void
finishBattle
(MasterHex masterHex, boolean attackerEntered, int points, int turnDone) (package private) void
boolean
(package private) Player
(package private) int
getBalancedTowers
(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) int
getIntOption
(String optname) getLegionByMarkerId
(String markerId) int
(package private) Player
(package private) INotifyWebServer
(package private) boolean
(package private) IOptions
getPlayerByMarkerId
(String markerId) (package private) Player
getPlayerByName
(String playerName) Resolve playerName into Player object.(package private) Player
getPlayerByNameIgnoreNull
(String playerName) Resolve playerName into Player object.(package private) Player
getPlayerByShortColor
(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 Player
getPlayerUsingColor
(String shortColor) private int
getPort()
(package private) Server
private LegionServerSide
getStartingLegion
(String markerId, MasterHex hex, Player player) (package private) String
getUniqueName
(String name, Player player) If the name is taken, add random digits to the end.private Player
private void
handleConcession
(Legion loser, Legion winner, boolean fled) private void
handleNegotiation
(Proposal results) (package private) void
handlePlayerWithdrawal
(Player player) A player requested he wants to withdraw (or connection was lost, and server socket handling does withdraw then).boolean
hasConventionalMove
(LegionServerSide legion, MasterHex hex, int roll, boolean ignoreFriends) private void
private void
private boolean
So far, we do autosave only at begin of each players turn, i.e.(package private) boolean
(package private) boolean
(package private) boolean
void
(package private) void
legionMoveEvent
(Legion legion, MasterHex newHex, EntrySide entrySide, boolean teleport, CreatureType lord) (package private) void
legionUndoMoveEvent
(Legion legion) boolean
loadGame
(org.jdom.Element root) (package private) boolean
boolean
loadGameAndWaitUntilOver
(org.jdom.Element root) private void
private String
makeNameByType
(String templateName, String type) (package private) static GameServerSide
makeNewGameServerSide
(Variant variant) Shortcut for UnitTests, to create a Game with dummy input objects on the fly.(package private) void
makeProposal
(String playerName, String proposalString) playerName offers proposal.(package private) void
mergeEvent
(String splitoffId, String survivorId) (package private) void
movementRollEvent
(Player player, int roll) (package private) int
mulligan()
private boolean
nameIsTaken
(String name, Player checkedPlayer) (package private) boolean
Start a new game.(package private) void
newGame2()
private void
newGame3()
Done picking player colors; proceed to start game.static GameServerSide
newGameServerSide
(WhatNextManager whatNextMgr, Options serverOptions, Variant variant) For more complicated functional tests(package private) void
protected void
private void
placeInitialLegion
(PlayerServerSide player, String markerId) (package private) void
playerElimEvent
(Player player, Player slayer) private void
readLegion
(org.jdom.Element leg, PlayerServerSide player) (package private) void
recruitEvent
(Legion legion, CreatureType recruit, CreatureType recruiter) (package private) void
Called locally and from Battle.(package private) void
removeCreatureEvent
(Legion legion, CreatureType creature, String reason) private boolean
(package private) void
revealEvent
(boolean allPlayers, List<Player> players, Legion legion, List<CreatureType> creatureNames, String reason) (package private) void
saveGameWithErrorHandling
(String filename, boolean autoSave) private void
setEngagementResult
(String aResult, Legion winner, int aPoints, int aTurn) void
setFlagFilename
(String flagFilename) void
setGameOver
(boolean gameOver, String message) private void
private void
private void
private void
private void
private void
Temporary solution ...(package private) void
splitEvent
(Legion parent, Legion child, List<CreatureType> splitoffs) boolean
startNewGameAndWaitUntilOver
(String hostingPlayer) private boolean
void
protected void
storeLocalClient
(String playerName, Client c) private void
Send all current game option values to all clients.(package private) void
(package private) void
undoRecruitEvent
(Legion legion) void
Update the dead and available counts for all creature types on all clients.private void
Update the dead and available counts for a creature type on all clients.protected void
Methods inherited from class net.sf.colossus.game.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
If the name is taken, add random digits to the end. -
findNetworkPlayer
Find a Player for a new remote client. If loading a game, this is the network player with a matching player name. If a new game, it's the first network player whose name is still set to -
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
Return a list with a balanced order of numPlayer towers chosen from towerList, which must hold numeric strings. -
getServer
Server getServer() -
createAndAddPlayer
-
getActivePlayerNum
int getActivePlayerNum() -
getActivePlayer
Player getActivePlayer() -
makeMovementRoll
private void makeMovementRoll() -
getMovementRoll
public int getMovementRoll()- Overrides:
getMovementRoll
in classGame
-
getPlayerByNameIgnoreNull
Resolve playerName into Player object. Name might be null, then returns null.- Parameters:
playerName
-- Returns:
- The player object for given player name, null if name was null
-
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
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. -
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
Advance to the next phase, only if the passed oldPhase and playerName are current. -
setGameOver
- Overrides:
setGameOver
in 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
playerName offers proposal. -
fight
-
handleConcession
-
handleNegotiation
-
askAcquireAngel
-
doneAcquiringAngels
void doneAcquiringAngels() -
setEngagementResult
-
checkEngagementDone
private void checkEngagementDone() -
gameShouldContinue
public boolean gameShouldContinue() -
getLegionByMarkerId
- Overrides:
getLegionByMarkerId
in 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
-