This commit is contained in:
Evil Factory
2022-04-28 12:36:24 -03:00
91 changed files with 1140 additions and 491 deletions
@@ -160,10 +160,14 @@ namespace Barotrauma.Networking
return Connection.EndpointMatches(endPoint);
}
public void SetPermissions(ClientPermissions permissions, List<DebugConsole.Command> permittedConsoleCommands)
public void SetPermissions(ClientPermissions permissions, IEnumerable<DebugConsole.Command> permittedConsoleCommands)
{
this.Permissions = permissions;
this.PermittedConsoleCommands = new List<DebugConsole.Command>(permittedConsoleCommands);
this.PermittedConsoleCommands.Clear();
foreach (var command in permittedConsoleCommands)
{
this.PermittedConsoleCommands.Add(command);
}
}
public void GivePermission(ClientPermissions permission)
@@ -15,11 +15,14 @@ namespace Barotrauma
if (GameMain.Server == null || spawnOrRemove?.Entity == null) { return; }
GameMain.Server.CreateEntityEvent(this, spawnOrRemove);
if (spawnOrRemove.Entity is Character { Info: { } } character)
if (spawnOrRemove is SpawnEntity)
{
foreach (var statKey in character.Info.SavedStatValues.Keys)
if (spawnOrRemove.Entity is Character { Info: { } } character && !character.Removed)
{
GameMain.NetworkMember.CreateEntityEvent(character, new Character.UpdatePermanentStatsEventData(statKey));
foreach (var statKey in character.Info.SavedStatValues.Keys)
{
GameMain.NetworkMember.CreateEntityEvent(character, new Character.UpdatePermanentStatsEventData(statKey));
}
}
}
}
@@ -286,7 +286,10 @@ namespace Barotrauma.Networking
if (newClient.Connection == OwnerConnection && OwnerConnection != null)
{
newClient.GivePermission(ClientPermissions.All);
newClient.PermittedConsoleCommands.AddRange(DebugConsole.Commands);
foreach (var command in DebugConsole.Commands)
{
newClient.PermittedConsoleCommands.Add(command);
}
SendConsoleMessage("Granted all permissions to " + newClient.Name + ".", newClient);
}
@@ -1239,16 +1242,6 @@ namespace Barotrauma.Networking
}
}
#warning TODO: remove this later
/*private IEnumerable<object> RoundRestartLoop()
{
yield return new WaitForSeconds(8.0f);
EndGame();
yield return new WaitForSeconds(8.0f);
StartGame();
yield return CoroutineStatus.Success;
}*/
private void ReadCrewMessage(IReadMessage inc, Client sender)
{
if (GameMain.GameSession?.Campaign is MultiPlayerCampaign mpCampaign)
@@ -1407,10 +1400,16 @@ namespace Barotrauma.Networking
bool continueCampaign = inc.ReadBoolean();
if (mpCampaign != null && mpCampaign.GameOver || continueCampaign)
{
if (mpCampaign.AllowedToManageCampaign(sender, ClientPermissions.ManageCampaign) || mpCampaign.AllowedToManageCampaign(sender, ClientPermissions.ManageMap))
if (gameStarted)
{
SendDirectChatMessage("Cannot continue the campaign from the previous save (round already running).", sender, ChatMessageType.Error);
break;
}
else if (mpCampaign.AllowedToManageCampaign(sender, ClientPermissions.ManageCampaign) || mpCampaign.AllowedToManageCampaign(sender, ClientPermissions.ManageMap))
{
MultiPlayerCampaign.LoadCampaign(GameMain.GameSession.SavePath);
}
}
else if (!gameStarted && !initiatedStartGame)
{
@@ -364,6 +364,13 @@ namespace Barotrauma.Networking
break;
}
#if DEBUG
netPeerConfiguration.SimulatedDuplicatesChance = GameMain.Server.SimulatedDuplicatesChance;
netPeerConfiguration.SimulatedMinimumLatency = GameMain.Server.SimulatedMinimumLatency;
netPeerConfiguration.SimulatedRandomLatency = GameMain.Server.SimulatedRandomLatency;
netPeerConfiguration.SimulatedLoss = GameMain.Server.SimulatedLoss;
#endif
NetOutgoingMessage lidgrenMsg = netServer.CreateMessage();
byte[] msgData = new byte[msg.LengthBytes];
msg.PrepareForSending(ref msgData, compressPastThreshold, out bool isCompressed, out int length);
@@ -541,7 +541,7 @@ namespace Barotrauma.Networking
public static void ReduceCharacterSkills(CharacterInfo characterInfo)
{
if (characterInfo?.Job == null) { return; }
foreach (Skill skill in characterInfo.Job.Skills)
foreach (Skill skill in characterInfo.Job.GetSkills())
{
var skillPrefab = characterInfo.Job.Prefab.Skills.Find(s => skill.Identifier == s.Identifier);
if (skillPrefab == null) { continue; }
@@ -466,7 +466,7 @@ namespace Barotrauma.Networking
}
ClientPermissions permissions = Networking.ClientPermissions.None;
List<DebugConsole.Command> permittedCommands = new List<DebugConsole.Command>();
HashSet<DebugConsole.Command> permittedCommands = new HashSet<DebugConsole.Command>();
if (clientElement.Attribute("preset") == null)
{
@@ -513,7 +513,7 @@ namespace Barotrauma.Networking
else
{
permissions = preset.Permissions;
permittedCommands = preset.PermittedCommands.ToList();
permittedCommands = preset.PermittedCommands.ToHashSet();
}
}
@@ -577,15 +577,15 @@ namespace Barotrauma.Networking
foreach (string line in lines)
{
string[] separatedLine = line.Split('|');
if (separatedLine.Length < 3) continue;
if (separatedLine.Length < 3) { continue; }
string name = string.Join("|", separatedLine.Take(separatedLine.Length - 2));
string ip = separatedLine[separatedLine.Length - 2];
ClientPermissions permissions = Networking.ClientPermissions.None;
ClientPermissions permissions;
if (Enum.TryParse(separatedLine.Last(), out permissions))
{
ClientPermissions.Add(new SavedClientPermission(name, ip, permissions, new List<DebugConsole.Command>()));
ClientPermissions.Add(new SavedClientPermission(name, ip, permissions, new HashSet<DebugConsole.Command>()));
}
}
}