forked from metin2/server
Add project files.
This commit is contained in:
210
game/src/char_change_empire.cpp
Normal file
210
game/src/char_change_empire.cpp
Normal file
@ -0,0 +1,210 @@
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "config.h"
|
||||
#include "char.h"
|
||||
#include "char_manager.h"
|
||||
#include "db.h"
|
||||
#include "guild_manager.h"
|
||||
#include "marriage.h"
|
||||
|
||||
/*
|
||||
Return Value
|
||||
0 : <20><> <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> or <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
1 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ٲٷ<D9B2><D9B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
2 : <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ij<><C4B3><EFBFBD>Ͱ<EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
3 : <20><>ȥ<EFBFBD><C8A5> ij<><C4B3><EFBFBD>Ͱ<EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
|
||||
999 : <20><><EFBFBD><EFBFBD> <20>̵<EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
*/
|
||||
int CHARACTER::ChangeEmpire(BYTE empire)
|
||||
{
|
||||
if (GetEmpire() == empire)
|
||||
return 1;
|
||||
|
||||
char szQuery[1024+1];
|
||||
DWORD dwAID;
|
||||
DWORD dwPID[4];
|
||||
memset(dwPID, 0, sizeof(dwPID));
|
||||
|
||||
{
|
||||
// 1. <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> pid<69><64> <20><><EFBFBD><EFBFBD> <20>´<EFBFBD>
|
||||
snprintf(szQuery, sizeof(szQuery),
|
||||
"SELECT id, pid1, pid2, pid3, pid4 FROM player_index%s WHERE pid1=%u OR pid2=%u OR pid3=%u OR pid4=%u AND empire=%u",
|
||||
get_table_postfix(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetEmpire());
|
||||
|
||||
std::auto_ptr<SQLMsg> msg(DBManager::instance().DirectQuery(szQuery));
|
||||
|
||||
if (msg->Get()->uiNumRows == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
MYSQL_ROW row = mysql_fetch_row(msg->Get()->pSQLResult);
|
||||
|
||||
str_to_number(dwAID, row[0]);
|
||||
str_to_number(dwPID[0], row[1]);
|
||||
str_to_number(dwPID[1], row[2]);
|
||||
str_to_number(dwPID[2], row[3]);
|
||||
str_to_number(dwPID[3], row[4]);
|
||||
}
|
||||
|
||||
const int loop = 4;
|
||||
|
||||
{
|
||||
// 2. <20><> ij<><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD>.
|
||||
// <20><> ij<><C4B3><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD> <20><><EFBFBD>忡 <20><><EFBFBD><EFBFBD> <20>Ǿ<EFBFBD> <20>ִٸ<D6B4>, <20><><EFBFBD><EFBFBD> <20>̵<EFBFBD><CCB5><EFBFBD> <20><> <20><> <20><><EFBFBD><EFBFBD>.
|
||||
DWORD dwGuildID[4];
|
||||
CGuild * pGuild[4];
|
||||
SQLMsg * pMsg = NULL;
|
||||
|
||||
for (int i = 0; i < loop; ++i)
|
||||
{
|
||||
snprintf(szQuery, sizeof(szQuery), "SELECT guild_id FROM guild_member%s WHERE pid=%u", get_table_postfix(), dwPID[i]);
|
||||
|
||||
pMsg = DBManager::instance().DirectQuery(szQuery);
|
||||
|
||||
if (pMsg != NULL)
|
||||
{
|
||||
if (pMsg->Get()->uiNumRows > 0)
|
||||
{
|
||||
MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
|
||||
|
||||
str_to_number(dwGuildID[i], row[0]);
|
||||
|
||||
pGuild[i] = CGuildManager::instance().FindGuild(dwGuildID[i]);
|
||||
|
||||
if (pGuild[i] != NULL)
|
||||
{
|
||||
M2_DELETE(pMsg);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dwGuildID[i] = 0;
|
||||
pGuild[i] = NULL;
|
||||
}
|
||||
|
||||
M2_DELETE(pMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// 3. <20><> ij<><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ȥ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD>.
|
||||
// <20><> ij<><C4B3><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD> <20><>ȥ <20><><EFBFBD>¶<EFBFBD><C2B6><EFBFBD> <20><><EFBFBD><EFBFBD> <20>̵<EFBFBD><CCB5><EFBFBD> <20><> <20><> <20><><EFBFBD><EFBFBD>.
|
||||
for (int i = 0; i < loop; ++i)
|
||||
{
|
||||
if (marriage::CManager::instance().IsEngagedOrMarried(dwPID[i]) == true)
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// 4. db<64><62> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ <20>Ѵ<EFBFBD>.
|
||||
snprintf(szQuery, sizeof(szQuery), "UPDATE player_index%s SET empire=%u WHERE pid1=%u OR pid2=%u OR pid3=%u OR pid4=%u AND empire=%u",
|
||||
get_table_postfix(), empire, GetPlayerID(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetEmpire());
|
||||
|
||||
std::auto_ptr<SQLMsg> msg(DBManager::instance().DirectQuery(szQuery));
|
||||
|
||||
if (msg->Get()->uiAffectedRows > 0)
|
||||
{
|
||||
// 5. <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>̷<EFBFBD><CCB7><EFBFBD> <20>߰<EFBFBD><DFB0>Ѵ<EFBFBD>.
|
||||
SetChangeEmpireCount();
|
||||
|
||||
return 999;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CHARACTER::GetChangeEmpireCount() const
|
||||
{
|
||||
char szQuery[1024+1];
|
||||
DWORD dwAID = GetAID();
|
||||
|
||||
if (dwAID == 0)
|
||||
return 0;
|
||||
|
||||
snprintf(szQuery, sizeof(szQuery), "SELECT change_count FROM change_empire WHERE account_id = %u", dwAID);
|
||||
|
||||
SQLMsg * pMsg = DBManager::instance().DirectQuery(szQuery);
|
||||
|
||||
if (pMsg != NULL)
|
||||
{
|
||||
if (pMsg->Get()->uiNumRows == 0)
|
||||
{
|
||||
M2_DELETE(pMsg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
|
||||
|
||||
DWORD count = 0;
|
||||
str_to_number(count, row[0]);
|
||||
|
||||
M2_DELETE(pMsg);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CHARACTER::SetChangeEmpireCount()
|
||||
{
|
||||
char szQuery[1024+1];
|
||||
|
||||
DWORD dwAID = GetAID();
|
||||
|
||||
if (dwAID == 0) return;
|
||||
|
||||
int count = GetChangeEmpireCount();
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
count++;
|
||||
snprintf(szQuery, sizeof(szQuery), "INSERT INTO change_empire VALUES(%u, %d, NOW())", dwAID, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
count++;
|
||||
snprintf(szQuery, sizeof(szQuery), "UPDATE change_empire SET change_count=%d WHERE account_id=%u", count, dwAID);
|
||||
}
|
||||
|
||||
std::auto_ptr<SQLMsg> pmsg(DBManager::instance().DirectQuery(szQuery));
|
||||
}
|
||||
|
||||
DWORD CHARACTER::GetAID() const
|
||||
{
|
||||
char szQuery[1024+1];
|
||||
DWORD dwAID = 0;
|
||||
|
||||
snprintf(szQuery, sizeof(szQuery), "SELECT id FROM player_index%s WHERE pid1=%u OR pid2=%u OR pid3=%u OR pid4=%u AND empire=%u",
|
||||
get_table_postfix(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetPlayerID(), GetEmpire());
|
||||
|
||||
SQLMsg* pMsg = DBManager::instance().DirectQuery(szQuery);
|
||||
|
||||
if (pMsg != NULL)
|
||||
{
|
||||
if (pMsg->Get()->uiNumRows == 0)
|
||||
{
|
||||
M2_DELETE(pMsg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
|
||||
|
||||
str_to_number(dwAID, row[0]);
|
||||
|
||||
M2_DELETE(pMsg);
|
||||
|
||||
return dwAID;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user