8
8
import java .util .Map ;
9
9
10
10
public class ServerConsole implements Runnable {
11
- private UserReader consoleReader ;
12
- private Map <String , ClientConnection > clients ;
11
+ private final UserReader consoleReader ;
12
+ private final Map <String , ClientConnection > clients ;
13
13
14
14
public ServerConsole (Map <String , ClientConnection > clients ) {
15
15
this .consoleReader = System .console () == null ? new UserSystemInReader () : new UserConsoleReader ();
@@ -20,7 +20,12 @@ public ServerConsole(Map<String, ClientConnection> clients) {
20
20
public void run () {
21
21
while (true ) {
22
22
try {
23
- executeCommand (consoleReader .readLine ());
23
+ String line = consoleReader .readLine ();
24
+ if (line != null ) {
25
+ executeCommand (consoleReader .readLine ());
26
+ } else {
27
+ break ;
28
+ }
24
29
} catch (IOException e ) {
25
30
e .printStackTrace ();
26
31
}
@@ -30,10 +35,15 @@ public void run() {
30
35
private void executeCommand (String command ) {
31
36
if (command .startsWith ("kick " )) {
32
37
kickUser (command .substring ("kick " .length ()));
33
- } else if (command .startsWith ("clients" )) {
38
+ } else if (command .equals ("clients" )) {
34
39
printListOfClients ();
35
40
} else if (command .startsWith ("broadcast " )) {
36
41
broadcast (command .substring ("broadcast " .length ()));
42
+ } else if (command .equals ("help" )) {
43
+ System .out .println ("Server commands:" +
44
+ "\n \t kick" +
45
+ "\n \t broadcast" +
46
+ "\n \t clients" );
37
47
} else {
38
48
System .err .println ("UNKNOWN COMMAND" );
39
49
}
0 commit comments