private void HandlePlayerEvent(Channel channel, PlayerEvent playerEvent) { if (playerEvent.PositionData != null) { channel.Player.PositionData = playerEvent.PositionData; } if (playerEvent.BlockUpdates != null) { AddBlockUpdates(playerEvent.BlockUpdates); } }
internal void DeregisterChannel(Channel channel) { Log.Info("Player disconnected"); lock (_mutex) { _entities.Remove(channel.Player); _channels.Remove(channel); } }
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; }
public IChannel ConnectPlayer() { Log.Info("Player connected"); lock (_mutex) { var entity = new Entity(); _entities.Add(entity); entity.PositionData = new PositionData(); Movement.Respawn(entity.PositionData); var channel = new Channel(this, entity); _channels.Add(channel); channel.SentBlockUpdates = _blockUpdates.Count; return channel; } }