简化协议
This commit is contained in:
parent
3c7084d484
commit
53ae9c96c1
@ -10,6 +10,7 @@ namespace NoSugarNet.Adapter
|
||||
public long mReciveAllLenght;
|
||||
public long mSendAllLenght;
|
||||
public long currSeed;
|
||||
public long mUid;
|
||||
static long Seed;
|
||||
|
||||
public enum AdptLogLevel
|
||||
@ -21,16 +22,16 @@ namespace NoSugarNet.Adapter
|
||||
}
|
||||
|
||||
public delegate void OnLogOutHandler(int LogLevel,string Msg);
|
||||
public delegate void OnClientLocalConnectHandler(byte tunnelId, byte _Idx);
|
||||
public delegate void OnClientLocalDisconnectHandler(byte tunnelId, byte _Idx);
|
||||
public delegate void OnClientTunnelDataCallBackHandler(byte tunnelId, byte Idx, byte[] data);
|
||||
public delegate void OnClientLocalConnectHandler(long UID, byte tunnelId, byte _Idx);
|
||||
public delegate void OnClientLocalDisconnectHandler(long UID, byte tunnelId, byte _Idx);
|
||||
public delegate void OnClientTunnelDataCallBackHandler(long UID, byte tunnelId, byte Idx, byte[] data);
|
||||
|
||||
public event OnLogOutHandler OnForwardLogOut;
|
||||
public event OnClientLocalConnectHandler OnClientLocalConnect;
|
||||
public event OnClientLocalDisconnectHandler OnClientLocalDisconnect;
|
||||
public event OnClientTunnelDataCallBackHandler OnClientTunnelDataCallBack;
|
||||
|
||||
public ForwardLocalListener(int numConnections, int receiveBufferSize, byte TunnelID)
|
||||
public ForwardLocalListener(int numConnections, int receiveBufferSize, byte TunnelID, long mUid)
|
||||
: base(numConnections, receiveBufferSize)
|
||||
{
|
||||
OnClientNumberChange += ClientNumberChange;
|
||||
@ -41,6 +42,7 @@ namespace NoSugarNet.Adapter
|
||||
mTunnelID = TunnelID;
|
||||
|
||||
currSeed = Seed++;
|
||||
this.mUid = mUid;
|
||||
}
|
||||
|
||||
|
||||
@ -75,7 +77,7 @@ namespace NoSugarNet.Adapter
|
||||
int Idx = AddDictSocket(token.Socket);
|
||||
if (GetSocketByIdx(Idx, out LocalClientInfo _localClientInf))
|
||||
{
|
||||
OnClientLocalConnect?.Invoke(mTunnelID, (byte)Idx);
|
||||
OnClientLocalConnect?.Invoke(mUid, mTunnelID, (byte)Idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -116,7 +118,7 @@ namespace NoSugarNet.Adapter
|
||||
try
|
||||
{
|
||||
//抛出网络数据
|
||||
OnClientTunnelDataCallBack?.Invoke(mTunnelID, (byte)Idx, data);
|
||||
OnClientTunnelDataCallBack?.Invoke(mUid, mTunnelID, (byte)Idx, data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -150,7 +152,7 @@ namespace NoSugarNet.Adapter
|
||||
if (!GetSocketIdxBySocket(token.Socket, out int Idx))
|
||||
return;
|
||||
|
||||
OnClientLocalDisconnect?.Invoke(mTunnelID, (byte)Idx);
|
||||
OnClientLocalDisconnect?.Invoke(mUid, mTunnelID, (byte)Idx);
|
||||
RemoveDictSocket(token.Socket);
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ namespace ServerCore.Manager
|
||||
mCompressAdapter = new NoSugarNet.Adapter.DataHelper.CompressAdapter(compressAdapterType);
|
||||
foreach (var cfg in mDictTunnelID2Cfg)
|
||||
{
|
||||
ForwardLocalListener listener = new ForwardLocalListener(256, 1024, cfg.Key);
|
||||
ForwardLocalListener listener = new ForwardLocalListener(256, 1024, cfg.Key,AppNoSugarNet.user.userdata.UID);
|
||||
AppNoSugarNet.log.Info($"开始监听配置 Tunnel:{cfg.Key},Port:{cfg.Value.Port}");
|
||||
listener.BandEvent(AppNoSugarNet.log.Log, OnClientLocalConnect, OnClientLocalDisconnect, OnClientTunnelDataCallBack);
|
||||
listener.StartListener((uint)cfg.Value.Port);
|
||||
@ -163,7 +163,7 @@ namespace ServerCore.Manager
|
||||
public void Recive_TunnelS2CConnect(byte[] reqData)
|
||||
{
|
||||
AppNoSugarNet.log.Debug("Recive_TunnelS2CConnect");
|
||||
Protobuf_S2C_Connect msg = ProtoBufHelper.DeSerizlize<Protobuf_S2C_Connect>(reqData);
|
||||
Protobuf_Tunnel_Connect msg = ProtoBufHelper.DeSerizlize<Protobuf_Tunnel_Connect>(reqData);
|
||||
if(msg.Connected == 1)
|
||||
OnServerLocalConnect((byte)msg.TunnelID,(byte)msg.Idx);
|
||||
else
|
||||
@ -172,13 +172,13 @@ namespace ServerCore.Manager
|
||||
public void Recive_TunnelS2CDisconnect(byte[] reqData)
|
||||
{
|
||||
AppNoSugarNet.log.Debug("Recive_TunnelS2CDisconnect");
|
||||
Protobuf_S2C_Disconnect msg = ProtoBufHelper.DeSerizlize<Protobuf_S2C_Disconnect>(reqData);
|
||||
Protobuf_Tunnel_Disconnect msg = ProtoBufHelper.DeSerizlize<Protobuf_Tunnel_Disconnect>(reqData);
|
||||
OnServerLocalDisconnect((byte)msg.TunnelID,(byte)msg.Idx);
|
||||
}
|
||||
public void Recive_TunnelS2CData(byte[] reqData)
|
||||
{
|
||||
//AppNoSugarNet.log.Debug("Recive_TunnelS2CData");
|
||||
Protobuf_S2C_DATA msg = ProtoBufHelper.DeSerizlize<Protobuf_S2C_DATA>(reqData);
|
||||
Protobuf_Tunnel_DATA msg = ProtoBufHelper.DeSerizlize<Protobuf_Tunnel_DATA>(reqData);
|
||||
OnServerLocalDataCallBack((byte)msg.TunnelID,(byte)msg.Idx, msg.HunterNetCoreData.ToArray());
|
||||
}
|
||||
#endregion
|
||||
@ -189,13 +189,13 @@ namespace ServerCore.Manager
|
||||
/// </summary>
|
||||
/// <param name="uid"></param>
|
||||
/// <param name="tunnelId"></param>
|
||||
public void OnClientLocalConnect(byte tunnelId,byte _Idx)
|
||||
public void OnClientLocalConnect(long UID, byte tunnelId,byte _Idx)
|
||||
{
|
||||
AppNoSugarNet.log.Debug($"OnClientLocalConnect {tunnelId},{_Idx}");
|
||||
if (!mDictTunnelID2Cfg.ContainsKey(tunnelId))
|
||||
return;
|
||||
|
||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_C2S_Connect()
|
||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_Tunnel_Connect()
|
||||
{
|
||||
TunnelID = tunnelId,
|
||||
Idx = _Idx,
|
||||
@ -209,14 +209,14 @@ namespace ServerCore.Manager
|
||||
/// </summary>
|
||||
/// <param name="uid"></param>
|
||||
/// <param name="tunnelId"></param>
|
||||
public void OnClientLocalDisconnect(byte tunnelId, byte _Idx)
|
||||
public void OnClientLocalDisconnect(long UID, byte tunnelId, byte _Idx)
|
||||
{
|
||||
AppNoSugarNet.log.Debug($"OnClientLocalDisconnect {tunnelId},{_Idx}");
|
||||
//隧道ID定位投递服务端本地连接
|
||||
if (!mDictTunnelID2Cfg.ContainsKey(tunnelId))
|
||||
return;
|
||||
|
||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_C2S_Disconnect()
|
||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_Tunnel_Disconnect()
|
||||
{
|
||||
TunnelID = tunnelId,
|
||||
Idx= _Idx,
|
||||
@ -288,7 +288,7 @@ namespace ServerCore.Manager
|
||||
/// <param name="uid"></param>
|
||||
/// <param name="tunnelId"></param>
|
||||
/// <param name="data"></param>
|
||||
public void OnClientTunnelDataCallBack(byte tunnelId,byte Idx, byte[] data)
|
||||
public void OnClientTunnelDataCallBack(long UID, byte tunnelId,byte Idx, byte[] data)
|
||||
{
|
||||
//AppNoSugarNet.log.Info($"OnClientTunnelDataCallBack {tunnelId},{Idx} data.Length->{data.Length}");
|
||||
|
||||
@ -326,7 +326,7 @@ namespace ServerCore.Manager
|
||||
//记录压缩后数据长度
|
||||
tSendAllLenght += data.Length;
|
||||
|
||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_C2S_DATA()
|
||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_Tunnel_DATA()
|
||||
{
|
||||
TunnelID = tunnelId,
|
||||
Idx = Idx,
|
||||
|
@ -59,7 +59,7 @@ namespace ServerCore.Manager
|
||||
public void Recive_TunnelS2CConnect(byte[] reqData)
|
||||
{
|
||||
AppNoSugarNet.log.Debug("Recive_TunnelS2CConnect");
|
||||
Protobuf_S2C_Connect msg = ProtoBufHelper.DeSerizlize<Protobuf_S2C_Connect>(reqData);
|
||||
Protobuf_Tunnel_Connect msg = ProtoBufHelper.DeSerizlize<Protobuf_Tunnel_Connect>(reqData);
|
||||
if (msg.Connected == 1)
|
||||
OnServerLocalConnect((byte)msg.TunnelID, (byte)msg.Idx);
|
||||
else
|
||||
@ -68,13 +68,13 @@ namespace ServerCore.Manager
|
||||
public void Recive_TunnelS2CDisconnect(byte[] reqData)
|
||||
{
|
||||
AppNoSugarNet.log.Debug("Recive_TunnelS2CDisconnect");
|
||||
Protobuf_S2C_Disconnect msg = ProtoBufHelper.DeSerizlize<Protobuf_S2C_Disconnect>(reqData);
|
||||
Protobuf_Tunnel_Disconnect msg = ProtoBufHelper.DeSerizlize<Protobuf_Tunnel_Disconnect>(reqData);
|
||||
OnServerLocalDisconnect((byte)msg.TunnelID, (byte)msg.Idx);
|
||||
}
|
||||
public void Recive_TunnelS2CData(byte[] reqData)
|
||||
{
|
||||
//AppNoSugarNet.log.Debug("Recive_TunnelS2CData");
|
||||
Protobuf_S2C_DATA msg = ProtoBufHelper.DeSerizlize<Protobuf_S2C_DATA>(reqData);
|
||||
Protobuf_Tunnel_DATA msg = ProtoBufHelper.DeSerizlize<Protobuf_Tunnel_DATA>(reqData);
|
||||
OnServerTunnelDataCallBack(AppNoSugarNet.user.userdata.UID, (byte)msg.TunnelID, (byte)msg.Idx, msg.HunterNetCoreData.ToArray());
|
||||
}
|
||||
#endregion
|
||||
@ -105,7 +105,7 @@ namespace ServerCore.Manager
|
||||
{
|
||||
//TODO告知客户端连接失败
|
||||
|
||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_S2C_Connect()
|
||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_Tunnel_Connect()
|
||||
{
|
||||
TunnelID = tunnelId,
|
||||
Idx = (uint)Idx,
|
||||
@ -134,7 +134,6 @@ namespace ServerCore.Manager
|
||||
CloseClientLocalClient(AppNoSugarNet.user.userdata.UID, tunnelId, Idx);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 当服务端本地端口连接
|
||||
/// </summary>
|
||||
@ -147,7 +146,7 @@ namespace ServerCore.Manager
|
||||
//添加到服务端本地连接列表
|
||||
AddClientLocalClient(uid, tunnelId, Idx, serverLocalClient);
|
||||
|
||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_S2C_Connect()
|
||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_Tunnel_Connect()
|
||||
{
|
||||
TunnelID = tunnelId,
|
||||
Idx = Idx,
|
||||
@ -167,7 +166,7 @@ namespace ServerCore.Manager
|
||||
//移除到服务端本地连接列表
|
||||
RemoveClientLocalClient(uid, tunnelId, Idx);
|
||||
|
||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_S2C_Disconnect()
|
||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_Tunnel_Disconnect()
|
||||
{
|
||||
TunnelID = tunnelId,
|
||||
Idx = Idx,
|
||||
@ -343,7 +342,7 @@ namespace ServerCore.Manager
|
||||
//记录压缩后数据长度
|
||||
tSendAllLenght += data.Length;
|
||||
|
||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_S2C_DATA()
|
||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_Tunnel_DATA()
|
||||
{
|
||||
TunnelID = tunnelId,
|
||||
Idx = Idx,
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -12,6 +12,10 @@ namespace ServerCore.Manager
|
||||
public bool IsOffline { get; set; } = false;
|
||||
public DateTime LogOutDT { get; set; }
|
||||
|
||||
public NoSugarNet.Adapter.DataHelper.E_CompressAdapter e_CompressAdapter { get; set; }
|
||||
|
||||
public Dictionary<byte, Protobuf_Cfgs_Single> _cfgs { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class ClientManager
|
||||
@ -85,6 +89,15 @@ namespace ServerCore.Manager
|
||||
return cinfo;
|
||||
}
|
||||
|
||||
public void SetUserCfg(long uid, NoSugarNet.Adapter.DataHelper.E_CompressAdapter CompressAdapter, Dictionary<byte, Protobuf_Cfgs_Single> cfg)
|
||||
{
|
||||
if (GetClientByUID(uid, out ClientInfo _c))
|
||||
{
|
||||
_c._cfgs = cfg;
|
||||
_c.e_CompressAdapter = CompressAdapter;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加用户
|
||||
/// </summary>
|
||||
|
@ -151,21 +151,21 @@ namespace ServerCore.Manager
|
||||
{
|
||||
ClientInfo _c = ServerManager.g_ClientMgr.GetClientForSocket(sk);
|
||||
ServerManager.g_Log.Debug("OnTunnelC2SConnect");
|
||||
Protobuf_C2S_Connect msg = ProtoBufHelper.DeSerizlize<Protobuf_C2S_Connect>(reqData);
|
||||
Protobuf_Tunnel_Connect msg = ProtoBufHelper.DeSerizlize<Protobuf_Tunnel_Connect>(reqData);
|
||||
OnClientLocalConnect(_c.UID, (byte)msg.TunnelID, (byte)msg.Idx);
|
||||
}
|
||||
public void Recive_TunnelC2SDisconnect(Socket sk, byte[] reqData)
|
||||
{
|
||||
ClientInfo _c = ServerManager.g_ClientMgr.GetClientForSocket(sk);
|
||||
ServerManager.g_Log.Debug("Recive_TunnelC2SDisconnect");
|
||||
Protobuf_C2S_Disconnect msg = ProtoBufHelper.DeSerizlize<Protobuf_C2S_Disconnect>(reqData);
|
||||
Protobuf_Tunnel_Disconnect msg = ProtoBufHelper.DeSerizlize<Protobuf_Tunnel_Disconnect>(reqData);
|
||||
OnClientLocalDisconnect(_c.UID, (byte)msg.TunnelID,(byte)msg.Idx);
|
||||
}
|
||||
public void Recive_TunnelC2SData(Socket sk, byte[] reqData)
|
||||
{
|
||||
ClientInfo _c = ServerManager.g_ClientMgr.GetClientForSocket(sk);
|
||||
//ServerManager.g_Log.Debug("OnTunnelC2SData");
|
||||
Protobuf_C2S_DATA msg = ProtoBufHelper.DeSerizlize<Protobuf_C2S_DATA>(reqData);
|
||||
Protobuf_Tunnel_DATA msg = ProtoBufHelper.DeSerizlize<Protobuf_Tunnel_DATA>(reqData);
|
||||
OnClientTunnelDataCallBack(_c.UID, (byte)msg.TunnelID, (byte)msg.Idx, msg.HunterNetCoreData.ToArray());
|
||||
}
|
||||
#endregion
|
||||
@ -197,7 +197,7 @@ namespace ServerCore.Manager
|
||||
{
|
||||
//TODO告知客户端连接失败
|
||||
|
||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_S2C_Connect()
|
||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_Tunnel_Connect()
|
||||
{
|
||||
TunnelID = tunnelId,
|
||||
Idx = (uint)Idx,
|
||||
@ -241,7 +241,7 @@ namespace ServerCore.Manager
|
||||
//添加到服务端本地连接列表
|
||||
AddServerLocalClient(uid, tunnelId, Idx, serverLocalClient);
|
||||
|
||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_S2C_Connect()
|
||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_Tunnel_Connect()
|
||||
{
|
||||
TunnelID = tunnelId,
|
||||
Idx = Idx,
|
||||
@ -263,7 +263,7 @@ namespace ServerCore.Manager
|
||||
//移除到服务端本地连接列表
|
||||
RemoveServerLocalClient(uid, tunnelId, Idx);
|
||||
|
||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_S2C_Disconnect()
|
||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_Tunnel_Disconnect()
|
||||
{
|
||||
TunnelID = tunnelId,
|
||||
Idx= Idx,
|
||||
@ -343,7 +343,7 @@ namespace ServerCore.Manager
|
||||
//记录压缩后数据长度
|
||||
tSendAllLenght += data.Length;
|
||||
|
||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_S2C_DATA()
|
||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_Tunnel_DATA()
|
||||
{
|
||||
TunnelID = tunnelId,
|
||||
Idx = Idx,
|
||||
|
@ -2,6 +2,10 @@
|
||||
{
|
||||
public class LogManager
|
||||
{
|
||||
public void Info(string str)
|
||||
{
|
||||
Console.WriteLine(str);
|
||||
}
|
||||
public void Debug(string str)
|
||||
{
|
||||
Console.WriteLine(str);
|
||||
|
324
NoSugarNet.ServerCore/Manager/ReverseLocalClientManager.cs
Normal file
324
NoSugarNet.ServerCore/Manager/ReverseLocalClientManager.cs
Normal file
@ -0,0 +1,324 @@
|
||||
//using AxibugProtobuf;
|
||||
//using Google.Protobuf;
|
||||
//using NoSugarNet.Adapter;
|
||||
//using NoSugarNet.Adapter.DataHelper;
|
||||
//using NoSugarNet.ServerCore.Common;
|
||||
//using ServerCore.Common;
|
||||
//using ServerCore.NetWork;
|
||||
//using System.Net.Sockets;
|
||||
|
||||
//namespace ServerCore.Manager
|
||||
//{
|
||||
// public class ReverseLocalClientManager
|
||||
// {
|
||||
// Dictionary<long, ForwardLocalListener> mDictCommKey2LocalListeners = new Dictionary<long, ForwardLocalListener>();
|
||||
|
||||
// public long tReciveAllLenght { get; private set; }
|
||||
// public long tSendAllLenght { get; private set; }
|
||||
|
||||
// static long GetCommKey(long Uid, int Tunnel)
|
||||
// {
|
||||
// return (Uid * 10000000) + (Tunnel * 10000);
|
||||
// }
|
||||
|
||||
// static long GetUidForCommKey(long CommKey)
|
||||
// {
|
||||
// return CommKey / 10000000;
|
||||
// }
|
||||
|
||||
|
||||
// public ReverseLocalClientManager()
|
||||
// {
|
||||
// //注册网络消息
|
||||
// NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdTunnelC2SReverseConnect, Recive_TunnelC2SConnect);
|
||||
// NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdTunnelC2SReverseDisconnect, Recive_TunnelC2SDisconnect);
|
||||
// NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdTunnelC2SReverseData, Recive_TunnelC2SData);
|
||||
// }
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// 初始化连接
|
||||
// /// </summary>
|
||||
// void InitListenerMode(long UID)
|
||||
// {
|
||||
// if (!ServerManager.g_ClientMgr.GetClientByUID(UID, out ClientInfo _c))
|
||||
// return;
|
||||
|
||||
// //初始化压缩适配器,代表压缩类型
|
||||
// ServerManager.g_Log.Info("初始化压缩适配器" + _c.e_CompressAdapter);
|
||||
// foreach (var cfg in _c._cfgs)
|
||||
// {
|
||||
// ForwardLocalListener listener = new ForwardLocalListener(256, 1024, cfg.Key, UID);
|
||||
// ServerManager.g_Log.Info($"开始监听配置 Tunnel:{cfg.Key},Port:{cfg.Value.Port}");
|
||||
// listener.BandEvent(ServerManager.g_Log.Log, OnLocalConnect, OnLocalDisconnect, OnTunnelDataCallBack);
|
||||
// listener.StartListener((uint)cfg.Value.Port);
|
||||
// AddLocalListener(UID,listener);
|
||||
// }
|
||||
// }
|
||||
|
||||
// #region 连接字典管理
|
||||
// /// <summary>
|
||||
// /// 追加监听者
|
||||
// /// </summary>
|
||||
// /// <param name="tunnelId"></param>
|
||||
// /// <param name="serverClient"></param>
|
||||
// void AddLocalListener(long UID,ForwardLocalListener _listener)
|
||||
// {
|
||||
// long Key = GetCommKey(UID, _listener.mTunnelID);
|
||||
// lock (mDictCommKey2LocalListeners)
|
||||
// {
|
||||
// mDictCommKey2LocalListeners[Key] = _listener;
|
||||
// }
|
||||
// }
|
||||
// /// <summary>
|
||||
// /// 删除监听
|
||||
// /// </summary>
|
||||
// /// <param name="tunnelId"></param>
|
||||
// /// <param name="serverClient"></param>
|
||||
// void RemoveLocalListener(long UID, ForwardLocalListener _listener)
|
||||
// {
|
||||
// long Key = GetCommKey(UID, _listener.mTunnelID);
|
||||
// lock (mDictCommKey2LocalListeners)
|
||||
// {
|
||||
// if (mDictCommKey2LocalListeners.ContainsKey(Key))
|
||||
// mDictCommKey2LocalListeners.Remove(Key);
|
||||
// }
|
||||
// }
|
||||
// bool GetLocalListener(long UID, byte tunnelId, out ForwardLocalListener _listener)
|
||||
// {
|
||||
// long Key = GetCommKey(UID, tunnelId);
|
||||
// _listener = null;
|
||||
// if (!mDictCommKey2LocalListeners.ContainsKey(Key))
|
||||
// return false;
|
||||
|
||||
// _listener = mDictCommKey2LocalListeners[Key];
|
||||
// return true;
|
||||
// }
|
||||
// public void StopAllByUid(long UID)
|
||||
// {
|
||||
// lock (mDictCommKey2LocalListeners)
|
||||
// {
|
||||
// long[] keys = mDictCommKey2LocalListeners.Keys.ToArray();
|
||||
// for (int i = 0; i < keys.Length; i++)
|
||||
// {
|
||||
// ForwardLocalListener _listener = mDictCommKey2LocalListeners[keys[i]];
|
||||
// if (_listener.mUid != UID)
|
||||
// continue;
|
||||
// _listener.StopAllLocalClient();
|
||||
// _listener.StopWithClear();
|
||||
// //_listener.Stop();
|
||||
// RemoveLocalListener(UID,_listener);
|
||||
// }
|
||||
// //服务端得按用户分开
|
||||
// //mDictCommKey2ServerLocalClients.Clear();
|
||||
// }
|
||||
// }
|
||||
// #endregion
|
||||
|
||||
|
||||
// #region 解析客户端下行数据
|
||||
// public void Recive_CmdCfgs(Socket sk, byte[] reqData)
|
||||
// {
|
||||
// ServerManager.g_Log.Debug("Recive_CmdCfgs");
|
||||
// ClientInfo _c = ServerManager.g_ClientMgr.GetClientForSocket(sk);
|
||||
// Protobuf_Cfgs msg = ProtoBufHelper.DeSerizlize<Protobuf_Cfgs>(reqData);
|
||||
|
||||
// Dictionary<byte, Protobuf_Cfgs_Single> tempDictTunnelID2Cfg = new Dictionary<byte, Protobuf_Cfgs_Single>();
|
||||
// for (int i = 0; i < msg.Cfgs.Count; i++)
|
||||
// {
|
||||
// Protobuf_Cfgs_Single cfg = msg.Cfgs[i];
|
||||
// tempDictTunnelID2Cfg[(byte)cfg.TunnelID] = cfg;
|
||||
// }
|
||||
// ServerManager.g_ClientMgr.SetUserCfg(_c.UID, (NoSugarNet.Adapter.DataHelper.E_CompressAdapter)msg.CompressAdapterType, tempDictTunnelID2Cfg);
|
||||
// InitListenerMode(_c.UID);
|
||||
// }
|
||||
// public void Recive_TunnelS2CConnect(byte[] reqData)
|
||||
// {
|
||||
// ServerManager.g_Log.Debug("Recive_TunnelS2CConnect");
|
||||
// Protobuf_Tunnel_Connect msg = ProtoBufHelper.DeSerizlize<Protobuf_Tunnel_Connect>(reqData);
|
||||
// if (msg.Connected == 1)
|
||||
// OnServerLocalConnect((byte)msg.TunnelID, (byte)msg.Idx);
|
||||
// else
|
||||
// OnServerLocalDisconnect((byte)msg.TunnelID, (byte)msg.Idx);
|
||||
// }
|
||||
// public void Recive_TunnelS2CDisconnect(byte[] reqData)
|
||||
// {
|
||||
// ServerManager.g_Log.Debug("Recive_TunnelS2CDisconnect");
|
||||
// Protobuf_Tunnel_Disconnect msg = ProtoBufHelper.DeSerizlize<Protobuf_Tunnel_Disconnect>(reqData);
|
||||
// OnServerLocalDisconnect((byte)msg.TunnelID, (byte)msg.Idx);
|
||||
// }
|
||||
// public void Recive_TunnelS2CData(byte[] reqData)
|
||||
// {
|
||||
// //ServerManager.g_Log.Debug("Recive_TunnelS2CData");
|
||||
// Protobuf_Tunnel_DATA msg = ProtoBufHelper.DeSerizlize<Protobuf_Tunnel_DATA>(reqData);
|
||||
// OnServerLocalDataCallBack((byte)msg.TunnelID, (byte)msg.Idx, msg.HunterNetCoreData.ToArray());
|
||||
// }
|
||||
// #endregion
|
||||
|
||||
|
||||
// #region 两端本地端口连接事件通知
|
||||
// /// <summary>
|
||||
// /// 当客户端本地端口连接
|
||||
// /// </summary>
|
||||
// /// <param name="uid"></param>
|
||||
// /// <param name="tunnelId"></param>
|
||||
// public void OnLocalConnect(long UID, byte tunnelId, byte _Idx)
|
||||
// {
|
||||
// ServerManager.g_Log.Debug($"OnLocalConnect {UID},{tunnelId},{_Idx}");
|
||||
|
||||
// if (!mDictTunnelID2Cfg.ContainsKey(tunnelId))
|
||||
// return;
|
||||
|
||||
// byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_Tunnel_Connect()
|
||||
// {
|
||||
// TunnelID = tunnelId,
|
||||
// Idx = _Idx,
|
||||
// });
|
||||
|
||||
// //告知给服务端,来自客户端本地的连接建立
|
||||
// AppNoSugarNet.networkHelper.SendToServer((int)CommandID.CmdTunnelC2SForwardConnect, respData);
|
||||
// }
|
||||
// /// <summary>
|
||||
// /// 当客户端本地端口连接断开
|
||||
// /// </summary>
|
||||
// /// <param name="uid"></param>
|
||||
// /// <param name="tunnelId"></param>
|
||||
// public void OnLocalDisconnect(long UID, byte tunnelId, byte _Idx)
|
||||
// {
|
||||
// AppNoSugarNet.log.Debug($"OnClientLocalDisconnect {tunnelId},{_Idx}");
|
||||
// //隧道ID定位投递服务端本地连接
|
||||
// if (!mDictTunnelID2Cfg.ContainsKey(tunnelId))
|
||||
// return;
|
||||
|
||||
// byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_Tunnel_Disconnect()
|
||||
// {
|
||||
// TunnelID = tunnelId,
|
||||
// Idx = _Idx,
|
||||
// });
|
||||
|
||||
// //告知给服务端,来自客户端本地的连接断开
|
||||
// AppNoSugarNet.networkHelper.SendToServer((int)CommandID.CmdTunnelC2SForwardDisconnect, respData);
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 当服务端本地端口连接
|
||||
// /// </summary>
|
||||
// /// <param name="tunnelId"></param>
|
||||
// public void OnRemoteLocalConnect(long UID, byte tunnelId, byte Idx)
|
||||
// {
|
||||
// AppNoSugarNet.log.Debug($"OnServerLocalConnect {tunnelId},{Idx}");
|
||||
// if (!GetLocalListener(tunnelId, out ForwardLocalListener _listener))
|
||||
// return;
|
||||
// //维护状态
|
||||
// _listener.SetRemoteConnectd(Idx, true);
|
||||
// if (_listener.GetDictMsgQueue(Idx, out List<IdxWithMsg> msglist))
|
||||
// {
|
||||
// for (int i = 0; i < msglist.Count; i++)
|
||||
// {
|
||||
// IdxWithMsg msg = msglist[i];
|
||||
// //投递给服务端,来自客户端本地的连接数据
|
||||
// AppNoSugarNet.networkHelper.SendToServer((int)CommandID.CmdTunnelC2SForwardData, msg.data);
|
||||
// //发送后回收
|
||||
// LocalMsgQueuePool._localMsgPool.Enqueue(msg);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// /// <summary>
|
||||
// /// 当服务端本地端口连接断开
|
||||
// /// </summary>
|
||||
// /// <param name="uid"></param>
|
||||
// /// <param name="tunnelId"></param>
|
||||
// public void OnRemoteLocalDisconnect(long UID, byte tunnelId, byte Idx)
|
||||
// {
|
||||
// AppNoSugarNet.log.Debug($"OnServerLocalDisconnect {tunnelId},{Idx}");
|
||||
// if (!GetLocalListener(tunnelId, out ForwardLocalListener _listener))
|
||||
// return;
|
||||
// _listener.SetRemoteConnectd(Idx, false);
|
||||
// _listener.CloseConnectByIdx(Idx);
|
||||
// }
|
||||
// #endregion
|
||||
|
||||
// #region 数据投递
|
||||
// /// <summary>
|
||||
// /// 来自服务端本地连接投递的Tunnel数据
|
||||
// /// </summary>
|
||||
// /// <param name="uid"></param>
|
||||
// /// <param name="tunnelId"></param>
|
||||
// /// <param name="data"></param>
|
||||
// public void OnRemoteLocalDataCallBack(long UID, byte tunnelId, byte Idx, byte[] data)
|
||||
// {
|
||||
// //AppNoSugarNet.log.Info($"OnServerLocalDataCallBack {tunnelId},{Idx},Data长度:{data.Length}");
|
||||
// if (!GetLocalListener(tunnelId, out ForwardLocalListener _listener))
|
||||
// return;
|
||||
// //记录压缩前数据长度
|
||||
// tReciveAllLenght += data.Length;
|
||||
// //解压
|
||||
// data = mCompressAdapter.Decompress(data);
|
||||
// _listener.SendSocketByIdx(Idx, data);
|
||||
// }
|
||||
// /// <summary>
|
||||
// /// 来自客户端本地连接投递的Tunnel数据
|
||||
// /// </summary>
|
||||
// /// <param name="uid"></param>
|
||||
// /// <param name="tunnelId"></param>
|
||||
// /// <param name="data"></param>
|
||||
// public void OnTunnelDataCallBack(long UID, byte tunnelId, byte Idx, byte[] data)
|
||||
// {
|
||||
// //AppNoSugarNet.log.Info($"OnClientTunnelDataCallBack {tunnelId},{Idx} data.Length->{data.Length}");
|
||||
|
||||
// int SlienLenght = 1000;
|
||||
// //判断数据量大时分包
|
||||
// if (data.Length > SlienLenght)
|
||||
// {
|
||||
// Span<byte> tempSpan = data;
|
||||
// Span<byte> tempSpanSlien = null;
|
||||
// int PageCount = (int)(data.Length / SlienLenght);
|
||||
// if (data.Length % SlienLenght > 0)
|
||||
// {
|
||||
// PageCount++;
|
||||
// }
|
||||
|
||||
// for (int i = 0; i < PageCount; i++)
|
||||
// {
|
||||
// int StartIdx = i * SlienLenght;
|
||||
// if (i != PageCount - 1)//不是最后一个包
|
||||
// tempSpanSlien = tempSpan.Slice(StartIdx, SlienLenght);
|
||||
// else//最后一个
|
||||
// tempSpanSlien = tempSpan.Slice(StartIdx);
|
||||
|
||||
// SendDataToRemote(tunnelId, Idx, tempSpanSlien.ToArray());
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
// SendDataToRemote(tunnelId, Idx, data);
|
||||
// }
|
||||
|
||||
// void SendDataToRemote(long UID, byte tunnelId, byte Idx, byte[] data)
|
||||
// {
|
||||
// //压缩
|
||||
// data = mCompressAdapter.Compress(data);
|
||||
// //记录压缩后数据长度
|
||||
// tSendAllLenght += data.Length;
|
||||
|
||||
// byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_Tunnel_DATA()
|
||||
// {
|
||||
// TunnelID = tunnelId,
|
||||
// Idx = Idx,
|
||||
// HunterNetCoreData = ByteString.CopyFrom(data)
|
||||
// });
|
||||
|
||||
// if (!GetLocalListener(tunnelId, out ForwardLocalListener _listener))
|
||||
// return;
|
||||
|
||||
// //远程未连接,添加到缓存
|
||||
// if (!_listener.CheckRemoteConnect(Idx))
|
||||
// {
|
||||
// _listener.EnqueueIdxWithMsg(Idx, respData);
|
||||
// return;
|
||||
// }
|
||||
// //投递给服务端,来自客户端本地的连接数据
|
||||
// AppNoSugarNet.networkHelper.SendToServer((int)CommandID.CmdTunnelC2SForwardData, respData);
|
||||
// }
|
||||
// #endregion
|
||||
// }
|
||||
//}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -14,19 +14,19 @@ enum CommandID
|
||||
|
||||
CMD_CHATMSG = 4001; //广播信息上行 | 下行 对应 Protobuf_ChatMsg | Protobuf_ChatMsg_RESP
|
||||
|
||||
CMD_TUNNEL_C2S_FORWARD_CONNECT = 5000; //正向代理,客户端告知服务端 客户端本地连接建立 上行 Protobuf_C2S_Connect
|
||||
CMD_TUNNEL_S2C_FORWARD_CONNECT = 5001; //正向代理,服务端告知客户端 服务端本地连接建立 下行 Protobuf_S2C_Connect
|
||||
CMD_TUNNEL_C2S_FORWARD_DISCONNECT = 5002; //正向代理,客户端告知服务端 客户端本地连接断开 上行 Protobuf_C2S_Disconnect
|
||||
CMD_TUNNEL_S2C_FORWARD_DISCONNECT = 5003; //正向代理,服务端告知客户端 服务端本地连接断开 下行 Protobuf_S2C_Disconnect
|
||||
CMD_TUNNEL_C2S_FORWARD_DATA = 5004; //正向代理,客户端投递本地TCP通讯数据包 上行 Protobuf_C2S_DATA
|
||||
CMD_TUNNEL_S2C_FORWARD_DATA = 5005; //正向代理,服务端投递本地TCP通讯数据包 下行 Protobuf_S2C_DATA
|
||||
CMD_TUNNEL_C2S_FORWARD_CONNECT = 5000; //正向代理,客户端告知服务端 客户端本地连接建立 上行 Protobuf_Tunnel_Connect
|
||||
CMD_TUNNEL_S2C_FORWARD_CONNECT = 5001; //正向代理,服务端告知客户端 服务端本地连接建立 下行 Protobuf_Tunnel_Connect
|
||||
CMD_TUNNEL_C2S_FORWARD_DISCONNECT = 5002; //正向代理,客户端告知服务端 客户端本地连接断开 上行 Protobuf_Tunnel_Disconnect
|
||||
CMD_TUNNEL_S2C_FORWARD_DISCONNECT = 5003; //正向代理,服务端告知客户端 服务端本地连接断开 下行 Protobuf_Tunnel_Disconnect
|
||||
CMD_TUNNEL_C2S_FORWARD_DATA = 5004; //正向代理,客户端投递本地TCP通讯数据包 上行 Protobuf_Tunnel_DATA
|
||||
CMD_TUNNEL_S2C_FORWARD_DATA = 5005; //正向代理,服务端投递本地TCP通讯数据包 下行 Protobuf_Tunnel_DATA
|
||||
|
||||
CMD_TUNNEL_C2S_REVERSE_CONNECT = 6000; //反向代理,客户端告知服务端 客户端本地连接建立 上行 Protobuf_C2S_Connect
|
||||
CMD_TUNNEL_S2C_REVERSE_CONNECT = 6001; //反向代理,服务端告知客户端 服务端本地连接建立 下行 Protobuf_S2C_Connect
|
||||
CMD_TUNNEL_C2S_REVERSE_DISCONNECT = 6002; //反向代理,客户端告知服务端 客户端本地连接断开 上行 Protobuf_C2S_Disconnect
|
||||
CMD_TUNNEL_S2C_REVERSE_DISCONNECT = 6003; //反向代理,服务端告知客户端 服务端本地连接断开 下行 Protobuf_S2C_Disconnect
|
||||
CMD_TUNNEL_C2S_REVERSE_DATA = 6004; //反向代理,客户端投递本地TCP通讯数据包 上行 Protobuf_C2S_DATA
|
||||
CMD_TUNNEL_S2C_REVERSE_DATA = 6005; //反向代理,服务端投递本地TCP通讯数据包 下行 Protobuf_S2C_DATA
|
||||
CMD_TUNNEL_C2S_REVERSE_CONNECT = 6000; //反向代理,客户端告知服务端 客户端本地连接建立 上行 Protobuf_Tunnel_Connect
|
||||
CMD_TUNNEL_S2C_REVERSE_CONNECT = 6001; //反向代理,服务端告知客户端 服务端本地连接建立 下行 Protobuf_Tunnel_Connect
|
||||
CMD_TUNNEL_C2S_REVERSE_DISCONNECT = 6002; //反向代理,客户端告知服务端 客户端本地连接断开 上行 Protobuf_Tunnel_Disconnect
|
||||
CMD_TUNNEL_S2C_REVERSE_DISCONNECT = 6003; //反向代理,服务端告知客户端 服务端本地连接断开 下行 Protobuf_Tunnel_Disconnect
|
||||
CMD_TUNNEL_C2S_REVERSE_DATA = 6004; //反向代理,客户端投递本地TCP通讯数据包 上行 Protobuf_Tunnel_DATA
|
||||
CMD_TUNNEL_S2C_REVERSE_DATA = 6005; //反向代理,服务端投递本地TCP通讯数据包 下行 Protobuf_Tunnel_DATA
|
||||
}
|
||||
|
||||
enum ErrorCode
|
||||
@ -106,39 +106,20 @@ message Protobuf_ChatMsg_RESP
|
||||
}
|
||||
|
||||
|
||||
message Protobuf_C2S_Connect
|
||||
{
|
||||
uint32 TunnelID = 1;//TunnelID
|
||||
uint32 Idx = 2;//单个隧道连接下标
|
||||
}
|
||||
|
||||
message Protobuf_S2C_Connect
|
||||
message Protobuf_Tunnel_Connect
|
||||
{
|
||||
uint32 TunnelID = 1;//TunnelID
|
||||
uint32 Idx = 2;//单个隧道连接下标
|
||||
uint32 Connected = 3;//[0]连接失败 [1]连接成功
|
||||
}
|
||||
|
||||
message Protobuf_C2S_Disconnect
|
||||
message Protobuf_Tunnel_Disconnect
|
||||
{
|
||||
uint32 TunnelID = 1;//TunnelID
|
||||
uint32 Idx = 2;//单个隧道连接下标
|
||||
}
|
||||
|
||||
message Protobuf_S2C_Disconnect
|
||||
{
|
||||
uint32 TunnelID = 1;//TunnelID
|
||||
uint32 Idx = 2;//单个隧道连接下标
|
||||
}
|
||||
|
||||
message Protobuf_C2S_DATA
|
||||
{
|
||||
uint32 TunnelID = 1;//TunnelID
|
||||
uint32 Idx = 2;//单个隧道连接下标
|
||||
bytes HunterNetCore_Data = 3;
|
||||
}
|
||||
|
||||
message Protobuf_S2C_DATA
|
||||
message Protobuf_Tunnel_DATA
|
||||
{
|
||||
uint32 TunnelID = 1;//TunnelID
|
||||
uint32 Idx = 2;//单个隧道连接下标
|
||||
|
Loading…
Reference in New Issue
Block a user