(bcb06cc5c) Unstable v0.9.9.0
This commit is contained in:
@@ -205,12 +205,12 @@ namespace Barotrauma.Networking
|
||||
GameMain.NetLobbyScreen.RandomizeSettings();
|
||||
if (!string.IsNullOrEmpty(serverSettings.SelectedSubmarine))
|
||||
{
|
||||
Submarine sub = Submarine.SavedSubmarines.FirstOrDefault(s => s.Name == serverSettings.SelectedSubmarine);
|
||||
SubmarineInfo sub = SubmarineInfo.SavedSubmarines.FirstOrDefault(s => s.Name == serverSettings.SelectedSubmarine);
|
||||
if (sub != null) { GameMain.NetLobbyScreen.SelectedSub = sub; }
|
||||
}
|
||||
if (!string.IsNullOrEmpty(serverSettings.SelectedShuttle))
|
||||
{
|
||||
Submarine shuttle = Submarine.SavedSubmarines.FirstOrDefault(s => s.Name == serverSettings.SelectedShuttle);
|
||||
SubmarineInfo shuttle = SubmarineInfo.SavedSubmarines.FirstOrDefault(s => s.Name == serverSettings.SelectedShuttle);
|
||||
if (shuttle != null) { GameMain.NetLobbyScreen.SelectedShuttle = shuttle; }
|
||||
}
|
||||
started = true;
|
||||
@@ -382,7 +382,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
bool isCrewDead =
|
||||
connectedClients.All(c => c.Character == null || c.Character.IsDead || c.Character.IsUnconscious);
|
||||
connectedClients.All(c => c.Character == null || c.Character.IsDead || c.Character.IsIncapacitated);
|
||||
|
||||
bool subAtLevelEnd = false;
|
||||
if (Submarine.MainSub != null && Submarine.MainSubs[1] == null)
|
||||
@@ -529,7 +529,7 @@ namespace Barotrauma.Networking
|
||||
c.ChatSpamSpeed = Math.Max(0.0f, c.ChatSpamSpeed - deltaTime);
|
||||
|
||||
//constantly increase AFK timer if the client is controlling a character (gets reset to zero every time an input is received)
|
||||
if (gameStarted && c.Character != null && !c.Character.IsDead && !c.Character.IsUnconscious)
|
||||
if (gameStarted && c.Character != null && !c.Character.IsDead && !c.Character.IsIncapacitated)
|
||||
{
|
||||
if (c.Connection != OwnerConnection) c.KickAFKTimer += deltaTime;
|
||||
}
|
||||
@@ -627,16 +627,21 @@ namespace Barotrauma.Networking
|
||||
//game already started -> send start message immediately
|
||||
if (gameStarted)
|
||||
{
|
||||
SendStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.GameMode.Preset, connectedClient);
|
||||
SendStartMessage(roundStartSeed, GameMain.GameSession.Level.Seed, GameMain.GameSession, connectedClient, true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ClientPacketHeader.REQUEST_STARTGAMEFINALIZE:
|
||||
if (gameStarted && connectedClient != null)
|
||||
{
|
||||
SendRoundStartFinalize(connectedClient);
|
||||
}
|
||||
break;
|
||||
case ClientPacketHeader.UPDATE_LOBBY:
|
||||
ClientReadLobby(inc);
|
||||
break;
|
||||
case ClientPacketHeader.UPDATE_INGAME:
|
||||
if (!gameStarted) return;
|
||||
|
||||
if (!gameStarted) { return; }
|
||||
ClientReadIngame(inc);
|
||||
break;
|
||||
case ClientPacketHeader.CAMPAIGN_SETUP_INFO:
|
||||
@@ -648,7 +653,7 @@ namespace Barotrauma.Networking
|
||||
string subName = inc.ReadString();
|
||||
string subHash = inc.ReadString();
|
||||
|
||||
var matchingSub = Submarine.SavedSubmarines.FirstOrDefault(s => s.Name == subName && s.MD5Hash.Hash == subHash);
|
||||
var matchingSub = SubmarineInfo.SavedSubmarines.FirstOrDefault(s => s.Name == subName && s.MD5Hash.Hash == subHash);
|
||||
|
||||
if (matchingSub == null)
|
||||
{
|
||||
@@ -743,7 +748,7 @@ namespace Barotrauma.Networking
|
||||
if (Level.Loaded != null && levelEqualityCheckVal != Level.Loaded.EqualityCheckVal)
|
||||
{
|
||||
errorStr += " Level equality check failed. The level generated at your end doesn't match the level generated by the server(seed: " + Level.Loaded.Seed +
|
||||
", sub: " + Submarine.MainSub.Name + " (" + Submarine.MainSub.MD5Hash.ShortHash + ")" +
|
||||
", sub: " + Submarine.MainSub.Info.Name + " (" + Submarine.MainSub.Info.MD5Hash.ShortHash + ")" +
|
||||
", mirrored: " + Level.Loaded.Mirrored + ").";
|
||||
}
|
||||
|
||||
@@ -778,8 +783,8 @@ namespace Barotrauma.Networking
|
||||
Directory.CreateDirectory(ServerLog.SavePath);
|
||||
}
|
||||
|
||||
string filePath = "event_error_log_server_" + client.Name + "_" + ToolBox.RemoveInvalidFileNameChars(DateTime.UtcNow.ToShortTimeString() + ".log");
|
||||
filePath = Path.Combine(ServerLog.SavePath, filePath);
|
||||
string filePath = "event_error_log_server_" + client.Name + "_" + DateTime.UtcNow.ToShortTimeString() + ".log";
|
||||
filePath = Path.Combine(ServerLog.SavePath, ToolBox.RemoveInvalidFileNameChars(filePath));
|
||||
if (File.Exists(filePath)) { return; }
|
||||
|
||||
List<string> errorLines = new List<string>
|
||||
@@ -793,7 +798,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
if (GameMain.GameSession?.Submarine != null)
|
||||
{
|
||||
errorLines.Add("Submarine: " + GameMain.GameSession.Submarine.Name);
|
||||
errorLines.Add("Submarine: " + GameMain.GameSession.Submarine.Info.Name);
|
||||
}
|
||||
if (Level.Loaded != null)
|
||||
{
|
||||
@@ -1072,7 +1077,7 @@ namespace Barotrauma.Networking
|
||||
case ClientPermissions.Kick:
|
||||
string kickedName = inc.ReadString().ToLowerInvariant();
|
||||
string kickReason = inc.ReadString();
|
||||
var kickedClient = connectedClients.Find(cl => cl != sender && cl.Name.ToLowerInvariant() == kickedName && cl.Connection != OwnerConnection);
|
||||
var kickedClient = connectedClients.Find(cl => cl != sender && cl.Name.Equals(kickedName, StringComparison.OrdinalIgnoreCase) && cl.Connection != OwnerConnection);
|
||||
if (kickedClient != null)
|
||||
{
|
||||
Log("Client \"" + sender.Name + "\" kicked \"" + kickedClient.Name + "\".", ServerLog.MessageType.ServerMessage);
|
||||
@@ -1089,7 +1094,7 @@ namespace Barotrauma.Networking
|
||||
bool range = inc.ReadBoolean();
|
||||
double durationSeconds = inc.ReadDouble();
|
||||
|
||||
var bannedClient = connectedClients.Find(cl => cl != sender && cl.Name.ToLowerInvariant() == bannedName && cl.Connection != OwnerConnection);
|
||||
var bannedClient = connectedClients.Find(cl => cl != sender && cl.Name.Equals(bannedName, StringComparison.OrdinalIgnoreCase) && cl.Connection != OwnerConnection);
|
||||
if (bannedClient != null)
|
||||
{
|
||||
Log("Client \"" + sender.Name + "\" banned \"" + bannedClient.Name + "\".", ServerLog.MessageType.ServerMessage);
|
||||
@@ -1148,7 +1153,7 @@ namespace Barotrauma.Networking
|
||||
break;
|
||||
case ClientPermissions.SelectMode:
|
||||
UInt16 modeIndex = inc.ReadUInt16();
|
||||
if (GameMain.NetLobbyScreen.GameModes[modeIndex].Identifier.ToLowerInvariant() == "multiplayercampaign")
|
||||
if (GameMain.NetLobbyScreen.GameModes[modeIndex].Identifier.Equals("multiplayercampaign", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
string[] saveFiles = SaveUtil.GetSaveFiles(SaveUtil.SaveType.Multiplayer).ToArray();
|
||||
for (int i = 0; i < saveFiles.Length; i++)
|
||||
@@ -1337,7 +1342,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
//if docked to a sub with a smaller ID, don't send an update
|
||||
// (= update is only sent for the docked sub that has the smallest ID, doesn't matter if it's the main sub or a shuttle)
|
||||
if (sub.IsOutpost || sub.DockedTo.Any(s => s.ID < sub.ID)) continue;
|
||||
if (sub.Info.IsOutpost || sub.DockedTo.Any(s => s.ID < sub.ID)) continue;
|
||||
if (!c.PendingPositionUpdates.Contains(sub)) c.PendingPositionUpdates.Enqueue(sub);
|
||||
}
|
||||
|
||||
@@ -1480,6 +1485,7 @@ namespace Barotrauma.Networking
|
||||
outmsg.Write(client.Character == null || !gameStarted ? (client.PreferredJob ?? "") : "");
|
||||
outmsg.Write(client.Character == null || !gameStarted ? (ushort)0 : client.Character.ID);
|
||||
outmsg.Write(client.Muted);
|
||||
outmsg.Write(client.InGame);
|
||||
outmsg.Write(client.Connection != OwnerConnection); //is kicking the player allowed
|
||||
outmsg.WritePadBits();
|
||||
}
|
||||
@@ -1649,12 +1655,12 @@ namespace Barotrauma.Networking
|
||||
|
||||
Log("Starting a new round...", ServerLog.MessageType.ServerMessage);
|
||||
|
||||
Submarine selectedSub = null;
|
||||
Submarine selectedShuttle = GameMain.NetLobbyScreen.SelectedShuttle;
|
||||
SubmarineInfo selectedSub = null;
|
||||
SubmarineInfo selectedShuttle = GameMain.NetLobbyScreen.SelectedShuttle;
|
||||
|
||||
if (serverSettings.Voting.AllowSubVoting)
|
||||
{
|
||||
selectedSub = serverSettings.Voting.HighestVoted<Submarine>(VoteType.Sub, connectedClients);
|
||||
selectedSub = serverSettings.Voting.HighestVoted<SubmarineInfo>(VoteType.Sub, connectedClients);
|
||||
if (selectedSub == null) selectedSub = GameMain.NetLobbyScreen.SelectedSub;
|
||||
}
|
||||
else
|
||||
@@ -1686,7 +1692,7 @@ namespace Barotrauma.Networking
|
||||
return true;
|
||||
}
|
||||
|
||||
private IEnumerable<object> InitiateStartGame(Submarine selectedSub, Submarine selectedShuttle, bool usingShuttle, GameModePreset selectedMode)
|
||||
private IEnumerable<object> InitiateStartGame(SubmarineInfo selectedSub, SubmarineInfo selectedShuttle, bool usingShuttle, GameModePreset selectedMode)
|
||||
{
|
||||
initiatedStartGame = true;
|
||||
|
||||
@@ -1734,7 +1740,7 @@ namespace Barotrauma.Networking
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
|
||||
private IEnumerable<object> StartGame(Submarine selectedSub, Submarine selectedShuttle, bool usingShuttle, GameModePreset selectedMode)
|
||||
private IEnumerable<object> StartGame(SubmarineInfo selectedSub, SubmarineInfo selectedShuttle, bool usingShuttle, GameModePreset selectedMode)
|
||||
{
|
||||
entityEventManager.Clear();
|
||||
|
||||
@@ -1773,10 +1779,10 @@ namespace Barotrauma.Networking
|
||||
//always allow the server owner to spectate even if it's disallowed in server settings
|
||||
playingClients.RemoveAll(c => c.Connection == OwnerConnection && c.SpectateOnly);
|
||||
|
||||
if (GameMain.GameSession.GameMode.Mission != null &&
|
||||
GameMain.GameSession.GameMode.Mission.AssignTeamIDs(playingClients))
|
||||
if (GameMain.GameSession.GameMode.Mission != null)
|
||||
{
|
||||
teamCount = 2;
|
||||
GameMain.GameSession.GameMode.Mission.AssignTeamIDs(playingClients);
|
||||
teamCount = GameMain.GameSession.GameMode.Mission.TeamCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1796,29 +1802,31 @@ namespace Barotrauma.Networking
|
||||
campaign.Map.SelectRandomLocation(preferUndiscovered: true);
|
||||
}
|
||||
|
||||
SendStartMessage(roundStartSeed, campaign.Map.SelectedConnection.Level.Seed, GameMain.GameSession, connectedClients, false);
|
||||
|
||||
GameMain.GameSession.StartRound(campaign.Map.SelectedConnection.Level,
|
||||
reloadSub: true,
|
||||
loadSecondSub: teamCount > 1,
|
||||
mirrorLevel: campaign.Map.CurrentLocation != campaign.Map.SelectedConnection.Locations[0]);
|
||||
|
||||
campaign.AssignClientCharacterInfos(connectedClients);
|
||||
Log("Game mode: " + selectedMode.Name, ServerLog.MessageType.ServerMessage);
|
||||
Log("Submarine: " + GameMain.GameSession.Submarine.Name, ServerLog.MessageType.ServerMessage);
|
||||
Log("Submarine: " + GameMain.GameSession.SubmarineInfo.Name, ServerLog.MessageType.ServerMessage);
|
||||
Log("Level seed: " + campaign.Map.SelectedConnection.Level.Seed, ServerLog.MessageType.ServerMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameMain.GameSession.StartRound(GameMain.NetLobbyScreen.LevelSeed, serverSettings.SelectedLevelDifficulty, teamCount > 1);
|
||||
SendStartMessage(roundStartSeed, GameMain.NetLobbyScreen.LevelSeed, GameMain.GameSession, connectedClients, false);
|
||||
|
||||
GameMain.GameSession.StartRound(GameMain.NetLobbyScreen.LevelSeed, serverSettings.SelectedLevelDifficulty);
|
||||
Log("Game mode: " + selectedMode.Name, ServerLog.MessageType.ServerMessage);
|
||||
Log("Submarine: " + selectedSub.Name, ServerLog.MessageType.ServerMessage);
|
||||
Log("Level seed: " + GameMain.NetLobbyScreen.LevelSeed, ServerLog.MessageType.ServerMessage);
|
||||
}
|
||||
|
||||
if (GameMain.GameSession.Submarine.IsFileCorrupted)
|
||||
if (GameMain.GameSession.SubmarineInfo.IsFileCorrupted)
|
||||
{
|
||||
CoroutineManager.StopCoroutines(startGameCoroutine);
|
||||
initiatedStartGame = false;
|
||||
SendChatMessage(TextManager.FormatServerMessage($"SubLoadError~[subname]={GameMain.GameSession.Submarine.Name}"), ChatMessageType.Error);
|
||||
SendChatMessage(TextManager.FormatServerMessage($"SubLoadError~[subname]={GameMain.GameSession.SubmarineInfo.Name}"), ChatMessageType.Error);
|
||||
yield return CoroutineStatus.Failure;
|
||||
}
|
||||
|
||||
@@ -1827,6 +1835,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (serverSettings.AllowRespawn && missionAllowRespawn) { respawnManager = new RespawnManager(this, usingShuttle ? selectedShuttle : null); }
|
||||
|
||||
Level.Loaded?.SpawnCorpses();
|
||||
AutoItemPlacer.PlaceIfNeeded(GameMain.GameSession.GameMode);
|
||||
|
||||
entityEventManager.RefreshEntityIDs();
|
||||
@@ -1946,8 +1955,6 @@ namespace Barotrauma.Networking
|
||||
|
||||
GameAnalyticsManager.AddDesignEvent("Traitors:" + (TraitorManager == null ? "Disabled" : "Enabled"));
|
||||
|
||||
SendStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.GameMode.Preset, connectedClients);
|
||||
|
||||
yield return CoroutineStatus.Running;
|
||||
|
||||
GameMain.GameScreen.Select();
|
||||
@@ -1965,35 +1972,34 @@ namespace Barotrauma.Networking
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
|
||||
private void SendStartMessage(int seed, Submarine selectedSub, GameModePreset selectedMode, List<Client> clients)
|
||||
private void SendStartMessage(int seed, string levelSeed, GameSession gameSession, List<Client> clients, bool includesFinalize)
|
||||
{
|
||||
foreach (Client client in clients)
|
||||
{
|
||||
SendStartMessage(seed, selectedSub, selectedMode, client);
|
||||
SendStartMessage(seed, levelSeed, gameSession, client, includesFinalize);
|
||||
}
|
||||
}
|
||||
|
||||
private void SendStartMessage(int seed, Submarine selectedSub, GameModePreset selectedMode, Client client)
|
||||
private void SendStartMessage(int seed, string levelSeed, GameSession gameSession, Client client, bool includesFinalize)
|
||||
{
|
||||
IWriteMessage msg = new WriteOnlyMessage();
|
||||
msg.Write((byte)ServerPacketHeader.STARTGAME);
|
||||
|
||||
msg.Write(seed);
|
||||
msg.Write(GameMain.GameSession.Level.Seed);
|
||||
msg.Write(GameMain.GameSession.Level.EqualityCheckVal);
|
||||
msg.Write(levelSeed);
|
||||
msg.Write(serverSettings.SelectedLevelDifficulty);
|
||||
|
||||
msg.Write((byte)GameMain.Config.LosMode);
|
||||
|
||||
msg.Write((byte)GameMain.NetLobbyScreen.MissionType);
|
||||
|
||||
msg.Write(selectedSub.Name);
|
||||
msg.Write(selectedSub.MD5Hash.Hash);
|
||||
msg.Write(gameSession.SubmarineInfo.Name);
|
||||
msg.Write(gameSession.SubmarineInfo.MD5Hash.Hash);
|
||||
msg.Write(serverSettings.UseRespawnShuttle);
|
||||
msg.Write(GameMain.NetLobbyScreen.SelectedShuttle.Name);
|
||||
msg.Write(GameMain.NetLobbyScreen.SelectedShuttle.MD5Hash.Hash);
|
||||
|
||||
msg.Write(selectedMode.Identifier);
|
||||
msg.Write(gameSession.GameMode.Preset.Identifier);
|
||||
msg.Write((short)(GameMain.GameSession.GameMode?.Mission == null ?
|
||||
-1 : MissionPrefab.List.IndexOf(GameMain.GameSession.GameMode.Mission.Prefab)));
|
||||
|
||||
@@ -2002,13 +2008,33 @@ namespace Barotrauma.Networking
|
||||
MissionMode missionMode = GameMain.GameSession.GameMode as MissionMode;
|
||||
bool missionAllowRespawn = campaign == null && (missionMode?.Mission == null || missionMode.Mission.AllowRespawn);
|
||||
msg.Write(serverSettings.AllowRespawn && missionAllowRespawn);
|
||||
msg.Write(Submarine.MainSubs[1] != null); //loadSecondSub
|
||||
|
||||
msg.Write(serverSettings.AllowDisguises);
|
||||
msg.Write(serverSettings.AllowRewiring);
|
||||
|
||||
msg.Write(serverSettings.AllowRagdollButton);
|
||||
|
||||
serverSettings.WriteMonsterEnabled(msg);
|
||||
|
||||
msg.Write(includesFinalize); msg.WritePadBits();
|
||||
if (includesFinalize)
|
||||
{
|
||||
WriteRoundStartFinalize(msg, client);
|
||||
}
|
||||
|
||||
serverPeer.Send(msg, client.Connection, DeliveryMethod.Reliable);
|
||||
}
|
||||
|
||||
private void SendRoundStartFinalize(Client client)
|
||||
{
|
||||
IWriteMessage msg = new WriteOnlyMessage();
|
||||
msg.Write((byte)ServerPacketHeader.STARTGAMEFINALIZE);
|
||||
WriteRoundStartFinalize(msg, client);
|
||||
serverPeer.Send(msg, client.Connection, DeliveryMethod.Reliable);
|
||||
}
|
||||
|
||||
private void WriteRoundStartFinalize(IWriteMessage msg, Client client)
|
||||
{
|
||||
//tell the client what content files they should preload
|
||||
var contentToPreload = GameMain.GameSession.EventManager.GetFilesToPreload();
|
||||
msg.Write((ushort)contentToPreload.Count());
|
||||
@@ -2017,12 +2043,8 @@ namespace Barotrauma.Networking
|
||||
msg.Write((byte)contentFile.Type);
|
||||
msg.Write(contentFile.Path);
|
||||
}
|
||||
|
||||
serverSettings.WriteMonsterEnabled(msg);
|
||||
|
||||
msg.Write(GameMain.GameSession.Level.EqualityCheckVal);
|
||||
GameMain.GameSession.Mission?.ServerWriteInitial(msg, client);
|
||||
|
||||
serverPeer.Send(msg, client.Connection, DeliveryMethod.Reliable);
|
||||
}
|
||||
|
||||
public void EndGame()
|
||||
@@ -2170,11 +2192,9 @@ namespace Barotrauma.Networking
|
||||
|
||||
public override void KickPlayer(string playerName, string reason)
|
||||
{
|
||||
playerName = playerName.ToLowerInvariant();
|
||||
|
||||
Client client = connectedClients.Find(c =>
|
||||
c.Name.ToLowerInvariant() == playerName ||
|
||||
(c.Character != null && c.Character.Name.ToLowerInvariant() == playerName));
|
||||
c.Name.Equals(playerName, StringComparison.OrdinalIgnoreCase) ||
|
||||
(c.Character != null && c.Character.Name.Equals(playerName, StringComparison.OrdinalIgnoreCase)));
|
||||
|
||||
KickClient(client, reason);
|
||||
}
|
||||
@@ -2208,11 +2228,9 @@ namespace Barotrauma.Networking
|
||||
|
||||
public override void BanPlayer(string playerName, string reason, bool range = false, TimeSpan? duration = null)
|
||||
{
|
||||
playerName = playerName.ToLowerInvariant();
|
||||
|
||||
Client client = connectedClients.Find(c =>
|
||||
c.Name.ToLowerInvariant() == playerName ||
|
||||
(c.Character != null && c.Character.Name.ToLowerInvariant() == playerName));
|
||||
c.Name.Equals(playerName, StringComparison.OrdinalIgnoreCase) ||
|
||||
(c.Character != null && c.Character.Name.Equals(playerName, StringComparison.OrdinalIgnoreCase)));
|
||||
|
||||
if (client == null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user