Merge main into feature/ava2-unlock

Conflicts resolved by keeping both sides: AVA2 attribute lock materials
(50348/50349) and battle pass tickets from main alongside the unlock
branch's costume enchants, talismans and new rings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-16 18:14:39 +09:00
co-authored by Claude Opus 5.5
556 changed files with 213114 additions and 44 deletions
+14 -1
View File
@@ -2473,11 +2473,24 @@ void CInstanceBase::__UpdateEffectShown()
else
isShown = false;
}
m_GraphicThingInstance.SetAttachingEffectShown(isShown);
m_GraphicThingInstance.SetAttachingEffectShown(isShown && PORT_IsDisplayVisible());
}
bool CInstanceBase::PORT_IsDisplayVisible()
{
// AVA2 CActorInstance::IsShop and InstanceBase::__CanRender, including
// the original 100/60/40/20/10 metre range presets. Never hide the main actor.
CInstanceBase* main = __GetMainInstancePtr();
if (!main || main == this || GetRace() < 30000 || GetRace() > 30020)
return true;
static const unsigned ranges[] = {10000, 6000, 4000, 2000, 1000};
return NEW_GetDistanceFromDestInstance(*main) <= ranges[CPythonSystem::Instance().GetShopNamesRange()];
}
bool CInstanceBase::__CanRender()
{
if (!PORT_IsDisplayVisible())
return false;
if (!__IsInViewFrustum())
return false;
if (IsAffect(AFFECT_INVISIBILITY))
+1
View File
@@ -402,6 +402,7 @@ class CInstanceBase
public:
void SetMainInstance();
bool PORT_IsDisplayVisible();
void OnSelected();
void OnUnselected();
@@ -12,6 +12,10 @@
#include <mutex>
#include <string>
#include <thread>
#include <chrono>
#ifdef MT_HAS_MESHPORT
#include "transport.h" // PORT: registration shares the same LAN/mesh policy as every game socket.
#endif
#include <arpa/inet.h>
#include <fcntl.h>
@@ -35,6 +39,11 @@ const int c_iRegisterTimeoutMs = 8000;
std::mutex gs_kRegisterMutex;
std::atomic<int> gs_iRegisterState(REGISTER_IDLE);
std::string gs_strRegisterResult;
// PORT: registration must stop on dialog cancellation and before the mesh runtime is torn down.
std::thread gs_registerWorker;
std::atomic<bool> gs_registerCancelled(false);
std::mutex gs_registerSocketMutex;
int gs_registerSocket = -1;
std::string __UrlEncode(const std::string& c_rstText)
{
@@ -58,8 +67,14 @@ std::string __UrlEncode(const std::string& c_rstText)
bool __WaitFor(int iSocket, short sEvents)
{
pollfd kPoll = { iSocket, sEvents, 0 };
return poll(&kPoll, 1, c_iRegisterTimeoutMs) == 1 && (kPoll.revents & sEvents);
const auto deadline = std::chrono::steady_clock::now() + std::chrono::milliseconds(c_iRegisterTimeoutMs);
while (!gs_registerCancelled && std::chrono::steady_clock::now() < deadline) {
pollfd kPoll = {iSocket,sEvents,0};
int result = poll(&kPoll,1,100);
if (result > 0) return (kPoll.revents & sEvents) != 0;
if (result < 0 && errno != EINTR) return false;
}
return false;
}
std::string __Post(const std::string& c_rstHost, int iPort, const std::string& c_rstBody)
@@ -72,6 +87,7 @@ std::string __Post(const std::string& c_rstHost, int iPort, const std::string& c
if (getaddrinfo(c_rstHost.c_str(), std::to_string(iPort).c_str(), &kHints, &pkAddr) != 0 || !pkAddr)
return "ERR CONNECT";
if (gs_registerCancelled) { freeaddrinfo(pkAddr); return "ERR CANCELLED"; }
const int iSocket = socket(pkAddr->ai_family, pkAddr->ai_socktype, pkAddr->ai_protocol);
if (iSocket < 0)
{
@@ -82,14 +98,37 @@ std::string __Post(const std::string& c_rstHost, int iPort, const std::string& c
const int iOne = 1;
setsockopt(iSocket, SOL_SOCKET, SO_NOSIGPIPE, &iOne, sizeof(iOne));
#endif
{
std::lock_guard<std::mutex> lock(gs_registerSocketMutex);
gs_registerSocket = iSocket;
}
fcntl(iSocket, F_SETFL, fcntl(iSocket, F_GETFL, 0) | O_NONBLOCK);
std::string stResult = "ERR CONNECT";
int iError = 0;
socklen_t iErrorLen = sizeof(iError);
#ifdef MT_HAS_MESHPORT
const int connected = mt::meshport::connect_socket(iSocket, *reinterpret_cast<sockaddr_in*>(pkAddr->ai_addr));
const bool throughMesh = mt::meshport::pending(iSocket);
bool meshReady = true;
if (mt::meshport::pending(iSocket)) {
int state = 0;
while (state == 0 && !gs_registerCancelled) {
state = mt::meshport::poll_socket(iSocket);
if (!state) std::this_thread::sleep_for(std::chrono::milliseconds(2));
}
meshReady = state == 1;
}
if (!gs_registerCancelled && meshReady && (throughMesh || connected == 0 ||
#else
if (connect(iSocket, pkAddr->ai_addr, pkAddr->ai_addrlen) == 0 ||
#endif
(errno == EINPROGRESS && __WaitFor(iSocket, POLLOUT) &&
getsockopt(iSocket, SOL_SOCKET, SO_ERROR, &iError, &iErrorLen) == 0 && iError == 0))
getsockopt(iSocket, SOL_SOCKET, SO_ERROR, &iError, &iErrorLen) == 0 && iError == 0)
#ifdef MT_HAS_MESHPORT
)
#endif
)
{
const std::string stRequest =
"POST /register HTTP/1.0\r\n"
@@ -140,9 +179,16 @@ std::string __Post(const std::string& c_rstHost, int iPort, const std::string& c
}
}
close(iSocket);
#ifdef MT_HAS_MESHPORT
mt::meshport::forget_socket(iSocket);
#endif
{
std::lock_guard<std::mutex> lock(gs_registerSocketMutex);
gs_registerSocket = -1;
close(iSocket);
}
freeaddrinfo(pkAddr);
return stResult;
return gs_registerCancelled ? "ERR CANCELLED" : stResult;
}
}
@@ -172,10 +218,12 @@ PyObject* netRegisterAccount(PyObject* poSelf, PyObject* poArgs)
return Py_BuildValue("i", 0); // one request at a time
}
if (gs_registerWorker.joinable()) gs_registerWorker.join();
gs_registerCancelled = false;
const std::string stHost = szHost;
const std::string stBody = "login=" + __UrlEncode(szLogin) + "&password=" + __UrlEncode(szPassword) +
"&social_id=" + __UrlEncode(szSocialID);
std::thread([stHost, iPort, stBody]()
gs_registerWorker = std::thread([stHost, iPort, stBody]()
{
const std::string stResult = __Post(stHost, iPort, stBody);
{
@@ -183,7 +231,7 @@ PyObject* netRegisterAccount(PyObject* poSelf, PyObject* poArgs)
gs_strRegisterResult = stResult;
}
gs_iRegisterState = REGISTER_DONE;
}).detach();
});
return Py_BuildValue("i", 1);
}
@@ -196,3 +244,22 @@ PyObject* netGetRegisterAccountResult(PyObject* poSelf, PyObject* poArgs)
std::lock_guard<std::mutex> kLock(gs_kRegisterMutex);
return Py_BuildValue("s", gs_strRegisterResult.c_str());
}
// PORT: cancellation interrupts both route preparation and HTTP I/O; the worker owns close().
void CancelAccountRegistration()
{
gs_registerCancelled = true;
std::lock_guard<std::mutex> lock(gs_registerSocketMutex);
if (gs_registerSocket >= 0) ::shutdown(gs_registerSocket,SHUT_RDWR);
}
void StopAccountRegistration()
{
CancelAccountRegistration();
if (gs_registerWorker.joinable()) gs_registerWorker.join();
gs_iRegisterState = REGISTER_IDLE;
}
PyObject* netCancelRegisterAccount(PyObject*,PyObject*)
{
CancelAccountRegistration();
return Py_BuildNone();
}
@@ -1,4 +1,7 @@
#include "StdAfx.h"
#ifdef MT_HAS_MESHPORT
#include "transport.h" // PORT: cancel only this login's pending mesh transports.
#endif
#include "PythonNetworkStream.h"
//#include "PythonNetworkDatagram.h"
#include "AccountConnector.h"
@@ -14,6 +17,7 @@ std::list<std::string> g_kList_strCommand;
// PORT: PythonAccountRegister.cpp
PyObject* netRegisterAccount(PyObject* poSelf, PyObject* poArgs);
PyObject* netGetRegisterAccountResult(PyObject* poSelf, PyObject* poArgs);
PyObject* netCancelRegisterAccount(PyObject*,PyObject*); // PORT: cancel pending HTTP/mesh work.
PyObject* netGetBettingGuildWarValue(PyObject* poSelf, PyObject* poArgs)
{
@@ -1014,6 +1018,22 @@ PyObject* netLogOutGame(PyObject* poSelf, PyObject* poArgs)
return Py_BuildNone();
}
#ifdef MT_HAS_MESHPORT
PyObject* netCancelPendingLogin(PyObject*,PyObject*)
{
bool cancelled = false;
auto& account = CAccountConnector::Instance();
auto& game = CPythonNetworkStream::Instance();
if (mt::meshport::pending_owner(static_cast<CNetworkStream*>(&account))) {
account.Disconnect(); cancelled = true;
}
if (mt::meshport::pending_owner(static_cast<CNetworkStream*>(&game))) {
game.Disconnect(); cancelled = true;
}
return PyBool_FromLong(cancelled);
}
#endif
PyObject* netDisconnect(PyObject* poSelf, PyObject* poArgs)
{
CPythonNetworkStream& rkNetStream=CPythonNetworkStream::Instance();
@@ -1774,6 +1794,10 @@ void initnet()
{ "SendChangeNamePacket", netSendChangeNamePacket, METH_VARARGS },
{ "SendCreateCharacterPacket", netSendCreateCharacterPacket, METH_VARARGS },
{ "RegisterAccount", netRegisterAccount, METH_VARARGS },
{ "CancelRegisterAccount", netCancelRegisterAccount, METH_NOARGS },
#ifdef MT_HAS_MESHPORT
{ "CancelPendingLogin", netCancelPendingLogin, METH_NOARGS },
#endif
{ "GetRegisterAccountResult", netGetRegisterAccountResult, METH_VARARGS },
{ "SendDestroyCharacterPacket", netSendDestroyCharacterPacket, METH_VARARGS },
{ "SendEnterGamePacket", netSendEnterGamePacket, METH_VARARGS },
+7 -1
View File
@@ -113,6 +113,10 @@ class CPythonSystem : public CSingleton<CPythonSystem>
// PORT: AVA2 effect_level (0 all, 1 hide players/NPCs, 2 hide monsters/NPCs, 3 hide others, 4 hide all).
int GetEffectLevel() { return m_iPortEffectLevel; }
void SetEffectLevel(int iLevel) { m_iPortEffectLevel = iLevel < 0 || iLevel > 4 ? 0 : iLevel; }
int GetShopNamesRange() { return m_iPortShopRange; }
void SetShopNamesRange(int index) { m_iPortShopRange = index < 0 || index > 4 ? 0 : index; }
bool GetShopNameStatus() { return m_bPortNPCNames; }
void SetShopNameStatus(bool shown) { m_bPortNPCNames = shown; }
bool IsUseDefaultIME();
bool IsNoSoundCard();
bool IsAutoTiling();
@@ -163,4 +167,6 @@ class CPythonSystem : public CSingleton<CPythonSystem>
PyObject * m_poInterfaceHandler;
TWindowStatus m_WindowStatus[WINDOW_MAX_NUM];
int m_iPortEffectLevel = 0;
};
int m_iPortShopRange = 0;
bool m_bPortNPCNames = true;
};
@@ -227,6 +227,29 @@ PyObject * systemGetEffectLevel(PyObject * poSelf, PyObject * poArgs)
return Py_BuildValue("i", CPythonSystem::Instance().GetEffectLevel());
}
PyObject* systemSetShopNamesRange(PyObject*, PyObject* args)
{
int index;
if (!PyTuple_GetInteger(args, 0, &index)) return Py_BadArgument();
CPythonSystem::Instance().SetShopNamesRange(index);
return Py_BuildNone();
}
PyObject* systemGetShopNamesRange(PyObject*, PyObject*)
{
return Py_BuildValue("i", CPythonSystem::Instance().GetShopNamesRange());
}
PyObject* systemSetShopNameStatus(PyObject*, PyObject* args)
{
int shown;
if (!PyTuple_GetInteger(args, 0, &shown)) return Py_BadArgument();
CPythonSystem::Instance().SetShopNameStatus(shown != 0);
return Py_BuildNone();
}
PyObject* systemGetShopNameStatus(PyObject*, PyObject*)
{
return Py_BuildValue("i", CPythonSystem::Instance().GetShopNameStatus());
}
PyObject * systemIsAlwaysShowName(PyObject * poSelf, PyObject * poArgs)
{
return Py_BuildValue("i", CPythonSystem::Instance().IsAlwaysShowName());
@@ -440,6 +463,10 @@ void initsystem()
{ "IsShowSalesText", systemIsShowSalesText, METH_VARARGS },
{ "SetEffectLevel", systemSetEffectLevel, METH_VARARGS }, // PORT: AVA2
{ "GetEffectLevel", systemGetEffectLevel, METH_VARARGS },
{ "SetShopNamesRange", systemSetShopNamesRange, METH_VARARGS },
{ "GetShopNamesRange", systemGetShopNamesRange, METH_VARARGS },
{ "SetShopNameStatus", systemSetShopNameStatus, METH_VARARGS },
{ "GetShopNameStatus", systemGetShopNameStatus, METH_VARARGS },
{ "GetShadowLevel", systemGetShadowLevel, METH_VARARGS },
{ "SetShadowLevel", systemSetShadowLevel, METH_VARARGS },
@@ -6,6 +6,7 @@
#include "resource.h"
#include "PythonTextTail.h"
#include "PythonCharacterManager.h"
#include "PythonSystem.h"
#include "PythonGuild.h"
#include "Locale.h"
#include "MarkManager.h"
@@ -463,6 +464,11 @@ void CPythonTextTail::ShowCharacterTextTail(DWORD VirtualID)
if (pInstance->IsGuildWall())
return;
if (!pInstance->PORT_IsDisplayVisible())
return;
if (pInstance->IsNPC() && (pInstance->GetRace() < 30000 || pInstance->GetRace() > 30020) &&
!CPythonSystem::Instance().GetShopNameStatus())
return;
if (pInstance->CanPickInstance())
m_CharacterTextTailList.push_back(pTextTail);