public void Setup()
 {
     state = new ThreadSafeCollection <InteractiveChildObjectIdentifier>();
     state.Add(new InteractiveChildObjectIdentifier(new NitroxId(), "/BlablaScene/SomeBlablaContainer/BlaItem"));
     byte[] idBytes = new byte[16];
     random.NextBytes(idBytes);
     state.Add(new InteractiveChildObjectIdentifier(new NitroxId(idBytes), ""));
     state.Add(new InteractiveChildObjectIdentifier(new NitroxId(), " herp "));
 }
Ejemplo n.º 2
0
 public void AddCells(IEnumerable <AbsoluteEntityCell> cells)
 {
     foreach (AbsoluteEntityCell cell in cells)
     {
         visibleCells.Add(cell);
     }
 }
Ejemplo n.º 3
0
        public void IterateAndAddSimultanious()
        {
            int iterations = 500000;

            ThreadSafeCollection <string> comeGetMe = new ThreadSafeCollection <string>(iterations);
            long addCount           = 0;
            long iterationsReadMany = 0;

            Random r = new Random();

            DoReaderWriter(() =>
            {
                foreach (string item in comeGetMe)
                {
                    item.Length.Should().BeGreaterThan(0);
                    Interlocked.Increment(ref iterationsReadMany);
                }
            },
                           i =>
            {
                comeGetMe.Add(new string(Enumerable.Repeat(' ', 10).Select(c => (char)r.Next('A', 'Z')).ToArray()));
                Interlocked.Increment(ref addCount);
            },
                           iterations);

            addCount.ShouldBeEquivalentTo(iterations);
            iterationsReadMany.Should().BePositive();
        }
Ejemplo n.º 4
0
        public void ReadAndWriteSimultanious()
        {
            int iterations = 500000;

            ThreadSafeCollection <string> comeGetMe = new ThreadSafeCollection <string>(iterations);
            List <long> countsRead = new List <long>();
            long        addCount   = 0;

            Random r = new Random();

            DoReaderWriter(() =>
            {
                countsRead.Add(Interlocked.Read(ref addCount));
            },
                           i =>
            {
                comeGetMe.Add(new string(Enumerable.Repeat(' ', 10).Select(c => (char)r.Next('A', 'Z')).ToArray()));
                Interlocked.Increment(ref addCount);
            },
                           iterations);

            addCount.ShouldBeEquivalentTo(iterations);
            countsRead.Count.Should().BeGreaterThan(0);
            countsRead.Last().ShouldBeEquivalentTo(iterations);
            comeGetMe.Count.ShouldBeEquivalentTo(iterations);
        }
Ejemplo n.º 5
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));
        }
Ejemplo n.º 6
0
 public void Setup()
 {
     list = new ThreadSafeCollection <string>();
     set  = new ThreadSafeCollection <string>(new HashSet <string>());
     for (int i = 0; i < 10; i++)
     {
         set.Add($"test {i}");
         list.Add($"test {i}");
     }
 }
Ejemplo n.º 7
0
        private static void AddClient(Client client)
        {
            lock (addClientLock)
            {
                clients.Add(client);

                Thread clienThread = new Thread(() => AcceptMessages(client));
                clienThread.IsBackground = true;
                clientsThreads.Add(clienThread);
                clienThread.Start();

                Log.WriteSystem($"Connected: {client.Name}");
            }
        }
Ejemplo n.º 8
0
        public void IterateAndAdd()
        {
            ThreadSafeCollection <int> nums = new ThreadSafeCollection <int>()
            {
                1, 2, 3, 4, 5
            };

            foreach (int num in nums)
            {
                if (num == 3)
                {
                    nums.Add(10);
                }
            }

            nums.Count.ShouldBeEquivalentTo(6);
            nums.Last().ShouldBeEquivalentTo(10);
        }
        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);
        }
Ejemplo n.º 10
0
 public void AddEquipment(EquippedItemData equipment)
 {
     equippedItems.Add(equipment);
 }
