Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http-server: add configurable server port #90

Open
wants to merge 2 commits into
base: http-plugin
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repositories {
mavenCentral()
}

def runeLiteVersion = '1.6.33'
def runeLiteVersion = 'latest.release'

dependencies {
compileOnly group: 'net.runelite', name:'client', version: runeLiteVersion
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package info.sigterm.plugins.httpserver;

import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
import net.runelite.client.config.Range;

@ConfigGroup("httpserver")
public interface HttpServerConfig extends Config {
@ConfigItem(
keyName = "port",
name = "Server port",
description = "Port to host the HTTP server on. Requires a plugin restart after changing."
)
@Range(
min = 1,
max = 65535
)
default int port() {
return 8080;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.inject.Provides;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
Expand All @@ -19,6 +20,7 @@
import net.runelite.api.ItemContainer;
import net.runelite.api.Skill;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.http.api.RuneLiteAPI;
Expand All @@ -34,12 +36,15 @@ public class HttpServerPlugin extends Plugin
@Inject
private ClientThread clientThread;

@Inject
private HttpServerConfig config;

private HttpServer server;

@Override
protected void startUp() throws Exception
{
server = HttpServer.create(new InetSocketAddress(8080), 0);
server = HttpServer.create(new InetSocketAddress(config.port()), 0);
server.createContext("/stats", this::handleStats);
server.createContext("/inv", handlerForInv(InventoryID.INVENTORY));
server.createContext("/equip", handlerForInv(InventoryID.EQUIPMENT));
Expand All @@ -53,6 +58,12 @@ protected void shutDown() throws Exception
server.stop(1);
}

@Provides
HttpServerConfig provideConfig(ConfigManager configManager)
{
return configManager.getConfig(HttpServerConfig.class);
}

public void handleStats(HttpExchange exchange) throws IOException
{
JsonArray skills = new JsonArray();
Expand Down