Jump to content

[C++] Hardware ban (mac address)


tierrilopes

Recommended Posts

Go to file root/intrologin.py

Look for:

"WRONGPWD"	: localeInfo.LOGIN_FAILURE_WRONG_PASSWORD,

Add this bellow:

"HWBANNED"	: "Login from this computer has been blocked",

 

Client source

Go to UserInterface/AccountConnector.cpp

Look for:

bool CAccountConnector::__AuthState_RecvEmpty()
{
	BYTE byEmpty;
	Recv (sizeof (BYTE), &byEmpty);
	return true;
}

Add this bellow:

//hardware ban revised
#include <intrin.h>
#include <Iphlpapi.h>
#pragma comment(lib, "iphlpapi.lib")
const char* GetMacAddress() {
	PIP_ADAPTER_INFO AdapterInfo;
	DWORD dwBufLen = sizeof(AdapterInfo);
	char *mac_addr = (char*)malloc(17);

	AdapterInfo = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO));
	if (!AdapterInfo) {
		return "";
	}
	if (GetAdaptersInfo(AdapterInfo, &dwBufLen) == ERROR_BUFFER_OVERFLOW) {

		AdapterInfo = (IP_ADAPTER_INFO *)malloc(dwBufLen);
		if (!AdapterInfo) {
			return "";
		}
	}

	CHAR _MACFORMAT[] = { '%', '0', '2', 'X', ':', '%', '0', '2', 'X', ':', '%', '0', '2', 'X', ':', '%', '0', '2', 'X', ':', '%', '0', '2', 'X', ':', '%', '0', '2', 'X', 0x0 }; //"%02X:%02X:%02X:%02X:%02X:%02X"
	if (GetAdaptersInfo(AdapterInfo, &dwBufLen) == NO_ERROR) {
		PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;
		do {
			sprintf(mac_addr, _MACFORMAT,
				pAdapterInfo->Address[0], pAdapterInfo->Address[1],
				pAdapterInfo->Address[2], pAdapterInfo->Address[3],
				pAdapterInfo->Address[4], pAdapterInfo->Address[5]);
			return mac_addr;

			pAdapterInfo = pAdapterInfo->Next;
		} while (pAdapterInfo);
	}
	free(AdapterInfo);
	return NULL;
}
//hardware ban revised

Inside:

bool CAccountConnector::__AuthState_RecvPhase()

Look for:

		strncpy (LoginPacket.name, m_strID.c_str(), ID_MAX_NUM);
		strncpy (LoginPacket.pwd, m_strPassword.c_str(), PASS_MAX_NUM);

Add this bellow:

		//hardware ban revised
		strncpy(LoginPacket.cHWInfo, GetMacAddress(), sizeof(LoginPacket.cHWInfo) - 1);
		//hardware ban revised

 

Look for:

		LoginPacket.name[ID_MAX_NUM] = '\0';
		LoginPacket.pwd[PASS_MAX_NUM] = '\0';

Add this bellow:

		//hardware ban revised
		LoginPacket.cHWInfo[255] = '\0';
		//hardware ban revised

 

Go to file UserInterface/Packet.h

Look for:

typedef struct command_login3 {
	BYTE	header;
	char	name[ID_MAX_NUM + 1];
	char	pwd[PASS_MAX_NUM + 1];
	DWORD	adwClientKey[4];
} TPacketCGLogin3;

Replace with:

typedef struct command_login3 {
	BYTE	header;
	char	name[ID_MAX_NUM + 1];
	char	pwd[PASS_MAX_NUM + 1];
	DWORD	adwClientKey[4];
	char	cHWInfo[255 + 1]; //hardware ban revised
} TPacketCGLogin3;

 

Game source

Go to file game/Packet.h

Look for:

typedef struct command_login3
{
	BYTE	header;
	char	login[LOGIN_MAX_LEN + 1];
	char	passwd[PASSWD_MAX_LEN + 1];
	DWORD	adwClientKey[4];
} TPacketCGLogin3;

Replace with:

typedef struct command_login3
{
	BYTE	header;
	char	login[LOGIN_MAX_LEN + 1];
	char	passwd[PASSWD_MAX_LEN + 1];
	DWORD	adwClientKey[4];
	char	cHWInfo[255 + 1]; // hardware ban revised
} TPacketCGLogin3;

 

Go to file game/input_auth.cpp

Look for:

	if (false == FN_IS_VALID_LOGIN_STRING (login)) {
		sys_log (0, "InputAuth::Login : IS_NOT_VALID_LOGIN_STRING(%s) desc %p",
				 login, get_pointer (d));
		LoginFailure (d, "NOID");
		return;
	}

Add this bellow:

	//hardware ban revised
	char query[1024];
	snprintf(query, sizeof(query),"SELECT hwid FROM account.hwid_ban WHERE hwid = '%s'", pinfo->cHWInfo);
	std::auto_ptr<SQLMsg> execquery(DBManager::instance().DirectQuery(query));
	
	if (execquery->Get()->uiNumRows >= 1)
	{
		LoginFailure(d, "HWBANNED");
		return;		
	}
	//hardware ban revised

 

Go to file game/db.cpp

Look for:

						char szQuery[1024];
						snprintf (szQuery, sizeof (szQuery), "UPDATE account SET last_play=NOW() WHERE id=%u", dwID);
						std::auto_ptr<SQLMsg> msg (DBManager::instance().DirectQuery (szQuery));

Add this bellow:

						//hardware ban revised
						char szHwid[255 * 2 + 1];
						DBManager::instance().EscapeString(szHwid, sizeof(szHwid), pinfo->cHWInfo, strlen(pinfo->cHWInfo));
						char szQuery2[1024];
						snprintf (szQuery2, sizeof (szQuery2), "UPDATE account SET hwid='%s' WHERE id=%u", szHwid, dwID); //Updates hwid of the account
						std::auto_ptr<SQLMsg> msg2 (DBManager::instance().DirectQuery (szQuery2));
						//hardware ban revised

 

Run this queries inside account database:

DROP TABLE IF EXISTS `hwid_ban`;
CREATE TABLE `hwid_ban` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `hwid` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
ALTER TABLE `account` ADD COLUMN `hwid` text DEFAULT NULL;

 

  • Like 4
Link to comment

Jogador ao fazer login, irá aparecer na sua conta (account.account), na tabela hwid o endereço mac da placa de rede com que entrou.

Ao adicionar esse valor à lista em account.hwid_ban, o jogador não conseguirá fazer login

 

@Darkness ban permanece mesmo aquando de mudança de ip, no entanto sim, é possível modificar endereço mac sem muita dificuldade

 

O que aconselho é utilizar como base para criarem o vosso próprio método de identificar o computador. Para tal basta criarem uma função nova e substituir onde está a ser chamada a GetMacAddress() pela vossa

Link to comment
  • 3 months later...
  • 1 month later...
  • 2 weeks later...
  • 2 years later...
  • 1 year later...

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...