Procházet zdrojové kódy

修复连接错误,并且加上了服务器actor模型

tanghai před 8 roky
rodič
revize
0a883994ad
100 změnil soubory, kde provedl 308 přidání a 381 odebrání
  1. 3 3
      Server/App/Program.cs
  2. 0 1
      Server/App/Properties/AssemblyInfo.cs
  3. 1 1
      Server/Base/DoubleMap.cs
  4. 1 1
      Server/Base/Helper/ArrayHelper.cs
  5. 8 3
      Server/Base/Helper/ByteHelper.cs
  6. 1 1
      Server/Base/Helper/EnumHelper.cs
  7. 1 4
      Server/Base/Helper/FileHelper.cs
  8. 1 1
      Server/Base/Helper/IdGenerater.cs
  9. 1 1
      Server/Base/Helper/MD5Helper.cs
  10. 1 1
      Server/Base/Helper/MethodInfoHelper.cs
  11. 1 1
      Server/Base/Helper/MongoHelper.cs
  12. 1 1
      Server/Base/Helper/NetHelper.cs
  13. 1 1
      Server/Base/Helper/ProtobufHelper.cs
  14. 1 1
      Server/Base/Helper/RandomHelper.cs
  15. 1 1
      Server/Base/Helper/StringHelper.cs
  16. 1 1
      Server/Base/Helper/TimeHelper.cs
  17. 1 1
      Server/Base/Helper/ZipHelper.cs
  18. 1 1
      Server/Base/Log.cs
  19. 1 1
      Server/Base/LogType.cs
  20. 1 1
      Server/Base/Logger/ALogDecorater.cs
  21. 1 1
      Server/Base/Logger/ILog.cs
  22. 1 1
      Server/Base/Logger/NLogAdapter.cs
  23. 1 1
      Server/Base/Logger/StackInfoDecorater.cs
  24. 1 1
      Server/Base/MultiMap.cs
  25. 1 1
      Server/Base/Network/AChannel.cs
  26. 1 4
      Server/Base/Network/AService.cs
  27. 1 1
      Server/Base/Network/TNet/PacketParser.cs
  28. 1 1
      Server/Base/Network/TNet/TBuffer.cs
  29. 1 1
      Server/Base/Network/TNet/TChannel.cs
  30. 1 1
      Server/Base/Network/TNet/TPoller.cs
  31. 1 1
      Server/Base/Network/TNet/TService.cs
  32. 1 1
      Server/Base/Network/TNet/TSocket.cs
  33. 1 1
      Server/Base/Network/UNet/Library.cs
  34. 1 1
      Server/Base/Network/UNet/NativeMethods.cs
  35. 1 1
      Server/Base/Network/UNet/NativeStructs.cs
  36. 1 1
      Server/Base/Network/UNet/UAddress.cs
  37. 1 1
      Server/Base/Network/UNet/UChannel.cs
  38. 1 1
      Server/Base/Network/UNet/UPacket.cs
  39. 1 1
      Server/Base/Network/UNet/UPoller.cs
  40. 1 1
      Server/Base/Network/UNet/UService.cs
  41. 1 1
      Server/Base/Network/UNet/USocket.cs
  42. 1 1
      Server/Base/Network/UNet/USocketManager.cs
  43. 0 1
      Server/Base/Properties/AssemblyInfo.cs
  44. 1 1
      Server/Base/QueueDictionary.cs
  45. 1 1
      Server/Base/TryLocker.cs
  46. 0 1
      Server/Hotfix/Message/C2G_LoginGateHandler.cs
  47. 0 1
      Server/Hotfix/Message/C2M_ReloadHandler.cs
  48. 0 3
      Server/Hotfix/Message/C2R_LoginHandler.cs
  49. 0 1
      Server/Hotfix/Message/G2G_LockReleaseRequestHandler.cs
  50. 0 1
      Server/Hotfix/Message/G2G_LockRequestHandler.cs
  51. 0 1
      Server/Hotfix/Message/M2A_ReloadHandler.cs
  52. 4 0
      Server/Hotfix/Message/ObjectGetRequestHandler.cs
  53. 0 1
      Server/Hotfix/Message/R2G_GetLoginKeyHandler.cs
  54. 0 1
      Server/Hotfix/Properties/AssemblyInfo.cs
  55. 0 1
      Server/Model/Component/ActorComponent.cs
  56. 5 6
      Server/Model/Component/ActorMessageDispatherComponent.cs
  57. 21 0
      Server/Model/Component/ActorProxyComponent.cs
  58. 0 1
      Server/Model/Component/AppManagerComponent.cs
  59. 0 1
      Server/Model/Component/BenchmarkComponent.cs
  60. 0 1
      Server/Model/Component/EventComponent.cs
  61. 0 1
      Server/Model/Component/GateSessionKeyComponent.cs
  62. 8 1
      Server/Model/Component/LocationProxyComponent.cs
  63. 6 7
      Server/Model/Component/MessageDispatherComponent.cs
  64. 4 3
      Server/Model/Component/NetInnerComponent.cs
  65. 7 7
      Server/Model/Component/NetOuterComponent.cs
  66. 5 4
      Server/Model/Component/NetworkComponent.cs
  67. 6 5
      Server/Model/Component/OpcodeTypeComponent.cs
  68. 0 1
      Server/Model/Component/RealmGateAddressComponent.cs
  69. 7 3
      Server/Model/Component/StartConfigComponent.cs
  70. 0 1
      Server/Model/Component/TimerComponent.cs
  71. 0 1
      Server/Model/Component/Unit/LockComponent.cs
  72. 0 1
      Server/Model/Component/Unit/MasterComponent.cs
  73. 0 1
      Server/Model/Config/ACategory.cs
  74. 38 0
      Server/Model/Entity/ActorProxy.cs
  75. 0 2
      Server/Model/Entity/DBTask.cs
  76. 0 3
      Server/Model/Entity/DBTaskQueue.cs
  77. 1 6
      Server/Model/Entity/Game.cs
  78. 2 11
      Server/Model/Entity/Message/InnerOpcode.cs
  79. 0 90
      Server/Model/Entity/Message/OuterMessage.cs
  80. 0 2
      Server/Model/Entity/Scene.cs
  81. 53 55
      Server/Model/Entity/Session.cs
  82. 4 5
      Server/Model/Message/AActorMessage.cs
  83. 13 13
      Server/Model/Message/AMActorHandler.cs
  84. 13 13
      Server/Model/Message/AMHandler.cs
  85. 9 1
      Server/Model/Message/AMessage.cs
  86. 1 0
      Server/Model/Message/ErrorCode.cs
  87. 1 1
      Server/Model/Message/IMActorHandler.cs
  88. 1 1
      Server/Model/Message/IMHandler.cs
  89. 18 0
      Server/Model/Message/IMessagePacker.cs
  90. 0 1
      Server/Model/Object/Disposer.cs
  91. 2 1
      Server/Model/Object/Entity.cs
  92. 0 1
      Server/Model/Object/Object.cs
  93. 0 1
      Server/Model/Object/ObjectEvents.cs
  94. 0 1
      Server/Model/Other/Options.cs
  95. 0 1
      Server/Model/Properties/AssemblyInfo.cs
  96. 19 2
      Server/Model/Server.Model.csproj
  97. 6 0
      Server/Model/Server.Model.csproj.user
  98. 2 0
      Server/Server.sln.DotSettings.user
  99. 0 6
      Unity/Assets/Scripts/Base/Helper/ByteHelper.cs
  100. 0 53
      Unity/Assets/Scripts/Component/NetInnerComponent.cs

+ 3 - 3
Server/App/Program.cs

@@ -1,6 +1,5 @@
 using System;
 using System.Threading;
-using Base;
 using Model;
 using NLog;
 
