Browse Source

增加管理App类型,所有进程由管理App管理,启动,停止,Reload等等

tanghai 9 years ago
parent
commit
707e1d169a

+ 6 - 10
Server/App/Program.cs

@@ -17,14 +17,7 @@ namespace App
 
 				Object.ObjectManager.Register("Base", typeof(Game).Assembly);
 				Object.ObjectManager.Register("Model", typeof(ErrorCode).Assembly);
-				byte[] dllBytes = File.ReadAllBytes("./Controller.dll");
-#if __MonoCS__
-				byte[] pdbBytes = File.ReadAllBytes("./Controller.dll.mdb");
-#else
-				byte[] pdbBytes = File.ReadAllBytes("./Controller.pdb");
-#endif
-				Assembly controller = Assembly.Load(dllBytes, pdbBytes);
-				Object.ObjectManager.Register("Controller", controller);
+				Object.ObjectManager.Register("Controller", DllHelper.GetController());
 
 				Options options = Game.Scene.AddComponent<OptionsComponent, string[]>(args).Options;
 				
@@ -36,10 +29,13 @@ namespace App
 				// 根据不同的AppType添加不同的组件
 				switch (options.AppType)
 				{
-					case "Realm":
+					case AppType.Manager:
+						Game.Scene.AddComponent<AppManagerComponent>();
+						break;
+					case AppType.Realm:
 						Game.Scene.AddComponent<RealmGateAddressComponent>();
 						break;
-					case "Gate":
+					case AppType.Gate:
 						Game.Scene.AddComponent<GateSessionKeyComponent>();
 						break;
 					default:

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

@@ -104,6 +104,9 @@
     <Compile Include="..\..\Unity\Assets\Plugins\Base\Helper\MongoHelper.cs">
       <Link>Helper\MongoHelper.cs</Link>
     </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Helper\NetHelper.cs">
+      <Link>Helper\NetHelper.cs</Link>
+    </Compile>
     <Compile Include="..\..\Unity\Assets\Plugins\Base\Helper\ProtobufHelper.cs">
       <Link>Helper\ProtobufHelper.cs</Link>
     </Compile>

+ 50 - 0
Server/Model/Component/AppManagerComponent.cs

@@ -0,0 +1,50 @@
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using Base;
+
+namespace Model
+{
+	[ObjectEvent]
+	public class AppManagerComponentEvent : ObjectEvent<AppManagerComponent>, IAwake
+	{
+		public void Awake()
+		{
+			this.GetValue().Awake();
+		}
+	}
+
+	public class AppManagerComponent : Component
+    {
+		private readonly Dictionary<int, Process> processes = new Dictionary<int, Process>();
+
+		public void Awake()
+		{
+			string[] ips = NetHelper.GetAddressIPs();
+			CommandLines commandLines = Game.Scene.GetComponent<OptionsComponent>().AllOptions;
+			foreach (Options options in commandLines.Options)
+			{
+				if (!ips.Contains(options.IP))
+				{
+					continue;
+				}
+
+				if (options.AppType == AppType.Manager)
+				{
+					continue;
+				}
+
+				string arguments = $"--appType={options.AppType} --id={options.Id} --Protocol={options.Protocol} --Host={options.Host} --Port={options.Port}";
+
+				ProcessStartInfo info = new ProcessStartInfo(@"App.exe", arguments)
+				{
+					UseShellExecute = true,
+					WorkingDirectory = @"..\Server\Bin\Debug"
+				};
+				Process process = Process.Start(info);
+				this.processes.Add(process.Id, process);
+			}
+		}
+    }
+}

+ 6 - 0
Server/Model/Component/OptionsComponent.cs

@@ -1,4 +1,5 @@
 using System;
+using System.IO;
 using Base;
 using CommandLine;
 
@@ -15,10 +16,15 @@ namespace Model
 
 	public class OptionsComponent: Component
 	{
+		public CommandLines AllOptions = new CommandLines();
+
 		public Options Options = new Options();
 
 		public void Awake(string[] args)
 		{
+			string s = File.ReadAllText("./CommandLineConfig.txt");
+			this.AllOptions = MongoHelper.FromJson<CommandLines>(s);
+
 			if (!Parser.Default.ParseArguments(args, this.Options))
 			{
 				throw new Exception($"命令行格式错误!");

+ 5 - 8
Server/Model/Component/RealmGateAddressComponent.cs

@@ -1,6 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
+using System.Collections.Generic;
 using Base;
 
 namespace Model
@@ -20,15 +18,14 @@ namespace Model
 
 		public void Awake()
 		{
-			string s = File.ReadAllText("./CommandLineConfig.txt");
-			CommandLines commandLines = MongoHelper.FromJson<CommandLines>(s);
-			foreach (CommandLine commandLine in commandLines.Commands)
+			CommandLines commandLines = this.GetComponent<OptionsComponent>().AllOptions;
+			foreach (Options options in commandLines.Options)
 			{
-				if (commandLine.Options.AppType != "Gate")
+				if (options.AppType != "Gate")
 				{
 					continue;
 				}
-				this.GateAddress.Add($"{commandLine.Options.Host}:{commandLine.Options.Port}");
+				this.GateAddress.Add($"{options.Host}:{options.Port}");
 			}
 		}
 

+ 20 - 0
Server/Model/Helper/DllHelper.cs

@@ -0,0 +1,20 @@
+using System.IO;
+using System.Reflection;
+
+namespace Model
+{
+	public static class DllHelper
+	{
+		public static Assembly GetController()
+		{
+			byte[] dllBytes = File.ReadAllBytes("./Controller.dll");
+#if __MonoCS__
+			byte[] pdbBytes = File.ReadAllBytes("./Controller.dll.mdb");
+#else
+			byte[] pdbBytes = File.ReadAllBytes("./Controller.pdb");
+#endif
+			Assembly assembly = Assembly.Load(dllBytes, pdbBytes);
+			return assembly;
+		}
+	}
+}

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

@@ -41,9 +41,6 @@
     <Reference Include="System.Core" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="..\..\Unity\Assets\Scripts\Component\AppInfoComponent.cs">
-      <Link>Component\AppInfoComponent.cs</Link>
-    </Compile>
     <Compile Include="..\..\Unity\Assets\Scripts\Component\EventComponent.cs">
       <Link>Component\EventComponent.cs</Link>
     </Compile>
@@ -83,10 +80,12 @@
     <Compile Include="..\..\Unity\Assets\Scripts\Other\Options.cs">
       <Link>Other\Options.cs</Link>
     </Compile>
+    <Compile Include="Component\AppManagerComponent.cs" />
     <Compile Include="Component\LogToClientComponent.cs" />
     <Compile Include="Component\GateSessionKeyComponent.cs" />
     <Compile Include="Component\RealmGateAddressComponent.cs" />
     <Compile Include="Component\OptionsComponent.cs" />
+    <Compile Include="Helper\DllHelper.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>
@@ -95,6 +94,7 @@
       <Name>Server.Base</Name>
     </ProjectReference>
   </ItemGroup>
+  <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.

+ 0 - 15
Server/Server.sln

@@ -15,8 +15,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ENet", "ThirdParty\ENet\ENe
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.App", "App\Server.App.csproj", "{3F8DC04C-9E05-403F-B6A5-36293EB99937}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nuget", "ThirdParty\Nuget\Nuget.csproj", "{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}"
-EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -85,24 +83,11 @@ Global
 		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Release|x64.Build.0 = Release|Any CPU
 		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Release|x86.ActiveCfg = Release|Any CPU
 		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Release|x86.Build.0 = Release|Any CPU
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Debug|x64.ActiveCfg = Debug|Any CPU
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Debug|x64.Build.0 = Debug|Any CPU
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Debug|x86.ActiveCfg = Debug|Any CPU
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Debug|x86.Build.0 = Debug|Any CPU
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Release|Any CPU.Build.0 = Release|Any CPU
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Release|x64.ActiveCfg = Release|Any CPU
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Release|x64.Build.0 = Release|Any CPU
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Release|x86.ActiveCfg = Release|Any CPU
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Release|x86.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
 	EndGlobalSection
 	GlobalSection(NestedProjects) = preSolution
 		{C9992B7C-313E-4C9F-A954-640D01EDFB58} = {01CCAD69-09B1-42F9-8A39-489268BEE18D}
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135} = {01CCAD69-09B1-42F9-8A39-489268BEE18D}
 	EndGlobalSection
 EndGlobal

+ 28 - 29
Unity/Assets/Editor/ServerCommandLineEditor/UI/ServerCommandLineEditor.cs

@@ -37,36 +37,36 @@ namespace MyEditor
 
 		void OnGUI()
 		{
-			for (int i = 0; i < this.commandLines.Commands.Count; ++i)
+			for (int i = 0; i < this.commandLines.Options.Count; ++i)
 			{
-				CommandLine commandLine = this.commandLines.Commands[i];
+				Options options = this.commandLines.Options[i];
 				GUILayout.BeginHorizontal();
-				GUILayout.Label($"IP:");
-				commandLine.IP = EditorGUILayout.TextField(commandLine.IP);
-				GUILayout.Label($"AppType:");
-				commandLine.Options.AppType = EditorGUILayout.TextField(commandLine.Options.AppType);
 				GUILayout.Label($"Id:");
-				commandLine.Options.Id = EditorGUILayout.IntField(commandLine.Options.Id);
+				options.Id = EditorGUILayout.IntField(options.Id);
+				GUILayout.Label($"服务器IP:");
+				options.IP = EditorGUILayout.TextField(options.IP);
+				GUILayout.Label($"AppType:");
+				options.AppType = EditorGUILayout.TextField(options.AppType);
 				GUILayout.Label($"Protocol:");
-				commandLine.Options.Protocol = (NetworkProtocol)EditorGUILayout.EnumPopup(commandLine.Options.Protocol);
+				options.Protocol = (NetworkProtocol)EditorGUILayout.EnumPopup(options.Protocol);
 				GUILayout.Label($"Host:");
-				commandLine.Options.Host = EditorGUILayout.TextField(commandLine.Options.Host);
+				options.Host = EditorGUILayout.TextField(options.Host);
 				GUILayout.Label($"Port:");
-				commandLine.Options.Port = EditorGUILayout.IntField(commandLine.Options.Port);
+				options.Port = EditorGUILayout.IntField(options.Port);
 				if (GUILayout.Button("删除"))
 				{
-					this.commandLines.Commands.Remove(commandLine);
+					this.commandLines.Options.Remove(options);
 					break;
 				}
 				if (GUILayout.Button("复制"))
 				{
 					for (int j = 1; j < this.copyNum + 1; ++j)
 					{
-						CommandLine newCommandLine = (CommandLine) commandLine.Clone();
-						newCommandLine.Options.Id += j;
-						newCommandLine.Options.Port += j;
-						newCommandLine.Options.Protocol = this.protocol;
-						this.commandLines.Commands.Add(newCommandLine);
+						Options newOptions = (Options)options.Clone();
+						newOptions.Id += j;
+						newOptions.Port += j;
+						newOptions.Protocol = this.protocol;
+						this.commandLines.Options.Add(newOptions);
 					}
 					break;
 				}
@@ -81,9 +81,9 @@ namespace MyEditor
 			GUILayout.BeginHorizontal();
 			if (GUILayout.Button("添加"))
 			{
-				CommandLine newCommandLine = new CommandLine();
-				newCommandLine.Options.Protocol = this.protocol;
-				this.commandLines.Commands.Add(newCommandLine);
+				Options newOptions = new Options();
+				newOptions.Protocol = this.protocol;
+				this.commandLines.Options.Add(newOptions);
 			}
 
 			if (GUILayout.Button("保存"))
@@ -93,17 +93,16 @@ namespace MyEditor
 
 			if (GUILayout.Button("启动"))
 			{
-				foreach (CommandLine commandLine in this.commandLines.Commands)
-				{
-					string arguments = $"--appType={commandLine.Options.AppType} --id={commandLine.Options.Id} --Protocol={commandLine.Options.Protocol} --Host={commandLine.Options.Host} --Port={commandLine.Options.Port}";
+				Options options = this.commandLines.Manager;
+				
+				string arguments = $"--appType={options.AppType} --id={options.Id} --Protocol={options.Protocol} --Host={options.Host} --Port={options.Port}";
 
-					ProcessStartInfo info = new ProcessStartInfo(@"App.exe", arguments)
-					{
-						UseShellExecute = true,
-						WorkingDirectory = @"..\Server\Bin\Debug"
-					};
-					Process.Start(info);
-				}
+				ProcessStartInfo info = new ProcessStartInfo(@"App.exe", arguments)
+				{
+					UseShellExecute = true,
+					WorkingDirectory = @"..\Server\Bin\Debug"
+				};
+				Process.Start(info);
 			}
 			GUILayout.EndHorizontal();
 		}

+ 22 - 0
Unity/Assets/Plugins/Base/Helper/NetHelper.cs

@@ -0,0 +1,22 @@
+using System.Collections.Generic;
+using System.Net;
+
+namespace Base
+{
+	public static class NetHelper
+	{
+		public static string[] GetAddressIPs()
+		{
+			//获取本地的IP地址
+			List<string> addressIPs = new List<string>();
+			foreach (IPAddress address in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
+			{
+				if (address.AddressFamily.ToString() == "InterNetwork")
+				{
+					addressIPs.Add(address.ToString());
+				}
+			}
+			return addressIPs.ToArray();
+		}
+	}
+}

+ 2 - 2
Unity/Assets/Scripts/Component/AppInfoComponent.cs.meta → Unity/Assets/Plugins/Base/Helper/NetHelper.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
-guid: d4852a0f714d73f43af0109603bd32ba
-timeCreated: 1476849603
+guid: 118568110604b5f4ebb8e56ca26d4f13
+timeCreated: 1476940305
 licenseType: Pro
 MonoImporter:
   serializedVersion: 2

+ 0 - 23
Unity/Assets/Scripts/Component/AppInfoComponent.cs

@@ -1,23 +0,0 @@
-using Base;
-
-namespace Model
-{
-	[ObjectEvent]
-	public class AppInfoComponentEvent : ObjectEvent<AppInfoComponent>, IAwake<string>
-	{
-		public void Awake(string appType)
-		{
-			this.GetValue().Awake(appType);
-		}
-	}
-
-	public class AppInfoComponent : Component
-    {
-		private string AppType { get; set; }
-
-		public void Awake(string appType)
-		{
-			this.AppType = appType;
-		}
-    }
-}

+ 26 - 30
Unity/Assets/Scripts/Component/TimerComponent.cs

@@ -2,19 +2,18 @@
 using System.Threading;
 using System.Threading.Tasks;
 using Base;
-using MongoDB.Bson;
 
 namespace Model
 {
 	public class Timer
 	{
-		public ObjectId Id { get; set; }
+		public long Id { get; set; }
 		public long Time { get; set; }
 		public TaskCompletionSource<bool> tcs;
 	}
 
 	[ObjectEvent]
-	public class TimerComponentEvent : ObjectEvent<TimerComponent> 
+	public class TimerComponentEvent : ObjectEvent<TimerComponent>, IUpdate
 	{
 		public void Update()
 		{
@@ -23,50 +22,47 @@ namespace Model
 		}
 	}
 
-	public static class TimerComponentExtension
+	public class TimerComponent: Component
 	{
-		public static void Update(this TimerComponent component)
+		private readonly Dictionary<long, Timer> timers = new Dictionary<long, Timer>();
+
+		/// <summary>
+		/// key: time, value: timer id
+		/// </summary>
+		private readonly MultiMap<long, long> timeId = new MultiMap<long, long>();
+
+		private readonly Queue<long> timeoutTimer = new Queue<long>();
+
+		public void Update()
 		{
 			long timeNow = TimeHelper.Now();
-			foreach (long time in component.timeId.Keys)
+			foreach (long time in this.timeId.Keys)
 			{
 				if (time > timeNow)
 				{
 					break;
 				}
-				component.timeoutTimer.Enqueue(time);
+				this.timeoutTimer.Enqueue(time);
 			}
 
-			while (component.timeoutTimer.Count > 0)
+			while (this.timeoutTimer.Count > 0)
 			{
-				long key = component.timeoutTimer.Dequeue();
-				ObjectId[] timeOutId = component.timeId.GetAll(key);
-				foreach (ObjectId id in timeOutId)
+				long key = this.timeoutTimer.Dequeue();
+				long[] timeOutId = this.timeId.GetAll(key);
+				foreach (long id in timeOutId)
 				{
 					Timer timer;
-					if (!component.timers.TryGetValue(id, out timer))
+					if (!this.timers.TryGetValue(id, out timer))
 					{
 						continue;
 					}
-					component.Remove(id);
+					this.Remove(id);
 					timer.tcs.SetResult(true);
 				}
 			}
 		}
-	}
-
-	public class TimerComponent: Component
-	{
-		public readonly Dictionary<ObjectId, Timer> timers = new Dictionary<ObjectId, Timer>();
-
-		/// <summary>
-		/// key: time, value: timer id
-		/// </summary>
-		public readonly MultiMap<long, ObjectId> timeId = new MultiMap<long, ObjectId>();
-
-		public readonly Queue<long> timeoutTimer = new Queue<long>();
 
-		public void Remove(ObjectId id)
+		private void Remove(long id)
 		{
 			Timer timer;
 			if (!this.timers.TryGetValue(id, out timer))
@@ -80,7 +76,7 @@ namespace Model
 		public Task WaitTillAsync(long tillTime, CancellationToken cancellationToken)
 		{
 			TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
-			Timer timer = new Timer { Id = ObjectId.GenerateNewId(), Time = tillTime, tcs = tcs };
+			Timer timer = new Timer { Id = IdGenerater.GenerateId(), Time = tillTime, tcs = tcs };
 			this.timers[timer.Id] = timer;
 			this.timeId.Add(timer.Time, timer.Id);
 			cancellationToken.Register(() =>
@@ -93,7 +89,7 @@ namespace Model
 		public Task WaitTillAsync(long tillTime)
 		{
 			TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
-			Timer timer = new Timer { Id = ObjectId.GenerateNewId(), Time = tillTime, tcs = tcs };
+			Timer timer = new Timer { Id = IdGenerater.GenerateId(), Time = tillTime, tcs = tcs };
 			this.timers[timer.Id] = timer;
 			this.timeId.Add(timer.Time, timer.Id);
 			return tcs.Task;
@@ -104,7 +100,7 @@ namespace Model
 			TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
 			Timer timer = new Timer
 			{
-				Id = ObjectId.GenerateNewId(),
+				Id = IdGenerater.GenerateId(),
 				Time = TimeHelper.Now() + time,
 				tcs = tcs
 			};
@@ -122,7 +118,7 @@ namespace Model
 			TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
 			Timer timer = new Timer
 			{
-				Id = ObjectId.GenerateNewId(),
+				Id = IdGenerater.GenerateId(),
 				Time = TimeHelper.Now() + time,
 				tcs = tcs
 			};

+ 9 - 0
Unity/Assets/Scripts/Helper.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: 750b9e7f02770174ba6d2e9aa59d68ae
+folderAsset: yes
+timeCreated: 1476935213
+licenseType: Pro
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 17 - 0
Unity/Assets/Scripts/Helper/DllHelper.cs

@@ -0,0 +1,17 @@
+using System.Reflection;
+using UnityEngine;
+
+namespace Model
+{
+	public static class DllHelper
+	{
+		public static Assembly GetController()
+		{
+			GameObject code = (GameObject)Resources.Load("Code");
+			byte[] assBytes = code.Get<TextAsset>("Controller.dll").bytes;
+			byte[] mdbBytes = code.Get<TextAsset>("Controller.dll.mdb").bytes;
+			Assembly assembly = Assembly.Load(assBytes, mdbBytes);
+			return assembly;
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Helper/DllHelper.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 1e547a91aff347f4391ed7bc7e00ef63
+timeCreated: 1476935213
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 6
Unity/Assets/Scripts/Init.cs

@@ -11,12 +11,7 @@ namespace Model
 		{
 			Object.ObjectManager.Register("Base", typeof(Game).Assembly);
 			Object.ObjectManager.Register("Model", typeof(Init).Assembly);
-
-			GameObject code = (GameObject)Resources.Load("Code");
-			byte[] assBytes = code.Get<TextAsset>("Controller.dll").bytes;
-			byte[] mdbBytes = code.Get<TextAsset>("Controller.dll.mdb").bytes;
-			Assembly assembly = Assembly.Load(assBytes, mdbBytes);
-			Object.ObjectManager.Register("Controller", assembly);
+			Object.ObjectManager.Register("Controller", DllHelper.GetController());
 
 			Game.Scene.AddComponent<EventComponent>().Run(EventIdType.InitSceneStart);
 		}

+ 1 - 0
Unity/Assets/Scripts/Message/AppType.cs

@@ -5,6 +5,7 @@
 		public const string Client = "Client";
 		public const string Robot = "Robot";
 
+		public const string Manager = "Manager";
 		public const string Realm = "Realm";
 		public const string Gate = "Gate";
 	}

+ 27 - 13
Unity/Assets/Scripts/Other/CommandLine.cs

@@ -1,23 +1,37 @@
-using System;
-using System.Collections.Generic;
-using Base;
-using Model;
+using System.Collections.Generic;
+using System.ComponentModel;
+using MongoDB.Bson.Serialization.Attributes;
 
 namespace Model
 {
-	public class CommandLine: ICloneable
+	public class CommandLines: ISupportInitialize
 	{
-		public string IP = "";
-		public Options Options = new Options();
+		[BsonIgnore]
+		public Options Manager { get; private set; }
 
-		public object Clone()
+		[BsonIgnore]
+		public Options Realm { get; private set; }
+		
+		public List<Options> Options = new List<Options>();
+
+		public void BeginInit()
 		{
-			return MongoHelper.FromBson<CommandLine>(MongoHelper.ToBson(this));
 		}
-	}
 
-	public class CommandLines
-	{
-		public List<CommandLine> Commands = new List<CommandLine>();
+		public void EndInit()
+		{
+			foreach (Options options in this.Options)
+			{
+				if (options.AppType == AppType.Realm)
+				{
+					this.Realm = options;
+				}
+
+				if (options.AppType == AppType.Manager)
+				{
+					this.Manager = options;
+				}
+			}
+		}
 	}
 }

+ 17 - 6
Unity/Assets/Scripts/Other/Options.cs

@@ -1,4 +1,5 @@
-using System.Text;
+using System;
+using System.Text;
 using Base;
 #if SERVER
 using CommandLine;
@@ -6,17 +7,22 @@ using CommandLine;
 
 namespace Model
 {
-	public class Options
+	public class Options: ICloneable
 	{
 #if SERVER
-		[Option("appType", Required = true, HelpText = "AppType: realm gate")]
+		[Option("id", Required = true, HelpText = "Id.")]
 #endif
-		public string AppType { get; set; }
+		public int Id { get; set; }
 
 #if SERVER
-		[Option("id", Required = true, HelpText = "Id.")]
+		[Option("IP", Required = false, HelpText = "进程运行的服务器ip.")]
 #endif
-		public int Id { get; set; }
+		public string IP { get; set; }
+
+#if SERVER
+		[Option("appType", Required = true, HelpText = "AppType: realm gate")]
+#endif
+		public string AppType { get; set; }
 
 #if SERVER
 		[Option("protocol", Required = false, HelpText = "Protocol, tcp or udp.", DefaultValue = NetworkProtocol.UDP)]
@@ -59,5 +65,10 @@ namespace Model
 			usage.AppendLine("Read user manual for usage instructions...");
 			return usage.ToString();
 		}
+
+		public object Clone()
+		{
+			return MongoHelper.FromBson<Options>(MongoHelper.ToBson(this));
+		}
 	}
 }

+ 1 - 1
Unity/Controller/Event/InitSceneStartEvent_InitGame.cs

@@ -14,7 +14,7 @@ namespace Controller
 		{
 			Game.Scene.AddComponent<MessageDispatherComponent, string>("Client");
 			NetworkComponent networkComponent = Game.Scene.AddComponent<NetworkComponent, NetworkProtocol>(NetworkProtocol.TCP);
-			Entity session = networkComponent.Get("127.0.0.1:8888");
+			Entity session = networkComponent.Get("127.0.0.1:10001");
 
 			try
 			{

+ 1 - 0
Unity/Unity.CSharp.Plugins.csproj

@@ -92,6 +92,7 @@
     <Compile Include="Assets\Plugins\Base\Helper\IdGenerater.cs" />
     <Compile Include="Assets\Plugins\Base\Helper\MD5Helper.cs" />
     <Compile Include="Assets\Plugins\Base\Helper\MongoHelper.cs" />
+    <Compile Include="Assets\Plugins\Base\Helper\NetHelper.cs" />
     <Compile Include="Assets\Plugins\Base\Helper\ProtobufHelper.cs" />
     <Compile Include="Assets\Plugins\Base\Helper\RandomHelper.cs" />
     <Compile Include="Assets\Plugins\Base\Helper\StringHelper.cs" />

+ 2 - 1
Unity/Unity.CSharp.csproj

@@ -83,7 +83,6 @@
     <Compile Include="Assets\Scripts\Component\EventComponent.cs" />
     <Compile Include="Assets\Scripts\Component\GameObjectComponent.cs" />
     <Compile Include="Assets\Scripts\Component\GlobalConfigComponent.cs" />
-    <Compile Include="Assets\Scripts\Component\AppInfoComponent.cs" />
     <Compile Include="Assets\Scripts\Component\KVComponent.cs" />
     <Compile Include="Assets\Scripts\Component\MessageComponent.cs" />
     <Compile Include="Assets\Scripts\Component\MessageDispatherComponent.cs" />
@@ -97,6 +96,7 @@
     <Compile Include="Assets\Scripts\Event\EnvKey.cs" />
     <Compile Include="Assets\Scripts\Event\EventIdType.cs" />
     <Compile Include="Assets\Scripts\GameObjectHelper.cs" />
+    <Compile Include="Assets\Scripts\Helper\DllHelper.cs" />
     <Compile Include="Assets\Scripts\Init.cs" />
     <Compile Include="Assets\Scripts\Message\AppType.cs" />
     <Compile Include="Assets\Scripts\Message\ErrorCode.cs" />
@@ -113,5 +113,6 @@
     <None Include="Assets\CSharp 6.0 Support\AsyncTools\Plugins\AsyncBridge.Net35.xml" />
     <None Include="Assets\CSharp 6.0 Support\AsyncTools\Plugins\System.Threading.xml" />
   </ItemGroup>
+  <ItemGroup />
   <Import Project="$(MSBuildExtensionsPath)\SyntaxTree\UnityVS\2015\UnityVS.CSharp.targets" />
 </Project>