Jump to content

System Team (Source)


Marcos

Recommended Posts

Boa tarde pessoal...

Eu implementei o sistema de equipe online pela source, não meu deu qualquer erro, tanto no game como no binário.

Mais quando eu logo acontece o seguinte:

1-) Quando logo tanto a conta de GM, ou player a lista fica vazia.

2-) Quando eu teleporto um char player, o mesmo aparece na lista da Staff como se ele fosse um GM.

Obs, não há qualquer syserr tanto no game quanto no cliente, ambos estão limpos.

Alguém q tenha o sistema sabe o q pode ser?

Boa tarde a todos, e obrigado pela atenção...

Link to comment

messenger_manager.cpp:

void MessengerManager::Login(MessengerManager::keyA account)
{
	if (m_set_loginAccount.find(account) != m_set_loginAccount.end())
		return;

	DBManager::instance().FuncQuery(std::bind1st(std::mem_fun(&MessengerManager::LoadList), this),
			"SELECT account, companion FROM messenger_list%s WHERE account='%s'", get_table_postfix(), __account);

#ifdef ENABLE_MESSENGER_TEAM
	DBManager::instance().FuncQuery(std::bind1st(std::mem_fun(&MessengerManager::LoadTeamList), this),
			"SELECT '%s' as account, mName as companion FROM common.gmlist", account.c_str());
#endif
	
	m_set_loginAccount.insert(account);
}


#ifdef ENABLE_MESSENGER_TEAM
void MessengerManager::LoadTeamList(SQLMsg * msg)
{
	if (NULL == msg or NULL == msg->Get() or msg->Get()->uiNumRows == 0)
		return;
	
	std::string account;

	for (uint i = 0; i < msg->Get()->uiNumRows; ++i)
	{
		MYSQL_ROW row = mysql_fetch_row(msg->Get()->pSQLResult);

		if (row[0] && row[1])
		{
			if (account.length() == 0)
				account = row[0];

			m_TeamRelation[row[0]].insert(row[1]);
			m_InverseTeamRelation[row[1]].insert(row[0]);
		}
	}

	SendTeamList(account);

	std::set<MessengerManager::keyT>::iterator it;

	for (it = m_InverseTeamRelation[account].begin(); it != m_InverseTeamRelation[account].end(); ++it)
		SendTeamLogin(*it, account);
}

void MessengerManager::SendTeamList(MessengerManager::keyA account)
{
	LPCHARACTER ch = CHARACTER_MANAGER::instance().FindPC(account.c_str());

	if (!ch)
		return;

	LPDESC d = ch->GetDesc();

	if (!d)
		return;

	TPacketGCMessenger pack;

	pack.header		= HEADER_GC_MESSENGER;
	pack.subheader	= MESSENGER_SUBHEADER_GC_TEAM_LIST;
	pack.size		= sizeof(TPacketGCMessenger);

	TPacketGCMessengerTeamListOffline pack_offline;
	TPacketGCMessengerTeamListOnline pack_online;

	TEMP_BUFFER buf(128 * 1024);

	itertype(m_TeamRelation[account]) it = m_TeamRelation[account].begin(), eit = m_TeamRelation[account].end();

	while (it != eit)
	{
		if (m_set_loginAccount.find(*it) != m_set_loginAccount.end())
		{
			pack_online.connected = 1;

			pack_online.length = it->size();

			buf.write(&pack_online, sizeof(TPacketGCMessengerTeamListOnline));
			buf.write(it->c_str(), it->size());
		}
		else
		{
			pack_offline.connected = 0;

			pack_offline.length = it->size();

			buf.write(&pack_offline, sizeof(TPacketGCMessengerTeamListOffline));
			buf.write(it->c_str(), it->size());
		}

		++it;
	}

	pack.size += buf.size();

	d->BufferedPacket(&pack, sizeof(TPacketGCMessenger));
	d->Packet(buf.read_peek(), buf.size());
}

void MessengerManager::SendTeamLogin(MessengerManager::keyA account, MessengerManager::keyA companion)
{
	LPCHARACTER ch = CHARACTER_MANAGER::instance().FindPC(account.c_str());
	LPDESC d = ch ? ch->GetDesc() : NULL;

	if (!d)
		return;

	if (!d->GetCharacter())
		return;

	BYTE bLen = companion.size();

	TPacketGCMessenger pack;

	pack.header			= HEADER_GC_MESSENGER;
	pack.subheader		= MESSENGER_SUBHEADER_GC_TEAM_LOGIN;
	pack.size			= sizeof(TPacketGCMessenger) + sizeof(BYTE) + bLen;

	d->BufferedPacket(&pack, sizeof(TPacketGCMessenger));
	d->BufferedPacket(&bLen, sizeof(BYTE));
	d->Packet(companion.c_str(), companion.size());
}

