Register for your free account! | Forgot your password?

You last visited: Today at 21:30

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[HowTo] Metin2 Web API

Discussion on [HowTo] Metin2 Web API within the Metin2 PServer Guides & Strategies forum part of the Metin2 Private Server category.

Reply
 
Old 11/24/2013, 16:39   #31
 
elite*gold: 0
Join Date: Oct 2012
Posts: 111
Received Thanks: 1
yes, this workperfect
xworldx is offline  
Old 01/01/2014, 01:13   #32
 
elite*gold: 0
Join Date: Oct 2009
Posts: 382
Received Thanks: 161
Quote:
Originally Posted by ProfDrKnowsItAll View Post
I like wrappers that's my thing

Here a complete working example:
PHP Code:
<?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$port5))
            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.162.0.1";
    
$port 13000;
    
$api = new GameConnector($host$port);
    
$api->Send("MyApiKeyIsSecureLol");
    
$api->Send("USER_COUNT");
    
//$api->Send("IS_SERVER_UP");
    
$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;
Changes:
Added packet header to send function, at the moment we don't want to send other packets.
Fixed various bugs
Changed substr <- Thanks to Mashkin
Added user count formatting
Added check for no custom response
i tried it but i have a problem

WEBADMIN : Wrong Connector : 159.253.38.253

what is the problem?
vpser is offline  
Old 01/01/2014, 01:28   #33
 
Mashkin's Avatar
 
elite*gold: 44
Join Date: May 2010
Posts: 2,053
Received Thanks: 1,747
Quote:
Originally Posted by vpser View Post
i tried it but i have a problem

WEBADMIN : Wrong Connector : 159.253.38.253

what is the problem?
Addthis IP (159....) in your game cores' CONFIG files with this directive.
Code:
adminpage_ip: 159.253.38.253
Mashkin is offline  
Thanks
1 User
Old 02/09/2014, 03:40   #34
 
Gl0bal's Avatar
 
elite*gold: 8
Join Date: Oct 2010
Posts: 564
Received Thanks: 906
Sry bros. I tried everything, but "IS_SERVER_UP" isn't working for me.
Can somebody give me an example how to use it. Most of the other commands work for me.

Regards
Gl0bal is offline  
Old 03/27/2015, 00:33   #35
 
elite*gold: 0
Join Date: Aug 2012
Posts: 11
Received Thanks: 1
can someone tell me how to use the dc command?
qualitygaming17 is offline  
Old 10/10/2024, 00:09   #36
 
elite*gold: 0
Join Date: Sep 2024
Posts: 2
Received Thanks: 0
Quote:
Originally Posted by vpser View Post
i tried it but i have a problem

WEBADMIN : Wrong Connector : 159.253.38.253

what is the problem?
I am trying to use the same code but I don't understand why it shows 0 users online instead of 1 for example when I am logged in

Changed adminpage_ip1 on Auth , port 30001


Total[0] 0 / 0 / 0 (this server 0)

Solveddd Instead of Auth I needed to use the CH port and edit adminpage_ip1 to config CH
(if anybody needs )

*I think I will need to do the same for CH2 and thing if show them separated or togheter
Viverealisbona is offline  
Old 10/22/2024, 23:34   #37
 
elite*gold: 0
Join Date: Sep 2024
Posts: 2
Received Thanks: 0
Quote:
Originally Posted by ProfDrKnowsItAll View Post
I like wrappers that's my thing

Here a complete working example:
PHP Code:
<?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$port5))
            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.162.0.1";
    
$port 13000;
    
$api = new GameConnector($host$port);
    
$api->Send("MyApiKeyIsSecureLol");
    
$api->Send("USER_COUNT");
    
//$api->Send("IS_SERVER_UP");
    
$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;
Changes:
Added packet header to send function, at the moment we don't want to send other packets.
Fixed various bugs
Changed substr <- Thanks to Mashkin
Added user count formatting
Added check for no custom response
I tried it and I have adapted it for both my channel thank you. I have added the same on my domain but it doensn't work. It seems that the packet are not sended, any solution? thank you in advance
Viverealisbona is offline  
Reply




All times are GMT +1. The time now is 21:30.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.