openrune: just about finish rework, gets to login

This commit is contained in:
therealunull
2020-12-13 15:12:37 -05:00
parent 11a239e94e
commit b54ff7f7db
693 changed files with 11362 additions and 3943 deletions

View File

@@ -25,6 +25,10 @@
package net.runelite.http.api;
import com.google.gson.Gson;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.MediaType;
@@ -33,21 +37,6 @@ import okhttp3.Request;
import okhttp3.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
public class RuneLiteAPI
{
@@ -64,36 +53,27 @@ public class RuneLiteAPI
private static final String BASE = "https://api.runelite.net";
private static final String WSBASE = "https://api.runelite.net/ws";
private static final String STATICBASE = "https://static.runelite.net";
private static final String OPENOSRS_SESSION = "http://session.openosrs.dev";
private static final String OPENOSRS_XTEA = "http://xtea.openosrs.dev";
private static final String MAVEN_METADATA = "https://repo.runelite.net/net/runelite/runelite-parent/maven-metadata.xml";
private static final Properties properties = new Properties();
private static String version;
private static String upstreamVersion;
private static int rsVersion;
static
{
try (InputStream in = RuneLiteAPI.class.getResourceAsStream("/runelite.properties"))
try
{
InputStream in = RuneLiteAPI.class.getResourceAsStream("/runelite.properties");
properties.load(in);
version = properties.getProperty("runelite.version");
rsVersion = Integer.parseInt(properties.getProperty("rs.version"));
String commit = properties.getProperty("runelite.commit");
boolean dirty = Boolean.parseBoolean(properties.getProperty("runelite.dirty"));
userAgent = "OpenOSRS/" + version + "-" + commit + (dirty ? "+" : "");
rsVersion = Integer.parseInt(properties.getProperty("rs.version"));
parseMavenVersion();
userAgent = "RuneLite/" + version + "-" + commit + (dirty ? "+" : "");
}
catch (NumberFormatException e)
{
e.printStackTrace();
throw new RuntimeException("Version string has not been substituted; Re-run Gradle");
throw new RuntimeException("Version string has not been substituted; Re-run maven");
}
catch (IOException ex)
{
@@ -104,6 +84,7 @@ public class RuneLiteAPI
.pingInterval(30, TimeUnit.SECONDS)
.addNetworkInterceptor(new Interceptor()
{
@Override
public Response intercept(Chain chain) throws IOException
{
@@ -119,12 +100,14 @@ public class RuneLiteAPI
public static HttpUrl getSessionBase()
{
return HttpUrl.parse(OPENOSRS_SESSION);
}
final String prop = System.getProperty("runelite.session.url");
public static HttpUrl getXteaBase()
{
return HttpUrl.parse(OPENOSRS_XTEA);
if (prop != null && !prop.isEmpty())
{
return HttpUrl.parse(prop);
}
return HttpUrl.parse(BASE + "/session");
}
public static HttpUrl getApiBase()
@@ -165,7 +148,12 @@ public class RuneLiteAPI
public static String getVersion()
{
return upstreamVersion;
return version;
}
public static void setVersion(String version)
{
RuneLiteAPI.version = version;
}
public static int getRsVersion()
@@ -173,60 +161,4 @@ public class RuneLiteAPI
return rsVersion;
}
public static String getRlpVersion()
{
return version;
}
private static byte[] downloadUrl(URL toDownload)
{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
InputStream stream;
try
{
byte[] chunk = new byte[4096];
int bytesRead;
URLConnection conn = toDownload.openConnection();
conn.setRequestProperty("User-Agent", userAgent);
stream = conn.getInputStream();
while ((bytesRead = stream.read(chunk)) > 0)
{
outputStream.write(chunk, 0, bytesRead);
}
stream.close();
}
catch (IOException e)
{
e.printStackTrace();
return null;
}
return outputStream.toByteArray();
}
private static void parseMavenVersion()
{
try (ByteArrayInputStream fis = new ByteArrayInputStream(downloadUrl(new URL(MAVEN_METADATA))))
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setIgnoringElementContentWhitespace(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(fis);
NodeList versionList = doc.getElementsByTagName("version");
for (int i = 0; i != versionList.getLength(); i++)
{
Node node = versionList.item(i);
if (node.getTextContent() != null && !node.getTextContent().endsWith("SNAPSHOT"))
{
upstreamVersion = node.getTextContent();
}
}
}
catch (ParserConfigurationException | IOException | SAXException ex)
{
logger.error(null, ex);
}
}
}

View File

@@ -25,7 +25,6 @@
package net.runelite.http.api.account;
import com.google.gson.JsonParseException;
import io.reactivex.rxjava3.core.Observable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -96,7 +95,7 @@ public class AccountClient
}
}
public Observable<Boolean> sessionCheck()
public boolean sessionCheck()
{
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
.addPathSegment("account")
@@ -104,23 +103,20 @@ public class AccountClient
.build();
log.debug("Built URI: {}", url);
return Observable.fromCallable(() ->
{
Request request = new Request.Builder()
.header(RuneLiteAPI.RUNELITE_AUTH, uuid.toString())
.url(url)
.build();
try (Response response = client.newCall(request).execute())
{
return response.isSuccessful();
}
catch (IOException ex)
{
log.debug("Unable to verify session", ex);
return true; // assume it is still valid if the server is unreachable
}
});
Request request = new Request.Builder()
.header(RuneLiteAPI.RUNELITE_AUTH, uuid.toString())
.url(url)
.build();
try (Response response = client.newCall(request).execute())
{
return response.isSuccessful();
}
catch (IOException ex)
{
log.debug("Unable to verify session", ex);
return true; // assume it is still valid if the server is unreachable
}
}
}

View File

@@ -40,7 +40,6 @@ import okhttp3.Response;
@AllArgsConstructor
public class ChatClient
{
private static final RequestBody body = RequestBody.Companion.create(new byte[0], null);
private final OkHttpClient client;
public boolean submitKc(String username, String boss, int kc) throws IOException
@@ -289,7 +288,6 @@ public class ChatClient
}
}
public Duels getDuels(String username) throws IOException
{
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()

View File

@@ -1,47 +0,0 @@
/*
* Copyright (c) 2019, Spedwards <https://github.com/Spedwards>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.http.api.chat;
import lombok.Data;
import net.runelite.http.api.RuneLiteAPI;
@Data
public class House
{
private String owner;
private boolean guildedAltarPresent;
private boolean occultAltarPresent;
private boolean spiritTreePresent;
private boolean fairyRingPresent;
private boolean wildernessObeliskPresent;
private boolean repairStandPresent;
private boolean combatDummyPresent;
@Override
public String toString()
{
return RuneLiteAPI.GSON.toJson(this);
}
}

View File

@@ -24,6 +24,7 @@
*/
package net.runelite.http.api.config;
import com.google.gson.Gson;
import com.google.gson.JsonParseException;
import java.io.IOException;
import java.io.InputStream;
@@ -48,6 +49,7 @@ import okhttp3.Response;
public class ConfigClient
{
private static final MediaType TEXT_PLAIN = MediaType.parse("text/plain");
private static final Gson GSON = RuneLiteAPI.GSON;
private final OkHttpClient client;
private final UUID uuid;
@@ -114,6 +116,59 @@ public class ConfigClient
return future;
}
public CompletableFuture<Void> patch(Configuration configuration)
{
CompletableFuture<Void> future = new CompletableFuture<>();
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
.addPathSegment("config")
.build();
log.debug("Built URI: {}", url);
Request request = new Request.Builder()
.patch(RequestBody.create(RuneLiteAPI.JSON, GSON.toJson(configuration)))
.header(RuneLiteAPI.RUNELITE_AUTH, uuid.toString())
.url(url)
.build();
client.newCall(request).enqueue(new Callback()
{
@Override
public void onFailure(Call call, IOException e)
{
log.warn("Unable to synchronize configuration item", e);
future.completeExceptionally(e);
}
@Override
public void onResponse(Call call, Response response)
{
if (response.code() != 200)
{
String body = "bad response";
try
{
body = response.body().string();
}
catch (IOException ignored)
{
}
log.warn("failed to synchronize some of {} configuration values: {}", configuration.getConfig().size(), body);
}
else
{
log.debug("Synchronized {} configuration values", configuration.getConfig().size());
}
response.close();
future.complete(null);
}
});
return future;
}
public CompletableFuture<Void> unset(String key)
{
CompletableFuture<Void> future = new CompletableFuture<>();
@@ -151,4 +206,4 @@ public class ConfigClient
return future;
}
}
}

