diff --git a/http-api/src/main/java/net/runelite/http/api/RuneLiteAPI.java b/http-api/src/main/java/net/runelite/http/api/RuneLiteAPI.java index 2f0ba34bc0..0b017518c8 100644 --- a/http-api/src/main/java/net/runelite/http/api/RuneLiteAPI.java +++ b/http-api/src/main/java/net/runelite/http/api/RuneLiteAPI.java @@ -43,6 +43,7 @@ public class RuneLiteAPI private static final Logger logger = LoggerFactory.getLogger(RuneLiteAPI.class); public static final String RUNELITE_AUTH = "RUNELITE-AUTH"; + public static final String RUNELITE_MACHINEID = "RUNELITE-MACHINEID"; public static final OkHttpClient CLIENT; public static final Gson GSON = new Gson(); diff --git a/http-api/src/main/java/net/runelite/http/api/ge/GrandExchangeClient.java b/http-api/src/main/java/net/runelite/http/api/ge/GrandExchangeClient.java index 78e64d383a..fd02f37ffc 100644 --- a/http-api/src/main/java/net/runelite/http/api/ge/GrandExchangeClient.java +++ b/http-api/src/main/java/net/runelite/http/api/ge/GrandExchangeClient.java @@ -27,7 +27,7 @@ package net.runelite.http.api.ge; import com.google.gson.Gson; import java.io.IOException; import java.util.UUID; -import lombok.AllArgsConstructor; +import lombok.Setter; import lombok.extern.slf4j.Slf4j; import net.runelite.http.api.RuneLiteAPI; import static net.runelite.http.api.RuneLiteAPI.JSON; @@ -39,12 +39,14 @@ import okhttp3.RequestBody; import okhttp3.Response; @Slf4j -@AllArgsConstructor public class GrandExchangeClient { private static final Gson GSON = RuneLiteAPI.GSON; - private final UUID uuid; + @Setter + private UUID uuid; + @Setter + private String machineId; public void submit(GrandExchangeTrade grandExchangeTrade) { @@ -52,8 +54,17 @@ public class GrandExchangeClient .addPathSegment("ge") .build(); - Request request = new Request.Builder() - .header(RuneLiteAPI.RUNELITE_AUTH, uuid.toString()) + Request.Builder builder = new Request.Builder(); + if (uuid != null) + { + builder.header(RuneLiteAPI.RUNELITE_AUTH, uuid.toString()); + } + if (machineId != null) + { + builder.header(RuneLiteAPI.RUNELITE_MACHINEID, machineId); + } + + Request request = builder .post(RequestBody.create(JSON, GSON.toJson(grandExchangeTrade))) .url(url) .build(); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangePlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangePlugin.java index 8215e16675..e43cf40475 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangePlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangePlugin.java @@ -29,17 +29,21 @@ package net.runelite.client.plugins.grandexchange; import com.google.common.annotations.VisibleForTesting; +import com.google.common.hash.Hasher; +import com.google.common.hash.Hashing; import com.google.common.primitives.Shorts; import com.google.gson.Gson; import com.google.inject.Provides; import java.awt.Color; import java.awt.image.BufferedImage; import java.io.IOException; +import java.net.NetworkInterface; import java.time.Duration; import java.time.Instant; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.Enumeration; import java.util.List; import java.util.Locale; import java.util.concurrent.ScheduledExecutorService; @@ -80,7 +84,6 @@ import net.runelite.client.account.SessionManager; import net.runelite.client.config.ConfigManager; import net.runelite.client.eventbus.Subscribe; import net.runelite.client.events.ConfigChanged; -import net.runelite.client.events.SessionClose; import net.runelite.client.events.SessionOpen; import net.runelite.client.game.ItemManager; import net.runelite.client.input.KeyManager; @@ -91,6 +94,7 @@ import net.runelite.client.ui.ClientToolbar; import net.runelite.client.ui.NavigationButton; import net.runelite.client.util.ColorUtil; import net.runelite.client.util.ImageUtil; +import net.runelite.client.util.OSType; import net.runelite.client.util.QuantityFormatter; import net.runelite.client.util.Text; import net.runelite.http.api.ge.GrandExchangeClient; @@ -176,10 +180,42 @@ public class GrandExchangePlugin extends Plugin private int osbItem; private OSBGrandExchangeResult osbGrandExchangeResult; + @Inject private GrandExchangeClient grandExchangeClient; + private static String machineUuid; private boolean wasFuzzySearch; + static + { + try + { + Hasher hasher = Hashing.sha256().newHasher(); + Runtime runtime = Runtime.getRuntime(); + + hasher.putByte((byte) OSType.getOSType().ordinal()); + hasher.putByte((byte) runtime.availableProcessors()); + hasher.putUnencodedChars(System.getProperty("os.arch", "")); + hasher.putUnencodedChars(System.getProperty("os.version", "")); + hasher.putUnencodedChars(System.getProperty("user.name", "")); + Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces(); + while (networkInterfaces.hasMoreElements()) + { + NetworkInterface networkInterface = networkInterfaces.nextElement(); + byte[] hardwareAddress = networkInterface.getHardwareAddress(); + if (hardwareAddress != null) + { + hasher.putBytes(hardwareAddress); + } + } + machineUuid = hasher.hash().toString(); + } + catch (Exception ex) + { + log.warn("unable to generate machine id", ex); + } + } + /** * Logic from {@link org.apache.commons.text.similarity.FuzzyScore} */ @@ -274,8 +310,13 @@ public class GrandExchangePlugin extends Plugin AccountSession accountSession = sessionManager.getAccountSession(); if (accountSession != null) { - grandExchangeClient = new GrandExchangeClient(accountSession.getUuid()); + grandExchangeClient.setUuid(accountSession.getUuid()); } + else + { + grandExchangeClient.setUuid(null); + } + grandExchangeClient.setMachineId(machineUuid); osbItem = -1; osbGrandExchangeResult = null; @@ -289,27 +330,13 @@ public class GrandExchangePlugin extends Plugin keyManager.unregisterKeyListener(inputListener); grandExchangeText = null; grandExchangeItem = null; - grandExchangeClient = null; } @Subscribe public void onSessionOpen(SessionOpen sessionOpen) { AccountSession accountSession = sessionManager.getAccountSession(); - if (accountSession.getUuid() != null) - { - grandExchangeClient = new GrandExchangeClient(accountSession.getUuid()); - } - else - { - grandExchangeClient = null; - } - } - - @Subscribe - public void onSessionClose(SessionClose sessionClose) - { - grandExchangeClient = null; + grandExchangeClient.setUuid(accountSession.getUuid()); } @Subscribe @@ -351,11 +378,6 @@ public class GrandExchangePlugin extends Plugin private void submitTrades(int slot, GrandExchangeOffer offer) { - if (grandExchangeClient == null) - { - return; - } - if (offer.getState() != GrandExchangeOfferState.BOUGHT && offer.getState() != GrandExchangeOfferState.SOLD && offer.getState() != GrandExchangeOfferState.CANCELLED_BUY && offer.getState() != GrandExchangeOfferState.CANCELLED_SELL) {