fix: stabilize turtle world entry session handling

This commit is contained in:
Kelsi 2026-03-15 01:21:23 -07:00
parent 4dba20b757
commit b0fafe5efa
20 changed files with 2283 additions and 1380 deletions

View file

@ -224,6 +224,7 @@ private:
std::future<PreparedCreatureModel> future;
};
std::vector<AsyncCreatureLoad> asyncCreatureLoads_;
std::unordered_set<uint32_t> asyncCreatureDisplayLoads_; // displayIds currently loading in background
void processAsyncCreatureResults(bool unlimited = false);
static constexpr int MAX_ASYNC_CREATURE_LOADS = 4; // concurrent background loads
std::unordered_set<uint64_t> deadCreatureGuids_; // GUIDs that should spawn in corpse/death pose
@ -280,7 +281,17 @@ private:
float z = 0.0f;
float orientation = 0.0f;
};
struct PendingTransportRegistration {
uint64_t guid = 0;
uint32_t entry = 0;
uint32_t displayId = 0;
float x = 0.0f;
float y = 0.0f;
float z = 0.0f;
float orientation = 0.0f;
};
std::unordered_map<uint64_t, PendingTransportMove> pendingTransportMoves_; // guid -> latest pre-registration move
std::deque<PendingTransportRegistration> pendingTransportRegistrations_;
uint32_t nextGameObjectModelId_ = 20000;
uint32_t nextGameObjectWmoModelId_ = 40000;
bool testTransportSetup_ = false;
@ -433,6 +444,7 @@ private:
};
std::vector<PendingTransportDoodadBatch> pendingTransportDoodadBatches_;
static constexpr size_t MAX_TRANSPORT_DOODADS_PER_FRAME = 4;
void processPendingTransportRegistrations();
void processPendingTransportDoodads();
// Quest marker billboard sprites (above NPCs)

View file

@ -7,6 +7,7 @@
#include "game/inventory.hpp"
#include "game/spell_defines.hpp"
#include "game/group_defines.hpp"
#include "network/packet.hpp"
#include <glm/glm.hpp>
#include <memory>
#include <string>
@ -2089,6 +2090,15 @@ private:
* Handle incoming packet from world server
*/
void handlePacket(network::Packet& packet);
void enqueueIncomingPacket(const network::Packet& packet);
void enqueueIncomingPacketFront(network::Packet&& packet);
void processQueuedIncomingPackets();
void enqueueUpdateObjectWork(UpdateObjectData&& data);
void processPendingUpdateObjectWork(const std::chrono::steady_clock::time_point& start,
float budgetMs);
void processOutOfRangeObjects(const std::vector<uint64_t>& guids);
void applyUpdateObjectBlock(const UpdateBlock& block, bool& newItemCreated);
void finalizeUpdateObjectBatch(bool newItemCreated);
/**
* Handle SMSG_AUTH_CHALLENGE from server
@ -2413,6 +2423,14 @@ private:
// Network
std::unique_ptr<network::WorldSocket> socket;
std::deque<network::Packet> pendingIncomingPackets_;
struct PendingUpdateObjectWork {
UpdateObjectData data;
size_t nextBlockIndex = 0;
bool outOfRangeProcessed = false;
bool newItemCreated = false;
};
std::deque<PendingUpdateObjectWork> pendingUpdateObjectWork_;
// State
WorldState state = WorldState::DISCONNECTED;

View file

@ -49,12 +49,14 @@ public:
/** Number of mapped opcodes. */
size_t size() const { return logicalToWire_.size(); }
/** Get canonical enum name for a logical opcode. */
static const char* logicalToName(LogicalOpcode op);
private:
std::unordered_map<uint16_t, uint16_t> logicalToWire_; // LogicalOpcode → wire
std::unordered_map<uint16_t, uint16_t> wireToLogical_; // wire → LogicalOpcode
static std::optional<LogicalOpcode> nameToLogical(const std::string& name);
static const char* logicalToName(LogicalOpcode op);
};
/**

View file

@ -451,6 +451,7 @@ public:
class TurtlePacketParsers : public ClassicPacketParsers {
public:
uint8_t movementFlags2Size() const override { return 0; }
bool parseUpdateObject(network::Packet& packet, UpdateObjectData& data) override;
bool parseMovementBlock(network::Packet& packet, UpdateBlock& block) override;
bool parseMonsterMove(network::Packet& packet, MonsterMoveData& data) override;
};

View file

@ -7,7 +7,13 @@
#include "auth/vanilla_crypt.hpp"
#include <functional>
#include <vector>
#include <deque>
#include <cstdint>
#include <chrono>
#include <thread>
#include <mutex>
#include <atomic>
#include <string>
namespace wowee {
namespace network {
@ -66,6 +72,8 @@ public:
*/
void initEncryption(const std::vector<uint8_t>& sessionKey, uint32_t build = 12340);
void tracePacketsFor(std::chrono::milliseconds duration, const std::string& reason);
/**
* Check if header encryption is enabled
*/
@ -76,11 +84,23 @@ private:
* Try to parse complete packets from receive buffer
*/
void tryParsePackets();
void pumpNetworkIO();
void dispatchQueuedPackets();
void asyncPumpLoop();
void startAsyncPump();
void stopAsyncPump();
void closeSocketNoJoin();
socket_t sockfd = INVALID_SOCK;
bool connected = false;
bool encryptionEnabled = false;
bool useVanillaCrypt = false; // true = XOR cipher, false = RC4
bool useAsyncPump_ = true;
std::thread asyncPumpThread_;
std::atomic<bool> asyncPumpStop_{false};
std::atomic<bool> asyncPumpRunning_{false};
mutable std::mutex ioMutex_;
mutable std::mutex callbackMutex_;
// WotLK RC4 ciphers for header encryption/decryption
auth::RC4 encryptCipher;
@ -94,6 +114,8 @@ private:
size_t receiveReadOffset_ = 0;
// Optional reused packet queue (feature-gated) to reduce per-update allocations.
std::vector<Packet> parsedPacketsScratch_;
// Parsed packets waiting for callback dispatch; drained with a strict per-update budget.
std::deque<Packet> pendingPacketCallbacks_;
// Runtime-gated network optimization toggles (default off).
bool useFastRecvAppend_ = false;
@ -105,6 +127,9 @@ private:
// Debug-only tracing window for post-auth packet framing verification.
int headerTracePacketsLeft = 0;
std::chrono::steady_clock::time_point packetTraceStart_{};
std::chrono::steady_clock::time_point packetTraceUntil_{};
std::string packetTraceReason_;
// Packet callback
std::function<void(const Packet&)> packetCallback;

