Fix voice and add Server.Forward() and Server.SendToAll()

This commit is contained in:
Sardelka 2022-08-13 08:56:05 +08:00
parent f9a411833a
commit 4dc3cc5c28
4 changed files with 17 additions and 10 deletions

View File

@ -250,7 +250,7 @@ namespace RageCoop.Client
case PacketType.Voice:
{
GTA.UI.Notification.Show("VOICE RECEIVED!");
Main.QueueAction(() => GTA.UI.Notification.Show("VOICE RECEIVED!"));
}
break;

View File

@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>RageCoop.Client</RootNamespace>
<AssemblyName>RageCoop.Client</AssemblyName>
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />

View File

@ -10,14 +10,11 @@ namespace RageCoop.Core
public override PacketType Type => PacketType.Voice;
public override byte[] Serialize()
{
var data = new List<byte>();
data.AddArray(Buffer);
return data.ToArray();
return Buffer;
}
public override void Deserialize(byte[] array)
{
var reader = new BitReader(array);
Buffer = reader.ReadByteArray();
Buffer = array;
}
}
}

View File

@ -486,9 +486,7 @@ namespace RageCoop.Server
case PacketType.Voice:
{
var msg = MainNetServer.CreateMessage();
data.GetPacket<Packets.Voice>().Pack(msg);
MainNetServer.SendMessage(msg, MainNetServer.Connections, NetDeliveryMethod.ReliableOrdered, (int)ConnectionChannel.Voice);
SendToAll(data.GetPacket<Packets.Voice>());
}
break;
@ -722,5 +720,17 @@ namespace RageCoop.Server
p.Pack(outgoingMessage);
MainNetServer.SendMessage(outgoingMessage, client.Connection,method,(int)channel);
}
internal void Forward(Packet p, Client except, ConnectionChannel channel = ConnectionChannel.Default, NetDeliveryMethod method = NetDeliveryMethod.UnreliableSequenced)
{
NetOutgoingMessage outgoingMessage = MainNetServer.CreateMessage();
p.Pack(outgoingMessage);
MainNetServer.SendToAll(outgoingMessage, except.Connection, method, (int)channel);
}
internal void SendToAll(Packet p, ConnectionChannel channel = ConnectionChannel.Default, NetDeliveryMethod method = NetDeliveryMethod.UnreliableSequenced)
{
NetOutgoingMessage outgoingMessage = MainNetServer.CreateMessage();
p.Pack(outgoingMessage);
MainNetServer.SendToAll(outgoingMessage, method, (int)channel);
}
}
}