View File

@@ -24,28 +24,15 @@
*/
package net.runelite.http.api.config;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ConfigEntry
{
private String key;
private String value;
public String getKey()
{
return key;
}
public void setKey(String key)
{
this.key = key;
}
public String getValue()
{
return value;
}
public void setValue(String value)
{
this.value = value;
}
}
}

View File

@@ -26,18 +26,12 @@ package net.runelite.http.api.config;
import java.util.ArrayList;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class Configuration
{
private List<ConfigEntry> config = new ArrayList<>();
public Configuration(List<ConfigEntry> config)
{
this.config = config;
}
public List<ConfigEntry> getConfig()
{
return config;
}
}
}

View File

@@ -1,100 +0,0 @@
/*
* Copyright (c) 2018, Forsco <https://github.com/forsco>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.http.api.discord;
import com.google.gson.Gson;
import java.io.IOException;
import lombok.extern.slf4j.Slf4j;
import net.runelite.http.api.RuneLiteAPI;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.HttpUrl;
import okhttp3.MediaType;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
@Slf4j
public class DiscordClient
{
public static final Gson gson = new Gson();
private static final MediaType JSON = MediaType.parse("application/json");
public void message(HttpUrl url, DiscordMessage discordMessage)
{
log.debug("Message being sent");
message(url, discordMessage, 0, 5);
}
private void message(HttpUrl url, DiscordMessage discordMessage, int retryAttempt, int maxAttempts)
{
RequestBody body = RequestBody.Companion.create(gson.toJson(discordMessage), JSON);
Request request = new Request.Builder()
.post(body)
.url(url)
.build();
log.debug("Attempting to message with {}", discordMessage);
RuneLiteAPI.CLIENT.newCall(request).enqueue(new Callback()
{
@Override
public void onFailure(Call call, IOException e)
{
log.warn("Unable to submit discord post.", e);
if (retryAttempt < maxAttempts)
{
message(url, discordMessage, retryAttempt + 1, maxAttempts);
}
}
@Override
public void onResponse(Call call, Response response) throws IOException
{
try
{
if (response.body() == null)
{
log.debug("API Call - Reponse was null.");
return;
}
if (response.body().string().contains("You are being rate limited") && retryAttempt < maxAttempts)
{
log.debug("You are being rate limited, retrying...");
message(url, discordMessage, retryAttempt + 1, maxAttempts);
}
}
finally
{
response.close();
log.debug("Submitted discord log record");
}
}
});
}
}

View File

@@ -1,80 +0,0 @@
/*
* Copyright (c) 2018, Forsco <https://github.com/forsco>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.http.api.discord;
import java.util.ArrayList;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import net.runelite.http.api.discord.embed.AuthorEmbed;
import net.runelite.http.api.discord.embed.FieldEmbed;
import net.runelite.http.api.discord.embed.FooterEmbed;
import net.runelite.http.api.discord.embed.ImageEmbed;
import net.runelite.http.api.discord.embed.ProviderEmbed;
import net.runelite.http.api.discord.embed.ThumbnailEmbed;
import net.runelite.http.api.discord.embed.VideoEmbed;
@Getter
@Setter
@Builder
@AllArgsConstructor
@ToString
public class DiscordEmbed
{
String title;
String type;
String description;
String url;
String timestamp;
String iconurl;
String color;
FooterEmbed footer;
ImageEmbed image;
ThumbnailEmbed thumbnail;
VideoEmbed video;
ProviderEmbed provider;
AuthorEmbed author;
final List<FieldEmbed> fields = new ArrayList<>();
public DiscordEmbed(AuthorEmbed author, ThumbnailEmbed thumb, String description, FooterEmbed footer, String color, List<FieldEmbed> fields)
{
this.author = author;
this.thumbnail = thumb;
this.description = description;
this.footer = footer;
this.color = color;
this.fields.addAll(fields);
}
public DiscordMessage toDiscordMessage(String username, String content, String avatarUrl)
{
return new DiscordMessage(username, content, avatarUrl, this);
}
}

View File

@@ -1,68 +0,0 @@
/*
* Copyright (c) 2018, Forsco <https://github.com/forsco>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.http.api.discord;
import com.google.gson.annotations.SerializedName;
import java.util.ArrayList;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
public class DiscordMessage
{
String username;
String content;
@SerializedName("avatar_url")
String avatarUrl;
@SerializedName("tts")
boolean textToSpeech;
final List<DiscordEmbed> embeds = new ArrayList<>();
DiscordMessage(String username, String content, String avatar_url, DiscordEmbed embed)
{
this.username = username;
this.content = content;
this.avatarUrl = avatar_url;
this.embeds.add(embed);
}
public void setUsername(String username)
{
if (username != null)
{
this.username = username.substring(0, Math.min(31, username.length()));
}
else
{
this.username = null;
}
}
}

View File

@@ -1,48 +0,0 @@
/*
* Copyright (c) 2018, Forsco <https://github.com/forsco>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.http.api.discord.embed;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class AuthorEmbed
{
String name;
String url;
String icon_url;
String proxy_icon_url;
}

View File

@@ -1,50 +0,0 @@
/*
* Copyright (c) 2018, Forsco <https://github.com/forsco>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.http.api.discord.embed;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class FieldEmbed
{
@NonNull
String name;
@NonNull
String value;
boolean inline;
}

View File

@@ -1,47 +0,0 @@
/*
* Copyright (c) 2018, Forsco <https://github.com/forsco>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.http.api.discord.embed;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class FooterEmbed
{
String text;
String icon_url;
String proxy_icon_url;
}

View File

@@ -1,46 +0,0 @@
/*
* Copyright (c) 2018, Forsco <https://github.com/forsco>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.http.api.discord.embed;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class ProviderEmbed
{
String name;
String url;
}

View File

@@ -1,48 +0,0 @@
/*
* Copyright (c) 2018, Forsco <https://github.com/forsco>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.http.api.discord.embed;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class ThumbnailEmbed
{
String url;
String proxy_url;
int height;
int width;
}

View File

@@ -1,47 +0,0 @@
/*
* Copyright (c) 2018, Forsco <https://github.com/forsco>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.http.api.discord.embed;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class VideoEmbed
{
String url;
int height;
int width;
}

View File

@@ -70,10 +70,9 @@ public class ExamineClient
log.debug("Built URI: {}", url);
RequestBody body = RequestBody.Companion.create(text, TEXT);
Request request = new Request.Builder()
.url(url)
.post(body)
.post(RequestBody.create(TEXT, text))
.build();
client.newCall(request).enqueue(new Callback()

View File

@@ -59,7 +59,6 @@ public class GrandExchangeClient
.addPathSegment("ge")
.build();
RequestBody body = RequestBody.Companion.create(GSON.toJson(grandExchangeTrade), JSON);
Request.Builder builder = new Request.Builder();
if (uuid != null)
{
@@ -71,7 +70,7 @@ public class GrandExchangeClient
}
Request request = builder
.post(body)
.post(RequestBody.create(JSON, GSON.toJson(grandExchangeTrade)))
.url(url)
.build();

View File

@@ -24,18 +24,14 @@
*/
package net.runelite.http.api.item;
import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonParseException;
import com.google.gson.stream.JsonReader;
import io.reactivex.rxjava3.core.Observable;
import java.awt.image.BufferedImage;
import com.google.gson.reflect.TypeToken;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import javax.imageio.ImageIO;
import javax.naming.directory.SearchResult;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.runelite.http.api.RuneLiteAPI;
@@ -50,13 +46,13 @@ public class ItemClient
{
private final OkHttpClient client;
public ItemPrice lookupItemPrice(int itemId) throws IOException
public ItemPrice[] getPrices() throws IOException
{
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
HttpUrl.Builder urlBuilder = RuneLiteAPI.getApiBase().newBuilder()
.addPathSegment("item")
.addPathSegment("" + itemId)
.addPathSegment("price")
.build();
.addPathSegment("prices.js");
HttpUrl url = urlBuilder.build();
log.debug("Built URI: {}", url);
@@ -68,43 +64,7 @@ public class ItemClient
{
if (!response.isSuccessful())
{
log.debug("Error looking up item {}: {}", itemId, response);
return null;
}
InputStream in = response.body().byteStream();
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), ItemPrice.class);
}
catch (JsonParseException ex)
{
throw new IOException(ex);
}
}
public ItemPrice[] lookupItemPrice(Integer[] itemIds) throws IOException
{
HttpUrl.Builder urlBuilder = RuneLiteAPI.getApiBase().newBuilder()
.addPathSegment("item")
.addPathSegment("price");
for (int itemId : itemIds)
{
urlBuilder.addQueryParameter("id", String.valueOf(itemId));
}
HttpUrl url = urlBuilder.build();
log.debug("Built URI: {}", url);
Request request = new Request.Builder()
.url(url)
.build();
try (Response response = client.newCall(request).execute())
{
if (!response.isSuccessful())
{
log.debug("Error looking up items {}: {}", Arrays.toString(itemIds), response);
log.warn("Error looking up prices: {}", response);
return null;
}
@@ -117,13 +77,14 @@ public class ItemClient
}
}
public Observable<BufferedImage> getIcon(int itemId)
public Map<Integer, ItemStats> getStats() throws IOException
{
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
HttpUrl.Builder urlBuilder = RuneLiteAPI.getStaticBase().newBuilder()
.addPathSegment("item")
.addPathSegment("" + itemId)
.addPathSegment("icon")
.build();
// TODO: Change this to stats.min.json later after release is undeployed
.addPathSegment("stats.ids.min.json");
HttpUrl url = urlBuilder.build();
log.debug("Built URI: {}", url);
@@ -131,128 +92,23 @@ public class ItemClient
.url(url)
.build();
return Observable.defer(() ->
try (Response response = client.newCall(request).execute())
{
try (Response response = client.newCall(request).execute())
if (!response.isSuccessful())
{
if (!response.isSuccessful())
{
log.debug("Error grabbing icon {}: {}", itemId, response);
return Observable.just(null);
}
InputStream in = response.body().byteStream();
synchronized (ImageIO.class)
{
return Observable.just(ImageIO.read(in));
}
log.warn("Error looking up item stats: {}", response);
return null;
}
});
}
public Observable<SearchResult> search(String itemName)
{
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
.addPathSegment("item")
.addPathSegment("search")
.addQueryParameter("query", itemName)
.build();
log.debug("Built URI: {}", url);
return Observable.defer(() ->
InputStream in = response.body().byteStream();
final Type typeToken = new TypeToken<Map<Integer, ItemStats>>()
{
}.getType();
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), typeToken);
}
catch (JsonParseException ex)
{
Request request = new Request.Builder()
.url(url)
.build();
try (Response response = client.newCall(request).execute())
{
if (!response.isSuccessful())
{
log.debug("Error looking up item {}: {}", itemName, response);
return Observable.just(null);
}
InputStream in = response.body().byteStream();
return Observable.just(RuneLiteAPI.GSON.fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), SearchResult.class));
}
catch (JsonParseException ex)
{
return Observable.error(ex);
}
});
}
public Observable<ImmutableMap<Integer, ItemPrice>> getPrices()
{
HttpUrl.Builder urlBuilder = RuneLiteAPI.getApiBase().newBuilder()
.addPathSegment("item")
.addPathSegment("prices.js");
HttpUrl url = urlBuilder.build();
log.debug("Built URI: {}", url);
return Observable.fromCallable(() ->
{
Request request = new Request.Builder()
.url(url)
.build();
try (JsonReader reader = new JsonReader(client.newCall(request).execute().body().charStream()))
{
ImmutableMap.Builder<Integer, ItemPrice> builder = ImmutableMap.builderWithExpectedSize(3666);
reader.beginArray();
while (reader.hasNext())
{
ItemPrice price = RuneLiteAPI.GSON.fromJson(reader, ItemPrice.class);
builder.put(
price.getId(),
price
);
}
reader.endArray();
return builder.build();
}
});
}
public Observable<ImmutableMap<Integer, ItemStats>> getStats()
{
HttpUrl url = RuneLiteAPI.getStaticBase()
.newBuilder()
.addPathSegment("item")
.addPathSegment("stats.ids.min.json")
.build();
log.debug("Built URI {}", url);
return Observable.fromCallable(() ->
{
Request request = new Request.Builder()
.url(url)
.build();
try (JsonReader reader = new JsonReader(client.newCall(request).execute().body().charStream()))
{
// This is the size the items are as I wrote this. the builder gets increased by 1 every time otherwise
ImmutableMap.Builder<Integer, ItemStats> builder = ImmutableMap.builderWithExpectedSize(7498);
reader.beginObject();
while (reader.hasNext())
{
builder.put(
Integer.parseInt(reader.nextName()),
RuneLiteAPI.GSON.fromJson(reader, ItemStats.class)
);
}
reader.endObject();
return builder.build();
}
});
throw new IOException(ex);
}
}
}

