11 Commits

10 changed files with 238 additions and 40 deletions

View File

@@ -10,13 +10,70 @@ module W3DHubLauncher
end
stack(style_class: [:dialog_container]) do
button "Sign In", tip: "https://sso.w3d.cyberarm.dev" do
# use SSO service
pop_state
title "Sign in with your W3D Hub forum account", margin_bottom: PADDING
tagline "Username"
@username = edit_line "", width: 1.0
tagline "Password"
@password = edit_line "", type: :password, width: 1.0
flow(width: 1.0, margin_top: LARGE_PADDING, margin_bottom: LARGE_PADDING) do
flow(fill: true, height: 2, v_align: :center, background: 0xff_000000)
tagline "OR", margin_left: HALF_PADDING, margin_right: HALF_PADDING
flow(fill: true, height: 2, v_align: :center, background: 0xff_000000)
end
tagline "Sign in with access token"
flow(width: 1.0) do
edit_line "", fill: true, enabled: false
button "Get token", tip: "https://sso.w3d.cyberarm.dev/account/token", enabled: false
end
end
flow(width: 1.0, padding: PADDING, background_nine_slice: NINE_SLICE_ROUNDED_BOTTOM, background_nine_slice_from_edge: NINE_SLICE_EDGE, background_nine_slice_color: 0) do
button "Cancel" do
pop_state
end
flow(fill: true)
button "Register", tip: "https://w3dhub.com/forum/register/" do
SDL.OpenURL("https://w3dhub.com/forum/register/")
end
flow(fill: true)
button "Sign In", **CTA_BUTTON_THEME do |btn|
# use SSO service, eventually. , tip: "https://sso.w3d.cyberarm.dev"
btn.enabled = false
Worker::Api.user_login(@username.value, @password.value) do |result|
if result.okay?
hash = JSON.parse(result.data)
MemCache[:settings].account = W3DHubLauncher::Worker::Api::Settings::Account.new(hash)
Worker::Api.update_settings(MemCache[:settings]) do |settings_result|
if settings_result.okay?
on_main_thread(-> {
pop_state
window.current_state&.populate_account_information
})
end
# FIXME: Retry? Show error? ???
pp settings_result
end
end
# FIXME: Show error message!
pp result
end
end
end
end
end

29
lib/dialogs/asterisk.rb Normal file
View File

@@ -0,0 +1,29 @@
module W3DHubLauncher
class Dialog
class Asterisk < W3DHubLauncher::Dialog
def setup
super
stack(width: 1.0, max_width: 600, height: 1.0, max_height: 600, style_class: [:dialog]) do
flow(width: 1.0, background_nine_slice: NINE_SLICE_ROUNDED_TOP, background_nine_slice_from_edge: NINE_SLICE_EDGE, background_nine_slice_color: 0) do
banner "Direct Connect", width: 1.0, text_align: :center
end
stack(style_class: [:dialog_container]) do
banner "Coming soon!"
end
flow(width: 1.0, padding: PADDING, background_nine_slice: NINE_SLICE_ROUNDED_BOTTOM, background_nine_slice_from_edge: NINE_SLICE_EDGE, background_nine_slice_color: 0) do
flow(fill: true)
button "Close", **CTA_BUTTON_THEME do
pop_state
end
flow(fill: true)
end
end
end
end
end
end

View File

View File

@@ -45,8 +45,8 @@ module W3DHubLauncher
end
end
button(safe_get_image("#{ROOT_PATH}/media/icons/target.png"), image_height: 1.0, tip: "Direct Connect", padding: HALF_PADDING, enabled: false, margin_left: PADDING) do
dialog(Dialog::DirectConnect)
button(safe_get_image("#{ROOT_PATH}/media/icons/target.png"), image_height: 1.0, tip: "Direct Connect", padding: HALF_PADDING, margin_left: PADDING) do
dialog(Dialog::Asterisk)
end
end
@@ -101,7 +101,7 @@ module W3DHubLauncher
# TODO: Sort servers?
end
def handle_game_server_list
def handle_game_server_list(payload)
after(1_000) do
populate_server_list
end
@@ -191,7 +191,9 @@ module W3DHubLauncher
end
w.subscribe(:clicked_left_mouse_button) do
@parent.populate_server_information(server)
current_server = (MemCache[:servers] || []).find { |s| s.id == server.id }
@parent.populate_server_information(current_server)
end
end
end

View File

