teeworlds_network/lib/game_server.rb

66 lines
1.6 KiB
Ruby
Raw Normal View History

2022-11-09 15:46:04 +00:00
# frozen_string_literal: true
require_relative 'map'
2022-11-11 12:42:11 +00:00
require_relative 'server_info'
require_relative 'game_info'
2022-11-09 15:46:04 +00:00
class GameServer
attr_accessor :pred_game_tick, :ack_game_tick, :map
2022-11-09 15:46:04 +00:00
def initialize(server)
@server = server
@ack_game_tick = -1
@pred_game_tick = 0
@map = Map.new(
name: 'dm1',
crc: '98a0a4c50c', # decimal 64548818
size: 6793,
sha256: '491af17a510214506270904f147a4c30ae0a85b91bb854395bef8c397fc078c3'
)
2022-11-09 15:46:04 +00:00
end
def on_info(chunk, packet)
2022-11-09 15:46:04 +00:00
u = Unpacker.new(chunk.data[1..])
net_version = u.get_string
password = u.get_string
client_version = u.get_int
puts "vers=#{net_version} vers=#{client_version} pass=#{password}"
# TODO: check version and password
@server.send_map(packet.addr)
2022-11-09 15:46:04 +00:00
end
2022-11-11 12:42:11 +00:00
def on_ready(_chunk, packet)
# vanilla server sends 3 chunks here usually
# - motd
# - server settings
# - ready
#
# We only send ready for now
@server.send_ready(packet.addr)
end
def on_startinfo(_chunk, packet)
# vanilla server sends 3 chunks here usually
# - vote clear options
# - tune params
# - ready to enter
#
# We only send ready to enter for now
@server.send_ready_to_enter(packet.addr)
end
def on_enter_game(_chunk, packet)
# vanilla server responds to enter game with two packets
# first:
# - server info
# second:
# - game info
# - client info
# - snap single
@server.send_server_info(packet.addr, ServerInfo.new.to_a)
@server.send_game_info(packet.addr, GameInfo.new.to_a)
end
2022-11-09 15:46:04 +00:00
end