Skip to content
Prev Previous commit
Next Next commit
Replace initial world sync on client join - vastly improves server pe…
…rformance during client's initial connection.
  • Loading branch information
rexxar-tc committed Oct 2, 2018
commit 53806df84b84177ed32bd700c04393bf115e6ff2
1 change: 1 addition & 0 deletions Essentials/Essentials.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
<Compile Include="Commands\PlayerModule.cs" />
<Compile Include="InfoCommand.cs" />
<Compile Include="Commands\InfoModule.cs" />
<Compile Include="Patches\SessionDownloadPatch.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utilities.cs" />
</ItemGroup>
Expand Down
24 changes: 24 additions & 0 deletions Essentials/EssentialsConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,29 @@ public int BackpackLimit

[Display(Visible=false)]
public ObservableCollection<ulong> KnownSteamIds { get; } = new ObservableCollection<ulong>();

private bool _packRespawn;
[Display(Name = "Pack Respawn", GroupName = "Client Join Tweaks", Description = "Packs ships which the client could respawn at into the initial world send. Will significantly decrease time waiting for ships to sync from the respawn menu, at the cost of slightly increased server load during client join.")]
public bool PackRespawn
{
get => _packRespawn;
set => SetValue(ref _packRespawn, value);
}

private int _maxRespawnSize;
[Display(Name = "Max Packed Respawn Size", GroupName = "Client Join Tweaks", Description = "Maximum size, in total block count, of ships that can be packed into the world send. Useful if your players often have very large grids. Will slightly lower performance impact of Pack Respawn option, by forcing clients to wait for very large grids the old way.")]
public int MaxPackedRespawnSize
{
get => _maxRespawnSize;
set => SetValue(ref _maxRespawnSize, value);
}

private string _loadingText;
[Display(Name = "Loading Text", GroupName = "Client Join Tweaks", Description = "Text displayed on the loading screen while the client is joining.")]
public string LoadingText
{
get => _loadingText;
set => SetValue(ref _loadingText, string.IsNullOrEmpty(value) ? null : value);
}
}
}
9 changes: 8 additions & 1 deletion Essentials/EssentialsPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using System.Windows.Controls;
using Essentials.Commands;
using Essentials.Patches;
using NLog;
using Sandbox.Engine.Multiplayer;
using Sandbox.Game;
Expand All @@ -20,6 +21,7 @@
using Torch.API.Session;
using Torch.Commands;
using Torch.Managers;
using Torch.Managers.PatchManager;
using Torch.Mod;
using Torch.Mod.Messages;
using Torch.Session;
Expand All @@ -41,11 +43,13 @@ public class EssentialsPlugin : TorchPluginBase, IWpfPlugin
private Persistent<EssentialsConfig> _config;
private static readonly Logger Log = LogManager.GetLogger("Essentials");
private HashSet<ulong> _motdOnce = new HashSet<ulong>();
private PatchManager _pm;
private PatchContext _context;

public static EssentialsPlugin Instance { get; private set; }

/// <inheritdoc />
public UserControl GetControl() => _control ?? (_control = new PropertyGrid(){DataContext=Config, IsEnabled = false});
public UserControl GetControl() => _control ?? (_control = new PropertyGrid(){DataContext=Config/*, IsEnabled = false*/});

public void Save()
{
Expand All @@ -66,6 +70,9 @@ public override void Init(ITorchBase torch)
Log.Warn("No session manager. MOTD won't work");

Instance = this;
_pm = torch.Managers.GetManager<PatchManager>();
_context = _pm.AcquireContext();
SessionDownloadPatch.Patch(_context);
}

private void SessionChanged(ITorchSession session, TorchSessionState state)
Expand Down
Loading