rodecomp/Source/Contents/Actors/ActorNameRequests.cpp
ragnarok-clanker 01696fba22 Confirm 2 functions in Source/Contents/Actors/PlayerNameDictionary.cpp, Source/Contents/Actors/ActorNameRequests.cpp
Batch #17872 by eAthena: 0 byte-identical, 2 confirmed by peer review.

- fn_04265 CPlayerNameDictionary::Update: logic confirmed by peer review (already on main)
- fn_03504 CActorNameCardHolder::ProcessRequests: logic confirmed by peer review (already on main)

Peer-reviewed-by: Yommy, codeplay, bibinir
Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
2026-11-12 05:04:25 +00:00

71 lines
2 KiB
C++

#include "Contents/Actors/ActorNameCard.h"
#include "Network/Connection/Connection.h"
#include "Network/Packets/PacketId.h"
#include <algorithm>
#include <cstdint>
#include <windows.h>
#include <timeapi.h>
template __declspec(noinline) void std::deque<std::uint32_t>::pop_front() noexcept;
#pragma pack(push, 1)
struct PACKET_CZ_REQNAME2 {
/* 0000 */ std::int16_t packetType;
/* 0002 */ std::uint32_t gid;
};
#pragma pack(pop)
#if defined(_WIN32) && !defined(_WIN64)
static_assert(sizeof(PACKET_CZ_REQNAME2) == 6);
#endif
// OFFSET: 0x005BFD10
// FUNCTION: fn_03500
const CActorNameCard& CActorNameCardHolder::Lookup(std::uint32_t id) {
const auto found = this->cards.find(id);
if (found != this->cards.end() && found->second.received == 1) {
return found->second;
}
if (std::find(this->pending.begin(), this->pending.end(), id) == this->pending.end()) {
this->pending.push_back(id);
}
// GLOBAL: gl_24526
static CActorNameCard empty;
return empty;
}
// OFFSET: 0x005C01D0
// FUNCTION: fn_03504
void CActorNameCardHolder::ProcessRequests() {
while (!this->requests.empty()) {
const Request request = this->requests.front();
if (timeGetTime() < request.tick + 10000) {
break;
}
this->requests.pop_front();
}
while (!this->pending.empty()) {
const std::uint32_t id = this->pending.front();
const auto found = this->cards.find(id);
if (found == this->cards.end() || found->second.received != 1) {
const auto requested = std::find_if(this->requests.begin(), this->requests.end(), [id](const Request& request) { return request.id == id; });
if (requested == this->requests.end()) {
this->pending.pop_front();
if (id != 0) {
PACKET_CZ_REQNAME2 packet;
packet.packetType = ID_CZ_REQNAME2;
packet.gid = id;
GetRagConnection().Send(sizeof(packet), &packet);
this->requests.push_back({ id, timeGetTime() });
}
return;
}
}
this->pending.pop_front();
}
}