Port native AVA2 itemshop with transactional purchases and verified catalogue

This commit is contained in:
shen
2026-10-19 07:08:51 -07:00
parent abda2c1cda
commit 32831010c0
21 changed files with 2676 additions and 8 deletions
+35
View File
@@ -0,0 +1,35 @@
# Native AVA2 item shop
Active UI is `uiitemshopnew.py`. GC93 retains the native catalogue/log layouts;
GD/DG76 transports authenticated account/character requests to the DB coordinator.
Purchase requests add a durable random token and the confirmed item/total quote.
`data/ava2-itemshop/original-products.tsv` contains all 217 original offers recovered
from the supplied MySQL56 archive. `source.json` records hashes. No prices are invented.
`compatibility.json` records 55 absent prototypes, 55 ITEM_NONE placeholders and 107
actual types needing item-system verification. `verified-products.json` selects 49
existing implemented mount, mount-skin, fixed-enchant and third-hand products.
Generate migration SQL with explicit configured schema names, review it and back up
account/award data before executing it:
```
python3 tools/ava2-itemshop/migrate.py --player player_sb --account account_sb --output /tmp/itemshop.sql
python3 tools/ava2-itemshop/enable_verified.py --player player_sb --output /tmp/itemshop-enable.sql
```
The migration uses InnoDB for account, catalogue, orders and awards. Account/player SQL
configurations must target the same MySQL host and port. Purchase failures leave all
four unchanged. A transaction temporarily disables reconnect and caps lock waits at
three seconds, restoring the original connection options afterwards. Unknown COMMIT
outcomes retry the same order. Unique `(account_id,token)` orders survive process restarts.
The old prototype loader indexed vector pointers before sorting; it now sorts before building the index so lookup keys always match their templates.
Awards use the existing mall redemption path; non-stackable purchases create separate
award rows. New clients use revision mt20261020. Legacy clients cannot request GC93.
No web recharge service or wheel reward service is enabled.
Acceptance evidence: `metin2-client/docs/AVA2-ITEMSHOP.md` and
`metin2-client/audit/evidence/itemshop/`. Only sbtest was changed; production binaries,
prices, balances and catalogue activation were not deployed by this task.
+12
View File
@@ -0,0 +1,12 @@
#!/usr/bin/env python3
"""Emit SQL enabling original offers backed by implemented item systems. Never executes SQL."""
import argparse,json,re
from pathlib import Path
p=argparse.ArgumentParser();p.add_argument('--player',required=True);p.add_argument('--output',type=Path,required=True);a=p.parse_args()
if not re.fullmatch('[A-Za-z0-9_]+',a.player):p.error('invalid schema')
root=Path(__file__).resolve().parents[2];rows=json.loads((root/'data/ava2-itemshop/verified-products.json').read_text())['products']
sql='USE `'+a.player+'`;\n'
for row in rows:
sql+='UPDATE ishop_data s JOIN item_proto p ON p.vnum=s.itemVnum SET s.enabled=1 WHERE s.id=%d AND s.itemVnum=%d AND p.type<>0;\n'%(row['id'],row['vnum'])
sql+='SELECT categoryType,categorySubType,COUNT(*) FROM ishop_data WHERE enabled=1 GROUP BY categoryType,categorySubType;\n'
a.output.parent.mkdir(parents=True,exist_ok=True);a.output.write_text(sql);print('SQL generated for',len(rows),'verified original offers; original prices preserved')
+45
View File
@@ -0,0 +1,45 @@
#!/usr/bin/env python3
"""Emit a reviewable migration for explicitly named isolated or production schemas.
Run mysql separately after backup. Native products are disabled until compatibility review.
"""
import argparse,re
from pathlib import Path
p=argparse.ArgumentParser();p.add_argument('--player',required=True);p.add_argument('--account',required=True);p.add_argument('--output',type=Path,required=True);a=p.parse_args()
for name in (a.player,a.account):
if not re.fullmatch('[A-Za-z0-9_]+',name):p.error('invalid schema')
sql=f'''USE `{a.player}`;
CREATE TABLE IF NOT EXISTS ishop_data (
id INT UNSIGNED PRIMARY KEY, categoryType INT NOT NULL, categorySubType INT NOT NULL,
itemVnum INT UNSIGNED NOT NULL,itemPrice BIGINT UNSIGNED NOT NULL,discount INT NOT NULL DEFAULT 0,
offerTime DATETIME NULL,addedTime DATETIME NULL,sellCount BIGINT UNSIGNED NOT NULL DEFAULT 0,
week_limit INT NOT NULL DEFAULT 0,month_limit INT NOT NULL DEFAULT 0,maxSellCount INT NOT NULL DEFAULT -1,
enabled TINYINT NOT NULL DEFAULT 0
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS port_itemshop_orders (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,account_id INT UNSIGNED NOT NULL,
token CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,product INT UNSIGNED NOT NULL,vnum INT UNSIGNED NOT NULL,
quantity INT UNSIGNED NOT NULL,paid BIGINT UNSIGNED NOT NULL,player_name VARCHAR(24) NOT NULL,ip VARCHAR(45) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE KEY request_once(account_id,token), KEY limits_by_account(account_id,product,created_at)
) ENGINE=InnoDB;
ALTER TABLE ishop_data ENGINE=InnoDB;
ALTER TABLE item_award ENGINE=InnoDB;
ALTER TABLE `{a.account}`.account ENGINE=InnoDB;
'''
# Upgrade an existing native catalogue without replacing its products or sales history.
sql+="""SET @enabled_exists=(SELECT COUNT(*) FROM information_schema.columns WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='ishop_data' AND COLUMN_NAME='enabled');
SET @ddl=IF(@enabled_exists=0,'ALTER TABLE ishop_data ADD enabled TINYINT NOT NULL DEFAULT 0','SELECT 1');
PREPARE shop_ddl FROM @ddl; EXECUTE shop_ddl; DEALLOCATE PREPARE shop_ddl;
"""
# Coins are added by a separate conditional step, since MySQL 5.6 lacks ADD IF NOT EXISTS.
sql+=f'''SET @column_exists=(SELECT COUNT(*) FROM information_schema.columns WHERE TABLE_SCHEMA='{a.account}' AND TABLE_NAME='account' AND COLUMN_NAME='coins');
SET @ddl=IF(@column_exists=0,'ALTER TABLE `{a.account}`.account ADD coins BIGINT UNSIGNED NOT NULL DEFAULT 0','SELECT 1');
PREPARE shop_ddl FROM @ddl; EXECUTE shop_ddl; DEALLOCATE PREPARE shop_ddl;
'''
source=Path(__file__).resolve().parents[2]/'data/ava2-itemshop/original-products.tsv'
for line in source.read_text().splitlines():
row=line.split('\t');assert len(row)==12
values=[str(int(v)) if i not in (6,7) else ('NULL' if v.startswith('0000') else "'"+v+"'") for i,v in enumerate(row)]
sql+='INSERT IGNORE INTO ishop_data(id,categoryType,categorySubType,itemVnum,itemPrice,discount,offerTime,addedTime,sellCount,week_limit,month_limit,maxSellCount) VALUES('+','.join(values)+');\n'
a.output.parent.mkdir(parents=True,exist_ok=True);a.output.write_text(sql)
print('217 native products imported disabled; review compatibility before enabling')