Search in sources :

Example 1 with InitialHandler

use of net.md_5.bungee.connection.InitialHandler in project DragonProxy by DragonetMC.

the class DPAddonBungee method onPlayerPreLogin.

@EventHandler(priority = EventPriority.LOW)
public void onPlayerPreLogin(PreLoginEvent event) {
    if (ProxyServer.getInstance().getConfig().isOnlineMode()) {
        event.registerIntent(this);
        ProxyServer.getInstance().getScheduler().runAsync(this, new Runnable() {

            @Override
            public void run() {
                String extraDataInHandshake = ((InitialHandler) event.getConnection()).getExtraDataInHandshake();
                List<String> bypassIPs = config.getConfiguration().getStringList("auth_bypass_ip");
                if (!bypassIPs.isEmpty() && bypassIPs.contains(event.getConnection().getAddress().getHostString())) {
                    // check if IP
                    String[] xboxliveProfileParts = extraDataInHandshake.split("\0");
                    if (xboxliveProfileParts.length == 2) {
                        LoginChainDecoder decoder = new LoginChainDecoder(xboxliveProfileParts[1].getBytes(), null);
                        try {
                            // verify login chain, extract players UUID and name
                            decoder.decode();
                        } catch (NullPointerException ex) {
                        }
                        if (decoder.isLoginVerified()) {
                            ReflectedClass initialHandler = new ReflectedClass(event.getConnection());
                            initialHandler.setField("name", decoder.username);
                            initialHandler.setField("uniqueId", decoder.clientUniqueId);
                            event.getConnection().setOnlineMode(false);
                            getLogger().info("Bedrock player " + decoder.username + " uuid : " + decoder.clientUniqueId + " injected in InitialHandler !");
                            bedrockPlayers.add(event.getConnection().getUniqueId());
                        } else {
                            getLogger().info("Bedrock player Fail to verify XBox Identity " + decoder.username);
                            event.getConnection().disconnect(TextComponent.fromLegacyText("Fail to verify XBox Identity, please login to XboxLive and retry."));
                        }
                    }
                }
                event.completeIntent(instance);
            }
        });
    }
}
Also used : LoginChainDecoder(org.dragonet.common.utilities.LoginChainDecoder) ReflectedClass(org.dragonet.common.utilities.ReflectedClass) List(java.util.List) EventHandler(net.md_5.bungee.event.EventHandler)

Example 2 with InitialHandler

use of net.md_5.bungee.connection.InitialHandler in project ChangeSkin by games647.

the class BungeeSkinAPI method applySkin.

@Override
public void applySkin(ProxiedPlayer player, SkinModel targetSkin) {
    plugin.getLog().debug("Applying skin for {}", player.getName());
    InitialHandler initialHandler = (InitialHandler) player.getPendingConnection();
    LoginResult loginProfile = initialHandler.getLoginProfile();
    // this is null in offline mode
    if (loginProfile == null) {
        String mojangUUID = UUIDTypeAdapter.toMojangId(player.getUniqueId());
        if (profileSetter != null) {
            try {
                LoginResult loginResult = new LoginResult(mojangUUID, player.getName(), toProperties(targetSkin));
                profileSetter.invokeExact(initialHandler, loginResult);
            } catch (Error error) {
                // rethrow errors we shouldn't silence them like OutOfMemoryError
                throw error;
            } catch (Throwable throwable) {
                plugin.getLog().error("Error applying skin: {} for {}", targetSkin, player, throwable);
            }
        }
    } else {
        applyProperties(loginProfile, targetSkin);
    }
    // send plugin channel update request
    plugin.sendPluginMessage(player.getServer(), new SkinUpdateMessage(player.getName()));
}
Also used : SkinUpdateMessage(com.github.games647.changeskin.core.message.SkinUpdateMessage) LoginResult(net.md_5.bungee.connection.LoginResult) InitialHandler(net.md_5.bungee.connection.InitialHandler)

Example 3 with InitialHandler

use of net.md_5.bungee.connection.InitialHandler in project SkinsRestorerX by DoNotSpamPls.

the class SkinApplier method applySkin.

