Exemple #1
0
        public async Task <List <NetworkClass> > GetNetworkGroupsAsync(ContentURI uri)
        {
            Helpers.SqlIOAsync sqlIO = new Helpers.SqlIOAsync(uri);
            SqlDataReader      networkGroups
                = await sqlIO.RunProcAsync("0GetNetworkGroups");

            List <NetworkClass> colNetworkGroups = new List <NetworkClass>();

            if (networkGroups != null)
            {
                //build a related service list to return to the client
                while (networkGroups.Read())
                {
                    NetworkClass newNetworkGroup = new NetworkClass();
                    newNetworkGroup.PKId = networkGroups.GetInt32(0);
                    newNetworkGroup.NetworkClassLabel          = networkGroups.GetString(1);
                    newNetworkGroup.NetworkClassName           = networkGroups.GetString(2);
                    newNetworkGroup.NetworkClassDesc           = networkGroups.GetString(3);
                    newNetworkGroup.NetworkClassControllerName = networkGroups.GetString(4);
                    newNetworkGroup.NetworkClassUserLanguage   = networkGroups.GetString(5);
                    newNetworkGroup.Network    = new List <Network>();
                    newNetworkGroup.IsSelected = false;
                    colNetworkGroups.Add(newNetworkGroup);
                }
            }
            sqlIO.Dispose();
            return(colNetworkGroups);
        }
Exemple #2
0
        /// <summary>
        /// Create request wrapper
        /// </summary>
        /// <param name="request"></param>
        /// <param name="networkClass"></param>
        public DiscoveryRequest(DiscoveryRequestModel request,
                                NetworkClass networkClass = NetworkClass.Wired)
        {
            Request      = request?.Clone() ?? throw new ArgumentNullException(nameof(request));
            NetworkClass = networkClass;

            if (!string.IsNullOrEmpty(request.Configuration?.AddressRangesToScan))
            {
                if (AddressRange.TryParse(request.Configuration?.AddressRangesToScan,
                                          out var addresses))
                {
                    AddressRanges = addresses;
                }
            }

            if (AddressRanges == null)
            {
                if (request.Discovery == DiscoveryMode.Fast)
                {
                    var interfaces = NetworkInformationEx.GetAllNetInterfaces(NetworkClass.Wired);
                    AddressRanges = interfaces.Select(t => new AddressRange(t, false, 24));
                    AddressRanges = AddressRanges.Concat(interfaces
                                                         .Where(t => t.Gateway != null &&
                                                                !t.Gateway.Equals(System.Net.IPAddress.Any) &&
                                                                !t.Gateway.Equals(System.Net.IPAddress.None))
                                                         .Select(i => new AddressRange(i.Gateway, 32)));
                }
            }

            if (!string.IsNullOrEmpty(request.Configuration?.PortRangesToScan))
            {
                if (PortRange.TryParse(request.Configuration?.PortRangesToScan,
                                       out var ports))
                {
                    PortRanges = ports;
                }
            }

            if (PortRanges == null)
            {
                switch (request.Discovery)
                {
                case DiscoveryMode.Local:
                    PortRanges = PortRange.All;
                    break;

                case DiscoveryMode.Fast:
                    PortRanges = PortRange.WellKnown;
                    break;

                case DiscoveryMode.Scan:
                    PortRanges = PortRange.Unassigned;
                    break;

                default:
                    PortRanges = PortRange.OpcUa;
                    break;
                }
            }
        }
        public async Task <List <NetworkClass> > GetNetworkGroupsAsync(SearchManager searcher,
                                                                       string networkGroupIsSelectedName)
        {
            List <NetworkClass> colNetworkGroups
                = await _repository.GetNetworkGroupsAsync(searcher.SearchResult);

            NetworkClass networkGroupSelected = colNetworkGroups.FirstOrDefault(
                ng => ng.NetworkClassControllerName == networkGroupIsSelectedName);

            if (networkGroupSelected != null)
            {
                networkGroupSelected.IsSelected = true;
            }
            else
            {
                //take the top one
                if (colNetworkGroups.Count > 0)
                {
                    networkGroupSelected = colNetworkGroups[0];
                }
                if (networkGroupSelected != null)
                {
                    networkGroupSelected.IsSelected = true;
                }
            }
            if (networkGroupSelected == null)
            {
                networkGroupSelected = new NetworkClass(true);
            }
            searcher.NetworkGroupSelected = networkGroupSelected;
            return(colNetworkGroups);
        }
 /// <summary>
 /// Create scanner
 /// </summary>
 /// <param name="logger"></param>
 /// <param name="replies"></param>
 /// <param name="local"></param>
 /// <param name="addresses"></param>
 /// <param name="netclass"></param>
 /// <param name="maxProbeCount"></param>
 /// <param name="timeout"></param>
 /// <param name="ct"></param>
 public NetworkScanner(ILogger logger, Action <NetworkScanner, PingReply> replies,
                       bool local, IEnumerable <AddressRange> addresses, NetworkClass netclass,
                       int?maxProbeCount, TimeSpan?timeout, CancellationToken ct)
 {
     _logger     = logger;
     _replies    = replies;
     _ct         = ct;
     _timeout    = timeout ?? kDefaultProbeTimeout;
     _completion = new TaskCompletionSource <bool>();
     _candidates = new List <uint>();
     if (addresses == null)
     {
         _addresses = NetworkInformationEx.GetAllNetInterfaces(netclass)
                      .Select(t => new AddressRange(t, local)).Distinct().ToList();
     }
     else
     {
         _addresses = addresses.Select(a => a.Copy()).Distinct().ToList();
     }
     _pings = CreatePings(local ? _addresses.Count + 1 :
                          maxProbeCount ?? kDefaultMaxProbeCount);
     // Start initial pings
     _logger.Information("Start scanning {addresses}...",
                         _addresses.Select(a => a.ToString()));
     foreach (var ping in _pings.ToList())
     {
         OnNextPing(ping);
     }
 }
