public void ArraySegment_MeanGeometric()
        {
            //====================================================================================================
            //  Arrange
            //  reading data from files

            sw = Stopwatch.StartNew();

            //----------------------------------------------------------------------------------------------------
            // Act
            ArraySegment <int> data = new ArraySegment <int>(data01);
            double             mean = data.MeanGeometric();

            sw.Stop();
            Console.WriteLine($"          mean               = {mean}");
            Console.WriteLine($"          size               = {data.Count()}");
            Console.WriteLine($"          elapsed[ticks]     = {sw.ElapsedTicks}");
            Console.WriteLine($"          elapsed[ms]        = {sw.Elapsed.TotalMilliseconds}");
            sw.Reset();
            //----------------------------------------------------------------------------------------------------
            // Assert
            #if NUNIT
            Assert.AreEqual(2.76289, mean, 0.00001);
            #elif XUNIT
            Assert.Equal(2.76289, mean, 5);
            #elif MSTEST
            Assert.AreEqual(2.76289, mean, 0.00001);
            #endif
            //====================================================================================================

            return;
        }
 public bool Execute(ArraySegment <string> arguments, ICommandSender sender, out string response)
 {
     if (!((CommandSender)sender).CheckPermission("fctrl.elevators"))
     {
         response = "Access denied.";
         return(false);
     }
     if (arguments.Count() < 1)
     {
         response = "Proper usage: \"nukeelevator (on/off)\"";
         return(false);
     }
     if (arguments.At(0) != "on" && arguments.At(0) != "off")
     {
         response = "Provided argument must be \"on\" or \"off\".";
         return(false);
     }
     foreach (Lift l in Map.Lifts.Where(i => i.elevatorName == ""))
     {
         l.SetLock(arguments.At(0) == "on" ? false : true);
         l.SetStatus((byte)1);
         l.UseLift();
     }
     response = $"Successfully {(arguments.At(0) == "on" ? "enabled" : "disabled")} the nuke elevator.";
     return(true);
 }
Exemple #3
0
        public override bool Run(ArraySegment <string> arguments, ICommandSender sender, out string response)
        {
            Player target;

            if ((target = Player.List.ElementAt(0)) != null)
            {
                string msg = $"The survivor {target.Nickname} is located in {target.CurrentRoom.Name} !";
                if (arguments.Count() > 0)
                {
                    if (arguments.ElementAt(0).ToLower().StartsWith("z"))
                    {
                        Player.List.Where(e => e.Role == RoleType.Scp0492).Do(e => e.Broadcast(5, msg));

                        response = $"The command has successfully broadcast {target.Nickname} position to every Zombies !";
                        return(true);
                    }
                    else
                    {
                        response = "Command unknown, if you wish to broadcast a survivor position to Zombies: only give 'z' as a first argument...";
                        return(false);
                    }
                }

                Map.Broadcast(5, msg);
                response = $"Everyone is now aware of {target.Nickname} position !";
                return(true);
            }
            else
            {
                response = "Couldn't find a target to broadcast...";
            }

            return(false);
        }
        public bool Execute(ArraySegment <string> arguments, ICommandSender sender, out string response)
        {
            if (!((CommandSender)sender).CheckPermission("fctrl.killzone"))
            {
                response = "Access denied.";
                return(false);
            }
            if (arguments.Count() < 1)
            {
                response = "Invalid format. Must be: \"killzone light/heavy/entrance/surface (eg. killzone light)";
                return(false);
            }
            if (arguments.At(0).ToLower() != "light" && arguments.At(0).ToLower() != "heavy" && arguments.At(0).ToLower() != "entrance" && arguments.At(0).ToLower() != "surface")
            {
                response = "First argument must be light, heavy, entrance, or surface";
                return(false);
            }
            ZoneType zone        = (arguments.At(0).ToLower() == "light" ? ZoneType.LightContainment : (arguments.At(0).ToLower() == "heavy" ? ZoneType.HeavyContainment : (arguments.At(0).ToLower() == "entrance" ? ZoneType.Entrance : (arguments.At(0).ToLower() == "surface" ? ZoneType.Surface : ZoneType.Unspecified))));
            int      totalKilled = 0;

            foreach (Player Ply in Player.List)
            {
                if (Ply.CurrentRoom.Zone == zone && !Ply.IsGodModeEnabled)
                {
                    Ply.Hurt(99999, DamageTypes.Wall, "ZONEKILL");
                    totalKilled++;
                }
            }
            response = $"Killed {totalKilled} players in {zone.ToString()}";
            return(true);
        }
