soc.client
Class SOCAccountClient

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
                  extended by soc.client.SOCAccountClient
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.KeyListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.lang.Runnable, java.util.EventListener, javax.accessibility.Accessible

public class SOCAccountClient
extends java.applet.Applet
implements java.lang.Runnable, java.awt.event.ActionListener, java.awt.event.KeyListener

Applet/Standalone client for connecting to the SOCServer and making user accounts. If you want another connection port, you have to specify it as the "port" argument in the html source. If you run this as a stand-alone, you have to specify the server's hostname and port on the command line.

Author:
Robert S Thomas
See Also:
Serialized Form

Nested Class Summary
private  class SOCAccountClient.MyWindowAdapter
           
 
Nested classes/interfaces inherited from class java.applet.Applet
java.applet.Applet.AccessibleApplet
 
Nested classes/interfaces inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  java.applet.AppletContext ac
           
protected  java.awt.CardLayout cardLayout
           
(package private)  java.util.Locale cliLocale
          Locale for i18n message lookups used for strings.
private  java.awt.Button conn_cancel
          Connect and Cancel buttons on connPanel.
private  java.awt.Button conn_connect
          Connect and Cancel buttons on connPanel.
private static java.lang.String CONN_PANEL
          CardLayout string for connPanel.
private  java.awt.TextField conn_pass
          Username, password, and status fields on connPanel.
private  boolean conn_sentAuth
          If true, a username/password SOCAuthRequest has been sent to the server from connPanel.
private  java.awt.TextField conn_status
          Username, password, and status fields on connPanel.
private  java.awt.TextField conn_user
          Username, password, and status fields on connPanel.
protected  boolean connected
           
private  java.awt.Panel connPanel
          Connect and Authenticate panel (CONN_PANEL), for when server needs authentication to create a user account.
protected  java.awt.TextField email
           
protected  java.lang.String emailAddress
          the email address
protected  java.lang.Exception ex
           
protected  java.lang.String host
           
protected  java.io.DataInputStream in
           
private static java.lang.String MAIN_PANEL
          CardLayout string for the main panel while connected to a server: Has fields to enter nick, pass, etc, status display and submit button.
private static java.lang.String MESSAGE_PANEL
          CardLayout string for the message panel when not connected to a server; message text is shown in messageLabel.
protected  java.awt.Label messageLabel
           
protected  java.awt.TextField nick
           
private  java.awt.Label nickLabel
          Nickname field label.
protected  java.lang.String nickname
          the nickname
private  AWTToolTip nickTTip
          Nickname field tooltip reference, for use if its text must be updated.
protected  java.io.DataOutputStream out
           
protected  java.awt.TextField pass
           
protected  java.awt.TextField pass2
           
protected  java.lang.String password
          the password
protected  java.lang.String password2
          the second password
protected  int port
           
private  java.awt.Label promptLabel
          Account info dialog prompt/label.
protected  java.lang.Thread reader
           
protected  java.net.Socket s
           
protected  SOCServerFeatures sFeatures
          Server's active optional features, sent soon after connect, or null if unknown.
static int SRV_VERSION_MIN
          Minimum server version (v1.1.19) to which this account-management client will connect.
protected  java.awt.TextField status
           
private  SOCStringManager strings
          i18n text strings.
protected  java.awt.Button submit
           
protected  boolean submitLock
           
protected  int sVersion
          Server version number for remote server, sent soon after connect.
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
SOCAccountClient()
          Create a SOCAccountClient connecting to localhost port 8880
SOCAccountClient(java.lang.String h, int p)
          Constructor for connecting to the specified host, on the specified port.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Handle mouse clicks and keyboard
private  void clickConnCancel()
          Disconnect from connect/auth panel, show "disconnected" message.
private  void clickConnConnect()
          "Connect" button, from connect/authenticate panel; check nickname & password fields, send auth request to server, set conn_sentAuth flag.
 void connect()
          Attempts to connect to the server.
private  java.awt.event.WindowAdapter createWindowAdapter()
           
 void destroy()
          destroy the applet
protected  void disconnect()
          disconnect from the net
 java.lang.String getAppletInfo()
          applet info
 int getHexParameter(java.lang.String name)
          Retrieve a parameter and translate to a hex value.
protected  void handleCHANNELS(SOCChannels mes)
          Handle the "list of channels" message: Server connection is complete, show MAIN_PANEL unless connPanel is already showing.
protected  void handleREJECTCONNECTION(SOCRejectConnection mes)
          handle the "reject connection" message
protected  void handleSTATUSMESSAGE(SOCStatusMessage mes)
          handle the "status message" message.
private  void handleVERSION(SOCVersion mes)
          Handle the "version" message: Server's version and feature report.
 void init()
          Initialize the applet
