|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectjava.lang.Thread
soc.server.genericServer.Server
soc.server.SOCServer
A server for Settlers of Catan
| Nested Class Summary |
| Nested classes inherited from class soc.server.genericServer.Server |
Server.NetStringServerSocket |
| Field Summary | |
protected SOCChannelList |
channelList
list of chat channels |
static int |
CLI_VERSION_MIN
Minimum required client version, to connect and play a game. |
static java.lang.String |
CLI_VERSION_MIN_DISPLAY
Minimum required client version, in "display" form, like "1.0.00". |
(package private) java.lang.String |
databasePassword
|
(package private) java.lang.String |
databaseUserName
|
static int |
GAME_EXPIRE_WARN_MINUTES
If game will expire in this or fewer minutes, warn the players. |
protected java.util.Hashtable |
gameDataFiles
table of game data files |
protected SOCGameList |
gameList
list of soc games |
(package private) SOCGameTimeoutChecker |
gameTimeoutChecker
game timeout checker |
protected int |
maxConnections
Maximum number of connections allowed |
static java.lang.String |
MSG_NICKNAME_ALREADY_IN_USE
Status Message to send, nickname already logged into the system |
protected int |
numberOfGamesFinished
the total number of games finished |
protected int |
numberOfGamesStarted
the total number of games that have been started |
protected int |
numberOfUsers
total number of users |
int |
port
The TCP port we listen on. |
static java.lang.String |
PRACTICE_STRINGPORT
For local practice games (pipes, not TCP), the name of the pipe. |
private java.util.Random |
rand
So we can get random numbers. |
static SOCRobotParameters |
ROBOT_PARAMS_DEFAULT
Robot default parameters; copied for each newly connecting robot. |
static SOCRobotParameters |
ROBOT_PARAMS_SMARTER
Smarter robot default parameters. |
protected java.util.Hashtable |
robotDismissRequests
table of requestst for robots to leave games |
protected java.util.Hashtable |
robotJoinRequests
table of requests for robots to join games |
protected java.util.Vector |
robots
A list of robots connected to this server |
static java.lang.String |
SERVERNAME
Name used when sending messages from the server. |
(package private) SOCServerRobotPinger |
serverRobotPinger
server robot pinger |
protected long |
startTime
the time that this server was started |
| Fields inherited from class soc.server.genericServer.Server |
conns, error, inQueue, numberOfConnections, strSocketName, unnamedConns |
| Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
SOCServer(int p,
int mc,
java.lang.String databaseUserName,
java.lang.String databasePassword)
Create a Settlers of Catan server listening on port p. |
|
SOCServer(java.lang.String s,
int mc,
java.lang.String databaseUserName,
java.lang.String databasePassword)
Create a Settlers of Catan server listening on local stringport s. |
|
| Method Summary | |
private boolean |
authenticateUser(StringConnection c,
java.lang.String userName,
java.lang.String password)
authenticate the user see if the user is in the db, if so then check the password if they're not in the db, but they supplied a password then send a message if they're not in the db, and no password, then ok |
protected void |
broadcastGameStats(SOCGame ga)
this broadcasts game information to all people connected used to display the scores on the player client |
void |
checkForExpiredGames()
check for games that have expired and destroy them. |
private boolean |
checkNickname(java.lang.String n)
check if a name is ok a name is ok if it hasn't been used yet |
protected boolean |
checkTurn(StringConnection c,
SOCGame ga)
make sure it's the player's turn |
void |
connectToChannel(StringConnection c,
java.lang.String ch)
Adds a connection to a chat channel. |
boolean |
connectToGame(StringConnection c,
java.lang.String ga)
Adds a connection to a game. |
private void |
createNewGameEventRecord()
create a new game event record |
void |
destroyGame(java.lang.String gm)
destroy the game WARNING: MUST HAVE THE gameList.takeMonitor() before calling this method |
private void |
endGameTurn(SOCGame ga)
Pre-checking already done, end the current player's turn in this game. |
private void |
forceEndGameTurn(SOCGame ga,
java.lang.String plName)
Try to force-end the current player's turn in this game. |
private void |
forceGamePlayerDiscard(SOCGame cg,
int cpn,
StringConnection c,
java.lang.String plName,
int pn)
Force this player (not current player) to discard, and report resources to all players. |
private SOCBoardLayout |
getBoardLayoutMessage(SOCGame ga)
put together the SOCBoardLayout message |
java.util.Enumeration |
getGameNames()
Used when SOCPlayerClient is also hosting games. |
int |
getGameState(java.lang.String gm)
Given a game name on this server, return its state. |
protected void |
giveDevCard(java.lang.String mes,
SOCGame game)
this is a debugging command that gives a dev card to a player |
protected void |
giveResources(java.lang.String mes,
SOCGame game)
this is a debugging command that gives resources to a player |
private void |
handleACCEPTOFFER(StringConnection c,
SOCAcceptOffer mes)
handle "accept offer" message |
private void |
handleBANKTRADE(StringConnection c,
SOCBankTrade mes)
handle "bank trade" message |
private void |
handleBUILDREQUEST(StringConnection c,
SOCBuildRequest mes)
handle "build request" message |
private void |
handleBUYCARDREQUEST(StringConnection c,
SOCBuyCardRequest mes)
handle "buy card request" message |
private void |
handleCANCELBUILDREQUEST(StringConnection c,
SOCCancelBuildRequest mes)
handle "cancel build request" message |
private void |
handleCHANGEFACE(StringConnection c,
SOCChangeFace mes)
handle "change face" message |
private void |
handleCHOOSEPLAYER(StringConnection c,
SOCChoosePlayer mes)
handle "choose player" message during robbery |
private void |
handleCLEAROFFER(StringConnection c,
SOCClearOffer mes)
handle "clear offer" message |
private void |
handleCREATEACCOUNT(StringConnection c,
SOCCreateAccount mes)
handle "create account" message |
private void |
handleDISCARD(StringConnection c,
SOCDiscard mes)
handle "discard" message |
private void |
handleDISCOVERYPICK(StringConnection c,
SOCDiscoveryPick mes)
handle "discovery pick" message (while playing Discovery card) |
private void |
handleENDTURN(StringConnection c,
SOCEndTurn mes)
handle "end turn" message |
private void |
handleIMAROBOT(StringConnection c,
SOCImARobot mes)
Handle the "I'm a robot" message. |
private void |
handleJOIN(StringConnection c,
SOCJoin mes)
Handle the "join a channel" message. |
private void |
handleJOINGAME(StringConnection c,
SOCJoinGame mes)
Handle the "join a game" message: Join or create a game. |
private void |
handleLEAVE(StringConnection c,
SOCLeave mes)
Handle the "leave a channel" message |
private void |
handleLEAVEGAME(StringConnection c,
SOCLeaveGame mes)
Handle the "leave game" message |
private void |
handleMAKEOFFER(StringConnection c,
SOCMakeOffer mes)
handle "make offer" message |
private void |
handleMONOPOLYPICK(StringConnection c,
SOCMonopolyPick mes)
handle "monopoly pick" message |
private void |
handleMOVEROBBER(StringConnection c,
SOCMoveRobber mes)
handle "move robber" message |
private void |
handlePLAYDEVCARDREQUEST(StringConnection c,
SOCPlayDevCardRequest mes)
handle "play development card request" message |
private void |
handlePUTPIECE(StringConnection c,
SOCPutPiece mes)
handle "put piece" message |
private void |
handleREJECTOFFER(StringConnection c,
SOCRejectOffer mes)
handle "reject offer" message |
private void |
handleRESETBOARDREQUEST(StringConnection c,
SOCResetBoardRequest mes)
handle "reset-board request" message. |
private void |
handleRESETBOARDVOTE(StringConnection c,
SOCResetBoardVote mes)
handle message of player's vote for a "reset-board" request. |
private void |
handleROLLDICE(StringConnection c,
SOCRollDice mes)
handle "roll dice" message |
private void |
handleSETSEATLOCK(StringConnection c,
SOCSetSeatLock mes)
handle "set seat lock" message |
private void |
handleSITDOWN(StringConnection c,
SOCSitDown mes)
handle "sit down" message |
private void |
handleSTARTGAME(StringConnection c,
SOCStartGame mes)
handle "start game" message. |
private void |
handleVERSION(StringConnection c,
SOCVersion mes)
Handle the "version" message, client's version report. |
private void |
initSocServer(java.lang.String databaseUserName,
java.lang.String databasePassword)
Common init for both constructors. |
private void |
joinGame(SOCGame gameData,
StringConnection c,
boolean isReset)
Client has been approved to join game; send the entire state of the game to client, send client join event to other players. |
java.util.Vector |
leaveAllChannels(StringConnection c)
the connection c leaves all channels it was in |
java.util.Vector |
leaveAllGames(StringConnection c)
the connection c leaves all games it was in |
boolean |
leaveChannel(StringConnection c,
java.lang.String ch,
boolean channelListLock)
the connection c leaves the channel ch WARNING: MUST HAVE THE channelList.takeMonitorForChannel(ch) before calling this method |
void |
leaveConnection(StringConnection c)
things to do when the connection c leaves |
boolean |
leaveGame(StringConnection c,
java.lang.String gm,
boolean gameListLock)
the connection c leaves the game gm. |
static void |
main(java.lang.String[] args)
Starting the server from the command line |
void |
messageToChannel(java.lang.String ch,
SOCMessage mes)
Send a message to the given channel |
void |
messageToChannelWithMon(java.lang.String ch,
SOCMessage mes)
Send a message to the given channel WARNING: MUST HAVE THE gameList.takeMonitorForChannel(ch) before calling this method |
void |
messageToGame(java.lang.String ga,
SOCMessage mes)
Send a message to the given game |
void |
messageToGameExcept(java.lang.String gn,
StringConnection ex,
SOCMessage mes)
Send a message to all the connections in a game excluding one. |
void |
messageToGameExcept(java.lang.String gn,
java.util.Vector ex,
SOCMessage mes)
Send a message to all the connections in a game excluding some. |
void |
messageToGameUrgent(java.lang.String ga,
java.lang.String mes)
Send an urgent SOCGameTextMsg to the given game. |
void |
messageToGameWithMon(java.lang.String ga,
SOCMessage mes)
Send a message to the given game WARNING: MUST HAVE THE gameList.takeMonitorForGame(ga) before calling this method |
void |
messageToPlayer(StringConnection c,
SOCMessage mes)
Send a message to a player and record it |
boolean |
newConnection1(StringConnection c)
Things to do when a new connection comes. |
protected void |
newConnection2(StringConnection c)
Send welcome messages (server version, and the lists of channels and games ( SOCChannels, SOCGames)) when a new
connection comes, part 2 - c has been accepted and added to a connection list. |
void |
processCommand(java.lang.String s,
StringConnection c)
Treat the incoming messages. |
void |
processDebugCommand(StringConnection debugCli,
java.lang.String ga,
java.lang.String dcmd)
Process a debug command, sent by the "debug" client/player. |
private void |
readyGameAskRobotsJoin(SOCGame ga,
StringConnection[] robotSeats)
Fill all the unlocked empty seats with robots. |
protected void |
recordGameEvent(java.lang.String gameName,
java.lang.String event)
record events that happen during the game |
protected void |
reportBankTrade(SOCGame ga,
SOCResourceSet give,
SOCResourceSet get)
report that the current player traded with the bank or a port, using SOCPlayerElement and SOCGameTextMsg messages. |
protected void |
reportRobbery(SOCGame ga,
SOCPlayer pe,
SOCPlayer vi,
int rsrc)
The current player is stealing from another player. |
private void |
reportRsrcGainLoss(java.lang.String gaName,
SOCResourceSet rset,
boolean isLoss,
int mainPlayer,
int tradingPlayer,
java.lang.StringBuffer message,
StringConnection playerConn)
Report the resources gained/lost by a player, and optionally (for trading) lost/gained by a second player. |
protected void |
reportTrade(SOCGame ga,
int offering,
int accepting)
report a trade that has taken place between players, using SOCPlayerElement
and SOCGameTextMsg messages. |
private void |
resetBoardAndNotify(java.lang.String gaName,
int requestingPlayer)
Reset the board, to a copy with same players but new layout. |
private void |
saveCurrentGameEventRecord(java.lang.String gn)
save the current game event record in the game record |
protected void |
sendGameState(SOCGame ga)
send the current state of the game with a message. |
protected boolean |
sendGameState(SOCGame ga,
boolean sendRollPrompt)
send the current state of the game with a message. |
protected void |
sendGameStateOVER(SOCGame ga)
If game is OVER, send messages reporting winner, final score, and each player's victory-point cards. |
private void |
sendTurn(SOCGame ga,
boolean sendRollPrompt)
send whose turn it is. |
private boolean |
setClientVersionOrReject(StringConnection c,
int cvers)
Set client's version, and check against minimum required version CLI_VERSION_MIN. |
private void |
sitDown(SOCGame ga,
StringConnection c,
int pn,
boolean robot,
boolean isReset)
This player is sitting down at the game |
protected void |
startGame(SOCGame ga)
do the stuff you need to do to start a game |
void |
stopServer()
The server is being cleanly stopped. |
void |
stopServer(java.lang.String stopMsg)
The server is being cleanly stopped. |
protected void |
storeGameScores(SOCGame ga)
if all the players stayed for the whole game, record the scores in the database |
| Methods inherited from class soc.server.genericServer.Server |
addConnection, broadcast, connectionCount, getConnection, getConnections, isUp, nameConnection, removeConnection, removeConnectionCleanup, run, serverDown, treat |
| Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final java.lang.String SERVERNAME
public static final int CLI_VERSION_MIN
Version.versionNumber().
Currently there is no minimum.
setClientVersionOrReject(StringConnection, int),
Constant Field Valuespublic static final java.lang.String CLI_VERSION_MIN_DISPLAY
setClientVersionOrReject(StringConnection, int),
Constant Field Valuespublic static int GAME_EXPIRE_WARN_MINUTES
checkForExpiredGames(),
SOCGameTimeoutChecker.run(),
SOCGameList.createGame(String)public static java.lang.String PRACTICE_STRINGPORT
LocalStringConnectionprivate java.util.Random rand
public int port
protected int maxConnections
protected java.util.Vector robots
public static SOCRobotParameters ROBOT_PARAMS_DEFAULT
handleIMAROBOT(StringConnection, soc.message.SOCImARobot),
SOCRobotDMpublic static SOCRobotParameters ROBOT_PARAMS_SMARTER
ROBOT_PARAMS_DEFAULT,
SOCRobotDMpublic static final java.lang.String MSG_NICKNAME_ALREADY_IN_USE
protected SOCChannelList channelList
protected SOCGameList gameList
protected java.util.Hashtable robotJoinRequests
protected java.util.Hashtable robotDismissRequests
protected java.util.Hashtable gameDataFiles
protected long startTime
protected int numberOfGamesStarted
protected int numberOfGamesFinished
protected int numberOfUsers
SOCServerRobotPinger serverRobotPinger
SOCGameTimeoutChecker gameTimeoutChecker
java.lang.String databaseUserName
java.lang.String databasePassword
| Constructor Detail |
public SOCServer(int p,
int mc,
java.lang.String databaseUserName,
java.lang.String databasePassword)
p - the port that the server listens onmc - the maximum number of connections alloweddatabaseUserName - the user name for accessing the databasedatabasePassword - the password for the user
public SOCServer(java.lang.String s,
int mc,
java.lang.String databaseUserName,
java.lang.String databasePassword)
s - the stringport that the server listens onmc - the maximum number of connections alloweddatabaseUserName - the user name for accessing the databasedatabasePassword - the password for the user| Method Detail |
private void initSocServer(java.lang.String databaseUserName,
java.lang.String databasePassword)
databaseUserName - Used for DB connect - not retaineddatabasePassword - Used for DB connect - not retained
public void connectToChannel(StringConnection c,
java.lang.String ch)
c - the Connection to be addedch - the name of the channel
public boolean leaveChannel(StringConnection c,
java.lang.String ch,
boolean channelListLock)
c - the connectionch - the channelchannelListLock - true if we have the channelList monitor
public boolean connectToGame(StringConnection c,
java.lang.String ga)
c - the Connection to be added; its name and version should already be set.ga - the name of the game
public boolean leaveGame(StringConnection c,
java.lang.String gm,
boolean gameListLock)
WARNING: MUST HAVE THE gameList.takeMonitorForGame(gm) before calling this method
c - the connection; if c is being dropped because of an error,
this method assumes that StringConnection.disconnect()
has already been called. This method won't exclude c from
any communication about leaving the game, in case they are
still connected and in other games.gm - the gamegameListLock - true if we have the gameList.takeMonitor() lock
private void forceGamePlayerDiscard(SOCGame cg,
int cpn,
StringConnection c,
java.lang.String plName,
int pn)
SOCGame.discardPickRandom(SOCResourceSet, int, SOCResourceSet, Random).
Assumes, as endGameTurn(SOCGame) does:
SOCGameList.takeMonitorForGame(String))
cg - Game objectcpn - Game's current player numberc - Connection of discarding playerplName - Discarding player's name, for GameTextMsgpn - Player number who must discardpublic void destroyGame(java.lang.String gm)
gm - the name of the gamepublic java.util.Enumeration getGameNames()
public int getGameState(java.lang.String gm)
gm - Game name
public java.util.Vector leaveAllChannels(StringConnection c)
c - the connection
public java.util.Vector leaveAllGames(StringConnection c)
c - the connection
public void messageToChannel(java.lang.String ch,
SOCMessage mes)
ch - the name of the channelmes - the message to send
public void messageToChannelWithMon(java.lang.String ch,
SOCMessage mes)
ch - the name of the channelmes - the message to send
public void messageToPlayer(StringConnection c,
SOCMessage mes)
c - the player connectionmes - the message to send
public void messageToGame(java.lang.String ga,
SOCMessage mes)
ga - the name of the gamemes - the message to send. If mes is a SOCGameTextMsg whose
text begins with ">>>", the client should consider this
an urgent message, and draw the user's attention in some way.
(See messageToGameUrgent(String, String))
public void messageToGameWithMon(java.lang.String ga,
SOCMessage mes)
ga - the name of the gamemes - the message to send
public void messageToGameExcept(java.lang.String gn,
java.util.Vector ex,
SOCMessage mes)
gn - the name of the gameex - the list of exceptionsmes - the message
public void messageToGameExcept(java.lang.String gn,
StringConnection ex,
SOCMessage mes)
gn - the name of the gameex - the excluded connection, or nullmes - the message
public void messageToGameUrgent(java.lang.String ga,
java.lang.String mes)
Like messageToGame, will take and release the game's monitor.
ga - the name of the gamemes - the message to send. If mes does not begin with ">>>",
will prepend ">>> " before sending mes.public void leaveConnection(StringConnection c)
leaveConnection in class Serverc - the connectionpublic boolean newConnection1(StringConnection c)
Server.unnamedConns until the
player "names" it by joining or creating a game under their player name.
Other communication is then done, in newConnection2(StringConnection).
SYNCHRONIZATION NOTE: During the call to newConnection1, the monitor lock of
Server.unnamedConns is held. Thus, defer as much as possible until
newConnection2(StringConnection) (after the connection is accepted).
newConnection1 in class Serverc - the new Connection
StringConnection.disconnectSoft().Server.addConnection(StringConnection),
newConnection2(StringConnection),
Server.nameConnection(StringConnection)protected void newConnection2(StringConnection c)
SOCChannels, SOCGames)) when a new
connection comes, part 2 - c has been accepted and added to a connection list.
Unlike newConnection1(StringConnection),
no connection-list locks are held when this method is called.
Also set client's "assumed version" to -1, until we have sent and received a VERSION message.
newConnection2 in class Serverprivate boolean checkNickname(java.lang.String n)
n - the name
public void processCommand(java.lang.String s,
StringConnection c)
Note: When there is a choice, always use local information over information from the message. For example, use the nickname from the connection to get the player information rather than the player information from the message. This makes it harder to send false messages making players do things they didn't want to do.
processCommand in class Servers - String containing the messagec - the Connection that sent the Message
public void processDebugCommand(StringConnection debugCli,
java.lang.String ga,
java.lang.String dcmd)
public void stopServer()
stopServer in class Serverpublic void stopServer(java.lang.String stopMsg)
stopMsg - Final text message to send to all connected clients, or null.
Will be sent as a SOCBCastTextMsg.
As always, if message starts with ">>" it will be considered urgent.
private boolean authenticateUser(StringConnection c,
java.lang.String userName,
java.lang.String password)
c - the user's connectionuserName - the user's nicknamepassword - the user's password
private void handleVERSION(StringConnection c,
SOCVersion mes)
c - the connection that sent the messagemes - the messsage
private boolean setClientVersionOrReject(StringConnection c,
int cvers)
CLI_VERSION_MIN.
If version is too low, send SOCRejectConnection.
c - Client's connectioncvers - Version reported by client, or assumed if no report
private void handleJOIN(StringConnection c,
SOCJoin mes)
c - the connection that sent the messagemes - the messsage
private void handleLEAVE(StringConnection c,
SOCLeave mes)
c - the connection that sent the messagemes - the messsage
private void handleIMAROBOT(StringConnection c,
SOCImARobot mes)
SOCVersion before sending this message.
Their version is checked here, must equal server's version.
c - the connection that sent the messagemes - the messsage
private void handleJOINGAME(StringConnection c,
SOCJoinGame mes)
c - the connection that sent the messagemes - the messsage
private void handleLEAVEGAME(StringConnection c,
SOCLeaveGame mes)
c - the connection that sent the messagemes - the messsage
private void handleSITDOWN(StringConnection c,
SOCSitDown mes)
c - the connection that sent the messagemes - the messsage
private void handlePUTPIECE(StringConnection c,
SOCPutPiece mes)
c - the connection that sent the messagemes - the messsage
private void handleMOVEROBBER(StringConnection c,
SOCMoveRobber mes)
c - the connection that sent the messagemes - the messsage
private void handleSTARTGAME(StringConnection c,
SOCStartGame mes)
c - the connection that sent the messagemes - the messsage
private void readyGameAskRobotsJoin(SOCGame ga,
StringConnection[] robotSeats)
throws java.lang.IllegalStateException,
java.lang.IllegalArgumentException
ga - Game to ask robots to joinrobotSeats - If robotSeats is null, robots are randomly selected.
If non-null, a MAXPLAYERS-sized array of StringConnections.
Any vacant non-locked seat, with index i,
is filled with the robot whose connection is robotSeats[i].
Other indexes should be null, and won't be used.
java.lang.IllegalStateException - if ga.gamestate is not READY
java.lang.IllegalArgumentException - if robotSeats is not null but wrong length,
or if a robotSeat element is null but that seat wants a robot (vacant non-locked).
private void handleROLLDICE(StringConnection c,
SOCRollDice mes)
c - the connection that sent the messagemes - the messsage
private void handleDISCARD(StringConnection c,
SOCDiscard mes)
c - the connection that sent the messagemes - the messsage
private void handleENDTURN(StringConnection c,
SOCEndTurn mes)
c - the connection that sent the messagemes - the messsageprivate void endGameTurn(SOCGame ga)
Assumes:
SOCGameList.takeMonitorForGame(String))
ga - Game to end turn
private void forceEndGameTurn(SOCGame ga,
java.lang.String plName)
endGameTurn(SOCGame) if appropriate.
Will send gameState and current player (turn) to clients.
Assumes, as endGameTurn(SOCGame) does:
SOCGameList.takeMonitorForGame(String))
ga - Game to force end turnplName - Current player's name. Needed because if they have been disconnected by
leaveGame(StringConnection, String, boolean),
their name within game object is already null.SOCGame.forceEndTurn()
private void handleCHOOSEPLAYER(StringConnection c,
SOCChoosePlayer mes)
c - the connection that sent the messagemes - the messsage
private void handleMAKEOFFER(StringConnection c,
SOCMakeOffer mes)
c - the connection that sent the messagemes - the messsage
private void handleCLEAROFFER(StringConnection c,
SOCClearOffer mes)
c - the connection that sent the messagemes - the messsage
private void handleREJECTOFFER(StringConnection c,
SOCRejectOffer mes)
c - the connection that sent the messagemes - the messsage
private void handleACCEPTOFFER(StringConnection c,
SOCAcceptOffer mes)
c - the connection that sent the messagemes - the messsage
private void handleBANKTRADE(StringConnection c,
SOCBankTrade mes)
c - the connection that sent the messagemes - the messsage
private void handleBUILDREQUEST(StringConnection c,
SOCBuildRequest mes)
c - the connection that sent the messagemes - the messsage
private void handleCANCELBUILDREQUEST(StringConnection c,
SOCCancelBuildRequest mes)
c - the connection that sent the messagemes - the messsage
private void handleBUYCARDREQUEST(StringConnection c,
SOCBuyCardRequest mes)
c - the connection that sent the messagemes - the messsage
private void handlePLAYDEVCARDREQUEST(StringConnection c,
SOCPlayDevCardRequest mes)
c - the connection that sent the messagemes - the messsage
private void handleDISCOVERYPICK(StringConnection c,
SOCDiscoveryPick mes)
c - the connection that sent the messagemes - the messsage
private void handleMONOPOLYPICK(StringConnection c,
SOCMonopolyPick mes)
c - the connection that sent the messagemes - the messsage
private void handleCHANGEFACE(StringConnection c,
SOCChangeFace mes)
c - the connectionmes - the message
private void handleSETSEATLOCK(StringConnection c,
SOCSetSeatLock mes)
c - the connectionmes - the message
private void handleRESETBOARDREQUEST(StringConnection c,
SOCResetBoardRequest mes)
The requesting player doesn't vote, but server still sends the vote-request-message, to tell that client their request was accepted and voting has begun.
If only one player remains (all other humans have left at end), ask them to start a new game instead. This is a rare occurrence and we shouldn't bring in new robots and all, since we already have an interface to set up a game.
If any human player's client is too old to vote for reset, assume they vote yes.
c - the connectionmes - the messageresetBoardAndNotify(String, int)
private void handleRESETBOARDVOTE(StringConnection c,
SOCResetBoardVote mes)
c - the connectionmes - the messageresetBoardAndNotify(String, int)
private void handleCREATEACCOUNT(StringConnection c,
SOCCreateAccount mes)
c - the connectionmes - the message
private void joinGame(SOCGame gameData,
StringConnection c,
boolean isReset)
gameData - Game to joinc - The connection of joining clientisReset - Game is a board-reset of an existing game
private void sitDown(SOCGame ga,
StringConnection c,
int pn,
boolean robot,
boolean isReset)
ga - the gamec - the connection for the playerpn - which seat the player is takingrobot - true if this player is a robotisReset - Game is a board-reset of an existing game
protected void reportRobbery(SOCGame ga,
SOCPlayer pe,
SOCPlayer vi,
int rsrc)
ga - the gamepe - the perpetratorvi - the the victimrsrc - type of resource stolen, as in SOCResourceConstantsprotected void sendGameState(SOCGame ga)
ga - the gamesendGameState(SOCGame, boolean)
protected boolean sendGameState(SOCGame ga,
boolean sendRollPrompt)
ga - the gamesendRollPrompt - If true, and if we send a text message to prompt
the player to roll, send a RollDicePrompt data message.
If the client is too old (1.0.6), it will ignore the prompt.
sendTurn(SOCGame, boolean),
sendGameState(SOCGame),
sendGameStateOVER(SOCGame)protected void sendGameStateOVER(SOCGame ga)
ga - This game is over; state should be OVER
protected void reportTrade(SOCGame ga,
int offering,
int accepting)
SOCPlayerElement
and SOCGameTextMsg messages. Trades are also reported to robots
by re-sending the accepting player's SOCAcceptOffer message.
ga - the gameoffering - the number of the player making the offeraccepting - the number of the player accepting the offerreportBankTrade(SOCGame, SOCResourceSet, SOCResourceSet)
protected void reportBankTrade(SOCGame ga,
SOCResourceSet give,
SOCResourceSet get)
SOCPlayerElement and SOCGameTextMsg messages.
ga - the gamegive - the number of the player making the offerget - the number of the player accepting the offerreportTrade(SOCGame, int, int)
private void reportRsrcGainLoss(java.lang.String gaName,
SOCResourceSet rset,
boolean isLoss,
int mainPlayer,
int tradingPlayer,
java.lang.StringBuffer message,
StringConnection playerConn)
Used to report the resources gained from a roll, discard, or discovery (year-of-plenty) pick. Also used to report the "give" or "get" half of a resource trade.
gaName - Game namerset - Resource set (from a roll, or the "give" or "get" side of a trade).
Resource type SOCResourceConstants.UNKNOWN is ignored.
Only positive resource amounts are sent (negative is ignored).isLoss - If true, "give" (SOCPlayerElement.LOSE), otherwise "get" (SOCPlayerElement.GAIN)mainPlayer - Player number "giving" if isLose==true, otherwise "getting".
For each nonzero resource involved, PLAYERELEMENT messages will be sent about this player.tradingPlayer - Player number on other side of trade, or -1 if no second player is involved.
If not -1, PLAYERELEMENT messages will also be sent about this player.message - Append resource numbers/types to this stringbuffer,
format like "3 clay,3 wood"; can be null.playerConn - Null or mainPlayer's connection; send messages here instead of
sending to all players in game. Because trades are public, there is no
such parameter for tradingPlayer.reportTrade(SOCGame, int, int),
reportBankTrade(SOCGame, SOCResourceSet, SOCResourceSet),
handleDISCARD(StringConnection, SOCDiscard),
handleDISCOVERYPICK(StringConnection, SOCDiscoveryPick),
handleROLLDICE(StringConnection, SOCRollDice)
protected boolean checkTurn(StringConnection c,
SOCGame ga)
c - the connection for playerga - the game
protected void startGame(SOCGame ga)
ga - the game
private void resetBoardAndNotify(java.lang.String gaName,
int requestingPlayer)
private void sendTurn(SOCGame ga,
boolean sendRollPrompt)
ga - the gamesendRollPrompt - whether to send a RollDicePrompt message afterwardsprivate SOCBoardLayout getBoardLayoutMessage(SOCGame ga)
ga - the game
private void createNewGameEventRecord()
private void saveCurrentGameEventRecord(java.lang.String gn)
gn - the name of the gameprotected void storeGameScores(SOCGame ga)
ga - the game
protected void recordGameEvent(java.lang.String gameName,
java.lang.String event)
gameName - the name of the gameevent - the event
protected void giveResources(java.lang.String mes,
SOCGame game)
protected void broadcastGameStats(SOCGame ga)
public void checkForExpiredGames()
GAME_EXPIRE_WARN_MINUTES,
SOCGameTimeoutChecker.run()
protected void giveDevCard(java.lang.String mes,
SOCGame game)
public static void main(java.lang.String[] args)
args - arguments: port number
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||