Exemple #5
0
        public bool Execute(ArraySegment <string> arguments, ICommandSender sender, out string response)
        {
            if (!((CommandSender)sender).CheckPermission("fctrl.zones"))
            {
                response = "Access denied.";
                return(false);
            }
            if (arguments.Count() < 1)
            {
                response = "Invalid format. Must be: \"blackoutzone light/heavy/entrance\" (eg. closezone light)";
                return(false);
            }
            if (arguments.At(0).ToLower() != "light" && arguments.At(0).ToLower() != "heavy" && arguments.At(0).ToLower() != "entrance")
            {
                response = "First argument must be light, heavy, or entrance";
                return(false);
            }
            ZoneType zone = (arguments.At(0).ToLower() == "light" ? ZoneType.LightContainment : (arguments.At(0).ToLower() == "heavy" ? ZoneType.HeavyContainment : (arguments.At(0).ToLower() == "entrance" ? ZoneType.Entrance : ZoneType.Unspecified)));

            foreach (Room r in Map.Rooms)
            {
                if (r.Zone == zone)
                {
                    foreach (Door d in r.Doors)
                    {
                        d.SetStateWithSound(false);
                    }
                }
            }
            response = $"Successfully closed all the doors in {zone.ToString()}";
            return(true);
        }
Exemple #6
0
        public bool Execute(ArraySegment <string> arguments, ICommandSender sender, out string response)
        {
            if (!((CommandSender)sender).CheckPermission("fctrl.respawn"))
            {
                response = "Access denied.";
                return(false);
            }
            if (arguments.Count() < 1)
            {
                response = "Proper usage: \"forcerespawn (mtf/chaos)\"";
                return(false);
            }
            if (arguments.At(0).ToLower() != "mtf" && arguments.At(0).ToLower() != "chaos")
            {
                response = "Provided argument must be \"mtf\" or \"chaos\".";
                return(false);
            }
            SpawnableTeamType spawningTeam = (arguments.At(0).ToLower() == "mtf" ? SpawnableTeamType.NineTailedFox : SpawnableTeamType.ChaosInsurgency);
            float             length       = (spawningTeam == SpawnableTeamType.NineTailedFox ? 18f : 13f);

            RespawnManager.Singleton.RestartSequence(); // Prevent the opposite team from spawning while the forced team's animation is playing.
            RespawnEffectsController.ExecuteAllEffects(RespawnEffectsController.EffectType.Selection, spawningTeam);
            Timing.CallDelayed(length, () =>
            {
                RespawnManager.Singleton.ForceSpawnTeam(spawningTeam);
            });
            response = $"Forcing {spawningTeam} spawn...";
            return(true);
        }
Exemple #7
0
    private int MajorityElement(int[] nums, int low, int high)
    {
        int size = high - low;

        if (1 == size)
        {
            return(nums[low]);
        }
        else
        {
            int mid = low + size / 2;

            int leftElement  = this.MajorityElement(nums, low, mid);
            int rightElement = this.MajorityElement(nums, mid, high);

            ArraySegment <int> portion = new ArraySegment <int>(nums, low, high - low);

            int leftCount  = portion.Count((int val) => val == leftElement);
            int rightCount = portion.Count((int val) => val == rightElement);

            return(leftCount > rightCount ? leftElement : rightElement);
        }
    }
Exemple #8
0
        public static void Copy <TFrom, TTo>(ArraySegment <TFrom> src, ArraySegment <TTo> dst)
            where TFrom : struct
            where TTo : struct
        {
            var bytes = new byte[src.Count() * Marshal.SizeOf(typeof(TFrom))];

            using (var pin = Pin.Create(src))
            {
                Marshal.Copy(pin.Ptr, bytes, 0, bytes.Length);
            };
            using (var pin = Pin.Create(dst))
            {
                Marshal.Copy(bytes, 0, pin.Ptr, bytes.Length);
            };
        }
 /// <summary>
 /// 发送
 /// </summary>
 /// <param name="segment"></param>
 public bool Send(ArraySegment <byte> segment)
 {
     try
     {
         easyClient.Send(segment);
         LogHelper.Logger.Info($"发送消息完成!");
         return(true);
     }
     catch (Exception ex)
     {
         LogHelper.Logger.Error($"发送消息时错误,segment Count:{segment.Count()}", ex);
         OnError?.Invoke(this, ex);
         return(false);
     }
 }