Exemple #5
0
        /// <summary>
        /// Scan entire network
        /// </summary>
        /// <param name="services"></param>
        /// <param name="netclass"></param>
        /// <param name="ct"></param>
        public static async Task <IEnumerable <PingReply> > ScanAsync(
            this IScanServices services, NetworkClass netclass, CancellationToken ct)
        {
            var result = new List <PingReply>();
            await services.ScanAsync(reply => result.Add(reply), netclass, ct);

            return(result);
        }
 /// <summary>
 /// Create scanner
 /// </summary>
 /// <param name="replies"></param>
 /// <param name="local"></param>
 /// <param name="addresses"></param>
 /// <param name="netclass"></param>
 /// <param name="maxProbeCount"></param>
 /// <param name="timeout"></param>
 /// <param name="ct"></param>
 /// <returns></returns>
 public async Task ScanAsync(Action <PingReply> replies, bool local,
                             IEnumerable <AddressRange> addresses, NetworkClass netclass,
                             int?maxProbeCount, TimeSpan?timeout, CancellationToken ct)
 {
     using (var scanner = new NetworkScanner(_logger, (s, p) => replies(p),
                                             local, addresses, netclass, maxProbeCount, timeout, ct)) {
         await scanner.Completion;
     }
 }
        static SocketsApi()
        {
            //IF NODO => InteropHelper.RegisterDLLOrExcept("NativeIO.dll", "64422BB2-E864-4118-91A8-E969628DAFDF");
            InteropHelper.RegisterDLLOrExcept("NativeIO_Mango.dll", "7A6562DA-6941-4DEF-8975-D55C9AC213A8");

            var nc = new NetworkClass();

            m_netSocketInterface = nc as INetSockets;
            int iret = Initialize();

            Debug.WriteLine("Winsock Initialized: " + iret);
        }
        public void HUDAwake(On.RoR2.UI.HUD.orig_Awake orig, RoR2.UI.HUD self)
        {
            orig(self);
            NetworkClass.EnsureNetworking();
            Networking._instance.IsArtifactEnabled      = RunArtifactManager.instance.IsArtifactEnabled(ArtifactOfDoom.Transmutation.artifactIndex);
            Networking._instance.IsCalculationSacrifice = ArtifactOfDoomConfig.useArtifactOfSacrificeCalculation.Value;
            if (!Networking._instance.IsArtifactEnabled)
            {
                return;
            }

            HUDRoot = self.transform.root;


            MainExpBarStart();
        }
Exemple #9
0
 /// <summary>
 /// Get all interface addresses
 /// </summary>
 /// <param name="netclass"></param>
 /// <returns></returns>
 public static IEnumerable <NetInterface> GetAllNetInterfaces(
     NetworkClass netclass)
 {
     return(NetworkInterface.GetAllNetworkInterfaces()
            .Where(n =>
                   n.NetworkInterfaceType.IsInClass(netclass) &&
                   !n.Name.Contains("(DockerNAT)") &&
                   n.OperationalStatus == OperationalStatus.Up &&
                   n.GetIPProperties() != null)
            .SelectMany(n => n.GetIPProperties().UnicastAddresses
                        .Select(x => new NetInterface(n.Name, x.Address, x.IPv4Mask)))
            .Where(t =>
                   t.UnicastAddress.AddressFamily == AddressFamily.InterNetwork &&
                   !IPAddress.IsLoopback(t.UnicastAddress))
            .Distinct());
 }
Exemple #10
0
        /// <summary>
        /// Check whether the interface type fits the class
        /// </summary>
        /// <param name="type"></param>
        /// <param name="netclass"></param>
        /// <returns></returns>
        public static bool IsInClass(this NetworkInterfaceType type,
                                     NetworkClass netclass)
        {
            switch (type)
            {
            case NetworkInterfaceType.Ethernet:
            case NetworkInterfaceType.Ethernet3Megabit:
            case NetworkInterfaceType.GigabitEthernet:
            case NetworkInterfaceType.FastEthernetT:
            case NetworkInterfaceType.FastEthernetFx:
            case NetworkInterfaceType.Slip:
            case NetworkInterfaceType.IPOverAtm:
                return((netclass & NetworkClass.Wired) != 0);

            case NetworkInterfaceType.BasicIsdn:
            case NetworkInterfaceType.PrimaryIsdn:
            case NetworkInterfaceType.Isdn:
            case NetworkInterfaceType.GenericModem:
            case NetworkInterfaceType.AsymmetricDsl:
            case NetworkInterfaceType.SymmetricDsl:
            case NetworkInterfaceType.RateAdaptDsl:
            case NetworkInterfaceType.VeryHighSpeedDsl:
            case NetworkInterfaceType.MultiRateSymmetricDsl:
            case NetworkInterfaceType.Ppp:
                return((netclass & NetworkClass.Modem) != 0);

            case NetworkInterfaceType.Wireless80211:
            case NetworkInterfaceType.Wman:
            case NetworkInterfaceType.Wwanpp:
            case NetworkInterfaceType.Wwanpp2:
                return((netclass & NetworkClass.Wireless) != 0);

            case NetworkInterfaceType.Tunnel:
                return((netclass & NetworkClass.Tunnel) != 0);

            case NetworkInterfaceType.TokenRing:
            case NetworkInterfaceType.HighPerformanceSerialBus:
            case NetworkInterfaceType.Fddi:
            case NetworkInterfaceType.Atm:
            case NetworkInterfaceType.Loopback:
                return(false);
            }
            return(false);
        }
