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:
co-authored by
Claude Opus 5.5
parent
a5293945b7
commit
400e44fae4
@@ -61,7 +61,7 @@ CPPFILE = BattleArena.cpp FSM.cpp MarkConvert.cpp MarkImage.cpp MarkManager.cpp
|
||||
desc_client.cpp desc_manager.cpp desc_p2p.cpp dev_log.cpp dungeon.cpp empire_text_convert.cpp entity.cpp\
|
||||
entity_view.cpp event.cpp event_queue.cpp exchange.cpp file_loader.cpp fishing.cpp gm.cpp guild.cpp\
|
||||
guild_manager.cpp guild_war.cpp horse_rider.cpp horsename_manager.cpp input.cpp input_auth.cpp input_db.cpp\
|
||||
input_login.cpp input_main.cpp input_p2p.cpp input_teen.cpp input_udp.cpp ip_ban.cpp\
|
||||
input_login.cpp input_main.cpp input_p2p.cpp port_boss_track.cpp input_teen.cpp input_udp.cpp ip_ban.cpp\
|
||||
item.cpp item_addon.cpp item_attribute.cpp item_manager.cpp item_manager_idrange.cpp locale.cpp\
|
||||
locale_service.cpp log.cpp login_data.cpp lzo_manager.cpp marriage.cpp matrix_card.cpp\
|
||||
messenger_manager.cpp mining.cpp mob_manager.cpp monarch.cpp motion.cpp over9refine.cpp p2p.cpp packet_info.cpp\
|
||||
|
||||
@@ -41,6 +41,8 @@ void CInputP2P::Logout(LPDESC d, const char * c_pData)
|
||||
P2P_MANAGER::instance().Logout(p->szName);
|
||||
}
|
||||
|
||||
bool PortBossRelay(LPDESC d, const char* name, const char* data, long size);
|
||||
|
||||
int CInputP2P::Relay(LPDESC d, const char * c_pData, size_t uiBytes)
|
||||
{
|
||||
TPacketGGRelay * p = (TPacketGGRelay *) c_pData;
|
||||
@@ -55,6 +57,9 @@ int CInputP2P::Relay(LPDESC d, const char * c_pData, size_t uiBytes)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (PortBossRelay(d, p->szName, c_pData + sizeof(TPacketGGRelay), p->lSize))
|
||||
return p->lSize;
|
||||
|
||||
sys_log(0, "InputP2P::Relay : %s size %d", p->szName, p->lSize);
|
||||
|
||||
LPCHARACTER pkChr = CHARACTER_MANAGER::instance().FindPC(p->szName);
|
||||
|
||||
@@ -237,6 +237,8 @@ extern std::map<DWORD, CLoginSim *> g_simByPID;
|
||||
extern std::vector<TPlayerTable> g_vec_save;
|
||||
unsigned int save_idx = 0;
|
||||
|
||||
void PortBossTick();
|
||||
|
||||
void heartbeat(LPHEART ht, int pulse)
|
||||
{
|
||||
DWORD t;
|
||||
@@ -262,6 +264,8 @@ void heartbeat(LPHEART ht, int pulse)
|
||||
|
||||
if (!g_bAuthServer)
|
||||
{
|
||||
PortBossTick();
|
||||
|
||||
TPlayerCountPacket pack;
|
||||
pack.dwCount = DESC_MANAGER::instance().GetLocalUserCount();
|
||||
db_clientdesc->DBPacket(HEADER_GD_PLAYER_COUNT, 0, &pack, sizeof(TPlayerCountPacket));
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
#include "stdafx.h"
|
||||
#include "utils.h"
|
||||
#include "config.h"
|
||||
#include "char.h"
|
||||
#include "desc.h"
|
||||
#include "event.h"
|
||||
#include "mob_manager.h"
|
||||
#include "p2p.h"
|
||||
#include "packet.h"
|
||||
#include "regen.h"
|
||||
#include "sectree_manager.h"
|
||||
#include "port_boss_track.h"
|
||||
|
||||
extern LPREGEN regen_list;
|
||||
static PortBossBoard s_portBoss;
|
||||
|
||||
// Leader of a boss regen (the mob itself, or member 0 of the group, which SpawnGroup makes the master),
|
||||
// or 0 when the regen is not a timed boss regen.
|
||||
static DWORD PortBossLeader(const REGEN* regen) {
|
||||
if(!regen->time || (regen->type!=REGEN_TYPE_MOB && regen->type!=REGEN_TYPE_GROUP && regen->type!=REGEN_TYPE_ANYWHERE))return 0;
|
||||
DWORD vnum=regen->vnum;
|
||||
if(regen->type==REGEN_TYPE_GROUP) {
|
||||
CMobGroup* group=CMobManager::instance().GetGroup(regen->vnum);
|
||||
if(!group || group->GetMemberVector().empty())return 0;
|
||||
vnum=group->GetMemberVector()[0];
|
||||
}
|
||||
const CMob* mob=CMobManager::instance().Get(vnum);
|
||||
if(!mob || mob->m_table.bType!=CHAR_TYPE_MONSTER || mob->m_table.bRank<MOB_RANK_BOSS)return 0;
|
||||
return vnum;
|
||||
}
|
||||
|
||||
void PortBossTick() {
|
||||
const long long now=get_global_time();
|
||||
std::vector<PortBossWire> rows;
|
||||
for(LPREGEN regen=regen_list;regen && rows.size()<kPortBossMaxRows;regen=regen->next) {
|
||||
const DWORD vnum=PortBossLeader(regen);
|
||||
if(!vnum)continue;
|
||||
PIXEL_POSITION base;
|
||||
if(!SECTREE_MANAGER::instance().GetMapBasePositionByMapIndex(regen->lMapIndex,base))continue;
|
||||
PortBossWire w;
|
||||
w.vnum=vnum;w.map=regen->lMapIndex;w.period=regen->time;
|
||||
w.x=regen->type==REGEN_TYPE_ANYWHERE?0:(regen->sx+regen->ex)/2-base.x;
|
||||
w.y=regen->type==REGEN_TYPE_ANYWHERE?0:(regen->sy+regen->ey)/2-base.y;
|
||||
w.alive=(unsigned char)std::min(std::max(regen->count,0),255);w.max=(unsigned char)std::min(std::max(regen->max_count,0),255);
|
||||
// regen_event tops the regen up to max_count each time it fires.
|
||||
w.next=regen->event?(unsigned)(now+event_time(regen->event)/passes_per_sec):0;
|
||||
rows.push_back(w);
|
||||
}
|
||||
if(!s_portBoss.SetLocal(rows,g_bChannel,now))return;
|
||||
const std::string payload=s_portBoss.Encode(p2p_port);
|
||||
std::string packet(sizeof(TPacketGGRelay),'\0');
|
||||
TPacketGGRelay* p=(TPacketGGRelay*)&packet[0];
|
||||
p->bHeader=HEADER_GG_RELAY;strlcpy(p->szName,kPortBossRelayName,sizeof(p->szName));p->lSize=payload.size();
|
||||
packet+=payload;
|
||||
P2P_MANAGER::instance().Send(packet.data(),packet.size());
|
||||
}
|
||||
|
||||
// Called by CInputP2P::Relay for every relay; true when it was a boss snapshot (consumed here).
|
||||
bool PortBossRelay(LPDESC d,const char* name,const char* data,long size) {
|
||||
if(strcmp(name,kPortBossRelayName))return false;
|
||||
if(!s_portBoss.Receive(d->GetHostName(),data,size,get_global_time()))
|
||||
sys_err("PortBossRelay: bad snapshot from %s size %ld",d->GetHostName(),size);
|
||||
return true;
|
||||
}
|
||||
|
||||
// MTF1 begin REQ bosses 0 0 TOTAL 0 TIME / boss REQ INDEX VNUM MAP X Y CHANNEL ALIVE MAX NEXT PERIOD / end REQ SENT
|
||||
void PortBossQuery(LPCHARACTER ch,unsigned request) {
|
||||
const long long now=get_global_time();
|
||||
const std::vector<PortBossRow> rows=s_portBoss.Rows(g_bChannel,now);
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"MTF1 begin %u bosses 0 0 %u 0 %lld",request,unsigned(rows.size()),now);
|
||||
for(unsigned i=0;i<rows.size();++i) {
|
||||
const PortBossWire& w=rows[i].wire;
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"MTF1 boss %u %u %u %u %d %d %u %u %u %u %u",request,i,w.vnum,w.map,w.x,w.y,
|
||||
rows[i].channel,unsigned(w.alive),unsigned(w.max),w.next,w.period);
|
||||
}
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"MTF1 end %u %u",request,unsigned(rows.size()));
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
#ifndef PORT_BOSS_TRACK_H
|
||||
#define PORT_BOSS_TRACK_H
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
// World boss tracking (AVA2 uitrack world-boss tab), read-only. Every core snapshots its own boss regens once a
|
||||
// second and shares them over the original HEADER_GG_RELAY addressed to a name no player can have, so cores
|
||||
// without this code just find no such player and skip the payload (a new GG header would make them close the link).
|
||||
static const char kPortBossRelayName[]="#mt_boss";
|
||||
static const unsigned kPortBossSharedChannel=99; // the shared core (game99) serves every channel
|
||||
static const unsigned kPortBossMaxRows=64; // per core
|
||||
static const unsigned kPortBossMaxTotal=128; // per query
|
||||
static const long long kPortBossExpire=150; // a peer that stopped sending (crash, shutdown) drops out
|
||||
static const long long kPortBossHeartbeat=60;
|
||||
#pragma pack(push,1)
|
||||
struct PortBossWire {
|
||||
unsigned vnum,map;int x,y;unsigned period,next;unsigned char alive,max;
|
||||
};
|
||||
struct PortBossHeader {
|
||||
unsigned short port;unsigned char channel,count;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
struct PortBossRow {
|
||||
PortBossWire wire;unsigned channel;
|
||||
};
|
||||
static bool PortBossSame(const std::vector<PortBossWire>& a,const std::vector<PortBossWire>& b) {
|
||||
if(a.size()!=b.size())return false;
|
||||
for(size_t i=0;i<a.size();++i) {
|
||||
const PortBossWire& x=a[i];const PortBossWire& y=b[i];
|
||||
// next is now + remaining pulses, so it may move by a second between two snapshots.
|
||||
if(x.vnum!=y.vnum || x.map!=y.map || x.alive!=y.alive || x.max!=y.max || x.period!=y.period ||
|
||||
std::llabs((long long)x.next-(long long)y.next)>2)return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
class PortBossBoard {
|
||||
public:
|
||||
// Returns true when the new local snapshot should be broadcast.
|
||||
bool SetLocal(const std::vector<PortBossWire>& rows,unsigned channel,long long now) {
|
||||
local=rows;if(local.size()>kPortBossMaxRows)local.resize(kPortBossMaxRows);localChannel=channel;
|
||||
if(sentAt && PortBossSame(local,sent) && now-sentAt<kPortBossHeartbeat)return false;
|
||||
sent=local;sentAt=now;return true;
|
||||
}
|
||||
std::string Encode(unsigned short port) const {
|
||||
PortBossHeader h={port,(unsigned char)localChannel,(unsigned char)local.size()};
|
||||
std::string out((const char*)&h,sizeof(h));
|
||||
if(!local.empty())out.append((const char*)&local[0],local.size()*sizeof(PortBossWire));
|
||||
return out;
|
||||
}
|
||||
// host is the sender's address; host+port names one core. False for a malformed payload.
|
||||
bool Receive(const std::string& host,const char* data,long size,long long now) {
|
||||
if(size<(long)sizeof(PortBossHeader))return false;
|
||||
PortBossHeader h;memcpy(&h,data,sizeof(h));
|
||||
if(h.count>kPortBossMaxRows || size!=(long)(sizeof(h)+h.count*sizeof(PortBossWire)))return false;
|
||||
Remote& r=remote[host+":"+std::to_string(h.port)];
|
||||
r.channel=h.channel;r.at=now;r.rows.resize(h.count);
|
||||
if(h.count)memcpy(&r.rows[0],data+sizeof(h),h.count*sizeof(PortBossWire));
|
||||
return true;
|
||||
}
|
||||
// Rows a player of channel sees: that channel and the shared core, sorted by map then boss.
|
||||
std::vector<PortBossRow> Rows(unsigned channel,long long now) {
|
||||
std::vector<PortBossRow> out;
|
||||
auto add=[&](const std::vector<PortBossWire>& rows,unsigned c) {
|
||||
if(c!=channel && c!=kPortBossSharedChannel)return;
|
||||
for(const auto& w:rows)out.push_back({w,c});
|
||||
};
|
||||
add(local,localChannel);
|
||||
for(auto it=remote.begin();it!=remote.end();) {
|
||||
if(now-it->second.at>kPortBossExpire){it=remote.erase(it);continue;}
|
||||
add(it->second.rows,it->second.channel);++it;
|
||||
}
|
||||
std::stable_sort(out.begin(),out.end(),[](const PortBossRow& a,const PortBossRow& b) {
|
||||
return a.wire.map!=b.wire.map?a.wire.map<b.wire.map:a.wire.vnum!=b.wire.vnum?a.wire.vnum<b.wire.vnum:a.channel<b.channel;
|
||||
});
|
||||
if(out.size()>kPortBossMaxTotal)out.resize(kPortBossMaxTotal);
|
||||
return out;
|
||||
}
|
||||
private:
|
||||
struct Remote {unsigned channel=0;long long at=0;std::vector<PortBossWire> rows;};
|
||||
std::vector<PortBossWire> local,sent;unsigned localChannel=0;long long sentAt=0;
|
||||
std::map<std::string,Remote> remote;
|
||||
};
|
||||
#endif
|
||||
@@ -4,7 +4,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <limits>
|
||||
// Own-player read-only protocol v1. Capability bits: drops, chests, stats, reverse sources, dungeon snapshots.
|
||||
// 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) {
|
||||
if (text.empty() || text.size()>10) return false;
|
||||
unsigned long long result=0;
|
||||
@@ -43,8 +44,9 @@ 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 255 %lld",request,(long long)get_global_time());return;}
|
||||
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=="dungeons" && args.size()==3) {PortDungeonQuery(ch,request);return;}
|
||||
if(kind=="bosses" && args.size()==3) {PortBossQuery(ch,request);return;}
|
||||
if(kind=="stats" && args.size()==3) {
|
||||
ch->ChatPacket(CHAT_TYPE_COMMAND,"MTF1 begin %u stats 0 0 %u 0 %lld",request,unsigned(sizeof(kPortStats)/sizeof(kPortStats[0])),(long long)get_global_time());
|
||||
for(unsigned i=0;i<sizeof(kPortStats)/sizeof(kPortStats[0]);++i) {
|
||||
|
||||
Reference in New Issue
Block a user