Register for your free account! | Forgot your password?

You last visited: Today at 07:33

  • 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   #1
 
elite*gold: 11
Join Date: Nov 2010
Posts: 1,709
Received Thanks: 3,827
[HowTo] Metin2 Web API

Hello,

Since I have seen that many servers are using a mysql query to get an approximation of a player count (last_play on the last 15 minutes???), I am publishing today a PHP function to use the Metin2 web API to fetch real player counts. Sending notices or changing event flags dinamically such as with a cron job is also possible.

You only need to edit the first two variables in the function to suit your server and it will be ready to go. Also, make sure your CONFIGS include the webserver's IP under the ADMINPAGE_IP flag.

Code:
function SendServer($text, $type = "NOTICE", $port = 13000)
{
        // IP and ADMINPAGE_PASSWORD of your Metin2 server
	$addr = ""; $pass = ""; 

	// CREATE
	$socket = socket_create (AF_INET, SOCK_STREAM, SOL_TCP);

	if ($socket < 0)
	{
		echo "\n Invalid socket definition...\n";

		exit;
	}

	$result = socket_connect ($socket, $addr, $port);

	if ($result < 0)
	{
		echo "\n Connection Error. Error : ".socket_strerror($result)."\n";
	}

	if($type == "USER_COUNT") {
		$query = "\x40".$type."\x0A";
	} else {
		$query2 = "\x40".$pass."\x0A";
		$query_size2 = strlen($query2);
		$query_result2 = socket_write($socket, $query2, $query_size2);
		socket_recv($socket, $result2, 256, 0);
		$query = "\x40".$type." ".$text."\x0A";
	}

	$query_size = strlen($query);
	$query_result = socket_write($socket, $query, $query_size);

	if ($query_result < 0)
	{
		echo "ERROR: ".socket_strerror($query_result)."\n";
	}
	else
	{
		$result1 = socket_recv($socket, $result2, 256, 0);


	if ($type == "USER_COUNT")
	{
	    $count = trim($result2);
	    $count = explode(' ', $count);
	    //$count[0] = users on channel online
	    //$count[1] = users in red kingdom online
	    //$count[2] = users in yellow kingdom online
	    //$count[3] = users in blue kingdom online
	    //$count[4] = users on core online
	    return $count;
	}
	else
	{
	    return "$result2\n";
	}  
	}


	// CLOSE
	socket_close($socket);
}
Usage examples:

echo SendServer("Welcome to World of Metin2");

Displays this message as announce (like /n)

echo SendServer(strtolower($login), "DC");

Disconnects the account $login (must be lowercase!)

echo SendServer("","USER_COUNT",13000)

Returns an array containing the player count of the channel listening on this port; [0] total [1] Shinsoo [2] Chunjo [3] Jinno


Here is the complete list of the Web API commands and their parameters, some are pretty obvious while others could be investigated further

IS_SERVER_UP Check Server Online Status
IS_PASSPOD_UP Check Passpod Online Status
USER_COUNT Returns Usercount
PACKET_INFO Checks if packet_info.txt exists
PROFILE Opens profile.txt
NOTICE %s Send Notice (notice)
CLOSE_PASSPOD Close Passpod
OPEN_PASSPOD Open Passpod
SHUTDOWN Shutdown Server
SHUTDOWN_ONLY Shutdown Server
RELOAD_CRC Reloads Server CRC List
CHECK_CLIENT_VERSION Check Client Version
RELOAD Reload dbcache Server (GM authorities, GM IPs and more)
EVENT %s %d Change Eventflags (flagname, value)
BLOCK_CHAT %s % Blocks the Chat of a Player (playername, duration)
PRIV_EMPIRE %d %d %d %d Enable Empire-Bonus (empire, type, value, duration)
BLOCK_EXCEPTION ?
SIEGE Start the Siege War


That's all, with this API you can dinamically change eventflags from your website, for example activating night mode with a cron job, and get real playercounts. Note that most of the commands will return UNKNOWN - that's normal and doesn't mean that the command failed.

Thanks to nico_w for the Web API code, and tim for the command list, without whom I wouldn't have learned to use this either
.Shōgun is offline  
Thanks
52 Users
Old 11/01/2013, 05:39   #2
 
elite*gold: 260
Join Date: Jan 2013
Posts: 178
Received Thanks: 104
Perfect release

glad to be the first
Metin2 Team is offline  
Old 11/01/2013, 08:02   #3

 
.MaisKolben™'s Avatar
 
elite*gold: 24
Join Date: May 2009
Posts: 1,165
Received Thanks: 1,222
Thank you for share Uncorrupted.

Kind regards
.MaisKolben™ is offline  
Thanks
1 User
Old 11/01/2013, 08:19   #4
 
elite*gold: 0
Join Date: Oct 2012
Posts: 111
Received Thanks: 1
hi, I have problem with user count.
i Try SendServer("","USER_COUNT","myport") but $count[0] is empty. can you help me, how print number of all players ?
(it show only unknown)
xworldx is offline  
Old 11/01/2013, 14:09   #5
 
elite*gold: 0
Join Date: Sep 2013
Posts: 491
Received Thanks: 675
Does this includes every core?
.Kibito is offline  
Old 11/01/2013, 15:15   #6
 
elite*gold: 11
Join Date: Nov 2010
Posts: 1,709
Received Thanks: 3,827
Quote:
Originally Posted by xworldx View Post
hi, I have problem with user count.
i Try SendServer("","USER_COUNT","myport") but $count[0] is empty. can you help me, how print number of all players ?
(it show only unknown)
There was something missing in the function. I have added it now. Please copy it again from #1 and try

