feat: serve native AVA2 battle pass, drop finder and event calendar
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
#ifndef METIN2_AVA2_NATIVE_PACKETS_H
|
||||
#define METIN2_AVA2_NATIVE_PACKETS_H
|
||||
#include <stdint.h>
|
||||
#pragma pack(push,1)
|
||||
struct TPacketCGAva2Drop {uint8_t header,subheader;int32_t vnum;};
|
||||
struct TPacketGCAva2Drop {uint8_t header,subheader;char name[100];uint32_t vnum,prob;int32_t count;};
|
||||
struct TPacketGCAva2Events {uint8_t header;uint32_t size;};
|
||||
struct TAva2Event {uint16_t id;uint8_t kind;uint32_t start,end;uint8_t empire,channel;uint32_t value[4];uint8_t active,onlyStart;char startText[25],endText[25];};
|
||||
#pragma pack(pop)
|
||||
static_assert(sizeof(TPacketCGAva2Drop)==6 && sizeof(TPacketGCAva2Drop)==114 && sizeof(TPacketGCAva2Events)==5 && sizeof(TAva2Event)==81,"AVA2 query wire sizes");
|
||||
class CHARACTER;
|
||||
void PortNativeDrop(CHARACTER*,const TPacketCGAva2Drop&);
|
||||
#endif
|
||||
@@ -0,0 +1,92 @@
|
||||
// Included only by cmd_general.cpp; reads the same loaded tables/schedule as actual drops.
|
||||
#include "ava2_native_packets.h"
|
||||
#include <cstring>
|
||||
inline bool PortNativeClient(LPCHARACTER ch) {
|
||||
const char* mark=ch && ch->GetDesc()?strstr(ch->GetDesc()->GetClientVersion(),"mt"):NULL;
|
||||
return mark && atoi(mark+2)>=20261019;
|
||||
}
|
||||
|
||||
void PortNativeDrop(LPCHARACTER ch,const TPacketCGAva2Drop& request) {
|
||||
if (!ch || !ch->GetDesc() || !PortNativeClient(ch))return;
|
||||
if (request.subheader!=0 && request.subheader!=1 && request.subheader!=6 && request.subheader!=7 && request.subheader!=8 && request.subheader!=9 && request.subheader!=10)return;
|
||||
TPacketGCAva2Drop p={};p.header=220;
|
||||
if (request.subheader==0) {p.subheader=2;ch->GetDesc()->Packet(&p,sizeof(p));return;}
|
||||
if (request.vnum<=0)return;
|
||||
const int now=get_global_time();
|
||||
// Always finish a refused request so an untagged AVA2 response cannot poison the next query.
|
||||
p.subheader=4;ch->GetDesc()->Packet(&p,sizeof(p));
|
||||
if (ch->GetProtectTime("native_drop")>now) {p.subheader=6;ch->GetDesc()->Packet(&p,sizeof(p));return;}
|
||||
ch->SetProtectTime("native_drop",now+1);
|
||||
auto& manager=ITEM_MANAGER::instance();unsigned sent=0;bool overflow=false;
|
||||
auto send=[&](unsigned id,unsigned count,unsigned probability,const char* name) {
|
||||
if(!id || !count)return;
|
||||
if(sent>=4096){overflow=true;return;}
|
||||
memset(&p,0,sizeof(p));p.header=220;p.subheader=3;p.vnum=id;p.count=count;p.prob=probability;
|
||||
strlcpy(p.name,name?name:"",sizeof(p.name));ch->GetDesc()->Packet(&p,sizeof(p));++sent;
|
||||
};
|
||||
std::set<unsigned> family;unsigned next=request.vnum;
|
||||
for(unsigned i=0;i<256 && next && !family.count(next);++i) {
|
||||
const auto* t=manager.GetTable(next);if(!t)break;
|
||||
family.insert(next);next=(request.subheader==9 || request.subheader==10)?t->dwRefinedVnum:0;
|
||||
}
|
||||
if ((request.subheader==1 || request.subheader==9) && !family.empty()) {
|
||||
for(auto it=CMobManager::instance().begin();it!=CMobManager::instance().end();++it)
|
||||
for(const auto& row:manager.PortWikiDrops(it->first))
|
||||
if(family.count(row.item))send(it->first,row.count,0,it->second->m_table.szLocaleName);
|
||||
} else if ((request.subheader==8 || request.subheader==10) && !family.empty()) {
|
||||
for(const auto& table:manager.GetTable())
|
||||
if(table.bType==ITEM_GIFTBOX || table.bType==ITEM_TREASURE_BOX)
|
||||
for(const auto& row:manager.PortWikiChest(table.dwVnum))
|
||||
if(family.count(row.item))send(table.dwVnum,row.count,0,table.szLocaleName);
|
||||
} else if (request.subheader==6 || request.subheader==7) {
|
||||
const auto rows=request.subheader==6?manager.PortWikiDrops(request.vnum):manager.PortWikiChest(request.vnum);
|
||||
for(const auto& row:rows) {
|
||||
const auto* proto=manager.GetTable(row.item);
|
||||
// Conditional mob rates cannot be represented by the legacy percentage field.
|
||||
unsigned probability=row.rule==WIKI_SINGLE && row.total?unsigned(100ULL*row.weight/row.total):row.rule==WIKI_INDEPENDENT?row.weight:0;
|
||||
if(proto)send(row.item,row.count,probability,proto->szLocaleName);
|
||||
}
|
||||
}
|
||||
memset(&p,0,sizeof(p));p.header=220;p.subheader=overflow?6:5;ch->GetDesc()->Packet(&p,sizeof(p));
|
||||
}
|
||||
|
||||
ACMD(do_event_manager) {
|
||||
if(!ch || !ch->GetDesc() || !PortNativeClient(ch))return;
|
||||
std::istringstream input(argument);std::string action,extra;
|
||||
if(!(input>>action) || action!="info" || (input>>extra))return;
|
||||
const int now=get_global_time();
|
||||
if(ch->GetProtectTime("native_calendar")>now)return;
|
||||
ch->SetProtectTime("native_calendar",now+2);
|
||||
auto& schedule=PortCurrentEvents();
|
||||
if(!schedule.valid){ch->ChatPacket(CHAT_TYPE_COMMAND,"EventCalendarError unavailable");return;}
|
||||
const time_t stamp=now;struct tm current;gmtime_r(&stamp,¤t);
|
||||
std::map<unsigned,std::vector<TAva2Event>> days;
|
||||
unsigned ordinal=0;
|
||||
for(const auto& e:schedule.events) {
|
||||
++ordinal;
|
||||
const time_t start=e.start,end=e.end;struct tm st,et;gmtime_r(&start,&st);gmtime_r(&end,&et);
|
||||
// Include an ongoing interval which began in the previous month, on day one.
|
||||
const bool starts=st.tm_year==current.tm_year && st.tm_mon==current.tm_mon;
|
||||
const bool overlaps=start<=stamp && end>stamp;
|
||||
if(!starts && !overlaps)continue;
|
||||
TAva2Event event={};event.id=ordinal;event.kind=e.kind==1?8:20;
|
||||
event.start=e.start;event.end=e.end;event.empire=e.empire;event.channel=e.channel;
|
||||
event.active=e.Active(now,g_bChannel,ch->GetEmpire());
|
||||
strftime(event.startText,sizeof(event.startText),"%Y-%m-%d %H:%M:%S",&st);
|
||||
strftime(event.endText,sizeof(event.endText),"%Y-%m-%d %H:%M:%S",&et);
|
||||
days[starts?unsigned(st.tm_mday):1].push_back(event);
|
||||
}
|
||||
// The AVA2 event-manager payload is retained; GC214 avoids classic SHOP_SIGN=39.
|
||||
TPacketGCAva2Events header={214,uint32_t(sizeof(TPacketGCAva2Events)+6)};
|
||||
for(const auto& day:days)header.size+=2+day.second.size()*sizeof(TAva2Event);
|
||||
if(header.size>32768)return;
|
||||
TEMP_BUFFER out;out.write(&header,sizeof(header));
|
||||
const uint8_t sub=0,dayCount=days.size();out.write(&sub,1);out.write(&dayCount,1);out.write(&now,4);
|
||||
for(const auto& day:days) {
|
||||
// Per-day count is BYTE in AVA2. Reject overflow rather than wrapping its length.
|
||||
if(day.second.size()>255){ch->ChatPacket(CHAT_TYPE_COMMAND,"EventCalendarError overflow");return;}
|
||||
const uint8_t index=day.first,count=day.second.size();out.write(&index,1);out.write(&count,1);
|
||||
out.write(day.second.data(),day.second.size()*sizeof(TAva2Event));
|
||||
}
|
||||
ch->GetDesc()->Packet(out.read_peek(),out.size());
|
||||
}
|
||||
@@ -22,6 +22,8 @@ ACMD(do_chest_drop);
|
||||
ACMD(do_chestdrop);
|
||||
ACMD(do_port_vip);
|
||||
ACMD(do_port_bp);
|
||||
ACMD(do_battle_pass);
|
||||
ACMD(do_event_manager);
|
||||
ACMD(do_user_horse_ride);
|
||||
ACMD(do_user_horse_back);
|
||||
ACMD(do_user_horse_feed);
|
||||
@@ -623,7 +625,9 @@ struct command_info cmd_info[] =
|
||||
{ "chestdrop", do_chestdrop, 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 },
|
||||
{ "mt_bp", do_port_bp, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "event_manager", do_event_manager, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "battle_pass", do_battle_pass, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "mt_bp", do_port_bp, 0, POS_DEAD, GM_PLAYER },
|
||||
{ "\n", NULL, 0, POS_DEAD, GM_IMPLEMENTOR } /* 반드시 이 것이 마지막이어야 한다. */
|
||||
};
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
#include "ava2_chest_commands.h"
|
||||
#include "port_premium.h"
|
||||
#include "port_battlepass_runtime.h"
|
||||
#include "ava2_native_queries.h"
|
||||
|
||||
ACMD(do_port_vip)
|
||||
{
|
||||
@@ -60,6 +61,8 @@ ACMD(do_port_vip)
|
||||
PortVipCommand(ch, argument);
|
||||
}
|
||||
|
||||
ACMD(do_battle_pass) { PortBpNativeCommand(ch,argument); }
|
||||
|
||||
// PORT: battle pass (port_battlepass_runtime.h)
|
||||
ACMD(do_port_bp)
|
||||
{
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
// #include "XTrapManager.h"
|
||||
#include "DragonSoul.h"
|
||||
#include "port_switchbot.h"
|
||||
#include "ava2_native_packets.h"
|
||||
|
||||
extern void SendShout(const char * szText, BYTE bEmpire);
|
||||
extern int g_nPortalLimitTime;
|
||||
@@ -3405,6 +3406,8 @@ int CInputMain::Analyze(LPDESC d, BYTE bHeader, const char * c_pData)
|
||||
Sash(ch, c_pData);
|
||||
break;
|
||||
|
||||
case HEADER_CG_AVA2_DROP:
|
||||
PortNativeDrop(ch,*reinterpret_cast<const TPacketCGAva2Drop*>(c_pData));break;
|
||||
case HEADER_CG_SWITCHBOT:
|
||||
if ((iExtraLen = Switchbot(ch, c_pData, m_iBufferLeft)) < 0)
|
||||
return -1;
|
||||
|
||||
@@ -110,6 +110,7 @@ enum
|
||||
HEADER_CG_DRAGON_SOUL_REFINE = 205,
|
||||
HEADER_CG_STATE_CHECKER = 206,
|
||||
HEADER_CG_SASH = 211, // AVA2 sash
|
||||
HEADER_CG_AVA2_DROP = 215,
|
||||
HEADER_CG_ITEMS_PICKUP = 235, // PORT: AVA2
|
||||
HEADER_CG_SWITCHBOT = 171, // AVA2 switchbot (port_switchbot.cpp)
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "stdafx.h"
|
||||
#include "ava2_native_packets.h"
|
||||
#include "../../common/stl.h"
|
||||
#include "constants.h"
|
||||
#include "packet_info.h"
|
||||
@@ -230,6 +231,7 @@ CPacketInfoCG::CPacketInfoCG()
|
||||
Set(HEADER_CG_STATE_CHECKER, sizeof(BYTE), "ServerStateCheck", false);
|
||||
Set(HEADER_CG_SASH, sizeof(TPacketSash), "Sash", true);
|
||||
Set(HEADER_CG_ITEMS_PICKUP,sizeof(TPacketCGItemsPickUp),"ItemsPickup",true);
|
||||
Set(HEADER_CG_AVA2_DROP,sizeof(TPacketCGAva2Drop),"Ava2Drop",true);
|
||||
Set(HEADER_CG_SWITCHBOT, sizeof(TPacketCGSwitchbot), "Switchbot", true);
|
||||
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ private:
|
||||
// progress and the stored value is capped at the target by the database itself.
|
||||
struct PortBpState {
|
||||
unsigned season=0,generation=0;
|
||||
bool loaded=false,watching=false,wantInfo=false;
|
||||
bool loaded=false,watching=false,wantInfo=false,nativeUI=false;
|
||||
unsigned long long base[kPortBpSlots+1]={},delta[kPortBpSlots+1]={},inflight[kPortBpSlots+1]={};
|
||||
std::set<unsigned> claimed; // slots; 0 = final
|
||||
unsigned playtimeMark=0; // get_dword_time() up to which play time has been counted
|
||||
|
||||
@@ -37,8 +37,29 @@ inline void PortBpSendRewards(std::string& line,const std::vector<PortBpReward>&
|
||||
for(const auto& r:rewards)line+=" "+std::to_string(r.vnum)+" "+std::to_string(r.count);
|
||||
}
|
||||
|
||||
// AVA2 uiBattlePassEx is ENABLE_BATTLE_PASS (/battle_pass), distinct from the older GC230 UI.
|
||||
inline unsigned PortBpNativeType(unsigned type) {
|
||||
static const unsigned map[]={0,10,1,20,13,2,14,9,18,17};
|
||||
return type<sizeof(map)/sizeof(map[0])?map[type]:0;
|
||||
}
|
||||
inline std::string PortBpNativeRewards(const std::vector<PortBpReward>& rewards) {
|
||||
std::string text;
|
||||
for (const auto& r:rewards) {if(!text.empty())text+="#";text+=std::to_string(r.vnum)+"|"+std::to_string(r.count);}
|
||||
return text.empty()?"Empty":text;
|
||||
}
|
||||
inline void PortBpAutoGrant(LPCHARACTER ch,const PortBpSeason& season,PortBpState& state);
|
||||
inline void PortBpSendNative(LPCHARACTER ch,const PortBpSeason& season,PortBpState& state) {
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"BattlePassClear");
|
||||
const time_t stamp=get_global_time();struct tm date;localtime_r(&stamp,&date);
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"BattlePassPeriod %u",unsigned((date.tm_year+1900)*100+date.tm_mon+1));
|
||||
for (const auto& m:season.missions)
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"BattlePassAppendMission %u %s %llu %llu %u %u",PortBpNativeType(m.type),PortBpNativeRewards(m.rewards).c_str(),state.Value(m),m.target,m.sub,m.slot);
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"BattlePassSetStatus %u %lld %s",PortBpAccess(ch),std::max(0LL,(long long)season.end-get_global_time()),PortBpNativeRewards(season.final).c_str());
|
||||
}
|
||||
|
||||
inline void PortBpSendInfo(LPCHARACTER ch,const PortBpSeason& season,PortBpState& state) {
|
||||
state.watching=true;state.wantInfo=false;
|
||||
if (state.nativeUI) {PortBpSendNative(ch,season,state);return;}
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"MTBP1 season %u %u %u %lld %u",season.id,season.start,season.end,(long long)get_global_time(),unsigned(season.missions.size()));
|
||||
const time_t serverNow=time_t(get_global_time());struct tm date;localtime_r(&serverNow,&date);
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"MTBP1 access %u %u",PortBpAccess(ch),unsigned(date.tm_mon+1));
|
||||
@@ -67,7 +88,7 @@ inline void PortBpFlush(DWORD pid,PortBpState& state,const PortBpSeason* season)
|
||||
if(!state.loaded)state.inflight[m.slot]+=d;
|
||||
}
|
||||
if(values.empty())return;
|
||||
DBManager::instance().Query("INSERT INTO player.mt_battlepass_progress (pid,season,slot,value,target) VALUES %s "
|
||||
DBManager::instance().Query("INSERT INTO mt_battlepass_progress (pid,season,slot,value,target) VALUES %s "
|
||||
"ON DUPLICATE KEY UPDATE value=LEAST(value+VALUES(value),VALUES(target)),target=VALUES(target)",values.c_str());
|
||||
}
|
||||
|
||||
@@ -80,7 +101,7 @@ inline void PortBpLoad(DWORD pid,PortBpState& state) {
|
||||
auto it=PortBpStates().find(pid);
|
||||
if(it==PortBpStates().end() || it->second.generation!=generation || it->second.season!=season)return;
|
||||
PortBpState& state=it->second;
|
||||
if(!msg->Get()){sys_err("PORT_BP: load failed pid %u season %u",pid,season);return;}
|
||||
if(!msg || msg->uiSQLErrno || !msg->Get()){sys_err("PORT_BP: load failed pid %u season %u",pid,season);return;}
|
||||
unsigned long long stored[kPortBpSlots+1]={};
|
||||
for(unsigned i=0;i<msg->Get()->uiNumRows;++i) {
|
||||
MYSQL_ROW row=mysql_fetch_row(msg->Get()->pSQLResult);
|
||||
@@ -94,12 +115,13 @@ inline void PortBpLoad(DWORD pid,PortBpState& state) {
|
||||
LPCHARACTER ch=CHARACTER_MANAGER::instance().FindByPID(pid);
|
||||
const PortBpSeason* now=PortBpConfigFile().Active(get_global_time());
|
||||
if(!ch || !now || now->id!=season)return;
|
||||
PortBpAutoGrant(ch,*now,state);
|
||||
// PortBpNotify held back the done notices of events counted before the load; send those now.
|
||||
for(const auto& m:now->missions)
|
||||
if(stored[m.slot]<m.target && state.Done(m))ch->ChatPacket(CHAT_TYPE_COMMAND,"MTBP1 done %u",m.slot);
|
||||
if(state.wantInfo)PortBpSendInfo(ch,*now,state);
|
||||
},"SELECT 'p',slot,value FROM player.mt_battlepass_progress WHERE pid=%u AND season=%u "
|
||||
"UNION ALL SELECT 'c',slot,0 FROM player.mt_battlepass_claim WHERE pid=%u AND season=%u",pid,season,pid,season);
|
||||
},"SELECT 'p',slot,value FROM mt_battlepass_progress WHERE pid=%u AND season=%u "
|
||||
"UNION ALL SELECT 'c',slot,0 FROM mt_battlepass_claim WHERE pid=%u AND season=%u",pid,season,pid,season);
|
||||
}
|
||||
|
||||
inline const PortBpSeason* PortBpFindSeason(unsigned id) {
|
||||
@@ -135,8 +157,11 @@ inline PortBpState* PortBpSync(LPCHARACTER ch,const PortBpSeason*& season) {
|
||||
inline void PortBpNotify(LPCHARACTER ch,const PortBpSeason& season,PortBpState& state,const std::vector<unsigned>& changed,const std::vector<unsigned>& finished) {
|
||||
if(state.watching)
|
||||
for(unsigned slot:changed)ch->ChatPacket(CHAT_TYPE_COMMAND,"MTBP1 progress %u %llu",slot,state.Value(*season.Slot(slot)));
|
||||
if (state.nativeUI && state.watching)
|
||||
for(unsigned slot:changed)ch->ChatPacket(CHAT_TYPE_COMMAND,"BattlePassSetMission %u %llu",PortBpNativeType(season.Slot(slot)->type),state.Value(*season.Slot(slot)));
|
||||
if(!state.loaded)return; // values are not known yet; the window shows them once it is loaded
|
||||
for(unsigned slot:finished)ch->ChatPacket(CHAT_TYPE_COMMAND,"MTBP1 done %u",slot);
|
||||
if (!finished.empty())PortBpAutoGrant(ch,season,state);
|
||||
}
|
||||
|
||||
inline void PortBpAccruePlaytime(LPCHARACTER ch,const PortBpSeason& season,PortBpState& state) {
|
||||
@@ -201,6 +226,7 @@ inline const char* PortBpStacks(const std::vector<PortBpReward>& rewards,std::ve
|
||||
// /mt_bp 1 claim SLOT. The claim row is written first and synchronously; only the request that inserted it hands
|
||||
// out the items, into cells checked free beforehand, so retries, double clicks and other cores cannot pay twice.
|
||||
inline void PortBpClaim(LPCHARACTER ch,const PortBpSeason& season,PortBpState& state,unsigned slot) {
|
||||
if(ch->IsDead() || ch->IsWarping() || !ch->CanHandleItem() || ch->GetExchange() || ch->GetMyShop() || ch->GetShopOwner() || ch->IsOpenSafebox() || ch->IsCubeOpen()){ch->ChatPacket(CHAT_TYPE_COMMAND,"MTBP1 error busy");return;}
|
||||
if(PortBpAccess(ch)!=1){ch->ChatPacket(CHAT_TYPE_COMMAND,"MTBP1 error ticket");return;}
|
||||
if(const char* error=PortBpClaimError(season,state,slot)){ch->ChatPacket(CHAT_TYPE_COMMAND,"MTBP1 error %s",error);return;}
|
||||
const std::vector<PortBpReward>& rewards=slot?season.Slot(slot)->rewards:season.final;
|
||||
@@ -216,8 +242,8 @@ inline void PortBpClaim(LPCHARACTER ch,const PortBpSeason& season,PortBpState& s
|
||||
if(!PortBpFit(free,INVENTORY_PAGE_SIZE,5,sizes,cells)){ch->ChatPacket(CHAT_TYPE_COMMAND,"MTBP1 error space");return;}
|
||||
const DWORD pid=ch->GetPlayerID();
|
||||
std::unique_ptr<SQLMsg> msg(DBManager::instance().DirectQuery(
|
||||
"INSERT IGNORE INTO player.mt_battlepass_claim (pid,season,slot,claimed_at) VALUES (%u,%u,%u,%lld)",pid,season.id,slot,(long long)get_global_time()));
|
||||
if(!msg || !msg->Get()){sys_err("PORT_BP: claim insert failed pid %u season %u slot %u",pid,season.id,slot);ch->ChatPacket(CHAT_TYPE_COMMAND,"MTBP1 error db");return;}
|
||||
"INSERT IGNORE INTO mt_battlepass_claim (pid,season,slot,claimed_at) VALUES (%u,%u,%u,%lld)",pid,season.id,slot,(long long)get_global_time()));
|
||||
if(!msg || msg->uiSQLErrno || !msg->Get()){sys_err("PORT_BP: claim insert failed pid %u season %u slot %u",pid,season.id,slot);ch->ChatPacket(CHAT_TYPE_COMMAND,"MTBP1 error db");return;}
|
||||
state.claimed.insert(slot);
|
||||
if(msg->Get()->uiAffectedRows!=1){ch->ChatPacket(CHAT_TYPE_COMMAND,"MTBP1 error claimed");return;}
|
||||
const std::string hint=std::to_string(season.id)+" "+std::to_string(slot);
|
||||
@@ -234,6 +260,18 @@ inline void PortBpClaim(LPCHARACTER ch,const PortBpSeason& season,PortBpState& s
|
||||
ch->Save();
|
||||
}
|
||||
|
||||
// AVA2 grants mission rewards on completion. Existing unique claim rows are retained as the
|
||||
// migration/idempotency boundary; full bags keep the mission claim pending for the next open.
|
||||
inline void PortBpAutoGrant(LPCHARACTER ch,const PortBpSeason& season,PortBpState& state) {
|
||||
static std::set<DWORD> granting;
|
||||
const DWORD pid=ch->GetPlayerID();
|
||||
if (!state.nativeUI || !state.loaded || state.season!=season.id || PortBpAccess(ch)!=1 || granting.count(pid))return;
|
||||
granting.insert(pid);
|
||||
for (const auto& m:season.missions)
|
||||
if (state.Done(m) && !state.claimed.count(m.slot))PortBpClaim(ch,season,state,m.slot);
|
||||
granting.erase(pid);
|
||||
}
|
||||
|
||||
// Explicit confirmation comes from the client; all identity, month, eligibility
|
||||
// and consumption checks are authoritative here. Never turn an arbitrary quest
|
||||
// item into a ticket just because its value[0] happens to match the month.
|
||||
@@ -253,8 +291,8 @@ inline void PortBpActivate(LPCHARACTER ch,const PortBpSeason& season,PortBpState
|
||||
// A free-pass installation may have old progress. Activation starts fresh,
|
||||
// as clear_old_battlepass() does in the AVA2 quest. The ordered connection
|
||||
// runs the deletes before the new load, including across a quick reconnect.
|
||||
DBManager::instance().Query("DELETE FROM player.mt_battlepass_progress WHERE pid=%u AND season=%u",ch->GetPlayerID(),season.id);
|
||||
DBManager::instance().Query("DELETE FROM player.mt_battlepass_claim WHERE pid=%u AND season=%u",ch->GetPlayerID(),season.id);
|
||||
DBManager::instance().Query("DELETE FROM mt_battlepass_progress WHERE pid=%u AND season=%u",ch->GetPlayerID(),season.id);
|
||||
DBManager::instance().Query("DELETE FROM mt_battlepass_claim WHERE pid=%u AND season=%u",ch->GetPlayerID(),season.id);
|
||||
state.Reset(season.id);state.playtimeMark=get_dword_time();state.wantInfo=true;
|
||||
ch->SetQuestFlag("mt_bp.ticket_period",(date.tm_year+1900)*100+date.tm_mon+1);
|
||||
ch->SetQuestFlag("mt_bp.ticket_status",1);
|
||||
@@ -289,4 +327,24 @@ inline void PortBpCommand(LPCHARACTER ch,const char* argument) {
|
||||
PortBpClaim(ch,*season,*state,unsigned(atoi(args[2].c_str())));
|
||||
if(state->loaded)PortBpSendInfo(ch,*season,*state);
|
||||
}
|
||||
inline void PortBpNativeCommand(LPCHARACTER ch,const char* argument) {
|
||||
if(!ch || !ch->IsPC() || !ch->GetDesc())return;
|
||||
std::istringstream input(argument);std::string action,cell,vnum,extra;
|
||||
if(!(input>>action))return;
|
||||
const PortBpSeason* season=nullptr;PortBpState* state=PortBpSync(ch,season);
|
||||
if(state)state->nativeUI=true;
|
||||
if (state && state->lastCommand && get_dword_time()-state->lastCommand<kPortBpGapMs)return;
|
||||
if (action=="info" && !(input>>extra)) {
|
||||
if(state && state->loaded)PortBpAutoGrant(ch,*season,*state);
|
||||
if(!state){ch->ChatPacket(CHAT_TYPE_COMMAND,"BattlePassClear");ch->ChatPacket(CHAT_TYPE_COMMAND,"BattlePassSetStatus 0 0 Empty");return;}
|
||||
PortBpCommand(ch,"1 info");
|
||||
} else if (action=="reward" && !(input>>extra)) {
|
||||
if(!state)return;
|
||||
PortBpAutoGrant(ch,*season,*state);
|
||||
for (const auto& m:season->missions)if(!state->claimed.count(m.slot)){ch->ChatPacket(CHAT_TYPE_COMMAND,"MTBP1 error incomplete");return;}
|
||||
PortBpCommand(ch,"1 claim 0");
|
||||
} else if (action=="activate" && (input>>cell>>vnum) && !(input>>extra)) {
|
||||
PortBpCommand(ch,("1 activate "+cell+" "+vnum).c_str());
|
||||
} else if (action=="close" && !(input>>extra) && state)state->watching=false;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user