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

moar steamy stuff

parent a3599db4
No related branches found
No related tags found
No related merge requests found
......@@ -99,6 +99,10 @@ function _M:start()
self.pass = self.generic.online.pass
self:tryAuth()
self:waitFirstAuth()
elseif core.steam and self.generic.onlinesteam and self.generic.onlinesteam.autolog then
self.steam_token = core.steam.sessionTicket():toHex()
self:tryAuth()
self:waitFirstAuth()
end
end
......@@ -140,6 +144,7 @@ end
local generic_profile_defs = {
firstrun = {nosync=true, {firstrun="number"}, receive=function(data, save) save.firstrun = data.firstrun end },
online = {nosync=true, {login="string:40", pass="string:40"}, receive=function(data, save) save.login = data.login save.pass = data.pass end },
onlinesteam = {nosync=true, {autolog="boolean"}, receive=function(data, save) save.autolog = data.autolog end },
modules_played = { {name="index:string:30"}, {time_played="number"}, receive=function(data, save) max_set(save, data.name, data, "time_played") end, export=function(env) for k, v in pairs(env) do add{name=k, time_played=v} end end },
modules_loaded = { {name="index:string:30"}, {nb="number"}, receive=function(data, save) max_set(save, data.name, data, "nb") end, export=function(env) for k, v in pairs(env) do add{name=k, nb=v} end end },
}
......@@ -374,6 +379,21 @@ function _M:performlogin(login, pass)
end
end
function _M:performloginSteam(token, name, email)
self.steam_token = token
self.steam_token_name = name
if email then self.steam_token_email = email end
print("[ONLINE PROFILE] attempting log in steam", token)
self.auth_tried = nil
self:tryAuth()
self:waitFirstAuth()
if (profile.auth) then
self:saveGenericProfile("onlinesteam", {autolog=true})
self:getConfigs("generic")
self:syncOnline("generic")
end
end
-----------------------------------------------------------------------
-- Events from the profile thread
-----------------------------------------------------------------------
......@@ -434,7 +454,7 @@ function _M:waitFirstAuth(timeout)
if not self.waiting_auth then return end
print("[PROFILE] waiting for first auth")
local first = true
timeout = timeout or 40
timeout = timeout or 60
while self.waiting_auth and timeout > 0 do
if not first then
if not self.waiting_auth_no_redraw then core.display.forceRedraw() end
......@@ -459,6 +479,8 @@ function _M:eventAuth(e)
self.auth = e.ok:unserialize()
print("[PROFILE] Main thread got authed", self.auth.name)
self:getConfigs("generic", function(e) self:syncOnline(e.module) end)
else
self.auth_last_error = e.reason or "unknown"
end
end
......@@ -535,7 +557,12 @@ end
function _M:tryAuth()
print("[ONLINE PROFILE] auth")
core.profile.pushOrder(table.serialize{o="Login", l=self.login, p=self.pass})
self.auth_last_error = nil
if self.steam_token then
core.profile.pushOrder(table.serialize{o="SteamLogin", token=self.steam_token, name=self.steam_token_name, email=self.steam_token_email})
else
core.profile.pushOrder(table.serialize{o="Login", l=self.login, p=self.pass})
end
self.waiting_auth = true
end
......@@ -546,6 +573,7 @@ function _M:logOut()
local pop = self:mountProfile(true)
fs.delete("/generic/online.profile")
fs.delete("/generic/onlinesteam.profile")
self:umountProfile(true, pop)
end
......
......@@ -401,6 +401,10 @@ function _M:checkFirstTime()
end
end
function _M:newSteamAccount()
self:registerDialog(require("mod.dialogs.ProfileSteamRegister").new())
end
function _M:createProfile(loginItem)
if not loginItem.create then
self.auth_tried = nil
......
......@@ -136,7 +136,13 @@ function _M:login()
end
function _M:loginSteam()
print("<<<", core.steam.sessionTicket():toHex())
profile:performloginSteam((core.steam.sessionTicket():toHex()))
profile:waitFirstAuth()
if not profile.auth and profile.auth_last_error then
if profile.auth_last_error == "auth error" then
game:newSteamAccount()
end
end
end
function _M:logout()
......
-- TE4 - T-Engine 4
-- Copyright (C) 2009, 2010, 2011, 2012, 2013 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
require "engine.class"
local Dialog = require "engine.ui.Dialog"
local Button = require "engine.ui.Button"
local Textbox = require "engine.ui.Textbox"
local Textzone = require "engine.ui.Textzone"
module(..., package.seeall, class.inherit(Dialog))
function _M:init()
Dialog.init(self, "Steam User Account", 500, 400)
self.alpha = 230
self.c_desc = Textzone.new{width=math.floor(self.iw - 10), auto_height=true, text=[[Welcome to #GOLD#Tales of Maj'Eyal#LAST#.
To enjoy all the features the game has to offer it is #{bold}#highly#{normal}# recommended that you register your steam account.
Luckily this is very easy to do: you only require a profile name and optionally an email (we send very few email, maybe two a year at most).
]]}
local login_filter = function(c)
if c:find("^[a-z0-9]$") then return c end
if c:find("^[A-Z]$") then return c:lower() end
return nil
end
self.c_login = Textbox.new{title="Username: ", text="", chars=30, max_len=20, fct=function(text) self:okclick() end}
self.c_email = Textbox.new{title="Email: ", size_title=self.c_login.title, text="", chars=30, max_len=60, hide=true, fct=function(text) self:okclick() end}
local ok = require("engine.ui.Button").new{text="Register", fct=function() self:okclick() end}
local cancel = require("engine.ui.Button").new{text="Cancel", fct=function() self:cancelclick() end}
self:loadUI{
{left=0, top=0, ui=self.c_desc},
{left=0, top=self.c_desc.h, ui=self.c_login},
{left=0, top=self.c_desc.h+self.c_login.h+5, ui=self.c_email},
{left=0, bottom=0, ui=ok},
{right=0, bottom=0, ui=cancel},
}
self:setFocus(self.c_login)
self:setupUI(true, true)
self.key:addBinds{
-- EXIT = function() game:unregisterDialog(self) end,
}
end
function _M:okclick()
if self.c_login.text:len() < 2 then
self:simplePopup("Username", "Your username is too short")
return
end
if self.c_email.text:len() > 0 and not self.c_email.text:find("..@..") then
self:simplePopup("Email", "Your email does not look right.")
return
end
local d = self:simpleWaiter("Registering...", "Registering on http://te4.org/, please wait...")
profile:performloginSteam(core.steam.sessionTicket():toHex(), self.c_login.text, self.c_email.text)
profile:waitFirstAuth()
d:done()
if not profile.auth and profile.auth_last_error then
if profile.auth_last_error == "already exists" then
self:simplePopup("Error", "Username or Email already taken, please select an other one.")
end
elseif profile.auth then
game:unregisterDialog(self)
end
end
function _M:cancelclick()
self.key:triggerVirtual("EXIT")
end
......@@ -23,7 +23,7 @@ local UserChat = require "profile-thread.UserChat"
module(..., package.seeall, class.make)
local debug = false
local debug = true
local mport = debug and 2259 or 2257
local pport = debug and 2260 or 2258
......@@ -105,6 +105,7 @@ function _M:read(ncode)
return nil
end
if ncode and l:sub(1, 3) ~= ncode then
self.last_error = l:sub(5)
return nil, "bad code"
end
self.last_line = l:sub(5)
......@@ -133,7 +134,40 @@ function _M:pread(ncode)
end
function _M:login()
if self.sock and not self.auth and self.user_login and self.user_pass then
if self.sock and not self.auth and self.steam_token then
if self.steam_token_name then
self:command("STM_ NAME", self.steam_token_name)
self:read("200")
end
if self.steam_token_email then
self:command("STM_ EMAIL", self.steam_token_email)
self:read("200")
end
self:command("STM_ AUTH", self.steam_token)
if not self:read("200") then
local err = "unknown"
if self.last_error:find('^auth refused') then err = "auth error"
elseif self.last_error:find('^already exists') then err = "already exists"
end
cprofile.pushEvent(string.format("e='Auth' ok=false reason=%q", err))
return false
end
self:command("PASS")
if self:read("200") then
self.auth = self.last_line:unserialize()
print("[PROFILE] logged in with steam!", self.auth.login)
cprofile.pushEvent(string.format("e='Auth' ok=%q", self.last_line))
self:connectedPull()
if self.cur_char then self:orderCurrentCharacter(self.cur_char) end
return true
else
print("[PROFILE] could not log in with steam")
self.user_login = nil
self.user_pass = nil
cprofile.pushEvent("e='Auth' ok=false")
return false
end
elseif self.sock and not self.auth and self.user_login and self.user_pass then
self:command("AUTH", self.user_login)
self:read("200")
self:command("PASS", self.user_pass)
......@@ -241,6 +275,20 @@ function _M:orderLogin(o)
end
end
function _M:orderSteamLogin(o)
self.steam_token = o.token
self.steam_token_name = o.name
if o.email and #o.email > 1 then self.steam_token_email = o.email end
-- Already logged?
if self.auth then
print("[PROFILE] reusing login", self.auth.name)
cprofile.pushEvent(string.format("e='Auth' ok=%q", table.serialize(self.auth)))
else
self:login()
end
end
function _M:orderLogoff(o)
-- Already logged?
if self.auth then
......
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