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 } }
public void OnHandshake(IMinecraftUser user, IMinecraftPacket packet) { var handshake = new HandshakePacket(packet); user.UpdateStatus(handshake.NextState); }