Exemple #11
0
    public void SetupConfig()
    {
        var artifactOfDoomNetworkingPrefab = new GameObject("ArtifactOfDoomNetworkingPrefab");

        artifactOfDoomNetworkingPrefab.AddComponent <NetworkIdentity>();

        //   prefabs = new List<GameObject>();
        //    prefabs.Add()
        //Resources.Load<GameObject>("ArtifactOfDoomNetworkingPrefab")
        NetworkClass.CentralNetworkObject = artifactOfDoomNetworkingPrefab.InstantiateClone("ArtifactOfDoomNetworking", true);


        NetworkClass.CentralNetworkObject.AddComponent <Networking>();

        On.RoR2.Networking.GameNetworkManager.OnServerAddPlayerInternal += (orig, self, conn, pcid, extraMsg) =>
        {
            orig(self, conn, pcid, extraMsg);
            NetworkClass.EnsureNetworking();
        };
    }
Exemple #12
0
 /// <summary>
 /// Get all interface addresses
 /// </summary>
 /// <param name="netclass"></param>
 /// <returns></returns>
 public static IEnumerable <NetInterface> GetAllNetInterfaces(
     NetworkClass netclass)
 {
     return(NetworkInterface.GetAllNetworkInterfaces()
            .Where(n =>
                   n.NetworkInterfaceType.IsInClass(netclass) &&
                   n.OperationalStatus == OperationalStatus.Up &&
                   n.GetIPProperties() != null)
            .SelectMany(n => n.GetIPProperties().UnicastAddresses
                        .Select(x => new NetInterface(n.Name,
                                                      n.GetPhysicalAddress(),
                                                      x.Address,
                                                      x.IPv4Mask,
                                                      n.GetIPProperties().GatewayAddresses.Count > 0 ?
                                                      n.GetIPProperties().GatewayAddresses[0].Address : null,
                                                      n.GetIPProperties().DnsSuffix,
                                                      n.GetIPProperties().DnsAddresses)))
            .Where(t =>
                   t.UnicastAddress.AddressFamily == AddressFamily.InterNetwork &&
                   !IPAddress.IsLoopback(t.UnicastAddress))
            .Distinct());
 }
Exemple #13
0
    public void TargetUpdateProgressBar(NetworkConnection target, string killedNeededEnemies)
    {
        NetworkClass.EnsureNetworking();

        if (killedNeededEnemies == null)
        {
            Debug.LogError("killedNeededEnemies == null");
        }
        if (!ArtifactOfDoomConfig.disableItemProgressBar.Value && !Networking._instance.IsCalculationSacrifice)
        {
            string[] stringkilledNeededEnemies = killedNeededEnemies.Split(',');
            if (stringkilledNeededEnemies == null)
            {
                Debug.LogError("stringkilledneededEnemies=null");
            }

            int enemiesKilled = Convert.ToInt32(stringkilledNeededEnemies[0]);
            int enemiesNeeded = Convert.ToInt32(stringkilledNeededEnemies[1]) + 2;


            double progress = (double)enemiesKilled / ((double)enemiesNeeded);

            if ((0.35f + (float)(progress * 0.3)) > 0.65f)
            {
                if (ArtifactOfDoomUI.itemGainBar.GetComponent <RectTransform>().anchorMax == null)
                {
                    Debug.LogError("itemGainBar.GetComponent<RectTransform>().anchorMax==null");
                }

                ArtifactOfDoomUI.itemGainBar.GetComponent <RectTransform>().anchorMax = new Vector2(0.65f, 0.06f);
            }
            else
            {
                ArtifactOfDoomUI.itemGainBar.GetComponent <RectTransform>().anchorMin = new Vector2(0.35f, 0.05f);

                ArtifactOfDoomUI.itemGainBar.GetComponent <RectTransform>().anchorMax = new Vector2(0.35f + (float)(progress * 0.3), 0.06f);
            }
        }
    }
Exemple #14
0
    public void TargetAddGainedItemsToPlayers(NetworkConnection target, string QueueGainedItemSpriteToString)
    {
        NetworkClass.EnsureNetworking();


        if (!ArtifactOfDoomConfig.disableSideBars.Value)
        {
            string[] QueueGainedItemSprite = QueueGainedItemSpriteToString.Split(' ');
            int      i = 0;
            foreach (var element in QueueGainedItemSprite)
            {
                if (element != "")
                {
                    if (ArtifactOfDoomUI.listGainedImages[i].GetComponent <Image>() == null)
                    {
                        ArtifactOfDoomUI.listGainedImages[i].AddComponent <Image>();
                    }
                    ArtifactOfDoomUI.listGainedImages[i].GetComponent <Image>().sprite = ItemCatalog.GetItemDef(ItemCatalog.FindItemIndex(element)).pickupIconSprite;
                    i++;
                }
            }
        }
    }
