📄 servertable.cpp
字号:
// PTCL_NOTIFY_SERVER_UP 菩哦阑 父电促.
szSendMsg[0] = (BYTE)PTCL_NOTIFY_SERVER_UP;
memcpy( szSendMsg+1, &this->GetOwnServerData()->wPort, 2 );
// PTCL_NOTIFY_SERVER_UP 菩哦阑 傈价茄促.
if( !this->Send( pServerData->dwConnectionIndex, szSendMsg, 3 ) )
{
this->SetServerStatus( pServerData, STATUS_INACTIVATED );
this->m_pINet->CompulsiveDisconnectServer( pServerData->dwConnectionIndex );
return false;
}
// PTCL_REQUEST_SET_SERVER_LIST 菩哦阑 父电促.
szSendMsg[0] = (BYTE)PTCL_REQUEST_SET_SERVER_LIST;
// PTCL_REQUEST_SET_SERVER_LIST 菩哦阑 傈价茄促.
if( !this->Send( pServerData->dwConnectionIndex, szSendMsg, 1 ) )
{
this->SetServerStatus( pServerData, STATUS_INACTIVATED );
this->m_pINet->CompulsiveDisconnectServer( pServerData->dwConnectionIndex );
return false;
}
// 咯扁鳖瘤 己傍窍搁 老窜 立加捞 沥惑利栏肺 捞风绢柳巴栏肺 夯促.
// 郴 惑怕甫 辑滚府胶飘 硅沥 措扁惑怕肺 官槽促.
this->SetServerStatus( STATUS_AWAITING_SERVER_LIST );
return true;
}
bool CServerTable::BeginNegotiationWithNormalServer( LP_SERVER_DATA pServerData )
{
char szSendMsg[32];
// PTCL_NOTIFY_SERVER_UP 父甸扁.
szSendMsg[0] = (BYTE)PTCL_NOTIFY_SERVER_UP;
memcpy( szSendMsg+1, &this->GetOwnServerData()->wPort, 2 );
// PTCL_NOTIFY_SERVER_UP 傈价.
if( !this->Send( pServerData->dwConnectionIndex, szSendMsg, 3 ) )
{
MyLog( LOG_IMPORTANT, "ConnectToServer() :: Failed To Send PTCL_NOTIFY_SERVER_UP to %s(%d)", GetTypedServerText(pServerData->dwServerType), pServerData->wPort);
this->SetServerStatus( pServerData, STATUS_INACTIVATED );
this->m_pINet->CompulsiveDisconnectServer( pServerData->dwConnectionIndex );
return false;
}
// Server Status 舅覆.
if( !this->NotifyServerStatus( pServerData ) )
{
MyLog( LOG_IMPORTANT, "ConnectToServer() :: Failed to Notify Server Status to %s(%d)", GetTypedServerText(pServerData->dwServerType), pServerData->wPort );
this->SetServerStatus( pServerData, STATUS_INACTIVATED );
this->m_pINet->CompulsiveDisconnectServer( pServerData->dwConnectionIndex );
return false;
}
return true;
}
bool CServerTable::InitServerTable( char *sFileName )
{
LP_SERVER_DATA pServerData = NULL;
char sDummyIP[MM_IP_LENGTH];
char sDummyExternalIP[MM_IP_LENGTH];
DWORD i;
WORD wDummyPort;
WORD wDummyExternalPort;
// 扁夯 Server沥焊 (Own Server, Proxy Server)甫 佬绰促.
char keyname_list[8][80+1] = {
"own_server_ip_for_server", // 0
"own_server_port_for_server",
"own_server_ip_for_user",
"own_server_port_for_user",
"primary_proxy_server_ip",
"primary_proxy_server_port",
"secondary_proxy_server_ip",
"secondary_proxy_server_port" // 7
};
#ifdef __IS_PROXY_SERVER
DWORD num_of_dr_servers;
char base_keyname[4][80+1] = {
"external_server_ip",
"external_server_port",
"external_server_ip_for_user",
"external_server_port_for_user"
};
// Read ServerSetInfo
this->m_dwServerSetNumber = (DWORD)GetPrivateProfileInt( "server_set_info", "own_server_set_number", 0, sFileName );
if( m_dwServerSetNumber == 0 )
{
MyLog( LOG_FATAL, "INI Read Fail('own_server_set_number') is 0 (Might be Read Fail)" );
this->DestroyServer( FINISH_TYPE_BOOT_FAIL );
return false;
}
// 2001.2.28 added by slowboat
// read max user define at INI file
this->m_dwMaxUserNumPerSec = (DWORD)GetPrivateProfileInt( "server_set_info", "default_max_user_can_login_per_sec", 0, sFileName );
this->m_dwMaxUserNum = (DWORD)GetPrivateProfileInt( "server_set_info", "default_max_user_can_login", 0, sFileName );
// Read NumOfDrServers
num_of_dr_servers = (DWORD)GetPrivateProfileInt( "external_server_info", "num_of_external_servers", 0, sFileName );
if( num_of_dr_servers == 0 )
{
MyLog( LOG_FATAL, "INI Read Fail(%s) : On Reading [num_of_external_servers]", sFileName );
this->DestroyServer( FINISH_TYPE_BOOT_FAIL );
return false;
}
#endif
for( i = 0; i < 8; i+=2 ) // attention. not ++, +=2
{
#ifdef __IS_PROXY_SERVER
if( i >= 4 )
break;
#endif
#if defined(__IS_MAP_SERVER) || defined(__IS_DB_DEMON)
if( i == 2 )
continue;
#endif
memset( sDummyIP, 0, MM_IP_LENGTH );
GetPrivateProfileString( "server_info", keyname_list[i], "", sDummyIP, sizeof(sDummyIP), sFileName );
wDummyPort = (WORD)GetPrivateProfileInt( "server_info", keyname_list[i+1], 0, sFileName );
if( ( (sDummyIP[0] == NULL) || (wDummyPort == 0) ) && (i != 6) )
{
MyLog( LOG_FATAL, "INI Read Fail(%s) : On Reading [%s]", sFileName, keyname_list[i] );
this->DestroyServer( FINISH_TYPE_BOOT_FAIL );
return false;
}
switch (i) {
case 0: // Own Server IP/Port for Server Connections.
{
// AddNewServer will create a SERVER_LIST, add it on serverlist, and return it's pointer.
pServerData = this->m_pOwnServerData = this->GetNewServerData( sDummyIP, wDummyPort );
}
break;
case 2: // Set Own Server IP/Port for User Connections. Map Server Does not need this parameters.
{
strcpy( pServerData->szIPForUser, sDummyIP );
pServerData->wPortForUser = wDummyPort;
}
break;
case 4: // Primary Proxy Server IP/Port
{
pServerData = this->GetNewServerData( sDummyIP, wDummyPort );
this->m_pOwnProxyServerData[PRIMARY_SERVER] = pServerData;
if( pServerData )
{
this->AddServerDataToList( pServerData );
}
}
break;
case 6: // Secondary Proxy Server IP/Port
{
// 2001/02/01
// 泅犁 滴俺狼 PROXY啊 豆阑锭 惑炔贸府啊 肯寒窍瘤 臼栏骨肺
// 窍唱狼 橇遏矫父 倾侩茄促.
/* pServerData = this->GetNewServerData( sDummyIP, wDummyPort );
this->m_pOwnProxyServerData[SECONDARY_SERVER] = pServerData;
if( pServerData )
{
this->AddServerDataToList( pServerData );
}
*/
}
break;
default:
return false;
}
}
#ifdef __IS_PROXY_SERVER
char dummy_key_name[80+1];
for( i = 0; i < num_of_dr_servers; i++ )
{
// Read IP
sprintf( dummy_key_name, "%s%d", base_keyname[0], i );
memset( sDummyIP, 0, MM_IP_LENGTH );
GetPrivateProfileString( "external_server_info", dummy_key_name, "", sDummyIP, sizeof(sDummyIP), sFileName );
if( sDummyIP[0] == NULL )
{
MyLog( LOG_FATAL, "INI Read Fail(%s) : On Reading [%s]", sFileName, dummy_key_name );
this->DestroyServer( FINISH_TYPE_BOOT_FAIL );
return false;
}
// Read Port
sprintf( dummy_key_name, "%s%d", base_keyname[1], i );
wDummyPort = (WORD)GetPrivateProfileInt( "external_server_info", dummy_key_name, 0, sFileName );
if( wDummyPort == 0 )
{
MyLog( LOG_FATAL, "INI Read Fail(%s) : On Reading [%s]", sFileName, dummy_key_name );
this->DestroyServer( FINISH_TYPE_BOOT_FAIL );
return false;
}
// Add it To ServerList
pServerData = this->GetNewServerData( sDummyIP, wDummyPort );
pServerData->wServerIndex = i;
// Added by chan78 at 2001/02/24
// 寇何 器飘沥焊甫 佬绰促
if( pServerData->dwServerType == SERVER_TYPE_AGENT )
{
// Read IP
sprintf( dummy_key_name, "%s%d", base_keyname[2], i );
GetPrivateProfileString( "external_server_info", dummy_key_name, "", sDummyExternalIP, sizeof(sDummyExternalIP), sFileName );
// Vertify
if( sDummyExternalIP[0] == 0 )
{
MyLog( LOG_FATAL, "INI Read Fail(%s) : On Reading [%s]", sFileName, dummy_key_name );
this->DestroyServer( FINISH_TYPE_BOOT_FAIL );
return false;
}
// Read Port
sprintf( dummy_key_name, "%s%d", base_keyname[3], i );
wDummyExternalPort = (WORD)GetPrivateProfileInt( "external_server_info", dummy_key_name, 0, sFileName );
// Vertify
if( wDummyExternalPort == 0 )
{
MyLog( LOG_FATAL, "INI Read Fail(%s) : On Reading [%s]", sFileName, dummy_key_name );
this->DestroyServer( FINISH_TYPE_BOOT_FAIL );
return false;
}
// Copy it
memcpy( pServerData->szIPForUser, sDummyExternalIP, MM_IP_LENGTH );
pServerData->wPortForUser = wDummyExternalPort;
}
if( !pServerData )
{
#ifdef __ON_DEBUG
// _asm int 3;
#endif
}
if( !this->AddServerDataToList( pServerData ) )
{
#ifdef __ON_DEBUG
// _asm int 3;
#endif
}
}
#endif //endif for #ifdef__IS_PROXY_SERVER
return true;
}
bool CServerTable::Send( WORD wServerID, char* pMsg, DWORD dwLength )
{
LP_SERVER_DATA pServerData = this->GetServerData( wServerID );
if ( !pServerData || !pServerData->dwConnectionIndex )
{
return false;
}
return this->m_pINet->SendToServer( pServerData->dwConnectionIndex, pMsg, dwLength, FLAG_SEND_NOT_ENCRYPTION );
}
bool CServerTable::Send( DWORD dwConnectionIndex, char* pMsg, DWORD dwLength )
{
return this->m_pINet->SendToServer( dwConnectionIndex, pMsg, dwLength, FLAG_SEND_NOT_ENCRYPTION );
}
bool CServerTable::SendToProxyServer( char* pMsg, DWORD dwLength )
{
LP_SERVER_DATA pProxyServer = this->m_pOwnProxyServerData[PRIMARY_SERVER];
if( !pProxyServer || (pProxyServer->dwConnectionIndex == 0) )
{
pProxyServer = this->m_pOwnProxyServerData[SECONDARY_SERVER];
}
if( !pProxyServer || (pProxyServer->dwConnectionIndex == 0) )
{
return false;
}
// For Debugging
// if( pProxyServer->dwServerType != SERVER_TYPE_PROXY )
// _asm int 3;
return this->m_pINet->SendToServer( pProxyServer->dwConnectionIndex, pMsg, dwLength, FLAG_SEND_NOT_ENCRYPTION );
}
bool CServerTable::SendToDBDemon( char *pMsg, DWORD dwLength )
{
LP_SERVER_DATA pDBDemon = this->m_pOwnDBDemonData;
if( pDBDemon && pDBDemon->dwConnectionIndex )
{
if( this->m_pINet->SendToServer( pDBDemon->dwConnectionIndex, pMsg, dwLength, FLAG_SEND_NOT_ENCRYPTION ) )
{
return true;
}
}
// Failed to Send to Given DB Demon
// First, Find-out another DB Demon
for( pDBDemon = this->m_pServerListHead; pDBDemon; pDBDemon->pNextServerData )
{
if( (pDBDemon->dwServerType == SERVER_TYPE_DB) && (pDBDemon->dwConnectionIndex) )
{
if( this->m_pINet->SendToServer( pDBDemon->dwConnectionIndex, pMsg, dwLength, FLAG_SEND_NOT_ENCRYPTION ) )
{
// Change DB Demon To This one.
this->m_pOwnDBDemonData = pDBDemon;
// Request to set DB Demon to PROXY
this->RequestToSetDBDemon();
return true;
}
}
}
// No way to send... It's FATAL ERROR.
return false;
}
// 漂沥 DB Demon俊霸 焊辰促. Entry甫 啊柳 User狼 贸府绰 捞犯霸 茄促.
bool CServerTable::SendToDBDemon( DWORD dwConnectionIndex, char *pMsg, DWORD dwLength )
{
LP_SERVER_DATA pDBDemon = this->GetServerData( dwConnectionIndex );
if( pDBDemon->dwConnectionIndex && pDBDemon->dwServerType == SERVER_TYPE_DB )
{
if( this->m_pINet->SendToServer( pDBDemon->dwConnectionIndex, pMsg, dwLength, FLAG_SEND_NOT_ENCRYPTION ) )
{
return true;
}
}
return false;
}
bool CServerTable::RequestToSetDBDemon()
{
char szDummyMsg[MM_MAX_PACKET_SIZE];
char buf[256+1];
sprintf( buf, "Now Request DB DEMON Setting..." );
szDummyMsg[0] = (BYTE)PTCL_REQUEST_SET_DB_DEMON;
if( this->SendToProxyServer( szDummyMsg, 1 ) )
{
strcat( buf, " Ok." );
MyLog( LOG_NORMAL, buf );
return true;
}
else
{
strcat( buf, " Failed!" );
MyLog( LOG_IMPORTANT, buf );
return false;
}
}
bool CServerTable::IsServerActivated( LP_SERVER_DATA pServerData )
{
if( !pServerData )
return false;
if( pServerData->dwStatus == STATUS_ACTIVATED )
{
return true;
}
return false;
}
bool CServerTable::IsServerActivated( WORD wPort )
{
LP_SERVER_DATA pServerData = this->GetServerData( wPort );
if( !pServerData )
return false;
if( pServerData->dwStatus == STATUS_ACTIVATED )
{
return true;
}
return false;
}
#ifdef __IS_MAP_SERVER
bool CServerTable::SendRajaPacketToOtherMapServer( WORD wPort, char* szMsg, DWORD dwLength )
{
char szDummyMsg[MM_MAX_PACKET_SIZE];
szDummyMsg[0] = (BYTE)PTCL_MAP_TO_MAP;
memcpy( szDummyMsg+1, szMsg, dwLength );
if( !this->Send( wPort, szDummyMsg, dwLength+1 ) )
{
#ifdef __ON_DEBUG
// _asm int 3;
#endif
return false;
}
return true;
}
#endif
#ifdef __IS_PROXY_SERVER
void CServerTable::ReBalanceDBDemonSettings()
{
LP_SERVER_DATA pDummyServerData;
DWORD dwNumOfServers1 = 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -