2024-01-19 21:34:08 +08:00
|
|
|
|
using HaoYueNet.ClientNetwork.OtherMode;
|
2024-01-16 18:04:15 +08:00
|
|
|
|
using ServerCore.Manager;
|
2024-01-22 15:08:43 +08:00
|
|
|
|
using System;
|
2024-01-25 17:17:16 +08:00
|
|
|
|
using System.Security.Cryptography;
|
2024-01-16 18:04:15 +08:00
|
|
|
|
|
2024-01-19 21:34:08 +08:00
|
|
|
|
namespace NoSugarNet.ClientCore.Network
|
2024-01-16 18:04:15 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 继承网络库,以支持网络功能
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ServerLocalClient : NetworkHelperCore_SourceMode
|
|
|
|
|
{
|
|
|
|
|
public long mUID;
|
|
|
|
|
public byte mTunnelID;
|
2024-01-19 21:34:08 +08:00
|
|
|
|
public byte mIdx;
|
2024-01-25 15:41:00 +08:00
|
|
|
|
public long mReciveAllLenght;
|
|
|
|
|
public long mSendAllLenght;
|
2024-01-22 15:08:43 +08:00
|
|
|
|
public ServerLocalClient(long UID,byte TunnelID, byte Idx)
|
2024-01-16 18:04:15 +08:00
|
|
|
|
{
|
2024-01-22 15:08:43 +08:00
|
|
|
|
mUID = UID;
|
2024-01-16 18:04:15 +08:00
|
|
|
|
mTunnelID = TunnelID;
|
2024-01-19 21:34:08 +08:00
|
|
|
|
mIdx = Idx;
|
2024-01-16 18:04:15 +08:00
|
|
|
|
//指定接收服务器数据事件
|
|
|
|
|
OnReceiveData += GetDataCallBack;
|
|
|
|
|
//断开连接
|
|
|
|
|
OnClose += OnConnectClose;
|
|
|
|
|
OnConnected += NetworkConnected;
|
|
|
|
|
//网络库调试信息输出事件,用于打印网络内容
|
|
|
|
|
OnLogOut += NetworkDeBugLog;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void NetworkConnected(bool IsConnect)
|
|
|
|
|
{
|
|
|
|
|
NetworkDeBugLog($"NetworkConnected:{IsConnect}");
|
|
|
|
|
if (IsConnect)
|
|
|
|
|
{
|
2024-01-19 21:34:08 +08:00
|
|
|
|
ServerManager.g_Local.OnServerLocalConnect(mUID, mTunnelID, mIdx, this);
|
2024-01-16 18:04:15 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//连接失败
|
|
|
|
|
NetworkDeBugLog("连接失败!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void NetworkDeBugLog(string str)
|
|
|
|
|
{
|
|
|
|
|
//用于Unity内的输出
|
|
|
|
|
//Debug.Log("NetCoreDebug >> "+str);
|
|
|
|
|
Console.WriteLine("NetCoreDebug >> " + str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 接受包回调
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="CMDID">协议ID</param>
|
|
|
|
|
/// <param name="ERRCODE">错误编号</param>
|
|
|
|
|
/// <param name="data">业务数据</param>
|
|
|
|
|
public void GetDataCallBack(byte[] data)
|
|
|
|
|
{
|
2024-01-23 17:06:47 +08:00
|
|
|
|
//NetworkDeBugLog("收到消息 数据长度=>" + data.Length);
|
2024-01-16 18:04:15 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
2024-01-25 15:41:00 +08:00
|
|
|
|
//记录接收数据长度
|
|
|
|
|
mReciveAllLenght += data.Length;
|
2024-01-16 18:04:15 +08:00
|
|
|
|
//抛出网络数据
|
2024-01-19 21:34:08 +08:00
|
|
|
|
ServerManager.g_Local.OnServerLocalDataCallBack(mUID, mTunnelID, mIdx, data);
|
2024-01-16 18:04:15 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
NetworkDeBugLog("逻辑处理错误:" + ex.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 关闭连接
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void OnConnectClose()
|
|
|
|
|
{
|
|
|
|
|
NetworkDeBugLog("OnConnectClose");
|
2024-01-19 21:34:08 +08:00
|
|
|
|
ServerManager.g_Local.OnServerLocalDisconnect(mUID, mTunnelID,mIdx,this);
|
2024-01-16 18:04:15 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|