SQCSimulator2023/SQCSim-srv/connection.cpp
2023-09-27 17:34:25 -04:00

55 lines
1.2 KiB
C++

#include "connection.h"
Connection::Connection(SOCKET sock,
sockaddr_in sockaddr,
netprot::LoginInfo log,
netprot::PlayerInfo play):
m_sock(sock),
m_addr(sockaddr),
m_loginfo(log),
m_playinfo(play) {
}
Connection::~Connection() {
closesocket(m_sock);
}
uint64_t Connection::GetHash(bool self) const { return self? m_loginfo.sid: m_playinfo.id; }
uint64_t Connection::GetTeamHash() const { return m_loginfo.tid; }
std::string Connection::GetName() const { return m_loginfo.name; }
void Connection::AddInput(netprot::Input in) {
m_input_manifest.insert({ in.timestamp, in });
}
netprot::Output* Connection::getOutput(Timestamp time) {
auto out = m_output_manifest.find(time);
if (out != m_output_manifest.end())
return &out->second;
return nullptr;
}
netprot::Sync Connection::getSync(Timestamp time) {
netprot::Sync sync;
auto out = m_output_manifest.find(time);
if (out != m_output_manifest.end()) {
sync.timestamp = out->second.timestamp;
sync.position = out->second.position;
sync.sid = m_loginfo.sid;
}
return sync;
}
void Connection::CleanInputManifest(Timestamp time) {
auto wat = m_input_manifest.find(time);
while (wat != m_input_manifest.begin())
m_input_manifest.erase(wat--);
}