Usage example

Code:
$count1 = SendServer("", "USER_COUNT",13000); //CH1
$count2 = SendServer("", "USER_COUNT",13010); //CH2
$count3 = SendServer("", "USER_COUNT",13020); //CH3
$count5 = SendServer("", "USER_COUNT",13099); //CH99

$count['total'] = $count1[0]+$count2[0]+$count3[0]+$count4[0]+$count5[0];
$count['red'] = $count1[1]+$count2[1]+$count3[1]+$count4[1]+$count5[1];
$count['yellow'] = $count1[2]+$count2[2]+$count3[2]+$count4[2]+$count5[2];
$count['blue'] = $count1[3]+$count2[3]+$count3[3]+$count4[3]+$count5[3];

echo "<table><caption>PLAYERCOUNT</caption>";

echo "<tr><th colspan='4' style='text-align: center;'><span style='font-size: 13pt; font-weight: bold;'>".$count['total'];
connectdb("server1","player");
$query=mysql_query("SELECT COUNT(DISTINCT ip) FROM player WHERE DATE(last_play) = DATE(NOW())");
$ontoday=mysql_result($query,0,0);
$query = mysql_query("SELECT COUNT(DISTINCT ip) FROM player WHERE last_play > DATE_SUB(NOW(), INTERVAL 1 DAY)");
$on24 = mysql_result($query,0,0);
echo "</span></th></tr>";
echo "<tr><td class='sub'>Channel</td><td width='80px' class='sub'>Shinsoo</td><td width='80px' class='sub'>Chunjo</td><td class='sub' width='80px'>Jinno</td></tr>";
echo "<tr><td class='sub'>CH1</td><td>".$count1[1]."</td><td>".$count1[2]."</td><td>".$count1[3]."</td></tr>";
echo "<tr><td class='sub'>CH2</td><td>".$count2[1]."</td><td>".$count2[2]."</td><td>".$count2[3]."</td></tr>";
echo "<tr><td class='sub'>CH3</td><td>".$count3[1]."</td><td>".$count3[2]."</td><td>".$count3[3]."</td></tr>";
echo "<tr><td class='sub'>CH99</td><td>".$count5[1]."</td><td>".$count5[2]."</td><td>".$count5[3]."</td></tr>";
echo "<tr><td class='sub'>Total</td><td>".$count['red']."</td><td>".$count['yellow']."</td><td>".$count['blue']."</td></tr>";
echo "<tr><td colspan='2'><b>Unique IPs Today</b> ".$ontoday."</td><td colspan='2'><b>Unique IPs last 24h</b> ".$on24."</td></tr>";
echo "</table><br />";
Result:

.Shōgun is offline  
Thanks
1 User
Old 11/01/2013, 15:27   #7
 
elite*gold: 32
The Black Market: 120/0/1
Join Date: Mar 2012
Posts: 6,717
Received Thanks: 2,737
Wow nice, thank you!!
Syuki is offline  
Old 11/01/2013, 16:51   #8
 
xRaNicky's Avatar
 
elite*gold: 0
Join Date: Nov 2012
Posts: 9
Received Thanks: 0
Very Good ! Thank's !
xRaNicky is offline  
Old 11/03/2013, 22:05   #9
 
elite*gold: 35
Join Date: Jun 2013
Posts: 51
Received Thanks: 8
Gibts nen Download LINK ?


ruß
Raiison™ is offline  
Old 11/03/2013, 23:58   #10
 
elite*gold: 139
Join Date: Sep 2010
Posts: 583
Received Thanks: 545
Quote:
Originally Posted by Raiison™ View Post
Gibts nen Download LINK ?


ruß
AHAHAHHAHAH XDDDD

made my day

Manche Leute puuh^^
.XXShuzZzle is offline  
Thanks
4 Users
Old 11/04/2013, 00:17   #11
 
elite*gold: 0
Join Date: Jan 2010
Posts: 1,916
Received Thanks: 538
Quote:
Originally Posted by Raiison™ View Post
Gibts nen Download LINK ?


ruß
scheiße.....
'oShet is offline  
Old 11/04/2013, 01:13   #12
 
elite*gold: 1
Join Date: Aug 2010
Posts: 579
Received Thanks: 300
Wow nice, thank you!
alpha-Atze is offline  
Thanks
2 Users
Old 11/12/2013, 12:11   #13

 
elite*gold: 1
Join Date: Jan 2009
Posts: 3,037
Received Thanks: 2,361
des api tool von infinity damals hat eigentlich das selbe bewirkt wie dein script hier
NiiceOne is offline  
Old 11/16/2013, 09:30   #14
 
elite*gold: 0
Join Date: Oct 2012
Posts: 3
Received Thanks: 2
I have a little problem using this API.

In fact, the IP Address of the website's server has to be always the same. So you can't use for instance a website which is using shared hosting package. I tried to put a host name in the CONFIG file but it doesn't work.
Furthermore, the sockets module have to be enabled in the configuration of apache/php.
Hystos is offline  
Old 11/16/2013, 14:38   #15


 
Mr. 'Avenue™'s Avatar
 
elite*gold: 222
The Black Market: 101/0/0
Join Date: Oct 2012
Posts: 2,367
Received Thanks: 3,388
echo SendServer("","USER_COUNT",13070)

returns just 'Array' :|
Mr. 'Avenue™ is offline  
Reply




All times are GMT +1. The time now is 07:33.


Powered by vBulletin®
Copyright ©2000 - 2024, 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 ©2024 elitepvpers All Rights Reserved.