1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-14 14:16:30 +09:00

Added fix for delayed Approval

This commit is contained in:
lidgren
2011-09-19 17:31:23 +00:00
parent e37430a219
commit 9e3104f5da
6 changed files with 34 additions and 11 deletions

View File

@@ -76,11 +76,12 @@ namespace Lidgren.Network
SendConnectResponse(now, true);
break;
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);
break;
case NetConnectionStatus.RespondedAwaitingApproval:
// awaiting approval
m_lastHandshakeSendTime = now; // postpone handshake resend
break;
default:
m_peer.LogWarning("Time to resend handshake, but status is " + m_status);
break;
@@ -212,6 +213,12 @@ namespace Lidgren.Network
/// </summary>
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_handshakeAttempts = 0;
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>
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_handshakeAttempts = 0;
SendConnectResponse((float)NetTime.Now, false);
@@ -283,6 +296,7 @@ namespace Lidgren.Network
if (m_remoteHailMessage != null)
appMsg.Write(m_remoteHailMessage.m_data, 0, m_remoteHailMessage.LengthBytes);
m_peer.ReleaseMessage(appMsg);
SetStatus(NetConnectionStatus.RespondedAwaitingApproval, "Awaiting approval");
return;
}
@@ -290,6 +304,11 @@ namespace Lidgren.Network
}
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)
{
// our ConnectResponse must have been lost

View File

@@ -35,6 +35,11 @@ namespace Lidgren.Network
/// </summary>
InitiatedConnect,
/// <summary>
/// Connect was received and ApprovalMessage released to the application; awaiting Approve() or Deny()
/// </summary>
RespondedAwaitingApproval, // We got Connect, released ApprovalMessage
/// <summary>
/// Connect was received and ConnectResponse has been sent; waiting for ConnectionEstablished
/// </summary>

View File

@@ -37,7 +37,7 @@ namespace Lidgren.Network
//
// excellent, right on time
//
m_peer.LogVerbose("Received RIGHT-ON-TIME " + message);
//m_peer.LogVerbose("Received RIGHT-ON-TIME " + message);
AdvanceWindow();
m_peer.ReleaseMessage(message);

View File

@@ -35,7 +35,7 @@ namespace Lidgren.Network
//
// excellent, right on time
//
m_peer.LogVerbose("Received RIGHT-ON-TIME " + message);
//m_peer.LogVerbose("Received RIGHT-ON-TIME " + message);
AdvanceWindow();
m_peer.ReleaseMessage(message);

View File

@@ -26,6 +26,7 @@ namespace ImageClient
NetPeerConfiguration config = copyConfig.Clone();
config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
config.EnableMessageType(NetIncomingMessageType.DebugMessage);
m_readList = new List<NetIncomingMessage>();
Client = new NetClient(config);

View File

@@ -26,6 +26,7 @@ namespace ImageServer
NetPeerConfiguration config = new NetPeerConfiguration("ImageTransfer");
config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
config.EnableMessageType(NetIncomingMessageType.DebugMessage);
config.AutoExpandMTU = true;
// listen on port 14242
@@ -33,9 +34,6 @@ namespace ImageServer
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.Run(MainForm);
}
@@ -58,7 +56,6 @@ namespace ImageServer
// just print any message
string str = inc.ReadString();
NativeMethods.AppendText(MainForm.richTextBox1, str);
//System.IO.File.AppendAllText("C:\\tmp\\serverlog.txt", str + Environment.NewLine);
break;
case NetIncomingMessageType.DiscoveryRequest:
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);
om.Write((ushort)ImageWidth);
om.Write((ushort)ImageHeight);
om.WriteVariableUInt32(0);
// send entire as a large message that will be automatically fragmented by the library
om.Write(ImageData);
Server.SendMessage(om, inc.SenderConnection, NetDeliveryMethod.ReliableOrdered, 0);