Merge branch 'master' of https://github.com/Regalis11/Barotrauma.git into Regalis11-master
This commit is contained in:
@@ -10,6 +10,7 @@ using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using Barotrauma.Extensions;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
{
|
||||
@@ -44,11 +45,13 @@ namespace Barotrauma.Networking
|
||||
[Flags]
|
||||
public enum NetFlags : byte
|
||||
{
|
||||
None = 0x0,
|
||||
Name = 0x1,
|
||||
Message = 0x2,
|
||||
Properties = 0x4,
|
||||
Misc = 0x8,
|
||||
LevelSeed = 0x10
|
||||
LevelSeed = 0x10,
|
||||
HiddenSubs = 0x20
|
||||
}
|
||||
|
||||
public static readonly string PermissionPresetFile = "Data" + Path.DirectorySeparatorChar + "permissionpresets.xml";
|
||||
@@ -284,6 +287,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
ExtraCargo = new Dictionary<ItemPrefab, int>();
|
||||
|
||||
HiddenSubs = new HashSet<string>();
|
||||
|
||||
PermissionPreset.LoadAll(PermissionPresetFile);
|
||||
InitProjSpecific();
|
||||
|
||||
@@ -339,8 +344,14 @@ namespace Barotrauma.Networking
|
||||
get { return serverName; }
|
||||
set
|
||||
{
|
||||
serverName = value;
|
||||
if (serverName.Length > NetConfig.ServerNameMaxLength) { ServerName = ServerName.Substring(0, NetConfig.ServerNameMaxLength); }
|
||||
string val = value;
|
||||
if (val.Length > NetConfig.ServerNameMaxLength) { val = val.Substring(0, NetConfig.ServerNameMaxLength); }
|
||||
if (serverName == val) { return; }
|
||||
serverName = val;
|
||||
ServerDetailsChanged = true;
|
||||
#if SERVER
|
||||
UpdateFlag(NetFlags.Name);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,9 +361,14 @@ namespace Barotrauma.Networking
|
||||
get { return serverMessageText; }
|
||||
set
|
||||
{
|
||||
if (serverMessageText == value) { return; }
|
||||
serverMessageText = value;
|
||||
string val = value;
|
||||
if (val.Length > NetConfig.ServerMessageMaxLength) { val = val.Substring(0, NetConfig.ServerMessageMaxLength); }
|
||||
if (serverMessageText == val) { return; }
|
||||
serverMessageText = val;
|
||||
ServerDetailsChanged = true;
|
||||
#if SERVER
|
||||
UpdateFlag(NetFlags.Message);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -370,8 +386,12 @@ namespace Barotrauma.Networking
|
||||
|
||||
public Dictionary<string, bool> MonsterEnabled { get; private set; }
|
||||
|
||||
public const int MaxExtraCargoItemsOfType = 10;
|
||||
public const int MaxExtraCargoItemTypes = 20;
|
||||
public Dictionary<ItemPrefab, int> ExtraCargo { get; private set; }
|
||||
|
||||
public HashSet<string> HiddenSubs { get; private set; }
|
||||
|
||||
private float selectedLevelDifficulty;
|
||||
private string password;
|
||||
|
||||
@@ -509,6 +529,13 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
}
|
||||
|
||||
[Serialize(Barotrauma.LosMode.Opaque, true)]
|
||||
public LosMode LosMode
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Serialize(800, true)]
|
||||
public int LinesPerLogFile
|
||||
{
|
||||
@@ -993,16 +1020,17 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
bool changed = false;
|
||||
UInt32 count = msg.ReadUInt32();
|
||||
if (ExtraCargo == null || count != ExtraCargo.Count) changed = true;
|
||||
if (ExtraCargo == null || count != ExtraCargo.Count) { changed = true; }
|
||||
Dictionary<ItemPrefab, int> extraCargo = new Dictionary<ItemPrefab, int>();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
string prefabIdentifier = msg.ReadString();
|
||||
byte amount = msg.ReadByte();
|
||||
|
||||
var itemPrefab = MapEntityPrefab.Find(null, prefabIdentifier, showErrorMessages: false) as ItemPrefab;
|
||||
if (itemPrefab != null && amount > 0)
|
||||
if (MapEntityPrefab.Find(null, prefabIdentifier, showErrorMessages: false) is ItemPrefab itemPrefab && amount > 0)
|
||||
{
|
||||
if (ExtraCargo.Keys.Count() >= MaxExtraCargoItemTypes) { continue; }
|
||||
if (ExtraCargo.ContainsKey(itemPrefab) && ExtraCargo[itemPrefab] >= MaxExtraCargoItemsOfType) { continue; }
|
||||
if (changed || !ExtraCargo.ContainsKey(itemPrefab) || ExtraCargo[itemPrefab] != amount) { changed = true; }
|
||||
extraCargo.Add(itemPrefab, amount);
|
||||
}
|
||||
@@ -1026,5 +1054,36 @@ namespace Barotrauma.Networking
|
||||
msg.Write((byte)kvp.Value);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReadHiddenSubs(IReadMessage msg)
|
||||
{
|
||||
var subList = GameMain.NetLobbyScreen.GetSubList();
|
||||
|
||||
HiddenSubs.Clear();
|
||||
uint count = msg.ReadVariableUInt32();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
int index = msg.ReadUInt16();
|
||||
if (index < 0 || index >= subList.Count) { continue; }
|
||||
string submarineName = subList[index].Name;
|
||||
HiddenSubs.Add(submarineName);
|
||||
}
|
||||
|
||||
#if SERVER
|
||||
MultiPlayerCampaign.UpdateCampaignSubs();
|
||||
SelectNonHiddenSubmarine();
|
||||
#endif
|
||||
}
|
||||
|
||||
public void WriteHiddenSubs(IWriteMessage msg)
|
||||
{
|
||||
var subList = GameMain.NetLobbyScreen.GetSubList();
|
||||
|
||||
msg.WriteVariableUInt32((uint)HiddenSubs.Count);
|
||||
foreach (string submarineName in HiddenSubs)
|
||||
{
|
||||
msg.Write((UInt16)subList.FindIndex(s => s.Name.Equals(submarineName, StringComparison.OrdinalIgnoreCase)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user