Example #1
0
        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.IsHardcore)
            {
                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;

            return(new MultiplayerSessionReservation(correlationId, playerId, reservationKey));
        }
Example #2
0
        private static void RemoveClient(Client client)
        {
            lock (removeClientLock)
            {
                if (clients.Contains(client))
                {
                    Boolean result = clients.Remove(client);
                    if (result)
                    {
                        Log.WriteSystem($"Disconnected: @{client.Name}");

                        if (clients.Count > 0)
                        {
                            packetStack.Push(new Packet {
                                ClientName = client.Name, Message = "Is Offline...", Ip = "Null"
                            });
                        }
                    }
                }
            }
        }
        public override void Process(RocketPreflightComplete packet, NitroxServer.Player player)
        {
            Optional <NeptuneRocketModel> opRocket = vehicleManager.GetVehicleModel <NeptuneRocketModel>(packet.Id);

            if (opRocket.HasValue)
            {
                ThreadSafeCollection <PreflightCheck> collection = opRocket.Value.PreflightChecks;

                if (!collection.Contains(packet.FlightCheck))
                {
                    collection.Add(packet.FlightCheck);
                }
                else
                {
                    Log.Error($"{nameof(RocketPreflightCompleteProcessor)}: Received an existing preflight '{packet.FlightCheck}' for rocket '{packet.Id}'");
                }
            }
            else
            {
                Log.Error($"{nameof(RocketPreflightCompleteProcessor)}: Can't find server model for rocket with id {packet.Id}");
            }

            playerManager.SendPacketToOtherPlayers(packet, player);
        }
Example #4
0
 public bool HasCellLoaded(AbsoluteEntityCell cell)
 {
     return(visibleCells.Contains(cell));
 }