mirror of
https://github.com/ViaVersion/ViaProxy.git
synced 2025-01-02 18:28:33 +01:00
Added JoinServerRequest event
This commit is contained in:
parent
7c70cfa481
commit
e6dc79ff61
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||||
|
* Copyright (C) 2021-2024 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package net.raphimc.viaproxy.plugins.events;
|
||||||
|
|
||||||
|
import net.raphimc.viaproxy.plugins.events.types.EventCancellable;
|
||||||
|
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||||
|
|
||||||
|
public class JoinServerRequestEvent extends EventCancellable {
|
||||||
|
|
||||||
|
private final ProxyConnection proxyConnection;
|
||||||
|
private final String serverIdHash;
|
||||||
|
|
||||||
|
public JoinServerRequestEvent(final ProxyConnection proxyConnection, final String serverIdHash) {
|
||||||
|
this.proxyConnection = proxyConnection;
|
||||||
|
this.serverIdHash = serverIdHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProxyConnection getProxyConnection() {
|
||||||
|
return this.proxyConnection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServerIdHash() {
|
||||||
|
return this.serverIdHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -35,9 +35,11 @@ import net.raphimc.viabedrock.api.BedrockProtocolVersion;
|
|||||||
import net.raphimc.viabedrock.protocol.storage.AuthChainData;
|
import net.raphimc.viabedrock.protocol.storage.AuthChainData;
|
||||||
import net.raphimc.viaproxy.ViaProxy;
|
import net.raphimc.viaproxy.ViaProxy;
|
||||||
import net.raphimc.viaproxy.plugins.events.FillPlayerDataEvent;
|
import net.raphimc.viaproxy.plugins.events.FillPlayerDataEvent;
|
||||||
|
import net.raphimc.viaproxy.plugins.events.JoinServerRequestEvent;
|
||||||
import net.raphimc.viaproxy.protocoltranslator.viaproxy.ViaProxyConfig;
|
import net.raphimc.viaproxy.protocoltranslator.viaproxy.ViaProxyConfig;
|
||||||
import net.raphimc.viaproxy.proxy.packethandler.OpenAuthModPacketHandler;
|
import net.raphimc.viaproxy.proxy.packethandler.OpenAuthModPacketHandler;
|
||||||
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||||
|
import net.raphimc.viaproxy.proxy.util.CloseAndReturn;
|
||||||
import net.raphimc.viaproxy.saves.impl.accounts.Account;
|
import net.raphimc.viaproxy.saves.impl.accounts.Account;
|
||||||
import net.raphimc.viaproxy.saves.impl.accounts.BedrockAccount;
|
import net.raphimc.viaproxy.saves.impl.accounts.BedrockAccount;
|
||||||
import net.raphimc.viaproxy.saves.impl.accounts.MicrosoftAccount;
|
import net.raphimc.viaproxy.saves.impl.accounts.MicrosoftAccount;
|
||||||
@ -94,6 +96,8 @@ public class ExternalInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ViaProxy.EVENT_MANAGER.call(new FillPlayerDataEvent(proxyConnection));
|
ViaProxy.EVENT_MANAGER.call(new FillPlayerDataEvent(proxyConnection));
|
||||||
|
} catch (CloseAndReturn e) {
|
||||||
|
throw e;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Logger.LOGGER.error("Failed to fill player data", e);
|
Logger.LOGGER.error("Failed to fill player data", e);
|
||||||
proxyConnection.kickClient("§cFailed to fill player data. This might be caused by outdated account tokens or rate limits. Wait a couple of seconds and try again. If the problem persists, remove and re-add your account.");
|
proxyConnection.kickClient("§cFailed to fill player data. This might be caused by outdated account tokens or rate limits. Wait a couple of seconds and try again. If the problem persists, remove and re-add your account.");
|
||||||
@ -103,24 +107,31 @@ public class ExternalInterface {
|
|||||||
proxyConnection.getLoginHelloPacket().uuid = proxyConnection.getGameProfile().getId();
|
proxyConnection.getLoginHelloPacket().uuid = proxyConnection.getGameProfile().getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void joinServer(final String serverIdHash, final ProxyConnection proxyConnection) throws InterruptedException, ExecutionException {
|
public static void joinServer(final String serverIdHash, final ProxyConnection proxyConnection) {
|
||||||
Logger.u_info("auth", proxyConnection, "Trying to join online mode server");
|
Logger.u_info("auth", proxyConnection, "Trying to join online mode server");
|
||||||
if (ViaProxy.getConfig().getAuthMethod() == ViaProxyConfig.AuthMethod.OPENAUTHMOD) {
|
try {
|
||||||
try {
|
if (ViaProxy.getConfig().getAuthMethod() == ViaProxyConfig.AuthMethod.OPENAUTHMOD) {
|
||||||
final ByteBuf response = proxyConnection.getPacketHandler(OpenAuthModPacketHandler.class).sendCustomPayload(OpenAuthModConstants.JOIN_CHANNEL, PacketTypes.writeString(Unpooled.buffer(), serverIdHash)).get(6, TimeUnit.SECONDS);
|
try {
|
||||||
if (response == null) throw new TimeoutException();
|
final ByteBuf response = proxyConnection.getPacketHandler(OpenAuthModPacketHandler.class).sendCustomPayload(OpenAuthModConstants.JOIN_CHANNEL, PacketTypes.writeString(Unpooled.buffer(), serverIdHash)).get(6, TimeUnit.SECONDS);
|
||||||
if (response.isReadable() && !response.readBoolean()) throw new TimeoutException();
|
if (response == null) throw new TimeoutException();
|
||||||
} catch (TimeoutException e) {
|
if (response.isReadable() && !response.readBoolean()) throw new TimeoutException();
|
||||||
proxyConnection.kickClient("§cAuthentication cancelled! You need to install OpenAuthMod in order to join this server.");
|
} catch (TimeoutException e) {
|
||||||
|
proxyConnection.kickClient("§cAuthentication cancelled! You need to install OpenAuthMod in order to join this server.");
|
||||||
|
}
|
||||||
|
} else if (proxyConnection.getUserOptions().account() instanceof MicrosoftAccount microsoftAccount) {
|
||||||
|
try {
|
||||||
|
AuthLibServices.SESSION_SERVICE.joinServer(microsoftAccount.getGameProfile(), microsoftAccount.getMcProfile().getMcToken().getAccessToken(), serverIdHash);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
proxyConnection.kickClient("§cFailed to authenticate with Mojang servers! Please try again in a couple of seconds.");
|
||||||
|
}
|
||||||
|
} else if (!ViaProxy.EVENT_MANAGER.call(new JoinServerRequestEvent(proxyConnection, serverIdHash)).isCancelled()) {
|
||||||
|
proxyConnection.kickClient("§cThis server is in online mode and requires a valid authentication mode.");
|
||||||
}
|
}
|
||||||
} else if (proxyConnection.getUserOptions().account() instanceof MicrosoftAccount microsoftAccount) {
|
} catch (CloseAndReturn e) {
|
||||||
try {
|
throw e;
|
||||||
AuthLibServices.SESSION_SERVICE.joinServer(microsoftAccount.getGameProfile(), microsoftAccount.getMcProfile().getMcToken().getAccessToken(), serverIdHash);
|
} catch (Throwable e) {
|
||||||
} catch (Throwable e) {
|
Logger.LOGGER.error("Failed to join online mode server", e);
|
||||||
proxyConnection.kickClient("§cFailed to authenticate with Mojang servers! Please try again in a couple of seconds.");
|
proxyConnection.kickClient("§cFailed to join online mode server. See console for more information.");
|
||||||
}
|
|
||||||
} else {
|
|
||||||
proxyConnection.kickClient("§cThis server is in online mode and requires a valid authentication mode.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user