diff --git a/src/server/game/src/char_item.cpp b/src/server/game/src/char_item.cpp index 1dfbe9c0..02434ee7 100755 --- a/src/server/game/src/char_item.cpp +++ b/src/server/game/src/char_item.cpp @@ -43,6 +43,7 @@ #include "../../common/VnumHelper.h" #include "DragonSoul.h" +#include "port_attr_lock.h" #include "buff_on_attributes.h" #include "belt_inventory_helper.h" @@ -4555,6 +4556,15 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell) break; case USE_CHANGE_ATTRIBUTE : + // AVA2 lock materials carry the selected 1-based attribute in socket 0. + if (item->GetVnum() == 50348 || item->GetVnum() == 50349) + { + const long index = item->GetSocket(0); + const char* error = index < 1 || index > 5 ? "slot" : + PortAttrLockUse(this, item2, unsigned(index - 1), item); + if (error) ChatPacket(CHAT_TYPE_INFO, "Attribute lock: %s", error); + return error == NULL; + } if (item2->GetAttributeSetIndex() == -1) { ChatPacket(CHAT_TYPE_INFO, LC_TEXT("속성을 변경할 수 없는 아이템입니다.")); diff --git a/src/server/game/src/cmd_general.cpp b/src/server/game/src/cmd_general.cpp index 9dbb8016..40edb2a8 100755 --- a/src/server/game/src/cmd_general.cpp +++ b/src/server/game/src/cmd_general.cpp @@ -42,6 +42,7 @@ #include "biolog_remote.h" #include "port_dungeons.h" #include "port_calendar_runtime.h" +#include "port_ava2_travel.h" #include "port_features.h" #include "port_switchbot.h" #include "port_pickup.h" diff --git a/src/server/game/src/port_attr_lock.cpp b/src/server/game/src/port_attr_lock.cpp index 3ceba37a..81b13774 100644 --- a/src/server/game/src/port_attr_lock.cpp +++ b/src/server/game/src/port_attr_lock.cpp @@ -36,3 +36,18 @@ bool PortAttrLockSet(CHARACTER* ch,CItem* item,unsigned mask) { if(ch)LogManager::instance().ItemLog(ch,item,"ATTR_LOCK",hint); return true; } + +const char* PortAttrLockUse(CHARACTER* ch,CItem* item,unsigned slot,CItem* material) { + if(!item || item->GetOwner()!=ch || item->IsEquipped() || item->IsExchanging() || item->isLocked())return "item"; + if(!material || material==item || material->GetOwner()!=ch || material->IsExchanging() || material->isLocked() || + material->IsEquipped() || material->GetCount()<1)return "material"; + const bool addon=item->GetProto() && item->GetProto()->sAddonType; + const unsigned old=PortAttrLockEffective(PortAttrLockGet(item),PortAttrFilled(item),addon); + const bool removing=slot<5 && (old>>slot&1); + if(material->GetVnum()!=(removing?50349u:50348u))return "material"; + unsigned mask=0; + if(const char* error=PortAttrLockToggle(old,slot,PortAttrFilled(item),addon,mask))return error; + if(!PortAttrLockSet(ch,item,mask))return "db"; + material->SetCount(material->GetCount()-1); + return NULL; +} diff --git a/src/server/game/src/port_attr_lock.h b/src/server/game/src/port_attr_lock.h index ec260e1f..fbdb7e78 100644 --- a/src/server/game/src/port_attr_lock.h +++ b/src/server/game/src/port_attr_lock.h @@ -36,6 +36,9 @@ inline const char* PortAttrLockToggle(unsigned mask,unsigned slot,unsigned fille mask=PortAttrLockEffective(mask,filled,addon); const unsigned bit=addon && slot<2?kPortAttrLockAddonPair&filled:1u<kPortAttrLockGroups || next==filled)return "max"; out=next;return 0; @@ -48,4 +51,7 @@ void PortAttrLockBoot(); unsigned PortAttrLockGet(CItem* item); // Writes synchronously (a following warp loads the new value on the next core); false on SQL error. bool PortAttrLockSet(CHARACTER* ch,CItem* item,unsigned mask); +// MATERIAL is 50348 (add) or 50349 (remove); SLOT is zero based. Only a +// successful persistent change consumes one material. Used by manual and UI paths. +const char* PortAttrLockUse(CHARACTER* ch,CItem* item,unsigned slot,CItem* material); #endif diff --git a/src/server/game/src/port_ava2_travel.h b/src/server/game/src/port_ava2_travel.h new file mode 100644 index 00000000..a0d57751 --- /dev/null +++ b/src/server/game/src/port_ava2_travel.h @@ -0,0 +1,33 @@ +#ifndef PORT_AVA2_TRAVEL_H +#define PORT_AVA2_TRAVEL_H +// AVA2 cmd_general.cpp do_track_window's m_TeleportData. Coordinates are +// WORLD coordinates in metres, not the local coordinates of a regen snapshot. +struct PortTrackDestination {unsigned boss;long x,y;unsigned minLevel,maxLevel;}; +static const PortTrackDestination kPortTrackDestinations[]={ + {9844,3840,14323,40,60},{9836,3327,14848,65,85},{9838,3840,14861,80,100}, + {9840,4350,14850,95,115},{9842,3327,15384,105,120}, + {1093,5905,1105,40,120},{2092,689,6111,70,120},{2493,1800,12199,75,120}, + {2598,5918,993,80,120},{6091,5984,7073,90,120},{6191,4319,1647,90,120}, + {9018,11082,17824,105,120},{20442,7358,6237,110,120} +}; +inline const PortTrackDestination* PortTrackFind(unsigned boss) { + for(const auto& destination:kPortTrackDestinations)if(destination.boss==boss)return &destination; + return nullptr; +} + +static void PortTrackTravel(LPCHARACTER ch,unsigned request,unsigned boss) { + const PortTrackDestination* destination=PortTrackFind(boss); + const char* error=nullptr; + quest::PC* pc=quest::CQuestManager::instance().GetPCForce(ch->GetPlayerID()); + if(!destination)error="unsupported"; + else if(ch->GetLevel()minLevel || ch->GetLevel()>destination->maxLevel)error="level"; + else if(!pc || !pc->IsLoaded() || pc->IsRunning() || ch->IsDead() || ch->IsStun() || ch->IsWarping() || + !ch->CanHandleItem() || !ch->CanWarp())error="busy"; + // WarpSet resolves the destination's core and refuses missing maps. Never + // bypass dungeon admission or consume a dungeon ticket here. + else if(!ch->WarpSet(destination->x*100,destination->y*100,0))error="unavailable"; + if(error){ch->ChatPacket(CHAT_TYPE_COMMAND,"MTF1 error %u %s",request,error);return;} + ch->ChatPacket(CHAT_TYPE_COMMAND,"MTF1 begin %u travel %u 0 0 0 %lld",request,boss,(long long)get_global_time()); + ch->ChatPacket(CHAT_TYPE_COMMAND,"MTF1 end %u 0",request); +} +#endif diff --git a/src/server/game/src/port_battlepass_runtime.h b/src/server/game/src/port_battlepass_runtime.h index 7e6ab331..866641b6 100644 --- a/src/server/game/src/port_battlepass_runtime.h +++ b/src/server/game/src/port_battlepass_runtime.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "port_battlepass_hooks.h" static const unsigned kPortBpGapMs=300; // per-player gap between /mt_bp commands @@ -22,6 +23,16 @@ inline const PortBpSeason* PortBpSeasonNow() { } inline std::map& PortBpStates() {static std::map states;return states;} +// AVA2 ENABLE_BATTLE_PASS / battlePass quest: 25150..25161, value[0] +// selects the calendar month. Keep the year as well, so last year's pass cannot +// accidentally become active again. 0=locked, 1=active, 2=final reward claimed. +inline unsigned PortBpAccess(LPCHARACTER ch) { + const time_t now=time_t(get_global_time()); + struct tm date;localtime_r(&now,&date); + if(ch->GetQuestFlag("mt_bp.ticket_period")!=(date.tm_year+1900)*100+date.tm_mon+1)return 0; + return unsigned(ch->GetQuestFlag("mt_bp.ticket_status")); +} + inline void PortBpSendRewards(std::string& line,const std::vector& rewards) { for(const auto& r:rewards)line+=" "+std::to_string(r.vnum)+" "+std::to_string(r.count); } @@ -29,6 +40,8 @@ inline void PortBpSendRewards(std::string& line,const std::vector& inline void PortBpSendInfo(LPCHARACTER ch,const PortBpSeason& season,PortBpState& state) { state.watching=true;state.wantInfo=false; 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)); for(const auto& m:season.missions) { std::string line="MTBP1 mission "+std::to_string(m.slot)+" "+std::to_string(m.type)+" "+std::to_string(m.sub)+" "+ std::to_string(m.target)+" "+std::to_string(state.Value(m))+" "+std::to_string(state.claimed.count(m.slot)); @@ -130,7 +143,7 @@ inline void PortBpAccruePlaytime(LPCHARACTER ch,const PortBpSeason& season,PortB const unsigned now=get_dword_time(),seconds=(now-state.playtimeMark)/1000; if(!seconds)return; state.playtimeMark+=seconds*1000; - if(!season.Has(PORT_BP_PLAYTIME))return; + if(PortBpAccess(ch)!=1 || !season.Has(PORT_BP_PLAYTIME))return; std::vector changed,finished; PortBpAdd(season,state,PORT_BP_PLAYTIME,0,seconds,changed,finished); PortBpNotify(ch,season,state,changed,finished); @@ -140,7 +153,7 @@ inline void PortBpAccruePlaytime(LPCHARACTER ch,const PortBpSeason& season,PortB void PortBpCount(LPCHARACTER ch,unsigned kind,unsigned what,unsigned long long amount) { const PortBpSeason* season=nullptr; PortBpState* state=PortBpSync(ch,season); - if(!state || !amount || !season->Has(kind))return; + if(!state || PortBpAccess(ch)!=1 || !amount || !season->Has(kind))return; std::vector changed,finished; PortBpAdd(*season,*state,kind,what,amount,changed,finished); PortBpNotify(ch,*season,*state,changed,finished); @@ -188,6 +201,7 @@ inline const char* PortBpStacks(const std::vector& 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(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& rewards=slot?season.Slot(slot)->rewards:season.final; std::vector stacks; @@ -216,24 +230,57 @@ inline void PortBpClaim(LPCHARACTER ch,const PortBpSeason& season,PortBpState& s } sys_log(0,"PORT_BP: %s claimed season %u slot %u (%u stacks)",ch->GetName(),season.id,slot,unsigned(stacks.size())); ch->ChatPacket(CHAT_TYPE_COMMAND,"MTBP1 claimed %u",slot); + if(!slot)ch->SetQuestFlag("mt_bp.ticket_status",2); + ch->Save(); +} + +// 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. +inline void PortBpActivate(LPCHARACTER ch,const PortBpSeason& season,PortBpState& state,unsigned cell,unsigned vnum) { + 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(!state.loaded){ch->ChatPacket(CHAT_TYPE_COMMAND,"MTBP1 error loading");return;} + if(PortBpAccess(ch)){ch->ChatPacket(CHAT_TYPE_COMMAND,"MTBP1 error activated");return;} + LPITEM ticket=cellGetItem(TItemPos(INVENTORY,cell)):nullptr; + if(!ticket || ticket->GetVnum()!=vnum || vnum<25150 || vnum>25161 || ticket->IsExchanging() || ticket->isLocked()){ + ch->ChatPacket(CHAT_TYPE_COMMAND,"MTBP1 error ticket");return; + } + const time_t now=time_t(get_global_time());struct tm date;localtime_r(&now,&date); + if(ticket->GetValue(0)!=date.tm_mon+1){ch->ChatPacket(CHAT_TYPE_COMMAND,"MTBP1 error month");return;} + // 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); + 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); + ITEM_MANAGER::instance().RemoveItem(ticket,"MT_BP_ACTIVATE"); + PortBpLoad(ch->GetPlayerID(),state); ch->Save(); } // /mt_bp 1 info | /mt_bp 1 claim SLOT | /mt_bp 1 close inline void PortBpCommand(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);} + while(input>>token){if(token.size()>10 || args.size()>=4)return;args.push_back(token);} if(args.empty() || args[0]!="1")return; const PortBpSeason* season=nullptr; PortBpState* state=PortBpSync(ch,season); const bool info=args.size()==2 && args[1]=="info",close=args.size()==2 && args[1]=="close"; const bool claim=args.size()==3 && args[1]=="claim" && args[2].size()<=2 && args[2].find_first_not_of("0123456789")==std::string::npos; - if(!info && !close && !claim){ch->ChatPacket(CHAT_TYPE_COMMAND,"MTBP1 error invalid");return;} + const bool activate=args.size()==4 && args[1]=="activate" && args[2].size()<=3 && args[3].size()<=5 && + args[2].find_first_not_of("0123456789")==std::string::npos && args[3].find_first_not_of("0123456789")==std::string::npos; + if(!info && !close && !claim && !activate){ch->ChatPacket(CHAT_TYPE_COMMAND,"MTBP1 error invalid");return;} if(!state){if(!close)ch->ChatPacket(CHAT_TYPE_COMMAND,"MTBP1 none");return;} if(close){state->watching=false;return;} if(state->lastCommand && get_dword_time()-state->lastCommandChatPacket(CHAT_TYPE_COMMAND,"MTBP1 error rate");return;} state->lastCommand=get_dword_time(); PortBpAccruePlaytime(ch,*season,*state); + if(activate){PortBpActivate(ch,*season,*state,unsigned(atoi(args[2].c_str())),unsigned(atoi(args[3].c_str())));return;} if(info) { if(state->loaded)PortBpSendInfo(ch,*season,*state); else {state->wantInfo=true;state->watching=true;} diff --git a/src/server/game/src/port_features.h b/src/server/game/src/port_features.h index 0f644045..778b76a7 100644 --- a/src/server/game/src/port_features.h +++ b/src/server/game/src/port_features.h @@ -4,6 +4,7 @@ #include #include #include +static void PortTrackTravel(LPCHARACTER ch,unsigned request,unsigned boss); // Own-player read-only protocol v1. Capability bits: drops, chests, stats, reverse sources, dungeon snapshots; 256 = world bosses. void PortBossQuery(LPCHARACTER ch,unsigned request); static bool PortFeatureNumber(const std::string& text,unsigned& value) { @@ -44,7 +45,7 @@ ACMD(do_port_features) { ch->ChatPacket(CHAT_TYPE_COMMAND,"MTF1 error %u rate",request);return; } ch->m_portFeatureLastQuery=get_dword_time(); - if(kind=="cap" && args.size()==3) {ch->ChatPacket(CHAT_TYPE_COMMAND,"MTF1 cap %u 1 511 %lld",request,(long long)get_global_time());return;} + if(kind=="cap" && args.size()==3) {ch->ChatPacket(CHAT_TYPE_COMMAND,"MTF1 cap %u 1 1023 %lld",request,(long long)get_global_time());return;} if(kind=="dungeons" && args.size()==3) {PortDungeonQuery(ch,request);return;} if(kind=="bosses" && args.size()==3) {PortBossQuery(ch,request);return;} if(kind=="stats" && args.size()==3) { @@ -61,6 +62,7 @@ ACMD(do_port_features) { ch->ChatPacket(CHAT_TYPE_COMMAND,"MTF1 error %u invalid",request);return; } if(kind=="calendar" && subject==1) {PortCalendarQuery(ch,request,offset);return;} + if(kind=="travel" && !offset) {PortTrackTravel(ch,request,subject);return;} std::vector rows; unsigned mode=0; auto& manager=ITEM_MANAGER::instance(); diff --git a/src/server/game/src/port_switchbot.h b/src/server/game/src/port_switchbot.h index 3e9a616c..a7ba3122 100644 --- a/src/server/game/src/port_switchbot.h +++ b/src/server/game/src/port_switchbot.h @@ -83,7 +83,8 @@ static LPITEM PortSwitchItem(LPCHARACTER ch,const PortSwitchbot& bot) { } static bool PortSwitchScroll(LPITEM scroll) { - return scroll && scroll->GetType()==ITEM_USE && scroll->GetSubType()==USE_CHANGE_ATTRIBUTE; + return scroll && scroll->GetVnum()!=50348 && scroll->GetVnum()!=50349 && + scroll->GetType()==ITEM_USE && scroll->GetSubType()==USE_CHANGE_ATTRIBUTE; } static void PortSwitchState(LPCHARACTER ch,const PortSwitchbot* bot,bool active,const char* reason) { @@ -159,9 +160,9 @@ static const char* PortSwitchLock(LPCHARACTER ch,unsigned cell,unsigned slot) { auto it=g_portSwitchbots.find(ch->GetPlayerID()); if(it!=g_portSwitchbots.end() && it->second.item==item->GetID())return "running"; const bool addon=item->GetProto() && item->GetProto()->sAddonType; - unsigned mask=0; - if(const char* error=PortAttrLockToggle(PortAttrLockGet(item),slot,PortAttrFilled(item),addon,mask))return error; - if(!PortAttrLockSet(ch,item,mask))return "db"; + const unsigned old=PortAttrLockEffective(PortAttrLockGet(item),PortAttrFilled(item),addon); + const bool removing=slot<5 && (old>>slot&1); + if(const char* error=PortAttrLockUse(ch,item,slot,ch->FindSpecifyItem(removing?50349:50348)))return error; PortSwitchLockLine(ch,item); return NULL; } diff --git a/tests/features/test_attr_lock.py b/tests/features/test_attr_lock.py index 409dac4c..fcdca61d 100644 --- a/tests/features/test_attr_lock.py +++ b/tests/features/test_attr_lock.py @@ -86,12 +86,12 @@ int main(){ assert(!PortAttrLockToggle(17,4,five,false,out) && out==1); // unlock assert(!strcmp(PortAttrLockToggle(0,3,three,false,out),"slot")); // empty slot assert(!strcmp(PortAttrLockToggle(0,5,five,false,out),"slot")); - assert(!strcmp(PortAttrLockToggle(1,1,3,false,out),"max")); // would lock every filled slot + assert(!strcmp(PortAttrLockToggle(1,1,3,false,out),"five_attr")); // adding requires five attributes assert(!PortAttrLockToggle(0,0,five,true,out) && out==3); // addon pair = one group assert(!PortAttrLockToggle(3,4,five,true,out) && out==19); assert(!strcmp(PortAttrLockToggle(19,2,five,true,out),"max")); assert(!PortAttrLockToggle(19,1,five,true,out) && out==16); - assert(!strcmp(PortAttrLockToggle(0,0,3,true,out),"max")); // pair is all there is + assert(!strcmp(PortAttrLockToggle(0,0,3,true,out),"five_attr")); // adding requires five attributes assert(PortAttrLockEffective(1,five,true)==3 && PortAttrLockEffective(0xff,three,false)==7 && PortAttrLockEffective(24,three,false)==0); assert(PortAttrLockGroupCount(31,true)==4 && PortAttrLockGroupCount(5,true)==2); puts("PASS: ChangeAttribute keeps locked slots (plain/addon/empty), no duplicates, rare untouched; toggle rules"); diff --git a/tests/features/test_battlepass.py b/tests/features/test_battlepass.py index d7ca44ee..dfc4bb34 100644 --- a/tests/features/test_battlepass.py +++ b/tests/features/test_battlepass.py @@ -81,6 +81,12 @@ 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){ + 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); + 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.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; @@ -106,10 +112,15 @@ struct DBManager{ }; // --- characters, bag and items class CHARACTER; -struct CItem{DWORD vnum,count;CHARACTER* owner=nullptr;unsigned cell=0;bool AddToCharacter(CHARACTER* ch,TItemPos pos);DWORD GetVnum(){return vnum;}}; +struct CItem{DWORD vnum,count;int month=10;bool exchanging=false,locked=false; + int GetValue(int){return month;}bool IsExchanging(){return exchanging;}bool isLocked(){return locked;}CHARACTER* owner=nullptr;unsigned cell=0;bool AddToCharacter(CHARACTER* ch,TItemPos pos);DWORD GetVnum(){return vnum;}}; using LPITEM=CItem*; struct DESC{}; class CHARACTER{public: + std::map flags={{"mt_bp.ticket_period",202610},{"mt_bp.ticket_status",1}}; + int GetQuestFlag(const char* key){return flags[key];}void SetQuestFlag(const char* key,int value){flags[key]=value;} + bool IsDead(){return false;}bool IsWarping(){return false;}bool CanHandleItem(){return true;}void* GetExchange(){return nullptr;}void* GetMyShop(){return nullptr;}void* GetShopOwner(){return nullptr;} + bool IsOpenSafebox(){return false;}bool IsCubeOpen(){return false;}LPITEM GetItem(TItemPos pos){for(auto i:bag)if(i->cell==pos.cell)return i;return nullptr;} DESC desc;bool online=true,pc=true,stone=false;DWORD pid=7,race=101;int level=50;BYTE rank=0;int saves=0; std::vector messages;std::vector used=std::vector(INVENTORY_MAX_NUM,false);std::vector bag; const char* GetName(){return "Admin";}bool IsPC(){return pc;}DESC* GetDesc(){return online?&desc:nullptr;}DWORD GetPlayerID(){return pid;} @@ -129,7 +140,8 @@ bool CItem::AddToCharacter(CHARACTER* ch,TItemPos pos){ for(unsigned k=0;kused[pos.cell+5*k]);ch->used[pos.cell+5*k]=true;} assert(pos.cell/45==(pos.cell+5*(size-1))/45);owner=ch;cell=pos.cell;ch->bag.push_back(this);return true;} static int flushedItems=0; -struct ITEM_MANAGER{static ITEM_MANAGER& instance(){static ITEM_MANAGER m;return m;} +struct ITEM_MANAGER{void RemoveItem(LPITEM item,const char*){item->count=0;} + static ITEM_MANAGER& instance(){static ITEM_MANAGER m;return m;} TItemTable* GetTable(DWORD v){auto it=tables.find(v);return it==tables.end()?nullptr:&it->second;} LPITEM CreateItem(DWORD v,DWORD c){return new CItem{v,c};} void FlushDelayedSave(LPITEM){++flushedItems;}}; @@ -227,15 +239,14 @@ int main(int argc,char** argv){ tick();PortBpCommand(a,"1 claim 3");assert(Said(a,"MTBP1 error space") && !claims.count(std::make_tuple(7u,77u,3u))); for(unsigned c=0;c=45)a->used[c]=false; tick();PortBpCommand(a,"1 claim 3");assert(Said(a,"MTBP1 claimed 3") && a->bag.back()->vnum==11299 && a->bag.back()->cell==45); + tick();PortBpCommand(a,"1 claim 0");assert(Said(a,"MTBP1 error incomplete")); // a dragon soul stone in the config is refused at claim time (and logged), the slot stays claimable {PortBpState& s=PortBpStates()[7];s.delta[6]=2;} tick();PortBpCommand(a,"1 claim 6");assert(Said(a,"MTBP1 error config") && !claims.count(std::make_tuple(7u,77u,6u))); assert(logs.back()=="ERR PORT_BP: season 77 slot 6 has a reward that cannot go to the bag"); - // the final reward needs every mission - tick();PortBpCommand(a,"1 claim 0");assert(Said(a,"MTBP1 error incomplete")); tick();PortBpCommand(a,"1 claim 11");assert(Said(a,"MTBP1 error slot")); for(auto bad:{"1 claim","1 claim x","1 claim 123","1 open"}){tick();mark=a->messages.size();PortBpCommand(a,bad);assert(a->messages.size()==mark+1 && Last(a)=="MTBP1 error invalid");} - mark=a->messages.size();PortBpCommand(a,"2 info");PortBpCommand(a,"1 a b c");PortBpCommand(a,"1 claim 1 2");PortBpCommand(a,"1 claim 12345678901");assert(a->messages.size()==mark); + mark=a->messages.size();PortBpCommand(a,"2 info");PortBpCommand(a,"1 claim 12345678901");assert(a->messages.size()==mark); {PortBpState& s=PortBpStates()[7];for(unsigned i=1;i<=6;++i)s.delta[i]+=100000;} // everything done tick();PortBpCommand(a,"1 claim 0");assert(Said(a,"MTBP1 claimed 0") && Said(a,"MTBP1 final 1 1 27992 2 27993 1 27994 1 70024 1")); // --- logout writes and forgets; a new session loads the claims @@ -259,11 +270,25 @@ int main(int argc,char** argv){ Kill(b,101);now+=100000;tick(5001);Kill(b,101);db.Run(); assert(progress[std::make_tuple(9u,77u,1u)].first==5 && progress.count(std::make_tuple(9u,78u,1u))==0 && PortBpStates()[9].season==78); PortBpSave(b);db.Run();assert(progress[std::make_tuple(9u,78u,1u)].first==1); + // Ticket eligibility: locked players cannot accrue or claim, only a valid current-month ticket unlocks. + CHARACTER* locked=new CHARACTER;locked->pid=20;locked->flags.clear();online[20]=locked; + tick();PortBpCommand(locked,"1 info");db.Run();assert(Said(locked,"MTBP1 access 0 10")); + Kill(locked,101);assert(PortBpStates()[20].delta[1]==0); + tick();PortBpCommand(locked,"1 claim 1");assert(Said(locked,"MTBP1 error ticket")); + CItem ticket{25159,1};ticket.cell=3;ticket.month=9;locked->bag.push_back(&ticket); + tick();PortBpCommand(locked,"1 activate 3 25159");assert(Last(locked)=="MTBP1 error month" && ticket.count==1); + ticket.month=10;ticket.exchanging=true; + tick();PortBpCommand(locked,"1 activate 3 25159");assert(Last(locked)=="MTBP1 error ticket" && ticket.count==1);ticket.exchanging=false; + tick();PortBpCommand(locked,"1 activate 3 25158");assert(Last(locked)=="MTBP1 error ticket" && ticket.count==1); + tick();PortBpCommand(locked,"1 activate 3 25159");db.Run();assert(ticket.count==0 && PortBpAccess(locked)==1 && Said(locked,"MTBP1 access 1 10")); + 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); // --- 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"); WriteConfig("MTBATTLEPASS 1\nseason 1 1 2\n");tick();PortBpCommand(b,"1 info");assert(Last(b)=="MTBP1 none" && logs.back().find("ERR PORT_BP: port_battlepass.tsv disabled: ")==0); - puts("PASS: config, fit, kills, pushes, save, play time, claims (idempotent, space, db, config), final, reload, load race, season change"); + puts("PASS: ticket activation/current month/identity/consumption, config, fit, kills, pushes, save, play time, claims (idempotent, space, db, config), final, reload, load race, season change"); } ''' with tempfile.TemporaryDirectory(prefix='mt-bp-') as folder: diff --git a/tests/features/test_bosses.py b/tests/features/test_bosses.py index a93d6965..202a8914 100644 --- a/tests/features/test_bosses.py +++ b/tests/features/test_bosses.py @@ -8,7 +8,7 @@ SRC=ROOT/'src/server/game/src' def text(name):return (SRC/name).read_bytes().decode('latin1') features=text('port_features.h');glue=text('port_boss_track.cpp');p2p=text('input_p2p.cpp');main=text('main.cpp') assert 'if(kind=="bosses" && args.size()==3) {PortBossQuery(ch,request);return;}' in features -assert '"MTF1 cap %u 1 511 %lld"' in features +assert '"MTF1 cap %u 1 1023 %lld"' in features assert 'port_boss_track.cpp' in text('Makefile') assert 'PortBossTick();' in main.split('if (!g_bAuthServer)',1)[1].split('}',1)[0] # 1 s block, game cores only # Relay hook runs after the size checks and before the player lookup; old cores just miss the name. diff --git a/tests/features/test_queries.py b/tests/features/test_queries.py index 140bb6da..bf0cabb0 100644 --- a/tests/features/test_queries.py +++ b/tests/features/test_queries.py @@ -72,6 +72,7 @@ using LPCHARACTER=Character*; #include static void PortCalendarQuery(LPCHARACTER,unsigned,unsigned){} static bool PortDungeonQuery(LPCHARACTER,unsigned){return true;} +static unsigned travelBoss=0;static void PortTrackTravel(LPCHARACTER,unsigned,unsigned boss){travelBoss=boss;} static unsigned bossQueries=0;void PortBossQuery(LPCHARACTER,unsigned request){bossQueries=request;} #include "port_features.h" #include "port_dungeon_rules.h" @@ -116,7 +117,7 @@ int main(){ assert(rewards[0].total==100 && rewards[0].rule==WIKI_SINGLE); rewards=items.PortWikiChest(50012);assert(rewards[1].rule==WIKI_INDEPENDENT && rewards[1].weight==150 && rewards[1].total==100); assert(items.PortWikiChest(50013).empty() && items.PortWikiChest(19).empty()); - Character ch;query(ch,"1 1 cap");assert(ch.messages.back()=="MTF1 cap 1 1 511 1700000000"); + Character ch;query(ch,"1 99 travel 2493 0");assert(travelBoss==2493);query(ch,"1 1 cap");assert(ch.messages.back()=="MTF1 cap 1 1 1023 1700000000"); ch.messages.clear();query(ch,"1 2 mob 101 0");assert(ch.messages.size()==10 && ch.messages.back()=="MTF1 end 2 8"); query(ch,"1 3 mob 101 999");assert(ch.messages.back()=="MTF1 error 3 offset"); query(ch,"1 4 mob 9001 0");assert(ch.messages.back()=="MTF1 error 4 missing"); diff --git a/tests/features/test_switchbot.py b/tests/features/test_switchbot.py index b2475f20..9a257750 100644 --- a/tests/features/test_switchbot.py +++ b/tests/features/test_switchbot.py @@ -8,6 +8,7 @@ SRC=ROOT/'src/server/game/src' # The quiet-INFO branch must stay in the real ChatPacket; the stub below mirrors it. assert 'if (m_portQuietInfo && type == CHAT_TYPE_INFO)' in (SRC/'char.cpp').read_bytes().decode('latin1') assert '"mt_switchbot", do_port_switchbot' in (SRC/'cmd.cpp').read_bytes().decode('latin1') +lock_use=(SRC/'port_attr_lock.cpp').read_text().split('const char* PortAttrLockUse(',1)[1] code=r''' #include #include @@ -50,6 +51,7 @@ class CItem {public: const TPlayerItemAttribute& GetAttribute(int i){return attrs[i];}BYTE GetAttributeType(int i){return attrs[i].bType;} int GetAttributeCount(){int n=0;for(int i=0;i<5;++i)n+=attrs[i].bType!=0;return n;} CHARACTER* GetOwner(){return owner;}BYTE GetWindow(){return window;}unsigned GetCell(){return cell;} + bool isLocked(){return false;}int GetCount(){return count;}void SetCount(int n){count=n;} bool IsEquipped(){return equipped;}bool IsExchanging(){return exchanging;} }; using LPITEM=CItem*; @@ -96,6 +98,7 @@ struct CHARACTER_MANAGER{ static std::map locks;static bool lockFail=false; unsigned PortAttrLockGet(CItem* item){return locks[item->id];} bool PortAttrLockSet(CHARACTER*,CItem* item,unsigned mask){if(lockFail)return false;locks[item->id]=mask;return true;} +const char* PortAttrLockUse(@LOCK_USE@ static CHARACTER ch; static void cmd(const char* text){clockms+=300;ch.messages.clear();do_port_switchbot(&ch,text);} static long tick(){for(auto& e:events)if(!e->cancelled&&e->func){long r=e->func(e.get(),0);if(!r)e->func=nullptr;return r;}return -1;} @@ -166,12 +169,19 @@ int main(){ ch.vid.id=100;ch.messages.clear();assert(tick()==0 && ch.messages.empty() && g_portSwitchbots.empty()); assert(ch.uses==6); - // Lock toggle: filled slots only, at most 2 groups and never every filled slot, not on the rolling item. + // AVA2 lock costs: no material, partial attributes, persistence failure never consume. + CItem lockMaterial{2100,50348,ITEM_USE,USE_CHANGE_ATTRIBUTE,-1,40};lockMaterial.owner=&ch;lockMaterial.count=20; + CItem unlockMaterial{2101,50349,ITEM_USE,USE_CHANGE_ATTRIBUTE,-1,41};unlockMaterial.owner=&ch;unlockMaterial.count=20; + cmd("1 lock 10 0");assert(last()=="MTSB1 error lock material"); + ch.inventory.push_back(&lockMaterial);ch.inventory.push_back(&unlockMaterial); + cmd("1 lock 10 0");assert(last()=="MTSB1 error lock five_attr" && lockMaterial.count==20); + armor.attrs[3]={APPLY_MAX_HP,500};armor.attrs[4]={APPLY_STR,1}; + // Lock toggle: five slots filled, max two groups, not on the rolling item. armor.attrs[0]={APPLY_STR,2};armor.attrs[1]={APPLY_CRITICAL,1};armor.attrs[2]={APPLY_ATTBONUS_MONSTER,2}; cmd("1 lock 10 0");assert(last()=="MTSB1 lock 10 11209 1"); cmd("1 lock 10 2");assert(last()=="MTSB1 lock 10 11209 5"); cmd("1 lock 10 1");assert(last()=="MTSB1 error lock max"); - cmd("1 lock 10 3");assert(last()=="MTSB1 error lock slot"); + cmd("1 lock 10 3");assert(last()=="MTSB1 error lock max"); cmd("1 lock 10 5");assert(last()=="MTSB1 error lock slot"); cmd("1 lock 10 0");assert(last()=="MTSB1 lock 10 11209 4" && locks[1001]==4); cmd("1 lock 10 1");assert(last()=="MTSB1 lock 10 11209 6"); @@ -179,7 +189,8 @@ int main(){ cmd("1 lock 30 0");assert(last()=="MTSB1 error lock no_attr"); cmd("1 lock 99 0");assert(last()=="MTSB1 error lock item"); cmd("1 lock 10");assert(last()=="MTSB1 error lock invalid"); - lockFail=true;cmd("1 lock 10 1");assert(last()=="MTSB1 error lock db" && locks[1001]==6);lockFail=false; + assert(lockMaterial.count==17 && unlockMaterial.count==19); + lockFail=true;cmd("1 lock 10 1");assert(last()=="MTSB1 error lock db" && locks[1001]==6);lockFail=false;assert(unlockMaterial.count==19); ch.rolls={{{APPLY_STR,2}}};cmd("1 start 10 71084 5 1 3 12");cmd("1 lock 10 1");assert(last()=="MTSB1 error lock running"); cmd("1 stop"); // Addon weapon: slots 0 and 1 lock together and count as one group. @@ -196,7 +207,7 @@ int main(){ cmd("1 start 99999999999 71084 5 1 3 12");assert(ch.messages.empty()); // overlong token puts("PASS: allowed targets, validation, alternatives, original UseItem path, quiet INFO, stop reasons, VID drop"); } -''' +'''.replace('@LOCK_USE@',lock_use) with tempfile.TemporaryDirectory(prefix='mt-switchbot-') 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) diff --git a/tests/features/test_travel.py b/tests/features/test_travel.py new file mode 100644 index 00000000..b9414869 --- /dev/null +++ b/tests/features/test_travel.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +"""Exercise the production AVA2 entrance handler, including refusal paths.""" +from pathlib import Path +import subprocess +import tempfile + +SRC=Path(__file__).resolve().parents[2]/'src/server/game/src' +CODE=r''' +#include +#include +#include +#include +#include +enum {CHAT_TYPE_COMMAND=5}; +long long get_global_time(){return 1790900000;} +namespace quest { +struct PC {bool loaded=true,running=false;bool IsLoaded(){return loaded;}bool IsRunning(){return running;}}; +struct CQuestManager { + PC pc;bool exists=true;static CQuestManager& instance(){static CQuestManager m;return m;} + PC* GetPCForce(unsigned){return exists?&pc:nullptr;} +}; +} +struct Character { + unsigned level=75;bool dead=false,stun=false,warping=false,handle=true,canWarp=true,mapAvailable=true; + unsigned calls=0;long x=0,y=0,map=-1;std::vector messages; + unsigned GetPlayerID(){return 7;}unsigned GetLevel(){return level;} + bool IsDead(){return dead;}bool IsStun(){return stun;}bool IsWarping(){return warping;} + bool CanHandleItem(){return handle;}bool CanWarp(){return canWarp;} + bool WarpSet(long a,long b,long c){++calls;x=a;y=b;map=c;return mapAvailable;} + void ChatPacket(int,const char* format,...){char out[512];va_list args;va_start(args,format);vsnprintf(out,sizeof(out),format,args);va_end(args);messages.emplace_back(out);} +}; +using LPCHARACTER=Character*; +#include "port_ava2_travel.h" +int main(){ + Character ch;auto& manager=quest::CQuestManager::instance(); + PortTrackTravel(&ch,1,691);assert(ch.calls==0 && ch.messages.back()=="MTF1 error 1 unsupported"); + // AVA2's dragon entrance: world coordinates, no private instance index. + PortTrackTravel(&ch,2,2493);assert(ch.calls==1 && ch.x==180000 && ch.y==1219900 && ch.map==0); + assert(ch.messages.back()=="MTF1 end 2 0"); + for(const auto& destination:kPortTrackDestinations){ + ch.level=destination.minLevel-1;unsigned before=ch.calls;PortTrackTravel(&ch,3,destination.boss); + assert(ch.calls==before && ch.messages.back()=="MTF1 error 3 level"); + ch.level=destination.maxLevel+1;PortTrackTravel(&ch,3,destination.boss);assert(ch.calls==before); + ch.level=destination.minLevel;PortTrackTravel(&ch,3,destination.boss);assert(ch.calls==before+1); + ch.level=destination.maxLevel;PortTrackTravel(&ch,3,destination.boss);assert(ch.calls==before+2); + } + ch.level=75; + for(bool* flag:{&ch.dead,&ch.stun,&ch.warping,&manager.pc.running}){ + *flag=true;unsigned before=ch.calls;PortTrackTravel(&ch,4,2493); + assert(ch.calls==before && ch.messages.back()=="MTF1 error 4 busy");*flag=false; + } + for(bool* flag:{&ch.handle,&ch.canWarp,&manager.pc.loaded,&manager.exists}){ + *flag=false;unsigned before=ch.calls;PortTrackTravel(&ch,4,2493); + assert(ch.calls==before && ch.messages.back()=="MTF1 error 4 busy");*flag=true; + } + ch.mapAvailable=false;PortTrackTravel(&ch,5,2493);assert(ch.messages.back()=="MTF1 error 5 unavailable"); + puts("PASS: AVA2 entrance destinations, inclusive level limits, busy/quest/warp/map refusals"); +} +''' +with tempfile.TemporaryDirectory(prefix='mt-travel-') 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)