Jump to content

Block Duplicate Connection in OX Event


Recommended Posts

On 11/24/2020 at 7:57 PM, Mali61 said:

bool COXEventManager::EnterAttender(LPCHARACTER pkChar)
{
	if (!CheckIpAddress(pkChar))
		return false; // // Will send you to your empire, if you are not GM

	DWORD pid = pkChar->GetPlayerID();
  	m_map_char.insert(std::make_pair(pid, pid));
	m_map_attender.insert(std::make_pair(pid, pid));

	return true;
}

bool COXEventManager::CheckIpAddress(LPCHARACTER ch)
{
	int IPCount = std::count_if(m_map_attender.begin(), m_map_attender.end(), [ch](const decltype(*m_map_attender.begin())& v)
	{
		LPCHARACTER tch = CHARACTER_MANAGER::Instance().FindByPID(v.second);
		if (!tch || !tch->GetDesc())
			return false;
		return !strcmp(ch->GetDesc()->GetHostName(), tch->GetDesc()->GetHostName());
	});

	const int MaxPlayer = 2;
	return !(IPCount >= MaxPlayer);
}

 

 

 

There is a problem :

image.png

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

  • Honorable Member
53 minutes ago, DeYaN. said:

 

 

There is a problem :

image.png

can you try?

bool COXEventManager::CheckIpAddress(LPCHARACTER ch) const
{
	BYTE bIPCount = 0;
	for (MapEventChar::const_iterator it = m_map_attender.begin(); it != m_map_attender.end(); ++it)
	{
		LPCHARACTER tch = CHARACTER_MANAGER::Instance().FindByPID(it->second);
		if (tch && tch->GetDesc() && !strcmp(ch->GetDesc()->GetHostName(), tch->GetDesc()->GetHostName()))
			bIPCount++;
	}

	const BYTE MaxPlayer = 2;
	return (bIPCount < MaxPlayer);
}

I can't open img so I write for old compiler xd sorry

Edited by Metin2 Dev
Core X - External 2 Internal
  • Love 1

 

Link to comment
Share on other sites

  • Developer
49 minutes ago, DeYaN. said:

 

 

There is a problem :

image.png

I think you haven't replaced the 'EnterAttender', remove the old function and use the one  from this tutorial

Edited by Metin2 Dev
Core X - External 2 Internal

r

Link to comment
Share on other sites

@Mali61  Sorry for my late answer, now i'm home.

The new errors ar:

https://metin2.download/picture/Uz97e59Z9Yom27XUO8JBz60cg92746q2/.png

 

@Finnis i have already replace the enterattender function with that postet by Mali . With Ken tut it`s working great.

 

 

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

  • Honorable Member
35 minutes ago, DeYaN. said:

@Mali61  Sorry for my late answer, now i'm home.

The new errors ar:

https://metin2.download/picture/Uz97e59Z9Yom27XUO8JBz60cg92746q2/.png

 

@Finnis i have already replace the enterattender function with that postet by Mali . With Ken tut it`s working great.

 

 

MapEventChar::const_iterator -> std::map<DWORD, DWORD>::const_iterator

sorry I'm using another source

and don't forget to add const keyword to function in header

Edited by Metin2 Dev
Core X - External 2 Internal

 

Link to comment
Share on other sites

37 minutes ago, Mali61 said:

MapEventChar::const_iterator -> std::map<DWORD, DWORD>::const_iterator

sorry I'm using another source

and don't forget to add const keyword to function in header

 

 

I appreciate the answer but I can't handle it .. i`m not a prof in c++

 

https://pastebin.com/AURmYqjs

https://pastebin.com/tP5pGSvy

Link to comment
Share on other sites

  • 4 weeks later...
  • 2 years later...
  • Contributor

If anyone using @ Mali's automatic ox system then we need some edit since he rewrote a lot of things in OX's base code.

OXEvent.cpp

bool COXEventManager::Enter(LPCHARACTER pkChar, std::uint8_t bState)
{
	if ((bState & STATE_ATTENDER) && !CheckIpAddress(pkChar)) // here
		return false; // Will send you to your empire, if you are not GM

	m_common_ox[pkChar->GetPlayerID()] = bState;
	return true;
}
bool COXEventManager::CheckIpAddress(LPCHARACTER ch)
{
	int IPCount = std::count_if(m_common_ox.begin(), m_common_ox.end(), [ch](const decltype(*m_common_ox.begin())& v) -> bool
	{
		LPCHARACTER tch = CHARACTER_MANAGER::Instance().FindByPID(v.first);
		if (!tch || !tch->GetDesc())
			return false;
		return !strcmp(ch->GetDesc()->GetHostName(), tch->GetDesc()->GetHostName()) && (v.second & STATE_ATTENDER);
	});

	const int MaxPlayer = 2;
	return !(IPCount >= MaxPlayer);
}
void COXEventManager::RemoveFromAttenderList(DWORD dwPID)
{
	auto it = m_common_ox.find(dwPID);
	if (it != m_common_ox.end())
	{
		if (it->second & STATE_ATTENDER)
		{
			m_common_ox.erase(it);
		}
	}
}

OXEvent.h (same)

	public:
		bool CheckIpAddress(LPCHARACTER ch);
		void RemoveFromAttenderList(DWORD dwPID);

Char.cpp (same)

#include "OXEvent.h"
	MessengerManager::instance().Logout(GetName());
	
	if (GetMapIndex() == OXEVENT_MAP_INDEX)
		COXEventManager::Instance().RemoveFromAttenderList(GetPlayerID());

Use with caution on live server, I just tested it quickly.

Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.