#include "StdAfx.h" #include ".\scriptmanager.h" #include "Script.h" #include "SunServerScript.h" #include "WorldServerScript.h" #include "GuildServerScript.h" #include "MasterServerScript.h" #include "DBProxyScript.h" #include "shlwapi.h" #include "WorldInfoManager.h" #include "WorldInfo.h" ScriptManager::ScriptManager(void) { } ScriptManager::~ScriptManager(void) { SCRIPT_ITER iter; for( iter = m_mapScript.begin(); iter != m_mapScript.end(); ++iter ) { Script* pScript = iter->second; if( pScript ) delete pScript; } m_mapScript.clear(); } void ScriptManager::Init() { Script* pScript = NULL; pScript = new SunServerScript; AddScript( AGENT_SERVER, pScript ); pScript = new SunServerScript; AddScript( BATTLE_SERVER, pScript ); pScript = new SunServerScript; AddScript( FIELD_SERVER, pScript ); pScript = new SunServerScript; AddScript( GAME_DBPROXY, pScript ); pScript = new WorldServerScript; AddScript( WORLD_SERVER, pScript ); pScript = new GuildServerScript; AddScript( GUILD_SERVER, pScript ); pScript = new MasterServerScript; AddScript( MASTER_SERVER, pScript ); // pScript = new DBProxyScript; // AddScript( GAME_DBPROXY_EX, pScript ); } void ScriptManager::AddScript( BYTE byServerType, Script* pScript ) { m_mapScript.insert( make_pair( byServerType, pScript) ); pScript->SetServerType( byServerType ); } Script* ScriptManager::GetScript( BYTE byServerType ) { SCRIPT_ITER pos; pos = m_mapScript.find( byServerType ); if( pos == m_mapScript.end() ) return NULL; return pos->second; } void ScriptManager::MakeScript( ) { //¿©±â¼­ ¼­¹öŸÀÔº° Àüü ¿ùµåÀÇ ½ºÅ©¸³Æ®¸¦ »ý»êÇÑ´Ù. WorldInfo* pWorldInfo = WorldInfoManager::GetInstance()->GetWorldInfo(); if( !pWorldInfo ) return; for( int i = 0; i < MAX_WORLD_COUNT; i++ ) { WORLD_LIST listWorld; pWorldInfo->GetBaseInfo( i, listWorld ); if( listWorld.size() == 0) continue; WORLD_LIST::iterator iter; for( iter = listWorld.begin(); iter != listWorld.end(); iter++ ) { _BaseInfo* pBaseInfo = *iter; if( !pBaseInfo ) continue; CString strPath; GetServerScriptDirectory( (BYTE)i, (BYTE)pBaseInfo->m_wChannel, (BYTE)pBaseInfo->m_wServerType, (BYTE)pBaseInfo->m_wServerNum, strPath ); MakeDirectory( strPath.GetString() ); CString strPathEx = strPath; if( !GetServerScriptFilePath( (BYTE)pBaseInfo->m_wServerType, strPath ) ) continue; Script* pScript = GetScript( (BYTE)pBaseInfo->m_wServerType ); if( !pScript ) return; pScript->Create( strPath, pBaseInfo, listWorld ); //if( pBaseInfo->m_wServerType == GAME_DBPROXY ) //GAME DBPROXY¸é DBPROXY ½ºÅ©¸³Æ®¸¦ Çϳª´õ ¸¸µç´Ù. //{ // if( !GetServerScriptFilePath( GAME_DBPROXY_EX, strPathEx ) ) // continue; // Script* pScript = GetScript( GAME_DBPROXY_EX ); // if( !pScript ) return; // pScript->Create( strPathEx, pBaseInfo, listWorld ); //} } } } BOOL ScriptManager::GetServerScriptFilePath( BYTE byServerType, CString& strPath ) { //1. SunServer if( byServerType == AGENT_SERVER || byServerType == BATTLE_SERVER || byServerType == FIELD_SERVER || byServerType == GAME_DBPROXY ) strPath += "\\SunServer.ini"; else if( byServerType == WORLD_SERVER ) strPath += "\\WorldServer.ini"; else if( byServerType == GUILD_SERVER ) strPath += "\\GuildServer.ini"; else if( byServerType == MASTER_SERVER ) strPath += "\\MasterServer.ini"; //else if( byServerType == GAME_DBPROXY_EX ) // strPath += "\\DBPServer.ini"; else return FALSE; return TRUE; } void ScriptManager::GetServerScriptDirectory( BYTE byWorld, BYTE byChannel, BYTE byServerType, BYTE byServerNum, CString& strPath ) { TCHAR szPath[MAX_PATH]; GetCurrentDirectory( MAX_PATH, szPath ); //Á¤Ã¥ //1. ÇØ´ç¿ùµå / ÇØ´çä³Î / ÇØ´ç¼­¹ö / ½ºÅ©¸³Æ® ÆÄÀÏ.. CString strTemp; strPath = szPath; strTemp.Format( "\\%dW\\%dC", byWorld, byChannel); strPath += strTemp; //1. SunServer if( byServerType == AGENT_SERVER ) strPath += "\\AgentServer"; else if( byServerType == BATTLE_SERVER ) strPath += "\\BattleServer"; else if( byServerType == FIELD_SERVER ) strPath += "\\FieldServer"; // else if( byServerType == GAME_DBPROXY || byServerType == GAME_DBPROXY_EX ) // strPath += "\\DBProxyServer"; else if( byServerType == WORLD_SERVER ) strPath += "\\WorldServer"; else if( byServerType == GUILD_SERVER ) strPath += "\\GuildServer"; else if( byServerType == MASTER_SERVER ) strPath += "\\MasterServer"; CString strNum; strNum.Format("%d", byServerNum ); strPath += strNum; } void ScriptManager::MakeDirectory( const char* pszDir ) { if( pszDir == NULL || strcmp( pszDir, "" ) == 0 ) return; int nLen = (int)strlen( pszDir ) + 1; char* szBuf = new char[nLen]; strncpy( szBuf, pszDir, nLen ); for( int i = 0; i < nLen; i++ ) { if( szBuf[i] && szBuf[i] != '\\' ) continue; szBuf[i] = '\0'; if( PathIsDirectory(szBuf) == FALSE ) CreateDirectory( szBuf, NULL ); szBuf[i] = '\\'; } delete[] szBuf; }