883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
144 lines
8.1 KiB
C++
144 lines
8.1 KiB
C++
// Authorized local fixture peer, NOT Forever character-creation acceptance.
|
|
// Tortoise CharacterHandler.cpp::HandleCharCreateOpcode and SharedDefines.h
|
|
// ResponseCodes define these exact Classic request fields / success0x2E.
|
|
#include "gateway/legacy_client.hpp"
|
|
#include "gateway/turtle_login_profile.hpp"
|
|
#include <algorithm>
|
|
#include <chrono>
|
|
#include <iostream>
|
|
#include <string_view>
|
|
|
|
using namespace gateway;
|
|
namespace {
|
|
bool valid_name(const std::string& name) {
|
|
return !name.empty() && name.size()<=12 && name[0]>='A' && name[0]<='Z' &&
|
|
std::all_of(name.begin()+1,name.end(),[](char c){return c>='a' && c<='z';});
|
|
}
|
|
unsigned identity_number(std::string_view value) {
|
|
if(value.empty() || value.size()>2 || value.front()<'1' || value.front()>'9')throw Error("invalid public identity number");
|
|
unsigned result=0;
|
|
for(char c:value){if(c<'0'||c>'9')throw Error("invalid public identity number");result=result*10+unsigned(c-'0');}
|
|
return result;
|
|
}
|
|
Bytes request(const std::string& name,unsigned race,unsigned gender,unsigned class_id=1) {
|
|
if(!valid_name(name) || !turtle_source_roster_pair(race,class_id) || gender>1)
|
|
throw Error("invalid public fixture parameters");
|
|
Bytes body;cstring(body,name);
|
|
append(body,Bytes{uint8_t(race),uint8_t(class_id),uint8_t(gender),0,0,0,0,0,0});le(body,0,4);
|
|
return body;
|
|
}
|
|
uint8_t result(const Bytes& body) {
|
|
Reader r(body);auto value=uint8_t(r.le(1));r.end();return value;
|
|
}
|
|
const Character* matching(const std::vector<Character>& rows,const std::string& name,unsigned race,unsigned gender,unsigned class_id=1) {
|
|
const Character* match=nullptr;
|
|
for(const auto& row:rows)if(normalize(row.name)==normalize(name)) {
|
|
if(match || row.name!=name || row.race!=race || row.cls!=class_id || row.gender!=gender || !row.guid)
|
|
throw Error("existing roster identity conflicts with requested fixture");
|
|
match=&row;
|
|
}
|
|
return match;
|
|
}
|
|
void output(const char* status,const Character& c) {
|
|
std::cout<<"RESULT "<<status<<' '<<c.guid<<' '<<unsigned(c.race)<<' '
|
|
<<unsigned(c.cls)<<' '<<unsigned(c.gender)<<' '<<unsigned(c.level)<<std::endl;
|
|
}
|
|
LegacyPacket await(LegacySession& session,uint32_t opcode) {
|
|
auto deadline=std::chrono::steady_clock::now()+std::chrono::seconds(12);
|
|
for(unsigned count=0;count<128 && std::chrono::steady_clock::now()<deadline;++count) {
|
|
auto packet=session.receive_for(250);
|
|
if(!packet)continue;
|
|
if(packet->opcode==opcode)return *packet;
|
|
if(packet->opcode==0x2E6)throw Error("unsupported server integrity challenge");
|
|
if(packet->opcode!=0x2EF && packet->opcode!=0xFD && packet->opcode!=0x127 &&
|
|
packet->opcode!=0x96 && packet->opcode!=0x14E)throw Error("unexpected fixture response");
|
|
}
|
|
throw Error("bounded fixture response wait expired");
|
|
}
|
|
void self_test() {
|
|
const auto bytes=request("Nativehoof",6,0);
|
|
if(bytes!=Bytes{'N','a','t','i','v','e','h','o','o','f',0,6,1,0,0,0,0,0,0,0,0,0,0,0})
|
|
throw Error("Classic create golden mismatch");
|
|
// Literal source request: High Elf10, Rogue4, female1, six actual default
|
|
// appearance/outfit bytes and the real zero challenge mask.
|
|
if(request("Nativeelf",10,1,4)!=Bytes{'N','a','t','i','v','e','e','l','f',0,10,4,1,0,0,0,0,0,0,0,0,0,0})
|
|
throw Error("High Elf Rogue create golden mismatch");
|
|
for(auto pair:TurtleSourceRosterRaceClasses)for(unsigned gender=0;gender<=1;++gender){
|
|
auto body=request("A",pair[0],gender,pair[1]);
|
|
if(body.size()!=15 || body[2]!=pair[0] || body[3]!=pair[1] || body[4]!=gender)throw Error("Classic request identity mismatch");
|
|
}
|
|
if(identity_number("10")!=10 || identity_number("11")!=11)throw Error("multidigit identity changed");
|
|
for(const auto& value:{"", "010", "04", "-1", "+1", "1x"}){
|
|
bool rejected=false;try{identity_number(value);}catch(const Error&){rejected=true;}
|
|
if(!rejected)throw Error("malformed identity accepted");
|
|
}
|
|
for(const auto& name:{"", "nativehoof", "NativeHoof", "Ab1", "Abcdefghijklm"}) {
|
|
bool rejected=false;try{request(name,6,0);}catch(const Error&){rejected=true;}
|
|
if(!rejected)throw Error("invalid name accepted");
|
|
}
|
|
for(auto row:{std::array<unsigned,3>{0,1,0},{10,7,0},{1,11,0},{9,1,2},{33,1,0},{1,12,0}}) {
|
|
bool rejected=false;try{request("Nativehoof",row[0],row[2],row[1]);}catch(const Error&){rejected=true;}
|
|
if(!rejected)throw Error("unsupported identity accepted");
|
|
}
|
|
if(result(Bytes{0x2E})!=0x2E || result(Bytes{0x31})!=0x31 || result(Bytes{0x33})!=0x33)throw Error("create result changed");
|
|
for(const auto& body:{Bytes{},Bytes{0x2E,0}}) {
|
|
bool rejected=false;try{result(body);}catch(const Error&){rejected=true;}
|
|
if(!rejected)throw Error("malformed create result accepted");
|
|
}
|
|
Character c{};c.guid=123;c.name="Nativehoof";c.race=6;c.cls=1;c.gender=0;c.level=1;
|
|
if(!matching({c},c.name,6,0) || matching({c},"Other",6,0))throw Error("roster reuse mismatch");
|
|
bool rejected=false;try{matching({c,c},c.name,6,0);}catch(const Error&){rejected=true;}
|
|
if(!rejected)throw Error("duplicate roster identity accepted");
|
|
rejected=false;try{matching({c},c.name,6,1);}catch(const Error&){rejected=true;}
|
|
if(!rejected)throw Error("conflicting roster identity accepted");
|
|
rejected=false;try{matching({c},c.name,6,0,7);}catch(const Error&){rejected=true;}
|
|
if(!rejected)throw Error("conflicting roster class accepted");
|
|
c.name="Nativeelf";c.race=10;c.cls=4;c.gender=1;
|
|
if(!matching({c},c.name,10,1,4))throw Error("High Elf Rogue reuse mismatch");
|
|
std::cout<<"PASS Classic create goldens, all59 source pairs, source results, multidigit arguments and roster identity guards\n";
|
|
}
|
|
}
|
|
int main(int argc,char** argv) {
|
|
try {
|
|
if(argc==2 && std::string_view(argv[1])=="--self-test"){self_test();return 0;}
|
|
std::string name;unsigned race=0,gender=2,class_id=1;
|
|
for(int i=1;i<argc;i+=2) {
|
|
if(i+1>=argc)throw Error("missing public argument");
|
|
std::string_view key=argv[i],value=argv[i+1];
|
|
if(key=="--name")name=value;
|
|
else if(key=="--race")race=identity_number(value);
|
|
else if(key=="--class")class_id=identity_number(value);
|
|
else if(key=="--gender" && (value=="0" || value=="1"))gender=value[0]-'0';
|
|
else throw Error("invalid public argument");
|
|
}
|
|
const auto creation=request(name,race,gender,class_id);
|
|
std::array<std::string,5> input;
|
|
for(auto& line:input)if(!std::getline(std::cin,line) || line.empty() || line.size()>1024 ||
|
|
line.find_first_of("\r\0",0,2)!=std::string::npos)throw Error("invalid private input framing");
|
|
if(input[0]!="GW_LOCAL_WARRIOR_FIXTURE_V1" || input[1].size()>128 ||
|
|
input[2][0]!='/' || input[3][0]!='/' || input[4][0]!='/')throw Error("invalid private input contract");
|
|
LegacyLogin login(3724,input[1],input[2],input[3]);
|
|
const auto& realms=login.realms();size_t selected=realms.size();
|
|
for(size_t i=0;i<realms.size();++i)if(!realms[i].offline() && realms[i].address=="127.0.0.1:8090") {
|
|
if(selected!=realms.size())throw Error("ambiguous real local realm");
|
|
selected=i;
|
|
}
|
|
if(selected==realms.size())throw Error("real local realm unavailable");
|
|
LegacySession session(login,selected,input[4],5875);
|
|
if(const auto* existing=matching(session.roster(),name,race,gender,class_id)){output("reused",*existing);return 0;}
|
|
std::cout<<"CREATE_ATTEMPT"<<std::endl;
|
|
session.send(0x36,creation);
|
|
const auto outcome=result(await(session,0x3A).body);
|
|
std::cout<<"CREATE_RESULT "<<unsigned(outcome)<<std::endl;
|
|
if(outcome!=0x2E)return 3;
|
|
session.send(0x37,{});
|
|
const auto roster=characters(await(session,0x3B).body);
|
|
const auto* created=matching(roster,name,race,gender,class_id);
|
|
if(!created)throw Error("successful creation missing from actual roster");
|
|
output("created",*created);return 0;
|
|
} catch(...) {
|
|
std::cerr<<"Local fixture operation failed; private inputs omitted. Inspect the public journal; do not blindly retry creation.\n";
|
|
return 1;
|
|
}
|
|
}
|