Esempio n. 1
0
    private void SendUpdateViewPosition(IMinecraftUser user)
    {
        // TODO: get chunk position according to current user's position.
        using var packet = new UpdateViewPositionPacket(0, 0);

        user.Send(packet);
    }
Esempio n. 2
0
    private void SendJoinGame(IMinecraftUser user)
    {
        using var joinPacket = new JoinGamePacket();

        joinPacket.WriteInt32(user.Player.EntityId);                  // EntityID
        joinPacket.WriteBoolean(_gameConfiguration.Value.IsHardcore); // Is hardcore
        joinPacket.WriteByte((byte)_gameConfiguration.Value.Mode);    // GameMode
        joinPacket.WriteSByte((sbyte)ServerGameModeType.Survival);    // Previous game mode

        var worldList = new[] { "minecraft:world" };

        joinPacket.WriteVarInt32(worldList.Length); // World count
        foreach (string world in worldList)
        {
            joinPacket.WriteString(world);
        }

        WriteDimensionsAndBiomes(_registry.Dimensions, _registry.Biomes, joinPacket);

        Dimension currentDimension = _registry.Dimensions.First();

        WriteDimension(currentDimension, joinPacket);
        joinPacket.WriteString(currentDimension.Name);                                                                                                                    // World name identifier

        joinPacket.WriteInt64(_gameConfiguration.Value.Seed);                                                                                                             // Seed
        joinPacket.WriteVarInt32((int)_serverConfiguration.Value.MaxPlayers);                                                                                             // Max players
        joinPacket.WriteVarInt32(Math.Clamp(_gameConfiguration.Value.RenderingDistance, RedstoneContants.MinimumRenderDistance, RedstoneContants.MaximumRenderDistance)); // Render distance (2-32 chunks)
        joinPacket.WriteBoolean(_serverConfiguration.Value.ReducedDebugInfo);                                                                                             // Reduced debug info
        joinPacket.WriteBoolean(_gameConfiguration.Value.DisplayRespawnScreen);                                                                                           // Respawn screen
        joinPacket.WriteBoolean(_serverConfiguration.Value.Debug);                                                                                                        // Is debug
        joinPacket.WriteBoolean(_serverConfiguration.Value.FlatTerrain);                                                                                                  // is flat terrain

        user.Send(joinPacket);
    }
Esempio n. 3
0
    public void OnPing(IMinecraftUser user, IMinecraftPacket packet)
    {
        var pingPacket = new StatusPingPacket(packet);

        using var pongPacket = new StatusPongPacket(pingPacket.Payload);
        user.Send(pongPacket);
    }
Esempio n. 4
0
    private void SendServerBrand(IMinecraftUser user)
    {
        using var serverBrandPacket = new PluginMessagePacket("minecraft:brand");

        serverBrandPacket.WriteString(_serverConfiguration.Value.Name);

        user.Send(serverBrandPacket);
    }
Esempio n. 5
0
    private void SendLoginSucess(IMinecraftUser user)
    {
        using var p = new MinecraftPacket(ClientLoginPacketType.LoginSuccess);

        p.WriteUUID(user.Id);
        p.WriteString(user.Username);

        user.Send(p);
    }
Esempio n. 6
0
    private void SendChunkData(IMinecraftUser user)
    {
        IChunk chunk = _worldManager.Overworld.GetRegion(0, 0).GetChunk(0, 0);

        chunk.GenerateHeightMap();

        // Temporary
        _worldManager.Overworld.AddPlayer(user.Player);

        using var packet = new ChunkDataPacket(chunk, serializeFullChunk: true);
        user.Send(packet);
    }
Esempio n. 7
0
    private void SendPlayerPositionAndLook(IMinecraftUser user, Position position)
    {
        using var packet = new PlayerPositionAndLookPacket();

        packet.WriteDouble(position.X); // x
        packet.WriteDouble(position.Y); // y
        packet.WriteDouble(position.Z); // z
        packet.WriteSingle(0);          // yaw
        packet.WriteSingle(0);          // pitch
        packet.WriteByte(0);
        //packet.WriteByte(0x01 | 0x02 | 0x04); // position flags (x|y|z)
        packet.WriteVarInt32(0); // teleport id

        user.Send(packet);
    }
Esempio n. 8
0
    private void SendSpawnPosition(IMinecraftUser user, Position position)
    {
        using var packet = new SpawnPositionPacket(position);

        user.Send(packet);
    }
Esempio n. 9
0
    private void SendPlayerInfo(IMinecraftUser user, PlayerInfoActionType actionType)
    {
        using var packet = new PlayerInfoPacket(actionType, _server.ConnectedPlayers.Select(x => x.Player));

        user.Send(packet);
    }
Esempio n. 10
0
    public void OnStatusRequest(IMinecraftUser user, IMinecraftPacket _)
    {
        using var responsePacket = new StatusResponsePacket(_server.GetServerStatus());

        user.Send(responsePacket);
    }
Esempio n. 11
0
 public override void SendPacket(IMinecraftPacket packet) => _user.Send(packet);