LUA 中校验被提出的合理检查
parent
3819ed162a
commit
18642e01ae
|
@ -231,7 +231,7 @@ public class SocketClient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int _NNN;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 读取消息
|
/// 读取消息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -240,11 +240,18 @@ public class SocketClient
|
||||||
int bytesRead = 0;
|
int bytesRead = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
//System.Net.Sockets.Socket.SocketAsyncResult
|
||||||
//NetBug.Fix by FHF..
|
//NetBug.Fix by FHF..
|
||||||
//甄别socket当前是否正在连接中,避免重连的间隔内收到服务端消息。.
|
//甄别socket当前是否正在连接中,避免重连的间隔内收到服务端消息。.
|
||||||
if (client == null || !client.Connected)
|
if (client == null || !client.Connected)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
//int ilen = client.GetStream().EndRead(asr);
|
||||||
|
// Debug.Log("[SocketClient] From Socket: EndRead.Len:" + ilen);
|
||||||
|
|
||||||
|
|
||||||
lock (client.GetStream())
|
lock (client.GetStream())
|
||||||
{
|
{
|
||||||
//读取字节流到缓冲区
|
//读取字节流到缓冲区
|
||||||
|
@ -257,6 +264,8 @@ public class SocketClient
|
||||||
AddStateInfo(NetworkStateType.Disconnect, "bytesRead < 1");
|
AddStateInfo(NetworkStateType.Disconnect, "bytesRead < 1");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Debug.Log("[SocketClient] NowClient:@" + ++_NNN+" _:"+bytesRead + ":" + client.Client.Handle);
|
||||||
|
|
||||||
OnReceive(byteBuffer, bytesRead); //分析数据包内容,抛给逻辑层
|
OnReceive(byteBuffer, bytesRead); //分析数据包内容,抛给逻辑层
|
||||||
lock (client.GetStream())
|
lock (client.GetStream())
|
||||||
{
|
{
|
||||||
|
@ -264,8 +273,8 @@ public class SocketClient
|
||||||
Array.Clear(byteBuffer, 0, byteBuffer.Length); //清空数组
|
Array.Clear(byteBuffer, 0, byteBuffer.Length); //清空数组
|
||||||
client.GetStream().BeginRead(byteBuffer, 0, MAX_READ, new AsyncCallback(OnRead), null);
|
client.GetStream().BeginRead(byteBuffer, 0, MAX_READ, new AsyncCallback(OnRead), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Log("SocketClient.OnRead " + byteBuffer.ToString());
|
//Debug.Log("SocketClient.OnRead " + byteBuffer.ToString());
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -427,18 +436,31 @@ public class SocketClient
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Close()
|
public void Close()
|
||||||
{
|
{
|
||||||
Debug.Log("****Socket*********************Close ---" + IpAddress);
|
|
||||||
//确保 关闭Client的链接状态。
|
//确保 关闭Client的链接状态。
|
||||||
UnregistNetMessage(INDICATION_ERROR_CODE, Ygqmgx_indicationErrorAction);
|
UnregistNetMessage(INDICATION_ERROR_CODE, Ygqmgx_indicationErrorAction);
|
||||||
if (client != null)
|
if (client != null)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
client.Client.Disconnect(false);
|
||||||
|
Debug.Log("****Socket*********************Disconnect() ---" + client.Client.Handle+ "@"+ client.Client.LocalEndPoint.ToString());
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
|
Debug.Log("****Socket*********************Close ---" + client.Client.Handle);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
client.Close();
|
client.Close();
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
client = null;
|
client = null;
|
||||||
|
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -719,6 +741,7 @@ public class SocketClient
|
||||||
var ipType = GetIPAddressType(IpAddress);
|
var ipType = GetIPAddressType(IpAddress);
|
||||||
client = null;
|
client = null;
|
||||||
client = new TcpClient(ipType);
|
client = new TcpClient(ipType);
|
||||||
|
Debug.Log("****Socket*********************NEW ---" + client.Client.Handle);
|
||||||
//client.SendTimeout = 1000;
|
//client.SendTimeout = 1000;
|
||||||
//client.ReceiveTimeout = 1000;
|
//client.ReceiveTimeout = 1000;
|
||||||
client.NoDelay = true;
|
client.NoDelay = true;
|
||||||
|
@ -797,7 +820,7 @@ public class SocketClient
|
||||||
outStream = client.GetStream();
|
outStream = client.GetStream();
|
||||||
client.GetStream().BeginRead(byteBuffer, 0, MAX_READ, new AsyncCallback(OnRead), null);
|
client.GetStream().BeginRead(byteBuffer, 0, MAX_READ, new AsyncCallback(OnRead), null);
|
||||||
AddStateInfo(NetworkStateType.Reconnected, null);
|
AddStateInfo(NetworkStateType.Reconnected, null);
|
||||||
Debug.Log("****Socket*********************OnReconnect SUCCESS ---" + IpAddress);
|
Debug.Log("****Socket*********************OnReconnect SUCCESS @"+ client.Client.LocalEndPoint.ToString());
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,6 +27,8 @@ function Network.New(type, socket)
|
||||||
instance.re_sendWaitTime = 0 --记录断线等待时间(秒)
|
instance.re_sendWaitTime = 0 --记录断线等待时间(秒)
|
||||||
instance.re_maxSendWaitTime = 5 --消息断线重发等待时间(秒),超过该时间会重连
|
instance.re_maxSendWaitTime = 5 --消息断线重发等待时间(秒),超过该时间会重连
|
||||||
|
|
||||||
|
instance.ReconnectTime=0 -- 重连的发生时间
|
||||||
|
|
||||||
setmetatable(instance, Network)
|
setmetatable(instance, Network)
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
|
@ -66,6 +68,7 @@ function Network:OnDisconnect(err)
|
||||||
|
|
||||||
RequestPanel.Show("您已掉线,正在请求重连")--..err)
|
RequestPanel.Show("您已掉线,正在请求重连")--..err)
|
||||||
self.socket:TryReconnect()
|
self.socket:TryReconnect()
|
||||||
|
self.ReconnectTime= Time.time
|
||||||
end
|
end
|
||||||
|
|
||||||
function Network:SendClientHeartBeat()
|
function Network:SendClientHeartBeat()
|
||||||
|
@ -231,6 +234,10 @@ function Network:ReceiveErrorInfo(buffer)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if msg.errCode == -101 or msg.errCode == -102 then
|
if msg.errCode == -101 or msg.errCode == -102 then
|
||||||
|
|
||||||
|
if(Time.time- self.ReconnectTime<10)then
|
||||||
|
return
|
||||||
|
end
|
||||||
--被顶号或者被封号
|
--被顶号或者被封号
|
||||||
Game.Logout()
|
Game.Logout()
|
||||||
AppConst.Code = msg.errMsg --TODO:重登会重置所有lua变量信息,用一个不用的C#变量记录,用于记录异常退出信息
|
AppConst.Code = msg.errMsg --TODO:重登会重置所有lua变量信息,用一个不用的C#变量记录,用于记录异常退出信息
|
||||||
|
|
Loading…
Reference in New Issue