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); }
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