mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
Исключения при сборке мусора для серверов и обязательная авторизация сервера
This commit is contained in:
parent
e77a848843
commit
20cb561b3e
2 changed files with 13 additions and 2 deletions
|
@ -10,6 +10,7 @@
|
|||
public class SessionManager implements NeedGarbageCollection {
|
||||
@LauncherAPI
|
||||
public static final long SESSION_TIMEOUT = 10 * 60 * 1000; // 10 минут
|
||||
public static final boolean NON_GARBAGE_SERVER = true;
|
||||
private Set<Client> clientSet = new HashSet<>(128);
|
||||
|
||||
@LauncherAPI
|
||||
|
@ -22,7 +23,7 @@ public boolean addClient(Client client) {
|
|||
@LauncherAPI
|
||||
public void garbageCollection() {
|
||||
long time = System.currentTimeMillis();
|
||||
clientSet.removeIf(c -> c.timestamp + SESSION_TIMEOUT < time);
|
||||
clientSet.removeIf(c -> (c.timestamp + SESSION_TIMEOUT < time) && ((c.type == Client.Type.USER) || ((c.type == Client.Type.SERVER) && !NON_GARBAGE_SERVER ) ));
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
@ -43,10 +44,13 @@ public Client getOrNewClient(long session) {
|
|||
|
||||
@LauncherAPI
|
||||
public void updateClient(long session) {
|
||||
for (Client c : clientSet)
|
||||
for (Client c : clientSet) {
|
||||
if (c.session == session) {
|
||||
c.up();
|
||||
return;
|
||||
}
|
||||
}
|
||||
Client newClient = new Client(session);
|
||||
clientSet.add(newClient);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
import ru.gravit.launchserver.socket.Client;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
import ru.gravit.launcher.profiles.ClientProfile;
|
||||
import ru.gravit.launcher.serialize.HInput;
|
||||
|
@ -20,7 +21,13 @@ public ProfilesResponse(LaunchServer server, long session, HInput input, HOutput
|
|||
@Override
|
||||
public void reply() throws IOException {
|
||||
// Resolve launcher binary
|
||||
Client client = server.sessionManager.getClient(session);
|
||||
input.readBoolean();
|
||||
if(client.type == Client.Type.USER) {
|
||||
LogHelper.warning("User session: %d ip %s try get profiles",session,ip);
|
||||
requestError("Assess denied");
|
||||
return;
|
||||
}
|
||||
writeNoError(output);
|
||||
Collection<SignedObjectHolder<ClientProfile>> profiles = server.getProfiles();
|
||||
output.writeLength(profiles.size(), 0);
|
||||
|
|
Loading…
Reference in a new issue