Example #1
0
        private void CheckRule5(NetworkComponent component)
        {
            HashSet <String> VisitedNodes = new HashSet <string>();

            VisitedNodes.Add(component.ID);
            List <NetworkComponent> list = GetNodeEdges(component, new HashSet <int>()
            {
                Constants.FIREWALL
            });

            foreach (NetworkComponent info in list)
            {
                String componentName = "unnamed";
                if (!String.IsNullOrWhiteSpace(component.ComponentName))
                {
                    componentName = component.ComponentName;
                }

                String endComponentName = "unnamed";
                if (!String.IsNullOrWhiteSpace(info.ComponentName))
                {
                    endComponentName = info.ComponentName;
                }

                String text = String.Format(rule5, componentName, endComponentName);
                SetLineMessage(component, info, text);
            }
        }
Example #2
0
    private bool AddComponentDataOnEntityAdded <T>(ref Entity entity, out NetworkComponent componentDataContainer) where T : struct, IComponentData
    {
        componentDataContainer = null;
        if (EntityManager.HasComponent <T>(entity))
        {
            ComponentType     componentType     = ComponentType.Create <T>();
            int               numberOfMembers   = reflectionUtility.GetFieldsCount(componentType.GetManagedType());
            Entity            networkDataEntity = networkFactory.CreateNetworkComponentData <T>(entity, numberOfMembers);
            NativeArray <int> values            = networkFactory.NetworkEntityManager.GetFixedArray <int>(networkDataEntity);
            PostUpdateCommands.AddComponent(entity, new NetworkComponentState <T>());

            T component = EntityManager.GetComponentData <T>(entity);
            NetworkField[]        networkMemberInfos   = reflectionUtility.GetFields(componentType);
            List <ComponentField> memberDataContainers = new List <ComponentField>();
            for (int i = 0; i < numberOfMembers; i++)
            {
                int value = (networkMemberInfos[i] as NetworkField <T>).GetValue(component);
                memberDataContainers.Add(new ComponentField()
                {
                    Id    = i,
                    Value = value
                });
                values[i] = value;
            }

            componentDataContainer = new NetworkComponent()
            {
                TypeId = reflectionUtility.GetId(componentType),
                Fields = memberDataContainers
            };
            return(true);
        }
        return(false);
    }
Example #3
0
 protected Component(NetworkComponent block, T definition)
 {
     Log        = block.Core.Logger.CreateProxy(GetType());
     Block      = block.Entity as IMyCubeBlock;
     Definition = definition;
     Network    = block;
 }
Example #4
0
    bool GetComponentData <T>(ref Entity entity, out NetworkComponent componentDataContainer) where T : struct, IComponentData
    {
        componentDataContainer = null;
        if (EntityManager.HasComponent <T>(entity))
        {
            ComponentType componentType   = ComponentType.Create <T>();
            int           numberOfMembers = reflectionUtility.GetFieldsCount(componentType.GetManagedType());

            T component = EntityManager.GetComponentData <T>(entity);
            NetworkField[]        networkMemberInfos   = reflectionUtility.GetFields(componentType);
            List <ComponentField> memberDataContainers = new List <ComponentField>();
            for (int i = 0; i < numberOfMembers; i++)
            {
                memberDataContainers.Add(new ComponentField()
                {
                    Id    = i,
                    Value = (networkMemberInfos[i] as NetworkField <T>).GetValue(component)
                });
            }


            componentDataContainer = new NetworkComponent()
            {
                TypeId = reflectionUtility.GetId(componentType),
                Fields = memberDataContainers
            };
            return(true);
        }
        return(false);
    }
Example #5
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            serializedObject.Update();

            NetworkComponent t = (NetworkComponent)target;

            EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
            {
                m_NetworkHelperInfo.Draw();

                EditorGUILayout.PropertyField(m_NetworkChannels, true);
            }
            EditorGUI.EndDisabledGroup();

            if (EditorApplication.isPlaying && PrefabUtility.GetPrefabType(t.gameObject) != PrefabType.Prefab)
            {
                EditorGUILayout.LabelField("Network Channel Count", t.NetworkChannelCount.ToString());

                INetworkChannel[] networkChannels = t.GetAllNetworkChannels();
                foreach (INetworkChannel networkChannel in networkChannels)
                {
                    DrawNetworkChannel(networkChannel);
                }
            }

            serializedObject.ApplyModifiedProperties();

            Repaint();
        }
        private Dictionary <Guid, NetworkComponent> ProcessNodes(XmlNodeList cells)
        {
            Dictionary <Guid, NetworkComponent> nodesList = new Dictionary <Guid, NetworkComponent>();

            foreach (var c in cells)
            {
                var cell = (XmlElement)c;
                if (cell.HasAttribute("ComponentGuid"))
                {
                    //this seems problematic in that a component could be missing a type
                    NetworkComponent cn = new NetworkComponent();
                    foreach (XmlAttribute a in cell.Attributes)
                    {
                        cn.setValue(a.Name, a.Value);
                    }

                    cn.Parent_id = GetParentId(cell);

                    // determine the component type
                    int ctype = GetComponentType(cell);
                    if (ctype != 0)
                    {
                        cn.Component_Symbol_Id = ctype;
                    }
                    else
                    {
                        throw new Exception("Unrecognized component: " + cell.OuterXml);
                    }

                    nodesList.Add(cn.ComponentGuid, cn);
                }
            }
            return(nodesList);
        }
