feat: serve native AVA2 battle pass, drop finder and event calendar
This commit is contained in:
@@ -71,7 +71,7 @@ static bool dbDown=false;
|
||||
using MYSQL_ROW=char**;
|
||||
struct Result{std::vector<std::vector<std::string>> rows;size_t next=0;std::vector<char*> cells;};
|
||||
struct SQLResult{unsigned uiNumRows=0,uiAffectedRows=0;Result* pSQLResult=nullptr;};
|
||||
struct SQLMsg{SQLResult result;Result data;bool ok=true;SQLResult* Get(){return ok?&result:nullptr;}};
|
||||
struct SQLMsg{unsigned uiSQLErrno=0;SQLResult result;Result data;bool ok=true;SQLResult* Get(){return ok?&result:nullptr;}};
|
||||
MYSQL_ROW mysql_fetch_row(Result* r){
|
||||
if(r->next>=r->rows.size())return nullptr;auto& row=r->rows[r->next++];r->cells.clear();
|
||||
for(auto& c:row)r->cells.push_back(&c[0]);return r->cells.data();}
|
||||
@@ -81,13 +81,13 @@ struct DBManager{
|
||||
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]{
|
||||
if(q.rfind("DELETE FROM player.mt_battlepass_",0)==0){
|
||||
if(q.rfind("DELETE FROM mt_battlepass_",0)==0){
|
||||
unsigned p,s;const bool isProgress=q.find("_progress")!=std::string::npos;
|
||||
sscanf(q.c_str()+std::string(isProgress?"DELETE FROM player.mt_battlepass_progress WHERE pid=":"DELETE FROM player.mt_battlepass_claim WHERE pid=").size(),"%u AND season=%u",&p,&s);
|
||||
sscanf(q.c_str()+std::string(isProgress?"DELETE FROM mt_battlepass_progress WHERE pid=":"DELETE FROM mt_battlepass_claim WHERE pid=").size(),"%u AND season=%u",&p,&s);
|
||||
if(isProgress){for(auto it=progress.begin();it!=progress.end();)if(std::get<0>(it->first)==p&&std::get<1>(it->first)==s)it=progress.erase(it);else ++it;}
|
||||
else {for(auto it=claims.begin();it!=claims.end();)if(std::get<0>(*it)==p&&std::get<1>(*it)==s)it=claims.erase(it);else ++it;}return;
|
||||
}
|
||||
assert(q.rfind("INSERT INTO player.mt_battlepass_progress (pid,season,slot,value,target) VALUES (",0)==0);
|
||||
assert(q.rfind("INSERT INTO mt_battlepass_progress (pid,season,slot,value,target) VALUES (",0)==0);
|
||||
assert(q.find("ON DUPLICATE KEY UPDATE value=LEAST(value+VALUES(value),VALUES(target)),target=VALUES(target)")!=std::string::npos);
|
||||
const char* p=q.c_str()+q.find("VALUES (")+7;unsigned pid,season,slot;unsigned long long v,t;int n;
|
||||
while(sscanf(p,"(%u,%u,%u,%llu,%llu)%n",&pid,&season,&slot,&v,&t,&n)==5){
|
||||
@@ -95,8 +95,8 @@ struct DBManager{
|
||||
});}
|
||||
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);++selects;
|
||||
queue.push_back([f,q]{unsigned pid,season,pid2,season2;
|
||||
assert(sscanf(q.c_str(),"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,&pid2,&season2)==4);
|
||||
assert(sscanf(q.c_str(),"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,&pid2,&season2)==4);
|
||||
assert(pid==pid2 && season==season2);
|
||||
SQLMsg m;m.ok=!dbDown;m.result.pSQLResult=&m.data;
|
||||
for(auto& e:progress)if(std::get<0>(e.first)==pid && std::get<1>(e.first)==season)
|
||||
@@ -105,7 +105,7 @@ struct DBManager{
|
||||
m.result.uiNumRows=unsigned(m.data.rows.size());f(&m);});}
|
||||
SQLMsg* DirectQuery(const char* f,...){va_list a;va_start(a,f);std::string q=format(f,a);va_end(a);queries.push_back(q);
|
||||
SQLMsg* m=new SQLMsg;m->ok=!dbDown;unsigned pid,season,slot;long long at;
|
||||
assert(sscanf(q.c_str(),"INSERT IGNORE INTO player.mt_battlepass_claim (pid,season,slot,claimed_at) VALUES (%u,%u,%u,%lld)",&pid,&season,&slot,&at)==4 && at==now);
|
||||
assert(sscanf(q.c_str(),"INSERT IGNORE INTO mt_battlepass_claim (pid,season,slot,claimed_at) VALUES (%u,%u,%u,%lld)",&pid,&season,&slot,&at)==4 && at==now);
|
||||
if(m->ok)m->result.uiAffectedRows=claims.insert(std::make_tuple(pid,season,slot)).second?1:0;
|
||||
return m;}
|
||||
void Run(){while(!queue.empty()){auto job=queue.front();queue.pop_front();job();}}
|
||||
@@ -284,6 +284,24 @@ int main(int argc,char** argv){
|
||||
tick();PortBpCommand(locked,"1 activate 3 25159");assert(Last(locked)=="MTBP1 error activated");
|
||||
Kill(locked,101);assert(PortBpStates()[20].delta[1]==1);
|
||||
locked->SetQuestFlag("mt_bp.ticket_period",202510);assert(PortBpAccess(locked)==0);
|
||||
|
||||
// Native mode reuses existing progress/claims and automatically grants each mission once.
|
||||
WriteConfig("MTBATTLEPASS 1\nseason 99 "+std::to_string(now-10)+" "+std::to_string(now+10000)+"\nmission 1 1 0 1 25041 1\nfinal 27992 1\n");tick(5001);
|
||||
auto native=new CHARACTER;native->pid=31;online[31]=native;
|
||||
PortBpNativeCommand(native,"info");db.Run();
|
||||
assert(Said(native,"BattlePassClear") && Said(native,"BattlePassAppendMission 10 25041|1 0 1 0 1"));
|
||||
Kill(native,101);assert(PortBpStates()[31].claimed.count(1) && claims.count(std::make_tuple(31u,99u,1u)));
|
||||
auto paid=native->bag.size();tick();PortBpNativeCommand(native,"info");db.Run();assert(native->bag.size()==paid);
|
||||
tick();PortBpNativeCommand(native,"reward");assert(PortBpStates()[31].claimed.count(0) && PortBpAccess(native)==2);
|
||||
paid=native->bag.size();tick();PortBpNativeCommand(native,"reward");assert(native->bag.size()==paid);
|
||||
auto migrated=new CHARACTER;migrated->pid=32;online[32]=migrated;
|
||||
progress[std::make_tuple(32u,99u,1u)]={1,1};claims.insert(std::make_tuple(32u,99u,1u));
|
||||
PortBpNativeCommand(migrated,"info");db.Run();assert(migrated->bag.empty() && PortBpStates()[32].claimed.count(1));
|
||||
auto full=new CHARACTER;full->pid=33;online[33]=full;std::fill(full->used.begin(),full->used.end(),true);
|
||||
progress[std::make_tuple(33u,99u,1u)]={1,1};PortBpNativeCommand(full,"info");db.Run();assert(!PortBpStates()[33].claimed.count(1));
|
||||
std::fill(full->used.begin(),full->used.end(),false);tick();PortBpNativeCommand(full,"info");assert(PortBpStates()[33].claimed.count(1) && full->bag.size()==1);
|
||||
for(const auto& sql:db.queries)assert(sql.find("player.")==std::string::npos);
|
||||
|
||||
// --- the file is removed: no season, nothing counted
|
||||
std::remove((basePath+"/port_battlepass.tsv").c_str());tick(5001);mark=b->messages.size();
|
||||
PortBpCommand(b,"1 info");assert(Last(b)=="MTBP1 none");
|
||||
|
||||
Reference in New Issue
Block a user