private  void initInterface_conn()
          Connect setup for username and password authentication: connPanel / CONN_PANEL.
protected  void initVisualElements()
          init the visual elements at startup: MESSAGE_PANEL, MAIN_PANEL.
 void keyPressed(java.awt.event.KeyEvent e)
          For Connect panel, handle Enter or Esc key (KeyListener).
 void keyReleased(java.awt.event.KeyEvent e)
          Stub required by KeyListener
 void keyTyped(java.awt.event.KeyEvent e)
          Stub required by KeyListener
static void main(java.lang.String[] args)
          for stand-alones
 boolean put(java.lang.String s)
          write a message to the net
 void run()
          continuously read from the net in a separate thread
 void treat(SOCMessage mes)
          Treat the incoming messages
private  void updateLabelsIfNotOpenReg()
          Update account-info label texts if needed.
static void usage()
          for stand-alones
 
Methods inherited from class java.applet.Applet
getAccessibleContext, getAppletContext, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start, stop
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SRV_VERSION_MIN

public static final int SRV_VERSION_MIN
Minimum server version (v1.1.19) to which this account-management client will connect. The required minimum version simplifies logic and assumptions about available SOCServerFeatures. Older clients can be downloaded or built from git release tags to work with older servers.

Same format as Version.versionNumber(). Same value as SOCServerFeatures.VERSION_FOR_SERVERFEATURES.

Since:
1.1.20
See Also:
Constant Field Values

MAIN_PANEL

private static final java.lang.String MAIN_PANEL
CardLayout string for the main panel while connected to a server: Has fields to enter nick, pass, etc, status display and submit button.

See Also:
Constant Field Values

MESSAGE_PANEL

private static final java.lang.String MESSAGE_PANEL
CardLayout string for the message panel when not connected to a server; message text is shown in messageLabel.

See Also:
Constant Field Values

CONN_PANEL

private static final java.lang.String CONN_PANEL
CardLayout string for connPanel.

See Also:
Constant Field Values

promptLabel

private java.awt.Label promptLabel
Account info dialog prompt/label.

Since:
1.1.20

nickLabel

private java.awt.Label nickLabel
Nickname field label.

Since:
1.1.20

nickTTip

private AWTToolTip nickTTip
Nickname field tooltip reference, for use if its text must be updated.


nick

protected java.awt.TextField nick

pass

protected java.awt.TextField pass

pass2

protected java.awt.TextField pass2

email

protected java.awt.TextField email

status

protected java.awt.TextField status

submit

protected java.awt.Button submit

messageLabel

protected java.awt.Label messageLabel

ac

protected java.applet.AppletContext ac

submitLock

protected boolean submitLock

connPanel

private java.awt.Panel connPanel
Connect and Authenticate panel (CONN_PANEL), for when server needs authentication to create a user account. Created in initInterface_conn().

Since:
1.1.19

conn_user

private java.awt.TextField conn_user
Username, password, and status fields on connPanel.

Since:
1.1.19

conn_pass

private java.awt.TextField conn_pass
Username, password, and status fields on connPanel.

Since:
1.1.19

conn_status

private java.awt.TextField conn_status
Username, password, and status fields on connPanel.

Since:
1.1.19

conn_connect

private java.awt.Button conn_connect
Connect and Cancel buttons on connPanel.

Since:
1.1.19

conn_cancel

private java.awt.Button conn_cancel
Connect and Cancel buttons on connPanel.

Since:
1.1.19

conn_sentAuth

private boolean conn_sentAuth
If true, a username/password SOCAuthRequest has been sent to the server from connPanel. Used by handleSTATUSMESSAGE(SOCStatusMessage) to show error results using connPanel instead of the main panel.

Since:
1.1.19

cardLayout

protected java.awt.CardLayout cardLayout

host

protected java.lang.String host

port

protected int port

s

protected java.net.Socket s

in

protected java.io.DataInputStream in

out

protected java.io.DataOutputStream out

reader

protected java.lang.Thread reader

ex

protected java.lang.Exception ex

connected

protected boolean connected

sVersion

protected int sVersion
Server version number for remote server, sent soon after connect.

Since:
1.1.19

sFeatures

protected SOCServerFeatures sFeatures
Server's active optional features, sent soon after connect, or null if unknown.

Since:
1.1.19

nickname

protected java.lang.String nickname
the nickname


password

protected java.lang.String password
the password


password2

protected java.lang.String password2
the second password


emailAddress

protected java.lang.String emailAddress
the email address


cliLocale

final java.util.Locale cliLocale
Locale for i18n message lookups used for strings. Also sent to server when connecting. Override if needed in the constructor by reading the PROP_JSETTLERS_LOCALE system property "jsettlers.locale".

