diff --git a/lib/api.rb b/lib/api.rb
index 33fefe8..f0aed19 100644
--- a/lib/api.rb
+++ b/lib/api.rb
@@ -29,6 +29,31 @@ class W3DHub
# See #user_refresh_token
def self.user_login(username, password)
+ response = W3DHUB_API_CONNECTION.post(
+ path: "apis/launcher/1/user-login",
+ headers: DEFAULT_HEADERS.merge({"Content-Type": "application/x-www-form-urlencoded"}),
+ body: "data=#{JSON.dump({username: username, password: password})}"
+ )
+
+ if response.status == 200
+ user_data = JSON.parse(response.body, symbolize_names: true)
+
+ return false if user_data[:error]
+
+ user_details = W3DHUB_API_CONNECTION.post(
+ path: "apis/w3dhub/1/get-user-details",
+ headers: DEFAULT_HEADERS.merge({"Content-Type": "application/x-www-form-urlencoded"}),
+ body: "data=#{JSON.dump({ id: user_data[:userid] })}"
+ )
+
+ if user_details.status == 200
+ user_details_data = JSON.parse(user_details.body, symbolize_names: true)
+ end
+
+ return Account.new(user_data, user_details_data)
+ else
+ false
+ end
end
# /apis/launcher/1/user-login
diff --git a/lib/api/account.rb b/lib/api/account.rb
new file mode 100644
index 0000000..ce78dbf
--- /dev/null
+++ b/lib/api/account.rb
@@ -0,0 +1,26 @@
+class W3DHub
+ class Api
+ class Account
+ attr_reader :id, :username, :displayname, :avatar_uri, :user_level, :session_token,
+ :access_token, :access_token_expiry, :refresh_token, :studio_user_level
+
+ def initialize(account, user_details)
+ @data = account
+
+ @id = @data[:userid]
+ @username = @data[:username]
+ @displayname = @data[:displayname]
+
+ @avatar_uri = user_details[:"avatar-uri"]
+
+ @user_level = @data[:userlevel]
+ @session_token = @data[:"session-token"]
+ @access_token = @data[:accessToken]
+ @access_token_expiry = Time.at(@data[:accessTokenExpiry])
+ @refresh_token = @data[:refreshToken]
+
+ @studio_user_level = @data[:"studio-userlevel"] # Dunno?
+ end
+ end
+ end
+end
diff --git a/lib/pages/download_manager.rb b/lib/pages/download_manager.rb
index 91d8a95..a983858 100644
--- a/lib/pages/download_manager.rb
+++ b/lib/pages/download_manager.rb
@@ -35,12 +35,12 @@ class W3DHub
# Available to download
stack(width: 1.0, height: 0.8, padding: 8, scroll: true) do
- [W3DHub::Game.games + W3DHub::Game.games].flatten.each_with_index do |game, i|
+ @host.applications.games.reject { |g| g.id == "ren" }.each_with_index do |game, i|
flow(width: 1.0, height: 64, padding: 8) do
background 0xff_333333 if i.odd?
flow(width: 0.7, height: 1.0) do
- image game.icon, width: 0.1, margin_right: 8
+ image "#{GAME_ROOT_PATH}/media/icons/#{game.id}.png", width: 0.1, margin_right: 8
stack(width: 0.9, height: 1.0) do
title game.name
@@ -49,9 +49,21 @@ class W3DHub
end
flow(width: 0.3, height: 1.0) do
- list_box items: ["Release", "1.7 Beta"]
+ version_selector = list_box items: game.channels.map { |c| c.name }, width: 0.499, enabled: game.channels.count > 1
+ version_selector.subscribe(:changed) do |item|
+ p item.value
+ end
- button "Install"
+ button "Install", width: 0.5 do
+ # Download/verify game-channel manifest
+ # Download broken/missing files
+ # Unpack
+ # Configure
+ # Disable install
+ # Enable Uninstall
+
+ get
+ end
end
end
end
diff --git a/lib/pages/games.rb b/lib/pages/games.rb
index c1e44c0..f9ce83e 100644
--- a/lib/pages/games.rb
+++ b/lib/pages/games.rb
@@ -172,8 +172,10 @@ class W3DHub
stack(width: 0.6, height: 1.0) do
stack(width: 1.0, height: 112) do
- para "#{item.title}"
- inscription "#{item.blurb.strip[0..180]}"
+ link "#{item.title}", text_size: 18 do
+ Launchy.open(item.uri)
+ end
+ inscription item.blurb.gsub(/\n+/, "\n").strip[0..180]
end
flow(width: 1.0) do
diff --git a/lib/pages/login.rb b/lib/pages/login.rb
index 032d509..60dc076 100644
--- a/lib/pages/login.rb
+++ b/lib/pages/login.rb
@@ -37,11 +37,41 @@ class W3DHub
# Do network stuff
Thread.new do
- sleep 0.2
+ account = Api.user_login(@username.value, @password.value)
- main_thread_queue << proc { populate_account_info; page(W3DHub::Pages::Games) }
+ if account
+ @host.account = account
+
+ ext = File.basename(account.avatar_uri).split(".").last
+ path = "#{CACHE_PATH}/#{Digest::SHA2.hexdigest(account.avatar_uri)}.#{ext}"
+
+ unless File.exist?(path)
+ response = Excon.get(account.avatar_uri)
+
+ if response.status == 200
+ File.open(path, "wb") do |f|
+ f.write(response.body)
+ end
+ end
+ end
+
+ main_thread_queue << proc { populate_account_info; page(W3DHub::Pages::Games) }
+ else
+ # An error occurred, enable account entry
+ # FIXME: Show an error message
+ # NOTE: Too many incorrect entries causes lock out (Unknown duration)
+ main_thread_queue << proc do
+ @username.enabled = true
+ @password.enabled = true
+ btn.enabled = true
+
+ @error_label.value = "Incorrect username or password.\nOr too many failed login attempts."
+ end
+ end
end
end
+
+ @error_label = caption "", width: 1.0, text_align: :center, color: 0xff_800000
end
end
end
@@ -52,15 +82,19 @@ class W3DHub
@host.instance_variable_get(:"@account_container").clear do
stack(width: 0.7, height: 1.0) do
# background 0xff_222222
- tagline "#{@username.value}"
+ tagline "#{@host.account.username}"
flow(width: 1.0) do
link("Logout", text_size: 16) { depopulate_account_info }
- link "Profile", text_size: 16
+ link "Profile", text_size: 16 do
+ Launchy.open("https://secure.w3dhub.com/forum/index.php?showuser=#{@host.account.id}")
+ end
end
end
- image "#{GAME_ROOT_PATH}/media/ui_icons/singleplayer.png", height: 1.0
+ ext = File.basename(@host.account.avatar_uri).split(".").last
+ path = "#{CACHE_PATH}/#{Digest::SHA2.hexdigest(@host.account.avatar_uri)}.#{ext}"
+ image path, height: 1.0
end
end
@@ -72,7 +106,9 @@ class W3DHub
flow(width: 1.0) do
link("Log in", text_size: 16) { page(W3DHub::Pages::Login) }
- link "Register", text_size: 16
+ link "Register", text_size: 16 do
+ Launchy.open("https://secure.w3dhub.com/forum/index.php?app=core&module=global§ion=register")
+ end
end
end
end
diff --git a/lib/states/interface.rb b/lib/states/interface.rb
index 9625e33..2ce7cb4 100644
--- a/lib/states/interface.rb
+++ b/lib/states/interface.rb
@@ -2,12 +2,12 @@ class W3DHub
class States
class Interface < CyberarmEngine::GuiState
attr_reader :main_thread_queue
- attr_accessor :refresh_token, :service_status, :applications
+ attr_accessor :account, :service_status, :applications
def setup
window.show_cursor = true
- @refresh_token = @options[:refresh_token]
+ @account = @options[:account]
@service_status = @options[:service_status]
@applications = @options[:applications]
@@ -92,7 +92,6 @@ class W3DHub
button(
get_image("#{GAME_ROOT_PATH}/media/ui_icons/import.png"),
- enabled: false,
tip: "Download Manager",
image_height: 1.0,
padding_left: 4,
@@ -115,7 +114,9 @@ class W3DHub
flow(width: 1.0) do
link("Log in", text_size: 16) { page(W3DHub::Pages::Login) }
- link "Register", text_size: 16
+ link "Register", text_size: 16 do
+ Launchy.open("https://secure.w3dhub.com/forum/index.php?app=core&module=global§ion=register")
+ end
end
end
end
diff --git a/w3dhub.rb b/w3dhub.rb
index 83fc1ae..bd0de69 100644
--- a/w3dhub.rb
+++ b/w3dhub.rb
@@ -20,6 +20,7 @@ require_relative "lib/api/service_status"
require_relative "lib/api/applications"
require_relative "lib/api/news"
require_relative "lib/api/server_list_server"
+require_relative "lib/api/account"
# require_relative "lib/game"
# require_relative "lib/games/renegade"