Skip to content
Snippets Groups Projects
Commit 100b6d48 authored by DarkGod's avatar DarkGod
Browse files

Game should start faster when no connection is found

parent 0674afaf
No related branches found
No related tags found
No related merge requests found
......@@ -165,11 +165,7 @@ function _M:display(nb_keyframes)
end
-- Check profile thread events
local evt = profile:popEvent()
while evt do
self:handleProfileEvent(evt)
evt = profile:popEvent()
end
self:handleEvents()
-- Check timers
if self._timers_cb and nb_keyframes > 0 then
......@@ -202,6 +198,16 @@ function _M:idling(focus)
-- print("Game got focus/unfocus", focus)
end
--- Handle pending events
function _M:handleEvents()
local evt = profile:popEvent()
while evt do
self:handleProfileEvent(evt)
evt = profile:popEvent()
end
end
--- Receives a profile event
-- Usualy this just transfers it to the PlayerProfile class but you can overload it to handle special stuff
function _M:handleProfileEvent(evt)
......
......@@ -88,6 +88,7 @@ function _M:init()
["^donations$"] = { invalid = { read={offline=true}, write="offline" }, valid = { read={offline=true}, write="offline" } },
}
self.auth = false
self.connected = nil
end
function _M:start()
......@@ -457,6 +458,7 @@ function _M:waitFirstAuth(timeout)
if self.auth_tried and self.auth_tried >= 1 then return end
if not self.waiting_auth then return end
print("[PROFILE] waiting for first auth")
if self.connected == false then print("[PROFILE] waiting cancelled, connected = false") return end -- Set to false when we got a disconnect event, at boot it is nil
local first = true
timeout = timeout or 120
while self.waiting_auth and timeout > 0 do
......@@ -466,8 +468,10 @@ function _M:waitFirstAuth(timeout)
end
local evt = self:popEvent()
while evt do
if type(game) == "table" then game:handleProfileEvent(evt)
else self:handleEvent(evt) end
local e
if type(game) == "table" then e = game:handleProfileEvent(evt)
else e = self:handleEvent(evt) end
if e and e.e == "Disconnected" then print("[PROFILE] waiting cancelled, got disconnect event") timeout = 0 break end
if not self.waiting_auth then break end
evt = self:popEvent()
end
......@@ -534,10 +538,12 @@ end
function _M:eventConnected(e)
if game and type(game) == "table" and game.log then game.log("#YELLOW#Connection to online server established.") end
self.connected = true
end
function _M:eventDisconnected(e)
if game and type(game) == "table" and game.log then game.log("#YELLOW#Connection to online server lost, trying to reconnect.") end
if game and type(game) == "table" and game.log and self.connected then game.log("#YELLOW#Connection to online server lost, trying to reconnect.") end
self.connected = false
end
function _M:eventFunFacts(e)
......
......@@ -70,6 +70,8 @@ function _M:init()
self.background, self.background_tw, self.background_th = self.background:glTexture()
end
self:handleEvents()
if not profile.connected then core.webview = nil end
if not core.webview then self.tooltip = Tooltip.new(nil, 14, nil, colors.DARK_GREY, 380) end
-- self.refuse_threads = true
......
......@@ -36,7 +36,7 @@ end
function _M:connected()
if self.sock then return true end
self.sock = socket.connect("profiles.te4.org", mport)
if not self.sock then return false end
if not self.sock then self:disconnect() return false end
-- self.sock:settimeout(10)
print("[PROFILE] Thread connected to profiles.te4.org")
self:login()
......@@ -63,12 +63,10 @@ end
function _M:disconnect()
cprofile.pushEvent("e='Disconnected'")
if self.psock then
self.psock:close()
self.psock = nil
end
self.sock:close()
if self.psock then self.psock:close() end
if self.sock then self.sock:close() end
self.sock = nil
self.psock = nil
self.auth = nil
core.game.sleep(5000) -- Wait 5 secs
end
......@@ -267,9 +265,12 @@ function _M:orderLogin(o)
self.user_login = o.l
self.user_pass = o.p
if not self.sock then cprofile.pushEvent("e='Disconnected'") return end
-- Already logged?
if self.auth and self.auth.login == o.l then
print("[PROFILE] reusing login", self.auth.name)
if self.sock then cprofile.pushEvent("e='Connected'") end
cprofile.pushEvent(string.format("e='Auth' ok=%q", table.serialize(self.auth)))
self.chat:forwardFriends()
else
......@@ -282,9 +283,12 @@ function _M:orderSteamLogin(o)
self.steam_token_name = o.name
if o.email and #o.email > 1 then self.steam_token_email = o.email end
if not self.sock then cprofile.pushEvent("e='Disconnected'") return end
-- Already logged?
if self.auth then
print("[PROFILE] reusing login", self.auth.name)
if self.sock then cprofile.pushEvent("e='Connected'") end
cprofile.pushEvent(string.format("e='Auth' ok=%q", table.serialize(self.auth)))
else
self:login()
......
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