diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java index ecce5e82..268e9196 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java @@ -3,17 +3,14 @@ import pro.gravit.launcher.NeedGarbageCollection; import pro.gravit.launchserver.socket.Client; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; public class SessionManager implements NeedGarbageCollection { public static final long SESSION_TIMEOUT = 3 * 60 * 60 * 1000; // 3 часа - private final Map clientSet = new HashMap<>(128); + private final Map clientSet = new HashMap<>(128); public boolean addClient(Client client) { @@ -31,21 +28,21 @@ public void garbageCollection() { } - public Client getClient(long session) { + public Client getClient(UUID session) { return clientSet.get(session); } - public Client getOrNewClient(long session) { + public Client getOrNewClient(UUID session) { return clientSet.computeIfAbsent(session, Client::new); } - public Client removeClient(long session) { + public Client removeClient(UUID session) { return clientSet.remove(session); } - public void updateClient(long session) { + public void updateClient(UUID session) { Client c = clientSet.get(session); if (c != null) { c.up(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java index 199e21ec..5a108372 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java @@ -10,9 +10,10 @@ import pro.gravit.utils.helper.LogHelper; import java.util.Map; +import java.util.UUID; public class Client { - public long session; + public UUID session; public String auth_id; public long timestamp; public AuthResponse.ConnectTypes type; @@ -29,7 +30,7 @@ public class Client { public transient Map properties; - public Client(long session) { + public Client(UUID session) { this.session = session; timestamp = System.currentTimeMillis(); type = null; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java index a51182c2..e891cf28 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java @@ -50,7 +50,7 @@ public void channelActive(ChannelHandlerContext ctx) { if (LogHelper.isDevEnabled()) { LogHelper.dev("New client %s", IOHelper.getIP(ctx.channel().remoteAddress())); } - client = new Client(0); + client = new Client(null); Channel ch = ctx.channel(); service.registerClient(ch); ctx.executor().schedule(() -> { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java index ae85d459..5d574a20 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java @@ -92,8 +92,8 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti result.accessToken = aresult.accessToken; result.permissions = clientData.permissions; if (getSession) { - if (clientData.session == 0) { - clientData.session = random.nextLong(); + if (clientData.session == null) { + clientData.session = UUID.randomUUID(); server.sessionManager.addClient(clientData); } result.session = clientData.session; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ExitResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ExitResponse.java index c35d4edb..3d7c4839 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ExitResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ExitResponse.java @@ -24,7 +24,7 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception { return; } if (username == null) { - if (client.session == 0 && exitAll) { + if (client.session == null && exitAll) { sendError("Session invalid"); return; } @@ -33,10 +33,10 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception { sendError("Exit internal error"); return; } - Client newClient = new Client(0); + Client newClient = new Client(null); newClient.checkSign = client.checkSign; handler.setClient(newClient); - if (client.session != 0) server.sessionManager.removeClient(client.session); + if (client.session != null) server.sessionManager.removeClient(client.session); if (exitAll) { service.channels.forEach((channel) -> { if (channel == null || channel.pipeline() == null) return; @@ -48,10 +48,10 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception { } else { if (chClient.session != client.session) return; } - Client newCusClient = new Client(0); + Client newCusClient = new Client(null); newCusClient.checkSign = chClient.checkSign; wsHandler.setClient(newCusClient); - if (chClient.session != 0) server.sessionManager.removeClient(chClient.session); + if (chClient.session != null) server.sessionManager.removeClient(chClient.session); ExitRequestEvent event = new ExitRequestEvent(ExitRequestEvent.ExitReason.SERVER); event.requestUUID = RequestEvent.eventUUID; wsHandler.service.sendObject(channel, event); @@ -65,10 +65,10 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception { if (wsHandler == null) return; Client chClient = wsHandler.getClient(); if (!chClient.isAuth || !username.equals(chClient.username)) return; - Client newCusClient = new Client(0); + Client newCusClient = new Client(null); newCusClient.checkSign = chClient.checkSign; wsHandler.setClient(newCusClient); - if (chClient.session != 0) server.sessionManager.removeClient(chClient.session); + if (chClient.session != null) server.sessionManager.removeClient(chClient.session); ExitRequestEvent event = new ExitRequestEvent(ExitRequestEvent.ExitReason.SERVER); event.requestUUID = RequestEvent.eventUUID; wsHandler.service.sendObject(channel, event); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RestoreSessionResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RestoreSessionResponse.java index f68dfe39..39ffa6f6 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RestoreSessionResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RestoreSessionResponse.java @@ -7,9 +7,11 @@ import pro.gravit.launchserver.socket.handlers.WebSocketFrameHandler; import pro.gravit.launchserver.socket.response.SimpleResponse; +import java.util.UUID; + public class RestoreSessionResponse extends SimpleResponse { @LauncherNetworkAPI - public long session; + public UUID session; @Override public String getType() { diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java index 2cb28b4a..3d958746 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java @@ -195,7 +195,7 @@ public static class ClientParams { //======== - public long session; + public UUID session; public transient HashedDir assetHDir; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/AuthRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/AuthRequestEvent.java index 4206f999..1bdffe2e 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/AuthRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/AuthRequestEvent.java @@ -5,6 +5,8 @@ import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.profiles.PlayerProfile; +import java.util.UUID; + public class AuthRequestEvent extends RequestEvent { @LauncherNetworkAPI @@ -16,7 +18,7 @@ public class AuthRequestEvent extends RequestEvent { @LauncherNetworkAPI public String protectToken; @LauncherNetworkAPI - public long session; + public UUID session; public AuthRequestEvent() { } @@ -34,7 +36,7 @@ public AuthRequestEvent(ClientPermissions permissions, PlayerProfile playerProfi this.protectToken = protectToken; } - public AuthRequestEvent(ClientPermissions permissions, PlayerProfile playerProfile, String accessToken, String protectToken, long session) { + public AuthRequestEvent(ClientPermissions permissions, PlayerProfile playerProfile, String accessToken, String protectToken, UUID session) { this.permissions = permissions; this.playerProfile = playerProfile; this.accessToken = accessToken; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java index e5eab74c..d475491a 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java @@ -11,16 +11,16 @@ public abstract class Request implements WebSocketRequest { public static StdWebSocketService service; - private static long session = SecurityHelper.secureRandom.nextLong(); + private static UUID session = UUID.randomUUID(); @LauncherNetworkAPI public final UUID requestUUID = UUID.randomUUID(); private transient final AtomicBoolean started = new AtomicBoolean(false); - public static long getSession() { + public static UUID getSession() { return Request.session; } - public static void setSession(long session) { + public static void setSession(UUID session) { Request.session = session; } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/RestoreSessionRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/RestoreSessionRequest.java index 6be0e757..9dd64e2b 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/RestoreSessionRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/RestoreSessionRequest.java @@ -5,11 +5,13 @@ import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.websockets.WebSocketRequest; +import java.util.UUID; + public class RestoreSessionRequest extends Request implements WebSocketRequest { @LauncherNetworkAPI - public final long session; + public final UUID session; - public RestoreSessionRequest(long session) { + public RestoreSessionRequest(UUID session) { this.session = session; }