public void CheckKeepAlive(long keepAliveId) { if (_keepAliveIdQueue.TryDequeue(out long nextKeepAliveId)) { if (nextKeepAliveId != keepAliveId) { _user.Disconnect("Keep-alive id doesn't match."); return; } Ping = (int)(TimeUtilities.GetElapsedMilliseconds() - nextKeepAliveId); using var playerInfoLatencyPacket = new PlayerInfoPacket(PlayerInfoActionType.UpdateLatency, this); World.SendToAll(playerInfoLatencyPacket); } }
public void OnChatMessage(IMinecraftUser user, IMinecraftPacket packet) { string message = packet.ReadString(); if (message.Length > 256) { user.Disconnect("Chat message exceeds 256 characters."); } if (message.StartsWith(RedstoneContants.CommandPrefix)) { // TODO: interpret commands } else { user.Player.Speak(message); } }
public void OnLogin(IMinecraftUser user, IMinecraftPacket packet) { string username = packet.ReadString(); _logger.LogInformation($"{user.Username} trying to log-in"); if (_serverConfiguration.Value.Mode == ServerModeType.Offline) { if (_serverConfiguration.Value.AllowMultiplayerDebug) { int count = _server.ConnectedPlayers.Count(x => x.Username.StartsWith(username)); if (count > 0 && _server.ConnectedPlayers.Any(x => x.Username.Equals(username))) { username = $"{username} ({count})"; } } else { if (_server.HasUser(username)) { user.Disconnect($"A player with the same name '{username}' is already connected."); return; } } Guid playerId = GuidUtilities.GenerateGuidFromString($"OfflinePlayer:{username}"); // TODO: initialize current player // TODO: Read player data from storage (DB or file-system) user.LoadPlayer(playerId, username); // DEBUG user.Player.Position.X = 8; user.Player.Position.Y = 2; user.Player.Position.Z = 8; SendLoginSucess(user); user.UpdateStatus(MinecraftUserStatus.Play); _server.Events.OnPlayerJoinGame(new PlayerJoinEventArgs(user.Player)); SendJoinGame(user); SendServerBrand(user); // TODO: held item changed // TODO: declare recipes // TODO: Tags // TODO: Entity status // TODO: declare commands // TODO: Unlock recipes SendPlayerPositionAndLook(user, user.Player.Position); SendPlayerInfo(user, PlayerInfoActionType.Add); SendPlayerInfo(user, PlayerInfoActionType.UpdateLatency); SendUpdateViewPosition(user); // TODO: Update light SendChunkData(user); SendUpdateViewPosition(user); // TODO: World border SendSpawnPosition(user, Position.Zero); SendPlayerPositionAndLook(user, user.Player.Position); user.Player.IsSpawned = true; } else { // TODO: login to Mojang API } }