Exemple #10
0
        public bool Execute(ArraySegment <string> arguments, ICommandSender sender, out string response)
        {
            if (!((CommandSender)sender).CheckPermission("fctrl.zones"))
            {
                response = "Access denied.";
                return(false);
            }
            if (arguments.Count() < 2)
            {
                response = "Invalid format. Must be: \"closezone light/heavy/entrance duration (eg. closezone light 5)";
                return(false);
            }
            if (arguments.At(0).ToLower() != "light" && arguments.At(0).ToLower() != "heavy" && arguments.At(0).ToLower() != "entrance")
            {
                response = "First argument must be light, heavy, or entrance";
                return(false);
            }
            ZoneType zone = (arguments.At(0).ToLower() == "light" ? ZoneType.LightContainment : (arguments.At(0).ToLower() == "heavy" ? ZoneType.HeavyContainment : (arguments.At(0).ToLower() == "entrance" ? ZoneType.Entrance : ZoneType.Unspecified)));
            int      length;

            try
            {
                length = Convert.ToInt32(arguments.At(1));
            }
            catch
            {
                response = "Second argument must be a valid number (duration)";
                return(false);
            }
            foreach (Room r in Map.Rooms)
            {
                if (r.Zone == zone)
                {
                    foreach (Door d in r.Doors)
                    {
                        d.SetLock(true);
                        d.SetState(false);
                        Timing.CallDelayed(length, () =>
                        {
                            d.SetLock(false);
                        });
                    }
                }
            }
            response = $"Successfully locked all doors in {zone.ToString()}";
            return(true);
        }
Exemple #11
0
        public IEnumerable <IEnumerable <int> > Permutations(ArraySegment <Ingredient> input, int maxSpoons)
        {
            if (input.Count == 1)
            {
                return new[] { new [] { maxSpoons } }
            }
            ;
            if (maxSpoons == 0)
            {
                return new[] { new int[input.Count()] }
            }
            ;

            return(Enumerable.Range(0, maxSpoons)
                   .SelectMany(numSpoons =>
                               Permutations(input.Slice(1), maxSpoons - numSpoons).Select(p => new[] { numSpoons }.Concat(p))));
        }
Exemple #12
0
            private void CalculateMin(int startIndex, int length)
            {
                if (TopIndex < 0)
                {
                    _Min = null;
                    return;
                }

                var validRange = new ArraySegment <int?>(_data, startIndex, length);

                if (validRange.Count(i => i.HasValue) == 0)
                {
                    _Min = null;
                    return;
                }

                _Min = validRange.Where(i => i.HasValue).Min();
            }
        public bool Execute(ArraySegment <string> arguments, ICommandSender sender, out string response)
        {
            if (!((CommandSender)sender).CheckPermission("fctrl.zones"))
            {
                response = "Access denied.";
                return(false);
            }
            if (arguments.Count() < 2)
            {
                response = "Invalid format. Must be: \"blackoutzone light/heavy/entrance duration (eg. blackoutzone light 5)";
                return(false);
            }
            if (arguments.At(0).ToLower() != "light" && arguments.At(0).ToLower() != "heavy" && arguments.At(0).ToLower() != "entrance")
            {
                response = "First argument must be light, heavy, or entrance";
                return(false);
            }
            ZoneType zone = (arguments.At(0).ToLower() == "light" ? ZoneType.LightContainment : (arguments.At(0).ToLower() == "heavy" ? ZoneType.HeavyContainment : (arguments.At(0).ToLower() == "entrance" ? ZoneType.Entrance : ZoneType.Unspecified)));
            int      length;

            try
            {
                length = Convert.ToInt32(arguments.At(1));
            }
            catch
            {
                response = "Second argument must be a valid number (duration)";
                return(false);
            }
            foreach (Room r in Map.Rooms)
            {
                if (r.Zone == zone)
                {
                    r.TurnOffLights(length);
                }
            }
            FacilityControl.LightsOut[zone] = true;
            Timing.CallDelayed((float)length, () =>
            {
                FacilityControl.LightsOut[zone] = false;
            });
            response = $"Successfully blacked out all lights in {zone.ToString()}";
            return(true);
        }
        public bool Execute(ArraySegment <string> arguments, ICommandSender sender, out string response)
        {
            if (!((CommandSender)sender).CheckPermission("fctrl.prygates"))
            {
                response = "Access denied.";
                return(false);
            }
            if (arguments.Count() < 2)
            {
                response = "Proper usage: prygates (add/remove) (player)";
                return(false);
            }
            if (arguments.At(0).ToLower() != "add" && arguments.At(0).ToLower() != "remove")
            {
                response = "Proper usage: prygates (add/remove) (player)";
                return(false);
            }
            List <Player> Plys = API.GetPlayers(arguments.At(1));

            if (Plys.Count() == 0)
            {
                response = "Invalid player(s).";
                return(false);
            }
            List <Player> Affected = new List <Player> {
            };

            foreach (Player Ply in Plys)
            {
                if (arguments.At(0).ToLower() == "add" && !FacilityControl.PlySets["PryGates"].Contains(Ply))
                {
                    FacilityControl.PlySets["PryGates"].Add(Ply);
                    Affected.Add(Ply);
                }
                if (arguments.At(0).ToLower() == "remove" && FacilityControl.PlySets["PryGates"].Contains(Ply))
                {
                    FacilityControl.PlySets["PryGates"].Remove(Ply);
                    Affected.Add(Ply);
                }
            }
            response = $"Done! The request affected {Affected.Count()} players.";
            return(false);
        }
