Просмотр исходного кода

前后端NetOutComponent统一,切换协议只需要修改NetOutComponent类里面的Protocol字段即可

tanghai 7 лет назад
Родитель
Сommit
d7a59ad790

+ 2 - 3
Config/StartConfig/BenchmarkWebsocket.txt

@@ -1,3 +1,2 @@
-{ "_t" : "StartConfig", "C" : [{ "_t" : "OuterConfig", "Address" : "127.0.0.1:10002", "Address2" : "127.0.0.1:10002" }, { "_t" : "InnerConfig", "Address" : "127.0.0.1:20000" }], "AppId" : 1, "AppType" : "Manager", "ServerIP" : "*" }
-{ "_t" : "StartConfig", "C" : [{ "_t" : "OuterConfig", "Address" : "http://*:8080/", "Address2" : "ws://127.0.0.1:8080" }], "AppId" : 2, "AppType" : "BenchmarkWebsocketServer", "ServerIP" : "*" }
-{ "_t" : "StartConfig", "C" : [{ "_t" : "ClientConfig", "Address" : "ws://127.0.0.1:8080" }], "AppId" : 3, "AppType" : "BenchmarkWebsocketClient", "ServerIP" : "*" }
+{ "_t" : "StartConfig", "C" : [{ "_t" : "InnerConfig", "Address" : "127.0.0.1:20000" }, { "_t" : "OuterConfig", "Address" : "http://*:8080/", "Address2" : "ws://127.0.0.1:8080" }], "AppId" : 1, "AppType" : "Manager", "ServerIP" : "*" }
+{ "_t" : "StartConfig", "C" : [{ "_t" : "ClientConfig", "Address" : "ws://127.0.0.1:8080" }], "AppId" : 2, "AppType" : "BenchmarkWebsocketClient", "ServerIP" : "*" }

+ 1 - 0
Config/StartConfig/LocalAllServerWebsocket.txt

@@ -0,0 +1 @@
+{ "_t" : "StartConfig", "_id" : NumberLong("98547768819754"), "C" : [{ "_t" : "OuterConfig", "Address" : "http://*:8080/", "Address2" : "ws://127.0.0.1:8080" }, { "_t" : "InnerConfig", "Address" : "127.0.0.1:20000" }, { "_t" : "HttpConfig", "Url" : "http://*:8080/", "AppId" : 0, "AppKey" : "", "ManagerSystemUrl" : "" }, { "_t" : "DBConfig", "ConnectionString" : null, "DBName" : null }], "AppId" : 1, "AppType" : "AllServer", "ServerIP" : "*" }

+ 9 - 9
Server/App/Program.cs

