<?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) 2002 - 2017 Nick Jones
| http://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: ajax.php
| Author: Virel (virel.eu)
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
require_once "../../../maincore.php";
include_once INFUSIONS . "virel_servers_status/includes/functions.php";


if((isset($_GET['ajax']) && $_GET['ajax'] == "checkServerConnection") && isset($_GET['type']) && isset($_GET['port']) && isset($_GET['ip'])) {
    
	if((!empty($_GET['ip'])) && (!empty($_GET['port']))) {
			
			$server_type = $_GET['type'];
			$server_ip = $_GET['ip'];
			$server_port = $_GET['port'];
			
			$servers =  array(
				array(
					'type'    => $server_type, 
					'host'    => $server_ip.':'.$server_port
				)	
			);
			

			$GameQ = new \GameQ\GameQ(); 
			$GameQ->addServers($servers);
			$GameQ->setOption('timeout', 5);

			$results = $GameQ->process();
			$server = $results[$server_ip.':'.$server_port];

			if($server) {
			echo "good";
				
			} else {
			echo "error2";
			}
			
	} else {
		echo "error1";
	}
			
}

?>