Переглянути джерело

客户端登录,realm分配gate需要告诉客户端Gate的Id

tanghai 6 роки тому
батько
коміт
9fa4647c49

+ 27 - 0
FileServer/Properties/launchSettings.json

@@ -0,0 +1,27 @@
+{
+  "iisSettings": {
+    "windowsAuthentication": false,
+    "anonymousAuthentication": true,
+    "iisExpress": {
+      "applicationUrl": "http://localhost:56073/",
+      "sslPort": 0
+    }
+  },
+  "profiles": {
+    "IIS Express": {
+      "commandName": "IISExpress",
+      "launchBrowser": true,
+      "environmentVariables": {
+        "ASPNETCORE_ENVIRONMENT": "Development"
+      }
+    },
+    "FileServer": {
+      "commandName": "Project",
+      "launchBrowser": true,
+      "environmentVariables": {
+        "ASPNETCORE_ENVIRONMENT": "Development"
+      },
+      "applicationUrl": "http://localhost:56076/"
+    }
+  }
+}

+ 2 - 0
Proto/HotfixMessage.proto

@@ -15,12 +15,14 @@ message R2C_Login // IResponse
 	string Message = 92;
 	string Address = 1;
 	int64 Key	    = 2;
+	int64 GateId = 3;
 }
 
 message C2G_LoginGate // IRequest
 {
 	int32 RpcId = 90;
 	int64 Key = 1;	// 帐号
+	int64 GateId = 2;
 }
 
 message G2C_LoginGate // IResponse

+ 2 - 1
Proto/InnerMessage.proto

@@ -11,7 +11,7 @@ message M2M_TrasferUnitRequest // IActorRequest
     Unit Unit = 1;
 }
 
-message M2M_TrasferUnitResponse // IActorResponse
+message M2M_TrasferUnitResponse // IActorResponseG2R_GetLoginKey
 {
     int32 RpcId = 90;
     int32 Error = 91;
@@ -149,6 +149,7 @@ message G2R_GetLoginKey // IActorResponse
     string Message = 92;
 
     int64 Key = 1;
+    int64 GateId = 2;
 }
 
 message G2M_CreateUnit // IActorRequest

+ 8 - 2
Server/Hotfix/Module/Demo/C2G_LoginGateHandler.cs

@@ -8,7 +8,13 @@ namespace ETHotfix
 	{
 		protected override async ETTask Run(Session session, C2G_LoginGate request, G2C_LoginGate response, Action reply)
 		{
-			string account = Game.Scene.GetComponent<GateSessionKeyComponent>().Get(request.Key);
+			Scene scene = Game.Scene.Get(request.GateId);
+			if (scene == null)
+			{
+				return;
+			}
+			
+			string account = scene.GetComponent<GateSessionKeyComponent>().Get(request.Key);
 			if (account == null)
 			{
 				response.Error = ErrorCode.ERR_ConnectGateKeyError;
@@ -17,7 +23,7 @@ namespace ETHotfix
 				return;
 			}
 			Player player = EntityFactory.Create<Player, string>(Game.Scene, account);
-			Game.Scene.GetComponent<PlayerComponent>().Add(player);
+			scene.GetComponent<PlayerComponent>().Add(player);
 			session.AddComponent<SessionPlayerComponent>().Player = player;
 			session.AddComponent<MailBoxComponent, MailboxType>(MailboxType.GateSession);
 

+ 4 - 11
Server/Hotfix/Module/Demo/C2R_LoginHandler.cs

@@ -9,26 +9,19 @@ namespace ETHotfix
 	{
 		protected override async ETTask Run(Session session, C2R_Login request, R2C_Login response, Action reply)
 		{
-			//if (message.Account != "abcdef" || message.Password != "111111")
-			//{
-			//	response.Error = ErrorCode.ERR_AccountOrPasswordError;
-			//	reply(response);
-			//	return;
-			//}
-
 			// 随机分配一个Gate
 			StartConfig config = RealmGateAddressHelper.GetGate();
 			//Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
-			string innerAddress = config.GetComponent<InnerConfig>().Address;
-			Session gateSession = Game.Scene.GetComponent<NetInnerComponent>().Get(innerAddress);
-
+			
 			// 向gate请求一个key,客户端可以拿着这个key连接gate
-			G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey() {Account = request.Account});
+			G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey) await ActorMessageSenderComponent.Instance.Call(
+				config.SceneInstanceId, new R2G_GetLoginKey() {Account = request.Account});
 
 			string outerAddress = config.GetComponent<OuterConfig>().Address2;
 
 			response.Address = outerAddress;
 			response.Key = g2RGetLoginKey.Key;
+			response.GateId = g2RGetLoginKey.GateId;
 			reply();
 		}
 	}

