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

Fix online profiles

git-svn-id: http://svn.net-core.org/repos/t-engine4@843 51575b47-30f0-44d4-a5cc-537603b46e54
parent 46bd4d47
No related branches found
No related tags found
No related merge requests found
......@@ -77,7 +77,7 @@ function _M:init(name)
self.auth = false
if self.generic.online then
if self.generic.online and self.generic.online.login and self.generic.online.pass then
self.login = self.generic.online.login
self.pass = self.generic.online.pass
self:tryAuth()
......@@ -137,7 +137,7 @@ function _M:loadModuleProfile(short_name)
end
--- Saves a profile data
function _M:saveGenericProfile(name, data)
function _M:saveGenericProfile(name, data, nosync)
data = serialize(data)
-- Check for readability
......@@ -154,12 +154,13 @@ function _M:saveGenericProfile(name, data)
f:close()
if restore then fs.setWritePath(restore) end
self:setConfigs("generic", name, data)
if not nosync then self:setConfigs("generic", name, data) end
end
--- Saves a module profile data
function _M:saveModuleProfile(name, data)
function _M:saveModuleProfile(name, data, module, nosync)
data = serialize(data)
module = module or self.mod_name
-- Check for readability
local f, err = loadstring(data)
......@@ -170,13 +171,13 @@ function _M:saveModuleProfile(name, data)
local restore = fs.getWritePath()
fs.setWritePath(engine.homepath)
fs.mkdir("/profiles/"..self.name.."/modules/")
fs.mkdir("/profiles/"..self.name.."/modules/"..self.mod_name.."/")
local f = fs.open("/profiles/"..self.name.."/modules/"..self.mod_name.."/"..name..".profile", "w")
fs.mkdir("/profiles/"..self.name.."/modules/"..module.."/")
local f = fs.open("/profiles/"..self.name.."/modules/"..module.."/"..name..".profile", "w")
f:write(data)
f:close()
if restore then fs.setWritePath(restore) end
self:setConfigs(self.mod_name, name, data)
if not nosync then self:setConfigs(module, name, data) end
end
......@@ -193,13 +194,13 @@ end
function _M:tryAuth()
local data = self:rpc{action="TryAuth", login=self.login, pass=self.pass}
if not data then print("[ONLINE PROFILE] not auth") return end
print("[ONLINE PROFILE] auth as ", data.name)
print("[ONLINE PROFILE] auth as ", data.name, data.hash)
self.auth = data
end
function _M:getConfigs(module)
if not self.auth then return end
local data = self:rpc{action="GetConfigs", login=self.login, pass=self.pass, module=module}
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
print("[ONLINE PROFILE] config ", name)
......@@ -210,10 +211,12 @@ function _M:getConfigs(module)
if module == "generic" then
self.generic[field] = self.generic[field] or {}
self:loadData(f, self.generic[field])
self:saveGenericProfile(field, self.generic[field], nosync)
else
self.modules[module] = self.modules[module] or {}
self.modules[module][field] = self.modules[module][field] or {}
self:loadData(f, self.modules[module][field])
self:saveModuleProfile(field, self.modules[module][field], module, nosync)
end
end
end
......@@ -223,7 +226,7 @@ function _M:setConfigs(module, name, val)
if type(val) ~= "string" then val = serialize(val) end
local data = self:rpc{action="SetConfigs", login=self.login, pass=self.pass, module=module, data={[name] = val}}
local data = self:rpc{action="SetConfigs", login=self.login, hash=self.auth.hash, module=module, data={[name] = val}}
if not data then return end
print("[ONLINE PROFILE] saved ", module, name, val)
end
......@@ -237,7 +240,14 @@ function _M:syncOnline(module)
local data = {}
for k, v in pairs(sync) do if k ~= "online" then data[k] = serialize(v) end end
local data = self:rpc{action="SetConfigs", login=self.login, pass=self.pass, module=module, data=data}
local data = self:rpc{action="SetConfigs", login=self.login, hash=self.auth.hash, module=module, data=data}
if not data then return end
print("[ONLINE PROFILE] saved ", module)
end
function _M:newProfile()
local data = self:rpc{action="NewProfile", login=tostring(os.time()), email=os.time().."te4@mailcatch.com", name=os.time().."member", pass="test"}
if not data then print("[ONLINE PROFILE] could not create") return end
print("[ONLINE PROFILE] profile id ", data.id)
end
......@@ -158,7 +158,4 @@ for i, t in ipairs(stype_tot) do
end
------------------------------------------------------------------------
-- Import old settings, this line should disappear in a future version
if config.settings.tome.allow_build then for k, e in pairs(config.settings.tome.allow_build) do require("mod.class.Game"):setAllowedBuild(k, false) end end
return {require "mod.class.Game", require "mod.class.World"}
......@@ -156,6 +156,12 @@ function _M:selectStepMain()
self:selectStepLoad()
end,
},
{
name = "Player Profile",
fct = function()
self:selectStepProfile()
end,
},
-- [[
{
name = "Install a game module",
......@@ -335,3 +341,69 @@ function _M:selectStepInstall()
self.step:setMouseHandling()
self.step.key:addBind("EXIT", function() self:unregisterDialog(display_module) self:selectStepMain() end)
end
function _M:selectStepProfile()
local linda, th = Module:loadRemoteList()
local rawdllist = linda:receive("moduleslist")
th:join()
local dllist = {}
for i, mod in ipairs(rawdllist) do
if not self.mod_list[mod.short_name] then
dllist[#dllist+1] = mod
else
local lmod = self.mod_list[mod.short_name]
if mod.version[1] * 1000000 + mod.version[2] * 1000 + mod.version[3] > lmod.version[1] * 1000000 + lmod.version[2] * 1000 + lmod.version[3] then
dllist[#dllist+1] = mod
end
end
end
if #dllist == 0 then
Dialog:simplePopup("No modules available", "There are no modules to install or upgrade.")
return
end
local display_module = Dialog.new("", self.w * 0.73, self.h, self.w * 0.26, 0, 255)
for i, mod in ipairs(dllist) do
mod.fct = function()
local d = DownloadDialog.new("Downloading: "..mod.long_name, mod.download, function(di, data)
fs.mkdir("/modules")
local f = fs.open("/modules/"..mod.short_name..".team", "w")
for i, v in ipairs(data) do f:write(v) end
f:close()
-- Relist modules and savefiles
self.mod_list = Module:listModules()
self.save_list = Module:listSavefiles()
if self.mod_list[mod.short_name] then
Dialog:simplePopup("Success!", "Your new game is now installed, you can play!", function() self:unregisterDialog(display_module) self:selectStepMain() end)
else
Dialog:simplePopup("Error!", "The downloaded game does not seem to respond to the test. Please contact contact@te4.org")
end
end)
self:registerDialog(d)
d:startDownload()
end
mod.onSelect = function()
display_module.title = mod.long_name
display_module.changed = true
end
end
display_module.drawDialog = function(self, s)
local lines = dllist[game.step.selected].description:splitLines(self.w - 8, self.font)
local r, g, b
for i = 1, #lines do
r, g, b = s:drawColorString(self.font, lines[i], 0, i * self.font:lineSkip(), r, g, b)
end
end
self:registerDialog(display_module)
self.step = ButtonList.new(dllist, 10, 10, self.w * 0.24, (5 + 35) * #dllist, nil, 5)
self.step:setKeyHandling()
self.step:setMouseHandling()
self.step.key:addBind("EXIT", function() self:unregisterDialog(display_module) self:selectStepMain() end)
end
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