void MessengerManager::SendTeamLogout(MessengerManager::keyA account, MessengerManager::keyA companion)
{
	if (!companion.size())
		return;

	LPCHARACTER ch = CHARACTER_MANAGER::instance().FindPC(account.c_str());
	LPDESC d = ch ? ch->GetDesc() : NULL;

	if (!d)
		return;

	BYTE bLen = companion.size();

	TPacketGCMessenger pack;

	pack.header		= HEADER_GC_MESSENGER;
	pack.subheader	= MESSENGER_SUBHEADER_GC_TEAM_LOGOUT;
	pack.size		= sizeof(TPacketGCMessenger) + sizeof(BYTE) + bLen;

	d->BufferedPacket(&pack, sizeof(TPacketGCMessenger));
	d->BufferedPacket(&bLen, sizeof(BYTE));
	d->Packet(companion.c_str(), companion.size());
}
#endif
      
      
void MessengerManager::Logout(MessengerManager::keyA account)
{
	if (m_set_loginAccount.find(account) == m_set_loginAccount.end())
		return;

	m_set_loginAccount.erase(account);

	std::set<MessengerManager::keyT>::iterator it;

	for (it = m_InverseRelation[account].begin(); it != m_InverseRelation[account].end(); ++it)
	{
		SendLogout(*it, account);
	}

	std::map<keyT, std::set<keyT> >::iterator it2 = m_Relation.begin();

	while (it2 != m_Relation.end())
	{
		it2->second.erase(account);
		++it2;
	}

#ifdef ENABLE_MESSENGER_TEAM
	std::set<MessengerManager::keyT>::iterator it5;
	
	for (it5 = m_InverseTeamRelation[account].begin(); it5 != m_InverseTeamRelation[account].end(); ++it5)
	{
		SendTeamLogout(*it5, account);
	}

	std::map<keyT, std::set<keyT> >::iterator it6 = m_TeamRelation.begin();

	while (it6 != m_TeamRelation.end())
	{
		it6->second.erase(account);
		++it6;
	}
	m_TeamRelation.erase(account);
#endif

	m_Relation.erase(account);
	//m_map_stMobile.erase(account);
}

 

Link to comment
15 minutos atrás, Marcos disse:

Boa tarde pessoal...

Eu implementei o sistema de equipe online pela source, não meu deu qualquer erro, tanto no game como no binário.

Mais quando eu logo acontece o seguinte:

1-) Quando logo tanto a conta de GM, ou player a lista fica vazia.

2-) Quando eu teleporto um char player, o mesmo aparece na lista da Staff como se ele fosse um GM.

Obs, não há qualquer syserr tanto no game quanto no cliente, ambos estão limpos.

Alguém q tenha o sistema sabe o q pode ser?

Boa tarde a todos, e obrigado pela atenção...


Deixa o tut aqui, pode ser útil para alguém 

Link to comment
1 hora atrás, Mário. disse:

messenger_manager.cpp:


void MessengerManager::Login(MessengerManager::keyA account)
{
	if (m_set_loginAccount.find(account) != m_set_loginAccount.end())
		return;

	DBManager::instance().FuncQuery(std::bind1st(std::mem_fun(&MessengerManager::LoadList), this),
			"SELECT account, companion FROM messenger_list%s WHERE account='%s'", get_table_postfix(), __account);

#ifdef ENABLE_MESSENGER_TEAM
	DBManager::instance().FuncQuery(std::bind1st(std::mem_fun(&MessengerManager::LoadTeamList), this),
			"SELECT '%s' as account, mName as companion FROM common.gmlist", account.c_str());
#endif
	
	m_set_loginAccount.insert(account);
}


#ifdef ENABLE_MESSENGER_TEAM
void MessengerManager::LoadTeamList(SQLMsg * msg)
{
	if (NULL == msg or NULL == msg->Get() or msg->Get()->uiNumRows == 0)
		return;
	
	std::string account;

	for (uint i = 0; i < msg->Get()->uiNumRows; ++i)
	{
		MYSQL_ROW row = mysql_fetch_row(msg->Get()->pSQLResult);

		if (row[0] && row[1])
		{
			if (account.length() == 0)
				account = row[0];

			m_TeamRelation[row[0]].insert(row[1]);
			m_InverseTeamRelation[row[1]].insert(row[0]);
		}
	}

	SendTeamList(account);

	std::set<MessengerManager::keyT>::iterator it;

	for (it = m_InverseTeamRelation[account].begin(); it != m_InverseTeamRelation[account].end(); ++it)
		SendTeamLogin(*it, account);
}