Exemple #15
0
 /// <summary>
 /// Create scanner
 /// </summary>
 /// <param name="services"></param>
 /// <param name="netclass"></param>
 /// <param name="local"></param>
 /// <param name="replies"></param>
 /// <param name="ct"></param>
 public static Task ScanAsync(this IScanServices services, Action <PingReply> replies,
                              bool local, NetworkClass netclass, CancellationToken ct) =>
 services.ScanAsync(replies, local, null, netclass, null, null, ct);
Exemple #16
0
 public void SetTCPPort(int tcpPort)
 {
     _hParams.IPPort    = tcpPort.ToString();
     _hParams.IPAddress = NetworkClass.getComputerIpAddress();
 }
        static SocketsApi()
        {
            //IF NODO => InteropHelper.RegisterDLLOrExcept("NativeIO.dll", "64422BB2-E864-4118-91A8-E969628DAFDF");
            InteropHelper.RegisterDLLOrExcept("NativeIO_Mango.dll", "7A6562DA-6941-4DEF-8975-D55C9AC213A8");

            var nc = new NetworkClass();
            m_netSocketInterface = nc as INetSockets;
            int iret = Initialize();
            Debug.WriteLine("Winsock Initialized: " + iret);
        }
Exemple #18
0
 public static void ServerEnsureNetworking()
 {
     NetworkClass.EnsureNetworking();
 }
Exemple #19
0
 /// <summary>
 /// Create scanner
 /// </summary>
 /// <param name="services"></param>
 /// <param name="netclass"></param>
 /// <param name="replies"></param>
 /// <param name="ct"></param>
 public static Task ScanAsync(this IScanServices services, Action <PingReply> replies,
                              NetworkClass netclass, CancellationToken ct)
 {
     return(services.ScanAsync(replies, false, null, netclass, null, null, ct));
 }
Exemple #20
0
        public FastConvert(String content)
        {
            Parsed = new NetworkClass();
            String[] lines = content.Split('\n');
            int      open  = 0;
            int      close = 0;
            bool     readingDeserialize = false;
            String   bloc = "";

            foreach (String line in lines)
            {
                if (readingDeserialize)
                {
                    if (line.Trim() == "{")
                    {
                        open++;
                    }
                    if (line.Trim() == "}")
                    {
                        close++;
                    }
                    bloc += line + "\n";
                    if (open == close)
                    {
                        break;
                    }
                }
                else if (SerializeFncReg.IsMatch(line))
                {
                    readingDeserialize = true;
                }
                else if (ClassDeclaration.IsMatch(line))
                {
                    Match m = ClassDeclaration.Match(line);
                    Parsed.Name   = m.Groups[1].Value;
                    Parsed.Parent = m.Groups[2].Value;
                }
                else if (ClassDeclarationSimple.IsMatch(line))
                {
                    Match m = ClassDeclarationSimple.Match(line);
                    Parsed.Name = m.Groups[1].Value;
                }
                else if (ProtocolId.IsMatch(line))
                {
                    Match m = ProtocolId.Match(line);
                    Parsed.Id = int.Parse(m.Groups[1].Value);
                }
            }
            bool useBw = false;

            Parsed.Fields         = ParseDeserializeBloc(bloc, out useBw);
            Parsed.UseByteWrapper = useBw;
            NetworkClassField last = null;

            foreach (NetworkClassField field in Parsed.Fields)
            {
                if (field.IsBoolean)
                {
                    field.IsLast = false;
                    last         = field;
                }
                field.ConvertNames();
            }
            if (last != null)
            {
                last.IsLast = true;
            }
        }
Exemple #21
0
 public void SetParams(HParams hParams)
 {
     _hParams           = hParams;
     _hParams.IPAddress = NetworkClass.getComputerIpAddress();
 }