Example #7
0
        public async void Run()
        {
            Game.Scene.AddComponent <MessageDispatherComponent, AppType>(AppType.Client);
            ClientConfig     clientConfig     = Game.Scene.AddComponent <ClientConfigComponent>().Config;
            NetworkComponent networkComponent = Game.Scene.AddComponent <NetOuterComponent>();
            Session          session          = networkComponent.Get(clientConfig.Address);

            try
            {
                R2C_Login s2CLogin = await session.Call <C2R_Login, R2C_Login>(new C2R_Login { Account = "abcdef", Password = "******" });

                networkComponent.Remove(session.Id);

                // 连接Gate
                Log.Debug(MongoHelper.ToJson(s2CLogin));
                Session gateSession = networkComponent.Get(s2CLogin.Address);
                await gateSession.Call <C2G_LoginGate, G2C_LoginGate>(new C2G_LoginGate(s2CLogin.Key));

                Log.Info("连接Gate验证成功!");
            }
            catch (RpcException e)
            {
                Log.Error(e.ToString());
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
            }
        }
    static void Main()
    {
        NetworkComponent[] _updatedComponents = new NetworkComponent[2] {
            new NetworkComponent {
            }, new NetworkComponent {
            }
        };
        const string          XmlNamespace = "http://www.xxx.com/nis/componentsync";
        XmlAttributeOverrides ao           = new XmlAttributeOverrides();

        ao.Add(typeof(ComponentsMessage), new XmlAttributes {
            XmlRoot = new XmlRootAttribute("components")
            {
                Namespace = XmlNamespace
            },
            XmlType = new XmlTypeAttribute("components")
            {
                Namespace = XmlNamespace
            }
        });
        ao.Add(typeof(ComponentsMessage), "Components", new XmlAttributes {
            XmlElements =
            {
                new XmlElementAttribute("component")
            }
        });
        ComponentsMessage msg = new ComponentsMessage {
            Components = _updatedComponents
        };
        XmlSerializer serializer = new XmlSerializer(msg.GetType(), ao);

        serializer.Serialize(Console.Out, msg);
    }
Example #9
0
    private void AddedComponents <T>() where T : struct, IComponentData
    {
        ComponentType                  componentType = ComponentType.Create <T>();
        ComponentGroup                 group         = GetComponentGroup(ComponentType.Create <SyncState>(), componentType, ComponentType.Subtractive <NetworkComponentState <T> >(), ComponentType.Create <NetworktOwner>());
        ComponentDataArray <T>         components    = group.GetComponentDataArray <T>();
        ComponentDataArray <SyncState> networkSyncStateComponents = group.GetComponentDataArray <SyncState>();
        EntityArray entities = group.GetEntityArray();

        NetworkField[] networkMemberInfos = reflectionUtility.GetFields(componentType);

        for (int i = 0; i < entities.Length; i++)
        {
            SyncState        networkSyncState = networkSyncStateComponents[i];
            NetworkComponent componentData    = new NetworkComponent {
                TypeId = reflectionUtility.GetId(componentType)
            };

            T component = components[i];
            for (int j = 0; j < networkMemberInfos.Length; j++)
            {
                componentData.Fields.Add(new ComponentField {
                    Id    = j,
                    Value = (networkMemberInfos[j] as NetworkField <T>).GetValue(component),
                });
            }


            ownNetworkSendMessageUtility.AddComponent(entities[i], networkSyncState.actorId, networkSyncState.networkId, componentData);
            AllNetworkSendMessageUtility.AddComponent(entities[i], networkSyncState.actorId, networkSyncState.networkId, componentData);

            int numberOfMembers = reflectionUtility.GetFieldsCount(componentType.GetManagedType());
            networkFactory.CreateNetworkComponentData <T>(entities[i], numberOfMembers);
            PostUpdateCommands.AddComponent(entities[i], new NetworkComponentState <T>());
        }
    }
