SQCSimulator2023/SQCSim-srv/connection.cpp

56 lines
1.4 KiB
C++
Raw Normal View History

2023-09-24 08:45:40 -04:00
#include "connection.h"
Connection::Connection(SOCKET sock,
sockaddr_in sockaddr,
2023-10-25 12:16:14 -04:00
LoginInfo log,
PlayerInfo play):
m_sock(sock),
m_addr(sockaddr),
m_loginfo(log),
m_playinfo(play) {
2023-09-24 08:45:40 -04:00
}
2023-10-25 12:16:14 -04:00
Connection::~Connection() { closesocket(m_sock); }
2023-09-24 08:45:40 -04:00
uint64_t Connection::GetHash(bool self) const { return self? m_loginfo.sid: m_playinfo.id; }
2023-09-24 08:45:40 -04:00
uint64_t Connection::GetTeamHash() const { return m_loginfo.tid; }
2023-09-24 08:45:40 -04:00
std::string Connection::GetName() const { return m_loginfo.name; }
2023-09-24 08:45:40 -04:00
2023-10-25 12:16:14 -04:00
void Connection::AddInput(Input in) { m_input_manifest.insert({ in.timestamp, in }); }
2023-09-24 11:07:03 -04:00
2023-10-25 12:16:14 -04:00
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-10-25 12:16:14 -04:00
Sync Connection::getSync(Timestamp time) {
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_loginfo.sid;
2023-09-24 11:07:03 -04:00
}
return sync;
}
2023-10-25 12:16:14 -04:00
SOCKET Connection::getSock() const { return m_sock; }
PlayerInfo* Connection::getInfo() const { return (PlayerInfo*)&m_playinfo; }
2023-10-26 17:57:42 -04:00
sockaddr_in* Connection::getAddr() const { return (sockaddr_in*)&m_addr; }
2023-09-24 11:07:03 -04:00
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
}