Skip to content
This repository was archived by the owner on Sep 15, 2024. It is now read-only.

Commit 9da7100

Browse files
adjust for packet flag params
1 parent ba29e84 commit 9da7100

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

Scripts/Netcode/Server/ENetServer.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,10 @@ public static Peer[] GetOtherPeers(uint id)
236236
return otherPeers.Values.ToArray();
237237
}
238238

239-
public static void Send(ServerPacketOpcode opcode, params Peer[] peers) => Send(opcode, null, peers);
240-
public static void Send(ServerPacketOpcode opcode, APacket data, params Peer[] peers) => Outgoing.Enqueue(new ServerPacket((byte)opcode, data, peers));
239+
public static void Send(ServerPacketOpcode opcode, params Peer[] peers) => Send(opcode, null, PacketFlags.Reliable, peers);
240+
public static void Send(ServerPacketOpcode opcode, APacket data, params Peer[] peers) => Send(opcode, data, PacketFlags.Reliable, peers);
241+
public static void Send(ServerPacketOpcode opcode, PacketFlags flags = PacketFlags.Reliable, params Peer[] peers) => Send(opcode, null, flags, peers);
242+
public static void Send(ServerPacketOpcode opcode, APacket data, PacketFlags flags = PacketFlags.Reliable, params Peer[] peers) => Outgoing.Enqueue(new ServerPacket((byte)opcode, flags, data, peers));
241243

242244
/// <summary>
243245
/// Provides a way to log a message on the Godot thread from the ENet thread

Scripts/Netcode/Server/GameServer.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void TimerNotifyClientsCallback(System.Object source, ElapsedEventArgs ar
3232
{
3333
SendToAllPlayers(ServerPacketOpcode.PlayerPositions, new SPacketPlayerPositions {
3434
PlayerPositions = Players.ToDictionary(x => x.Key, x => x.Value.Position)
35-
});
35+
}, PacketFlags.Reliable);
3636
}
3737

3838
public void TimerGameLoopCallback(System.Object source, ElapsedEventArgs args)
@@ -52,7 +52,9 @@ public void TimerGameLoopCallback(System.Object source, ElapsedEventArgs args)
5252
if (player.PressedDown)
5353
dir.y = 1;
5454

55-
player.Position += dir * 250 * Delta;
55+
var delta = 0.016667f;
56+
57+
player.Position += dir * 250 * delta;
5658
}
5759
}
5860

@@ -93,38 +95,38 @@ public static Dictionary<uint, DataPlayer> GetOtherPlayers(uint id)
9395
public static Peer[] GetOtherPlayerPeers(uint id) => Players.Keys.Where(x => x != id).Select(x => Peers[x]).ToArray();
9496
public static Peer[] GetAllPlayerPeers() => Players.Keys.Select(x => Peers[x]).ToArray();
9597

96-
public static void SendToAllPlayers(ServerPacketOpcode opcode, APacket data = null)
98+
public static void SendToAllPlayers(ServerPacketOpcode opcode, APacket data = null, PacketFlags flags = PacketFlags.Reliable)
9799
{
98100
var allPlayers = GetAllPlayerPeers();
99101

100102
if (data == null)
101-
Send(opcode, allPlayers);
103+
Send(opcode, flags, allPlayers);
102104
else
103-
Send(opcode, data, allPlayers);
105+
Send(opcode, data, flags, allPlayers);
104106
}
105107

106-
public static void SendToOtherPeers(uint id, ServerPacketOpcode opcode, APacket data = null)
108+
public static void SendToOtherPeers(uint id, ServerPacketOpcode opcode, APacket data = null, PacketFlags flags = PacketFlags.Reliable)
107109
{
108110
var otherPeers = GetOtherPeers(id);
109111
if (otherPeers.Length == 0)
110112
return;
111113

112114
if (data == null)
113-
Send(opcode, otherPeers);
115+
Send(opcode, flags, otherPeers);
114116
else
115-
Send(opcode, data, otherPeers);
117+
Send(opcode, data, flags, otherPeers);
116118
}
117119

118-
public static void SendToOtherPlayers(uint id, ServerPacketOpcode opcode, APacket data = null)
120+
public static void SendToOtherPlayers(uint id, ServerPacketOpcode opcode, APacket data = null, PacketFlags flags = PacketFlags.Reliable)
119121
{
120122
var otherPlayers = GetOtherPlayerPeers(id);
121123
if (otherPlayers.Length == 0)
122124
return;
123125

124126
if (data == null)
125-
Send(opcode, otherPlayers);
127+
Send(opcode, flags, otherPlayers);
126128
else
127-
Send(opcode, data, otherPlayers);
129+
Send(opcode, data, flags, otherPlayers);
128130
}
129131

130132
public static void UpdatePressed(uint id, Direction dir, bool pressed)

0 commit comments

Comments
 (0)