Added basic dialogs, added 'blindman' implementation of TACNET networking code, added font

This commit is contained in:
2020-06-07 15:18:31 -05:00
parent 5ea8d13653
commit c694d29050
20 changed files with 870 additions and 5 deletions

58
lib/tacnet/connection.rb Normal file
View File

@@ -0,0 +1,58 @@
module TAC
class TACNET
class Connection
def initialize(hostname = DEFAULT_HOSTNAME, port = DEFAULT_PORT)
@hostname = hostname
@port = port
@last_sync_time = 0
@sync_interval = SYNC_INTERVAL
@last_heartbeat_sent = 0
@heartbeat_interval = HEARTBEAT_INTERVAL
@connection_handler = proc do
handle_connection
end
end
def connect(error_callback)
return if @client
@client = Client.new
Thread.new do
begin
@client.socket = Socket.tcp(@hostname, @port, connect_timeout: 5)
while @client && @client.connected?
if Gosu.milliseconds > @last_sync_time + @sync_interval
@last_sync_time = Gosu.milliseconds
@client.sync(@connection_handler)
end
end
rescue => error
p error
error_callback.call(error)
end
end
end
def handle_connection
if @client && @client.connected?
message = @client.gets
PacketHandler.handle(message) if message
if Gosu.milliseconds > @last_heartbeat_sent + @heartbeat_interval
last_heartbeat_sent = Gosu.milliseconds
client.puts(PacketHandler.packet_heartbeat)
end
end
end
end
end
end