public Player(ushort id, string name, bool isPermaDeath, PlayerContext playerContext, NitroxConnection connection, NitroxVector3 position, NitroxId playerId, Optional <NitroxId> subRootId, Perms perms, PlayerStatsData stats, IEnumerable <EquippedItemData> equippedItems, IEnumerable <EquippedItemData> modules) { Id = id; Name = name; IsPermaDeath = isPermaDeath; PlayerContext = playerContext; this.connection = connection; Position = position; SubRootId = subRootId; GameObjectId = playerId; Permissions = perms; Stats = stats; LastStoredPosition = null; this.equippedItems = new ThreadSafeCollection <EquippedItemData>(equippedItems); this.modules = new ThreadSafeCollection <EquippedItemData>(modules); visibleCells = new ThreadSafeCollection <AbsoluteEntityCell>(new HashSet <AbsoluteEntityCell>(), false); }
public Player(ushort id, string name, bool isPermaDeath, PlayerContext playerContext, NitroxConnection connection, NitroxVector3 position, NitroxId playerId, Optional <NitroxId> subRootId, Perms perms, PlayerStatsData stats, IEnumerable <NitroxTechType> usedItems, IEnumerable <string> quickSlotsBinding, IEnumerable <EquippedItemData> equippedItems, IEnumerable <EquippedItemData> modules, HashSet <string> completedGoals) { Id = id; Name = name; IsPermaDeath = isPermaDeath; PlayerContext = playerContext; Connection = connection; Position = position; SubRootId = subRootId; GameObjectId = playerId; Permissions = perms; Stats = stats; LastStoredPosition = null; LastStoredSubRootID = Optional.Empty; UsedItems = new ThreadSafeList <NitroxTechType>(usedItems); QuickSlotsBinding = new ThreadSafeList <string>(quickSlotsBinding); this.equippedItems = new ThreadSafeList <EquippedItemData>(equippedItems); this.modules = new ThreadSafeList <EquippedItemData>(modules); visibleCells = new ThreadSafeSet <AbsoluteEntityCell>(); CompletedGoals = new ThreadSafeSet <string>(completedGoals); }
public override void Process(PlayerJoiningMultiplayerSession packet, NitroxConnection connection) { Player player = playerManager.PlayerConnected(connection, packet.ReservationKey, out bool wasBrandNewPlayer); NitroxId assignedEscapePodId = world.EscapePodManager.AssignPlayerToEscapePod(player.Id, out Optional <EscapePodModel> newlyCreatedEscapePod); if (newlyCreatedEscapePod.HasValue) { AddEscapePod addEscapePod = new(newlyCreatedEscapePod.Value); playerManager.SendPacketToOtherPlayers(addEscapePod, player); } List <EquippedItemData> equippedItems = player.GetEquipment(); List <NitroxTechType> techTypes = equippedItems.Select(equippedItem => equippedItem.TechType).ToList(); List <ItemData> inventoryItems = GetInventoryItems(player.GameObjectId); PlayerJoinedMultiplayerSession playerJoinedPacket = new(player.PlayerContext, player.SubRootId, techTypes, inventoryItems); playerManager.SendPacketToOtherPlayers(playerJoinedPacket, player); // Make players on localhost admin by default. if (IPAddress.IsLoopback(connection.Endpoint.Address)) { player.Permissions = Perms.ADMIN; } List <NitroxId> simulations = world.EntitySimulation.AssignGlobalRootEntities(player).ToList(); IEnumerable <VehicleModel> vehicles = world.VehicleManager.GetVehicles(); foreach (VehicleModel vehicle in vehicles) { if (world.SimulationOwnershipData.TryToAcquire(vehicle.Id, player, SimulationLockType.TRANSIENT)) { simulations.Add(vehicle.Id); } } InitialPlayerSync initialPlayerSync = new(player.GameObjectId, wasBrandNewPlayer, world.EscapePodManager.GetEscapePods(), assignedEscapePodId, equippedItems, GetAllModules(world.InventoryManager.GetAllModules(), player.GetModules()), world.BaseManager.GetBasePiecesForNewlyConnectedPlayer(), vehicles, world.InventoryManager.GetAllInventoryItems(), world.InventoryManager.GetAllStorageSlotItems(), player.UsedItems, player.QuickSlotsBinding, world.GameData.PDAState.GetInitialPDAData(), world.GameData.StoryGoals.GetInitialStoryGoalData(), player.Position, player.SubRootId, player.Stats, GetRemotePlayerData(player), world.EntityManager.GetGlobalRootEntities(), simulations, world.GameMode, player.Permissions ); timeKeeper.SendCurrentTimePacket(); player.SendPacket(initialPlayerSync); }
// This will extend in the future when we look into different options for auth public override void Process(MultiplayerSessionPolicyRequest packet, NitroxConnection connection) { Log.Info("Providing session policies..."); connection.SendPacket(new MultiplayerSessionPolicy(packet.CorrelationId, config.DisableConsole, config.MaxConnections, config.IsPasswordRequired)); }
public InitialSyncTimerData(NitroxConnection connection, AuthenticationContext context, int initialSyncTimeout) { Connection = connection; Context = context; MaxCounter = (int)Math.Ceiling(initialSyncTimeout / 200f); }
public abstract void Process(T packet, NitroxConnection connection);
public MultiplayerSessionReservation ReservePlayerContext( NitroxConnection connection, PlayerSettings playerSettings, AuthenticationContext authenticationContext, string correlationId) { // TODO: ServerPassword in NitroxClient if (!string.IsNullOrEmpty(serverConfig.ServerPassword) && (!authenticationContext.ServerPassword.HasValue || authenticationContext.ServerPassword.Value != serverConfig.ServerPassword)) { MultiplayerSessionReservationState rejectedState = MultiplayerSessionReservationState.REJECTED | MultiplayerSessionReservationState.AUTHENTICATION_FAILED; return(new MultiplayerSessionReservation(correlationId, rejectedState)); } if (reservedPlayerNames.Count >= serverConfig.MaxConnections) { MultiplayerSessionReservationState rejectedState = MultiplayerSessionReservationState.REJECTED | MultiplayerSessionReservationState.SERVER_PLAYER_CAPACITY_REACHED; return(new MultiplayerSessionReservation(correlationId, rejectedState)); } string playerName = authenticationContext.Username; Player player; allPlayersByName.TryGetValue(playerName, out player); if ((player?.IsPermaDeath == true) && serverConfig.GameMode == "Hardcore") { MultiplayerSessionReservationState rejectedState = MultiplayerSessionReservationState.REJECTED | MultiplayerSessionReservationState.HARDCORE_PLAYER_DEAD; return(new MultiplayerSessionReservation(correlationId, rejectedState)); } if (reservedPlayerNames.Contains(playerName)) { MultiplayerSessionReservationState rejectedState = MultiplayerSessionReservationState.REJECTED | MultiplayerSessionReservationState.UNIQUE_PLAYER_NAME_CONSTRAINT_VIOLATED; return(new MultiplayerSessionReservation(correlationId, rejectedState)); } ConnectionAssets assetPackage; assetsByConnection.TryGetValue(connection, out assetPackage); if (assetPackage == null) { assetPackage = new ConnectionAssets(); assetsByConnection.Add(connection, assetPackage); reservedPlayerNames.Add(playerName); } bool hasSeenPlayerBefore = player != null; ushort playerId = hasSeenPlayerBefore ? player.Id : ++currentPlayerId; PlayerContext playerContext = new PlayerContext(playerName, playerId, !hasSeenPlayerBefore, playerSettings); string reservationKey = Guid.NewGuid().ToString(); reservations.Add(reservationKey, playerContext); assetPackage.ReservationKey = reservationKey; if (ConnectedPlayers().Count() == 1) { Server.Instance.EnablePeriodicSaving(); } return(new MultiplayerSessionReservation(correlationId, playerId, reservationKey)); }