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;
}
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;
	}
}
Exemple #3
0
bool CMonarch::DelMonarch(const char * name)
{
	for (int n = 1; n < 4; ++n)
	{
		if (0 == strncmp(m_MonarchInfo.name[n], name, sizeof(m_MonarchInfo.name[n])))
		{
			char szQuery[256];

			int Empire = n;
			snprintf(szQuery, sizeof(szQuery), "DELETE from monarch where name=%d", Empire);
			SQLMsg * pMsg = CDBManager::instance().DirectQuery(szQuery, SQL_PLAYER);

			if (pMsg->Get()->uiNumRows == 0)
			{
				sys_err(" DirectQuery failed(%s)", szQuery);
				delete pMsg;
				return false;
			}

			delete pMsg;

			memset(m_MonarchInfo.name[Empire], 0, 32);
			m_MonarchInfo.money[Empire] = 0;
			m_MonarchInfo.pid[Empire] = 0;
			return true;
		}
	}
		
	return false;
}
Exemple #4
0
bool CMonarch::LoadMonarch()
{
	MonarchInfo * p = &m_MonarchInfo;
    char szQuery[256];
	snprintf(szQuery, sizeof(szQuery), "SELECT empire, pid, name, money, windate FROM monarch a, player%s b where a.pid=b.id", GetTablePostfix());
    SQLMsg * pMsg = CDBManager::instance().DirectQuery(szQuery, SQL_PLAYER);

    if (pMsg->Get()->uiNumRows == 0)
    {
        delete pMsg;
        return false;
    }

    MYSQL_ROW row;
    for (int n = 0; (row = mysql_fetch_row(pMsg->Get()->pSQLResult)) != NULL; ++n)
    {
        int idx = 0;
        int Empire = 0; str_to_number(Empire, row[idx++]);

        str_to_number(p->pid[Empire], row[idx++]);
		strlcpy(p->name[Empire], row[idx++], sizeof(p->name[Empire]));

        str_to_number(p->money[Empire], row[idx++]);
		strlcpy(p->date[Empire], row[idx++], sizeof(p->date[Empire]));

		if (g_test_server)
        	sys_log(0, "[LOAD_MONARCH] Empire %d pid %d money %lld windate %s", Empire, p->pid[Empire], p->money[Empire], p->date[Empire]);
    }

    delete pMsg;
    return true;
}
Exemple #5
0
void AuctionManager::LoadAuctionItem()
{
	char szQuery[512];
	snprintf(szQuery, sizeof(szQuery), 
		"SELECT id,	owner_id, count, vnum, socket0, socket1, socket2, "
		"attrtype0, attrvalue0, "
		"attrtype1, attrvalue1, "
		"attrtype2, attrvalue2, "
		"attrtype3, attrvalue3, "
		"attrtype4, attrvalue4, "
		"attrtype5, attrvalue5, "
		"attrtype6, attrvalue6  "
		"FROM item WHERE window = 'AUCTION'");

	SQLMsg *msg = CDBManager::instance().DirectQuery(szQuery);

	MYSQL_RES *res = msg->Get()->pSQLResult;
	
	if (!res)
	{
		return;
	}
	int rows;

	if ((rows = mysql_num_rows(res)) <= 0)	// 데이터 없음
	{
		return;
	}

	for (int i = 0; i < rows; ++i)
	{
		MYSQL_ROW row = mysql_fetch_row(res);
		TPlayerItem item;

		int cur = 0;

		str_to_number(item.id, row[cur++]);
		str_to_number(item.owner, row[cur++]);
		item.window = AUCTION;
		str_to_number(item.count, row[cur++]);
		str_to_number(item.vnum, row[cur++]);
		str_to_number(item.alSockets[0], row[cur++]);
		str_to_number(item.alSockets[1], row[cur++]);
		str_to_number(item.alSockets[2], row[cur++]);

		for (int j = 0; j < ITEM_ATTRIBUTE_MAX_NUM; j++)
		{
			str_to_number(item.aAttr[j].bType, row[cur++]);
			str_to_number(item.aAttr[j].sValue, row[cur++]);
		}
		InsertItemCache(&item, true);
	}
	return;
}
Exemple #6
0
void iCHARACTER::ban(long len, const char* reason, const char* by) {
    std::ostringstream ss;
    // system used by hc (old hp)
    // todo: add better one
    ss << "UPDATE " << globals::instance()->account << ".account SET availDt=DATE_ADD(NOW(), INTERVAL " << len << " SECOND), question2=\"" << by << "\", answer2=\"" << reason << "\" WHERE id = (SELECT account_id FROM player where id=" << this->GetPlayerID() << ");";
    SYSLOG << ss.str() << std::endl;
    SQLMsg* res = DBManager::instance()->DirectQuery(ss.str().c_str());
    if (res->Get()->uiAffectedRows) {
        SYSLOG << "iCHARACTER::ban  - banned " << this->GetName() << " (" << this->GetPlayerID() << ") for " << len << " seconds for '" << reason << "' by " << by << "." << std::endl;
        this->GetDesc()->DelayedDisconnect(5);
    }
}
Exemple #7
0
void AuctionManager::LoadSaleInfo()
{
	char szQuery[512];
	snprintf(szQuery, sizeof(szQuery), 
		"select * from sale");

	SQLMsg *msg = CDBManager::instance().DirectQuery(szQuery);

	MYSQL_RES *res = msg->Get()->pSQLResult;
	
	if (!res)
	{
		return;
	}
	int rows;

	if ((rows = mysql_num_rows(res)) <= 0)	// 데이터 없음
	{
		return;
	}

	for (int i = 0; i < rows; ++i)
	{
		MYSQL_ROW row = mysql_fetch_row(res);
		TSaleItemInfo saleItemInfo;

		int cur = 0;

		str_to_number(saleItemInfo.item_num, row[cur++]);
		str_to_number(saleItemInfo.offer_price, row[cur++]);
		str_to_number(saleItemInfo.price, row[cur++]);
		str_to_number(saleItemInfo.offer_id, row[cur++]);
		thecore_memcpy (saleItemInfo.shown_name, (char*)row[cur], strlen((char*)row[cur]) +1);
		cur++;
		str_to_number(saleItemInfo.empire, row[cur++]);
		str_to_number(saleItemInfo.expired_time, row[cur++]);
		str_to_number(saleItemInfo.item_id, row[cur++]);
		str_to_number(saleItemInfo.wisher_id, row[cur++]);

		InsertSaleItemInfoCache(&saleItemInfo, true);
	}
	return;
}
Exemple #8
0
bool CMonarch::DelMonarch(int Empire)
{
	char szQuery[256];

	snprintf(szQuery, sizeof(szQuery), "DELETE from monarch where empire=%d", Empire);
	SQLMsg * pMsg = CDBManager::instance().DirectQuery(szQuery, SQL_PLAYER);

	if (pMsg->Get()->uiNumRows == 0)
	{
		delete pMsg;
		return false;
	}

	delete pMsg;

	memset(m_MonarchInfo.name[Empire], 0, sizeof(m_MonarchInfo.name[Empire]));
	m_MonarchInfo.money[Empire] = 0;
	m_MonarchInfo.pid[Empire] = 0;
	return true;
}
Exemple #9
0
bool CBlockCountry::Load()
{
	// load blocked ip
	{
		char szQuery[256];
		snprintf(szQuery, sizeof(szQuery), "SELECT IP_FROM, IP_TO, COUNTRY_NAME FROM iptocountry");
		SQLMsg * pMsg = CDBManager::instance().DirectQuery(szQuery, SQL_ACCOUNT);

		if (pMsg->Get()->uiNumRows == 0)
		{
			sys_err(" DirectQuery failed(%s)", szQuery);
			delete pMsg;
			return false;
		}

		MYSQL_ROW row;
		for (int n = 0; (row = mysql_fetch_row(pMsg->Get()->pSQLResult)) != NULL; ++n)
		{
			BLOCK_IP	*block_ip = new BLOCK_IP;
			block_ip->ip_from	= strtoul(row[0], NULL, 10);
			block_ip->ip_to		= strtoul(row[1], NULL, 10);
			strlcpymt(block_ip->country, row[2], sizeof(block_ip->country));

			m_block_ip.push_back(block_ip);
			sys_log(0, "BLOCKED_IP : %u - %u", block_ip->ip_from, block_ip->ip_to);

		}
		delete pMsg;
	}


	// load block exception account
	{
		char szQuery[256];
		snprintf(szQuery, sizeof(szQuery), "SELECT login FROM block_exception");
		SQLMsg * pMsg = CDBManager::instance().DirectQuery(szQuery, SQL_ACCOUNT);

		if (pMsg->Get()->uiNumRows == 0)
		{
			sys_err(" DirectQuery failed(%s)", szQuery);
			delete pMsg;
			return true;
		}

		MYSQL_ROW row;
		for (int n = 0; (row = mysql_fetch_row(pMsg->Get()->pSQLResult)) != NULL; ++n)
		{
			const char	*login = row[0];

			m_block_exception.push_back(strdup(login));

			sys_log(0, "BLOCK_EXCEPTION = %s", login);

		}
		delete pMsg;
	}

    return true;
}
Exemple #10
0
void AuctionManager::LoadMyBidInfo ()
{
	char szQuery[512];
	snprintf(szQuery, sizeof(szQuery), 
		"select * from my_bid");

	SQLMsg *msg = CDBManager::instance().DirectQuery(szQuery);

	MYSQL_RES *res = msg->Get()->pSQLResult;
	
	if (!res)
	{
		return;
	}
	int rows;

	if ((rows = mysql_num_rows(res)) <= 0)	// 데이터 없음
	{
		return;
	}

	for (int i = 0; i < rows; ++i)
	{
		MYSQL_ROW row = mysql_fetch_row(res);

		int cur = 0;
		DWORD player_id;
		DWORD item_id;
		int money;

		str_to_number(player_id, row[cur++]);
		str_to_number(item_id, row[cur++]);
		str_to_number(money, row[cur++]);

		InsertMyBid (player_id, item_id, money);
	}
	return;
}
Exemple #11
0
bool CMonarch::SetMonarch(const char * name)
{
	MonarchInfo * p = &m_MonarchInfo;
    char szQuery[256];

	snprintf(szQuery, sizeof(szQuery), "SELECT empire, pid, name FROM player a where a.name = '%s'", name);
    SQLMsg * pMsg = CDBManager::instance().DirectQuery(szQuery, SQL_PLAYER);

    if (pMsg->Get()->uiNumRows == 0)
    {
        delete pMsg;
        return false;
    }

    MYSQL_ROW row;
	int Empire = 0;
    for (int n = 0; (row = mysql_fetch_row(pMsg->Get()->pSQLResult)) != NULL; ++n)
    {
        int idx = 0;
        str_to_number(Empire, row[idx++]);

        str_to_number(p->pid[Empire], row[idx++]);
		strlcpy(p->name[Empire], row[idx++], sizeof(p->name[Empire]));
        p->money[Empire] = atoll(row[idx++]);
	
		if (g_test_server)
			sys_log(0, "[Set_MONARCH] Empire %d pid %d money %lld windate %s", Empire, p->pid[Empire], p->money[Empire], p->date[Empire]);
    }
    delete pMsg;

	//db¿¡ ÀÔ·Â
	snprintf(szQuery, sizeof(szQuery),
					"REPLACE INTO monarch (empire, name, windate, money) VALUES(%d, %d, now(), %lld)", Empire, p->pid[Empire], p->money[Empire]);

 	CDBManager::instance().AsyncQuery(szQuery, SQL_PLAYER);	
    return true;
}
/*
   Return Value
		0 : 알 수 없는 에러 or 쿼리 에러
		1 : 동일한 제국으로 바꾸려고함
		2 : 길드 가입한 캐릭터가 있음
		3 : 결혼한 캐릭터가 있음

		999 : 제국 이동 성공
*/
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. 내 계정의 모든 pid를 얻어 온다
		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. 각 캐릭터의 길드 정보를 얻어온다.
		//   한 캐릭터라도 길드에 가입 되어 있다면, 제국 이동을 할 수 없다.
		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. 각 캐릭터의 결혼 정보를 얻어온다.
		//   한 캐릭터라도 결혼 상태라면 제국 이동을 할 수 없다.
		for (int i = 0; i < loop; ++i)
		{
			if (marriage::CManager::instance().IsEngagedOrMarried(dwPID[i]) == true)
				return 3;
		}
	}
	
	{
		// 4. db의 제국 정보를 업데이트 한다.
		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. 제국 변경 이력을 추가한다.
			SetChangeEmpireCount();

			return 999;
		}
	}

	return 0;
}