Build 0.18.7.0

This commit is contained in:
Markus Isberg
2022-06-08 21:52:38 +09:00
parent 5a10b444ee
commit 4f5a3bf8b9
56 changed files with 401 additions and 245 deletions
@@ -10,6 +10,11 @@ namespace Barotrauma
{
private readonly Dictionary<Identifier, float> prevSentSkill = new Dictionary<Identifier, float>();
/// <summary>
/// The client opted to create a new character and discard this one
/// </summary>
public bool Discarded;
partial void OnSkillChanged(Identifier skillIdentifier, float prevLevel, float newLevel)
{
if (Character == null || Character.Removed) { return; }
@@ -230,7 +230,7 @@ namespace Barotrauma
if (!matchingCharacterData.HasSpawned) { continue; }
characterInfo ??= matchingCharacterData.CharacterInfo;
}
if (characterInfo == null) { continue; }
if (characterInfo == null || characterInfo.Discarded) { continue; }
//reduce skills if the character has died
if (characterInfo.CauseOfDeath != null && characterInfo.CauseOfDeath.Type != CauseOfDeathType.Disconnected)
{
@@ -420,6 +420,8 @@ namespace Barotrauma
{
discardedCharacters.Add(data);
}
DebugConsole.Log($"Client \"{client}\" discarded the character ({data.Name})");
data.CharacterInfo.Discarded = true;
characterData.Remove(data);
IncrementLastUpdateIdForFlag(NetFlags.CharacterInfo);
}
@@ -1,4 +1,5 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using Barotrauma.Networking;
@@ -18,7 +19,8 @@ namespace Barotrauma
IWriteMessage msg = new WriteOnlyMessage();
msg.Write((byte) ServerPacketHeader.READY_CHECK);
msg.Write((byte) ReadyCheckState.Start);
msg.Write(endTime);
msg.Write(new DateTimeOffset(startTime).ToUnixTimeSeconds());
msg.Write(new DateTimeOffset(endTime).ToUnixTimeSeconds());
msg.Write(author);
if (sender != null)
@@ -53,10 +55,9 @@ namespace Barotrauma
foreach (Client client in ActivePlayers)
{
IWriteMessage msg = new WriteOnlyMessage();
msg.Write((byte) ServerPacketHeader.READY_CHECK);
msg.Write((byte) ReadyCheckState.Update);
msg.Write(time); // sync time
msg.Write((byte) state);
msg.Write((byte)ServerPacketHeader.READY_CHECK);
msg.Write((byte)ReadyCheckState.Update);
msg.Write((byte)state);
msg.Write(otherClient);
GameMain.Server.ServerPeer.Send(msg, client.Connection, DeliveryMethod.Reliable);
}
@@ -1,13 +1,22 @@
using Barotrauma.Networking;
using Microsoft.Xna.Framework;
using System;
using System.Globalization;
using System.Xml.Linq;
namespace Barotrauma.Items.Components
{
partial class Pump : Powered, IServerSerializable, IClientSerializable
{
const float NetworkUpdateInterval = 5.0f;
private float networkUpdateTimer;
partial void UpdateProjSpecific(float deltaTime)
{
networkUpdateTimer -= deltaTime;
if (networkUpdateTimer <= 0.0f)
{
item.CreateServerEvent(this);
networkUpdateTimer = NetworkUpdateInterval;
}
}
public void ServerEventRead(IReadMessage msg, Client c)
{
float newFlowPercentage = msg.ReadRangedInteger(-10, 10) * 10.0f;
@@ -2,10 +2,7 @@
using Barotrauma.Networking;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using Barotrauma.Extensions;
using Barotrauma.MapCreatures.Behavior;
namespace Barotrauma
{
@@ -39,9 +36,9 @@ namespace Barotrauma
return;
}
statusUpdateTimer -= deltaTime;
decalUpdateTimer -= deltaTime;
backgroundSectionUpdateTimer -= deltaTime;
statusUpdateTimer += deltaTime;
decalUpdateTimer += deltaTime;
backgroundSectionUpdateTimer += deltaTime;
//update client hulls if the amount of water has changed by >10%
//or if oxygen percentage has changed by 5%
@@ -49,33 +46,32 @@ namespace Barotrauma
(Math.Abs(lastSentVolume - waterVolume) > Volume * 0.1f
|| Math.Abs(lastSentOxygen - OxygenPercentage) > 5f
|| lastSentFireCount != FireSources.Count)
&& statusUpdateTimer <= 0.0f;
&& (statusUpdateTimer > NetConfig.HullUpdateInterval);
if (shouldSendStatusUpdate)
//force an update every 5 seconds even if nothing's changed (in case a client's gotten out of sync somehow)
if (shouldSendStatusUpdate || statusUpdateTimer > NetConfig.SparseHullUpdateInterval)
{
GameMain.NetworkMember.CreateEntityEvent(this, new StatusEventData());
GameMain.NetworkMember.CreateEntityEvent(this, new StatusEventData());
lastSentVolume = waterVolume;
lastSentOxygen = OxygenPercentage;
lastSentFireCount = FireSources.Count;
statusUpdateTimer = NetConfig.SparseHullUpdateInterval;
statusUpdateTimer = 0;
}
if (decalUpdatePending && decalUpdateTimer <= 0.0f)
if (decalUpdatePending && decalUpdateTimer > NetConfig.HullUpdateInterval)
{
GameMain.NetworkMember.CreateEntityEvent(this, new DecalEventData());
decalUpdateTimer = NetConfig.HullUpdateInterval;
decalUpdateTimer = 0;
decalUpdatePending = false;
}
if (pendingSectionUpdates.Count > 0 && backgroundSectionUpdateTimer <= 0.0f)
if (pendingSectionUpdates.Count > 0 && backgroundSectionUpdateTimer > NetConfig.HullUpdateInterval)
{
foreach (int pendingSectionUpdate in pendingSectionUpdates)
{
GameMain.NetworkMember.CreateEntityEvent(this, new BackgroundSectionsEventData(pendingSectionUpdate));
}
backgroundSectionUpdateTimer = NetConfig.HullUpdateInterval;
backgroundSectionUpdateTimer = 0;
pendingSectionUpdates.Clear();
}
}
@@ -73,6 +73,9 @@ namespace Barotrauma.Networking
characterInfo = value;
}
}
public string PendingName;
public NetworkConnection Connection { get; set; }
public bool SpectateOnly;
@@ -1046,7 +1046,7 @@ namespace Barotrauma.Networking
c.LastRecvChatMsgID = NetIdUtils.Clamp(inc.ReadUInt16(), c.LastRecvChatMsgID, c.LastChatMsgQueueID);
c.LastRecvClientListUpdate = NetIdUtils.Clamp(inc.ReadUInt16(), c.LastRecvClientListUpdate, LastClientListUpdateID);
TryChangeClientName(c, inc);
ReadClientNameChange(c, inc);
c.LastRecvCampaignSave = inc.ReadUInt16();
if (c.LastRecvCampaignSave > 0)
@@ -2675,7 +2675,7 @@ namespace Barotrauma.Networking
base.AddChatMessage(message);
}
private bool TryChangeClientName(Client c, IReadMessage inc)
private bool ReadClientNameChange(Client c, IReadMessage inc)
{
UInt16 nameId = inc.ReadUInt16();
string newName = inc.ReadString();
@@ -2685,16 +2685,21 @@ namespace Barotrauma.Networking
if (c == null || string.IsNullOrEmpty(newName) || !NetIdUtils.IdMoreRecent(nameId, c.NameID)) { return false; }
c.NameID = nameId;
newName = Client.SanitizeName(newName);
if (newName == c.Name && newJob == c.PreferredJob && newTeam == c.PreferredTeam) { return false; }
c.PreferredJob = newJob;
c.PreferredTeam = newTeam;
return TryChangeClientName(c, newName);
}
public bool TryChangeClientName(Client c, string newName)
{
newName = Client.SanitizeName(newName);
//update client list even if the name cannot be changed to the one sent by the client,
//so the client will be informed what their actual name is
LastClientListUpdateID++;
if (newName == c.Name) { return false; }
if (newName == c.Name || string.IsNullOrEmpty(newName)) { return false; }
if (IsNameValid(c, newName))
{
@@ -2710,6 +2715,7 @@ namespace Barotrauma.Networking
}
}
private bool IsNameValid(Client c, string newName)
{
newName = Client.SanitizeName(newName);
@@ -3542,6 +3548,10 @@ namespace Barotrauma.Networking
{
newName = sender.Name;
}
else
{
sender.PendingName = newName;
}
}
int tagCount = message.ReadByte();
@@ -392,6 +392,14 @@ namespace Barotrauma.Networking
bool forceSpawnInMainSub = false;
if (!bot && campaign != null)
{
//the client has opted to change the name of their new character
//when the character spawns, set the client's name to match
if (clients[i].PendingName == characterInfos[i].Name)
{
GameMain.Server?.TryChangeClientName(clients[i], clients[i].PendingName);
clients[i].PendingName = null;
}
var matchingData = campaign?.GetClientCharacterData(clients[i]);
if (matchingData != null)
{