/// <summary> /// Creates a new <see cref="HandshakePacket"/> instance. /// </summary> /// <param name="packet">Incoming packet from client.</param> public HandshakePacket(IMinecraftPacket packet) { ProtocolVersion = packet.ReadVarInt32(); ServerAddress = packet.ReadString(); ServerPort = packet.ReadUInt16(); NextState = (MinecraftUserStatus)packet.ReadVarInt32(); }
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 } }