Metin2 [C++] Fix Api Tool / P2P Port Protection

Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

TeoDoR

Well-known member
Joined
Jun 10, 2019
Messages
168
Credits
123
Open common and search service.h
Add:
C++:
Expand Collapse Copy
#define ENABLE_PORT_SECURITY
sVfIOd4.png



Open db/src and search Peerbase.cpp
Search:

C++:
Expand Collapse Copy
bool CPeerBase::Accept(socket_t fd_accept)
{
    struct sockaddr_in peer;

    if ((m_fd = socket_accept(fd_accept, &peer)) == INVALID_SOCKET)
    {
        Destroy();
        return false;
    }

Add bellow:
C++:
Expand Collapse Copy
#ifdef ENABLE_PORT_SECURITY
    if (strcmp(inet_ntoa(peer.sin_addr), "127.0.0.1")) // refuse if remote host != localhost (only the same machine must be able to connect in here)
    {
        sys_log(0, "BLOCK CONNECTION FROM %s", inet_ntoa(peer.sin_addr));
        Destroy();
        return false;
    }
#endif
ZKYxvY1.png



Open game/src and search desc_p2p.cpp

Search:

C++:
Expand Collapse Copy
#include "desc_p2p.h"

Add bellow:
C++:
Expand Collapse Copy
#ifdef ENABLE_PORT_SECURITY
#include "config.h"
#endif
XUjmbdk.png



Search:
C++:
Expand Collapse Copy
m_iMinInputBufferLen = 1024 * 1024;

Add bellow:
C++:
Expand Collapse Copy
#ifdef ENABLE_PORT_SECURITY
    if (strcmp(host, g_szPublicIP)) // refuse if remote host != public ip (only the same machine must be able to connect in here)
    {
        sys_log(0, "SYSTEM: new p2p connection from [%s] to [%s] fd: %d BLOCKED", host, g_szPublicIP, m_sock);
        SetPhase(PHASE_CLOSE);
        return true;
    }
#endif
t1G5lPL.png



Open input.cpp
Search:

C++:
Expand Collapse Copy
int CInputHandshake::Analyze(LPDESC d, BYTE bHeader, const char * c_pData)
{
    if (bHeader == 10) // ??? ??
        return 0;

    if (bHeader == HEADER_CG_TEXT)
    {

Add bellow:
C++:
Expand Collapse Copy
#ifdef ENABLE_PORT_SECURITY
        if (IsEmptyAdminPage() || !IsAdminPage(inet_ntoa(d->GetAddr().sin_addr))) // block if adminpage is not set or if not admin
        {
            sys_log(0, "SOCKET_CMD: BLOCK FROM(%s)", d->GetHostName());
            return -1;
        }
#endif

U4HN7VZ.png
 
Back
Top