فهرست منبع

增加服务器reload功能,Tools/服务器管理 工具中可以指定Reload哪个类型的服务器

tanghai 9 سال پیش
والد
کامیت
58c9772c9b

+ 36 - 0
Server/Controller/Message/C2M_ReloadHandler.cs

@@ -0,0 +1,36 @@
+using System;
+using Base;
+using Model;
+
+namespace Controller
+{
+	[MessageHandler(AppType.Manager)]
+	public class C2M_ReloadHandler: AMRpcEvent<C2M_Reload, M2C_Reload>
+	{
+		protected override async void Run(Entity session, C2M_Reload message, Action<M2C_Reload> reply)
+		{
+			M2C_Reload m2CReload = new M2C_Reload();
+			try
+			{
+				StartConfigComponent startConfigComponent = Game.Scene.GetComponent<StartConfigComponent>();
+				NetInnerComponent netInnerComponent = Game.Scene.GetComponent<NetInnerComponent>();
+				foreach (StartConfig startConfig in startConfigComponent.GetAll())
+				{
+					if (!message.AppType.Contains(startConfig.Options.AppType))
+					{
+						continue;
+					}
+					InnerConfig innerConfig = startConfig.Config.GetComponent<InnerConfig>();
+					Entity serverSession = netInnerComponent.Get($"{innerConfig.Host}:{innerConfig.Port}");
+					await serverSession.GetComponent<MessageComponent>().Call<M2A_Reload, A2M_Reload>(new M2A_Reload());
+				}
+			}
+			catch (Exception e)
+			{
+				m2CReload.Error = ErrorCode.ERR_ReloadFail;
+				m2CReload.Message = e.ToString();
+			}
+			reply(m2CReload);
+		}
+	}
+}

+ 28 - 0
Server/Controller/Message/M2A_ReloadHandler.cs

@@ -0,0 +1,28 @@
+using System;
+using Base;
+using Model;
+using Object = Base.Object;
+
+namespace Controller
+{
+	[MessageHandler(AppType.Manager, AppType.Realm, AppType.Gate)]
+	public class M2A_ReloadHandler : AMRpcEvent<M2A_Reload, A2M_Reload>
+	{
+		protected override void Run(Entity session, M2A_Reload message, Action<A2M_Reload> reply)
+		{
+			A2M_Reload a2MReload = new A2M_Reload();
+			try
+			{
+				Object.ObjectManager.Register("Controller", DllHelper.GetController());
+			}
+			catch (Exception e)
+			{
+				a2MReload.Error = ErrorCode.ERR_ReloadFail;
+				StartConfig myStartConfig = Game.Scene.GetComponent<StartConfigComponent>().MyConfig;
+				InnerConfig innerConfig = myStartConfig.Config.GetComponent<InnerConfig>();
+				a2MReload.Message = $"{innerConfig.Host}:{innerConfig.Port} reload fail, {e}";
+			}
+			reply(a2MReload);
+		}
+	}
+}

+ 2 - 0
Server/Controller/Server.Controller.csproj

@@ -35,6 +35,8 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Message\C2G_LoginGateHandler.cs" />
+    <Compile Include="Message\M2A_ReloadHandler.cs" />
+    <Compile Include="Message\C2M_ReloadHandler.cs" />
     <Compile Include="Message\R2G_GetLoginKeyHandler.cs" />
     <Compile Include="Message\C2R_SubscribeLogHandler.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />

+ 0 - 6
Unity/Assets/Editor/RsyncEditor/RsyncEditor.cs

@@ -18,12 +18,6 @@ namespace MyEditor
 			GetWindow(typeof(RsyncEditor));
 		}
 
