Compare commits
2 Commits
0f69efeba4
...
74827a1907
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
74827a1907 | ||
|
|
8a5f6e70ee |
@@ -103,6 +103,76 @@ namespace
|
||||
return stmt.BindParam(MYSQL_TYPE_LONG, &guildId);
|
||||
}
|
||||
|
||||
bool InsertGuildRecord(const char* name, uint32_t masterPid, uint32_t& guildId)
|
||||
{
|
||||
CStmt stmt;
|
||||
const std::string query = std::string("INSERT INTO guild") + get_table_postfix()
|
||||
+ "(name, master, sp, level, exp, skill_point, skill) "
|
||||
+ "VALUES(?, ?, 1000, 1, 0, 0, '\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0')";
|
||||
|
||||
guildId = 0;
|
||||
|
||||
if (!PrepareGameStmt(stmt, query))
|
||||
return false;
|
||||
|
||||
if (!stmt.BindParam(MYSQL_TYPE_STRING, const_cast<char*>(name))
|
||||
|| !stmt.BindParam(MYSQL_TYPE_LONG, &masterPid)
|
||||
|| !stmt.Execute())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
guildId = static_cast<uint32_t>(stmt.GetInsertId());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InsertGuildGrade(uint32_t guildId, int grade, const char* gradeName, int authFlag)
|
||||
{
|
||||
CStmt stmt;
|
||||
const std::string query = std::string("INSERT INTO guild_grade") + get_table_postfix() + " VALUES(?, ?, ?, ?)";
|
||||
|
||||
if (!PrepareGameStmt(stmt, query))
|
||||
return false;
|
||||
|
||||
if (!stmt.BindParam(MYSQL_TYPE_LONG, &guildId)
|
||||
|| !stmt.BindParam(MYSQL_TYPE_LONG, &grade)
|
||||
|| !stmt.BindParam(MYSQL_TYPE_STRING, const_cast<char*>(gradeName))
|
||||
|| !stmt.BindParam(MYSQL_TYPE_LONG, &authFlag))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return stmt.Execute();
|
||||
}
|
||||
|
||||
bool LoadGuildInviteLimit(uint32_t guildId, uint32_t& inviteLimit, bool& found)
|
||||
{
|
||||
CStmt stmt;
|
||||
const std::string query = "SELECT value FROM guild_invite_limit WHERE id=?";
|
||||
|
||||
inviteLimit = 0;
|
||||
found = false;
|
||||
|
||||
if (!PrepareGameStmt(stmt, query))
|
||||
return false;
|
||||
|
||||
if (!stmt.BindParam(MYSQL_TYPE_LONG, &guildId)
|
||||
|| !stmt.BindResult(MYSQL_TYPE_LONG, &inviteLimit)
|
||||
|| !stmt.Execute())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (stmt.iRows == 0)
|
||||
return true;
|
||||
|
||||
if (!stmt.Fetch())
|
||||
return false;
|
||||
|
||||
found = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
struct FGuildNameSender
|
||||
{
|
||||
FGuildNameSender(uint32_t id, const char* guild_name) : id(id), name(guild_name)
|
||||
@@ -149,22 +219,15 @@ CGuild::CGuild(TGuildCreateParameter & cp)
|
||||
m_data.grade_array[i].auth_flag = 0;
|
||||
}
|
||||
|
||||
auto pmsg = DBManager::instance().DirectQuery(
|
||||
"INSERT INTO guild%s(name, master, sp, level, exp, skill_point, skill) "
|
||||
"VALUES('%s', %u, 1000, 1, 0, 0, '\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0')",
|
||||
get_table_postfix(), m_data.name, m_data.master_pid);
|
||||
|
||||
// TODO if error occur?
|
||||
m_data.guild_id = pmsg->Get()->uiInsertID;
|
||||
InsertGuildRecord(m_data.name, m_data.master_pid, m_data.guild_id);
|
||||
|
||||
for (int i = 0; i < GUILD_GRADE_COUNT; ++i)
|
||||
{
|
||||
DBManager::instance().Query("INSERT INTO guild_grade%s VALUES(%u, %d, '%s', %d)",
|
||||
get_table_postfix(),
|
||||
m_data.guild_id,
|
||||
i + 1,
|
||||
m_data.grade_array[i].grade_name,
|
||||
m_data.grade_array[i].auth_flag);
|
||||
InsertGuildGrade(
|
||||
m_data.guild_id,
|
||||
i + 1,
|
||||
m_data.grade_array[i].grade_name,
|
||||
m_data.grade_array[i].auth_flag);
|
||||
}
|
||||
|
||||
ComputeGuildPoints();
|
||||
@@ -2200,13 +2263,13 @@ CGuild::GuildJoinErrCode CGuild::VerifyGuildJoinableCondition( const LPCHARACTER
|
||||
}
|
||||
else if ( LC_IsBrazil() == true )
|
||||
{
|
||||
auto pMsg = DBManager::instance().DirectQuery("SELECT value FROM guild_invite_limit WHERE id=%d", GetID());
|
||||
uint32_t inviteLimit = 0;
|
||||
bool hasInviteLimit = false;
|
||||
|
||||
if ( pMsg->Get()->uiNumRows > 0 )
|
||||
if (LoadGuildInviteLimit(GetID(), inviteLimit, hasInviteLimit) && hasInviteLimit)
|
||||
{
|
||||
MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
|
||||
time_t limit_time=0;
|
||||
str_to_number( limit_time, row[0] );
|
||||
limit_time = inviteLimit;
|
||||
|
||||
if (test_server)
|
||||
{
|
||||
|
||||
@@ -11,10 +11,113 @@
|
||||
#include "char.h"
|
||||
#include "char_manager.h"
|
||||
#include "questmanager.h"
|
||||
#include "libsql/Statement.h"
|
||||
|
||||
static char __account[CHARACTER_NAME_MAX_LEN * 2 + 1];
|
||||
static char __companion[CHARACTER_NAME_MAX_LEN * 2 + 1];
|
||||
|
||||
namespace
|
||||
{
|
||||
bool PrepareMessengerStmt(CStmt& stmt, const std::string& query)
|
||||
{
|
||||
CAsyncSQL* sql = DBManager::instance().GetDirectSQL();
|
||||
|
||||
if (!sql)
|
||||
{
|
||||
sys_err("messenger direct SQL handle is not initialized");
|
||||
return false;
|
||||
}
|
||||
|
||||
return stmt.Prepare(sql, query.c_str());
|
||||
}
|
||||
|
||||
bool LoadMessengerCompanions(MessengerManager::keyA account, std::vector<std::string>& companions)
|
||||
{
|
||||
CStmt stmt;
|
||||
char companion[CHARACTER_NAME_MAX_LEN + 1];
|
||||
const std::string query = std::string("SELECT companion FROM messenger_list") + get_table_postfix() + " WHERE account=?";
|
||||
|
||||
memset(companion, 0, sizeof(companion));
|
||||
companions.clear();
|
||||
|
||||
if (!PrepareMessengerStmt(stmt, query))
|
||||
return false;
|
||||
|
||||
if (!stmt.BindParam(MYSQL_TYPE_STRING, const_cast<char*>(account.c_str()))
|
||||
|| !stmt.BindResult(MYSQL_TYPE_STRING, companion, sizeof(companion))
|
||||
|| !stmt.Execute())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < stmt.iRows; ++i)
|
||||
{
|
||||
memset(companion, 0, sizeof(companion));
|
||||
|
||||
if (!stmt.Fetch())
|
||||
return false;
|
||||
|
||||
companions.emplace_back(companion);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InsertMessengerRelation(MessengerManager::keyA account, MessengerManager::keyA companion)
|
||||
{
|
||||
CStmt stmt;
|
||||
const std::string query = std::string("INSERT INTO messenger_list") + get_table_postfix() + " VALUES (?, ?)";
|
||||
|
||||
if (!PrepareMessengerStmt(stmt, query))
|
||||
return false;
|
||||
|
||||
if (!stmt.BindParam(MYSQL_TYPE_STRING, const_cast<char*>(account.c_str()))
|
||||
|| !stmt.BindParam(MYSQL_TYPE_STRING, const_cast<char*>(companion.c_str())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return stmt.Execute();
|
||||
}
|
||||
|
||||
bool DeleteMessengerRelation(MessengerManager::keyA account, MessengerManager::keyA companion)
|
||||
{
|
||||
CStmt stmt;
|
||||
const std::string query = std::string("DELETE FROM messenger_list") + get_table_postfix()
|
||||
+ " WHERE (account=? AND companion=?) OR (account=? AND companion=?)";
|
||||
|
||||
if (!PrepareMessengerStmt(stmt, query))
|
||||
return false;
|
||||
|
||||
if (!stmt.BindParam(MYSQL_TYPE_STRING, const_cast<char*>(account.c_str()))
|
||||
|| !stmt.BindParam(MYSQL_TYPE_STRING, const_cast<char*>(companion.c_str()))
|
||||
|| !stmt.BindParam(MYSQL_TYPE_STRING, const_cast<char*>(companion.c_str()))
|
||||
|| !stmt.BindParam(MYSQL_TYPE_STRING, const_cast<char*>(account.c_str())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return stmt.Execute();
|
||||
}
|
||||
|
||||
bool DeleteAllMessengerRelations(MessengerManager::keyA account)
|
||||
{
|
||||
CStmt stmt;
|
||||
const std::string query = std::string("DELETE FROM messenger_list") + get_table_postfix() + " WHERE account=? OR companion=?";
|
||||
|
||||
if (!PrepareMessengerStmt(stmt, query))
|
||||
return false;
|
||||
|
||||
if (!stmt.BindParam(MYSQL_TYPE_STRING, const_cast<char*>(account.c_str()))
|
||||
|| !stmt.BindParam(MYSQL_TYPE_STRING, const_cast<char*>(account.c_str())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return stmt.Execute();
|
||||
}
|
||||
}
|
||||
|
||||
MessengerManager::MessengerManager()
|
||||
{
|
||||
}
|
||||
@@ -51,39 +154,26 @@ void MessengerManager::Login(MessengerManager::keyA account)
|
||||
if (account.compare(__account))
|
||||
return;
|
||||
|
||||
DBManager::instance().FuncQuery(std::bind(&MessengerManager::LoadList, this, std::placeholders::_1),
|
||||
"SELECT account, companion FROM messenger_list%s WHERE account='%s'", get_table_postfix(), account.c_str());
|
||||
|
||||
m_set_loginAccount.insert(account);
|
||||
LoadList(account);
|
||||
}
|
||||
|
||||
void MessengerManager::LoadList(SQLMsg * msg)
|
||||
void MessengerManager::LoadList(MessengerManager::keyA account)
|
||||
{
|
||||
if (NULL == msg)
|
||||
std::vector<std::string> companions;
|
||||
|
||||
if (!LoadMessengerCompanions(account, companions))
|
||||
return;
|
||||
|
||||
if (NULL == msg->Get())
|
||||
if (companions.empty())
|
||||
return;
|
||||
|
||||
if (msg->Get()->uiNumRows == 0)
|
||||
return;
|
||||
|
||||
std::string account;
|
||||
|
||||
sys_log(1, "Messenger::LoadList");
|
||||
|
||||
for (uint i = 0; i < msg->Get()->uiNumRows; ++i)
|
||||
for (const auto& companion : companions)
|
||||
{
|
||||
MYSQL_ROW row = mysql_fetch_row(msg->Get()->pSQLResult);
|
||||
|
||||
if (row[0] && row[1])
|
||||
{
|
||||
if (account.length() == 0)
|
||||
account = row[0];
|
||||
|
||||
m_Relation[row[0]].insert(row[1]);
|
||||
m_InverseRelation[row[1]].insert(row[0]);
|
||||
}
|
||||
m_Relation[account].insert(companion);
|
||||
m_InverseRelation[companion].insert(account);
|
||||
}
|
||||
|
||||
SendList(account);
|
||||
@@ -501,8 +591,7 @@ void MessengerManager::AddToList(MessengerManager::keyA account, MessengerManage
|
||||
|
||||
sys_log(0, "Messenger Add %s %s", account.c_str(), companion.c_str());
|
||||
|
||||
DBManager::instance().Query("INSERT INTO messenger_list%s VALUES ('%s', '%s')",
|
||||
get_table_postfix(), account.c_str(), companion.c_str());
|
||||
InsertMessengerRelation(account, companion);
|
||||
|
||||
__AddToList(account, companion);
|
||||
|
||||
@@ -568,9 +657,7 @@ void MessengerManager::RemoveFromList(MessengerManager::keyA account, MessengerM
|
||||
|
||||
sys_log(1, "Messenger Remove %s %s", account.c_str(), companion.c_str());
|
||||
|
||||
// Fix
|
||||
DBManager::instance().Query("DELETE FROM messenger_list%s WHERE (account='%s' AND companion = '%s') OR (account = '%s' AND companion = '%s')",
|
||||
get_table_postfix(), account.c_str(), companion.c_str(), companion.c_str(), account.c_str());
|
||||
DeleteMessengerRelation(account, companion);
|
||||
|
||||
// MR-3: Remove from messenger Fix
|
||||
LPCHARACTER ch = CHARACTER_MANAGER::instance().FindPC(account.c_str());
|
||||
@@ -601,8 +688,7 @@ void MessengerManager::RemoveAllList(keyA account)
|
||||
return;
|
||||
|
||||
/* SQL Data 삭제 */
|
||||
DBManager::instance().Query("DELETE FROM messenger_list%s WHERE account='%s' OR companion='%s'",
|
||||
get_table_postfix(), account.c_str(), account.c_str());
|
||||
DeleteAllMessengerRelations(account);
|
||||
|
||||
/* 내가 가지고있는 리스트 삭제 */
|
||||
for (std::set<keyT>::iterator iter = company.begin();
|
||||
@@ -739,4 +825,3 @@ void MessengerManager::SendLogout(MessengerManager::keyA account, MessengerManag
|
||||
d->BufferedPacket(&bLen, sizeof(BYTE));
|
||||
d->Packet(companion.c_str(), companion.size());
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ class MessengerManager : public singleton<MessengerManager>
|
||||
void SendLogin(keyA account, keyA companion);
|
||||
void SendLogout(keyA account, keyA companion);
|
||||
|
||||
void LoadList(SQLMsg * pmsg);
|
||||
void LoadList(keyA account);
|
||||
|
||||
void Destroy();
|
||||
|
||||
|
||||
@@ -188,3 +188,11 @@ unsigned long long CStmt::GetAffectedRows() const
|
||||
|
||||
return mysql_stmt_affected_rows(m_pkStmt);
|
||||
}
|
||||
|
||||
unsigned long long CStmt::GetInsertId() const
|
||||
{
|
||||
if (!m_pkStmt)
|
||||
return 0;
|
||||
|
||||
return mysql_stmt_insert_id(m_pkStmt);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ class CStmt
|
||||
bool Fetch();
|
||||
unsigned long GetResultLength(unsigned int index) const;
|
||||
unsigned long long GetAffectedRows() const;
|
||||
unsigned long long GetInsertId() const;
|
||||
|
||||
void Error(const char * c_pszMsg);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user