public static void applySkin(final ProxiedPlayer p) {
    ProxyServer.getInstance().getScheduler().runAsync(SkinsRestorer.getInstance(), () -> {
        try {
            Property textures = (Property) SkinStorage.getOrCreateSkinForPlayer(p.getName());
            InitialHandler handler = (InitialHandler) p.getPendingConnection();
            if (handler.isOnlineMode()) {
                sendUpdateRequest(p, textures);
                return;
            }
            LoginResult profile;
            try {
                // NEW BUNGEECORD
                profile = (net.md_5.bungee.connection.LoginResult) ReflectionUtil.invokeConstructor(LoginResult, new Class<?>[] { String.class, String.class, Property[].class }, p.getUniqueId().toString(), p.getName(), new Property[] { textures });
            } catch (Exception e) {
                // FALL BACK TO OLD
                profile = (net.md_5.bungee.connection.LoginResult) ReflectionUtil.invokeConstructor(LoginResult, new Class<?>[] { String.class, Property[].class }, p.getUniqueId().toString(), new Property[] { textures });
            }
            Property[] present = profile.getProperties();
            Property[] newprops = new Property[present.length + 1];
            System.arraycopy(present, 0, newprops, 0, present.length);
            newprops[present.length] = textures;
            profile.getProperties()[0].setName(newprops[0].getName());
            profile.getProperties()[0].setValue(newprops[0].getValue());
            profile.getProperties()[0].setSignature(newprops[0].getSignature());
            ReflectionUtil.setObject(InitialHandler.class, handler, "loginProfile", profile);
            if (SkinsRestorer.getInstance().isMultiBungee())
                sendUpdateRequest(p, textures);
            else
                sendUpdateRequest(p, null);
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
}
Also used : LoginResult(net.md_5.bungee.connection.LoginResult) Property(net.md_5.bungee.connection.LoginResult.Property) IOException(java.io.IOException) InitialHandler(net.md_5.bungee.connection.InitialHandler)

Example 4 with InitialHandler

use of net.md_5.bungee.connection.InitialHandler in project SkinsRestorerX by DoNotSpamPls.

the class AdminCommands method execute.

@SuppressWarnings("deprecation")
public void execute(final CommandSender sender, final String[] args) {
    if (sender.hasPermission("skinsrestorer.cmds")) {
        if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
            Locale.load();
            Config.load(SkinsRestorer.getInstance().getResourceAsStream("config.yml"));
            sender.sendMessage(new TextComponent(Locale.RELOAD));
        } else if (args.length == 2 && args[0].equalsIgnoreCase("drop")) {
            StringBuilder sb = new StringBuilder();
            SkinStorage.removeSkinData(sb.toString());
            sender.sendMessage(Locale.SKIN_DATA_DROPPED.replace("%player", sb.toString()));
        } else if (args.length > 2 && args[0].equalsIgnoreCase("set")) {
            final String skin = args[2];
            ProxiedPlayer player = ProxyServer.getInstance().getPlayer(args[1]);
            if (player == null)
                for (ProxiedPlayer pl : ProxyServer.getInstance().getPlayers()) if (pl.getName().startsWith(args[1])) {
                    player = pl;
                    break;
                }
            if (player == null) {
                sender.sendMessage(Locale.NOT_ONLINE);
                return;
            }
            final ProxiedPlayer p = player;
            ProxyServer.getInstance().getScheduler().runAsync(SkinsRestorer.getInstance(), () -> {
                try {
                    MojangAPI.getUUID(skin);
                    SkinStorage.setPlayerSkin(p.getName(), skin);
                    SkinApplier.applySkin(p);
                    sender.sendMessage(Locale.SKIN_CHANGE_SUCCESS);
                } catch (MojangAPI.SkinRequestException e) {
                    sender.sendMessage(e.getReason());
                }
            });
        } else if (args.length == 1 && args[0].equalsIgnoreCase("config")) {
            sender.sendMessage("§e[§2SkinsRestorer§e] §2/sr config has been removed from SkinsRestorer. Farewell!");
        } else if (args.length > 0 && args[0].equalsIgnoreCase("props")) {
            ProxiedPlayer p;
            if (args.length == 1) {
                if (!(sender instanceof ProxiedPlayer)) {
                    sender.sendMessage(Locale.NOT_PLAYER);
                }
                p = (ProxiedPlayer) sender;
            } else {
                StringBuilder name = new StringBuilder();
                for (int i = 1; i < args.length; i++) if (args.length == 2)
                    name.append(args[i]);
                else if (i + 1 == args.length)
                    name.append(args[i]);
                else
                    name.append(args[i]).append(" ");
                p = ProxyServer.getInstance().getPlayer(name.toString());
                if (p == null) {
                    sender.sendMessage(Locale.NOT_ONLINE);
                    return;
                }
            }
            InitialHandler h = (InitialHandler) p.getPendingConnection();
            LoginResult.Property prop = h.getLoginProfile().getProperties()[0];
            if (prop == null) {
                sender.sendMessage(Locale.NO_SKIN_DATA);
                return;
            }
            CommandSender cons = ProxyServer.getInstance().getConsole();
            cons.sendMessage("\n§aName: §8" + prop.getName());
            cons.sendMessage("\n§aValue : §8" + prop.getValue());
            cons.sendMessage("\n§aSignature : §8" + prop.getSignature());
            byte[] decoded = Base64.getDecoder().decode(prop.getValue());
            cons.sendMessage("\n§aValue Decoded: §e" + Arrays.toString(decoded));
            sender.sendMessage("\n§e" + Arrays.toString(decoded));
            sender.sendMessage("§cMore info in console!");
        } else {
            if (!Locale.SR_LINE.isEmpty())
                sender.sendMessage(Locale.SR_LINE);
            sender.sendMessage(Locale.HELP_ADMIN.replace("%ver%", SkinsRestorer.getInstance().getVersion()));
            if (!Locale.SR_LINE.isEmpty())
                sender.sendMessage(Locale.SR_LINE);
        }
    } else {
        sender.sendMessage(Locale.PLAYER_HAS_NO_PERMISSION);
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) LoginResult(net.md_5.bungee.connection.LoginResult) MojangAPI(skinsrestorer.shared.utils.MojangAPI) CommandSender(net.md_5.bungee.api.CommandSender) InitialHandler(net.md_5.bungee.connection.InitialHandler)

Aggregations

InitialHandler (net.md_5.bungee.connection.InitialHandler)3 LoginResult (net.md_5.bungee.connection.LoginResult)3 SkinUpdateMessage (com.github.games647.changeskin.core.message.SkinUpdateMessage)1 IOException (java.io.IOException)1 List (java.util.List)1 CommandSender (net.md_5.bungee.api.CommandSender)1 TextComponent (net.md_5.bungee.api.chat.TextComponent)1 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)1 Property (net.md_5.bungee.connection.LoginResult.Property)1 EventHandler (net.md_5.bungee.event.EventHandler)1 LoginChainDecoder (org.dragonet.common.utilities.LoginChainDecoder)1 ReflectedClass (org.dragonet.common.utilities.ReflectedClass)1 MojangAPI (skinsrestorer.shared.utils.MojangAPI)1