Removed gosu dependency from Server by adding TACNET.milliseconds method, made tacnet hostname/port editable

This commit is contained in:
2020-06-09 21:19:31 -05:00
parent ca193ea24a
commit 270f3b381f
9 changed files with 41 additions and 24 deletions

View File

@@ -9,7 +9,7 @@ module TAC
end
def config_changed!
@config.config.updated_at = Time.now
@config.configuration.updated_at = Time.now
@config_changed = true
end

View File

@@ -1,8 +1,8 @@
module TAC
class Config
attr_reader :config, :groups
attr_reader :configuration, :groups
def initialize
@config = nil
@configuration = nil
@groups = nil
parse(File.read(TAC::CONFIG_PATH))
@@ -24,13 +24,13 @@ module TAC
end
def parse_spec_current(data)
@config = Configuration.from_json(data[:config])
@configuration = Configuration.from_json(data[:config])
@groups = data.dig(:data, :groups).map { |g| Group.from_json(g) }
end
def to_json(*args)
{
config: @config,
config: @configuration,
data: {
groups: @groups
}

View File

@@ -9,8 +9,8 @@ module TAC
TIMECRAFTERS_SECONDARY = Gosu::Color.new(0xff_006000)
TIMECRAFTERS_TERTIARY = Gosu::Color.new(0xff_00d000)
TACNET_PRIMARY = Gosu::Color.new(0xff_000080)
TACNET_SECONDARY = Gosu::Color.new(0xff_000060)
TACNET_PRIMARY = Gosu::Color.new(0xff_003f7f)
TACNET_SECONDARY = Gosu::Color.new(0xff_007f7f)
GROUPS_PRIMARY = Gosu::Color.new(0xff_444444)
GROUPS_SECONDARY = Gosu::Color.new(0xff_444444)

View File

@@ -47,8 +47,20 @@ module TAC
flow width: 0.399 do
stack width: 0.5 do
label "TACNET v#{TACNET::Packet::PROTOCOL_VERSION}", color: TAC::Palette::TACNET_PRIMARY
@tacnet_ip_address = label "#{TACNET::DEFAULT_HOSTNAME}:#{TACNET::DEFAULT_PORT}", color: TAC::Palette::TACNET_SECONDARY
label "TACNET v#{TACNET::Packet::PROTOCOL_VERSION}", color: TAC::Palette::TACNET_PRIMARY, text_shadow: true, text_shadow_size: 1, text_shadow_color: Gosu::Color::BLACK
flow width: 1.0 do
@tacnet_hostname = edit_line "#{window.backend.config.configuration.hostname}", text_size: 18, width: 0.5, margin_right: 0
@tacnet_hostname.subscribe(:changed) do |caller, value|
window.backend.config.configuration.hostname = value
window.backend.config_changed!
end
label ":", text_size: 18, margin: 0, padding: 0, padding_top: 3
@tacnet_port = edit_line "#{window.backend.config.configuration.port}", text_size: 18, width: 0.2, margin_left: 0
@tacnet_port.subscribe(:changed) do |caller, value|
window.backend.config.configuration.port = Integer(value)
window.backend.config_changed!
end
end
end
stack width: 0.499 do
@@ -59,7 +71,7 @@ module TAC
when :connected, :connecting
window.backend.tacnet.close
when :not_connected, :connection_error
window.backend.tacnet.connect("localhost")#("192.168.1.5")
window.backend.tacnet.connect(@tacnet_hostname.value, @tacnet_port.value)
end
end
button get_image("#{TAC::ROOT_PATH}/media/icons/information.png"), image_width: 18, width: 0.475 do

View File

@@ -70,5 +70,9 @@ module TAC
def gets
@connection.gets if connected?
end
def self.milliseconds
Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)
end
end
end

View File

@@ -9,10 +9,10 @@ module TAC
@client = nil
@last_sync_time = Gosu.milliseconds
@last_sync_time = TACNET.milliseconds
@sync_interval = SYNC_INTERVAL
@last_heartbeat_sent = Gosu.milliseconds
@last_heartbeat_sent = TACNET.milliseconds
@heartbeat_interval = HEARTBEAT_INTERVAL
@connection_handler = proc do
@@ -33,8 +33,8 @@ module TAC
log.i(TAG, "Connected to: #{@hostname}:#{@port}")
while @client && @client.connected?
if Gosu.milliseconds > @last_sync_time + @sync_interval
@last_sync_time = Gosu.milliseconds
if TACNET.milliseconds > @last_sync_time + @sync_interval
@last_sync_time = TACNET.milliseconds
@client.sync(@connection_handler)
end
@@ -58,8 +58,8 @@ module TAC
@packet_handler.handle(message) if message
if Gosu.milliseconds > @last_heartbeat_sent + @heartbeat_interval
@last_heartbeat_sent = Gosu.milliseconds
if TACNET.milliseconds > @last_heartbeat_sent + @heartbeat_interval
@last_heartbeat_sent = TACNET.milliseconds
@client.puts(PacketHandler.packet_heartbeat)
end

View File

@@ -18,10 +18,10 @@ module TAC
@packets_sent, @packets_received, @client_last_packets_sent, @client_last_packets_received = 0, 0, 0, 0
@data_sent, @data_received, @client_last_data_sent, @client_last_data_received = 0, 0, 0, 0
@last_sync_time = Gosu.milliseconds
@last_sync_time = TACNET.milliseconds
@sync_interval = SYNC_INTERVAL
@last_heartbeat_sent = Gosu.milliseconds
@last_heartbeat_sent = TACNET.milliseconds
@heartbeat_interval = HEARTBEAT_INTERVAL
@client_handler_proc = proc do
@@ -80,8 +80,8 @@ module TAC
Thread.new do
while @active_client && @active_client.connected?
if Gosu.milliseconds > @last_sync_time + @sync_interval
@last_sync_time = Gosu.milliseconds
if TACNET.milliseconds > @last_sync_time + @sync_interval
@last_sync_time = TACNET.milliseconds
@active_client.sync(@client_handler_proc)
update_stats
@@ -108,8 +108,8 @@ module TAC
@packet_handler.handle(message)
end
if Gosu.milliseconds > @last_heartbeat_sent + @heartbeat_interval
@last_heartbeat_sent = Gosu.milliseconds
if TACNET.milliseconds > @last_heartbeat_sent + @heartbeat_interval
@last_heartbeat_sent = TACNET.milliseconds
@active_client.puts(PacketHandler.packet_heartbeat)
end

View File

@@ -14,6 +14,9 @@ module TAC
active: {
background: TAC::Palette::TIMECRAFTERS_TERTIARY
}
},
EditLine: {
caret_color: Gosu::Color.new(0xff_434343)
}
}
end

View File

@@ -2,8 +2,6 @@ require "json"
require "socket"
require "securerandom"
require "gosu"
require_relative "lib/tac"
require_relative "lib/logger"