2 using Microsoft.Xna.Framework;
4 using System.Collections.Generic;
10 private readonly ServerPeer netServer;
11 private readonly List<VoipQueue> queues;
12 private readonly Dictionary<VoipQueue, DateTime> lastSendTime;
17 queues =
new List<VoipQueue>();
18 lastSendTime =
new Dictionary<VoipQueue, DateTime>();
23 if (!queues.Contains(queue)) queues.Add(queue);
28 if (queues.Contains(queue)) queues.Remove(queue);
35 if (queue.
LastReadTime < DateTime.Now - VoipConfig.SEND_INTERVAL) {
continue; }
37 if (lastSendTime.ContainsKey(queue))
39 if ((lastSendTime[queue] + VoipConfig.SEND_INTERVAL) > DateTime.Now) {
continue; }
40 lastSendTime[queue] = DateTime.Now;
44 lastSendTime.Add(queue, DateTime.Now);
47 Client sender = clients.Find(c => c.VoipQueue == queue);
48 if (sender ==
null) {
return; }
50 foreach (
Client recipient
in clients)
52 if (recipient == sender) {
continue; }
54 if (!CanReceive(sender, recipient, out
float distanceFactor)) {
continue; }
63 netServer.Send(msg, recipient.
Connection, DeliveryMethod.Unreliable);
68 private static bool CanReceive(
Client sender,
Client recipient, out
float distanceFactor)
72 distanceFactor = 0.0f;
76 distanceFactor = 0.0f;
79 if (sender.
Muted) {
return false; }
87 return recipientSpectating;
99 var canUse = GameMain.LuaCs.Hook.Call<
bool?>(
"canUseVoiceRadio",
new object[] { sender, recipient });
106 if (recipientSpectating)
108 if (recipient.
SpectatePos ==
null) {
return true; }
110 return distanceFactor < 1.0f;
112 else if (recipientRadio !=
null && recipientRadio.CanReceive(senderRadio))
119 float range = GameMain.LuaCs.Hook.Call<
float?>(
"changeLocalVoiceRange", sender, recipient) ?? 1.0f;
121 if (recipientSpectating)
123 if (recipient.
SpectatePos ==
null) {
return true; }
125 return distanceFactor < 1.0f;
131 distanceFactor = garbleAmount;
132 return garbleAmount < range;
139 if (queue.Read(inc, discardData:
false))
145 var msg =
new WriteOnlyMessage().WithHeader(
ServerPacketHeader.VOICE_AMPLITUDE_DEBUG);
146 msg.WriteRangedSingle(connectedClient.
VoipServerDecoder.Amplitude, min: 0, max: 1, bitCount: 8);
Character(CharacterPrefab prefab, Vector2 position, string seed, CharacterInfo characterInfo=null, ushort id=Entity.NullEntityID, bool isRemotePlayer=false, RagdollParams ragdollParams=null, bool spawnInitialItems=true)
virtual Vector2 WorldPosition
static GameScreen GameScreen
const float SpeakRangeVOIP
This is shorter than the text chat speak range, because the voice chat is still intelligible (just qu...
static float GetGarbleAmount(Entity listener, Entity sender, float range, float obstructionMultiplier=2.0f)
How much messages sent by sender should get garbled. Takes the distance between the entities and opt...
static bool CanUseRadio(Character sender, bool ignoreJamming=false)
VoipServerDecoder VoipServerDecoder
NetworkConnection Connection
virtual void Write(IWriteMessage msg)
void RegisterQueue(VoipQueue queue)
static void Read(IReadMessage inc, Client connectedClient)
VoipServer(ServerPeer server)
void UnregisterQueue(VoipQueue queue)
void SendToClients(List< Client > clients)
void WriteRangedSingle(Single val, Single min, Single max, int bitCount)