Only send snaps to in game clients

This commit is contained in:
ChillerDragon 2022-11-13 08:40:17 +01:00
parent 09bd7bfebb
commit 846b487eb2
2 changed files with 9 additions and 1 deletions

View file

@ -59,6 +59,7 @@ class GameServer
# - game info
# - client info
# - snap single
packet.client.in_game = true
@server.send_server_info(packet.client, ServerInfo.new.to_a)
@server.send_game_info(packet.client, GameInfo.new.to_a)
end

View file

@ -16,7 +16,7 @@ require_relative 'message'
require_relative 'token'
class Client
attr_accessor :id, :addr, :vital_sent, :last_recv_time, :token, :player
attr_accessor :id, :addr, :vital_sent, :last_recv_time, :token, :player, :in_game
attr_reader :ack
def initialize(attr = {})
@ -24,6 +24,7 @@ class Client
@addr = attr[:addr]
@vital_sent = 0
@ack = 0
@in_game = false
@last_recv_time = Time.now
@player = Player.new(
id: @id,
@ -37,6 +38,10 @@ class Client
SecurityToken.validate(@token)
end
def in_game?
@in_game
end
def bump_ack
@ack = (@ack + 1) % NET_MAX_SEQUENCE
end
@ -297,6 +302,8 @@ class TeeworldsServer
[pack_msg_id(NETMSG_SNAPEMPTY, system: true)] +
data
@clients.each do |_id, client|
next unless client.in_game?
@netbase.send_packet(msg_snap_empty, chunks: 1, client:)
end
end