From c8cb3e818b57f8e61a74816e1795bcee110d7c79 Mon Sep 17 00:00:00 2001 From: Berkay Date: Tue, 23 Sep 2025 00:11:19 +0300 Subject: [PATCH 1/2] chore: unused fm removed --- src/game/FileMonitor_FreeBSD.cpp | 138 ------------------------------- src/game/FileMonitor_FreeBSD.h | 44 ---------- src/game/IFileMonitor.h | 30 ------- src/game/desc_manager.h | 1 - src/game/main.cpp | 19 ----- 5 files changed, 232 deletions(-) delete mode 100644 src/game/FileMonitor_FreeBSD.cpp delete mode 100644 src/game/FileMonitor_FreeBSD.h delete mode 100644 src/game/IFileMonitor.h diff --git a/src/game/FileMonitor_FreeBSD.cpp b/src/game/FileMonitor_FreeBSD.cpp deleted file mode 100644 index 35709da..0000000 --- a/src/game/FileMonitor_FreeBSD.cpp +++ /dev/null @@ -1,138 +0,0 @@ -#include "stdafx.h" -#ifdef OS_FREEBSD -#include "FileMonitor_FreeBSD.h" -#include "libthecore/log.h" - - -#define INVALID_KERNEL_EVENT -1 - -FileMonitorFreeBSD::FileMonitorFreeBSD() -{ - m_KernelEventQueue = INVALID_KERNEL_EVENT; -} - -FileMonitorFreeBSD::~FileMonitorFreeBSD() -{ - if( m_KernelEventQueue != INVALID_KERNEL_EVENT ) - { - close ( m_KernelEventQueue ); - m_KernelEventQueue = INVALID_KERNEL_EVENT; - } - - TMonitorFileHashMap::iterator it; - for( it = m_FileLists.begin(); it != m_FileLists.end(); ++it ) - { - close(it->second.fhMonitor); - } - - m_FileLists.clear(); - - m_MonitoredEventLists.clear(); - m_TriggeredEventLists.clear(); -} - - -void FileMonitorFreeBSD::Update(DWORD dwPulses) -{ - if( m_KernelEventQueue == INVALID_KERNEL_EVENT || m_FileLists.size() == 0 ) - return; - - int nEvent = kevent(m_KernelEventQueue, &m_TriggeredEventLists[0], (int)m_TriggeredEventLists.size(), &m_MonitoredEventLists[0], (int)m_MonitoredEventLists.size(), NULL ); - if( nEvent == INVALID_KERNEL_EVENT ) - { - return; - } - else if( nEvent > 0 ) - { - for( int i = 0; i < nEvent; ++i ) - { - int nEventFlags = m_MonitoredEventLists[i].flags; - eFileUpdatedOptions eUpdateOption = e_FileUpdate_None; - - if (nEventFlags & EV_ERROR) - eUpdateOption = e_FileUpdate_Error; - - else if (nEventFlags & NOTE_DELETE) - eUpdateOption = e_FileUpdate_Deleted; - - else if (nEventFlags & NOTE_EXTEND || nEventFlags & NOTE_WRITE) - eUpdateOption = e_FileUpdate_Modified; - - else if (nEventFlags & NOTE_ATTRIB) - eUpdateOption = e_FileUpdate_AttrModified; - - else if (nEventFlags & NOTE_LINK) - eUpdateOption = e_FileUpdate_Linked; - - else if (nEventFlags & NOTE_RENAME) - eUpdateOption = e_FileUpdate_Renamed; - - else if (nEventFlags & NOTE_REVOKE) - eUpdateOption = e_FileUpdate_Revoked; - - if( eUpdateOption != e_FileUpdate_None ) - { - TMonitorFileHashMap::iterator it; - for( it = m_FileLists.begin(); it != m_FileLists.end(); ++it ) - { - FileIOContext_FreeBSD& context = it->second; - if( context.idxToEventList == i ) - { - std::string strModifedFileName = it->first; - context.pListenFunc( strModifedFileName, eUpdateOption ); - break; - } - } - } - } - } -} - -void FileMonitorFreeBSD::AddWatch(const std::string& strFileName, PFN_FileChangeListener pListenerFunc) -{ - int iFileHandle = -1; - if( (iFileHandle = open(strFileName.c_str(), O_RDONLY)) == -1) - { - sys_err("FileMonitorFreeBSD:AddWatch : can`t open file(%s).\n", strFileName.c_str()); - return; - } - - //create kqueue if not exists - if( m_KernelEventQueue == INVALID_KERNEL_EVENT ) - m_KernelEventQueue = kqueue(); - - if( m_KernelEventQueue == INVALID_KERNEL_EVENT ) - { - sys_err("FileMonitorFreeBSD:AddWatch : failed to create kqueue.\n"); - return; - } - - TMonitorFileHashMap::iterator it = m_FileLists.find( strFileName ); - if( it != m_FileLists.end() ) - { - sys_log(0, "FileMonitorFreeBSD:AddWatch : trying to add duplicated watch on file(%s).\n", strFileName.c_str() ); - return; - } - - //set file context - FileIOContext_FreeBSD context; - { - context.fhMonitor = iFileHandle; - context.idxToEventList = (int)m_MonitoredEventLists.size(); - context.pListenFunc = pListenerFunc; - } - - m_FileLists[strFileName] = context; - - //set events - struct kevent kTriggerEvent, kMonitorEvent; - - EV_SET(&kTriggerEvent, iFileHandle, EVFILT_VNODE, - EV_ADD | EV_ENABLE | EV_ONESHOT, - NOTE_DELETE | NOTE_WRITE | NOTE_EXTEND | NOTE_ATTRIB | NOTE_LINK | NOTE_RENAME | NOTE_REVOKE, - 0, 0); - - m_TriggeredEventLists.push_back( kTriggerEvent ); - m_MonitoredEventLists.push_back( kMonitorEvent ); -} -#endif \ No newline at end of file diff --git a/src/game/FileMonitor_FreeBSD.h b/src/game/FileMonitor_FreeBSD.h deleted file mode 100644 index b605743..0000000 --- a/src/game/FileMonitor_FreeBSD.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once -#ifdef OS_FREEBSD -#include "IFileMonitor.h" -#include -#include -#include -#include -#include - -struct FileIOContext_FreeBSD -{ - int fhMonitor; - int idxToEventList; // evtTrigger & evtMonitor index should be same - PFN_FileChangeListener pListenFunc; -}; - -class FileMonitorFreeBSD : public IFileMonitor -{ -private: - FileMonitorFreeBSD(); //hidden - -public: - virtual ~FileMonitorFreeBSD(); - - void AddWatch (const std::string& strFileName, PFN_FileChangeListener pListenerFunc); - void Update (DWORD dwPulses); - - static FileMonitorFreeBSD& Instance() - { - static FileMonitorFreeBSD theMonitor; - return theMonitor; - } - -private: - typedef std::unordered_map TMonitorFileHashMap; - typedef std::vector TEventList; - - TMonitorFileHashMap m_FileLists; - TEventList m_MonitoredEventLists; - TEventList m_TriggeredEventLists; - - int m_KernelEventQueue; -}; -#endif \ No newline at end of file diff --git a/src/game/IFileMonitor.h b/src/game/IFileMonitor.h deleted file mode 100644 index ec7e643..0000000 --- a/src/game/IFileMonitor.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef IFILEMONITOR_INCLUDED -#define IFILEMONITOR_INCLUDED - -//#include -#include - -enum eFileUpdatedOptions -{ - e_FileUpdate_None = -1, - e_FileUpdate_Error, - e_FileUpdate_Deleted, - e_FileUpdate_Modified, - e_FileUpdate_AttrModified, - e_FileUpdate_Linked, - e_FileUpdate_Renamed, - e_FileUpdate_Revoked, -}; - -// TODO : in FreeBSD boost function doesn`t work with boost bind -// so currently we only support for static function ptr only -//typedef boost::function< void ( const std::string&, eFileUpdatedOptions ) > PFN_FileChangeListener; -typedef void (* PFN_FileChangeListener )(const std::string&, eFileUpdatedOptions); - -struct IFileMonitor -{ - virtual void Update (DWORD dwPulses) = 0; - virtual void AddWatch (const std::string& strFileName, PFN_FileChangeListener pListenerFunc) = 0; -}; - -#endif // IFILEMONITOR_INCLUDED diff --git a/src/game/desc_manager.h b/src/game/desc_manager.h index b8b306b..5d0fe42 100644 --- a/src/game/desc_manager.h +++ b/src/game/desc_manager.h @@ -5,7 +5,6 @@ #include "common/stl.h" #include "common/length.h" -#include "IFileMonitor.h" class CLoginKey; class CClientPackageCryptInfo; diff --git a/src/game/main.cpp b/src/game/main.cpp index fdf4b94..5004c0f 100644 --- a/src/game/main.cpp +++ b/src/game/main.cpp @@ -63,12 +63,6 @@ #include "limit_time.h" #endif -//#define __FILEMONITOR__ - -#if defined (OS_FREEBSD) && defined(__FILEMONITOR__) - #include "FileMonitor_FreeBSD.h" -#endif - // #ifndef OS_WINDOWS // #include // #endif @@ -298,14 +292,6 @@ void heartbeat(LPHEART ht, int pulse) if (!(pulse % (passes_per_sec + 4))) CHARACTER_MANAGER::instance().ProcessDelayedSave(); - //4초 마다 -#if defined (OS_FREEBSD) && defined(__FILEMONITOR__) - if (!(pulse % (passes_per_sec * 5))) - { - FileMonitorFreeBSD::Instance().Update(pulse); - } -#endif - // 약 5.08초마다 if (!(pulse % (passes_per_sec * 5 + 2))) { @@ -537,11 +523,6 @@ int main(int argc, char **argv) sys_err("Failed to Load ClientPackageCryptInfo File(%s)", strPackageCryptInfoDir.c_str()); } -#if defined (OS_FREEBSD) && defined(__FILEMONITOR__) - PFN_FileChangeListener pPackageNotifyFunc = &(DESC_MANAGER::NotifyClientPackageFileChanged); - //FileMonitorFreeBSD::Instance().AddWatch( strPackageCryptInfoName, pPackageNotifyFunc ); -#endif - while (idle()); sys_log(0, " Starting..."); From ede7533074c3199a859d4a0e065315411d3ce505 Mon Sep 17 00:00:00 2001 From: Berkay Date: Tue, 23 Sep 2025 00:14:45 +0300 Subject: [PATCH 2/2] chore: limit time & valid server check removed --- src/db/ClientManagerLogin.cpp | 18 ------ src/game/char_manager.cpp | 9 --- src/game/desc.cpp | 10 --- src/game/input.cpp | 23 ------- src/game/input_auth.cpp | 15 ----- src/game/limit_time.h | 8 --- src/game/main.cpp | 117 ---------------------------------- 7 files changed, 200 deletions(-) delete mode 100644 src/game/limit_time.h diff --git a/src/db/ClientManagerLogin.cpp b/src/db/ClientManagerLogin.cpp index d0f1186..f352ba8 100644 --- a/src/db/ClientManagerLogin.cpp +++ b/src/db/ClientManagerLogin.cpp @@ -80,24 +80,6 @@ bool CClientManager::FindLogonAccount(const char * c_pszLogin) void CClientManager::QUERY_LOGIN_BY_KEY(CPeer * pkPeer, DWORD dwHandle, TPacketGDLoginByKey * p) { -#ifdef ENABLE_LIMIT_TIME - static int s_updateCount = 0; - static int s_curTime = time(0); - if (s_updateCount > 100) - { - s_curTime = time(0); - s_updateCount = 0; - } - ++s_updateCount; - - if (s_curTime >= GLOBAL_LIMIT_TIME) - { - sys_err("Server life time expired."); - exit(0); - return; - } -#endif - CLoginData * pkLoginData = GetLoginData(p->dwLoginKey); char szLogin[LOGIN_MAX_LEN + 1]; trim_and_lower(p->szLogin, szLogin, sizeof(szLogin)); diff --git a/src/game/char_manager.cpp b/src/game/char_manager.cpp index aaf6e54..10f2401 100644 --- a/src/game/char_manager.cpp +++ b/src/game/char_manager.cpp @@ -692,15 +692,6 @@ void CHARACTER_MANAGER::Update(int iPulse) for (itertype(m_map_dwMobKillCount) it = m_map_dwMobKillCount.begin(); it != m_map_dwMobKillCount.end(); ++it) DBManager::instance().SendMoneyLog(MONEY_LOG_MONSTER_KILL, it->first, it->second); -#ifdef _USE_SERVER_KEY_ - extern bool Metin2Server_IsInvalid(); - extern bool g_bShutdown; - if (Metin2Server_IsInvalid()) - { - g_bShutdown = true; - } -#endif - m_map_dwMobKillCount.clear(); } diff --git a/src/game/desc.cpp b/src/game/desc.cpp index ac3b5b9..391f6ea 100644 --- a/src/game/desc.cpp +++ b/src/game/desc.cpp @@ -192,16 +192,6 @@ EVENTFUNC(ping_event) desc->SetPong(false); } -#ifdef ENABLE_LIMIT_TIME - if ((unsigned)get_global_time() >= GLOBAL_LIMIT_TIME) - { - extern void ClearAdminPages(); - ClearAdminPages(); - extern g_bShutdown; - g_bShutdown = true; - } -#endif - desc->SendHandshake(get_dword_time(), 0); return (ping_event_second_cycle); diff --git a/src/game/input.cpp b/src/game/input.cpp index 9773e30..1b5908a 100644 --- a/src/game/input.cpp +++ b/src/game/input.cpp @@ -18,10 +18,6 @@ #include "castle.h" #include "dev_log.h" -#ifndef OS_WINDOWS - #include "limit_time.h" -#endif - extern time_t get_global_time(); bool IsEmptyAdminPage() @@ -39,14 +35,6 @@ bool IsAdminPage(const char * ip) return 0; } -void ClearAdminPages() -{ - for (size_t n = 0; n < g_stAdminPageIP.size(); ++n) - g_stAdminPageIP[n].clear(); - - g_stAdminPageIP.clear(); -} - CInputProcessor::CInputProcessor() : m_pPacketInfo(NULL), m_iBufferLeft(0) { if (!m_pPacketInfo) @@ -174,17 +162,6 @@ bool CInputProcessor::Process(LPDESC lpDesc, const void * c_pvOrig, int iBytes, void CInputProcessor::Pong(LPDESC d) { d->SetPong(true); - - extern bool Metin2Server_IsInvalid(); - -#ifdef ENABLE_LIMIT_TIME - if (Metin2Server_IsInvalid()) - { - extern bool g_bShutdown; - g_bShutdown = true; - ClearAdminPages(); - } -#endif } void CInputProcessor::Handshake(LPDESC d, const char * c_pData) diff --git a/src/game/input_auth.cpp b/src/game/input_auth.cpp index d3e2c71..3b628b9 100644 --- a/src/game/input_auth.cpp +++ b/src/game/input_auth.cpp @@ -10,10 +10,6 @@ #include "auth_brazil.h" #include "db.h" -#ifndef OS_WINDOWS - #include "limit_time.h" -#endif - extern time_t get_global_time(); bool FN_IS_VALID_LOGIN_STRING(const char *str) @@ -107,17 +103,6 @@ CInputAuth::CInputAuth() void CInputAuth::Login(LPDESC d, const char * c_pData) { - extern bool Metin2Server_IsInvalid(); - -#ifdef ENABLE_LIMIT_TIME - if (Metin2Server_IsInvalid()) - { - extern void ClearAdminPages(); - ClearAdminPages(); - exit(1); - return; - } -#endif TPacketCGLogin3 * pinfo = (TPacketCGLogin3 *) c_pData; if (!g_bAuthServer) diff --git a/src/game/limit_time.h b/src/game/limit_time.h deleted file mode 100644 index 68f684e..0000000 --- a/src/game/limit_time.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __LIMIT_TIME__ -#define __LIMIT_TIME__ - -// #define ENABLE_LIMIT_TIME -#define GLOBAL_LIMIT_TIME 1684265966UL // Tue May 16 21:39:26 2023 -#define TIME_OVER_PONG_DOWN_RATE 50000 -#define TIME_OVER_LOGIN_DOWN_RATE 10000 -#endif diff --git a/src/game/main.cpp b/src/game/main.cpp index 5004c0f..6ab5a09 100644 --- a/src/game/main.cpp +++ b/src/game/main.cpp @@ -59,9 +59,6 @@ #include "skill_power.h" #include "SpeedServer.h" #include "DragonSoul.h" -#ifndef OS_WINDOWS - #include "limit_time.h" -#endif // #ifndef OS_WINDOWS // #include @@ -71,11 +68,6 @@ #include #endif -// 윈도우에서 테스트할 때는 항상 서버키 체크 -#ifdef _WIN32 - //#define _USE_SERVER_KEY_ -#endif - extern void WriteVersion(); //extern const char * _malloc_options; #if defined(OS_FREEBSD) && defined(DEBUG_ALLOC) @@ -231,13 +223,6 @@ void heartbeat(LPHEART ht, int pulse) // 1초마다 if (!(pulse % ht->passes_per_sec)) { -#ifdef ENABLE_LIMIT_TIME - if ((unsigned)get_global_time() >= GLOBAL_LIMIT_TIME) - { - g_bShutdown = true; - } -#endif - if (g_bAuthServer && LC_IsBrazil() && !test_server) auth_brazil_log(); @@ -325,87 +310,6 @@ void heartbeat(LPHEART ht, int pulse) } } -static bool g_isInvalidServer = false; - -bool Metin2Server_IsInvalid() -{ - return g_isInvalidServer; -} - -void Metin2Server_Check() -{ -#ifdef _SERVER_CHECK_ - -#ifdef _USE_SERVER_KEY_ - if (false == CheckServer::CheckIp(g_szPublicIP)) - { -#ifdef _WIN32 - fprintf(stderr, "check ip failed\n"); -#endif - g_isInvalidServer = true; - } - return; -#endif - - if (LC_IsEurope() || test_server) - return; - - - // 브라질 ip - if (strncmp (g_szPublicIP, "189.112.1", 9) == 0) - { - return; - } - - // 캐나다 ip - if (strncmp (g_szPublicIP, "74.200.6", 8) == 0) - { - return; - } - - return; - - static const size_t CheckServerListSize = 1; - static const char* CheckServerList[] = { "202.31.178.251"}; - static const int CheckServerPort = 7120; - - socket_t sockConnector = INVALID_SOCKET; - - for (size_t i = 0 ; i < CheckServerListSize ; i++) - { - sockConnector = socket_connect( CheckServerList[i], CheckServerPort ); - - if (0 < sockConnector) - break; - } - - if (0 > sockConnector) - { - if (true != LC_IsEurope()) // 유럽은 접속을 하지 못하면 인증된 것으로 간주 - g_isInvalidServer = true; - - return; - } - - char buf[256] = { 0, }; - - socket_read(sockConnector, buf, sizeof(buf) - 1); - - sys_log(0, "recv[%s]", buf); - - if (strncmp(buf, "OK", 2) == 0) - g_isInvalidServer = false; - else if (strncmp(buf, "CK", 2) == 0) - g_isInvalidServer = true; - - socket_close(sockConnector); -#else - g_isInvalidServer = false; - return; -#endif - -} - static void CleanUpForEarlyExit() { CancelReloadSpamEvent(); } @@ -504,15 +408,6 @@ int main(int argc, char **argv) ani_init(); PanamaLoad(); - Metin2Server_Check(); - -#if defined(_WIN32) && defined(_USE_SERVER_KEY_) - if (CheckServer::IsFail()) - { - return 1; - } -#endif - if ( g_bTrafficProfileOn ) TrafficProfiler::instance().Initialize( TRAFFIC_PROFILE_FLUSH_CYCLE, "ProfileLog" ); @@ -615,12 +510,6 @@ int start(int argc, char **argv) #if defined(OS_FREEBSD) && defined(DEBUG_ALLOC) _malloc_message = WriteMallocMessage; #endif -#ifdef ENABLE_LIMIT_TIME - if ((unsigned)get_global_time() >= GLOBAL_LIMIT_TIME) - { - return 0; - } -#endif char optstring[] = "npverltI"; while ((ch = getopt(argc, argv, optstring)) != -1) @@ -855,12 +744,6 @@ int idle() memset(&thecore_profiler[0], 0, sizeof(thecore_profiler)); memset(&s_dwProfiler[0], 0, sizeof(s_dwProfiler)); } -#ifdef _USE_SERVER_KEY_ - if (Metin2Server_IsInvalid() && 0 == (thecore_random() % 7146)) - { - return 0; // shutdown - } -#endif #ifdef OS_WINDOWS if (_kbhit()) {