123 lines
4.4 KiB
C++
123 lines
4.4 KiB
C++
#pragma once
|
|
#include "gateway/source_feedback.hpp"
|
|
#include "gateway/forever_opcode_profile.hpp"
|
|
#include "gateway/legacy_stream.hpp"
|
|
#include <algorithm>
|
|
#include <iterator>
|
|
#include <limits>
|
|
#include <string_view>
|
|
|
|
namespace gateway {
|
|
struct RaidResetMap {
|
|
uint32_t id;
|
|
std::string_view name;
|
|
uint16_t difficulty;
|
|
};
|
|
|
|
// Octo source Map.dbc names paired with the ordinary MapDifficulty on 70334.
|
|
// Zero keeps the original map name when a matching native instance is unavailable.
|
|
inline constexpr RaidResetMap raid_reset_maps[] = {
|
|
{33, "Shadowfang Keep", 1},
|
|
{34, "Stormwind Stockade", 1},
|
|
{35, "Stormwind Vault", 0},
|
|
{36, "Deadmines", 1},
|
|
{43, "Wailing Caverns", 1},
|
|
{47, "Razorfen Kraul", 1},
|
|
{48, "Blackfathom Deeps", 1},
|
|
{70, "Uldaman", 1},
|
|
{90, "Gnomeregan", 1},
|
|
{109, "Sunken Temple", 1},
|
|
{129, "Razorfen Downs", 1},
|
|
{189, "Scarlet Monastery", 1},
|
|
{209, "Zul'Farrak", 1},
|
|
{229, "Blackrock Spire", 1},
|
|
{230, "Blackrock Depths", 1},
|
|
{249, "Onyxia's Lair", 9},
|
|
{269, "Caverns of Time", 1},
|
|
{289, "Scholomance", 1},
|
|
{309, "Zul'Gurub", 148},
|
|
{329, "Stratholme", 1},
|
|
{349, "Maraudon", 1},
|
|
{389, "Ragefire Chasm", 1},
|
|
{409, "Molten Core", 9},
|
|
{429, "Dire Maul", 1},
|
|
{469, "Blackwing Lair", 9},
|
|
{509, "Ruins of Ahn'Qiraj", 148},
|
|
{531, "Ahn'Qiraj Temple", 9},
|
|
{532, "Lower Karazhan Halls", 0},
|
|
{533, "Naxxramas", 9},
|
|
{800, "Karazhan Crypt", 0},
|
|
{802, "Crescent Grove", 0},
|
|
{807, "Emerald Sanctum", 0},
|
|
{808, "Hateforge Quarry", 1},
|
|
{814, "Tower of Karazhan", 0},
|
|
{815, "Gilneas City", 0},
|
|
{816, "Dragonmaw Retreat", 1},
|
|
{818, "Stormwrought Ruins", 1},
|
|
{819, "Timbermaw Hold", 0},
|
|
{820, "Windhorn Canyon", 1},
|
|
{822, "Frostmane Hollow", 1},
|
|
};
|
|
|
|
// Preserve sub-minute warnings, including the source operator's 10s and 30s timers.
|
|
inline std::string raid_reset_duration(uint32_t seconds) {
|
|
std::string text;
|
|
auto consume = [&](uint32_t unit, std::string_view name) {
|
|
const uint32_t count = seconds / unit;
|
|
seconds %= unit;
|
|
if (!count) return;
|
|
if (!text.empty()) text += ' ';
|
|
text += std::to_string(count);
|
|
text += ' ';
|
|
text += name;
|
|
if (count != 1) text += 's';
|
|
};
|
|
consume(86400, "day");
|
|
consume(3600, "hour");
|
|
consume(60, "minute");
|
|
consume(1, "second");
|
|
return text;
|
|
}
|
|
|
|
inline std::optional<LegacyPacket> forever_raid_reset_warning(std::span<const uint8_t> payload, RosterRealm realm) {
|
|
if (payload.size() != 12) return std::nullopt;
|
|
Reader reader(payload);
|
|
const auto type = reader.le(4);
|
|
const auto map = reader.le(4);
|
|
const auto seconds = uint32_t(reader.le(4));
|
|
// Player::SendInstanceResetWarning chooses the type from these exact thresholds.
|
|
const unsigned expected = seconds > 3600 ? 4 : seconds > 900 ? 1 : seconds > 300 ? 2 : 3;
|
|
if (type != expected || seconds > std::numeric_limits<int32_t>::max()) return std::nullopt;
|
|
const auto place = std::find_if(std::begin(raid_reset_maps), std::end(raid_reset_maps),
|
|
[map](const RaidResetMap& entry) { return entry.id == map; });
|
|
if (place == std::end(raid_reset_maps)) return std::nullopt;
|
|
if (type == 4 && place->difficulty) {
|
|
Bytes out;
|
|
le(out, 1, 4); // Native RAID_INSTANCE_WELCOME.
|
|
le(out, map, 4);
|
|
le(out, place->difficulty, 2);
|
|
le(out, seconds, 4);
|
|
le(out, 0, 2); // Empty warning tag. The source requests neither special lock message.
|
|
// Original ClassicOpcodes normalizes SMSG_RAID_INSTANCE_MESSAGE (0x4a000a).
|
|
return LegacyPacket{0x4c000c, std::move(out)};
|
|
}
|
|
// Native warning type 4 substitutes only a duration into its GlobalStrings tag.
|
|
// The original warnings need a map as well. Use the source profile's enUS
|
|
// system text, including the imminent reset's original home-bind instruction.
|
|
std::string text;
|
|
if (type == 4) {
|
|
text = "Welcome to ";
|
|
text += place->name;
|
|
text += ". This raid instance is scheduled to reset";
|
|
} else {
|
|
text = "WARNING! ";
|
|
text += place->name;
|
|
text += " is scheduled to reset";
|
|
}
|
|
text += seconds ? " in " + raid_reset_duration(seconds) : " now";
|
|
text += type == 2 ? "!" : ".";
|
|
if (type == 3) text += " Please exit the zone or you will be returned to your bind location!";
|
|
return LegacyPacket{forever_opcodes::SMSG_CHAT, forever_source_system_feedback({0x2fa, 0, text}, realm)};
|
|
}
|
|
}
|