Example #10
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            if (!EditorApplication.isPlaying)
            {
                EditorGUILayout.HelpBox("Available during runtime only.", MessageType.Info);
                return;
            }

            NetworkComponent t = (NetworkComponent)target;

            if (IsPrefabInHierarchy(t.gameObject))
            {
                EditorGUILayout.LabelField("Network Channel Count", t.NetworkChannelCount.ToString());

                INetworkChannel[] networkChannels = t.GetAllNetworkChannels();
                foreach (INetworkChannel networkChannel in networkChannels)
                {
                    DrawNetworkChannel(networkChannel);
                }
            }

            Repaint();
        }
Example #11
0
        private void CheckRule6(NetworkLink link)
        {
            NetworkComponent headComponent = link.SourceComponent;
            NetworkComponent tailComponent = link.TargetComponent;

            if ((headComponent == null) || (tailComponent == null))
            {
                return;
            }
            if (link.Security == Constants.UnTrusted)
            {
                if (headComponent.IsFirewall || tailComponent.IsFirewall)
                {
                    //If there is firewall don't show message
                }
                else
                {
                    String headName = "unnamed";
                    if (!String.IsNullOrWhiteSpace(headComponent.ComponentName))
                    {
                        headName = headComponent.ComponentName;
                    }

                    String tailName = "unnamed";
                    if (!String.IsNullOrWhiteSpace(tailComponent.ComponentName))
                    {
                        tailName = tailComponent.ComponentName;
                    }

                    String text = String.Format(rule6, headName, tailName).Replace("\n", " ");
                    SetLineMessage(headComponent, tailComponent, text);
                }
            }
        }
Example #12
0
    public void Button()
    {
        string    portString = portInput.text;
        string    ipString   = ipInput.text;
        int       port;
        IPAddress ip;

        if (portString == string.Empty && ipString == string.Empty)
        {
            port = 7777;
            ip   = NetworkComponent.GetLocalIPAddress();
        }
        else
        {
            if (!int.TryParse(portString, out port))
            {
                Debug.LogWarning("portti meni vituix");
                return;
            }

            if (!IPAddress.TryParse(ipString, out ip))
            {
                Debug.LogWarning("ip meni vituix");
                return;
            }
        }

        client.StartClient(ip, port);
    }
Example #13
0
 internal HttpServiceHost(NetworkComponent <int, string> component, string baseAddress)
     : base(typeof(SoapComunicationService), new Uri(baseAddress))
 {
     foreach (var cd in this.ImplementedContracts.Values)
     {
         cd.Behaviors.Add(new HttpServiceInstanceProvider(component));
     }
 }
Example #14
0
        public static int GetOpCode(this NetworkComponent networkComponent, PacketType packetType, int packetId)
        {
            if (packetId < 0 || packetId > 0x00ffffff)
            {
                throw new GameFrameworkException("Packet id is invalid.");
            }

            return(((int)packetType << 24) | packetId);
        }
Example #15
0
        /// <summary>
        /// rewriting the rules to make more sense  NOTE the data flows in the direction of the arrow
        /// so for this one we need to determine orientation of the device
        /// we want to recurse up into the network from the connections and
        /// see if we can find some control system devices if we can
        /// then data should only flow out of the control system side of the data diode
        /// if we find control systems components on both sides we should warn and have the user resolve it.
        /// maybe we should popup a dialog to determine how to analyse the network
        ///
        /// ie if this is classified then data should flow in
        /// if this is control systems network it should flow out
        /// </summary>
        /// <param name="component"></param>
        private void CheckRule7(NetworkComponent component)
        {
            if (component.IsUnidirectional)
            {
                //determine the zone type of the zone the unidirectional device
                //is in if the zone is anything but classified information
                //should flow from high to low

                bool isHighToLow = true;
                //if it is a classified zone it should flow from low to high
                if (component.Zone != null)
                {
                    if (component.Zone.ZoneType == "Classified")
                    {
                        //must flow from low to high
                        isHighToLow = false;
                    }
                }
                //else must flow from high to low


                //look to see if the items connected are in the same zone
                //if they are not then start moving out
                //if items are not in my same zone
                foreach (NetworkComponent link in component.Connections)
                {
                    if (component.IsInSameZone(link))
                    {
                        continue;
                    }
                    bool isComponentConnectionValid  = true;
                    UNIVERSAL_SAL_LEVEL componentSal = sals[component.Zone.SAL.ToLower()];
                    UNIVERSAL_SAL_LEVEL targetSal    = sals[link.Zone.SAL.ToLower()];

                    if (isHighToLow)
                    {
                        isComponentConnectionValid = componentSal.Sal_Level_Order > targetSal.Sal_Level_Order;
                    }
                    else
                    {
                        isComponentConnectionValid = componentSal.Sal_Level_Order < targetSal.Sal_Level_Order;
                    }

                    String componentName = "unnamed";
                    if (!String.IsNullOrWhiteSpace(component.ComponentName))
                    {
                        componentName = component.ComponentName;
                    }

                    if (!isComponentConnectionValid)
                    {
                        String text = String.Format(rule7, componentName).Replace("\n", " ");
                        SetLineMessage(component, link, text);
                    }
                }
            }
        }