@@ -38,10 +38,11 @@ module W3DHubLauncher
link("GAMES",height: 1.0, text_v_align: :center, font: FONT_BLACK, margin_left: PADDING) { page(Page::Games) }
link("SERVERS",height: 1.0, text_v_align: :center, font: FONT_BLACK, margin_left: PADDING) { page(Page::ServerBrowser) }
stack(fill: true)
image safe_get_image("#{ROOT_PATH}/media/icons/import.png"), height: 40, color: 0xff_bbbbbb, tip: "Downloads" do |img|
dialog(Dialog::Downloads)
stack(v_align: :center) do
button safe_get_image("#{ROOT_PATH}/media/icons/import.png"), image_height: 40, color: 0xff_bbbbbb, padding_left: QUARTER_PADDING, padding_right: QUARTER_PADDING, tip: "Downloads" do |img|
dialog(Dialog::Downloads)
end
end
image safe_get_image("#{ROOT_PATH}/media/icons/information.png"), height: 40, color: 0xff_bbbbbb, tip: "Notifications"
end
# application task status bar container
@application_task_status_bar_container = stack(width: 1.0, fill: true, margin_left: PADDING, visible: false) do
@@ -56,32 +57,8 @@ module W3DHubLauncher
# self account container
@account_container = flow(width: 400, height: 80, margin_left: LARGE_PADDING) do
# self avatar container
stack(width: 80, height: 1.0, background_image: rounded_avatar(safe_get_image("#{ROOT_PATH}/media/default.png")), tag: :account_avatar) do |i|
i.subscribe(:clicked_left_mouse_button) do
dialog(Dialog::Account)
end
# self online state container
stack(width: 20, height: 20, v_align: :bottom, h_align: :right, background_image: safe_get_image("#{ROOT_PATH}/media/ui/circle_small.png"), background_image_color: 0xff_26a269, tag: :account_online_state)
end
stack(fill: true, height: 1.0, margin_left: HALF_PADDING) do
flow(fill: true)
# self name
caption "cyberarm", font: FONT_BLACK, text_wrap: :none, width: 1.0, tag: :account_name
# self set online state
link "Online ▼", text_size: 18 do |l|
menu(parent: l) do
menu_item("Online")
menu_item("Do Not Disturb")
menu_item("Away")
menu_item("Invisible")
menu_item("Sign Out")
end.show
end
flow(fill: true)
end
end
populate_account_information
end
# layout container
@@ -357,6 +334,65 @@ module W3DHubLauncher
composite.save(path)
end
def populate_account_information
account = MemCache[:settings].account
avatar_path = account ? "#{CACHE_PATH}/avatar_#{account&.user_id}#{File.extname(account&.avatar_uri)}" : nil
@account_container.clear do
# self avatar container
stack(width: 80, height: 1.0, background_image: rounded_avatar(safe_get_image(avatar_path || "#{ROOT_PATH}/media/default.png")), tag: :account_avatar) do
# self online state container
stack(
width: 20,
height: 20,
v_align: :bottom,
h_align: :right,
background_image: safe_get_image("#{ROOT_PATH}/media/ui/circle_small.png"),
background_image_color: 0xff_77767b,
tag: :account_online_state
) do
if account.signed_in?
image safe_get_image("#{ROOT_PATH}/media/ui/circle_small.png"), width: 1.0, height: 1.0, color: 0xff_26a269, padding: 1
end
end
end
stack(fill: true, height: 1.0, margin_left: HALF_PADDING) do
flow(fill: true)
# self name
caption account.signed_in? ? account.displayname : MemCache[:settings].preferences.nickname, font: FONT_BLACK, text_wrap: :none, width: 1.0, tag: :account_name
if account.signed_in?
# self set online state
link "Online ▼", text_size: 18 do |l|
menu(parent: l) do
menu_item("Online")
menu_item("Do Not Disturb")
menu_item("Away")
menu_item("Invisible")
menu_item("Sign Out") do
# sign out
end
end.show
end
else
button "Sign In", text_size: 18 do
dialog(Dialog::Account)
end
end
flow(fill: true)
end
end
if account && !account.avatar_uri.empty?
img = find_element_by_tag(@account_container, :account_avatar)
remote_image(avatar_path, url: account.avatar_uri, element: img) do |e, path|
e&.background_image = rounded_avatar(safe_get_image(path))
end
end
end
def button_up(id)
super

View File

@@ -2,6 +2,7 @@ module W3DHubLauncher
LARGE_PADDING = 40
PADDING = 20
HALF_PADDING = 10
QUARTER_PADDING = 5
ALPHA_BLACK = 0x88_000000
ALPHA_GRAY = 0x88_5e5c64

View File