void MessengerManager::SendTeamList(MessengerManager::keyA account)
{
	LPCHARACTER ch = CHARACTER_MANAGER::instance().FindPC(account.c_str());

	if (!ch)
		return;

	LPDESC d = ch->GetDesc();

	if (!d)
		return;

	TPacketGCMessenger pack;

	pack.header		= HEADER_GC_MESSENGER;
	pack.subheader	= MESSENGER_SUBHEADER_GC_TEAM_LIST;
	pack.size		= sizeof(TPacketGCMessenger);

	TPacketGCMessengerTeamListOffline pack_offline;
	TPacketGCMessengerTeamListOnline pack_online;

	TEMP_BUFFER buf(128 * 1024);

	itertype(m_TeamRelation[account]) it = m_TeamRelation[account].begin(), eit = m_TeamRelation[account].end();

	while (it != eit)
	{
		if (m_set_loginAccount.find(*it) != m_set_loginAccount.end())
		{
			pack_online.connected = 1;

			pack_online.length = it->size();

			buf.write(&pack_online, sizeof(TPacketGCMessengerTeamListOnline));
			buf.write(it->c_str(), it->size());
		}
		else
		{
			pack_offline.connected = 0;

			pack_offline.length = it->size();

			buf.write(&pack_offline, sizeof(TPacketGCMessengerTeamListOffline));
			buf.write(it->c_str(), it->size());
		}

		++it;
	}

	pack.size += buf.size();

	d->BufferedPacket(&pack, sizeof(TPacketGCMessenger));
	d->Packet(buf.read_peek(), buf.size());
}

void MessengerManager::SendTeamLogin(MessengerManager::keyA account, MessengerManager::keyA companion)
{
	LPCHARACTER ch = CHARACTER_MANAGER::instance().FindPC(account.c_str());
	LPDESC d = ch ? ch->GetDesc() : NULL;

	if (!d)
		return;

	if (!d->GetCharacter())
		return;

	BYTE bLen = companion.size();

	TPacketGCMessenger pack;

	pack.header			= HEADER_GC_MESSENGER;
	pack.subheader		= MESSENGER_SUBHEADER_GC_TEAM_LOGIN;
	pack.size			= sizeof(TPacketGCMessenger) + sizeof(BYTE) + bLen;

	d->BufferedPacket(&pack, sizeof(TPacketGCMessenger));
	d->BufferedPacket(&bLen, sizeof(BYTE));
	d->Packet(companion.c_str(), companion.size());
}

void MessengerManager::SendTeamLogout(MessengerManager::keyA account, MessengerManager::keyA companion)
{
	if (!companion.size())
		return;

	LPCHARACTER ch = CHARACTER_MANAGER::instance().FindPC(account.c_str());
	LPDESC d = ch ? ch->GetDesc() : NULL;

	if (!d)
		return;

	BYTE bLen = companion.size();

	TPacketGCMessenger pack;

	pack.header		= HEADER_GC_MESSENGER;
	pack.subheader	= MESSENGER_SUBHEADER_GC_TEAM_LOGOUT;
	pack.size		= sizeof(TPacketGCMessenger) + sizeof(BYTE) + bLen;

	d->BufferedPacket(&pack, sizeof(TPacketGCMessenger));
	d->BufferedPacket(&bLen, sizeof(BYTE));
	d->Packet(companion.c_str(), companion.size());
}
#endif
      
      
void MessengerManager::Logout(MessengerManager::keyA account)
{
	if (m_set_loginAccount.find(account) == m_set_loginAccount.end())
		return;

	m_set_loginAccount.erase(account);

	std::set<MessengerManager::keyT>::iterator it;

	for (it = m_InverseRelation[account].begin(); it != m_InverseRelation[account].end(); ++it)
	{
		SendLogout(*it, account);
	}

	std::map<keyT, std::set<keyT> >::iterator it2 = m_Relation.begin();

	while (it2 != m_Relation.end())
	{
		it2->second.erase(account);
		++it2;
	}

#ifdef ENABLE_MESSENGER_TEAM
	std::set<MessengerManager::keyT>::iterator it5;
	
	for (it5 = m_InverseTeamRelation[account].begin(); it5 != m_InverseTeamRelation[account].end(); ++it5)
	{
		SendTeamLogout(*it5, account);
	}

	std::map<keyT, std::set<keyT> >::iterator it6 = m_TeamRelation.begin();

	while (it6 != m_TeamRelation.end())
	{
		it6->second.erase(account);
		++it6;
	}
	m_TeamRelation.erase(account);
#endif

	m_Relation.erase(account);
	//m_map_stMobile.erase(account);
}

 

Funcionando 100%

Obrigado @Mário.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...