Merge remote-tracking branch 'upstream/master' into develop
This commit is contained in:
@@ -30,6 +30,7 @@ namespace Barotrauma.Networking
|
||||
txt = msg.ReadString();
|
||||
|
||||
string senderName = msg.ReadString();
|
||||
Entity sender = null;
|
||||
Character senderCharacter = null;
|
||||
Client senderClient = null;
|
||||
bool hasSenderClient = msg.ReadBoolean();
|
||||
@@ -40,13 +41,14 @@ namespace Barotrauma.Networking
|
||||
=> c.SessionOrAccountIdMatches(userId));
|
||||
if (senderClient != null) { senderName = senderClient.Name; }
|
||||
}
|
||||
bool hasSenderCharacter = msg.ReadBoolean();
|
||||
if (hasSenderCharacter)
|
||||
bool hasSender = msg.ReadBoolean();
|
||||
if (hasSender)
|
||||
{
|
||||
senderCharacter = Entity.FindEntityByID(msg.ReadUInt16()) as Character;
|
||||
if (senderCharacter != null)
|
||||
sender = Entity.FindEntityByID(msg.ReadUInt16());
|
||||
senderCharacter = sender as Character;
|
||||
if (sender is Character or Item)
|
||||
{
|
||||
senderName = senderCharacter.Name;
|
||||
senderName = OrderChatMessage.NameFromEntityOrNull(sender);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +182,7 @@ namespace Barotrauma.Networking
|
||||
GameMain.Client.ServerSettings.ServerLog?.WriteLine(txt, messageType);
|
||||
break;
|
||||
default:
|
||||
GameMain.Client.AddChatMessage(txt, type, senderName, senderClient, senderCharacter, changeType, textColor: textColor);
|
||||
GameMain.Client.AddChatMessage(txt, type, senderName, senderClient, sender, changeType, textColor: textColor);
|
||||
if (type == ChatMessageType.Radio && CanUseRadio(senderCharacter, out WifiComponent radio))
|
||||
{
|
||||
Signal s = new Signal(txt, sender: senderCharacter, source: radio.Item);
|
||||
|
||||
@@ -21,6 +21,10 @@ namespace Barotrauma.Networking
|
||||
|
||||
public override bool IsClient => true;
|
||||
public override bool IsServer => false;
|
||||
|
||||
#if DEBUG
|
||||
public float DebugServerVoipAmplitude;
|
||||
#endif
|
||||
|
||||
public override Voting Voting { get; }
|
||||
|
||||
@@ -112,6 +116,8 @@ namespace Barotrauma.Networking
|
||||
//has the client been given a character to control this round
|
||||
public bool HasSpawned;
|
||||
|
||||
public float EndRoundTimeRemaining { get; private set; }
|
||||
|
||||
public LocalizedString TraitorFirstObjective;
|
||||
public TraitorEventPrefab TraitorMission = null;
|
||||
|
||||
@@ -198,20 +204,6 @@ namespace Barotrauma.Networking
|
||||
CanBeFocused = false
|
||||
};
|
||||
|
||||
cameraFollowsSub = new GUITickBox(new RectTransform(new Vector2(0.05f, 0.05f), inGameHUD.RectTransform, anchor: Anchor.TopCenter, pivot: Pivot.CenterLeft)
|
||||
{
|
||||
AbsoluteOffset = new Point(0, HUDLayoutSettings.ButtonAreaTop.Y + HUDLayoutSettings.ButtonAreaTop.Height / 2),
|
||||
MaxSize = new Point(GUI.IntScale(25))
|
||||
}, TextManager.Get("CamFollowSubmarine"))
|
||||
{
|
||||
Selected = Camera.FollowSub,
|
||||
OnSelected = (tbox) =>
|
||||
{
|
||||
Camera.FollowSub = tbox.Selected;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
chatBox = new ChatBox(inGameHUD, isSinglePlayer: false);
|
||||
chatBox.OnEnterMessage += EnterChatMessage;
|
||||
chatBox.InputBox.OnTextChanged += TypingChatMessage;
|
||||
@@ -250,6 +242,19 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
};
|
||||
ShowLogButton.TextBlock.AutoScaleHorizontal = true;
|
||||
|
||||
cameraFollowsSub = new GUITickBox(new RectTransform(new Vector2(0.1f, 0.4f), buttonContainer.RectTransform)
|
||||
{
|
||||
MinSize = new Point(150, 0)
|
||||
}, TextManager.Get("CamFollowSubmarine"))
|
||||
{
|
||||
Selected = Camera.FollowSub,
|
||||
OnSelected = (tbox) =>
|
||||
{
|
||||
Camera.FollowSub = tbox.Selected;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
GameMain.DebugDraw = false;
|
||||
Hull.EditFire = false;
|
||||
@@ -676,6 +681,11 @@ namespace Barotrauma.Networking
|
||||
|
||||
VoipClient.Read(inc);
|
||||
break;
|
||||
#if DEBUG
|
||||
case ServerPacketHeader.VOICE_AMPLITUDE_DEBUG:
|
||||
GameMain.Client.DebugServerVoipAmplitude = inc.ReadRangedSingle(min: 0, max: 1, bitCount: 8);
|
||||
break;
|
||||
#endif
|
||||
case ServerPacketHeader.QUERY_STARTGAME:
|
||||
DebugConsole.Log("Received QUERY_STARTGAME packet.");
|
||||
string subName = inc.ReadString();
|
||||
@@ -1384,6 +1394,7 @@ namespace Barotrauma.Networking
|
||||
ServerSettings.AllowRewiring = inc.ReadBoolean();
|
||||
ServerSettings.AllowImmediateItemDelivery = inc.ReadBoolean();
|
||||
ServerSettings.AllowFriendlyFire = inc.ReadBoolean();
|
||||
ServerSettings.AllowDragAndDropGive = inc.ReadBoolean();
|
||||
ServerSettings.LockAllDefaultWires = inc.ReadBoolean();
|
||||
ServerSettings.AllowLinkingWifiToChat = inc.ReadBoolean();
|
||||
ServerSettings.MaximumMoneyTransferRequest = inc.ReadInt32();
|
||||
@@ -1814,6 +1825,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
GameStarted = inc.ReadBoolean();
|
||||
bool allowSpectating = inc.ReadBoolean();
|
||||
bool permadeathMode = inc.ReadBoolean();
|
||||
bool ironmanMode = inc.ReadBoolean();
|
||||
|
||||
ReadPermissions(inc);
|
||||
|
||||
@@ -1821,8 +1834,17 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (Screen.Selected != GameMain.GameScreen)
|
||||
{
|
||||
new GUIMessageBox(TextManager.Get("PleaseWait"), TextManager.Get(allowSpectating ? "RoundRunningSpectateEnabled" : "RoundRunningSpectateDisabled"));
|
||||
if (Screen.Selected is not ModDownloadScreen) { GameMain.NetLobbyScreen.Select(); }
|
||||
LocalizedString message;
|
||||
if (permadeathMode)
|
||||
{
|
||||
message = TextManager.Get(ironmanMode ? "RoundRunningIronman" : "RoundRunningPermadeath");
|
||||
}
|
||||
else
|
||||
{
|
||||
message = TextManager.Get(allowSpectating ? "RoundRunningSpectateEnabled" : "RoundRunningSpectateDisabled");
|
||||
}
|
||||
new GUIMessageBox(TextManager.Get("PleaseWait"), message);
|
||||
if (!(Screen.Selected is ModDownloadScreen)) { GameMain.NetLobbyScreen.Select(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2105,6 +2127,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
float sendingTime = inc.ReadSingle() - 0.0f;//TODO: reimplement inc.SenderConnection.RemoteTimeOffset;
|
||||
|
||||
EndRoundTimeRemaining = inc.ReadSingle();
|
||||
|
||||
SegmentTableReader<ServerNetSegment>.Read(inc,
|
||||
segmentDataReader: (segment, inc) =>
|
||||
{
|
||||
@@ -2375,7 +2399,16 @@ namespace Barotrauma.Networking
|
||||
WaitForNextRoundRespawn = waitForNextRoundRespawn;
|
||||
IWriteMessage msg = new WriteOnlyMessage();
|
||||
msg.WriteByte((byte)ClientPacketHeader.READY_TO_SPAWN);
|
||||
msg.WriteBoolean((bool)waitForNextRoundRespawn);
|
||||
msg.WriteBoolean(GameMain.NetLobbyScreen.Spectating);
|
||||
msg.WriteBoolean(waitForNextRoundRespawn);
|
||||
ClientPeer?.Send(msg, DeliveryMethod.Reliable);
|
||||
}
|
||||
|
||||
public void SendTakeOverBotRequest(CharacterInfo bot)
|
||||
{
|
||||
IWriteMessage msg = new WriteOnlyMessage();
|
||||
msg.WriteByte((byte)ClientPacketHeader.TAKEOVERBOT);
|
||||
msg.WriteUInt16(bot.ID);
|
||||
ClientPeer?.Send(msg, DeliveryMethod.Reliable);
|
||||
}
|
||||
|
||||
@@ -2711,16 +2744,19 @@ namespace Barotrauma.Networking
|
||||
if (should != null && should.Value) { return; }
|
||||
|
||||
if (string.IsNullOrEmpty(message.Text)) { return; }
|
||||
if (message.Sender != null && !message.Sender.IsDead)
|
||||
if (message.SenderCharacter is { IsDead: false } sender)
|
||||
{
|
||||
if (message.Text.IsNullOrEmpty())
|
||||
{
|
||||
message.Sender.ShowTextlessSpeechBubble(2.0f, message.Color);
|
||||
|
||||
sender.ShowTextlessSpeechBubble(2.0f, message.Color);
|
||||
}
|
||||
else
|
||||
{
|
||||
message.Sender.ShowSpeechBubble(message.Color, message.Text);
|
||||
sender.ShowSpeechBubble(message.Color, message.Text);
|
||||
if (!sender.IsBot)
|
||||
{
|
||||
sender.TextChatVolume = 1f;
|
||||
}
|
||||
}
|
||||
}
|
||||
GameMain.NetLobbyScreen.NewChatMessage(message);
|
||||
@@ -3204,19 +3240,19 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
LocalizedString respawnText = string.Empty;
|
||||
Color textColor = Color.White;
|
||||
bool canChooseRespawn =
|
||||
GameMain.GameSession.GameMode is CampaignMode &&
|
||||
Character.Controlled == null &&
|
||||
Level.Loaded?.Type != LevelData.LevelType.Outpost &&
|
||||
(characterInfo == null || HasSpawned);
|
||||
bool hideRespawnButtons = false;
|
||||
|
||||
if (EndRoundTimeRemaining > 0)
|
||||
{
|
||||
respawnText = TextManager.GetWithVariable("endinground", "[time]", ToolBox.SecondsToReadableTime(EndRoundTimeRemaining))
|
||||
.Fallback(ToolBox.SecondsToReadableTime(EndRoundTimeRemaining), useDefaultLanguageIfFound: false);
|
||||
}
|
||||
if (RespawnManager.CurrentState == RespawnManager.State.Waiting)
|
||||
{
|
||||
if (RespawnManager.RespawnCountdownStarted)
|
||||
{
|
||||
float timeLeft = (float)(RespawnManager.RespawnTime - DateTime.Now).TotalSeconds;
|
||||
respawnText = TextManager.GetWithVariable(
|
||||
RespawnManager.UsingShuttle && !RespawnManager.ForceSpawnInMainSub ?
|
||||
"RespawnShuttleDispatching" : "RespawningIn", "[time]", ToolBox.SecondsToReadableTime(timeLeft));
|
||||
respawnText = TextManager.GetWithVariable("RespawningIn", "[time]", ToolBox.SecondsToReadableTime(timeLeft));
|
||||
}
|
||||
else if (RespawnManager.PendingRespawnCount > 0)
|
||||
{
|
||||
@@ -3239,12 +3275,12 @@ namespace Barotrauma.Networking
|
||||
//textScale = 1.0f + phase * 0.5f;
|
||||
textColor = Color.Lerp(GUIStyle.Red, Color.White, 1.0f - phase);
|
||||
}
|
||||
canChooseRespawn = false;
|
||||
hideRespawnButtons = true;
|
||||
}
|
||||
|
||||
GameMain.GameSession?.SetRespawnInfo(
|
||||
visible: !respawnText.IsNullOrEmpty() || canChooseRespawn, text: respawnText.Value, textColor: textColor,
|
||||
buttonsVisible: canChooseRespawn, waitForNextRoundRespawn: (WaitForNextRoundRespawn ?? true));
|
||||
GameMain.GameSession.SetRespawnInfo(
|
||||
text: respawnText.Value, textColor: textColor,
|
||||
waitForNextRoundRespawn: (WaitForNextRoundRespawn ?? true), hideButtons: hideRespawnButtons);
|
||||
}
|
||||
|
||||
if (!ShowNetStats) { return; }
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
{
|
||||
@@ -23,6 +22,14 @@ namespace Barotrauma.Networking
|
||||
get; private set;
|
||||
}
|
||||
|
||||
public static void ShowDeathPromptIfNeeded(float delay = 1.0f)
|
||||
{
|
||||
if (UseDeathPrompt)
|
||||
{
|
||||
DeathPrompt.Create(delay);
|
||||
}
|
||||
}
|
||||
|
||||
partial void UpdateTransportingProjSpecific(float deltaTime)
|
||||
{
|
||||
if (GameMain.Client?.Character == null || GameMain.Client.Character.Submarine != RespawnShuttle) { return; }
|
||||
@@ -37,72 +44,10 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
}
|
||||
|
||||
private CoroutineHandle respawnPromptCoroutine;
|
||||
|
||||
public void ShowRespawnPromptIfNeeded(float delay = 5.0f)
|
||||
{
|
||||
if (!UseRespawnPrompt) { return; }
|
||||
if (CoroutineManager.IsCoroutineRunning(respawnPromptCoroutine) || GUIMessageBox.MessageBoxes.Any(mb => mb.UserData as string == "respawnquestionprompt"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
respawnPromptCoroutine = CoroutineManager.Invoke(() =>
|
||||
{
|
||||
if (Character.Controlled != null || (GameMain.GameSession is not { IsRunning: true })) { return; }
|
||||
|
||||
LocalizedString text;
|
||||
GUIMessageBox respawnPrompt;
|
||||
if (SkillLossPercentageOnImmediateRespawn > 0)
|
||||
{
|
||||
// Respawn asap with extra skill loss?
|
||||
text = TextManager.GetWithVariable("respawnquestionprompt", "[percentage]", ((int)Math.Round(SkillLossPercentageOnImmediateRespawn)).ToString());
|
||||
respawnPrompt = new GUIMessageBox(
|
||||
TextManager.Get("tutorial.tryagainheader"), text,
|
||||
new LocalizedString[] { TextManager.Get("respawnquestionpromptrespawn"), TextManager.Get("respawnquestionpromptwait") })
|
||||
{
|
||||
UserData = "respawnquestionprompt"
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
// Respawn asap?
|
||||
text = TextManager.Get("respawnquestionpromptnoloss");
|
||||
respawnPrompt = new GUIMessageBox(
|
||||
TextManager.Get("tutorial.tryagainheader"), text,
|
||||
new LocalizedString[] { TextManager.Get("respawnquestionpromptrespawnnoloss"), TextManager.Get("respawnquestionpromptwait") })
|
||||
{
|
||||
UserData = "respawnquestionprompt"
|
||||
};
|
||||
}
|
||||
if (SkillLossPercentageOnDeath > 0)
|
||||
{
|
||||
// You have died... etc added BEFORE the above text
|
||||
text =
|
||||
TextManager.GetWithVariable("respawnskillpenalty", "[percentage]", ((int)SkillLossPercentageOnDeath).ToString()) +
|
||||
"\n\n" + text;
|
||||
};
|
||||
|
||||
respawnPrompt.Buttons[0].OnClicked += (btn, userdata) =>
|
||||
{
|
||||
GameMain.Client?.SendRespawnPromptResponse(waitForNextRoundRespawn: false);
|
||||
respawnPrompt.Close();
|
||||
return true;
|
||||
};
|
||||
respawnPrompt.Buttons[1].OnClicked += (btn, userdata) =>
|
||||
{
|
||||
GameMain.Client?.SendRespawnPromptResponse(waitForNextRoundRespawn: true);
|
||||
respawnPrompt.Close();
|
||||
return true;
|
||||
};
|
||||
}, delay: delay);
|
||||
}
|
||||
|
||||
public void ClientEventRead(IReadMessage msg, float sendingTime)
|
||||
{
|
||||
bool respawnPromptPending = false;
|
||||
var newState = (State)msg.ReadRangedInteger(0, Enum.GetNames(typeof(State)).Length);
|
||||
ForceSpawnInMainSub = false;
|
||||
switch (newState)
|
||||
{
|
||||
case State.Transporting:
|
||||
@@ -122,7 +67,6 @@ namespace Barotrauma.Networking
|
||||
RequiredRespawnCount = msg.ReadUInt16();
|
||||
respawnPromptPending = msg.ReadBoolean();
|
||||
RespawnCountdownStarted = msg.ReadBoolean();
|
||||
ForceSpawnInMainSub = msg.ReadBoolean();
|
||||
ResetShuttle();
|
||||
float newRespawnTime = msg.ReadSingle();
|
||||
RespawnTime = DateTime.Now + new TimeSpan(0, 0, 0, 0, milliseconds: (int)(newRespawnTime * 1000.0f));
|
||||
@@ -136,7 +80,7 @@ namespace Barotrauma.Networking
|
||||
if (respawnPromptPending)
|
||||
{
|
||||
GameMain.Client.HasSpawned = true;
|
||||
ShowRespawnPromptIfNeeded(delay: 1.0f);
|
||||
DeathPrompt.Create(delay: 1.0f);
|
||||
}
|
||||
|
||||
msg.ReadPadBits();
|
||||
|
||||
@@ -468,11 +468,28 @@ namespace Barotrauma.Networking
|
||||
};
|
||||
AssignGUIComponent(nameof(SaveServerLogs), saveLogsBox);
|
||||
|
||||
LocalizedString newCampaignDefaultSalaryLabel = TextManager.Get("ServerSettingsNewCampaignDefaultSalary");
|
||||
NetLobbyScreen.CreateLabeledSlider(listBox.Content, headerTag: "ServerSettingsNewCampaignDefaultSalary", valueLabelTag: "ServerSettingsKickVotesRequired", tooltipTag: "ServerSettingsNewCampaignDefaultSalaryToolTip",
|
||||
out var defaultSalarySlider, out var defaultSalarySliderLabel);
|
||||
defaultSalarySlider.Range = new Vector2(0, 100);
|
||||
defaultSalarySlider.StepValue = 1;
|
||||
defaultSalarySlider.OnMoved = (scrollBar, _) =>
|
||||
{
|
||||
if (scrollBar.UserData is not GUITextBlock text) { return false; }
|
||||
text.Text = TextManager.AddPunctuation(
|
||||
':',
|
||||
newCampaignDefaultSalaryLabel,
|
||||
TextManager.GetWithVariable("percentageformat", "[value]", ((int)Math.Round(scrollBar.BarScrollValue, digits: 0)).ToString()));
|
||||
return true;
|
||||
};
|
||||
AssignGUIComponent(nameof(NewCampaignDefaultSalary), defaultSalarySlider);
|
||||
defaultSalarySlider.OnMoved(defaultSalarySlider, defaultSalarySlider.BarScroll);
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// game settings
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
GUILayoutGroup buttonHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.1f), listBox.Content.RectTransform), isHorizontal: true)
|
||||
GUILayoutGroup buttonHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.1f), listBox.Content.RectTransform), isHorizontal: true, childAnchor: Anchor.BottomLeft)
|
||||
{
|
||||
Stretch = true,
|
||||
RelativeSpacing = 0.05f
|
||||
@@ -683,7 +700,7 @@ namespace Barotrauma.Networking
|
||||
// antigriefing
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
var tickBoxContainer = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.25f), listBox.Content.RectTransform))
|
||||
var tickBoxContainer = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.268f), listBox.Content.RectTransform))
|
||||
{
|
||||
AutoHideScrollBar = true,
|
||||
UseGridLayout = true
|
||||
@@ -693,6 +710,10 @@ namespace Barotrauma.Networking
|
||||
var allowFriendlyFire = new GUITickBox(new RectTransform(new Vector2(0.48f, 0.05f), tickBoxContainer.Content.RectTransform),
|
||||
TextManager.Get("ServerSettingsAllowFriendlyFire"));
|
||||
AssignGUIComponent(nameof(AllowFriendlyFire), allowFriendlyFire);
|
||||
|
||||
var allowDragAndDropGive = new GUITickBox(new RectTransform(new Vector2(0.48f, 0.05f), tickBoxContainer.Content.RectTransform),
|
||||
TextManager.Get("ServerSettingsAllowDragAndDropGive"));
|
||||
AssignGUIComponent(nameof(AllowDragAndDropGive), allowDragAndDropGive);
|
||||
|
||||
var killableNPCs = new GUITickBox(new RectTransform(new Vector2(0.48f, 0.05f), tickBoxContainer.Content.RectTransform),
|
||||
TextManager.Get("ServerSettingsKillableNPCs"));
|
||||
|
||||
@@ -1,19 +1,10 @@
|
||||
using Concentus.Enums;
|
||||
using Concentus.Structs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
{
|
||||
static partial class VoipConfig
|
||||
{
|
||||
public const int FREQUENCY = 48000; //48Khz
|
||||
public const int BITRATE = 16000; //16Kbps
|
||||
public const int BUFFER_SIZE = (8 * MAX_COMPRESSED_SIZE * FREQUENCY) / BITRATE; //20ms window
|
||||
|
||||
public static OpusEncoder CreateEncoder()
|
||||
{
|
||||
var encoder = new OpusEncoder(FREQUENCY, 1, OpusApplication.OPUS_APPLICATION_VOIP);
|
||||
@@ -22,10 +13,5 @@ namespace Barotrauma.Networking
|
||||
encoder.SignalType = OpusSignal.OPUS_SIGNAL_VOICE;
|
||||
return encoder;
|
||||
}
|
||||
|
||||
public static OpusDecoder CreateDecoder()
|
||||
{
|
||||
return new OpusDecoder(FREQUENCY, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user