Esempio n. 1
0
void UDPProxyClient::Update(void)
{
	unsigned int idx1=0;
	while (idx1 < pingServerGroups.Size())
	{
		PingServerGroup *psg = pingServerGroups[idx1];

		if (psg->serversToPing.Size() > 0 && 
			RakNet::GetTimeMS() > psg->startPingTime+DEFAULT_UNRESPONSIVE_PING_TIME_COORDINATOR)
		{
			// If they didn't reply within DEFAULT_UNRESPONSIVE_PING_TIME_COORDINATOR, just give up on them
			psg->SendPingedServersToCoordinator(rakPeerInterface);

			RakNet::OP_DELETE(psg,_FILE_AND_LINE_);
			pingServerGroups.RemoveAtIndex(idx1);
		}
		else
			idx1++;
	}

}
void UDPProxyClient::Update(void)
{
	DataStructures::DefaultIndexType idx1=0;
	while (idx1 < pingServerGroups.GetSize())
	{
		PingServerGroup *psg = pingServerGroups[idx1];

		if (psg->serversToPing.GetSize() > 0 && 
			RakNet::GetTime() > psg->startPingTime+DEFAULT_UNRESPONSIVE_PING_TIME)
		{
			// If they didn't reply within DEFAULT_UNRESPONSIVE_PING_TIME, just give up on them
			psg->SendPingedServersToCoordinator(rakPeerInterface);

			RakNet::OP_DELETE(psg,__FILE__,__LINE__);
			pingServerGroups.RemoveAtIndex(idx1, __FILE__, __LINE__ );
		}
		else
			idx1++;
	}

}
Esempio n. 3
0
PluginReceiveResult UDPProxyClient::OnReceive(Packet *packet)
{
	if (packet->data[0]==ID_UNCONNECTED_PONG)
	{
		unsigned int idx1, idx2;
		PingServerGroup *psg;
		for (idx1=0; idx1 < pingServerGroups.Size(); idx1++)
		{
			psg = pingServerGroups[idx1];
			for (idx2=0; idx2 < psg->serversToPing.Size(); idx2++)
			{
				if (psg->serversToPing[idx2].serverAddress==packet->systemAddress)
				{
					RakNet::BitStream bsIn(packet->data,packet->length,false);
					bsIn.IgnoreBytes(sizeof(MessageID));
					RakNet::TimeMS sentTime;
					bsIn.Read(sentTime);
					RakNet::TimeMS curTime=RakNet::GetTimeMS();
					int ping;
					if (curTime>sentTime)
						ping=(int) (curTime-sentTime);
					else
						ping=0;
					psg->serversToPing[idx2].ping=(unsigned short) ping;

					// If all servers to ping are now pinged, reply to coordinator
					if (psg->AreAllServersPinged())
					{
						psg->SendPingedServersToCoordinator(rakPeerInterface);
						RakNet::OP_DELETE(psg,_FILE_AND_LINE_);
						pingServerGroups.RemoveAtIndex(idx1);
					}

					return RR_STOP_PROCESSING_AND_DEALLOCATE;
				}
			}

		}
	}
	else if (packet->data[0]==ID_UDP_PROXY_GENERAL && packet->length>1)
	{
		switch (packet->data[1])
		{
		case ID_UDP_PROXY_PING_SERVERS_FROM_COORDINATOR_TO_CLIENT:
			{
				OnPingServers(packet);
			}
		break;
		case ID_UDP_PROXY_FORWARDING_SUCCEEDED:
		case ID_UDP_PROXY_ALL_SERVERS_BUSY:
		case ID_UDP_PROXY_IN_PROGRESS:
		case ID_UDP_PROXY_NO_SERVERS_ONLINE:
		case ID_UDP_PROXY_RECIPIENT_GUID_NOT_CONNECTED_TO_COORDINATOR:
		case ID_UDP_PROXY_FORWARDING_NOTIFICATION:
			{
				RakNetGUID targetGuid;
				SystemAddress senderAddress, targetAddress;
				RakNet::BitStream incomingBs(packet->data, packet->length, false);
				incomingBs.IgnoreBytes(sizeof(MessageID)*2);
				incomingBs.Read(senderAddress);
				incomingBs.Read(targetAddress);
				incomingBs.Read(targetGuid);

				switch (packet->data[1])
				{
				case ID_UDP_PROXY_FORWARDING_NOTIFICATION:
				case ID_UDP_PROXY_FORWARDING_SUCCEEDED:
				case ID_UDP_PROXY_IN_PROGRESS:
					{
						unsigned short forwardingPort;
						RakNet::RakString serverIP;
						incomingBs.Read(serverIP);
						incomingBs.Read(forwardingPort);
						if (packet->data[1]==ID_UDP_PROXY_FORWARDING_SUCCEEDED)
						{
							if (resultHandler)
								resultHandler->OnForwardingSuccess(serverIP.C_String(), forwardingPort, packet->systemAddress, senderAddress, targetAddress, targetGuid, this);
						}
						else if (packet->data[1]==ID_UDP_PROXY_IN_PROGRESS)
						{
							if (resultHandler)
								resultHandler->OnForwardingInProgress(serverIP.C_String(), forwardingPort, packet->systemAddress, senderAddress, targetAddress, targetGuid, this);
						}
						else
						{
							// Send a datagram to the proxy, so if we are behind a router, that router adds an entry to the routing table.
							// Otherwise the router would block the incoming datagrams from source
							// It doesn't matter if the message actually arrives as long as it goes through the router
							rakPeerInterface->Ping(serverIP.C_String(), forwardingPort, false);

							if (resultHandler)
								resultHandler->OnForwardingNotification(serverIP.C_String(), forwardingPort, packet->systemAddress, senderAddress, targetAddress, targetGuid, this);
						}
					}
					break;
				case ID_UDP_PROXY_ALL_SERVERS_BUSY:
					if (resultHandler)
						resultHandler->OnAllServersBusy(packet->systemAddress, senderAddress, targetAddress, targetGuid, this);
					break;
				case ID_UDP_PROXY_NO_SERVERS_ONLINE:
					if (resultHandler)
						resultHandler->OnNoServersOnline(packet->systemAddress, senderAddress, targetAddress, targetGuid, this);
					break;
				case ID_UDP_PROXY_RECIPIENT_GUID_NOT_CONNECTED_TO_COORDINATOR:
					{
						if (resultHandler)
							resultHandler->OnRecipientNotConnected(packet->systemAddress, senderAddress, targetAddress, targetGuid, this);
						break;
					}
				}
			
			}
			return RR_STOP_PROCESSING_AND_DEALLOCATE;
		}
	}
	return RR_CONTINUE_PROCESSING;
}