Файл: _rootinc/gamecp.inc.php
Строк: 180
<?
class GameCP
{
public $url = null;
public $password = null;
public $error = null;
public function init($url,$password) {
$this->url=$url;
$this->password=$password;
}
public function send($postfields) {
$postfields["passphrase"] = $this->password;
$fp = curl_init();
curl_setopt($fp, CURLOPT_URL, $this->url."/billing/mb/index.php");
curl_setopt($fp, CURLOPT_POST, 1);
curl_setopt($fp, CURLOPT_TIMEOUT, 20);
curl_setopt($fp, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($fp, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($fp, CURLOPT_HEADER, 0);
curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($fp, CURLOPT_POSTFIELDS, $postfields);
$result = curl_exec($fp);
if (@curl_errno($fp)) {
$this->error = "cURL Error ".@curl_errno($fp).": ".@curl_error($fp);
return false;
}
curl_close($fp);
return $result;
}
public function createClient($username,$password,$email,$gameid,$slots) {
$postfields["action"] = "create";
$postfields["function"] = "createacct";
$postfields["username"] = $username;
$postfields["password"] = $password;
$postfields["emailaddr"] = $email;
$postfields["game_id"] = $gameid;
if ($slots) { $postfields["max_players"] = $slots; }
$result = $this->send($postfields);
if (preg_match("/Command Execution Result: Ok/iu", strip_tags($result))) {
if (preg_match("/uid:(d+):(d+):/iu",$result,$arr)) {
$resultArray[uid] = $arr[1];
$resultArray[gid] = $arr[2];
return $resultArray;
} else {
$this->error = "createClient: Account created but unable to get UID and GID. Do this manually.";
return false;
}
} else if (preg_match("/Unable to determine IP address/iu", strip_tags($result))) {
$this->error = "createClient: GameCP was unable to select an ip address for this server. Please check your machines slot and user quota.";
return false;
} else if (preg_match("/Passed Security Checks: Failed/iu", strip_tags($result))) {
$this->error = "createClient: Your GameCP passphrase is incorrect. Check your settings.";
return false;
} else {
$this->error = "createClient: unknown error";
return false;
}
}
public function suspendClient($customerid,$packageid) {
$postfields["action"] = "suspend";
$postfields["idtype"] = "direct";
$postfields["customerid"] = $customerid;
$postfields["packageid"] = $packageid;
$result = $this->send($postfields);
if (preg_match("/Command Execution Result: Ok/iu", strip_tags($result))) {
return true;
} else if (preg_match("/Passed Security Checks: Failed/iu", strip_tags($result))) {
$this->error = "suspendClient: Your GameCP passphrase is incorrect. Check your settings.";
return false;
} else if (preg_match("/You do not have the correct permission to access this location from (.+)/iu", $result, $arr)) {
$this->error = "suspendClient: $arr[1] do not have the correct permission to access API.";
} else {
$this->error = "suspendClient: unknown error";
return false;
}
}
public function unSuspendClient($customerid,$packageid) {
$postfields["action"] = "unsuspend";
$postfields["idtype"] = "direct";
$postfields["customerid"] = $customerid;
$postfields["packageid"] = $packageid;
$result = $this->send($postfields);
if (preg_match("/Command Execution Result: Ok/iu", strip_tags($result))) {
return true;
} else if (preg_match("/Passed Security Checks: Failed/iu", strip_tags($result))) {
$this->error = "unSuspendClient: Your GameCP passphrase is incorrect. Check your settings.";
return false;
} else if (preg_match("/You do not have the correct permission to access this location from (.+)/iu", $result, $arr)) {
$this->error = "unSuspendClient: $arr[1] do not have the correct permission to access API.";
} else {
$this->error = "unSuspendClient: unknown error";
return false;
}
}
public function deleteClient($customerid,$packageid) {
$postfields["action"] = "delete";
$postfields["idtype"] = "direct";
$postfields["customerid"] = $customerid;
$postfields["packageid"] = $packageid;
$result = $this->send($postfields);
if (preg_match("/Command Execution Result: Ok/iu", strip_tags($result))) {
return true;
} else if (preg_match("/Passed Security Checks: Failed/iu", strip_tags($result))) {
$this->error = "deleteClient: Your GameCP passphrase is incorrect. Check your settings.";
return false;
} else if (preg_match("/You do not have the correct permission to access this location from (.+)/iu", $result, $arr)) {
$this->error = "deleteClient: $arr[1] do not have the correct permission to access API.";
} else {
$this->error = "deleteClient: unknown error";
return false;
}
}
public function changePlayers($customerid,$packageid,$slots) {
$postfields["action"] = "changeplayers";
$postfields["idtype"] = "direct";
$postfields["packageid"] = $packageid;
$postfields["max_players"] = $slots;
$result = $this->send($postfields);
if (preg_match("/Command Execution Result: Ok/iu", strip_tags($result))) {
$this->restartGame($customerid,$packageid);
return true;
} else if (preg_match("/Passed Security Checks: Failed/iu", strip_tags($result))) {
$this->error = "changePlayers: Your GameCP passphrase is incorrect. Check your settings.";
return false;
} else if (preg_match("/You do not have the correct permission to access this location from (.+)/iu", $result, $arr)) {
$this->error = "changePlayers: $arr[1] do not have the correct permission to access API.";
} else {
$this->error = "changePlayers: unknown error";
return false;
}
}
public function restartGame($customerid,$packageid) {
$postfields["action"] = "restart";
$postfields["idtype"] = "direct";
$postfields["packageid"] = $packageid;
$postfields["customerid"] = $customerid;
$result = $this->send($postfields);
if (preg_match("/Command Execution Result: Ok/iu", strip_tags($result))) {
return true;
} else if (preg_match("/Passed Security Checks: Failed/iu", strip_tags($result))) {
$this->error = "restartGame: Your GameCP passphrase is incorrect. Check your settings.";
return false;
} else if (preg_match("/You do not have the correct permission to access this location from (.+)/iu", $result, $arr)) {
$this->error = "restartGame: $arr[1] do not have the correct permission to access API.";
} else {
$this->error = "restartGame: unknown error";
return false;
}
}
}
?>