Исключения при сборке мусора для серверов и обязательная авторизация сервера

This commit is contained in:
Gravit 2018-09-27 04:30:43 +07:00
parent e77a848843
commit 20cb561b3e
2 changed files with 13 additions and 2 deletions

View file

@ -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);
}
}

View file

@ -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);