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 {
|
public class SessionManager implements NeedGarbageCollection {
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public static final long SESSION_TIMEOUT = 10 * 60 * 1000; // 10 минут
|
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);
|
private Set<Client> clientSet = new HashSet<>(128);
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
|
@ -22,7 +23,7 @@ public boolean addClient(Client client) {
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public void garbageCollection() {
|
public void garbageCollection() {
|
||||||
long time = System.currentTimeMillis();
|
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
|
@LauncherAPI
|
||||||
|
@ -43,10 +44,13 @@ public Client getOrNewClient(long session) {
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public void updateClient(long session) {
|
public void updateClient(long session) {
|
||||||
for (Client c : clientSet)
|
for (Client c : clientSet) {
|
||||||
if (c.session == session) {
|
if (c.session == session) {
|
||||||
c.up();
|
c.up();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Client newClient = new Client(session);
|
||||||
|
clientSet.add(newClient);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import ru.gravit.launchserver.socket.Client;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
import ru.gravit.launcher.profiles.ClientProfile;
|
import ru.gravit.launcher.profiles.ClientProfile;
|
||||||
import ru.gravit.launcher.serialize.HInput;
|
import ru.gravit.launcher.serialize.HInput;
|
||||||
|
@ -20,7 +21,13 @@ public ProfilesResponse(LaunchServer server, long session, HInput input, HOutput
|
||||||
@Override
|
@Override
|
||||||
public void reply() throws IOException {
|
public void reply() throws IOException {
|
||||||
// Resolve launcher binary
|
// Resolve launcher binary
|
||||||
|
Client client = server.sessionManager.getClient(session);
|
||||||
input.readBoolean();
|
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);
|
writeNoError(output);
|
||||||
Collection<SignedObjectHolder<ClientProfile>> profiles = server.getProfiles();
|
Collection<SignedObjectHolder<ClientProfile>> profiles = server.getProfiles();
|
||||||
output.writeLength(profiles.size(), 0);
|
output.writeLength(profiles.size(), 0);
|
||||||
|
|
Loading…
Reference in a new issue