forked from openrs2/openrs2
The API endpoint isn't always updated immediately, so this is useful for gathering keys semi-manually if they're needed more urgently. Signed-off-by: Graham <gpe@openrs2.org>
parent
346302fc05
commit
b53149ce6b
@ -0,0 +1,46 @@ |
||||
plugins { |
||||
`java-library` |
||||
`maven-publish` |
||||
} |
||||
|
||||
dependencies { |
||||
annotationProcessor(libs.pf4j) |
||||
|
||||
compileOnly(libs.pf4j) |
||||
compileOnly(libs.runelite.client) |
||||
|
||||
testImplementation(libs.runelite.client) |
||||
} |
||||
|
||||
publishing { |
||||
publications.create<MavenPublication>("maven") { |
||||
from(components["java"]) |
||||
|
||||
pom { |
||||
packaging = "jar" |
||||
name.set("OpenRS2 XTEA Plugin") |
||||
description.set( |
||||
""" |
||||
A RuneLite/OpenOSRS plugin that collects XTEA keys and submits |
||||
them to the OpenRS2 Archive. |
||||
""".trimIndent() |
||||
) |
||||
} |
||||
} |
||||
} |
||||
|
||||
tasks.jar { |
||||
manifest { |
||||
attributes["Plugin-Description"] = "Collects XTEA keys and submits them to the OpenRS2 Archive" |
||||
attributes["Plugin-Id"] = "OpenRS2 XTEA" |
||||
attributes["Plugin-License"] = "ISC" |
||||
attributes["Plugin-Provider"] = "OpenRS2" |
||||
attributes["Plugin-Version"] = project.version |
||||
} |
||||
} |
||||
|
||||
tasks.register<JavaExec>("run") { |
||||
classpath = project.sourceSets.test.get().runtimeClasspath |
||||
mainClass.set("org.openrs2.xtea.XteaPluginTest") |
||||
jvmArgs = listOf("-ea") |
||||
} |
@ -0,0 +1,17 @@ |
||||
package org.openrs2.xtea; |
||||
|
||||
import net.runelite.client.config.Config; |
||||
import net.runelite.client.config.ConfigGroup; |
||||
import net.runelite.client.config.ConfigItem; |
||||
|
||||
@ConfigGroup("openrs2xtea") |
||||
public interface XteaConfig extends Config { |
||||
@ConfigItem( |
||||
keyName = "endpoint", |
||||
name = "API Endpoint", |
||||
description = "The URL the XTEA keys are submitted to" |
||||
) |
||||
default String endpoint() { |
||||
return "https://archive.openrs2.org/keys"; |
||||
} |
||||
} |
@ -0,0 +1,85 @@ |
||||
package org.openrs2.xtea; |
||||
|
||||
import java.io.IOException; |
||||
import javax.inject.Inject; |
||||
|
||||
import com.google.inject.Provides; |
||||
import net.runelite.api.Client; |
||||
import net.runelite.api.GameState; |
||||
import net.runelite.api.events.GameStateChanged; |
||||
import net.runelite.client.config.ConfigManager; |
||||
import net.runelite.client.eventbus.Subscribe; |
||||
import net.runelite.client.plugins.Plugin; |
||||
import net.runelite.client.plugins.PluginDescriptor; |
||||
import net.runelite.http.api.RuneLiteAPI; |
||||
import okhttp3.Call; |
||||
import okhttp3.Callback; |
||||
import okhttp3.OkHttpClient; |
||||
import okhttp3.Request; |
||||
import okhttp3.RequestBody; |
||||
import okhttp3.Response; |
||||
import okhttp3.internal.annotations.EverythingIsNonNull; |
||||
import org.pf4j.Extension; |
||||
import org.pf4j.ExtensionPoint; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
@Extension |
||||
@PluginDescriptor( |
||||
name = "OpenRS2 XTEA", |
||||
description = "Collects XTEA keys and submits them to the OpenRS2 Archive" |
||||
) |
||||
public final class XteaPlugin extends Plugin implements ExtensionPoint { |
||||
private static final Logger log = LoggerFactory.getLogger(XteaPlugin.class); |
||||
|
||||
@Inject |
||||
private XteaConfig config; |
||||
|
||||
@Inject |
||||
private Client client; |
||||
|
||||
@Inject |
||||
private OkHttpClient httpClient; |
||||
|
||||
@Provides |
||||
public XteaConfig provideConfig(ConfigManager configManager) { |
||||
return configManager.getConfig(XteaConfig.class); |
||||
} |
||||
|
||||
@Subscribe |
||||
public void onGameStateChanged(GameStateChanged event) { |
||||
if (event.getGameState() != GameState.LOGGED_IN) { |
||||
return; |
||||
} |
||||
|
||||
int[][] keys = client.getXteaKeys(); |
||||
String url = config.endpoint(); |
||||
|
||||
log.debug("Submitting {} XTEA keys to {}", keys.length, url); |
||||
|
||||
Request request = new Request.Builder() |
||||
.post(RequestBody.create(RuneLiteAPI.JSON, RuneLiteAPI.GSON.toJson(keys))) |
||||
.url(url) |
||||
.build(); |
||||
|
||||
httpClient.newCall(request).enqueue(new Callback() { |
||||
@EverythingIsNonNull |
||||
@Override |
||||
public void onFailure(Call call, IOException ex) { |
||||
log.error("XTEA key submission failed", ex); |
||||
} |
||||
|
||||
@EverythingIsNonNull |
||||
@Override |
||||
public void onResponse(Call call, Response response) { |
||||
try (response) { |
||||
if (response.isSuccessful()) { |
||||
log.debug("XTEA key submission successful"); |
||||
} else { |
||||
log.error("XTEA key submission failed with status code {}", response.code()); |
||||
} |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
} |
@ -0,0 +1,9 @@ |
||||
package org.pf4j; |
||||
|
||||
/** |
||||
* Stub implementation of {@code org.pf4j.ExtensionPoint} so the plugin works |
||||
* in and builds against RuneLite, which doesn't have P4J on its classpath. |
||||
*/ |
||||
public interface ExtensionPoint { |
||||
// empty
|
||||
} |
@ -0,0 +1,16 @@ |
||||
package org.openrs2.xtea; |
||||
|
||||
import net.runelite.client.RuneLite; |
||||
import net.runelite.client.externalplugins.ExternalPluginManager; |
||||
|
||||
public final class XteaPluginTest { |
||||
@SuppressWarnings("unchecked") |
||||
public static void main(String[] args) throws Exception { |
||||
ExternalPluginManager.loadBuiltin(XteaPlugin.class); |
||||
RuneLite.main(args); |
||||
} |
||||
|
||||
private XteaPluginTest() { |
||||
// empty
|
||||
} |
||||
} |
Loading…
Reference in new issue