+ 1 - 0
Server/Hotfix/Module/Demo/R2G_GetLoginKeyHandler.cs

@@ -11,6 +11,7 @@ namespace ETHotfix
 			long key = RandomHelper.RandInt64();
 			scene.GetComponent<GateSessionKeyComponent>().Add(key, request.Account);
 			response.Key = key;
+			response.GateId = scene.Id;
 			reply();
 			await ETTask.CompletedTask;
 		}

+ 2 - 0
Server/Model/Module/Message/InnerMessage.cs

@@ -241,6 +241,8 @@ namespace ETModel
 
 		public long Key { get; set; }
 
+		public long GateId { get; set; }
+
 	}
 
 	[Message(InnerOpcode.G2M_CreateUnit)]

+ 2 - 1
Unity/Assets/Hotfix/Module/Demo/Helper/LoginHelper.cs

@@ -24,7 +24,8 @@ namespace ETHotfix
                 // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中
                 Game.Scene.AddComponent<SessionComponent>().Session = EntityFactory.Create<Session, ETModel.Session>(Game.Scene, gateSession);
 				
-                G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate() { Key = r2CLogin.Key });
+                G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(
+                    new C2G_LoginGate() { Key = r2CLogin.Key, GateId = r2CLogin.GateId});
 
                 Log.Info("登陆gate成功!");
 

+ 40 - 0
Unity/Assets/Hotfix/Module/Message/HotfixMessage.cs

@@ -144,6 +144,14 @@ namespace ETHotfix {
       }
     }
 
+    private long gateId_;
+    public long GateId {
+      get { return gateId_; }
+      set {
+        gateId_ = value;
+      }
+    }
+
     public void WriteTo(pb::CodedOutputStream output) {
       if (Address.Length != 0) {
         output.WriteRawTag(10);
@@ -153,6 +161,10 @@ namespace ETHotfix {
         output.WriteRawTag(16);
         output.WriteInt64(Key);
       }
+      if (GateId != 0L) {
+        output.WriteRawTag(24);
+        output.WriteInt64(GateId);
+      }
       if (RpcId != 0) {
         output.WriteRawTag(208, 5);
         output.WriteInt32(RpcId);
@@ -184,12 +196,16 @@ namespace ETHotfix {
       if (Key != 0L) {
         size += 1 + pb::CodedOutputStream.ComputeInt64Size(Key);
       }
+      if (GateId != 0L) {
+        size += 1 + pb::CodedOutputStream.ComputeInt64Size(GateId);
+      }
       return size;
     }
 
     public void MergeFrom(pb::CodedInputStream input) {
       address_ = "";
       key_ = 0;
+      gateId_ = 0;
       rpcId_ = 0;
       error_ = 0;
       message_ = "";
@@ -207,6 +223,10 @@ namespace ETHotfix {
             Key = input.ReadInt64();
             break;
           }
+          case 24: {
+            GateId = input.ReadInt64();
+            break;
+          }
           case 720: {
             RpcId = input.ReadInt32();
             break;
@@ -248,11 +268,23 @@ namespace ETHotfix {
       }
     }
 
+    private long gateId_;
+    public long GateId {
+      get { return gateId_; }
+      set {
+        gateId_ = value;
+      }
+    }
+
     public void WriteTo(pb::CodedOutputStream output) {
       if (Key != 0L) {
         output.WriteRawTag(8);
         output.WriteInt64(Key);
       }
+      if (GateId != 0L) {
+        output.WriteRawTag(16);
+        output.WriteInt64(GateId);
+      }
       if (RpcId != 0) {
         output.WriteRawTag(208, 5);
         output.WriteInt32(RpcId);
@@ -267,11 +299,15 @@ namespace ETHotfix {
       if (Key != 0L) {
         size += 1 + pb::CodedOutputStream.ComputeInt64Size(Key);
       }
+      if (GateId != 0L) {
+        size += 1 + pb::CodedOutputStream.ComputeInt64Size(GateId);
+      }
       return size;
     }
 
     public void MergeFrom(pb::CodedInputStream input) {
       key_ = 0;
+      gateId_ = 0;
       rpcId_ = 0;
       uint tag;
       while ((tag = input.ReadTag()) != 0) {
@@ -283,6 +319,10 @@ namespace ETHotfix {
             Key = input.ReadInt64();
             break;
           }
+          case 16: {
+            GateId = input.ReadInt64();
+            break;
+          }
           case 720: {
             RpcId = input.ReadInt32();
             break;