Files
Sun1602/Tools/SUNAutoScriptMaker/ScriptManager.cpp
T
2022-10-26 12:25:11 +08:00

200 lines
4.9 KiB
C++

#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;
}