diff --git a/src/main/java/net/raphimc/viaproxy/ViaProxy.java b/src/main/java/net/raphimc/viaproxy/ViaProxy.java
index 36cf577..278c971 100644
--- a/src/main/java/net/raphimc/viaproxy/ViaProxy.java
+++ b/src/main/java/net/raphimc/viaproxy/ViaProxy.java
@@ -43,6 +43,7 @@ import net.raphimc.viaproxy.plugins.PluginManager;
import net.raphimc.viaproxy.plugins.events.Client2ProxyHandlerCreationEvent;
import net.raphimc.viaproxy.plugins.events.ProxyStartEvent;
import net.raphimc.viaproxy.plugins.events.ProxyStopEvent;
+import net.raphimc.viaproxy.plugins.events.ViaProxyLoadedEvent;
import net.raphimc.viaproxy.proxy.EventListener;
import net.raphimc.viaproxy.proxy.client2proxy.Client2ProxyChannelInitializer;
import net.raphimc.viaproxy.proxy.client2proxy.Client2ProxyHandler;
@@ -162,6 +163,7 @@ public class ViaProxy {
Thread.sleep(1000);
}
ui.eventManager.call(new UIInitEvent());
+ EVENT_MANAGER.call(new ViaProxyLoadedEvent());
Logger.LOGGER.info("ViaProxy started successfully!");
} else {
Options.parse(args);
@@ -171,6 +173,7 @@ public class ViaProxy {
}
loaderThread.start();
loaderThread.join();
+ EVENT_MANAGER.call(new ViaProxyLoadedEvent());
Logger.LOGGER.info("ViaProxy started successfully!");
startProxy();
diff --git a/src/main/java/net/raphimc/viaproxy/plugins/events/ProxySessionCreationEvent.java b/src/main/java/net/raphimc/viaproxy/plugins/events/ProxySessionCreationEvent.java
new file mode 100644
index 0000000..f7e673c
--- /dev/null
+++ b/src/main/java/net/raphimc/viaproxy/plugins/events/ProxySessionCreationEvent.java
@@ -0,0 +1,51 @@
+/*
+ * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
+ * Copyright (C) 2023 RK_01/RaphiMC and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package net.raphimc.viaproxy.plugins.events;
+
+import net.raphimc.netminecraft.netty.connection.NetClient;
+
+public class ProxySessionCreationEvent {
+
+ /**
+ * The proxy session which will be used to connect to the server and store connection related data.
+ */
+ private T proxySession;
+
+ /**
+ * Whether the proxy session is a legacy passthrough handler.
+ */
+ private final boolean isLegacyPassthrough;
+
+ public ProxySessionCreationEvent(final T proxySession, final boolean isLegacyPassthrough) {
+ this.proxySession = proxySession;
+ this.isLegacyPassthrough = isLegacyPassthrough;
+ }
+
+ public T getProxySession() {
+ return this.proxySession;
+ }
+
+ public void setProxySession(final T proxySession) {
+ this.proxySession = proxySession;
+ }
+
+ public boolean isLegacyPassthrough() {
+ return this.isLegacyPassthrough;
+ }
+
+}
diff --git a/src/main/java/net/raphimc/viaproxy/plugins/events/ViaProxyLoadedEvent.java b/src/main/java/net/raphimc/viaproxy/plugins/events/ViaProxyLoadedEvent.java
new file mode 100644
index 0000000..5d972c6
--- /dev/null
+++ b/src/main/java/net/raphimc/viaproxy/plugins/events/ViaProxyLoadedEvent.java
@@ -0,0 +1,21 @@
+/*
+ * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
+ * Copyright (C) 2023 RK_01/RaphiMC and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package net.raphimc.viaproxy.plugins.events;
+
+public class ViaProxyLoadedEvent {
+}
diff --git a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java
index c1cf530..5cdcb2c 100644
--- a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java
+++ b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java
@@ -31,10 +31,7 @@ import net.raphimc.vialoader.util.VersionEnum;
import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.cli.options.Options;
import net.raphimc.viaproxy.injection.VersionEnumExtension;
-import net.raphimc.viaproxy.plugins.events.ConnectEvent;
-import net.raphimc.viaproxy.plugins.events.PreConnectEvent;
-import net.raphimc.viaproxy.plugins.events.Proxy2ServerHandlerCreationEvent;
-import net.raphimc.viaproxy.plugins.events.ResolveSrvEvent;
+import net.raphimc.viaproxy.plugins.events.*;
import net.raphimc.viaproxy.protocolhack.viaproxy.ViaBedrockTransferHolder;
import net.raphimc.viaproxy.proxy.packethandler.*;
import net.raphimc.viaproxy.proxy.proxy2server.Proxy2ServerChannelInitializer;
@@ -202,11 +199,13 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler {
private void connect(final ServerAddress serverAddress, final VersionEnum serverVersion, final VersionEnum clientVersion, final ConnectionState intendedState, final UserOptions userOptions, final String[] handshakeParts) {
final Supplier handlerSupplier = () -> ViaProxy.EVENT_MANAGER.call(new Proxy2ServerHandlerCreationEvent(new Proxy2ServerHandler(), false)).getHandler();
+ final ProxyConnection proxyConnection;
if (serverVersion.equals(VersionEnum.bedrockLatest)) {
- this.proxyConnection = new BedrockProxyConnection(handlerSupplier, Proxy2ServerChannelInitializer::new, this.proxyConnection.getC2P());
+ proxyConnection = new BedrockProxyConnection(handlerSupplier, Proxy2ServerChannelInitializer::new, this.proxyConnection.getC2P());
} else {
- this.proxyConnection = new ProxyConnection(handlerSupplier, Proxy2ServerChannelInitializer::new, this.proxyConnection.getC2P());
+ proxyConnection = new ProxyConnection(handlerSupplier, Proxy2ServerChannelInitializer::new, this.proxyConnection.getC2P());
}
+ this.proxyConnection = ViaProxy.EVENT_MANAGER.call(new ProxySessionCreationEvent<>(proxyConnection, false)).getProxySession();
this.proxyConnection.getC2P().attr(ProxyConnection.PROXY_CONNECTION_ATTRIBUTE_KEY).set(this.proxyConnection);
this.proxyConnection.setClientVersion(clientVersion);
this.proxyConnection.setC2pConnectionState(intendedState);
diff --git a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/passthrough/PassthroughClient2ProxyHandler.java b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/passthrough/PassthroughClient2ProxyHandler.java
index 94b4d42..6519c87 100644
--- a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/passthrough/PassthroughClient2ProxyHandler.java
+++ b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/passthrough/PassthroughClient2ProxyHandler.java
@@ -24,6 +24,7 @@ import net.raphimc.vialoader.util.VersionEnum;
import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.cli.options.Options;
import net.raphimc.viaproxy.plugins.events.Proxy2ServerHandlerCreationEvent;
+import net.raphimc.viaproxy.plugins.events.ProxySessionCreationEvent;
import net.raphimc.viaproxy.plugins.events.ResolveSrvEvent;
import net.raphimc.viaproxy.proxy.proxy2server.passthrough.PassthroughProxy2ServerChannelInitializer;
import net.raphimc.viaproxy.proxy.proxy2server.passthrough.PassthroughProxy2ServerHandler;
@@ -74,7 +75,8 @@ public class PassthroughClient2ProxyHandler extends SimpleChannelInboundHandler<
protected void connectToServer(final Channel c2pChannel) {
final Supplier handlerSupplier = () -> ViaProxy.EVENT_MANAGER.call(new Proxy2ServerHandlerCreationEvent(new PassthroughProxy2ServerHandler(), true)).getHandler();
- this.proxyConnection = new LegacyProxyConnection(handlerSupplier, PassthroughProxy2ServerChannelInitializer::new, c2pChannel);
+ final LegacyProxyConnection proxyConnection = new LegacyProxyConnection(handlerSupplier, PassthroughProxy2ServerChannelInitializer::new, c2pChannel);
+ this.proxyConnection = ViaProxy.EVENT_MANAGER.call(new ProxySessionCreationEvent<>(proxyConnection, true)).getProxySession();
this.proxyConnection.getC2P().attr(LegacyProxyConnection.LEGACY_PROXY_CONNECTION_ATTRIBUTE_KEY).set(this.proxyConnection);
final ServerAddress unresolvedAddress = this.getServerAddress();