88import java .util .Map ;
99
1010public 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 ;
1313
1414 public ServerConsole (Map <String , ClientConnection > clients ) {
1515 this .consoleReader = System .console () == null ? new UserSystemInReader () : new UserConsoleReader ();
@@ -20,7 +20,12 @@ public ServerConsole(Map<String, ClientConnection> clients) {
2020 public void run () {
2121 while (true ) {
2222 try {
23- executeCommand (consoleReader .readLine ());
23+ String line = consoleReader .readLine ();
24+ if (line != null ) {
25+ executeCommand (consoleReader .readLine ());
26+ } else {
27+ break ;
28+ }
2429 } catch (IOException e ) {
2530 e .printStackTrace ();
2631 }
@@ -30,10 +35,15 @@ public void run() {
3035 private void executeCommand (String command ) {
3136 if (command .startsWith ("kick " )) {
3237 kickUser (command .substring ("kick " .length ()));
33- } else if (command .startsWith ("clients" )) {
38+ } else if (command .equals ("clients" )) {
3439 printListOfClients ();
3540 } else if (command .startsWith ("broadcast " )) {
3641 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" );
3747 } else {
3848 System .err .println ("UNKNOWN COMMAND" );
3949 }
0 commit comments