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.

102 lines
3.1 KiB

import java.net.*;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
public class ctServer {
public static Boolean[] sessions;
public static List<client> sockets;
public static int socketID;
public static ArrayList<ClientInfo> clientInfoList;
public static class ClientInfo{
public static String VKID, ROLE, PROTOCOL, EVENT, TRACKID;
public static int TIME;
public static Boolean notEmpty = false;
public static void destroy(){
VKID = null;
ROLE = null;
PROTOCOL = null;
EVENT = null;
TRACKID = null;
TIME = 0;
notEmpty = false;
}
}
public static boolean checkClient(client c, String[] args){
ClientInfo ci = new ClientInfo();
ci.destroy();
try {
for (String name : args) {
Pattern main = Pattern.compile(":");
String[] sx = main.split(name);
switch (sx[0]) {
case "PROTOCOL":
ci.PROTOCOL = sx[1];
break;
case "VKID":
ci.VKID = sx[1];
break;
}
}
if (!ci.VKID.equals("")) {
if (!ci.PROTOCOL.equals("")) {
clientInfoList.add(c.socketID, ci);
c.httpAuthed = true;
console.debug("Авторизация произошла!");
return true;
}
}
} catch (NullPointerException e){
return false;
}
return false;
}
public static void main(String[] args) throws IOException{
sessions = new Boolean[1000];
for (int i = 0; i < sessions.length; i++) {
sessions[i] = false;
}
clientInfoList = new ArrayList<>();
sockets = new ArrayList<>();
try{
new console().consoleListner();
}
catch (IOException e){
}
int port = 80;
console.out("Socket Port", port+"");
ServerSocket ss = new ServerSocket(port);
try {
console.out("Server", "Waiting for a client");
while(true) {
Socket socket = ss.accept();
try {
for(int i = 0; ctServer.sessions.length > i; i++){
if(ctServer.sessions[i] == null){
ctServer.socketID = i;
ctServer.sessions[i] = true;
break;
}
if(ctServer.sessions[i] == false){
ctServer.socketID = i;
ctServer.sessions[i] = true;
break;
}
}
new client().openSocket(socket);
} catch (IOException e) {
socket.close();
}
}
} finally {
ss.close();
}
}
}