-		[MenuItem("Tools/Rsync同步")]
-		private static void ShowTool()
-		{
-			GetWindow(typeof(RsyncEditor));
-		}
-
 		private void OnEnable()
 		{
 			if (!File.Exists(ConfigFile))

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

@@ -19,8 +19,8 @@ namespace MyEditor
 		private string AppType = Model.AppType.Manager;
 
 		private readonly List<StartConfig> startConfigs = new List<StartConfig>();
-
-		[MenuItem("Tools/服务端命令行配置")]
+	
+		[MenuItem("Tools/命令行配置")]
 		private static void ShowWindow()
 		{
 			GetWindow(typeof(ServerCommandLineEditor));

+ 9 - 0
Unity/Assets/Editor/ServerManagerEditor.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: 68b2a7ca3d66a6f4086fdc349c8489fc
+folderAsset: yes
+timeCreated: 1477318769
+licenseType: Pro
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 82 - 0
Unity/Assets/Editor/ServerManagerEditor/ServerManagerEditor.cs

@@ -0,0 +1,82 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using Base;
+using Model;
+using UnityEditor;
+using UnityEngine;
+
+namespace MyEditor
+{
+	public class ServerManagerEditor : EditorWindow
+	{
+		private string managerAddress;
+
+		private bool isAll;
+
+		private string[] appTypes = { "Manager", "Realm", "Gate" };
+		private bool[] isCheck = { false, false, false };
+
+		[MenuItem("Tools/服务器管理")]
+		private static void ShowWindow()
+		{
+			GetWindow(typeof(ServerManagerEditor));
+		}
+
+		private void OnEnable()
+		{
+		}
+
+		private void OnGUI()
+		{
+			if (!Application.isPlaying)
+			{
+				GUILayout.Label("请启动游戏!");
+				return;
+			}
+
+			List<string> selected = new List<string>();
+			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.appTypes.Length; ++i)
+			{
+				this.isCheck[i] = GUILayout.Toggle(this.isCheck[i], this.appTypes[i]);
+				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])
+					{
+						selected.Add(this.appTypes[i]);
+					}
+				}
+				NetworkComponent networkComponent = Game.Scene.GetComponent<NetOuterComponent>();
+				Entity session = networkComponent.Get($"{this.managerAddress}");
+				try
+				{
+					session.GetComponent<MessageComponent>().Call<C2M_Reload, M2C_Reload>(new C2M_Reload { AppType = selected });
+				}
+				catch (RpcException e)
+				{
+					Log.Error(e.ToString());
+				}
+				Log.Info("Reload OK!");
+			}
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Editor/ServerManagerEditor/ServerManagerEditor.cs.meta

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

+ 12 - 3
Unity/Assets/Plugins/Base/Message/MessageHandlerAttribute.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Collections.Generic;
 
 namespace Base
 {
@@ -7,11 +8,19 @@ namespace Base
 	/// </summary>
 	public class MessageHandlerAttribute : Attribute
 	{
-		public string AppType { get; private set; }
+		public HashSet<string> AppTypes { get; private set; } = new HashSet<string>();
 
-		public MessageHandlerAttribute(string appType)
+		public MessageHandlerAttribute(params string[] appTypes)
 		{
-			this.AppType = appType;
+			foreach (string appType in appTypes)
+			{
+				this.AppTypes.Add(appType);
+			}
+		}
+
+		public bool Contains(string appType)
+		{
+			return this.AppTypes.Contains(appType);
 		}
 	}
 }

+ 1 - 1
Unity/Assets/Scripts/Component/MessageDispatherComponent.cs

@@ -81,7 +81,7 @@ namespace Model
 					}
 
 					MessageHandlerAttribute messageHandlerAttribute = (MessageHandlerAttribute)attrs[0];
-					if (messageHandlerAttribute.AppType != this.AppType)
+					if (!messageHandlerAttribute.Contains(this.AppType))
 					{
 						continue;
 					}

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

@@ -5,5 +5,6 @@ namespace Model
 		public const int ERR_Success = 0;
 		public const int ERR_AccountOrPasswordError = 1;
 		public const int ERR_ConnectGateKeyError = 2;
+		public const int ERR_ReloadFail = 3;
 	}
 }

+ 26 - 0
Unity/Assets/Scripts/Message/Message.cs

@@ -1,3 +1,4 @@
+using System.Collections.Generic;
 using Base;
 using MongoDB.Bson.Serialization.Attributes;
 
@@ -85,4 +86,29 @@ namespace Model
 	public class G2C_LoginGate : AResponse
 	{
 	}
+
+	[Message(10)]
+	[BsonIgnoreExtraElements]
+	public class C2M_Reload : ARequest
+	{
+		public List<string> AppType = new List<string>();
+	}
+
+	[Message(11)]
+	[BsonIgnoreExtraElements]
+	public class M2C_Reload : AResponse
+	{
+	}
+
+	[Message(12)]
+	[BsonIgnoreExtraElements]
+	public class M2A_Reload : ARequest
+	{
+	}
+
+	[Message(13)]
+	[BsonIgnoreExtraElements]
+	public class A2M_Reload : AResponse
+	{
+	}
 }

+ 2 - 0
Unity/Unity.CSharp.Editor.csproj

@@ -120,10 +120,12 @@
     <Compile Include="Assets\Editor\RsyncEditor\RsyncConfig.cs" />
     <Compile Include="Assets\Editor\RsyncEditor\RsyncEditor.cs" />
     <Compile Include="Assets\Editor\ServerCommandLineEditor\ServerCommandLineEditor.cs" />
+    <Compile Include="Assets\Editor\ServerManagerEditor\ServerManagerEditor.cs" />
   </ItemGroup>
   <ItemGroup>
     <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>