void FullyConnectedMesh2::SendFCMGuidRequest(SystemAddress addr)
{
#ifdef DEBUG_FCM2
	printf("SendFCMGuidRequest to %s. guid=%s.\n", addr.ToString(), rakPeerInterface->GetGuidFromSystemAddress(addr).ToString());
#endif

	RakNet::BitStream bsOut;
	bsOut.Write((MessageID)ID_FCM2_REQUEST_FCMGUID);
	bsOut.Write(GetElapsedRuntime());
	rakPeerInterface->Send(&bsOut,HIGH_PRIORITY,RELIABLE_ORDERED,0,addr,false);
}
Exemplo n.º 2
0
void FullyConnectedMesh2::SendFCMGuidRequest(RakNetGUID rakNetGuid)
{
	if (rakNetGuid==rakPeerInterface->GetGuidFromSystemAddress(UNASSIGNED_SYSTEM_ADDRESS))
		return;

	RakNet::BitStream bsOut;
	bsOut.Write((MessageID)ID_FCM2_REQUEST_FCMGUID);
	if (ourFCMGuid==0)
	{
		bsOut.Write(false);
		bsOut.Write(GetElapsedRuntime());
	}
	else
	{
		bsOut.Write(true);
		bsOut.Write(totalConnectionCount);
		bsOut.Write(ourFCMGuid);
	}
 	rakPeerInterface->Send(&bsOut,HIGH_PRIORITY,RELIABLE_ORDERED,0,rakNetGuid,false);
}
void FullyConnectedMesh2::OnRequestFCMGuid(Packet *packet)
{
	RakNet::BitStream bsIn(packet->data,packet->length,false);
	bsIn.IgnoreBytes(sizeof(MessageID));

	// Only the host says who is host
	if (ourFCMGuid!=0 && IsHostSystem()==false)
	{
		return;
	}

	RakNetTimeUS senderElapsedRuntime;
	if (ourFCMGuid==0)
	{
		bsIn.Read(senderElapsedRuntime);
		RakNetTimeUS ourElapsedRuntime = GetElapsedRuntime();

		// TODO: BUG: Multiple simultaneous connections can create a subnet. Don't respond to this until all systems answer.
		// Even if both systems disagree on who is host by time, the problem is avoid because of the random number for the low 4 bytes of FCM2Guid
		if (ourElapsedRuntime>senderElapsedRuntime)
		{
			// We are probably host
			// 2 is for 2 total connections
			// Their total connection count is one higher, so their FCM2Guid has a lower priority than ours
			SendFCMGuidResponse(packet->systemAddress, totalConnectionCount+1, 2);
		}
		else
		{
			// They are probably host
			SendFCMGuidResponse(packet->systemAddress, totalConnectionCount, 2);
		}
	}
	else
	{
		// totalConnectionCount is set to the value of 2 passed to SendFCMGuidResponse when our own guid is first assigned
		// We are host here
		RakAssert(totalConnectionCount!=0);
		SendFCMGuidResponse(packet->systemAddress, totalConnectionCount+1, totalConnectionCount+1);
	}
}
Exemplo n.º 4
0
void FullyConnectedMesh2::OnRequestFCMGuid(Packet *packet)
{
	RakNet::BitStream bsIn(packet->data,packet->length,false);
	bsIn.IgnoreBytes(sizeof(MessageID));
	bool hasRemoteFCMGuid;
	bsIn.Read(hasRemoteFCMGuid);
	RakNetTimeUS senderElapsedRuntime=0;
	unsigned int remoteTotalConnectionCount=0;
	FCM2Guid theirFCMGuid=0;
	if (hasRemoteFCMGuid)
	{
		bsIn.Read(remoteTotalConnectionCount);
		bsIn.Read(theirFCMGuid);
	}
	else
	{
		bsIn.Read(senderElapsedRuntime);
	}
	AddParticipantInternal(packet->guid,theirFCMGuid);
	if (ourFCMGuid==0)
	{
		if (hasRemoteFCMGuid==false)
		{
			// Nobody has a fcmGuid

			RakNetTimeUS ourElapsedRuntime = GetElapsedRuntime();
			if (ourElapsedRuntime>senderElapsedRuntime)
			{
				// We are probably host
				SendConnectionCountResponse(packet->systemAddress, 2);
			}
			else
			{
				// They are probably host
				SendConnectionCountResponse(packet->systemAddress, 1);
			}
		}
		else
		{
			// They have a fcmGuid, we do not

			IncrementTotalConnectionCount(remoteTotalConnectionCount+1);

			AssignOurFCMGuid();
			DataStructures::DefaultIndexType idx;
			for (idx=0; idx < participantList.Size(); idx++)
				SendOurFCMGuid(rakPeerInterface->GetSystemAddressFromGuid(participantList[idx].rakNetGuid));
		}
	}
	else
	{
		if (hasRemoteFCMGuid==false)
		{
			// We have a fcmGuid they do not

			SendConnectionCountResponse(packet->systemAddress, totalConnectionCount+1);

		}
		else
		{
			// We both have fcmGuids

			IncrementTotalConnectionCount(remoteTotalConnectionCount);

			SendOurFCMGuid(packet->systemAddress);
		}
	}
	CalculateAndPushHost();
}