View File

@@ -29,7 +29,7 @@ import lombok.Builder;
import lombok.Value;
@Value
@Builder(builderClassName = "Builder")
@Builder
public class ItemEquipmentStats
{
private int slot;

View File

@@ -24,14 +24,10 @@
*/
package net.runelite.http.api.item;
import lombok.AllArgsConstructor;
import lombok.Builder;
import com.google.gson.annotations.SerializedName;
import lombok.Value;
@Value
@AllArgsConstructor
@Builder(builderClassName = "Builder")
public class ItemStats
{
private boolean quest;
@@ -57,9 +53,9 @@ public class ItemStats
{
final ItemEquipmentStats equipment = this.equipment != null
? this.equipment
: new ItemEquipmentStats.Builder().build();
: new ItemEquipmentStats.ItemEquipmentStatsBuilder().build();
newEquipment = new ItemEquipmentStats.Builder()
newEquipment = new ItemEquipmentStats.ItemEquipmentStatsBuilder()
.slot(equipment.getSlot())
.astab(equipment.getAstab() - other.equipment.getAstab())
.aslash(equipment.getAslash() - other.equipment.getAslash())

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Forsco <https://github.com/forsco>
* Copyright (c) 2020, Adam <Adam@sigterm.info>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -7,7 +7,6 @@
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
@@ -23,26 +22,23 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.http.api.loottracker;
package net.runelite.http.api.discord.embed;
import java.time.Instant;
import java.util.Collection;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class ImageEmbed
public class LootAggregate
{
String url;
String proxy_url;
int height;
int width;
private String eventId;
private LootRecordType type;
private Collection<GameItem> drops;
private Instant first_time;
private Instant last_time;
private int amount;
}

View File

@@ -26,10 +26,8 @@ package net.runelite.http.api.loottracker;
import java.time.Instant;
import java.util.Collection;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
@Data
@@ -38,27 +36,8 @@ import lombok.NoArgsConstructor;
public class LootRecord
{
private String eventId;
@Getter
private String username;
private LootRecordType type;
private Object metadata;
private Collection<GameItem> drops;
private Instant time;
/**
* constructor for lootRecords retrieved by http api (doesn't store/retrieve username)
* @param eventId - the eventID or the name/title of the LootRecord
* @param type - The LootRecordType
* @param gameItems - the list of items/quantities
* @param time - the Instant that the Loot Record was received
*/
public LootRecord(String eventId, LootRecordType type, List<GameItem> gameItems, Instant time)
{
// Insert blank username
this.username = "";
this.eventId = eventId;
this.type = type;
this.drops = gameItems;
this.time = time;
}
}

View File

@@ -29,7 +29,6 @@ public enum LootRecordType
NPC,
PLAYER,
EVENT,
DEATH,
PICKPOCKET,
UNKNOWN
}

View File

@@ -64,13 +64,18 @@ public class LootTrackerClient
{
CompletableFuture<Void> future = new CompletableFuture<>();
RequestBody body = RequestBody.Companion.create(GSON.toJson(lootRecords), JSON);
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
.addPathSegment("loottracker")
.build();
Request.Builder requestBuilder = new Request.Builder();
if (uuid != null)
{
requestBuilder.header(RuneLiteAPI.RUNELITE_AUTH, uuid.toString());
}
requestBuilder.post(body);
requestBuilder.post(RequestBody.create(JSON, GSON.toJson(lootRecords)))
.url(url)
.build();
client.newCall(requestBuilder.build()).enqueue(new Callback()
{
@@ -100,7 +105,7 @@ public class LootTrackerClient
return future;
}
public Collection<LootRecord> get() throws IOException
public Collection<LootAggregate> get() throws IOException
{
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
.addPathSegment("loottracker")
@@ -120,7 +125,9 @@ public class LootTrackerClient
}
InputStream in = response.body().byteStream();
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), new TypeToken<List<LootRecord>>() {}.getType());
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), new TypeToken<List<LootAggregate>>()
{
}.getType());
}
catch (JsonParseException ex)
{

View File

@@ -25,7 +25,6 @@
package net.runelite.http.api.osbuddy;
import com.google.gson.JsonParseException;
import io.reactivex.rxjava3.core.Observable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -44,7 +43,7 @@ public class OSBGrandExchangeClient
{
private final OkHttpClient client;
public Observable<OSBGrandExchangeResult> lookupItem(int itemId)
public OSBGrandExchangeResult lookupItem(int itemId) throws IOException
{
final HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
.addPathSegment("osb")
@@ -54,26 +53,23 @@ public class OSBGrandExchangeClient
log.debug("Built URI: {}", url);
return Observable.defer(() ->
final Request request = new Request.Builder()
.url(url)
.build();
try (final Response response = client.newCall(request).execute())
{
final Request request = new Request.Builder()
.url(url)
.build();
try (final Response response = client.newCall(request).execute())
if (!response.isSuccessful())
{
if (!response.isSuccessful())
{
return Observable.error(new IOException("Error looking up item id: " + response));
}
final InputStream in = response.body().byteStream();
return Observable.just(RuneLiteAPI.GSON.fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), OSBGrandExchangeResult.class));
throw new IOException("Error looking up item id: " + response);
}
catch (JsonParseException ex)
{
return Observable.error(ex);
}
});
final InputStream in = response.body().byteStream();
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), OSBGrandExchangeResult.class);
}
catch (JsonParseException ex)
{
throw new IOException(ex);
}
}
}

