1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#include "LoopbackConnection.h"
#include "Net/Protocol/NetMessageTypes.h"
namespace netcode {
void CLoopbackConnection::SendData(std::shared_ptr<const RawPacket> pkt) {
numPings += (pkt->data[0] == NETMSG_PING);
pktQueue.push_back(pkt);
}
std::shared_ptr<const RawPacket> CLoopbackConnection::Peek(unsigned ahead) const {
if (ahead >= pktQueue.size())
return {};
return pktQueue[ahead];
}
void CLoopbackConnection::DeleteBufferPacketAt(unsigned index) {
if (index >= pktQueue.size())
return;
numPings -= (pktQueue[index]->data[0] == NETMSG_PING);
pktQueue.erase(pktQueue.begin() + index);
}
std::shared_ptr<const RawPacket> CLoopbackConnection::GetData() {
if (pktQueue.empty())
return {};
numPings -= (pktQueue[0]->data[0] == NETMSG_PING);
std::shared_ptr<const RawPacket> next = pktQueue.front();
pktQueue.pop_front();
return next;
}
} // namespace netcode
|