Add feature queries, dungeon information and event calendar UI

This commit is contained in:
shen
2026-10-15 02:28:01 -07:00
parent 9d9993b007
commit 4e2d39b612
17 changed files with 1248 additions and 11 deletions
+43
View File
@@ -15,6 +15,7 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
using namespace mtnet::classic;
@@ -911,6 +912,48 @@ bool FakeLoginServer::ServeGame(Connection& c, int index)
if (!c.Send(chat) || !c.Send(cmd.c_str(), cmd.size() + 1)) return Fail(name + ": biolog reply");
}
}
else if (text.rfind("/mt_features ",0)==0) {
std::istringstream in(text);std::string command,kind;unsigned version=0,request=0,subject=0,offset=0;
in>>command>>version>>request>>kind>>subject>>offset;
auto reply=[&](const std::string& cmd) {
GCChatHead chat={HDR_GC_CHAT,static_cast<std::uint16_t>(sizeof(GCChatHead)+cmd.size()+1),5,0,1};
return c.Send(chat)&&c.Send(cmd.c_str(),cmd.size()+1);
};
const std::string r=std::to_string(request);
if(kind=="cap") {if(!reply("MTF1 cap "+r+" 1 63 1700000000"))return Fail(name+": feature cap");}
else if(kind=="calendar") {
if(!reply("MTF1 begin "+r+" calendar 1 0 2 0 1700000000") ||
!reply("MTF1 event "+r+" 0 1 1 1700000000 1700003600 0 0 1") ||
!reply("MTF1 event "+r+" 1 2 2 1700086400 1700090000 2 0 0") ||
!reply("MTF1 end "+r+" 2"))return Fail(name+": calendar");
}
else if(kind=="dungeons") {
const std::pair<const char*,long long> values[]={
{"lair_end",1700003600},{"lair_join_end",1700000300},{"lair_phase",1},
{"lair_ticket",30179},{"lair_tickets",3},{"lair_boss",2430},{"lair_owned",7},
{"lair_alive",1},{"lair_npc",30121},{"lair_map",208},
{"weekly_end",1700561600},{"weekly_hunt_end",1700007200},{"weekly_active",1},
{"weekly_npc",30122},{"weekly_map",73}};
if(!reply("MTF1 begin "+r+" dungeons 0 0 15 0 1700000000"))return Fail(name+": dungeon begin");
for(unsigned i=0;i<15;++i)
if(!reply("MTF1 stat "+r+" "+std::to_string(i)+" "+values[i].first+" "+std::to_string(values[i].second)))return Fail(name+": dungeon stat");
if(!reply("MTF1 end "+r+" 15"))return Fail(name+": dungeon end");
}
else if(kind=="stats") {
if(!reply("MTF1 begin "+r+" stats 0 0 3 0 1700000000") ||
!reply("MTF1 stat "+r+" 0 maxhp 1500") || !reply("MTF1 stat "+r+" 1 stone 10") ||
!reply("MTF1 stat "+r+" 2 resist_human 4") || !reply("MTF1 end "+r+" 3"))return Fail(name+": feature stats");
} else {
unsigned total=kind=="mob"?10:kind=="chest"?2:1;
if(!reply("MTF1 begin "+r+" "+kind+" "+std::to_string(subject)+" "+std::to_string(offset)+" "+std::to_string(total)+" "+(kind=="chest"?"10":"0")+" 1700000000"))return Fail(name+": feature begin");
unsigned sent=0;
for(unsigned i=offset;i<total && sent<8;++i,++sent) {
std::string row=kind=="mob"?"30006 1 1 0 0 100 0 0":kind=="sources"?"101 1 0 1 30 100 0 0":i==0?"19 1 10 0 0 80 100 0":"1 500 10 0 0 20 100 0";
if(!reply("MTF1 row "+r+" "+std::to_string(i)+" "+row))return Fail(name+": feature row");
}
if(!reply("MTF1 end "+r+" "+std::to_string(sent)))return Fail(name+": feature end");
}
}
else if (text == "/server_bonuses") {
const std::string cmd = "ServerBonuses 200 200 200 200 200 0 200 0";
GCChatHead chat = {HDR_GC_CHAT, static_cast<std::uint16_t>(sizeof(GCChatHead) + cmd.size() + 1), 5, 0, 1};
+36 -1
View File
@@ -560,7 +560,7 @@ int main(int argc, char** argv)
if (!live && std::getenv("MT_TEST_WIKI")) {
CHECK(py("import mt_wiki, mt_wiki_data, mt_biolog, player\n"
"assert mt_wiki.g_window and mt_wiki.g_entry\n"
"assert not mt_wiki.CAPABILITIES['live_drops']\n"
"assert mt_wiki.ServerCapabilities()['live_drops'] is None\n"
"mt_wiki.g_entry.OnUpdate()"));
std::string xy;
CHECK(PythonBoot::Evaluate("'%d %d' % mt_wiki.g_entry.GetGlobalPosition()", &xy, nullptr));
@@ -605,6 +605,41 @@ int main(int argc, char** argv)
"_missing.Open()\nassert _missing.error and not _missing.catalogue\n"
"_missing.Destroy()\nmt_wiki.PATH=_saved_path"));
PythonBoot::SetUISize(800,600);
CHECK(py("_wiki.Open(30006)\n_wiki.QueryRemote('sources',30006)"));
CHECK(pump_until(7,[]{return py_true("_wiki.remoteData is not None");}));
CHECK(py("assert mt_wiki.ServerCapabilities()['live_drops']\nassert _wiki.remoteData['rows'][0][0]==101\n"
"_wiki.Follow(next(i for i,p in enumerate(_wiki.links) if isinstance(p[1],tuple) and p[1][0]=='mobs'))\n"
"assert _wiki.selected==('mobs',101)\n_wiki.QueryRemote('mob',101)"));
CHECK(pump_until(5,[]{return py_true("_wiki.remoteData is not None");}));
CHECK(py("assert _wiki.remoteData['total']==10 and len(_wiki.remoteData['rows'])==8\n_wiki.QueryRemote('mob',101,8)"));
CHECK(pump_until(5,[]{return py_true("_wiki.remoteData is not None and _wiki.remoteData['offset']==8");}));
CHECK(py("assert len(_wiki.remoteData['rows'])==2\n_wiki.Back()\n_wiki.QueryRemote('chest',50011)"));
CHECK(pump_until(5,[]{return py_true("_wiki.remoteData is not None and _wiki.remoteData['kind']=='chest'");}));
CHECK(py("assert _wiki.remoteData['mode']==10\nassert _wiki.remoteData['rows'][1][0]==1\n"
"assert any(p[0].startswith(u'金币') for p in _wiki.links)\n_wiki.Hide()\n"
"import mt_details\nmt_details.Toggle()"));
CHECK(pump_until(5,[]{return py_true("mt_details.g_window.values is not None");}));
CHECK(py("assert mt_details.g_window.values['stone']==10\n"
"assert mt_details.g_window.values['maxhp']==1500\n"
"assert mt_details.g_window.values['resist_human']==4\nmt_details.g_window.Hide()"));
CHECK(count_syserr("mt_feature_service: install failed")==0);
CHECK(py("import mt_dungeons\nmt_dungeons.Toggle()"));
CHECK(pump_until(5,[]{return py_true("mt_dungeons.g_window.values is not None");}));
CHECK(py("assert mt_wiki.ServerCapabilities()['dungeons']\n"
"_dungeon=mt_dungeons.g_window\nassert _dungeon.values['lair_tickets']==3\n"
"assert _dungeon.values['weekly_end']>_dungeon.values['lair_end']\n"
"_dungeon.Remind()\nassert _dungeon.reminder[0]==0\n"
"_dungeon.Select(1)\n_dungeon.Entry()\n_dungeon.Hide()"));
CHECK(py("import mt_calendar\nmt_calendar.Toggle()"));
CHECK(pump_until(5,[]{return py_true("mt_calendar.g_window.data is not None");}));
CHECK(py("assert mt_wiki.ServerCapabilities()['calendar']\n"
"_calendar=mt_calendar.g_window\nassert _calendar.data['rows'][0][6]==1\n"
"_calendar.Watch(1)\nassert _calendar.watch['id']==2\n"
"_calendar.Remind()\nassert _calendar.watch is None\n_calendar.Hide()"));
CHECK(count_syserr("mt_calendar: install failed")==0);
CHECK(count_syserr("mt_dungeons: install failed")==0);
CHECK(count_syserr("mt_details: install failed")==0);
CHECK(count_syserr("mt_wiki_entries: install failed")==0);
CHECK(count_syserr("mt_wiki: install failed")==0);
CHECK(count_syserr("mt_wiki_data: install failed")==0);
}