Class WebClient

  • All Implemented Interfaces:
    java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.RootPaneContainer, javax.swing.WindowConstants, IWebClient

    public class WebClient
    extends KFrame
    implements IWebClient
    This is the main class for one user client for the web server. One such client can register and/or login to the web server, propose a game, browse proposed games and enroll to such a game. When a game has enough players, it can be started, and this brings up the MasterBoard like the network client would do.
    Author:
    Clemens Katzer
    See Also:
    Serialized Form
    • Field Detail

      • LOGGER

        private static final java.util.logging.Logger LOGGER
      • WC_VERSION_GENERAL_MESSAGE

        public static final int WC_VERSION_GENERAL_MESSAGE
        See Also:
        Constant Field Values
      • WC_VERSION_SUPPORTS_PING

        public static final int WC_VERSION_SUPPORTS_PING
        See Also:
        Constant Field Values
      • myLocale

        static final java.util.Locale myLocale
      • hostname

        private java.lang.String hostname
      • port

        private int port
      • login

        private java.lang.String login
      • username

        private java.lang.String username
      • password

        private java.lang.String password
      • isAdmin

        private boolean isAdmin
      • options

        private final Options options
      • gameClient

        private Client gameClient
      • localServer

        private Server localServer
      • startedGameId

        private java.lang.String startedGameId
      • startedAtPort

        private int startedAtPort
      • startedAtHost

        private java.lang.String startedAtHost
      • comingUpMutex

        private final java.lang.Object comingUpMutex
      • timeIsUp

        private boolean timeIsUp
      • clientIsUp

        private boolean clientIsUp
      • clientStartFailed

        private boolean clientStartFailed
      • startingGame

        private GameInfo startingGame
      • failedDueToDuplicateLogin

        private boolean failedDueToDuplicateLogin
      • failedDueToOwnCancel

        private boolean failedDueToOwnCancel
      • state

        private int state
      • enrolledInstantGameId

        private java.lang.String enrolledInstantGameId
      • watchingInstantGameId

        private java.lang.String watchingInstantGameId
      • scheduledGamesMode

        private boolean scheduledGamesMode
      • usersLoggedIn

        private int usersLoggedIn
      • usersEnrolled

        private int usersEnrolled
      • usersPlaying

        private int usersPlaying
      • usersDead

        private int usersDead
      • usersLogoffAgo

        private long usersLogoffAgo
      • usersText

        private java.lang.String usersText
      • tabbedPane

        private javax.swing.JTabbedPane tabbedPane
      • serverTab

        private javax.swing.Box serverTab
      • preferencesPane

        private javax.swing.JPanel preferencesPane
      • createGamesTab

        private javax.swing.Box createGamesTab
      • runningGamesTab

        private javax.swing.Box runningGamesTab
      • adminTab

        private javax.swing.Box adminTab
      • defaultLocation

        private final java.awt.Point defaultLocation
      • statusLabel

        private javax.swing.JLabel statusLabel
      • userinfoLabel

        private javax.swing.JLabel userinfoLabel
      • webserverHostField

        private javax.swing.JTextField webserverHostField
      • webserverPortField

        private javax.swing.JTextField webserverPortField
      • loginField

        private javax.swing.JTextField loginField
      • passwordField

        private javax.swing.JPasswordField passwordField
      • commandField

        private javax.swing.JTextField commandField
      • receivedField

        private javax.swing.JLabel receivedField
      • loginLogoutButton

        private javax.swing.JButton loginLogoutButton
      • quitButton

        private javax.swing.JButton quitButton
      • autologinCB

        private javax.swing.JCheckBox autologinCB
      • autoGamePaneCB

        private javax.swing.JCheckBox autoGamePaneCB
      • registerOrPasswordLabel

        private javax.swing.JLabel registerOrPasswordLabel
      • registerOrPasswordButton

        private javax.swing.JButton registerOrPasswordButton
      • debugSubmitButton

        private javax.swing.JButton debugSubmitButton
      • rereadLoginMsgButton

        private javax.swing.JButton rereadLoginMsgButton
      • shutdownButton

        private javax.swing.JButton shutdownButton
      • dumpInfoButton

        private javax.swing.JButton dumpInfoButton
      • notifyMessageField

        private javax.swing.JTextField notifyMessageField
      • notifyUserField

        private javax.swing.JTextField notifyUserField
      • beepCountField

        private javax.swing.JTextField beepCountField
      • beepIntervalField

        private javax.swing.JTextField beepIntervalField
      • statusField

        private javax.swing.JLabel statusField
      • statusText

        private java.lang.String statusText
      • variantBox

        private javax.swing.JComboBox variantBox
      • viewmodeBox

        private javax.swing.JComboBox viewmodeBox
      • eventExpiringBox

        private javax.swing.JComboBox eventExpiringBox
      • spinner1

        private javax.swing.JSpinner spinner1
      • spinner2

        private javax.swing.JSpinner spinner2
      • spinner3

        private javax.swing.JSpinner spinner3
      • maxLabel

        private javax.swing.JLabel maxLabel
      • unlimitedMulligansCB

        private javax.swing.JCheckBox unlimitedMulligansCB
      • balancedTowersCB

        private javax.swing.JCheckBox balancedTowersCB
      • nowDateAndTimeLabel

        private javax.swing.JLabel nowDateAndTimeLabel
      • atDateField

        private javax.swing.JTextField atDateField
      • atTimeField

        private javax.swing.JTextField atTimeField
      • durationField

        private javax.swing.JTextField durationField
      • summaryText

        private javax.swing.JTextField summaryText
      • myDateFormat

        private java.text.DateFormat myDateFormat
      • myTimeFormat

        private java.text.DateFormat myTimeFormat
      • proposeButton

        private javax.swing.JButton proposeButton
      • cancelButton

        private javax.swing.JButton cancelButton
      • enrollButton

        private javax.swing.JButton enrollButton
      • unenrollButton

        private javax.swing.JButton unenrollButton
      • startButton

        private javax.swing.JButton startButton
      • startLocallyButton

        private javax.swing.JButton startLocallyButton
      • watchButton

        private javax.swing.JButton watchButton
      • hideButton

        private javax.swing.JButton hideButton
      • hideButtonText

        private javax.swing.JLabel hideButtonText
      • gameNrField

        private javax.swing.JTextField gameNrField
      • autoGSNothingRB

        private javax.swing.JRadioButton autoGSNothingRB
      • autoGSHideRB

        private javax.swing.JRadioButton autoGSHideRB
      • autoGSCloseRB

        private javax.swing.JRadioButton autoGSCloseRB
      • infoTextLabel

        private javax.swing.JLabel infoTextLabel
      • gamesUpdates

        private final java.util.ArrayList<GameInfo> gamesUpdates
      • gameHash

        private final java.util.HashMap<java.lang.String,​GameInfo> gameHash
        NOTE: shared with SocketThread, because WCST needs it to restore game tokens to an GameInfo object
      • deletedGames

        private final java.util.HashSet<java.lang.String> deletedGames
      • gamesTablesPanel

        private javax.swing.JPanel gamesTablesPanel
      • gamesCards

        private javax.swing.JPanel gamesCards
      • propGamesCard

        private javax.swing.JPanel propGamesCard
      • proposedGameTable

        private javax.swing.JTable proposedGameTable
      • runGameTable

        private javax.swing.JTable runGameTable
      • windowTitle

        private static java.lang.String windowTitle
      • LogoutButtonText

        private static final java.lang.String LogoutButtonText
        See Also:
        Constant Field Values
      • CancelLoginButtonText

        private static final java.lang.String CancelLoginButtonText
        See Also:
        Constant Field Values
      • createAccountButtonText

        private static final java.lang.String createAccountButtonText
        See Also:
        Constant Field Values
      • chgPasswordButtonText

        private static final java.lang.String chgPasswordButtonText
        See Also:
        Constant Field Values
      • ProposeButtonText

        private static final java.lang.String ProposeButtonText
        See Also:
        Constant Field Values
      • EnrollButtonText

        private static final java.lang.String EnrollButtonText
        See Also:
        Constant Field Values
      • UnenrollButtonText

        private static final java.lang.String UnenrollButtonText
        See Also:
        Constant Field Values
      • CancelButtonText

        private static final java.lang.String CancelButtonText
        See Also:
        Constant Field Values
      • StartLocallyButtonText

        private static final java.lang.String StartLocallyButtonText
        See Also:
        Constant Field Values
      • AutoGamePaneCBText

        private static final java.lang.String AutoGamePaneCBText
        See Also:
        Constant Field Values
      • createAccountLabelText

        private static final java.lang.String createAccountLabelText
        See Also:
        Constant Field Values
      • chgPasswordLabelText

        private static final java.lang.String chgPasswordLabelText
        See Also:
        Constant Field Values
      • AutoGameStartActionNothing

        private static final java.lang.String AutoGameStartActionNothing
        See Also:
        Constant Field Values
      • AutoGameStartActionHide

        private static final java.lang.String AutoGameStartActionHide
        See Also:
        Constant Field Values
      • AutoGameStartActionClose

        private static final java.lang.String AutoGameStartActionClose
        See Also:
        Constant Field Values
      • optAutoGameStartAction

        private static final java.lang.String optAutoGameStartAction
        See Also:
        Constant Field Values
      • defaultSummaryText

        private static final java.lang.String defaultSummaryText
        See Also:
        Constant Field Values
      • dialogTitle

        private static java.lang.String dialogTitle
      • dialogMessage

        private static java.lang.String dialogMessage
    • Constructor Detail

      • WebClient

        public WebClient​(WhatNextManager whatNextManager,
                         java.lang.String hostname,
                         int port,
                         java.lang.String login,
                         java.lang.String password)
    • Method Detail

      • initValues

        private void initValues​(java.lang.String hostname,
                                int port,
                                java.lang.String login,
                                java.lang.String password)
      • setGameClient

        public void setGameClient​(Client c)
      • setScheduledGamesMode

        private void setScheduledGamesMode​(boolean scheduled)
      • getScheduledGamesMode

        public boolean getScheduledGamesMode()
      • onGameStartAutoAction

        public void onGameStartAutoAction()
      • setupGUI

        private void setupGUI()
      • autoActions

        private void autoActions()
      • doAutoGSAction

        private void doAutoGSAction()
      • updateStatus

        public void updateStatus​(java.lang.String text,
                                 java.awt.Color color)
      • addAdminTab

        private void addAdminTab()
      • removeAdminTab

        private void removeAdminTab()
      • setAdmin

        private void setAdmin​(boolean isAdmin)
      • isAdmin

        public boolean isAdmin()
      • showAnswer

        public void showAnswer​(java.lang.String s)
      • getHost

        public java.lang.String getHost()
      • getPort

        public java.lang.String getPort()
      • createServerTab

        private void createServerTab()
      • addRadioButton

        private void addRadioButton​(java.awt.Container cont,
                                    javax.swing.ButtonGroup group,
                                    java.lang.String text,
                                    java.lang.String current,
                                    java.awt.event.ItemListener listener)
      • nonBoldLabel

        private javax.swing.JLabel nonBoldLabel​(java.lang.String text)
      • makeTextBox

        private javax.swing.Box makeTextBox​(java.awt.Component c)
      • makeTextBox2

        private javax.swing.Box makeTextBox2​(java.awt.Component c,
                                             java.awt.Component c2)
      • initFormats

        private void initFormats()
      • makeDateTimeInfoString

        private java.lang.String makeDateTimeInfoString​(java.util.Calendar now)
      • updateDateTimeInfoString

        private void updateDateTimeInfoString()
      • createCreateGamesTab

        private void createCreateGamesTab()
      • getNowPlusOffset

        private java.util.Calendar getNowPlusOffset​(java.util.Calendar now,
                                                    int days,
                                                    int hours)
        Determine a point in time given amount of days and hours from now. Round it to a full hour (down if min <= 10, next hour otherwise).
        Parameters:
        days -
        hours -
        Returns:
      • reactOnScheduleRadioButtonChange

        public void reactOnScheduleRadioButtonChange​(java.awt.event.ItemEvent e)
      • createPreferencesPane

        private void createPreferencesPane()
      • updateMaxSpinner

        private void updateMaxSpinner​(java.lang.String variant)
      • adjustToPossibleMax

        private void adjustToPossibleMax​(javax.swing.JSpinner spinner,
                                         int max)
      • getMaxForVariant

        private int getMaxForVariant​(java.lang.String variant)
      • createRunningGamesTab

        private void createRunningGamesTab()
      • createAdminTab

        private void createAdminTab()
      • beepButtonAction

        public void beepButtonAction()
      • createLoginWebClientSocketThread

        public java.lang.String createLoginWebClientSocketThread​(boolean force)
      • createRegisterWebClientSocketThread

        public java.lang.String createRegisterWebClientSocketThread​(java.lang.String username,
                                                                    java.lang.String password,
                                                                    java.lang.String email,
                                                                    java.lang.String confCode)
      • logout

        private void logout()
      • doQuit

        private void doQuit()
      • dispose

        public void dispose()
        Overrides:
        dispose in class KFrame
      • getUserinfoText

        private java.lang.String getUserinfoText()
      • updateGUI

        public void updateGUI()
      • getSelectedGameId

        public java.lang.String getSelectedGameId()
      • getSelectedGameFromRunTableId

        public java.lang.String getSelectedGameFromRunTableId()
      • makeWindowTitleForState

        private java.lang.String makeWindowTitleForState​(int state)
      • makeInfoTextForState

        private java.lang.String makeInfoTextForState​(int state)
      • makeStatusTextForState

        private java.lang.String makeStatusTextForState​(int state)
      • isEligibleToStart

        private boolean isEligibleToStart​(GameInfo gi)
        Returns true if this user would be allowed to start this game (given that all other conditions are fulfilled). Usually the allowed player is the one who created it, but if that one is not enrolled, the first of the enrolled ones is allowed then to do it.
        Parameters:
        gi -
        Returns:
        Whether this player would be allowed to start this game
      • checkIfCouldWatch

        private boolean checkIfCouldWatch​(int state)
      • checkIfCouldStartOnServer

        private boolean checkIfCouldStartOnServer​(int state)
      • isScheduledGameAndStartable

        private boolean isScheduledGameAndStartable​(java.lang.String id)
      • checkIfCouldPropose

        private boolean checkIfCouldPropose()
      • checkIfCouldCancel

        private boolean checkIfCouldCancel()
      • checkIfCouldEnroll

        private boolean checkIfCouldEnroll()
      • checkIfCouldUnenroll

        private boolean checkIfCouldUnenroll()
      • doUpdateGUI

        public void doUpdateGUI()
      • getGameHash

        public java.util.HashMap<java.lang.String,​GameInfo> getGameHash()
      • findGameByIdNoComplaint

        private GameInfo findGameByIdNoComplaint​(java.lang.String gameId)
      • findGameById

        private GameInfo findGameById​(java.lang.String gameId)
      • isOwner

        private boolean isOwner​(java.lang.String gameId)
      • validateField

        public boolean validateField​(java.awt.Component parent,
                                     java.lang.String content,
                                     java.lang.String fieldName)
      • validatePort

        boolean validatePort​(java.awt.Component parent,
                             java.lang.String portText)
      • doLogin

        public void doLogin()
      • doCancelConnect

        public void doCancelConnect()
      • validateServerAndPort

        public boolean validateServerAndPort()
      • doLogout

        public void doLogout()
      • cancelOwnInstantGameOnLogout

        private void cancelOwnInstantGameOnLogout()
      • doRegisterOrPasswordDialog

        private void doRegisterOrPasswordDialog​(boolean register)
      • tryChangePassword

        public java.lang.String tryChangePassword​(java.lang.String name,
                                                  java.lang.String oldPW,
                                                  java.lang.String newPW1)
      • doCancel

        private void doCancel​(java.lang.String gameId)
      • doScheduleDummy

        public void doScheduleDummy()
      • do_proposeGame

        private void do_proposeGame​(java.lang.String variant,
                                    java.lang.String viewmode,
                                    long startAt,
                                    int duration,
                                    java.lang.String summary,
                                    java.lang.String expire,
                                    boolean unlimMulli,
                                    boolean balTowers,
                                    int min,
                                    int target,
                                    int max)
      • getStartTime

        private long getStartTime()
      • getDuration

        private int getDuration()
      • getSummaryText

        private java.lang.String getSummaryText()
      • doEnroll

        private boolean doEnroll​(java.lang.String gameId)
      • doUnenroll

        private boolean doUnenroll​(java.lang.String gameId)
      • doStart

        boolean doStart​(java.lang.String gameId)
      • doStartLocally

        private boolean doStartLocally​(java.lang.String gameId)
      • informStartingOnPlayerHost

        public void informStartingOnPlayerHost​(java.lang.String hostingPlayer,
                                               java.lang.String hostingHost,
                                               int hostingPort)
      • informGameStartedLocally

        public void informGameStartedLocally()
      • informLocallyGameOver

        public void informLocallyGameOver()
      • setLocalServer

        public void setLocalServer​(Server server)
      • didEnroll

        public void didEnroll​(java.lang.String gameId,
                              java.lang.String user)
        Specified by:
        didEnroll in interface IWebClient
      • didUnenroll

        public void didUnenroll​(java.lang.String gameId,
                                java.lang.String user)
        Specified by:
        didUnenroll in interface IWebClient
      • setWatching

        public void setWatching​(java.lang.String gameId)
      • clearWatching

        public void clearWatching()
      • gameStartsSoon

        public void gameStartsSoon​(java.lang.String gameId,
                                   java.lang.String startUser)
        Specified by:
        gameStartsSoon in interface IWebClient
      • notifyComingUp

        public void notifyComingUp​(boolean success)
      • setupTimer

        private java.util.Timer setupTimer()
      • gameStartsNow

        public void gameStartsNow​(java.lang.String gameId,
                                  int port,
                                  java.lang.String hostingHost)
        Specified by:
        gameStartsNow in interface IWebClient
      • startOwnClient

        public void startOwnClient​(java.lang.String gameId,
                                   int port,
                                   java.lang.String hostingHost)
      • startSpectatorClient

        public void startSpectatorClient​(java.lang.String gameId,
                                         int port,
                                         java.lang.String hostingHost)
      • gameCancelled

        public void gameCancelled​(java.lang.String gameId,
                                  java.lang.String byUser)
        Specified by:
        gameCancelled in interface IWebClient
      • chatDeliver

        public void chatDeliver​(java.lang.String chatId,
                                long when,
                                java.lang.String sender,
                                java.lang.String message,
                                boolean resent)
        Specified by:
        chatDeliver in interface IWebClient
      • watchGameInfo

        public void watchGameInfo​(java.lang.String gameId,
                                  java.lang.String host,
                                  int port)
        Specified by:
        watchGameInfo in interface IWebClient
      • requestAttention

        public void requestAttention​(long when,
                                     java.lang.String byUser,
                                     boolean byAdmin,
                                     java.lang.String message,
                                     int beepCount,
                                     long beepInterval,
                                     boolean windows)
        Specified by:
        requestAttention in interface IWebClient
      • showRequestAttentionMessage

        private void showRequestAttentionMessage()
      • deliverGeneralMessage

        public void deliverGeneralMessage​(long when,
                                          boolean error,
                                          java.lang.String title,
                                          java.lang.String message)
        Specified by:
        deliverGeneralMessage in interface IWebClient
      • systemMessage

        public void systemMessage​(long when,
                                  java.lang.String message)
        Specified by:
        systemMessage in interface IWebClient
      • tellGameEnds

        public void tellGameEnds()
      • userInfo

        public void userInfo​(int loggedin,
                             int enrolled,
                             int playing,
                             int dead,
                             long ago,
                             java.lang.String text)
        Specified by:
        userInfo in interface IWebClient
      • handleGameInfoUpdates

        private void handleGameInfoUpdates​(GameInfo gi)
      • replaceInTable

        private void replaceInTable​(javax.swing.JTable table,
                                    GameInfo gi)
      • hideButtonAction

        private void hideButtonAction()
      • watchButtonAction

        private void watchButtonAction()
      • loadGameButtonAction

        private void loadGameButtonAction()
      • quitButtonAction

        private void quitButtonAction()
      • loginLogoutButtonAction

        void loginLogoutButtonAction​(java.lang.String command)
      • executeLoginLogoutButtonAction

        private void executeLoginLogoutButtonAction​(java.lang.String command)
      • rereadLoginMsgButtonAction

        private void rereadLoginMsgButtonAction()
      • shutdownButtonAction

        private void shutdownButtonAction()
      • dumpInfoButtonAction

        private void dumpInfoButtonAction()
      • debugSubmitButtonAction

        private void debugSubmitButtonAction()
      • registerOrPasswordButtonAction

        private void registerOrPasswordButtonAction​(java.lang.String command)
      • startLocallyButtonAction

        private void startLocallyButtonAction()
      • startButtonAction

        private void startButtonAction()
      • cancelButtonAction

        private void cancelButtonAction()
      • unenrollButtonAction

        private void unenrollButtonAction()
      • findMyInstantGames

        private java.util.List<GameInfo> findMyInstantGames()
        Find all "relevant" instant games owned by this player (relevant means except those who are running, ending or deleted). Normally there should ever be only one, but in strange cases... (like, game start failed or something...)
      • ownInstantGameIfAny

        private GameInfo ownInstantGameIfAny()
        If there is at least one instant game by this player, return it (one of it if many), otherwise null. Normally there should ever be only one, but in strange cases... (like, game start failed or something...)
        Returns:
        The (or: any) instant game or null
      • displayOnlyOneInstantGameMessage

        private void displayOnlyOneInstantGameMessage​(java.lang.String action,
                                                      java.lang.String message)
      • enrollButtonAction

        private void enrollButtonAction()
      • proposeButtonAction

        private void proposeButtonAction()