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

Game modules will be verified against an online check; profile data logging...

Game modules will be verified against an online check; profile data logging and online charsheet will only activate if the game is found to be clean. This is to prevent developpers & testers from erroneously uploading false data


git-svn-id: http://svn.net-core.org/repos/t-engine4@2142 51575b47-30f0-44d4-a5cc-537603b46e54
parent 5cf44da9
No related branches found
No related tags found
No related merge requests found
......@@ -110,6 +110,11 @@ end
function _M:run()
end
--- Checks if the current character is "tainted" by cheating
function _M:isTainted()
return false
end
--- Sets the current level
-- @param level an engine.Level (or subclass) object
function _M:setLevel(level)
......
......@@ -186,6 +186,8 @@ function _M:instanciate(mod, name, new_game, no_reboot)
return
end
if mod.short_name == "boot" then profile.hash_valid = true end
profile.generic.modules_loaded = profile.generic.modules_loaded or {}
profile.generic.modules_loaded[mod.short_name] = (profile.generic.modules_loaded[mod.short_name] or 0) + 1
......@@ -199,6 +201,32 @@ function _M:instanciate(mod, name, new_game, no_reboot)
_G.game = M.new()
_G.game:setPlayerName(name)
-- Check MD5sum with the server
local md5 = require "md5"
local md5s = {}
local function fp(dir)
for i, file in ipairs(fs.list(dir)) do
local f = dir.."/"..file
if fs.isdir(f) then
fp(f)
elseif f:find("%.lua$") then
local fff = fs.open(f, "r")
if fff then
local data = fff:read(10485760)
md5s[#md5s+1] = f..":"..md5.sumhexa(data)
fff:close()
end
end
end
end
local t = core.game.getTime()
fp("/mod")
fp("/data")
fp("/engine")
table.sort(md5s)
local fmd5 = md5.sumhexa(table.concat(md5s))
print("[MODULE LOADER] module MD5", fmd5, "computed in ", core.game.getTime() - t)
-- Load the world, or make a new one
if W then
local save = Savefile.new("")
......@@ -221,6 +249,14 @@ function _M:instanciate(mod, name, new_game, no_reboot)
-- And now run it!
_G.game:run()
-- Disable the profile if ungood
if mod.short_name ~= "boot" then
local ok, err = profile:checkModuleHash(("%s-%d.%d.%d"):format(mod.short_name, mod.version[1], mod.version[2], mod.version[3]), fmd5)
if not ok then
game.log("#LIGHT_RED#Profile disabled due to %s.", err)
end
end
end
--- Setup write dir for a module
......
......@@ -246,7 +246,7 @@ function _M:tryAuth()
end
function _M:getConfigs(module)
if not self.auth then return end
if not self.auth or not self.hash_valid 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 then return end
if not self.auth or not self.hash_valid 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 then return end
if not self.auth or not self.hash_valid then return end
local sync = self.generic
if module ~= "generic" then sync = self.modules[module] end
if not sync then return end
......@@ -337,7 +337,7 @@ function _M:checkFirstRun()
end
function _M:registerNewCharacter(module)
if not self.auth then return end
if not self.auth or not self.hash_valid then return end
local dialog = Dialog:simplePopup("Registering character", "Character is being registered on http://te4.org/") dialog.__showup = nil core.display.forceRedraw()
local data = self:rpc{action="RegisterNewCharacter", login=self.login, hash=self.auth.hash, module=module}
game:unregisterDialog(dialog)
......@@ -347,10 +347,22 @@ function _M:registerNewCharacter(module)
end
function _M:registerSaveChardump(module, uuid, title, data)
if not self.auth then return end
if not self.auth or not self.hash_valid then return end
local dialog = Dialog:simplePopup("Uploading character data", "Character sheet is being uploaded to http://te4.org/") dialog.__showup = nil core.display.forceRedraw()
local data = self:rpc{action="SaveChardump", login=self.login, hash=self.auth.hash, module=module, uuid=uuid, title=title, data=data}
game:unregisterDialog(dialog)
if not data or not data.ok then return end
print("[ONLINE PROFILE] saved character ", uuid)
end
function _M:checkModuleHash(module, md5)
self.hash_valid = false
if not self.auth then return nil, "no online profile active" end
if config.settings.cheat then return nil, "cheat mode active" end
if game and game:isTainted() then return nil, "savefile tainted" end
local data = self:rpc{action="CheckModuleHash", login=self.login, hash=self.auth.hash, module=module, md5=md5}
if not data or not data.ok then return nil, "bad game version" end
print("[ONLINE PROFILE] module hash is valid")
self.hash_valid = true
return true
end
......@@ -36,7 +36,7 @@ function _M:mouseMove(tmx, tmy, spotHostiles)
tmx = util.bound(tmx, 0, game.level.map.w - 1)
tmy = util.bound(tmy, 0, game.level.map.h - 1)
if config.settings.tome.cheat and core.key.modState("ctrl") then
if config.settings.cheat and core.key.modState("ctrl") then
game.log("[CHEAT] teleport to %dx%d", tmx, tmy)
self:move(tmx, tmy, true)
else
......
......@@ -124,7 +124,7 @@ end
function _M:generateList()
local list = {}
if config.settings.tome and config.settings.tome.cheat then list[#list+1] = {name="Resurrect by cheating", action="cheat"} end
if config.settings.cheat then list[#list+1] = {name="Resurrect by cheating", action="cheat"} end
list[#list+1] = {name="Character dump", action="dump"}
list[#list+1] = {name="Exit to main menu", action="exit"}
......
......@@ -124,7 +124,7 @@ end
function _M:generateList()
local list = {}
if config.settings.tome and config.settings.tome.cheat then list[#list+1] = {name="Resurrect by cheating", action="cheat"} end
if config.settings.cheat then list[#list+1] = {name="Resurrect by cheating", action="cheat"} end
list[#list+1] = {name="Character dump", action="dump"}
list[#list+1] = {name="Exit to main menu", action="exit"}
......
......@@ -124,7 +124,7 @@ end
function _M:generateList()
local list = {}
if config.settings.tome and config.settings.tome.cheat then list[#list+1] = {name="Resurrect by cheating", action="cheat"} end
if config.settings.cheat then list[#list+1] = {name="Resurrect by cheating", action="cheat"} end
list[#list+1] = {name="Character dump", action="dump"}
list[#list+1] = {name="Exit to main menu", action="exit"}
......
......@@ -124,6 +124,12 @@ function _M:run()
if self.level then self:setupDisplayMode() end
end
--- Checks if the current character is "tainted" by cheating
function _M:isTainted()
if config.settings.cheat then return true end
return (game.player and game.player.__cheated) and true or false
end
function _M:newGame()
self.player = Player.new{name=self.player_name, game_ender=true}
Map:setViewerActor(self.player)
......@@ -137,6 +143,8 @@ function _M:newGame()
self.zone.object_list[#self.zone.object_list+1] = o
end
if config.settings.cheat then self.player.__cheated = true end
-- Register the character online if possible
self.player:getUUID()
end
......@@ -188,8 +196,6 @@ function _M:newGame()
else self.player:playerLevelup(birthend) end
end, quickbirth, 720, 500)
-- Load a full player instead of a simpler quickbirthing, if possible
birth.quickBirth = function(b)
birth.quickBirth = nil
......@@ -262,6 +268,7 @@ function _M:loaded()
self.key = engine.KeyBind.new()
if self.always_target then Map:setViewerFaction(self.player.faction) end
if self.player and config.settings.cheat then self.player.__cheated = true end
end
function _M:createSeparators()
......@@ -687,7 +694,7 @@ function _M:setupCommands()
self.key:addCommands{
[{"_d","ctrl"}] = function()
if config.settings.tome.cheat then
if config.settings.cheat then
self.player:forceLevelup(50)
self.player.no_breath = 1
self.player.invulnerable = 1
......@@ -709,7 +716,7 @@ function _M:setupCommands()
end
end,
[{"_z","ctrl"}] = function()
if config.settings.tome.cheat then
if config.settings.cheat then
self.player:forceLevelup(50)
self.player.no_breath = 1
self.player.invulnerable = 1
......@@ -719,7 +726,7 @@ function _M:setupCommands()
end
end,
[{"_f","ctrl"}] = function()
if config.settings.tome.cheat then
if config.settings.cheat then
self.player:incStat("str", 100) self.player:incStat("dex", 100) self.player:incStat("mag", 100) self.player:incStat("wil", 100) self.player:incStat("cun", 100) self.player:incStat("con", 100)
self.player:learnTalent(self.player.T_HEAVY_ARMOUR_TRAINING, true) self.player:learnTalent(self.player.T_MASSIVE_ARMOUR_TRAINING, true)
-- [[
......@@ -746,7 +753,7 @@ function _M:setupCommands()
end
end,
[{"_g","ctrl"}] = function()
if config.settings.tome.cheat then
if config.settings.cheat then
-- local m = game.zone:makeEntityByName(game.level, "actor", "TEST")
-- game.zone:addEntity(game.level, m, "actor", game.player.x, game.player.y+1)
-- self.player:grantQuest("anti-antimagic")
......@@ -910,7 +917,7 @@ function _M:setupCommands()
end,
-- Lua console
LUA_CONSOLE = function()
if config.settings.tome.cheat then
if config.settings.cheat then
self:registerDialog(DebugConsole.new())
end
end,
......
......@@ -165,7 +165,7 @@ end
function _M:generateList()
local list = {}
if config.settings.tome and config.settings.tome.cheat then list[#list+1] = {name="Resurrect by cheating", action="cheat"} end
if config.settings.cheat then list[#list+1] = {name="Resurrect by cheating", action="cheat"} end
if self.actor:attr("easy_mode_lifes") then list[#list+1] = {name=("Resurrect with easy mode (%d left)"):format(self.actor.easy_mode_lifes), action="easy_mode"} end
if self.actor:attr("blood_life") and not self.actor:attr("undead") then list[#list+1] = {name="Resurrect with the Blood of Life", action="blood_life"} end
if self.actor:getTalentLevelRaw(self.actor.T_SKELETON_REASSEMBLE) >= 5 and not self.actor:attr("re-assembled") then list[#list+1] = {name="Re-assemble your bones and resurrect (Skeleton ability)", action="skeleton"} end
......
----------------------------------------------------------------------------
-- $Id: md5.lua,v 1.4 2006/08/21 19:24:21 carregal Exp $
----------------------------------------------------------------------------
local core = require"md5.core"
local string = require"string"
module ("md5")
----------------------------------------------------------------------------
-- @param k String with original message.
-- @return String with the md5 hash value converted to hexadecimal digits
function core.sumhexa (k)
k = core.sum(k)
return (string.gsub(k, ".", function (c)
return string.format("%02x", string.byte(c))
end))
end
return core
......@@ -81,7 +81,7 @@ project "TEngine"
language "C"
targetname "t-engine"
files { "src/*.c", }
links { "physfs", "lua".._OPTIONS.lua, "fov", "luasocket", "luaprofiler", "lualanes", "lpeg", "tcodimport", "lxp", "expatstatic" }
links { "physfs", "lua".._OPTIONS.lua, "fov", "luasocket", "luaprofiler", "lualanes", "lpeg", "tcodimport", "lxp", "expatstatic", "luamd5" }
defines { "_DEFAULT_VIDEOMODE_FLAGS_='SDL_HWSURFACE|SDL_DOUBLEBUF'" }
defines { [[TENGINE_HOME_PATH='".t-engine"']] }
......@@ -250,3 +250,10 @@ project "lxp"
targetname "lxp"
files { "src/lxp/*.c", }
project "luamd5"
kind "StaticLib"
language "C"
targetname "luamd5"
files { "src/luamd5/*.c", }
......@@ -1764,6 +1764,15 @@ static int lua_fs_exists(lua_State *L)
return 1;
}
static int lua_fs_isdir(lua_State *L)
{
const char *file = luaL_checkstring(L, 1);
lua_pushboolean(L, PHYSFS_isDirectory(file));
return 1;
}
static int lua_fs_mkdir(lua_State *L)
{
const char *dir = luaL_checkstring(L, 1);
......@@ -2077,6 +2086,7 @@ static const struct luaL_reg fslib[] =
{"exists", lua_fs_exists},
{"rename", lua_fs_rename},
{"mkdir", lua_fs_mkdir},
{"isdir", lua_fs_isdir},
{"delete", lua_fs_delete},
{"list", lua_fs_list},
{"setWritePath", lua_fs_set_write_dir},
......
......@@ -11,3 +11,4 @@ int luaopen_shaders(lua_State *L);
int luaopen_struct(lua_State *L);
int luaopen_noise(lua_State *L);
int luaopen_lxp(lua_State *L);
int luaopen_md5_core (lua_State *L);
......@@ -587,6 +587,7 @@ void boot_lua(int state, bool rebooting, int argc, char *argv[])
luaopen_profiler(L);
luaopen_lpeg(L);
luaopen_lxp(L);
luaopen_md5_core(L);
luaopen_map(L);
luaopen_particles(L);
luaopen_gas(L);
......
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