SQCSimulator2023/SQCSim-srv/connection.cpp

57 lines
1.2 KiB
C++
Raw Normal View History

2023-09-24 08:45:40 -04:00
#include "connection.h"
Connection::Connection(in_addr addr,
std::string name,
2023-09-25 08:23:52 -04:00
uint64_t id,
uint64_t self_id,
uint64_t team_id):
2023-09-24 08:45:40 -04:00
m_addr(addr),
2023-09-24 11:07:03 -04:00
m_id(id),
m_sid(self_id),
m_tid(team_id),
2023-09-24 08:45:40 -04:00
m_name(name) {
}
Connection::~Connection() {
}
in_addr Connection::GetAddr() const { return m_addr; }
2023-09-25 08:23:52 -04:00
uint64_t Connection::GetHash(bool self) const { return self? m_sid: m_id; }
2023-09-24 08:45:40 -04:00
2023-09-25 08:23:52 -04:00
uint64_t Connection::GetTeamHash() const { return m_tid; }
2023-09-24 08:45:40 -04:00
std::string Connection::GetName() const { return m_name; }
2023-09-25 16:30:03 -04:00
void Connection::AddInput(netprot::Input in) {
m_input_manifest.insert({ in.timestamp, in });
2023-09-24 11:07:03 -04:00
}
2023-09-25 16:30:03 -04:00
netprot::Output* Connection::getOutput(Timestamp time) {
2023-09-24 11:07:03 -04:00
auto out = m_output_manifest.find(time);
if (out != m_output_manifest.end())
return &out->second;
return nullptr;
}
2023-09-25 16:30:03 -04:00
netprot::Sync Connection::getSync(Timestamp time) {
netprot::Sync sync;
2023-09-24 11:07:03 -04:00
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_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--);
2023-09-24 08:45:40 -04:00
}