123 lines
7.9 KiB
C++
123 lines
7.9 KiB
C++
#include "gateway/talents.hpp"
|
|
#include "gateway/chat.hpp"
|
|
#include "gateway/roster_translation.hpp"
|
|
#include <iostream>
|
|
using namespace gateway;
|
|
static void check(bool ok){if(!ok)throw Error("talent addon control assertion");}
|
|
static Bytes request(std::string text,std::string name="Fixture",std::string prefix="GWTURTLE"){
|
|
Bytes out;const auto bits=(prefix.size()<<11)|(text.size()<<3);
|
|
le(out,bits>>8,1);le(out,bits,1);le(out,7,4);
|
|
out.insert(out.end(),prefix.begin(),prefix.end());out.insert(out.end(),text.begin(),text.end());
|
|
append(out,pack_guid(Guid128{}));append(out,pack_guid(Guid128{}));le(out,0,4);
|
|
auto names=(name.size()+1)<<15;le(out,names>>16,1);le(out,names>>8,1);le(out,names,1);le(out,0,1);cstring(out,name);return out;
|
|
}
|
|
static void grave_requests(const Character& self) {
|
|
auto send = [&](const Bytes& native, uint8_t race) {
|
|
return turtle_grave_request(forever_self_addon_request(native, self, 70), race);
|
|
};
|
|
auto expect = [&](std::string text, uint8_t race, uint32_t language, std::string expected) {
|
|
auto body = send(request(text, self.name, "GWGRAVE"), race);
|
|
Reader r(body);
|
|
check(r.le(4) == 0 && r.le(4) == language && r.cstring(255) == expected);
|
|
r.end();
|
|
};
|
|
auto rejects = [&](const Bytes& native, uint8_t race = 1) {
|
|
try { (void)send(native, race); }
|
|
catch (const Error&) { return; }
|
|
throw std::runtime_error("invalid grave request accepted");
|
|
};
|
|
expect("CAPS", 1, 7, ".owl caps 8");
|
|
expect("CAPS", 9, 1, ".owl caps 8");
|
|
expect("WATCH 18446744073709551615", 10, 7, ".owl dghost 18446744073709551615");
|
|
expect("WATCH 00042", 2, 1, ".owl dghost 00042");
|
|
for (const char* text : {"CAPS 14", ".owl hello", "WATCH", "WATCH ", "WATCH 0",
|
|
"WATCH +1", "WATCH -1", "WATCH 1 extra", "WATCH 1\n",
|
|
"WATCH 18446744073709551616", "WATCH 000000000000000000001"})
|
|
rejects(request(text, self.name, "GWGRAVE"));
|
|
rejects(request("CAPS", self.name, "GWGRAVE"), 0);
|
|
rejects(request("CAPS", "Neighbor", "GWGRAVE"));
|
|
rejects(request("CAPS", self.name, "OWLDTH"));
|
|
auto guild = request("CAPS", self.name, "GWGRAVE");
|
|
guild[2] = 4;
|
|
rejects(guild);
|
|
}
|
|
int main(){
|
|
Character self{};self.guid=4509;self.name="Fixture";
|
|
grave_requests(self);
|
|
auto parse=[&](const Bytes& b){return turtle_talent_addon_control(b,self,70);};
|
|
check(parse(request("state"))==".gwtalent state");
|
|
auto actual=unhex("4028070000004757545552544c457374617465000000000000000006000000476174657761797465737400");
|
|
Character captured=self;captured.name="Gatewaytest";
|
|
check(turtle_talent_addon_control(actual,captured,70)==".gwtalent state");
|
|
check(parse(request("learn 57 1"))==".gwtalent learn 57 1");
|
|
check(parse(request("reset 17379390974119196772"))==".gwtalent reset 17379390974119196772");
|
|
auto rejects=[&](const Bytes& b){try{parse(b);}catch(const Error&){return;}throw Error("invalid provider message accepted");};
|
|
auto good=request("learn 57 1");
|
|
for(size_t i=0;i<good.size();++i)rejects(Bytes(good.begin(),good.begin()+i));
|
|
auto bad=good;bad.push_back(0);rejects(bad);
|
|
bad=good;bad[6]='X';rejects(bad); // Foreign addon prefix.
|
|
bad=good;bad[4]=1;rejects(bad); // Non-WHISPER distribution.
|
|
bad=good;bad[1]|=4;rejects(bad); // Logged, not ordinary provider IPC.
|
|
bad=request("state");bad[30]=1;rejects(bad); // Unknown target preamble semantics.
|
|
rejects(request("state","Another"));rejects(request("learn 57 6"));rejects(request("learn 57 1 extra"));
|
|
for(const auto& text:{"GetTransmogStatus","GetSetsStatus:","GetAvailableTransmogsItemIDs:19:18:109"}){
|
|
auto modern=request(text,"Fixture","TW_TRANSMOG");
|
|
auto parsed=forever_self_addon_request(modern,self,70);
|
|
auto wire=turtle_transmog_request(parsed);Reader r(wire);
|
|
check(r.le(4)==3 && r.le(4)==0xffffffffu);
|
|
check(r.cstring(255)==std::string("TW_TRANSMOG\t")+text);r.end();
|
|
rejects(modern); // It must never become a talent purchase/control.
|
|
for(size_t i=0;i<modern.size();++i){try{forever_self_addon_request(std::span(modern).first(i),self,70);throw std::runtime_error("truncated self addon accepted");}catch(const Error&){}}
|
|
}
|
|
for(const auto& text:{"DoTransmog:0:109:1","DoTransmog:15:58214:16","ResetTransmog:16:17","ResetTransmog:18:19"}){
|
|
auto modern=request(text,"Fixture","TW_TRANSMOG");
|
|
auto parsed=forever_self_addon_request(modern,self,70);
|
|
auto wire=turtle_server_addon_request(parsed);Reader r(wire);
|
|
check(r.le(4)==3 && r.le(4)==0xffffffffu);
|
|
check(r.cstring(255)==std::string("TW_TRANSMOG\t")+text);r.end();
|
|
}
|
|
for(const auto& text:{"DoTransmog:1:2:3","DoTransmog:15:0:16","DoTransmog:15:58214:17","DoTransmog:19:58214:20","DoTransmog:15:58214","DoTransmog:15:58214:16:1","DoTransmog:15:-1:16","ResetTransmog:1:0","ResetTransmog:16:18","ResetTransmog:16","ResetTransmog:16:17:1","GetTransmogStatus extra","GetAvailableTransmogsItemIDs:20:0:109","GetAvailableTransmogsItemIDs:1:0:0","GetAvailableTransmogsItemIDs:1:0:109:2","GetAvailableTransmogsItemIDs:1:-1:109"}){
|
|
try{turtle_transmog_request({"TW_TRANSMOG",text});throw std::runtime_error("unsupported mutation/query accepted");}catch(const Error&){}
|
|
}
|
|
try{turtle_transmog_request({"OTHER","GetTransmogStatus"});return EXIT_FAILURE;}catch(const Error&){}
|
|
Character peer{};peer.guid=42;peer.name="Neighbor";
|
|
auto original_request=turtle_inspect_talents_request(peer);
|
|
Reader wire(original_request);
|
|
check(wire.le(4)==3 && wire.le(4)==0xffffffffu);
|
|
check(wire.cstring()=="TW_CHAT_MSG_WHISPER<Neighbor>\tINSTalentShow");wire.end();
|
|
auto reply=ServerAddonMessage{42,0,"TW_CHAT_MSG_WHISPER","INSTalentTabInfo;1;Frost;12;17"};
|
|
auto result=forever_inspect_talents_reply(reply,peer,{});
|
|
Reader delivered(result);check(delivered.le(1)==4 && delivered.le(4)==183);
|
|
const auto identity=forever_player_guid(peer.guid,70);
|
|
check(unpack_guid(delivered,16)==Bytes(identity.begin(),identity.end()));
|
|
const auto expected_tail=peer.name+std::string(InspectTalentPrefix)+reply.text;
|
|
check(result.size()>expected_tail.size() && std::equal(expected_tail.begin(),expected_tail.end(),result.end()-expected_tail.size()));
|
|
for(const char* text:{"INSTalentEND;","INSTalentInfo;2;1;Unrelenting;1;2;1;5;1;-1;-1;-1"}){
|
|
reply.text=text;check(is_inspect_talent_reply(reply));
|
|
}
|
|
for(const char* text:{"INSTalentShow","INSTalentEND;more","INSTalentInfo;|Htalent:1|h","INSTalentTabInfo;1\n"}){
|
|
reply.text=text;check(!is_inspect_talent_reply(reply));
|
|
}
|
|
auto forwarded=[&](std::string text){
|
|
Bytes body;le(body,3,1);le(body,0xffffffffu,4);le(body,peer.guid,8);
|
|
le(body,text.size()+1,4);cstring(body,text);le(body,0,1);
|
|
return turtle_server_addon_message(body);
|
|
};
|
|
for(const char* text:{"INSTalentTabInfo;1;Frost;12;17","INSTalentInfo;1;1;Test;1;1;0;5;1;-1;-1;-1","INSTalentEND;"}){
|
|
const std::string prefix="TW_CHAT_MSG_WHISPER\t";
|
|
for(const auto& separator:{std::string{},std::string{"\t"}}){
|
|
auto parsed=forwarded(prefix+separator+text);
|
|
check(parsed.text==text && is_inspect_talent_reply(parsed));
|
|
check(forever_inspect_talents_reply(parsed,peer,{})==
|
|
forever_inspect_talents_reply({peer.guid,0,"TW_CHAT_MSG_WHISPER",text},peer,{}));
|
|
}
|
|
check(!is_inspect_talent_reply(forwarded(prefix+"\t\t"+text)));
|
|
}
|
|
check(forwarded("TW_CHAT_MSG_WHISPER\t\tSpellInfo").text=="\tSpellInfo");
|
|
reply.text="INSTalentEND;";reply.sender=99;
|
|
try{forever_inspect_talents_reply(reply,peer,{});return EXIT_FAILURE;}catch(const Error&){}
|
|
peer.name="Other>Injected";
|
|
try{turtle_inspect_talents_request(peer);return EXIT_FAILURE;}catch(const Error&){}
|
|
std::cout<<"Self-addressed talent addon channel and transmog source request grammar passed; no real-client claim\n";
|
|
}
|