本文整理汇总了C#中Lidgren.Network.NetConnection.ReceivedHandshake方法的典型用法代码示例。如果您正苦于以下问题:C# NetConnection.ReceivedHandshake方法的具体用法?C# NetConnection.ReceivedHandshake怎么用?C# NetConnection.ReceivedHandshake使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetConnection
的用法示例。
在下文中一共展示了NetConnection.ReceivedHandshake方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReceivedUnconnectedLibraryMessage
private void ReceivedUnconnectedLibraryMessage(double now, IPEndPoint senderEndpoint, NetMessageType tp, int ptr, int payloadByteLength)
{
NetConnection shake;
if (m_handshakes.TryGetValue(senderEndpoint, out shake))
{
shake.ReceivedHandshake(now, tp, ptr, payloadByteLength);
return;
}
//
// Library message from a completely unknown sender; lets just accept Connect
//
switch (tp)
{
case NetMessageType.Discovery:
if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.DiscoveryRequest))
{
NetIncomingMessage dm = CreateIncomingMessage(NetIncomingMessageType.DiscoveryRequest, payloadByteLength);
if (payloadByteLength > 0)
Buffer.BlockCopy(m_receiveBuffer, ptr, dm.m_data, 0, payloadByteLength);
dm.m_receiveTime = now;
dm.m_bitLength = payloadByteLength * 8;
dm.m_senderEndpoint = senderEndpoint;
ReleaseMessage(dm);
}
return;
case NetMessageType.DiscoveryResponse:
if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.DiscoveryResponse))
{
NetIncomingMessage dr = CreateIncomingMessage(NetIncomingMessageType.DiscoveryResponse, payloadByteLength);
if (payloadByteLength > 0)
Buffer.BlockCopy(m_receiveBuffer, ptr, dr.m_data, 0, payloadByteLength);
dr.m_receiveTime = now;
dr.m_bitLength = payloadByteLength * 8;
dr.m_senderEndpoint = senderEndpoint;
ReleaseMessage(dr);
}
return;
case NetMessageType.NatIntroduction:
HandleNatIntroduction(ptr);
return;
case NetMessageType.NatPunchMessage:
HandleNatPunch(ptr, senderEndpoint);
return;
case NetMessageType.Connect:
// proceed
break;
case NetMessageType.Disconnect:
// this is probably ok
LogVerbose("Received Disconnect from unconnected source: " + senderEndpoint);
return;
default:
LogWarning("Received unhandled library message " + tp + " from " + senderEndpoint);
return;
}
// It's someone wanting to shake hands with us!
int reservedSlots = m_handshakes.Count + m_connections.Count;
if (reservedSlots >= m_configuration.m_maximumConnections)
{
// server full
NetOutgoingMessage full = CreateMessage("Server full");
full.m_messageType = NetMessageType.Disconnect;
SendLibrary(full, senderEndpoint);
return;
}
// Ok, start handshake!
NetConnection conn = new NetConnection(this, senderEndpoint);
m_handshakes.Add(senderEndpoint, conn);
conn.ReceivedHandshake(now, tp, ptr, payloadByteLength);
return;
}
示例2: ReceivedUnconnectedLibraryMessage
private void ReceivedUnconnectedLibraryMessage(double now, IPEndPoint senderEndpoint, NetMessageType tp, int ptr, int payloadByteLength)
{
NetConnection shake;
if (m_handshakes.TryGetValue(senderEndpoint, out shake))
{
shake.ReceivedHandshake(now, tp, ptr, payloadByteLength);
return;
}
//
// Library message from a completely unknown sender; lets just accept Connect
//
switch (tp)
{
case NetMessageType.Discovery:
HandleIncomingDiscoveryRequest(now, senderEndpoint, ptr, payloadByteLength);
return;
case NetMessageType.DiscoveryResponse:
HandleIncomingDiscoveryResponse(now, senderEndpoint, ptr, payloadByteLength);
return;
case NetMessageType.NatIntroduction:
HandleNatIntroduction(ptr);
return;
case NetMessageType.NatPunchMessage:
HandleNatPunch(ptr, senderEndpoint);
return;
case NetMessageType.ConnectResponse:
lock (m_handshakes)
{
foreach (var hs in m_handshakes)
{
if (hs.Key.Address.Equals(senderEndpoint.Address))
{
if (hs.Value.m_connectionInitiator)
{
//
// We are currently trying to connection to XX.XX.XX.XX:Y
// ... but we just received a ConnectResponse from XX.XX.XX.XX:Z
// Lets just assume the router decided to use this port instead
//
var hsconn = hs.Value;
m_connectionLookup.Remove(hs.Key);
m_handshakes.Remove(hs.Key);
LogDebug("Detected host port change; rerouting connection to " + senderEndpoint);
hsconn.MutateEndpoint(senderEndpoint);
m_connectionLookup.Add(senderEndpoint, hsconn);
m_handshakes.Add(senderEndpoint, hsconn);
hsconn.ReceivedHandshake(now, tp, ptr, payloadByteLength);
return;
}
}
}
}
LogWarning("Received unhandled library message " + tp + " from " + senderEndpoint);
return;
case NetMessageType.Connect:
// proceed
break;
case NetMessageType.Disconnect:
// this is probably ok
LogVerbose("Received Disconnect from unconnected source: " + senderEndpoint);
return;
default:
LogWarning("Received unhandled library message " + tp + " from " + senderEndpoint);
return;
}
// It's someone wanting to shake hands with us!
int reservedSlots = m_handshakes.Count + m_connections.Count;
if (reservedSlots >= m_configuration.m_maximumConnections)
{
// server full
NetOutgoingMessage full = CreateMessage("Server full");
full.m_messageType = NetMessageType.Disconnect;
SendLibrary(full, senderEndpoint);
return;
}
// Ok, start handshake!
NetConnection conn = new NetConnection(this, senderEndpoint);
m_handshakes.Add(senderEndpoint, conn);
conn.ReceivedHandshake(now, tp, ptr, payloadByteLength);
return;
}