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