@@ -65,11 +64,12 @@ namespace App
 					case AppType.AllServer:
 						Game.Scene.AddComponent<LocationComponent>();
 						Game.Scene.AddComponent<ActorMessageDispatherComponent>();
-						Game.Scene.AddComponent<ActorManagerComponent>();
-						Game.Scene.AddComponent<ActorComponent>();
 						Game.Scene.AddComponent<NetInnerComponent, string, int>(innerConfig.Host, innerConfig.Port);
 						Game.Scene.AddComponent<NetOuterComponent, string, int>(outerConfig.Host, outerConfig.Port);
 						Game.Scene.AddComponent<AppManagerComponent>();
+						Game.Scene.AddComponent<LocationProxyComponent>();
+						Game.Scene.AddComponent<ActorManagerComponent>();
+						Game.Scene.AddComponent<ActorComponent>();
 						Game.Scene.AddComponent<RealmGateAddressComponent>();
 						Game.Scene.AddComponent<GateSessionKeyComponent>();
 						break;

+ 0 - 1
Server/App/Properties/AssemblyInfo.cs

@@ -1,5 +1,4 @@
 using System.Reflection;
-using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 
 // 有关程序集的一般信息由以下

+ 1 - 1
Server/Base/DoubleMap.cs

@@ -1,7 +1,7 @@
 using System;
 using System.Collections.Generic;
 