Exemple #22
0
        private void Awake()
        {
            _logger = Logger;


            cfgFile = new ConfigFile(Path.Combine(Paths.ConfigPath, ModGuid + ".cfg"), true);
            ArtifactOfDoomUI artifactOfDoomUI = new ArtifactOfDoomUI();
            ArtifactOfDoom   artifactOfDoom   = new ArtifactOfDoom();
            NetworkClass     network          = new NetworkClass();

            averageItemsPerStage = cfgFile.Bind(new ConfigDefinition("Gameplay Settings", "averageItemsPerStage"), 3, new ConfigDescription(
                                                    "Base chance in percent that enemys steal items from you ((totalItems - currentStage * averageItemsPerStage) ^ exponentTriggerItems; \nIf that value is lower you'll need to kill more enemies to get an item"));
            exponentTriggerItems = cfgFile.Bind(new ConfigDefinition("Gameplay Settings", "exponentTriggerItems"), 2.0, new ConfigDescription(
                                                    "The exponent for calculation when you'll get an item. If it's 1 you have a linear increase. Default is 2"));

            minItemsPerStage = cfgFile.Bind(new ConfigDefinition("Gameplay Settings", "minItemsPerStage"), 2, new ConfigDescription(
                                                "The expected minimum item count per stage. If you have less Items than that you'll have a decreased chance that you lose items"));
            maxItemsPerStage = cfgFile.Bind(new ConfigDefinition("Gameplay Settings", "maxItemsPerStage"), 7, new ConfigDescription(
                                                "The expected maximum item count per stage. If you have more Items than that you'll have a chance to lose more than one item per hit"));
            exponentailFactorToCalculateSumOfLostItems = cfgFile.Bind(new ConfigDefinition("Gameplay Settings", "exponentailFactorToCalculateSumOfLostItems"), 1.5, new ConfigDescription(
                                                                          "The exponent to Calculate how many items you'll lose if you're over maxItemsPerStage"));
            exponentailFactorIfYouAreUnderAverageItemsPerStage = cfgFile.Bind(new ConfigDefinition("Gameplay Settings", "exponentailFactorIfYouAreUnderAverageItemsPerStage"), 0.0, new ConfigDescription(
                                                                                  "The exponent to Calculate how many kills you'll need if you're under averageItemsPerStage. The formula is totalitems^exponentailFactorIfYouAreUnderAverageItemsPerStage. Default is 0 so you'll need always two kills."));

            artifactOfSwarmNerf = cfgFile.Bind(new ConfigDefinition("Gameplay Settings", "artifactOfSwarmNerf"), false, new ConfigDescription(
                                                   "Enable the nerf for Artifact of Swarm where you've to kill double as many enemies"));

            useArtifactOfSacrificeCalculation = cfgFile.Bind(new ConfigDefinition("Gameplay Settings", "useArtifactOfSacreficeCalculation"), false, new ConfigDescription(
                                                                 "Chance the item gain to a specific drop rate of enemys"));
            multiplayerForArtifactOfSacrificeDropRate = cfgFile.Bind(new ConfigDefinition("Gameplay Settings", "multiplayerForArtifactOfSacrificeDropRate"), 2.0, new ConfigDescription(
                                                                         "Multiplier for the drop rate (base Chance is 5)"));

            disableItemProgressBar = cfgFile.Bind(new ConfigDefinition("UI Settings", "disableItemProgressBar"), false, new ConfigDescription(
                                                      "If true it disables the Progress bar in the bottom of the UI"));
            disableSideBars = cfgFile.Bind(new ConfigDefinition("UI Settings", "disableSideBars"), false, new ConfigDescription(
                                               "Disables the item Sidebars"));
            enableChatItemOutput = cfgFile.Bind(new ConfigDefinition("UI Settings", "enableChatItemOutput"), false, new ConfigDescription(
                                                    "Enables the chat output for gained/lost Items. This setting is not synced."));
            sizeOfSideBars = cfgFile.Bind(new ConfigDefinition("UI Settings", "sizeOfSideBars"), 0.02, new ConfigDescription(
                                              "Spezifies the size of the sidebars. 1 is whole window 0 is invisible (but for that plase use the disable setting)."));
            timeAfterHitToNotLoseItemDrizzly = cfgFile.Bind(new ConfigDefinition("Gameplay Settings", "timeAfterHitToNotLooseItemDrizzly"), 0.8, new ConfigDescription(
                                                                "The time in seconds where you will not lose items after you lost one on drizzly"));
            timeAfterHitToNotLoseItemRainstorm = cfgFile.Bind(new ConfigDefinition("Gameplay Settings", "timeAfterHitToNotLooseItemRainstorm"), 0.2, new ConfigDescription(
                                                                  "The time in seconds where you will not lose items after you lost one on rainstorm"));
            timeAfterHitToNotLoseItemMonsoon = cfgFile.Bind(new ConfigDefinition("Gameplay Settings", "timeAfterHitToNotLooseItemMonsoon"), 0.05, new ConfigDescription(
                                                                "The time in seconds where you will not lose items after you lost one on monsoon"));
            timeAfterHitToNotLoseItemOtherDifficulty = cfgFile.Bind(new ConfigDefinition("Gameplay Settings", "timeAfterHitToNotLooseOtherDifficulty"), "[{\"DifficultyIndex\": \"DIFFICULTYINDEX\", \"time\": 1.0}]", new ConfigDescription(
                                                                        "The time in seconds where you will not lose items after you lost one on monsoon"));


            CommandoBonusItems = cfgFile.Bind(new ConfigDefinition("Character specific settings", "CommandoBonusItems"), 1.0, new ConfigDescription(
                                                  "The count of items which you get if you kill enough enemies"));
            CommandoMultiplierForTimedBuff = cfgFile.Bind(new ConfigDefinition("Character specific settings", "commandoMultiplyerForTimedBuff"), 1.0, new ConfigDescription(
                                                              "The Multiplier for that specific character for the length of timeAfterHitToNotLooseItems"));
            HuntressBonusItems = cfgFile.Bind(new ConfigDefinition("Character specific settings", "HuntressBonusItems"), 1.0, new ConfigDescription(
                                                  "The count of items which you get if you kill enough enemies"));
            HuntressMultiplierForTimedBuff = cfgFile.Bind(new ConfigDefinition("Character specific settings", "HuntressMultiplierForTimedBuff"), 1.0, new ConfigDescription(
                                                              "The Multiplier for that specific character for the length of timeAfterHitToNotLooseItems"));
            MULTBonusItems = cfgFile.Bind(new ConfigDefinition("Character specific settings", "MULTBonusItems"), 1.0, new ConfigDescription(
                                              "The count of items which you get if you kill enough enemies"));
            MULTMultiplierForTimedBuff = cfgFile.Bind(new ConfigDefinition("Character specific settings", "MULTMultiplierForTimedBuff"), 1.0, new ConfigDescription(
                                                          "The Multiplier for that specific character for the length of timeAfterHitToNotLooseItems"));
            EngineerBonusItems = cfgFile.Bind(new ConfigDefinition("Character specific settings", "EngineerBonusItems"), 1.0, new ConfigDescription(
                                                  "The count of items which you get if you kill enough enemies"));
            EngineerMultiplierForTimedBuff = cfgFile.Bind(new ConfigDefinition("Character specific settings", "EngineerMultiplierForTimedBuff"), 1.0, new ConfigDescription(
                                                              "The Multiplier for that specific character for the length of timeAfterHitToNotLooseItems"));
            ArtificerBonusItems = cfgFile.Bind(new ConfigDefinition("Character specific settings", "ArtificerBonusItems"), 2.0, new ConfigDescription(
                                                   "The count of items which you get if you kill enough enemies"));
            ArtificerMultiplierForTimedBuff = cfgFile.Bind(new ConfigDefinition("Character specific settings", "ArtificerMultiplierForTimedBuff"), 1.0, new ConfigDescription(
                                                               "The Multiplier for that specific character for the length of timeAfterHitToNotLooseItems"));
            MercenaryBonusItems = cfgFile.Bind(new ConfigDefinition("Character specific settings", "MercenaryBonusItems"), 1.0, new ConfigDescription(
                                                   "The count of items which you get if you kill enough enemies"));
            MercenaryMultiplierForTimedBuff = cfgFile.Bind(new ConfigDefinition("Character specific settings", "MercenaryMultiplierForTimedBuff"), 4.0, new ConfigDescription(
                                                               "The Multiplier for that specific character for the length of timeAfterHitToNotLooseItems"));
            RexBonusItems = cfgFile.Bind(new ConfigDefinition("Character specific settings", "RexBonusItems"), 1.0, new ConfigDescription(
                                             "The count of items which you get if you kill enough enemies"));
            RexMultiplierForTimedBuff = cfgFile.Bind(new ConfigDefinition("Character specific settings", "RexMultiplierForTimedBuff"), 1.0, new ConfigDescription(
                                                         "The Multiplier for that specific character for the length of timeAfterHitToNotLooseItems"));
            LoaderBonusItems = cfgFile.Bind(new ConfigDefinition("Character specific settings", "LoaderBonusItems"), 1.0, new ConfigDescription(
                                                "The count of items which you get if you kill enough enemies"));
            LoaderMultiplierForTimedBuff = cfgFile.Bind(new ConfigDefinition("Character specific settings", "LoaderMultiplierForTimedBuff"), 4.0, new ConfigDescription(
                                                            "The Multiplier for that specific character for the length of timeAfterHitToNotLooseItems"));
            AcridBonusItems = cfgFile.Bind(new ConfigDefinition("Character specific settings", "AcridBonusItems"), 1.0, new ConfigDescription(
                                               "The count of items which you get if you kill enough enemies"));
            AcridMultiplierForTimedBuff = cfgFile.Bind(new ConfigDefinition("Character specific settings", "AcridMultiplierForTimedBuff"), 4.0, new ConfigDescription(
                                                           "The Multiplier for that specific character for the length of timeAfterHitToNotLooseItems"));
            CaptainBonusItems = cfgFile.Bind(new ConfigDefinition("Character specific settings", "CaptainBonusItems"), 1.0, new ConfigDescription(
                                                 "The count of items which you get if you kill enough enemies"));
            CaptainMultiplierForTimedBuff = cfgFile.Bind(new ConfigDefinition("Character specific settings", "BanditMultiplierForTimedBuff"), 1.0, new ConfigDescription(
                                                             "The Multiplier for that specific character for the length of timeAfterHitToNotLooseItems"));
            BanditBonusItems = cfgFile.Bind(new ConfigDefinition("Character specific settings", "BanditBonusItems"), 1.0, new ConfigDescription(
                                                "The count of items which you get if you kill enough enemies"));
            BanditMultiplierForTimedBuff = cfgFile.Bind(new ConfigDefinition("Character specific settings", "BanditMultiplierForTimedBuff"), 1.0, new ConfigDescription(
                                                            "The Multiplier for that specific character for the length of timeAfterHitToNotLooseItems"));
            CustomSurvivorBonusItems = cfgFile.Bind(new ConfigDefinition("Character specific settings", "CustomSurvivorBonusItems"), 1.0, new ConfigDescription(
                                                        "The count of items which you get if you kill enough enemies"));
            CustomSurvivorMultiplierForTimedBuff = cfgFile.Bind(new ConfigDefinition("Character specific settings", "CustomSurvivorMultiplierForTimedBuff"), 1.0, new ConfigDescription(
                                                                    "The Multiplier for that specific character for the length of timeAfterHitToNotLoseItems"));
            CustomChars = cfgFile.Bind(new ConfigDefinition("Character specific settings", "CustomCharacters"), "[{\"Name\": \"CUSTOM_CHAR_BODY_NAME1\", \"MultiplierForTimedBuff\": 1.0, \"BonusItems\": 1.0},{\"Name\": \"CUSTOM_CHAR_BODY_NAME2\", \"MultiplierForTimedBuff\": 2.0, \"BonusItems\": 2.0}]", new ConfigDescription(
                                           "The Multiplier for that specific character for the length of timeAfterHitToNotLoseItems"));



            ArtifactOfDoomBuff.name      = "ArtifactOfDoomDidLoseItem";
            ArtifactOfDoomBuff.buffColor = Color.black;
            ArtifactOfDoomBuff.canStack  = false;
            ArtifactOfDoomBuff.isDebuff  = false;
            ArtifactAPI.Add(ArtifactOfDoom.Transmutation);

            BuffAPI.Add(new CustomBuff(ArtifactOfDoomBuff));



            On.RoR2.ContentManagement.ContentManager.SetContentPacks += ContentManager_SetContentPacks;
            //On.RoR2.ContentManager.SetContentPacks += ContentManager_SetContentPacks;
        }
 /// <summary>
 /// Create scanner
 /// </summary>
 /// <param name="logger"></param>
 /// <param name="replies"></param>
 /// <param name="local"></param>
 /// <param name="netclass"></param>
 /// <param name="ct"></param>
 public NetworkScanner(ILogger logger, Action <NetworkScanner, PingReply> replies,
                       bool local, NetworkClass netclass, CancellationToken ct) :
     this(logger, replies, local, null, netclass, null, null, ct)
 {
 }
 /// <summary>
 /// Create scanner
 /// </summary>
 /// <param name="logger"></param>
 /// <param name="replies"></param>
 /// <param name="netclass"></param>
 /// <param name="ct"></param>
 public NetworkScanner(ILogger logger, Action <PingReply> replies,
                       NetworkClass netclass, CancellationToken ct) :
     this(logger, replies, false, null, netclass, null, null, ct)
 {
 }
        /// <summary>
        /// Create request wrapper
        /// </summary>
        /// <param name="request"></param>
        /// <param name="networkClass"></param>
        /// <param name="isScan"></param>
        public DiscoveryRequest(DiscoveryRequestModel request,
                                NetworkClass networkClass = NetworkClass.Wired, bool isScan = false)
        {
            Request      = request?.Clone() ?? throw new ArgumentNullException(nameof(request));
            _cts         = new CancellationTokenSource();
            NetworkClass = networkClass;
            IsScan       = isScan;

            if (Request.Configuration == null)
            {
                Request.Configuration = new DiscoveryConfigModel();
            }

            if (Request.Discovery == null ||
                Request.Discovery == DiscoveryMode.Off)
            {
                // Report empty configuration if off, but keep the
                // discovery urls details from the original request
                Request.Configuration = new DiscoveryConfigModel()
                {
                    ActivationFilter = Request.Configuration.ActivationFilter?.Clone(),
                    DiscoveryUrls    = Request.Configuration.DiscoveryUrls?.ToList(),
                    Locales          = Request.Configuration.Locales?.ToList()
                };
                Request.Discovery = DiscoveryMode.Off;
                return;
            }

            // Parse whatever provided

            if (!string.IsNullOrEmpty(Request.Configuration.PortRangesToScan))
            {
                if (PortRange.TryParse(Request.Configuration.PortRangesToScan,
                                       out var ports))
                {
                    PortRanges = ports;
                    if (Request.Discovery == null)
                    {
                        Request.Discovery = DiscoveryMode.Fast;
                    }
                }
            }

            if (!string.IsNullOrEmpty(Request.Configuration.AddressRangesToScan))
            {
                if (AddressRange.TryParse(Request.Configuration.AddressRangesToScan,
                                          out var addresses))
                {
                    AddressRanges = addresses;
                    if (Request.Discovery == null)
                    {
                        Request.Discovery = DiscoveryMode.Fast;
                    }
                }
            }

            // Set default ranges

            if (AddressRanges == null)
            {
                IEnumerable <NetInterface> interfaces;
                switch (Request.Discovery)
                {
                case DiscoveryMode.Local:
                    interfaces    = NetworkInformationEx.GetAllNetInterfaces(NetworkClass);
                    AddressRanges = AddLocalHost(interfaces
                                                 .Select(t => new AddressRange(t, true)))
                                    .Distinct();
                    break;

                case DiscoveryMode.Fast:
                    interfaces    = NetworkInformationEx.GetAllNetInterfaces(NetworkClass.Wired);
                    AddressRanges = AddLocalHost(interfaces
                                                 .Select(t => new AddressRange(t, false, 24))
                                                 .Concat(interfaces
                                                         .Where(t => t.Gateway != null &&
                                                                !t.Gateway.Equals(IPAddress.Any) &&
                                                                !t.Gateway.Equals(IPAddress.None))
                                                         .Select(i => new AddressRange(i.Gateway, 32)))
                                                 .Distinct());
                    break;

                case DiscoveryMode.Network:
                case DiscoveryMode.Scan:
                    interfaces    = NetworkInformationEx.GetAllNetInterfaces(NetworkClass);
                    AddressRanges = AddLocalHost(interfaces
                                                 .Select(t => new AddressRange(t, false))
                                                 .Concat(interfaces
                                                         .Where(t => t.Gateway != null &&
                                                                !t.Gateway.Equals(IPAddress.Any) &&
                                                                !t.Gateway.Equals(IPAddress.None))
                                                         .Select(i => new AddressRange(i.Gateway, 32)))
                                                 .Distinct());
                    break;

                case DiscoveryMode.Off:
                default:
                    AddressRanges = Enumerable.Empty <AddressRange>();
                    break;
                }
            }

            if (PortRanges == null)
            {
                switch (Request.Discovery)
                {
                case DiscoveryMode.Local:
                    PortRanges = PortRange.All;
                    break;

                case DiscoveryMode.Fast:
                    PortRanges = PortRange.WellKnown;
                    break;

                case DiscoveryMode.Scan:
                    PortRanges = PortRange.Unassigned;
                    break;

                case DiscoveryMode.Network:
                    PortRanges = PortRange.OpcUa;
                    break;

                case DiscoveryMode.Off:
                default:
                    PortRanges = Enumerable.Empty <PortRange>();
                    break;
                }
            }

            // Update reported configuration with used settings

            if (AddressRanges != null && AddressRanges.Any())
            {
                Request.Configuration.AddressRangesToScan = AddressRange.Format(AddressRanges);
                TotalAddresses = AddressRanges?.Sum(r => r.Count) ?? 0;
            }

            if (PortRanges != null && PortRanges.Any())
            {
                Request.Configuration.PortRangesToScan = PortRange.Format(PortRanges);
                TotalPorts = PortRanges?.Sum(r => r.Count) ?? 0;
            }

            Request.Configuration.IdleTimeBetweenScans ??= kDefaultIdleTime;
            Request.Configuration.PortProbeTimeout ??= kDefaultPortProbeTimeout;
            Request.Configuration.NetworkProbeTimeout ??= kDefaultNetworkProbeTimeout;
        }
