Search in sources :

Example 1 with ReflectedClass

use of org.dragonet.common.utilities.ReflectedClass 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)

Aggregations

List (java.util.List)1 EventHandler (net.md_5.bungee.event.EventHandler)1 LoginChainDecoder (org.dragonet.common.utilities.LoginChainDecoder)1 ReflectedClass (org.dragonet.common.utilities.ReflectedClass)1