0.15.21.0

This commit is contained in:
Markus Isberg
2021-12-16 01:05:43 +09:00
parent 617d9ede88
commit 7d43cb1e91
74 changed files with 487 additions and 541 deletions
@@ -10,6 +10,9 @@ namespace Barotrauma.Networking
public UInt16 LastRecvClientListUpdate = 0;
public UInt16 LastSentServerSettingsUpdate = 0;
public UInt16 LastRecvServerSettingsUpdate = 0;
public UInt16 LastRecvLobbyUpdate = 0;
public UInt16 LastSentChatMsgID = 0; //last msg this client said
@@ -1036,6 +1036,11 @@ namespace Barotrauma.Networking
case ClientNetObject.SYNC_IDS:
//TODO: might want to use a clever class for this
c.LastRecvLobbyUpdate = NetIdUtils.Clamp(inc.ReadUInt16(), c.LastRecvLobbyUpdate, GameMain.NetLobbyScreen.LastUpdateID);
if (c.HasPermission(ClientPermissions.ManageSettings) &&
NetIdUtils.IdMoreRecentOrMatches(c.LastRecvLobbyUpdate, c.LastSentServerSettingsUpdate))
{
c.LastRecvServerSettingsUpdate = c.LastSentServerSettingsUpdate;
}
c.LastRecvChatMsgID = NetIdUtils.Clamp(inc.ReadUInt16(), c.LastRecvChatMsgID, c.LastChatMsgQueueID);
c.LastRecvClientListUpdate = NetIdUtils.Clamp(inc.ReadUInt16(), c.LastRecvClientListUpdate, LastClientListUpdateID);
@@ -2469,6 +2474,7 @@ namespace Barotrauma.Networking
msg.Write(serverSettings.AllowFriendlyFire);
msg.Write(serverSettings.LockAllDefaultWires);
msg.Write(serverSettings.AllowRagdollButton);
msg.Write(serverSettings.AllowLinkingWifiToChat);
msg.Write(serverSettings.UseRespawnShuttle);
msg.Write((byte)serverSettings.LosMode);
msg.Write(includesFinalize); msg.WritePadBits();
@@ -15,13 +15,17 @@ namespace Barotrauma.Networking
public static readonly char SubmarineSeparatorChar = '|';
public readonly Dictionary<NetFlags, UInt16> LastUpdateIdForFlag = new Dictionary<NetFlags, UInt16>();
public UInt16 LastPropertyUpdateId { get; private set; } = 1;
public void UpdateFlag(NetFlags flag)
=> LastUpdateIdForFlag[flag] = (UInt16)(GameMain.NetLobbyScreen.LastUpdateID + 1);
private bool IsFlagRequired(Client c, NetFlags flag)
=> LastUpdateIdForFlag[flag] > c.LastRecvLobbyUpdate;
public NetFlags GetRequiredFlags(Client c)
=> LastUpdateIdForFlag.Keys
.Where(k => LastUpdateIdForFlag[k] > c.LastRecvLobbyUpdate)
.Where(k => IsFlagRequired(c, k))
.Concat(NetFlags.None.ToEnumerable()) //prevents InvalidOperationException in Aggregate
.Aggregate((f1, f2) => f1 | f2);
@@ -43,14 +47,7 @@ namespace Barotrauma.Networking
public void ServerAdminWrite(IWriteMessage outMsg, Client c)
{
//outMsg.Write(isPublic);
//outMsg.Write(EnableUPnP);
//outMsg.WritePadBits();
//outMsg.Write((UInt16)QueryPort);
NetFlags requiredFlags = GetRequiredFlags(c);
if (!requiredFlags.HasFlag(NetFlags.Properties)) { return; }
c.LastSentServerSettingsUpdate = LastPropertyUpdateId;
WriteNetProperties(outMsg);
WriteMonsterEnabled(outMsg);
BanList.ServerAdminWrite(outMsg, c);
@@ -85,7 +82,8 @@ namespace Barotrauma.Networking
WriteHiddenSubs(outMsg);
if (c.HasPermission(Networking.ClientPermissions.ManageSettings))
if (c.HasPermission(Networking.ClientPermissions.ManageSettings)
&& !NetIdUtils.IdMoreRecentOrMatches(c.LastRecvServerSettingsUpdate, LastPropertyUpdateId))
{
outMsg.Write(true);
outMsg.WritePadBits();
@@ -153,8 +151,12 @@ namespace Barotrauma.Networking
if (changedMonsterSettings) { ReadMonsterEnabled(incMsg); }
propertiesChanged |= BanList.ServerAdminRead(incMsg, c);
propertiesChanged |= Whitelist.ServerAdminRead(incMsg, c);
if (propertiesChanged) { UpdateFlag(NetFlags.Properties); }
if (propertiesChanged)
{
UpdateFlag(NetFlags.Properties);
LastPropertyUpdateId = (UInt16)(GameMain.NetLobbyScreen.LastUpdateID + 1);
}
changed |= propertiesChanged;
}
@@ -30,10 +30,9 @@ namespace Barotrauma
public static SubmarineVote SubVote;
private void StartSubmarineVote(IReadMessage inc, VoteType voteType, Client sender)
private void StartSubmarineVote(SubmarineInfo subInfo, VoteType voteType, Client sender)
{
string subName = inc.ReadString();
SubVote.Sub = SubmarineInfo.SavedSubmarines.FirstOrDefault(s => s.Name == subName);
SubVote.Sub = subInfo;
SubVote.DeliveryFee = voteType == VoteType.SwitchSub ? GameMain.GameSession.Map.DistanceToClosestLocationWithOutpost(GameMain.GameSession.Map.CurrentLocation, out Location endLocation) : 0;
SubVote.VoteType = voteType;
SubVote.State = VoteState.Started;
@@ -130,7 +129,12 @@ namespace Barotrauma
bool startVote = inc.ReadBoolean();
if (startVote)
{
StartSubmarineVote(inc, voteType, sender);
string subName = inc.ReadString();
SubmarineInfo subInfo = SubmarineInfo.SavedSubmarines.FirstOrDefault(s => s.Name == subName);
if (GameMain.GameSession?.Campaign is MultiPlayerCampaign campaign && campaign.CanPurchaseSub(subInfo))
{
StartSubmarineVote(subInfo, voteType, sender);
}
}
else
{