Progress on server side snaps

No errors in client log but still in connecting screen
This commit is contained in:
ChillerDragon 2024-02-21 19:41:53 +08:00
parent 420c6deb92
commit f44a370dc0
2 changed files with 38 additions and 2 deletions

View file

@ -216,6 +216,7 @@ class SnapshotUnpacker
obj = NetEvent::HammerHit.new(u) obj = NetEvent::HammerHit.new(u)
elsif @verbose elsif @verbose
puts "no match #{item_type}" puts "no match #{item_type}"
exit(1)
end end
obj = unpack_ddnet_item(u, notes) if !obj && item_type.zero? obj = unpack_ddnet_item(u, notes) if !obj && item_type.zero?
if obj if obj

View file

@ -14,6 +14,7 @@ require_relative 'packer'
require_relative 'game_server' require_relative 'game_server'
require_relative 'models/token' require_relative 'models/token'
require_relative 'messages/sv_emoticon' require_relative 'messages/sv_emoticon'
require_relative 'snapshot/builder'
class Client class Client
attr_accessor :id, :addr, :vital_sent, :last_recv_time, :token, :player, :in_game, :authed attr_accessor :id, :addr, :vital_sent, :last_recv_time, :token, :player, :in_game, :authed
@ -470,11 +471,32 @@ class TeeworldsServer
end end
end end
require_relative 'snapshot/items/game_data'
require_relative 'snapshot/items/game_data_team'
require_relative 'snapshot/items/game_data_flag'
def do_snap_single def do_snap_single
builder = SnapshotBuilder.new builder = SnapshotBuilder.new
builder.new_item(0, NetObj::GameData.new(
game_start_tick: 0,
game_state_flags: 1,
game_state_end_tick: 500
))
builder.new_item(0, NetObj::GameDataTeam.new(
teamscore_red: 0,
teamscore_blue: 0
))
builder.new_item(0, NetObj::GameDataFlag.new(
flag_carrier_red: -2,
flag_carrier_blue: -2,
flag_drop_tick_red: 0,
flag_drop_tick_blue: 0
))
snap = builder.finish snap = builder.finish
items = snap.to_a items = snap.to_a
delta_tick = -1
data = [] data = []
# Game tick Int # Game tick Int
data += Packer.pack_int(@current_game_tick) data += Packer.pack_int(@current_game_tick)
@ -483,15 +505,28 @@ class TeeworldsServer
# Crc Int # Crc Int
data += Packer.pack_int(snap.crc) data += Packer.pack_int(snap.crc)
# Part size Int The size of this part. Meaning the size in bytes of the next raw data field. # Part size Int The size of this part. Meaning the size in bytes of the next raw data field.
data += Packer.pack_int(items.size) header = []
header += [0x00] # removed items
header += Packer.pack_int(snap.items.count) # num item deltas
header += [0x00] # _zero
part_size = items.size + header.size
data += Packer.pack_int(part_size)
# Data # Data
data += header
data += items data += items
msg = NetChunk.create_header(vital: false, size: data.size + 1) +
[pack_msg_id(NETMSG_SNAPSINGLE, system: true)] +
data
@clients.each_value do |client|
next unless client.in_game?
p data @netbase.send_packet(msg, chunks: 1, client:)
end
end end
def do_snapshot def do_snapshot
do_snap_empty do_snap_empty
# do_snap_single
end end
def get_player_by_id(id) def get_player_by_id(id)