From 052ff131ca33ce90acbd7b60be4c72fec93d536e Mon Sep 17 00:00:00 2001 From: tanghai Date: Mon, 31 Oct 2016 15:59:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A5=E5=90=8E=E4=B8=80=E4=B8=AAApp?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E5=AD=98=E5=9C=A8=E5=A4=9A=E4=B8=AAMessageDi?= =?UTF-8?q?spather=EF=BC=8C=E6=89=80=E4=BB=A5=E4=B8=8D=E8=83=BD=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E7=BB=99Game.Scene=E7=9A=84MessageDispather=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E3=80=82=E6=94=B9=E6=88=90=EF=BC=8C=E8=BD=AC=E7=BB=99?= =?UTF-8?q?=E8=87=AA=E5=B7=B1=E7=9A=84Scene=E4=B8=8A=E6=8C=82=E5=9C=A8?= =?UTF-8?q?=E7=9A=84MessageDispather=E5=A4=84=E7=90=86=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Unity/Assets/Scripts/Component/NetworkComponent.cs | 5 ++--- Unity/Assets/Scripts/Entity/Session.cs | 10 ++++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Unity/Assets/Scripts/Component/NetworkComponent.cs b/Unity/Assets/Scripts/Component/NetworkComponent.cs index 464c95c4..345f4bca 100644 --- a/Unity/Assets/Scripts/Component/NetworkComponent.cs +++ b/Unity/Assets/Scripts/Component/NetworkComponent.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Net.Sockets; using Base; namespace Model @@ -70,7 +69,7 @@ namespace Model AChannel channel = await this.Service.AcceptChannel(); - Session session = new Session(channel); + Session session = new Session(this.GetOwner(), channel); channel.ErrorCallback += (c, e) => { this.Remove(session.Id); }; this.Add(session); } @@ -138,7 +137,7 @@ namespace Model int port = int.Parse(ss[1]); string host = ss[0]; AChannel channel = this.Service.ConnectChannel(host, port); - Session session = new Session(channel); + Session session = new Session(this.GetOwner(), channel); channel.ErrorCallback += (c, e) => { this.Remove(session.Id); }; return session; } diff --git a/Unity/Assets/Scripts/Entity/Session.cs b/Unity/Assets/Scripts/Entity/Session.cs index 99bbbabb..1b560bb4 100644 --- a/Unity/Assets/Scripts/Entity/Session.cs +++ b/Unity/Assets/Scripts/Entity/Session.cs @@ -9,11 +9,13 @@ namespace Model public sealed class Session: Entity { private static uint RpcId { get; set; } + private readonly Scene scene; private readonly Dictionary> requestCallback = new Dictionary>(); private readonly AChannel channel; - public Session(AChannel channel) : base(EntityType.Session) + public Session(Scene scene, AChannel channel) : base(EntityType.Session) { + this.scene = scene; this.channel = channel; this.StartRecv(); } @@ -88,7 +90,7 @@ namespace Model // 普通消息 if (rpcId == 0) { - Game.Scene.GetComponent().Handle(this, opcode, messageBytes, offset, 0); + this.scene.GetComponent().Handle(this, opcode, messageBytes, offset, 0); return; } @@ -106,7 +108,7 @@ namespace Model } else // 这是一个rpc请求消息 { - Game.Scene.GetComponent().Handle(this, opcode, messageBytes, offset, rpcId); + this.scene.GetComponent().Handle(this, opcode, messageBytes, offset, rpcId); } } @@ -195,7 +197,7 @@ namespace Model private void SendMessage(uint rpcId, object message, bool isCall = true) { - ushort opcode = Game.Scene.GetComponent().GetOpcode(message.GetType()); + ushort opcode = this.scene.GetComponent().GetOpcode(message.GetType()); byte[] opcodeBytes = BitConverter.GetBytes(opcode); if (!isCall) { -- GitLab