Пример #1
0
        private void ExecutePlayerActionPacket(PlayerActionPacket packet)
        {
            Player player = BeepLiveGame.Map.Players.Find(p => p.Guid == packet.PlayerGuid);

            switch (packet)
            {
            case PlayerJumpPacket jumpPacket:
                player.Velocity += jumpPacket.Direction;
                break;

            case PlayerShotPacket shotPacket:
                var shotConfig = BeepLiveGame.BeepConfig.ShotConfigs[shotPacket.ShotConfigId];
                switch (shotConfig)
                {
                case ClusterShotConfig clusterShotConfig:
                    player.Shoot(clusterShotConfig, shotPacket.Direction).OnExplodeEvent +=
                        clusterShot => TriggerShake(clusterShot.ShotConfig.ExplosionPower / 100, 100);
                    break;

                default:
                    player.Shoot(shotConfig, shotPacket.Direction);
                    break;
                }
                break;

            default:
                HandlePacket(packet);
                break;
            }
        }
Пример #2
0
        public void BroadcastWithoutSecret(PlayerActionPacket packet)
        {
            if (packet == null)
            {
                throw new ArgumentNullException(nameof(packet));
            }

            packet.Secret = default;
            GameServer.Broadcast(packet);
        }
Пример #3
0
        private void AddPacketToDeferredMap(PlayerActionPacket playerAction, AbsoluteEntityCell cell)
        {
            lock (deferredPacketsByAbsoluteCell)
            {
                if (!deferredPacketsByAbsoluteCell.ContainsKey(cell))
                {
                    deferredPacketsByAbsoluteCell.Add(cell, new Queue <Packet>());
                }

                deferredPacketsByAbsoluteCell[cell].Enqueue(playerAction);
            }
        }
Пример #4
0
        private void AddPacketToDeferredMap(PlayerActionPacket playerAction, Int3 batchId)
        {
            lock (deferredPacketsByBatchId)
            {
                if (!deferredPacketsByBatchId.ContainsKey(batchId))
                {
                    deferredPacketsByBatchId.Add(batchId, new Queue <Packet>());
                }

                deferredPacketsByBatchId[batchId].Enqueue(playerAction);
            }
        }
Пример #5
0
        private void AddPacketToDeferredMap(PlayerActionPacket playerAction, Int3 chunk)
        {
            lock (deferredPacketsByChunk)
            {
                if (!deferredPacketsByChunk.ContainsKey(chunk))
                {
                    deferredPacketsByChunk.Add(chunk, new Queue <Packet>());
                }

                deferredPacketsByChunk[chunk].Enqueue(playerAction);
            }
        }
Пример #6
0
        protected override Task OnMessage(MessageEventArgs e)
        {
            using (System.IO.MemoryStream memStream = new System.IO.MemoryStream())
                using (System.IO.BinaryReader reader = new System.IO.BinaryReader(memStream))
                {
                    e.Data.CopyTo(memStream);
                    memStream.Position = 0;

                    PacketType packetType = (PacketType)reader.ReadByte();
                    Packet     packet;

                    switch (packetType)
                    {
                    case PacketType.PlayerAction:
                        packet = PlayerActionPacket.Parse(reader);
                        break;

                    case PacketType.Ping:
                        packet = PingPacket.Parse(reader);
                        break;

                    case PacketType.PlayerUpdate:
                        packet = PlayerUpdatePacket.Parse(reader, this);
                        break;

                    case PacketType.PlayerShoot:
                        packet = PlayerShootPacket.Parse(reader);
                        break;

                    default:
                        return(base.OnMessage(e)); // Packet not recognized. Ignore it.
                    }

                    packet.PacketType = packetType;
                    packet.Handle(this);

                    return(base.OnMessage(e));
                }
        }
