v0.13.0.11

This commit is contained in:
Joonas Rikkonen
2021-04-22 17:33:08 +03:00
parent 0697d7fc64
commit 8bb31f2893
391 changed files with 17271 additions and 5949 deletions
@@ -56,6 +56,11 @@ namespace Barotrauma.Networking
public readonly NetStats NetStats;
protected GUITickBox cameraFollowsSub;
public GUITickBox FollowSubTickBox => cameraFollowsSub;
public bool IsFollowSubTickBoxVisible =>
gameStarted && Screen.Selected == GameMain.GameScreen &&
cameraFollowsSub != null && cameraFollowsSub.Visible;
public CameraTransition EndCinematic;
@@ -159,6 +164,12 @@ namespace Barotrauma.Networking
get { return entityEventManager; }
}
public bool? WaitForNextRoundRespawn
{
get;
set;
}
private readonly object serverEndpoint;
private readonly int ownerKey;
private readonly bool steamP2POwner;
@@ -185,10 +196,10 @@ namespace Barotrauma.Networking
CanBeFocused = false
};
cameraFollowsSub = new GUITickBox(new RectTransform(new Vector2(0.05f, 0.05f), inGameHUD.RectTransform, anchor: Anchor.TopCenter)
cameraFollowsSub = new GUITickBox(new RectTransform(new Vector2(0.05f, 0.05f), inGameHUD.RectTransform, anchor: Anchor.TopCenter, pivot: Pivot.CenterLeft)
{
AbsoluteOffset = new Point(0, 5),
MaxSize = new Point(25, 25)
AbsoluteOffset = new Point(0, HUDLayoutSettings.ButtonAreaTop.Y + HUDLayoutSettings.ButtonAreaTop.Height / 2),
MaxSize = new Point(GUI.IntScale(25))
}, TextManager.Get("CamFollowSubmarine"))
{
Selected = Camera.FollowSub,
@@ -857,12 +868,25 @@ namespace Barotrauma.Networking
string endMessage = string.Empty;
endMessage = inc.ReadString();
bool missionSuccessful = inc.ReadBoolean();
byte missionCount = inc.ReadByte();
for (int i = 0; i < missionCount; i++)
{
bool missionSuccessful = inc.ReadBoolean();
var mission = GameMain.GameSession?.GetMission(i);
if (mission != null)
{
mission.Completed = missionSuccessful;
}
}
CharacterTeamType winningTeam = (CharacterTeamType)inc.ReadByte();
if (missionSuccessful && GameMain.GameSession?.Mission != null)
if (winningTeam != CharacterTeamType.None)
{
GameMain.GameSession.WinningTeam = winningTeam;
GameMain.GameSession.Mission.Completed = true;
var combatMission = GameMain.GameSession.Missions.FirstOrDefault(m => m is CombatMission);
if (combatMission != null)
{
combatMission.Completed = true;
}
}
byte traitorCount = inc.ReadByte();
@@ -928,7 +952,11 @@ namespace Barotrauma.Networking
ReadTraitorMessage(inc);
break;
case ServerPacketHeader.MISSION:
GameMain.GameSession?.Mission?.ClientRead(inc);
{
int missionIndex = inc.ReadByte();
Mission mission = GameMain.GameSession?.GetMission(missionIndex);
mission?.ClientRead(inc);
}
break;
case ServerPacketHeader.EVENTACTION:
GameMain.GameSession?.EventManager.ClientRead(inc);
@@ -959,17 +987,26 @@ namespace Barotrauma.Networking
throw new Exception(errorMsg);
}
string missionIdentifier = inc.ReadString() ?? "";
if (missionIdentifier != (GameMain.GameSession.Mission?.Prefab.Identifier ?? ""))
byte missionCount = inc.ReadByte();
if (missionCount != GameMain.GameSession.Missions.Count())
{
string errorMsg = $"Mission equality check failed. The mission selected at your end doesn't match the one loaded by the server (server: {missionIdentifier ?? "null"}, client: {GameMain.GameSession.Mission?.Prefab.Identifier ?? ""})";
GameAnalyticsManager.AddErrorEventOnce("GameClient.StartGame:MissionsDontMatch" + Level.Loaded.Seed, GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg);
string errorMsg = $"Mission equality check failed. Mission count doesn't match the server (server: {missionCount}, client: {GameMain.GameSession.Missions.Count()})";
throw new Exception(errorMsg);
}
foreach (Mission mission in GameMain.GameSession.Missions)
{
string missionIdentifier = inc.ReadString() ?? "";
if (missionIdentifier != mission.Prefab.Identifier)
{
string errorMsg = $"Mission equality check failed. The mission selected at your end doesn't match the one loaded by the server (server: {missionIdentifier ?? "null"}, client: {mission.Prefab.Identifier})";
GameAnalyticsManager.AddErrorEventOnce("GameClient.StartGame:MissionsDontMatch" + Level.Loaded.Seed, GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg);
throw new Exception(errorMsg);
}
}
byte equalityCheckValueCount = inc.ReadByte();
List<int> levelEqualityCheckValues = new List<int>();
for (int i = 0; i<equalityCheckValueCount; i++)
for (int i = 0; i < equalityCheckValueCount; i++)
{
levelEqualityCheckValues.Add(inc.ReadInt32());
}
@@ -1004,7 +1041,10 @@ namespace Barotrauma.Networking
}
}
GameMain.GameSession.Mission?.ClientReadInitial(inc);
foreach (Mission mission in GameMain.GameSession.Missions)
{
mission.ClientReadInitial(inc);
}
roundInitStatus = RoundInitStatus.Started;
}
@@ -1395,6 +1435,8 @@ namespace Barotrauma.Networking
EndVoteTickBox.Selected = false;
WaitForNextRoundRespawn = null;
roundInitStatus = RoundInitStatus.Starting;
int seed = inc.ReadInt32();
@@ -1411,6 +1453,7 @@ namespace Barotrauma.Networking
bool respawnAllowed = inc.ReadBoolean();
serverSettings.AllowDisguises = inc.ReadBoolean();
serverSettings.AllowRewiring = inc.ReadBoolean();
serverSettings.LockAllDefaultWires = inc.ReadBoolean();
serverSettings.AllowRagdollButton = inc.ReadBoolean();
GameMain.NetLobbyScreen.UsingShuttle = inc.ReadBoolean();
GameMain.LightManager.LosMode = (LosMode)inc.ReadByte();
@@ -1432,7 +1475,12 @@ namespace Barotrauma.Networking
string subHash = inc.ReadString();
string shuttleName = inc.ReadString();
string shuttleHash = inc.ReadString();
int missionIndex = inc.ReadInt16();
List<int> missionIndices = new List<int>();
int missionCount = inc.ReadByte();
for (int i = 0; i < missionCount; i++)
{
missionIndices.Add(inc.ReadInt16());
}
if (!GameMain.NetLobbyScreen.TrySelectSub(subName, subHash, GameMain.NetLobbyScreen.SubList))
{
roundInitStatus = RoundInitStatus.Interrupted;
@@ -1486,7 +1534,9 @@ namespace Barotrauma.Networking
yield return CoroutineStatus.Failure;
}
GameMain.GameSession = new GameSession(GameMain.NetLobbyScreen.SelectedSub, gameMode, missionPrefab: missionIndex < 0 ? null : MissionPrefab.List[missionIndex]);
var selectedMissions = missionIndices.Select(i => MissionPrefab.List[i]);
GameMain.GameSession = new GameSession(GameMain.NetLobbyScreen.SelectedSub, gameMode, missionPrefabs: selectedMissions);
GameMain.GameSession.StartRound(levelSeed, levelDifficulty);
}
else
@@ -1653,13 +1703,15 @@ namespace Barotrauma.Networking
}
foreach (Submarine sub in Submarine.MainSubs[i].DockedTo)
{
if (sub.Info.Type == SubmarineType.Outpost) { continue; }
sub.TeamID = teamID;
}
}
if (respawnAllowed)
{
respawnManager = new RespawnManager(this, GameMain.NetLobbyScreen.UsingShuttle && gameMode != GameModePreset.MultiPlayerCampaign ? GameMain.NetLobbyScreen.SelectedShuttle : null);
if (respawnAllowed)
{
bool isOutpost = GameMain.GameSession?.GameMode is MultiPlayerCampaign campaign && Level.Loaded?.Type == LevelData.LevelType.Outpost;
respawnManager = new RespawnManager(this, GameMain.NetLobbyScreen.UsingShuttle && !isOutpost ? GameMain.NetLobbyScreen.SelectedShuttle : null);
}
gameStarted = true;
@@ -1702,6 +1754,7 @@ namespace Barotrauma.Networking
gameStarted = false;
Character.Controlled = null;
WaitForNextRoundRespawn = null;
SpawnAsTraitor = false;
GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;
GameMain.LightManager.LosEnabled = false;
@@ -1712,7 +1765,7 @@ namespace Barotrauma.Networking
// Enable characters near the main sub for the endCinematic
foreach (Character c in Character.CharacterList)
{
if (Vector2.DistanceSquared(Submarine.MainSub.WorldPosition, c.WorldPosition) < NetConfig.EnableCharacterDistSqr)
if (Vector2.DistanceSquared(Submarine.MainSub.WorldPosition, c.WorldPosition) < MathUtils.Pow2(c.Params.DisableDistance))
{
c.Enabled = true;
}
@@ -1757,8 +1810,10 @@ namespace Barotrauma.Networking
var matchingSub = SubmarineInfo.SavedSubmarines.FirstOrDefault(s => s.Name == subName && s.MD5Hash.Hash == subHash);
if (matchingSub == null)
{
matchingSub = new SubmarineInfo(Path.Combine(SubmarineInfo.SavePath, subName) + ".sub", subHash, tryLoad: false);
matchingSub.SubmarineClass = (SubmarineClass)subClass;
matchingSub = new SubmarineInfo(Path.Combine(SubmarineInfo.SavePath, subName) + ".sub", subHash, tryLoad: false)
{
SubmarineClass = (SubmarineClass)subClass
};
}
matchingSub.RequiredContentPackagesInstalled = requiredContentPackagesInstalled;
ServerSubmarines.Add(matchingSub);
@@ -1928,14 +1983,19 @@ namespace Barotrauma.Networking
}
foreach (Client client in ConnectedClients)
{
if (!previouslyConnectedClients.Any(c => c.ID == client.ID))
int index = previouslyConnectedClients.FindIndex(c => c.ID == client.ID);
if (index < 0)
{
while (previouslyConnectedClients.Count > 100)
if (previouslyConnectedClients.Count > 100)
{
previouslyConnectedClients.RemoveAt(0);
previouslyConnectedClients.RemoveRange(0, previouslyConnectedClients.Count - 100);
}
previouslyConnectedClients.Add(client);
}
else
{
previouslyConnectedClients.RemoveAt(index);
}
previouslyConnectedClients.Add(client);
}
if (updateClientListId) { LastClientListUpdateID = listId; }
@@ -2028,6 +2088,8 @@ namespace Barotrauma.Networking
bool autoRestartEnabled = inc.ReadBoolean();
float autoRestartTimer = autoRestartEnabled ? inc.ReadSingle() : 0.0f;
bool radiationEnabled = inc.ReadBoolean();
//ignore the message if we already a more up-to-date one
//or if we're still waiting for the initial update
if (NetIdUtils.IdMoreRecent(updateID, GameMain.NetLobbyScreen.LastUpdateID) &&
@@ -2038,8 +2100,14 @@ namespace Barotrauma.Networking
serverSettings.ClientRead(settingsBuf);
if (!IsServerOwner)
{
ServerInfo info = GameMain.ServerListScreen.UpdateServerInfoWithServerSettings(serverEndpoint, serverSettings);
ServerInfo info = serverSettings.GetServerListInfo();
GameMain.ServerListScreen.AddToRecentServers(info);
GameMain.NetLobbyScreen.Favorite.Visible = true;
GameMain.NetLobbyScreen.Favorite.Selected = GameMain.ServerListScreen.IsFavorite(info);
}
else
{
GameMain.NetLobbyScreen.Favorite.Visible = false;
}
GameMain.NetLobbyScreen.LastUpdateID = updateID;
@@ -2083,8 +2151,9 @@ namespace Barotrauma.Networking
GameMain.NetLobbyScreen.SetAllowSpectating(allowSpectating);
GameMain.NetLobbyScreen.LevelSeed = levelSeed;
GameMain.NetLobbyScreen.SetLevelDifficulty(levelDifficulty);
GameMain.NetLobbyScreen.SetBotCount(botCount);
GameMain.NetLobbyScreen.SetRadiationEnabled(radiationEnabled);
GameMain.NetLobbyScreen.SetBotSpawnMode(botSpawnMode);
GameMain.NetLobbyScreen.SetBotCount(botCount);
GameMain.NetLobbyScreen.SetAutoRestart(autoRestartEnabled, autoRestartTimer);
serverSettings.VoiceChatEnabled = voiceChatEnabled;
@@ -2325,7 +2394,7 @@ namespace Barotrauma.Networking
if (outmsg.LengthBytes > MsgConstants.MTU)
{
DebugConsole.ThrowError("Maximum packet size exceeded (" + outmsg.LengthBytes + " > " + MsgConstants.MTU);
DebugConsole.ThrowError($"Maximum packet size exceeded ({outmsg.LengthBytes} > {MsgConstants.MTU})");
}
clientPeer.Send(outmsg, DeliveryMethod.Unreliable);
@@ -2376,7 +2445,7 @@ namespace Barotrauma.Networking
if (outmsg.LengthBytes > MsgConstants.MTU)
{
DebugConsole.ThrowError("Maximum packet size exceeded (" + outmsg.LengthBytes + " > " + MsgConstants.MTU);
DebugConsole.ThrowError($"Maximum packet size exceeded ({outmsg.LengthBytes} > {MsgConstants.MTU})");
}
clientPeer.Send(outmsg, DeliveryMethod.Unreliable);
@@ -2406,6 +2475,15 @@ namespace Barotrauma.Networking
chatMsgQueue.Add(chatMessage);
}
public void SendRespawnPromptResponse(bool waitForNextRoundRespawn)
{
WaitForNextRoundRespawn = waitForNextRoundRespawn;
IWriteMessage msg = new WriteOnlyMessage();
msg.Write((byte)ClientPacketHeader.READY_TO_SPAWN);
msg.Write((bool)waitForNextRoundRespawn);
clientPeer?.Send(msg, DeliveryMethod.Reliable);
}
public void RequestFile(FileTransferType fileType, string file, string fileHash)
{
IWriteMessage msg = new WriteOnlyMessage();
@@ -2528,7 +2606,7 @@ namespace Barotrauma.Networking
if (!(GameMain.GameSession?.GameMode is MultiPlayerCampaign campaign) || campaign.CampaignID != campaignID)
{
string savePath = transfer.FilePath;
GameMain.GameSession = new GameSession(null, savePath, GameModePreset.MultiPlayerCampaign);
GameMain.GameSession = new GameSession(null, savePath, GameModePreset.MultiPlayerCampaign, CampaignSettings.Unsure);
campaign = (MultiPlayerCampaign)GameMain.GameSession.GameMode;
campaign.CampaignID = campaignID;
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
@@ -2876,7 +2954,7 @@ namespace Barotrauma.Networking
clientPeer.Send(msg, DeliveryMethod.Reliable);
}
public void SetupNewCampaign(SubmarineInfo sub, string saveName, string mapSeed)
public void SetupNewCampaign(SubmarineInfo sub, string saveName, string mapSeed, CampaignSettings settings)
{
GameMain.NetLobbyScreen.CampaignSetupFrame.Visible = false;
GameMain.NetLobbyScreen.CampaignFrame.Visible = false;
@@ -2891,6 +2969,7 @@ namespace Barotrauma.Networking
msg.Write(mapSeed);
msg.Write(sub.Name);
msg.Write(sub.MD5Hash.Hash);
settings.Serialize(msg);
clientPeer.Send(msg, DeliveryMethod.Reliable);
}
@@ -3096,11 +3175,11 @@ namespace Barotrauma.Networking
cameraFollowsSub.Visible = Character.Controlled == null;
}
if (Character.Controlled == null || Character.Controlled.IsDead)
/*if (Character.Controlled == null || Character.Controlled.IsDead)
{
GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;
GameMain.LightManager.LosEnabled = false;
}
}*/
}
//tab doesn't autoselect the chatbox when debug console is open,
@@ -3208,9 +3287,13 @@ namespace Barotrauma.Networking
if (respawnManager != null)
{
string respawnText = "";
float textScale = 1.0f;
string 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);
if (respawnManager.CurrentState == RespawnManager.State.Waiting &&
respawnManager.RespawnCountdownStarted)
{
@@ -3228,18 +3311,18 @@ namespace Barotrauma.Networking
{
//oscillate between 0-1
float phase = (float)(Math.Sin(timeLeft * MathHelper.Pi) + 1.0f) * 0.5f;
textScale = 1.0f + phase * 0.5f;
//textScale = 1.0f + phase * 0.5f;
textColor = Color.Lerp(GUI.Style.Red, Color.White, 1.0f - phase);
}
canChooseRespawn = false;
}
if (!string.IsNullOrEmpty(respawnText))
{
GUI.SmallFont.DrawString(spriteBatch, respawnText, new Vector2(120.0f, 10), textColor, 0.0f, Vector2.Zero, textScale, Microsoft.Xna.Framework.Graphics.SpriteEffects.None, 0.0f);
}
GameMain.GameSession?.SetRespawnInfo(
visible: !string.IsNullOrEmpty(respawnText) || canChooseRespawn, text: respawnText, textColor: textColor,
buttonsVisible: canChooseRespawn, waitForNextRoundRespawn: (WaitForNextRoundRespawn ?? true));
}
if (!ShowNetStats) return;
if (!ShowNetStats) { return; }
NetStats.Draw(spriteBatch, new Rectangle(300, 10, 300, 150));
@@ -3367,9 +3450,12 @@ namespace Barotrauma.Networking
{
var banReasonPrompt = new GUIMessageBox(
TextManager.Get(ban ? "BanReasonPrompt" : "KickReasonPrompt"),
"", new string[] { TextManager.Get("OK"), TextManager.Get("Cancel") }, new Vector2(0.25f, 0.22f), new Point(400, 220));
"", new string[] { TextManager.Get("OK"), TextManager.Get("Cancel") }, new Vector2(0.25f, 0.25f), new Point(400, 260));
var content = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.6f), banReasonPrompt.InnerFrame.RectTransform, Anchor.Center));
var content = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.6f), banReasonPrompt.InnerFrame.RectTransform, Anchor.Center))
{
AbsoluteSpacing = GUI.IntScale(5)
};
var banReasonBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.3f), content.RectTransform))
{
Wrap = true,
@@ -3380,10 +3466,9 @@ namespace Barotrauma.Networking
GUITickBox permaBanTickBox = null;
if (ban)
{
{
var labelContainer = new GUILayoutGroup(new RectTransform(new Vector2(1f, 0.25f), content.RectTransform), isHorizontal: false);
new GUITextBlock(new RectTransform(new Vector2(1f, 0.5f), labelContainer.RectTransform), TextManager.Get("BanDuration")) { Padding = Vector4.Zero };
new GUITextBlock(new RectTransform(new Vector2(1f, 0.0f), labelContainer.RectTransform), TextManager.Get("BanDuration"), font: GUI.SubHeadingFont) { Padding = Vector4.Zero };
var buttonContent = new GUILayoutGroup(new RectTransform(new Vector2(1f, 0.5f), labelContainer.RectTransform), isHorizontal: true);
permaBanTickBox = new GUITickBox(new RectTransform(new Vector2(0.4f, 0.15f), buttonContent.RectTransform), TextManager.Get("BanPermanent"))
{
@@ -3494,12 +3579,19 @@ namespace Barotrauma.Networking
errorLines.Add("Campaign ID: " + campaign.CampaignID);
errorLines.Add("Campaign save ID: " + campaign.LastSaveID + "(pending: " + campaign.PendingSaveID + ")");
}
errorLines.Add("Mission: " + (GameMain.GameSession?.Mission?.Prefab.Identifier ?? "none"));
foreach (Mission mission in GameMain.GameSession.Missions)
{
errorLines.Add("Mission: " + mission.Prefab.Identifier);
}
}
if (GameMain.GameSession?.Submarine != null)
{
errorLines.Add("Submarine: " + GameMain.GameSession.Submarine.Info.Name);
}
if (GameMain.NetworkMember?.RespawnManager?.RespawnShuttle != null)
{
errorLines.Add("Respawn shuttle: " + GameMain.NetworkMember.RespawnManager.RespawnShuttle.Info.Name);
}
if (Level.Loaded != null)
{
errorLines.Add("Level: " + Level.Loaded.Seed + ", " + string.Join(", ", Level.Loaded.EqualityCheckValues.Select(cv => cv.ToString("X"))));