Port PythonExceptionSender and install it at boot as 40250 Main does

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-09-30 12:31:04 +09:00
co-authored by Claude Opus 5.5
parent 3dfb09df92
commit ff71726ff0
6 changed files with 128 additions and 0 deletions
+8
View File
@@ -14,6 +14,7 @@
#include "../EterLib/HostCursor.h"
#include "UserInterface/PythonNetworkStream.h"
#include "UserInterface/AccountConnector.h"
#include "UserInterface/PythonExceptionSender.h"
#include "UserInterface/ServerStateChecker.h"
#include "UserInterface/PythonPlayer.h"
#include "GameLib/FlyingObjectManager.h"
@@ -70,6 +71,8 @@ namespace
{
// 40250 has this on Main()'s stack. CPythonLauncher is a CSingleton, so there is still only ever one.
std::unique_ptr<CPythonLauncher> g_launcher;
// 40250 Main(): CPythonExceptionSender pyExceptionSender; SetExceptionSender(&pyExceptionSender);
std::unique_ptr<CPythonExceptionSender> g_exception_sender;
std::unique_ptr<UI::CWindowManager> g_window_manager;
std::unique_ptr<CPythonResource> g_resource;
// 40250 CPythonApplication::m_timer; CSlotWindow's cool time and Process() read it via Instance().
@@ -733,6 +736,8 @@ bool Start(const char* stdlib_path, std::string* error)
PythonHost::Configure();
g_launcher = std::make_unique<CPythonLauncher>(); // Py_Initialize
g_exception_sender = std::make_unique<CPythonExceptionSender>();
SetExceptionSender(g_exception_sender.get());
// The script fiber (RunMainScript) is a second OS thread; 2.7 creates the GIL lazily.
PyEval_InitThreads();
if (!g_launcher->Create())
@@ -1071,6 +1076,9 @@ void Stop()
g_window_manager.reset();
g_resource.reset();
g_timer.reset();
// PORT: 40250 leaves g_pkExceptionSender dangling once Main() returns; Boot can run again here.
SetExceptionSender(NULL);
g_exception_sender.reset();
g_launcher.reset();
}
+10
View File
@@ -0,0 +1,10 @@
// stdafx.cpp : source file that includes just the standard includes
// scriptLib.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "StdAfx.h"
void SetExceptionSender(IPythonExceptionSender * pkExceptionSender)
{
g_pkExceptionSender = pkExceptionSender;
}
@@ -0,0 +1,67 @@
#include "StdAfx.h"
#include "PythonExceptionSender.h"
void CPythonExceptionSender::Send()
{
//DWORD dwCRC32 = GetCaseCRC32(m_strExceptionString.c_str(), m_strExceptionString.length());
//if (m_kSet_dwSendedExceptionCRC.end() != m_kSet_dwSendedExceptionCRC.find(dwCRC32))
// return;
//TraceError("%s", m_strExceptionString.c_str());
//SOCKET s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
//if (s==INVALID_SOCKET)
//{
// Tracef(" CPythonExceptionSender::Send() - Invalid Socket");
//}
//DWORD arg = 1;
//ioctlsocket(s, FIONBIO, &arg); // Non-blocking mode
//char szServerAddr[256];
//int nServerPort;
//strncpy(szServerAddr, "211.105.222.20", sizeof(szServerAddr)-1);
//nServerPort=LocaleService_GetPythonErrorReportPort();
//
//sockaddr_in sa;
//sa.sin_family = AF_INET;
//sa.sin_port = htons(nServerPort);
//sa.sin_addr.s_addr = inet_addr(szServerAddr);
//if (connect(s,(sockaddr*)&sa,sizeof(sa)))
// return;
//int number_ticket=0;
//if (recv(s,(char*)&number_ticket,4,0))
// return;
//int length=m_strExceptionString.length();
//int total=0;
//int ret=0;
//int count = 100;
//while(count--)
//{
// // send plain text
// ret = send(s,(char*)(&m_strExceptionString[0])+total,length-total,0);
//
// if (ret<0)
// break;
// total+=ret;
// if (total>=length)
// break;
//}
//closesocket(s);
//m_kSet_dwSendedExceptionCRC.insert(dwCRC32);
}
CPythonExceptionSender::CPythonExceptionSender()
{
}
CPythonExceptionSender::~CPythonExceptionSender()
{
}
@@ -0,0 +1,13 @@
#pragma once
class CPythonExceptionSender : public IPythonExceptionSender
{
public:
CPythonExceptionSender();
virtual ~CPythonExceptionSender();
void Send();
protected:
std::set<DWORD> m_kSet_dwSendedExceptionCRC;
};