From d9b0096ae8b6774a6c58721a12fba168bb98cdae Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Sun, 13 Nov 2022 09:40:05 +0100 Subject: [PATCH] Send server settings --- lib/game_server.rb | 3 ++- lib/models/server_settings.rb | 23 +++++++++++++++++++++++ lib/teeworlds_server.rb | 7 +++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 lib/models/server_settings.rb diff --git a/lib/game_server.rb b/lib/game_server.rb index b9b09ca..dc889ff 100644 --- a/lib/game_server.rb +++ b/lib/game_server.rb @@ -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 diff --git a/lib/models/server_settings.rb b/lib/models/server_settings.rb new file mode 100644 index 0000000..4335250 --- /dev/null +++ b/lib/models/server_settings.rb @@ -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 diff --git a/lib/teeworlds_server.rb b/lib/teeworlds_server.rb index 971ac92..1f888e3 100644 --- a/lib/teeworlds_server.rb +++ b/lib/teeworlds_server.rb @@ -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)] +