• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

OTCV8 UPDATER TIME OUT

Felipe93

Ghost Member
Joined
Mar 21, 2015
Messages
1,995
Solutions
9
Reaction score
336
Location
Chile
Hello im trying to configure the auto updater from otcv8

this is my updater.php placed in var/www/html/api/updater.php
LUA:
<?php
// CONFIG
$files_dir = "/var/www/html/files";
$files_url = "http://139.162.189.30/var/www/html/files";
$files_and_dirs = array("init.lua", "data", "modules", "layouts");
$checksum_file = "checksums.txt";
$checksum_update_interval = 60; // seconds
$binaries = array(
    "WIN32-WGL" => "otclient_gl.exe",
    "WIN32-EGL" => "otclient_dx.exe",
    "WIN32-WGL-GCC" => "otclient_gcc_gl.exe",
    "WIN32-EGL-GCC" => "otclient_gcc_dx.exe",
    "X11-GLX" => "otclient_linux",
    "X11-EGL" => "otclient_linux",
    "ANDROID-EGL" => "", // we can't update android binary
    "ANDROID64-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] ?: "";

$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());
    }
    file_put_contents($cache_file . ".tmp", json_encode($cache));
    rename($cache_file . ".tmp", $cache_file);
}
$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;
    }
    if($base == $binary && !empty($binary)) {
        $ret["binary"] = array("file" => $file, "checksum" => $checksum);
    }
}

echo(json_encode($ret, JSON_PRETTY_PRINT));

?>
advanced_
Code:
<?php
// version of updater user on ************
// CONFIG
$files_dir = "/var/www/otclient/var/www/html/files";
$files_url = "http://************/var/www/html/files";
$files_and_dirs = array("data", "modules", "layouts", "init.lua");
$checksum_file = "checksums.txt";
$checksum_update_interval = 30; // 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] ?: "";

if($build != "3.1" && strpos($platform, "ANDROID") !== false) {
    sendError("Outdated client ($build).\nUinstall current client and then download new from:\nhttp://************/otclientv8.apk");
}

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

?>
updater.php
inside var/www/html/files
i placed my otcv8 files
Code:
otclient_gl.exe, otclient_dx.exe, libEGL.dll, libGLESv2.dll, d3dcompiler_46.dll and data.zip
this is my init.lua
Code:
-- CONFIG
APP_NAME = "otclientv8"  -- important, change it, it's name for config dir and files in appdata
APP_VERSION = 800       -- client version for updater and login to identify outdated client
DEFAULT_LAYOUT = "black" -- on android it's forced to "mobile", check code bellow

-- If you don't use updater or other service, set it to updater = ""
Services = {
  website = "http://139.162.189.30", -- currently not used
  updater = "http://139.162.189.30/var/www/html/api/updater.php",
  stats = "",
  crash = "http://139.162.189.30/var/www/html/api/crash.php",
  feedback = "http://139.162.189.30/var/www/html/api/feedback.php",
  status = "http://139.162.189.30/var/www/html/api/status.php"
}

-- Servers accept http login url, websocket login url or ip:port:version
Servers = {
meuserver= "139.162.189.30:7171:800"
}


--Server = "ws://************:3000/"
--Server = "ws://127.0.0.1:88/"
--USE_NEW_ENERGAME = true -- uses entergamev2 based on websockets instead of entergame
ALLOW_CUSTOM_SERVERS = false -- if true it shows option ANOTHER on server list

g_app.setName("OTCv8")
-- CONFIG END

-- print first terminal message
g_logger.info(os.date("== application started at %b %d %Y %X"))
g_logger.info(g_app.getName() .. ' ' .. g_app.getVersion() .. ' rev ' .. g_app.getBuildRevision() .. ' (' .. g_app.getBuildCommit() .. ') made by ' .. g_app.getAuthor() .. ' built on ' .. g_app.getBuildDate() .. ' for arch ' .. g_app.getBuildArch())

if not g_resources.directoryExists("/data") then
  g_logger.fatal("Data dir doesn't exist.")
end

if not g_resources.directoryExists("/modules") then
  g_logger.fatal("Modules dir doesn't exist.")
end

-- settings
g_configs.loadSettings("/config.otml")

-- set layout
local settings = g_configs.getSettings()
local layout = DEFAULT_LAYOUT
if g_app.isMobile() then
  layout = "mobile"
elseif settings:exists('layout') then
  layout = settings:getValue('layout')
end
g_resources.setLayout(layout)

-- load mods
g_modules.discoverModules()
g_modules.ensureModuleLoaded("corelib")
 
local function loadModules()
  -- libraries modules 0-99
  g_modules.autoLoadModules(99)
  g_modules.ensureModuleLoaded("gamelib")

  -- client modules 100-499
  g_modules.autoLoadModules(499)
  g_modules.ensureModuleLoaded("client")

  -- game modules 500-999
  g_modules.autoLoadModules(999)
  g_modules.ensureModuleLoaded("game_interface")

  -- mods 1000-9999
  g_modules.autoLoadModules(9999)
end

-- report crash
if type(Services.crash) == 'string' and Services.crash:len() > 4 and g_modules.getModule("crash_reporter") then
  g_modules.ensureModuleLoaded("crash_reporter")
end

-- run updater, must use data.zip
if type(Services.updater) == 'string' and Services.updater:len() > 4
  and g_resources.isLoadedFromArchive() and g_modules.getModule("updater") then
  g_modules.ensureModuleLoaded("updater")
  return Updater.init(loadModules)
end
loadModules()

and i've added chmod to the api folder
Code:
chmod 777 /var/www/html/api

when the client is updateing i receive an error message, what im missing?
2.png
 
on your init.lua

change:
LUA:
Services = {
  website = "http://139.162.189.30", -- currently not used
  updater = "http://139.162.189.30/var/www/html/api/updater.php", -- this line cause problem
To:

LUA:
Services = {
  website = "http://139.162.189.30", -- currently not used
  updater = "http://139.162.189.30/api/updater.php",    -- fixed typo


when you build a website, to access it, all the related content inside the " html/ " folder

returns direct directory to " / "


so if your files are located at var/www/html/api/updater.php

results in redirection to " /api/updater.php "
 
Last edited:
How to configure the update on Android

Same thing on init.lua
and i miss u need change ur updater.php on site files from:


PHP:
$files_dir = "/var/www/html/files";
$files_url = "http://139.162.189.30/var/www/html/files";
$files_and_dirs = array("init.lua", "data", "modules", "layouts");

To this:

PHP:
$files_dir = "/var/www/html/files";
$files_url = "http://139.162.189.30/files";
$files_and_dirs = array("init.lua", "data", "modules", "layouts");


And remember don't put the entire location of files on http:// only need the last inside html/
 
how to configure to make it works in windows 10? in having problems here
have this in updater.php

LUA:
 CONFIG
$files_dir = "C:/xampp/htdocs/windowsfiles";
$files_url = "http://xxx/windowsfiles";
//$files_dir = "/var/www/otclient/var/www/html/files";
//$files_url = "http://************/var/www/html/
and this in my init.lua
Code:
 CONFIG
$files_dir = "C:/xampp/htdocs/windowsfiles";
$files_url = "http://xxx.ddns.net/windowsfiles";
//$files_dir = "/var/www/otclient/var/www/html/files";
//$files_url = "http://************/var/www/html/
 
Last edited:

Similar threads

Back
Top