Port native AVA2 itemshop with transactional purchases and verified catalogue
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compile the production wire and total-price helper, including malformed bounds."""
|
||||
import subprocess,tempfile,unittest
|
||||
from pathlib import Path
|
||||
ROOT=Path(__file__).resolve().parents[2]
|
||||
class ItemShop(unittest.TestCase):
|
||||
def test_native_wire_and_integer_quantity_discount(self):
|
||||
source=r'''
|
||||
#include "src/server/common/ava2_itemshop.h"
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
int main(){
|
||||
static_assert(sizeof(Ava2ShopRequest)==103,"request");
|
||||
static_assert(sizeof(Ava2ShopProduct)==49,"native catalogue");
|
||||
static_assert(sizeof(Ava2ShopLog)==90,"native log");
|
||||
int64_t price=123;
|
||||
assert(Ava2ShopTotal(99,2,25,price) && price==148);
|
||||
assert(Ava2ShopTotal(1,1,99,price) && price==0);
|
||||
assert(Ava2ShopTotal(1000000000000LL,20,0,price) && price==20000000000000LL);
|
||||
assert(!Ava2ShopTotal(-1,1,0,price));assert(!Ava2ShopTotal(1000000000001LL,1,0,price));
|
||||
assert(!Ava2ShopTotal(1,0,0,price));assert(!Ava2ShopTotal(1,21,0,price));assert(!Ava2ShopTotal(1,1,101,price));
|
||||
Ava2ShopProduct p={};p.id=0x01020304;p.vnum=71084;p.price=99;p.discount=25;p.stock=-1;
|
||||
const unsigned char* bytes=reinterpret_cast<const unsigned char*>(&p);
|
||||
assert(bytes[0]==4 && bytes[3]==1 && bytes[20]==25 && bytes[45]==255);
|
||||
}
|
||||
'''
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
p=Path(d);(p/'test.cpp').write_text(source)
|
||||
subprocess.run(['c++','-std=c++17','-I'+str(ROOT),str(p/'test.cpp'),'-o',str(p/'test')],check=True);subprocess.run([str(p/'test')],check=True)
|
||||
def test_sorted_prototype_index_points_to_the_matching_item(self):
|
||||
source=(ROOT/'src/server/db/src/ClientManagerBoot.cpp').read_bytes().decode('latin1')
|
||||
body=source[source.index('bool CClientManager::InitializeItemTable()'):source.index('bool CClientManager::InitializeSkillTable()')]
|
||||
start=body.rindex('// END_OF_QUEST_ITEM_PROTO_DISABLE')
|
||||
tail=body[start:body.rfind('return true;')+len('return true;')]
|
||||
harness=r"""
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#define sys_log(...) ((void)0)
|
||||
#define itertype(c) decltype(c)::iterator
|
||||
using namespace std;
|
||||
using DWORD=unsigned;
|
||||
struct TItemTable { DWORD dwVnum;unsigned bType; };
|
||||
struct FCompareVnum { bool operator()(const TItemTable& a,const TItemTable& b)const {return a.dwVnum<b.dwVnum;} };
|
||||
struct Database {
|
||||
vector<TItemTable> m_vec_itemTable={{71084,3},{54051,3},{1,0},{71502,28}};
|
||||
map<DWORD,TItemTable*> m_map_itemTableByVnum;
|
||||
bool Build() { BODY }
|
||||
};
|
||||
int main(){ Database db;assert(db.Build());for(auto& row:db.m_map_itemTableByVnum)assert(row.first==row.second->dwVnum);assert(db.m_map_itemTableByVnum[54051]->bType==3);assert(db.m_map_itemTableByVnum[71502]->bType==28); }
|
||||
""".replace('BODY',tail)
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
p=Path(d);(p/'test.cpp').write_text(harness)
|
||||
subprocess.run(['c++','-std=c++17',str(p/'test.cpp'),'-o',str(p/'test')],check=True)
|
||||
subprocess.run([str(p/'test')],check=True)
|
||||
|
||||
if __name__=='__main__':unittest.main()
|
||||
@@ -103,8 +103,10 @@ if cpacket.is_file():
|
||||
assert 'static_assert(sizeof(TPacketCGSwitchbot) == 7 && sizeof(TPacketGCSwitchbot) == 7,' in client
|
||||
stream=(CLIENT/'PythonNetworkStreamPhaseGame.cpp').read_bytes().decode('latin1')
|
||||
# the EU branch (the one every locale.cfg build takes) keeps 1215955205 first for the atoi version check
|
||||
assert 'strncpy(kVersionPacket.timestamp, "1215955205 mt20261019", sizeof(kVersionPacket.timestamp)-1);' in stream
|
||||
assert 'strncpy(kVersionPacket.timestamp, "mt20261019", sizeof(kVersionPacket.timestamp)-1);' in stream
|
||||
modern=re.search(r'strncpy\(kVersionPacket.timestamp, "1215955205 mt(\d{8})"',stream)
|
||||
legacy=re.search(r'strncpy\(kVersionPacket.timestamp, "mt(\d{8})"',stream)
|
||||
assert modern and legacy and modern.group(1)==legacy.group(1)
|
||||
assert int(modern.group(1))>=20261016 # switchbot gate; newer features may advance this revision
|
||||
pyswitch=(CLIENT/'PythonSwitchbot.h').read_bytes().decode('latin1')
|
||||
ctable=pyswitch[pyswitch.index('struct TSwitchbotTable'):];ctable=ctable[:ctable.index('};')]
|
||||
assert re.findall(r'^\s*[A-Za-z_][\w:]*\s+(\w+)(?:\[[^;]*\])?;',ctable,re.M)==table,ctable
|
||||
|
||||
Reference in New Issue
Block a user