// GameServer.cpp : ÄÜ¼Ö ÀÀ¿ë ÇÁ·Î±×·¥¿¡ ´ëÇÑ ÁøÀÔÁ¡À» Á¤ÀÇÇÕ´Ï´Ù. // #include "stdafx.h" #include #include #include #include "FieldServer.h" #include "BattleServer.h" #include "GameServerEx.h" #include "main.h" #include "ServerGlobal.h" #include "Psapi.h" //================================================================================================== // @desc ¸Þ¸ð¸® ´©¼ö ¸®Æ÷ÅÍ »ç¿ë ¿©ºÎ #define MEMORY_LEAK_REPORT_FILE "memory_leak_Game.txt" // @desc °øÀ¯µÈ ¸Þ¸ð¸® ´©¼ö Ãâ·Â ÆÄÀϸí #define MEMORY_LEAK_REPORT_FILE_FOR_SHARED "./memory_leak_Game_shared.txt" #include "./SharedMemoryLeakReporter.hxx" //================================================================================================== // Global SolarSimpleConsole g_Console; extern "C" { int WinMainCRTStartup(); } INT SunEntryPoint() { SharedMemoryPool::CreateInstance(); #ifdef __WAVERIX_TEST_LOGIC_TASK_MACRO__ WaverixTestEntry(); #endif return WinMainCRTStartup(); } #ifdef _NA_007743_20141027_USE_MINIDUMP_WITH_FULLMEMORY static SolarDump solarDUMP(".", MiniDumpWithFullMemory); #else // _NA_007743_20141027_USE_MINIDUMP_WITH_FULLMEMORY static SolarDump solarDUMP("."); #endif // _NA_007743_20141027_USE_MINIDUMP_WITH_FULLMEMORY static VOID Init_Circumstance(); int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow ) { __UNUSED((hInstance,hPrevInstance,nCmdShow)); StartMemoryLeakCheck(); //BreakPointOnMemoryLeak(259894); Init_Circumstance(); // ¸í·É Àμö ÆÄ½Ì if( ParsingGameServerType( (LPTSTR)lpCmdLine ) ) { if( g_pGameServer->DoInit( "./GameServer.ini", GameServerEx::DoAllocServerSession, GameServerEx::DoFreeServerSession, GameServerEx::DoFreeConnectSession, GameServerEx::DoAllocClient_NotUsed, GameServerEx::DoFreeClient_NotUsed, GameServerEx::DoFreeConnect_NotUsed ) ) { g_pGameServer->DoProcess(); g_pGameServer->DoRelease(); g_pGameServer->Finalize(); } else { DISPMSG( "Frame Init() is Failed!\n" ); system( "pause" ); } } else { DISPMSG( "Invalid command line.\n" ); system( "pause" ); } // ÄܼÖâ Á¾·á g_Console.Release(); delete g_pGameServer; g_pGameServer = NULL; return 0; } BOOL ParseArgumentsForGameServer( char *lpCmdLine ) { char szServerType[255], szPath[255]; GetCommandLineArg( 0, lpCmdLine, szServerType, 255 ); GetCommandLineArg( 1, lpCmdLine, szPath, 255 ); // ¼­¹öŸÀÔ ¼³Á¤ if( _stricmp( szServerType, "field" ) == 0 || _stricmp( szServerType, "" ) == 0 ) { g_pGameServer = new FieldServer; } else if( _stricmp( szServerType, "battle" ) == 0 ) { g_pGameServer = new BattleServer; } // ÀÛ¾÷µð·ºÅ丮 ¼³Á¤ if( _stricmp( szPath, "" ) == 0 ) SetApplicationDirectory(); else SetCurrentDirectory( szPath ); return TRUE; } BOOL ParsingGameServerType( LPSTR lpCmdLine ) { #if defined(_DEBUG) char szArg[255]; GetCommandLineArg( 0, lpCmdLine, szArg, 255 ); if( _stricmp( szArg, "" ) != 0 ) { if( _stricmp( szArg, "field" ) == 0 ) { g_pGameServer = new FieldServer; SetApplicationDirectory(); return TRUE; } else if( _stricmp( szArg, "battle" ) == 0 ) { g_pGameServer = new BattleServer; SetApplicationDirectory(); return TRUE; } else //S_Drive SetCurrentDirectory( szArg ); } #endif HANDLE hCurPro = GetCurrentProcess(); if( hCurPro ) { TCHAR szFilePath[MAX_PATH], szProcessName[MAX_PATH], szProcessDir[MAX_PATH], szProcessFile[MAX_PATH]; GetProcessImageFileName( hCurPro, szFilePath, MAX_PATH ); _splitpath( szFilePath, NULL, szProcessDir, szProcessName, szProcessFile ); // CHANGES: f110310.3L, changes partial searching szProcessName[_countof(szProcessName) - 1] = _T('\0'); // CHANGES: f110526.2L, fixed to lowercase comparison // because the executing image name is undefined. _strlwr(szProcessName); BOOST_STATIC_ASSERT(sizeof(szProcessName[0]) == sizeof(char)); if (strstr(szProcessName, "field")) { g_pGameServer = new FieldServer; } else if (strstr(szProcessName, "battle")) { g_pGameServer = new BattleServer; } else { return false; } #if SUN_CODE_BACKUP if( _stricmp( szProcessName, "FieldServer_d" ) == 0 || _stricmp( szProcessName, "FieldServer" ) == 0 ) g_pGameServer = new FieldServer; else if( _stricmp( szProcessName, "BattleServer_d" ) == 0 || _stricmp( szProcessName, "BattleServer" ) == 0 ) g_pGameServer = new BattleServer; else return FALSE; #endif char szArg[255]; GetCommandLineArg( 0, lpCmdLine, szArg, 255 ); // µð¹ö±×µµ ¾Æ´Ñµ¥, ÀÎÀÚ°¡ ÀÖ´Ù¸é... S_Drive °æ·Î´Ù. if( _stricmp( szArg, "" ) != 0 ) SetCurrentDirectory( szArg); else SetApplicationDirectory(); return TRUE; } return FALSE; } static VOID ErrorHandler_new() { printf( "ÎÞ·¨·ÖÅäÄÚ´æ\n" ); if( g_pSunLog ) { MessageOut( eCRITICAL_LOG, _T("ÎÞ·¨·ÖÅäÄÚ´æ\n") ); g_pSunLog->Flush( CSunLog::cOUTPUT_BOTH ); } // ÄݽºÅà ´ýÇÁ¸¦ ¾ò±â À§Çؼ­ ¼öÁ¤ int* break_point = NULL; *break_point = 200; //__debugbreak(); } //#ifdef __NA000000_080317_ABNORMAL_EXIT_REDIRECT__ #include VOID signal_redirect( INT signo ) { __TOUCHED(signo); __debugbreak(); } //#endif static VOID Init_Circumstance() { std::set_new_handler( ErrorHandler_new ); #ifdef __NA000000_080317_ABNORMAL_EXIT_REDIRECT__ signal( SIGABRT, signal_redirect ); _set_error_mode( _OUT_TO_STDERR ); #endif // ÄܼÖâ ÃʱâÈ­ CONSOLE_DESC cdesc; ZeroMemory( &cdesc, sizeof(cdesc) ); cdesc.bUsingConsoleInput = FALSE; cdesc.bUsingRedirect = TRUE; g_Console.Init( &cdesc ); }