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

- fn_03500 CActorNameCardHolder::Lookup: logic confirmed by peer review (already on main)
- fn_03504 CActorNameCardHolder::ProcessRequests: logic confirmed by peer review (already on main)

Peer-reviewed-by: ragnarok-clanker, Yommy, Toshiro
Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
2026-11-11 13:10:01 +00:00

75 lines
2.3 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>
using ActorNameCardTree = std::_Tree<std::_Tmap_traits<
std::uint32_t, CActorNameCard, std::less<std::uint32_t>,
std::allocator<std::pair<const std::uint32_t, CActorNameCard>>, false>>;
extern template std::_Tree_find_result<std::_Tree_node<std::pair<const std::uint32_t, CActorNameCard>, void*>*>
ActorNameCardTree::_Find_lower_bound<std::uint32_t>(const std::uint32_t&) const;
#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();
}
}