Jump to content

Metin2 Socket API - P2P


Recommended Posts

  • Bronze

M2 Download Center

This is the hidden content, please
( 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

 

  • Metin2 Dev 5
  • Eyes 1
  • Good 4
  • Love 10

No advertising in signatures

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

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.