@@ -200,6 +200,9 @@ module W3DHubLauncher
msg = [8, 0, 0, 0, sequence_id].flatten.pack("C2n2A64")
echo_requests[sequence_id] = { send_time: Time.now, address: server_address, replied: false }
socket.send(msg, 0, address)
rescue Errno::ENETUNREACH
# network was unreachable, cleanup
echo_requests.delete(sequence_id)
end
# Receive replies until timeout
@@ -372,7 +375,7 @@ module W3DHubLauncher
content_length: content_length
})
message_requester(query.request_id, Request::STATUS_IN_PROGRESS, progress_result.data, progress_result.error)
message_requester(request_id: query.request_id, status: Request::STATUS_IN_PROGRESS, data: progress_result.data, error: progress_result.error)
end
end
@@ -516,6 +519,10 @@ module W3DHubLauncher
FileUtils.mkdir_p(W3DHubLauncher::CONFIG_PATH)
File.write(W3DHubLauncher::SETTINGS_FILE_PATH, query.data)
if @settings&.account&.signed_in?
@w3dhub_api.access_token = @settings.account.access_token
end
result.data = query.data
rescue => e
result.error = e

View File

@@ -30,6 +30,14 @@ module W3DHubLauncher
def self.account
end
def self.user_login(username, password, &block)
W3DHubLauncher::Worker::Request.new(:w3dhub_api_call, { call: :user_login, arguments: [username, password] }, &block)
end
def self.refresh_user_login(refresh_token, &block)
W3DHubLauncher::Worker::Request.new(:w3dhub_api_call, { call: :refresh_user_login, arguments: [refresh_token] }, &block)
end
# returns launcher settings
def self.settings
end

View File

@@ -8,6 +8,8 @@ module W3DHubLauncher
attr_reader :applications
attr_writer :access_token
def initialize
@access_token = nil
@@ -91,16 +93,71 @@ module W3DHubLauncher
result
end
def user_login()
def user_login(username, password)
result = CyberarmEngine::Result.new
body = URI.encode_www_form("data": JSON.dump({username: username, password: password}))
response = fetch("#{PRIMARY_W3DHUB_API_ENDPOINT}/apis/launcher/1/user-login", method: :post, body: body, headers: headers(form_encoded: true))
if response.okay?
hash = JSON.parse(response.data)
user_details_result = fetch_user_details(Integer(hash["userid"]))
user_details_hash = user_details_result.okay? ? JSON.parse(user_details_result.data) : {}
account = W3DHubLauncher::Worker::Api::Settings::Account.create(
user_id: hash["userid"],
username: hash["username"],
displayname: hash["displayname"],
avatar_uri: user_details_hash["avatar-uri"] || "",
access_token: hash["accessToken"],
refresh_token: hash["refreshToken"],
access_token_expiration_time: hash["accessTokenExpiry"]
)
result.data = account.to_json
end
result
end
def refresh_user_login()
def refresh_user_login(refresh_token)
result = CyberarmEngine::Result.new
body = URI.encode_www_form("data": JSON.dump({refreshToken: refresh_token}))
response = fetch("#{PRIMARY_W3DHUB_API_ENDPOINT}/apis/launcher/1/user-login", method: :post, body: body, headers: headers(form_encoded: true))
if response.okay?
hash = JSON.parse(response.data)
user_details_result = fetch_user_details(Integer(hash["userid"]))
user_details_hash = user_details_result.okay? ? JSON.parse(user_details_result.data) : {}
account = W3DHubLauncher::Worker::Api::Settings::Account.create(
user_id: hash["userid"],
username: hash["username"],
displayname: hash["displayname"],
avatar_uri: user_details_hash["avatar-uri"] || "",
access_token: hash["accessToken"],
refresh_token: hash["refreshToken"],
access_token_expiration_time: hash["accessTokenExpiry"]
)
result.data = account.to_json
end
result
end
def fetch_user_details()
def fetch_user_details(user_id)
result = CyberarmEngine::Result.new
body = URI.encode_www_form("data": JSON.dump({id: user_id}))
response = fetch("#{PRIMARY_W3DHUB_API_ENDPOINT}/apis/w3dhub/1/get-user-details", method: :post, body: body, headers: headers(form_encoded: true))
result.data = response.data if response.okay?
result
end
def fetch_applications
@@ -145,7 +202,7 @@ module W3DHubLauncher
fetch("#{PRIMARY_W3DHUB_API_ENDPOINT}/apis/w3dhub/1/get-server-events", method: :post, body: "data={\"serverPath\":\"#{category}\"}", headers: headers(form_encoded: true))
end
def fetch_test_events(category)
def fetch_test_events
fetch("#{PRIMARY_W3DHUB_API_ENDPOINT}/apis/w3dhub/1/get-testing-times")
end

View File

@@ -44,6 +44,7 @@ require_relative "lib/dialogs/account"
require_relative "lib/dialogs/import_application"
require_relative "lib/dialogs/launcher_settings"
require_relative "lib/dialogs/application_settings"
require_relative "lib/dialogs/asterisk"
require_relative "lib/states/boot"
require_relative "lib/states/interface"
require_relative "lib/window"