Build AsminVoicechat / prepare-release (push) Successful in 14s
Build AsminVoicechat / build-and-test (17) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (18) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (19) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (20) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (21) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (22) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (23) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (24) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (25) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (26) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (27-ea) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (16) (push) Canceled after 38s
168 lines
6.8 KiB
Java
168 lines
6.8 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* org.bukkit.Bukkit
|
|
* org.bukkit.entity.Player
|
|
* org.bukkit.event.EventHandler
|
|
* org.bukkit.event.Listener
|
|
* org.bukkit.event.player.PlayerJoinEvent
|
|
* org.bukkit.event.player.PlayerQuitEvent
|
|
*/
|
|
package de.maxhenkel.voicechat.voice.server;
|
|
|
|
import de.maxhenkel.voicechat.Voicechat;
|
|
import de.maxhenkel.voicechat.compatibility.PlayerHideEvent;
|
|
import de.maxhenkel.voicechat.compatibility.PlayerShowEvent;
|
|
import de.maxhenkel.voicechat.net.NetManager;
|
|
import de.maxhenkel.voicechat.net.PacketRateLimiter;
|
|
import de.maxhenkel.voicechat.net.RequestSecretPacket;
|
|
import de.maxhenkel.voicechat.net.SecretPacket;
|
|
import de.maxhenkel.voicechat.plugins.PluginManager;
|
|
import de.maxhenkel.voicechat.voice.common.Secret;
|
|
import de.maxhenkel.voicechat.voice.server.Server;
|
|
import java.util.Map;
|
|
import java.util.UUID;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.Listener;
|
|
import org.bukkit.event.player.PlayerJoinEvent;
|
|
import org.bukkit.event.player.PlayerQuitEvent;
|
|
|
|
public class ServerVoiceEvents
|
|
implements Listener {
|
|
private static final int LEGACY_COMPATIBILITY_VERSION = 18;
|
|
private static final int CURRENT_COMPATIBILITY_VERSION = 20;
|
|
private final Map<UUID, Integer> clientCompatibilities = new ConcurrentHashMap<UUID, Integer>();
|
|
private final PacketRateLimiter rateLimiter;
|
|
private Server server;
|
|
|
|
public ServerVoiceEvents() {
|
|
this.rateLimiter = new PacketRateLimiter(Voicechat.SERVER_CONFIG.tcpRateLimit.get());
|
|
}
|
|
|
|
public void init() {
|
|
if (this.server != null) {
|
|
return;
|
|
}
|
|
if (!Bukkit.getOnlineMode()) {
|
|
Voicechat.LOGGER.warn("Running in offline mode - Voice chat encryption is not secure!", new Object[0]);
|
|
}
|
|
Voicechat.compatibility.registerPlayerHideEvent(this::onPlayerHide);
|
|
Voicechat.compatibility.registerPlayerShowEvent(this::onPlayerShow);
|
|
this.server = new Server();
|
|
this.server.start();
|
|
PluginManager.instance().onServerStarted();
|
|
}
|
|
|
|
public void onRequestSecretPacket(Player player, RequestSecretPacket requestSecretPacket) {
|
|
UUID uUID;
|
|
int n = requestSecretPacket.getCompatibilityVersion();
|
|
Voicechat.LOGGER.info("Received secret request of {} ({})", player.getName(), n);
|
|
try {
|
|
uUID = player.getUniqueId();
|
|
}
|
|
catch (UnsupportedOperationException unsupportedOperationException) {
|
|
player.kickPlayer("Tried to authenticate voice chat while still connecting");
|
|
Voicechat.LOGGER.warn("{} tried to authenticate voice chat while still connecting", player.getName());
|
|
return;
|
|
}
|
|
this.clientCompatibilities.put(uUID, n);
|
|
if (!ServerVoiceEvents.isSupportedCompatibilityVersion(n)) {
|
|
Voicechat.LOGGER.warn("Connected client {} has incompatible voice chat version (server={}, client={})", player.getName(), Voicechat.COMPATIBILITY_VERSION, n);
|
|
ServerVoiceEvents.sendIncompatibleMessage(player, n);
|
|
return;
|
|
}
|
|
this.initializePlayerConnection(player);
|
|
}
|
|
|
|
private static boolean isSupportedCompatibilityVersion(int n) {
|
|
return n == 18 || n == 20;
|
|
}
|
|
|
|
public boolean isCompatible(Player player) {
|
|
return this.isCompatible(player.getUniqueId());
|
|
}
|
|
|
|
public boolean isCompatible(UUID uUID) {
|
|
return ServerVoiceEvents.isSupportedCompatibilityVersion(this.clientCompatibilities.getOrDefault(uUID, -1));
|
|
}
|
|
|
|
public static void sendIncompatibleMessage(Player player, int n) {
|
|
if (n <= 6) {
|
|
player.sendMessage(String.format(Voicechat.TRANSLATIONS.voicechatNotCompatibleMessage.get(), "2.6.x", "Simple Voice Chat"));
|
|
} else {
|
|
Voicechat.compatibility.sendIncompatibleMessage(player, "2.6.x", "Simple Voice Chat");
|
|
}
|
|
}
|
|
|
|
public void initializePlayerConnection(Player player) {
|
|
if (this.server == null) {
|
|
return;
|
|
}
|
|
UUID uUID = player.getUniqueId();
|
|
this.server.getPlayerStateManager().onPlayerCompatibilityCheckSucceeded(player);
|
|
this.server.getCategoryManager().onPlayerCompatibilityCheckSucceeded(player);
|
|
this.server.getGroupManager().onPlayerCompatibilityCheckSucceeded(player);
|
|
Secret secret = this.server.generateNewSecret(uUID);
|
|
if (secret == null) {
|
|
Voicechat.LOGGER.warn("Player already requested secret - ignoring", new Object[0]);
|
|
return;
|
|
}
|
|
secret.setLegacyProtocol(this.clientCompatibilities.getOrDefault(uUID, -1) == 18);
|
|
String string = PluginManager.instance().getVoiceHost(player, Voicechat.SERVER_CONFIG.voiceHost.get());
|
|
NetManager.sendToClient(player, new SecretPacket(player, secret, this.server.getPort(), Voicechat.SERVER_CONFIG, string));
|
|
Voicechat.LOGGER.info("Sent secret to {}", player.getName());
|
|
}
|
|
|
|
@EventHandler
|
|
public void onPlayerJoin(PlayerJoinEvent playerJoinEvent) {
|
|
this.server.getPlayerStateManager().onPlayerJoin(playerJoinEvent);
|
|
if (!Voicechat.SERVER_CONFIG.forceVoiceChat.get().booleanValue()) {
|
|
return;
|
|
}
|
|
Player player = playerJoinEvent.getPlayer();
|
|
Voicechat.compatibility.runTaskLater(() -> {
|
|
if (!player.isOnline()) {
|
|
return;
|
|
}
|
|
if (!this.isCompatible(player)) {
|
|
player.kickPlayer(String.format(Voicechat.TRANSLATIONS.forceVoicechatKickMessage.get(), "Simple Voice Chat", Voicechat.INSTANCE.getDescription().getVersion()));
|
|
}
|
|
}, (long)Voicechat.SERVER_CONFIG.loginTimeout.get().intValue() / 50L);
|
|
}
|
|
|
|
@EventHandler
|
|
public void onPlayerQuit(PlayerQuitEvent playerQuitEvent) {
|
|
this.server.getPlayerStateManager().onPlayerQuit(playerQuitEvent);
|
|
this.server.getGroupManager().onPlayerQuit(playerQuitEvent);
|
|
UUID uUID = playerQuitEvent.getPlayer().getUniqueId();
|
|
this.clientCompatibilities.remove(uUID);
|
|
this.rateLimiter.onPlayerLoggedOut(playerQuitEvent.getPlayer());
|
|
if (this.server == null) {
|
|
return;
|
|
}
|
|
this.server.disconnectClient(uUID);
|
|
Voicechat.LOGGER.info("Disconnecting client {}", playerQuitEvent.getPlayer().getName());
|
|
}
|
|
|
|
public void onPlayerHide(PlayerHideEvent playerHideEvent) {
|
|
this.server.getPlayerStateManager().onPlayerHide(playerHideEvent);
|
|
}
|
|
|
|
public void onPlayerShow(PlayerShowEvent playerShowEvent) {
|
|
this.server.getPlayerStateManager().onPlayerShow(playerShowEvent);
|
|
}
|
|
|
|
public PacketRateLimiter getRateLimiter() {
|
|
return this.rateLimiter;
|
|
}
|
|
|
|
public Server getServer() {
|
|
return this.server;
|
|
}
|
|
}
|
|
|