You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
3.8 KiB
94 lines
3.8 KiB
import java.io.BufferedReader;
|
|
import java.io.IOException;
|
|
import java.io.InputStreamReader;
|
|
import java.time.Clock;
|
|
import java.time.Instant;
|
|
import java.util.ArrayList;
|
|
import java.util.regex.Pattern;
|
|
|
|
/**
|
|
* Created by itsmy on 08.08.2016.
|
|
*/
|
|
public class console extends Thread{
|
|
|
|
private BufferedReader in;
|
|
private String line;
|
|
|
|
public void consoleListner() throws IOException{
|
|
in = new BufferedReader(new InputStreamReader(System.in));
|
|
line = "";
|
|
start();
|
|
}
|
|
|
|
public static void out(String parent, String msg){
|
|
String time = Clock.systemUTC().instant().toString();
|
|
System.out.println("["+time+"|"+parent+"]: "+msg);
|
|
}
|
|
|
|
public static void socket(Integer socketId, String msg){
|
|
String time = Clock.systemUTC().instant().toString();
|
|
System.out.println("["+time+"|"+"Socket "+socketId+"]: "+msg);
|
|
}
|
|
|
|
public static void debug(String msg){
|
|
String out = "[";
|
|
out += Clock.systemUTC().instant().toString();
|
|
out += "|DEBUG]: ";
|
|
out += msg;
|
|
System.out.println(out);
|
|
}
|
|
|
|
public void run() {
|
|
while (line.equalsIgnoreCase("quit") == false) {
|
|
try{
|
|
line = in.readLine();
|
|
Integer sid;
|
|
Pattern main = Pattern.compile(" ");
|
|
String[] sx = main.split(line);
|
|
switch (sx[0]){
|
|
case "/list":
|
|
console.out("Server","/list");
|
|
for(int i = 0; socketInfo.SOCKETID.size() > i; i++){
|
|
int id = socketInfo.SOCKETID.get(i);
|
|
if(socketInfo.isProtocolAuth(id)) {
|
|
console.socket(id,"VKID " + socketInfo.VKID.get(id) + " and PROTOCOL " + socketInfo.PROTOCOL.get(id));
|
|
}else{
|
|
console.socket(id,"Protocol not checked!");
|
|
}
|
|
}
|
|
break;
|
|
case "/kick":
|
|
sid = Integer.valueOf(sx[1]);
|
|
if(socketInfo.findSocket(Integer.valueOf(sx[1])) != -1){
|
|
socketInfo.getClient(sid).close();
|
|
}
|
|
break;
|
|
case "/help":
|
|
console.out("Server","/kick [socketid] для отключения сокета от сервера");
|
|
console.out("Server","/list для отображения всех клиентов");
|
|
console.out("Server","/info [socketid] для отображения полной информации о данном клиенте");
|
|
console.out("Server","/send [socketid] [msg] отладочная команда");
|
|
console.out("Server","ctServer Proto Defend Development 2016");
|
|
break;
|
|
case "/send":
|
|
sid = socketInfo.findSocket(Integer.valueOf(sx[1]));
|
|
if(sid != -1){
|
|
String msg = "";
|
|
for (int i = 2; i < sx.length ; i++) {
|
|
msg += " ";
|
|
msg += sx[i];
|
|
}
|
|
socketInfo.getClient(Integer.valueOf(sx[1])).sendSocket(msg);
|
|
}
|
|
break;
|
|
default: console.out("Server","Введите /help для помощи");
|
|
}
|
|
|
|
}catch (IOException e){
|
|
console.out("Console","Something goes wrong...");
|
|
}catch (NumberFormatException e){
|
|
console.out("Console","Hey guy, don't be so crazy!!!");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|