Example #1
0
    // Update is called once per frame
    void Update()
    {
        if ((Input.GetKeyDown(KeyCode.Space) || inAnimation || currTimeIdx < 0) && !queryActive)
        {
            currTimeIdx++;

            currTimeIdx = Math.Max(0, Math.Min(timeSlices.Length - 2, currTimeIdx));

            timelineScript.updateSliderPosition((float)currTimeIdx / (float)timeSlices.Length);

            getVals();

            UpdateActiveTimeRange();
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            for (int i = 0; i < 3; i++)
            {
                Debug.Log("Subnet " + (i + 1) + ": " + currNfIpsSeen[i].Count);
            }
        }


        if (queryActive)
        {
            long   ipNum;
            string ipAddress = "";
            int    numTimesSeen;
            int    statusVal;

            long   dstIpNum;
            string dstIpAddress;
            int    priorityVal;

            int idx;

            // int numLoaded = 0;
            double currTime = DateTime.Now.TimeOfDay.TotalMilliseconds;
            double maxTime  = currTime + iterTimeOffset;

            ipDataStruct  tmpNfValue  = new ipDataStruct();
            bbDataStruct  tmpBbValue  = new bbDataStruct();
            ipsDataStruct tmpIPSValue = new ipsDataStruct();

            bool foundInSubnet = false;

            while (currTime < maxTime && hasResultSets)
            {
                if (currDbDataType == dbDataType.NETWORK_FLOW)
                {
                    while (dataReader.Read())
                    {
                        try
                        {
                            ipAddress    = dataReader.GetString(0);
                            ipNum        = dataReader.GetInt64(1);
                            numTimesSeen = dataReader.GetInt32(2);

                            foundInSubnet = false;

                            for (idx = 0; idx < 3; idx++)
                            {
                                if (ipNum <= maxSubnetIpNum[idx] && ipNum >= minSubnetIpNum[idx])
                                {
                                    //nextIpsSeen[idx].



                                    if (!nextNfIpsSeen[idx].TryGetValue(ipNum, out tmpNfValue))
                                    {
                                        tmpNfValue              = new ipDataStruct();
                                        tmpNfValue.ipAddress    = ipAddress;
                                        tmpNfValue.numTimesSeen = numTimesSeen;
                                        nextNfIpsSeen[idx].Add(ipNum, tmpNfValue);
                                    }
                                    else
                                    {
                                        tmpNfValue.numTimesSeen += numTimesSeen;
                                    }

                                    foundInSubnet = true;

                                    break;
                                }
                            }



                            if (!foundInSubnet)
                            {
                                tmpNfValue           = new ipDataStruct();
                                tmpNfValue.ipAddress = ipAddress;
                                outOfNetIpsSeen.Add(ipNum, tmpNfValue);
                            }
                        }

                        catch (System.InvalidCastException e)
                        {
                            Debug.Log(e);
                        }

                        currTime = DateTime.Now.TimeOfDay.TotalMilliseconds;

                        if (currTime >= maxTime)
                        {
                            break;
                        }
                    }
                }
                else if (currDbDataType == dbDataType.BIG_BROTHER)
                {
                    while (dataReader.Read())
                    {
                        try
                        {
                            ipAddress = dataReader.GetString(0);

                            if (ipAddress == null || ipAddress.Length < 7)
                            {
                                continue;
                            }

                            ipNum     = dataReader.GetInt64(1);
                            statusVal = dataReader.GetInt32(2);

                            for (idx = 0; idx < 3; idx++)
                            {
                                if (ipNum <= maxSubnetIpNum[idx] && ipNum >= minSubnetIpNum[idx])
                                {
                                    //nextIpsSeen[idx].

                                    if (!nextBbIpsSeen[idx].TryGetValue(ipNum, out tmpBbValue))
                                    {
                                        tmpBbValue           = new bbDataStruct();
                                        tmpBbValue.ipAddress = ipAddress;
                                        tmpBbValue.status    = statusVal;
                                        nextBbIpsSeen[idx].Add(ipNum, tmpBbValue);
                                    }
                                    else
                                    {
                                        if (statusVal > tmpBbValue.status)
                                        {
                                            tmpBbValue.status = statusVal;
                                        }
                                    }
                                    break;
                                }
                            }
                        }

                        catch (System.InvalidCastException e)
                        {
                            Debug.Log(e.Message + " for ip/time: " + ipAddress + "/" + timeSlices[currTimeIdx]);
                        }

                        currTime = DateTime.Now.TimeOfDay.TotalMilliseconds;

                        if (currTime >= maxTime)
                        {
                            break;
                        }
                    }
                }
                else if (currDbDataType == dbDataType.INTRUSION_PROTECTION)
                {
                    while (dataReader.Read())
                    {
                        try
                        {
                            ipAddress    = dataReader.GetString(0);
                            ipNum        = dataReader.GetInt64(1);
                            dstIpAddress = dataReader.GetString(2);
                            dstIpNum     = dataReader.GetInt64(3);

                            priorityVal = dataReader.GetInt32(4);

                            for (idx = 0; idx < 3; idx++)
                            {
                                if (ipNum <= maxSubnetIpNum[idx] && ipNum >= minSubnetIpNum[idx])
                                {
                                    if (!nextIPSIpsSeen[idx].TryGetValue(ipNum, out tmpIPSValue))
                                    {
                                        tmpIPSValue           = new ipsDataStruct();
                                        tmpIPSValue.ipAddress = ipAddress;
                                        tmpIPSValue.priority  = priorityVal;
                                        nextIPSIpsSeen[idx].Add(ipNum, tmpIPSValue);
                                    }
                                    else
                                    {
                                        if (priorityVal > tmpIPSValue.priority)
                                        {
                                            tmpIPSValue.priority = priorityVal;
                                        }
                                    }

                                    break;
                                }
                            }

                            for (idx = 0; idx < 3; idx++)
                            {
                                if (dstIpNum <= maxSubnetIpNum[idx] && dstIpNum >= minSubnetIpNum[idx])
                                {
                                    if (!nextIPSIpsSeen[idx].TryGetValue(dstIpNum, out tmpIPSValue))
                                    {
                                        tmpIPSValue           = new ipsDataStruct();
                                        tmpIPSValue.ipAddress = dstIpAddress;
                                        tmpIPSValue.priority  = priorityVal;
                                        nextIPSIpsSeen[idx].Add(dstIpNum, tmpIPSValue);
                                    }
                                    else
                                    {
                                        if (priorityVal > tmpIPSValue.priority)
                                        {
                                            tmpIPSValue.priority = priorityVal;
                                        }
                                    }

                                    break;
                                }
                            }
                        }

                        catch (System.InvalidCastException e)
                        {
                            Debug.Log(e.Message);
                        }

                        currTime = DateTime.Now.TimeOfDay.TotalMilliseconds;

                        if (currTime >= maxTime)
                        {
                            break;
                        }
                    }
                }

                if (currTime >= maxTime)
                {
                    break;
                }
                else if (dataReader.NextResult())
                {
                    if (currDbDataType == dbDataType.NETWORK_FLOW)
                    {
                        currDbDataType = dbDataType.BIG_BROTHER;
                    }
                    else if (currDbDataType == dbDataType.BIG_BROTHER)
                    {
                        currDbDataType = dbDataType.INTRUSION_PROTECTION;
                    }
                    continue;
                }
                else
                {
                    hasResultSets = false;
                }
            }

            if (!hasResultSets)
            {
                queryActive = false;

                queryEndTime = DateTime.Now.TimeOfDay;

                for (int i = 0; i < subnetObjects.Length; i++)
                {
                    currNfIpsSeen[i].Clear();
                    currBbIpsSeen[i].Clear();
                    currIPSIpsSeen[i].Clear();

                    currNfIpsSeen[i]  = nextNfIpsSeen[i];
                    currBbIpsSeen[i]  = nextBbIpsSeen[i];
                    currIPSIpsSeen[i] = nextIPSIpsSeen[i];

                    subnetMappings[i].activateNodes(nextNfIpsSeen[i]);
                    subnetMappings[i].activateBBNodes(nextBbIpsSeen[i]);
                    subnetMappings[i].activateIPSNodes(nextIPSIpsSeen[i]);
                }
            }
        }
    }
