コード例 #1
0
void FullyConnectedMesh2::OnRespondConnectionCount(Packet *packet)
{
	RakNet::BitStream bsIn(packet->data,packet->length,false);
	bsIn.IgnoreBytes(sizeof(MessageID));
	unsigned int responseTotalConnectionCount;
	bsIn.Read(responseTotalConnectionCount);
	IncrementTotalConnectionCount(responseTotalConnectionCount);
	bool wasAssigned;
	if (ourFCMGuid==0)
	{
		wasAssigned=true;
		AssignOurFCMGuid();
	}
	else
		wasAssigned=false;

	// 1 is returned to give us lower priority, but the actual minimum is 2
	IncrementTotalConnectionCount(2);

	if (wasAssigned==true)
	{
		DataStructures::DefaultIndexType idx;
		for (idx=0; idx < participantList.Size(); idx++)
			SendOurFCMGuid(rakPeerInterface->GetSystemAddressFromGuid(participantList[idx].rakNetGuid));
		CalculateAndPushHost();
	}
}
コード例 #2
0
void FullyConnectedMesh2::OnRespondFCMGuid(Packet *packet)
{
	RakNet::BitStream bsIn(packet->data,packet->length,false);
	bsIn.IgnoreBytes(sizeof(MessageID));
	unsigned int responseAssignedConnectionCount;
	unsigned int responseTotalConnectionCount;
	bsIn.Read(responseAssignedConnectionCount);
	bsIn.Read(responseTotalConnectionCount);
	if (ourFCMGuid==0)
	{
		AssignOurFCMGuid(responseAssignedConnectionCount);
		guidRequestRetryList.Clear(true,__FILE__,__LINE__);
		// printf("Total connection count updated from %i to %i\n", totalConnectionCount, responseTotalConnectionCount);
		totalConnectionCount=responseTotalConnectionCount;
		if (participantList.Size()!=0)
		{
			CalculateHost(&hostSystemAddress, &hostRakNetGuid, &hostFCM2Guid);
			PushNewHost(hostSystemAddress, hostRakNetGuid);
		}
	}
	SendOurFCMGuid(packet->systemAddress);
	DataStructures::DefaultIndexType idx;
	for (idx=0; idx < participantList.Size(); idx++)
		SendOurFCMGuid(participantList[idx].systemAddress);
}
コード例 #3
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();
}