Example #16
0
        protected List <NetworkComponent> GetNodeEdges(NetworkComponent component, HashSet <int> typeNodes, HashSet <string> SetVisted = null)
        {
            SetVisted = SetVisted ?? new HashSet <String>();
            SetVisted.Add(component.ID);
            List <NetworkComponent> listInfo = new List <NetworkComponent>();

            GetNodeInfoRecursive(ref listInfo, typeNodes, SetVisted, component);
            return(listInfo);
        }
Example #17
0
        private UDPClient m_UDPClient02;             //UDP网络实例


        private void Start()
        {
            m_NetworkComponent = GameBox.GetComponent <NetworkComponent>();
            m_UDPServer        = m_NetworkComponent.CreateNetwork <UDPServer>("服务端", "127.0.0.1", 6666);
            m_UDPClient01      = m_NetworkComponent.CreateNetwork <UDPClient>("客户端01", "127.0.0.1", 6666);
            m_UDPClient02      = m_NetworkComponent.CreateNetwork <UDPClient>("客户端02", "127.0.0.1", 6666);

            m_NetworkComponent.NetworkEventHandler += M_NetworkComponent_NetworkEventHandler; //监听网络事件
            m_NetworkComponent.Register(this);
        }
        private void OnGUI()
        {
            if (!Application.isPlaying)
            {
                GUILayout.Label("请启动游戏!");
                return;
            }


            AppType reloadType = AppType.None;

            this.isAll = GUILayout.Toggle(this.isAll, "All");
            if (this.isAll)
            {
                for (int i = 0; i < this.isCheck.Length; ++i)
                {
                    this.isCheck[i] = true;
                }
            }

            for (int i = 0; i < this.serverTypes.Count; ++i)
            {
                this.isCheck[i] = GUILayout.Toggle(this.isCheck[i], this.serverTypes[i].ToString());
                if (!this.isCheck[i])
                {
                    this.isAll = false;
                }
            }

            this.managerAddress = EditorGUILayout.TextField("Manager Address: ", this.managerAddress);

            if (GUILayout.Button("Reload"))
            {
                for (int i = 0; i < this.isCheck.Length; ++i)
                {
                    if (this.isCheck[i])
                    {
                        reloadType = reloadType | this.serverTypes[i];
                    }
                }
                NetworkComponent networkComponent = Game.Scene.GetComponent <NetOuterComponent>();
                Session          session          = networkComponent.Get($"{this.managerAddress}");
                try
                {
                    session.Call <C2M_Reload, M2C_Reload>(new C2M_Reload {
                        AppType = reloadType
                    });
                }
                catch (RpcException e)
                {
                    Log.Error(e.ToString());
                }
                Log.Info("Reload OK!");
            }
        }
Example #19
0
 private void sendEventToServer(EntityRef entity, Event @event)
 {
     if (networkSystem.Mode == NetworkMode.CLIENT)
     {
         NetworkComponent netComp = entity.getComponent(typeof(NetworkComponent));
         if (netComp != null)
         {
             networkSystem.Server.send(@event, entity);
         }
     }
 }
Example #20
0
 /// <summary>
 /// 连接游戏服
 /// </summary>
 /// <param name="networkComponent"></param>
 public static void ConnectGameChannel(this NetworkComponent networkComponent)
 {
     if (NetworkExtension.GameChannel != null)
     {
         NetworkExtension.GameChannel.Connect(IPAddress.Parse(NetworkExtension.GameServerIP), NetworkExtension.GameServerPort);
     }
     else
     {
         Log.Error("Please 'CreateNetworkChannel' first !!");
     }
 }
