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) classCheck whether any game executed in an own process has been finished.private static final classA Null Object for the web server GUI interface. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate PrintWriterprivate final ChatChannelprivate IWebServerGUIprivate static final Loggerprivate final IColossusMailprivate final intprivate static final intprivate WebServerOptionsprivate PortBookKeeperprivate Stringprivate booleanprivate final booleanControls whether the GUI is shown or not.private static final Stringprivate final intServer port where we listen for WebClient connectionsprivate ServerSocketServer actual socket where we listen for WebClient connectionsprivate booleanprivate UserDBprivate final ClientWatchDogprivate final FormatWhenFields inherited from interface 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 TypeMethodDescriptionvoidvoidprivate voidattemptStartOnServer(GameInfo gi, User byUser) voidcancelGame(String gameId, String byUser) voidcancelIfNecessary(User user) voidchatSubmit(String chatId, String sender, String message) private voidconfirmRegistration(String username, String confirmationCode) private intcountProposedGames(boolean shallBeScheduled) private voidprivate voidprivate voidvoiddumpInfo()Dump server state info into a static file, at the moment dump-info.txtvoiddumpInfo(PrintWriter pw) Dump info into given PrintWritervoidenrollUserToGame(String gameId, String username) private GameInfofindByGameId(String gameId) private GameInfofindFromRunningGames(String gameId) findUserByName(String name) voidgameFailed(GameInfo gi, String reason) voidgameStarted(GameInfo gi) private IGameRunnerprivate intSearches the game directory tree for highest game number for which a game directory had been earlier created.(package private) StringEach user server thread's name is set to it user's name.getStringOption(String key) voidhandlePing(String sender, String pingCommand) voidhandlePingQuotedName(String sender, String pingCommand) voidinformAllEnrolledAbout(GameInfo gi, String message) voidinformAllEnrolledThatStartFailed(GameInfo gi, String reason, User byUser) voidinformLocallyGameOver(String gameId) private voidinformPingFailed(String sender, String failMessage) voidinformStartedByPlayer(String gameId) voidinitiateShutdown(String byUserName) private GameInfoisInvolvedInInstantGame(String initiatorName) voidlogout()static voidvoidproposeGame(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 voidreadGamesFromFile(String filename, HashMap<String, GameInfo> proposedGames) private voidreadLoginMessageFromFile(String filename) voidreEnrollIfNecessary(WebServerClient newclient) registerUser(String username, String password, String email) private voidvoidrequestUserAttention(long when, String sender, boolean isAdmin, String recipient, String message, int beepCount, long beepInterval, boolean windows) voidTriggered by remode admin connection(package private) voidvoidvoidsendMessageOfTheDayToOne(WebServerClient client, String chatId) voidsendOldVersionWarningToOne(WebServerClient client, String userName, String chatId) voidsendWatchGameInfo(String userName, String gameId, String host, int port) voidvoidvoidstartGameOnPlayerHost(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 StringstartOneGame(GameInfo gi) private voidstoreGamesToFile(String filename) voidsystemMessageToAll(String message) voidtellAllGamesFromListToOne(WebServerClient client, ArrayList<GameInfo> games) voidvoidvoidtellEnrolledGameStartsNow(GameInfo gi, String host, int port) voidvoidtellLastChatMessagesToOne(WebServerClient client, String chatId) voidunenrollUserFromGame(String gameId, String username) voidunregisterGame(GameInfo gi, int port) unregister a game from runningGames (or proposedGames), and keep in endingGames until it's reapedvoidunregister a game (run on player's PC) from runningGames, keep in endingGames until it's reapedvoidvoidupdateLoggedinStatus(User u, WebServerClient wsc) (package private) booleanupdateOnline(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.voidverifyLogin(String username, String password) private booleanvoidvoid
-
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:
rereadLoginMessagein interfaceIWebServer
-
runSocketServer
void runSocketServer() -
getGeneralChat
-
writeBackUsers
public void writeBackUsers() -
updateLoggedinStatus
-
initiateShutdown
-
shutdownServer
public void shutdownServer()- Specified by:
shutdownServerin 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:
getPortProviderin interfaceIRunWebServer
-
updateGUI
public void updateGUI() -
watchGame
- Specified by:
watchGamein interfaceIWebServer
-
sendWatchGameInfo
-
dumpInfo
public void dumpInfo()Dump server state info into a static file, at the moment dump-info.txt- Specified by:
dumpInfoin 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:
proposeGamein interfaceIWebServer
-
cancelIfNecessary
-
reEnrollIfNecessary
-
tellAllGamesFromListToOne
-
tellAllProposedGamesToOne
-
tellAllRunningGamesToOne
-
allTellGameInfo
- Specified by:
allTellGameInfoin interfaceIRunWebServer
-
tellEnrolledGameStartsSoon
- Specified by:
tellEnrolledGameStartsSoonin interfaceIRunWebServer
-
tellEnrolledGameStartsNow
- Specified by:
tellEnrolledGameStartsNowin interfaceIRunWebServer
-
gameStarted
- Specified by:
gameStartedin interfaceIRunWebServer
-
gameFailed
- Specified by:
gameFailedin interfaceIRunWebServer
-
enrollUserToGame
- Specified by:
enrollUserToGamein interfaceIWebServer
-
unenrollUserFromGame
- Specified by:
unenrollUserFromGamein interfaceIWebServer
-
cancelGame
- Specified by:
cancelGamein interfaceIWebServer
-
startGame
- Specified by:
startGamein 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:
startGameOnPlayerHostin interfaceIWebServer
-
informStartedByPlayer
- Specified by:
informStartedByPlayerin interfaceIWebServer
-
informAllEnrolledAbout
- Specified by:
informAllEnrolledAboutin 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:
requestUserAttentionin interfaceIWebServer
-
informPingFailed
-
informLocallyGameOver
- Specified by:
informLocallyGameOverin interfaceIWebServer
-
updateUserCounts
public void updateUserCounts() -
allTellUserCounts
public void allTellUserCounts() -
chatSubmit
- Specified by:
chatSubmitin interfaceIWebServer
-
handlePingQuotedName
-
handlePing
-
tellLastChatMessagesToOne
-
sendMessageOfTheDayToOne
-
sendOldVersionWarningToOne
-
readLoginMessageFromFile
-
logout
public void logout()- Specified by:
logoutin interfaceIWebServer
-
registerUser
-
confirmRegistration
-
changeProperties
public String changeProperties(String username, String oldPW, String newPW, String email, Boolean isAdminObj) - Specified by:
changePropertiesin 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:
unregisterGamein 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)
-