Administrative source import: native x86 compilation passed for 423 authored units. Source placement and submission states are migrated separately; this commit does not imply peer acceptance.
Previous head: 35d2a8cb36
Payload SHA256: 592f016d2730c5593bb653aa054c1e5f76a6df72c8f5a09e66f74876e2e33dee
93 lines
2.7 KiB
C++
93 lines
2.7 KiB
C++
#include "Contents/MessageTable.h"
|
|
#include "Contents/PlayerNameDictionary.h"
|
|
#include "Network/Connection/Connection.h"
|
|
|
|
#include <algorithm>
|
|
#include <cstring>
|
|
#include <windows.h>
|
|
#include <timeapi.h>
|
|
|
|
// OFFSET: 0x0060AE30
|
|
// FUNCTION: fn_04259
|
|
CPlayerNameDictionary::CPlayerNameDictionary(PlayerNameContext& context) : m_enabled(true), m_context(&context) {
|
|
}
|
|
|
|
// OFFSET: 0x0060A9D0
|
|
// OFFSET: 0x0060AAE0
|
|
CPlayerNameDictionary::~CPlayerNameDictionary() = default;
|
|
|
|
// OFFSET: 0x0060AFB0
|
|
// FUNCTION: fn_04261
|
|
// OFFSET: 0x0060B010
|
|
// FUNCTION: fn_04262
|
|
std::string CPlayerNameDictionary::Lookup(std::uint32_t id) {
|
|
const auto entry = this->m_names.find(id);
|
|
if (entry != this->m_names.end()) {
|
|
return entry->second.name;
|
|
}
|
|
|
|
if (std::find(this->m_pending.begin(), this->m_pending.end(), id) == this->m_pending.end()) {
|
|
this->m_pending.push_back(id);
|
|
}
|
|
|
|
return LookupMessage(581, this->m_context->languagePrefix, this->m_context->service, this->m_context->language);
|
|
}
|
|
|
|
// OFFSET: 0x0060ABB0
|
|
// FUNCTION: fn_04258
|
|
void CPlayerNameDictionary::Set(std::uint32_t id, std::string name) {
|
|
this->m_names.insert_or_assign(id, Entry{std::move(name), timeGetTime()});
|
|
const auto request = std::find_if(this->m_requests.begin(), this->m_requests.end(), [&](const Request& value) { return value.id == id; });
|
|
if (request != this->m_requests.end()) {
|
|
this->m_requests.erase(request);
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x0060B2E0
|
|
// FUNCTION: fn_04263
|
|
void CPlayerNameDictionary::Clear() {
|
|
this->m_names.clear();
|
|
this->m_pending.clear();
|
|
this->m_requests.clear();
|
|
}
|
|
|
|
// OFFSET: 0x0060B420
|
|
// FUNCTION: fn_04264
|
|
bool CPlayerNameDictionary::Contains(std::uint32_t id) const {
|
|
return this->m_names.contains(id);
|
|
}
|
|
|
|
// OFFSET: 0x0060B470
|
|
// FUNCTION: fn_04265
|
|
void CPlayerNameDictionary::Update() {
|
|
while (!this->m_requests.empty()) {
|
|
if (timeGetTime() < this->m_requests.front().tick + 10000u) {
|
|
break;
|
|
}
|
|
|
|
this->m_requests.pop_front();
|
|
}
|
|
|
|
while (!this->m_pending.empty()) {
|
|
const std::uint32_t id = this->m_pending.front();
|
|
const auto cached = this->m_names.find(id);
|
|
const bool fresh = cached != this->m_names.end() && !(cached->second.tick + 600000u < timeGetTime());
|
|
const auto outstanding = std::find_if(this->m_requests.begin(), this->m_requests.end(), [&](const Request& request) { return request.id == id; });
|
|
this->m_pending.pop_front();
|
|
|
|
if (fresh || outstanding != this->m_requests.end()) {
|
|
continue;
|
|
}
|
|
|
|
if (id != 0) {
|
|
unsigned char packet[6];
|
|
const std::uint16_t header = 873;
|
|
std::memcpy(packet, &header, sizeof(header));
|
|
std::memcpy(packet + 2, &id, sizeof(id));
|
|
this->m_context->connection.Send(sizeof(packet), packet);
|
|
this->m_requests.push_back({id, timeGetTime()});
|
|
}
|
|
|
|
return;
|
|
}
|
|
}
|