@@ -48,14 +48,14 @@ namespace App
 				switch (startConfig.AppType)
 				{
 					case AppType.Manager:
-						Game.Scene.AddComponent<AppManagerComponent, NetworkProtocol>(options.Protocol);
+						Game.Scene.AddComponent<AppManagerComponent>();
 						Game.Scene.AddComponent<NetInnerComponent, string>(innerConfig.Address);
-						Game.Scene.AddComponent<NetOuterComponent, NetworkProtocol, string>(options.Protocol, outerConfig.Address);
+						Game.Scene.AddComponent<NetOuterComponent, string>(outerConfig.Address);
 						break;
 					case AppType.Realm:
 						Game.Scene.AddComponent<ActorMessageDispatherComponent>();
 						Game.Scene.AddComponent<NetInnerComponent, string>(innerConfig.Address);
-						Game.Scene.AddComponent<NetOuterComponent, NetworkProtocol, string>(options.Protocol, outerConfig.Address);
+						Game.Scene.AddComponent<NetOuterComponent, string>(outerConfig.Address);
 						Game.Scene.AddComponent<LocationProxyComponent>();
 						Game.Scene.AddComponent<RealmGateAddressComponent>();
 						break;
@@ -63,7 +63,7 @@ namespace App
 						Game.Scene.AddComponent<PlayerComponent>();
 						Game.Scene.AddComponent<ActorMessageDispatherComponent>();
 						Game.Scene.AddComponent<NetInnerComponent, string>(innerConfig.Address);
-						Game.Scene.AddComponent<NetOuterComponent, NetworkProtocol, string>(options.Protocol, outerConfig.Address);
+						Game.Scene.AddComponent<NetOuterComponent, string>(outerConfig.Address);
 						Game.Scene.AddComponent<LocationProxyComponent>();
 						Game.Scene.AddComponent<ActorMessageSenderComponent>();
 						Game.Scene.AddComponent<GateSessionKeyComponent>();
@@ -90,9 +90,9 @@ namespace App
 						Game.Scene.AddComponent<LocationComponent>();
 						Game.Scene.AddComponent<ActorMessageDispatherComponent>();
 						Game.Scene.AddComponent<NetInnerComponent, string>(innerConfig.Address);
-						Game.Scene.AddComponent<NetOuterComponent, NetworkProtocol, string>(options.Protocol, outerConfig.Address);
+						Game.Scene.AddComponent<NetOuterComponent, string>(outerConfig.Address);
 						Game.Scene.AddComponent<LocationProxyComponent>();
-						Game.Scene.AddComponent<AppManagerComponent, NetworkProtocol>(options.Protocol);
+						Game.Scene.AddComponent<AppManagerComponent>();
 						Game.Scene.AddComponent<RealmGateAddressComponent>();
 						Game.Scene.AddComponent<GateSessionKeyComponent>();
 						Game.Scene.AddComponent<ConfigComponent>();
@@ -100,14 +100,14 @@ namespace App
 						// Game.Scene.AddComponent<HttpComponent>();
 						break;
 					case AppType.Benchmark:
-						Game.Scene.AddComponent<NetOuterComponent, NetworkProtocol>(options.Protocol);
+						Game.Scene.AddComponent<NetOuterComponent>();
 						Game.Scene.AddComponent<BenchmarkComponent, string>(clientConfig.Address);
 						break;
 					case AppType.BenchmarkWebsocketServer:
-						Game.Scene.AddComponent<NetOuterComponent, NetworkProtocol, string>(NetworkProtocol.WebSocket, outerConfig.Address);
+						Game.Scene.AddComponent<NetOuterComponent, string>(outerConfig.Address);
 						break;
 					case AppType.BenchmarkWebsocketClient:
-						Game.Scene.AddComponent<NetOuterComponent, NetworkProtocol>(NetworkProtocol.WebSocket);
+						Game.Scene.AddComponent<NetOuterComponent>();
 						Game.Scene.AddComponent<WebSocketBenchmarkComponent, string>(clientConfig.Address);
 						break;
 					default:

+ 3 - 0
Server/Hotfix/Server.Hotfix.csproj

@@ -17,6 +17,9 @@
   </PropertyGroup>
   <ItemGroup>
     <Compile Remove="Other\**" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Module\Message\NetOuterComponentSystem.cs">
+      <Link>Module\Message\NetOuterComponentSystem.cs</Link>
+    </Compile>
     <EmbeddedResource Remove="Other\**" />
     <None Remove="Other\**" />
   </ItemGroup>

+ 5 - 7
Server/Model/Component/AppManagerComponent.cs

@@ -7,22 +7,20 @@ using System.Runtime.InteropServices;
 namespace ETModel
 {
 	[ObjectSystem]
-	public class AppManagerComponentAwakeSystem : AwakeSystem<AppManagerComponent, NetworkProtocol>
+	public class AppManagerComponentAwakeSystem : AwakeSystem<AppManagerComponent>
 	{
-		public override void Awake(AppManagerComponent self, NetworkProtocol protocol)
+		public override void Awake(AppManagerComponent self)
 		{
-			self.Awake(protocol);
+			self.Awake();
 		}
 	}
 
 	public class AppManagerComponent: Component
 	{
-		private NetworkProtocol networkProtocol;
 		private readonly Dictionary<int, Process> processes = new Dictionary<int, Process>();
 
-		public void Awake(NetworkProtocol protocol)
+		public void Awake()
 		{
-			this.networkProtocol = protocol;
 			string[] ips = NetHelper.GetAddressIPs();
 			StartConfig[] startConfigs = StartConfigComponent.Instance.GetAll();
 			
@@ -53,7 +51,7 @@ namespace ETModel
 			string configFile = optionComponent.Options.Config;
 			StartConfig startConfig = startConfigComponent.Get(appId);
 			const string exe = "dotnet";
-			string arguments = $"App.dll --appId={startConfig.AppId} --appType={startConfig.AppType} --config={configFile} --protocol={this.networkProtocol}";
+			string arguments = $"App.dll --appId={startConfig.AppId} --appType={startConfig.AppType} --config={configFile}";
 
 			Log.Info($"{exe} {arguments}");
 			try

+ 0 - 6
Server/Model/Module/Message/NetOuterComponent.cs

@@ -1,6 +0,0 @@
-namespace ETModel
-{
-	public class NetOuterComponent: NetworkComponent
-	{
-	}
-}

+ 0 - 3
Server/Model/Other/Options.cs

@@ -15,8 +15,5 @@ namespace ETModel
 
 		[Option("config", Required = false, Default = "../Config/StartConfig/LocalAllServer.txt")]
 		public string Config { get; set; }
-		
-		[Option("protocol", Required = false, Default = NetworkProtocol.TCP)]
-		public NetworkProtocol Protocol { get; set; }
 	}
 }

+ 3 - 0
Server/Model/Server.Model.csproj

@@ -20,6 +20,9 @@
     <Compile Include="..\..\Unity\Assets\Scripts\Module\Message\MessagePool.cs">
       <Link>Module\Message\MessagePool\ETModel\MessagePool.cs</Link>
     </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Module\Message\NetOuterComponent.cs">
+      <Link>Module\Message\NetOuterComponent.cs</Link>
+    </Compile>
     <Compile Include="..\..\Unity\Hotfix\Module\Message\MessagePool.cs">
       <Link>Module\Message\MessagePool\ETHotfix\MessagePool.cs</Link>
     </Compile>

+ 1 - 2
Unity/Assets/Editor/ServerCommandLineEditor/ServerCommandLineEditor.cs

@@ -333,12 +333,11 @@ namespace ETEditor
 			GUILayout.EndHorizontal();
 
 			GUILayout.BeginHorizontal();
-
 			if (GUILayout.Button("保存"))
 			{
 				this.Save();
 			}
-
+			
 			if (GUILayout.Button("启动"))
 			{
 				StartConfig startConfig = null;

+ 0 - 3
Unity/Assets/Scripts/Module/Message/ClientDispatcher.cs.meta

@@ -1,3 +0,0 @@
-fileFormatVersion: 2
-guid: a8a80ba0258647f2b5c0af2bf71576db
-timeCreated: 1503568672

+ 1 - 29
Unity/Assets/Scripts/Module/Message/NetOuterComponent.cs

@@ -1,35 +1,7 @@
 namespace ETModel
 {
-	[ObjectSystem]
-	public class NetOuterComponentAwakeSystem : AwakeSystem<NetOuterComponent>
-	{
-		public override void Awake(NetOuterComponent self)
-		{
-			self.Awake();
-		}
-	}
-
-	[ObjectSystem]
-	public class NetOuterComponentUpdateSystem : UpdateSystem<NetOuterComponent>
-	{
-		public override void Update(NetOuterComponent self)
-		{
-			self.Update();
-		}
-	}
-
 	public class NetOuterComponent : NetworkComponent
 	{
-		public void Awake()
-		{
-			this.Awake(NetworkProtocol.TCP);
-			this.MessagePacker = new ProtobufPacker();
-			this.MessageDispatcher = new ClientDispatcher();
-		}
-
-		public new void Update()
-		{
-			base.Update();
-		}
+		public NetworkProtocol Protocol = NetworkProtocol.TCP;
 	}
 }

+ 6 - 6
Server/Hotfix/Module/Message/NetOuterComponentSystem.cs → Unity/Assets/Scripts/Module/Message/NetOuterComponentSystem.cs

@@ -5,22 +5,22 @@ using ETModel;
 namespace ETHotfix
 {
 	[ObjectSystem]
-	public class NetOuterComponentAwakeSystem : AwakeSystem<NetOuterComponent, NetworkProtocol>
+	public class NetOuterComponentAwakeSystem : AwakeSystem<NetOuterComponent>
 	{
-		public override void Awake(NetOuterComponent self, NetworkProtocol protocol)
+		public override void Awake(NetOuterComponent self)
 		{
-			self.Awake(protocol);
+			self.Awake(self.Protocol);
 			self.MessagePacker = new ProtobufPacker();
 			self.MessageDispatcher = new OuterMessageDispatcher();
 		}
 	}
 
 	[ObjectSystem]
-	public class NetOuterComponentAwake1System : AwakeSystem<NetOuterComponent, NetworkProtocol, string>
+	public class NetOuterComponentAwake1System : AwakeSystem<NetOuterComponent, string>
 	{
-		public override void Awake(NetOuterComponent self, NetworkProtocol protocol, string address)
+		public override void Awake(NetOuterComponent self, string address)
 		{
-			self.Awake(protocol, address);
+			self.Awake(self.Protocol, address);
 			self.MessagePacker = new ProtobufPacker();
 			self.MessageDispatcher = new OuterMessageDispatcher();
 		}

+ 11 - 0
Unity/Assets/Scripts/Module/Message/NetOuterComponentSystem.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 424f24de99d7f19429c7ae61649c5af5
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 1
Unity/Assets/Scripts/Module/Message/ClientDispatcher.cs → Unity/Assets/Scripts/Module/Message/OuterMessageDispatcher.cs

@@ -1,6 +1,6 @@
 namespace ETModel
 {
-	public class ClientDispatcher: IMessageDispatcher
+	public class OuterMessageDispatcher: IMessageDispatcher
 	{
 		public void Dispatch(Session session, ushort opcode, object message)
 		{

+ 11 - 0
Unity/Assets/Scripts/Module/Message/OuterMessageDispatcher.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 4718b5fb8dff51f438ac8179c036699d
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 9 - 5
Unity/Unity.csproj

@@ -12,13 +12,16 @@
     <ProjectTypeGuids>{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
     <TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
     <TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
-    <TargetFrameworkProfile></TargetFrameworkProfile>
-    <CompilerResponseFile></CompilerResponseFile>
+    <TargetFrameworkProfile>
+    </TargetFrameworkProfile>
+    <CompilerResponseFile>
+    </CompilerResponseFile>
     <UnityProjectGenerator>VSTU</UnityProjectGenerator>
     <UnityProjectType>Game:1</UnityProjectType>
     <UnityBuildTarget>StandaloneWindows64:19</UnityBuildTarget>
     <UnityVersion>2017.4.9f1</UnityVersion>
-    <RootNamespace></RootNamespace>
+    <RootNamespace>
+    </RootNamespace>
     <LangVersion>6</LangVersion>
   </PropertyGroup>
   <PropertyGroup>
@@ -378,7 +381,7 @@
     <Compile Include="Assets\Scripts\Module\FrameSync\UnitComponent.cs" />
     <Compile Include="Assets\Scripts\Module\FrameSync\UnitFactory.cs" />
     <Compile Include="Assets\Scripts\Module\Message\AMHandler.cs" />
-    <Compile Include="Assets\Scripts\Module\Message\ClientDispatcher.cs" />
+    <Compile Include="Assets\Scripts\Module\Message\OuterMessageDispatcher.cs" />
     <Compile Include="Assets\Scripts\Module\Message\ErrorCode.cs" />
     <Compile Include="Assets\Scripts\Module\Message\IActorMessage.cs" />
     <Compile Include="Assets\Scripts\Module\Message\IMessage.cs" />
@@ -392,6 +395,7 @@
     <Compile Include="Assets\Scripts\Module\Message\MessagePool.cs" />
     <Compile Include="Assets\Scripts\Module\Message\MessageProxy.cs" />
     <Compile Include="Assets\Scripts\Module\Message\NetOuterComponent.cs" />
+    <Compile Include="Assets\Scripts\Module\Message\NetOuterComponentSystem.cs" />
     <Compile Include="Assets\Scripts\Module\Message\Network\AChannel.cs" />
     <Compile Include="Assets\Scripts\Module\Message\Network\AService.cs" />
     <Compile Include="Assets\Scripts\Module\Message\Network\Circularbuffer.cs" />
@@ -1146,4 +1150,4 @@
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Target Name="GenerateTargetFrameworkMonikerAttribute" />
-</Project>
+</Project>