/*
 * Called when a packet with the opcode XPT_OPC_S_PING is received
 */
bool xptClient_processPacket_ping(xptClient_t* xptClient)
{
	xptPacketbuffer_t* cpb = xptClient->recvBuffer;
	// read data from the packet
	xptPacketbuffer_beginReadPacket(cpb);
	// start parsing
	bool readError = false;
	// read timestamp
	uint64 timestamp = xptPacketbuffer_readU64(cpb, &readError);
	if( readError )
		return false;
	// get current high precision time and frequency
	LARGE_INTEGER hpc;
	LARGE_INTEGER hpcFreq;
	QueryPerformanceCounter(&hpc);
	QueryPerformanceFrequency(&hpcFreq);
	uint64 timestampNow = (uint64)hpc.QuadPart;
	// calculate time difference in ms
	uint64 timeDif = timestampNow - timestamp;
	timeDif *= 10000ULL;
	timeDif /= (uint64)hpcFreq.QuadPart;
	// update and calculate simple average
	xptClient->pingSum += timeDif;
	xptClient->pingCount++;
	double averagePing = (double)xptClient->pingSum / (double)xptClient->pingCount / 10.0;
	printf("Ping %d.%dms (Average %.1lf)\n", (sint32)(timeDif/10), (sint32)(timeDif%10), averagePing);
	return true;
}
/*
 * Called when a packet with the opcode XPT_OPC_S_PING is received
 */
bool xptClient_processPacket_ping(xptClient_t* xptClient)
{
    xptPacketbuffer_t* cpb = xptClient->recvBuffer;
    // read data from the packet
    xptPacketbuffer_beginReadPacket(cpb);
    // start parsing
    bool readError = false;
    // read timestamp
    uint64 timestamp = xptPacketbuffer_readU64(cpb, &readError);
    if( readError )
        return false;
    // get current high precision time and frequency
    uint64 timestampNow = getTimeHighRes();
    // calculate time difference in ms
    uint64 timeDif = timestampNow - timestamp;
#ifdef _WIN32
    timeDif *= 10000ULL;
    timeDif /= getTimerRes();
#else
    timeDif /= 100000;
#endif
    // update and calculate simple average
    xptClient->pingSum += timeDif;
    xptClient->pingCount++;
    double averagePing = (double)xptClient->pingSum / (double)xptClient->pingCount / 10.0;
    printf("Ping %d.%dms (Average %.1lf)\n", (sint32)(timeDif/10), (sint32)(timeDif%10), averagePing);
    return true;
}