-namespace Base
+namespace Model
 {
 	public class DoubleMap<K, V>
 	{

+ 1 - 1
Server/Base/Helper/ArrayHelper.cs

@@ -1,4 +1,4 @@
-namespace Base
+namespace Model
 {
 	public static class ObjectHelper
 	{

+ 8 - 3
Server/Base/Helper/ByteHelper.cs

@@ -1,7 +1,7 @@
 using System;
 using System.Text;
 
-namespace Base
+namespace Model
 {
 	public static class ByteHelper
 	{
@@ -45,9 +45,14 @@ namespace Base
 			return Encoding.Default.GetString(bytes);
 		}
 
-		public static string Utf8ToStr(this byte[] bytes)
+		public static string ToStr(this byte[] bytes, int offset, int count)
 		{
-			return Encoding.UTF8.GetString(bytes);
+			return Encoding.Default.GetString(bytes, offset, count);
+		}
+
+		public static string Utf8ToStr(this byte[] bytes, int offset, int count)
+		{
+			return Encoding.UTF8.GetString(bytes, offset, count);
 		}
 
 		public static byte[] Reverse(this byte[] bytes)

+ 1 - 1
Server/Base/Helper/EnumHelper.cs

@@ -1,6 +1,6 @@
 using System;
 
-namespace Base
+namespace Model
 {
 	public static class EnumHelper
 	{

+ 1 - 4
Server/Base/Helper/FileHelper.cs

@@ -1,10 +1,7 @@
 using System;
-using System.Collections.Generic;
 using System.IO;
-using System.Linq;
-using System.Text;
 
-namespace Base
+namespace Model
 {
 	public static class FileHelper
 	{

+ 1 - 1
Server/Base/Helper/IdGenerater.cs

@@ -1,4 +1,4 @@
-namespace Base
+namespace Model
 {
 	public static class IdGenerater
 	{

+ 1 - 1
Server/Base/Helper/MD5Helper.cs

@@ -1,7 +1,7 @@
 using System.IO;
 using System.Security.Cryptography;
 
-namespace Base
+namespace Model
 {
 	public static class MD5Helper
 	{

+ 1 - 1
Server/Base/Helper/MethodInfoHelper.cs

@@ -1,6 +1,6 @@
 using System.Reflection;
 
-namespace Base
+namespace Model
 {
 	public static class MethodInfoHelper
 	{

+ 1 - 1
Server/Base/Helper/MongoHelper.cs

@@ -4,7 +4,7 @@ using MongoDB.Bson;
 using MongoDB.Bson.IO;
 using MongoDB.Bson.Serialization;
 
-namespace Base
+namespace Model
 {
 	public static class MongoHelper
 	{

+ 1 - 1
Server/Base/Helper/NetHelper.cs

@@ -1,7 +1,7 @@
 using System.Collections.Generic;
 using System.Net;
 
-namespace Base
+namespace Model
 {
 	public static class NetHelper
 	{

+ 1 - 1
Server/Base/Helper/ProtobufHelper.cs

@@ -3,7 +3,7 @@ using System.ComponentModel;
 using System.IO;
 using ProtoBuf;
 
-namespace Base
+namespace Model
 {
 	public static class ProtobufHelper
 	{

+ 1 - 1
Server/Base/Helper/RandomHelper.cs

@@ -1,6 +1,6 @@
 using System;
 
-namespace Base
+namespace Model
 {
 	public static class RandomHelper
 	{

+ 1 - 1
Server/Base/Helper/StringHelper.cs

@@ -3,7 +3,7 @@ using System.Collections.Generic;
 using System.Globalization;
 using System.Text;
 
-namespace Base
+namespace Model
 {
 	public static class StringHelper
 	{

+ 1 - 1
Server/Base/Helper/TimeHelper.cs

@@ -1,6 +1,6 @@
 using System;
 
-namespace Base
+namespace Model
 {
 	public static class TimeHelper
 	{

+ 1 - 1
Server/Base/Helper/ZipHelper.cs

@@ -1,7 +1,7 @@
 using System.IO;
 using ICSharpCode.SharpZipLib.Zip.Compression;
 
-namespace Base
+namespace Model
 {
 	public static class ZipHelper
 	{

+ 1 - 1
Server/Base/Log.cs

@@ -1,4 +1,4 @@
-namespace Base
+namespace Model
 {
 	public static class Log
 	{

+ 1 - 1
Server/Base/LogType.cs

@@ -1,4 +1,4 @@
-namespace Base
+namespace Model
 {
 	public enum LogType
 	{

+ 1 - 1
Server/Base/Logger/ALogDecorater.cs

@@ -1,4 +1,4 @@
-namespace Base
+namespace Model
 {
 	public abstract class ALogDecorater
 	{

+ 1 - 1
Server/Base/Logger/ILog.cs

@@ -1,4 +1,4 @@
-namespace Base
+namespace Model
 {
 	public interface ILog
 	{

+ 1 - 1
Server/Base/Logger/NLogAdapter.cs

@@ -1,6 +1,6 @@
 using NLog;
 
-namespace Base
+namespace Model
 {
 	public class NLogAdapter: ALogDecorater, ILog
 	{

+ 1 - 1
Server/Base/Logger/StackInfoDecorater.cs

@@ -1,7 +1,7 @@
 using System.Diagnostics;
 using System.IO;
 
-namespace Base
+namespace Model
 {
 	internal class StackInfoDecorater: ALogDecorater
 	{

+ 1 - 1
Server/Base/MultiMap.cs

@@ -1,6 +1,6 @@
 using System.Collections.Generic;
 
-namespace Base
+namespace Model
 {
 	public class MultiMap<T, K>
 	{

+ 1 - 1
Server/Base/Network/AChannel.cs

@@ -3,7 +3,7 @@ using System.Collections.Generic;
 using System.Net.Sockets;
 using System.Threading.Tasks;
 
-namespace Base
+namespace Model
 {
 	[Flags]
 	public enum PacketFlags

+ 1 - 4
Server/Base/Network/AService.cs

@@ -1,10 +1,7 @@
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net.Sockets;
 using System.Threading.Tasks;
 
-namespace Base
+namespace Model
 {
 	public enum NetworkProtocol
 	{

+ 1 - 1
Server/Base/Network/TNet/PacketParser.cs

@@ -1,6 +1,6 @@
 using System;
 
-namespace Base
+namespace Model
 {
 	internal enum ParserState
 	{

+ 1 - 1
Server/Base/Network/TNet/TBuffer.cs

@@ -1,7 +1,7 @@
 using System;
 using System.Collections.Generic;
 
-namespace Base
+namespace Model
 {
 	public class TBuffer
 	{

+ 1 - 1
Server/Base/Network/TNet/TChannel.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Net.Sockets;
 using System.Threading.Tasks;
 
-namespace Base
+namespace Model
 {
 	public class TChannel : AChannel
 	{

+ 1 - 1
Server/Base/Network/TNet/TPoller.cs

@@ -1,7 +1,7 @@
 using System;
 using System.Collections.Generic;
 
-namespace Base
+namespace Model
 {
 	public class TPoller
 	{

+ 1 - 1
Server/Base/Network/TNet/TService.cs

@@ -3,7 +3,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 
-namespace Base
+namespace Model
 {
 	public sealed class TService: AService
 	{

+ 1 - 1
Server/Base/Network/TNet/TSocket.cs

@@ -3,7 +3,7 @@ using System.Net;
 using System.Net.Sockets;
 using System.Threading.Tasks;
 
-namespace Base
+namespace Model
 {
 	/// <summary>
 	/// 封装Socket,将回调push到主线程处理

+ 1 - 1
Server/Base/Network/UNet/Library.cs

@@ -1,6 +1,6 @@
 using System;
 
-namespace Base
+namespace Model
 {
 	internal static class Library
 	{

+ 1 - 1
Server/Base/Network/UNet/NativeMethods.cs

@@ -2,7 +2,7 @@
 using System.Runtime.InteropServices;
 using System.Text;
 
-namespace Base
+namespace Model
 {
 	public static class NativeMethods
 	{

+ 1 - 1
Server/Base/Network/UNet/NativeStructs.cs

@@ -1,7 +1,7 @@
 using System;
 using System.Runtime.InteropServices;
 
-namespace Base
+namespace Model
 {
 	internal enum EventType
 	{

+ 1 - 1
Server/Base/Network/UNet/UAddress.cs

@@ -1,7 +1,7 @@
 using System;
 using System.Net;
 
-namespace Base
+namespace Model
 {
 	internal struct UAddress
 	{

+ 1 - 1
Server/Base/Network/UNet/UChannel.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Net.Sockets;
 using System.Threading.Tasks;
 
-namespace Base
+namespace Model
 {
 	internal class UChannel: AChannel
 	{

+ 1 - 1
Server/Base/Network/UNet/UPacket.cs

@@ -1,7 +1,7 @@
 using System;
 using System.Runtime.InteropServices;
 
-namespace Base
+namespace Model
 {
 	internal sealed class UPacket: IDisposable
 	{

+ 1 - 1
Server/Base/Network/UNet/UPoller.cs

@@ -2,7 +2,7 @@
 using System.Collections.Generic;
 using System.Threading.Tasks;
 
-namespace Base
+namespace Model
 {
 	internal sealed class UPoller : IDisposable
 	{

+ 1 - 1
Server/Base/Network/UNet/UService.cs

@@ -3,7 +3,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 
-namespace Base
+namespace Model
 {
 	public sealed class UService: AService
 	{

+ 1 - 1
Server/Base/Network/UNet/USocket.cs

@@ -3,7 +3,7 @@ using System.Collections.Generic;
 using System.Net;
 using System.Runtime.InteropServices;
 
-namespace Base
+namespace Model
 {
 	internal class BufferInfo
 	{

+ 1 - 1
Server/Base/Network/UNet/USocketManager.cs

@@ -1,7 +1,7 @@
 using System;
 using System.Collections.Generic;
 
-namespace Base
+namespace Model
 {
 	internal class USocketManager
 	{

+ 0 - 1
Server/Base/Properties/AssemblyInfo.cs

@@ -1,5 +1,4 @@
 using System.Reflection;
-using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 
 // 有关程序集的一般信息由以下

+ 1 - 1
Server/Base/QueueDictionary.cs

@@ -1,6 +1,6 @@
 using System.Collections.Generic;
 
-namespace Base
+namespace Model
 {
 	public class QueueDictionary<T, K>
 	{

+ 1 - 1
Server/Base/TryLocker.cs

@@ -1,7 +1,7 @@
 using System;
 using System.Threading;
 
-namespace Base
+namespace Model
 {
 	public class TryLock : IDisposable
 	{

+ 0 - 1
Server/Hotfix/Message/C2G_LoginGateHandler.cs

@@ -1,5 +1,4 @@
 using System;
-using Base;
 using Model;
 
 namespace Hotfix

+ 0 - 1
Server/Hotfix/Message/C2M_ReloadHandler.cs

@@ -1,5 +1,4 @@
 using System;
-using Base;
 using Model;
 
 namespace Hotfix

+ 0 - 3
Server/Hotfix/Message/C2R_LoginHandler.cs

@@ -1,5 +1,4 @@
 using System;
-using Base;
 using Model;
 
 namespace Hotfix
@@ -33,8 +32,6 @@ namespace Hotfix
 				response.Address = outerAddress;
 				response.Key = g2RGetLoginKey.Key;
 				reply(response);
-
-				session.Send(new R2C_ServerLog());
 			}
 			catch (Exception e)
 			{

+ 0 - 1
Server/Hotfix/Message/G2G_LockReleaseRequestHandler.cs

@@ -1,5 +1,4 @@
 using System;
-using Base;
 using Model;
 
 namespace Hotfix

+ 0 - 1
Server/Hotfix/Message/G2G_LockRequestHandler.cs

@@ -1,5 +1,4 @@
 using System;
-using Base;
 using Model;
 
 namespace Hotfix

+ 0 - 1
Server/Hotfix/Message/M2A_ReloadHandler.cs

@@ -1,5 +1,4 @@
 using System;
-using Base;
 using Model;
 
 namespace Hotfix

+ 4 - 0
Server/Hotfix/Message/ObjectGetRequestHandler.cs

@@ -12,6 +12,10 @@ namespace Hotfix
 			try
 			{
 				string location = await Game.Scene.GetComponent<LocationComponent>().GetAsync(message.Key);
+				if (location == "")
+				{
+					response.Error = ErrorCode.ERR_ActorLocationNotFound;
+				}
 				response.Location = location;
 				reply(response);
 			}

+ 0 - 1
Server/Hotfix/Message/R2G_GetLoginKeyHandler.cs

@@ -1,5 +1,4 @@
 using System;
-using Base;
 using Model;
 
 namespace Hotfix

+ 0 - 1
Server/Hotfix/Properties/AssemblyInfo.cs

@@ -1,5 +1,4 @@
 using System.Reflection;
-using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 
 // 有关程序集的一般信息由以下

+ 0 - 1
Server/Model/Component/ActorComponent.cs

@@ -1,5 +1,4 @@
 using System;
-using Base;
 
 namespace Model
 {

+ 5 - 6
Server/Model/Component/ActorMessageDispatherComponent.cs

@@ -1,6 +1,5 @@
 using System;
 using System.Collections.Generic;
-using Base;
 
 namespace Model
 {
@@ -65,15 +64,15 @@ namespace Model
 			}
 		}
 
-		public void Handle(Session session, MessageInfo messageInfo)
+		public void Handle(Session session, object message)
 		{
-			if (!this.handlers.TryGetValue(messageInfo.Message.GetType(), out IMActorHandler handler))
+			if (!this.handlers.TryGetValue(message.GetType(), out IMActorHandler handler))
 			{
-				Log.Error($"not found message handler: {messageInfo.Message.GetType()}");
+				Log.Error($"not found message handler: {message.GetType()}");
 				return;
 			}
-			Entity entity = this.GetComponent<ActorManagerComponent>().Get(((AActorMessage)messageInfo.Message).Id);
-			handler.Handle(session, entity, messageInfo);
+			Entity entity = this.GetComponent<ActorManagerComponent>().Get(((AActorMessage)message).Id);
+			handler.Handle(session, entity, message);
 		}
 
 		public override void Dispose()

+ 21 - 0
Server/Model/Component/ActorProxyComponent.cs

@@ -0,0 +1,21 @@
+using System.Collections.Generic;
+
+namespace Model
+{
+	public class ActorProxyComponent: Component
+	{
+		private readonly Dictionary<long, ActorProxy> dictionary = new Dictionary<long, ActorProxy>();
+
+		public ActorProxy Get(long id)
+		{
+			if (this.dictionary.TryGetValue(id, out ActorProxy actorProxy))
+			{
+				return actorProxy;
+			}
+			
+			actorProxy = new ActorProxy(id);
+			this.dictionary[id] = actorProxy;
+			return actorProxy;
+		}
+	}
+}

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

@@ -2,7 +2,6 @@
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Linq;
-using Base;
 
 namespace Model
 {

+ 0 - 1
Server/Model/Component/BenchmarkComponent.cs

@@ -1,5 +1,4 @@
 using System;
-using Base;
 
 namespace Model
 {

+ 0 - 1
Server/Model/Component/EventComponent.cs

@@ -1,6 +1,5 @@
 using System;
 using System.Collections.Generic;
-using Base;
 
 namespace Model
 {

+ 0 - 1
Server/Model/Component/GateSessionKeyComponent.cs

@@ -1,5 +1,4 @@
 using System.Collections.Generic;
-using Base;
 
 namespace Model
 {

+ 8 - 1
Server/Model/Component/LocationProxyComponent.cs

@@ -31,7 +31,14 @@ namespace Model
 			Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(this.LocationAddress);
 			await session.Call<ObjectRemoveRequest, ObjectRemoveResponse>(new ObjectRemoveRequest() { Key = key });
 		}
-		
+
+		public async Task<string> Get(long key)
+		{
+			Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(this.LocationAddress);
+			ObjectGetResponse response = await session.Call<ObjectGetRequest, ObjectGetResponse>(new ObjectGetRequest() { Key = key });
+			return response.Location;
+		}
+
 		public override void Dispose()
 		{
 			if (this.Id == 0)

+ 6 - 7
Server/Model/Component/MessageDispatherComponent.cs

@@ -1,6 +1,5 @@
 using System;
 using System.Collections.Generic;
-using Base;
 
 namespace Model
 {
@@ -35,7 +34,7 @@ namespace Model
 		public void Load()
 		{
 			this.handlers = new Dictionary<Type, List<IMHandler>>();
-			
+
 			Type[] types = DllHelper.GetMonoTypes();
 			foreach (Type type in types)
 			{
@@ -69,19 +68,19 @@ namespace Model
 			}
 		}
 
-		public void Handle(Session session, MessageInfo messageInfo)
+		public void Handle(Session session, object message)
 		{
-			if (!this.handlers.TryGetValue(messageInfo.Message.GetType(), out List<IMHandler> actions))
+			if (!this.handlers.TryGetValue(message.GetType(), out List<IMHandler> actions))
 			{
-				Log.Error($"消息 {messageInfo.Opcode} 没有处理");
+				Log.Error($"消息 {message.GetType().FullName} 没有处理");
 				return;
 			}
-			
+
 			foreach (IMHandler ev in actions)
 			{
 				try
 				{
-					ev.Handle(session, messageInfo);
+					ev.Handle(session, message);
 				}
 				catch (Exception e)
 				{

+ 4 - 3
Server/Model/Component/NetInnerComponent.cs

@@ -1,5 +1,4 @@
 using System.Collections.Generic;
-using Base;
 
 namespace Model
 {
@@ -21,19 +20,21 @@ namespace Model
 			this.Get().Update();
 		}
 	}
-	
-	public class NetInnerComponent: NetworkComponent
+
+	public class NetInnerComponent : NetworkComponent
 	{
 		private readonly Dictionary<string, Session> adressSessions = new Dictionary<string, Session>();
 
 		public void Awake()
 		{
 			this.Awake(NetworkProtocol.TCP);
+			this.messagePacker = new MongoPacker();
 		}
 
 		public void Awake(string host, int port)
 		{
 			this.Awake(NetworkProtocol.TCP, host, port);
+			this.messagePacker = new MongoPacker();
 		}
 
 		public new void Update()

+ 7 - 7
Server/Model/Component/NetOuterComponent.cs

@@ -1,6 +1,4 @@
-using Base;
-
-namespace Model
+namespace Model
 {
 	[ObjectEvent]
 	public class NetOuterComponentEvent : ObjectEvent<NetOuterComponent>, IAwake, IAwake<string, int>, IUpdate
@@ -20,17 +18,19 @@ namespace Model
 			this.Get().Update();
 		}
 	}
-	
-	public class NetOuterComponent: NetworkComponent
+
+	public class NetOuterComponent : NetworkComponent
 	{
 		public void Awake()
 		{
-			this.Awake(NetworkProtocol.UDP);
+			this.Awake(NetworkProtocol.TCP);
+			this.messagePacker = new JsondotnetPacker();
 		}
 
 		public void Awake(string host, int port)
 		{
-			this.Awake(NetworkProtocol.UDP, host, port);
+			this.Awake(NetworkProtocol.TCP, host, port);
+			this.messagePacker = new JsondotnetPacker();
 		}
 
 		public new void Update()

+ 5 - 4
Server/Model/Component/NetworkComponent.cs

@@ -2,16 +2,17 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
-using Base;
 
 namespace Model
 {
-	public abstract class NetworkComponent: Component
+	public abstract class NetworkComponent : Component
 	{
 		private AService Service;
 
 		private readonly Dictionary<long, Session> sessions = new Dictionary<long, Session>();
 
+		protected IMessagePacker messagePacker;
+
 		protected void Awake(NetworkProtocol protocol)
 		{
 			switch (protocol)
@@ -60,7 +61,7 @@ namespace Model
 		private async Task<Session> Accept()
 		{
 			AChannel channel = await this.Service.AcceptChannel();
-			Session session = new Session(this, channel);
+			Session session = new Session(this, channel, messagePacker);
 			channel.ErrorCallback += (c, e) => { this.Remove(session.Id); };
 			this.sessions.Add(session.Id, session);
 			return session;
@@ -91,7 +92,7 @@ namespace Model
 			int port = int.Parse(ss[1]);
 			string host = ss[0];
 			AChannel channel = this.Service.ConnectChannel(host, port);
-			Session session = new Session(this, channel);
+			Session session = new Session(this, channel, this.messagePacker);
 			channel.ErrorCallback += (c, e) => { this.Remove(session.Id); };
 			this.sessions.Add(session.Id, session);
 			return session;

+ 6 - 5
Server/Model/Component/OpcodeTypeComponent.cs

@@ -19,8 +19,8 @@ namespace Model
 	
 	public class OpcodeTypeComponent : Component
 	{
-		private Dictionary<ushort, Type> opcodeType { get; set; }
-		private Dictionary<Type, ActorMessageAttribute> messageOpcode { get; set; }
+		private Dictionary<ushort, Type> opcodeType;
+		private Dictionary<Type, MessageAttribute> messageOpcode;
 
 		public void Awake()
 		{
@@ -30,17 +30,18 @@ namespace Model
 		public void Load()
 		{
 			this.opcodeType = new Dictionary<ushort, Type>();
+			this.messageOpcode = new Dictionary<Type, MessageAttribute>();
 
 			Type[] types = DllHelper.GetMonoTypes();
 			foreach (Type type in types)
 			{
-				object[] attrs = type.GetCustomAttributes(typeof(ActorMessageAttribute), false);
+				object[] attrs = type.GetCustomAttributes(typeof(MessageAttribute), false);
 				if (attrs.Length == 0)
 				{
 					continue;
 				}
 
-				ActorMessageAttribute messageAttribute = (ActorMessageAttribute)attrs[0];
+				MessageAttribute messageAttribute = (MessageAttribute)attrs[0];
 				this.messageOpcode[type] = messageAttribute;
 				this.opcodeType[messageAttribute.Opcode] = type;
 			}
@@ -48,7 +49,7 @@ namespace Model
 
 		public ushort GetOpcode(Type type)
 		{
-			if (!this.messageOpcode.TryGetValue(type, out ActorMessageAttribute messageAttribute))
+			if (!this.messageOpcode.TryGetValue(type, out MessageAttribute messageAttribute))
 			{
 				throw new Exception($"查找Opcode失败: {type.Name}");
 			}

+ 0 - 1
Server/Model/Component/RealmGateAddressComponent.cs

@@ -1,5 +1,4 @@
 using System.Collections.Generic;
-using Base;
 
 namespace Model
 {

+ 7 - 3
Server/Model/Component/StartConfigComponent.cs

@@ -1,7 +1,6 @@
 using System;
 using System.Collections.Generic;
 using System.IO;
-using Base;
 
 namespace Model
 {
@@ -44,9 +43,14 @@ namespace Model
 					this.allConfigs.Add(startConfig);
 					this.configDict.Add(startConfig.AppId, startConfig);
 
-					if (startConfig.AppType == AppType.Location)
+					if (startConfig.AppType.Is(AppType.Realm))
 					{
-						LocationConfig = startConfig;
+						this.RealmConfig = startConfig;
+					}
+
+					if (startConfig.AppType.Is(AppType.Location))
+					{
+						this.LocationConfig = startConfig;
 					}
 				}
 				catch (Exception)

+ 0 - 1
Server/Model/Component/TimerComponent.cs

@@ -1,7 +1,6 @@
 using System.Collections.Generic;
 using System.Threading;
 using System.Threading.Tasks;
-using Base;
 
 namespace Model
 {

+ 0 - 1
Server/Model/Component/Unit/LockComponent.cs

@@ -1,7 +1,6 @@
 using System;
 using System.Collections.Generic;
 using System.Threading.Tasks;
-using Base;
 
 namespace Model
 {

+ 0 - 1
Server/Model/Component/Unit/MasterComponent.cs

@@ -1,6 +1,5 @@
 using System.Collections.Generic;
 using System.Threading.Tasks;
-using Base;
 
 namespace Model
 {

+ 0 - 1
Server/Model/Config/ACategory.cs

@@ -1,7 +1,6 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
-using Base;
 
 namespace Model
 {

+ 38 - 0
Server/Model/Entity/ActorProxy.cs

@@ -0,0 +1,38 @@
+using System.Threading.Tasks;
+
+namespace Model
+{
+	public sealed class ActorProxy : Entity
+	{
+		public string Address;
+		
+		public ActorProxy(long id): base(id)
+		{
+		}
+
+		public void Send<Message>(Message message) where Message : AActorMessage
+		{
+			Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(this.Address);
+			session.Send(message);
+		}
+
+		public async Task<Response> Call<Request, Response>(Request request) where Request : AActorRequest where Response: AActorResponse
+		{
+			this.Address = await this.Parent.GetComponent<LocationProxyComponent>().Get(this.Id);
+			
+			Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(this.Address);
+			Response response = await session.Call<Request, Response>(request);
+			return response;
+		}
+
+		public override void Dispose()
+		{
+			if (this.Id == 0)
+			{
+				return;
+			}
+
+			base.Dispose();
+		}
+	}
+}

+ 0 - 2
Server/Model/Entity/DBTask.cs

@@ -1,8 +1,6 @@
 using System;
 using System.Collections.Generic;
 using System.Threading.Tasks;
-using Base;
-using Model;
 using MongoDB.Bson;
 using MongoDB.Driver;
 

+ 0 - 3
Server/Model/Entity/DBTaskQueue.cs

@@ -1,9 +1,6 @@
 using System;
 using System.Collections.Generic;
-using System.Threading;
 using System.Threading.Tasks;
-using Base;
-using Model;
 
 namespace Model
 {

+ 1 - 6
Server/Model/Entity/Game.cs

@@ -1,9 +1,4 @@
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Base;
-
-namespace Model
+namespace Model
 {
 	public static class Game
 	{

+ 2 - 11
Server/Model/Entity/Message/Opcode.cs → Server/Model/Entity/Message/InnerOpcode.cs

@@ -1,6 +1,6 @@
 namespace Model
 {
-	public static class Opcode
+	public static partial class Opcode
 	{
 		public const ushort G2G_LockRequest = 10;
 		public const ushort G2G_LockResponse = 11;
@@ -31,16 +31,7 @@
 		public const ushort ObjectUnLockResponse = 77;
 		public const ushort ObjectGetRequest = 78;
 		public const ushort ObjectGetResponse = 79;
-
-		public const ushort C2R_Login = 1000;
-		public const ushort R2C_Login = 1002;
-		public const ushort R2C_ServerLog = 1003;
-		public const ushort C2G_LoginGate = 1004;
-		public const ushort G2C_LoginGate = 1005;
-		public const ushort C2G_GetPlayerInfo = 1006;
-		public const ushort G2C_GetPlayerInfo = 1007;
-		public const ushort C2M_Reload = 1008;
-
+		
 		public const ushort R2G_GetLoginKey = 10001;
 		public const ushort G2R_GetLoginKey = 10002;
 	}

+ 0 - 90
Server/Model/Entity/Message/OuterMessage.cs

@@ -1,90 +0,0 @@
-using Base;
-using MongoDB.Bson.Serialization.Attributes;
-
-// 服务器与客户端之间的消息 Opcode从1-9999
-
-namespace Model
-{
-	[Message(Opcode.C2R_Login)]
-	[BsonIgnoreExtraElements]
-	public class C2R_Login: ARequest
-	{
-		[BsonElement("A")]
-		public string Account;
-
-		[BsonElement("P")]
-		public string Password;
-	}
-
-	[Message(Opcode.R2C_Login)]
-	[BsonIgnoreExtraElements]
-	public class R2C_Login: AResponse
-	{
-		[BsonElement("A")]
-		public string Address { get; set; }
-
-		[BsonElement("K")]
-		public long Key { get; set; }
-	}
-
-	[Message(Opcode.R2C_ServerLog)]
-	[BsonIgnoreExtraElements]
-	public class R2C_ServerLog: AMessage
-	{
-		[BsonElement("AT")]
-		public AppType AppType { get; set; }
-
-		[BsonElement("A")]
-		public int AppId { get; set; }
-
-		[BsonElement("T")]
-		public LogType Type { get; set; }
-
-		[BsonElement("L")]
-		public string Log { get; set; }
-	}
-
-	[Message(Opcode.C2G_LoginGate)]
-	[BsonIgnoreExtraElements]
-	public class C2G_LoginGate: ARequest
-	{
-		[BsonElement("K")]
-		public long Key;
-
-		public C2G_LoginGate(long key)
-		{
-			this.Key = key;
-		}
-	}
-
-	[Message(Opcode.G2C_LoginGate)]
-	[BsonIgnoreExtraElements]
-	public class G2C_LoginGate: AResponse
-	{
-	}
-
-	[Message(Opcode.C2M_Reload)]
-	[BsonIgnoreExtraElements]
-	public class C2M_Reload: ARequest
-	{
-		public AppType AppType;
-	}
-
-	[Message(11)]
-	[BsonIgnoreExtraElements]
-	public class M2C_Reload: AResponse
-	{
-	}
-
-	[Message(14)]
-	[BsonIgnoreExtraElements]
-	public class C2R_Ping: ARequest
-	{
-	}
-
-	[Message(15)]
-	[BsonIgnoreExtraElements]
-	public class R2C_Ping: AResponse
-	{
-	}
-}

+ 0 - 2
Server/Model/Entity/Scene.cs

@@ -17,8 +17,6 @@
 	
 	public sealed class Scene: Entity
 	{
-		public Scene Parent { get; set; }
-
 		public string Name { get; set; }
 
 		public SceneType SceneType { get; private set; }

+ 53 - 55
Server/Model/Entity/Session.cs

@@ -2,8 +2,6 @@
 using System.Collections.Generic;
 using System.Threading;
 using System.Threading.Tasks;
-using Base;
-using MongoDB.Bson;
 
 namespace Model
 {
@@ -11,14 +9,17 @@ namespace Model
 	{
 		private static uint RpcId { get; set; }
 		private readonly NetworkComponent network;
-		private readonly Dictionary<uint, Action<byte[], int, int>> requestCallback = new Dictionary<uint, Action<byte[], int, int>>();
+		private readonly Dictionary<uint, Action<object>> requestCallback = new Dictionary<uint, Action<object>>();
 		private readonly AChannel channel;
 		private bool isRpc;
 
-		public Session(NetworkComponent network, AChannel channel)
+		private readonly IMessagePacker messagePacker;
+
+		public Session(NetworkComponent network, AChannel channel, IMessagePacker messagePacker)
 		{
 			this.network = network;
 			this.channel = channel;
+			this.messagePacker = messagePacker;
 			this.StartRecv();
 		}
 
@@ -64,13 +65,12 @@ namespace Model
 					continue;
 				}
 
-				if (messageBytes.Length < 6)
+				if (messageBytes.Length < 3)
 				{
 					continue;
 				}
 
 				ushort opcode = BitConverter.ToUInt16(messageBytes, 0);
-
 				try
 				{
 					this.Run(opcode, messageBytes);
@@ -85,71 +85,71 @@ namespace Model
 		private void Run(ushort opcode, byte[] messageBytes)
 		{
 			int offset = 0;
-			uint flag = BitConverter.ToUInt32(messageBytes, 2);
+			byte flag = messageBytes[2];
 
-			bool isCompressed = (flag & 0x80000000) > 0;
+			bool isCompressed = (flag & 0x80) > 0;
+			const int opcodeAndFlagLength = 3;
 			if (isCompressed) // 最高位为1,表示有压缩,需要解压缩
 			{
-				messageBytes = ZipHelper.Decompress(messageBytes, 6, messageBytes.Length - 6);
+				messageBytes = ZipHelper.Decompress(messageBytes, opcodeAndFlagLength, messageBytes.Length - opcodeAndFlagLength);
 				offset = 0;
 			}
 			else
 			{
-				offset = 6;
+				offset = opcodeAndFlagLength;
 			}
 
-			this.RunDecompressedBytes(opcode, flag, messageBytes, offset);
+			this.RunDecompressedBytes(opcode, messageBytes, offset);
 		}
 
-		private void RunDecompressedBytes(ushort opcode, uint flag, byte[] messageBytes, int offset)
+		private void RunDecompressedBytes(ushort opcode, byte[] messageBytes, int offset)
 		{
-			uint rpcFlag = flag & 0x40000000;
-			uint rpcId = flag & 0x3fffffff;
-
-			// 普通消息或者是Rpc请求消息
-			if (rpcFlag == 0)
+			Type messageType = this.network.Owner.GetComponent<OpcodeTypeComponent>().GetType(opcode);
+			object message = messagePacker.DeserializeFrom(messageType, messageBytes, offset, messageBytes.Length - offset);
+			
+			if (message is AActorMessage)
 			{
-				MessageInfo messageInfo = new MessageInfo(opcode, messageBytes, offset, rpcId);
-				Type messageType = this.network.Owner.GetComponent<OpcodeTypeComponent>().GetType(messageInfo.Opcode);
-				object message = MongoHelper.FromBson(messageType, messageInfo.MessageBytes, messageInfo.Offset, messageInfo.Count);
-				messageInfo.Message = message;
-				if (message is AActorMessage)
-				{
-					this.network.Owner.GetComponent<ActorMessageDispatherComponent>().Handle(this, messageInfo);
-				}
-				else
-				{
-					this.network.Owner.GetComponent<MessageDispatherComponent>().Handle(this, messageInfo);
-				}
+				this.network.Owner.GetComponent<ActorMessageDispatherComponent>().Handle(this, message);
+				return;
+			}
+			if (message is AMessage || message is ARequest)
+			{
+				this.network.Owner.GetComponent<MessageDispatherComponent>().Handle(this, message);
 				return;
 			}
 
-			// rpcFlag>0 表示这是一个rpc响应消息
-			// Rpc回调有找不着的可能,因为client可能取消Rpc调用
-			if (!this.requestCallback.TryGetValue(rpcId, out Action<byte[], int, int> action))
+			if (message is AResponse response)
 			{
+				// rpcFlag>0 表示这是一个rpc响应消息
+				// Rpc回调有找不着的可能,因为client可能取消Rpc调用
+				if (!this.requestCallback.TryGetValue(response.RpcId, out Action<object> action))
+				{
+					return;
+				}
+				this.requestCallback.Remove(response.RpcId);
+				action(message);
 				return;
 			}
-			this.requestCallback.Remove(rpcId);
-			action(messageBytes, offset, messageBytes.Length - offset);
+
+			throw new Exception($"message type error: {message.GetType().FullName}");
 		}
 
 		/// <summary>
 		/// Rpc调用
 		/// </summary>
 		public Task<Response> Call<Request, Response>(Request request, CancellationToken cancellationToken) where Request : ARequest
-				where Response : AResponse
+			where Response : AResponse
 		{
-
-			this.SendMessage(++RpcId, request);
+			request.RpcId = ++RpcId;
+			this.SendMessage(request);
 
 			var tcs = new TaskCompletionSource<Response>();
 
-			this.requestCallback[RpcId] = (bytes, offset, count) =>
+			this.requestCallback[RpcId] = (message) =>
 			{
 				try
 				{
-					Response response = MongoHelper.FromBson<Response>(bytes, offset, count);
+					Response response = (Response)message;
 					if (response.Error != 0)
 					{
 						tcs.SetException(new RpcException(response.Error, response.Message));
@@ -175,20 +175,21 @@ namespace Model
 		/// </summary>
 		public Task<Response> Call<Request, Response>(Request request) where Request : ARequest where Response : AResponse
 		{
-			this.SendMessage(++RpcId, request);
+			request.RpcId = ++RpcId;
+			this.SendMessage(request);
 
 			var tcs = new TaskCompletionSource<Response>();
-			this.requestCallback[RpcId] = (bytes, offset, count) =>
+			this.requestCallback[RpcId] = (message) =>
 			{
 				try
 				{
-					Response response = MongoHelper.FromBson<Response>(bytes, offset, count);
+					Response response = (Response)message;
 					if (response.Error != 0)
 					{
 						tcs.SetException(new RpcException(response.Error, response.Message));
 						return;
 					}
-					//Log.Info($"recv: {response.ToJson()}");
+					//Log.Debug($"recv: {response.ToJson()}");
 					this.isRpc = true;
 					tcs.SetResult(response);
 				}
@@ -207,42 +208,39 @@ namespace Model
 			{
 				throw new Exception("session已经被Dispose了");
 			}
-			this.SendMessage(0, message);
+			this.SendMessage(message);
 		}
 
-		public void Reply<Response>(uint rpcId, Response message)
+		public void Reply<Response>(Response message) where Response : AResponse
 		{
 			if (this.Id == 0)
 			{
 				throw new Exception("session已经被Dispose了");
 			}
-			this.SendMessage(rpcId, message, false);
+			this.SendMessage(message);
 		}
 
-		private void SendMessage(uint rpcId, object message, bool isCall = true)
+		private void SendMessage(object message)
 		{
 			//Log.Debug($"send: {message.ToJson()}");
 			ushort opcode = this.network.Owner.GetComponent<OpcodeTypeComponent>().GetOpcode(message.GetType());
 			byte[] opcodeBytes = BitConverter.GetBytes(opcode);
-			if (!isCall)
-			{
-				rpcId = rpcId | 0x40000000;
-			}
 
-			byte[] messageBytes = message.ToBson();
+			byte[] messageBytes = messagePacker.SerializeToByteArray(message);
+			byte flag = 0;
 			if (messageBytes.Length > 100)
 			{
 				byte[] newMessageBytes = ZipHelper.Compress(messageBytes);
 				if (newMessageBytes.Length < messageBytes.Length)
 				{
 					messageBytes = newMessageBytes;
-					rpcId = rpcId | 0x80000000;
+					flag |= 0x80;
 				}
 			}
 
-			byte[] seqBytes = BitConverter.GetBytes(rpcId);
+			byte[] flagBytes = { flag };
 
-			channel.Send(new List<byte[]> { opcodeBytes, seqBytes, messageBytes });
+			channel.Send(new List<byte[]> { opcodeBytes, flagBytes, messageBytes });
 		}
 
 		public override void Dispose()

+ 4 - 5
Server/Model/Message/AActorMessage.cs

@@ -1,20 +1,19 @@
 namespace Model
 {
-	public abstract class AActorMessage
+	public abstract class AActorMessage: AMessage
 	{
 		public long Id { get; set; }
 	}
 
-	public abstract class AActorRequest : AMessage
+	public abstract class AActorRequest : ARequest
 	{
+		public long Id { get; set; }
 	}
 
 	/// <summary>
 	/// 服务端回的RPC消息需要继承这个抽象类
 	/// </summary>
-	public abstract class AActorResponse
+	public abstract class AActorResponse: AResponse
 	{
-		public int Error = 0;
-		public string Message = "";
 	}
 }

+ 13 - 13
Server/Model/Message/AMActorHandler.cs

@@ -1,18 +1,17 @@
 using System;
-using Base;
 
 namespace Model
 {
-	public abstract class AMActorHandler<E, Message>: IMActorHandler where E: Entity where Message : AActorMessage
+	public abstract class AMActorHandler<E, Message> : IMActorHandler where E : Entity where Message : AActorMessage
 	{
 		protected abstract void Run(E entity, Message message);
 
-		public void Handle(Session session, Entity entity, MessageInfo messageInfo)
+		public void Handle(Session session, Entity entity, object msg)
 		{
-			Message message = messageInfo.Message as Message;
+			Message message = msg as Message;
 			if (message == null)
 			{
-				Log.Error($"消息类型转换错误: {messageInfo.Message.GetType().Name} to {typeof (Message).Name}");
+				Log.Error($"消息类型转换错误: {msg.GetType().FullName} to {typeof(Message).Name}");
 			}
 			E e = entity as E;
 			if (e == null)
@@ -24,11 +23,11 @@ namespace Model
 
 		public Type GetMessageType()
 		{
-			return typeof (Message);
+			return typeof(Message);
 		}
 	}
 
-	public abstract class AMActorRpcHandler<Request, Response>: IMActorHandler where Request : AActorRequest where Response : AActorResponse
+	public abstract class AMActorRpcHandler<Request, Response> : IMActorHandler where Request : AActorRequest where Response : AActorResponse
 	{
 		protected static void ReplyError(Response response, Exception e, Action<Response> reply)
 		{
@@ -40,14 +39,14 @@ namespace Model
 
 		protected abstract void Run(Entity entity, Request message, Action<Response> reply);
 
-		public void Handle(Session session, Entity entity,  MessageInfo messageInfo)
+		public void Handle(Session session, Entity entity, object message)
 		{
 			try
 			{
-				Request request = messageInfo.Message as Request;
+				Request request = message as Request;
 				if (request == null)
 				{
-					Log.Error($"消息类型转换错误: {messageInfo.Message.GetType().Name} to {typeof (Request).Name}");
+					Log.Error($"消息类型转换错误: {message.GetType().FullName} to {typeof(Request).Name}");
 				}
 				this.Run(session, request, response =>
 				{
@@ -56,18 +55,19 @@ namespace Model
 					{
 						return;
 					}
-					session.Reply(messageInfo.RpcId, response);
+					response.RpcId = request.RpcId;
+					session.Reply(response);
 				});
 			}
 			catch (Exception e)
 			{
-				throw new Exception($"解释消息失败: {messageInfo.Opcode}", e);
+				throw new Exception($"解释消息失败: {message.GetType().FullName}", e);
 			}
 		}
 
 		public Type GetMessageType()
 		{
-			return typeof (Request);
+			return typeof(Request);
 		}
 	}
 }

+ 13 - 13
Server/Model/Message/AMHandler.cs

@@ -1,29 +1,28 @@
 using System;
-using Base;
 
 namespace Model
 {
-	public abstract class AMHandler<Message>: IMHandler where Message : AMessage
+	public abstract class AMHandler<Message> : IMHandler where Message : AMessage
 	{
 		protected abstract void Run(Session session, Message message);
 
-		public void Handle(Session session, MessageInfo messageInfo)
+		public void Handle(Session session, object msg)
 		{
-			Message message = messageInfo.Message as Message;
+			Message message = msg as Message;
 			if (message == null)
 			{
-				Log.Error($"消息类型转换错误: {messageInfo.Message.GetType().Name} to {typeof (Message).Name}");
+				Log.Error($"消息类型转换错误: {msg.GetType().Name} to {typeof(Message).Name}");
 			}
 			this.Run(session, message);
 		}
 
 		public Type GetMessageType()
 		{
-			return typeof (Message);
+			return typeof(Message);
 		}
 	}
 
-	public abstract class AMRpcHandler<Request, Response>: IMHandler where Request : ARequest where Response : AResponse
+	public abstract class AMRpcHandler<Request, Response> : IMHandler where Request : ARequest where Response : AResponse
 	{
 		protected static void ReplyError(Response response, Exception e, Action<Response> reply)
 		{
@@ -35,14 +34,14 @@ namespace Model
 
 		protected abstract void Run(Session session, Request message, Action<Response> reply);
 
-		public void Handle(Session session, MessageInfo messageInfo)
+		public void Handle(Session session, object message)
 		{
 			try
 			{
-				Request request = messageInfo.Message as Request;
+				Request request = message as Request;
 				if (request == null)
 				{
-					Log.Error($"消息类型转换错误: {messageInfo.Message.GetType().Name} to {typeof (Request).Name}");
+					Log.Error($"消息类型转换错误: {message.GetType().Name} to {typeof(Request).Name}");
 				}
 				this.Run(session, request, response =>
 				{
@@ -51,18 +50,19 @@ namespace Model
 					{
 						return;
 					}
-					session.Reply(messageInfo.RpcId, response);
+					response.RpcId = request.RpcId;
+					session.Reply(response);
 				});
 			}
 			catch (Exception e)
 			{
-				throw new Exception($"解释消息失败: {messageInfo.Opcode}", e);
+				throw new Exception($"解释消息失败: {message.GetType().FullName}", e);
 			}
 		}
 
 		public Type GetMessageType()
 		{
-			return typeof (Request);
+			return typeof(Request);
 		}
 	}
 }

+ 9 - 1
Server/Model/Message/AMessage.cs

@@ -4,8 +4,9 @@
 	{
 	}
 
-	public abstract class ARequest: AMessage
+	public abstract class ARequest
 	{
+		public uint RpcId;
 	}
 
 	/// <summary>
@@ -13,7 +14,14 @@
 	/// </summary>
 	public abstract class AResponse
 	{
+		public uint RpcId;
+
 		public int Error = 0;
 		public string Message = "";
 	}
+
+	public abstract class AFrameMessage : AMessage
+	{
+		public long Id;
+	}
 }

+ 1 - 0
Server/Model/Message/ErrorCode.cs

@@ -8,5 +8,6 @@ namespace Model
 		public const int ERR_ConnectGateKeyError = 3;
 		public const int ERR_ReloadFail = 4;
 		public const int ERR_NotFoundUnit = 5;
+		public const int ERR_ActorLocationNotFound = 6;
 	}
 }

+ 1 - 1
Server/Model/Message/IMActorHandler.cs

@@ -4,7 +4,7 @@ namespace Model
 {
 	public interface IMActorHandler
 	{
-		void Handle(Session session, Entity entity, MessageInfo messageInfo);
+		void Handle(Session session, Entity entity, object message);
 		Type GetMessageType();
 	}
 }

+ 1 - 1
Server/Model/Message/IMHandler.cs

@@ -4,7 +4,7 @@ namespace Model
 {
 	public interface IMHandler
 	{
-		void Handle(Session session, MessageInfo messageInfo);
+		void Handle(Session session, object message);
 		Type GetMessageType();
 	}
 }

+ 18 - 0
Server/Model/Message/IMessagePacker.cs

@@ -0,0 +1,18 @@
+using System;
+
+namespace Model
+{
+	public interface IMessagePacker
+	{
+		byte[] SerializeToByteArray(object obj);
+		string SerializeToText(object obj);
+
+		object DeserializeFrom(Type type, byte[] bytes);
+		object DeserializeFrom(Type type, byte[] bytes, int index, int count);
+		T DeserializeFrom<T>(byte[] bytes);
+		T DeserializeFrom<T>(byte[] bytes, int index, int count);
+
+		T DeserializeFrom<T>(string str);
+		object DeserializeFrom(Type type, string str);
+	}
+}

+ 0 - 1
Server/Model/Object/Disposer.cs

@@ -1,5 +1,4 @@
 using System;
-using Base;
 
 namespace Model
 {

+ 2 - 1
Server/Model/Object/Entity.cs

@@ -1,7 +1,6 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
-using Base;
 using MongoDB.Bson.Serialization.Attributes;
 
 namespace Model
@@ -10,6 +9,8 @@ namespace Model
 	{
 		public EntityType Type { get; set; }
 
+		public Entity Parent { get; set; }
+
 		[BsonElement]
 		[BsonIgnoreIfNull]
 		private HashSet<Component> components = new HashSet<Component>();

+ 0 - 1
Server/Model/Object/Object.cs

@@ -1,6 +1,5 @@
 using System;
 using System.ComponentModel;
-using Base;
 using MongoDB.Bson;
 using MongoDB.Bson.Serialization.Attributes;
 

+ 0 - 1
Server/Model/Object/ObjectEvents.cs

@@ -2,7 +2,6 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Reflection;
-using Base;
 
 namespace Model
 {

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

@@ -1,5 +1,4 @@
 using System;
-using Base;
 using MongoDB.Bson;
 
 #if SERVER

+ 0 - 1
Server/Model/Properties/AssemblyInfo.cs

@@ -1,5 +1,4 @@
 using System.Reflection;
-using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 
 // 有关程序集的一般信息由以下

+ 19 - 2
Server/Model/Server.Model.csproj

@@ -44,10 +44,26 @@
     <Reference Include="MongoDB.Driver.Core">
       <HintPath>..\Lib\MongoDB.Driver.Core.dll</HintPath>
     </Reference>
+    <Reference Include="Newtonsoft.Json">
+      <HintPath>..\..\..\X1\X1\client\trunk\Server\Lib\Newtonsoft.Json.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="..\..\Unity\Assets\Scripts\Entity\Message\Opcode.cs">
+      <Link>Entity\Message\Opcode.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Entity\Message\OuterMessage.cs">
+      <Link>Entity\Message\OuterMessage.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Message\JsondotnetPacker.cs">
+      <Link>Message\JsondotnetPacker.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Message\MongoPacker.cs">
+      <Link>Message\MongoPacker.cs</Link>
+    </Compile>
+    <Compile Include="Component\ActorProxyComponent.cs" />
     <Compile Include="Component\OpcodeTypeComponent.cs" />
     <Compile Include="Component\ActorManagerComponent.cs" />
     <Compile Include="Component\BenchmarkComponent.cs" />
@@ -88,6 +104,8 @@
     <Compile Include="Config\ICategory.cs" />
     <Compile Include="Entity\Config\BuffConfig.cs" />
     <Compile Include="Entity\Config\StartConfig.cs" />
+    <Compile Include="Entity\ActorProxy.cs" />
+    <Compile Include="Entity\Message\InnerOpcode.cs" />
     <Compile Include="Entity\SceneEntity.cs" />
     <Compile Include="Entity\DBSceneEntity.cs" />
     <Compile Include="Entity\DBEntity.cs" />
@@ -96,8 +114,6 @@
     <Compile Include="Entity\Game.cs" />
     <Compile Include="Entity\Http.cs" />
     <Compile Include="Entity\Message\InnerMessage.cs" />
-    <Compile Include="Entity\Message\Opcode.cs" />
-    <Compile Include="Entity\Message\OuterMessage.cs" />
     <Compile Include="Entity\Scene.cs" />
     <Compile Include="Entity\Session.cs" />
     <Compile Include="Entity\Unit.cs" />
@@ -115,6 +131,7 @@
     <Compile Include="Message\AppType.cs" />
     <Compile Include="Message\ErrorCode.cs" />
     <Compile Include="Message\IMActorHandler.cs" />
+    <Compile Include="Message\IMessagePacker.cs" />
     <Compile Include="Message\IMHandler.cs" />
     <Compile Include="Message\ActorMessageAttribute.cs" />
     <Compile Include="Message\MessageAttribute.cs" />

+ 6 - 0
Server/Model/Server.Model.csproj.user

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <ProjectView>ProjectFiles</ProjectView>
+  </PropertyGroup>
+</Project>

+ 2 - 0
Server/Server.sln.DotSettings.user

@@ -0,0 +1,2 @@
+<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
+	<s:Boolean x:Key="/Default/Environment/OpenDocument/OpenDocumentAfterModification/@EntryValue">False</s:Boolean></wpf:ResourceDictionary>

+ 0 - 6
Unity/Assets/Scripts/Base/Helper/ByteHelper.cs

@@ -59,11 +59,5 @@ namespace Model
 		{
 			return Encoding.UTF8.GetString(bytes, index, count);
 		}
-
-		public static byte[] Reverse(this byte[] bytes)
-		{
-			Array.Reverse(bytes);
-			return bytes;
-		}
 	}
 }

+ 0 - 53
Unity/Assets/Scripts/Component/NetInnerComponent.cs

@@ -1,53 +0,0 @@
-using System.Collections.Generic;
-
-namespace Model
-{
-	[EntityEvent(EntityEventId.NetInnerComponent)]
-	public class NetInnerComponent: NetworkComponent
-	{
-		private readonly Dictionary<string, Session> adressSessions = new Dictionary<string, Session>();
-
-		private void Awake()
-		{
-			this.Awake(NetworkProtocol.TCP);
-		}
-
-		private void Awake(string host, int port)
-		{
-			this.Awake(NetworkProtocol.TCP, host, port);
-		}
-
-		private new void Update()
-		{
-			base.Update();
-		}
-
-		public override void Remove(long id)
-		{
-			Session session = this.Get(id);
-			if (session == null)
-			{
-				return;
-			}
-			this.adressSessions.Remove(session.RemoteAddress);
-
-			base.Remove(id);
-		}
-
-		/// <summary>
-		/// 从地址缓存中取Session,如果没有则创建一个新的Session,并且保存到地址缓存中
-		/// </summary>
-		public Session Get(string address)
-		{
-			Session session;
-			if (this.adressSessions.TryGetValue(address, out session))
-			{
-				return session;
-			}
-
-			session = this.Create(address);
-			this.adressSessions.Add(address, session);
-			return session;
-		}
-	}
-}

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů