From 02da3ce8afbfab4ca8421de07f1b6b033c46bcfe Mon Sep 17 00:00:00 2001 From: sardelka9515 Date: Mon, 22 Aug 2022 17:55:58 +0800 Subject: [PATCH] Fix voice on P2P mode --- RageCoop.Server/Networking/Server.Listener.cs | 57 +++++++++++++++++++ RageCoop.Server/Networking/Server.cs | 56 ------------------ 2 files changed, 57 insertions(+), 56 deletions(-) diff --git a/RageCoop.Server/Networking/Server.Listener.cs b/RageCoop.Server/Networking/Server.Listener.cs index 1a4e2a4..9fcf69c 100644 --- a/RageCoop.Server/Networking/Server.Listener.cs +++ b/RageCoop.Server/Networking/Server.Listener.cs @@ -190,5 +190,62 @@ namespace RageCoop.Server MainNetServer.Recycle(message); } + + private void HandlePacket(PacketType type, byte[] data, Client sender) + { + try + { + switch (type) + { + case PacketType.PedSync: + PedSync(data.GetPacket(), sender); + break; + + case PacketType.VehicleSync: + VehicleSync(data.GetPacket(), sender); + break; + + case PacketType.ProjectileSync: + ProjectileSync(data.GetPacket(), sender); + break; + + case PacketType.ChatMessage: + { + Packets.ChatMessage packet = new((b) => + { + return Security.Decrypt(b, sender.EndPoint); + }); + packet.Deserialize(data); + ChatMessageReceived(packet.Username, packet.Message, sender); + } + break; + + case PacketType.Voice: + { + if (Settings.UseVoice && !Settings.UseP2P) + { + Forward(data.GetPacket(), sender, ConnectionChannel.Voice); + } + } + break; + + case PacketType.CustomEvent: + { + Packets.CustomEvent packet = new Packets.CustomEvent(); + packet.Deserialize(data); + _worker.QueueJob(() => API.Events.InvokeCustomEventReceived(packet, sender)); + } + break; + default: + Logger?.Error("Unhandled Data / Packet type"); + break; + + } + } + catch (Exception e) + { + DisconnectAndLog(sender.Connection, type, e); + } + } } } diff --git a/RageCoop.Server/Networking/Server.cs b/RageCoop.Server/Networking/Server.cs index ec33edf..921b911 100644 --- a/RageCoop.Server/Networking/Server.cs +++ b/RageCoop.Server/Networking/Server.cs @@ -188,62 +188,6 @@ namespace RageCoop.Server { _worker.QueueJob(job); } - private void HandlePacket(PacketType type,byte[] data,Client sender) - { - try - { - switch (type) - { - case PacketType.PedSync: - PedSync(data.GetPacket(), sender); - break; - - case PacketType.VehicleSync: - VehicleSync(data.GetPacket(), sender); - break; - - case PacketType.ProjectileSync: - ProjectileSync(data.GetPacket(), sender); - break; - - case PacketType.ChatMessage: - { - Packets.ChatMessage packet = new((b) => - { - return Security.Decrypt(b,sender.EndPoint); - }); - packet.Deserialize(data); - ChatMessageReceived(packet.Username,packet.Message, sender); - } - break; - - case PacketType.Voice: - { - if (Settings.UseVoice) - { - Forward(data.GetPacket(), sender, ConnectionChannel.Voice); - } - } - break; - - case PacketType.CustomEvent: - { - Packets.CustomEvent packet = new Packets.CustomEvent(); - packet.Deserialize(data); - _worker.QueueJob(() => API.Events.InvokeCustomEventReceived(packet, sender)); - } - break; - default: - Logger?.Error("Unhandled Data / Packet type"); - break; - - } - } - catch (Exception e) - { - DisconnectAndLog(sender.Connection, type, e); - } - } // Send a message to targets or all players internal void ChatMessageReceived(string name, string message,Client sender=null)