Používám nejnovější verzi.
1 hráč poslal SMS za 79 kč a toto mu odepsali :
Doručeno
Kód: Vybrat vše
<br /> <b>Warning</b>: unpack(): Type V: not enough input, need 4, have 0 in <b>/data/web/virtuals/62126/virtual/www/vipscript/mobilni-platby.php</b> on l 79Kc
Další posílal za 149 kč a odepsali mu toto :
Čeká na doručení
Kód: Vybrat vše
<br /> <b>Warning</b>: unpack(): Type V: not enough input, need 4, have 0 in <b>/data/web/virtuals/62126/virtual/www/vipscript/mobilni-platby.php</b> on line <b>288</b><br /> <br /> <b>Warning</b>: fread(): Length parameter must be greater than 0 in <b>/data/web/virtuals/62126/virtual/www/vipscript/mobilni-platby.php</b> on line <b>297</b><br /> <br /> <b>Warning</b>: unpack(): Type V: not enough input, need 4, have 0 in <b>/data/web/virtuals/62126/virtual/www/vipscript/mobilni-platby.php</b> on line <b>298</b><br /> Cannot connect to server RCON. Please check your settings.
U této druhé SMS nebyl nejspíše funkční server, neboť je tam psáno, že se nelze připojit na RCON, ale co ta 1 SMS ?
log
V logu nebylo nic napsáno o těchto 2 SMS.
database
Zde taky nic není.
mobilni-platby.php
Nic jsem zde neměnil již půl roku.
Spoiler: zobrazit
Kód: Vybrat vše
<?php
/**
* Název: MobilniPlatby.cz - PHP script pro zaslání RCON příkazů na MineCraft server po odeslání prémiové SMS
* Autor: Mysteria - http://www.mysty.cz
* Verze: 1.0.0-beta2
* Poslední update: 27. 7. 2014
* Více informací & download: http://forum.fakaheda.eu/viewtopic.php?f=85&t=20682#p134652
*/
$settings = (object)[ // Nastavení serverového RCONu
'ip' => '93.91.250.212',
'port' => 26486,
'password' => '*******'
];
$messages = (object)[ // Nastavení chybových SMS zpráv
'sms_bad_price' => 'Litujeme, ale poslali jste SMS za :REALPRICE:Kc misto SMS za :PRICE:Kc.',
'sms_not_found' => 'Litujeme, ale poslali jste SMS, ktera nebyla automaticky rozpoznana. Kontaktujte prosim administratory.'
];
$levels = [ // Nastavení SMS levelů
[
'price' => 10, // Cena SMSky
'text' => 'GVMC VIP :NICK:', // Text SMSky, :NICK: bude nahrazen skutečným nickem uvedeným v SMS, musí být unikátní v rámci všech platebních levelů
'answer' => 'Dekujeme za podporu serveru. VIP ti bude aktivovano ihned !', // Odpověď na správně zaslanou SMS
'commands' => [ // RCON příkazy vykonané po úspěšném zpracování SMSky, :NICK: bude nahrazen skutečným nickem uvedeným v SMS
'pex user :NICK: group set vip'
]
], [
'price' => 30,
'text' => 'GVMC VIPP :NICK:',
'answer' => 'Dekujeme za podporu serveru. VIP+ ti bude aktivovano ihned !',
'commands' => [
'pex user :NICK: group set vip+'
]
], [
'price' => 50,
'text' => 'GVMC EVIP :NICK:',
'answer' => 'Dekujeme za podporu serveru. ExtraVIP ti bude aktivovano ihned !',
'commands' => [
'pex user :NICK: group set evip'
]
], [
'price' => 79,
'text' => 'GVMC UVIP :NICK:',
'answer' => 'Dekujeme za podporu serveru. UltraVIP ti bude aktivovano ihned !',
'commands' => [
'pex user :NICK: group set uvip'
]
], [
'price' => 99,
'text' => 'GVMC SPON :NICK:',
'answer' => 'Dekujeme za podporu serveru. Sponzor ti bude aktivovano ihned !',
'commands' => [
'pex user :NICK: group set sponzor'
]
], [
'price' => 149,
'text' => 'GVMC SSPON :NICK:',
'answer' => 'Dekujeme za podporu serveru. SuperSponzor ti bude aktivovano ihned !',
'commands' => [
'pex user :NICK: group set ssponzor'
]
]
];
/* Do not make any changes below this line if you don't know what are you doing! */
$rcon = new Rcon($settings->ip, $settings->port, $settings->password, 3);
if (!$rcon->connect()) exit('Cannot connect to server RCON. Please check your settings.');
$url = (object)filter_input_array(INPUT_GET);
try {
if (isset($url->shortcode)) {
$url->sms = trim($url->sms);
if (mb_strlen($url->shortcode) === 7) {
$realPrice = (int)substr($url->shortcode, -2, 2);
foreach ($levels as $level) {
$level = (object)$level;
if ($level->price >= 100) continue;
$realNick = explode(' ', $url->sms)[array_search(':NICK:', explode(' ', $level->text))];
if (strtolower($url->sms) === strtolower(str_replace(':NICK:', $realNick, $level->text))) {
if ($realPrice === $level->price) {
foreach ($level->commands as $command) $rcon->send_command(str_replace(':NICK:', $realNick, $command));
File::write('./mobilni-platby.log', date('d. m. Y H:i:s', time()) . " => [SUCCESS] SMS zpráva s obsahem '$url->sms' s cenou {$realPrice}Kč byla úspěšně zpracována." . PHP_EOL);
header('Content-type:text/plain');
header('Content-length:' . mb_strlen($level->answer));
exit($level->answer);
} else {
File::write('./mobilni-platby.log', date('d. m. Y H:i:s', time()) . " => [!ERROR!] SMS zpráva s obsahem '$url->sms' s cenou {$realPrice}Kč nebyla zpracována, protože měla mít cenu {$level->price}Kč." . PHP_EOL);
$answer = str_replace(':PRICE:', $level->price, str_replace(':REALPRICE:', $realPrice, $messages->sms_bad_price));
header('Content-type:text/plain');
header('Content-length:' . mb_strlen($answer));
exit($answer);
}
}
}
File::write('./mobilni-platby.log', date('d. m. Y H:i:s', time()) . " => [!ERROR!] SMS zpráva s obsahem '$url->sms' s cenou {$realPrice}Kč nebyla zpracována, protože nebyla rozpoznána." . PHP_EOL);
header('Content-type:text/plain');
header('Content-length:' . mb_strlen($messages->sms_not_found));
exit($messages->sms_not_found);
} else {
foreach ($levels as $level) {
$level = (object)$level;
if ($level->price <= 99) continue;
$realNick = explode(' ', $url->sms)[array_search(':NICK:', explode(' ', $level->text))];
if (strtolower($url->sms) === strtolower(str_replace(':NICK:', $realNick, $level->text))) {
$file = "./database/$url->id.txt";
$commands = NULL;
foreach ($level->commands as $command) $commands .= str_replace(':NICK:', $realNick, $command) . ';;;';
File::write($file, $commands);
$level->answer .= ";90333$level->price";
File::write('./mobilni-platby.log', date('d. m. Y H:i:s', time()) . " => [SUCCESS] SMS zpráva ID $url->id s obsahem '$url->sms' s cenou {$level->price}Kč byla úspěšně zpracována." . PHP_EOL);
header('Content-type:text/plain');
header('Content-length:' . mb_strlen($level->answer));
exit($level->answer);
}
}
File::write('./mobilni-platby.log', date('d. m. Y H:i:s', time()) . " => [!ERROR!] SMS zpráva ID $url->id s obsahem '$url->sms' s cenou {$level->price}Kč nebyla zpracována, protože nebyla rozpoznána." . PHP_EOL);
header('Content-type:text/plain');
header('Content-length:' . mb_strlen($messages->sms_not_found));
exit("$messages->sms_not_found;FREE90333199");
}
} elseif (isset($url->request)) {
if ($url->status === 'DELIVERED') {
$file = "./database/$url->request.txt";
if (is_array($commands = explode(';;;', File::read($file)))) foreach ($commands as $command) $rcon->send_command($command);
File::remove($file);
File::write('./mobilni-platby.log', date('d. m. Y H:i:s', time()) . " => [SUCCESS] Doručenka SMS zprávy ID $url->request byla úspěšně zpracována." . PHP_EOL);
} else File::write('./mobilni-platby.log', date('d. m. Y H:i:s', time()) . " => [!ERROR!] Doručenka SMS zprávy ID $url->request nebyla zpracována, protože přišla se statusem $url->status ($url->message)." . PHP_EOL);
header('HTTP/1.1 204 No Content');
exit;
}
} catch (\FileException $e) { exit($e->getMessage()); }
class File {
public static function read($source, $mode = 'r') {
if (file_exists($source)) {
if ($file = fopen($source, $mode)) {
if ($content = fread($file, filesize($source))) {
if (fclose($file)) {
return $content;
} else throw new \FileException("Cannot close file $source.");
} else throw new \FileException("Cannot read file $source.");
} else throw new \FileException("Cannot open file $source.");
} else throw new \FileException("Cannot find file $source.");
}
public static function write($destination, $content, $mode = 'a') {
if (!is_dir(dirname($destination))) if (!mkdir(dirname($destination), 0777, TRUE)) throw new \FileException("Cannot create path $destination.");
if ($file = fopen($destination, $mode)) {
if (fwrite($file, $content)) {
if (fclose($file)) {
return TRUE;
} else throw new \FileException("Cannot close file $destination.");
} else throw new \FileException("Cannot write file $destination.");
} else throw new \FileException("Cannot find file $destination.");
}
public static function remove($source) {
if (file_exists($source)) {
if (unlink($source)) {
return TRUE;
} else throw new \FileException("Cannot remove file $source.");
} else throw new \FileException("Cannot find file $source.");
}
}
class FileException extends \Exception { }
class Rcon {
private $host;
private $port;
private $password;
private $timeout;
private $socket;
private $authorized;
private $last_response;
const PACKET_AUTHORIZE = 5;
const PACKET_COMMAND = 6;
const SERVERDATA_AUTH = 3;
const SERVERDATA_AUTH_RESPONSE = 2;
const SERVERDATA_EXECCOMMAND = 2;
const SERVERDATA_RESPONSE_VALUE = 0;
public function __construct($host, $port, $password, $timeout) {
$this->host = $host;
$this->port = $port;
$this->password = $password;
$this->timeout = $timeout;
}
public function get_response() {
return $this->last_response;
}
public function connect() {
$this->socket = fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
if (!$this->socket) {
$this->last_response = $errstr;
return false;
}
//set timeout
stream_set_timeout($this->socket, 3, 0);
//authorize
$auth = $this->authorize();
if ($auth) {
return true;
}
return false;
}
public function disconnect() {
if ($this->socket) {
fclose($this->socket);
}
}
public function is_connected() {
return $this->authorized;
}
public function send_command($command) {
if (!$this->is_connected()) return false;
// send command packet.
$this->write_packet(Rcon::PACKET_COMMAND, Rcon::SERVERDATA_EXECCOMMAND, $command);
// get response.
$response_packet = $this->read_packet();
if ($response_packet['id'] == Rcon::PACKET_COMMAND) {
if ($response_packet['type'] == Rcon::SERVERDATA_RESPONSE_VALUE) {
$this->last_response = $response_packet['body'];
return $response_packet['body'];
}
}
return false;
}
private function authorize() {
$this->write_packet(Rcon::PACKET_AUTHORIZE, Rcon::SERVERDATA_AUTH, $this->password);
$response_packet = $this->read_packet();
if ($response_packet['type'] == Rcon::SERVERDATA_AUTH_RESPONSE) {
if ($response_packet['id'] == Rcon::PACKET_AUTHORIZE) {
$this->authorized = true;
return true;
}
}
$this->disconnect();
return false;
}
/**
* Writes a packet to the socket stream..
*/
private function write_packet($packet_id, $packet_type, $packet_body) {
/*
Size 32-bit little-endian Signed Integer Varies, see below.
ID 32-bit little-endian Signed Integer Varies, see below.
Type 32-bit little-endian Signed Integer Varies, see below.
Body Null-terminated ASCII String Varies, see below.
Empty String Null-terminated ASCII String 0x00
*/
//create packet
$packet = pack("VV", $packet_id, $packet_type);
$packet = $packet . $packet_body . "\x00";
$packet = $packet . "\x00";
// get packet size.
$packet_size = strlen($packet);
// attach size to packet.
$packet = pack("V", $packet_size) . $packet;
// write packet.
fwrite($this->socket, $packet, strlen($packet));
}
private function read_packet() {
//get packet size.
$size_data = fread($this->socket, 4);
$size_pack = unpack("V1size", $size_data);
$size = $size_pack['size'];
// if size is > 4096, the response will be in multiple packets.
// this needs to be address. get more info about multi-packet responses
// from the RCON protocol specification at
// https://developer.valvesoftware.com/wiki/Source_RCON_Protocol
// currently, this script does not support multi-packet responses.
$packet_data = fread($this->socket, $size);
$packet_pack = unpack("V1id/V1type/a*body", $packet_data);
return $packet_pack;
}
}
Děkuji za odpověď a rady.