Search in sources :

Example 1 with PlayStatusPacket

use of org.dragonet.protocol.packets.PlayStatusPacket in project DragonProxy by DragonetMC.

the class UpstreamSession method onLogin.

public void onLogin(LoginPacket packet) {
    if (username != null) {
        disconnect("Already logged in, this must be an error! ");
        return;
    }
    getDataCache().put(CacheKey.PACKET_LOGIN_PACKET, packet);
    PlayStatusPacket status = new PlayStatusPacket();
    proxy.getLogger().debug("CLIENT PROTOCOL = " + packet.protocol);
    if (packet.protocol != ProtocolInfo.CURRENT_PROTOCOL) {
        status.status = PlayStatusPacket.LOGIN_FAILED_CLIENT;
        sendPacket(status, true);
        disconnect(proxy.getLang().get(Lang.MESSAGE_UNSUPPORTED_CLIENT));
        return;
    }
    // Get the profile and read out the username!
    profile = packet.decoded;
    // Verify the integrity of the LoginPacket
    if (proxy.getConfig().authenticate_players && !packet.decoded.isLoginVerified()) {
        status.status = PlayStatusPacket.LOGIN_FAILED_INVALID_TENANT;
        sendPacket(status, true);
        disconnect(proxy.getLang().get(Lang.LOGIN_VERIFY_FAILED));
        return;
    }
    status.status = PlayStatusPacket.LOGIN_SUCCESS;
    sendPacket(status, true);
    this.username = profile.username;
    // Okay @dktapps ;)
    sendPacket(new ResourcePacksInfoPacket(), true);
    PlayerLoginEvent loginEvent = new PlayerLoginEvent(this);
    proxy.getEventManager().callEvent(loginEvent);
// now wait for response
}
Also used : PlayStatusPacket(org.dragonet.protocol.packets.PlayStatusPacket) PlayerLoginEvent(org.dragonet.proxy.events.defaults.player.PlayerLoginEvent) ResourcePacksInfoPacket(org.dragonet.protocol.packets.ResourcePacksInfoPacket)

Example 2 with PlayStatusPacket

use of org.dragonet.protocol.packets.PlayStatusPacket in project DragonProxy by DragonetMC.

the class UpstreamSession method setSpawned.

public void setSpawned() {
    if (!spawned) {
        spawned = true;
        PlayStatusPacket play = new PlayStatusPacket(PlayStatusPacket.PLAYER_SPAWN);
        sendPacket(play, true);
    }
}
Also used : PlayStatusPacket(org.dragonet.protocol.packets.PlayStatusPacket)

Example 3 with PlayStatusPacket

use of org.dragonet.protocol.packets.PlayStatusPacket in project DragonProxy by DragonetMC.

the class PCRespawnPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerRespawnPacket packet) {
    CachedEntity entity = session.getEntityCache().getClientEntity();
    if (entity.dimention != packet.getDimension()) {
        // the player have changed dimention
        DragonProxy.getInstance().getLogger().info(session.getUsername() + " change dim " + entity.dimention + " to " + packet.getDimension());
        // entity.dimention = packet.getDimension();
        // purge and despawn
        session.getEntityCache().reset(true);
        session.getChunkCache().purge();
        // send new world gamemode
        SetPlayerGameTypePacket pkgm = new SetPlayerGameTypePacket();
        pkgm.gamemode = packet.getGameMode() == GameMode.CREATIVE ? 1 : 0;
        session.sendPacket(pkgm);
        // send new adventure settings
        AdventureSettingsPacket adv = new AdventureSettingsPacket();
        adv.setFlag(AdventureSettingsPacket.WORLD_IMMUTABLE, packet.getGameMode().equals(GameMode.ADVENTURE));
        adv.setFlag(AdventureSettingsPacket.ALLOW_FLIGHT, packet.getGameMode().equals(GameMode.CREATIVE) || packet.getGameMode().equals(GameMode.SPECTATOR));
        adv.setFlag(AdventureSettingsPacket.NO_CLIP, packet.getGameMode().equals(GameMode.SPECTATOR));
        adv.setFlag(AdventureSettingsPacket.WORLD_BUILDER, !packet.getGameMode().equals(GameMode.SPECTATOR) || !packet.getGameMode().equals(GameMode.ADVENTURE));
        adv.setFlag(AdventureSettingsPacket.FLYING, packet.getGameMode().equals(GameMode.SPECTATOR));
        adv.setFlag(AdventureSettingsPacket.MUTED, false);
        adv.eid = entity.proxyEid;
        adv.commandsPermission = AdventureSettingsPacket.PERMISSION_NORMAL;
        adv.playerPermission = AdventureSettingsPacket.LEVEL_PERMISSION_MEMBER;
        session.sendPacket(adv);
        // send entity attributes
        UpdateAttributesPacket attr = new UpdateAttributesPacket();
        attr.rtid = entity.proxyEid;
        if (entity.attributes.isEmpty()) {
            attr.entries = new ArrayList();
            attr.entries.addAll(PEEntityAttribute.getDefault());
        } else
            attr.entries = entity.attributes.values();
        session.sendPacket(attr);
        // set world difficulty
        session.sendPacket(new SetDifficultyPacket(packet.getDifficulty()));
        if (packet.getGameMode().equals(GameMode.CREATIVE))
            session.sendCreativeInventory();
        return null;
    } else
        return new PEPacket[] { new PlayStatusPacket(PlayStatusPacket.PLAYER_SPAWN) };
}
Also used : SetPlayerGameTypePacket(org.dragonet.protocol.packets.SetPlayerGameTypePacket) SetDifficultyPacket(org.dragonet.protocol.packets.SetDifficultyPacket) PlayStatusPacket(org.dragonet.protocol.packets.PlayStatusPacket) AdventureSettingsPacket(org.dragonet.protocol.packets.AdventureSettingsPacket) UpdateAttributesPacket(org.dragonet.protocol.packets.UpdateAttributesPacket) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) ArrayList(java.util.ArrayList)

