Jump to content
Forgot your email address? ×
×
×
  • Create New...

Metin2 Socket API - P2P


Recommended Posts

M2 Download Center

Hidden Content

    Give reaction to this post to see the hidden content.
( Internal )

 

<?php

class SocketConnection {
      
    private $m_socket;
    private $m_recv_buf;
   
    public function __construct()
    {
        $this->m_socket = 0;
        $this->m_recv_buf = "";
    }

    public function Connect($host, $port, $timeout)
    {
        $this->m_socket = fsockopen($host, $port, $errno, $errstr, $timeout);

        if (!$this->m_socket)
        {
            echo(sprintf("%s (%d)<br>\n", $errstr, $errno));
            return false;
        }


        return true;
    }

    public function Recv($len)
    {
        $this->m_recv_buf = fread($this->m_socket, $len);
    }

    public function Send($buf)
    {
        fwrite($this->m_socket, $buf);
    }
   
    public function GetRecvBuf()
    {
        return $this->m_recv_buf;
    }

}

class GameConnector
{
    private $m_socketConnector;

    public function __construct($host, $port)
    {
        $this->m_socketConnector = new SocketConnection;

        if (!$this->m_socketConnector->Connect($host, $port, 5))
            return false;

        $this->m_socketConnector->Recv(32);

        $recvBuf = $this->m_socketConnector->GetRecvBuf();
       
        if (ord($recvBuf[0]) != 253)
        {
            echo("GameConnector does not handle this packet!");
            return false;
        }
    }

    public function Send($str)
    {
        $this->m_socketConnector->Send("@".$str."\n");
        $this->m_socketConnector->Recv(64);
    }

    public function GetBuffer()
    {
        return $this->m_socketConnector->GetRecvBuf();
    }
   
}

$host = "192.168.1.120"; //ip adresi
$port = 13000; // port
$api = new GameConnector($host, $port);
$api->Send("sjefjfhsfjkfs1"); // p2p şifre
$api->Send("NOTICE Web Uzerinden Bildirim Yolla Testi 2"); // Komut
$apiBuf = substr($api->GetBuffer(), 0, -1);

if(empty($apiBuf))
{
    echo "Game did not respond";
    exit;
}

if(is_numeric($apiBuf[0]))
{
    $userCount = explode(" ", $apiBuf);
    echo sprintf("Total[%d] %d / %d / %d (this server %d)", $userCount[0], $userCount[1], $userCount[2], $userCount[3], $userCount[4]);
    exit;
}

if($apiBuf=="UNKNOWN")
    echo "Command send and executed no custom response";
else
    echo $apiBuf;
?>

source

 

  • Love 3

No advertising in signatures

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

Announcements

  • -15% Discount in Metin2 Dev Store (01/10/2021 => 31/12/2021) => Code => 15_PCT_OCT_TO_DEC_2021


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.