Parcourir la source

Merge branch 'master' of http://47.122.5.112:3000/mojito/StarEscort

大爷 il y a 1 an
Parent
commit
0e478dbb82

+ 0 - 9
DotNet/Hotfix/DotNet.Hotfix.csproj

@@ -22,15 +22,6 @@
         <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     </PropertyGroup>
     <ItemGroup>
-        <Compile Include="..\..\Unity\Assets\Scripts\Codes\Hotfix\Client\Session\NetClientComponentOnReadEvent.cs">
-          <Link>Client\Session\NetClientComponentOnReadEvent.cs</Link>
-        </Compile>
-        <Compile Include="..\..\Unity\Assets\Scripts\Codes\Hotfix\Client\Session\NetClientComponentSystem.cs">
-          <Link>Client\Session\NetClientComponentSystem.cs</Link>
-        </Compile>
-        <Compile Include="..\..\Unity\Assets\Scripts\Codes\Hotfix\Client\Session\SessionComponentSystem.cs">
-          <Link>Client\Session\SessionComponentSystem.cs</Link>
-        </Compile>
         <Compile Include="..\..\Unity\Assets\Scripts\Codes\Hotfix\Share\**\*.cs">
             <Link>Share\%(RecursiveDir)%(FileName)%(Extension)</Link>
         </Compile>

+ 100 - 0
DotNet/Hotfix/Module/Message/NetClientComponentSystem.cs

@@ -0,0 +1,100 @@
+using System.Net;
+using System.Net.Sockets;
+
+namespace ET.Client
+{
+    [FriendOf(typeof(NetClientComponent))]
+    public static class NetClientComponentSystem
+    {
+        [ObjectSystem]
+        public class AwakeSystem: AwakeSystem<NetClientComponent, AddressFamily, NetworkProtocol>
+        {
+            protected override void Awake(NetClientComponent self, AddressFamily addressFamily, NetworkProtocol protocol)
+            {
+                switch (protocol)
+                {
+                    case NetworkProtocol.KCP:
+                    {
+                        self.ServiceId = NetServices.Instance.AddService(new KService(addressFamily, ServiceType.Outer));
+                        break;
+                    }
+                    case NetworkProtocol.TCP:
+                    {
+                        self.ServiceId = NetServices.Instance.AddService(new TService(addressFamily, ServiceType.Outer));
+                        break;
+                    }
+                }
+                NetServices.Instance.RegisterReadCallback(self.ServiceId, self.OnRead);
+                NetServices.Instance.RegisterErrorCallback(self.ServiceId, self.OnError);
+            }
+        }
+
+        [ObjectSystem]
+        public class DestroySystem: DestroySystem<NetClientComponent>
+        {
+            protected override void Destroy(NetClientComponent self)
+            {
+                NetServices.Instance.RemoveService(self.ServiceId);
+            }
+        }
+
+        private static void OnRead(this NetClientComponent self, long channelId, long actorId, object message)
+        {
+            Session session = self.GetChild<Session>(channelId);
+            if (session == null)
+            {
+                return;
+            }
+
+            session.LastRecvTime = TimeHelper.ClientNow();
+
+            OpcodeHelper.LogMsg(self.DomainZone(), message);
+
+            EventSystem.Instance.Publish(NetClientComponentOnRead.Clone(session, message));
+        }
+
+        private static void OnError(this NetClientComponent self, long channelId, int error)
+        {
+            Session session = self.GetChild<Session>(channelId);
+            if (session == null)
+            {
+                return;
+            }
+
+            session.Error = error;
+            session.Dispose();
+        }
+
+        public static Session Create(this NetClientComponent self, IPEndPoint realIPEndPoint)
+        {
+            long channelId = NetServices.Instance.CreateConnectChannelId();
+            Session session = self.AddChildWithId<Session, int>(channelId, self.ServiceId);
+            session.RemoteAddress = realIPEndPoint;
+#if !UNITY
+            if (self.DomainScene().SceneType != SceneType.Benchmark)
+            {
+                session.AddComponent<SessionIdleCheckerComponent>();
+            }
+#endif
+            NetServices.Instance.CreateChannel(self.ServiceId, session.Id, realIPEndPoint);
+
+            return session;
+        }
+
+        public static Session Create(this NetClientComponent self, IPEndPoint routerIPEndPoint, IPEndPoint realIPEndPoint, uint localConn)
+        {
+            long channelId = localConn;
+            Session session = self.AddChildWithId<Session, int>(channelId, self.ServiceId);
+            session.RemoteAddress = realIPEndPoint;
+#if !UNITY
+            if (self.DomainScene().SceneType != SceneType.Benchmark)
+            {
+                session.AddComponent<SessionIdleCheckerComponent>();
+            }
+#endif
+            NetServices.Instance.CreateChannel(self.ServiceId, session.Id, routerIPEndPoint);
+
+            return session;
+        }
+    }
+}

+ 0 - 6
DotNet/Model/DotNet.Model.csproj

@@ -24,12 +24,6 @@
         <Optimize>true</Optimize>
     </PropertyGroup>
     <ItemGroup>
-        <Compile Include="..\..\Unity\Assets\Scripts\Codes\Model\Client\Message\NetClientComponent.cs">
-          <Link>Client\Message\NetClientComponent.cs</Link>
-        </Compile>
-        <Compile Include="..\..\Unity\Assets\Scripts\Codes\Model\Client\Session\SessionComponent.cs">
-          <Link>Client\Session\SessionComponent.cs</Link>
-        </Compile>
         <Compile Include="..\..\Unity\Assets\Scripts\Codes\Model\Share\**\*.cs">
             <Link>Share\%(RecursiveDir)%(FileName)%(Extension)</Link>
         </Compile>

+ 24 - 0
DotNet/Model/Module/Message/NetClientComponent.cs

@@ -0,0 +1,24 @@
+using System.Net.Sockets;
+
+namespace ET.Client
+{
+    public class NetClientComponentOnRead
+    {
+        public Session Session;
+        public object Message;
+
+        public static NetClientComponentOnRead Static = new();
+        public static NetClientComponentOnRead Clone(Session s, object message)
+        {
+            Static.Session = s;
+            Static.Message = message;
+            return Static;
+        }
+    }
+
+    [ComponentOf(typeof(Scene))]
+    public class NetClientComponent: Entity, IAwake<AddressFamily, NetworkProtocol>, IDestroy
+    {
+        public int ServiceId;
+    }
+}