Skip to content

Commit

Permalink
Fix HTTP server on outdated servers
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMicky-FR committed Dec 28, 2019
1 parent 2a922f0 commit ba90c22
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
10 changes: 6 additions & 4 deletions common/src/main/java/com/azuriom/azlink/common/AzLinkPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public void init() {

scheduler.scheduleAtFixedRate(fetcherTask, startDelay, TimeUnit.MINUTES.toMillis(1), TimeUnit.MILLISECONDS);

if (config.hasInstantCommands()) {
platform.executeAsync(httpServer::startSafe);
}

if (!config.isValid()) {
getLogger().warn("Invalid configuration, you can use '/azlink' to setup the plugin.");
return;
Expand All @@ -88,10 +92,6 @@ public void init() {
getLogger().warn("Unable to verify website connection: " + e.getMessage() + " - " + e.getClass().getName());
}
});

if (config.hasInstantCommands()) {
platform.executeAsync(httpServer::startSafe);
}
}

public void restartHttpServer() throws Exception {
Expand All @@ -103,8 +103,10 @@ public void restartHttpServer() throws Exception {
}

public void shutdown() {
getLogger().info("Shutting down scheduler");
scheduler.shutdown();

getLogger().info("Stopping HTTP server");
httpServer.stopSafe();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,27 @@ public HttpHandler(AzLinkPlugin plugin) {

@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) {
if (!request.uri().equals("/")) {
//noinspection deprecation - Request#uri is not avaible on old MC versions :(
String uri = request.getUri();
//noinspection deprecation - Request#method is not avaible on old MC versions :(
HttpMethod method = request.getMethod();

if (!uri.equals("/")) {
close(ctx, writeResponse(HttpResponseStatus.NOT_FOUND, "Error: Not Found"));
return;
}

if (request.method() == HttpMethod.GET) {
if (method == HttpMethod.GET) {
close(ctx, writeResponse(HttpResponseStatus.OK, "Status: OK"));
return;
}

if (request.method() == HttpMethod.POST) {
if (method == HttpMethod.POST) {
if (!plugin.getConfig().isValid()) {
close(ctx, writeResponse(HttpResponseStatus.UNPROCESSABLE_ENTITY, "Error: Invalid configuration"));
return;
}

String siteKeyHash = Hash.SHA_256.hash(plugin.getConfig().getSiteKey());

if (!siteKeyHash.equals(request.headers().get("Authorization"))) {
Expand Down
5 changes: 5 additions & 0 deletions universal-legacy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ dependencies {
compile project(':azlink-sponge')

compile 'com.google.code.gson:gson:2.8.5'

compile 'io.netty:netty-handler:4.1.38.Final'
compile 'io.netty:netty-codec-http:4.1.38.Final'
}

shadowJar {
archiveFileName = "AzLink-Legacy-${project.version}.jar"

relocate 'okio', 'com.azuriom.azlink.libs.okio'
relocate 'okhttp3', 'com.azuriom.azlink.libs.okhttp3'
relocate 'com.google.gson', 'com.azuriom.azlink.libs.gson'
relocate 'io.netty', 'com.azuriom.azlink.libs.netty'
}

artifacts {
Expand Down

0 comments on commit ba90c22

Please sign in to comment.