package server.shells;

import server.ServerListener;
import server.Server;
import java.util.logging.Level;

public class LineShell implements ServerListener {

    private Server server;
    private int port;

    public static final Level LOG_OUTPUT_LEVEL = Level.INFO;

    public LineShell(int port) {
        this.port = port;
    }

    public void setServer(Server server) {
        this.server = server;
    }

    public void teamsLoaded() {
        this.server.start(this.port);
    }

    public void started() {
    }

    public void startException() {
    }

    public void stopped() {
    }

    public void gotUserList (String userList) {
        if(userList.length() > 0) System.out.println(userList);
        else System.out.println("No users online right now.");
    }

    public void gotGameList (String gameList) {
        if(gameList.length() > 0) System.out.println(gameList);
        else System.out.println("No games on the server right now.");
    }

    public void log(Level level, String message) {
        if(level.intValue() >= LOG_OUTPUT_LEVEL.intValue()){
            System.out.println(message);
        }
    }
}

@@ -17,16 +17,74 @@
 hells;%0A%0A
+import java.util.logging.Level;%0Aimport java.util.Scanner;%0A
 import s
@@ -130,40 +130,8 @@
 ver;
-%0Aimport java.util.logging.Level;
 %0A%0Apu
@@ -539,24 +539,72 @@
 started() %7B%0A
+        (new Thread(new LineReader())).start();%0A
     %7D%0A%0A    p
@@ -1156,16 +1156,17 @@
 Value())
+ 
 %7B%0A      
@@ -1215,11 +1215,1732 @@
  %7D%0A    %7D
+%0A%0A    class LineReader implements Runnable %7B%0A%0A        public void run() %7B%0A            Scanner scanner = new Scanner(System.in);%0A%0A            while (true) %7B%0A                System.out.print(%22sb%3E %22);%0A                String rawCmd = scanner.next();%0A%0A                parseCmd(rawCmd);%0A            %7D%0A        %7D%0A%0A        private void parseCmd(String rawCmd) %7B%0A            String message, recipient;%0A            String text = rawCmd;%0A            %0A            if(rawCmd.startsWith(%22@%22)) %7B%0A                // %22@milan hello there!%22 -%3E message = %22hello there!%22 recipient = %22milan%22%0A                message = text.replaceAll(%22%5E@%5C%5CS+%22, %22%22);%0A                if(message.length() %3E 1) %7B%0A                    message = message.substring(1, message.length());%0A                    recipient = text.substring(1, text.length() - message.length() - 1);%0A                %7D%0A                else return; // don't send if message was empty%0A            %7D else %7B%0A                // check if it is a command%0A                if(text.toLowerCase().equals(%22/games%22) %7C%7C text.toLowerCase().equals(%22/g%22)) %7B // get games list command%0A                    server.log(Level.INFO, %22Getting games list.%22);%0A                    server.getGamesList();%0A%0A                    return;%0A                %7D else if(text.toLowerCase().equals(%22/users%22) %7C%7C text.toLowerCase().equals(%22/u%22)) %7B // get users list command%0A                    server.log(Level.INFO, %22Getting list of users online.%22);%0A                    server.getUsersList();%0A%0A                    return;%0A                %7D else %7B%0A                    message = text;%0A                    recipient = %22all%22;%0A                %7D%0A            %7D%0A            server.chat(recipient.toLowerCase().trim(), message);%0A        %7D%0A    %7D
 %0A%7D%0A

add possibility to send commands from the lineshell