64 lines
1.4 KiB
C#
64 lines
1.4 KiB
C#
using Fleck;
|
|
using System;
|
|
using pb = global::Google.Protobuf;
|
|
|
|
namespace BattleServer
|
|
{
|
|
/// <summary>
|
|
/// 客户端链接对象
|
|
/// </summary>
|
|
class Client
|
|
{
|
|
private IWebSocketConnection socket;
|
|
|
|
public Client(IWebSocketConnection _socket)
|
|
{
|
|
socket = _socket;
|
|
socket.OnMessage = domessage;
|
|
socket.OnBinary = doBinary;
|
|
}
|
|
private void domessage(string message)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 接收rpc数据
|
|
/// </summary>
|
|
/// <param name="message"></param>
|
|
private void doBinary(byte[] message)
|
|
{
|
|
Pb.RpcMessage msg = Deserialize<Pb.RpcMessage>(message);
|
|
Task.Run(() =>
|
|
{
|
|
handle(msg);
|
|
});
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 处理远程请求
|
|
/// </summary>
|
|
/// <param name="msg"></param>
|
|
private void handle(Pb.RpcMessage msg)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 反序列化protobuf
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="dataBytes"></param>
|
|
/// <returns></returns>
|
|
public static T Deserialize<T>(byte[] dataBytes) where T : pb.IMessage, new()
|
|
{
|
|
T msg = new T();
|
|
msg = (T)msg.Descriptor.Parser.ParseFrom(dataBytes);
|
|
return msg;
|
|
}
|
|
|
|
|
|
}
|
|
} |