v0.19.0.0 (unstable)

This commit is contained in:
Regalis11
2022-07-20 18:47:07 +03:00
parent 2e2663a175
commit 6b55adcdd9
170 changed files with 2769 additions and 1634 deletions
@@ -1,5 +1,4 @@
using Barotrauma.Networking;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -66,19 +65,16 @@ namespace Barotrauma
if (Job != null)
{
msg.Write(Job.Prefab.Identifier);
msg.Write(Job.Prefab.UintIdentifier);
msg.Write((byte)Job.Variant);
var skills = Job.GetSkills();
msg.Write((byte)skills.Count());
foreach (Skill skill in skills)
foreach (SkillPrefab skillPrefab in Job.Prefab.Skills.OrderBy(s => s.Identifier))
{
msg.Write(skill.Identifier);
msg.Write(skill.Level);
msg.Write(Job.GetSkill(skillPrefab.Identifier).Level);
}
}
else
{
msg.Write("");
msg.Write((uint)0);
msg.Write((byte)0);
}
@@ -359,11 +359,12 @@ namespace Barotrauma
tempBuffer.Write(AnimController.Dir > 0.0f);
}
if (SelectedCharacter != null || SelectedConstruction != null)
if (SelectedCharacter != null || HasSelectedAnyItem)
{
tempBuffer.Write(true);
tempBuffer.Write(SelectedCharacter != null ? SelectedCharacter.ID : NullEntityID);
tempBuffer.Write(SelectedConstruction != null ? SelectedConstruction.ID : NullEntityID);
tempBuffer.Write(SelectedItem != null ? SelectedItem.ID : NullEntityID);
tempBuffer.Write(SelectedSecondaryItem != null ? SelectedSecondaryItem.ID : NullEntityID);
if (SelectedCharacter != null)
{
tempBuffer.Write(AnimController.Anim == AnimController.Animation.CPR);
@@ -424,8 +425,8 @@ namespace Barotrauma
msg.Write(owner == c && owner.Character == this);
msg.Write(owner != null && owner.Character == this && GameMain.Server.ConnectedClients.Contains(owner) ? owner.ID : (byte)0);
break;
case CharacterStatusEventData _:
WriteStatus(msg);
case CharacterStatusEventData statusEventData:
WriteStatus(msg, statusEventData.ForceAfflictionData);
break;
case UpdateSkillsEventData _:
if (Info?.Job == null)
@@ -573,7 +574,7 @@ namespace Barotrauma
msg.WriteRangedInteger((int)CauseOfDeath.Type, 0, Enum.GetValues(typeof(CauseOfDeathType)).Length - 1);
if (CauseOfDeath.Type == CauseOfDeathType.Affliction)
{
msg.Write(CauseOfDeath.Affliction.Identifier);
msg.Write(CauseOfDeath.Affliction.UintIdentifier);
}
msg.Write(forceAfflictionData);
if (forceAfflictionData)
@@ -58,7 +58,7 @@ namespace Barotrauma
Reset();
}
private bool IsBlockedByAnotherConversation(IEnumerable<Entity> targets)
private bool IsBlockedByAnotherConversation(IEnumerable<Entity> targets, float duration)
{
foreach (Entity e in targets)
{
@@ -68,7 +68,7 @@ namespace Barotrauma
{
if (lastActiveAction.ContainsKey(targetClient) &&
lastActiveAction[targetClient].ParentEvent != ParentEvent &&
Timing.TotalTime < lastActiveAction[targetClient].lastActiveTime + BlockOtherConversationsDuration)
Timing.TotalTime < lastActiveAction[targetClient].lastActiveTime + duration)
{
return true;
}
@@ -91,7 +91,7 @@ namespace Barotrauma
{
targetClients.Add(targetClient);
lastActiveAction[targetClient] = this;
ServerWrite(speaker, targetClient);
ServerWrite(speaker, targetClient, interrupt);
}
}
}
@@ -105,14 +105,14 @@ namespace Barotrauma
{
targetClients.Add(c);
lastActiveAction[c] = this;
ServerWrite(speaker, c);
ServerWrite(speaker, c, interrupt);
}
}
}
}
}
private void ServerWrite(Character speaker, Client client)
public void ServerWrite(Character speaker, Client client, bool interrupt)
{
IWriteMessage outmsg = new WriteOnlyMessage();
outmsg.Write((byte)ServerPacketHeader.EVENTACTION);
@@ -27,16 +27,24 @@ namespace Barotrauma
#endif
continue;
}
if (selectedOption == byte.MaxValue)
if (convAction.SelectedOption > -1)
{
convAction.IgnoreClient(sender, 3f);
//someone else already chose an option for this conversation: interrupt for this client
convAction.ServerWrite(convAction.speaker, sender, interrupt: true);
}
else
{
convAction.SelectedOption = selectedOption;
if (selectedOption == byte.MaxValue)
{
convAction.IgnoreClient(sender, 3f);
}
else
{
convAction.SelectedOption = selectedOption;
}
}
return;
return;
}
}
}
@@ -329,7 +329,7 @@ namespace Barotrauma
if (Server == null) { break; }
SteamManager.Update((float)Timing.Step);
TaskPool.Update();
CoroutineManager.Update((float)Timing.Step, (float)Timing.Step);
CoroutineManager.Update(paused: false, (float)Timing.Step);
Timing.Accumulator -= Timing.Step;
updateCount++;
@@ -6,6 +6,8 @@ namespace Barotrauma
{
private readonly Queue<WalletChangedData> transactions = new Queue<WalletChangedData>();
public bool ShouldForceUpdate;
partial void SettingsChanged(Option<int> balanceChanged, Option<int> rewardChanged)
{
transactions.Enqueue(new WalletChangedData
@@ -15,6 +17,15 @@ namespace Barotrauma
});
}
/// <summary>
/// Forces the server to sync the state of the wallet regardless if the balance/reward has changed
/// </summary>
public void ForceUpdate()
{
SettingsChanged(balanceChanged: Option<int>.Some(0), rewardChanged: Option<int>.None());
ShouldForceUpdate = true;
}
public bool HasTransactions() => transactions.Count > 0;
public NetWalletTransaction DequeueAndMergeTransactions(ushort id)
@@ -354,6 +354,7 @@ namespace Barotrauma
LeaveUnconnectedSubs(leavingSub);
NextLevel = newLevel;
GameMain.GameSession.SubmarineInfo = new SubmarineInfo(GameMain.GameSession.Submarine);
GameMain.GameSession.EventManager.RegisterEventHistory();
SaveUtil.SaveGame(GameMain.GameSession.SavePath);
}
else
@@ -530,8 +531,9 @@ namespace Barotrauma
if (wallet.HasTransactions())
{
NetWalletTransaction transaction = wallet.DequeueAndMergeTransactions(id);
if (transaction.ChangedData.BalanceChanged.IsNone() && transaction.ChangedData.RewardDistributionChanged.IsNone()) { continue; }
if (!wallet.ShouldForceUpdate && transaction.ChangedData.BalanceChanged.IsNone() && transaction.ChangedData.RewardDistributionChanged.IsNone()) { continue; }
transactions.Add(transaction);
wallet.ShouldForceUpdate = false;
}
}
@@ -790,11 +792,19 @@ namespace Barotrauma
purchasedItemSwaps.Add(new PurchasedItemSwap(itemToRemove, itemToInstall));
}
int hullRepairCost = GetHullRepairCost();
int itemRepairCost = GetItemRepairCost();
int shuttleRetrieveCost = CampaignMode.ShuttleReplaceCost;
Location location = Map.CurrentLocation;
int hullRepairCost = location?.GetAdjustedMechanicalCost(HullRepairCost) ?? HullRepairCost;
int itemRepairCost = location?.GetAdjustedMechanicalCost(ItemRepairCost) ?? ItemRepairCost;
int shuttleRetrieveCost = location?.GetAdjustedMechanicalCost(ShuttleReplaceCost) ?? ShuttleReplaceCost;
if (location != null)
{
hullRepairCost = location.GetAdjustedMechanicalCost(hullRepairCost);
itemRepairCost = location.GetAdjustedMechanicalCost(itemRepairCost);
shuttleRetrieveCost = location.GetAdjustedMechanicalCost(shuttleRetrieveCost);
}
Wallet personalWallet = GetWallet(sender);
personalWallet?.ForceUpdate();
if (purchasedHullRepairs != PurchasedHullRepairs)
{
@@ -875,6 +885,9 @@ namespace Barotrauma
{
foreach (var item in store.Value.ToList())
{
if (map?.CurrentLocation?.Stores == null || !map.CurrentLocation.Stores.ContainsKey(store.Key)) { continue; }
item.Quantity = Math.Min(map.CurrentLocation.Stores[store.Key].Stock.Find(s => s.ItemPrefab == item.ItemPrefab)?.Quantity ?? 0, item.Quantity);
if (item.Quantity <= 0) { continue; }
CargoManager.ModifyItemQuantityInBuyCrate(store.Key, item.ItemPrefab, item.Quantity, sender);
}
}
@@ -62,6 +62,8 @@ namespace Barotrauma.Networking
public float DeleteDisconnectedTimer;
public DateTime JoinTime;
private CharacterInfo characterInfo;
public CharacterInfo CharacterInfo
{
@@ -114,6 +116,8 @@ namespace Barotrauma.Networking
//initialize to infinity, gets set to a proper value when initializing midround syncing
MidRoundSyncTimeOut = double.PositiveInfinity;
JoinTime = DateTime.Now;
}
partial void DisposeProjSpecific()
@@ -2081,7 +2081,7 @@ namespace Barotrauma.Networking
float waitForResponseTimer = 5.0f;
while (connectedClients.Any(c => !c.ReadyToStart) && waitForResponseTimer > 0.0f)
{
waitForResponseTimer -= CoroutineManager.UnscaledDeltaTime;
waitForResponseTimer -= CoroutineManager.DeltaTime;
yield return CoroutineStatus.Running;
}
@@ -2090,7 +2090,7 @@ namespace Barotrauma.Networking
float waitForTransfersTimer = 20.0f;
while (FileSender.ActiveTransfers.Count > 0 && waitForTransfersTimer > 0.0f)
{
waitForTransfersTimer -= CoroutineManager.UnscaledDeltaTime;
waitForTransfersTimer -= CoroutineManager.DeltaTime;
yield return CoroutineStatus.Running;
}
}
@@ -3278,7 +3278,8 @@ namespace Barotrauma.Networking
Client.UpdateKickVotes(connectedClients);
int minimumKickVotes = Math.Max(1, (int)(connectedClients.Count * serverSettings.KickVoteRequiredRatio));
var kickVoteEligibleClients = connectedClients.Where(c => (DateTime.Now - c.JoinTime).TotalSeconds > ServerSettings.DisallowKickVoteTime);
int minimumKickVotes = Math.Max(2, (int)(kickVoteEligibleClients.Count() * serverSettings.KickVoteRequiredRatio));
var clientsToKick = connectedClients.FindAll(c =>
c.Connection != OwnerConnection &&
!c.HasPermission(ClientPermissions.Kick) &&
@@ -3581,14 +3582,14 @@ namespace Barotrauma.Networking
List<JobVariant> jobPreferences = new List<JobVariant>();
int count = message.ReadByte();
// TODO: modding support?
for (int i = 0; i < Math.Min(count, 3); i++)
{
string jobIdentifier = message.ReadString();
int variant = message.ReadByte();
if (JobPrefab.Prefabs.ContainsKey(jobIdentifier))
if (JobPrefab.Prefabs.TryGet(jobIdentifier, out JobPrefab jobPrefab))
{
jobPreferences.Add(new JobVariant(JobPrefab.Prefabs[jobIdentifier], variant));
if (jobPrefab.HiddenJob) { continue; }
jobPreferences.Add(new JobVariant(jobPrefab, variant));
}
}
@@ -188,9 +188,9 @@ namespace Barotrauma
}
}
if (client.Character?.Info?.Job.Prefab.Identifier == "captain" && client.Character.SelectedConstruction != null)
if (client.Character?.Info?.Job.Prefab.Identifier == "captain" && client.Character.SelectedItem != null)
{
if (client.Character.SelectedConstruction.GetComponent<Steering>() != null)
if (client.Character.SelectedItem.GetComponent<Steering>() != null)
{
AdjustKarma(client.Character, SteerSubKarmaIncrease * deltaTime, "Steering the sub");
}
@@ -125,7 +125,7 @@ namespace Barotrauma.Networking
return characterToRespawnCount >= GetMinCharactersToRespawn();
}
partial void UpdateWaiting(float deltaTime)
partial void UpdateWaiting(float _)
{
if (RespawnShuttle != null)
{
@@ -487,6 +487,20 @@ namespace Barotrauma.Networking
{
AutoItemPlacer.RegenerateLoot(RespawnShuttle, respawnContainer);
}
//try to put the items in containers in the shuttle
foreach (var respawnItem in respawnItems)
{
foreach (Item shuttleItem in RespawnShuttle.GetItems(alsoFromConnectedSubs: false))
{
if (shuttleItem.NonInteractable || shuttleItem.NonPlayerTeamInteractable) { continue; }
var container = shuttleItem.GetComponent<ItemContainer>();
if (container != null && container.Inventory.TryPutItem(respawnItem, user: null))
{
break;
}
}
}
}
var characterData = campaign?.GetClientCharacterData(clients[i]);
@@ -254,15 +254,21 @@ namespace Barotrauma
break;
case VoteType.Kick:
byte kickedClientID = inc.ReadByte();
Client kicked = GameMain.Server.ConnectedClients.Find(c => c.ID == kickedClientID);
if (kicked != null && kicked.Connection != GameMain.Server.OwnerConnection && !kicked.HasKickVoteFrom(sender))
if ((DateTime.Now - sender.JoinTime).TotalSeconds > GameMain.Server.ServerSettings.DisallowKickVoteTime)
{
kicked.AddKickVote(sender);
Client.UpdateKickVotes(GameMain.Server.ConnectedClients);
GameMain.Server.SendChatMessage($"ServerMessage.HasVotedToKick~[initiator]={sender.Name}~[target]={kicked.Name}", ChatMessageType.Server, null);
}
GameMain.Server.SendDirectChatMessage($"ServerMessage.kickvotedisallowed", sender);
}
else
{
Client kicked = GameMain.Server.ConnectedClients.Find(c => c.ID == kickedClientID);
if (kicked != null && kicked.Connection != GameMain.Server.OwnerConnection && !kicked.HasKickVoteFrom(sender))
{
kicked.AddKickVote(sender);
Client.UpdateKickVotes(GameMain.Server.ConnectedClients);
GameMain.Server.SendChatMessage($"ServerMessage.HasVotedToKick~[initiator]={sender.Name}~[target]={kicked.Name}", ChatMessageType.Server, null);
}
}
break;
case VoteType.StartRound:
bool ready = inc.ReadBoolean();
@@ -55,6 +55,10 @@ namespace Barotrauma
#if LINUX
setLinuxEnv();
AppDomain.CurrentDomain.ProcessExit += (s, e) =>
{
GameMain.ShouldRun = false;
};
#endif
Console.WriteLine("Barotrauma Dedicated Server " + GameMain.Version +
" (" + AssemblyInfo.BuildString + ", branch " + AssemblyInfo.GitBranch + ", revision " + AssemblyInfo.GitRevision + ")");
@@ -93,7 +97,7 @@ namespace Barotrauma
private static void CrashHandler(object sender, UnhandledExceptionEventArgs args)
{
void swallowExceptions(Action action)
static void swallowExceptions(Action action)
{
try
{