Пример #7
0
        private bool PacketWasDeferred(Packet packet)
        {
            if (packet is PlayerActionPacket)
            {
                PlayerActionPacket playerAction = (PlayerActionPacket)packet;

                if (!playerAction.PlayerMustBeInRangeToReceive)
                {
                    return(false);
                }

                Int3 actionBatchId = LargeWorldStreamer.main.GetContainingBatch(playerAction.ActionPosition);

                if (!loadedChunks.HasChunkWithMinDesiredLevelOfDetail(actionBatchId, DESIRED_CHUNK_MIN_LOD_FOR_ACTIONS))
                {
                    Log.Debug("Action was deferred, batch not loaded (with required lod): " + actionBatchId);
                    AddPacketToDeferredMap(playerAction, actionBatchId);
                    return(true);
                }
            }

            return(false);
        }
Пример #8
0
        private bool PacketWasDeferred(Packet packet)
        {
            if (packet is PlayerActionPacket)
            {
                PlayerActionPacket playerAction = (PlayerActionPacket)packet;

                if (!playerAction.PlayerMustBeInRangeToReceive)
                {
                    return(false);
                }

                Int3 actionChunk = loadedChunks.GetChunk(playerAction.ActionPosition);

                if (!loadedChunks.IsLoadedChunk(actionChunk))
                {
                    Console.WriteLine("Action was deferred, chunk not loaded: " + actionChunk);
                    AddPacketToDeferredMap(playerAction, actionChunk);
                    return(true);
                }
            }

            return(false);
        }
Пример #9
0
        private bool PacketWasDeferred(Packet packet)
        {
            if (packet is PlayerActionPacket)
            {
                PlayerActionPacket playerAction = (PlayerActionPacket)packet;

                if (!playerAction.PlayerMustBeInRangeToReceive)
                {
                    return(false);
                }

                AbsoluteEntityCell cell = new AbsoluteEntityCell(playerAction.ActionPosition);

                bool cellLoaded = false;

                for (int level = 0; level <= DESIRED_CELL_MIN_LOD_FOR_ACTIONS; level++)
                {
                    VisibleCell visibleCell = new VisibleCell(cell, level);

                    if (visibleCells.HasVisibleCell(visibleCell))
                    {
                        cellLoaded = true;
                        break;
                    }
                }

                if (!cellLoaded)
                {
                    Log.Debug("Action was deferred, cell not loaded (with required lod): " + cell);
                    AddPacketToDeferredMap(playerAction, cell);
                    return(true);
                }
            }

            return(false);
        }
Пример #10
0
 public bool IsValid(PlayerActionPacket packet) =>
 Players.Find(p =>
              p.PlayerGuid
              == packet.PlayerGuid).Secret
 == packet?.Secret;
