"""Exercise per-admin catalog navigation; discovery itself is checked natively.""" from policy_harness import ROOT, body, run core=ROOT/'addons/core/Scripts/Game/ERR/00_Core' s=body(core/'ERR_AdminSession.c','protected bool ItemCatalogCommand(') for a,b in [('protected ',''),('array replies','Array& replies'),('array parts','Array parts'),('ERR_ServerItemCatalog catalog','Catalog* catalog'),('GetGame().ERR_ServerItems()','GetCatalog()'),('GetGame().ERR_ItemSelections().','preferences.'),('catalog.','catalog->'),('ERR_CommandArguments.Integer','Integer')]:s=s.replace(a,b) run(r''' #include #include #include #include struct string; templatestruct Array:std::vector{using std::vector::vector;bool IsEmpty(){return this->empty();}int Count(){return this->size();}void Insert(T x){this->push_back(x);}}; struct string:std::string{using std::string::string;string(std::string s):std::string(s){}void Split(string,Array& out,bool){std::istringstream in(*this);std::string word;while(in>>word)out.push_back(word);}}; struct Catalog{bool Contains(string a,string i){return a=="loaded-a"&&i=="known-item";}void Start(void*){}bool Find(string s){return s=="loaded-a"||s=="loaded-b";}} catalog; Catalog* GetCatalog(){return &catalog;} bool Integer(string s,int& n){try{size_t p;n=std::stoi(s,&p);return p==s.size();}catch(...){return false;}} struct Preferences{int edits=0;bool Preset(string action,string name){edits++;return action=="save"&&name=="test";}bool Set(string,string,bool){edits++;return true;}bool SetWeight(string,string,int){edits++;return true;}} preferences; struct Session{void* m_Mode=nullptr;string m_ItemAddon;int m_ItemPage=0; ''' + s + r''' }; int main(){Session a,b;Array replies; assert(!a.ItemCatalogCommand("status",replies)); assert(a.ItemCatalogCommand("items list loaded-a 2",replies)&&a.m_ItemAddon=="loaded-a"&&a.m_ItemPage==2); assert(b.ItemCatalogCommand("items list loaded-b 1",replies)&&b.m_ItemAddon=="loaded-b"&&a.m_ItemAddon=="loaded-a"&&a.m_ItemPage==2); for(string bad:{"items", "items list unknown 0", "items list loaded-a -1", "items list loaded-a 2731", "items list loaded-a 0junk", "items list loaded-a 0 extra", "items disable loaded-a 0"}){ assert(a.ItemCatalogCommand(bad,replies));assert(a.m_ItemAddon=="loaded-a"&&a.m_ItemPage==2); } assert(a.ItemCatalogCommand("items list loaded-a 0",replies)&&a.m_ItemPage==0); for(string bad:{"items set unknown * 0","items set loaded-a unknown-item 0","items set loaded-a known-item 2","items set loaded-a * 0 extra"})a.ItemCatalogCommand(bad,replies); assert(preferences.edits==0); a.ItemCatalogCommand("items set loaded-a known-item 0",replies);assert(preferences.edits==1); a.ItemCatalogCommand("items set loaded-a * 1",replies);assert(preferences.edits==2); a.ItemCatalogCommand("items preset save test",replies);assert(preferences.edits==3); for(string bad:{"items weight unknown * 100","items weight loaded-a unknown-item 100","items weight loaded-a * 101","items weight loaded-a * -1","items weight loaded-a * 100junk"})a.ItemCatalogCommand(bad,replies); assert(preferences.edits==3); a.ItemCatalogCommand("items weight loaded-a * 100",replies);assert(preferences.edits==4); a.ItemCatalogCommand("items weight loaded-a known-item 0",replies);assert(preferences.edits==5); assert(a.m_ItemAddon=="loaded-a"&&a.m_ItemPage==0); } ''') command=body(core/'ERR_AdminSession.c','void Command(') assert command.index('if (!Authorize()) return;') < command.index('ItemCatalogCommand(arguments, replies)') assert 'PAGE_SIZE = 12' in (core/'ERR_ServerItemCatalog.c').read_text() assert 'GetLoadedAddons' in (core/'ERR_ServerItemCatalog.c').read_text() print('PASS: catalog requests use authenticated sessions, independent admin page selections, loaded-mod allowlisting, bounded pages and allowlisted item mutations')