loottracker: submit loot when not logged in
This is to aid the wiki drop log project. The data is not otherwise stored.
This commit is contained in:
@@ -35,7 +35,9 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.http.api.RuneLiteAPI;
|
||||
import static net.runelite.http.api.RuneLiteAPI.JSON;
|
||||
@@ -48,13 +50,15 @@ import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
public class LootTrackerClient
|
||||
{
|
||||
private static final Gson GSON = RuneLiteAPI.GSON;
|
||||
|
||||
private final OkHttpClient client;
|
||||
private final UUID uuid;
|
||||
@Getter
|
||||
@Setter
|
||||
private UUID uuid;
|
||||
|
||||
public CompletableFuture<Void> submit(Collection<LootRecord> lootRecords)
|
||||
{
|
||||
@@ -64,13 +68,16 @@ public class LootTrackerClient
|
||||
.addPathSegment("loottracker")
|
||||
.build();
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.header(RuneLiteAPI.RUNELITE_AUTH, uuid.toString())
|
||||
.post(RequestBody.create(JSON, GSON.toJson(lootRecords)))
|
||||
Request.Builder requestBuilder = new Request.Builder();
|
||||
if (uuid != null)
|
||||
{
|
||||
requestBuilder.header(RuneLiteAPI.RUNELITE_AUTH, uuid.toString());
|
||||
}
|
||||
requestBuilder.post(RequestBody.create(JSON, GSON.toJson(lootRecords)))
|
||||
.url(url)
|
||||
.build();
|
||||
|
||||
client.newCall(request).enqueue(new Callback()
|
||||
client.newCall(requestBuilder.build()).enqueue(new Callback()
|
||||
{
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e)
|
||||
|
||||
@@ -65,14 +65,22 @@ public class LootTrackerController
|
||||
@RequestMapping(method = RequestMethod.POST)
|
||||
public void storeLootRecord(HttpServletRequest request, HttpServletResponse response, @RequestBody Collection<LootRecord> records) throws IOException
|
||||
{
|
||||
SessionEntry e = auth.handle(request, response);
|
||||
if (e == null)
|
||||
SessionEntry session = null;
|
||||
if (request.getHeader(RuneLiteAPI.RUNELITE_AUTH) != null)
|
||||
{
|
||||
response.setStatus(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
|
||||
return;
|
||||
session = auth.handle(request, response);
|
||||
if (session == null)
|
||||
{
|
||||
// error is set here on the response, so we shouldn't continue
|
||||
return;
|
||||
}
|
||||
}
|
||||
Integer userId = session == null ? null : session.getUser();
|
||||
|
||||
service.store(records, e.getUser());
|
||||
if (userId != null)
|
||||
{
|
||||
service.store(records, userId);
|
||||
}
|
||||
response.setStatus(HttpStatusCodes.STATUS_CODE_OK);
|
||||
|
||||
try (Jedis jedis = redisPool.getResource())
|
||||
|
||||
@@ -27,6 +27,7 @@ package net.runelite.http.service.loottracker;
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import net.runelite.http.api.RuneLiteAPI;
|
||||
@@ -91,7 +92,10 @@ public class LootTrackerControllerTest
|
||||
lootRecord.setDrops(Collections.singletonList(new GameItem(4151, 1)));
|
||||
|
||||
String data = RuneLiteAPI.GSON.toJson(Collections.singletonList(lootRecord));
|
||||
mockMvc.perform(post("/loottracker").content(data).contentType(MediaType.APPLICATION_JSON))
|
||||
mockMvc.perform(post("/loottracker")
|
||||
.header(RuneLiteAPI.RUNELITE_AUTH, UUID.nameUUIDFromBytes("test".getBytes()))
|
||||
.content(data)
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
verify(lootTrackerService).store(eq(Collections.singletonList(lootRecord)), anyInt());
|
||||
|
||||
@@ -82,7 +82,7 @@ public interface LootTrackerConfig extends Config
|
||||
@ConfigItem(
|
||||
keyName = "saveLoot",
|
||||
name = "Submit loot tracker data",
|
||||
description = "Submit loot tracker data (requires being logged in)"
|
||||
description = "Submit loot tracker data"
|
||||
)
|
||||
default boolean saveLoot()
|
||||
{
|
||||
|
||||
@@ -279,7 +279,7 @@ class LootTrackerPanel extends PluginPanel
|
||||
reset.addActionListener(e ->
|
||||
{
|
||||
final LootTrackerClient client = plugin.getLootTrackerClient();
|
||||
final boolean syncLoot = client != null && config.syncPanel();
|
||||
final boolean syncLoot = client.getUuid() != null && config.syncPanel();
|
||||
final int result = JOptionPane.showOptionDialog(overallPanel,
|
||||
syncLoot ? SYNC_RESET_ALL_WARNING_TEXT : NO_SYNC_RESET_ALL_WARNING_TEXT,
|
||||
"Are you sure?", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE,
|
||||
@@ -568,7 +568,7 @@ class LootTrackerPanel extends PluginPanel
|
||||
|
||||
LootTrackerClient client = plugin.getLootTrackerClient();
|
||||
// Without loot being grouped we have no way to identify single kills to be deleted
|
||||
if (client != null && groupLoot && config.syncPanel())
|
||||
if (client.getUuid() != null && groupLoot && config.syncPanel())
|
||||
{
|
||||
client.delete(box.getId());
|
||||
}
|
||||
|
||||
@@ -262,9 +262,6 @@ public class LootTrackerPlugin extends Plugin
|
||||
@Inject
|
||||
private LootManager lootManager;
|
||||
|
||||
@Inject
|
||||
private OkHttpClient okHttpClient;
|
||||
|
||||
private LootTrackerPanel panel;
|
||||
private NavigationButton navButton;
|
||||
@VisibleForTesting
|
||||
@@ -281,6 +278,7 @@ public class LootTrackerPlugin extends Plugin
|
||||
private Multiset<Integer> inventorySnapshot;
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
@Inject
|
||||
private LootTrackerClient lootTrackerClient;
|
||||
private final List<LootRecord> queuedLoots = new ArrayList<>();
|
||||
|
||||
@@ -313,6 +311,12 @@ public class LootTrackerPlugin extends Plugin
|
||||
return list;
|
||||
}
|
||||
|
||||
@Provides
|
||||
LootTrackerClient provideLootTrackerClient(OkHttpClient okHttpClient)
|
||||
{
|
||||
return new LootTrackerClient(okHttpClient);
|
||||
}
|
||||
|
||||
@Provides
|
||||
LootTrackerConfig provideConfig(ConfigManager configManager)
|
||||
{
|
||||
@@ -325,11 +329,11 @@ public class LootTrackerPlugin extends Plugin
|
||||
AccountSession accountSession = sessionManager.getAccountSession();
|
||||
if (accountSession.getUuid() != null)
|
||||
{
|
||||
lootTrackerClient = new LootTrackerClient(okHttpClient, accountSession.getUuid());
|
||||
lootTrackerClient.setUuid(accountSession.getUuid());
|
||||
}
|
||||
else
|
||||
{
|
||||
lootTrackerClient = null;
|
||||
lootTrackerClient.setUuid(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,7 +341,7 @@ public class LootTrackerPlugin extends Plugin
|
||||
public void onSessionClose(SessionClose sessionClose)
|
||||
{
|
||||
submitLoot();
|
||||
lootTrackerClient = null;
|
||||
lootTrackerClient.setUuid(null);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -373,7 +377,7 @@ public class LootTrackerPlugin extends Plugin
|
||||
AccountSession accountSession = sessionManager.getAccountSession();
|
||||
if (accountSession != null)
|
||||
{
|
||||
lootTrackerClient = new LootTrackerClient(okHttpClient, accountSession.getUuid());
|
||||
lootTrackerClient.setUuid(accountSession.getUuid());
|
||||
|
||||
clientThread.invokeLater(() ->
|
||||
{
|
||||
@@ -420,7 +424,7 @@ public class LootTrackerPlugin extends Plugin
|
||||
{
|
||||
submitLoot();
|
||||
clientToolbar.removeNavigation(navButton);
|
||||
lootTrackerClient = null;
|
||||
lootTrackerClient.setUuid(null);
|
||||
chestLooted = false;
|
||||
}
|
||||
|
||||
@@ -831,15 +835,14 @@ public class LootTrackerPlugin extends Plugin
|
||||
queuedLoots.clear();
|
||||
}
|
||||
|
||||
if (lootTrackerClient == null || !config.saveLoot())
|
||||
if (!config.saveLoot())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
log.debug("Submitting {} loot records", copy.size());
|
||||
|
||||
CompletableFuture<Void> future = lootTrackerClient.submit(copy);
|
||||
return future;
|
||||
return lootTrackerClient.submit(copy);
|
||||
}
|
||||
|
||||
private void setEvent(LootRecordType lootRecordType, String eventType, Object metadata)
|
||||
|
||||
@@ -61,6 +61,7 @@ import net.runelite.client.game.SpriteManager;
|
||||
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
|
||||
import net.runelite.http.api.item.ItemPrice;
|
||||
import net.runelite.http.api.loottracker.LootRecordType;
|
||||
import net.runelite.http.api.loottracker.LootTrackerClient;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import org.junit.Before;
|
||||
@@ -135,6 +136,10 @@ public class LootTrackerPluginTest
|
||||
@Bind
|
||||
private ChatMessageManager chatMessageManager;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private LootTrackerClient lootTrackerClient;
|
||||
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user