Example #2
0
    void updateControllerStates()
    {
        bool stateIsValid = vrSystem.GetControllerState((uint)index, ref state);

        if (stateIsValid && state.GetHashCode() != prevState.GetHashCode())
        {
            if ((state.ulButtonPressed & SteamVR_Controller.ButtonMask.ApplicationMenu) != 0 &&
                (prevState.ulButtonPressed & SteamVR_Controller.ButtonMask.ApplicationMenu) == 0)
            {
                // hit the menu button
                if (hasController)
                {
                    releaseController();
                }
                else
                {
                    hasController = true;
                    otherControllerScript.releaseController();
                    timelineGameObject.SetActive(true);
                    timelineGameObject.transform.SetParent(gameObject.transform);
                    timelineGameObject.transform.localPosition = new Vector3(0.0f, 0.0f, 0.1f);
                    timelineGameObject.transform.localRotation = Quaternion.Euler(90.0f, 0.0f, 0.0f);
                }
            }


            if ((state.ulButtonPressed & SteamVR_Controller.ButtonMask.Grip) != 0 &&
                (prevState.ulButtonPressed & SteamVR_Controller.ButtonMask.Grip) == 0)
            {
                // hit the grip button
                gripPressed = true;

                if (otherControllerScript.isGripPressed())
                {
                    accordianManager.deactivate();
                    scaleTimeline = true;
                    currSliderScript.startScale(transform.position, otherController.transform.position);
                }
                else
                {
                    Vector3 dir = transform.forward - transform.up;
                    dir.y = 0.0f;
                    dir.Normalize();
                    Vector3 pos = transform.position;

                    // shoot a ray and see if the controller is pointed at the timeline

                    RaycastHit hitInfo;

                    // try for timeline slider
                    if (Physics.Raycast(deviceRay.origin, deviceRay.direction, out hitInfo, 30.0f, sliderMask))
                    {
                        accordianManager.setAccordianType(AccordianActionType.TIMELINE);
                    }
                    else
                    {
                        accordianManager.setAccordianType(AccordianActionType.SUBNETS);
                    }

                    accordianManager.activate(pos, dir);
                }
            }

            else if ((state.ulButtonPressed & SteamVR_Controller.ButtonMask.Grip) == 0 &&
                     (prevState.ulButtonPressed & SteamVR_Controller.ButtonMask.Grip) != 0)
            {
                gripPressed = false;
                currSliderScript.endScale();
                scaleTimeline = false;
                accordianManager.deactivate();
            }



            // trigger is being pressed
            if ((state.ulButtonPressed & SteamVR_Controller.ButtonMask.Trigger) != 0)
            {
                // trigger completely pressed
                if (prevState.rAxis1.x < 1.0f && state.rAxis1.x >= 1.0f)
                {
                    handleTriggerClick();
                }
                // trigger released from completely pressed
                else if (state.rAxis1.x < 1.0f && prevState.rAxis1.x >= 1.0f)
                {
                    handleTriggerUnclick();
                }
            }

            if ((state.ulButtonPressed & SteamVR_Controller.ButtonMask.Touchpad) != 0 &&
                (prevState.ulButtonPressed & SteamVR_Controller.ButtonMask.Touchpad) == 0)
            {
                if (Mathf.Abs(state.rAxis0.y) >= Mathf.Abs(state.rAxis0.x) && state.rAxis0.y < 0.0f)
                {
                    togglePlayAnimation();
                    otherControllerScript.togglePlayAnimation();
                }
                else
                {
                    int currTime = sqlConnClass.getTimeSliceIdx();
                    if (state.rAxis0.x < 0.0f)
                    {
                        sqlConnClass.setTimeSlice(currTime - 1);
                    }
                    else if (state.rAxis0.x > 0.0f)
                    {
                        sqlConnClass.setTimeSlice(currTime + 1);
                    }

                    float currPos = sqlConnClass.getTimeSliceFloat();
                    currSliderScript.updateSliderPosition(currPos);
                }
            }


            prevState = state;
        }


        if ((state.ulButtonPressed & SteamVR_Controller.ButtonMask.Grip) != 0)
        {
            accordianManager.tryToAdjustDistance(transform.position);
        }
    }