From faf0685820b5c0bde13e5d182d8684ed22c355a7 Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Wed, 1 Jun 2011 09:17:52 +0000
Subject: [PATCH] Added a 10 seconds timeout to online character registration
 If a character has not been registered online the game is more lenient and
 can try again later

git-svn-id: http://svn.net-core.org/repos/t-engine4@3516 51575b47-30f0-44d4-a5cc-537603b46e54
---
 game/engines/default/engine/PlayerProfile.lua            | 4 ++--
 game/engines/default/engine/interface/PlayerDumpJSON.lua | 8 +++++++-
 game/modules/tome/class/Game.lua                         | 8 ++++----
 game/modules/tome/class/Player.lua                       | 3 +++
 4 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/game/engines/default/engine/PlayerProfile.lua b/game/engines/default/engine/PlayerProfile.lua
index 8f6cf8f04c..2606d4ae17 100644
--- a/game/engines/default/engine/PlayerProfile.lua
+++ b/game/engines/default/engine/PlayerProfile.lua
@@ -524,7 +524,7 @@ function _M:checkModuleHash(module, md5)
 	if game and game:isTainted() then return nil, "savefile tainted" end
 	core.profile.pushOrder(table.serialize{o="CheckModuleHash", module=module, md5=md5})
 
-	self:waitEvent("CheckModuleHash", function(e) ok = e.ok end)
+	self:waitEvent("CheckModuleHash", function(e) ok = e.ok end, 10000)
 
 	if not ok then return nil, "bad game version" end
 	print("[ONLINE PROFILE] module hash is valid")
@@ -543,7 +543,7 @@ function _M:registerNewCharacter(module)
 
 	core.profile.pushOrder(table.serialize{o="RegisterNewCharacter", module=module})
 	local uuid = nil
-	self:waitEvent("RegisterNewCharacter", function(e) uuid = e.uuid end)
+	self:waitEvent("RegisterNewCharacter", function(e) uuid = e.uuid end, 10000)
 
 	game:unregisterDialog(dialog)
 	if not uuid then return end
diff --git a/game/engines/default/engine/interface/PlayerDumpJSON.lua b/game/engines/default/engine/interface/PlayerDumpJSON.lua
index ea31f63075..bc9532eb9a 100644
--- a/game/engines/default/engine/interface/PlayerDumpJSON.lua
+++ b/game/engines/default/engine/interface/PlayerDumpJSON.lua
@@ -24,6 +24,8 @@ require "Json2"
 -- This is used for auto uploads to te4.org, could be for other stuff too
 module(..., package.seeall, class.make)
 
+allow_late_uuid = false
+
 --- Register the character on te4.org and return a UUID for it
 function _M:getUUID()
 	local uuid = profile:registerNewCharacter(game.__mod_info.short_name)
@@ -34,7 +36,11 @@ end
 
 --- Call this when a character is saved to upload data to te4.org
 function _M:saveUUID()
-	if not self.__te4_uuid then return end
+	if not self.__te4_uuid then
+		-- Try to grab an UUID even after char reg
+		if self.allow_late_uuid and not game:isTainted() then self:getUUID() end
+		if not self.__te4_uuid then return end
+	end
 	local data = {sections={}}
 	setmetatable(data, {__index={
 		newSection = function(self, display, table, type, column, sectable)
diff --git a/game/modules/tome/class/Game.lua b/game/modules/tome/class/Game.lua
index e0bcd20a6b..182bd37748 100644
--- a/game/modules/tome/class/Game.lua
+++ b/game/modules/tome/class/Game.lua
@@ -159,7 +159,7 @@ function _M:run()
 end
 
 --- Checks if the current character is "tainted" by cheating
-function _M:isTainted()
+function _M:isTainted() do
 	if config.settings.cheat then return true end
 	return (game.player and game.player.__cheated) and true or false
 end
@@ -494,18 +494,18 @@ function _M:changeLevel(lev, zone, keep_old_lev, force_down)
 	if game.player:isTalentActive(game.player.T_JUMPGATE) then
 		game.player:forceUseTalent(game.player.T_JUMPGATE, {ignore_energy=true})
 	end
-	
+
 	if game.player:isTalentActive(game.player.T_JUMPGATE_TWO) then
 		game.player:forceUseTalent(game.player.T_JUMPGATE_TWO, {ignore_energy=true})
 	end
 
 	-- clear chrono worlds and their various effects
 	if game._chronoworlds then game._chronoworlds = nil end
-	
+
 	if game.player:isTalentActive(game.player.T_DOOR_TO_THE_PAST) then
 		game.player:forceUseTalent(game.player.T_DOOR_TO_THE_PAST, {ignore_energy=true})
 	end
-	
+
 	local left_zone = self.zone
 
 	if self.zone and self.zone.on_leave then
diff --git a/game/modules/tome/class/Player.lua b/game/modules/tome/class/Player.lua
index 675448cc88..9a05fe7b87 100644
--- a/game/modules/tome/class/Player.lua
+++ b/game/modules/tome/class/Player.lua
@@ -49,6 +49,9 @@ module(..., package.seeall, class.inherit(
 	mod.class.interface.PartyDeath
 ))
 
+-- Allow character registration even after birth
+allow_late_uuid = true
+
 function _M:init(t, no_default)
 	t.display=t.display or '@'
 	t.color_r=t.color_r or 230
-- 
GitLab