Class WebClient

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, 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:
  • Field Details

  • Constructor Details

  • Method Details

    • getClientVersion

      public int getClientVersion()
      Specified by:
      getClientVersion in interface IWebClient
    • initValues

      private void initValues(String hostname, int port, String login, 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(String text, Color color)
    • addAdminTab

      private void addAdminTab()
    • removeAdminTab

      private void removeAdminTab()
    • setAdmin

      private void setAdmin(boolean isAdmin)
    • isAdmin

      public boolean isAdmin()
    • showAnswer

      public void showAnswer(String s)
    • getHost

      public String getHost()
    • getPort

      public String getPort()
    • getGameRunner

      public IGameRunner getGameRunner()
    • getWhomToNotify

      public INotifyWebServer getWhomToNotify()
    • createServerTab

      private void createServerTab()
    • addRadioButton

      private void addRadioButton(Container cont, ButtonGroup group, String text, String current, ItemListener listener)
    • nonBoldLabel

      private JLabel nonBoldLabel(String text)
    • makeTextBox

      private Box makeTextBox(Component c)
    • makeTextBox2

      private Box makeTextBox2(Component c, Component c2)
    • initFormats

      private void initFormats()
    • makeDateTimeInfoString

      private String makeDateTimeInfoString(Calendar now)
    • updateDateTimeInfoString

      private void updateDateTimeInfoString()
    • createCreateGamesTab

      private void createCreateGamesTab()
    • getNowPlusOffset

      private Calendar getNowPlusOffset(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(ItemEvent e)
    • createPreferencesPane

      private void createPreferencesPane()
    • updateMaxSpinner

      private void updateMaxSpinner(String variant)
    • adjustToPossibleMax

      private void adjustToPossibleMax(JSpinner spinner, int max)
    • getMaxForVariant

      private int getMaxForVariant(String variant)
    • createRunningGamesTab

      private void createRunningGamesTab()
    • createAdminTab

      private void createAdminTab()
    • beepButtonAction

      public void beepButtonAction()
    • createLoginWebClientSocketThread

      public String createLoginWebClientSocketThread(boolean force)
    • createRegisterWebClientSocketThread

      public String createRegisterWebClientSocketThread(String username, String password, String email, String confCode)
    • logout

      private void logout()
    • doQuit

      private void doQuit()
    • dispose

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

      private String getUserinfoText()
    • updateGUI

      public void updateGUI()
    • getSelectedGameId

      public String getSelectedGameId()
    • getSelectedGameFromRunTableId

      public String getSelectedGameFromRunTableId()
    • makeWindowTitleForState

      private String makeWindowTitleForState(int state)
    • makeInfoTextForState

      private String makeInfoTextForState(int state)
    • makeStatusTextForState

      private 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(String id)
    • checkIfCouldPropose

      private boolean checkIfCouldPropose()
    • checkIfCouldCancel

      private boolean checkIfCouldCancel()
    • checkIfCouldEnroll

      private boolean checkIfCouldEnroll()
    • checkIfCouldUnenroll

      private boolean checkIfCouldUnenroll()
    • doUpdateGUI

      public void doUpdateGUI()
    • getGameHash

      public HashMap<String,GameInfo> getGameHash()
    • findGameByIdNoComplaint

      private GameInfo findGameByIdNoComplaint(String gameId)
    • findGameById

      private GameInfo findGameById(String gameId)
    • isOwner

      private boolean isOwner(String gameId)
    • validateField

      public boolean validateField(Component parent, String content, String fieldName)
    • validatePort

      boolean validatePort(Component parent, 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 String tryChangePassword(String name, String oldPW, String newPW1)
    • doCancel

      private void doCancel(String gameId)
    • doScheduleDummy

      public void doScheduleDummy()
    • do_proposeGame

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

      private long getStartTime()
    • getDuration

      private int getDuration()
    • getSummaryText

      private String getSummaryText()
    • doEnroll

      private boolean doEnroll(String gameId)
    • doUnenroll

      private boolean doUnenroll(String gameId)
    • doStart

      boolean doStart(String gameId)
    • doStartLocally

      private boolean doStartLocally(String gameId)
    • informStartingOnPlayerHost

      public void informStartingOnPlayerHost(String hostingPlayer, String hostingHost, int hostingPort)
    • informGameStartedLocally

      public void informGameStartedLocally()
    • informLocallyGameOver

      public void informLocallyGameOver()
    • setLocalServer

      public void setLocalServer(Server server)
    • grantAdminStatus

      public void grantAdminStatus()
      Specified by:
      grantAdminStatus in interface IWebClient
    • didEnroll

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

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

      public void setWatching(String gameId)
    • clearWatching

      public void clearWatching()
    • gameStartsSoon

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

      public void notifyComingUp(boolean success)
    • setupTimer

      private Timer setupTimer()
    • gameStartsNow

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

      public void startOwnClient(String gameId, int port, String hostingHost)
    • startSpectatorClient

      public void startSpectatorClient(String gameId, int port, String hostingHost)
    • gameCancelled

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

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

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

      public void requestAttention(long when, String byUser, boolean byAdmin, 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, String title, String message)
      Specified by:
      deliverGeneralMessage in interface IWebClient
    • systemMessage

      public void systemMessage(long when, 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, String text)
      Specified by:
      userInfo in interface IWebClient
    • gameInfo

      public void gameInfo(GameInfo gi)
      Specified by:
      gameInfo in interface IWebClient
    • handleGameInfoUpdates

      private void handleGameInfoUpdates(GameInfo gi)
    • replaceInTable

      private void replaceInTable(JTable table, GameInfo gi)
    • connectionReset

      public void connectionReset(boolean forced)
      Specified by:
      connectionReset in interface IWebClient
    • hideButtonAction

      private void hideButtonAction()
    • watchButtonAction

      private void watchButtonAction()
    • loadGameButtonAction

      private void loadGameButtonAction()
    • quitButtonAction

      private void quitButtonAction()
    • loginLogoutButtonAction

      void loginLogoutButtonAction(String command)
    • executeLoginLogoutButtonAction

      private void executeLoginLogoutButtonAction(String command)
    • rereadLoginMsgButtonAction

      private void rereadLoginMsgButtonAction()
    • shutdownButtonAction

      private void shutdownButtonAction()
    • dumpInfoButtonAction

      private void dumpInfoButtonAction()
    • debugSubmitButtonAction

      private void debugSubmitButtonAction()
    • registerOrPasswordButtonAction

      private void registerOrPasswordButtonAction(String command)
    • startLocallyButtonAction

      private void startLocallyButtonAction()
    • startButtonAction

      private void startButtonAction()
    • cancelButtonAction

      private void cancelButtonAction()
    • unenrollButtonAction

      private void unenrollButtonAction()
    • findMyInstantGames

      private 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(String action, String message)
    • enrollButtonAction

      private void enrollButtonAction()
    • proposeButtonAction

      private void proposeButtonAction()