Ejemplo n.º 11
0
 public void AddModule(EquippedItemData module)
 {
     modules.Add(module);
 }
        public FoldersControl()
        {
            mailbox    = VirtualMailBox.Current;
            viewFilter = ViewFilter.Current;
            labels     = new ThreadSafeCollection <LabelsContainer>();

            LabelsViewSource = new CollectionViewSource {
                Source = labels
            };
            LabelsViewSource.SortDescriptions.Add(new SortDescription("Count", ListSortDirection.Descending));
            LabelsViewSource.View.Filter = IsLabelVisible;

            InitializeComponent();

            signal       = new AutoResetEvent(false);
            workerThread = new Thread(UpdateCounters)
            {
                Name         = "Counter update thread",
                IsBackground = true,
                Priority     = ThreadPriority.BelowNormal
            };

            workerThread.Start();

            DataContext = this;

            VirtualMailBox.Current.LoadComplete += delegate { UpdateCountersAsync(); };

            EventBroker.Subscribe(AppEvents.RebuildOverview, UpdateCountersAsync);
            EventBroker.Subscribe(AppEvents.ReceiveMessagesFinished, UpdateCountersAsync);
            EventBroker.Subscribe(AppEvents.MessageUpdated, UpdateCountersAsync);

            EventBroker.Subscribe(AppEvents.View, delegate(ActivityView view)
            {
                ClientState.Current.ViewController.MoveTo(WellKnownView.Overview);

                // Find the radio-button with the requested view
                LogicalTreeWalker.Walk(this, delegate(RadioButton rb)
                {
                    if (GetActivityView(rb) == view)
                    {
                        rb.IsChecked = true;
                    }
                });

                viewFilter.Filter.CurrentView = view;
                viewFilter.RebuildCurrentViewAsync();

                EventBroker.Publish(AppEvents.RequestFocus);
            });

            EventBroker.Subscribe(AppEvents.View, delegate(Label label)
            {
                EventBroker.Publish(AppEvents.View, ActivityView.Label);

                viewFilter.Filter.Label = label.Labelname;
                viewFilter.RebuildCurrentViewAsync();

                EventBroker.Publish(AppEvents.RequestFocus);
            });

            EventBroker.Subscribe(AppEvents.ShuttingDown, () => Thread.CurrentThread.ExecuteOnUIThread(delegate
            {
                // Save settings during shutdown
                SettingsManager.ClientSettings.AppConfiguration.ShowProductivityColumn = ProductivityExpander.IsExpanded;
                SettingsManager.ClientSettings.AppConfiguration.ShowLabelsColumn       = LabelsExpander.IsExpanded;
                SettingsManager.Save();
            }));

            EventBroker.Subscribe(AppEvents.LabelCreated, (string label) => labels.Add(new LabelsContainer(label)));
        }
Ejemplo n.º 13
0
        public FoldersControl()
        {
            mailbox = VirtualMailBox.Current;
            viewFilter = ViewFilter.Current;
            labels = new ThreadSafeCollection<LabelsContainer>();

            LabelsViewSource = new CollectionViewSource { Source = labels };
            LabelsViewSource.SortDescriptions.Add(new SortDescription("Count", ListSortDirection.Descending));
            LabelsViewSource.View.Filter = IsLabelVisible;

            InitializeComponent();

            signal = new AutoResetEvent(false);
            workerThread = new Thread(UpdateCounters)
            {
                Name = "Counter update thread",
                IsBackground = true,
                Priority = ThreadPriority.BelowNormal
            };

            workerThread.Start();

            DataContext = this;

            VirtualMailBox.Current.LoadComplete += delegate { UpdateCountersAsync(); };

            EventBroker.Subscribe(AppEvents.RebuildOverview, UpdateCountersAsync);
            EventBroker.Subscribe(AppEvents.ReceiveMessagesFinished, UpdateCountersAsync);
            EventBroker.Subscribe(AppEvents.MessageUpdated, UpdateCountersAsync);

            EventBroker.Subscribe(AppEvents.View, delegate(ActivityView view)
                {
                    ClientState.Current.ViewController.MoveTo(WellKnownView.Overview);

                    // Find the radio-button with the requested view
                    LogicalTreeWalker.Walk(this, delegate(RadioButton rb)
                        {
                            if (GetActivityView(rb) == view)
                                rb.IsChecked = true;
                        });

                    viewFilter.Filter.CurrentView = view;
                    viewFilter.RebuildCurrentViewAsync();

                    EventBroker.Publish(AppEvents.RequestFocus);
                });

            EventBroker.Subscribe(AppEvents.View, delegate(Label label)
                {
                    EventBroker.Publish(AppEvents.View, ActivityView.Label);

                    viewFilter.Filter.Label = label.Labelname;
                    viewFilter.RebuildCurrentViewAsync();

                    EventBroker.Publish(AppEvents.RequestFocus);
                });

            EventBroker.Subscribe(AppEvents.ShuttingDown, () => Thread.CurrentThread.ExecuteOnUIThread(delegate
                {
                    // Save settings during shutdown
                    SettingsManager.ClientSettings.AppConfiguration.ShowProductivityColumn = ProductivityExpander.IsExpanded;
                    SettingsManager.ClientSettings.AppConfiguration.ShowLabelsColumn = LabelsExpander.IsExpanded;
                    SettingsManager.Save();
                }));

            EventBroker.Subscribe(AppEvents.LabelCreated, (string label) => labels.Add(new LabelsContainer(label)));
        }
Ejemplo n.º 14
0
 /// <summary>
 /// returning useless block to pool
 /// </summary>
 /// <param name="block">block to reuse</param>
 public static void ReturnObject(Block block)
 {
     Returned++;
     block.Reset();
     blocks.Add(block);
 }
Ejemplo n.º 15
0
 public void AddParticle(Particle particle)
 {
     m_safeParticlesCollection.Add(particle);
 }
Ejemplo n.º 16
0
        private void AddExplosion(GameObject exploded)
        {
            ExplosionXna explosion = new ExplosionXna(Game, exploded, m_coordinatesTransformer);

            m_safeDrawableGameComponents.Add(explosion);
        }