Fix null character access in server bonus status query

This commit is contained in:
shen
2026-09-30 23:10:22 -07:00
parent eb5833747a
commit f2848af3ac
4 changed files with 56 additions and 3 deletions
+24
View File
@@ -63,6 +63,12 @@ struct CHARACTER_MANAGER {
std::map<DWORD,Character*> mobs;
static CHARACTER_MANAGER& instance() { static CHARACTER_MANAGER value; return value; }
Character* Find(DWORD vid) { return mobs[vid]; }
int GetMobExpRate(LPCHARACTER) { return 200; }
int GetMobGoldAmountRate(LPCHARACTER) { return 300; }
int GetMobGoldDropRate(LPCHARACTER) { return 400; }
int GetMobItemRate(LPCHARACTER ch) { assert(ch); return 999; } // locale rules require a real character
int GetGlobalMobItemRate() { return 500; }
};
using LPSECTREE=Sectree*;
struct SectreeMap {
@@ -90,6 +96,12 @@ int get_global_time() { return now; }
#define ACMD(name) void name(LPCHARACTER ch,const char* argument)
#define MT_AUTOHUNT_SERVER_TEST
#include "../../tools/server/autohunt-pull/autohunt_pull.h"
constexpr int PRIV_EXP_PCT=4, PRIV_ITEM_DROP=1, PRIV_GOLD_DROP=2, PRIV_GOLD10_DROP=3;
struct CPrivManager {
static CPrivManager& instance() { static CPrivManager pm; return pm; }
int GetPriv(LPCHARACTER ch, int type) { assert(ch); return type*10; }
};
#include "../../tools/server/autohunt-pull-range/server_bonuses.h"
int main() {
Sectree sec;
@@ -160,5 +172,17 @@ int main() {
for(auto vid:ten.mobs) assert(vid/10 < 10);
auto sparse=mt_autohunt::SelectGroups({{1,1,100,true},{1,2,110,true},{2,3,50,true}},20);
assert(sparse.groups==2 && sparse.mobs.size()==3 && sparse.mobs[0]==3);
// The status command must use the global item rate, never the locale getter with NULL.
Character bonusOwner; bonusOwner.pc=true;
do_server_bonuses(&bonusOwner, "");
assert(bonusOwner.replies.back()=="ServerBonuses 200 300 400 500 40 10 20 30");
do_server_bonuses(&bonusOwner, "");
assert(bonusOwner.replies.size()==1);
now+=2;
do_server_bonuses(&bonusOwner, "");
assert(bonusOwner.replies.size()==2);
Character notPlayer;
do_server_bonuses(&notPlayer, "");
assert(notPlayer.replies.empty());
puts("autohunt_pull_test: PASS");
}