Since:
2.0.00

strings

private final SOCStringManager strings
i18n text strings. Set in constructor based on cliLocale.

Since:
2.0.00
Constructor Detail

SOCAccountClient

public SOCAccountClient()
Create a SOCAccountClient connecting to localhost port 8880


SOCAccountClient

public SOCAccountClient(java.lang.String h,
                        int p)
Constructor for connecting to the specified host, on the specified port. Must call 'init' to start up and do layout.

The SOCAccountClient GUI's own localized strings use the current user's default locale, unless overridden by setting the PROP_JSETTLERS_LOCALE system property "jsettlers.locale".

Parameters:
h - host
p - port
Method Detail

initVisualElements

protected void initVisualElements()
init the visual elements at startup: MESSAGE_PANEL, MAIN_PANEL. Labels' text assumes self-registration (Open Registration); if this is not the case call updateLabelsIfNotOpenReg() afterwards.

See Also:
initInterface_conn()

initInterface_conn

private void initInterface_conn()
Connect setup for username and password authentication: connPanel / CONN_PANEL. Called if server doesn't have SOCServerFeatures.FEAT_OPEN_REG. Calls Container.validate() and conn_user.requestFocus().

Since:
1.1.19
See Also:
initVisualElements()

updateLabelsIfNotOpenReg

private void updateLabelsIfNotOpenReg()
Update account-info label texts if needed. If server supports self-registration (Open Registration), does nothing. Assumes initVisualElements() has already been called.

Since:
1.1.20

getHexParameter

public int getHexParameter(java.lang.String name)
Retrieve a parameter and translate to a hex value.

Parameters:
name - a parameter name. null is ignored
Returns:
the parameter parsed as a hex value or -1 on error

init

public void init()
Initialize the applet

Overrides:
init in class java.applet.Applet

connect

public void connect()
Attempts to connect to the server. See connected for success or failure.

Throws:
java.lang.IllegalStateException - if already connected

clickConnConnect

private void clickConnConnect()
"Connect" button, from connect/authenticate panel; check nickname & password fields, send auth request to server, set conn_sentAuth flag. When the server responds with SOCStatusMessage.SV_OK, the MAIN_PANEL will be shown.

Since:
1.1.19

clickConnCancel

private void clickConnCancel()
Disconnect from connect/auth panel, show "disconnected" message.

Since:
1.1.19

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Handle mouse clicks and keyboard

Specified by:
actionPerformed in interface java.awt.event.ActionListener

run

public void run()
continuously read from the net in a separate thread

Specified by:
run in interface java.lang.Runnable

put

public boolean put(java.lang.String s)
write a message to the net

Parameters:
s - the message
Returns:
true if the message was sent, false if not

treat

public void treat(SOCMessage mes)
Treat the incoming messages

Parameters:
mes - the message

handleVERSION

private void handleVERSION(SOCVersion mes)
Handle the "version" message: Server's version and feature report. Will disconnect if server is older than SRV_VERSION_MIN.

Parameters:
mes - the message
Since:
1.1.19

handleCHANNELS

protected void handleCHANNELS(SOCChannels mes)
Handle the "list of channels" message: Server connection is complete, show MAIN_PANEL unless connPanel is already showing.

Parameters:
mes - the message

handleREJECTCONNECTION

protected void handleREJECTCONNECTION(SOCRejectConnection mes)
handle the "reject connection" message

Parameters:
mes - the message

handleSTATUSMESSAGE

protected void handleSTATUSMESSAGE(SOCStatusMessage mes)
handle the "status message" message. If this is in response to authrequest when connecting, show MAIN_PANEL. If we've just created a user (SOCStatusMessage.SV_ACCT_CREATED_OK), clear the password fields: must re-enter if creating another.

Parameters:
mes - the message

disconnect

protected void disconnect()
disconnect from the net


getAppletInfo

public java.lang.String getAppletInfo()
applet info

Overrides:
getAppletInfo in class java.applet.Applet

destroy

public void destroy()
destroy the applet

Overrides:
destroy in class java.applet.Applet

usage

public static void usage()
for stand-alones


main

public static void main(java.lang.String[] args)
for stand-alones


createWindowAdapter

private java.awt.event.WindowAdapter createWindowAdapter()

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
For Connect panel, handle Enter or Esc key (KeyListener).

Specified by:
keyPressed in interface java.awt.event.KeyListener
Since:
1.1.19

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Stub required by KeyListener

Specified by:
keyReleased in interface java.awt.event.KeyListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Stub required by KeyListener

Specified by:
keyTyped in interface java.awt.event.KeyListener