Author SHA1 Message Date
shenleiandClaude Opus 5.5 bc32475742 Record the batch chest channel5 live test
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 23:31:03 +09:00
shenleiandClaude Opus 5.5 4b4f32ed58 Add batch gift box opening (mt_chest)
AVA2 ENABLE_MULTI_CHEST port: /mt_chest 1 open CELL COUNT opens up to 200
gift boxes of one vnum across bag cells through the original UseItem path,
stops at 3 free cells, skips monster/debuff groups and reports the gains
as MTCH1 lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 23:24:11 +09:00
shenleiandClaude Opus 5.5 bcd318791e Record the attribute lock production deploy
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 23:11:29 +09:00
6 changed files with 299 additions and 1 deletions
+13 -1
View File
@@ -68,4 +68,16 @@ MTSB1 error lock CODE item equipped no_attr busy running slot max
- a new client session showed `lock 19 11209 10` (reloaded from the table);
- unlocking → 8 → 0, and the row was deleted;
- `log` has four `ATTR_LOCK` rows (hints 2, 10, 8, 0).
- Not done: Android device test and production deploy.
- Not done: Android device test.
## Production deployment
- 2026-10-15 16:08, approved by the user. All 203 live cores now run main `dc71593` (`game` sha256 `a8556bdc…`, the exact binary the channel-5 core was tested with, built in `/root/metin2-features-dev`). The db binary is unchanged. 0 players were online.
- Package `/root/deploy-features/20261015-attrlock` (`deploy.sh check|go|rollback`, `SHA256SUMS`). The previous `game`/`db` (boss deploy, `400e44f`) are in `/root/backup-bin/20261015-160813`. The 8 changed files were synced into `/usr/metin2/src`, and the replaced ones are in `src-before/`. Because `item.h` changed, a later `rebuild.sh build` must touch every game .cpp. `sh deploy.sh rollback` restores both; the `mt_item_attr_lock` table can stay, since old binaries ignore it.
- CH2–CH4 and the channel-5 core were started by hand after `start.sh 1`, giving 14 game cores plus db and auth.
- Live acceptance on CH1 (13000), same armour 11209 (item 20000178), scroll 71084:
- lock slot 1 → 2, slot 3 → 10, slot 0 → `error lock max`;
- 10 switchbot rolls (scrolls 133 → 123): (23,10) and (39,10) unchanged on every roll, the other slots changed;
- the row read `20000178 10`; a new session showed `lock 19 11209 10`;
- unlocking → 8 → 0 deleted the row, and four new `ATTR_LOCK` log rows were written;
- no `PortAttrLock` syserr entries.
+52
View File
@@ -0,0 +1,52 @@
# PORT batch chest opening, v1
Date: 2026-10-15. AVA2-style batch opening of gift boxes (reference: AVA2 `ENABLE_MULTI_CHEST`, `/chest_drop`, `CHARACTER::OpenChest`). Source: `src/server/game/src/port_chest.h` (header-only, included from `cmd_general.cpp`), command `mt_chest` (cmd.cpp). It reuses the quiet-INFO hook (`m_portQuietInfo` / `m_portLastInfo`) added for the switchbot. No packet header, no DB schema, no char.h/item.h change.
AVA2 rewrote the drop loop (`GiveItemFromSpecialItemGroupNew`, `AutoGiveItemChest`, cap 1000). That rewrite is not ported. Here every box goes through the original `CHARACTER::UseItem` → `UseItemEx` `ITEM_GIFTBOX` path, one box at a time, so the original checks, the `special_item_group` roll, gold/exp, `ItemLog` and consumption stay exactly as they are.
## Rules
- Only `ITEM_GIFTBOX` items whose special item group exists, is not empty and contains none of the give types `MOB`, `SLOW`, `DRAIN_HP`, `POISON`, `MOB_GROUP`. Boxes that spawn monsters or apply debuffs stay single-use (`error kind`). Other item types (e.g. `ITEM_USE` chests with quest scripts) are not batchable.
- The chosen cell is opened first while it still holds the box vnum; after that, any other bag cell with the same vnum. Most gift boxes on 203 have no stack flag, so a batch normally spans many cells. Items being exchanged are skipped.
- At most 200 boxes per command.
- Before each box the character must still have 3 free bag cells (`GetEmptyInventory(3)`). This keeps room for any reward, so `AutoGiveItem` never has to drop one on the ground. The loop stops with reason `full`.
- Busy: dead, stunned, warping, observer, `!CanHandleItem`, exchange, own shop, shop open, safebox, cube. Checked before the command and before each box.
- A box counts as opened only when the bag count of its vnum went down by exactly one. Anything else (the original path refused it, e.g. the dragon soul qualification) stops the loop with reason `rejected`. The last INFO line of that refusal is forwarded once.
- Per-box INFO lines are held back while the batch runs.
- Throttle: one command per 500 ms per player id.
## Protocol (CHAT_TYPE_COMMAND, version 1)
```
/mt_chest 1 open CELL COUNT CELL = bag cell, COUNT = 1..200, digits only (at most 5)
MTCH1 got VNUM COUNT one line per gained vnum (box vnum excluded), at most 40 lines
MTCH1 done VNUM ASKED OPENED REASON GOLD
MTCH1 error rate|invalid|busy|item|kind|full
```
- REASON: `done` (all asked boxes opened), `empty` (no box of this vnum left), `full` (fewer than 3 free cells), `busy`, `rejected`.
- GOLD: gold balance change over the batch.
- Gains are the difference between bag + dragon soul bag counts before and after the batch.
- A request with a version other than `1`, a token longer than 10 characters or more than 5 tokens is ignored silently.
There is no MTF1 capability bit (the mask stays 511). The client marks the server unsupported when no `MTCH1` reply arrives within 3 s and falls back to normal single use.
## Verification
- `tests/features/test_chest.py` compiles the production header against stubs of the `UseItem` gift-box contract (consume one box, gold, stacking reward, dragon soul reward, INFO lines). It covers:
- cross-cell order and the gains/gold summary with INFO held back;
- a stack, fewer asked than held, more asked than held (`empty`);
- the 3-free-cell stop (`full`, `error full`);
- refusal by the original path (`rejected`, INFO forwarded once);
- non-gift box, monster box, missing and empty group (`kind`);
- missing/exchanging item, busy, invalid input, silently ignored version, throttle.
- It also checks the cmd.cpp / cmd_general.cpp wiring.
- All `tests/features/test_*.py` pass.
- FreeBSD build of the game target in `/root/metin2-features-dev` (log `chest-build.log`, binary sha256 `412977c7d7fda073493533d5bee43812a8f48dcb63399f747db6180d24803853`). The live `/usr/metin2` binary was not replaced and no live service was restarted.
- Live test on 2026-10-15 against the channel-5 test core (port 13040, isolated binary) with the macOS native client as [SA]Admin, boxes created with `/item`:
- 50037 (stacking, 30 held), 10 asked → `done 50037 10 10 done 0`, 6 gained vnums matching the bag difference exactly;
- 50070 (not stacking, 4 boxes in 4 cells), all → `done 50070 4 4 done 100000`, gold balance +100000;
- 71036 (group spawns a monster) → `error kind`, nothing consumed; an immediate second command → `error rate`;
- remaining 20 of 50037 → `done 50037 20 20 done 0`, 11 gained vnums;
- plain right click without Ctrl still uses one box the original way.
- `log.log` only has the original path's rows (`SYSTEM`, `TREASURE_EXP`, `TREASURE_GOLD`). syserr shows only the pre-existing `new_quest_lv52` LUA_ERROR.
+2
View File
@@ -12,6 +12,7 @@ ACMD(do_port_biolog);
ACMD(do_port_features);
ACMD(do_port_switchbot);
ACMD(do_port_pickup);
ACMD(do_port_chest);
ACMD(do_user_horse_ride);
ACMD(do_user_horse_back);
ACMD(do_user_horse_feed);
@@ -289,6 +290,7 @@ struct command_info cmd_info[] =
{ "mt_features", do_port_features, 0, POS_DEAD, GM_PLAYER },
{ "mt_switchbot", do_port_switchbot, 0, POS_DEAD, GM_PLAYER },
{ "mt_pickup", do_port_pickup, 0, POS_DEAD, GM_PLAYER },
{ "mt_chest", do_port_chest, 0, POS_DEAD, GM_PLAYER },
{ "bio", do_port_biolog, 0, POS_DEAD, GM_PLAYER },
{ "biolog", do_port_biolog, 0, POS_DEAD, GM_PLAYER },
{ "server_bonuses", do_server_bonuses, 0, POS_DEAD, GM_PLAYER },
+1
View File
@@ -45,6 +45,7 @@
#include "port_features.h"
#include "port_switchbot.h"
#include "port_pickup.h"
#include "port_chest.h"
extern int g_server_id;
+115
View File
@@ -0,0 +1,115 @@
#ifndef METIN2_PORT_CHEST_H
#define METIN2_PORT_CHEST_H
// PORT: AVA2-style batch chest opening (ENABLE_MULTI_CHEST /chest_drop). AVA2 rewrote the drop loop
// (GiveItemFromSpecialItemGroupNew); here every box goes through the original CHARACTER::UseItem gift-box path,
// so its checks, special_item_group roll, gold/exp, ItemLog and consumption are unchanged. Boxes of one vnum are
// opened from the chosen cell first, then from any other cell (most gift boxes do not stack). Per-box INFO lines
// are held back and the gains are reported once as MTCH1 lines. Protocol: docs/FEATURE-CHEST.md.
#include <map>
#include <sstream>
#include <string>
#include <vector>
static const unsigned kPortChestMax=200, kPortChestReportVnums=40, kPortChestFreeCells=3;
static const DWORD kPortChestGapMs=500;
static std::map<DWORD,DWORD> g_portChestLastCommand;
static bool PortChestNumber(const std::string& text,unsigned& value) {
if(text.empty() || text.size()>5)return false;
value=0;
for(char c:text){if(c<'0'||c>'9')return false;value=value*10+unsigned(c-'0');}
return true;
}
// Gift boxes whose group only hands out items, gold or exp. Groups that spawn monsters, slow, poison or drain
// HP stay single-use: opening a stack of them at once would spawn every group around the player in one tick.
static bool PortChestBatchable(LPITEM item) {
if(item->GetType()!=ITEM_GIFTBOX)return false;
const CSpecialItemGroup* group=ITEM_MANAGER::instance().GetSpecialItemGroup(item->GetVnum());
if(!group || group->IsEmpty())return false;
const DWORD unsafe[]={CSpecialItemGroup::MOB,CSpecialItemGroup::SLOW,CSpecialItemGroup::DRAIN_HP,
CSpecialItemGroup::POISON,CSpecialItemGroup::MOB_GROUP};
for(DWORD kind:unsafe)if(group->Contains(kind))return false;
return true;
}
static bool PortChestBusy(LPCHARACTER ch) {
return ch->IsDead() || ch->IsStun() || ch->IsWarping() || ch->IsObserverMode() || !ch->CanHandleItem() ||
ch->GetExchange() || ch->GetMyShop() || ch->GetShopOwner() || ch->IsOpenSafebox() || ch->IsCubeOpen();
}
// Item counts by vnum over the bag and the dragon soul bag, where AutoGiveItem puts what a box gives.
static std::map<DWORD,long long> PortChestSnapshot(LPCHARACTER ch) {
std::map<DWORD,long long> counts;
for(int i=0;i<INVENTORY_MAX_NUM;++i)if(LPITEM item=ch->GetInventoryItem(i))counts[item->GetVnum()]+=item->GetCount();
for(int i=0;i<DRAGON_SOUL_INVENTORY_MAX_NUM;++i)
if(LPITEM item=ch->GetItem(TItemPos(DRAGON_SOUL_INVENTORY,i)))counts[item->GetVnum()]+=item->GetCount();
return counts;
}
// The box to open next: the chosen cell while it still holds this vnum, otherwise any bag cell that does.
static LPITEM PortChestNext(LPCHARACTER ch,unsigned cell,DWORD vnum) {
LPITEM item=ch->GetInventoryItem(cell);
if(item && item->GetVnum()==vnum && !item->IsExchanging())return item;
for(int i=0;i<INVENTORY_MAX_NUM;++i) {
item=ch->GetInventoryItem(i);
if(item && item->GetVnum()==vnum && !item->IsExchanging())return item;
}
return NULL;
}
static const char* PortChestOpen(LPCHARACTER ch,unsigned cell,unsigned asked) {
if(cell>=unsigned(INVENTORY_MAX_NUM) || !asked || asked>kPortChestMax)return "invalid";
if(PortChestBusy(ch))return "busy";
LPITEM first=ch->GetInventoryItem(cell);
if(!first || first->IsExchanging())return "item";
if(!PortChestBatchable(first))return "kind";
if(ch->GetEmptyInventory(kPortChestFreeCells)==-1)return "full";
const DWORD vnum=first->GetVnum();
const std::map<DWORD,long long> before=PortChestSnapshot(ch);
const long long goldBefore=ch->GetGold();
unsigned opened=0;const char* reason="done";std::string rejection;
while(opened<asked) {
if(PortChestBusy(ch)){reason="busy";break;}
// Stop while a whole weapon still fits, so AutoGiveItem never has to drop a reward on the ground.
if(ch->GetEmptyInventory(kPortChestFreeCells)==-1){reason="full";break;}
LPITEM box=PortChestNext(ch,cell,vnum);
if(!box){reason="empty";break;}
const int count=ch->CountSpecifyItem(vnum);
ch->m_portQuietInfo=true;ch->m_portLastInfo.clear();
ch->UseItem(TItemPos(INVENTORY,box->GetCell()));
ch->m_portQuietInfo=false;
// Success is judged by the original path consuming exactly one box, not by its return value.
if(ch->CountSpecifyItem(vnum)!=count-1){reason="rejected";rejection=ch->m_portLastInfo;break;}
++opened;
}
if(!rejection.empty())ch->ChatPacket(CHAT_TYPE_INFO,"%s",rejection.c_str());
const std::map<DWORD,long long> after=PortChestSnapshot(ch);
unsigned reported=0;
for(const auto& entry:after) {
if(entry.first==vnum)continue;
auto it=before.find(entry.first);
const long long gained=entry.second-(it==before.end()?0:it->second);
if(gained<=0)continue;
if(++reported>kPortChestReportVnums)break;
ch->ChatPacket(CHAT_TYPE_COMMAND,"MTCH1 got %u %lld",unsigned(entry.first),gained);
}
ch->ChatPacket(CHAT_TYPE_COMMAND,"MTCH1 done %u %u %u %s %lld",unsigned(vnum),asked,opened,reason,
(long long)ch->GetGold()-goldBefore);
return NULL;
}
ACMD(do_port_chest) {
if(!ch || !ch->IsPC() || !ch->GetDesc())return;
std::istringstream input(argument);std::vector<std::string> args;std::string token;
while(input>>token){if(token.size()>10 || args.size()>=5)return;args.push_back(token);}
if(args.size()<2 || args[0]!="1")return;
DWORD& last=g_portChestLastCommand[ch->GetPlayerID()];
if(last && get_dword_time()-last<kPortChestGapMs){ch->ChatPacket(CHAT_TYPE_COMMAND,"MTCH1 error rate");return;}
last=get_dword_time();
unsigned cell=0,count=0;const char* error="invalid";
if(args[1]=="open" && args.size()==4 && PortChestNumber(args[2],cell) && PortChestNumber(args[3],count))
error=PortChestOpen(ch,cell,count);
if(error)ch->ChatPacket(CHAT_TYPE_COMMAND,"MTCH1 error %s",error);
}
#endif
+116
View File
@@ -0,0 +1,116 @@
#!/usr/bin/env python3
"""Compile the production batch-chest header against stubs of the original UseItem gift-box contract."""
from pathlib import Path
import subprocess
import tempfile
ROOT=Path(__file__).resolve().parents[2]
SRC=ROOT/'src/server/game/src'
cmd=(SRC/'cmd.cpp').read_bytes().decode('latin1')
assert 'ACMD(do_port_chest);' in cmd and '"mt_chest", do_port_chest, 0, POS_DEAD, GM_PLAYER' in cmd
assert '#include "port_chest.h"' in (SRC/'cmd_general.cpp').read_bytes().decode('latin1')
code=r'''
#include <cassert>
#include <cstdarg>
#include <cstdio>
#include <map>
#include <string>
#include <vector>
using DWORD=unsigned;using BYTE=unsigned char;using WORD=unsigned short;using INT=int;
enum {ITEM_USE=3,ITEM_GIFTBOX=23,INVENTORY=1,DRAGON_SOUL_INVENTORY=3,INVENTORY_MAX_NUM=10,DRAGON_SOUL_INVENTORY_MAX_NUM=4};
enum {CHAT_TYPE_INFO=1,CHAT_TYPE_COMMAND=5};
static DWORD clockms=1000;DWORD get_dword_time(){return clockms;}
struct TItemPos{BYTE window_type;WORD cell;TItemPos(BYTE w,WORD c):window_type(w),cell(c){}};
struct CItem{DWORD vnum;int count;BYTE type;bool exchanging=false;WORD cell=0;
DWORD GetVnum(){return vnum;}int GetCount(){return count;}BYTE GetType(){return type;}bool IsExchanging(){return exchanging;}WORD GetCell(){return cell;}};
using LPITEM=CItem*;
struct CSpecialItemGroup{
enum EGiveType{NONE,GOLD,EXP,MOB,SLOW,DRAIN_HP,POISON,MOB_GROUP};
std::vector<DWORD> vnums;bool IsEmpty()const{return vnums.empty();}
bool Contains(DWORD v)const{for(DWORD x:vnums)if(x==v)return true;return false;}
};
static std::map<DWORD,CSpecialItemGroup> groups;
struct ITEM_MANAGER{static ITEM_MANAGER& instance(){static ITEM_MANAGER m;return m;}
const CSpecialItemGroup* GetSpecialItemGroup(DWORD v){auto it=groups.find(v);return it==groups.end()?nullptr:&it->second;}};
struct CHARACTER{
bool m_portQuietInfo=false;std::string m_portLastInfo;
LPITEM bag[INVENTORY_MAX_NUM]={};LPITEM ds[DRAGON_SOUL_INVENTORY_MAX_NUM]={};std::vector<CItem*> owned;
int gold=0;bool dead=false,shop=false,refuse=false;int uses=0;std::vector<std::string> messages,info;
bool IsPC(){return true;}void* GetDesc(){return this;}DWORD GetPlayerID(){return 7;}
bool IsDead(){return dead;}bool IsStun()const{return false;}bool IsWarping()const{return false;}bool IsObserverMode(){return false;}
bool CanHandleItem(){return true;}void* GetExchange(){return nullptr;}void* GetMyShop(){return shop?this:nullptr;}
void* GetShopOwner(){return nullptr;}bool IsOpenSafebox(){return false;}bool IsCubeOpen(){return false;}
INT GetGold()const{return gold;}
LPITEM GetInventoryItem(WORD c)const{return c<INVENTORY_MAX_NUM?bag[c]:nullptr;}
LPITEM GetItem(TItemPos p){return p.window_type==DRAGON_SOUL_INVENTORY?ds[p.cell]:bag[p.cell];}
int GetEmptyInventory(BYTE size)const{int free=0;for(auto* i:bag)free+=!i;return free>=size?0:-1;}
int CountSpecifyItem(DWORD v)const{int n=0;for(auto* i:bag)if(i&&i->vnum==v)n+=i->count;return n;}
LPITEM Put(DWORD v,int n,BYTE t=ITEM_USE,int at=-1){
for(int c=0;c<INVENTORY_MAX_NUM;++c)if(at<0?!bag[c]:c==at){CItem* i=new CItem{v,n,t};i->cell=c;bag[c]=i;owned.push_back(i);return i;}
return nullptr;}
void ChatPacket(BYTE type,const char* format,...){
char out[513];va_list a;va_start(a,format);vsnprintf(out,sizeof(out),format,a);va_end(a);
if(m_portQuietInfo&&type==CHAT_TYPE_INFO){m_portLastInfo=out;return;}
(type==CHAT_TYPE_INFO?info:messages).emplace_back(out);
}
// Original gift-box contract: one box consumed, 100 gold + one 27001 (stacking) + a dragon soul for box 50100,
// one INFO line per reward; the DS-quest style refusal returns false with an INFO line and consumes nothing.
bool UseItem(TItemPos p){
++uses;LPITEM box=GetItem(p);assert(box && p.window_type==INVENTORY && m_portQuietInfo);
if(refuse){ChatPacket(CHAT_TYPE_INFO,"finish the dragon soul quest first");return false;}
gold+=100;ChatPacket(CHAT_TYPE_INFO,"gold 100");
if(--box->count==0)bag[p.cell]=nullptr;
bool stacked=false;for(auto* i:bag)if(i&&i->vnum==27001){++i->count;stacked=true;break;}
if(!stacked)Put(27001,1);
if(box->vnum==50100)for(auto*& d:ds)if(!d){d=new CItem{110000,1,ITEM_USE};owned.push_back(d);break;}
ChatPacket(CHAT_TYPE_INFO,"got potion");
return true;
}
};
using LPCHARACTER=CHARACTER*;
#define ACMD(name) void name(LPCHARACTER ch,const char* argument)
#include "port_chest.h"
static CHARACTER* ch;
static void cmd(const char* text){clockms+=600;ch->messages.clear();ch->info.clear();ch->uses=0;do_port_chest(ch,text);}
static const std::string& last(){return ch->messages.back();}
static void fresh(){ch=new CHARACTER;}
int main(){
groups[50100].vnums={27001,1,110000};groups[50200].vnums={27001,CSpecialItemGroup::MOB};groups[50300].vnums={};
// Non-stacking boxes spread over cells: chosen cell first, then the others; gains summed, INFO held back.
fresh();ch->Put(50100,1,ITEM_GIFTBOX,0);ch->Put(50100,1,ITEM_GIFTBOX,4);ch->Put(50100,1,ITEM_GIFTBOX,5);
cmd("1 open 4 3");
assert(ch->messages.size()==3 && ch->messages[0]=="MTCH1 got 27001 3" && ch->messages[1]=="MTCH1 got 110000 3");
assert(last()=="MTCH1 done 50100 3 3 done 300" && ch->info.empty() && !ch->m_portQuietInfo && ch->CountSpecifyItem(50100)==0);
// Stacked box, fewer asked than held; then more asked than held -> empty.
fresh();ch->Put(50100,5,ITEM_GIFTBOX);cmd("1 open 0 2");assert(last()=="MTCH1 done 50100 2 2 done 200" && ch->bag[0]->count==3);
cmd("1 open 0 200");assert(last()=="MTCH1 done 50100 200 3 empty 300" && ch->uses==3);
// Single boxes free their own cell for the reward, so free space never shrinks.
fresh();for(int i=0;i<7;++i)ch->Put(50100,1,ITEM_GIFTBOX);
cmd("1 open 0 7");assert(last()=="MTCH1 done 50100 7 7 done 700");
// A stack + 6 fillers leaves exactly 3 free cells: the first reward takes one, then it stops at 2 free.
fresh();ch->Put(50100,7,ITEM_GIFTBOX);for(int i=0;i<6;++i)ch->Put(1,1);
cmd("1 open 0 7");assert(last()=="MTCH1 done 50100 7 1 full 100" && ch->uses==1);
cmd("1 open 0 1");assert(last()=="MTCH1 error full" && ch->uses==0);
// Refusal by the original path: stops, forwards its INFO once.
fresh();ch->Put(50100,3,ITEM_GIFTBOX);ch->refuse=true;cmd("1 open 0 3");
assert(last()=="MTCH1 done 50100 3 0 rejected 0" && ch->info.size()==1 && ch->info[0]=="finish the dragon soul quest first");
// Kinds: not a gift box, monster group box, no/empty group.
fresh();ch->Put(27001,5);cmd("1 open 0 1");assert(last()=="MTCH1 error kind");
ch->Put(50200,2,ITEM_GIFTBOX);cmd("1 open 1 1");assert(last()=="MTCH1 error kind");
ch->Put(50300,2,ITEM_GIFTBOX);cmd("1 open 2 1");assert(last()=="MTCH1 error kind");
ch->Put(50400,2,ITEM_GIFTBOX);cmd("1 open 3 1");assert(last()=="MTCH1 error kind" && ch->uses==0);
// Item, exchange, busy, validation, throttle.
cmd("1 open 9 1");assert(last()=="MTCH1 error item");
LPITEM box=ch->Put(50100,2,ITEM_GIFTBOX);box->exchanging=true;cmd("1 open 4 1");assert(last()=="MTCH1 error item");box->exchanging=false;
ch->shop=true;cmd("1 open 4 1");assert(last()=="MTCH1 error busy");ch->shop=false;
for(auto bad:{"1 open 4 0","1 open 4 201","1 open 10 1","1 open 4","1 open x 1","1 open 4 1 1","1 close 4 1","1 open 4 999999"}){cmd(bad);assert(last()=="MTCH1 error invalid");}
cmd("2 open 4 1");assert(ch->messages.empty());
cmd("1 open 4 1");assert(last()=="MTCH1 done 50100 1 1 done 100");
do_port_chest(ch,"1 open 4 1");assert(last()=="MTCH1 error rate" && ch->CountSpecifyItem(50100)==1);
cmd("1 open 4 1");assert(last()=="MTCH1 done 50100 1 1 done 100");
puts("PASS: cross-cell order, stacks, gains summary, free-cell stop, refusal, kinds, item/busy/validation/throttle");
}
'''
with tempfile.TemporaryDirectory(prefix='mt-chest-') as folder:
path=Path(folder);(path/'test.cpp').write_text(code)
subprocess.run(['c++','-std=c++17','-Wall','-I'+str(SRC),str(path/'test.cpp'),'-o',str(path/'test')],check=True)
subprocess.run([str(path/'test')],check=True)