Exemple #26
0
        /// <summary>
        /// Create request wrapper
        /// </summary>
        /// <param name="request"></param>
        /// <param name="networkClass"></param>
        /// <param name="isScan"></param>
        public DiscoveryRequest(DiscoveryRequestModel request,
                                NetworkClass networkClass = NetworkClass.Wired, bool isScan = false)
        {
            Request      = request?.Clone() ?? throw new ArgumentNullException(nameof(request));
            _cts         = new CancellationTokenSource();
            NetworkClass = networkClass;
            IsScan       = isScan;

            if (request == null)
            {
                request = new DiscoveryRequestModel {
                    Discovery = DiscoveryMode.Off
                };
            }
            if (request.Configuration == null)
            {
                request.Configuration = new DiscoveryConfigModel();
            }

            if (!string.IsNullOrEmpty(request.Configuration.AddressRangesToScan))
            {
                if (AddressRange.TryParse(request.Configuration.AddressRangesToScan,
                                          out var addresses))
                {
                    AddressRanges = addresses;
                }
            }

            if (AddressRanges == null)
            {
                switch (request.Discovery)
                {
                case DiscoveryMode.Local:
                    AddressRanges = NetworkInformationEx.GetAllNetInterfaces(NetworkClass)
                                    .Select(t => new AddressRange(t, true)).Distinct();
                    break;

                case DiscoveryMode.Fast:
                    var interfaces = NetworkInformationEx.GetAllNetInterfaces(NetworkClass.Wired);
                    AddressRanges = interfaces.Select(t => new AddressRange(t, false, 24));
                    AddressRanges = AddressRanges.Concat(interfaces
                                                         .Where(t => t.Gateway != null &&
                                                                !t.Gateway.Equals(System.Net.IPAddress.Any) &&
                                                                !t.Gateway.Equals(System.Net.IPAddress.None))
                                                         .Select(i => new AddressRange(i.Gateway, 32)));
                    break;

                case DiscoveryMode.Off:
                    AddressRanges = Enumerable.Empty <AddressRange>();
                    break;

                case DiscoveryMode.Scan:
                    AddressRanges = NetworkInformationEx.GetAllNetInterfaces(NetworkClass)
                                    .Select(t => new AddressRange(t, false)).Distinct();
                    break;

                default:
                    AddressRanges = Enumerable.Empty <AddressRange>();
                    break;
                }
            }

            request.Configuration.AddressRangesToScan = AddressRange.Format(AddressRanges);

            if (!string.IsNullOrEmpty(request.Configuration.PortRangesToScan))
            {
                if (PortRange.TryParse(request.Configuration.PortRangesToScan,
                                       out var ports))
                {
                    PortRanges = ports;
                }
            }

            if (PortRanges == null)
            {
                switch (request.Discovery)
                {
                case DiscoveryMode.Local:
                    PortRanges = PortRange.All;
                    break;

                case DiscoveryMode.Fast:
                    PortRanges = PortRange.WellKnown;
                    break;

                case DiscoveryMode.Scan:
                    PortRanges = PortRange.Unassigned;
                    break;

                case DiscoveryMode.Off:
                    PortRanges = Enumerable.Empty <PortRange>();
                    break;

                default:
                    PortRanges = PortRange.OpcUa;
                    break;
                }
            }

            request.Configuration.PortRangesToScan = PortRange.Format(PortRanges);
            request.Configuration.IdleTimeBetweenScans ??= kDefaultIdleTime;
            request.Configuration.PortProbeTimeout ??= kDefaultPortProbeTimeout;
            request.Configuration.NetworkProbeTimeout ??= kDefaultNetworkProbeTimeout;

            TotalAddresses = AddressRanges?.Sum(r => r.Count) ?? 0;
            TotalPorts     = PortRanges?.Sum(r => r.Count) ?? 0;
        }