session: add logged-in tracking
This commit is contained in:
@@ -29,9 +29,12 @@ import java.util.UUID;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.client.util.RunnableExceptionLogger;
|
||||
|
||||
@Singleton
|
||||
@@ -40,15 +43,16 @@ public class ClientSessionManager
|
||||
{
|
||||
private final SessionClient sessionClient = new SessionClient();
|
||||
private final ScheduledExecutorService executorService;
|
||||
private final Client client;
|
||||
|
||||
private ScheduledFuture<?> scheduledFuture;
|
||||
private UUID sessionId;
|
||||
|
||||
|
||||
@Inject
|
||||
ClientSessionManager(ScheduledExecutorService executorService)
|
||||
ClientSessionManager(ScheduledExecutorService executorService, @Nullable Client client)
|
||||
{
|
||||
this.executorService = executorService;
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public void start()
|
||||
@@ -101,9 +105,15 @@ public class ClientSessionManager
|
||||
return;
|
||||
}
|
||||
|
||||
boolean loggedIn = false;
|
||||
if (client != null)
|
||||
{
|
||||
loggedIn = client.getGameState() != GameState.LOGIN_SCREEN;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
sessionClient.ping(sessionId);
|
||||
sessionClient.ping(sessionId, loggedIn);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.util.UUID;
|
||||
import net.runelite.http.api.RuneLiteAPI;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
@@ -43,6 +44,7 @@ class SessionClient
|
||||
.build();
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.post(RequestBody.create(null, new byte[0]))
|
||||
.url(url)
|
||||
.build();
|
||||
|
||||
@@ -59,14 +61,16 @@ class SessionClient
|
||||
}
|
||||
}
|
||||
|
||||
void ping(UUID uuid) throws IOException
|
||||
void ping(UUID uuid, boolean loggedIn) throws IOException
|
||||
{
|
||||
HttpUrl url = RuneLiteAPI.getSessionBase().newBuilder()
|
||||
.addPathSegment("ping")
|
||||
.addQueryParameter("session", uuid.toString())
|
||||
.addQueryParameter("logged-in", String.valueOf(loggedIn))
|
||||
.build();
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.post(RequestBody.create(null, new byte[0]))
|
||||
.url(url)
|
||||
.build();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user