Add read-only world boss tracking (AVA2 uitrack port)

Each game core snapshots its timed boss regens once a second and shares
them over the original HEADER_GG_RELAY addressed to "#mt_boss", so old
cores just miss the player lookup instead of dropping the P2P link.
New /mt_features query kind "bosses" (capability bit 256, mask 511)
lists the player's channel plus the shared channel 99.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-15 22:36:04 +09:00
co-authored by Claude Opus 5.5
parent a5293945b7
commit 400e44fae4
10 changed files with 322 additions and 5 deletions
+67
View File
@@ -0,0 +1,67 @@
#!/usr/bin/env python3
"""Compile the world-boss board (port_boss_track.h) and check how the game wires it in."""
from pathlib import Path
import subprocess
import tempfile
ROOT=Path(__file__).resolve().parents[2]
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 '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.
relay=p2p.split('int CInputP2P::Relay',1)[1].split('\n}\n',1)[0]
assert relay.index('p->lSize < 0')<relay.index('PortBossRelay(d, p->szName')<relay.index('FindPC(p->szName)')
assert 'HEADER_GG_RELAY' in glue and 'P2P_MANAGER::instance().Send' in glue
assert 'regen->type==REGEN_TYPE_GROUP' in glue and 'GetMemberVector()[0]' in glue and 'bRank<MOB_RANK_BOSS' in glue
code=r'''
#include <cassert>
#include <cstdio>
#include "port_boss_track.h"
static PortBossWire W(unsigned vnum,unsigned map,unsigned alive,unsigned next){PortBossWire w={vnum,map,100,200,1800,next,(unsigned char)alive,1};return w;}
int main(){
static_assert(sizeof(PortBossWire)==26 && sizeof(PortBossHeader)==4,"wire layout");
assert(sizeof(kPortBossRelayName)<=25 && kPortBossRelayName[0]=='#'); // fits szName, never a player name
PortBossBoard a,b;
// Broadcast on the first snapshot, on alive changes, on next moving by more than 2 s, and every 60 s.
std::vector<PortBossWire> rows={W(2307,68,1,1000),W(1192,72,0,5000)};
assert(a.SetLocal(rows,1,100));assert(!a.SetLocal(rows,1,101));
rows[1].next=5002;assert(!a.SetLocal(rows,1,102));rows[1].next=5003;assert(a.SetLocal(rows,1,103));
rows[0].alive=0;assert(a.SetLocal(rows,1,104));
assert(!a.SetLocal(rows,1,163));assert(a.SetLocal(rows,1,164));
// Round trip to another core of the same channel, plus the shared core and another channel.
std::string packet=a.Encode(13001);assert(packet.size()==4+2*26);
assert(b.Receive("10.0.0.1",packet.data(),packet.size(),200));
PortBossBoard shared,other;
shared.SetLocal({W(2191,125,1,0)},99,200);other.SetLocal({W(591,3,1,0)},2,200);
std::string s=shared.Encode(13099),o=other.Encode(13011);
assert(b.Receive("10.0.0.1",s.data(),s.size(),200)&&b.Receive("10.0.0.1",o.data(),o.size(),200));
b.SetLocal({W(2091,104,1,0)},1,200);
auto seen=b.Rows(1,200);
assert(seen.size()==4); // CH2 rows hidden from CH1
assert(seen[0].wire.map==68&&seen[1].wire.map==72&&seen[2].wire.map==104&&seen[3].wire.map==125&&seen[3].channel==99);
assert(seen[0].wire.alive==0&&seen[1].wire.next==5003&&seen[0].wire.x==100&&seen[0].wire.period==1800);
assert(b.Rows(2,200).size()==2); // a CH2 player sees CH2 + shared, not CH1
// A newer snapshot from the same core replaces the old one; silent cores expire after 150 s.
a.SetLocal({W(2307,68,1,1000)},1,300);packet=a.Encode(13001);assert(b.Receive("10.0.0.1",packet.data(),packet.size(),300));
assert(b.Rows(1,300).size()==3);
assert(b.Rows(1,351).size()==2); // shared (last heard at 200) dropped, 13001 still fresh
assert(b.Rows(1,451).size()==1); // only the local snapshot remains
// Malformed payloads are rejected.
assert(!b.Receive("x",packet.data(),3,300));
assert(!b.Receive("x",packet.data(),packet.size()-1,300));
std::string big(4+65*26,'\0');big[3]=65;assert(!b.Receive("x",big.data(),big.size(),300));
// Local rows are capped per core; a query never exceeds 128 rows.
PortBossBoard many;std::vector<PortBossWire> lots;for(unsigned i=0;i<80;++i)lots.push_back(W(1000+i,1,1,0));
many.SetLocal(lots,1,0);assert(many.Encode(1).size()==4+64*26);
for(unsigned port=0;port<3;++port){std::string p=many.Encode(port);assert(b.Receive("y",p.data(),p.size(),452));}
assert(b.Rows(1,452).size()==128);
puts("PASS: broadcast throttle, encode/decode, channel filter, sort, replace, expiry, validation, caps");
}
'''
with tempfile.TemporaryDirectory(prefix='mt-boss-') 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)
+3 -1
View File
@@ -70,6 +70,7 @@ using LPCHARACTER=Character*;
#include <cstring>
static void PortCalendarQuery(LPCHARACTER,unsigned,unsigned){}
static bool PortDungeonQuery(LPCHARACTER,unsigned){return true;}
static unsigned bossQueries=0;void PortBossQuery(LPCHARACTER,unsigned request){bossQueries=request;}
#include "port_features.h"
#include "port_dungeon_rules.h"
static void query(Character& ch,const char* text){clockms+=300;do_port_features(&ch,text);}
@@ -106,7 +107,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 255 1700000000");
Character ch;query(ch,"1 1 cap");assert(ch.messages.back()=="MTF1 cap 1 1 511 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");
@@ -116,6 +117,7 @@ int main(){
bool stone=false,hp=false;for(auto& line:ch.messages){stone|=line.find(" stone 10")!=std::string::npos;hp|=line.find(" hp 123")!=std::string::npos;}
assert(stone && hp && ch.messages.size()==sizeof(kPortStats)/sizeof(kPortStats[0])+2);
do_port_features(&ch,"1 8 stats");assert(ch.messages.back()=="MTF1 error 8 rate");
query(ch,"1 11 bosses");assert(bossQueries==11);query(ch,"1 12 bosses 1 0");assert(bossQueries==11 && ch.messages.back()=="MTF1 error 12 unsupported");
for(auto bad:{"2 9 stats","1 0 cap","1 -1 cap","1 4294967296 cap","1 10 cap too many extra"}) {
auto size=ch.messages.size();query(ch,bad);assert(ch.messages.size()==size);
}