128 lines
9.3 KiB
C++
128 lines
9.3 KiB
C++
// Credential-free static validation shared by encoder and cached-roster API.
|
|
#include "session.h"
|
|
#include "gateway/roster_translation.hpp"
|
|
#include "gateway/turtle_login_profile.hpp"
|
|
#include <cstddef>
|
|
#include <iostream>
|
|
using namespace gateway;
|
|
namespace {
|
|
void check(bool okay){if(!okay)throw Error("roster diagnostics regression");}
|
|
Character valid(){Character c{};c.guid=42;c.name="Synthetic";c.race=1;c.cls=1;c.gender=0;c.level=60;return c;}
|
|
void reason(const Character& c,RosterValidationReason expected){
|
|
check(forever_roster_row_reason(c)==expected);
|
|
bool accepted=false;try{forever_roster({c},{});accepted=true;}catch(const Error&){}
|
|
check(accepted==(expected==RosterValidationReason::Ok));
|
|
}
|
|
}
|
|
int main(){
|
|
static_assert(sizeof(gw_native_roster_diagnostic_row)==24);
|
|
static_assert(sizeof(gw_native_roster_diagnostics)==256);
|
|
static_assert(offsetof(gw_native_roster_diagnostics,rows)==16);
|
|
static_assert(GW_NATIVE_ROSTER_DIAGNOSTICS_ABI==2);
|
|
static_assert(offsetof(gw_native_roster_diagnostic_row,preview_race)==20);
|
|
static_assert(uint32_t(RosterValidationReason::Ok)==GW_NATIVE_ROSTER_OK);
|
|
static_assert(uint32_t(RosterValidationReason::CountBound)==GW_NATIVE_ROSTER_COUNT_BOUND);
|
|
static_assert(uint32_t(RosterValidationReason::UnsupportedPair)==GW_NATIVE_ROSTER_UNSUPPORTED_PAIR);
|
|
static_assert(uint32_t(RosterValidationReason::GenderBound)==GW_NATIVE_ROSTER_GENDER_BOUND);
|
|
static_assert(uint32_t(RosterValidationReason::NameShape)==GW_NATIVE_ROSTER_NAME_SHAPE);
|
|
static_assert(uint32_t(RosterValidationReason::SourceIdentity)==GW_NATIVE_ROSTER_SOURCE_IDENTITY);
|
|
static_assert(uint32_t(RosterValidationReason::VisualType)==GW_NATIVE_ROSTER_VISUAL_TYPE);
|
|
static_assert(turtle_native_presentation_pair(1,2) && turtle_native_presentation_pair(3,2));
|
|
static_assert(!turtle_native_presentation_pair(6,2) && TurtleNativeCreationClassDisableMask==0x1a20);
|
|
auto c=valid();reason(c,RosterValidationReason::Ok);
|
|
for(unsigned race=1;race<=8;++race)for(unsigned gender=0;gender<=1;++gender){c=valid();c.race=race;c.gender=gender;reason(c,RosterValidationReason::Ok);}
|
|
for(auto pair:{std::pair{1,8},std::pair{6,5}}){
|
|
c=valid();c.race=pair.first;c.cls=pair.second;reason(c,RosterValidationReason::Ok);
|
|
check(turtle_native_presentation_pair(c.race,c.cls)); // Source-valid login; mechanics unverified.
|
|
}
|
|
check(TurtleOriginalRosterRaceClasses.size()==48 && TurtleNativePresentationRaceClasses.size()==59);
|
|
for(auto pair:TurtleOriginalRosterRaceClasses){c=valid();c.race=pair[0];c.cls=pair[1];reason(c,RosterValidationReason::Ok);}
|
|
for(auto pair:{std::pair{9,1},std::pair{10,1},std::pair{1,6},std::pair{6,10},std::pair{0,1},std::pair{1,0}}){
|
|
c=valid();c.race=pair.first;c.cls=pair.second;reason(c,RosterValidationReason::UnsupportedPair);
|
|
}
|
|
c=valid();c.gender=2;reason(c,RosterValidationReason::GenderBound);
|
|
c=valid();c.name.clear();reason(c,RosterValidationReason::NameShape);
|
|
c=valid();c.name=std::string(64,'A');reason(c,RosterValidationReason::NameShape);
|
|
c=valid();c.guid=0;reason(c,RosterValidationReason::SourceIdentity);
|
|
c=valid();c.visuals[18].type=29;reason(c,RosterValidationReason::VisualType);
|
|
c=valid();c.visuals[19].type=255;reason(c,RosterValidationReason::Ok); // Source bag19 is not a rendered slot.
|
|
c=valid();c.cls=6;c.gender=255;c.name.clear();c.guid=0;c.visuals[0].type=255;reason(c,RosterValidationReason::UnsupportedPair);
|
|
c=valid();c.gender=255;c.name.clear();c.guid=0;reason(c,RosterValidationReason::GenderBound);
|
|
c=valid();c.name.clear();c.guid=0;reason(c,RosterValidationReason::NameShape);
|
|
c=valid();c.guid=0;c.visuals[0].type=255;reason(c,RosterValidationReason::SourceIdentity);
|
|
// Level is reported, not an additional fabricated encoder restriction.
|
|
c=valid();c.level=0;reason(c,RosterValidationReason::Ok);
|
|
gw_native_roster_diagnostics out{};out.abi=99;out.rows[0].race=99;
|
|
check(gw_native_transport_roster_diagnostics(nullptr,&out)==-1 && !out.abi && !out.rows[0].race);
|
|
check(gw_native_transport_roster_diagnostics(nullptr,nullptr)==-1);
|
|
bool count_rejected=false;try{forever_roster(std::vector<Character>(11,valid()),{});}catch(const Error&){count_rejected=true;}
|
|
check(count_rejected);
|
|
// Mixed genuine source identities retain their GUIDs/order and ownership;
|
|
// the explicit view withholds only valid custom-race presentation.
|
|
auto warrior=valid();warrior.guid=42;warrior.race=6;
|
|
auto high_elf=valid();high_elf.guid=43;high_elf.race=10;high_elf.cls=4;high_elf.level=1;
|
|
auto shaman=valid();shaman.guid=44;shaman.race=6;shaman.cls=7;shaman.level=1;
|
|
const std::vector<Character> source{warrior,high_elf,shaman};
|
|
auto view=forever_presented_roster(source);
|
|
check(source.size()==3 && source[1].guid==43 && source[1].race==10 && source[1].cls==4);
|
|
check(view.size()==2 && view[0].guid==42 && view[1].guid==44 && view[1].cls==7);
|
|
check(turtle_native_presentation_pair(6,7)); // Source-valid login, class mechanics unverified.
|
|
bool strict_rejected=false;try{forever_roster(source,{});}catch(const Error&){strict_rejected=true;}check(strict_rejected);
|
|
forever_roster(view,{});auto restrictions=forever_restrictions(view,{});Reader restriction_reader(restrictions);check(restriction_reader.le(4)==2);
|
|
for(const auto& c:view){check(restriction_reader.le(1)==0);auto id=unpack_guid(restriction_reader,16);auto expected=forever_player_guid(c.guid,70);check(id==Bytes(expected.begin(),expected.end()));restriction_reader.take(8);}restriction_reader.end();
|
|
for(unsigned failure=0;failure<7;++failure){
|
|
auto changed=source;
|
|
if(failure==0)changed[1].gender=2;
|
|
if(failure==1)changed[1].name.clear();
|
|
if(failure==2)changed[1].name=std::string(64,'X');
|
|
if(failure==3)changed[1].guid=0;
|
|
if(failure==4)changed[1].visuals[18].type=29;
|
|
if(failure==5)changed[1].guid=42;
|
|
if(failure==6)changed[1].cls=7; // Unknown High Elf/Shaman, not a source-valid omission.
|
|
bool rejected=false;try{forever_presented_roster(changed);}catch(const Error&){rejected=true;}check(rejected);
|
|
}
|
|
check(forever_presented_roster({high_elf}).empty());
|
|
count_rejected=false;try{forever_presented_roster(std::vector<Character>(11,warrior));}catch(const Error&){count_rejected=true;}check(count_rejected);
|
|
auto preview=forever_preview_roster(source);
|
|
check(preview.size()==3 && preview[1].guid==43 && preview[1].race==10 && preview[1].cls==4);
|
|
check(source[1].race==10 && forever_roster_row_reason(source[1])==RosterValidationReason::UnsupportedPair);
|
|
check(forever_roster_preview_race(high_elf)==10);
|
|
auto goblin=warrior;goblin.race=9;goblin.guid=45;check(forever_roster_preview_race(goblin)==9);
|
|
// Independent wire comparison: strict original Human Rogue/Warrior is a
|
|
// valid writer baseline. For an unprojectable Source appearance, preview
|
|
// must change only RaceID, never common identity/equipment/unlock fields.
|
|
// Proven race-specific appearance vectors have separate wire goldens.
|
|
for(auto custom:{high_elf,goblin})for(uint8_t gender:{0,1})for(bool realmless:{false,true}){
|
|
custom.gender=gender;custom.appearance.fill(255); // Both rows retain the prior empty customization vector.
|
|
auto reference=custom;reference.race=1;
|
|
auto expected=forever_roster({reference},{},realmless);
|
|
Reader header(expected);header.take(34);unpack_guid(header,16);
|
|
const auto race_offset=expected.size()-header.left()+6;
|
|
check(expected[race_offset]==1);expected[race_offset]=custom.race;
|
|
check(forever_roster_preview({custom},{},realmless)==expected);
|
|
check(custom.race==10 || custom.race==9);
|
|
bool strict_custom_rejected=false;try{forever_roster({custom},{},realmless);}catch(const Error&){strict_custom_rejected=true;}check(strict_custom_rejected);
|
|
}
|
|
for(auto pair:TurtleOriginalRosterRaceClasses){
|
|
c=valid();c.race=pair[0];c.cls=pair[1];
|
|
check(forever_roster_preview_race(c)==c.race);
|
|
check(forever_roster_preview({c},{},false)==forever_roster({c},{},false));
|
|
}
|
|
c=high_elf;c.cls=7;check(!forever_roster_preview_race(c));
|
|
for(unsigned failure=0;failure<5;++failure){
|
|
auto bad=high_elf;
|
|
if(failure==0)bad.guid=0;
|
|
if(failure==1)bad.gender=2;
|
|
if(failure==2)bad.name.clear();
|
|
if(failure==3)bad.visuals[0].type=29;
|
|
if(failure==4)bad.cls=7;
|
|
bool rejected=false;try{forever_roster_preview({bad},{});}catch(const Error&){rejected=true;}check(rejected);
|
|
}
|
|
auto preview_restrictions=forever_restrictions(preview,{});Reader preview_restriction_reader(preview_restrictions);check(preview_restriction_reader.le(4)==3);
|
|
for(const auto& original:source){check(preview_restriction_reader.le(1)==0);auto guid=unpack_guid(preview_restriction_reader,16);auto expected=forever_player_guid(original.guid,70);check(guid==Bytes(expected.begin(),expected.end()));preview_restriction_reader.take(8);}preview_restriction_reader.end();
|
|
check(turtle_native_presentation_pair(high_elf.race,high_elf.cls));
|
|
check(turtle_native_presentation_pair(goblin.race,goblin.cls));
|
|
check(turtle_native_presentation_pair(shaman.race,shaman.cls));
|
|
std::cout<<"PASS bounded public roster diagnostics ABI and encoder-shared first-failure guards; no network or account data\n";
|
|
}
|