You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-17 15:46:33 +09:00
Added fix for delayed Approval
This commit is contained in:
@@ -76,11 +76,12 @@ namespace Lidgren.Network
|
|||||||
SendConnectResponse(now, true);
|
SendConnectResponse(now, true);
|
||||||
break;
|
break;
|
||||||
case NetConnectionStatus.None:
|
case NetConnectionStatus.None:
|
||||||
if (m_peerConfiguration.IsMessageTypeEnabled(NetIncomingMessageType.ConnectionApproval))
|
|
||||||
break; // we're probably waiting for connection approval here
|
|
||||||
m_peer.LogWarning("Time to resend handshake, but status is " + m_status);
|
m_peer.LogWarning("Time to resend handshake, but status is " + m_status);
|
||||||
break;
|
break;
|
||||||
|
case NetConnectionStatus.RespondedAwaitingApproval:
|
||||||
|
// awaiting approval
|
||||||
|
m_lastHandshakeSendTime = now; // postpone handshake resend
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
m_peer.LogWarning("Time to resend handshake, but status is " + m_status);
|
m_peer.LogWarning("Time to resend handshake, but status is " + m_status);
|
||||||
break;
|
break;
|
||||||
@@ -212,6 +213,12 @@ namespace Lidgren.Network
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void Approve()
|
public void Approve()
|
||||||
{
|
{
|
||||||
|
if (m_status != NetConnectionStatus.RespondedAwaitingApproval)
|
||||||
|
{
|
||||||
|
m_peer.LogWarning("Approve() called in wrong status; expected RespondedAwaitingApproval; got " + m_status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_localHailMessage = null;
|
m_localHailMessage = null;
|
||||||
m_handshakeAttempts = 0;
|
m_handshakeAttempts = 0;
|
||||||
SendConnectResponse((float)NetTime.Now, false);
|
SendConnectResponse((float)NetTime.Now, false);
|
||||||
@@ -223,6 +230,12 @@ namespace Lidgren.Network
|
|||||||
/// <param name="localHail">The local hail message that will be set as RemoteHailMessage on the remote host</param>
|
/// <param name="localHail">The local hail message that will be set as RemoteHailMessage on the remote host</param>
|
||||||
public void Approve(NetOutgoingMessage localHail)
|
public void Approve(NetOutgoingMessage localHail)
|
||||||
{
|
{
|
||||||
|
if (m_status != NetConnectionStatus.RespondedAwaitingApproval)
|
||||||
|
{
|
||||||
|
m_peer.LogWarning("Approve() called in wrong status; expected RespondedAwaitingApproval; got " + m_status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_localHailMessage = localHail;
|
m_localHailMessage = localHail;
|
||||||
m_handshakeAttempts = 0;
|
m_handshakeAttempts = 0;
|
||||||
SendConnectResponse((float)NetTime.Now, false);
|
SendConnectResponse((float)NetTime.Now, false);
|
||||||
@@ -283,6 +296,7 @@ namespace Lidgren.Network
|
|||||||
if (m_remoteHailMessage != null)
|
if (m_remoteHailMessage != null)
|
||||||
appMsg.Write(m_remoteHailMessage.m_data, 0, m_remoteHailMessage.LengthBytes);
|
appMsg.Write(m_remoteHailMessage.m_data, 0, m_remoteHailMessage.LengthBytes);
|
||||||
m_peer.ReleaseMessage(appMsg);
|
m_peer.ReleaseMessage(appMsg);
|
||||||
|
SetStatus(NetConnectionStatus.RespondedAwaitingApproval, "Awaiting approval");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,6 +304,11 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (m_status == NetConnectionStatus.RespondedAwaitingApproval)
|
||||||
|
{
|
||||||
|
m_peer.LogWarning("Ignoring multiple Connect() most likely due to a delayed Approval");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (m_status == NetConnectionStatus.RespondedConnect)
|
if (m_status == NetConnectionStatus.RespondedConnect)
|
||||||
{
|
{
|
||||||
// our ConnectResponse must have been lost
|
// our ConnectResponse must have been lost
|
||||||
|
|||||||
@@ -35,6 +35,11 @@ namespace Lidgren.Network
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
InitiatedConnect,
|
InitiatedConnect,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Connect was received and ApprovalMessage released to the application; awaiting Approve() or Deny()
|
||||||
|
/// </summary>
|
||||||
|
RespondedAwaitingApproval, // We got Connect, released ApprovalMessage
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Connect was received and ConnectResponse has been sent; waiting for ConnectionEstablished
|
/// Connect was received and ConnectResponse has been sent; waiting for ConnectionEstablished
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace Lidgren.Network
|
|||||||
//
|
//
|
||||||
// excellent, right on time
|
// excellent, right on time
|
||||||
//
|
//
|
||||||
m_peer.LogVerbose("Received RIGHT-ON-TIME " + message);
|
//m_peer.LogVerbose("Received RIGHT-ON-TIME " + message);
|
||||||
|
|
||||||
AdvanceWindow();
|
AdvanceWindow();
|
||||||
m_peer.ReleaseMessage(message);
|
m_peer.ReleaseMessage(message);
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace Lidgren.Network
|
|||||||
//
|
//
|
||||||
// excellent, right on time
|
// excellent, right on time
|
||||||
//
|
//
|
||||||
m_peer.LogVerbose("Received RIGHT-ON-TIME " + message);
|
//m_peer.LogVerbose("Received RIGHT-ON-TIME " + message);
|
||||||
|
|
||||||
AdvanceWindow();
|
AdvanceWindow();
|
||||||
m_peer.ReleaseMessage(message);
|
m_peer.ReleaseMessage(message);
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ namespace ImageClient
|
|||||||
|
|
||||||
NetPeerConfiguration config = copyConfig.Clone();
|
NetPeerConfiguration config = copyConfig.Clone();
|
||||||
config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
|
config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
|
||||||
|
config.EnableMessageType(NetIncomingMessageType.DebugMessage);
|
||||||
m_readList = new List<NetIncomingMessage>();
|
m_readList = new List<NetIncomingMessage>();
|
||||||
|
|
||||||
Client = new NetClient(config);
|
Client = new NetClient(config);
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ namespace ImageServer
|
|||||||
NetPeerConfiguration config = new NetPeerConfiguration("ImageTransfer");
|
NetPeerConfiguration config = new NetPeerConfiguration("ImageTransfer");
|
||||||
config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
|
config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
|
||||||
config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
|
config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
|
||||||
|
config.EnableMessageType(NetIncomingMessageType.DebugMessage);
|
||||||
config.AutoExpandMTU = true;
|
config.AutoExpandMTU = true;
|
||||||
|
|
||||||
// listen on port 14242
|
// listen on port 14242
|
||||||
@@ -33,9 +34,6 @@ namespace ImageServer
|
|||||||
|
|
||||||
Server = new NetServer(config);
|
Server = new NetServer(config);
|
||||||
|
|
||||||
System.IO.File.Delete("C:\\tmp\\clientlog.txt");
|
|
||||||
System.IO.File.Delete("C:\\tmp\\serverlog.txt");
|
|
||||||
|
|
||||||
Application.Idle += new EventHandler(AppLoop);
|
Application.Idle += new EventHandler(AppLoop);
|
||||||
Application.Run(MainForm);
|
Application.Run(MainForm);
|
||||||
}
|
}
|
||||||
@@ -58,7 +56,6 @@ namespace ImageServer
|
|||||||
// just print any message
|
// just print any message
|
||||||
string str = inc.ReadString();
|
string str = inc.ReadString();
|
||||||
NativeMethods.AppendText(MainForm.richTextBox1, str);
|
NativeMethods.AppendText(MainForm.richTextBox1, str);
|
||||||
//System.IO.File.AppendAllText("C:\\tmp\\serverlog.txt", str + Environment.NewLine);
|
|
||||||
break;
|
break;
|
||||||
case NetIncomingMessageType.DiscoveryRequest:
|
case NetIncomingMessageType.DiscoveryRequest:
|
||||||
NetOutgoingMessage dom = Server.CreateMessage();
|
NetOutgoingMessage dom = Server.CreateMessage();
|
||||||
@@ -110,13 +107,14 @@ namespace ImageServer
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//
|
||||||
|
// A client connected; send the entire image in one very large message that will be fragmented automatically by the library
|
||||||
|
//
|
||||||
NetOutgoingMessage om = Server.CreateMessage(ImageData.Length + 5);
|
NetOutgoingMessage om = Server.CreateMessage(ImageData.Length + 5);
|
||||||
|
|
||||||
om.Write((ushort)ImageWidth);
|
om.Write((ushort)ImageWidth);
|
||||||
om.Write((ushort)ImageHeight);
|
om.Write((ushort)ImageHeight);
|
||||||
om.WriteVariableUInt32(0);
|
om.WriteVariableUInt32(0);
|
||||||
|
|
||||||
// send entire as a large message that will be automatically fragmented by the library
|
|
||||||
om.Write(ImageData);
|
om.Write(ImageData);
|
||||||
|
|
||||||
Server.SendMessage(om, inc.SenderConnection, NetDeliveryMethod.ReliableOrdered, 0);
|
Server.SendMessage(om, inc.SenderConnection, NetDeliveryMethod.ReliableOrdered, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user