Example #21
0
 /// <summary>
 /// 发游戏消息
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="networkComponent"></param>
 /// <param name="packet"></param>
 public static void Send <T>(this NetworkComponent networkComponent, T packet) where T : CSPacketBase
 {
     if (NetworkExtension.GameChannel != null)
     {
         NetworkExtension.GameChannel.Send <T>(packet);
     }
     else
     {
         Log.Error("Please 'CreateNetworkChannel' first !!");
     }
 }
Example #22
0
 private bool CheckAddVisited(HashSet <String> visitedNodes, NetworkComponent otherComponent)
 {
     if (visitedNodes.Contains(otherComponent.ID))
     {
         return(true);
     }
     else
     {
         visitedNodes.Add(otherComponent.ID);
         return(false);
     }
 }
Example #23
0
        public void OnDestroy()
        {
            try
            {
                NetworkComponent?.Disconnect();
            }
            catch (Exception ex)
            {
                Logger.Get().Error("[GM] {error}", ex.Message);
            }

            Logger.OnDestroy();
        }
Example #24
0
        private Dictionary <Guid, NetworkComponent> lookupValue(Dictionary <Guid, NetworkComponent> sourcedictionary, Dictionary <Guid, NetworkComponent> destinationDictionary)
        {
            Dictionary <Guid, NetworkComponent> differences = new Dictionary <Guid, NetworkComponent>();

            foreach (KeyValuePair <Guid, NetworkComponent> g in sourcedictionary)
            {
                NetworkComponent ignoreme = null;
                if (!destinationDictionary.TryGetValue(g.Key, out ignoreme))
                {
                    differences.Add(g.Key, g.Value);
                }
            }
            return(differences);
        }
Example #25
0
        private void printNodeSimple(NetworkComponent top, int indent)
        {
            Trace.Write(new String('\t', indent));
            Trace.WriteLine("-->" + top.ID + ":" + top.ComponentName);
            int nextIndent = indent + 1;

            alreadySeenNodes.Add(top);
            foreach (NetworkComponent f in top.Connections)
            {
                if (!alreadySeenNodes.Contains(f))
                {
                    printNode(f, nextIndent);
                }
            }
        }
Example #26
0
        public void ConnectToCommunicationServer(INetworkComponent mockedNetworkComponent = null)
        {
            NetworkComponent = mockedNetworkComponent != null
                ? mockedNetworkComponent
                : new ClientNetworkComponent(Configuration.CsIP, Configuration.CsPort);

            if (!NetworkComponent.Connect(ClientType.GameMaster))
            {
                throw new ApplicationException("Unable to connect to CS");
            }

            Logger.Get().Info("[GM] Connected to Communication Server");
            state = GameMasterState.ConnectingAgents;
            currentMessageProcessor = ConnectionLogic;
        }
Example #27
0
 private void sendEventToOwner(EntityRef entity, Event @event)
 {
     if (networkSystem.Mode.Server)
     {
         NetworkComponent netComp = entity.getComponent(typeof(NetworkComponent));
         if (netComp != null)
         {
             Client client = networkSystem.getOwner(entity);
             if (client != null)
             {
                 client.send(@event, entity);
             }
         }
     }
 }
Example #28
0
    public override void processOnGrid(NetworkComponent network)
    {
        //Debug.Log ("Chicken Testing: "+type.ToString());
        //Search through all connections and see how many are resources
        //Debug.Log ("Looking for Turrets");

        foreach (GameObject go in network.connections)
        {
            NetworkComponent nC = go.GetComponent <NetworkComponent> ();
            //Debug.Log ("Network Type: "+nC.type);
            if (go.GetComponent <turret>() != null)
            {
                go.GetComponent <turret>().boost = 1f;
            }
        }
    }
Example #29
0
    public override void processOnGrid(NetworkComponent network)
    {
        foreach (GameObject go in network.fullNetwork)
        {
            if (go.GetComponent <Module> () != null)
            {
                //Debug.Log ("Activating "+ go.GetComponent<Module>().ToString());

                if (go.GetComponent <Module> () is CommandModule)
                {
                    //Debug.Log ("Skipping");
                    continue;
                }
                go.GetComponent <Module> ().processOnGrid(go.GetComponent <NetworkComponent>());
            }
        }
    }
Example #30
0
 public void SendMessage(BaseMessage message)
 {
     try
     {
         NetworkComponent.SendMessage(message);
     }
     catch (CommunicationErrorException e)
     {
         if (e.Type == CommunicationExceptionType.InvalidSocket)
         {
             SetCriticalException(e);
         }
         else
         {
             Logger.Get().Error("[GM] Exception occured: {ex}", e.Message);
         }
     }
 }