예제 #1
0
    /// <summary>
    /// Create a new group for computers to be added to
    /// </summary>
    /// <param name="ipToCheck"></param>
    private void MakeNewGroup(int ipToCheck, int groupIPFirstThree)
    {
        // Instatiate a new instance of a group, and set it equal to temp so we can access it
        temp = (GameObject)Instantiate(groupPrefab, transform.position, Quaternion.identity);

        // Parent the object to the manager, so that we can scale it
        temp.transform.parent = this.transform;

        // If it doesnt fit then we have to make a new group object
        newGroup = temp.GetComponent <IPGroup>();

        // Set the group address to the first 3 numbers of the new IP
        newGroup.GroupAddress = groupIPFirstThree;

        // Set the position of this group to something random
        SetGroupPosition(temp);

        // Set the color of the group
        SetGroupColor(newGroup);

        // Add to the dictoinary of groups
        groupsDictionary.Add(groupIPFirstThree, newGroup);

        // Add the IP to that group
        newGroup.AddToGroup(ipToCheck);
    }
예제 #2
0
        /// <summary>
        /// 添加IP
        /// </summary>
        /// <param name="ip">IP地址</param>
        /// <param name="maskLevel">掩码位数(1-32)</param>
        /// <param name="rule">IP规则,可为null</param>
        public void Add(uint ip, int maskLevel, object rule)
        {
            if (maskLevel < 1 || maskLevel > 32)
                throw new ArgumentException("The value must between 1 and 32.", "maskLevel");

            int index = maskLevel - 1;
            var group = groups[index];
            if (group == null)
            {
                group = new IPGroup(IPHelper.GetMask(maskLevel));
                groups[index] = group;
            }

            group.Add(ip, rule);
        }
예제 #3
0
    /// <summary>
    /// This method will set the group color field to one
    /// of the random colors in thepossible colors array
    /// </summary>
    /// <param name="groupToColor"></param>
    private void SetGroupColor(IPGroup groupToColor)
    {
        // Check and make sure taht we actually have some colors
        if (possibleColors == null || possibleColors.Length == 0)
        {
            // Return if we dont
            return;
        }

        // See if we are looking at blue team address or not
        int whichBlueTeam = isBlueTeam(groupToColor.GroupAddress);
        int whichRedTeam  = IsRedTeam(groupToColor.GroupAddress);

        // Check if the IP is red team or blue
        if (whichRedTeam >= 0)
        {
            // This is a special team that we care about
            groupToColor.IsSpecialTeam = true;

            // Set the color to the red team specific color
            if (whichRedTeam >= redTeamColors.Length)
            {
                // Pick a random red team color
                groupToColor.GroupColor = redTeamColors[Random.Range(0, redTeamColors.Length)];
            }
            else
            {
                // Set it to a proper red team color
                groupToColor.GroupColor = redTeamColors[whichRedTeam];
            }
            return;
        }
        // This is blue team
        else if (whichBlueTeam >= 0)
        {
            // tell us that this is a special team that we care about
            groupToColor.IsSpecialTeam = true;

            // Set the color to the blue team specific color
            if (whichBlueTeam >= blueTeamColors.Length)
            {
                groupToColor.GroupColor = blueTeamColors[Random.Range(0, blueTeamColors.Length)];
            }
            else
            {
                groupToColor.GroupColor = blueTeamColors[whichBlueTeam];
            }

            return;
        }

        // If we only have one color
        else if (possibleColors.Length == 1)
        {
            // Set that color to the only one that we have
            groupToColor.GroupColor = possibleColors[0];
            // We are done so return
            return;
        }

        // Generate a random number that represents the index of possible color array
        int x = Random.Range(0, possibleColors.Length);

        // If this is the same as the last color used
        while (x == lastColorUsed)
        {
            // This is so that we never get the same color that we used last time
            x = Random.Range(0, possibleColors.Length);
        }

        // Set the group color to that
        groupToColor.GroupColor = possibleColors[x];

        // Store the last color that we used
        lastColorUsed = x;
    }