Пример #11
0
 public void HandlePlayerActionPacket(PlayerActionPacket packet)
 {
     lock (QueuedPlayerActionPackets) QueuedPlayerActionPackets.Add(packet);
 }
        private void PlayerActionHandle(PlayerActionPacket pk)
        {
            Vector3   pos  = pk.Position;
            BlockFace face = pk.Face;

            if (pk.ActionType == PlayerActionPacket.ACTION_START_BREAK)
            {
                //TODO : InteractEvent
                //TODO : LevelEventPacket
            }
            else if (pk.ActionType == PlayerActionPacket.ACTION_ABORT_BREAK)
            {
            }
            else if (pk.ActionType == PlayerActionPacket.ACTION_STOP_BREAK)
            {
                //TODO : LevelEventPacket
            }
            else if (pk.ActionType == PlayerActionPacket.ACTION_GET_UPDATED_BLOCK)
            {
            }
            else if (pk.ActionType == PlayerActionPacket.ACTION_DROP_ITEM)
            {
            }
            else if (pk.ActionType == PlayerActionPacket.ACTION_START_SLEEPING)
            {
            }
            else if (pk.ActionType == PlayerActionPacket.ACTION_STOP_SLEEPING)
            {
            }
            else if (pk.ActionType == PlayerActionPacket.ACTION_RESPAWN)
            {
            }
            else if (pk.ActionType == PlayerActionPacket.ACTION_JUMP)
            {
                PlayerJumpEventArgs playerJumpEvent = new PlayerJumpEventArgs(this);
                PlayerEvents.OnPlayerJump(playerJumpEvent);
                if (this.Sprinting)
                {
                    this.AddExhaustion(0.8f, PlayerExhaustEventArgs.CAUSE_SPRINT_JUMPING);
                }
                else
                {
                    this.AddExhaustion(0.2f, PlayerExhaustEventArgs.CAUSE_JUMPING);
                }
            }
            else if (pk.ActionType == PlayerActionPacket.ACTION_START_SPRINT)
            {
                PlayerToggleSprintEventArgs playerToggleSprintEvent = new PlayerToggleSprintEventArgs(this, true);
                PlayerEvents.OnPlayerToggleSprint(playerToggleSprintEvent);
                if (playerToggleSprintEvent.IsCancel)
                {
                    this.SendDataProperties();
                }
                this.Sprinting = true;
                this.SendDataProperties();
            }
            else if (pk.ActionType == PlayerActionPacket.ACTION_STOP_SPRINT)
            {
                PlayerToggleSprintEventArgs playerToggleSprintEvent = new PlayerToggleSprintEventArgs(this, false);
                PlayerEvents.OnPlayerToggleSprint(playerToggleSprintEvent);
                if (playerToggleSprintEvent.IsCancel)
                {
                    this.SendDataProperties();
                }
                this.Sprinting = false;
                this.SendDataProperties();
            }
            else if (pk.ActionType == PlayerActionPacket.ACTION_START_SNEAK)
            {
                PlayerToggleSneakEventArgs playerToggleSneakEvent = new PlayerToggleSneakEventArgs(this, true);
                PlayerEvents.OnPlayerToggleSneak(playerToggleSneakEvent);
                if (playerToggleSneakEvent.IsCancel)
                {
                    this.SendDataProperties();
                }
                this.Sneaking = true;
                this.SendDataProperties();
            }
            else if (pk.ActionType == PlayerActionPacket.ACTION_STOP_SNEAK)
            {
                PlayerToggleSneakEventArgs playerToggleSneakEvent = new PlayerToggleSneakEventArgs(this, false);
                PlayerEvents.OnPlayerToggleSneak(playerToggleSneakEvent);
                if (playerToggleSneakEvent.IsCancel)
                {
                    this.SendDataProperties();
                }
                this.Sneaking = false;
                this.SendDataProperties();
            }
            else if (pk.ActionType == PlayerActionPacket.ACTION_DIMENSION_CHANGE_REQUEST)
            {
            }
            else if (pk.ActionType == PlayerActionPacket.ACTION_DIMENSION_CHANGE_ACK)
            {
            }
            else if (pk.ActionType == PlayerActionPacket.ACTION_START_GLIDE)
            {
                PlayerToggleGlideEventArgs playerToggleGlideEvent = new PlayerToggleGlideEventArgs(this, true);
                PlayerEvents.OnPlayerToggleGlide(playerToggleGlideEvent);
                if (playerToggleGlideEvent.IsCancel)
                {
                    this.SendDataProperties();
                }
                this.Gliding = true;
                this.SendDataProperties();
            }
            else if (pk.ActionType == PlayerActionPacket.ACTION_STOP_GLIDE)
            {
                PlayerToggleGlideEventArgs playerToggleGlideEvent = new PlayerToggleGlideEventArgs(this, false);
                PlayerEvents.OnPlayerToggleGlide(playerToggleGlideEvent);
                if (playerToggleGlideEvent.IsCancel)
                {
                    this.SendDataProperties();
                }
                this.Gliding = false;
                this.SendDataProperties();
            }
            else if (pk.ActionType == PlayerActionPacket.ACTION_BUILD_DENIED)
            {
            }
            else if (pk.ActionType == PlayerActionPacket.ACTION_CONTINUE_BREAK)
            {
            }
            this.Action = false;
        }