Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69e335ba9c |
@@ -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: <name> type <i> end <unix>`.
|
||||
|
||||
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.
|
||||
@@ -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];
|
||||
|
||||
@@ -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()))
|
||||
{
|
||||
|
||||
@@ -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 } /* 반드시 이 것이 마지막이어야 한다. */
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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())
|
||||
{
|
||||
|
||||
@@ -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 <cstdlib>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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<DWORD,DWORD> last;
|
||||
DWORD& at=last[ch->GetPlayerID()];
|
||||
if(at && get_dword_time()-at<kPortVipGapMs)return true;
|
||||
at=get_dword_time();
|
||||
return false;
|
||||
}
|
||||
|
||||
// The account's end times (unix seconds) are the truth: premium state, icons, and on request the client.
|
||||
inline void PortVipApply(LPCHARACTER ch,const int* times,bool report) {
|
||||
const int now=get_global_time();
|
||||
std::string line="MTVIP1 times";
|
||||
for(int i=0;i<kPortVipTypes;++i) {
|
||||
const int remain=times[i]-now;
|
||||
if(times[i]!=ch->GetPremiumRemainSeconds(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;i<kPortVipTypes;++i)columns+=std::string(i?",":"")+"UNIX_TIMESTAMP("+kPortVipColumns[i]+")";
|
||||
DBManager::instance().FuncQuery([pid,account,report](SQLMsg* msg) {
|
||||
LPCHARACTER ch=CHARACTER_MANAGER::instance().FindByPID(pid);
|
||||
if(!ch || !ch->GetDesc() || 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;i<kPortVipTypes;++i)times[i]=row[i]?atoi(row[i]):0;
|
||||
PortVipApply(ch,times,report);
|
||||
},"SELECT %s FROM account.account WHERE id=%u",columns.c_str(),account);
|
||||
}
|
||||
|
||||
// Called by CHARACTER::UseItem before the original item handling: true when the item is a VIP card, used or not.
|
||||
inline bool PortVipUseCard(LPCHARACTER ch,LPITEM item) {
|
||||
const int days=PortVipCardDays(item->GetVnum());
|
||||
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;i<kPortVipTypes;++i) {
|
||||
const int remain=ch->GetPremiumRemainSeconds(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;i<kPortVipTypes;++i) {
|
||||
const std::string column=kPortVipColumns[i];
|
||||
sets+=(i?",":"")+column+"=FROM_UNIXTIME(GREATEST(UNIX_TIMESTAMP("+column+"),UNIX_TIMESTAMP())+"+
|
||||
std::to_string(days*86400)+")";
|
||||
}
|
||||
LogManager::instance().ItemLog(ch,item,"MT_VIP_CARD",std::to_string(days).c_str());
|
||||
item->SetCount(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<std::string> 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
|
||||
@@ -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)<hook<item.index('IS_SUMMON_ITEM(item->GetVnum())',use)
|
||||
login=source('input_login.cpp')
|
||||
assert login.index('AFFECT_PREMIUM_START + i')<login.index('PortVipRefresh(ch, false);')
|
||||
assert 'void\t\t\t\tPortSetPremiumTime(BYTE bType, int iTime)' in source('char.h')
|
||||
code=r'''
|
||||
#include <cassert>
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
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<std::string> 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<DWORD,std::vector<int>> 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<std::function<void()>> queue;std::vector<std::string> 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<class F> 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<DWORD,long> affects;std::vector<std::string> 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 t<PREMIUM_MAX_NUM?premium[t]-now:0;}
|
||||
void PortSetPremiumTime(BYTE t,int v){if(t<PREMIUM_MAX_NUM)premium[t]=v;}
|
||||
bool AddAffect(DWORD type,BYTE,long,DWORD,long duration,long,bool override){assert(override);affects[type]=duration;return true;}
|
||||
bool RemoveAffect(DWORD type){return affects.erase(type)>0;}
|
||||
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<std::string> 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<int>(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;i<PREMIUM_MAX_NUM;++i)player->premium[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)
|
||||
Reference in New Issue
Block a user