Jump to content

Function - Same IP Detection


Recommended Posts

  • Premium
Spoiler

170421x1.PNG.9f6e1b44c3fce295b6d5ffc8293

It's static because i need to use only one time fastly. If you need to detect same ip on PvP things or else it's good for you.

 

if (!pkKiller || !pkVictim)
    return; //Null ptr prevent, the bool will check the desc.

if (IsSameIp(pkKiller, pkVictim))
    return; //Same ip detected

 

Regards WeedHex

  • Metin2 Dev 1
  • Love 4
Link to comment
Share on other sites

  • Bronze
Vegas quest functions

Server/quest_functions:

pc.get_ip
npc.get_ip



Src/game/questlua_pc.cpp
 

int pc_get_ip(lua_State* L)
    {
        LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
        if(!ch) return 0;
        lua_pushstring(L, ch->GetDesc()->GetHostName());
        return 1;
    }

    { "get_ip",                pc_get_ip                            },



Src/game/questlua_npc.cpp
 

int npc_get_ip(lua_State* L)
    {
        LPCHARACTER npc = CQuestManager::instance().GetCurrentNPCCharacterPtr();
        if (npc && npc->IsPC())
            lua_pushstring(L, npc->GetDesc()->GetHostName());
        else
            lua_pushstring(L, "");
        return 1;
    }

    { "get_ip",                        npc_get_ip                        },


 

#include "desc.h"
Link to comment
Share on other sites

  • Forum Moderator

Good idea, but you should return false if GetDesc is nullptr, not true.

static const bool __FN_check_ip_ptr(const LPCHARACTER pkChr, const LPCHARACTER pkTargetChr)
{
	if (!pkChr || !pkTargetChr)
		return false;
	
	const LPDESC pkDesc = pkChr->GetDesc();
	const LPDESC pkTargetDesc = pkTargetChr->GetDesc();
	if (!pkDesc || !pkTargetDesc)
		return false;
	
	const std::string & stIPAddress1 = pkDesc->GetHostName();
	const std::string & stIPAddress2 = pkTargetDesc->GetHostName();
	return (!stIPAddress1.compare(stIPAddress2));
}

static const bool __FN_check_ip_str(const std::string & stIPAddress1, const std::string & stIPAddress2)
{
	return (!stIPAddress1.compare(stIPAddress2));
}

// const bool bIsSameIP = __FN_check_ip_ptr(ch, tch);
// const bool bIsSameIP = __FN_check_ip_str(row[0], row[1]);

It's a little bit useless if two guys play metin2 from same network connection, as @Chyu ^^ said.
We can use HWID (Hardware Identification) for this detection, much better.

  • Love 5
Link to comment
Share on other sites

  • Honorable Member

moved to: 

This is the hidden content, please

Added somewhere (even .h)

inline bool ch_compare_ip(LPCHARACTER ch1, LPCHARACTER ch2)
{
	if (!ch1 || !ch2 || !ch1->GetDesc() || !ch2->GetDesc())
		return false;
	const std::string ip1 = ch1->GetDesc()->GetHostName();
	const std::string ip2 = ch2->GetDesc()->GetHostName();
	return (ip1.compare(ip2) == 0);
}

or if added in char.h inside CHARACTER:

inline bool CHARACTER::CompareIP(LPCHARACTER ch2)
{
	if (!ch2 || !this->GetDesc() || !ch2->GetDesc())
		return false;
	const std::string ip1 = this->GetDesc()->GetHostName();
	const std::string ip2 = ch2->GetDesc()->GetHostName();
	return (ip1.compare(ip2) == 0);
}

 

Edited by martysama0134
  • Metin2 Dev 5
  • Good 4
  • Love 10
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.