提交 052ff131 编写于 作者: T tanghai

以后一个App可能存在多个MessageDispather,所以不能直接给Game.Scene的MessageDispather组件。改成,转给自己的Sce...

以后一个App可能存在多个MessageDispather,所以不能直接给Game.Scene的MessageDispather组件。改成,转给自己的Scene上挂在的MessageDispather处理,
上级 c6de9464
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.Sockets;
using Base; using Base;
namespace Model namespace Model
...@@ -70,7 +69,7 @@ namespace Model ...@@ -70,7 +69,7 @@ namespace Model
AChannel channel = await this.Service.AcceptChannel(); AChannel channel = await this.Service.AcceptChannel();
Session session = new Session(channel); Session session = new Session(this.GetOwner<Scene>(), channel);
channel.ErrorCallback += (c, e) => { this.Remove(session.Id); }; channel.ErrorCallback += (c, e) => { this.Remove(session.Id); };
this.Add(session); this.Add(session);
} }
...@@ -138,7 +137,7 @@ namespace Model ...@@ -138,7 +137,7 @@ namespace Model
int port = int.Parse(ss[1]); int port = int.Parse(ss[1]);
string host = ss[0]; string host = ss[0];
AChannel channel = this.Service.ConnectChannel(host, port); AChannel channel = this.Service.ConnectChannel(host, port);
Session session = new Session(channel); Session session = new Session(this.GetOwner<Scene>(), channel);
channel.ErrorCallback += (c, e) => { this.Remove(session.Id); }; channel.ErrorCallback += (c, e) => { this.Remove(session.Id); };
return session; return session;
} }
......
...@@ -9,11 +9,13 @@ namespace Model ...@@ -9,11 +9,13 @@ namespace Model
public sealed class Session: Entity public sealed class Session: Entity
{ {
private static uint RpcId { get; set; } private static uint RpcId { get; set; }
private readonly Scene scene;
private readonly Dictionary<uint, Action<byte[], int, int>> requestCallback = new Dictionary<uint, Action<byte[], int, int>>(); private readonly Dictionary<uint, Action<byte[], int, int>> requestCallback = new Dictionary<uint, Action<byte[], int, int>>();
private readonly AChannel channel; 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.channel = channel;
this.StartRecv(); this.StartRecv();
} }
...@@ -88,7 +90,7 @@ namespace Model ...@@ -88,7 +90,7 @@ namespace Model
// 普通消息 // 普通消息
if (rpcId == 0) if (rpcId == 0)
{ {
Game.Scene.GetComponent<MessageDispatherComponent>().Handle(this, opcode, messageBytes, offset, 0); this.scene.GetComponent<MessageDispatherComponent>().Handle(this, opcode, messageBytes, offset, 0);
return; return;
} }
...@@ -106,7 +108,7 @@ namespace Model ...@@ -106,7 +108,7 @@ namespace Model
} }
else // 这是一个rpc请求消息 else // 这是一个rpc请求消息
{ {
Game.Scene.GetComponent<MessageDispatherComponent>().Handle(this, opcode, messageBytes, offset, rpcId); this.scene.GetComponent<MessageDispatherComponent>().Handle(this, opcode, messageBytes, offset, rpcId);
} }
} }
...@@ -195,7 +197,7 @@ namespace Model ...@@ -195,7 +197,7 @@ namespace Model
private void SendMessage(uint rpcId, object message, bool isCall = true) private void SendMessage(uint rpcId, object message, bool isCall = true)
{ {
ushort opcode = Game.Scene.GetComponent<MessageDispatherComponent>().GetOpcode(message.GetType()); ushort opcode = this.scene.GetComponent<MessageDispatherComponent>().GetOpcode(message.GetType());
byte[] opcodeBytes = BitConverter.GetBytes(opcode); byte[] opcodeBytes = BitConverter.GetBytes(opcode);
if (!isCall) if (!isCall)
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册