Skip to content

Commit 77d263f

Browse files
committed
Renamed ConnectState to ConnectionState.
Added basic empty string validation to the LoginState.join() method.
1 parent b806847 commit 77d263f

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

sim-eth-basic/src/main/java/example/ConnectState.java renamed to sim-eth-basic/src/main/java/example/ConnectionState.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@
6161
*
6262
* @author Paul Speed
6363
*/
64-
public class ConnectState extends BaseAppState {
64+
public class ConnectionState extends BaseAppState {
6565

66-
static Logger log = LoggerFactory.getLogger(ConnectState.class);
66+
static Logger log = LoggerFactory.getLogger(ConnectionState.class);
6767

6868
private AppState parent;
6969

@@ -79,7 +79,7 @@ public class ConnectState extends BaseAppState {
7979

8080
private volatile boolean closing;
8181

82-
public ConnectState( AppState parent, String host, int port ) {
82+
public ConnectionState( AppState parent, String host, int port ) {
8383
this.parent = parent;
8484
this.host = host;
8585
this.port = port;
@@ -94,6 +94,12 @@ public void disconnect() {
9494

9595
public boolean join( String userName ) {
9696
log.info("join(" + userName + ")");
97+
98+
userName = userName.trim();
99+
if( userName.length() == 0 ) {
100+
showError("Join Error", "Please specify a player name for use in game.", null, false);
101+
return false;
102+
}
97103

98104
return true;
99105
}

sim-eth-basic/src/main/java/example/HostState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public HostState( int port, String description ) {
8686

8787
protected void joinGame() {
8888
log.info("joinGame()");
89-
getStateManager().attach(new ConnectState(this, "127.0.0.1", port));
89+
getStateManager().attach(new ConnectionState(this, "127.0.0.1", port));
9090
setEnabled(false); // hide our window
9191
}
9292

sim-eth-basic/src/main/java/example/LoginState.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
/**
4949
* A basic "login" state that provides a simple UI for logging in
5050
* once a connection has been established. This just manages the UI
51-
* and calls back to the ConnectState to do the actual 'work'.
51+
* and calls back to the ConnectionState to do the actual 'work'.
5252
*
5353
* @author Paul Speed
5454
*/
@@ -63,13 +63,13 @@ public LoginState() {
6363
protected void join() {
6464

6565
String name = nameField.getText().trim();
66-
if( getState(ConnectState.class).join(nameField.getText()) ) {
66+
if( getState(ConnectionState.class).join(nameField.getText()) ) {
6767
getStateManager().detach(this);
6868
}
6969
}
7070

7171
protected void cancel() {
72-
getState(ConnectState.class).disconnect();
72+
getState(ConnectionState.class).disconnect();
7373
getStateManager().detach(this);
7474
}
7575

sim-eth-basic/src/main/java/example/MainMenuState.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ protected void connect() {
107107

108108
// Add the state that will manage our remote connection and create
109109
// the game states and so on.
110-
getStateManager().attach(new ConnectState(this, host, port));
110+
getStateManager().attach(new ConnectionState(this, host, port));
111111

112112
// Disable ourselves
113113
setEnabled(false);
@@ -123,7 +123,7 @@ protected void host() {
123123

124124
try {
125125
// Add the state to manage the hosting environment. It will launch
126-
// a self-connecting ConnectState on its own.
126+
// a self-connecting ConnectionState on its own.
127127
getStateManager().attach(new HostState(port, hostDescription.getText()));
128128

129129
// Disable ourselves

0 commit comments

Comments
 (0)