mirror of
https://github.com/TimeCrafters/timecrafters_configuration_tool_desktop.git
synced 2025-12-15 21:32:35 +00:00
Added socket error storage to client, TACNET UI now semi-functional
This commit is contained in:
@@ -1,26 +1,27 @@
|
|||||||
module TAC
|
module TAC
|
||||||
module Palette
|
module Palette
|
||||||
TACNET_CONNECTED = Gosu::Color.new(0xff008000)
|
TACNET_CONNECTED = Gosu::Color.new(0xff_008000)
|
||||||
TACNET_CONNECTING = Gosu::Color.new(0xffff8800)
|
TACNET_CONNECTING = Gosu::Color.new(0xff_ff8800)
|
||||||
TACNET_CONNECTION_ERROR = Gosu::Color.new(0xff800000)
|
TACNET_CONNECTION_ERROR = Gosu::Color.new(0xff_800000)
|
||||||
|
TACNET_NOT_CONNECTED = Gosu::Color.new(0xff_222222)
|
||||||
|
|
||||||
TIMECRAFTERS_PRIMARY = Gosu::Color.new(0xff008000)
|
TIMECRAFTERS_PRIMARY = Gosu::Color.new(0xff_008000)
|
||||||
TIMECRAFTERS_SECONDARY = Gosu::Color.new(0xff006000)
|
TIMECRAFTERS_SECONDARY = Gosu::Color.new(0xff_006000)
|
||||||
TIMECRAFTERS_TERTIARY = Gosu::Color.new(0xff00d000)
|
TIMECRAFTERS_TERTIARY = Gosu::Color.new(0xff_00d000)
|
||||||
|
|
||||||
TACNET_PRIMARY = Gosu::Color.new(0xff000080)
|
TACNET_PRIMARY = Gosu::Color.new(0xff_000080)
|
||||||
TACNET_SECONDARY = Gosu::Color.new(0xff000060)
|
TACNET_SECONDARY = Gosu::Color.new(0xff_000060)
|
||||||
|
|
||||||
GROUPS_PRIMARY = Gosu::Color.new(0xff444444)
|
GROUPS_PRIMARY = Gosu::Color.new(0xff_444444)
|
||||||
GROUPS_SECONDARY = Gosu::Color.new(0xff444444)
|
GROUPS_SECONDARY = Gosu::Color.new(0xff_444444)
|
||||||
|
|
||||||
ACTIONS_PRIMARY = Gosu::Color.new(0xff4444aa)
|
ACTIONS_PRIMARY = Gosu::Color.new(0xff_4444aa)
|
||||||
ACTIONS_SECONDARY = Gosu::Color.new(0xff040404)
|
ACTIONS_SECONDARY = Gosu::Color.new(0xff_040404)
|
||||||
|
|
||||||
VALUES_PRIMARY = Gosu::Color.new(0xff660066)
|
VALUES_PRIMARY = Gosu::Color.new(0xff_660066)
|
||||||
VALUES_SECONDARY = Gosu::Color.new(0xff440044)
|
VALUES_SECONDARY = Gosu::Color.new(0xff_440044)
|
||||||
|
|
||||||
EDITOR_PRIMARY = Gosu::Color.new(0xff446688)
|
EDITOR_PRIMARY = Gosu::Color.new(0xff_446688)
|
||||||
EDITOR_SECONDARY = Gosu::Color.new(0xff224466)
|
EDITOR_SECONDARY = Gosu::Color.new(0xff_224466)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -50,9 +50,19 @@ module TAC
|
|||||||
end
|
end
|
||||||
|
|
||||||
stack width: 0.499 do
|
stack width: 0.499 do
|
||||||
@tacnet_status = label "Connection Error", background: TAC::Palette::TACNET_CONNECTION_ERROR, text_size: 18, padding: 5, margin_top: 2
|
@tacnet_status = label "Not Connected", background: TAC::Palette::TACNET_NOT_CONNECTED, width: 1.0, text_size: 18, padding: 5, margin_top: 2, border_thickness: 1, border_color: Gosu::Color::GRAY
|
||||||
@tacnet_connection_button = button "Connect", text_size: 18 do
|
flow width: 1.0 do
|
||||||
window.backend.tacnet.connect("localhost")
|
@tacnet_connection_button = button "Connect", width: 0.475, text_size: 18 do
|
||||||
|
case window.backend.tacnet.status
|
||||||
|
when :connected, :connecting
|
||||||
|
window.backend.tacnet.close
|
||||||
|
when :not_connected, :connection_error
|
||||||
|
window.backend.tacnet.connect("localhost")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
button "Status", text_size: 18, width: 0.475 do
|
||||||
|
push_state(Dialog::AlertDialog, title: "TACNET Status", message: window.backend.tacnet.full_status)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -112,6 +122,37 @@ module TAC
|
|||||||
end
|
end
|
||||||
|
|
||||||
populate_groups_list
|
populate_groups_list
|
||||||
|
|
||||||
|
@tacnet_status_monitor = CyberarmEngine::Timer.new(250) do
|
||||||
|
case window.backend.tacnet.status
|
||||||
|
when :connected
|
||||||
|
@tacnet_status.value = "Connected"
|
||||||
|
@tacnet_status.background = TAC::Palette::TACNET_CONNECTED
|
||||||
|
|
||||||
|
@tacnet_connection_button.value = "Disconnect"
|
||||||
|
when :connecting
|
||||||
|
@tacnet_status.value = "Connecting..."
|
||||||
|
@tacnet_status.background = TAC::Palette::TACNET_CONNECTING
|
||||||
|
|
||||||
|
@tacnet_connection_button.value = "Disconnect"
|
||||||
|
when :connection_error
|
||||||
|
@tacnet_status.value = "Connection Error"
|
||||||
|
@tacnet_status.background = TAC::Palette::TACNET_CONNECTION_ERROR
|
||||||
|
|
||||||
|
@tacnet_connection_button.value = "Connect"
|
||||||
|
when :not_connected
|
||||||
|
@tacnet_status.value = "Not Connected"
|
||||||
|
@tacnet_status.background = TAC::Palette::TACNET_NOT_CONNECTED
|
||||||
|
|
||||||
|
@tacnet_connection_button.value = "Connect"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
super
|
||||||
|
|
||||||
|
@tacnet_status_monitor.update
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_group(name)
|
def create_group(name)
|
||||||
|
|||||||
@@ -10,33 +10,66 @@ module TAC
|
|||||||
@connection = nil
|
@connection = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def connect(hostname = DEFAULT_HOSTNAME, port = DEFAULT_PORT, error_callback = proc {})
|
def connect(hostname = DEFAULT_HOSTNAME, port = DEFAULT_PORT)
|
||||||
return if @connection && @connection.connected?
|
return if @connection && @connection.connected?
|
||||||
|
|
||||||
@connection = Connection.new(hostname, port)
|
@connection = Connection.new(hostname, port)
|
||||||
@connection.connect(error_callback)
|
@connection.connect
|
||||||
|
end
|
||||||
|
|
||||||
|
def status
|
||||||
|
if connected?
|
||||||
|
:connected
|
||||||
|
elsif @connection && !@connection.client.socket_error?
|
||||||
|
:connecting
|
||||||
|
elsif @connection && @connection.client.socket_error?
|
||||||
|
:connection_error
|
||||||
|
else
|
||||||
|
:not_connected
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def full_status
|
||||||
|
_status = status.to_s.split("_").map { |c| c.capitalize }.join(" ")
|
||||||
|
|
||||||
|
if connected?
|
||||||
|
net_stats = ""
|
||||||
|
net_stats += "<b>Connection Statistics:</b>\n"
|
||||||
|
net_stats += "<b>Packets Sent:</b> #{client.packets_sent}\n"
|
||||||
|
net_stats += "<b>Packets Received:</b> #{client.packets_received}\n\n"
|
||||||
|
net_stats += "<b>Data Sent:</b> #{client.data_sent} bytes\n"
|
||||||
|
net_stats += "<b>Data Received:</b> #{client.data_received} bytes\n"
|
||||||
|
|
||||||
|
"<b>Status:</b> #{_status}\n\n#{net_stats}"
|
||||||
|
elsif @connection && @connection.client && @connection.client.socket_error?
|
||||||
|
"<b>Status:</b> #{_status}\n\n#{@connection.client.last_socket_error.to_s.chars.each_slice(32).to_a.map { |c| c.join }.join("\n")}"
|
||||||
|
else
|
||||||
|
pp client
|
||||||
|
"<b>Status:</b> #{_status}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def connected?
|
def connected?
|
||||||
@connection && @connection.connected?
|
@connection && @connection.connected?
|
||||||
end
|
end
|
||||||
|
|
||||||
def client
|
def close
|
||||||
if connected?
|
if connected?
|
||||||
@connection.client
|
@connection.close
|
||||||
|
@connection = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def client
|
||||||
|
@connection.client if connected?
|
||||||
|
end
|
||||||
|
|
||||||
def puts(packet)
|
def puts(packet)
|
||||||
if connected?
|
@connection.puts(packet) if connected?
|
||||||
@connection.puts(packet)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def gets
|
def gets
|
||||||
if connected?
|
@connection.gets if connected?
|
||||||
@connection.gets
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -7,7 +7,7 @@ module TAC
|
|||||||
attr_reader :uuid, :read_queue, :write_queue, :socket,
|
attr_reader :uuid, :read_queue, :write_queue, :socket,
|
||||||
:packets_sent, :packets_received,
|
:packets_sent, :packets_received,
|
||||||
:data_sent, :data_received
|
:data_sent, :data_received
|
||||||
attr_accessor :sync_interval
|
attr_accessor :sync_interval, :last_socket_error, :socket_error
|
||||||
def initialize
|
def initialize
|
||||||
@uuid = SecureRandom.uuid
|
@uuid = SecureRandom.uuid
|
||||||
@read_queue = []
|
@read_queue = []
|
||||||
@@ -15,6 +15,10 @@ module TAC
|
|||||||
|
|
||||||
@sync_interval = 100
|
@sync_interval = 100
|
||||||
|
|
||||||
|
@last_socket_error = nil
|
||||||
|
@socket_error = false
|
||||||
|
@bound = false
|
||||||
|
|
||||||
@packets_sent, @packets_received = 0, 0
|
@packets_sent, @packets_received = 0, 0
|
||||||
@data_sent, @data_received = 0, 0
|
@data_sent, @data_received = 0, 0
|
||||||
end
|
end
|
||||||
@@ -25,6 +29,7 @@ module TAC
|
|||||||
|
|
||||||
def socket=(socket)
|
def socket=(socket)
|
||||||
@socket = socket
|
@socket = socket
|
||||||
|
@bound = true
|
||||||
|
|
||||||
listen
|
listen
|
||||||
end
|
end
|
||||||
@@ -82,12 +87,16 @@ module TAC
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def connected?
|
def socket_error?
|
||||||
!closed?
|
@socket_error
|
||||||
end
|
end
|
||||||
|
|
||||||
def bound?
|
def connected?
|
||||||
@socket.bound? if @socket
|
if closed? == true || closed? == nil
|
||||||
|
false
|
||||||
|
else
|
||||||
|
true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def closed?
|
def closed?
|
||||||
@@ -97,7 +106,9 @@ module TAC
|
|||||||
def write(message)
|
def write(message)
|
||||||
begin
|
begin
|
||||||
@socket.puts("#{message}\r\n\n")
|
@socket.puts("#{message}\r\n\n")
|
||||||
rescue Errno::EPIPE, IOError => error
|
rescue => error
|
||||||
|
@last_socket_error = error
|
||||||
|
@socket_error = true
|
||||||
log.e(TAG, error.message)
|
log.e(TAG, error.message)
|
||||||
close
|
close
|
||||||
end
|
end
|
||||||
@@ -109,7 +120,10 @@ module TAC
|
|||||||
begin
|
begin
|
||||||
data = @socket.readpartial(CHUNK_SIZE)
|
data = @socket.readpartial(CHUNK_SIZE)
|
||||||
message += data
|
message += data
|
||||||
rescue Errno::EPIPE, EOFError
|
rescue => error
|
||||||
|
@last_socket_error = error
|
||||||
|
@socket_error = true
|
||||||
|
|
||||||
message = ""
|
message = ""
|
||||||
break
|
break
|
||||||
end until message.end_with?("\r\n\n")
|
end until message.end_with?("\r\n\n")
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ module TAC
|
|||||||
@hostname = hostname
|
@hostname = hostname
|
||||||
@port = port
|
@port = port
|
||||||
|
|
||||||
|
@client = nil
|
||||||
|
|
||||||
@last_sync_time = 0
|
@last_sync_time = 0
|
||||||
@sync_interval = SYNC_INTERVAL
|
@sync_interval = SYNC_INTERVAL
|
||||||
|
|
||||||
@@ -20,7 +22,7 @@ module TAC
|
|||||||
@packet_handler = PacketHandler.new(host_is_a_connection: true)
|
@packet_handler = PacketHandler.new(host_is_a_connection: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def connect(error_callback)
|
def connect
|
||||||
return if @client
|
return if @client
|
||||||
|
|
||||||
@client = Client.new
|
@client = Client.new
|
||||||
@@ -39,8 +41,13 @@ module TAC
|
|||||||
end
|
end
|
||||||
|
|
||||||
rescue => error
|
rescue => error
|
||||||
p error
|
log.e(TAG, error)
|
||||||
error_callback.call(error)
|
|
||||||
|
if @client
|
||||||
|
@client.close
|
||||||
|
@client.last_socket_error = error
|
||||||
|
@client.socket_error = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -68,12 +75,16 @@ module TAC
|
|||||||
end
|
end
|
||||||
|
|
||||||
def connected?
|
def connected?
|
||||||
!closed?
|
@client.connected? if @client
|
||||||
end
|
end
|
||||||
|
|
||||||
def closed?
|
def closed?
|
||||||
@client.closed? if @client
|
@client.closed? if @client
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def close
|
||||||
|
@client.close if @client
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -35,7 +35,7 @@ module TAC
|
|||||||
begin
|
begin
|
||||||
log.i(TAG, "Starting server...")
|
log.i(TAG, "Starting server...")
|
||||||
@socket = TCPServer.new(@port)
|
@socket = TCPServer.new(@port)
|
||||||
rescue => error
|
rescue IOError => error
|
||||||
log.e(TAG, error)
|
log.e(TAG, error)
|
||||||
|
|
||||||
@connection_attempts += 1
|
@connection_attempts += 1
|
||||||
@@ -46,8 +46,8 @@ module TAC
|
|||||||
while @socket && !@socket.closed?
|
while @socket && !@socket.closed?
|
||||||
begin
|
begin
|
||||||
run_server
|
run_server
|
||||||
rescue => error
|
rescue IOError => error
|
||||||
p error
|
log.e(TAG, error)
|
||||||
@socket.close if @socket
|
@socket.close if @socket
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user