private PlayerEvent OnGameEvent(GameEvent gameEvent)
        {
            if (gameEvent.IsDisconnected)
            {
                Disconnect();
                return null;
            }

            if (Client == null) return null;

            Client.HandleGameEvent(gameEvent);
            return Client.CreatePlayerEvent();
        }
        private async Task OnGameEventAsync(GameEvent gameEvent)
        {
            if (gameEvent == null) return;

            PlayerEvent playerEvent = null;
            await _gameLoop.SendAsync(() => playerEvent = OnGameEvent(gameEvent));
            if (playerEvent != null && _channel != null) await _channel.SendPlayerEventAsync(playerEvent);
        }
Exemple #3
0
 public void QueueGameEvent(GameEvent gameEvent)
 {
     _gameEvents.Enqueue(gameEvent);
 }
Exemple #4
0
 private Task SendGameEventAsync(Stream stream, GameEvent e)
 {
     return stream.WriteObjectAsync(e);
 }
Exemple #5
0
        private GameEvent GetCurrentGameEvent(Channel channel)
        {
            var player = channel.Player;

            var gameEvent = new GameEvent() { EntityInfos = new List<EntityData>() };
            foreach (var entity in _entities)
            {
                if (entity != player)
                {
                    gameEvent.EntityInfos.Add(new EntityData { PositionData = entity.PositionData, ModelIndex = entity.ModelIndex });
                }
            }

            if (player.PositionData != null)
            {
                var playerChunkPos = (ChunkPos)player.PositionData.Placement.Pos;

                int chunksInPacket = 0;

                ChunkPos.IterateOutwards(
                    playerChunkPos,
                    ChunkViewRadiusXZ,
                    ChunkViewRadiusY,
                    chunkPos =>
                    {
                        if (!channel.SentChunks.ContainsKey(chunkPos))
                        {
                            var chunk = _startWorld.GetChunk(chunkPos);

                            if (chunksInPacket < 5 && chunk.IsCreated)
                            {
                                channel.SentChunks[chunkPos] = true;

                                if (chunk != null)
                                {
                                    if (gameEvent.ChunkDataList == null)
                                    {
                                        gameEvent.ChunkDataList = new List<ChunkData>();
                                    }

                                    gameEvent.ChunkDataList.Add(chunk.GetChunkData());
                                    ++chunksInPacket;
                                }
                            }
                        }
                    });
            }

            if (channel.SentBlockUpdates != _blockUpdates.Count)
            {
                gameEvent.BlockUpdates = _blockUpdates.GetRange(channel.SentBlockUpdates, _blockUpdates.Count - channel.SentBlockUpdates);
                channel.SentBlockUpdates = _blockUpdates.Count;
            }

            return gameEvent;
        }