port: ServerStateChecker + module (batch 2 P2)

Verbatim 40250 CServerStateChecker and the ServerStateChecker Python
module replace the stub; PythonBoot owns the instance like
CPythonApplication::m_kServerStateChecker. The fake server gets a state
port that answers CG_STATE_CHECKER the way CInputHandshake and
CInputDB::RespondChannelStatus do; login_flow requests the channel list
after the character list (live: {1: 1, 2: 1}).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-09-24 00:27:35 +09:00
co-authored by Claude Opus 5.5
parent be5a68ff35
commit ce9f96398e
13 changed files with 362 additions and 32 deletions
@@ -0,0 +1,105 @@
#include "StdAfx.h"
#include "Packet.h"
#include "ServerStateChecker.h"
#include "../EterLib/NetAddress.h"
#pragma pack(push)
#pragma pack(1)
typedef unsigned char ServerStateChecker_Header;
typedef unsigned long ServerStateChecker_Key;
typedef unsigned long ServerStateChecker_Index;
typedef unsigned char ServerStateChecker_State;
#pragma pack(pop)
CServerStateChecker::CServerStateChecker()
{
Initialize();
}
CServerStateChecker::~CServerStateChecker()
{
Initialize();
m_poWnd = NULL;
}
void CServerStateChecker::Create(PyObject* poWnd)
{
m_poWnd = poWnd;
}
void CServerStateChecker::AddChannel(UINT uServerIndex, const char* c_szAddr, UINT uPort)
{
TChannel c;
c.uServerIndex = uServerIndex;
c.c_szAddr = c_szAddr;
c.uPort = uPort;
m_lstChannel.push_back(c);
}
void CServerStateChecker::Request()
{
if (m_lstChannel.empty()) {
return;
}
if (!m_kStream.Connect(m_lstChannel.begin()->c_szAddr, m_lstChannel.begin()->uPort))
{
for (std::list<TChannel>::const_iterator it = m_lstChannel.begin(); it != m_lstChannel.end(); ++it) {
PyCallClassMemberFunc(m_poWnd, "NotifyChannelState", Py_BuildValue("(ii)", it->uServerIndex, 0));
}
return;
}
m_kStream.ClearRecvBuffer();
m_kStream.SetSendBufferSize(1024);
m_kStream.SetRecvBufferSize(1024);
BYTE bHeader = HEADER_CG_STATE_CHECKER;
if (!m_kStream.Send(sizeof(bHeader), &bHeader))
{
for (std::list<TChannel>::const_iterator it = m_lstChannel.begin(); it != m_lstChannel.end(); ++it) {
PyCallClassMemberFunc(m_poWnd, "NotifyChannelState", Py_BuildValue("(ii)", it->uServerIndex, 0));
}
Initialize();
return;
}
}
void CServerStateChecker::Update()
{
m_kStream.Process();
BYTE bHeader;
if (!m_kStream.Recv(sizeof(bHeader), &bHeader)) {
return;
}
if (HEADER_GC_RESPOND_CHANNELSTATUS != bHeader) {
return;
}
int nSize;
if (!m_kStream.Recv(sizeof(nSize), &nSize)) {
return;
}
for (int i = 0; i < nSize; i++) {
TChannelStatus channelStatus;
if (!m_kStream.Recv(sizeof(channelStatus), &channelStatus)) {
return;
}
for (std::list<TChannel>::const_iterator it = m_lstChannel.begin(); it != m_lstChannel.end(); ++it) {
if (channelStatus.nPort == it->uPort) {
PyCallClassMemberFunc(m_poWnd, "NotifyChannelState", Py_BuildValue("(ii)", it->uServerIndex, channelStatus.bStatus));
break;
}
}
}
Initialize();
}
void CServerStateChecker::Initialize()
{
m_lstChannel.clear();
m_kStream.Disconnect();
}
@@ -0,0 +1,64 @@
#include "StdAfx.h"
#include "ServerStateChecker.h"
PyObject * ServerStateCheckerCreate(PyObject* poSelf, PyObject* poArgs)
{
PyObject * poWnd;
if (!PyTuple_GetObject(poArgs, 0, &poWnd))
return Py_BadArgument();
CServerStateChecker::Instance().Create(poWnd);
return Py_BuildNone();
}
PyObject * ServerStateCheckerUpdate(PyObject* poSelf, PyObject* poArgs)
{
CServerStateChecker::Instance().Update();
return Py_BuildNone();
}
PyObject * ServerStateCheckerRequest(PyObject* poSelf, PyObject* poArgs)
{
CServerStateChecker::Instance().Request();
return Py_BuildNone();
}
PyObject * ServerStateCheckerAddChannel(PyObject* poSelf, PyObject* poArgs)
{
int nServerIndex;
if (!PyTuple_GetInteger(poArgs, 0, &nServerIndex))
return Py_BuildException();
char * szAddr;
if (!PyTuple_GetString(poArgs, 1, &szAddr))
return Py_BuildException();
int nPort;
if (!PyTuple_GetInteger(poArgs, 2, &nPort))
return Py_BuildException();
CServerStateChecker::Instance().AddChannel(nServerIndex, szAddr, nPort);
return Py_BuildNone();
}
PyObject * ServerStateCheckerInitialize(PyObject* poSelf, PyObject* poArgs)
{
CServerStateChecker::Instance().Initialize();
return Py_BuildNone();
}
void initServerStateChecker()
{
static PyMethodDef s_methods[] =
{
{ "Create", ServerStateCheckerCreate, METH_VARARGS },
{ "Update", ServerStateCheckerUpdate, METH_VARARGS },
{ "Request", ServerStateCheckerRequest, METH_VARARGS },
{ "AddChannel", ServerStateCheckerAddChannel, METH_VARARGS },
{ "Initialize", ServerStateCheckerInitialize, METH_VARARGS },
{ NULL, NULL, NULL },
};
//PyObject * poModule = Py_InitModule("ServerStateChecker", s_methods);
Py_InitModule("ServerStateChecker", s_methods);
}
@@ -51,3 +51,4 @@ void initChat();
void initnet();
void initeffect();
void initfly();
void initServerStateChecker();