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.
89 lines
3.6 KiB
89 lines
3.6 KiB
import javafx.application.Application;
|
|
|
|
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){
|
|
Instant instant2 = Clock.systemUTC().instant();
|
|
String time = instant2.toString();
|
|
System.out.println("["+time+"|"+parent+"]: "+msg);
|
|
}
|
|
|
|
public static void socket(Integer socketId, String msg){
|
|
Instant instant2 = Clock.systemUTC().instant();
|
|
String time = instant2.toString();
|
|
System.out.println("["+time+"|"+"Socket "+socketId+"]: "+msg);
|
|
}
|
|
|
|
public static void debug(String msg){
|
|
Instant instant2 = Clock.systemUTC().instant();
|
|
String time = instant2.toString();
|
|
System.out.println("["+time+"|DEBUG]: "+msg);
|
|
}
|
|
|
|
public void run() {
|
|
while (line.equalsIgnoreCase("quit") == false) {
|
|
try{
|
|
line = in.readLine();
|
|
Pattern main = Pattern.compile(" ");
|
|
String[] sx = main.split(line);
|
|
switch (sx[0]){
|
|
case "/list":
|
|
ArrayList<ctServer.ClientInfo> cil = ctServer.clientInfoList;
|
|
console.out("Server","/list");
|
|
for(int i = 0; ctServer.sessions[i]; i++){
|
|
if(ctServer.sockets.get(Integer.valueOf(i)).socketAuthed) {
|
|
ctServer.ClientInfo ci = cil.get(i);
|
|
console.out("Socket " + i, "VKID " + ci.VKID + " and PROTOCOL " + ci.PROTOCOL);
|
|
}else{
|
|
console.out("Socket "+ i,"Not authed!");
|
|
}
|
|
}
|
|
break;
|
|
case "/kick":
|
|
if(sx.length < 2) {
|
|
console.out("Server","/kick - Укажите имя сокета");
|
|
}
|
|
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":
|
|
if(ctServer.sessions[Integer.valueOf(sx[1])]) {
|
|
if ((ctServer.sockets.size() >= Integer.valueOf(sx[1])) && (Integer.valueOf(sx[1]) >= 0)) {
|
|
ctServer.sockets.get(Integer.valueOf(sx[1])).sendSocket(sx[2]);
|
|
}
|
|
}
|
|
break;
|
|
default: console.out("Server","Введите /help для помощи");
|
|
}
|
|
|
|
}catch (IOException e){
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|