mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-18 18:02:34 +00:00
Compare commits
2 Commits
3ca8ab656f
...
d7533a18a9
| Author | SHA1 | Date | |
|---|---|---|---|
| d7533a18a9 | |||
| 014de7c6aa |
111
lib/asterisk/irc_client.rb
Normal file
111
lib/asterisk/irc_client.rb
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
require "socket"
|
||||||
|
require "openssl"
|
||||||
|
require "ircparser"
|
||||||
|
|
||||||
|
require_relative "irc_profile"
|
||||||
|
|
||||||
|
class W3DHub
|
||||||
|
class Asterisk
|
||||||
|
class IRCClient
|
||||||
|
class SSL
|
||||||
|
def self.default_context
|
||||||
|
verify_peer_and_hostname
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.verify_peer_and_hostname
|
||||||
|
verify_peer.tap do |context|
|
||||||
|
context.verify_hostname = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.verify_peer
|
||||||
|
no_verify.tap do |context|
|
||||||
|
context.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
||||||
|
context.cert_store = OpenSSL::X509::Store.new.tap(&:set_default_paths)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.verify_hostname_only
|
||||||
|
no_verify.tap do |context|
|
||||||
|
context.verify_hostname = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.no_verify
|
||||||
|
OpenSSL::SSL::SSLContext.new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
attr_reader :status
|
||||||
|
|
||||||
|
def initialize(irc_profile = nil)
|
||||||
|
@irc_profile = irc_profile
|
||||||
|
|
||||||
|
socket = dial(
|
||||||
|
@irc_profile.server_hostname,
|
||||||
|
@irc_profile.server_port,
|
||||||
|
ssl_context: irc_profile.server_ssl ? irc_profile.server_verify_ssl ? SSL.default_context : SSL.no_verify : false
|
||||||
|
)
|
||||||
|
|
||||||
|
authenticate_with_brenbot!(socket)
|
||||||
|
ensure
|
||||||
|
socket&.close
|
||||||
|
end
|
||||||
|
|
||||||
|
def dial(hostname, port = 6697, local_host: nil, local_port: nil, ssl_context: SSL.default_context)
|
||||||
|
Socket.tcp(hostname, port, local_host, local_port).then do |socket|
|
||||||
|
if ssl_context
|
||||||
|
ssl_context = SSL.send(ssl_context) if ssl_context.is_a? Symbol
|
||||||
|
|
||||||
|
OpenSSL::SSL::SSLSocket.new(socket, ssl_context).tap do |ssl_socket|
|
||||||
|
ssl_socket.hostname = hostname
|
||||||
|
ssl_socket.connect
|
||||||
|
end
|
||||||
|
else
|
||||||
|
socket
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def authenticate_with_brenbot!(socket)
|
||||||
|
pp @irc_profile, "#{@irc_profile.nickname}!#{@irc_profile.username.split("/").first}"
|
||||||
|
# exit
|
||||||
|
|
||||||
|
pass = IRCParser::Message.new(command: "PASS", parameters: [@irc_profile.password])
|
||||||
|
user = IRCParser::Message.new(command: "USER", parameters: [@irc_profile.username, "0", "*", ":#{@irc_profile.nickname}"])
|
||||||
|
nick = IRCParser::Message.new(command: "NICK", parameters: [@irc_profile.nickname])
|
||||||
|
|
||||||
|
socket.puts(pass)
|
||||||
|
socket.puts(user)
|
||||||
|
socket.puts(nick)
|
||||||
|
|
||||||
|
pp socket
|
||||||
|
socket.flush
|
||||||
|
|
||||||
|
until socket.closed?
|
||||||
|
raw = socket.gets
|
||||||
|
next if raw.to_s.empty?
|
||||||
|
|
||||||
|
msg = IRCParser::Message.parse(raw)
|
||||||
|
|
||||||
|
if msg.command == "PING"
|
||||||
|
pong = IRCParser::Message.new(command: "PONG", parameters: [msg.parameters.first.sub("\r\n", "")])
|
||||||
|
socket.puts("#{pong}")
|
||||||
|
socket.flush
|
||||||
|
elsif msg.command == "001" && msg.parameters.join.include?("#{@irc_profile.nickname}!#{@irc_profile.username.split("/").first}")
|
||||||
|
pm = IRCParser::Message.new(command: "PRIVMSG", parameters: [@irc_profile.server_bot, "!auth #{@irc_profile.bot_auth_username} password"])
|
||||||
|
socket.puts(pm)
|
||||||
|
|
||||||
|
quit = IRCParser::Message.new(command: "QUIT", parameters: ["Quiting from an Asterisk"])
|
||||||
|
socket.puts(quit)
|
||||||
|
socket.flush
|
||||||
|
|
||||||
|
socket.close
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
W3DHub::Asterisk::IRCClient.new
|
||||||
@@ -21,17 +21,17 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
|
|
||||||
stack(width: 1.0, fill: true, padding_left: 8, padding_right: 8) do
|
stack(width: 1.0, fill: true, padding_left: 8, padding_right: 8) do
|
||||||
stack(width: 1.0, height: 60) do
|
stack(width: 1.0, height: 66) do
|
||||||
para "Game or Mod Title:"
|
para "Game or Mod Title:"
|
||||||
@game_title = edit_line "#{@game&.title}", width: 1.0
|
@game_title = edit_line "#{@game&.title}", width: 1.0, fill: true
|
||||||
end
|
end
|
||||||
|
|
||||||
stack(width: 1.0, height: 60) do
|
stack(width: 1.0, height: 66) do
|
||||||
para "Path to Executable:"
|
para "Path to Executable:"
|
||||||
|
|
||||||
flow(width: 1.0) do
|
flow(width: 1.0, fill: true) do
|
||||||
@game_path = edit_line "#{@game&.path}", width: 0.749
|
@game_path = edit_line "#{@game&.path}", fill: true, height: 1.0
|
||||||
button "Browse...", width: 0.25, enabled: W3DHub.unix?, tip: W3DHub.unix? ? "Browse for game executable" : "Not available on Windows" do
|
button "Browse...", width: 128, height: 1.0, enabled: W3DHub.unix?, tip: W3DHub.unix? ? "Browse for game executable" : "Not available on Windows" do
|
||||||
path = W3DHub.ask_file
|
path = W3DHub.ask_file
|
||||||
@game_path.value = path if !path.empty? && File.exist?(path)
|
@game_path.value = path if !path.empty? && File.exist?(path)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,70 +15,62 @@ class W3DHub
|
|||||||
background 0x88_000000
|
background 0x88_000000
|
||||||
|
|
||||||
# tagline "<b>#{I18n.t(:"server_browser.direct_connect")}</b>", fill: true, text_align: :center
|
# tagline "<b>#{I18n.t(:"server_browser.direct_connect")}</b>", fill: true, text_align: :center
|
||||||
tagline @profile ? "Update IRC Profile" : "Add IRC Profile", width: 1.0, text_align: :center
|
tagline @profile ? "Update IRC Profile" : "Add IRC Profile", width: 1.0, fill: true, text_align: :center
|
||||||
end
|
end
|
||||||
|
|
||||||
stack(width: 1.0, fill: true, padding_left: 8, padding_right: 8) do
|
stack(width: 1.0, fill: true, padding_left: 8, padding_right: 8) do
|
||||||
stack(width: 1.0, height: 60) do
|
stack(width: 1.0, height: 66) do
|
||||||
para "IRC Nickname:"
|
para "IRC Nickname:"
|
||||||
@irc_nickname = edit_line "#{@profile&.nickname}", width: 1.0
|
@nickname = edit_line "#{@profile&.nickname}", width: 1.0, fill: true
|
||||||
end
|
end
|
||||||
|
|
||||||
stack(width: 1.0, height: 60) do
|
stack(width: 1.0, height: 66) do
|
||||||
flow(width: 1.0, height: 1.0) do
|
flow(width: 1.0, height: 1.0) do
|
||||||
stack(width: 0.5, height: 1.0) do
|
stack(width: 0.5, height: 1.0) do
|
||||||
para "IRC Username:"
|
para "IRC Username (Optional):"
|
||||||
@irc_username = edit_line "#{@profile&.username}", width: 1.0
|
@username = edit_line "#{@profile&.username}", width: 1.0, fill: true
|
||||||
end
|
end
|
||||||
|
|
||||||
stack(width: 0.5, height: 1.0) do
|
stack(width: 0.5, height: 1.0) do
|
||||||
para "IRC Server Password:"
|
para "IRC Server Password (Optional):"
|
||||||
@irc_password = edit_line @profile ? Base64.strict_decode64(@profile.password) : "", width: 1.0, type: :password
|
@password = edit_line @profile ? Base64.strict_decode64(@profile.password) : "", width: 1.0, fill: true, type: :password
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
stack(width: 1.0, height: 60) do
|
stack(width: 1.0, height: 66, margin_top: 32) do
|
||||||
flow(width: 1.0, height: 1.0) do
|
flow(width: 1.0, height: 1.0) do
|
||||||
stack(width: 0.75, height: 1.0) do
|
stack(width: 0.75, height: 1.0) do
|
||||||
para "IRC Server IP or Hostname:"
|
para "IRC Server IP or Hostname:"
|
||||||
@irc_hostname = edit_line "#{@profile&.server_hostname}", width: 1.0
|
@server_hostname = edit_line "#{@profile&.server_hostname}", width: 1.0, fill: true
|
||||||
end
|
end
|
||||||
|
|
||||||
stack(width: 0.249, height: 1.0) do
|
stack(width: 0.249, height: 1.0) do
|
||||||
para "IRC Server Port:"
|
para "IRC Server Port:"
|
||||||
@irc_port = edit_line "#{@profile&.server_port || '6667'}", width: 1.0
|
@server_port = edit_line "#{@profile&.server_port || '6667'}", width: 1.0, fill: true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
flow(width: 1.0, height: 60, margin_top: 8) do
|
flow(width: 1.0, height: 66, margin_top: 8) do
|
||||||
flow(width: 0.5, height: 60) do
|
@server_ssl = check_box "IRC Server Use SSL", checked: @profile&.server_ssl, text_size: 18, width: 0.5, height: 66
|
||||||
para "IRC Server Use SSL:", margin_top: 8
|
@server_verify_ssl = check_box "IRC Verify Server SSL Certificate", checked: @profile ? @profile.server_verify_ssl : true, text_size: 18, width: 0.5, height: 66
|
||||||
@irc_bot = check_box "#{@profile&.server_bot}"
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
flow(width: 0.5, height: 60) do
|
|
||||||
para "IRC Verify Server SSL Certificate:", margin_top: 8
|
|
||||||
@irc_bot = check_box "#{@profile&.server_bot}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
stack(width: 1.0, height: 60, margin_top: 32) do
|
stack(width: 1.0, height: 66) do
|
||||||
para "Brenbot Bot Name:"
|
para "Brenbot Bot Name:"
|
||||||
@irc_bot = edit_line "#{@profile&.server_bot}", width: 1.0
|
@bot_username = edit_line "#{@profile&.bot_username}", width: 1.0, fill: true
|
||||||
end
|
end
|
||||||
|
|
||||||
flow(width: 1.0, height: 60) do
|
flow(width: 1.0, height: 66) do
|
||||||
stack(width: 0.5, height: 60) do
|
stack(width: 0.5, height: 66) do
|
||||||
para "Brenbot Auth Username:"
|
para "Brenbot Auth Username:"
|
||||||
@irc_bot = edit_line "#{@profile&.server_bot}", width: 1.0
|
@bot_auth_username = edit_line "#{@profile&.bot_auth_username}", width: 1.0, fill: true
|
||||||
end
|
end
|
||||||
|
|
||||||
stack(width: 0.5, height: 60) do
|
stack(width: 0.5, height: 66) do
|
||||||
para "Brenbot Auth Password:"
|
para "Brenbot Auth Password:"
|
||||||
@irc_password = edit_line @profile ? Base64.strict_decode64(@profile.password) : "", width: 1.0, type: :password
|
@bot_auth_password = edit_line @profile ? Base64.strict_decode64(@profile.bot_auth_password) : "", width: 1.0, fill: true, type: :password
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -95,11 +87,16 @@ class W3DHub
|
|||||||
pop_state
|
pop_state
|
||||||
@options[:save_callback].call(
|
@options[:save_callback].call(
|
||||||
@profile,
|
@profile,
|
||||||
@irc_nickname.value,
|
@nickname.value,
|
||||||
@irc_password.value,
|
@username.value,
|
||||||
@irc_hostname.value,
|
@password.value,
|
||||||
@irc_port.value,
|
@server_hostname.value,
|
||||||
@irc_bot.value
|
@server_port.value,
|
||||||
|
@server_ssl.value,
|
||||||
|
@server_verify_ssl.value,
|
||||||
|
@bot_username.value,
|
||||||
|
@bot_auth_username.value,
|
||||||
|
@bot_auth_password.value
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -132,18 +129,19 @@ class W3DHub
|
|||||||
|
|
||||||
def valid?
|
def valid?
|
||||||
generated_name = IRCProfileForm.generate_profile_name(
|
generated_name = IRCProfileForm.generate_profile_name(
|
||||||
@irc_nickname.value,
|
@nickname.value,
|
||||||
@irc_hostname.value,
|
@server_hostname.value,
|
||||||
@irc_port.value,
|
@server_port.value,
|
||||||
@irc_bot.value
|
@bot_username.value
|
||||||
)
|
)
|
||||||
existing_profile = W3DHub::Store[:asterisk_config].irc_profiles.find { |profile| profile.name == generated_name }
|
existing_profile = W3DHub::Store[:asterisk_config].irc_profiles.find { |profile| profile.name == generated_name }
|
||||||
|
|
||||||
@irc_nickname.value.length.positive? &&
|
@nickname.value.length.positive? &&
|
||||||
@irc_password.value.length.positive? && # May be optional?
|
@server_hostname.value.length.positive? &&
|
||||||
@irc_hostname.value.length.positive? &&
|
@server_port.value.length.positive? &&
|
||||||
@irc_port.value.length.positive? &&
|
@bot_username.value.length.positive? &&
|
||||||
@irc_bot.value.length.positive?
|
@bot_auth_username.value.length.positive? &&
|
||||||
|
@bot_auth_password.value.length.positive?
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.generate_profile_name(nickname, hostname, port, bot)
|
def self.generate_profile_name(nickname, hostname, port, bot)
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
|
|
||||||
stack(width: 1.0, fill: true, padding_left: 8, padding_right: 8) do
|
stack(width: 1.0, fill: true, padding_left: 8, padding_right: 8) do
|
||||||
stack(width: 1.0, height: 65) do
|
stack(width: 1.0, height: 66) do
|
||||||
para "Server Profile Name:"
|
para "Server Profile Name:"
|
||||||
@server_name = edit_line "#{@server_profile&.name}", width: 1.0
|
@server_name = edit_line "#{@server_profile&.name}", width: 1.0, fill: true
|
||||||
@server_name.subscribe(:changed) do |label|
|
@server_name.subscribe(:changed) do |label|
|
||||||
@save_button.enabled = label.value.length.positive?
|
@save_button.enabled = label.value.length.positive?
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class W3DHub
|
|||||||
|
|
||||||
background 0xee_444444
|
background 0xee_444444
|
||||||
|
|
||||||
stack(width: 1.0, max_width: 720, height: 1.0, max_height: 512, v_align: :center, h_align: :center, background: 0xee_222222) do
|
stack(width: 1.0, max_width: 720, height: 1.0, max_height: 540, v_align: :center, h_align: :center, background: 0xee_222222) do
|
||||||
# Title bar
|
# Title bar
|
||||||
flow(width: 1.0, height: 32, padding: 8) do
|
flow(width: 1.0, height: 32, padding: 8) do
|
||||||
background 0x88_000000
|
background 0x88_000000
|
||||||
@@ -20,7 +20,7 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
|
|
||||||
stack(width: 1.0, fill: true, scroll: true) do
|
stack(width: 1.0, fill: true, scroll: true) do
|
||||||
stack(width: 1.0, height: 60, margin_left: 8, margin_right: 8) do
|
stack(width: 1.0, height: 66, margin_left: 8, margin_right: 8) do
|
||||||
para "Server profiles", text_align: :center, width: 1.0
|
para "Server profiles", text_align: :center, width: 1.0
|
||||||
|
|
||||||
flow(width: 1.0, fill: true) do
|
flow(width: 1.0, fill: true) do
|
||||||
@@ -51,7 +51,7 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
|
|
||||||
stack(width: 1.0, fill: true, margin_top: 8, padding: 8, border_color: 0xff_111111, border_thickness: 1) do
|
stack(width: 1.0, fill: true, margin_top: 8, padding: 8, border_color: 0xff_111111, border_thickness: 1) do
|
||||||
flow(width: 1.0, height: 60) do
|
flow(width: 1.0, height: 66) do
|
||||||
stack(width: 0.5, height: 1.0) do
|
stack(width: 0.5, height: 1.0) do
|
||||||
para "Nickname:"
|
para "Nickname:"
|
||||||
@server_nickname = edit_line "", width: 1.0, fill: true
|
@server_nickname = edit_line "", width: 1.0, fill: true
|
||||||
@@ -73,7 +73,7 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
flow(width: 1.0, height: 60) do
|
flow(width: 1.0, height: 66) do
|
||||||
stack(width: 0.5, height: 1.0) do
|
stack(width: 0.5, height: 1.0) do
|
||||||
para "Server IP or Hostname:"
|
para "Server IP or Hostname:"
|
||||||
@server_hostname = edit_line "", width: 1.0, fill: true
|
@server_hostname = edit_line "", width: 1.0, fill: true
|
||||||
@@ -95,7 +95,7 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
stack(width: 1.0, height: 60) do
|
stack(width: 1.0, height: 66) do
|
||||||
para "Game or Mod:"
|
para "Game or Mod:"
|
||||||
|
|
||||||
flow(width: 1.0, fill: true) do
|
flow(width: 1.0, fill: true) do
|
||||||
@@ -124,7 +124,7 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
stack(width: 1.0, height: 60) do
|
stack(width: 1.0, height: 66) do
|
||||||
para "Launch arguments (Optional):"
|
para "Launch arguments (Optional):"
|
||||||
@launch_arguments = edit_line "", width: 1.0, fill: true
|
@launch_arguments = edit_line "", width: 1.0, fill: true
|
||||||
@launch_arguments.subscribe(:changed) do |e|
|
@launch_arguments.subscribe(:changed) do |e|
|
||||||
@@ -134,7 +134,7 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
stack(width: 1.0, height: 60) do
|
stack(width: 1.0, height: 66) do
|
||||||
para "IRC Profile:"
|
para "IRC Profile:"
|
||||||
|
|
||||||
flow(width: 1.0, fill: true) do
|
flow(width: 1.0, fill: true) do
|
||||||
@@ -293,24 +293,43 @@ class W3DHub
|
|||||||
@games_list.choose = title
|
@games_list.choose = title
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_irc_profile(updated, nickname, password, hostname, port, bot)
|
def save_irc_profile(
|
||||||
generated_name = Asterisk::States::IRCProfileForm.generate_profile_name(nickname, hostname, port, bot)
|
updated, nickname, username, password,
|
||||||
|
server_hostname, server_port, server_ssl, server_verify_ssl,
|
||||||
|
bot_username, bot_auth_username, bot_auth_password
|
||||||
|
)
|
||||||
|
generated_name = Asterisk::States::IRCProfileForm.generate_profile_name(
|
||||||
|
nickname,
|
||||||
|
server_hostname,
|
||||||
|
server_port,
|
||||||
|
bot_username
|
||||||
|
)
|
||||||
|
|
||||||
if updated
|
if updated
|
||||||
updated.name = generated_name
|
updated.name = generated_name
|
||||||
updated.nickname = nickname
|
updated.nickname = nickname
|
||||||
|
updated.username = username
|
||||||
updated.password = Base64.strict_encode64(password)
|
updated.password = Base64.strict_encode64(password)
|
||||||
updated.server_hostname = hostname
|
updated.server_hostname = hserver_hostname
|
||||||
updated.server_port = port
|
updated.server_port = hserver_port
|
||||||
updated.server_bot = bot
|
updated.server_ssl = server_ssl
|
||||||
|
updated.server_verify_ssl = server_verify_ssl
|
||||||
|
updated.bot_username = bot_username
|
||||||
|
updated.bot_auth_username = bot_auth_username
|
||||||
|
updated.bot_auth_password = Base64.strict_encode64(bot_auth_password)
|
||||||
else
|
else
|
||||||
profile = Asterisk::IRCProfile.new({
|
profile = Asterisk::IRCProfile.new({
|
||||||
name: generated_name,
|
name: generated_name,
|
||||||
nickname: nickname,
|
nickname: nickname,
|
||||||
|
username: username,
|
||||||
password: Base64.strict_encode64(password),
|
password: Base64.strict_encode64(password),
|
||||||
server_hostname: hostname,
|
server_hostname: server_hostname,
|
||||||
server_port: port,
|
server_port: server_port,
|
||||||
server_bot: bot
|
server_ssl: server_ssl,
|
||||||
|
server_verify_ssl: server_verify_ssl,
|
||||||
|
bot_username: bot_username,
|
||||||
|
bot_auth_username: bot_auth_username,
|
||||||
|
bot_auth_password: Base64.strict_encode64(bot_auth_password)
|
||||||
})
|
})
|
||||||
|
|
||||||
W3DHub::Store[:asterisk_config].irc_profiles << profile
|
W3DHub::Store[:asterisk_config].irc_profiles << profile
|
||||||
|
|||||||
Reference in New Issue
Block a user