diff --git a/pom.xml b/pom.xml
index 9b4b2b9..7a85e9b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -24,7 +24,7 @@
com.eu.habbo
Habbo
- 2.5.0
+ 3.0.0
\ No newline at end of file
diff --git a/src/main/java/org/krews/plugin/nitro/Utils.java b/src/main/java/org/krews/plugin/nitro/Utils.java
new file mode 100644
index 0000000..5f643e4
--- /dev/null
+++ b/src/main/java/org/krews/plugin/nitro/Utils.java
@@ -0,0 +1,22 @@
+package org.krews.plugin.nitro;
+
+import java.net.URI;
+
+public class Utils {
+ public static String getDomainNameFromUrl(String url) throws Exception {
+ URI uri = new URI(url);
+ String domain = uri.getHost();
+ return domain.startsWith("www.") ? domain.substring(4) : domain;
+ }
+
+ public static boolean isWhitelisted(String toCheck, String[] whitelist) {
+ for(String whitelistEntry : whitelist) {
+ if(whitelistEntry.startsWith("*")) {
+ if(toCheck.endsWith(whitelistEntry.substring(1)) || ("." + toCheck).equals(whitelistEntry.substring(1))) return true;
+ } else {
+ if(toCheck.equals(whitelistEntry)) return true;
+ }
+ }
+ return false;
+ }
+}
diff --git a/src/main/java/org/krews/plugin/nitro/main.java b/src/main/java/org/krews/plugin/nitro/main.java
index df881f1..5b2bb7e 100644
--- a/src/main/java/org/krews/plugin/nitro/main.java
+++ b/src/main/java/org/krews/plugin/nitro/main.java
@@ -6,12 +6,16 @@ import com.eu.habbo.plugin.EventHandler;
import com.eu.habbo.plugin.EventListener;
import com.eu.habbo.plugin.HabboPlugin;
import com.eu.habbo.plugin.events.emulator.EmulatorLoadedEvent;
+import com.eu.habbo.plugin.events.users.UserGetIPAddressEvent;
+import io.netty.channel.Channel;
+import io.netty.util.AttributeKey;
import org.krews.plugin.nitro.websockets.NetworkChannelInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class main extends HabboPlugin implements EventListener {
private static final Logger LOGGER = LoggerFactory.getLogger(main.class);
+ public static final AttributeKey WS_IP = AttributeKey.valueOf("WS_IP");
public void onEnable() throws Exception {
Emulator.getPluginManager().registerEvents(this, this);
@@ -34,6 +38,7 @@ public class main extends HabboPlugin implements EventListener {
Emulator.getConfig().register("websockets.whitelist", "localhost");
Emulator.getConfig().register("ws.nitro.host", "0.0.0.0");
Emulator.getConfig().register("ws.nitro.port", "2096");
+ Emulator.getConfig().register("ws.nitro.ip.header", "");
NetworkChannelInitializer wsChannelHandler = new NetworkChannelInitializer();
Emulator.getGameServer().getServerBootstrap().childHandler(wsChannelHandler);
@@ -43,4 +48,15 @@ public class main extends HabboPlugin implements EventListener {
LOGGER.info("OFFICIAL PLUGIN - Nitro Websockets has started!");
LOGGER.info("Nitro Websockets Listening on " + (wsChannelHandler.isSSL() ? "wss://" : "ws://") + Emulator.getConfig().getValue("ws.nitro.host", "0.0.0.0") + ":" + Emulator.getConfig().getInt("ws.nitro.port", 2096));
}
+
+ @EventHandler
+ public void onUserGetIPEvent(UserGetIPAddressEvent e) {
+ Channel channel = e.habbo.getClient().getChannel();
+ if(channel != null && channel.hasAttr(main.WS_IP)) {
+ String ip = channel.attr(main.WS_IP).get();
+ if(!ip.isEmpty()) {
+ e.setUpdatedIp(ip);
+ }
+ }
+ }
}
diff --git a/src/main/java/org/krews/plugin/nitro/websockets/NetworkChannelInitializer.java b/src/main/java/org/krews/plugin/nitro/websockets/NetworkChannelInitializer.java
index 07cafdd..a8c46b7 100644
--- a/src/main/java/org/krews/plugin/nitro/websockets/NetworkChannelInitializer.java
+++ b/src/main/java/org/krews/plugin/nitro/websockets/NetworkChannelInitializer.java
@@ -14,6 +14,7 @@ import io.netty.handler.logging.LoggingHandler;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.timeout.IdleStateHandler;
import org.krews.plugin.nitro.websockets.codec.WebSocketCodec;
+import org.krews.plugin.nitro.websockets.handlers.CustomHTTPHandler;
import org.krews.plugin.nitro.websockets.ssl.SSLCertificateLoader;
public class NetworkChannelInitializer extends ChannelInitializer {
@@ -37,6 +38,7 @@ public class NetworkChannelInitializer extends ChannelInitializer
}
ch.pipeline().addLast("httpCodec", new HttpServerCodec());
ch.pipeline().addLast("objectAggregator", new HttpObjectAggregator(65536));
+ ch.pipeline().addLast("customHttpHandler", new CustomHTTPHandler());
ch.pipeline().addLast("protocolHandler", new WebSocketServerProtocolHandler("/", true));
ch.pipeline().addLast("websocketCodec", new WebSocketCodec());
diff --git a/src/main/java/org/krews/plugin/nitro/websockets/codec/WebSocketCodec.java b/src/main/java/org/krews/plugin/nitro/websockets/codec/WebSocketCodec.java
index 3bf7960..d8c6059 100644
--- a/src/main/java/org/krews/plugin/nitro/websockets/codec/WebSocketCodec.java
+++ b/src/main/java/org/krews/plugin/nitro/websockets/codec/WebSocketCodec.java
@@ -1,23 +1,14 @@
package org.krews.plugin.nitro.websockets.codec;
-import com.eu.habbo.Emulator;
import io.netty.buffer.ByteBuf;
-import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageCodec;
-import io.netty.handler.codec.http.websocketx.*;
-import org.krews.plugin.nitro.main;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
+import io.netty.handler.codec.http.websocketx.WebSocketFrame;
-import java.net.URI;
-import java.net.URISyntaxException;
import java.util.List;
public class WebSocketCodec extends MessageToMessageCodec {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketCodec.class);
-
@Override
protected void encode(ChannelHandlerContext ctx, ByteBuf in, List