偶尔出现的 同设备登录BUG, 通过SocketClient重新链接后的的安全甄别
parent
f4cc0e0d63
commit
fd7f19c8ec
|
|
@ -226,7 +226,7 @@ namespace GameLogic
|
|||
public static string ShareSDK_AppID = string.Empty;
|
||||
public static string ShareSDK_AppSecret = string.Empty;
|
||||
|
||||
public static float ConnectTimeout = 3.0f;
|
||||
public static float ConnectTimeout = 5f;
|
||||
public static float HttpTimeout = 3.0f;
|
||||
public static string AliyResourceErrorStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error>\n <Code>NoSuchKey</Code>\n <Message>The specified key does not exist.</Message>";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,11 @@ static class IPAddressExtensions
|
|||
public class SocketClient
|
||||
{
|
||||
public NetworkManager netMgr;
|
||||
|
||||
private TcpClient client = null;
|
||||
|
||||
|
||||
|
||||
private NetworkStream outStream = null;
|
||||
private MemoryStream _memStream;
|
||||
public MemoryStream CurMemoryStream
|
||||
|
|
@ -236,6 +240,11 @@ public class SocketClient
|
|||
int bytesRead = 0;
|
||||
try
|
||||
{
|
||||
//NetBug.Fix by FHF..
|
||||
//甄别socket当前是否正在连接中,避免重连的间隔内收到服务端消息。.
|
||||
if (client == null || !client.Connected)
|
||||
return;
|
||||
|
||||
lock (client.GetStream())
|
||||
{
|
||||
//读取字节流到缓冲区
|
||||
|
|
@ -375,6 +384,10 @@ public class SocketClient
|
|||
/// <param name="ms"></param>
|
||||
void OnReceivedMessage(ByteBuffer buffer)
|
||||
{
|
||||
//NetBug.Fix by FHF..
|
||||
//甄别socket当前是否正在连接中,避免重连的间隔内收到服务端消息。.
|
||||
if (client == null || !client.Connected)
|
||||
return;
|
||||
//user id
|
||||
buffer.ReadIntToByte();
|
||||
//token
|
||||
|
|
@ -415,23 +428,30 @@ public class SocketClient
|
|||
public void Close()
|
||||
{
|
||||
Debug.Log("****Socket*********************Close ---" + IpAddress);
|
||||
//确保 关闭Client的链接状态。
|
||||
if (client != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
client.Close();
|
||||
}
|
||||
finally
|
||||
{
|
||||
client = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
UnregistNetMessage(INDICATION_ERROR_CODE, Ygqmgx_indicationErrorAction);
|
||||
m_isConnected = false;
|
||||
m_isConnecting = false;
|
||||
|
||||
lock (mEvents)
|
||||
{
|
||||
mEvents.Clear();
|
||||
}
|
||||
|
||||
dispatchers.Clear();
|
||||
callbacks.Clear();
|
||||
stateInfoStack.Clear();
|
||||
|
||||
if (client != null)
|
||||
{
|
||||
client.Close();
|
||||
client = null;
|
||||
}
|
||||
|
||||
|
||||
if (_memStream != null)
|
||||
{
|
||||
|
|
@ -444,6 +464,11 @@ public class SocketClient
|
|||
_reader = null;
|
||||
}
|
||||
Array.Clear(byteBuffer, 0, byteBuffer.Length);
|
||||
|
||||
//lock (mEvents)
|
||||
//{
|
||||
mEvents.Clear();
|
||||
//}
|
||||
}
|
||||
|
||||
bool testConnect;
|
||||
|
|
@ -636,12 +661,21 @@ public class SocketClient
|
|||
|
||||
m_isConnecting = true;
|
||||
|
||||
yield return new WaitForEndOfFrame();
|
||||
if (IsConnected())
|
||||
{
|
||||
Close();
|
||||
yield return new WaitForSeconds(1);
|
||||
}
|
||||
|
||||
|
||||
Reconnect();
|
||||
yield return new WaitForSeconds(AppConst.ConnectTimeout);
|
||||
if (!IsConnected())
|
||||
{
|
||||
OnReconnectFail();
|
||||
Close();
|
||||
}
|
||||
|
||||
|
||||
m_isConnecting = false;
|
||||
reconnect_co = null;
|
||||
|
|
@ -655,14 +689,14 @@ public class SocketClient
|
|||
_LastReconectime = Time.time;
|
||||
|
||||
Debug.Log("****Socket*********************TryReconnect ---" + IpAddress);
|
||||
if (IsConnected())
|
||||
{
|
||||
NetworkStateInfo info = new NetworkStateInfo();
|
||||
info.type = NetworkStateType.Reconnected;
|
||||
info.msg = null;
|
||||
stateInfoStack.Push(info);
|
||||
return;
|
||||
}
|
||||
//if (IsConnected())
|
||||
//{
|
||||
// NetworkStateInfo info = new NetworkStateInfo();
|
||||
// info.type = NetworkStateType.Reconnected;
|
||||
// info.msg = null;
|
||||
// stateInfoStack.Push(info);
|
||||
// return;
|
||||
//}
|
||||
|
||||
|
||||
if (reconnect_co != null)
|
||||
|
|
@ -675,7 +709,9 @@ public class SocketClient
|
|||
public void Reconnect()
|
||||
{
|
||||
Debug.Log("****Socket*********************Reconnect ---" + IpAddress);
|
||||
|
||||
Close();
|
||||
|
||||
try
|
||||
{
|
||||
var ipType = GetIPAddressType(IpAddress);
|
||||
|
|
@ -735,7 +771,7 @@ public class SocketClient
|
|||
|
||||
public void OnReconnectFail()
|
||||
{
|
||||
//Debug.Log("****Socket*********************OnReconnectFail ---" + IpAddress);
|
||||
Debug.Log("****Socket*********************OnReconnectFail ---" + IpAddress);
|
||||
AddStateInfo(NetworkStateType.ReconnectFail, null);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue