client: native AVA2 cube_renewal module (ENABLE_CUBE_RENEWAL_WORLDARD=1)
PythonCubeRenewal + PhaseGameCubeRenewal ported verbatim from AVA2: GC 221 fills the recipe list and calls BINARY_CUBE_RENEWAL_OPEN, the XXF uicuberenewal window sends CG 216 make/close (its 3rd "improve" argument is accepted and not sent). Replaces the read-only CubeRenewalScript.inc preview shim. Version mt20261026 so the server picks the new window. FakeLoginServer: CG 215/216 sizes and a /mt_test_cube_open fixture. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
d6617e01f7
commit
909fc8f851
@@ -219,6 +219,8 @@ enum : uint8_t {
|
||||
HDR_CG_XTRAP_ACK = 204,
|
||||
HDR_CG_DRAGON_SOUL_REFINE = 205,
|
||||
HDR_CG_STATE_CHECKER = 206,
|
||||
HDR_CG_AVA2_DROP = 215, // AVA2 drop query, 1+1+4
|
||||
HDR_CG_CUBE_RENEWAL = 216, // AVA2 cuberenewal, 1+1+4+4
|
||||
};
|
||||
|
||||
// GC (server -> client). Server packet.h (wire authority).
|
||||
@@ -1427,6 +1429,8 @@ constexpr int packet_size_cg(uint8_t h) {
|
||||
case HDR_CG_SAFEBOX_CHECKOUT: return sizeof(CGSafeboxCheckout);
|
||||
case HDR_CG_SAFEBOX_ITEM_MOVE: return sizeof(CGItemMove);
|
||||
case HDR_CG_STATE_CHECKER: return 1;
|
||||
case HDR_CG_AVA2_DROP: return 6;
|
||||
case HDR_CG_CUBE_RENEWAL: return 10;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -903,6 +903,13 @@ bool FakeLoginServer::ServeGame(Connection& c, int index)
|
||||
if (!ok)
|
||||
return Fail(name + ": send GC_EXCHANGE");
|
||||
}
|
||||
if (header == HDR_CG_CUBE_RENEWAL)
|
||||
{
|
||||
std::uint32_t index = 0, count = 0;
|
||||
std::memcpy(&index, packet + 2, 4);
|
||||
std::memcpy(&count, packet + 6, 4);
|
||||
Event(name + ":cube_renewal " + std::to_string(packet[1]) + " " + std::to_string(index) + " " + std::to_string(count));
|
||||
}
|
||||
// CInputMain::Chat (input_main.cpp): the line comes back to the speaker (PacketAround includes them)
|
||||
// as a CHAT_TYPE_TALKING GC_CHAT "<name> : <text>" carrying their vid and empire.
|
||||
if (header == HDR_CG_CHAT)
|
||||
@@ -941,6 +948,19 @@ bool FakeLoginServer::ServeGame(Connection& c, int index)
|
||||
if (!c.Send(chat) || !c.Send(cmd.c_str(), cmd.size() + 1)) return Fail(name + ": biolog reply");
|
||||
}
|
||||
}
|
||||
else if (text == "/mt_test_cube_open" && std::getenv("MT_TEST_CUBE")) {
|
||||
// cube.cpp CubeRenewal_Open: CLEAR, one DATES per recipe, LOADING, OPEN (GC 221, 167 bytes).
|
||||
auto cube=[&](std::uint8_t sub,bool row) {
|
||||
std::uint8_t pkt[167]={};pkt[0]=221;pkt[1]=sub;
|
||||
if(row) {
|
||||
const std::uint32_t head[4]={20383,0,19,1};std::memcpy(pkt+2,head,sizeof(head));
|
||||
const std::int32_t tail[12]={30006,1,0,0,0,0,0,0,0,0,100,50};std::memcpy(pkt+19,tail,sizeof(tail));
|
||||
std::memcpy(pkt+67,"WORLDARD",8);
|
||||
}
|
||||
return c.Send(pkt,sizeof(pkt));
|
||||
};
|
||||
if(!cube(1,false)||!cube(2,true)||!cube(3,false)||!cube(0,false))return Fail(name+": cube renewal open");
|
||||
}
|
||||
else if (text.rfind("/mt_features ",0)==0) {
|
||||
std::istringstream in(text);std::string command,kind;unsigned version=0,request=0,subject=0,offset=0;
|
||||
in>>command>>version>>request>>kind>>subject>>offset;
|
||||
@@ -949,21 +969,7 @@ bool FakeLoginServer::ServeGame(Connection& c, int index)
|
||||
return c.Send(chat)&&c.Send(cmd.c_str(),cmd.size()+1);
|
||||
};
|
||||
const std::string r=std::to_string(request);
|
||||
if(kind=="cap") {if(!reply("MTF1 cap "+r+" 1 "+(std::getenv("MT_TEST_CUBE")?"4159":std::getenv("MT_TEST_QUIVER")?"2111":"63")+" 1700000000"))return Fail(name+": feature cap");}
|
||||
else if(kind=="cube" && std::getenv("MT_TEST_CUBE")) {
|
||||
if(!reply("MTF1 begin "+r+" cube 20383 0 1 0 1700000000")||
|
||||
!reply("MTF1 recipe "+r+" 0 1 1111111111111111 2222222222222222 19 1 0 100 50 0 574f524c44415244 1 30006 1")||
|
||||
!reply("MTF1 end "+r+" 1"))return Fail(name+": cube catalogue");
|
||||
}
|
||||
else if(kind=="cubecheck" && std::getenv("MT_TEST_CUBE")) {
|
||||
std::vector<std::pair<std::string,int64_t>> rows={{"revision_hi",0x22222222},{"revision_lo",0x22222222},
|
||||
{"attempts",offset},{"gold_required",int64_t(offset)*100},{"gold_available",1000},{"materials_ok",1},
|
||||
{"gold_ok",1},{"mutation_enabled",0},{"reward_maximum",offset},{"capacity_reserved",0},{"copy_required",0},
|
||||
{"material1",30006},{"needed1",offset},{"available1",offset}};
|
||||
if(!reply("MTF1 begin "+r+" cubecheck "+std::to_string(subject)+" "+std::to_string(offset)+" "+std::to_string(rows.size())+" 0 1700000000"))return Fail(name+": cube preflight begin");
|
||||
for(unsigned i=0;i<rows.size();++i)if(!reply("MTF1 stat "+r+" "+std::to_string(i)+" "+rows[i].first+" "+std::to_string(rows[i].second)))return Fail(name+": cube preflight row");
|
||||
if(!reply("MTF1 end "+r+" "+std::to_string(rows.size())))return Fail(name+": cube preflight end");
|
||||
}
|
||||
if(kind=="cap") {if(!reply("MTF1 cap "+r+" 1 "+(std::getenv("MT_TEST_QUIVER")?"2111":"63")+" 1700000000"))return Fail(name+": feature cap");}
|
||||
else if(kind=="quiver" && std::getenv("MT_TEST_QUIVER")) {
|
||||
if(!reply("MTF1 begin "+r+" quiver 0 0 0 0 1700000000") || !reply("MTF1 end "+r+" 0"))return Fail(name+": quiver ack");
|
||||
std::uint8_t state[6]={219,0,0,0,0,9};std::uint32_t vid=kMainVID;
|
||||
|
||||
@@ -553,18 +553,17 @@ int main(int argc, char** argv)
|
||||
" item.SelectItem(_pack_vnum)\n"
|
||||
" assert item.GetItemType()==_pack_type and item.GetItemSubType()==0, (_pack_vnum,item.GetItemType(),item.GetItemSubType())\n"));
|
||||
}
|
||||
CHECK(py("import cube_renewal, app, player\nassert not app.ENABLE_CUBE_RENEWAL_WORLDARD\n_cube_gold=player.GetElk()\n_cube_materials=player.GetItemCountByVnum(30006)\ncube_renewal.LoadCatalogue(20383)"));
|
||||
// AVA2 cuberenewal: GC 221 fills the list and opens the window, CG 216 carries make/close.
|
||||
CHECK(py("import cube_renewal, app\nassert app.ENABLE_CUBE_RENEWAL_WORLDARD\nimport net\nnet.SendChatPacket('/mt_test_cube_open')"));
|
||||
CHECK(pump_until(8,[] {return py_true("cube_renewal.CountDates()==1");}));
|
||||
CHECK(py("assert cube_renewal.GetDates(0)==(19,1,False,30006,1,0,0,0,0,0,0,0,0,100,50,'WORLDARD')"));
|
||||
if(std::getenv("MT_TEST_CUBE_LAYOUT")) {
|
||||
CHECK(py("_stream.curPhaseWindow.BINARY_Cube_Open(20383)"));
|
||||
CHECK(pump_until(8,[] {return py_true("cube_renewal._window is not None and cube_renewal._window.IsShow() and cube_renewal._readonly");}));
|
||||
CHECK(py("cube_renewal.CubeRenewalMakeItem(0,3)"));
|
||||
} else CHECK(py("cube_renewal.CheckBatch(0,3)"));
|
||||
CHECK(pump_until(8,[] {return py_true("cube_renewal._last_preflight is not None");}));
|
||||
CHECK(py("assert cube_renewal._last_error is None\nassert cube_renewal._last_preflight['gold_required']==300\nassert cube_renewal._last_preflight['mutation_enabled']==0\nassert player.GetElk()==_cube_gold\nassert player.GetItemCountByVnum(30006)==_cube_materials\nassert cube_renewal.CheckBatch(0,101)==0\ncube_renewal.CubeRenewalClose()\nassert cube_renewal.CountDates()==0\napp.Exit()"));
|
||||
CHECK(py("assert cube_renewal.GetDates(0)==(19,1,False,30006,1,0,0,0,0,0,0,0,0,100,50,'WORLDARD'), cube_renewal.GetDates(0)\nassert cube_renewal.GetDates(1)[0]==0"));
|
||||
if(std::getenv("MT_TEST_CUBE_LAYOUT"))
|
||||
CHECK(pump_until(8,[] {return py_true("_stream.curPhaseWindow.interface.wndCubeRenewal.IsShow()");}));
|
||||
CHECK(py("cube_renewal.CubeRenewalMakeItem(0,3,-1)\ncube_renewal.CubeRenewalClose()"));
|
||||
CHECK(pump_until(8,[&server] {bool make=false,close=false;for(const auto& e:server->Events()){make|=e.find(":cube_renewal 4 0 3")!=std::string::npos;close|=e.find(":cube_renewal 5 0 0")!=std::string::npos;}return make&&close;}));
|
||||
CHECK(py("app.Exit()"));
|
||||
pump_until(2,[] {return !PythonBoot::IsAppLooping();});PythonBoot::Stop();
|
||||
std::printf("cube read-only catalogue/preflight fixture: %s\n",g_failures?"FAILED":"PASS");return g_failures?1:0;
|
||||
std::printf("cube renewal packet fixture: %s\n",g_failures?"FAILED":"PASS");return g_failures?1:0;
|
||||
}
|
||||
if (server && std::getenv("MT_TEST_AUTOHUNT_BATCH")) {
|
||||
CHECK(CPythonPlayer::Instance().NEW_GetMainActorPtr());
|
||||
@@ -1922,7 +1921,7 @@ int main(int argc, char** argv)
|
||||
CHECK(py("import cube_renewal"));
|
||||
CHECK(py_true("cube_renewal.CountDates() == 0"));
|
||||
CHECK(py_true("cube_renewal.GetDates(0)[0] == 0"));
|
||||
CHECK(py("try:\n cube_renewal.CubeRenewalMakeItem(0, 1)\nexcept RuntimeError:\n pass\nelse:\n raise AssertionError('unsupported craft silently succeeded')\n"));
|
||||
CHECK(py_true("app.ENABLE_CUBE_RENEWAL_WORLDARD == 1"));
|
||||
|
||||
// F24: Full server ranking system (uirank)
|
||||
CHECK(py_true("app.ENABLE_RANKING_SYSTEM == 1"));
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
"""Run the real modern Cube controller with explicit transport/UI substitutes."""
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import types
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
ROOT=Path(__file__).resolve().parents[2]
|
||||
|
||||
|
||||
class CubeCatalogueTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.requests=[];self.replies=[]
|
||||
mods={n:types.ModuleType(n) for n in ('game','chat','mt_feature_service','mt_biolog')}
|
||||
mods['game'].GameWindow=type('GameWindow',(),dict(BINARY_Cube_Open=lambda s,n:None,BINARY_Cube_Close=lambda s:None,Close=lambda s:None))
|
||||
mods['chat'].CHAT_TYPE_INFO=1;mods['chat'].AppendChat=lambda *a:None
|
||||
mods['mt_biolog'].L=lambda text:text
|
||||
class Service:
|
||||
def Request(service,*args):self.requests.append(args);return len(self.requests)
|
||||
mods['mt_feature_service'].g_service=Service()
|
||||
raw=(ROOT/'src/platform/ScriptLib/CubeRenewalScript.inc').read_text()
|
||||
self.ns={}
|
||||
with patch.dict(sys.modules,mods):exec(raw.split('R"PY(',1)[1].rsplit(')PY";',1)[0],self.ns)
|
||||
|
||||
def row(self,i=1,revision='2222222222222222',catalogue='1111111111111111'):
|
||||
return dict(id=i,catalogue=catalogue,revision=revision,reward=19,count=1,stackable=False,
|
||||
gold=100,percent=50,copy=False,category='WORLDARD',materials=[(30006,2)])
|
||||
|
||||
def page(self,rows,total=None,offset=0):
|
||||
self.requests[-1][3](dict(rows=rows,total=len(rows) if total is None else total,offset=offset),None)
|
||||
|
||||
def load(self):
|
||||
self.ns['LoadCatalogue'](20383,lambda d,e:self.replies.append((d,e)))
|
||||
self.page([self.row()])
|
||||
|
||||
def result(self,**changes):
|
||||
values=dict(revision_hi=0x22222222,revision_lo=0x22222222,attempts=3,gold_required=300,
|
||||
gold_available=1000,materials_ok=1,gold_ok=1,mutation_enabled=0,capacity_reserved=0,
|
||||
reward_maximum=3,copy_required=0,material1=30006,needed1=6,available1=6)
|
||||
values.update(changes);return dict(rows=list(values.items()))
|
||||
|
||||
def test_no_partial_catalogue_and_exact_original_tuple(self):
|
||||
self.ns['LoadCatalogue'](20383)
|
||||
self.page([self.row(i) for i in range(1,9)],9)
|
||||
self.assertEqual(self.ns['CountDates'](),0)
|
||||
self.page([self.row(9)],9,8)
|
||||
self.assertEqual(self.ns['CountDates'](),9)
|
||||
self.assertEqual(self.ns['GetDates'](0),(19,1,False,30006,2,0,0,0,0,0,0,0,0,100,50,'WORLDARD'))
|
||||
|
||||
def test_mixed_pages_and_stale_callback_never_commit(self):
|
||||
self.ns['LoadCatalogue'](20383)
|
||||
self.page([self.row(i) for i in range(1,9)],9)
|
||||
self.page([self.row(9,catalogue='aaaaaaaaaaaaaaaa')],9,8)
|
||||
self.assertEqual(self.ns['CountDates'](),0)
|
||||
self.ns['LoadCatalogue'](20383);callback=self.requests[-1][3]
|
||||
self.ns['CubeRenewalClose']();callback(dict(rows=[self.row()],total=1,offset=0),None)
|
||||
self.assertEqual(self.ns['CountDates'](),0)
|
||||
|
||||
def test_missing_ui_preserves_classic_without_enabling_crafting(self):
|
||||
self.ns['OpenPreview'](20383)
|
||||
with patch.dict(sys.modules,{'uiCubeRenewal':None}):self.page([self.row()])
|
||||
self.assertEqual(self.ns['_last_error'],'cube_ui_unavailable')
|
||||
self.assertFalse(self.ns['_readonly'])
|
||||
self.assertIsNone(self.ns['_handler'])
|
||||
self.assertIsNone(self.ns['_window'])
|
||||
|
||||
def test_preflight_is_read_only_and_revision_bound(self):
|
||||
self.load();self.ns['CheckBatch'](0,3,lambda d,e:self.replies.append((d,e)))
|
||||
self.assertEqual(self.requests[-1][:3],('cubecheck',1,3))
|
||||
self.requests[-1][3](self.result(),None);self.assertIsNone(self.replies[-1][1])
|
||||
for update in (dict(revision_lo=1),dict(gold_required=301),dict(materials_ok=0),dict(available1=5),dict(extra=1)):
|
||||
self.ns['CheckBatch'](0,3,lambda d,e:self.replies.append((d,e)))
|
||||
self.requests[-1][3](self.result(**update),None)
|
||||
self.assertIsNone(self.replies[-1][0]);self.assertIsNotNone(self.replies[-1][1])
|
||||
with self.assertRaises(RuntimeError):self.ns['CubeRenewalMakeItem'](0,3)
|
||||
self.ns['_readonly']=True;self.ns['CubeRenewalMakeItem'](0,3)
|
||||
self.assertTrue(all(r[0] in ('cube','cubecheck') for r in self.requests))
|
||||
|
||||
def test_newer_check_or_closed_window_discards_old_reply(self):
|
||||
self.load();self.ns['CheckBatch'](0,3);old=self.requests[-1][3]
|
||||
self.ns['CheckBatch'](0,4);old(self.result(),None)
|
||||
self.assertIsNone(self.ns['_last_preflight'])
|
||||
latest=self.requests[-1][3];self.ns['CubeRenewalClose']();latest(self.result(attempts=4),None)
|
||||
self.assertIsNone(self.ns['_last_preflight'])
|
||||
self.load();self.ns['CheckBatch'](0,3);self.requests[-1][3](self.result(),None)
|
||||
self.assertIsNotNone(self.ns['_last_preflight'])
|
||||
self.ns['LoadCatalogue'](20384)
|
||||
self.assertIsNone(self.ns['_last_preflight'])
|
||||
self.assertEqual(self.ns['CheckBatch'](0,3),0)
|
||||
self.assertEqual(self.ns['_last_error'],'invalid')
|
||||
|
||||
|
||||
if __name__=='__main__':unittest.main()
|
||||
Reference in New Issue
Block a user