View File

@@ -1,215 +0,0 @@
/*
* Copyright (c) 2019, Lucas <https://github.com/lucwousin>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.http.api.util;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.time.Instant;
import net.runelite.http.api.item.ItemEquipmentStats;
import net.runelite.http.api.item.ItemPrice;
import net.runelite.http.api.item.ItemStats;
/**
* A class to put GSON TypeAdapters. These make just as fast the first time you
* deserialize something as it would otherwise be after creating these itself.
* Kinda funny actually, cause the first time probably matters the most, especially
* for jsons that only get deserialized once.
*/
public class TypeAdapters
{
public static final TypeAdapter<ItemStats> ITEMSTATS = new TypeAdapter<ItemStats>()
{
@Deprecated
@Override
public void write(JsonWriter out, ItemStats value)
{
throw new UnsupportedOperationException("Not supported");
}
@Override
public ItemStats read(JsonReader in) throws IOException
{
in.beginObject();
boolean quest = false;
boolean equip = false;
double weight = 0;
ItemEquipmentStats stats = null;
while (in.peek() != JsonToken.END_OBJECT)
{
switch (in.nextName())
{
case "quest":
quest = in.nextBoolean();
break;
case "equipable":
equip = in.nextBoolean();
break;
case "weight":
weight = in.nextDouble();
break;
case "equipment":
stats = EQUIPMENTSTATS.read(in);
break;
}
}
in.endObject();
return new ItemStats(quest, equip, weight, 0, stats);
}
};
public static final TypeAdapter<ItemEquipmentStats> EQUIPMENTSTATS = new TypeAdapter<ItemEquipmentStats>()
{
@Deprecated
@Override
public void write(JsonWriter out, ItemEquipmentStats value)
{
throw new UnsupportedOperationException("Not supported");
}
@Override
public ItemEquipmentStats read(JsonReader in) throws IOException
{
ItemEquipmentStats.Builder builder = ItemEquipmentStats.builder();
in.beginObject();
while (in.peek() != JsonToken.END_OBJECT)
{
String name = in.nextName();
int val = in.nextInt();
switch (name)
{
case "slot":
builder.slot(val);
break;
case "astab":
builder.astab(val);
break;
case "aslash":
builder.aslash(val);
break;
case "acrush":
builder.acrush(val);
break;
case "amagic":
builder.amagic(val);
break;
case "arange":
builder.arange(val);
break;
case "dstab":
builder.dstab(val);
break;
case "dslash":
builder.dslash(val);
break;
case "dcrush":
builder.dcrush(val);
break;
case "dmagic":
builder.dmagic(val);
break;
case "drange":
builder.drange(val);
break;
case "str":
builder.str(val);
break;
case "rstr":
builder.rstr(val);
break;
case "mdmg":
builder.mdmg(val);
break;
case "prayer":
builder.prayer(val);
break;
case "aspeed":
builder.aspeed(val);
break;
}
}
in.endObject();
return builder.build();
}
};
public static final TypeAdapter<ItemPrice> ITEMPRICE = new TypeAdapter<ItemPrice>()
{
@Override
public void write(JsonWriter out, ItemPrice value)
{
throw new UnsupportedOperationException("Not supported");
}
@Override
public ItemPrice read(JsonReader in) throws IOException
{
/*
* The ItemPrice json hosted by runelite is 'perfect'
* by that I mean every field always exists, even with value 0.
* This is why we can skip names and known-0 values
*/
ItemPrice ret = new ItemPrice();
in.beginObject();
// ID
in.skipValue();
ret.setId(in.nextInt());
// Name
in.skipValue();
ret.setName(in.nextString());
// Price
in.skipValue();
ret.setPrice(in.nextInt());
// Time
in.skipValue();
in.beginObject();
// Secs
in.skipValue();
ret.setTime(Instant.ofEpochSecond(in.nextLong()));
// Nanos
in.skipValue();
in.skipValue();
in.endObject();
in.endObject();
return ret;
}
};
}