Exemple #15
0
        public static Signature Restore(ArraySegment <byte> signatureData)
        {
            if (!signatureData.Valid() || signatureData.Count() < PADDING_BYTES)
            {
                throw new ArgumentException(nameof(signatureData));
            }

            var keyType  = (KeyTypes)signatureData.Array[signatureData.Offset];
            var hashType = (HashTypes)signatureData.Array[signatureData.Offset + 1];

            Key.CheckKeyType(keyType, true);
            Hash.CheckHashType(hashType, true);

            if (keyType == KeyTypes.Ed25519)
            {
                return(new Ed25519Signature(signatureData, hashType));
            }

            throw new ArgumentException(string.Format("Signature type not implemented {0}", keyType));
        }
Exemple #16
0
 public bool Execute(ArraySegment <string> arguments, ICommandSender sender, out string response)
 {
     if (!((CommandSender)sender).CheckPermission("fctrl.settings"))
     {
         response = "Access denied.";
         return(false);
     }
     if (arguments.Count() < 1)
     {
         response = "Proper usage: \"escaping (on/off)\"";
         return(false);
     }
     if (arguments.At(0) != "on" && arguments.At(0) != "off")
     {
         response = "Provided argument must be \"on\" or \"off\".";
         return(false);
     }
     FacilityControl.EscapingDisabled = (arguments.At(0) == "on" ? false : true);
     response = $"Successfully {(arguments.At(0) == "on" ? "enabled" : "disabled")} escaping.";
     return(true);
 }
        public bool Execute(ArraySegment <string> arguments, ICommandSender sender, out string response)
        {
            if (arguments.Count() == 0)
            {
                response = "Missing required first argument (must be 'enable' or 'disable').";
                return(false);
            }

            switch (arguments.At(0))
            {
            case "enable":
                if (!((CommandSender)sender).CheckPermission("scp914tp.settings"))
                {
                    response = "Access denied.";
                    return(false);
                }
                Scp914Teleportation.enabledInGame = true;
                response = "Successfully enabled SCP-914 Teleportation.";
                break;

            case "disable":
                if (!((CommandSender)sender).CheckPermission("scp914tp.settings"))
                {
                    response = "Access denied.";
                    return(false);
                }
                Scp914Teleportation.enabledInGame = false;
                response = "Successfully disabled SCP-914 Teleportation.";
                break;

            default:
                response = $"Uknown parameter '{arguments.At(0)}'";
                break;
            }

            return(true);
        }
