feat: add account point rewards and extended item storage
Implement configurable kill rewards with account-wide daily limits, transactional deduplication, and game-to-db retries. Add the approved wide rules and tested isolation tooling. Stage wear40 equipment and persistent extra item metadata with an explicit migration plan and client revision gate. Track all 168 remaining offers; sixteen have staged data/assets, while live acceptance and other systems remain incomplete. This commit is not a production deployment.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Build game/db without either Makefile's production installation default."""
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
|
||||
|
||||
def main():
|
||||
p = argparse.ArgumentParser(description=__doc__)
|
||||
p.add_argument('--source', type=Path, required=True, help='directory containing server/ and extern/')
|
||||
p.add_argument('--output', type=Path, required=True)
|
||||
p.add_argument('--target', choices=['game', 'db'], required=True)
|
||||
p.add_argument('--jobs', type=int, default=1)
|
||||
a = p.parse_args()
|
||||
source, output = a.source.resolve(), a.output.resolve()
|
||||
for destination in (output, (output/'bin').resolve(), (output/'work').resolve()):
|
||||
if destination == Path('/usr/metin2/server') or Path('/usr/metin2/server') in destination.parents:
|
||||
p.error('build outputs must not be inside the production server tree')
|
||||
for name in ('bin', 'work', 'obj-'+a.target):
|
||||
(output/name).mkdir(parents=True, exist_ok=True)
|
||||
# DB uses DBDIR, game uses GAMEDIR. Always override both, even when building one target.
|
||||
subprocess.run(['gmake', '-j%d' % max(1, a.jobs), 'BINDIR='+str(output/'work'),
|
||||
'GAMEDIR='+str(output/'bin'), 'DBDIR='+str(output/'bin'),
|
||||
'OBJDIR='+str(output/('obj-'+a.target))],
|
||||
cwd=source/'server'/a.target/'src', check=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -22,6 +22,13 @@ CREATE TABLE IF NOT EXISTS port_itemshop_orders (
|
||||
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;
|
||||
CREATE TABLE IF NOT EXISTS port_point_rewards (
|
||||
token CHAR(32) CHARACTER SET ascii COLLATE ascii_bin PRIMARY KEY,
|
||||
account_id INT UNSIGNED NOT NULL,player_id INT UNSIGNED NOT NULL,vnum INT UNSIGNED NOT NULL,
|
||||
requested INT UNSIGNED NOT NULL,amount INT UNSIGNED NOT NULL,reward_day DATE NOT NULL,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
KEY daily_account(account_id,reward_day)
|
||||
) ENGINE=InnoDB;
|
||||
ALTER TABLE ishop_data ENGINE=InnoDB;
|
||||
ALTER TABLE item_award ENGINE=InnoDB;
|
||||
ALTER TABLE `{a.account}`.account ENGINE=InnoDB;
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Plan/apply the 32->40 wear-slot migration with cores/db stopped and a full backup.
|
||||
|
||||
The saved plan contains exact row IDs and before/after values. Reapplying that same plan
|
||||
is safe after interruption; never regenerate a plan from partially migrated data.
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
NAME = 'ava2-shop-wear-40'
|
||||
|
||||
|
||||
def quickslots(blob):
|
||||
if not blob:
|
||||
return blob
|
||||
if len(blob) != 108:
|
||||
raise ValueError('Expected 36 three-byte quick slots')
|
||||
output = bytearray(blob)
|
||||
for index in range(0, len(blob), 3):
|
||||
kind, lo, hi = blob[index:index+3]
|
||||
pos = lo | hi << 8
|
||||
if kind == 1 and (257 <= pos <= 268 or 287 <= pos <= 302):
|
||||
output[index+1:index+3] = (pos+8).to_bytes(2, 'little')
|
||||
return bytes(output)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--player', required=True)
|
||||
parser.add_argument('--plan', type=Path, required=True)
|
||||
parser.add_argument('--apply', action='store_true')
|
||||
args = parser.parse_args()
|
||||
if not re.fullmatch('[A-Za-z0-9_]+', args.player):
|
||||
parser.error('Invalid database name')
|
||||
|
||||
def sql(query):
|
||||
result = subprocess.run(['mysql', '-N', '-B', args.player], input=query,
|
||||
text=True, capture_output=True, check=True)
|
||||
return [line.split('\t') for line in result.stdout.splitlines()]
|
||||
|
||||
sql('CREATE TABLE IF NOT EXISTS mt_migration(name VARCHAR(64) PRIMARY KEY,done DATETIME);')
|
||||
if sql("SELECT name FROM mt_migration WHERE name='%s';" % NAME):
|
||||
print(NAME + ': already applied')
|
||||
return
|
||||
if args.plan.exists():
|
||||
plan = json.loads(args.plan.read_text())
|
||||
if plan['schema'] != args.player:
|
||||
raise RuntimeError('Plan belongs to another database')
|
||||
else:
|
||||
# Equipped DS cells are relative; belt cells in INVENTORY are absolute.
|
||||
bad = sql("SELECT i.id FROM item i LEFT JOIN item_proto p ON i.vnum=p.vnum "
|
||||
"WHERE i.window='EQUIPMENT' AND i.pos>=32 AND "
|
||||
"(i.pos>43 OR p.type IS NULL OR p.type NOT IN (29,30));")
|
||||
if bad:
|
||||
raise RuntimeError('Unexpected occupied extended equipment cells; inspect before migration')
|
||||
items = sql("SELECT id,pos FROM item WHERE (window='EQUIPMENT' AND pos BETWEEN 32 AND 43) "
|
||||
"OR (window='INVENTORY' AND pos BETWEEN 287 AND 302) ORDER BY pos DESC;")
|
||||
plan = {'schema': args.player, 'items': [[int(i), int(p), int(p)+8] for i, p in items],
|
||||
'quickslots': []}
|
||||
for table in ('player', 'player_deleted'):
|
||||
for pid, value in sql('SELECT id,HEX(quickslot) FROM `%s`;' % table):
|
||||
old = bytes.fromhex(value)
|
||||
new = quickslots(old)
|
||||
if old != new:
|
||||
plan['quickslots'].append([table, int(pid), old.hex(), new.hex()])
|
||||
args.plan.parent.mkdir(parents=True, exist_ok=True)
|
||||
args.plan.write_text(json.dumps(plan, indent=2)+'\n')
|
||||
args.plan.chmod(0o600)
|
||||
print('planned items=%d quickslots=%d' % (len(plan['items']), len(plan['quickslots'])))
|
||||
if not args.apply:
|
||||
return
|
||||
# Every update is conditional on its original value, allowing safe saved-plan replay.
|
||||
for item, old, new in plan['items']:
|
||||
row = sql('SELECT pos FROM item WHERE id=%d;' % item)
|
||||
if row not in ([[str(old)]], [[str(new)]]):
|
||||
raise RuntimeError('Item changed since planning; cores/db must stay stopped')
|
||||
sql('UPDATE item SET pos=%d WHERE id=%d AND pos=%d;' % (new, item, old))
|
||||
for table, pid, old, new in plan['quickslots']:
|
||||
row = sql('SELECT HEX(quickslot) FROM `%s` WHERE id=%d;' % (table, pid))
|
||||
if not row or row[0][0].lower() not in (old, new):
|
||||
raise RuntimeError('Quickslot changed since planning')
|
||||
sql("UPDATE `%s` SET quickslot=X'%s' WHERE id=%d AND HEX(quickslot)='%s';" %
|
||||
(table, new, pid, old.upper()))
|
||||
columns = sql("SELECT COLUMN_NAME FROM information_schema.columns WHERE TABLE_SCHEMA=DATABASE() "
|
||||
"AND TABLE_NAME='item' AND COLUMN_NAME='port_extra';")
|
||||
if not columns:
|
||||
sql("ALTER TABLE item ADD port_extra VARBINARY(69) NOT NULL DEFAULT ''; ")
|
||||
sql("INSERT INTO mt_migration(name,done) VALUES('%s',NOW());" % NAME)
|
||||
print(NAME + ': applied; retain the saved plan for recovery')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"points_mob_chance": 500,
|
||||
"points_mob_min": 1,
|
||||
"points_mob_max": 1,
|
||||
"points_stone_chance": 10000,
|
||||
"points_stone_min": 3,
|
||||
"points_stone_max": 8,
|
||||
"points_min_level": 1,
|
||||
"points_max_overlevel": 15,
|
||||
"points_daily_cap": 500
|
||||
}
|
||||
Reference in New Issue
Block a user