Example 4 with PlayStatusPacket

use of org.dragonet.protocol.packets.PlayStatusPacket in project DragonProxy by DragonetMC.

the class UpstreamSession method postLogin.

public void postLogin() {
    sendPacket(new ResourcePackStackPacket(), true);
    loggedIn = true;
    proxy.getLogger().info(proxy.getLang().get(Lang.MESSAGE_CLIENT_CONNECTED, username, remoteAddress));
    PlayerAuthenticationEvent authEvent = new PlayerAuthenticationEvent(this);
    proxy.getEventManager().callEvent(authEvent);
    if (authEvent.isCancelled​())
        return;
    if (proxy.getAuthMode().equals("online")) {
        proxy.getLogger().debug("Login online mode, sending placeholder datas");
        StartGamePacket pkStartGame = new StartGamePacket();
        // well we use 1 now
        pkStartGame.eid = getEntityCache().getClientEntity().proxyEid;
        pkStartGame.rtid = getEntityCache().getClientEntity().proxyEid;
        pkStartGame.dimension = 0;
        pkStartGame.seed = 0;
        pkStartGame.generator = 1;
        pkStartGame.difficulty = Difficulty.PEACEFUL;
        pkStartGame.spawnPosition = new BlockPosition(0, 72, 0);
        pkStartGame.position = new Vector3F(0f, 72f + EntityType.PLAYER.getOffset(), 0f);
        pkStartGame.levelId = "";
        pkStartGame.worldName = "World";
        pkStartGame.defaultPlayerPermission = 2;
        pkStartGame.commandsEnabled = true;
        pkStartGame.premiumWorldTemplateId = "";
        sendPacket(pkStartGame, true);
        SetSpawnPositionPacket pkSpawn = new SetSpawnPositionPacket();
        pkSpawn.position = new BlockPosition(0, 72, 0);
        sendPacket(pkSpawn, true);
        ChunkData data = new ChunkData();
        data.sections = new Section[16];
        for (int cy = 0; cy < 16; cy++) {
            data.sections[cy] = new Section();
            if (cy < 6)
                Arrays.fill(data.sections[cy].blockIds, (byte) 1);
        }
        data.encode();
        sendPacket(new FullChunkDataPacket(0, 0, data.getBuffer()), true);
        sendPacket(new FullChunkDataPacket(0, -1, data.getBuffer()), true);
        sendPacket(new FullChunkDataPacket(-1, 0, data.getBuffer()), true);
        sendPacket(new FullChunkDataPacket(-1, -1, data.getBuffer()), true);
        dataCache.put(CacheKey.AUTHENTICATION_STATE, "online_login_wait");
        PlayStatusPacket pkStat = new PlayStatusPacket();
        pkStat.status = PlayStatusPacket.PLAYER_SPAWN;
        sendPacket(pkStat, true);
        sendChat(proxy.getLang().get(Lang.MESSAGE_LOGIN_PROMPT));
    } else if (proxy.getAuthMode().equals("cls")) {
        // CLS LOGIN!
        if (!CLSAuthenticationService.getInstance().authenticate(this)) {
            if (getDataCache().containsKey("cls_link_server") && getDataCache().containsKey("cls_link_pin")) {
                disconnect("You must link your Mojang account, please visit :\n" + (String) getDataCache().get("cls_link_server") + "\n" + "Your pin code is: " + (String) getDataCache().get("cls_link_pin"));
                return;
            }
            disconnect(proxy.getLang().get(Lang.MESSAGE_SERVER_ERROR, proxy.getLang().get(Lang.ERROR_CLS_UNREACHABLE)));
            proxy.getLogger().severe(proxy.getLang().get(Lang.MESSAGE_SERVER_ERROR, proxy.getLang().get(Lang.ERROR_CLS_UNREACHABLE)).replace("§c", "").replace("§0", ""));
            return;
        }
        AuthenticationService authSvc = new AuthenticationService((String) dataCache.get("mojang_clientToken"));
        authSvc.setUsername((String) dataCache.get("mojang_displayName"));
        authSvc.setAccessToken((String) dataCache.get("mojang_accessToken"));
        try {
            authSvc.login();
            getDataCache().put("mojang_accessToken", authSvc.getAccessToken());
        } catch (RequestException ex) {
            ex.printStackTrace();
            disconnect(proxy.getLang().get(Lang.MESSAGE_SERVER_ERROR, proxy.getLang().get(Lang.ERROR_CLS_ERROR)));
            return;
        }
        username = authSvc.getSelectedProfile().getName();
        CLSAuthenticationService.getInstance().refresh(this, authSvc.getAccessToken());
        protocol = new MinecraftProtocol(authSvc.getSelectedProfile(), authSvc.getAccessToken());
        proxy.getLogger().debug("Initially joining [" + proxy.getConfig().remote_server_addr + "]... ");
        connectToServer(proxy.getConfig().remote_server_addr, proxy.getConfig().remote_server_port);
    } else {
        protocol = new MinecraftProtocol(username);
        proxy.getLogger().debug("Initially joining [" + proxy.getConfig().remote_server_addr + "]... ");
        connectToServer(proxy.getConfig().remote_server_addr, proxy.getConfig().remote_server_port);
    }
}
Also used : ChunkData(org.dragonet.protocol.type.chunk.ChunkData) PlayStatusPacket(org.dragonet.protocol.packets.PlayStatusPacket) BlockPosition(org.dragonet.common.maths.BlockPosition) MinecraftProtocol(com.github.steveice10.mc.protocol.MinecraftProtocol) StartGamePacket(org.dragonet.protocol.packets.StartGamePacket) Section(org.dragonet.protocol.type.chunk.Section) RequestException(com.github.steveice10.mc.auth.exception.request.RequestException) SetSpawnPositionPacket(org.dragonet.protocol.packets.SetSpawnPositionPacket) Vector3F(org.dragonet.common.maths.Vector3F) FullChunkDataPacket(org.dragonet.protocol.packets.FullChunkDataPacket) PlayerAuthenticationEvent(org.dragonet.proxy.events.defaults.player.PlayerAuthenticationEvent) ResourcePackStackPacket(org.dragonet.protocol.packets.ResourcePackStackPacket) AuthenticationService(com.github.steveice10.mc.auth.service.AuthenticationService) CLSAuthenticationService(org.dragonet.proxy.utilities.CLSAuthenticationService)

