From 69e335ba9cd6c012a30c4c179a7fda31474fdc99 Mon Sep 17 00:00:00 2001 From: shenlei Date: Fri, 16 Oct 2026 02:13:17 +0900 Subject: [PATCH] Add VIP cards extending the seven premium services Using 38001 (7 days) or 38002 (30 days) moves every account.account *_expire column to max(now, end) + days, capped at 400 days left, with a 1 s gap per player. The db core only hands out the login-time premium times (CLoginData), so the game reads the row back after a card and on every enter-game and updates m_aiPremiumTimes and the 500..506 icons. /mt_vip 1 status reports the remaining seconds. docs/FEATURE-VIP.md. Co-Authored-By: Claude Opus 5.5 --- docs/FEATURE-VIP.md | 84 +++++++++++++++++ src/server/game/src/char.h | 2 + src/server/game/src/char_item.cpp | 5 + src/server/game/src/cmd.cpp | 2 + src/server/game/src/cmd_general.cpp | 8 ++ src/server/game/src/input_login.cpp | 5 + src/server/game/src/port_premium.h | 103 +++++++++++++++++++++ tests/features/test_vip.py | 137 ++++++++++++++++++++++++++++ 8 files changed, 346 insertions(+) create mode 100644 docs/FEATURE-VIP.md create mode 100644 src/server/game/src/port_premium.h create mode 100644 tests/features/test_vip.py diff --git a/docs/FEATURE-VIP.md b/docs/FEATURE-VIP.md new file mode 100644 index 00000000..9e42db98 --- /dev/null +++ b/docs/FEATURE-VIP.md @@ -0,0 +1,84 @@ +# PORT VIP card + +A card extends all seven original premium services of the account. 40250 has the services but no in-game way to grant them. Source: `src/server/game/src/port_premium.h`, the hook in `CHARACTER::UseItem` (char_item.cpp), the enter-game refresh in input_login.cpp, `CHARACTER::PortSetPremiumTime` (char.h) and `/mt_vip` (cmd_general.cpp, cmd.cpp). Item data (size, flags, names, shop): metin2-client `tools/server/vip-card`. + +## Services + +`account.account` holds one end time per service. The game keeps them in `m_aiPremiumTimes` and shows affect `AFFECT_PREMIUM_START + i` (500..506) as the icon. + +| i | Premium | Column | Effect on newcibn | +|---|---|---|---| +| 0 | `PREMIUM_EXP` | `silver_expire` | monster exp ×1.2 × `mob_exp_buyer`/100 (char_battle.cpp) | +| 1 | `PREMIUM_ITEM` | `gold_expire` | item drop rate | +| 2 | `PREMIUM_SAFEBOX` | `safebox_expire` | safebox size 3 (input_db.cpp) | +| 3 | `PREMIUM_AUTOLOOT` | `autoloot_expire` | gold goes straight to the bag (char_battle.cpp) | +| 4 | `PREMIUM_FISH_MIND` | `fish_mind_expire` | fishing | +| 5 | `PREMIUM_MARRIAGE_FAST` | `marriage_fast_expire` | marriage love points | +| 6 | `PREMIUM_GOLD` | `money_drop_rate_expire` | gold drop rate | + +## Cards + +| Vnum | Days | +|---|---| +| 38001 | 7 | +| 38002 | 30 | + +Both are unused `ITEM_NONE` rows in 40250. `PortVipUseCard` runs in `UseItem` after the sex check, before any type handling, so the item type does not matter. + +When a card is used: + +1. The card is refused, and not consumed, in two cases: + - the player used a card or `/mt_vip` less than 1 s ago (`rate`); + - for any service, the remaining time plus the card would exceed 400 days (`full`). The `int` end times stay far below 2038. +2. Otherwise one card is consumed, with an `MT_VIP_CARD` item log whose hint is the number of days. +3. One `UPDATE` moves every column to `GREATEST(UNIX_TIMESTAMP(col), UNIX_TIMESTAMP()) + days × 86400`. A service that has expired restarts from now; a running one is extended. + +## Freshness + +Auth reads the columns only at login and passes them to the db core's `CLoginData`. Every later player load, such as a warp or a core change, fills `TPlayerTable.aiPremiumTimes` from that login-time copy. So after a card, and on every enter-game, the game reads the row itself. + +`PortVipRefresh` handles this: +- It queues `SELECT UNIX_TIMESTAMP(col)... FROM account.account WHERE id=` through `DBManager::FuncQuery`. That is the same ordered queue and connection as the card's `UPDATE`, so the read sees the update. +- The answer finds the player again by PID and checks the account ID; if the player has left, nothing happens. +- For each service whose end changed, it sets `m_aiPremiumTimes[i]`, then either adds the affect with the remaining duration or removes it if the service has expired. +- It logs `PORT_VIP: type end `. + +The db core is not changed. + +## Protocol + +``` +/mt_vip 1 status ask for the remaining time +MTVIP1 times R0 R1 R2 R3 R4 R5 R6 remaining seconds per service (0 = none), PREMIUM_EXP .. PREMIUM_GOLD +MTVIP1 added VNUM DAYS a card was consumed; a times line follows once the row is read back +MTVIP1 error CODE rate full invalid +``` + +- `status` and card use share the 1 s throttle per player. +- A wrong version, or more than three tokens, gets no answer; an old client never sends one. +- The client (metin2-client `src/platform/ScriptLib/VipScript.inc`, module `mt_vip`) treats a `status` with no answer within 3 s as a server without the feature. + +## Exp bonus + +On newcibn the premium exp branch multiplies by 1.2 and then by `GetMobExpRate`, which returns event flag `mob_exp_buyer` (default 100). `/e mob_exp_buyer 167` gives 1.2 × 1.67 ≈ 2.0, that is +100 %. Event flags live in `player.quest` (pid 0) and every core shares them, so the flag is set once, by a GM, at deploy. + +## Verification + +- `tests/features/test_vip.py` checks the wiring: + - the command entry is at the end of `cmd_info`; + - the include is outside the `__AUCTION__` block; + - the hook sits between the sex check and the summon-item block; + - the refresh runs after the login affect loop. +- It also compiles the production header against a stub account table, the ordered SQL queue and the affects. It covers: + - a 7-day card, the read-back and the icons; + - the gap refusal, then a 30-day card stacked onto the current end; + - the 400-day cap: no card consumed, no query; + - other items left untouched; + - the enter-game refresh over stale values; + - a service expired by hand, and the `status` command; + - a player who leaves before the answer, and a missing account row. +- Live test, channel5 (2026-10-15), Admin account with all expire values reset to 0: + - 38002 (30 days) set all seven columns to now + 30 days, added affects 500..506 and returned `times 2592000…`. + - Two 38001 used through the inventory right-click, 2 s apart, extended to 44 days. + - A same-map `/warp` reloaded the player with the login-time 30 days. The refresh logged the seven `PORT_VIP` corrections to 44 days, and the panel showed "剩余 43 天 23 å°�æ—¶" for every service. + - Earlier, with premium, autoloot gold went straight to the bag; without it, the gold stayed on the ground. diff --git a/src/server/game/src/char.h b/src/server/game/src/char.h index 41ae917c..54473efe 100755 --- a/src/server/game/src/char.h +++ b/src/server/game/src/char.h @@ -1746,6 +1746,8 @@ class CHARACTER : public CEntity, public CFSM, public CHorseRider public: int GetPremiumRemainSeconds(BYTE bType) const; + // PORT: the VIP card re-reads the account end times (port_premium.h). + void PortSetPremiumTime(BYTE bType, int iTime) { if (bType < PREMIUM_MAX_NUM) m_aiPremiumTimes[bType] = iTime; } private: int m_aiPremiumTimes[PREMIUM_MAX_NUM]; diff --git a/src/server/game/src/char_item.cpp b/src/server/game/src/char_item.cpp index a77696cc..c0784c58 100755 --- a/src/server/game/src/char_item.cpp +++ b/src/server/game/src/char_item.cpp @@ -50,6 +50,7 @@ #ifdef __AUCTION__ #include "auction_manager.h" #endif +#include "port_premium.h" const int ITEM_BROKEN_METIN_VNUM = 28960; // CHANGE_ITEM_ATTRIBUTES @@ -5207,6 +5208,10 @@ bool CHARACTER::UseItem(TItemPos Cell, TItemPos DestCell) return false; } + // PORT: VIP card (port_premium.h) + if (PortVipUseCard(this, item)) + return true; + //PREVENT_TRADE_WINDOW if (IS_SUMMON_ITEM(item->GetVnum())) { diff --git a/src/server/game/src/cmd.cpp b/src/server/game/src/cmd.cpp index b16f5eab..bd9ccf4b 100755 --- a/src/server/game/src/cmd.cpp +++ b/src/server/game/src/cmd.cpp @@ -13,6 +13,7 @@ ACMD(do_port_features); ACMD(do_port_switchbot); ACMD(do_port_pickup); ACMD(do_port_chest); +ACMD(do_port_vip); ACMD(do_user_horse_ride); ACMD(do_user_horse_back); ACMD(do_user_horse_feed); @@ -605,6 +606,7 @@ struct command_info cmd_info[] = { "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 }, + { "mt_vip", do_port_vip, 0, POS_DEAD, GM_PLAYER }, { "\n", NULL, 0, POS_DEAD, GM_IMPLEMENTOR } /* ¹Ýµå½Ã ÀÌ °ÍÀÌ ¸¶Áö¸·À̾î¾ß ÇÑ´Ù. */ }; diff --git a/src/server/game/src/cmd_general.cpp b/src/server/game/src/cmd_general.cpp index 3f07df82..913cf8f8 100755 --- a/src/server/game/src/cmd_general.cpp +++ b/src/server/game/src/cmd_general.cpp @@ -46,6 +46,14 @@ #include "port_switchbot.h" #include "port_pickup.h" #include "port_chest.h" +#include "port_premium.h" + +ACMD(do_port_vip) +{ + if (!ch || !ch->IsPC() || !ch->GetDesc()) + return; + PortVipCommand(ch, argument); +} extern int g_server_id; diff --git a/src/server/game/src/input_login.cpp b/src/server/game/src/input_login.cpp index 9adbe242..6f6f3e2b 100755 --- a/src/server/game/src/input_login.cpp +++ b/src/server/game/src/input_login.cpp @@ -28,6 +28,9 @@ #include "block_country.h" #include "dev_log.h" #include "log.h" +#include "db.h" +#include "item.h" +#include "port_premium.h" #include "horsename_manager.h" #include "MarkManager.h" // #include "HackShield.h" @@ -642,6 +645,8 @@ void CInputLogin::Entergame(LPDESC d, const char * data) ch->AddAffect(AFFECT_PREMIUM_START + i, POINT_NONE, 0, 0, remain, 0, true); sys_log(0, "PREMIUM: %s type %d %dmin", ch->GetName(), i, remain); } + // PORT: the db core keeps the login-time premium ends; a VIP card used since then is in the account table. + PortVipRefresh(ch, false); if (LC_IsEurope()) { diff --git a/src/server/game/src/port_premium.h b/src/server/game/src/port_premium.h new file mode 100644 index 00000000..c01be6c7 --- /dev/null +++ b/src/server/game/src/port_premium.h @@ -0,0 +1,103 @@ +#ifndef METIN2_PORT_PREMIUM_H +#define METIN2_PORT_PREMIUM_H +// PORT: VIP card. Using card 38001 (7 days) or 38002 (30 days) extends all seven premium services of the account +// (account.account *_expire) from the later of now and their current end. The original server reads these columns +// only when auth logs the account in, and the db core hands those login-time values to every later player load +// (CLoginData), so after a card and on every enter-game the game re-reads them and updates m_aiPremiumTimes and the +// AFFECT_PREMIUM_START+i icons. Protocol: docs/FEATURE-VIP.md. +#include +#include +#include +#include +#include + +static const int kPortVipTypes=7; // PREMIUM_EXP .. PREMIUM_GOLD, in account column order +static const char* const kPortVipColumns[kPortVipTypes]={"silver_expire","gold_expire","safebox_expire", + "autoloot_expire","fish_mind_expire","marriage_fast_expire","money_drop_rate_expire"}; +static const DWORD kPortVipCards[][2]={{38001,7},{38002,30}}; +static const int kPortVipMaxDays=400; // remaining time a card may reach, far from the 2038 limit of the int times +static const DWORD kPortVipGapMs=1000; + +inline int PortVipCardDays(DWORD vnum) { + for(const auto& card:kPortVipCards)if(card[0]==vnum)return int(card[1]); + return 0; +} + +// One throttle per player id for card use and status requests: both queue a query whose answer updates memory. +inline bool PortVipThrottled(LPCHARACTER ch) { + static std::map last; + DWORD& at=last[ch->GetPlayerID()]; + if(at && get_dword_time()-atGetPremiumRemainSeconds(i)+now) { + ch->PortSetPremiumTime(i,times[i]); + if(remain>0)ch->AddAffect(AFFECT_PREMIUM_START+i,POINT_NONE,0,0,remain,0,true); + else ch->RemoveAffect(AFFECT_PREMIUM_START+i); + sys_log(0,"PORT_VIP: %s type %d end %d",ch->GetName(),i,times[i]); + } + line+=" "+std::to_string(remain>0?remain:0); + } + if(report)ch->ChatPacket(CHAT_TYPE_COMMAND,"%s",line.c_str()); +} + +inline void PortVipRefresh(LPCHARACTER ch,bool report) { + if(!ch->GetDesc())return; + const DWORD pid=ch->GetPlayerID(),account=ch->GetDesc()->GetAccountTable().id; + std::string columns; + for(int i=0;iGetDesc() || ch->GetDesc()->GetAccountTable().id!=account)return; + if(!msg->Get() || msg->Get()->uiNumRows!=1){sys_err("PORT_VIP: account %u not found",account);return;} + MYSQL_ROW row=mysql_fetch_row(msg->Get()->pSQLResult); + int times[kPortVipTypes]; + for(int i=0;iGetVnum()); + if(!days)return false; + if(!ch->IsPC() || !ch->GetDesc())return true; + if(PortVipThrottled(ch)){ch->ChatPacket(CHAT_TYPE_COMMAND,"MTVIP1 error rate");return true;} + for(int i=0;iGetPremiumRemainSeconds(i); + if((remain>0?remain:0)+days*86400>kPortVipMaxDays*86400){ch->ChatPacket(CHAT_TYPE_COMMAND,"MTVIP1 error full");return true;} + } + const DWORD vnum=item->GetVnum(),account=ch->GetDesc()->GetAccountTable().id; + std::string sets; + for(int i=0;iSetCount(item->GetCount()-1); + // Same connection as the refresh, which therefore reads the updated row. + DBManager::instance().Query("UPDATE account.account SET %s WHERE id=%u",sets.c_str(),account); + ch->ChatPacket(CHAT_TYPE_COMMAND,"MTVIP1 added %u %d",unsigned(vnum),days); + PortVipRefresh(ch,true); + return true; +} + +// /mt_vip 1 status -> MTVIP1 times (seven remaining seconds, PREMIUM_EXP .. PREMIUM_GOLD) +inline void PortVipCommand(LPCHARACTER ch,const char* argument) { + std::istringstream input(argument);std::vector args;std::string token; + while(input>>token){if(token.size()>10 || args.size()>=3)return;args.push_back(token);} + if(args.empty() || args[0]!="1")return; + if(args.size()!=2 || args[1]!="status"){ch->ChatPacket(CHAT_TYPE_COMMAND,"MTVIP1 error invalid");return;} + if(PortVipThrottled(ch)){ch->ChatPacket(CHAT_TYPE_COMMAND,"MTVIP1 error rate");return;} + PortVipRefresh(ch,true); +} +#endif diff --git a/tests/features/test_vip.py b/tests/features/test_vip.py new file mode 100644 index 00000000..ce58784d --- /dev/null +++ b/tests/features/test_vip.py @@ -0,0 +1,137 @@ +#!/usr/bin/env python3 +"""Compile the production VIP card header against stubs of the account table, the ordered async SQL queue and +the premium affects.""" +from pathlib import Path +import subprocess +import tempfile +ROOT=Path(__file__).resolve().parents[2] +SRC=ROOT/'src/server/game/src' +def source(name):return (SRC/name).read_bytes().decode('latin1') +cmd=source('cmd.cpp') +assert 'ACMD(do_port_vip);' in cmd and '"mt_vip", do_port_vip, 0, POS_DEAD, GM_PLAYER' in cmd +general=source('cmd_general.cpp') +assert '#include "port_premium.h"' in general and 'PortVipCommand(ch, argument);' in general +item=source('char_item.cpp') +use=item.index('bool CHARACTER::UseItem(TItemPos Cell, TItemPos DestCell)') +hook=item.index('if (PortVipUseCard(this, item))',use) +assert '#endif\n#include "port_premium.h"\n' in item # not inside the __AUCTION__ block +assert item.index('FN_check_item_sex(this, item)',use)GetVnum())',use) +login=source('input_login.cpp') +assert login.index('AFFECT_PREMIUM_START + i') +#include +#include +#include +#include +#include +#include +#include +#include +using DWORD=unsigned;using BYTE=unsigned char; +enum {CHAT_TYPE_INFO=1,CHAT_TYPE_COMMAND=5,POINT_NONE=0,AFFECT_PREMIUM_START=500,PREMIUM_MAX_NUM=9}; +static int now=1700000000;static DWORD clockms=1000; +int get_global_time(){return now;}DWORD get_dword_time(){return clockms;} +static std::vector logs; +void sys_log(int,const char* format,...){char out[512];va_list a;va_start(a,format);vsnprintf(out,sizeof(out),format,a);va_end(a);logs.push_back(out);} +void sys_err(const char* format,...){char out[512];va_list a;va_start(a,format);vsnprintf(out,sizeof(out),format,a);va_end(a);logs.push_back(std::string("ERR ")+out);} +static std::string format(const char* f,va_list a){char out[4096];vsnprintf(out,sizeof(out),f,a);return out;} +// Account table: id -> seven end times (0 = never), as UNIX_TIMESTAMP reads them. +static std::map> accounts; +using MYSQL_ROW=char**; +struct Rows{char* cells[7];char text[7][16];}; +struct SQLResult{unsigned uiNumRows;Rows* pSQLResult;Rows rows;}; +struct SQLMsg{SQLResult result;bool ok=true;SQLResult* Get(){return ok?&result:nullptr;}}; +MYSQL_ROW mysql_fetch_row(Rows* r){return r->cells;} +struct DBManager{ + std::deque> queue;std::vector queries; + static DBManager& instance(){static DBManager m;return m;} + void Query(const char* f,...){va_list a;va_start(a,f);std::string q=format(f,a);va_end(a);queries.push_back(q); + queue.push_back([q]{DWORD id;int secs; + const char* where=strstr(q.c_str()," WHERE id=");assert(where && sscanf(where," WHERE id=%u",&id)==1); + const char* add=strstr(q.c_str(),"UNIX_TIMESTAMP())+");assert(add && sscanf(add,"UNIX_TIMESTAMP())+%d)",&secs)==1); + for(int& t:accounts[id])t=(t>now?t:now)+secs;});} + template void FuncQuery(F f,const char* fmt,...){va_list a;va_start(a,fmt);std::string q=format(fmt,a);va_end(a);queries.push_back(q); + queue.push_back([f,q]{DWORD id;assert(sscanf(strstr(q.c_str()," WHERE id="), " WHERE id=%u",&id)==1); + SQLMsg m{};auto it=accounts.find(id);m.result.uiNumRows=it==accounts.end()?0:1;m.result.pSQLResult=&m.result.rows; + for(int i=0;i<7;++i){m.result.rows.cells[i]=m.result.rows.text[i];snprintf(m.result.rows.text[i],16,"%d",it==accounts.end()?0:it->second[i]);} + f(&m);});} + void Run(){while(!queue.empty()){auto job=queue.front();queue.pop_front();job();}} +}; +struct CItem{DWORD vnum;int count;DWORD GetVnum(){return vnum;}int GetCount(){return count;}void SetCount(int c){count=c;}}; +using LPITEM=CItem*; +struct TAccountTable{DWORD id;}; +struct DESC{TAccountTable table;TAccountTable& GetAccountTable(){return table;}}; +struct CHARACTER{ + DESC desc;bool online=true;int premium[PREMIUM_MAX_NUM]={};std::map affects;std::vector messages; + const char* GetName(){return "Admin";}bool IsPC(){return true;}DESC* GetDesc(){return online?&desc:nullptr;}DWORD GetPlayerID(){return 7;} + int GetPremiumRemainSeconds(BYTE t)const{return t0;} + void ChatPacket(BYTE type,const char* f,...){va_list a;va_start(a,f);std::string s=format(f,a);va_end(a);assert(type==CHAT_TYPE_COMMAND);messages.push_back(s);} +}; +using LPCHARACTER=CHARACTER*; +static CHARACTER* player=nullptr; +struct CHARACTER_MANAGER{static CHARACTER_MANAGER& instance(){static CHARACTER_MANAGER m;return m;} + LPCHARACTER FindByPID(DWORD pid){return player && pid==7?player:nullptr;}}; +static std::vector itemlog; +struct LogManager{static LogManager& instance(){static LogManager m;return m;} + void ItemLog(LPCHARACTER,LPITEM item,const char* how,const char* hint){assert(item->count>0);itemlog.push_back(std::string(how)+" "+std::to_string(item->vnum)+" "+hint);}}; +#include "port_premium.h" +static DBManager& db=DBManager::instance(); +static const std::string& last(){return player->messages.back();} +static void tick(){clockms+=1100;} +int main(){ + const int DAY=86400; + accounts[1]=std::vector(7,0); + player=new CHARACTER;player->desc.table.id=1; + // Fresh account: 7 days from now on all seven columns, one card consumed, icons 500..506 for 7 days. + CItem card{38001,2}; + assert(PortVipUseCard(player,&card) && card.count==1 && itemlog.back()=="MT_VIP_CARD 38001 7"); + assert(db.queries[0].rfind("UPDATE account.account SET silver_expire=FROM_UNIXTIME(GREATEST(UNIX_TIMESTAMP(silver_expire),UNIX_TIMESTAMP())+604800),gold_expire=",0)==0); + assert(db.queries[0].find("money_drop_rate_expire=FROM_UNIXTIME(GREATEST(UNIX_TIMESTAMP(money_drop_rate_expire),UNIX_TIMESTAMP())+604800) WHERE id=1")!=std::string::npos); + assert(db.queries[1]=="SELECT UNIX_TIMESTAMP(silver_expire),UNIX_TIMESTAMP(gold_expire),UNIX_TIMESTAMP(safebox_expire),UNIX_TIMESTAMP(autoloot_expire),UNIX_TIMESTAMP(fish_mind_expire),UNIX_TIMESTAMP(marriage_fast_expire),UNIX_TIMESTAMP(money_drop_rate_expire) FROM account.account WHERE id=1"); + assert(last()=="MTVIP1 added 38001 7" && player->premium[0]==0); // memory waits for the read-back + db.Run(); + assert(last()=="MTVIP1 times 604800 604800 604800 604800 604800 604800 604800"); + for(int i=0;i<7;++i)assert(player->premium[i]==now+7*DAY && player->affects[500+i]==7*DAY && accounts[1][i]==now+7*DAY); + assert(!player->affects.count(507) && player->premium[7]==0); + // A second card inside the gap is refused and kept; after it, 30 days add to the current end. + CItem month{38002,1}; + assert(PortVipUseCard(player,&month) && last()=="MTVIP1 error rate" && month.count==1); + tick();now+=DAY;assert(PortVipUseCard(player,&month) && month.count==0);db.Run(); + assert(last()=="MTVIP1 times 3110400 3110400 3110400 3110400 3110400 3110400 3110400" && player->premium[3]==now-DAY+37*DAY); + // Past the 400-day cap: refused before anything is consumed or queried. + const size_t queries=db.queries.size();CItem many{38002,20}; + for(int k=0;k<13;++k){tick();assert(PortVipUseCard(player,&many));db.Run();} // 36 days left: 12 cards reach 396 + assert(last()=="MTVIP1 error full" && many.count==8 && db.queries.size()==queries+24); + // Not a card: untouched, nothing queried. + CItem other{27001,5};assert(!PortVipUseCard(player,&other) && other.count==5 && db.queries.size()==queries+24); + // Enter-game on another core: the db core still has the login-time ends (here, none); the refresh restores them. + tick();const auto stale=player->messages.size(); + for(int i=0;ipremium[i]=0;player->affects.clear(); + PortVipRefresh(player,false);db.Run(); + assert(player->messages.size()==stale && player->premium[6]==accounts[1][6] && player->affects[506]==accounts[1][6]-now); + // Expired in the account (edited by hand): state and icon go away; unchanged types keep their icon untouched. + accounts[1][2]=now-5;player->affects[502]=1;player->affects[503]=12345; + PortVipRefresh(player,false);db.Run(); + assert(player->GetPremiumRemainSeconds(2)<0 && !player->affects.count(502) && player->affects[503]==12345); + // Status command: version, validation, throttle, report of remaining seconds (0 when expired). + tick();PortVipCommand(player,"1 status");db.Run();assert(last().rfind("MTVIP1 times ",0)==0 && last().find(" 0 ")!=std::string::npos); + PortVipCommand(player,"1 status");assert(last()=="MTVIP1 error rate"); + for(auto bad:{"1 stats","1","1 status x"}){tick();PortVipCommand(player,bad);assert(last()=="MTVIP1 error invalid");} + const auto quiet=player->messages.size();tick();PortVipCommand(player,"2 status");PortVipCommand(player,"1 status x y z"); + assert(player->messages.size()==quiet); + // The player left before the read-back: nothing is touched. + tick();PortVipCommand(player,"1 status");CHARACTER* gone=player;player=nullptr;db.Run();assert(gone->messages.size()==quiet); + // Missing account row: logged, no state change. + player=gone;player->desc.table.id=99;tick();PortVipRefresh(player,true);db.Run();assert(logs.back()=="ERR PORT_VIP: account 99 not found"); + puts("PASS: card use and read-back, stacking, gap, cap, other items, enter-game refresh, expiry, status command"); +} +''' +with tempfile.TemporaryDirectory(prefix='mt-vip-') 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)