Skip to content
Snippets Groups Projects
Commit f7334752 authored by dg's avatar dg
Browse files

Unlocks, achievements, .. should correctly update again

Bad game version detection will switch to a "development" profile automatically
Added the -P"profname" command line switch to switch to a "profname" profile (to prevent uploading bad data)


git-svn-id: http://svn.net-core.org/repos/t-engine4@2212 51575b47-30f0-44d4-a5cc-537603b46e54
parent 974e93d1
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,7 @@ require "engine.class"
local lanes = require "lanes"
local Dialog = require "engine.ui.Dialog"
local Savefile = require "engine.Savefile"
require "engine.PlayerProfile"
--- Handles dialog windows
module(..., package.seeall, class.make)
......@@ -118,24 +119,26 @@ function _M:loadDefinition(dir, team)
end
-- Make a function to activate it
mod.load = function()
core.display.setWindowTitle(mod.long_name)
self:setupWrite(mod)
if not team then
fs.mount(fs.getRealPath(dir), "/mod", false)
fs.mount(fs.getRealPath(dir).."/data/", "/data", false)
if fs.exists(dir.."/engine") then fs.mount(fs.getRealPath(dir).."/engine/", "/engine", false) end
else
local src = fs.getRealPath(team)
fs.mount(src, "/", false)
mod.load = function(mode)
if mode == "setup" then
core.display.setWindowTitle(mod.long_name)
self:setupWrite(mod)
if not team then
fs.mount(fs.getRealPath(dir), "/mod", false)
fs.mount(fs.getRealPath(dir).."/data/", "/data", false)
if fs.exists(dir.."/engine") then fs.mount(fs.getRealPath(dir).."/engine/", "/engine", false) end
else
local src = fs.getRealPath(team)
fs.mount(src, "/", false)
end
elseif mode == "init" then
local m = require(mod.starter)
m[1].__session_time_played_start = os.time()
m[1].__mod_info = mod
print("[MODULE LOADER] loading module", mod.long_name, "["..mod.starter.."]", "::", m[1] and m[1].__CLASSNAME, m[2] and m[2].__CLASSNAME)
return m[1], m[2]
end
profile:loadModuleProfile(mod.short_name)
local m = require(mod.starter)
m[1].__session_time_played_start = os.time()
m[1].__mod_info = mod
print("[MODULE LOADER] loading module", mod.long_name, "["..mod.starter.."]", "::", m[1] and m[1].__CLASSNAME, m[2] and m[2].__CLASSNAME)
return m[1], m[2]
end
print("Loaded module definition for "..mod.version_string.." using engine "..eng_req)
......@@ -198,10 +201,8 @@ function _M:instanciate(mod, name, new_game, no_reboot)
-- Turn based by default
core.game.setRealtime(0)
-- Ok run the module
local M, W = mod.load()
_G.game = M.new()
_G.game:setPlayerName(name)
-- Init the module directories
mod.load("setup")
-- Check MD5sum with the server
local md5 = require "md5"
......@@ -228,6 +229,19 @@ function _M:instanciate(mod, name, new_game, no_reboot)
table.sort(md5s)
local fmd5 = md5.sumhexa(table.concat(md5s))
print("[MODULE LOADER] module MD5", fmd5, "computed in ", core.game.getTime() - t)
local hash_valid, hash_err = profile:checkModuleHash(mod.version_name, fmd5)
-- If bad hash, switch to dev profile
if not hash_valid then
print("[PROFILE] switching to dev profile")
_G.profile = engine.PlayerProfile.new("dev")
end
profile:loadModuleProfile(mod.short_name)
-- Init the module code
local M, W = mod.load("init")
_G.game = M.new()
_G.game:setPlayerName(name)
-- Load the world, or make a new one
if W then
......@@ -254,9 +268,8 @@ function _M:instanciate(mod, name, new_game, no_reboot)
-- Disable the profile if ungood
if mod.short_name ~= "boot" then
local ok, err = profile:checkModuleHash(mod.version_name, fmd5)
if not ok then
game.log("#LIGHT_RED#Profile disabled due to %s.", err)
if not hash_valid then
game.log("#LIGHT_RED#Profile disabled(switching to development profile) due to %s.", hash_err)
end
end
end
......
......@@ -246,7 +246,7 @@ function _M:tryAuth()
end
function _M:getConfigs(module)
if not self.auth or not self.hash_valid then return end
if not self.auth then return end
local data = self:rpc{action="GetConfigs", login=self.login, hash=self.auth.hash, module=module}
if not data then print("[ONLINE PROFILE] get configs") return end
for name, val in pairs(data) do
......@@ -272,7 +272,7 @@ function _M:getConfigs(module)
end
function _M:setConfigs(module, name, val)
if not self.auth or not self.hash_valid then return end
if not self.auth then return end
if name == "online" then return end
if type(val) ~= "string" then val = serialize(val) end
......@@ -283,7 +283,7 @@ function _M:setConfigs(module, name, val)
end
function _M:syncOnline(module)
if not self.auth or not self.hash_valid then return end
if not self.auth then return end
local sync = self.generic
if module ~= "generic" then sync = self.modules[module] end
if not sync then return end
......
......@@ -92,7 +92,7 @@ engine.interface.GameMusic:soundSystemStatus(config.settings.sound.enabled, true
core.sound.activateMusicCallback()
-- Load profile configs
profile = engine.PlayerProfile.new()
profile = engine.PlayerProfile.new(__request_profile or "default")
-- Create a savefile pipe
savefile_pipe = engine.SavefilePipe.new()
......
......@@ -38,6 +38,7 @@ local load load = function(...)
else
__module_extra_info = {}
end
__request_profile = args[7] or "default"
print("Reboot using", req_engine, req_version, __load_module, __player_name, __player_new)
......
......@@ -51,6 +51,7 @@ int current_mousehandler = LUA_NOREF;
int current_keyhandler = LUA_NOREF;
int current_game = LUA_NOREF;
bool reboot_lua = FALSE, reboot_new = FALSE;
char *request_profile = "default";
char *reboot_engine = NULL, *reboot_engine_version = NULL, *reboot_module = NULL, *reboot_name = NULL, *reboot_einfo = NULL;
bool exit_engine = FALSE;
bool no_sound = FALSE;
......@@ -645,7 +646,8 @@ void boot_lua(int state, bool rebooting, int argc, char *argv[])
if (reboot_name) lua_pushstring(L, reboot_name); else lua_pushnil(L);
lua_pushboolean(L, reboot_new);
if (reboot_einfo) lua_pushstring(L, reboot_einfo); else lua_pushnil(L);
docall(L, 6, 0);
if (request_profile) lua_pushstring(L, request_profile); else lua_pushnil(L);
docall(L, 7, 0);
}
}
......@@ -674,6 +676,7 @@ int main(int argc, char *argv[])
for (i = 1; i < argc; i++)
{
char *arg = argv[i];
if (!strncmp(arg, "-P", 2)) request_profile = strdup(arg+2);
if (!strncmp(arg, "-M", 2)) reboot_module = strdup(arg+2);
if (!strncmp(arg, "-u", 2)) reboot_name = strdup(arg+2);
if (!strncmp(arg, "-E", 2)) reboot_einfo = strdup(arg+2);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment