Files
WoW-Hybrid-gateway/tests/native_instance_notifications_test.cpp
2026-11-23 03:28:32 +02:00

85 lines
4.1 KiB
C++

#include "world_translation.hpp"
#include "gateway/source_feedback.hpp"
#include <iostream>
using namespace gateway;
static Bytes word(uint32_t value) {
Bytes bytes;
le(bytes,value,4);
return bytes;
}
int main() {
NativeWorldTranslation world{};
world.selected.guid=4514;
world.realm=70;
unsigned checks=0;
auto verify=[&](uint32_t source,const Bytes& input,uint32_t opcode,const Bytes& expected) {
Bytes packets=world.translate({source,input},0x46010046,0,nullptr);
Reader reader(packets);
if (reader.le(4)!=(opcode?1:0)) throw Error("instance notification count");
if (opcode && (reader.le(4)!=opcode || reader.take(reader.le(4))!=expected))
throw Error("instance notification encoding");
reader.end();
++checks;
};
for(bool created : {false,true}) {
world.self_created=created;
verify(0x2cb,word(0),0x470228,{0});
verify(0x32b,word(1),0x470156,word(1));
for(uint32_t map : {33u,229u,409u}) {
verify(0x320,word(map),0x470135,word(map));
verify(0x31e,word(map),0x470133,word(map));
for(uint32_t reason : {0u,1u,2u,3u,UINT32_MAX}) {
auto failure=word(reason);
append(failure,word(map));
auto expected=word(map);
expected.push_back(uint8_t(reason<<6));
verify(0x31f,failure,reason<=2?0x470134:0,expected);
}
}
auto warning = [](uint32_t type, uint32_t map, uint32_t seconds) {
Bytes in;
le(in,type,4); le(in,map,4); le(in,seconds,4);
return in;
};
auto welcome = [&](uint32_t map, uint32_t difficulty, uint32_t seconds) {
Bytes expected;
le(expected,1,4); le(expected,map,4); le(expected,difficulty,2);
le(expected,seconds,4); le(expected,0,2);
verify(0x2fa,warning(4,map,seconds),0x4c000c,expected);
};
auto text = [&](uint32_t type, uint32_t map, uint32_t seconds, std::string message) {
auto expected = forever_source_system_feedback({0x2fa,0,std::move(message)}, {70,0x46010046});
verify(0x2fa,warning(type,map,seconds),0x4c0001,expected);
};
welcome(409,9,3601);
welcome(249,9,604800);
welcome(309,148,86401);
welcome(509,148,0x7fffffffu);
welcome(808,1,7200);
text(1,409,3600,"WARNING! Molten Core is scheduled to reset in 1 hour.");
text(1,409,3599,"WARNING! Molten Core is scheduled to reset in 59 minutes 59 seconds.");
text(1,409,901,"WARNING! Molten Core is scheduled to reset in 15 minutes 1 second.");
text(2,309,900,"WARNING! Zul'Gurub is scheduled to reset in 15 minutes!");
text(2,309,301,"WARNING! Zul'Gurub is scheduled to reset in 5 minutes 1 second!");
const std::string exit = " Please exit the zone or you will be returned to your bind location!";
text(3,807,300,"WARNING! Emerald Sanctum is scheduled to reset in 5 minutes." + exit);
text(3,807,60,"WARNING! Emerald Sanctum is scheduled to reset in 1 minute." + exit);
text(3,807,30,"WARNING! Emerald Sanctum is scheduled to reset in 30 seconds." + exit);
text(3,807,10,"WARNING! Emerald Sanctum is scheduled to reset in 10 seconds." + exit);
text(3,807,0,"WARNING! Emerald Sanctum is scheduled to reset now." + exit);
text(4,807,90061,"Welcome to Emerald Sanctum. This raid instance is scheduled to reset in 1 day 1 hour 1 minute 1 second.");
text(4,819,7200,"Welcome to Timbermaw Hold. This raid instance is scheduled to reset in 2 hours.");
for (auto input : {warning(0,409,3600), warning(5,409,30), warning(1,409,300),
warning(4,409,UINT32_MAX), warning(3,0,30), warning(3,999999,30), Bytes(11), Bytes(13)})
verify(0x2fa,input,0,{});
verify(0x32b,word(0),0x470156,word(0));
verify(0x32b,word(2),0,{});
verify(0x2cb,word(1),0,{});
for(uint32_t opcode : {0x2cbu,0x31eu,0x31fu,0x320u,0x32bu})verify(opcode,{1,2},0,{});
}
std::cout<<checks<<" source instance notifications and timed raid warning checks passed.\n";
}