Skip to content

Commit

Permalink
Added beacon name sync (SubnauticaNitrox#959)
Browse files Browse the repository at this point in the history
* Added beacon name sync

* Cleaned up LiteNetLibServer register call in ServerAutoFacRegistrar.cs

* Fixed locking on SerializableParsedBatches

* Fixed Y opening chat while another input has focus (again)

* Fixed issue where player stats would throw errors if gamemode set to creative

* Cleaned up some code

* Added beacon metadata persist to server

* Regenerated equality members for player.cs

* Explained how ShowChat functionality works or does not work

* Changed IfAlive to AliveOrNull extension method
  • Loading branch information
Measurity authored Apr 5, 2020
1 parent f538fe4 commit 54f167b
Show file tree
Hide file tree
Showing 33 changed files with 489 additions and 247 deletions.
16 changes: 14 additions & 2 deletions Nitrox.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,25 @@
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=Nitrox/@EntryIndexedValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Profile name="Nitrox"&gt;&lt;CSReorderTypeMembers&gt;True&lt;/CSReorderTypeMembers&gt;&lt;AspOptimizeRegisterDirectives&gt;True&lt;/AspOptimizeRegisterDirectives&gt;&lt;HtmlReformatCode&gt;True&lt;/HtmlReformatCode&gt;&lt;JsInsertSemicolon&gt;True&lt;/JsInsertSemicolon&gt;&lt;FormatAttributeQuoteDescriptor&gt;True&lt;/FormatAttributeQuoteDescriptor&gt;&lt;CorrectVariableKindsDescriptor&gt;True&lt;/CorrectVariableKindsDescriptor&gt;&lt;VariablesToInnerScopesDescriptor&gt;True&lt;/VariablesToInnerScopesDescriptor&gt;&lt;StringToTemplatesDescriptor&gt;True&lt;/StringToTemplatesDescriptor&gt;&lt;JsReformatCode&gt;True&lt;/JsReformatCode&gt;&lt;JsFormatDocComments&gt;True&lt;/JsFormatDocComments&gt;&lt;RemoveRedundantQualifiersTs&gt;True&lt;/RemoveRedundantQualifiersTs&gt;&lt;OptimizeImportsTs&gt;True&lt;/OptimizeImportsTs&gt;&lt;OptimizeReferenceCommentsTs&gt;True&lt;/OptimizeReferenceCommentsTs&gt;&lt;PublicModifierStyleTs&gt;True&lt;/PublicModifierStyleTs&gt;&lt;ExplicitAnyTs&gt;True&lt;/ExplicitAnyTs&gt;&lt;TypeAnnotationStyleTs&gt;True&lt;/TypeAnnotationStyleTs&gt;&lt;RelativePathStyleTs&gt;True&lt;/RelativePathStyleTs&gt;&lt;AsInsteadOfCastTs&gt;True&lt;/AsInsteadOfCastTs&gt;&lt;XMLReformatCode&gt;True&lt;/XMLReformatCode&gt;&lt;CSCodeStyleAttributes ArrangeTypeAccessModifier="True" ArrangeTypeMemberAccessModifier="True" SortModifiers="True" RemoveRedundantParentheses="True" AddMissingParentheses="True" ArrangeBraces="False" ArrangeAttributes="True" ArrangeArgumentsStyle="True" ArrangeCodeBodyStyle="False" ArrangeVarStyle="False" /&gt;&lt;RemoveCodeRedundanciesVB&gt;True&lt;/RemoveCodeRedundanciesVB&gt;&lt;CssAlphabetizeProperties&gt;True&lt;/CssAlphabetizeProperties&gt;&lt;VBOptimizeImports&gt;True&lt;/VBOptimizeImports&gt;&lt;VBShortenReferences&gt;True&lt;/VBShortenReferences&gt;&lt;RemoveCodeRedundancies&gt;True&lt;/RemoveCodeRedundancies&gt;&lt;CSUseAutoProperty&gt;True&lt;/CSUseAutoProperty&gt;&lt;CSMakeFieldReadonly&gt;True&lt;/CSMakeFieldReadonly&gt;&lt;CSMakeAutoPropertyGetOnly&gt;True&lt;/CSMakeAutoPropertyGetOnly&gt;&lt;CSArrangeQualifiers&gt;True&lt;/CSArrangeQualifiers&gt;&lt;CSFixBuiltinTypeReferences&gt;True&lt;/CSFixBuiltinTypeReferences&gt;&lt;CssReformatCode&gt;True&lt;/CssReformatCode&gt;&lt;VBReformatCode&gt;True&lt;/VBReformatCode&gt;&lt;VBFormatDocComments&gt;True&lt;/VBFormatDocComments&gt;&lt;CSOptimizeUsings&gt;&lt;OptimizeUsings&gt;True&lt;/OptimizeUsings&gt;&lt;EmbraceInRegion&gt;False&lt;/EmbraceInRegion&gt;&lt;RegionName&gt;&lt;/RegionName&gt;&lt;/CSOptimizeUsings&gt;&lt;CSShortenReferences&gt;True&lt;/CSShortenReferences&gt;&lt;CSReformatCode&gt;True&lt;/CSReformatCode&gt;&lt;CSharpFormatDocComments&gt;True&lt;/CSharpFormatDocComments&gt;&lt;/Profile&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/RecentlyUsedProfile/@EntryValue">Built-in: Full Cleanup</s:String>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/SilentCleanupProfile/@EntryValue">Nitrox</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_LINQ_QUERY/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_ARGUMENT/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_CALLS_CHAIN/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_EXTENDS_LIST/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_FOR_STMT/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_PARAMETER/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTIPLE_DECLARATION/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTLINE_TYPE_PARAMETER_CONSTRAINS/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTLINE_TYPE_PARAMETER_LIST/@EntryValue">True</s:Boolean>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_BLANK_LINES_IN_CODE/@EntryValue">1</s:Int64>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue">1</s:Int64>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/MAX_INITIALIZER_ELEMENTS_ON_LINE/@EntryValue">2</s:Int64>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_ACCESSORHOLDER_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_INITIALIZER_ON_SINGLE_LINE/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_INITIALIZER_ON_SINGLE_LINE/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/STICK_COMMENT/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_ARRAY_INITIALIZER_STYLE/@EntryValue">CHOP_IF_LONG</s:String>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LIMIT/@EntryValue">256</s:Int64>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_OBJECT_AND_COLLECTION_INITIALIZER_STYLE/@EntryValue">CHOP_ALWAYS</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_OBJECT_AND_COLLECTION_INITIALIZER_STYLE/@EntryValue">CHOP_IF_LONG</s:String>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/XmlFormatter/WRAP_LIMIT/@EntryValue">200</s:Int64>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForBuiltInTypes/@EntryValue">UseExplicitType</s:String>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForOtherTypes/@EntryValue">UseExplicitType</s:String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ public CyclopsDamagePointHealthChangedProcessor(IPacketSender packetSender)
public override void Process(CyclopsDamagePointRepaired packet)
{
GameObject gameObject = NitroxEntity.RequireObjectFrom(packet.Id);
SubRoot cyclops = GameObjectHelper.RequireComponent<SubRoot>(gameObject);
SubRoot cyclops = gameObject.RequireComponent<SubRoot>();

using (packetSender.Suppress<CyclopsDamage>())
using (packetSender.Suppress<CyclopsDamagePointRepaired>())
{
using (packetSender.Suppress<CyclopsDamagePointRepaired>())
{
cyclops.damageManager.damagePoints[packet.DamagePointIndex].liveMixin.AddHealth(packet.RepairAmount);
}
cyclops.damageManager.damagePoints[packet.DamagePointIndex].liveMixin.AddHealth(packet.RepairAmount);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
using NitroxModel.Logger;
using NitroxClient.MonoBehaviours;
using System.Collections;
using NitroxClient.Communication.Abstract;

namespace NitroxClient.Communication.Packets.Processors
{
public class InitialPlayerSyncProcessor : ClientPacketProcessor<InitialPlayerSync>
{
private HashSet<InitialSyncProcessor> processors;
private HashSet<Type> alreadyRan = new HashSet<Type>();
private readonly IPacketSender packetSender;
private readonly HashSet<InitialSyncProcessor> processors;
private readonly HashSet<Type> alreadyRan = new HashSet<Type>();
private InitialPlayerSync packet;

private WaitScreen.ManualWaitItem loadingMultiplayerWaitItem;
Expand All @@ -21,8 +23,9 @@ public class InitialPlayerSyncProcessor : ClientPacketProcessor<InitialPlayerSyn
private int cumulativeProcessorsRan;
private int processorsRanLastCycle;

public InitialPlayerSyncProcessor(IEnumerable<InitialSyncProcessor> processors)
public InitialPlayerSyncProcessor(IPacketSender packetSender, IEnumerable<InitialSyncProcessor> processors)
{
this.packetSender = packetSender;
this.processors = processors.ToSet();
}

Expand All @@ -36,19 +39,21 @@ public override void Process(InitialPlayerSync packet)

private IEnumerator ProcessInitialSyncPacket(object sender, EventArgs eventArgs)
{
bool moreProcessorsToRun;

do
// Some packets should not fire during game session join but only afterwards so that initialized/spawned game objects don't trigger packet sending again.
using (packetSender.Suppress<PingRenamed>())
{
yield return Multiplayer.Main.StartCoroutine(RunPendingProcessors());

moreProcessorsToRun = (alreadyRan.Count < processors.Count);

if (moreProcessorsToRun && processorsRanLastCycle == 0)
bool moreProcessorsToRun;
do
{
throw new Exception("Detected circular dependencies in initial packet sync between: " + GetRemainingProcessorsText());
}
} while (moreProcessorsToRun);
yield return Multiplayer.Main.StartCoroutine(RunPendingProcessors());

moreProcessorsToRun = alreadyRan.Count < processors.Count;
if (moreProcessorsToRun && processorsRanLastCycle == 0)
{
throw new Exception("Detected circular dependencies in initial packet sync between: " + GetRemainingProcessorsText());
}
} while (moreProcessorsToRun);
}

WaitScreen.Remove(loadingMultiplayerWaitItem);
Multiplayer.Main.InitialSyncCompleted = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using NitroxClient.Communication.Abstract;
using NitroxClient.Communication.Packets.Processors.Abstract;
using NitroxClient.MonoBehaviours;
using NitroxModel.DataStructures.Util;
using NitroxModel.Logger;
using NitroxModel.Packets;
using UnityEngine;

namespace NitroxClient.Communication.Packets.Processors
{
/// <summary>
/// Only syncs pings from beacons for now.
/// </summary>
public class PingRenamedProcessor : ClientPacketProcessor<PingRenamed>
{
private readonly IPacketSender sender;

public PingRenamedProcessor(IPacketSender sender)
{
this.sender = sender;
}

public override void Process(PingRenamed packet)
{
Optional<GameObject> obj = NitroxEntity.GetObjectFrom(packet.Id);
if (!obj.HasValue)
{
// Not the object we're looking for.
return;
}
Beacon beacon = obj.Value.GetComponent<Beacon>();
if (!beacon)
{
// This can be ok if origin of ping instance component was not from a beacon (but from signal or other).
return;
}
if (beacon.GetComponent<Player>())
{
// Skip over beacon component on player GameObjects
return;
}

using (sender.Suppress<PingRenamed>())
{
beacon.beaconLabel.SetLabel(packet.Name);
Log.Debug($"Received ping rename: '{packet.Name}' on object '{obj.Value.GetFullName()}' with Nitrox id: '{packet.Id}'");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public override void Process(VehicleColorChange colorPacket)

using (packetSender.Suppress<VehicleColorChange>())
{
// Switch to the currently selected tab:
subNameInput.SetSelected(colorPacket.Index);
// Switch to the currently selected tab:
subNameInput.SetSelected(colorPacket.Index);

// OnColorChange calls these two methods, in order to update the vehicle color and the color+text on the ingame panel, respectively:
subNameTarget.SetColor(colorPacket.Index, colorPacket.HSB, colorPacket.Color);
subNameInput.ReflectionCall("SetColor", args: new object[] { colorPacket.Index, colorPacket.Color });
// OnColorChange calls these two methods, in order to update the vehicle color and the color+text on the ingame panel, respectively:
subNameTarget.SetColor(colorPacket.Index, colorPacket.HSB, colorPacket.Color);
subNameInput.ReflectionCall("SetColor", args: new object[] { colorPacket.Index, colorPacket.Color });
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public override void Process(VehicleNameChange namePacket)

using (packetSender.Suppress<VehicleNameChange>())
{
subNameInput.OnNameChange(namePacket.Name);
subNameInput.OnNameChange(namePacket.Name);
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion NitroxClient/GameLogic/ChatUI/PlayerChat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ public void HideLog()

public void ShowChat()
{
ShowLog();
// Skip enabling chat log too if chat input field cannot have focus right now.
if (!InputField.CanEnable())
{
return;
}
InputField.ChatEnabled = true;
ShowLog();
}
}
}
8 changes: 3 additions & 5 deletions NitroxClient/GameLogic/Entities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Entities
private readonly SerializedEntitySpawner serializedEntitySpawner = new SerializedEntitySpawner();
private readonly Dictionary<TechType, IEntitySpawner> customSpawnersByTechType = new Dictionary<TechType, IEntitySpawner>();
private readonly Dictionary<Int3, BatchCells> batchCellsById = new Dictionary<Int3, BatchCells>();
private readonly CellRootSpawner cellRootSpawner = new CellRootSpawner();

public Entities(IPacketSender packetSender)
{
Expand Down Expand Up @@ -125,14 +126,11 @@ private IEntitySpawner ResolveEntitySpawner(Entity entity)
{
return serializedEntitySpawner;
}

TechType techType = entity.TechType.Enum();

if (entity.ClassId == "55d7ab35-de97-4d95-af6c-ac8d03bb54ca")
{
return new CellRootSpawner();
return cellRootSpawner;
}

TechType techType = entity.TechType.Enum();
if (customSpawnersByTechType.ContainsKey(techType))
{
return customSpawnersByTechType[techType];
Expand Down
23 changes: 10 additions & 13 deletions NitroxClient/GameLogic/Helper/EquipmentHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using NitroxClient.Unity.Helper;
using NitroxModel.DataStructures.Util;
using NitroxModel.Helper;
using UnityEngine;
Expand All @@ -10,19 +11,15 @@ public class EquipmentHelper
{
private static readonly List<Func<GameObject, Equipment>> equipmentFinders = new List<Func<GameObject, Equipment>>
{
o => (Equipment)o.GetComponent<Charger>()?.ReflectionGet("equipment"),
o => (Equipment)o.GetComponent<BaseNuclearReactor>()?.ReflectionGet("_equipment"),
o => o.GetComponent<CyclopsDecoyLoadingTube>()?.decoySlots,
o => o.GetComponent<Exosuit>()?.modules,
o => o.GetComponent<SeaMoth>()?.modules,
o => o.GetComponent<UpgradeConsole>()?.modules,
o => o.GetComponent<Vehicle>()?.modules,
o => o.GetComponent<VehicleUpgradeConsoleInput>()?.equipment,
o =>
{
Player playerComponent = o.GetComponent<Player>();
return "Player".Equals(playerComponent.name, StringComparison.InvariantCulture) ? Inventory.main.equipment : null;
}
o => (Equipment)o.GetComponent<Charger>().AliveOrNull()?.ReflectionGet("equipment"),
o => (Equipment)o.GetComponent<BaseNuclearReactor>().AliveOrNull()?.ReflectionGet("_equipment"),
o => o.GetComponent<CyclopsDecoyLoadingTube>().AliveOrNull()?.decoySlots,
o => o.GetComponent<Exosuit>().AliveOrNull()?.modules,
o => o.GetComponent<SeaMoth>().AliveOrNull()?.modules,
o => o.GetComponent<UpgradeConsole>().AliveOrNull()?.modules,
o => o.GetComponent<Vehicle>().AliveOrNull()?.modules,
o => o.GetComponent<VehicleUpgradeConsoleInput>().AliveOrNull()?.equipment,
o => string.Equals("Player", o.GetComponent<Player>().AliveOrNull()?.name, StringComparison.InvariantCulture) ? Inventory.main.equipment : null
};

public static Optional<Equipment> FindEquipmentComponent(GameObject owner)
Expand Down
2 changes: 1 addition & 1 deletion NitroxClient/GameLogic/ItemDropActions/ItemDropAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public abstract class ItemDropAction
{
public abstract void ProcessDroppedItem(GameObject gameObject);

private static Dictionary<TechType, ItemDropAction> dropActionsByTechType = new Dictionary<TechType, ItemDropAction>()
private static readonly Dictionary<TechType, ItemDropAction> dropActionsByTechType = new Dictionary<TechType, ItemDropAction>()
{
{ TechType.Constructor, new ConstructorDropAction() }
};
Expand Down
2 changes: 1 addition & 1 deletion NitroxClient/GameLogic/Spawning/CellRootSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public Optional<GameObject> Spawn(Entity entity, Optional<GameObject> parent, En
NitroxInt3 cellId = entity.AbsoluteEntityCell.CellId;
NitroxInt3 batchId = entity.AbsoluteEntityCell.BatchId;

cellRoot.liveRoot.name = string.Format("CellRoot {0}, {1}, {2}; Batch {3}, {4}, {5}", cellId.X, cellId.Y, cellId.Z, batchId.X, batchId.Y, batchId.Z);
cellRoot.liveRoot.name = $"CellRoot {cellId.X}, {cellId.Y}, {cellId.Z}; Batch {batchId.X}, {batchId.Y}, {batchId.Z}";

NitroxEntity.SetNewId(cellRoot.liveRoot, entity.Id);

Expand Down
2 changes: 1 addition & 1 deletion NitroxClient/GameLogic/Spawning/DefaultEntitySpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public Optional<GameObject> Spawn(Entity entity, Optional<GameObject> parent, En
gameObject.transform.SetParent(parent.Value.transform, true);
}

if (parent.HasValue && parent.Value.GetComponent<LargeWorldEntityCell>() != null)
if (parent.HasValue && !parent.Value.GetComponent<LargeWorldEntityCell>())
{
LargeWorldEntity.Register(gameObject); // This calls SetActive on the GameObject
}
Expand Down
2 changes: 1 addition & 1 deletion NitroxClient/GameLogic/Spawning/SerializedEntitySpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public Optional<GameObject> Spawn(Entity entity, Optional<GameObject> parent, En
gameObject.transform.position = entity.Transform.Position;
gameObject.transform.rotation = entity.Transform.Rotation;
gameObject.transform.localScale = entity.Transform.LocalScale;

if (entity.WaterParkId != null)
{
AssignToWaterPark(gameObject, entity.WaterParkId);
Expand Down
Loading

0 comments on commit 54f167b

Please sign in to comment.