Aggregations

PlayStatusPacket (org.dragonet.protocol.packets.PlayStatusPacket)4 RequestException (com.github.steveice10.mc.auth.exception.request.RequestException)1 AuthenticationService (com.github.steveice10.mc.auth.service.AuthenticationService)1 MinecraftProtocol (com.github.steveice10.mc.protocol.MinecraftProtocol)1 ArrayList (java.util.ArrayList)1 BlockPosition (org.dragonet.common.maths.BlockPosition)1 Vector3F (org.dragonet.common.maths.Vector3F)1 AdventureSettingsPacket (org.dragonet.protocol.packets.AdventureSettingsPacket)1 FullChunkDataPacket (org.dragonet.protocol.packets.FullChunkDataPacket)1 ResourcePackStackPacket (org.dragonet.protocol.packets.ResourcePackStackPacket)1 ResourcePacksInfoPacket (org.dragonet.protocol.packets.ResourcePacksInfoPacket)1 SetDifficultyPacket (org.dragonet.protocol.packets.SetDifficultyPacket)1 SetPlayerGameTypePacket (org.dragonet.protocol.packets.SetPlayerGameTypePacket)1 SetSpawnPositionPacket (org.dragonet.protocol.packets.SetSpawnPositionPacket)1 StartGamePacket (org.dragonet.protocol.packets.StartGamePacket)1 UpdateAttributesPacket (org.dragonet.protocol.packets.UpdateAttributesPacket)1 ChunkData (org.dragonet.protocol.type.chunk.ChunkData)1 Section (org.dragonet.protocol.type.chunk.Section)1 PlayerAuthenticationEvent (org.dragonet.proxy.events.defaults.player.PlayerAuthenticationEvent)1 PlayerLoginEvent (org.dragonet.proxy.events.defaults.player.PlayerLoginEvent)1