diff --git a/Lib/HaoYueNet.ClientNetwork.dll b/Lib/HaoYueNet.ClientNetwork.dll index bc3795c..62b18f6 100644 Binary files a/Lib/HaoYueNet.ClientNetwork.dll and b/Lib/HaoYueNet.ClientNetwork.dll differ diff --git a/Lib/HaoYueNet.ServerNetwork.dll b/Lib/HaoYueNet.ServerNetwork.dll index 6e7dce7..4e568e7 100644 Binary files a/Lib/HaoYueNet.ServerNetwork.dll and b/Lib/HaoYueNet.ServerNetwork.dll differ diff --git a/Lib/NetLib_Standard2/HaoYueNet.ClientNetworkNet.Standard2.dll b/Lib/NetLib_Standard2/HaoYueNet.ClientNetworkNet.Standard2.dll index c3c4a90..b1390f1 100644 Binary files a/Lib/NetLib_Standard2/HaoYueNet.ClientNetworkNet.Standard2.dll and b/Lib/NetLib_Standard2/HaoYueNet.ClientNetworkNet.Standard2.dll differ diff --git a/NoSugarNet.ClientCore/Manager/AppLocalClient.cs b/NoSugarNet.ClientCore/Manager/AppLocalClient.cs index f7000c5..e319675 100644 --- a/NoSugarNet.ClientCore/Manager/AppLocalClient.cs +++ b/NoSugarNet.ClientCore/Manager/AppLocalClient.cs @@ -49,6 +49,24 @@ namespace ServerCore.Manager ClientUserCount = mDictTunnelID2Listeners.Count; } + public void GetClientDebugInfo() + { + AppNoSugarNet.log.Debug($"------------ mDictTunnelID2Listeners {mDictTunnelID2Listeners.Count} ------------"); + lock (mDictTunnelID2Listeners) + { + foreach (var item in mDictTunnelID2Listeners) + { + var cinfo = item.Value.GetDictIdx2LocalClientInfo(); + AppNoSugarNet.log.Debug($"----- TunnelID {item.Key} ObjcurrSeed->{item.Value.currSeed} ClientList->{item.Value.ClientList.Count} Idx2LocalClient->{cinfo.Count} -----"); + + foreach (var c in cinfo) + { + AppNoSugarNet.log.Debug($"----- Idx {c.Key} bRemoteConnect->{c.Value.bRemoteConnect} msgQueue.Count->{c.Value.msgQueue.Count} -----"); + } + } + } + } + /// /// 初始化连接,先获取到配置 /// @@ -114,10 +132,12 @@ namespace ServerCore.Manager for (int i = 0; i < keys.Length; i++) { LocalListener _listener = mDictTunnelID2Listeners[keys[i]]; - _listener.StopAll(); + _listener.StopAllLocalClient(); + _listener.Stop(); //_listener.Stop(); RemoveLocalListener(_listener); } + mDictTunnelID2Listeners.Clear(); } } #endregion @@ -266,7 +286,7 @@ namespace ServerCore.Manager /// public void OnClientTunnelDataCallBack(byte tunnelId,byte Idx, byte[] data) { - //AppNoSugarNet.log.Info($"OnClientTunnelDataCallBack {tunnelId},{Idx}"); + //AppNoSugarNet.log.Info($"OnClientTunnelDataCallBack {tunnelId},{Idx} data.Length->{data.Length}"); int SlienLenght = 1000; //判断数据量大时分包 diff --git a/NoSugarNet.ClientCore/Manager/AppLogin.cs b/NoSugarNet.ClientCore/Manager/AppLogin.cs index 73a013b..d1ad4de 100644 --- a/NoSugarNet.ClientCore/Manager/AppLogin.cs +++ b/NoSugarNet.ClientCore/Manager/AppLogin.cs @@ -6,16 +6,22 @@ namespace NoSugarNet.ClientCore.Manager { public class AppLogin { + static string LastLoginGuid = ""; public AppLogin() { NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdLogin, RecvLoginMsg); } - public void Login(string Account) + + public void Login() { + if(string.IsNullOrEmpty(LastLoginGuid)) + LastLoginGuid = Guid.NewGuid().ToString(); + + AppNoSugarNet.user.userdata.Account = LastLoginGuid; Protobuf_Login msg = new Protobuf_Login() { LoginType = 0, - Account = Account, + Account = AppNoSugarNet.user.userdata.Account, }; AppNoSugarNet.networkHelper.SendToServer((int)CommandID.CmdLogin, ProtoBufHelper.Serizlize(msg)); } diff --git a/NoSugarNet.ClientCore/Manager/LocalClient/LocalListener.cs b/NoSugarNet.ClientCore/Manager/LocalClient/LocalListener.cs index 5501e4d..247f6a7 100644 --- a/NoSugarNet.ClientCore/Manager/LocalClient/LocalListener.cs +++ b/NoSugarNet.ClientCore/Manager/LocalClient/LocalListener.cs @@ -8,6 +8,9 @@ namespace NoSugarNet.ClientCore public byte mTunnelID; public long mReciveAllLenght; public long mSendAllLenght; + public long currSeed; + static long Seed; + public LocalListener(int numConnections, int receiveBufferSize, byte TunnelID) : base(numConnections, receiveBufferSize) { @@ -17,12 +20,14 @@ namespace NoSugarNet.ClientCore OnNetLog += OnShowNetLog; mTunnelID = TunnelID; + + currSeed = Seed++; } private void ClientNumberChange(int num, AsyncUserToken token) { AppNoSugarNet.log.Info("Client数发生变化"); - //增加连接数 + //增加连接数stsc if (num > 0) { int Idx = AddDictSocket(token.Socket); @@ -79,9 +84,16 @@ namespace NoSugarNet.ClientCore public void CloseConnectByIdx(byte Idx) { - if (GetSocketByIdx(Idx, out LocalClientInfo _localClientInf)) + if (GetSocketByIdx(Idx, out LocalClientInfo _localClientInfo)) { - _localClientInf._socket.Shutdown(SocketShutdown.Both); + //把未发送消息队列回收了 + while (_localClientInfo.msgQueue.Count > 0) + { + IdxWithMsg msg = _localClientInfo.msgQueue.Dequeue(); + AppNoSugarNet.local._localMsgPool.Enqueue(msg); + } + + _localClientInfo._socket.Shutdown(SocketShutdown.Both); } } @@ -118,6 +130,11 @@ namespace NoSugarNet.ClientCore public Queue msgQueue = new Queue(); } + public Dictionary GetDictIdx2LocalClientInfo() + { + return DictIdx2LocalClientInfo; + } + int GetNextIdx() { if (FreeIdxs.Count > 0) @@ -129,6 +146,12 @@ namespace NoSugarNet.ClientCore return mSeedIdx++; } + void ResetFree() + { + FreeIdxs.Clear(); + mSeedIdx = 0; + } + /// /// 追加Socket返回下标 /// @@ -143,6 +166,7 @@ namespace NoSugarNet.ClientCore int Idx = GetNextIdx(); DictSocketHandle2Idx[socket.Handle] = Idx; DictIdx2LocalClientInfo[Idx] = new LocalClientInfo() { _socket = socket,bRemoteConnect = false}; + AppNoSugarNet.log.Debug($"AddDictSocket mTunnelID->{mTunnelID} Idx->{Idx} socket.Handle{socket.Handle}"); return Idx; } } @@ -160,6 +184,7 @@ namespace NoSugarNet.ClientCore if (DictIdx2LocalClientInfo.ContainsKey(Idx)) DictIdx2LocalClientInfo.Remove(Idx); DictSocketHandle2Idx.Remove(socket.Handle); + AppNoSugarNet.log.Debug($"RemoveDictSocket mTunnelID->{mTunnelID} Idx->{Idx} socket.Handle{socket.Handle}"); } } @@ -211,7 +236,7 @@ namespace NoSugarNet.ClientCore _localClientInfo.bRemoteConnect = bConnected; } - public void StopAll() + public void StopAllLocalClient() { lock (DictIdx2LocalClientInfo) { @@ -221,6 +246,14 @@ namespace NoSugarNet.ClientCore CloseConnectByIdx((byte)Idxs[i]); } DictIdx2LocalClientInfo.Clear(); + DictSocketHandle2Idx.Clear(); + ResetFree(); + + //清理事件 + OnClientNumberChange -= ClientNumberChange; + OnReceive -= ReceiveData; + OnDisconnected -= OnDisconnect; + OnNetLog -= OnShowNetLog; } } diff --git a/NoSugarNet.ClientCore/Manager/LocalClient/LocalListener_Source.cs b/NoSugarNet.ClientCore/Manager/LocalClient/LocalListener_Source.cs index 163b2c7..0e93238 100644 --- a/NoSugarNet.ClientCore/Manager/LocalClient/LocalListener_Source.cs +++ b/NoSugarNet.ClientCore/Manager/LocalClient/LocalListener_Source.cs @@ -1,290 +1,296 @@ -using HaoYueNet.ClientNetwork.OtherMode; -using HaoYueNet.ServerNetwork; -using System.Net.Sockets; +//using HaoYueNet.ClientNetwork.OtherMode; +//using HaoYueNet.ServerNetwork; +//using System.Net.Sockets; -namespace NoSugarNet.ClientCore -{ - public class LocalListener_Source : NetworkHelperCore_ListenerMode - { - public byte mTunnelID; - public long mReciveAllLenght; - public long mSendAllLenght; - public LocalListener_Source(int numConnections, int receiveBufferSize, byte TunnelID) - : base() - { - OnConnected += ClientNumberChange; - OnReceive += ReceiveData; - OnDisconnected += OnDisconnectClient; - OnNetLog += OnShowNetLog; +//namespace NoSugarNet.ClientCore +//{ +// public class LocalListener_Source : NetworkHelperCore_ListenerMode +// { +// public byte mTunnelID; +// public long mReciveAllLenght; +// public long mSendAllLenght; +// public LocalListener_Source(int numConnections, int receiveBufferSize, byte TunnelID) +// : base() +// { +// OnConnected += ClientNumberChange; +// OnReceive += ReceiveData; +// OnDisconnected += OnDisconnectClient; +// OnNetLog += OnShowNetLog; - mTunnelID = TunnelID; - } +// mTunnelID = TunnelID; +// } - private void ClientNumberChange(Socket socket) - { - AppNoSugarNet.log.Info("Client数发生变化"); - //增加连接数 - int Idx = AddDictSocket(socket); - if (GetSocketByIdx(Idx, out LocalClientInfo _localClientInf)) - { - AppNoSugarNet.local.OnClientLocalConnect(mTunnelID, (byte)Idx); - } - } +// private void ClientNumberChange(Socket socket) +// { +// AppNoSugarNet.log.Info("Client数发生变化"); +// //增加连接数 +// int Idx = AddDictSocket(socket); +// if (GetSocketByIdx(Idx, out LocalClientInfo _localClientInf)) +// { +// AppNoSugarNet.local.OnClientLocalConnect(mTunnelID, (byte)Idx); +// } +// } - /// - /// 通过下标发送 - /// - /// - /// - public void SendSocketByIdx(int Idx, byte[] data) - { - if (GetSocketByIdx(Idx, out LocalClientInfo _localClientInfo)) - { - mSendAllLenght += data.Length; - SendToClient(_localClientInfo._socket, data); - } - //TODO连接前缓存数据 - } +// /// +// /// 通过下标发送 +// /// +// /// +// /// +// public void SendSocketByIdx(int Idx, byte[] data) +// { +// if (GetSocketByIdx(Idx, out LocalClientInfo _localClientInfo)) +// { +// mSendAllLenght += data.Length; +// SendToClient(_localClientInfo._socket, data); +// } +// //TODO连接前缓存数据 +// } - /// - /// 接受包回调 - /// - /// 协议ID - /// 错误编号 - /// 业务数据 - private void ReceiveData(Socket sk, byte[] data) - { - DataCallBack(sk, data); - } +// /// +// /// 接受包回调 +// /// +// /// 协议ID +// /// 错误编号 +// /// 业务数据 +// private void ReceiveData(Socket sk, byte[] data) +// { +// DataCallBack(sk, data); +// } - public void DataCallBack(Socket sk, byte[] data) - { - //AppNoSugarNet.log.Info("收到消息 数据长度=>" + data.Length); - //记录接受长度 - mReciveAllLenght += data.Length; - if (!GetSocketIdxBySocket(sk, out int Idx)) - return; - try - { - if (GetMsgQueueByIdx(sk.Handle, out Queue _queue)) - { - lock (_queue) - { - _queue.Enqueue(data); - while (_queue.Count > 0) - { - AppNoSugarNet.local.OnClientTunnelDataCallBack(mTunnelID, (byte)Idx, _queue.Dequeue()); - } - } - } +// public void DataCallBack(Socket sk, byte[] data) +// { +// //AppNoSugarNet.log.Info("收到消息 数据长度=>" + data.Length); +// //记录接受长度 +// mReciveAllLenght += data.Length; +// if (!GetSocketIdxBySocket(sk, out int Idx)) +// return; +// try +// { +// if (GetMsgQueueByIdx(sk.Handle, out Queue _queue)) +// { +// lock (_queue) +// { +// _queue.Enqueue(data); +// while (_queue.Count > 0) +// { +// AppNoSugarNet.local.OnClientTunnelDataCallBack(mTunnelID, (byte)Idx, _queue.Dequeue()); +// } +// } +// } - ////抛出网络数据 - //AppNoSugarNet.local.OnClientTunnelDataCallBack(mTunnelID, (byte)Idx, data); - } - catch (Exception ex) - { - AppNoSugarNet.log.Info("逻辑处理错误:" + ex.ToString()); - } - } +// ////抛出网络数据 +// //AppNoSugarNet.local.OnClientTunnelDataCallBack(mTunnelID, (byte)Idx, data); +// } +// catch (Exception ex) +// { +// AppNoSugarNet.log.Info("逻辑处理错误:" + ex.ToString()); +// } +// } - public void CloseConnectByIdx(byte Idx) - { - if (GetSocketByIdx(Idx, out LocalClientInfo _localClientInf)) - { - _localClientInf._socket.Shutdown(SocketShutdown.Both); - } - } +// public void CloseConnectByIdx(byte Idx) +// { +// if (GetSocketByIdx(Idx, out LocalClientInfo _localClientInf)) +// { +// _localClientInf._socket.Shutdown(SocketShutdown.Both); +// } +// } - /// - /// 断开连接 - /// - /// - public void OnDisconnectClient(Socket sk) - { - AppNoSugarNet.log.Info("断开连接"); +// /// +// /// 断开连接 +// /// +// /// +// public void OnDisconnectClient(Socket sk) +// { +// AppNoSugarNet.log.Info("断开连接"); - if (!GetSocketIdxBySocket(sk, out int Idx)) - return; +// if (!GetSocketIdxBySocket(sk, out int Idx)) +// return; - AppNoSugarNet.local.OnClientLocalDisconnect(mTunnelID, (byte)Idx); - RemoveDictSocket(sk); - } +// AppNoSugarNet.local.OnClientLocalDisconnect(mTunnelID, (byte)Idx); +// RemoveDictSocket(sk); +// } - public void OnShowNetLog(string msg) - { - AppNoSugarNet.log.Info(msg); - } +// public void OnShowNetLog(string msg) +// { +// AppNoSugarNet.log.Info(msg); +// } - #region 一个轻量级无用户连接管理 - Dictionary DictSocketHandle2Idx = new Dictionary(); - Dictionary> DictSocketHandle2Msg = new Dictionary>(); - Dictionary DictIdx2LocalClientInfo = new Dictionary(); - int mSeedIdx = 0; - List FreeIdxs = new List(); - public class LocalClientInfo - { - public Socket _socket; - public bool bRemoteConnect; - public bool bLocalConnect => _socket.Connected; - public Queue msgQueue = new Queue(); - } +// #region 一个轻量级无用户连接管理 +// Dictionary DictSocketHandle2Idx = new Dictionary(); +// Dictionary> DictSocketHandle2Msg = new Dictionary>(); +// Dictionary DictIdx2LocalClientInfo = new Dictionary(); +// int mSeedIdx = 0; +// List FreeIdxs = new List(); +// public class LocalClientInfo +// { +// public Socket _socket; +// public bool bRemoteConnect; +// public bool bLocalConnect => _socket.Connected; +// public Queue msgQueue = new Queue(); +// } - int GetNextIdx() - { - if (FreeIdxs.Count > 0) - { - int Idx = FreeIdxs[0]; - FreeIdxs.RemoveAt(0); - return Idx; - } - return mSeedIdx++; - } +// int GetNextIdx() +// { +// if (FreeIdxs.Count > 0) +// { +// int Idx = FreeIdxs[0]; +// FreeIdxs.RemoveAt(0); +// return Idx; +// } +// return mSeedIdx++; +// } - /// - /// 追加Socket返回下标 - /// - /// - /// - public int AddDictSocket(Socket socket) - { - if (socket == null) - return -1; - lock (DictSocketHandle2Idx) - { - int Idx = GetNextIdx(); - DictSocketHandle2Idx[socket.Handle] = Idx; - DictIdx2LocalClientInfo[Idx] = new LocalClientInfo() { _socket = socket,bRemoteConnect = false}; - DictSocketHandle2Msg[socket.Handle] = new Queue(); - return Idx; - } - } +// /// +// /// 追加Socket返回下标 +// /// +// /// +// /// +// public int AddDictSocket(Socket socket) +// { +// if (socket == null) +// return -1; - public void RemoveDictSocket(Socket socket) - { - if (socket == null) - return; - lock (DictSocketHandle2Idx) - { - if (!DictSocketHandle2Idx.ContainsKey(socket.Handle)) - return; - int Idx = DictSocketHandle2Idx[socket.Handle]; - FreeIdxs.Add(Idx); - if (DictIdx2LocalClientInfo.ContainsKey(Idx)) - DictIdx2LocalClientInfo.Remove(Idx); +// lock (DictSocketHandle2Idx) +// { +// int Idx = GetNextIdx(); +// DictSocketHandle2Idx[socket.Handle] = Idx; +// DictIdx2LocalClientInfo[Idx] = new LocalClientInfo() { _socket = socket,bRemoteConnect = false}; +// DictSocketHandle2Msg[socket.Handle] = new Queue(); +// AppNoSugarNet.log.Debug($"AddDictSocket mTunnelID->{mTunnelID} Idx->{Idx} socket.Handle{socket.Handle}"); +// return Idx; +// } +// } + +// public void RemoveDictSocket(Socket socket) +// { +// if (socket == null) +// return; +// lock (DictSocketHandle2Idx) +// { +// if (!DictSocketHandle2Idx.ContainsKey(socket.Handle)) +// return; +// int Idx = DictSocketHandle2Idx[socket.Handle]; +// FreeIdxs.Add(Idx); +// if (DictIdx2LocalClientInfo.ContainsKey(Idx)) +// DictIdx2LocalClientInfo.Remove(Idx); - if (DictSocketHandle2Msg.ContainsKey(socket.Handle)) - DictSocketHandle2Msg.Remove(socket.Handle); +// if (DictSocketHandle2Msg.ContainsKey(socket.Handle)) +// DictSocketHandle2Msg.Remove(socket.Handle); - DictSocketHandle2Idx.Remove(socket.Handle); - } - } +// DictSocketHandle2Idx.Remove(socket.Handle); - bool GetSocketByIdx(int Idx, out LocalClientInfo _localClientInfo) - { - if (!DictIdx2LocalClientInfo.ContainsKey(Idx)) - { - _localClientInfo = null; - return false; - } +// AppNoSugarNet.log.Debug($"RemoveDictSocket mTunnelID->{mTunnelID} Idx->{Idx} socket.Handle{socket.Handle}"); +// } +// } - _localClientInfo = DictIdx2LocalClientInfo[Idx]; - return true; - } +// bool GetSocketByIdx(int Idx, out LocalClientInfo _localClientInfo) +// { +// if (!DictIdx2LocalClientInfo.ContainsKey(Idx)) +// { +// _localClientInfo = null; +// return false; +// } - bool GetMsgQueueByIdx(nint handle, out Queue _queue) - { - if (!DictSocketHandle2Msg.ContainsKey(handle)) - { - _queue = null; - return false; - } +// _localClientInfo = DictIdx2LocalClientInfo[Idx]; +// return true; +// } - _queue = DictSocketHandle2Msg[handle]; - return true; - } +// bool GetMsgQueueByIdx(nint handle, out Queue _queue) +// { +// if (!DictSocketHandle2Msg.ContainsKey(handle)) +// { +// _queue = null; +// return false; +// } - public bool GetSocketIdxBySocket(Socket _socket, out int Idx) - { - if (_socket == null) - { - Idx = -1; - return false; - } +// _queue = DictSocketHandle2Msg[handle]; +// return true; +// } - if (!DictSocketHandle2Idx.ContainsKey(_socket.Handle)) - { - Idx = -1; - return false; - } +// public bool GetSocketIdxBySocket(Socket _socket, out int Idx) +// { +// if (_socket == null) +// { +// Idx = -1; +// return false; +// } - Idx = DictSocketHandle2Idx[_socket.Handle]; - return true; - } +// if (!DictSocketHandle2Idx.ContainsKey(_socket.Handle)) +// { +// Idx = -1; +// return false; +// } - public bool CheckRemoteConnect(int Idx) - { - if (!GetSocketByIdx(Idx, out LocalClientInfo _localClientInfo)) - return false; - return _localClientInfo.bRemoteConnect; - } +// Idx = DictSocketHandle2Idx[_socket.Handle]; +// return true; +// } - public void SetRemoteConnectd(int Idx,bool bConnected) - { - if (!GetSocketByIdx(Idx, out LocalClientInfo _localClientInfo)) - return; - if (bConnected) - AppNoSugarNet.log.Info("远端本地连接已连接!!!!"); - else - AppNoSugarNet.log.Info("远端本地连接已断开连接!!!!"); - _localClientInfo.bRemoteConnect = bConnected; - } +// public bool CheckRemoteConnect(int Idx) +// { +// if (!GetSocketByIdx(Idx, out LocalClientInfo _localClientInfo)) +// return false; +// return _localClientInfo.bRemoteConnect; +// } - public void StopAll() - { - lock (DictIdx2LocalClientInfo) - { - int[] Idxs = DictIdx2LocalClientInfo.Keys.ToArray(); - for (int i = 0; i < Idxs.Length; i++) - { - CloseConnectByIdx((byte)Idxs[i]); - } - DictIdx2LocalClientInfo.Clear(); - } - } +// public void SetRemoteConnectd(int Idx,bool bConnected) +// { +// if (!GetSocketByIdx(Idx, out LocalClientInfo _localClientInfo)) +// return; +// if (bConnected) +// AppNoSugarNet.log.Info("远端本地连接已连接!!!!"); +// else +// AppNoSugarNet.log.Info("远端本地连接已断开连接!!!!"); +// _localClientInfo.bRemoteConnect = bConnected; +// } - #endregion +// public void StopAll() +// { +// lock (DictIdx2LocalClientInfo) +// { +// int[] Idxs = DictIdx2LocalClientInfo.Keys.ToArray(); +// for (int i = 0; i < Idxs.Length; i++) +// { +// CloseConnectByIdx((byte)Idxs[i]); +// } +// DictIdx2LocalClientInfo.Clear(); +// FreeIdxs.Clear(); +// mSeedIdx = 0; +// } +// } + +// #endregion - #region 缓存 - public void EnqueueIdxWithMsg(byte Idx, byte[] data) - { - if (!GetSocketByIdx(Idx, out LocalClientInfo _localClientInfo)) - return; +// #region 缓存 +// public void EnqueueIdxWithMsg(byte Idx, byte[] data) +// { +// if (!GetSocketByIdx(Idx, out LocalClientInfo _localClientInfo)) +// return; - IdxWithMsg Msg = AppNoSugarNet.local._localMsgPool.Dequeue(); - Msg.Idx = Idx; - Msg.data = data; - _localClientInfo.msgQueue.Enqueue(Msg); - } - public bool GetDictMsgQueue(byte Idx,out List MsgList) - { - if (!GetSocketByIdx(Idx, out LocalClientInfo _localClientInfo) || _localClientInfo.msgQueue.Count < 1) - { - MsgList = null; - return false; - } +// IdxWithMsg Msg = AppNoSugarNet.local._localMsgPool.Dequeue(); +// Msg.Idx = Idx; +// Msg.data = data; +// _localClientInfo.msgQueue.Enqueue(Msg); +// } +// public bool GetDictMsgQueue(byte Idx,out List MsgList) +// { +// if (!GetSocketByIdx(Idx, out LocalClientInfo _localClientInfo) || _localClientInfo.msgQueue.Count < 1) +// { +// MsgList = null; +// return false; +// } - MsgList = new List(); - lock (_localClientInfo.msgQueue) - { - while (_localClientInfo.msgQueue.Count > 0) - { - IdxWithMsg msg = _localClientInfo.msgQueue.Dequeue(); - MsgList.Add(msg); - } - return true; - } - } - #endregion - } -} +// MsgList = new List(); +// lock (_localClientInfo.msgQueue) +// { +// while (_localClientInfo.msgQueue.Count > 0) +// { +// IdxWithMsg msg = _localClientInfo.msgQueue.Dequeue(); +// MsgList.Add(msg); +// } +// return true; +// } +// } +// #endregion +// } +//} diff --git a/NoSugarNet.ClientCore/Manager/UserDataManager.cs b/NoSugarNet.ClientCore/Manager/UserDataManager.cs index 553ec82..050452a 100644 --- a/NoSugarNet.ClientCore/Manager/UserDataManager.cs +++ b/NoSugarNet.ClientCore/Manager/UserDataManager.cs @@ -49,7 +49,7 @@ namespace NoSugarNet.ClientCore.Manager //如果之前已登录,则重新登录 if (userdata.IsLoggedIn) { - AppNoSugarNet.login.Login(userdata.Account); + AppNoSugarNet.login.Login(); } } } diff --git a/NoSugarNet.ClientCore/Network/NetworkHelper.cs b/NoSugarNet.ClientCore/Network/NetworkHelper.cs index 430c587..df64c5c 100644 --- a/NoSugarNet.ClientCore/Network/NetworkHelper.cs +++ b/NoSugarNet.ClientCore/Network/NetworkHelper.cs @@ -33,7 +33,7 @@ namespace NoSugarNet.ClientCore.Network /// /// 是否自动重连 /// - public bool bAutoReConnect = false; + public bool bAutoReConnect = true; /// /// 重连尝试时间 /// @@ -44,12 +44,21 @@ namespace NoSugarNet.ClientCore.Network NetworkDeBugLog($"NetworkConnected:{IsConnect}"); if (IsConnect) { - AppNoSugarNet.login.Login(Guid.NewGuid().ToString()); + //从未登录过 + if (!AppNoSugarNet.user.IsLoggedIn) + { + //首次登录 + AppNoSugarNet.login.Login(); + } } else { //连接失败 NetworkDeBugLog("连接失败!"); + + //停止所有 + AppNoSugarNet.local.StopAll(); + //自动重连开关 if (bAutoReConnect) ReConnect(); diff --git a/NoSugarNet.ClientCore/Properties/PublishProfiles/FolderProfile.pubxml.user b/NoSugarNet.ClientCore/Properties/PublishProfiles/FolderProfile.pubxml.user index be64a25..95f96cb 100644 --- a/NoSugarNet.ClientCore/Properties/PublishProfiles/FolderProfile.pubxml.user +++ b/NoSugarNet.ClientCore/Properties/PublishProfiles/FolderProfile.pubxml.user @@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121. --> - True|2024-01-23T08:25:49.0876201Z; + True|2024-04-23T09:15:55.5521754Z;True|2024-01-23T16:25:49.0876201+08:00; \ No newline at end of file diff --git a/NoSugarNet.ServerCore/Properties/PublishProfiles/FolderProfile.pubxml.user b/NoSugarNet.ServerCore/Properties/PublishProfiles/FolderProfile.pubxml.user index 8aebd5c..55d7f13 100644 --- a/NoSugarNet.ServerCore/Properties/PublishProfiles/FolderProfile.pubxml.user +++ b/NoSugarNet.ServerCore/Properties/PublishProfiles/FolderProfile.pubxml.user @@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121. --> - True|2024-01-25T09:08:35.3176032Z; + True|2024-04-23T09:13:21.9642037Z;True|2024-04-23T17:02:04.8137007+08:00;True|2024-01-25T17:08:35.3176032+08:00; \ No newline at end of file diff --git a/Sample/NoSugarNet.ClientCli/NoSugarNet.ClientCli.csproj.user b/Sample/NoSugarNet.ClientCli/NoSugarNet.ClientCli.csproj.user index 2241f9c..6d2fdd4 100644 --- a/Sample/NoSugarNet.ClientCli/NoSugarNet.ClientCli.csproj.user +++ b/Sample/NoSugarNet.ClientCli/NoSugarNet.ClientCli.csproj.user @@ -1,6 +1,6 @@  - <_LastSelectedProfileId>D:\NoSugarNet\Sample\NoSugarNet.ClientCli\Properties\PublishProfiles\FolderProfile.pubxml + <_LastSelectedProfileId>F:\Sin365\NoSugarNet\Sample\NoSugarNet.ClientCli\Properties\PublishProfiles\FolderProfile.pubxml \ No newline at end of file diff --git a/Sample/NoSugarNet.ClientCli/Program.cs b/Sample/NoSugarNet.ClientCli/Program.cs index 1f72b17..68d698d 100644 --- a/Sample/NoSugarNet.ClientCli/Program.cs +++ b/Sample/NoSugarNet.ClientCli/Program.cs @@ -27,6 +27,12 @@ namespace NoSugarNet.ClientCli case "con": AppNoSugarNet.Connect(Config.ServerIP, Config.ServerPort); break; + case "tlist": + AppNoSugarNet.local.GetClientCount(out int ClientUserCount, out int TunnelCount); + Console.WriteLine($"GetClientCount->{ClientUserCount} TunnelCount->{TunnelCount}"); + + AppNoSugarNet.local.GetClientDebugInfo(); + break; case "stop": AppNoSugarNet.Close(); break; diff --git a/Sample/NoSugarNet.ClientCli/Properties/PublishProfiles/FolderProfile.pubxml b/Sample/NoSugarNet.ClientCli/Properties/PublishProfiles/FolderProfile.pubxml index 7d6298f..d37ba18 100644 --- a/Sample/NoSugarNet.ClientCli/Properties/PublishProfiles/FolderProfile.pubxml +++ b/Sample/NoSugarNet.ClientCli/Properties/PublishProfiles/FolderProfile.pubxml @@ -6,12 +6,13 @@ https://go.microsoft.com/fwlink/?LinkID=208121. Release Any CPU - bin\Release\net8.0\publish\linux-x64\ + bin\Release\net8.0\publish\win-x64\ FileSystem <_TargetId>Folder net8.0 - linux-x64 + win-x64 false false + false \ No newline at end of file diff --git a/Sample/NoSugarNet.ClientCli/Properties/PublishProfiles/FolderProfile.pubxml.user b/Sample/NoSugarNet.ClientCli/Properties/PublishProfiles/FolderProfile.pubxml.user index 535e1dd..6a16d09 100644 --- a/Sample/NoSugarNet.ClientCli/Properties/PublishProfiles/FolderProfile.pubxml.user +++ b/Sample/NoSugarNet.ClientCli/Properties/PublishProfiles/FolderProfile.pubxml.user @@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121. --> - True|2024-04-14T14:24:49.2846754Z;True|2024-01-23T16:35:06.3918472+08:00;True|2024-01-23T16:34:52.0595483+08:00;True|2024-01-23T16:27:36.4850749+08:00;True|2024-01-23T16:27:04.0721589+08:00; + True|2024-06-18T04:59:35.6257454Z;True|2024-06-18T10:27:07.8233386+08:00;True|2024-06-17T15:05:24.3158316+08:00;True|2024-05-20T18:14:09.8394409+08:00;True|2024-05-20T18:13:33.8442145+08:00;True|2024-05-20T18:01:49.3220793+08:00;True|2024-05-20T18:01:28.3681468+08:00;True|2024-04-14T22:24:49.2846754+08:00;True|2024-01-23T16:35:06.3918472+08:00;True|2024-01-23T16:34:52.0595483+08:00;True|2024-01-23T16:27:36.4850749+08:00;True|2024-01-23T16:27:04.0721589+08:00; \ No newline at end of file diff --git a/Sample/NoSugarNet.ServerCli/Properties/PublishProfiles/FolderProfile.pubxml.user b/Sample/NoSugarNet.ServerCli/Properties/PublishProfiles/FolderProfile.pubxml.user index bc9d86e..4195f51 100644 --- a/Sample/NoSugarNet.ServerCli/Properties/PublishProfiles/FolderProfile.pubxml.user +++ b/Sample/NoSugarNet.ServerCli/Properties/PublishProfiles/FolderProfile.pubxml.user @@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121. --> - True|2024-04-15T07:24:50.3598281Z;True|2024-04-15T15:24:34.0374231+08:00;True|2024-01-25T17:09:07.9161603+08:00;True|2024-01-23T18:28:01.1220581+08:00;True|2024-01-23T16:36:21.1141328+08:00; + True|2024-06-18T03:37:53.3986849Z;True|2024-06-18T11:21:56.8035265+08:00;True|2024-06-18T11:21:19.5434721+08:00;True|2024-06-18T11:21:01.1589956+08:00;True|2024-06-18T11:13:38.3624463+08:00;True|2024-06-18T11:10:28.0508856+08:00;True|2024-06-18T10:39:23.0033920+08:00;True|2024-06-18T10:28:08.9658896+08:00;True|2024-06-17T14:46:33.2307641+08:00;True|2024-05-20T17:56:34.6581491+08:00;True|2024-04-23T17:02:36.4793408+08:00;True|2024-04-15T15:24:50.3598281+08:00;True|2024-04-15T15:24:34.0374231+08:00;True|2024-01-25T17:09:07.9161603+08:00;True|2024-01-23T18:28:01.1220581+08:00;True|2024-01-23T16:36:21.1141328+08:00; \ No newline at end of file