Package net.sf.colossus.webserver
Class WebServer
java.lang.Object
net.sf.colossus.webserver.WebServer
- All Implemented Interfaces:
IRunWebServer
,IWebServer
The main class for the WebServer
- brings up the WebServer GUI
- starts the ServerSocket and listens there for WebClients
- based on actions coming from clients, keeps book of
"instant" and "running" games (both GameInfo objects),
and tell the GameInfo objects when to start the game.
- Author:
- Clemens Katzer
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) class
Check whether any game executed in an own process has been finished.private static final class
A Null Object for the web server GUI interface. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate PrintWriter
private final ChatChannel
private IWebServerGUI
private static final Logger
private final IColossusMail
private final int
private static final int
private WebServerOptions
private PortBookKeeper
private String
private boolean
private final boolean
Controls whether the GUI is shown or not.private static final String
private final int
Server port where we listen for WebClient connectionsprivate ServerSocket
Server actual socket where we listen for WebClient connectionsprivate boolean
private UserDB
private final ClientWatchDog
private final FormatWhen
Fields inherited from interface net.sf.colossus.webcommon.IWebServer
Cancel, ChangePassword, ChatSubmit, ConfirmCommand, ConfirmRegistration, DumpInfo, Echo, Enroll, generalChatName, LocallyGameOver, Login, Logout, PingResponse, Propose, RegisterUser, RequestUserAttention, RereadLoginMessage, ShutdownServer, Start, StartAtPlayer, StartedByPlayer, Unenroll, WatchGame, WebProtocolSeparator
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
private void
attemptStartOnServer
(GameInfo gi, User byUser) void
cancelGame
(String gameId, String byUser) void
cancelIfNecessary
(User user) void
chatSubmit
(String chatId, String sender, String message) private void
confirmRegistration
(String username, String confirmationCode) private int
countProposedGames
(boolean shallBeScheduled) private void
private void
private void
void
dumpInfo()
Dump server state info into a static file, at the moment dump-info.txtvoid
dumpInfo
(PrintWriter pw) Dump info into given PrintWritervoid
enrollUserToGame
(String gameId, String username) private GameInfo
findByGameId
(String gameId) private GameInfo
findFromRunningGames
(String gameId) findUserByName
(String name) void
gameFailed
(GameInfo gi, String reason) void
gameStarted
(GameInfo gi) private IGameRunner
private int
Searches the game directory tree for highest game number for which a game directory had been earlier created.(package private) String
Each user server thread's name is set to it user's name.getStringOption
(String key) void
handlePing
(String sender, String pingCommand) void
handlePingQuotedName
(String sender, String pingCommand) void
informAllEnrolledAbout
(GameInfo gi, String message) void
informAllEnrolledThatStartFailed
(GameInfo gi, String reason, User byUser) void
informLocallyGameOver
(String gameId) private void
informPingFailed
(String sender, String failMessage) void
informStartedByPlayer
(String gameId) void
initiateShutdown
(String byUserName) private GameInfo
isInvolvedInInstantGame
(String initiatorName) void
logout()
static void
void
proposeGame
(String initiator, String variant, String viewmode, long startAt, int duration, String summary, String expire, boolean unlimitedMulligans, boolean balancedTowers, int min, int target, int max) private void
readGamesFromFile
(String filename, HashMap<String, GameInfo> proposedGames) private void
readLoginMessageFromFile
(String filename) void
reEnrollIfNecessary
(WebServerClient newclient) registerUser
(String username, String password, String email) private void
void
requestUserAttention
(long when, String sender, boolean isAdmin, String recipient, String message, int beepCount, long beepInterval, boolean windows) void
Triggered by remode admin connection(package private) void
void
void
sendMessageOfTheDayToOne
(WebServerClient client, String chatId) void
sendOldVersionWarningToOne
(WebServerClient client, String userName, String chatId) void
sendWatchGameInfo
(String userName, String gameId, String host, int port) void
void
void
startGameOnPlayerHost
(String gameId, String hostingPlayer, String playerHost, int port) A game was started by a WebClient user locally on his computer and is ready to accept the other players as remote client; so we notify them and tell them host and port to where to connect.private String
startOneGame
(GameInfo gi) private void
storeGamesToFile
(String filename) void
systemMessageToAll
(String message) void
tellAllGamesFromListToOne
(WebServerClient client, ArrayList<GameInfo> games) void
void
void
tellEnrolledGameStartsNow
(GameInfo gi, String host, int port) void
void
tellLastChatMessagesToOne
(WebServerClient client, String chatId) void
unenrollUserFromGame
(String gameId, String username) void
unregisterGame
(GameInfo gi, int port) unregister a game from runningGames (or proposedGames), and keep in endingGames until it's reapedvoid
unregister a game (run on player's PC) from runningGames, keep in endingGames until it's reapedvoid
void
updateLoggedinStatus
(User u, WebServerClient wsc) (package private) boolean
updateOnline
(GameInfo gi) When a user logged in or out, this is called for every GameInfo to update how many of the enrolled players are currently online.void
verifyLogin
(String username, String password) private boolean
void
void
-
Field Details
-
LOGGER
-
options
-
portBookKeeper
-
gui
-
mailObject
-
MIN_FREE_GAME_PORTS
private static final int MIN_FREE_GAME_PORTS- See Also:
-
loginMessage
-
runGUI
private final boolean runGUIControls whether the GUI is shown or not. At the moment this is configured only by the possibility of doing so: if the environment supports running a GUI, we will, if not, we won't. It could be combined with a command line option to suppress the GUI even if it would be possible to show one. -
shutdownRequested
private boolean shutdownRequested -
proposedGamesFilename
-
proposedGamesListModified
private boolean proposedGamesListModified -
maxClients
private final int maxClients -
userDB
-
proposedGames
-
runningGames
-
endingGames
-
sep
- See Also:
-
serverPort
private final int serverPortServer port where we listen for WebClient connections -
serverSocket
Server actual socket where we listen for WebClient connections -
generalChat
-
watchDog
-
whenFormatter
-
dumpInfoFile
-
-
Constructor Details
-
WebServer
-
-
Method Details
-
main
-
doReadGamesFromFile
private void doReadGamesFromFile() -
doReadUsersFromFile
private void doReadUsersFromFile() -
doReadLoginMessage
private void doReadLoginMessage() -
rereadLoginMessage
public void rereadLoginMessage()Triggered by remode admin connection- Specified by:
rereadLoginMessage
in interfaceIWebServer
-
runSocketServer
void runSocketServer() -
getGeneralChat
-
writeBackUsers
public void writeBackUsers() -
updateLoggedinStatus
-
initiateShutdown
-
shutdownServer
public void shutdownServer()- Specified by:
shutdownServer
in interfaceIWebServer
-
makeDummyConnection
public void makeDummyConnection() -
waitForUser
private boolean waitForUser() -
reject
-
closeAllWebServerClientSocketThreads
private void closeAllWebServerClientSocketThreads() -
getPlayerName
String getPlayerName()Each user server thread's name is set to it user's name. -
getUserDB
-
findUserByName
-
verifyLogin
-
getPortBookKeeper
-
getPortProvider
- Specified by:
getPortProvider
in interfaceIRunWebServer
-
updateGUI
public void updateGUI() -
watchGame
- Specified by:
watchGame
in interfaceIWebServer
-
sendWatchGameInfo
-
dumpInfo
public void dumpInfo()Dump server state info into a static file, at the moment dump-info.txt- Specified by:
dumpInfo
in interfaceIWebServer
-
dumpInfo
Dump info into given PrintWriter- Parameters:
pw
- PrintWriter for the file to print dump to
-
isInvolvedInInstantGame
-
proposeGame
public GameInfo proposeGame(String initiator, String variant, String viewmode, long startAt, int duration, String summary, String expire, boolean unlimitedMulligans, boolean balancedTowers, int min, int target, int max) - Specified by:
proposeGame
in interfaceIWebServer
-
cancelIfNecessary
-
reEnrollIfNecessary
-
tellAllGamesFromListToOne
-
tellAllProposedGamesToOne
-
tellAllRunningGamesToOne
-
allTellGameInfo
- Specified by:
allTellGameInfo
in interfaceIRunWebServer
-
tellEnrolledGameStartsSoon
- Specified by:
tellEnrolledGameStartsSoon
in interfaceIRunWebServer
-
tellEnrolledGameStartsNow
- Specified by:
tellEnrolledGameStartsNow
in interfaceIRunWebServer
-
gameStarted
- Specified by:
gameStarted
in interfaceIRunWebServer
-
gameFailed
- Specified by:
gameFailed
in interfaceIRunWebServer
-
enrollUserToGame
- Specified by:
enrollUserToGame
in interfaceIWebServer
-
unenrollUserFromGame
- Specified by:
unenrollUserFromGame
in interfaceIWebServer
-
cancelGame
- Specified by:
cancelGame
in interfaceIWebServer
-
startGame
- Specified by:
startGame
in interfaceIWebServer
-
attemptStartOnServer
-
startGameOnPlayerHost
A game was started by a WebClient user locally on his computer and is ready to accept the other players as remote client; so we notify them and tell them host and port to where to connect.- Specified by:
startGameOnPlayerHost
in interfaceIWebServer
-
informStartedByPlayer
- Specified by:
informStartedByPlayer
in interfaceIWebServer
-
informAllEnrolledAbout
- Specified by:
informAllEnrolledAbout
in interfaceIRunWebServer
-
systemMessageToAll
-
informAllEnrolledThatStartFailed
-
requestUserAttention
public void requestUserAttention(long when, String sender, boolean isAdmin, String recipient, String message, int beepCount, long beepInterval, boolean windows) - Specified by:
requestUserAttention
in interfaceIWebServer
-
informPingFailed
-
informLocallyGameOver
- Specified by:
informLocallyGameOver
in interfaceIWebServer
-
updateUserCounts
public void updateUserCounts() -
allTellUserCounts
public void allTellUserCounts() -
chatSubmit
- Specified by:
chatSubmit
in interfaceIWebServer
-
handlePingQuotedName
-
handlePing
-
tellLastChatMessagesToOne
-
sendMessageOfTheDayToOne
-
sendOldVersionWarningToOne
-
readLoginMessageFromFile
-
logout
public void logout()- Specified by:
logout
in interfaceIWebServer
-
registerUser
-
confirmRegistration
-
changeProperties
public String changeProperties(String username, String oldPW, String newPW, String email, Boolean isAdminObj) - Specified by:
changeProperties
in interfaceIWebServer
-
updateOnline
When a user logged in or out, this is called for every GameInfo to update how many of the enrolled players are currently online.- Parameters:
userDB
- TODO- Returns:
- true if the count of online users was changed i.e. GameInfo needs to be updated to all clients
-
countProposedGames
private int countProposedGames(boolean shallBeScheduled) -
findByGameId
-
findFromRunningGames
-
getGameOnServer
-
startOneGame
-
unregisterGame
unregister a game from runningGames (or proposedGames), and keep in endingGames until it's reaped- Specified by:
unregisterGame
in interfaceIRunWebServer
-
unregisterGamePlayerPC
unregister a game (run on player's PC) from runningGames, keep in endingGames until it's reaped -
readGamesFromFile
-
saveGamesIfNeeded
public void saveGamesIfNeeded() -
storeGamesToFile
-
getStringOption
-
getMaximumGameIdFromFiles
private int getMaximumGameIdFromFiles()Searches the game directory tree for highest game number for which a game directory had been earlier created. Tree is expected to have groups per each 100 games; example: base base/nn00-nn99 base/nn00-nn99/nn00 base/nn00-nn99/nn04 base/nn00-nn99/nn98 base/mm00-mm99/mm12 base/mm00-mm99/mm87 Eventually, when we reach gameId 10000+, groupdirs will have the form base/kkk00-kkk99 base/kkk00-kkk99/kkk02 base/kkk00-kkk99/kkk87 Example, if last created game dir was 6789 ( "base/6700-6799/6789" ), this returns 6789.- Returns:
- The highest game number for which a directory already exists, (otherwise 0 if therre is no dir at all)
-