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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
3590a06946
commit
69e335ba9c
@@ -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
|
||||
Reference in New Issue
Block a user