View File

@@ -33,7 +33,6 @@ import java.nio.charset.StandardCharsets;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.runelite.http.api.RuneLiteAPI;
import okhttp3.CacheControl;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
@@ -55,7 +54,6 @@ public class WorldClient
Request request = new Request.Builder()
.url(url)
.cacheControl(CacheControl.FORCE_NETWORK)
.build();
try (Response response = client.newCall(request).execute())

View File

@@ -16,6 +16,10 @@
package net.runelite.http.api.ws;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
@@ -27,9 +31,6 @@ import com.google.gson.internal.Streams;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Adapts values whose runtime type may differ from their declaration type. This

View File

@@ -24,9 +24,7 @@
*/
package net.runelite.http.api.ws;
import net.runelite.api.events.Event;
public class WebsocketMessage implements Event
public class WebsocketMessage
{
protected boolean _party;

View File

@@ -25,10 +25,9 @@
package net.runelite.http.api.ws.messages;
import java.util.UUID;
import net.runelite.api.events.Event;
import net.runelite.http.api.ws.WebsocketMessage;
public class Handshake extends WebsocketMessage implements Event
public class Handshake extends WebsocketMessage
{
private UUID session;

View File

@@ -24,14 +24,13 @@
*/
package net.runelite.http.api.ws.messages;
import net.runelite.api.events.Event;
import net.runelite.http.api.ws.WebsocketMessage;
/**
* Called after a successful login to the server
* @author Adam
*/
public class LoginResponse extends WebsocketMessage implements Event
public class LoginResponse extends WebsocketMessage
{
private String username;

View File

@@ -27,12 +27,11 @@ package net.runelite.http.api.ws.messages.party;
import java.util.UUID;
import lombok.EqualsAndHashCode;
import lombok.Value;
import net.runelite.api.events.Event;
import net.runelite.http.api.ws.WebsocketMessage;
@Value
@EqualsAndHashCode(callSuper = true)
public class Join extends WebsocketMessage implements Event
public class Join extends WebsocketMessage
{
private final UUID partyId;
private final String name;

View File

@@ -24,7 +24,8 @@
*/
package net.runelite.http.api.ws.messages.party;
import net.runelite.api.events.Event;
import net.runelite.http.api.ws.WebsocketMessage;
public class Part extends WebsocketMessage implements Event {}
public class Part extends WebsocketMessage
{
}

View File

@@ -24,12 +24,10 @@
*/
package net.runelite.http.api.ws.messages.party;
import lombok.EqualsAndHashCode;
import lombok.Value;
import net.runelite.api.events.Event;
@Value
@EqualsAndHashCode(callSuper = true)
public class PartyChatMessage extends PartyMemberMessage implements Event
public class PartyChatMessage extends PartyMemberMessage
{
private final String value;
}

View File

@@ -3,11 +3,10 @@ package net.runelite.http.api.ws.messages.party;
import java.util.UUID;
import lombok.Getter;
import lombok.Setter;
import net.runelite.api.events.Event;
@Getter
@Setter
public abstract class PartyMemberMessage extends PartyMessage implements Event
public abstract class PartyMemberMessage extends PartyMessage
{
private UUID memberId;
}

View File

@@ -24,10 +24,9 @@
*/
package net.runelite.http.api.ws.messages.party;
import net.runelite.api.events.Event;
import net.runelite.http.api.ws.WebsocketMessage;
public abstract class PartyMessage extends WebsocketMessage implements Event
public abstract class PartyMessage extends WebsocketMessage
{
public PartyMessage()
{

View File

@@ -27,12 +27,11 @@ package net.runelite.http.api.ws.messages.party;
import java.util.UUID;
import lombok.EqualsAndHashCode;
import lombok.Value;
import net.runelite.api.events.Event;
import net.runelite.http.api.ws.WebsocketMessage;
@Value
@EqualsAndHashCode(callSuper = true)
public class UserJoin extends WebsocketMessage implements Event
public class UserJoin extends WebsocketMessage
{
private final UUID memberId;
private final UUID partyId;

View File

@@ -27,12 +27,11 @@ package net.runelite.http.api.ws.messages.party;
import java.util.UUID;
import lombok.EqualsAndHashCode;
import lombok.Value;
import net.runelite.api.events.Event;
import net.runelite.http.api.ws.WebsocketMessage;
@Value
@EqualsAndHashCode(callSuper = true)
public class UserPart extends WebsocketMessage implements Event
public class UserPart extends WebsocketMessage
{
private final UUID memberId;
}

View File

@@ -26,8 +26,9 @@ package net.runelite.http.api.ws.messages.party;
import lombok.EqualsAndHashCode;
import lombok.Value;
import net.runelite.api.events.Event;
@Value
@EqualsAndHashCode(callSuper = true)
public class UserSync extends PartyMemberMessage implements Event {}
public class UserSync extends PartyMemberMessage
{
}

View File

@@ -29,16 +29,18 @@ import com.google.gson.reflect.TypeToken;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.nio.charset.StandardCharsets;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.runelite.http.api.RuneLiteAPI;
import static net.runelite.http.api.RuneLiteAPI.JSON;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
@Slf4j
@@ -47,21 +49,18 @@ public class XteaClient
{
private final OkHttpClient client;
public void submit(int region, int[] keys)
public void submit(XteaRequest xteaRequest)
{
String json = RuneLiteAPI.GSON.toJson(xteaRequest);
HttpUrl url = RuneLiteAPI.getXteaBase().newBuilder()
.addPathSegment("submit")
.addQueryParameter("region", String.valueOf(region))
.addQueryParameter("key1", String.valueOf(keys[0]))
.addQueryParameter("key2", String.valueOf(keys[1]))
.addQueryParameter("key3", String.valueOf(keys[2]))
.addQueryParameter("key4", String.valueOf(keys[3]))
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
.addPathSegment("xtea")
.build();
log.debug("Built URI: {}", url);
Request request = new Request.Builder()
.post(RequestBody.create(JSON, json))
.url(url)
.build();
@@ -91,10 +90,10 @@ public class XteaClient
});
}
public HashMap<Integer, Integer[]> get() throws IOException
public List<XteaKey> get() throws IOException
{
HttpUrl url = RuneLiteAPI.getXteaBase().newBuilder()
.addPathSegment("get")
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
.addPathSegment("xtea")
.build();
Request request = new Request.Builder()
@@ -105,7 +104,7 @@ public class XteaClient
{
InputStream in = response.body().byteStream();
// CHECKSTYLE:OFF
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), new TypeToken<HashMap<Integer, Integer[]>>() {}.getType());
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), new TypeToken<List<XteaKey>>() { }.getType());
// CHECKSTYLE:ON
}
catch (JsonParseException ex)
@@ -113,4 +112,26 @@ public class XteaClient
throw new IOException(ex);
}
}
}
public XteaKey get(int region) throws IOException
{
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
.addPathSegment("xtea")
.addPathSegment(Integer.toString(region))
.build();
Request request = new Request.Builder()
.url(url)
.build();
try (Response response = client.newCall(request).execute())
{
InputStream in = response.body().byteStream();
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), XteaKey.class);
}
catch (JsonParseException ex)
{
throw new IOException(ex);
}
}
}

View File

@@ -27,7 +27,7 @@ package net.runelite.http.api.xtea;
public class XteaKey
{
private int region;
private int[] keys;
private int keys[];
public int getRegion()
{