Send server settings

This commit is contained in:
ChillerDragon 2022-11-13 09:40:05 +01:00
parent 263e579661
commit d9b0096ae8
3 changed files with 32 additions and 1 deletions

View file

@ -2,6 +2,7 @@
require_relative 'models/map'
require_relative 'models/server_info'
require_relative 'models/server_settings'
require_relative 'models/game_info'
class GameServer
@ -37,7 +38,7 @@ class GameServer
# - server settings
# - ready
#
# We only send ready for now
@server.send_server_settings(packet.client, ServerSettings.new.to_a)
@server.send_ready(packet.client)
end

View file

@ -0,0 +1,23 @@
# frozen_string_literal: true
class ServerSettings
def initialize(attr = {})
@kick_vote = attr[:kick_vote] || 0
@kick_min = attr[:kick_min] || 0
@spec_vote = attr[:spec_vote] || 0
@team_lock = attr[:team_lock] || 0
@team_balance = attr[:team_balance] || 0
@player_slots = attr[:player_slots] || 16
end
# basically to_network
# int array the server sends to the client
def to_a
Packer.pack_int(@kick_vote) +
Packer.pack_int(@kick_min) +
Packer.pack_int(@spec_vote) +
Packer.pack_int(@team_lock) +
Packer.pack_int(@team_balance) +
Packer.pack_int(@player_slots)
end
end

View file

@ -213,6 +213,13 @@ class TeeworldsServer
@netbase.send_packet(msg, chunks: 1, client:)
end
def send_server_settings(client, server_settings)
msg = NetChunk.create_header(vital: true, size: 1 + server_settings.size, client:) +
[pack_msg_id(NETMSGTYPE_SV_SERVERSETTINGS, system: false)] +
server_settings
@netbase.send_packet(msg, chunks: 1, client:)
end
def send_server_info(client, server_info)
msg = NetChunk.create_header(vital: true, size: 1 + server_info.size, client:) +
[pack_msg_id(NETMSG_SERVERINFO, system: true)] +