View file

@ -296,7 +296,9 @@ private:
std::unordered_map<VkTexture*, bool> textureColorKeyBlackByPtr_;
std::unordered_map<std::string, VkTexture*> compositeCache_; // key → texture for reuse
std::unordered_set<std::string> failedTextureCache_; // negative cache for budget exhaustion
std::unordered_map<std::string, uint64_t> failedTextureRetryAt_;
std::unordered_set<std::string> loggedTextureLoadFails_; // dedup warning logs
uint64_t textureLookupSerial_ = 0;
size_t textureCacheBytes_ = 0;
uint64_t textureCacheCounter_ = 0;
size_t textureCacheBudgetBytes_ = 1024ull * 1024 * 1024;

View file

@ -477,7 +477,9 @@ private:
uint64_t textureCacheCounter_ = 0;
size_t textureCacheBudgetBytes_ = 2048ull * 1024 * 1024;
std::unordered_set<std::string> failedTextureCache_;
std::unordered_map<std::string, uint64_t> failedTextureRetryAt_;
std::unordered_set<std::string> loggedTextureLoadFails_;
uint64_t textureLookupSerial_ = 0;
uint32_t textureBudgetRejectWarnings_ = 0;
std::unique_ptr<VkTexture> whiteTexture_;
std::unique_ptr<VkTexture> glowTexture_;

View file

@ -671,7 +671,9 @@ private:
uint64_t textureCacheCounter_ = 0;
size_t textureCacheBudgetBytes_ = 8192ull * 1024 * 1024; // 8 GB default, overridden at init
std::unordered_set<std::string> failedTextureCache_;
std::unordered_map<std::string, uint64_t> failedTextureRetryAt_;
std::unordered_set<std::string> loggedTextureLoadFails_;
uint64_t textureLookupSerial_ = 0;
uint32_t textureBudgetRejectWarnings_ = 0;
// Default white texture