Merge remote-tracking branch 'upstream/master' into develop

This commit is contained in:
EvilFactory
2024-04-24 12:20:11 -03:00
397 changed files with 15250 additions and 6473 deletions

View File

@@ -89,7 +89,7 @@ namespace Barotrauma.Networking
public readonly List<SubmarineInfo> ServerSubmarines = new List<SubmarineInfo>();
public string ServerName { get; private set; }
public string ServerName => ServerSettings.ServerName;
private bool canStart;
@@ -270,11 +270,11 @@ namespace Barotrauma.Networking
otherClients = new List<Client>();
ServerSettings = new ServerSettings(this, "Server", 0, 0, 0, false, false, System.Net.IPAddress.Any);
ServerSettings = new ServerSettings(this, serverName, 0, 0, 0, false, false, System.Net.IPAddress.Any);
Voting = new Voting();
serverEndpoints = endpoints;
InitiateServerJoin(serverName);
InitiateServerJoin();
//ServerLog = new ServerLog("");
@@ -289,7 +289,7 @@ namespace Barotrauma.Networking
return serverInfo;
}
private void InitiateServerJoin(string hostName)
private void InitiateServerJoin()
{
LastClientListUpdateID = 0;
@@ -306,8 +306,6 @@ namespace Barotrauma.Networking
GameMain.NetLobbyScreen.ChatInput.Enabled = false;
}
ServerName = hostName;
myCharacter = Character.Controlled;
ChatMessage.LastID = 0;
@@ -318,9 +316,8 @@ namespace Barotrauma.Networking
CoroutineManager.StartCoroutine(WaitForStartingInfo(), "WaitForStartingInfo");
}
public void SetLobbyPublic(bool isPublic)
public static void SetLobbyPublic(bool isPublic)
{
GameMain.NetLobbyScreen.SetPublic(isPublic);
SteamManager.SetLobbyPublic(isPublic);
}
@@ -725,7 +722,7 @@ namespace Barotrauma.Networking
if (readyToStart && !CoroutineManager.IsCoroutineRunning("WaitForStartRound"))
{
CoroutineManager.StartCoroutine(GameMain.NetLobbyScreen.WaitForStartRound(startButton: null), "WaitForStartRound");
CoroutineManager.StartCoroutine(NetLobbyScreen.WaitForStartRound(startButton: null), "WaitForStartRound");
}
break;
case ServerPacketHeader.STARTGAME:
@@ -1098,7 +1095,7 @@ namespace Barotrauma.Networking
var prevContentPackages = ClientPeer.ServerContentPackages;
//decrement lobby update ID to make sure we update the lobby when we reconnect
GameMain.NetLobbyScreen.LastUpdateID--;
InitiateServerJoin(ServerName);
InitiateServerJoin();
if (ClientPeer != null)
{
//restore the previous list of content packages so we can reconnect immediately without having to recheck that the packages match
@@ -1191,7 +1188,7 @@ namespace Barotrauma.Networking
{
if (!CoroutineManager.IsCoroutineRunning("WaitForStartingInfo"))
{
InitiateServerJoin(ServerName);
InitiateServerJoin();
yield return new WaitForSeconds(5.0f);
}
yield return new WaitForSeconds(0.5f);
@@ -1255,7 +1252,7 @@ namespace Barotrauma.Networking
if (!(this.permittedConsoleCommands.Any(c => !permittedConsoleCommands.Contains(c)) ||
permittedConsoleCommands.Any(c => !this.permittedConsoleCommands.Contains(c))))
{
if (newPermissions == permissions) return;
if (newPermissions == permissions) { return; }
}
bool refreshCampaignUI = permissions.HasFlag(ClientPermissions.ManageCampaign) != newPermissions.HasFlag(ClientPermissions.ManageCampaign) ||
@@ -1337,6 +1334,8 @@ namespace Barotrauma.Networking
}
GameMain.NetLobbyScreen.RefreshEnabledElements();
//close settings menu in case it was open
ServerSettings.Close();
OnPermissionChanged.Invoke(new PermissionChangedEvent(permissions, this.permittedConsoleCommands));
}
@@ -2027,18 +2026,15 @@ namespace Barotrauma.Networking
GameMain.NetLobbyScreen.LastUpdateID = updateID;
ServerSettings.ServerLog.ServerName = ServerSettings.ServerName;
if (!GameMain.NetLobbyScreen.ServerName.Selected) { GameMain.NetLobbyScreen.ServerName.Text = ServerSettings.ServerName; }
if (!GameMain.NetLobbyScreen.ServerMessage.Selected) { GameMain.NetLobbyScreen.ServerMessage.Text = ServerSettings.ServerMessageText; }
GameMain.NetLobbyScreen.UsingShuttle = usingShuttle;
if (!allowSubVoting) { GameMain.NetLobbyScreen.TrySelectSub(selectSubName, selectSubHash, GameMain.NetLobbyScreen.SubList); }
if (!allowSubVoting || GameMain.NetLobbyScreen.SelectedSub == null) { GameMain.NetLobbyScreen.TrySelectSub(selectSubName, selectSubHash, GameMain.NetLobbyScreen.SubList); }
GameMain.NetLobbyScreen.TrySelectSub(selectShuttleName, selectShuttleHash, GameMain.NetLobbyScreen.ShuttleList.ListBox);
GameMain.NetLobbyScreen.SetTraitorProbability(traitorProbability);
GameMain.NetLobbyScreen.SetTraitorDangerLevel(traitorDangerLevel);
GameMain.NetLobbyScreen.SetMissionType(missionType);
GameMain.NetLobbyScreen.LevelSeed = levelSeed;
GameMain.NetLobbyScreen.SelectMode(modeIndex);
if (isInitialUpdate && GameMain.NetLobbyScreen.SelectedMode == GameModePreset.MultiPlayerCampaign)
@@ -2055,7 +2051,6 @@ namespace Barotrauma.Networking
}
GameMain.NetLobbyScreen.SetAllowSpectating(allowSpectating);
GameMain.NetLobbyScreen.LevelSeed = levelSeed;
GameMain.NetLobbyScreen.SetLevelDifficulty(levelDifficulty);
GameMain.NetLobbyScreen.SetBotSpawnMode(botSpawnMode);
GameMain.NetLobbyScreen.SetBotCount(botCount);
@@ -2576,12 +2571,17 @@ namespace Barotrauma.Networking
}
public override void CreateEntityEvent(INetSerializable entity, NetEntityEvent.IData extraData = null)
{
CreateEntityEvent(entity, extraData, requireControlledCharacter: true);
}
public void CreateEntityEvent(INetSerializable entity, NetEntityEvent.IData extraData, bool requireControlledCharacter)
{
if (entity is not IClientSerializable clientSerializable)
{
throw new InvalidCastException($"Entity is not {nameof(IClientSerializable)}");
}
EntityEventManager.CreateEvent(clientSerializable, extraData);
EntityEventManager.CreateEvent(clientSerializable, extraData, requireControlledCharacter);
}
public bool HasPermission(ClientPermissions permission)
@@ -2708,11 +2708,21 @@ namespace Barotrauma.Networking
public override void AddChatMessage(ChatMessage message)
{
var should = GameMain.LuaCs.Hook.Call<bool?>("chatMessage", message.Text, message.SenderClient, message.Type, message);
if (should != null && should.Value) return;
base.AddChatMessage(message);
if (should != null && should.Value) { return; }
if (string.IsNullOrEmpty(message.Text)) { return; }
if (message.Sender != null && !message.Sender.IsDead)
{
if (message.Text.IsNullOrEmpty())
{
message.Sender.ShowTextlessSpeechBubble(2.0f, message.Color);
}
else
{
message.Sender.ShowSpeechBubble(message.Color, message.Text);
}
}
GameMain.NetLobbyScreen.NewChatMessage(message);
chatBox.AddMessage(message);
}
@@ -2901,7 +2911,7 @@ namespace Barotrauma.Networking
ClientPeer.Send(msg, DeliveryMethod.Reliable);
}
public bool SpectateClicked(GUIButton button, object _)
public bool JoinOnGoingClicked(GUIButton button, object _)
{
MultiPlayerCampaign campaign =
GameMain.NetLobbyScreen.SelectedMode == GameMain.GameSession?.GameMode.Preset ?
@@ -3290,17 +3300,36 @@ namespace Barotrauma.Networking
private void CreateSelectionRelatedButtons(Client client, GUIComponent frame)
{
var content = new GUIFrame(new RectTransform(new Vector2(1f, 1.0f - frame.RectTransform.RelativeSize.Y), frame.RectTransform, Anchor.BottomCenter, Pivot.TopCenter),
style: null);
var content = new GUILayoutGroup(new RectTransform(new Vector2(1f, 1.0f - frame.RectTransform.RelativeSize.Y), frame.RectTransform, Anchor.BottomCenter, Pivot.TopCenter), childAnchor: Anchor.TopCenter);
var mute = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.5f), content.RectTransform, Anchor.TopCenter),
var mute = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.2f), content.RectTransform, Anchor.TopCenter),
TextManager.Get("Mute"))
{
Selected = client.MutedLocally,
OnSelected = (tickBox) => { client.MutedLocally = tickBox.Selected; return true; }
};
var volumeLayout = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.45f), content.RectTransform, Anchor.TopCenter), isHorizontal: false);
var buttonContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.35f), content.RectTransform, Anchor.BottomCenter), isHorizontal: true, childAnchor: Anchor.BottomLeft)
var volumeTextLayout = new GUILayoutGroup(new RectTransform(new Vector2(1f, 0.5f), volumeLayout.RectTransform), isHorizontal: true, childAnchor: Anchor.CenterLeft);
var label = new GUITextBlock(new RectTransform(new Vector2(0.6f, 1f), volumeTextLayout.RectTransform), TextManager.Get("VoiceChatVolume"));
var percentageText = new GUITextBlock(new RectTransform(new Vector2(0.4f, 1f), volumeTextLayout.RectTransform), ToolBox.GetFormattedPercentage(client.VoiceVolume), textAlignment: Alignment.Right);
var volumeSlider = new GUIScrollBar(new RectTransform(new Vector2(1f, 0.5f), volumeLayout.RectTransform), barSize: 0.1f, style: "GUISlider")
{
Range = new Vector2(0f, 1f),
BarScroll = client.VoiceVolume / Client.MaxVoiceChatBoost,
OnMoved = (_, barScroll) =>
{
float newVolume = barScroll * Client.MaxVoiceChatBoost;
client.VoiceVolume = newVolume;
percentageText.Text = ToolBox.GetFormattedPercentage(newVolume);
return true;
}
};
var buttonContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.35f), content.RectTransform), isHorizontal: true, childAnchor: Anchor.BottomLeft)
{
RelativeSpacing = 0.05f,
Stretch = true
@@ -3334,7 +3363,7 @@ namespace Barotrauma.Networking
TextManager.Get("Ban"), style: "GUIButtonSmall")
{
UserData = client,
OnClicked = (btn, userdata) => { GameMain.NetLobbyScreen.BanPlayer(client); return false; }
OnClicked = (btn, userdata) => { NetLobbyScreen.BanPlayer(client); return false; }
};
}
if (HasPermission(ClientPermissions.Kick) && client.AllowKicking)
@@ -3343,7 +3372,7 @@ namespace Barotrauma.Networking
TextManager.Get("Kick"), style: "GUIButtonSmall")
{
UserData = client,
OnClicked = (btn, userdata) => { GameMain.NetLobbyScreen.KickPlayer(client); return false; }
OnClicked = (btn, userdata) => { NetLobbyScreen.KickPlayer(client); return false; }
};
}
else if (ServerSettings.AllowVoteKick && client.AllowKicking)