Exemple #18
0
        async void ReceiveTask()
        {
            while (rconAlive)
            {
                await Task.Delay(20);

                var packets = new ArraySegment <byte>(await rcon.SendCommandAsync(Encoding.UTF8.GetBytes("/RoutingTXBuff\0")));

                VarInt size;

                while (packets.Count() > 2)
                {
                    (size, packets) = VarInt.Take(packets);

                    var packet = new ArraySegment <byte>(packets.Array, packets.Offset, size);

                    var packetframe = new PackedFrame(packet, Map).Unpack();
                    packetframe.origin = this;
                    OnReceive?.Invoke(packetframe);

                    packets = new ArraySegment <byte>(packets.Array, packets.Offset + size, packets.Count - size);
                }
            }
        }
        public bool Execute(ArraySegment <string> arguments, ICommandSender sender, out string response)
        {
            if (!((CommandSender)sender).CheckPermission("fctrl.zones"))
            {
                response = "Access denied.";
                return(false);
            }
            if (arguments.Count() < 2)
            {
                response = "Invalid format. Must be: \"isolate light/heavy/entrance duration (eg. isolate light 5)";
                return(false);
            }
            if (arguments.At(0).ToLower() != "light" && arguments.At(0).ToLower() != "heavy" && arguments.At(0).ToLower() != "entrance" && arguments.At(0).ToLower() != "facility")
            {
                response = "First argument must be light, heavy, entrance, or facility";
                return(false);
            }
            ZoneType zone = (arguments.At(0).ToLower() == "light" ? ZoneType.LightContainment : (arguments.At(0).ToLower() == "heavy" ? ZoneType.HeavyContainment : (arguments.At(0).ToLower() == "entrance" ? ZoneType.Entrance : (arguments.At(0).ToLower() == "facility" ? ZoneType.Surface : ZoneType.Unspecified))));
            int      length;

            try
            {
                length = Convert.ToInt32(arguments.At(1));
            }
            catch
            {
                response = "Second argument must be a valid number (duration)";
                return(false);
            }
            List <Door> doors = new List <Door> {
            };

            switch (zone)
            {
            case ZoneType.LightContainment:
                doors = Map.Doors.ToList().FindAll(door => door.DoorName == "CHECKPOINT_LCZ_A" || door.DoorName == "CHECKPOINT_LCZ_B");
                break;

            case ZoneType.HeavyContainment:
                doors = Map.Doors.ToList().FindAll(door => door.DoorName == "CHECKPOINT_LCZ_A" || door.DoorName == "CHECKPOINT_LCZ_B" || door.DoorName == "CHECKPOINT_ENT");
                break;

            case ZoneType.Entrance:
                doors = Map.Doors.ToList().FindAll(door => door.DoorName == "GATE_A" || door.DoorName == "GATE_B" || door.DoorName == "CHECKPOINT_ENT");
                break;

            case ZoneType.Surface:
                doors = Map.Doors.ToList().FindAll(door => door.DoorName == "GATE_A" || door.DoorName == "GATE_B");
                break;
            }
            foreach (Door door in doors)
            {
                door.SetStateWithSound(false);
                door.SetLock(true);
            }
            Timing.CallDelayed(length, () =>
            {
                foreach (Door door in doors)
                {
                    door.SetLock(false);
                }
            });
            response = $"Successfully isolated {(zone == ZoneType.Surface ? "the facility" : zone.ToString())}";
            return(true);
        }
        public void ArraySegment_Frequencies()
        {
            //====================================================================================================
            //  Arrange
            //  reading data from files

            sw = Stopwatch.StartNew();

            //----------------------------------------------------------------------------------------------------
            // Act
            ArraySegment <int> data = new ArraySegment <int>(data01);
            IEnumerable <KeyValuePair <int, uint> > frequencies = data.Frequencies();

            sw.Stop();
            Console.WriteLine($"          frequencies        = {frequencies}");
            Console.WriteLine($"          size               = {data.Count()}");
            Console.WriteLine($"          elapsed[ticks]     = {sw.ElapsedTicks}");
            Console.WriteLine($"          elapsed[ms]        = {sw.Elapsed.TotalMilliseconds}");
            sw.Reset();
            //----------------------------------------------------------------------------------------------------
            // Assert
            #if NUNIT
            CollectionAssert.AreEquivalent
            (
                new Dictionary <int, uint>
            {
                { 3, 4 },
                { 2, 2 },
                { 4, 2 },
                { 1, 1 },
                { 5, 1 },
            }
                .ToList(),
                frequencies
            );
            #elif XUNIT
            Assert.Equal
            (
                new Dictionary <int, uint>
            {
                { 3, 4 },
                { 2, 2 },
                { 4, 2 },
                { 1, 1 },
                { 5, 1 },
            }
                .ToList(),
                frequencies
            );
            #elif MSTEST
            CollectionAssert.AreEquivalent
            (
                new Dictionary <int, uint>
            {
                { 3, 4 },
                { 2, 2 },
                { 4, 2 },
                { 1, 1 },
                { 5, 1 },
            }
                .ToList(),
                frequencies.ToArray()
            );
            #endif
            //====================================================================================================

            return;
        }
Exemple #21
0
 /// <summary>
 /// 发送一维字节数组
 /// </summary>
 /// <param name="segment"></param>
 public bool Send(System.Net.IPEndPoint iPEndPoint, ArraySegment <byte> segment)
 {
     try
     {
         var sessions = socketServer.GetSessions(a => a.RemoteEndPoint.ToString() == iPEndPoint.ToString());
         if (Equals(sessions, null) || !sessions.Any())
         {
             LogHelper.Logger.Info($"未找到客户端:{iPEndPoint.ToString()},发送消息失败!");
             return(false);
         }
         else
         {
             sessions.FirstOrDefault()?.Send(segment);
             return(true);
         }
     }
     catch (Exception ex)
     {
         LogHelper.Logger.Error($"给客户端:{iPEndPoint.ToString()}发送消息时错误,segment Count:{segment.Count()}", ex);
         return(false);
     }
 }