-
Notifications
You must be signed in to change notification settings - Fork 2
/
packet_desynced_level.lua
35 lines (33 loc) · 2.12 KB
/
packet_desynced_level.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
---@param p any
local function recieve_packet(p)
if p.packetType ~= nil then -- make sure the packet is valid
-- check the packet type we specified when using the create_packet function
if p.packetType == PACKET_TYPE_LEVEL_DESYNCED then
if p.reason == DESYNC_REASON_LEVEL then
-- send the level to the desynced player to resync them
-- use the create packet function to create a packet with the packet type Desynced Initiate Resync
local desyncPacket = create_packet(PACKET_TYPE_LEVEL_DESYNCED_INITIATE_RESYNC, gGlobalSyncTable.selectedLevel)
-- send the packet to the global index that we set when the desynced player sent their global index
send_packet(p.globalIndex, desyncPacket)
log_to_console("Tag: Sent the ok to resync, desync reason is " .. p.reason)
elseif p.reason == DESYNC_REASON_ROUND_STATE then
-- send the round state to the desynced player to resync them
-- use the create packet function to create a packet with the packet type Desynced Initiate Resync
local desyncPacket = create_packet(PACKET_TYPE_LEVEL_DESYNCED_INITIATE_RESYNC, gGlobalSyncTable.roundState)
-- send the packet to the global index that we set when the desynced player sent their global index
send_packet(p.globalIndex, desyncPacket)
log_to_console("Tag: Sent data to resync, desync reason is " .. p.reason)
end
elseif p.packetType == PACKET_TYPE_LEVEL_DESYNCED_INITIATE_RESYNC then
-- Resync the player by setting the selected level to the server's selected level
if desyncReason == DESYNC_REASON_LEVEL then
gGlobalSyncTable.selectedLevel = p.data
elseif desyncReason == DESYNC_REASON_ROUND_STATE then
gGlobalSyncTable.roundState = p.data
end
log_to_console("Tag: You have been resynced due to " .. tostring(p.reason))
end
end
end
-- here we recieve the packet using a hook
hook_event(HOOK_ON_PACKET_RECEIVE, recieve_packet)