diff --git a/.idea/workspace.xml b/.idea/workspace.xml index b3c1550..e188593 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -28,8 +28,8 @@ - - + + @@ -37,18 +37,22 @@ - + - - + + - - + + + + + + @@ -57,31 +61,37 @@ - - - + + + + + - - + + - - - + + + + + + + - - + + - - + + - + @@ -108,10 +118,10 @@ @@ -152,6 +162,7 @@ + @@ -186,6 +197,24 @@ - @@ -215,6 +243,7 @@ + @@ -698,12 +727,13 @@ - + + - @@ -720,30 +750,30 @@ - + - + - - - + + + - + - - + - + - + + @@ -759,7 +789,15 @@ - @@ -768,6 +806,57 @@ @@ -860,6 +962,7 @@ + @@ -887,12 +990,16 @@ - - + + + + + + @@ -904,6 +1011,7 @@ + @@ -923,12 +1031,16 @@ - - + + + + + + @@ -940,6 +1052,7 @@ + @@ -959,12 +1072,16 @@ - - + + + + + + @@ -976,6 +1093,7 @@ + @@ -996,12 +1114,16 @@ - - + + + + + + @@ -1013,6 +1135,7 @@ + @@ -1033,12 +1156,16 @@ - - + + + + + + @@ -1050,6 +1177,7 @@ + @@ -1078,74 +1206,85 @@ + - - + + - + - + - + - - + + + - + - - - + + + + + + + - + - - - + + + + + - + - - + + - - - - - - + - - + + - - + + + + + + + + + + diff --git a/src/client.java b/src/client.java index 5160f6f..12845bc 100644 --- a/src/client.java +++ b/src/client.java @@ -1,5 +1,4 @@ import javax.json.Json; -import javax.json.JsonObject; import javax.json.stream.JsonParser; import javax.xml.bind.DatatypeConverter; import java.io.*; @@ -18,62 +17,67 @@ public class client extends Thread { private Socket socket; private OutputStream out; private InputStream in; - private Integer id; + private Integer socketid; private Boolean isClosing = false; public void openSocket(Socket s) throws IOException { socket = s; out = socket.getOutputStream(); in = socket.getInputStream(); - id = socketInfo.getNewID(); - console.debug("Create new socket " + id); - socketInfo.create(this, id); + socketid = socketInfo.getNewID(); + console.debug("Create new socket " + socketid); + socketInfo.create(this, socketid); start(); } public void run() { - console.socket(id, "New connection"); + console.socket(socketid, "New connection"); wsControl(); } public void close() { - if(!socketInfo.isOnline(id)){ + if(!socketInfo.isOnline(socketid)){ return; } - sendSocket("{\"fn\":\"close\",\"reason\":\"\"}"); try { in.close(); out.close(); socket.close(); } catch (IOException e) { } - console.socket(id, "Disconnected"); - socketInfo.close(id); + console.socket(socketid, "Disconnected"); + socketInfo.close(socketid); } public void wsControl() { handshake(); - if (!socketInfo.isHttpAuth(id)) { + if (!socketInfo.isHttpAuth(socketid)) { return; } - while (socketInfo.isOnline(id)) { - // Получение сообщения - String msg = readSocket(); - // Сохранение данных из сообщения + String msg = readSocket(); + parseInput(msg); + if(!socketInfo.isProtocolAuth(socketid)){socketInfo.checkProtocol(socketid);} + if(!socketInfo.isProtocolAuth(socketid)){close(); return;} + eventHandler.connect(socketid); + while (socketInfo.isOnline(socketid)) { + msg = readSocket(); parseInput(msg); - // Проверка протокола - if(!socketInfo.isProtocolAuth(id)){socketInfo.checkProtocol(id);} - if(!socketInfo.isProtocolAuth(id)){close();} - //TODO: подключить Event Handler - //TODO: проверить ROLE клиента - //TODO: выполнить событие в зависимости от ROLE клиента - //RoleChecker -> socketInfo - //eventFilter -> eventHandler - //eventFilter > switch > EVENT & ROLE - //eventFilter >> eventMaker >> client.socket - //TODO: убрать ECHO сообщение - sendSocket(msg); + + int id = socketInfo.findSocket.bySID(socketid); + if(id == -1){return;} + switch (socketInfo.EVENT.get(id)){ + case "play": eventHandler.play(socketid); + break; + case "pause": eventHandler.pause(socketid); + break; + case "next": eventHandler.next(socketid); + break; + case "prev": eventHandler.prev(socketid); + break; + case "wind": eventHandler.wind(socketid); + break; + } } } @@ -88,9 +92,9 @@ public class client extends Thread { } private void handshake() { - if(!socketInfo.isOnline(id)){close(); return;} + if(!socketInfo.isOnline(socketid)){close(); return;} try { - if (!socketInfo.isHttpAuth(id)) { + if (!socketInfo.isHttpAuth(socketid)) { socket.setSoTimeout(2000); String data = new Scanner(in, "UTF-8").useDelimiter("\\r\\n\\r\\n").next(); Matcher get = Pattern.compile("^GET").matcher(data); @@ -115,30 +119,29 @@ public class client extends Thread { console.out("Server Error:", e.toString()); } socket.setSoTimeout(0); - socketInfo.setHttpAuth(id, true); - console.socket(id, "Handshake accepted!"); + socketInfo.setHttpAuth(socketid, true); + console.socket(socketid, "Handshake accepted!"); } } - } catch (SocketException e) { - console.debug("исключение 22"); + } catch (SocketException ignored) { } catch (NoSuchElementException e) { - console.socket(id, "Handshake Timeout (2000ms)"); - socketInfo.setHttpAuth(id, false); + console.socket(socketid, "Handshake Timeout (2000ms)"); + socketInfo.setHttpAuth(socketid, false); close(); } catch(IllegalStateException e){ - console.socket(id, "Bad handshake request!"); + console.socket(socketid, "Bad handshake request!"); close(); } } public Boolean sendSocket(String message) { - if(!socketInfo.isOnline(id)){close(); return false;} + if(!socketInfo.isOnline(socketid)){close(); return false;} byte[] response; byte[] r; try { response = message.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { - console.socket(id, "Unsupported encoding!"); + console.socket(socketid, "Unsupported encoding!"); return false; } catch (NullPointerException e) { return false; @@ -183,7 +186,7 @@ public class client extends Thread { } public String readSocket() { - if(!socketInfo.isOnline(id)){close(); return null;} + if(!socketInfo.isOnline(socketid)){close(); return null;} String out = ""; try { int[] MSG = new int[0]; @@ -248,13 +251,13 @@ public class client extends Thread { console.out("Socket Exception", "Client socket is closed?! Closing socket connection!"); close(); } - if(!socketInfo.isOnline(id)){close(); return null;} - console.socket(id, "Message: " + out); + if(!socketInfo.isOnline(socketid)){close(); return null;} + console.socket(socketid, "Получаю: " + out); return out; } public Boolean parseInput(String input) { - if(!socketInfo.isOnline(id)){close();return false;} + if(!socketInfo.isOnline(socketid)){close();return false;} try { String keyName = null; JsonParser jsonParser = Json.createParser(new StringReader(input)); @@ -265,14 +268,16 @@ public class client extends Thread { keyName = jsonParser.getString(); break; case VALUE_STRING: - socketInfo.setString(id, keyName, jsonParser.getString()); + socketInfo.setString(socketid, keyName, jsonParser.getString()); break; case VALUE_NUMBER: - socketInfo.setInteger(id, keyName, jsonParser.getInt()); + socketInfo.setInteger(socketid, keyName, jsonParser.getBigDecimal()); break; case VALUE_FALSE: + socketInfo.setBoolean(socketid, keyName, false); break; case VALUE_TRUE: + socketInfo.setBoolean(socketid, keyName, true); break; case VALUE_NULL: // don't set anything @@ -284,7 +289,7 @@ public class client extends Thread { } return true; }catch(NullPointerException e){ - console.socket(id,"Request parsing error!"); + console.socket(socketid,"Request parsing error!"); return false; } } diff --git a/src/console.java b/src/console.java index fa79833..c294ca5 100644 --- a/src/console.java +++ b/src/console.java @@ -2,7 +2,6 @@ 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; @@ -13,6 +12,7 @@ public class console extends Thread{ private BufferedReader in; private String line; + private static Boolean hide = false; public void consoleListner() throws IOException{ in = new BufferedReader(new InputStreamReader(System.in)); @@ -21,6 +21,7 @@ public class console extends Thread{ } public static void out(String parent, String msg){ + if(hide){return;} String out = "["; out += Clock.systemUTC().instant().toString(); out += "|"; @@ -31,6 +32,7 @@ public class console extends Thread{ } public static void socket(Integer socketId, String msg){ + if(hide){return;} String out = "["; out += Clock.systemUTC().instant().toString(); out += "|Socket "; @@ -41,6 +43,7 @@ public class console extends Thread{ } public static void debug(String msg){ + if(hide){return;} String out = "["; out += Clock.systemUTC().instant().toString(); out += "|DEBUG]: "; @@ -49,84 +52,33 @@ public class console extends Thread{ } public void run() { - while (line.equalsIgnoreCase("quit") == false) { + console.out("Server", "Welcome to the ctServer/build25"); + while (line.equalsIgnoreCase("/stop") == false) { try{ line = in.readLine(); - Integer sid; - Integer id; 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++){ - sid = socketInfo.SOCKETID.get(i); - if(socketInfo.protocolAuth.get(i)) { - console.socket(sid,"VKID " + socketInfo.VKID.get(i) - + " PROTOCOL " + socketInfo.PROTOCOL.get(i) - + " EVENT " + socketInfo.EVENT.get(i) - + " PARTYID " + socketInfo.PARTYID.get(i) - + " TRACKDURATION " + socketInfo.DURATION.get(i)); - }else{ - console.socket(sid,"Protocol not checked!"); - } - } + cList(); break; case "/kick": - sid = Integer.valueOf(sx[1]); - if(socketInfo.findSocket.bySID(Integer.valueOf(sx[1])) != -1){ - socketInfo.getClient(sid).close(); - } + cKick(sx); break; case "/send": - sid = socketInfo.findSocket.bySID(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); - } + cSend(sx); break; case "/info": - if(sx.length < 3){ - console.out("Server","/info [pid/sid] "); - } else { - switch (sx[1]) { - case "sid": - sid = Integer.valueOf(sx[2]); - id = socketInfo.findSocket.bySID(sid); - if(id == -1){break;} - console.socket(sid,"VKID " + socketInfo.VKID.get(id) - + " PROTOCOL " + socketInfo.PROTOCOL.get(id) - + " EVENT " + socketInfo.EVENT.get(id) - + " PARTYID " + socketInfo.PARTYID.get(id) - + " TRACKDURATION " + socketInfo.DURATION.get(id)); - break; - case "pid": - ArrayList a = socketInfo.findSocket.byPID(Integer.valueOf(sx[2])); - for (int i = 0; i < a.size(); i++) { - id = a.get(i); - console.socket(socketInfo.SOCKETID.get(id),"VKID " + socketInfo.VKID.get(id) - + " PROTOCOL " + socketInfo.PROTOCOL.get(id) - + " EVENT " + socketInfo.EVENT.get(id) - + " PARTYID " + socketInfo.PARTYID.get(id) - + " TRACKDURATION " + socketInfo.DURATION.get(id)); - } - break; - default: - console.out("Server", "/info [pid/sid] "); - break; - } - } + cInfo(sx); break; case "/help": - console.out("Server","/kick [socketid] для отключения сокета от сервера"); - console.out("Server","/list для отображения всех клиентов"); - console.out("Server","/info pid/sid [id] для отображения полной информации о данном клиенте"); - console.out("Server","/send [socketid] [msg] отладочная команда"); - console.out("Server","ctServer Proto Defend Development 2016"); + cHelp(); + break; + case "/hide": + cHide(); + break; + case "/restart": + cRestart(); break; default: console.out("Server","Введите /help для помощи"); } @@ -137,5 +89,101 @@ public class console extends Thread{ console.out("Console","Hey guy, don't be so crazy!!!"); } } + for (int i = 0; i < socketInfo.SOCKETID.size(); i++) { + socketInfo.CLIENT.get(i).close(); + } + } + + private void cHide() { + if(!hide){hide = true;} else {hide = false;} + } + + private void cList() { + Integer sid; + console.out("Server","/list"); + for(int i = 0; socketInfo.SOCKETID.size() > i; i++){ + sid = socketInfo.SOCKETID.get(i); + if(socketInfo.protocolAuth.get(i)) { + console.socket(sid,"VKID " + socketInfo.VKID.get(i) + + " PROTOCOL " + socketInfo.PROTOCOL.get(i) + + " EVENT " + socketInfo.EVENT.get(i) + + " PARTYID " + socketInfo.PARTYID.get(i) + + " TIME " + socketInfo.TIME.get(i) + + " TRACKDURATION " + socketInfo.DURATION.get(i)); + }else{ + console.socket(sid,"Protocol not checked!"); + } + } + } + + private void cKick(String[] sx) { + Integer sid; + sid = Integer.valueOf(sx[1]); + if(socketInfo.findSocket.bySID(Integer.valueOf(sx[1])) != -1){ + socketInfo.getClient(sid).close(); + } + } + + private void cSend(String[] sx) { + Integer sid; + sid = socketInfo.findSocket.bySID(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); + } + } + + private void cHelp() { + console.out("Server","/kick [socketid] для отключения сокета от сервера"); + console.out("Server","/list для отображения всех клиентов"); + console.out("Server","/info pid/sid [id] для отображения полной информации о данном клиенте"); + console.out("Server","/send [socketid] [msg] отладочная команда"); + console.out("Server","ctServer Proto Defend Development 2016"); + } + + private void cInfo(String[] sx) { + Integer sid; + Integer id; + if(sx.length < 3){ + console.out("Server","/info [pid/sid] "); + } else { + switch (sx[1]) { + case "sid": + sid = Integer.valueOf(sx[2]); + id = socketInfo.findSocket.bySID(sid); + if(id == -1){break;} + console.socket(sid,"VKID " + socketInfo.VKID.get(id) + + " PROTOCOL " + socketInfo.PROTOCOL.get(id) + + " EVENT " + socketInfo.EVENT.get(id) + + " PARTYID " + socketInfo.PARTYID.get(id) + + " TRACKDURATION " + socketInfo.DURATION.get(id)); + break; + case "pid": + ArrayList a = socketInfo.findSocket.byPID(Integer.valueOf(sx[2])); + for (int i = 0; i < a.size(); i++) { + id = a.get(i); + console.socket(socketInfo.SOCKETID.get(id),"VKID " + socketInfo.VKID.get(id) + + " PROTOCOL " + socketInfo.PROTOCOL.get(id) + + " EVENT " + socketInfo.EVENT.get(id) + + " PARTYID " + socketInfo.PARTYID.get(id) + + " TRACKDURATION " + socketInfo.DURATION.get(id)); + } + break; + default: + console.out("Server", "/info [pid/sid] "); + break; + } + } + } + + private void cRestart(){ + for (int i = 0; i < socketInfo.SOCKETID.size(); i++) { + socketInfo.CLIENT.get(i).sendSocket("{\"EVENT\":\"RESTART\"}"); + } + System.exit(99); } } diff --git a/src/ctServer.java b/src/ctServer.java index de9d517..5455e8e 100644 --- a/src/ctServer.java +++ b/src/ctServer.java @@ -5,13 +5,10 @@ public class ctServer { public static void main(String[] args) throws IOException{ socketInfo.init(); - //TODO: оптимизация идентификаторов сокетов try{ new console().consoleListner(); } - catch (IOException ignored){ - - } + catch (IOException ignored){} int port = 80; console.out("Socket Port", port+""); ServerSocket ss = new ServerSocket(port); diff --git a/src/eventHandler.java b/src/eventHandler.java index 7f92d91..ed695d3 100644 --- a/src/eventHandler.java +++ b/src/eventHandler.java @@ -1,6 +1,157 @@ +import jdk.nashorn.internal.parser.JSONParser; + +import javax.json.Json; +import javax.json.JsonObject; +import javax.json.JsonObjectBuilder; +import java.util.ArrayList; + /** * Created by itsmy on 15.08.2016. */ -public class eventHandler extends client { +public class eventHandler { + + + public static synchronized void connect(Integer sid){ + JsonObjectBuilder creator = Json.createObjectBuilder(); + creator.add("EVENT","SERVICE"); + int id = socketInfo.findSocket.bySID(sid); + if(id == -1){return;} + ArrayList a = socketInfo.findSocket.byPID(socketInfo.PARTYID.get(id)); + if(a.size() == 1) { //Если клиент первым подключился, то он управляет + creator.add("ROLE", 0); + creator.add("ONLINE", 0); + socketInfo.ROLE.set(id, 0); + JsonObject cc = creator.build(); + socketInfo.CLIENT.get(id).sendSocket(cc.toString()); + } else if(a.size() > 1) { //Если клиент уже не первый, то всем остальным клиентам идет рассылка о новом подключении + socketInfo.ROLE.set(id, 1); + creator.add("ONLINE" , a.size()-1); + for (int i = 0; i < a.size(); i++) { + if(socketInfo.ROLE.get(i) == 0){ + JsonObject cc = creator.build(); + socketInfo.CLIENT.get(a.get(i)).sendSocket(cc.toString()); + } + else{ + JsonObjectBuilder listner = Json.createObjectBuilder(); + listner.add("EVENT","SERVICE"); + listner.add("ROLE", 1); + listner.add("ONLINE" , a.size()-1); + JsonObject lc = listner.build(); + socketInfo.CLIENT.get(a.get(i)).sendSocket(lc.toString()); + } + } + } + + } + + public static void close(Integer sid){ + JsonObjectBuilder c = Json.createObjectBuilder(); + c.add("EVENT","SERVICE"); + int id = socketInfo.findSocket.bySID(sid); + ArrayList a = socketInfo.findSocket.byPID(socketInfo.PARTYID.get(id)); + if(a.size() < 2){return;} + if(socketInfo.ROLE.get(id) == 0){ + for (int i = 0; i < socketInfo.ROLE.size() ; i++) { + if(id != i){ + socketInfo.ROLE.set(i, 0); + JsonObjectBuilder creator = Json.createObjectBuilder(); + creator.add("EVENT","SERVICE"); + creator.add("ROLE", 1); + creator.add("ONLINE" , a.size()-2); + JsonObject lc = creator.build(); + socketInfo.CLIENT.get(i).sendSocket(lc.toString()); + break; + } + } + } + for (int i = 0; i < a.size(); i++) { +// JsonObjectBuilder listner = Json.createObjectBuilder(); +// listner.add("EVENT","SERVICE"); +// listner.add("ROLE", 1); +// listner.add("ONLINE" , a.size()-1); +// JsonObject lc = listner.build(); +// socketInfo.CLIENT.get(i).sendSocket(lc.toString()); + } + } + + public static void play(Integer sid){ + int id = socketInfo.findSocket.bySID(sid); + if(id == -1){return;} + JsonObjectBuilder creator = Json.createObjectBuilder(); + creator.add("EVENT", "play"); + creator.add("tm",socketInfo.TIME.get(id)); + creator.add("tI", socketInfo.TRACKID.get(id)); + creator.add("li", "main"); + creator.add("tT", socketInfo.TRACKTIME.get(id)); + creator.add("tD", socketInfo.DURATION.get(id)); + creator.add("aP", socketInfo.AUTOPLAY.get(id)); + eventSender(id,creator); + } + + public static void next(Integer sid){ + int id = socketInfo.findSocket.bySID(sid); + if(id == -1){return;} + JsonObjectBuilder creator = Json.createObjectBuilder(); + creator.add("EVENT", "next"); + creator.add("tm",socketInfo.TIME.get(id)); + creator.add("tI", socketInfo.TRACKID.get(id)); + creator.add("li", "main"); + creator.add("tT", socketInfo.TRACKTIME.get(id)); + creator.add("tD", socketInfo.DURATION.get(id)); + creator.add("aP", socketInfo.AUTOPLAY.get(id)); + eventSender(id,creator); + } + + + public static void prev(Integer sid){ + int id = socketInfo.findSocket.bySID(sid); + if(id == -1){return;} + JsonObjectBuilder creator = Json.createObjectBuilder(); + creator.add("EVENT", "prev"); + creator.add("tm",socketInfo.TIME.get(id)); + creator.add("tI", socketInfo.TRACKID.get(id)); + creator.add("li", "main"); + creator.add("tT", socketInfo.TRACKTIME.get(id)); + creator.add("tD", socketInfo.DURATION.get(id)); + creator.add("aP", socketInfo.AUTOPLAY.get(id)); + eventSender(id,creator); + } + + public static void pause(Integer sid){ + int id = socketInfo.findSocket.bySID(sid); + if(id == -1){return;} + JsonObjectBuilder creator = Json.createObjectBuilder(); + creator.add("EVENT", "pause"); + creator.add("tm",socketInfo.TIME.get(id)); + creator.add("tI", socketInfo.TRACKID.get(id)); + creator.add("li", "main"); + creator.add("tT", socketInfo.TRACKTIME.get(id)); + creator.add("tD", socketInfo.DURATION.get(id)); + creator.add("aP", socketInfo.AUTOPLAY.get(id)); + eventSender(id,creator); + + } + + public static void eventSender(Integer id, JsonObjectBuilder creator){ + ArrayList a = socketInfo.findSocket.byPID(socketInfo.PARTYID.get(id)); + for (int i = 0; i < a.size(); i++) { + JsonObject c = creator.build(); + socketInfo.CLIENT.get(a.get(i)).sendSocket(c.toString()); + } + } + + public static void wind(Integer sid){ + int id = socketInfo.findSocket.bySID(sid); + if(id == -1){return;} + JsonObjectBuilder creator = Json.createObjectBuilder(); + creator.add("EVENT", "wind"); + creator.add("tm",socketInfo.TIME.get(id)); + creator.add("tI", socketInfo.TRACKID.get(id)); + creator.add("tT", socketInfo.TRACKTIME.get(id)); + creator.add("tD", socketInfo.DURATION.get(id)); + creator.add("ps", false); + eventSender(id,creator); + } + } diff --git a/src/socketInfo.java b/src/socketInfo.java index f75da33..e1bd41e 100644 --- a/src/socketInfo.java +++ b/src/socketInfo.java @@ -1,5 +1,6 @@ import com.sun.istack.internal.NotNull; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; import java.util.function.BooleanSupplier; @@ -8,9 +9,12 @@ import java.util.function.BooleanSupplier; * Created by itsmy_000 on 13.08.2016. */ public class socketInfo { - public static ArrayList ROLE, PROTOCOL, EVENT, TRACKID; - public static ArrayList VKID, TIME, SOCKETID, PARTYID, DURATION; - public static ArrayList ONLINE, httpAuth, protocolAuth; +// public enum EVENT{PLAY,NEXT,REWIND,PAUSE,PREV,SCROB} +// public static ArrayList EVENTS; + public static ArrayList TIME, TRACKTIME; + public static ArrayList PROTOCOL, EVENT, TRACKID; + public static ArrayList ROLE, VKID, SOCKETID, PARTYID, DURATION; + public static ArrayList ONLINE, httpAuth, protocolAuth, AUTOPLAY; public static ArrayList CLIENT; public static Integer sid; @@ -19,6 +23,7 @@ public class socketInfo { sid = 0; VKID = new ArrayList<>(); TIME = new ArrayList<>(); + TRACKTIME = new ArrayList<>(); ROLE = new ArrayList<>(); EVENT = new ArrayList<>(); CLIENT = new ArrayList<>(); @@ -30,12 +35,14 @@ public class socketInfo { ONLINE = new ArrayList<>(); httpAuth = new ArrayList<>(); protocolAuth = new ArrayList<>(); + AUTOPLAY = new ArrayList<>(); } public static void create(client c, Integer sid){ VKID.add(0); - TIME.add(0); - ROLE.add(""); + TIME.add(BigDecimal.ZERO); + TRACKTIME.add(BigDecimal.ZERO); + ROLE.add(1); EVENT.add(""); ONLINE.add(true); CLIENT.add(c); @@ -46,6 +53,7 @@ public class socketInfo { SOCKETID.add(sid); httpAuth.add(false); protocolAuth.add(false); + AUTOPLAY.add(false); } public static void close(Integer sid){ @@ -57,12 +65,14 @@ public class socketInfo { TRACKID.remove(s); SOCKETID.remove(s); TIME.remove(s); + TRACKTIME.remove(s); DURATION.remove(s); PARTYID.remove(s); CLIENT.remove(s); ONLINE.remove(s); httpAuth.remove(s); protocolAuth.remove(s); + AUTOPLAY.remove(s); } public static Integer getNewID(){ @@ -136,7 +146,7 @@ public class socketInfo { int s = findSocket.bySID(sid); if (s == -1) return; switch (keyName) { - case "fn": + case "EVENT": EVENT.set(s, value); break; case "tI": @@ -148,18 +158,31 @@ public class socketInfo { } } - public static void setInteger(Integer sid, String keyName, Integer value){ + public static void setInteger(Integer sid, String keyName, BigDecimal value){ int s = findSocket.bySID(sid); if(s == -1) return; switch (keyName){ - case "vk_id": VKID.set(s, value); + case "vk_id": VKID.set(s, value.intValueExact()); break; - case "tT": TIME.set(s, value); + case "tm": TIME.set(s, value); break; - case "partyId": PARTYID.set(s, value); + case "tT": TRACKTIME.set(s, value); break; - case "tD": DURATION.set(s, value); + case "partyId": PARTYID.set(s, value.intValueExact()); + break; + case "tD": DURATION.set(s, value.intValueExact()); break; } } + + public static void setBoolean(Integer sid, String keyName, Boolean value){ + int s = findSocket.bySID(sid); + if(s == -1) return; + switch (keyName) { + case "aP": + AUTOPLAY.set(s, value.booleanValue()); + break; + } + + } }