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>
68 lines
4.4 KiB
Python
68 lines
4.4 KiB
Python
#!/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)
|