This commit is contained in:
OTCv8
2020-06-09 18:19:20 +02:00
parent 76d6f2ce7d
commit 541e189d3f
154 changed files with 2540 additions and 1221 deletions

View File

@@ -1,11 +0,0 @@
<?php
$data = file_get_contents("php://input", false, stream_context_get_default(), 0, $_SERVER["CONTENT_LENGTH"]);
if($_REQUEST['txt'] == 1) {
file_put_contents("crashes/".time()."_".$_SERVER['REMOTE_ADDR'].".txt", $data);
} else if($_REQUEST['txt'] == 2) {
file_put_contents("crashes/".time()."_".$_SERVER['REMOTE_ADDR'].".log", $data);
} else {
file_put_contents("crashes/".time()."_".$_SERVER['REMOTE_ADDR'].".dmp", $data);
}
echo "OK";
?>

View File

@@ -1,14 +0,0 @@
<?php
$data = file_get_contents("php://input");
if(empty($data)) {
return http_response_code(400);
}
$json = json_decode($data);
if(!$json) {
return http_response_code(400);
}
file_put_contents("feedback.txt", ($json->player->name) .": ". ($json->text) ."\n".$data."\n\n\n", FILE_APPEND);
echo "OK";
?>

View File

@@ -1,92 +1,68 @@
<?php
// set write permission or chmod 777 to dir with this file to let it create checksum files
$data = json_decode(file_get_contents("php://input"));
$platform = "";
$version = 0;
if(!empty($data)) {
$platform = $data->platform;
$version = $data->version; // currently not used
}
if($platform == "WIN32-WGL") { // opengl
$binary_path = "/otclient_gl.exe";
$checksums_file = "checksums_gl.txt";
} else if($platform == "WIN32-EGL") { // dx
$binary_path = "/otclient_dx.exe";
$checksums_file = "checksums_dx.txt";
} else {
$binary_path = "";
$checksums_file = "checksums.txt";
}
$data_dir = "/var/www/otclient/files";
// CONFIG
$files_dir = "/var/www/otclient/files";
$files_url = "http://otclient.ovh/files";
$update_checksum_interval = 60; // caling updater 100x/s would lag disc, we need to cache it
$main_files_and_dirs = array("data", "modules", "layouts", "init.lua"); // used to ignore other files/dirs in data_dir
$files_and_dirs = array("init.lua", "data", "modules", "layouts");
$checksum_file = "checksums.txt";
$checksum_update_interval = 60; // seconds
$binaries = array(
"WIN32-WGL" => "otclient_dx.exe",
"WIN32-EGL" => "otclient_gl.exe",
"WIN32-WGL-GCC" => "otclient_gcc_dx.exe",
"WIN32-EGL-GCC" => "otclient_gcc_gl.exe",
"X11-GLX" => "otclient_linux",
"X11-EGL" => "otclient_linux",
"ANDROID-EGL" => "" // we can't update android binary
);
// CONFIG END
$data = array("url" => $files_url, "files" => array(), "things" => array(), "binary" => $binary_path);
function sendError($error) {
echo(json_encode(array("error" => $error)));
die();
}
function getDirFiles($dir, &$results = array()){
$files = scandir($dir);
$data = json_decode(file_get_contents("php://input"));
//if(!$data) {
// sendError("Invalid input data");
//}
foreach($files as $key => $value){
$path = realpath($dir.DIRECTORY_SEPARATOR.$value);
if(!is_dir($path)) {
$results[] = $path;
} else if($value != "." && $value != "..") {
getDirFiles($path, $results);
}
$version = $data->version ?: 0; // APP_VERSION from init.lua
$build = $data->build ?: ""; // 2.4, 2.4.1, 2.5, etc
$os = $data->os ?: "unknown"; // android, windows, mac, linux, unknown
$platform = $data->platform ?: ""; // WIN32-WGL, X11-GLX, ANDROID-EGL, etc
$args = $data->args; // custom args when calling Updater.check()
$binary = $binaries[$platform] ?: "";
$cache = null;
$cache_file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $checksum_file;
if (file_exists($cache_file) && (filemtime($cache_file) + $checksum_update_interval > time())) {
$cache = json_decode(file_get_contents($cache_file), true);
}
if(!$cache) { // update cache
$dir = realpath($files_dir);
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
$cache = array();
foreach ($rii as $file) {
if (!$file->isFile())
continue;
$path = str_replace($dir, '', $file->getPathname());
$path = str_replace(DIRECTORY_SEPARATOR, '/', $path);
$cache[$path] = hash_file("crc32b", $file->getPathname());
}
return $results;
file_put_contents($cache_file . ".tmp", json_encode($cache));
rename($cache_file . ".tmp", $cache_file);
}
function updateChecksums() {
global $data_dir;
global $main_files_and_dirs;
global $binary_path;
global $checksums_file;
global $data;
$ret = array();
$data_dir_realpath = realpath($data_dir);
$files = getDirFiles($data_dir);
foreach($files as $file) {
$relative_path = str_replace($data_dir_realpath, "", $file);
$ps = explode(DIRECTORY_SEPARATOR, $relative_path);
if($relative_path == $binary_path || (count($ps) >= 2 && in_array($ps[1], $main_files_and_dirs)))
$ret[$relative_path] = md5_file($file);
}
foreach($ret as $file => $checksum) {
$data["files"][$file] = $checksum;
}
$ret = json_encode($data);
if(file_put_contents($checksums_file, $ret) === FALSE) {
echo "Can't create checksum file (try to set correct chmod) ". - $checksums_file;
exit();
$ret = array("url" => $files_url, "files" => array(), "keepFiles" => false);
foreach($cache as $file => $checksum) {
$base = trim(explode("/", ltrim($file, "/"))[0]);
if(in_array($base, $files_and_dirs)) {
$ret["files"][$file] = $checksum;
}
return $ret;
}
if (function_exists('sem_get')) {
$semaphore = sem_get(18237192837, 1, 0666, 1);
if(!$semaphore)
{
echo "Failed to get semaphore - sem_get().\n";
exit();
if($base == $binary && !empty($binary)) {
$ret["binary"] = array("file" => $file, "checksum" => $checksum);
}
sem_acquire($semaphore);
}
$ft = file_exists($checksums_file) ? filemtime($checksums_file) : false;
if($ft === false || $ft + $update_checksum_interval < time()) {
echo updateChecksums();
} else {
echo file_get_contents($checksums_file);
}
if (function_exists('sem_get')) {
sem_release($semaphore);
}
echo(json_encode($ret, JSON_PRETTY_PRINT));
?>

76
api/updater_advanced.php Normal file
View File

@@ -0,0 +1,76 @@
<?php
// CONFIG
$files_dir = "/var/www/otclient/files";
$files_url = "http://otclient.ovh/files";
$files_and_dirs = array("data", "modules", "layouts", "init.lua");
$checksum_file = "checksums.txt";
$checksum_update_interval = 5; // seconds
$binaries = array(
"WIN32-WGL" => "otclient_dx.exe",
"WIN32-EGL" => "otclient_gl.exe",
"WIN32-WGL-GCC" => "otclient_gcc_dx.exe",
"WIN32-EGL-GCC" => "otclient_gcc_gl.exe",
"X11-GLX" => "otclient_linux",
"X11-EGL" => "otclient_linux",
"ANDROID-EGL" => "" // we can't update android binary
);
// CONFIG END
function sendError($error) {
echo(json_encode(array("error" => $error)));
die();
}
$data = json_decode(file_get_contents("php://input"));
//if(!$data) {
// sendError("Invalid input data");
//}
$version = $data->version ?: 0; // APP_VERSION from init.lua
$build = $data->build ?: ""; // 2.4, 2.4.1, 2.5, etc
$os = $data->os ?: "unknown"; // android, windows, mac, linux, unknown
$platform = $data->platform ?: ""; // WIN32-WGL, X11-GLX, ANDROID-EGL, etc
$args = $data->args; // custom args when calling Updater.check()
$binary = $binaries[$platform] ?: "";
$forVersion = "";
if($args && $args->version) {
$forVersion = strval($args->version);
}
$cache = null;
$cache_file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $checksum_file;
if (file_exists($cache_file) && (filemtime($cache_file) + $checksum_update_interval > time())) {
$cache = json_decode(file_get_contents($cache_file), true);
}
if(!$cache) { // update cache
$dir = realpath($files_dir);
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS));
$cache = array();
foreach ($rii as $file) {
if (!$file->isFile())
continue;
$path = str_replace($dir, '', $file->getPathname());
$path = str_replace(DIRECTORY_SEPARATOR, '/', $path);
$cache[$path] = hash_file("crc32b", $file->getPathname());
}
file_put_contents($cache_file . ".tmp", json_encode($cache));
rename($cache_file . ".tmp", $cache_file);
}
$ret = array("url" => $files_url, "files" => array(), "keepFiles" => empty($forVersion) ? false : true);
foreach($cache as $file => $checksum) {
$base = trim(explode("/", ltrim($file, "/"))[0]);
if(strpos($file, "data/things") !== false && (empty($forVersion) || strpos($file, $forVersion) === false)) {
continue;
}
if(in_array($base, $files_and_dirs)) {
$ret["files"][$file] = $checksum;
}
if($base == $binary && !empty($binary)) {
$ret["binary"] = array("file" => $file, "checksum" => $checksum);
}
}
echo(json_encode($ret, JSON_PRETTY_PRINT));
?>