Build 0.20.7.0

This commit is contained in:
Markus Isberg
2022-11-18 18:13:38 +02:00
parent 8c8fd865c5
commit ecb6d40b4b
111 changed files with 1346 additions and 701 deletions
@@ -2,19 +2,18 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Text;
namespace Barotrauma.Networking
{
class VoipServer
{
private ServerPeer netServer;
private List<VoipQueue> queues;
private Dictionary<VoipQueue,DateTime> lastSendTime;
private readonly ServerPeer netServer;
private readonly List<VoipQueue> queues;
private readonly Dictionary<VoipQueue,DateTime> lastSendTime;
public VoipServer(ServerPeer server)
{
this.netServer = server;
netServer = server;
queues = new List<VoipQueue>();
lastSendTime = new Dictionary<VoipQueue, DateTime>();
}
@@ -46,17 +45,19 @@ namespace Barotrauma.Networking
}
Client sender = clients.Find(c => c.VoipQueue == queue);
if (sender == null) { return; }
foreach (Client recipient in clients)
{
if (recipient == sender) { continue; }
if (!CanReceive(sender, recipient)) { continue; }
if (!CanReceive(sender, recipient, out float distanceFactor)) { continue; }
IWriteMessage msg = new WriteOnlyMessage();
msg.WriteByte((byte)ServerPacketHeader.VOICE);
msg.WriteByte((byte)queue.QueueID);
msg.WriteRangedSingle(distanceFactor, 0.0f, 1.0f, 8);
queue.Write(msg);
netServer.Send(msg, recipient.Connection, DeliveryMethod.Unreliable);
@@ -64,9 +65,15 @@ namespace Barotrauma.Networking
}
}
private bool CanReceive(Client sender, Client recipient)
private static bool CanReceive(Client sender, Client recipient, out float distanceFactor)
{
if (Screen.Selected != GameMain.GameScreen) { return true; }
if (Screen.Selected != GameMain.GameScreen)
{
distanceFactor = 0.0f;
return true;
}
distanceFactor = 0.0f;
//no-one can hear muted players
if (sender.Muted) { return false; }
@@ -74,30 +81,47 @@ namespace Barotrauma.Networking
bool recipientSpectating = recipient.Character == null || recipient.Character.IsDead;
bool senderSpectating = sender.Character == null || sender.Character.IsDead;
//TODO: only allow spectators to hear the voice chat if close enough to the speaker?
//non-spectators cannot hear spectators
if (senderSpectating && !recipientSpectating) { return false; }
//both spectating, no need to do radio/distance checks
if (recipientSpectating && senderSpectating) { return true; }
//spectators can hear non-spectators
if (!senderSpectating && recipientSpectating) { return true; }
//non-spectators cannot hear spectators, and spectators can always hear spectators
if (senderSpectating)
{
return recipientSpectating;
}
//sender can't speak
if (sender.Character != null && sender.Character.SpeechImpediment >= 100.0f) { return false; }
//check if the message can be sent via radio
WifiComponent recipientRadio = null;
if (!sender.VoipQueue.ForceLocal &&
ChatMessage.CanUseRadio(sender.Character, out WifiComponent senderRadio) &&
ChatMessage.CanUseRadio(recipient.Character, out WifiComponent recipientRadio))
ChatMessage.CanUseRadio(sender.Character, out WifiComponent senderRadio) &&
(recipientSpectating || ChatMessage.CanUseRadio(recipient.Character, out recipientRadio)))
{
if (recipientRadio.CanReceive(senderRadio)) { return true; }
if (recipientSpectating)
{
if (recipient.SpectatePos == null) { return true; }
distanceFactor = MathHelper.Clamp(Vector2.Distance(sender.Character.WorldPosition, recipient.SpectatePos.Value) / senderRadio.Range, 0.0f, 1.0f);
return distanceFactor < 1.0f;
}
else if (recipientRadio != null && recipientRadio.CanReceive(senderRadio))
{
distanceFactor = MathHelper.Clamp(Vector2.Distance(sender.Character.WorldPosition, recipient.Character.WorldPosition) / senderRadio.Range, 0.0f, 1.0f);
return true;
}
}
//otherwise do a distance check
return ChatMessage.GetGarbleAmount(recipient.Character, sender.Character, ChatMessage.SpeakRange) < 1.0f;
if (recipientSpectating)
{
if (recipient.SpectatePos == null) { return true; }
distanceFactor = MathHelper.Clamp(Vector2.Distance(sender.Character.WorldPosition, recipient.SpectatePos.Value) / ChatMessage.SpeakRange, 0.0f, 1.0f);
return distanceFactor < 1.0f;
}
else
{
//otherwise do a distance check
float garbleAmount = ChatMessage.GetGarbleAmount(recipient.Character, sender.Character, ChatMessage.SpeakRange);
distanceFactor = garbleAmount;
return garbleAmount < 1.0f;
}
}
}
}