Compare commits
25 Commits
1.0.180.47
...
1.1.229.26
Author | SHA1 | Date | |
---|---|---|---|
![]() |
82815f66e5 | ||
![]() |
97da740e7e | ||
![]() |
42bb24ca6a | ||
![]() |
2f3b6cdda7 | ||
![]() |
525b496774 | ||
![]() |
562bb77dda | ||
![]() |
76a13dc53a | ||
![]() |
df0f8072a9 | ||
![]() |
87d9825c91 | ||
![]() |
3dba4f744f | ||
![]() |
1fcfe6fb5f | ||
![]() |
3ece4baba6 | ||
![]() |
f49dae2cbf | ||
![]() |
ddf15d756a | ||
![]() |
96d1faddbe | ||
![]() |
17ee96038c | ||
![]() |
e9b432288e | ||
![]() |
b814d1210b | ||
![]() |
c137fb4953 | ||
![]() |
4acce1c9c9 | ||
![]() |
8ab16c3d30 | ||
![]() |
7373dd37a6 | ||
![]() |
1251b945bc | ||
![]() |
79fe6a08ab | ||
![]() |
5e0f69e0e6 |
33
CHANGELOG.md
Normal file
33
CHANGELOG.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# Torch 1.1.229.265
|
||||
* Features
|
||||
- Added more lenient version parsing for plugins (v#.# should work)
|
||||
- Added countdown option to restart command (!restart [seconds])
|
||||
* Fixes
|
||||
- General fixes to work with the latest SE version
|
||||
- Fixed config changes not saving
|
||||
- (hopefully) Fixed issue causing crashes on servers using the Windows Classic theme
|
||||
|
||||
# Torch 1.1.207.7
|
||||
* Notes
|
||||
- This release makes significant changes to TorchConfig.xml. It has been renamed to Torch.cfg and has different options.
|
||||
* Features
|
||||
- Plugins, Torch, and the DS can now all update automatically
|
||||
- Changed command prefix to !
|
||||
- Added manual save command (thanks to Maldark)
|
||||
- Added restart command
|
||||
- Improved instance creation: now creates an entire skeleton instance with blank config
|
||||
- Added instance name to console title
|
||||
* Fixes
|
||||
- Optimized UI so it's snappier and freezes less often
|
||||
- Fixed NetworkManager.RaiseEvent overload that had an off-by-one bug
|
||||
- Fixed chat window so it automatically scrolls down
|
||||
|
||||
# Torch 1.0.182.329
|
||||
* Improved logging, logs now to go the Logs folder and aren't deleted on start
|
||||
* Fixed chat tab not enabling with -autostart
|
||||
* Fixed player list
|
||||
* Watchdog time-out is now configurable in TorchConfig.xml
|
||||
* Fixed infinario log spam
|
||||
* Fixed crash when sending empty message from chat tab
|
||||
* Fixed permissions on Torch commands
|
||||
* Changed plugin StoragePath to the current instance path (per-instance configs)
|
26
CONTRIBUTING.md
Normal file
26
CONTRIBUTING.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# Making a Pull Request
|
||||
* Fork this repository and make sure your local **master** branch is up to date with the main repository.
|
||||
* Create a new branch for your addition with an appropriate name, e.g. **add-restart-command**
|
||||
* PRs work by submitting the *entire* branch, so this allows you to continue work without locking up your whole repository.
|
||||
* Commit your changes to that branch, making sure that you **follow the code guidelines below**.
|
||||
* Submit your branch as a PR to be reviewed.
|
||||
|
||||
## Naming Conventions
|
||||
* Types: **PascalCase**
|
||||
* Prefix interfaces with "**I**"
|
||||
* Suffix delegates with "**Del**"
|
||||
* Methods: **PascalCase**
|
||||
* Method names should generally use verbs in the infinitive tense, for example `GetValue()` or `OpenFile()`. Callbacks and events should use present continuous (-ing) or past tense depending on the context.
|
||||
* Non-Private Members: **PascalCase**
|
||||
* Private Members: **_camelCase**
|
||||
|
||||
## Code Design
|
||||
* **One type per file** with the exception of nested types and delegate declarations.
|
||||
* **No public fields** except for consts, use properties instead
|
||||
* **No stateful static types.** These are a pain to clean up, static types should not store any information.
|
||||
* Use **[dependency injection](https://stackoverflow.com/a/130862)** when possible. Most Torch code uses constructor injection.
|
||||
* **Events and actions** should be null checked before calling or invoked with the `action?.Invoke()` syntax.
|
||||
|
||||
## Documentation
|
||||
* All types and members not marked **private** or **internal** should have XML documentation using the `/// <summary>` tag.
|
||||
* Interface implementations and overridden methods should use the `/// <inheritdoc />` tag unless the summary needs to be changed from the base/interface summary.
|
10
NLog.config
10
NLog.config
@@ -3,13 +3,13 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
|
||||
<targets>
|
||||
<target name="logfile" layout="${longdate} [${level:uppercase=true}] ${logger}: ${message}" xsi:type="File" fileName="Torch.log" deleteOldFileOnStartup="true"/>
|
||||
<target name="console" layout="${longdate} [${level:uppercase=true}] ${logger}: ${message}" xsi:type="ColoredConsole" />
|
||||
<target xsi:type="File" name="main" layout="${time} [${level:uppercase=true}] ${logger}: ${message}" fileName="Logs\Torch-${shortdate}.log" />
|
||||
<target xsi:type="File" name="chat" layout="${longdate} ${message}" fileName="Logs\Chat.log" />
|
||||
<target xsi:type="ColoredConsole" name="console" layout="${time} [${level:uppercase=true}] ${logger}: ${message}" />
|
||||
</targets>
|
||||
|
||||
<rules>
|
||||
<logger name="*" minlevel="Info" writeTo="logfile" />
|
||||
<logger name="*" minlevel="Info" writeTo="console" />
|
||||
<logger name="*" minlevel="Info" writeTo="main, console" />
|
||||
<logger name="Chat" minlevel="Info" writeTo="chat" />
|
||||
</rules>
|
||||
|
||||
</nlog>
|
18
README.md
18
README.md
@@ -10,18 +10,15 @@ Torch is the successor to SE Server Extender and gives server admins the tools t
|
||||
* Organized, easy to use configuration editor
|
||||
* Extensible using the Torch plugin system
|
||||
|
||||
# Installation
|
||||
|
||||
* Get the latest Torch release here: https://github.com/TorchAPI/Torch/releases
|
||||
* Unzip the Torch release into its own directory and run the executable. It will automatically download the SE DS and generate the other necessary files.
|
||||
- If you already have a DS installed you can unzip the Torch files into the folder that contains the DedicatedServer64 folder.
|
||||
|
||||
# Building
|
||||
To build Torch you must first have a complete SE Dedicated installation somewhere. Before you open the solution, run the Setup batch file and enter the path of that installation's DedicatedServer64 folder. The script will make a symlink to that folder so the Torch solution can find the DLL references it needs.
|
||||
|
||||
# Installation Guide
|
||||
Note: Until Torch is in a stable, nearly feature complete state there will not be any binaries available. You'll have to compile the solution yourself.
|
||||
|
||||
### Automatic (recommended)
|
||||
* Unzip Torch to its own folder, run Torch.Server.exe and enter 'y' in the prompt for automatic updates. Torch will automatically download the Space Engineers files and generate all of the configs/folders necessary.
|
||||
|
||||
### Manual (for hosting companies or the paranoid)
|
||||
* Install the Space Engineers DS and then unzip the Torch files into the server's DedicatedServer64 directory. It will automatically detect the manual install and disable automatic updates.
|
||||
|
||||
In both cases you will need to set the InstancePath in TorchConfig.xml to an existing dedicated server instance as Torch can't fully generate it on its own yet.
|
||||
|
||||
# Official Plugins
|
||||
@@ -29,4 +26,5 @@ Install plugins by unzipping them into the 'Plugins' folder which should be in t
|
||||
* [Essentials](https://github.com/TorchAPI/Essentials): Adds a slew of chat commands and other tools to help manage your server.
|
||||
* [Concealment](https://github.com/TorchAPI/Concealment): Adds game logic and physics optimizations that significantly improve sim speed.
|
||||
|
||||
If you have a more enjoyable server experience because of Torch, please consider supporting us on [Patreon](https://www.patreon.com/bePatron?u=847269)!
|
||||
If you have a more enjoyable server experience because of Torch, please consider supporting us on Patreon.
|
||||
[](https://www.patreon.com/bePatron?u=847269)!
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -8,32 +8,110 @@ using VRage.Game.ModAPI;
|
||||
|
||||
namespace Torch.API
|
||||
{
|
||||
/// <summary>
|
||||
/// API for Torch functions shared between client and server.
|
||||
/// </summary>
|
||||
public interface ITorchBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Fired when the session begins loading.
|
||||
/// </summary>
|
||||
event Action SessionLoading;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when the session finishes loading.
|
||||
/// </summary>
|
||||
event Action SessionLoaded;
|
||||
|
||||
/// <summary>
|
||||
/// Fires when the session begins unloading.
|
||||
/// </summary>
|
||||
event Action SessionUnloading;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when the session finishes unloading.
|
||||
/// </summary>
|
||||
event Action SessionUnloaded;
|
||||
|
||||
/// <summary>
|
||||
/// Configuration for the current instance.
|
||||
/// </summary>
|
||||
ITorchConfig Config { get; }
|
||||
|
||||
/// <inheritdoc cref="IMultiplayerManager"/>
|
||||
IMultiplayerManager Multiplayer { get; }
|
||||
|
||||
/// <inheritdoc cref="IPluginManager"/>
|
||||
IPluginManager Plugins { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The binary version of the current instance.
|
||||
/// </summary>
|
||||
Version TorchVersion { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Invoke an action on the game thread.
|
||||
/// </summary>
|
||||
void Invoke(Action action);
|
||||
|
||||
/// <summary>
|
||||
/// Invoke an action on the game thread and block until it has completed.
|
||||
/// If this is called on the game thread the action will execute immediately.
|
||||
/// </summary>
|
||||
void InvokeBlocking(Action action);
|
||||
|
||||
/// <summary>
|
||||
/// Invoke an action on the game thread asynchronously.
|
||||
/// </summary>
|
||||
Task InvokeAsync(Action action);
|
||||
string[] RunArgs { get; set; }
|
||||
bool IsOnGameThread();
|
||||
|
||||
/// <summary>
|
||||
/// Start the Torch instance.
|
||||
/// </summary>
|
||||
void Start();
|
||||
|
||||
/// <summary>
|
||||
/// Stop the Torch instance.
|
||||
/// </summary>
|
||||
void Stop();
|
||||
|
||||
/// <summary>
|
||||
/// Restart the Torch instance.
|
||||
/// </summary>
|
||||
void Restart();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a save of the game.
|
||||
/// </summary>
|
||||
/// <param name="callerId">Id of the player who initiated the save.</param>
|
||||
Task Save(long callerId);
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the Torch instance.
|
||||
/// </summary>
|
||||
void Init();
|
||||
|
||||
/// <summary>
|
||||
/// Get an <see cref="IManager"/> that is part of the Torch instance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Manager type</typeparam>
|
||||
T GetManager<T>() where T : class, IManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// API for the Torch server.
|
||||
/// </summary>
|
||||
public interface ITorchServer : ITorchBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Path of the dedicated instance folder.
|
||||
/// </summary>
|
||||
string InstancePath { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// API for the Torch client.
|
||||
/// </summary>
|
||||
public interface ITorchClient : ITorchBase
|
||||
{
|
||||
|
||||
|
@@ -1,12 +1,23 @@
|
||||
namespace Torch
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Torch
|
||||
{
|
||||
public interface ITorchConfig
|
||||
{
|
||||
bool Autostart { get; set; }
|
||||
bool ForceUpdate { get; set; }
|
||||
bool GetPluginUpdates { get; set; }
|
||||
bool GetTorchUpdates { get; set; }
|
||||
string InstanceName { get; set; }
|
||||
string InstancePath { get; set; }
|
||||
bool RedownloadPlugins { get; set; }
|
||||
bool AutomaticUpdates { get; set; }
|
||||
bool NoGui { get; set; }
|
||||
bool NoUpdate { get; set; }
|
||||
List<string> Plugins { get; set; }
|
||||
bool RestartOnCrash { get; set; }
|
||||
bool ShouldUpdatePlugins { get; }
|
||||
bool ShouldUpdateTorch { get; }
|
||||
int TickTimeout { get; set; }
|
||||
string WaitForPID { get; set; }
|
||||
|
||||
bool Save(string path = null);
|
||||
}
|
||||
|
@@ -6,8 +6,14 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Torch.API.Managers
|
||||
{
|
||||
/// <summary>
|
||||
/// Base interface for Torch managers.
|
||||
/// </summary>
|
||||
public interface IManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes the manager. Called after Torch is initialized.
|
||||
/// </summary>
|
||||
void Init();
|
||||
}
|
||||
}
|
||||
|
@@ -6,17 +6,56 @@ using VRage.Game.ModAPI;
|
||||
|
||||
namespace Torch.API.Managers
|
||||
{
|
||||
/// <summary>
|
||||
/// Delegate for received messages.
|
||||
/// </summary>
|
||||
/// <param name="message">Message data.</param>
|
||||
/// <param name="sendToOthers">Flag to broadcast message to other players.</param>
|
||||
public delegate void MessageReceivedDel(IChatMessage message, ref bool sendToOthers);
|
||||
|
||||
/// <summary>
|
||||
/// API for multiplayer related functions.
|
||||
/// </summary>
|
||||
public interface IMultiplayerManager : IManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Fired when a player joins.
|
||||
/// </summary>
|
||||
event Action<IPlayer> PlayerJoined;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a player disconnects.
|
||||
/// </summary>
|
||||
event Action<IPlayer> PlayerLeft;
|
||||
|
||||
/// <summary>
|
||||
/// Fired when a chat message is received.
|
||||
/// </summary>
|
||||
event MessageReceivedDel MessageReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Send a chat message to all or one specific player.
|
||||
/// </summary>
|
||||
void SendMessage(string message, string author = "Server", long playerId = 0, string font = MyFontEnum.Blue);
|
||||
|
||||
/// <summary>
|
||||
/// Kicks the player from the game.
|
||||
/// </summary>
|
||||
void KickPlayer(ulong steamId);
|
||||
|
||||
/// <summary>
|
||||
/// Bans or unbans a player from the game.
|
||||
/// </summary>
|
||||
void BanPlayer(ulong steamId, bool banned = true);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a player by their Steam64 ID or returns null if the player isn't found.
|
||||
/// </summary>
|
||||
IMyPlayer GetPlayerBySteamId(ulong id);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a player by their display name or returns null if the player isn't found.
|
||||
/// </summary>
|
||||
IMyPlayer GetPlayerByName(string name);
|
||||
}
|
||||
}
|
@@ -9,14 +9,30 @@ using VRage.Network;
|
||||
|
||||
namespace Torch.API.Managers
|
||||
{
|
||||
/// <summary>
|
||||
/// API for the network intercept.
|
||||
/// </summary>
|
||||
public interface INetworkManager : IManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Register a network handler.
|
||||
/// </summary>
|
||||
void RegisterNetworkHandler(INetworkHandler handler);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handler for multiplayer network messages.
|
||||
/// </summary>
|
||||
public interface INetworkHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns if the handler can process the call site.
|
||||
/// </summary>
|
||||
bool CanHandle(CallSite callSite);
|
||||
|
||||
/// <summary>
|
||||
/// Processes a network message.
|
||||
/// </summary>
|
||||
bool Handle(ulong remoteUserId, CallSite site, BitStream stream, object obj, MyPacket packet);
|
||||
}
|
||||
}
|
||||
|
@@ -6,11 +6,34 @@ using VRage.Plugins;
|
||||
|
||||
namespace Torch.API.Managers
|
||||
{
|
||||
/// <summary>
|
||||
/// API for the Torch plugin manager.
|
||||
/// </summary>
|
||||
public interface IPluginManager : IManager, IEnumerable<ITorchPlugin>
|
||||
{
|
||||
event Action<List<ITorchPlugin>> PluginsLoaded;
|
||||
List<ITorchPlugin> Plugins { get; }
|
||||
/// <summary>
|
||||
/// Fired when plugins are loaded.
|
||||
/// </summary>
|
||||
event Action<IList<ITorchPlugin>> PluginsLoaded;
|
||||
|
||||
/// <summary>
|
||||
/// Collection of loaded plugins.
|
||||
/// </summary>
|
||||
IList<ITorchPlugin> Plugins { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Updates all loaded plugins.
|
||||
/// </summary>
|
||||
void UpdatePlugins();
|
||||
|
||||
/// <summary>
|
||||
/// Disposes all loaded plugins.
|
||||
/// </summary>
|
||||
void DisposePlugins();
|
||||
|
||||
/// <summary>
|
||||
/// Load plugins.
|
||||
/// </summary>
|
||||
void LoadPlugins();
|
||||
}
|
||||
}
|
@@ -6,11 +6,29 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Torch.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to indicate the state of the dedicated server.
|
||||
/// </summary>
|
||||
public enum ServerState
|
||||
{
|
||||
/// <summary>
|
||||
/// The server is not running.
|
||||
/// </summary>
|
||||
Stopped,
|
||||
|
||||
/// <summary>
|
||||
/// The server is starting/loading the session.
|
||||
/// </summary>
|
||||
Starting,
|
||||
|
||||
/// <summary>
|
||||
/// The server is running.
|
||||
/// </summary>
|
||||
Running,
|
||||
|
||||
/// <summary>
|
||||
/// The server encountered an error.
|
||||
/// </summary>
|
||||
Error
|
||||
}
|
||||
}
|
||||
|
@@ -158,12 +158,12 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="ConnectionState.cs" />
|
||||
<Compile Include="IChatMessage.cs" />
|
||||
<Compile Include="ITorchConfig.cs" />
|
||||
<Compile Include="Managers\IManager.cs" />
|
||||
<Compile Include="Managers\IMultiplayerManager.cs" />
|
||||
<Compile Include="IPlayer.cs" />
|
||||
<Compile Include="Managers\INetworkManager.cs" />
|
||||
<Compile Include="Managers\IPluginManager.cs" />
|
||||
<Compile Include="ITorchConfig.cs" />
|
||||
<Compile Include="Plugins\ITorchPlugin.cs" />
|
||||
<Compile Include="IServerControls.cs" />
|
||||
<Compile Include="ITorchBase.cs" />
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: AssemblyVersion("1.0.169.376")]
|
||||
[assembly: AssemblyFileVersion("1.0.169.376")]
|
||||
[assembly: AssemblyVersion("1.0.229.265")]
|
||||
[assembly: AssemblyFileVersion("1.0.229.265")]
|
@@ -45,6 +45,10 @@
|
||||
<HintPath>..\packages\NLog.4.4.1\lib\net45\NLog.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Sandbox.Common, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\GameBinaries\Sandbox.Common.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Sandbox.Game">
|
||||
<HintPath>..\GameBinaries\Sandbox.Game.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
@@ -99,6 +103,9 @@
|
||||
<HintPath>..\GameBinaries\VRage.Render11.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="VRage.Steam">
|
||||
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Steam.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="WindowsBase" />
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
|
@@ -9,7 +9,9 @@ using Sandbox;
|
||||
using Sandbox.Engine.Platform;
|
||||
using Sandbox.Engine.Utils;
|
||||
using Sandbox.Game;
|
||||
using Sandbox.ModAPI;
|
||||
using SpaceEngineers.Game;
|
||||
using VRage.Steam;
|
||||
using Torch.API;
|
||||
using VRage.FileSystem;
|
||||
using VRageRender;
|
||||
@@ -21,7 +23,6 @@ namespace Torch.Client
|
||||
private MyCommonProgramStartup _startup;
|
||||
private IMyRender _renderer;
|
||||
private const uint APP_ID = 244850;
|
||||
private VRageGameServices _services;
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
@@ -58,7 +59,6 @@ namespace Torch.Client
|
||||
|
||||
InitializeRender();
|
||||
|
||||
_services = new VRageGameServices(mySteamService);
|
||||
if (!Game.IsDedicated)
|
||||
MyFileSystem.InitUserSpecific(mySteamService.UserId.ToString());
|
||||
}
|
||||
@@ -84,7 +84,7 @@ namespace Torch.Client
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
using (var spaceEngineersGame = new SpaceEngineersGame(_services, RunArgs))
|
||||
using (var spaceEngineersGame = new SpaceEngineersGame(RunArgs))
|
||||
{
|
||||
Log.Info("Starting client");
|
||||
spaceEngineersGame.OnGameLoaded += SpaceEngineersGame_OnGameLoaded;
|
||||
|
59
Torch.Server/ListBoxExtensions.cs
Normal file
59
Torch.Server/ListBoxExtensions.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Torch.Server
|
||||
{
|
||||
public static class ListBoxExtensions
|
||||
{
|
||||
//https://stackoverflow.com/questions/28689125/how-to-autoscroll-listbox-to-bottom-wpf-c
|
||||
public static void ScrollToItem(this ListBox listBox, int index)
|
||||
{
|
||||
// Find a container
|
||||
UIElement container = null;
|
||||
for (int i = index; i > 0; i--)
|
||||
{
|
||||
container = listBox.ItemContainerGenerator.ContainerFromIndex(i) as UIElement;
|
||||
if (container != null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (container == null)
|
||||
return;
|
||||
|
||||
// Find the ScrollContentPresenter
|
||||
ScrollContentPresenter presenter = null;
|
||||
for (Visual vis = container; vis != null && vis != listBox; vis = VisualTreeHelper.GetParent(vis) as Visual)
|
||||
if ((presenter = vis as ScrollContentPresenter) != null)
|
||||
break;
|
||||
if (presenter == null)
|
||||
return;
|
||||
|
||||
// Find the IScrollInfo
|
||||
var scrollInfo =
|
||||
!presenter.CanContentScroll ? presenter :
|
||||
presenter.Content as IScrollInfo ??
|
||||
FirstVisualChild(presenter.Content as ItemsPresenter) as IScrollInfo ??
|
||||
presenter;
|
||||
|
||||
// Find the amount of items that is "Visible" in the ListBox
|
||||
var height = (container as ListBoxItem).ActualHeight;
|
||||
var lbHeight = listBox.ActualHeight;
|
||||
var showCount = (int)Math.Floor(lbHeight / height) - 1;
|
||||
|
||||
//Set the scrollbar
|
||||
if (scrollInfo.CanVerticallyScroll)
|
||||
scrollInfo.SetVerticalOffset(index - showCount);
|
||||
}
|
||||
|
||||
private static DependencyObject FirstVisualChild(Visual visual)
|
||||
{
|
||||
if (visual == null) return null;
|
||||
if (VisualTreeHelper.GetChildrenCount(visual) == 0) return null;
|
||||
return VisualTreeHelper.GetChild(visual, 0);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,62 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Sandbox.Engine.Utils;
|
||||
using Torch.API;
|
||||
using Torch.API.Managers;
|
||||
using Torch.Managers;
|
||||
using Torch.Server.ViewModels;
|
||||
using VRage.Game;
|
||||
|
||||
namespace Torch.Server.Managers
|
||||
{
|
||||
//TODO
|
||||
public class ConfigManager : Manager
|
||||
{
|
||||
private const string CONFIG_NAME = "SpaceEngineers-Dedicated.cfg";
|
||||
public ConfigDedicatedViewModel DedicatedConfig { get; set; }
|
||||
public TorchConfig TorchConfig { get; set; }
|
||||
|
||||
public ConfigManager(ITorchBase torchInstance) : base(torchInstance)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Init()
|
||||
{
|
||||
LoadInstance(Torch.Config.InstancePath);
|
||||
}
|
||||
|
||||
public void LoadInstance(string path)
|
||||
{
|
||||
if (!Directory.Exists(path))
|
||||
throw new FileNotFoundException($"Instance directory not found at '{path}'");
|
||||
|
||||
var configPath = Path.Combine(path, CONFIG_NAME);
|
||||
var config = new MyConfigDedicated<MyObjectBuilder_SessionSettings>(configPath);
|
||||
config.Load();
|
||||
DedicatedConfig = new ConfigDedicatedViewModel(config);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a skeleton of a DS instance folder at the given directory.
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
public void CreateInstance(string path)
|
||||
{
|
||||
if (Directory.Exists(path))
|
||||
return;
|
||||
|
||||
Directory.CreateDirectory(path);
|
||||
var savesPath = Path.Combine(path, "Saves");
|
||||
Directory.CreateDirectory(savesPath);
|
||||
var modsPath = Path.Combine(path, "Mods");
|
||||
Directory.CreateDirectory(modsPath);
|
||||
LoadInstance(path);
|
||||
}
|
||||
}
|
||||
}
|
173
Torch.Server/Managers/InstanceManager.cs
Normal file
173
Torch.Server/Managers/InstanceManager.cs
Normal file
@@ -0,0 +1,173 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Havok;
|
||||
using NLog;
|
||||
using Sandbox.Engine.Networking;
|
||||
using Sandbox.Engine.Utils;
|
||||
using Torch.API;
|
||||
using Torch.API.Managers;
|
||||
using Torch.Managers;
|
||||
using Torch.Server.ViewModels;
|
||||
using VRage.FileSystem;
|
||||
using VRage.Game;
|
||||
using VRage.ObjectBuilders;
|
||||
|
||||
namespace Torch.Server.Managers
|
||||
{
|
||||
public class InstanceManager : Manager
|
||||
{
|
||||
private const string CONFIG_NAME = "SpaceEngineers-Dedicated.cfg";
|
||||
public ConfigDedicatedViewModel DedicatedConfig { get; set; }
|
||||
private static readonly Logger Log = LogManager.GetLogger(nameof(InstanceManager));
|
||||
|
||||
public InstanceManager(ITorchBase torchInstance) : base(torchInstance)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Init()
|
||||
{
|
||||
MyFileSystem.ExePath = Path.Combine(Torch.GetManager<FilesystemManager>().TorchDirectory, "DedicatedServer64");
|
||||
MyFileSystem.Init("Content", Torch.Config.InstancePath);
|
||||
//Initializes saves path. Why this isn't in Init() we may never know.
|
||||
MyFileSystem.InitUserSpecific(null);
|
||||
}
|
||||
|
||||
public void LoadInstance(string path, bool validate = true)
|
||||
{
|
||||
if (validate)
|
||||
ValidateInstance(path);
|
||||
|
||||
MyFileSystem.Reset();
|
||||
MyFileSystem.ExePath = Path.Combine(Torch.GetManager<FilesystemManager>().TorchDirectory, "DedicatedServer64");
|
||||
MyFileSystem.Init("Content", path);
|
||||
//Initializes saves path. Why this isn't in Init() we may never know.
|
||||
MyFileSystem.InitUserSpecific(null);
|
||||
|
||||
var configPath = Path.Combine(path, CONFIG_NAME);
|
||||
if (!File.Exists(configPath))
|
||||
{
|
||||
Log.Error($"Failed to load dedicated config at {path}");
|
||||
return;
|
||||
}
|
||||
|
||||
var config = new MyConfigDedicated<MyObjectBuilder_SessionSettings>(configPath);
|
||||
config.Load(configPath);
|
||||
|
||||
DedicatedConfig = new ConfigDedicatedViewModel(config);
|
||||
var worldFolders = Directory.EnumerateDirectories(Path.Combine(Torch.Config.InstancePath, "Saves"));
|
||||
|
||||
foreach (var f in worldFolders)
|
||||
DedicatedConfig.WorldPaths.Add(f);
|
||||
|
||||
if (DedicatedConfig.WorldPaths.Count == 0)
|
||||
{
|
||||
Log.Warn($"No worlds found in the current instance {path}.");
|
||||
return;
|
||||
}
|
||||
|
||||
ImportWorldConfig();
|
||||
|
||||
/*
|
||||
if (string.IsNullOrEmpty(DedicatedConfig.LoadWorld))
|
||||
{
|
||||
Log.Warn("No world specified, importing first available world.");
|
||||
SelectWorld(DedicatedConfig.WorldPaths[0], false);
|
||||
}*/
|
||||
}
|
||||
|
||||
public void SelectWorld(string worldPath, bool modsOnly = true)
|
||||
{
|
||||
DedicatedConfig.LoadWorld = worldPath;
|
||||
ImportWorldConfig(modsOnly);
|
||||
}
|
||||
|
||||
|
||||
private void ImportWorldConfig(bool modsOnly = true)
|
||||
{
|
||||
if (string.IsNullOrEmpty(DedicatedConfig.LoadWorld))
|
||||
return;
|
||||
|
||||
var sandboxPath = Path.Combine(DedicatedConfig.LoadWorld, "Sandbox.sbc");
|
||||
|
||||
if (!File.Exists(sandboxPath))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
MyObjectBuilderSerializer.DeserializeXML(sandboxPath, out MyObjectBuilder_Checkpoint checkpoint, out ulong sizeInBytes);
|
||||
if (checkpoint == null)
|
||||
{
|
||||
Log.Error($"Failed to load {DedicatedConfig.LoadWorld}, checkpoint null ({sizeInBytes} bytes, instance {TorchBase.Instance.Config.InstancePath})");
|
||||
return;
|
||||
}
|
||||
|
||||
var sb = new StringBuilder();
|
||||
foreach (var mod in checkpoint.Mods)
|
||||
sb.AppendLine(mod.PublishedFileId.ToString());
|
||||
|
||||
DedicatedConfig.Mods = sb.ToString();
|
||||
|
||||
Log.Debug("Loaded mod list from world");
|
||||
|
||||
if (!modsOnly)
|
||||
DedicatedConfig.SessionSettings = new SessionSettingsViewModel(checkpoint.Settings);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error($"Error loading mod list from world, verify that your mod list is accurate. '{DedicatedConfig.LoadWorld}'.");
|
||||
Log.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveConfig()
|
||||
{
|
||||
DedicatedConfig.Save();
|
||||
Log.Info("Saved dedicated config.");
|
||||
|
||||
try
|
||||
{
|
||||
MyObjectBuilderSerializer.DeserializeXML(Path.Combine(DedicatedConfig.LoadWorld, "Sandbox.sbc"), out MyObjectBuilder_Checkpoint checkpoint, out ulong sizeInBytes);
|
||||
if (checkpoint == null)
|
||||
{
|
||||
Log.Error($"Failed to load {DedicatedConfig.LoadWorld}, checkpoint null ({sizeInBytes} bytes, instance {TorchBase.Instance.Config.InstancePath})");
|
||||
return;
|
||||
}
|
||||
checkpoint.Settings = DedicatedConfig.SessionSettings;
|
||||
checkpoint.Mods.Clear();
|
||||
foreach (var modId in DedicatedConfig.Model.Mods)
|
||||
checkpoint.Mods.Add(new MyObjectBuilder_Checkpoint.ModItem(modId));
|
||||
|
||||
MyLocalCache.SaveCheckpoint(checkpoint, DedicatedConfig.LoadWorld);
|
||||
Log.Info("Saved world config.");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error("Failed to write sandbox config, changes will not appear on server");
|
||||
Log.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures that the given path is a valid server instance.
|
||||
/// </summary>
|
||||
private void ValidateInstance(string path)
|
||||
{
|
||||
Directory.CreateDirectory(Path.Combine(path, "Saves"));
|
||||
Directory.CreateDirectory(Path.Combine(path, "Mods"));
|
||||
var configPath = Path.Combine(path, CONFIG_NAME);
|
||||
if (File.Exists(configPath))
|
||||
return;
|
||||
|
||||
var config = new MyConfigDedicated<MyObjectBuilder_SessionSettings>(configPath);
|
||||
config.Save(configPath);
|
||||
}
|
||||
}
|
||||
}
|
@@ -23,6 +23,7 @@ using Torch.Server.Views;
|
||||
using VRage.Game.ModAPI;
|
||||
using System.IO.Compression;
|
||||
using System.Net;
|
||||
using System.Security.Policy;
|
||||
using Torch.Server.Managers;
|
||||
using VRage.FileSystem;
|
||||
using VRageRender;
|
||||
@@ -34,8 +35,8 @@ namespace Torch.Server
|
||||
private static ITorchServer _server;
|
||||
private static Logger _log = LogManager.GetLogger("Torch");
|
||||
private static bool _restartOnCrash;
|
||||
public static bool IsManualInstall;
|
||||
private static TorchCli _cli;
|
||||
private static TorchConfig _config;
|
||||
private static bool _steamCmdDone;
|
||||
|
||||
/// <summary>
|
||||
/// This method must *NOT* load any types/assemblies from the vanilla game, otherwise automatic updates will fail.
|
||||
@@ -46,10 +47,10 @@ namespace Torch.Server
|
||||
//Ensures that all the files are downloaded in the Torch directory.
|
||||
Directory.SetCurrentDirectory(new FileInfo(typeof(Program).Assembly.Location).Directory.ToString());
|
||||
|
||||
IsManualInstall = File.Exists("SpaceEngineersDedicated.exe");
|
||||
if (!IsManualInstall)
|
||||
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
|
||||
foreach (var file in Directory.GetFiles(Directory.GetCurrentDirectory(), "*.old"))
|
||||
File.Delete(file);
|
||||
|
||||
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
|
||||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
||||
|
||||
if (!Environment.UserInteractive)
|
||||
@@ -61,55 +62,36 @@ namespace Torch.Server
|
||||
return;
|
||||
}
|
||||
|
||||
var configName = "TorchConfig.xml";
|
||||
var configPath = Path.Combine(Directory.GetCurrentDirectory(), configName);
|
||||
TorchConfig options;
|
||||
if (File.Exists(configName))
|
||||
//CommandLine reflection triggers assembly loading, so DS update must be completely separated.
|
||||
if (!args.Contains("-noupdate"))
|
||||
{
|
||||
_log.Info($"Loading config {configPath}");
|
||||
options = TorchConfig.LoadFrom(configPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
_log.Info($"Generating default config at {configPath}");
|
||||
options = new TorchConfig();
|
||||
|
||||
if (!IsManualInstall)
|
||||
if (!Directory.Exists("DedicatedServer64"))
|
||||
{
|
||||
//new ConfigManager().CreateInstance("Instance");
|
||||
options.InstancePath = Path.GetFullPath("Instance");
|
||||
|
||||
_log.Warn("Would you like to enable automatic updates? (Y/n):");
|
||||
|
||||
var input = Console.ReadLine() ?? "";
|
||||
var autoUpdate = !input.Equals("n", StringComparison.InvariantCultureIgnoreCase);
|
||||
options.AutomaticUpdates = autoUpdate;
|
||||
if (autoUpdate)
|
||||
{
|
||||
_log.Info("Automatic updates enabled, updating server.");
|
||||
RunSteamCmd();
|
||||
}
|
||||
_log.Error("Game libraries not found. Press the Enter key to install the dedicated server.");
|
||||
Console.ReadLine();
|
||||
}
|
||||
|
||||
//var setupDialog = new FirstTimeSetup { DataContext = options };
|
||||
//setupDialog.ShowDialog();
|
||||
options.Save(configPath);
|
||||
RunSteamCmd();
|
||||
}
|
||||
|
||||
_cli = new TorchCli { Config = options };
|
||||
if (!_cli.Parse(args))
|
||||
InitConfig();
|
||||
|
||||
if (!_config.Parse(args))
|
||||
return;
|
||||
|
||||
_log.Debug(_cli.ToString());
|
||||
|
||||
if (!string.IsNullOrEmpty(_cli.WaitForPID))
|
||||
if (!string.IsNullOrEmpty(_config.WaitForPID))
|
||||
{
|
||||
try
|
||||
{
|
||||
var pid = int.Parse(_cli.WaitForPID);
|
||||
var pid = int.Parse(_config.WaitForPID);
|
||||
var waitProc = Process.GetProcessById(pid);
|
||||
_log.Warn($"Waiting for process {pid} to exit.");
|
||||
waitProc.WaitForExit();
|
||||
_log.Info("Continuing in 5 seconds.");
|
||||
Thread.Sleep(5000);
|
||||
if (!waitProc.HasExited)
|
||||
{
|
||||
_log.Warn($"Killing old process {pid}.");
|
||||
waitProc.Kill();
|
||||
}
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -117,18 +99,25 @@ namespace Torch.Server
|
||||
}
|
||||
}
|
||||
|
||||
_restartOnCrash = _cli.RestartOnCrash;
|
||||
_restartOnCrash = _config.RestartOnCrash;
|
||||
RunServer(_config);
|
||||
}
|
||||
|
||||
if (options.AutomaticUpdates || _cli.Update)
|
||||
public static void InitConfig()
|
||||
{
|
||||
var configName = "Torch.cfg";
|
||||
var configPath = Path.Combine(Directory.GetCurrentDirectory(), configName);
|
||||
if (File.Exists(configName))
|
||||
{
|
||||
if (IsManualInstall)
|
||||
_log.Warn("Detected manual install, won't attempt to update DS");
|
||||
else
|
||||
{
|
||||
RunSteamCmd();
|
||||
}
|
||||
_log.Info($"Loading config {configPath}");
|
||||
_config = TorchConfig.LoadFrom(configPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
_log.Info($"Generating default config at {configPath}");
|
||||
_config = new TorchConfig { InstancePath = Path.GetFullPath("Instance") };
|
||||
_config.Save(configPath);
|
||||
}
|
||||
RunServer(options, _cli);
|
||||
}
|
||||
|
||||
private const string STEAMCMD_DIR = "steamcmd";
|
||||
@@ -142,6 +131,9 @@ quit";
|
||||
|
||||
public static void RunSteamCmd()
|
||||
{
|
||||
if (_steamCmdDone)
|
||||
return;
|
||||
|
||||
var log = LogManager.GetLogger("SteamCMD");
|
||||
|
||||
if (!Directory.Exists(STEAMCMD_DIR))
|
||||
@@ -187,38 +179,40 @@ quit";
|
||||
log.Info(cmd.StandardOutput.ReadLine());
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
|
||||
_steamCmdDone = true;
|
||||
}
|
||||
|
||||
public static void RunServer(TorchConfig options, TorchCli cli)
|
||||
public static void RunServer(TorchConfig config)
|
||||
{
|
||||
|
||||
|
||||
/*
|
||||
if (!parser.ParseArguments(args, options))
|
||||
if (!parser.ParseArguments(args, config))
|
||||
{
|
||||
_log.Error($"Parsing arguments failed: {string.Join(" ", args)}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(options.Config) && File.Exists(options.Config))
|
||||
if (!string.IsNullOrEmpty(config.Config) && File.Exists(config.Config))
|
||||
{
|
||||
options = ServerConfig.LoadFrom(options.Config);
|
||||
parser.ParseArguments(args, options);
|
||||
config = ServerConfig.LoadFrom(config.Config);
|
||||
parser.ParseArguments(args, config);
|
||||
}*/
|
||||
|
||||
//RestartOnCrash autostart autosave=15
|
||||
//gamepath ="C:\Program Files\Space Engineers DS" instance="Hydro Survival" instancepath="C:\ProgramData\SpaceEngineersDedicated\Hydro Survival"
|
||||
|
||||
/*
|
||||
if (options.InstallService)
|
||||
if (config.InstallService)
|
||||
{
|
||||
var serviceName = $"\"Torch - {options.InstanceName}\"";
|
||||
var serviceName = $"\"Torch - {config.InstanceName}\"";
|
||||
// Working on installing the service properly instead of with sc.exe
|
||||
_log.Info($"Installing service '{serviceName}");
|
||||
var exePath = $"\"{Assembly.GetExecutingAssembly().Location}\"";
|
||||
var createInfo = new ServiceCreateInfo
|
||||
{
|
||||
Name = options.InstanceName,
|
||||
Name = config.InstanceName,
|
||||
BinaryPath = exePath,
|
||||
};
|
||||
_log.Info("Service Installed");
|
||||
@@ -238,7 +232,7 @@ quit";
|
||||
return;
|
||||
}
|
||||
|
||||
if (options.UninstallService)
|
||||
if (config.UninstallService)
|
||||
{
|
||||
_log.Info("Uninstalling Torch service");
|
||||
var startInfo = new ProcessStartInfo
|
||||
@@ -254,18 +248,17 @@ quit";
|
||||
return;
|
||||
}*/
|
||||
|
||||
_server = new TorchServer(options);
|
||||
_server.Init();
|
||||
_server = new TorchServer(config);
|
||||
|
||||
if (cli.NoGui || cli.Autostart)
|
||||
_server.Init();
|
||||
if (config.NoGui || config.Autostart)
|
||||
{
|
||||
new Thread(() => _server.Start()).Start();
|
||||
}
|
||||
|
||||
if (!cli.NoGui)
|
||||
if (!config.NoGui)
|
||||
{
|
||||
var ui = new TorchUI((TorchServer)_server);
|
||||
ui.LoadConfig(options);
|
||||
ui.ShowDialog();
|
||||
}
|
||||
}
|
||||
@@ -291,19 +284,13 @@ quit";
|
||||
{
|
||||
var ex = (Exception)e.ExceptionObject;
|
||||
_log.Fatal(ex);
|
||||
Console.WriteLine("Exiting in 5 seconds.");
|
||||
Thread.Sleep(5000);
|
||||
if (_restartOnCrash)
|
||||
{
|
||||
/* Throws an exception somehow and I'm too lazy to debug it.
|
||||
try
|
||||
{
|
||||
if (MySession.Static != null && MySession.Static.AutoSaveInMinutes > 0)
|
||||
MySession.Static.Save();
|
||||
}
|
||||
catch { }*/
|
||||
|
||||
var exe = typeof(Program).Assembly.Location;
|
||||
_cli.WaitForPID = Process.GetCurrentProcess().Id.ToString();
|
||||
Process.Start(exe, _cli.ToString());
|
||||
_config.WaitForPID = Process.GetCurrentProcess().Id.ToString();
|
||||
Process.Start(exe, _config.ToString());
|
||||
}
|
||||
//1627 = Function failed during execution.
|
||||
Environment.Exit(1627);
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: AssemblyVersion("1.0.169.376")]
|
||||
[assembly: AssemblyFileVersion("1.0.169.376")]
|
||||
[assembly: AssemblyVersion("1.1.229.265")]
|
||||
[assembly: AssemblyFileVersion("1.1.229.265")]
|
@@ -8,7 +8,7 @@ using System.Reflection;
|
||||
|
||||
<# var dt = DateTime.Now;
|
||||
int major = 1;
|
||||
int minor = 0;
|
||||
int minor = 1;
|
||||
int build = dt.DayOfYear;
|
||||
int rev = (int)dt.TimeOfDay.TotalMinutes / 2;
|
||||
#>
|
||||
|
@@ -59,9 +59,11 @@
|
||||
<HintPath>..\GameBinaries\Microsoft.CodeAnalysis.CSharp.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.4.1\lib\net45\NLog.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\NLog.4.4.11\lib\net45\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Sandbox.Common, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
@@ -183,8 +185,8 @@
|
||||
<Reference Include="PresentationFramework" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Managers\ConfigManager.cs" />
|
||||
<Compile Include="TorchCli.cs" />
|
||||
<Compile Include="ListBoxExtensions.cs" />
|
||||
<Compile Include="Managers\InstanceManager.cs" />
|
||||
<Compile Include="NativeMethods.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
@@ -365,7 +367,9 @@
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>copy "$(SolutionDir)NLog.config" "$(TargetDir)"</PostBuildEvent>
|
||||
<PostBuildEvent>cd "$(TargetDir)"
|
||||
copy "$(SolutionDir)NLog.config" "$(TargetDir)"
|
||||
"Torch Server Release.bat"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
@@ -1,41 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Torch.Server
|
||||
{
|
||||
public class TorchCli : CommandLine
|
||||
{
|
||||
public TorchConfig Config { get; set; }
|
||||
|
||||
[Arg("instancepath", "Server data folder where saves and mods are stored.")]
|
||||
public string InstancePath { get => Config.InstancePath; set => Config.InstancePath = value; }
|
||||
|
||||
[Arg("noupdate", "Disable automatically downloading game and plugin updates.")]
|
||||
public bool NoUpdate { get => !Config.AutomaticUpdates; set => Config.AutomaticUpdates = !value; }
|
||||
|
||||
[Arg("update", "Manually check for and install updates.")]
|
||||
public bool Update { get; set; }
|
||||
|
||||
//TODO: backend code for this
|
||||
//[Arg("worldpath", "Path to the game world folder to load.")]
|
||||
public string WorldPath { get; set; }
|
||||
|
||||
[Arg("autostart", "Start the server immediately.")]
|
||||
public bool Autostart { get; set; }
|
||||
|
||||
[Arg("restartoncrash", "Automatically restart the server if it crashes.")]
|
||||
public bool RestartOnCrash { get => Config.RestartOnCrash; set => Config.RestartOnCrash = value; }
|
||||
|
||||
[Arg("nogui", "Do not show the Torch UI.")]
|
||||
public bool NoGui { get; set; }
|
||||
|
||||
[Arg("silent", "Do not show the Torch UI or the command line.")]
|
||||
public bool Silent { get; set; }
|
||||
|
||||
[Arg("waitforpid", "Makes Torch wait for another process to exit.")]
|
||||
public string WaitForPID { get; set; }
|
||||
}
|
||||
}
|
@@ -3,52 +3,86 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
|
||||
namespace Torch.Server
|
||||
{
|
||||
public class TorchConfig : ITorchConfig
|
||||
public class TorchConfig : CommandLine, ITorchConfig
|
||||
{
|
||||
private static Logger _log = LogManager.GetLogger("Config");
|
||||
|
||||
public string InstancePath { get; set; }
|
||||
public bool ShouldUpdatePlugins => (GetPluginUpdates && !NoUpdate) || ForceUpdate;
|
||||
public bool ShouldUpdateTorch => (GetTorchUpdates && !NoUpdate) || ForceUpdate;
|
||||
|
||||
/// <inheritdoc />
|
||||
[Arg("instancename", "The name of the Torch instance.")]
|
||||
public string InstanceName { get; set; }
|
||||
#warning World Path not implemented
|
||||
public string WorldPath { get; set; }
|
||||
//public int Autosave { get; set; }
|
||||
//public bool AutoRestart { get; set; }
|
||||
//public bool LogChat { get; set; }
|
||||
public bool AutomaticUpdates { get; set; } = true;
|
||||
public bool RedownloadPlugins { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
[Arg("instancepath", "Server data folder where saves and mods are stored.")]
|
||||
public string InstancePath { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
[XmlIgnore, Arg("noupdate", "Disable automatically downloading game and plugin updates.")]
|
||||
public bool NoUpdate { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
[XmlIgnore, Arg("forceupdate", "Manually check for and install updates.")]
|
||||
public bool ForceUpdate { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
[Arg("autostart", "Start the server immediately.")]
|
||||
public bool Autostart { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
[Arg("restartoncrash", "Automatically restart the server if it crashes.")]
|
||||
public bool RestartOnCrash { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
[Arg("nogui", "Do not show the Torch UI.")]
|
||||
public bool NoGui { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
[XmlIgnore, Arg("waitforpid", "Makes Torch wait for another process to exit.")]
|
||||
public string WaitForPID { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool GetTorchUpdates { get; set; } = true;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool GetPluginUpdates { get; set; } = true;
|
||||
|
||||
/// <inheritdoc />
|
||||
public int TickTimeout { get; set; } = 60;
|
||||
|
||||
/// <inheritdoc />
|
||||
public List<string> Plugins { get; set; } = new List<string>();
|
||||
public Point WindowSize { get; set; } = new Point(800, 600);
|
||||
public Point WindowPosition { get; set; } = new Point();
|
||||
[NonSerialized]
|
||||
|
||||
internal Point WindowSize { get; set; } = new Point(800, 600);
|
||||
internal Point WindowPosition { get; set; } = new Point();
|
||||
[XmlIgnore]
|
||||
private string _path;
|
||||
|
||||
public TorchConfig() : this("Torch") { }
|
||||
|
||||
public TorchConfig(string instanceName = "Torch", string instancePath = null, int autosaveInterval = 5, bool autoRestart = false)
|
||||
public TorchConfig(string instanceName = "Torch", string instancePath = null)
|
||||
{
|
||||
InstanceName = instanceName;
|
||||
InstancePath = instancePath ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SpaceEngineersDedicated");
|
||||
//Autosave = autosaveInterval;
|
||||
//AutoRestart = autoRestart;
|
||||
}
|
||||
|
||||
public static TorchConfig LoadFrom(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
var serializer = new XmlSerializer(typeof(TorchConfig));
|
||||
TorchConfig config;
|
||||
var ser = new XmlSerializer(typeof(TorchConfig));
|
||||
using (var f = File.OpenRead(path))
|
||||
{
|
||||
config = (TorchConfig)serializer.Deserialize(f);
|
||||
var config = (TorchConfig)ser.Deserialize(f);
|
||||
config._path = path;
|
||||
return config;
|
||||
}
|
||||
config._path = path;
|
||||
return config;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -66,11 +100,9 @@ namespace Torch.Server
|
||||
|
||||
try
|
||||
{
|
||||
var serializer = new XmlSerializer(typeof(TorchConfig));
|
||||
var ser = new XmlSerializer(typeof(TorchConfig));
|
||||
using (var f = File.Create(path))
|
||||
{
|
||||
serializer.Serialize(f, this);
|
||||
}
|
||||
ser.Serialize(f, this);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@@ -10,14 +10,19 @@ using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security.Principal;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Xml.Serialization.GeneratedAssembly;
|
||||
using Sandbox.Engine.Analytics;
|
||||
using Sandbox.Game.Multiplayer;
|
||||
using Sandbox.ModAPI;
|
||||
using SteamSDK;
|
||||
using Torch.API;
|
||||
using Torch.Managers;
|
||||
using Torch.Server.Managers;
|
||||
using VRage.Dedicated;
|
||||
using VRage.FileSystem;
|
||||
using VRage.Game;
|
||||
using VRage.Game.ModAPI;
|
||||
using VRage.Game.ObjectBuilder;
|
||||
using VRage.Game.SessionComponents;
|
||||
using VRage.Library;
|
||||
@@ -35,27 +40,35 @@ namespace Torch.Server
|
||||
public TimeSpan ElapsedPlayTime { get => _elapsedPlayTime; set { _elapsedPlayTime = value; OnPropertyChanged(); } }
|
||||
public Thread GameThread { get; private set; }
|
||||
public ServerState State { get => _state; private set { _state = value; OnPropertyChanged(); } }
|
||||
public bool IsRunning { get => _isRunning; set { _isRunning = value; OnPropertyChanged(); } }
|
||||
public InstanceManager DedicatedInstance { get; }
|
||||
/// <inheritdoc />
|
||||
public string InstanceName => Config?.InstanceName;
|
||||
/// <inheritdoc />
|
||||
public string InstancePath => Config?.InstancePath;
|
||||
|
||||
private bool _isRunning;
|
||||
private ServerState _state;
|
||||
private TimeSpan _elapsedPlayTime;
|
||||
private float _simRatio;
|
||||
private readonly AutoResetEvent _stopHandle = new AutoResetEvent(false);
|
||||
private Timer _watchdog;
|
||||
private Stopwatch _uptime;
|
||||
|
||||
public TorchServer(TorchConfig config = null)
|
||||
{
|
||||
DedicatedInstance = new InstanceManager(this);
|
||||
AddManager(DedicatedInstance);
|
||||
Config = config ?? new TorchConfig();
|
||||
MyFakes.ENABLE_INFINARIO = false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Init()
|
||||
{
|
||||
Log.Info($"Init server '{Config.InstanceName}' at '{Config.InstancePath}'");
|
||||
base.Init();
|
||||
|
||||
Log.Info($"Init server '{Config.InstanceName}' at '{Config.InstancePath}'");
|
||||
|
||||
MyFakes.ENABLE_INFINARIO = false;
|
||||
MyPerGameSettings.SendLogToKeen = false;
|
||||
MyPerServerSettings.GameName = MyPerGameSettings.GameName;
|
||||
MyPerServerSettings.GameNameSafe = MyPerGameSettings.GameNameSafe;
|
||||
@@ -64,43 +77,22 @@ namespace Torch.Server
|
||||
MySessionComponentExtDebug.ForceDisable = true;
|
||||
MyPerServerSettings.AppId = 244850;
|
||||
MyFinalBuildConstants.APP_VERSION = MyPerGameSettings.BasicGameInfo.GameVersion;
|
||||
|
||||
MyObjectBuilderSerializer.RegisterFromAssembly(typeof(MyObjectBuilder_CheckpointSerializer).Assembly);
|
||||
|
||||
InvokeBeforeRun();
|
||||
|
||||
//MyObjectBuilderSerializer.RegisterFromAssembly(typeof(MyObjectBuilder_CheckpointSerializer).Assembly);
|
||||
MyPlugins.RegisterGameAssemblyFile(MyPerGameSettings.GameModAssembly);
|
||||
MyPlugins.RegisterGameObjectBuildersAssemblyFile(MyPerGameSettings.GameModObjBuildersAssembly);
|
||||
MyPlugins.RegisterSandboxAssemblyFile(MyPerGameSettings.SandboxAssembly);
|
||||
MyPlugins.RegisterSandboxGameAssemblyFile(MyPerGameSettings.SandboxGameAssembly);
|
||||
MyPlugins.Load();
|
||||
MyGlobalTypeMetadata.Static.Init();
|
||||
RuntimeHelpers.RunClassConstructor(typeof(MyObjectBuilder_Base).TypeHandle);
|
||||
|
||||
GetManager<InstanceManager>().LoadInstance(Config.InstancePath);
|
||||
Plugins.LoadPlugins();
|
||||
}
|
||||
|
||||
public void InvokeBeforeRun()
|
||||
private void InvokeBeforeRun()
|
||||
{
|
||||
|
||||
var contentPath = "Content";
|
||||
|
||||
var privateContentPath = typeof(MyFileSystem).GetField("m_contentPath", BindingFlags.Static | BindingFlags.NonPublic)?.GetValue(null) as string;
|
||||
if (privateContentPath != null)
|
||||
Log.Debug("MyFileSystem already initialized");
|
||||
else
|
||||
{
|
||||
if (Program.IsManualInstall)
|
||||
{
|
||||
var rootPath = new FileInfo(MyFileSystem.ExePath).Directory.FullName;
|
||||
contentPath = Path.Combine(rootPath, "Content");
|
||||
}
|
||||
else
|
||||
{
|
||||
MyFileSystem.ExePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DedicatedServer64");
|
||||
}
|
||||
|
||||
MyFileSystem.Init(contentPath, InstancePath);
|
||||
}
|
||||
|
||||
MySandboxGame.Log.Init("SpaceEngineers-Dedicated.log", MyFinalBuildConstants.APP_VERSION_STRING);
|
||||
MySandboxGame.Log.WriteLine("Steam build: Always true");
|
||||
MySandboxGame.Log.WriteLine("Environment.ProcessorCount: " + MyEnvironment.ProcessorCount);
|
||||
@@ -129,16 +121,16 @@ namespace Torch.Server
|
||||
MySandboxGame.Config.Load();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start server on the current thread.
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public override void Start()
|
||||
{
|
||||
if (State != ServerState.Stopped)
|
||||
return;
|
||||
|
||||
DedicatedInstance.SaveConfig();
|
||||
_uptime = Stopwatch.StartNew();
|
||||
IsRunning = true;
|
||||
GameThread = Thread.CurrentThread;
|
||||
Config.Save();
|
||||
State = ServerState.Starting;
|
||||
Log.Info("Starting server.");
|
||||
|
||||
@@ -150,6 +142,8 @@ namespace Torch.Server
|
||||
VRage.Service.ExitListenerSTA.OnExit += delegate { MySandboxGame.Static?.Exit(); };
|
||||
|
||||
base.Start();
|
||||
//Stops RunInternal from calling MyFileSystem.InitUserSpecific(null), we call it in InstanceManager.
|
||||
MySandboxGame.IsReloading = true;
|
||||
runInternal.Invoke(null, null);
|
||||
|
||||
MySandboxGame.Log.Close();
|
||||
@@ -169,12 +163,13 @@ namespace Torch.Server
|
||||
{
|
||||
base.Update();
|
||||
SimulationRatio = Sync.ServerSimulationRatio;
|
||||
ElapsedPlayTime = MySession.Static?.ElapsedPlayTime ?? default(TimeSpan);
|
||||
var elapsed = TimeSpan.FromSeconds(Math.Floor(_uptime.Elapsed.TotalSeconds));
|
||||
ElapsedPlayTime = elapsed;
|
||||
|
||||
if (_watchdog == null)
|
||||
if (_watchdog == null && Config.TickTimeout > 0)
|
||||
{
|
||||
Log.Info("Starting server watchdog.");
|
||||
_watchdog = new Timer(CheckServerResponding, this, TimeSpan.Zero, TimeSpan.FromSeconds(30));
|
||||
_watchdog = new Timer(CheckServerResponding, this, TimeSpan.Zero, TimeSpan.FromSeconds(Config.TickTimeout));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,20 +177,18 @@ namespace Torch.Server
|
||||
{
|
||||
var mre = new ManualResetEvent(false);
|
||||
((TorchServer)state).Invoke(() => mre.Set());
|
||||
if (!mre.WaitOne(TimeSpan.FromSeconds(30)))
|
||||
if (!mre.WaitOne(TimeSpan.FromSeconds(Instance.Config.TickTimeout)))
|
||||
{
|
||||
var mainThread = MySandboxGame.Static.UpdateThread;
|
||||
mainThread.Suspend();
|
||||
var stackTrace = new StackTrace(mainThread, true);
|
||||
throw new TimeoutException($"Server watchdog detected that the server was frozen for at least 30 seconds.\n{stackTrace}");
|
||||
throw new TimeoutException($"Server watchdog detected that the server was frozen for at least {((TorchServer)state).Config.TickTimeout} seconds.\n{stackTrace}");
|
||||
}
|
||||
|
||||
Log.Debug("Server watchdog responded");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop the server.
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public override void Stop()
|
||||
{
|
||||
if (State == ServerState.Stopped)
|
||||
@@ -217,6 +210,54 @@ namespace Torch.Server
|
||||
Log.Info("Server stopped.");
|
||||
_stopHandle.Set();
|
||||
State = ServerState.Stopped;
|
||||
IsRunning = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restart the program. DOES NOT SAVE!
|
||||
/// </summary>
|
||||
public override void Restart()
|
||||
{
|
||||
var exe = Assembly.GetExecutingAssembly().Location;
|
||||
((TorchConfig)Config).WaitForPID = Process.GetCurrentProcess().Id.ToString();
|
||||
Process.Start(exe, Config.ToString());
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override Task Save(long callerId)
|
||||
{
|
||||
return SaveGameAsync(statusCode => SaveCompleted(statusCode, callerId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Callback for when save has finished.
|
||||
/// </summary>
|
||||
/// <param name="statusCode">Return code of the save operation</param>
|
||||
/// <param name="callerId">Caller of the save operation</param>
|
||||
private void SaveCompleted(SaveGameStatus statusCode, long callerId = 0)
|
||||
{
|
||||
switch (statusCode)
|
||||
{
|
||||
case SaveGameStatus.Success:
|
||||
Log.Info("Save completed.");
|
||||
Multiplayer.SendMessage("Saved game.", playerId: callerId);
|
||||
break;
|
||||
case SaveGameStatus.SaveInProgress:
|
||||
Log.Error("Save failed, a save is already in progress.");
|
||||
Multiplayer.SendMessage("Save failed, a save is already in progress.", playerId: callerId, font: MyFontEnum.Red);
|
||||
break;
|
||||
case SaveGameStatus.GameNotReady:
|
||||
Log.Error("Save failed, game was not ready.");
|
||||
Multiplayer.SendMessage("Save failed, game was not ready.", playerId: callerId, font: MyFontEnum.Red);
|
||||
break;
|
||||
case SaveGameStatus.TimedOut:
|
||||
Log.Error("Save failed, save timed out.");
|
||||
Multiplayer.SendMessage("Save failed, save timed out.", playerId: callerId, font: MyFontEnum.Red);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@ namespace Torch.Server.ViewModels
|
||||
{
|
||||
private static readonly Logger Log = LogManager.GetLogger("Config");
|
||||
private MyConfigDedicated<MyObjectBuilder_SessionSettings> _config;
|
||||
public MyConfigDedicated<MyObjectBuilder_SessionSettings> Model => _config;
|
||||
|
||||
public ConfigDedicatedViewModel() : this(new MyConfigDedicated<MyObjectBuilder_SessionSettings>(""))
|
||||
{
|
||||
@@ -54,9 +55,10 @@ namespace Torch.Server.ViewModels
|
||||
_config.Save(path);
|
||||
}
|
||||
|
||||
public SessionSettingsViewModel SessionSettings { get; }
|
||||
private SessionSettingsViewModel _sessionSettings;
|
||||
public SessionSettingsViewModel SessionSettings { get => _sessionSettings; set { _sessionSettings = value; OnPropertyChanged(); } }
|
||||
|
||||
public ObservableCollection<string> WorldPaths { get; } = new ObservableCollection<string>();
|
||||
public ObservableList<string> WorldPaths { get; } = new ObservableList<string>();
|
||||
private string _administrators;
|
||||
public string Administrators { get => _administrators; set { _administrators = value; OnPropertyChanged(); } }
|
||||
private string _banned;
|
||||
|
@@ -15,7 +15,7 @@ namespace Torch.Server.ViewModels.Blocks
|
||||
public class BlockViewModel : EntityViewModel
|
||||
{
|
||||
public IMyTerminalBlock Block { get; }
|
||||
public MTObservableCollection<PropertyViewModel> Properties { get; } = new MTObservableCollection<PropertyViewModel>();
|
||||
public ObservableList<PropertyViewModel> Properties { get; } = new ObservableList<PropertyViewModel>();
|
||||
|
||||
public string FullName => $"{Block.CubeGrid.CustomName} - {Block.CustomName}";
|
||||
|
||||
@@ -24,8 +24,11 @@ namespace Torch.Server.ViewModels.Blocks
|
||||
get => Block?.CustomName ?? "null";
|
||||
set
|
||||
{
|
||||
TorchBase.Instance.InvokeBlocking(() => Block.CustomName = value);
|
||||
OnPropertyChanged();
|
||||
TorchBase.Instance.Invoke(() =>
|
||||
{
|
||||
Block.CustomName = value;
|
||||
OnPropertyChanged();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,13 +40,22 @@ namespace Torch.Server.ViewModels.Blocks
|
||||
get => ((MySlimBlock)Block.SlimBlock).BuiltBy;
|
||||
set
|
||||
{
|
||||
TorchBase.Instance.InvokeBlocking(() => ((MySlimBlock)Block.SlimBlock).TransferAuthorship(value));
|
||||
OnPropertyChanged();
|
||||
TorchBase.Instance.Invoke(() =>
|
||||
{
|
||||
((MySlimBlock)Block.SlimBlock).TransferAuthorship(value);
|
||||
OnPropertyChanged();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanStop => false;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Delete()
|
||||
{
|
||||
Block.CubeGrid.RazeBlock(Block.Position);
|
||||
}
|
||||
|
||||
public BlockViewModel(IMyTerminalBlock block, EntityTreeViewModel tree) : base(block, tree)
|
||||
{
|
||||
Block = block;
|
||||
|
@@ -16,17 +16,15 @@ namespace Torch.Server.ViewModels.Blocks
|
||||
|
||||
public T Value
|
||||
{
|
||||
get
|
||||
{
|
||||
var val = default(T);
|
||||
TorchBase.Instance.InvokeBlocking(() => val = _prop.GetValue(Block.Block));
|
||||
return val;
|
||||
}
|
||||
get => _prop.GetValue(Block.Block);
|
||||
set
|
||||
{
|
||||
TorchBase.Instance.InvokeBlocking(() => _prop.SetValue(Block.Block, value));
|
||||
OnPropertyChanged();
|
||||
Block.RefreshModel();
|
||||
TorchBase.Instance.Invoke(() =>
|
||||
{
|
||||
_prop.SetValue(Block.Block, value);
|
||||
OnPropertyChanged();
|
||||
Block.RefreshModel();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -37,9 +37,15 @@ namespace Torch.Server.ViewModels.Entities
|
||||
|
||||
public virtual bool CanDelete => !(Entity is IMyCharacter);
|
||||
|
||||
public virtual void Delete()
|
||||
{
|
||||
Entity.Close();
|
||||
}
|
||||
|
||||
public EntityViewModel(IMyEntity entity, EntityTreeViewModel tree)
|
||||
{
|
||||
Entity = entity;
|
||||
Tree = tree;
|
||||
}
|
||||
|
||||
public EntityViewModel()
|
||||
|
@@ -1,5 +1,5 @@
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Sandbox.Game.Entities;
|
||||
using Sandbox.ModAPI;
|
||||
using Torch.Server.ViewModels.Blocks;
|
||||
@@ -9,17 +9,16 @@ namespace Torch.Server.ViewModels.Entities
|
||||
public class GridViewModel : EntityViewModel, ILazyLoad
|
||||
{
|
||||
private MyCubeGrid Grid => (MyCubeGrid)Entity;
|
||||
public MTObservableCollection<BlockViewModel> Blocks { get; } = new MTObservableCollection<BlockViewModel>();
|
||||
private static readonly Logger Log = LogManager.GetLogger(nameof(GridViewModel));
|
||||
public ObservableList<BlockViewModel> Blocks { get; } = new ObservableList<BlockViewModel>();
|
||||
|
||||
/// <inheritdoc />
|
||||
public string DescriptiveName => $"{Name} ({Grid.BlocksCount} blocks)";
|
||||
public string DescriptiveName { get; }
|
||||
|
||||
public GridViewModel() { }
|
||||
|
||||
public GridViewModel(MyCubeGrid grid, EntityTreeViewModel tree) : base(grid, tree)
|
||||
{
|
||||
Log.Debug($"Creating model {Grid.DisplayName}");
|
||||
DescriptiveName = $"{grid.DisplayName} ({grid.BlocksCount} blocks)";
|
||||
Blocks.Add(new BlockViewModel(null, Tree));
|
||||
}
|
||||
|
||||
@@ -28,7 +27,6 @@ namespace Torch.Server.ViewModels.Entities
|
||||
if (obj.FatBlock != null)
|
||||
Blocks.RemoveWhere(b => b.Block.EntityId == obj.FatBlock?.EntityId);
|
||||
|
||||
Blocks.Sort(b => b.Block.GetType().AssemblyQualifiedName);
|
||||
OnPropertyChanged(nameof(Name));
|
||||
}
|
||||
|
||||
@@ -36,9 +34,8 @@ namespace Torch.Server.ViewModels.Entities
|
||||
{
|
||||
var block = obj.FatBlock as IMyTerminalBlock;
|
||||
if (block != null)
|
||||
Blocks.Add(new BlockViewModel(block, Tree));
|
||||
Blocks.Insert(new BlockViewModel(block, Tree), b => b.Name);
|
||||
|
||||
Blocks.Sort(b => b.Block.GetType().AssemblyQualifiedName);
|
||||
OnPropertyChanged(nameof(Name));
|
||||
}
|
||||
|
||||
@@ -48,20 +45,23 @@ namespace Torch.Server.ViewModels.Entities
|
||||
if (_load)
|
||||
return;
|
||||
|
||||
Log.Debug($"Loading model {Grid.DisplayName}");
|
||||
_load = true;
|
||||
Blocks.Clear();
|
||||
TorchBase.Instance.InvokeBlocking(() =>
|
||||
TorchBase.Instance.Invoke(() =>
|
||||
{
|
||||
foreach (var block in Grid.GetFatBlocks().Where(b => b is IMyTerminalBlock))
|
||||
{
|
||||
Blocks.Add(new BlockViewModel((IMyTerminalBlock)block, Tree));
|
||||
}
|
||||
});
|
||||
Blocks.Sort(b => b.Block.GetType().AssemblyQualifiedName);
|
||||
|
||||
Grid.OnBlockAdded += Grid_OnBlockAdded;
|
||||
Grid.OnBlockRemoved += Grid_OnBlockRemoved;
|
||||
Grid.OnBlockAdded += Grid_OnBlockAdded;
|
||||
Grid.OnBlockRemoved += Grid_OnBlockRemoved;
|
||||
|
||||
Tree.ControlDispatcher.BeginInvoke(() =>
|
||||
{
|
||||
Blocks.Sort(b => b.Block.CustomName);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ namespace Torch.Server.ViewModels.Entities
|
||||
|
||||
public override bool CanStop => false;
|
||||
|
||||
public MTObservableCollection<GridViewModel> AttachedGrids { get; } = new MTObservableCollection<GridViewModel>();
|
||||
public ObservableList<GridViewModel> AttachedGrids { get; } = new ObservableList<GridViewModel>();
|
||||
|
||||
public async Task UpdateAttachedGrids()
|
||||
{
|
||||
|
@@ -3,22 +3,28 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
using Sandbox.Game.Entities;
|
||||
using Sandbox.Game.Entities.Character;
|
||||
using Torch.Server.ViewModels.Entities;
|
||||
using VRage.Game.ModAPI;
|
||||
using VRage.ModAPI;
|
||||
using System.Windows.Threading;
|
||||
using NLog;
|
||||
|
||||
namespace Torch.Server.ViewModels
|
||||
{
|
||||
public class EntityTreeViewModel : ViewModel
|
||||
{
|
||||
public MTObservableCollection<GridViewModel> Grids { get; set; } = new MTObservableCollection<GridViewModel>();
|
||||
public MTObservableCollection<CharacterViewModel> Characters { get; set; } = new MTObservableCollection<CharacterViewModel>();
|
||||
public MTObservableCollection<EntityViewModel> FloatingObjects { get; set; } = new MTObservableCollection<EntityViewModel>();
|
||||
public MTObservableCollection<VoxelMapViewModel> VoxelMaps { get; set; } = new MTObservableCollection<VoxelMapViewModel>();
|
||||
//TODO: these should be sorted sets for speed
|
||||
public ObservableList<GridViewModel> Grids { get; set; } = new ObservableList<GridViewModel>();
|
||||
public ObservableList<CharacterViewModel> Characters { get; set; } = new ObservableList<CharacterViewModel>();
|
||||
public ObservableList<EntityViewModel> FloatingObjects { get; set; } = new ObservableList<EntityViewModel>();
|
||||
public ObservableList<VoxelMapViewModel> VoxelMaps { get; set; } = new ObservableList<VoxelMapViewModel>();
|
||||
public Dispatcher ControlDispatcher => _control.Dispatcher;
|
||||
|
||||
private EntityViewModel _currentEntity;
|
||||
private UserControl _control;
|
||||
|
||||
public EntityViewModel CurrentEntity
|
||||
{
|
||||
@@ -26,7 +32,12 @@ namespace Torch.Server.ViewModels
|
||||
set { _currentEntity = value; OnPropertyChanged(); }
|
||||
}
|
||||
|
||||
public EntityTreeViewModel()
|
||||
public EntityTreeViewModel(UserControl control)
|
||||
{
|
||||
_control = control;
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
MyEntities.OnEntityAdd += MyEntities_OnEntityAdd;
|
||||
MyEntities.OnEntityRemove += MyEntities_OnEntityRemove;
|
||||
@@ -56,20 +67,16 @@ namespace Torch.Server.ViewModels
|
||||
switch (obj)
|
||||
{
|
||||
case MyCubeGrid grid:
|
||||
if (Grids.All(g => g.Entity.EntityId != obj.EntityId))
|
||||
Grids.Add(new GridViewModel(grid, this));
|
||||
Grids.Insert(new GridViewModel(grid, this), g => g.Name);
|
||||
break;
|
||||
case MyCharacter character:
|
||||
if (Characters.All(g => g.Entity.EntityId != obj.EntityId))
|
||||
Characters.Add(new CharacterViewModel(character, this));
|
||||
Characters.Insert(new CharacterViewModel(character, this), c => c.Name);
|
||||
break;
|
||||
case MyFloatingObject floating:
|
||||
if (FloatingObjects.All(g => g.Entity.EntityId != obj.EntityId))
|
||||
FloatingObjects.Add(new FloatingObjectViewModel(floating, this));
|
||||
FloatingObjects.Insert(new FloatingObjectViewModel(floating, this), f => f.Name);
|
||||
break;
|
||||
case MyVoxelBase voxel:
|
||||
if (VoxelMaps.All(g => g.Entity.EntityId != obj.EntityId))
|
||||
VoxelMaps.Add(new VoxelMapViewModel(voxel, this));
|
||||
VoxelMaps.Insert(new VoxelMapViewModel(voxel, this), v => v.Name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ namespace Torch.Server.ViewModels
|
||||
{
|
||||
public class PluginManagerViewModel : ViewModel
|
||||
{
|
||||
public MTObservableCollection<PluginViewModel> Plugins { get; } = new MTObservableCollection<PluginViewModel>();
|
||||
public ObservableList<PluginViewModel> Plugins { get; } = new ObservableList<PluginViewModel>();
|
||||
|
||||
private PluginViewModel _selectedPlugin;
|
||||
public PluginViewModel SelectedPlugin
|
||||
@@ -24,10 +24,12 @@ namespace Torch.Server.ViewModels
|
||||
|
||||
public PluginManagerViewModel(IPluginManager pluginManager)
|
||||
{
|
||||
foreach (var plugin in pluginManager)
|
||||
Plugins.Add(new PluginViewModel(plugin));
|
||||
pluginManager.PluginsLoaded += PluginManager_PluginsLoaded;
|
||||
}
|
||||
|
||||
private void PluginManager_PluginsLoaded(List<ITorchPlugin> obj)
|
||||
private void PluginManager_PluginsLoaded(IList<ITorchPlugin> obj)
|
||||
{
|
||||
Plugins.Clear();
|
||||
foreach (var plugin in obj)
|
||||
|
@@ -35,7 +35,7 @@ namespace Torch.Server.ViewModels
|
||||
BlockLimits.Add(new BlockLimitViewModel(this, limit.Key, limit.Value));
|
||||
}
|
||||
|
||||
public MTObservableCollection<BlockLimitViewModel> BlockLimits { get; } = new MTObservableCollection<BlockLimitViewModel>();
|
||||
public ObservableList<BlockLimitViewModel> BlockLimits { get; } = new ObservableList<BlockLimitViewModel>();
|
||||
|
||||
#region Multipliers
|
||||
|
||||
@@ -74,6 +74,12 @@ namespace Torch.Server.ViewModels
|
||||
{
|
||||
get => _settings.HackSpeedMultiplier; set { _settings.HackSpeedMultiplier = value; OnPropertyChanged(); }
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="MyObjectBuilder_SessionSettings.WelderSpeedMultiplier"/>
|
||||
public float WelderSpeedMultiplier
|
||||
{
|
||||
get => _settings.WelderSpeedMultiplier; set { _settings.WelderSpeedMultiplier = value; OnPropertyChanged(); }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region NPCs
|
||||
|
@@ -5,12 +5,13 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Torch.Server"
|
||||
mc:Ignorable="d">
|
||||
<DockPanel>
|
||||
<DockPanel DockPanel.Dock="Bottom">
|
||||
<Button x:Name="Send" Content="Send" DockPanel.Dock="Right" Width="50" Margin="5,5,5,5" Click="SendButton_Click"></Button>
|
||||
<TextBox x:Name="Message" DockPanel.Dock="Left" Margin="5,5,5,5" KeyDown="Message_OnKeyDown"></TextBox>
|
||||
</DockPanel>
|
||||
<ListView x:Name="ChatItems" ItemsSource="{Binding ChatHistory}" Margin="5,5,5,5">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<ListView Grid.Row="0" x:Name="ChatItems" ItemsSource="{Binding ChatHistory}" Margin="5,5,5,5">
|
||||
<ScrollViewer HorizontalScrollBarVisibility="Disabled"/>
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<WrapPanel>
|
||||
@@ -23,5 +24,13 @@
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</DockPanel>
|
||||
<Grid Grid.Row="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Button Grid.Column="1" x:Name="Send" Content="Send" DockPanel.Dock="Right" Width="50" Margin="5,5,5,5" Click="SendButton_Click"></Button>
|
||||
<TextBox Grid.Column="0" x:Name="Message" DockPanel.Dock="Left" Margin="5,5,5,5" KeyDown="Message_OnKeyDown"></TextBox>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -40,7 +41,23 @@ namespace Torch.Server
|
||||
{
|
||||
_server = (TorchBase)server;
|
||||
_multiplayer = (MultiplayerManager)server.Multiplayer;
|
||||
ChatItems.Items.Clear();
|
||||
DataContext = _multiplayer;
|
||||
if (_multiplayer.ChatHistory is INotifyCollectionChanged ncc)
|
||||
ncc.CollectionChanged += ChatHistory_CollectionChanged;
|
||||
}
|
||||
|
||||
private void ChatHistory_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
ChatItems.ScrollToItem(ChatItems.Items.Count - 1);
|
||||
/*
|
||||
if (VisualTreeHelper.GetChildrenCount(ChatItems) > 0)
|
||||
{
|
||||
|
||||
Border border = (Border)VisualTreeHelper.GetChild(ChatItems, 0);
|
||||
ScrollViewer scrollViewer = (ScrollViewer)VisualTreeHelper.GetChild(border, 0);
|
||||
scrollViewer.ScrollToBottom();
|
||||
}*/
|
||||
}
|
||||
|
||||
private void SendButton_Click(object sender, RoutedEventArgs e)
|
||||
@@ -62,22 +79,26 @@ namespace Torch.Server
|
||||
return;
|
||||
|
||||
var commands = _server.Commands;
|
||||
string response = null;
|
||||
if (commands.IsCommand(text))
|
||||
{
|
||||
_multiplayer.ChatHistory.Add(new ChatMessage(DateTime.Now, 0, "Server", text));
|
||||
_server.InvokeBlocking(() =>
|
||||
_server.Invoke(() =>
|
||||
{
|
||||
response = commands.HandleCommandFromServer(text);
|
||||
var response = commands.HandleCommandFromServer(text);
|
||||
Dispatcher.BeginInvoke(() => OnMessageEntered_Callback(response));
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
_server.Multiplayer.SendMessage(text);
|
||||
}
|
||||
Message.Text = "";
|
||||
}
|
||||
|
||||
private void OnMessageEntered_Callback(string response)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(response))
|
||||
_multiplayer.ChatHistory.Add(new ChatMessage(DateTime.Now, 0, "Server", response));
|
||||
Message.Text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -10,15 +10,27 @@
|
||||
<UserControl.DataContext>
|
||||
<viewModels:ConfigDedicatedViewModel />
|
||||
</UserControl.DataContext>
|
||||
<DockPanel>
|
||||
<DockPanel DockPanel.Dock="Top">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<DockPanel Grid.Row="0">
|
||||
<Label Content="World:" DockPanel.Dock="Left" />
|
||||
<Button Content="New World" Margin="3" DockPanel.Dock="Right" Click="NewWorld_OnClick"/>
|
||||
<ComboBox Text="{Binding LoadWorld}" ItemsSource="{Binding WorldPaths}" IsEditable="True" Margin="3" SelectionChanged="Selector_OnSelectionChanged"/>
|
||||
</DockPanel>
|
||||
<DockPanel DockPanel.Dock="Bottom">
|
||||
<StackPanel DockPanel.Dock="Left">
|
||||
<ScrollViewer IsEnabled="True">
|
||||
<Grid Grid.Row="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid Grid.Column="0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<ScrollViewer Grid.Row="0" Margin="3">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<StackPanel Margin="3" DockPanel.Dock="Left">
|
||||
<Label Content="Server Name" />
|
||||
@@ -37,24 +49,6 @@
|
||||
<CheckBox IsChecked="{Binding PauseGameWhenEmpty}" Content="Pause When Empty" Margin="3" />
|
||||
</StackPanel>
|
||||
<StackPanel Margin="3">
|
||||
<!--
|
||||
<ListBox ItemsSource="{Binding Banned}" Width="130" Margin="3,0,3,3" Height="100"
|
||||
MouseDoubleClick="Banned_OnMouseDoubleClick" /> -->
|
||||
<!--
|
||||
<ListBox ItemsSource="{Binding Administrators}" Width="130" Margin="3,0,3,3" Height="100"
|
||||
MouseDoubleClick="Administrators_OnMouseDoubleClick">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox Text="{Binding SteamId}" Width="100"/>
|
||||
<Label Content="{Binding Name}"/>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox> -->
|
||||
<!--
|
||||
<ListBox ItemsSource="{Binding Mods}" Width="130" Margin="3,0,3,3" Height="100"
|
||||
MouseDoubleClick="Mods_OnMouseDoubleClick" /> -->
|
||||
<Label Content="Mods" />
|
||||
<TextBox Text="{Binding Mods}" Margin="3" Height="100" AcceptsReturn="true" VerticalScrollBarVisibility="Auto"/>
|
||||
<Label Content="Administrators" />
|
||||
@@ -64,23 +58,23 @@
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
<Button Content="Save Config" Margin="3" Click="Save_OnClick" />
|
||||
</StackPanel>
|
||||
<ScrollViewer Margin="3" DockPanel.Dock="Right" IsEnabled="True">
|
||||
<Button Grid.Row="1" Content="Save Config" Margin="3" Click="Save_OnClick" />
|
||||
</Grid>
|
||||
<ScrollViewer Grid.Column="1" Margin="3">
|
||||
<StackPanel DataContext="{Binding SessionSettings}">
|
||||
<Expander Header="Block Limits">
|
||||
<StackPanel Margin="10,0,0,0">
|
||||
<DockPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox Text="{Binding MaxBlocksPerPlayer}" Margin="3" Width="70" />
|
||||
<Label Content="Max Blocks Per Player" />
|
||||
</DockPanel>
|
||||
<DockPanel>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox Text="{Binding MaxGridSize}" Margin="3" Width="70" />
|
||||
<Label Content="Max Grid Size" />
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
<Button Content="Add" Margin="3" Click="AddLimit_OnClick" />
|
||||
<ListView ItemsSource="{Binding BlockLimits}" Margin="3">
|
||||
<ListBox.ItemTemplate>
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox Text="{Binding BlockType}" Width="150" Margin="3" />
|
||||
@@ -88,36 +82,40 @@
|
||||
<Button Content=" X " Margin="3" Click="RemoveLimit_OnClick" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</StackPanel>
|
||||
</Expander>
|
||||
<Expander Header="Multipliers">
|
||||
<StackPanel Margin="10,0,0,0">
|
||||
<DockPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox Text="{Binding InventorySizeMultiplier}" Margin="3" Width="70" />
|
||||
<Label Content="Inventory Size" />
|
||||
</DockPanel>
|
||||
<DockPanel>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox Text="{Binding RefinerySpeedMultiplier}" Margin="3" Width="70" />
|
||||
<Label Content="Refinery Speed" />
|
||||
</DockPanel>
|
||||
<DockPanel>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox Text="{Binding AssemblerEfficiencyMultiplier}" Margin="3" Width="70" />
|
||||
<Label Content="Assembler Efficiency" />
|
||||
</DockPanel>
|
||||
<DockPanel>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox Text="{Binding AssemblerSpeedMultiplier}" Margin="3" Width="70" />
|
||||
<Label Content="Assembler Speed" />
|
||||
</DockPanel>
|
||||
<DockPanel>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox Text="{Binding WelderSpeedMultiplier}" Margin="3" Width="70" />
|
||||
<Label Content="Welder Speed" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox Text="{Binding GrinderSpeedMultiplier}" Margin="3" Width="70" />
|
||||
<Label Content="Grinder Speed" />
|
||||
</DockPanel>
|
||||
<DockPanel>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox Text="{Binding HackSpeedMultiplier}" Margin="3" Width="70" />
|
||||
<Label Content="Hacking Speed" />
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Expander>
|
||||
<Expander Header="NPCs">
|
||||
@@ -131,14 +129,14 @@
|
||||
</Expander>
|
||||
<Expander Header="Environment">
|
||||
<StackPanel Margin="10,0,0,0">
|
||||
<DockPanel ToolTip="Increases physics precision at the cost of performance.">
|
||||
<StackPanel Orientation="Horizontal" ToolTip="Increases physics precision at the cost of performance.">
|
||||
<TextBox Text="{Binding PhysicsIterations}" Margin="3" Width="70" />
|
||||
<Label Content="Physics Iterations" />
|
||||
</DockPanel>
|
||||
<DockPanel>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox Text="{Binding MaxFloatingObjects}" Margin="3" Width="70" />
|
||||
<Label Content="Max Floating Objects" />
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
<CheckBox IsChecked="{Binding EnableRealisticSound}" Content="Enable Realistic Sound"
|
||||
Margin="3" />
|
||||
<CheckBox IsChecked="{Binding EnableAirtightness}" Content="Enable Airtightness" Margin="3" />
|
||||
@@ -149,41 +147,41 @@
|
||||
<CheckBox IsChecked="{Binding EnableVoxelDestruction}" Content="Enable Voxel Destruction"
|
||||
Margin="3" />
|
||||
<CheckBox IsChecked="{Binding EnableSunRotation}" Content="Enable Sun Rotation" Margin="3" />
|
||||
<DockPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox Text="{Binding SunRotationInterval}" Margin="3" Width="70" />
|
||||
<Label Content="Sun Rotation Interval (mins)" />
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
<CheckBox IsChecked="{Binding EnableFlora}" Content="Enable Flora" Margin="3" />
|
||||
<DockPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox Text="{Binding FloraDensity}" Margin="3" Width="70" />
|
||||
<Label Content="Flora Density" />
|
||||
</DockPanel>
|
||||
<DockPanel>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox Text="{Binding FloraDensityMultiplier}" Margin="3" Width="70" />
|
||||
<Label Content="Flora Density Multiplier" />
|
||||
</DockPanel>
|
||||
<DockPanel>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox Text="{Binding ViewDistance}" Margin="3" Width="70" />
|
||||
<Label Content="View Distance (meters)" />
|
||||
</DockPanel>
|
||||
<DockPanel>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox Text="{Binding WorldSize}" Margin="3" Width="70" />
|
||||
<Label Content="World Size (km)" />
|
||||
</DockPanel>
|
||||
<DockPanel>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<ComboBox SelectedItem="{Binding EnvironmentHostility}"
|
||||
ItemsSource="{Binding EnvironmentHostilityValues}" Margin="3" Width="100"
|
||||
DockPanel.Dock="Left" />
|
||||
<Label Content="Environment Hostility" />
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Expander>
|
||||
<Expander Header="Players">
|
||||
<StackPanel Margin="10,0,0,0">
|
||||
<DockPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox Text="{Binding MaxPlayers}" Margin="3" Width="70" />
|
||||
<Label Content="Max Players" />
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
<CheckBox IsChecked="{Binding EnableThirdPerson}" Content="Enable 3rd Person Camera"
|
||||
Margin="3" />
|
||||
<CheckBox IsChecked="{Binding EnableJetpack}" Content="Enable Jetpack" Margin="3" />
|
||||
@@ -191,20 +189,20 @@
|
||||
<CheckBox IsChecked="{Binding EnableCopyPaste}" Content="Enable Copy/Paste" Margin="3" />
|
||||
<CheckBox IsChecked="{Binding ShowPlayerNamesOnHud}" Content="Show Player Names on HUD"
|
||||
Margin="3" />
|
||||
<DockPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox Text="{Binding SpawnTimeMultiplier}" Margin="3" Width="70" />
|
||||
<Label Content="Respawn Time Multiplier" />
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
<CheckBox IsChecked="{Binding ResetOwnership}" Content="Reset Ownership" Margin="3" />
|
||||
<CheckBox IsChecked="{Binding SpawnWithTools}" Content="Spawn With Tools" Margin="3" />
|
||||
</StackPanel>
|
||||
</Expander>
|
||||
<Expander Header="Miscellaneous">
|
||||
<StackPanel Margin="10,0,0,0">
|
||||
<DockPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox Text="{Binding AutosaveInterval}" Margin="3" Width="70" />
|
||||
<Label Content="Autosave Interval (minutes)" />
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
<CheckBox IsChecked="{Binding EnableConvertToStation}" Content="Enable Convert to Station"
|
||||
Margin="3" />
|
||||
|
||||
@@ -223,19 +221,19 @@
|
||||
<CheckBox IsChecked="{Binding EnableWeapons}" Content="Enable Weapons" Margin="3" />
|
||||
<CheckBox IsChecked="{Binding EnableIngameScripts}" Content="Enable Ingame Scripts"
|
||||
Margin="3" />
|
||||
<DockPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<ComboBox SelectedItem="{Binding GameMode}" ItemsSource="{Binding GameModeValues}"
|
||||
Margin="3" Width="100" DockPanel.Dock="Left" />
|
||||
<Label Content="Game Mode" />
|
||||
</DockPanel>
|
||||
<DockPanel>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox Text="{Binding MaxBackupSaves}" Margin="3" Width="70" />
|
||||
<Label Content="Max Backup Saves" />
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Expander>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</DockPanel>
|
||||
</DockPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
@@ -1,33 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using System.Xml.Serialization;
|
||||
using NLog;
|
||||
using Sandbox;
|
||||
using Sandbox.Engine.Networking;
|
||||
using Sandbox.Engine.Utils;
|
||||
using Torch.Server.Managers;
|
||||
using Torch.Server.ViewModels;
|
||||
using Torch.Views;
|
||||
using VRage;
|
||||
using VRage.Dedicated;
|
||||
using VRage.Game;
|
||||
using VRage.ObjectBuilders;
|
||||
using Path = System.IO.Path;
|
||||
|
||||
namespace Torch.Server.Views
|
||||
{
|
||||
@@ -36,110 +10,29 @@ namespace Torch.Server.Views
|
||||
/// </summary>
|
||||
public partial class ConfigControl : UserControl
|
||||
{
|
||||
private readonly Logger Log = LogManager.GetLogger("Config");
|
||||
public MyConfigDedicated<MyObjectBuilder_SessionSettings> Config { get; set; }
|
||||
private ConfigDedicatedViewModel _viewModel;
|
||||
private string _configPath;
|
||||
private TorchConfig _torchConfig;
|
||||
private InstanceManager _instanceManager;
|
||||
|
||||
public ConfigControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void SaveConfig()
|
||||
{
|
||||
_viewModel.Save(_configPath);
|
||||
Log.Info("Saved DS config.");
|
||||
try
|
||||
{
|
||||
//var checkpoint = MyLocalCache.LoadCheckpoint(Config.LoadWorld, out _);
|
||||
MyObjectBuilderSerializer.DeserializeXML(Path.Combine(Config.LoadWorld, "Sandbox.sbc"), out MyObjectBuilder_Checkpoint checkpoint, out ulong sizeInBytes);
|
||||
if (checkpoint == null)
|
||||
{
|
||||
Log.Error($"Failed to load {Config.LoadWorld}, checkpoint null ({sizeInBytes} bytes, instance {TorchBase.Instance.Config.InstancePath})");
|
||||
return;
|
||||
}
|
||||
checkpoint.Settings = Config.SessionSettings;
|
||||
checkpoint.Mods.Clear();
|
||||
foreach (var modId in Config.Mods)
|
||||
checkpoint.Mods.Add(new MyObjectBuilder_Checkpoint.ModItem(modId));
|
||||
|
||||
MyLocalCache.SaveCheckpoint(checkpoint, Config.LoadWorld);
|
||||
Log.Info("Saved world config.");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error("Failed to write sandbox config, changes will not appear on server");
|
||||
Log.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadDedicatedConfig(TorchConfig torchConfig)
|
||||
{
|
||||
_torchConfig = torchConfig;
|
||||
DataContext = null;
|
||||
MySandboxGame.Config = new MyConfig(MyPerServerSettings.GameNameSafe + ".cfg");
|
||||
var path = Path.Combine(torchConfig.InstancePath, "SpaceEngineers-Dedicated.cfg");
|
||||
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
Log.Error($"Failed to load dedicated config at {path}");
|
||||
DataContext = null;
|
||||
return;
|
||||
}
|
||||
|
||||
Config = new MyConfigDedicated<MyObjectBuilder_SessionSettings>(path);
|
||||
Config.Load(path);
|
||||
_configPath = path;
|
||||
|
||||
_viewModel = new ConfigDedicatedViewModel(Config);
|
||||
var worldFolders = Directory.EnumerateDirectories(Path.Combine(torchConfig.InstancePath, "Saves"));
|
||||
|
||||
foreach (var f in worldFolders)
|
||||
_viewModel.WorldPaths.Add(f);
|
||||
|
||||
LoadWorldMods();
|
||||
DataContext = _viewModel;
|
||||
}
|
||||
|
||||
private void LoadWorldMods()
|
||||
{
|
||||
var sandboxPath = Path.Combine(Config.LoadWorld, "Sandbox.sbc");
|
||||
|
||||
if (!File.Exists(sandboxPath))
|
||||
return;
|
||||
|
||||
MyObjectBuilderSerializer.DeserializeXML(sandboxPath, out MyObjectBuilder_Checkpoint checkpoint, out ulong sizeInBytes);
|
||||
if (checkpoint == null)
|
||||
{
|
||||
Log.Error($"Failed to load {Config.LoadWorld}, checkpoint null ({sizeInBytes} bytes, instance {TorchBase.Instance.Config.InstancePath})");
|
||||
return;
|
||||
}
|
||||
|
||||
var sb = new StringBuilder();
|
||||
foreach (var mod in checkpoint.Mods)
|
||||
sb.AppendLine(mod.PublishedFileId.ToString());
|
||||
|
||||
_viewModel.Mods = sb.ToString();
|
||||
|
||||
Log.Info("Loaded mod list from world");
|
||||
_instanceManager = TorchBase.Instance.GetManager<InstanceManager>();
|
||||
DataContext = _instanceManager.DedicatedConfig;
|
||||
}
|
||||
|
||||
private void Save_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SaveConfig();
|
||||
_instanceManager.SaveConfig();
|
||||
}
|
||||
|
||||
private void RemoveLimit_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var vm = (BlockLimitViewModel)((Button)sender).DataContext;
|
||||
_viewModel.SessionSettings.BlockLimits.Remove(vm);
|
||||
_instanceManager.DedicatedConfig.SessionSettings.BlockLimits.Remove(vm);
|
||||
}
|
||||
|
||||
private void AddLimit_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_viewModel.SessionSettings.BlockLimits.Add(new BlockLimitViewModel(_viewModel.SessionSettings, "", 0));
|
||||
_instanceManager.DedicatedConfig.SessionSettings.BlockLimits.Add(new BlockLimitViewModel(_instanceManager.DedicatedConfig.SessionSettings, "", 0));
|
||||
}
|
||||
|
||||
private void NewWorld_OnClick(object sender, RoutedEventArgs e)
|
||||
@@ -152,8 +45,7 @@ namespace Torch.Server.Views
|
||||
//The control doesn't update the binding before firing the event.
|
||||
if (e.AddedItems.Count > 0)
|
||||
{
|
||||
Config.LoadWorld = (string)e.AddedItems[0];
|
||||
LoadWorldMods();
|
||||
_instanceManager.SelectWorld((string)e.AddedItems[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,8 +9,12 @@
|
||||
<UserControl.DataContext>
|
||||
<blocks:BlockViewModel />
|
||||
</UserControl.DataContext>
|
||||
<DockPanel x:Name="Stack" Margin="3">
|
||||
<StackPanel DockPanel.Dock="Top">
|
||||
<Grid Margin="3">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Grid.Row="0">
|
||||
<Label Content="{Binding FullName}" FontSize="16" />
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Label Content="Built By: "/>
|
||||
@@ -18,7 +22,7 @@
|
||||
</StackPanel>
|
||||
<Label Content="Properties"/>
|
||||
</StackPanel>
|
||||
<ListView ItemsSource="{Binding Properties}" Margin="3" IsEnabled="True" DockPanel.Dock="Bottom">
|
||||
<ListView Grid.Row="1" ItemsSource="{Binding Properties}" Margin="3" IsEnabled="True">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<local:PropertyView />
|
||||
@@ -35,5 +39,5 @@
|
||||
</Style>
|
||||
</ListView.ItemContainerStyle>
|
||||
</ListView>
|
||||
</DockPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
@@ -10,13 +10,17 @@
|
||||
<UserControl.Resources>
|
||||
<converters:StringIdConverter x:Key="StringIdConverter"/>
|
||||
</UserControl.Resources>
|
||||
<DockPanel x:Name="Dock">
|
||||
<Label x:Name="Label" Width="150" VerticalAlignment="Center" DockPanel.Dock="Left">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="0" x:Name="Label" Width="150" VerticalAlignment="Center">
|
||||
<Label.Content>
|
||||
<TextBlock Text="{Binding Name, StringFormat={}{0}: }" />
|
||||
</Label.Content>
|
||||
</Label>
|
||||
<Frame x:Name="Frame" DockPanel.Dock="Right" NavigationUIVisibility="Hidden"/>
|
||||
</DockPanel>
|
||||
<Frame Grid.Column="1" x:Name="Frame" NavigationUIVisibility="Hidden"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
|
@@ -32,10 +32,10 @@ namespace Torch.Server.Views.Blocks
|
||||
{
|
||||
switch (args.NewValue)
|
||||
{
|
||||
case PropertyViewModel<bool> vmBool:
|
||||
case PropertyViewModel<bool> _:
|
||||
InitBool();
|
||||
break;
|
||||
case PropertyViewModel<StringBuilder> vmSb:
|
||||
case PropertyViewModel<StringBuilder> _:
|
||||
InitStringBuilder();
|
||||
break;
|
||||
default:
|
||||
|
@@ -8,17 +8,17 @@
|
||||
xmlns:entities="clr-namespace:Torch.Server.ViewModels.Entities"
|
||||
xmlns:blocks="clr-namespace:Torch.Server.ViewModels.Blocks"
|
||||
mc:Ignorable="d">
|
||||
<UserControl.DataContext>
|
||||
<viewModels:EntityTreeViewModel />
|
||||
</UserControl.DataContext>
|
||||
<DockPanel>
|
||||
<DockPanel DockPanel.Dock="Left">
|
||||
<StackPanel DockPanel.Dock="Bottom">
|
||||
<Button Content="Delete" Click="Delete_OnClick" IsEnabled="{Binding CurrentEntity.CanDelete}"
|
||||
Margin="3" />
|
||||
<Button Content="Stop" Click="Stop_OnClick" IsEnabled="{Binding CurrentEntity.CanStop}" Margin="3" />
|
||||
</StackPanel>
|
||||
<TreeView Width="300" Margin="3" DockPanel.Dock="Top" SelectedItemChanged="TreeView_OnSelectedItemChanged" TreeViewItem.Expanded="TreeViewItem_OnExpanded">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition MinWidth="300" Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid Grid.Column="0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<TreeView Grid.Row="0" Margin="3" DockPanel.Dock="Top" SelectedItemChanged="TreeView_OnSelectedItemChanged" TreeViewItem.Expanded="TreeViewItem_OnExpanded">
|
||||
<TreeView.Resources>
|
||||
<HierarchicalDataTemplate DataType="{x:Type entities:GridViewModel}" ItemsSource="{Binding Blocks}">
|
||||
<TextBlock Text="{Binding DescriptiveName}" />
|
||||
@@ -66,7 +66,12 @@
|
||||
</TreeViewItem.ItemTemplate>
|
||||
</TreeViewItem>
|
||||
</TreeView>
|
||||
</DockPanel>
|
||||
<Frame x:Name="EditorFrame" Margin="3" NavigationUIVisibility="Hidden" />
|
||||
</DockPanel>
|
||||
<StackPanel Grid.Row="1" DockPanel.Dock="Bottom">
|
||||
<Button Content="Delete" Click="Delete_OnClick" IsEnabled="{Binding CurrentEntity.CanDelete}"
|
||||
Margin="3" />
|
||||
<Button Content="Stop" Click="Stop_OnClick" IsEnabled="{Binding CurrentEntity.CanStop}" Margin="3" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<Frame Grid.Column="1" x:Name="EditorFrame" Margin="3" NavigationUIVisibility="Hidden" />
|
||||
</Grid>
|
||||
</UserControl>
|
@@ -27,12 +27,14 @@ namespace Torch.Server.Views
|
||||
/// </summary>
|
||||
public partial class EntitiesControl : UserControl
|
||||
{
|
||||
public EntityTreeViewModel Entities { get; set; } = new EntityTreeViewModel();
|
||||
public EntityTreeViewModel Entities { get; set; }
|
||||
|
||||
public EntitiesControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
Entities = new EntityTreeViewModel(this);
|
||||
DataContext = Entities;
|
||||
Entities.Init();
|
||||
}
|
||||
|
||||
private void TreeView_OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
|
||||
@@ -41,7 +43,7 @@ namespace Torch.Server.Views
|
||||
{
|
||||
Entities.CurrentEntity = vm;
|
||||
if (e.NewValue is GridViewModel gvm)
|
||||
EditorFrame.Content = new Entities.GridView { DataContext = gvm};
|
||||
EditorFrame.Content = new Entities.GridView {DataContext = gvm};
|
||||
if (e.NewValue is BlockViewModel bvm)
|
||||
EditorFrame.Content = new BlockView {DataContext = bvm};
|
||||
if (e.NewValue is VoxelMapViewModel vvm)
|
||||
@@ -58,7 +60,7 @@ namespace Torch.Server.Views
|
||||
{
|
||||
if (Entities.CurrentEntity?.Entity is IMyCharacter)
|
||||
return;
|
||||
TorchBase.Instance.Invoke(() => Entities.CurrentEntity?.Entity.Close());
|
||||
TorchBase.Instance.Invoke(() => Entities.CurrentEntity?.Delete());
|
||||
}
|
||||
|
||||
private void Stop_OnClick(object sender, RoutedEventArgs e)
|
||||
|
@@ -14,9 +14,9 @@
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<WrapPanel>
|
||||
<TextBlock Text="{Binding Name}" FontWeight="Bold"/>
|
||||
<TextBlock Text="{Binding Value.Name}" FontWeight="Bold"/>
|
||||
<TextBlock Text=" ("/>
|
||||
<TextBlock Text="{Binding State}"/>
|
||||
<TextBlock Text="{Binding Value.State}"/>
|
||||
<TextBlock Text=")"/>
|
||||
</WrapPanel>
|
||||
</DataTemplate>
|
||||
|
@@ -21,6 +21,7 @@ using Sandbox.ModAPI;
|
||||
using SteamSDK;
|
||||
using Torch.API;
|
||||
using Torch.Managers;
|
||||
using Torch.ViewModels;
|
||||
using VRage.Game.ModAPI;
|
||||
|
||||
namespace Torch.Server
|
||||
@@ -45,20 +46,14 @@ namespace Torch.Server
|
||||
|
||||
private void KickButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var player = PlayerList.SelectedItem as IMyPlayer;
|
||||
if (player != null)
|
||||
{
|
||||
_server.Multiplayer.KickPlayer(player.SteamUserId);
|
||||
}
|
||||
var player = (KeyValuePair<ulong, PlayerViewModel>)PlayerList.SelectedItem;
|
||||
_server.Multiplayer.KickPlayer(player.Key);
|
||||
}
|
||||
|
||||
private void BanButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var player = PlayerList.SelectedItem as IMyPlayer;
|
||||
if (player != null)
|
||||
{
|
||||
_server.Multiplayer.BanPlayer(player.SteamUserId);
|
||||
}
|
||||
var player = (KeyValuePair<ulong, PlayerViewModel>) PlayerList.SelectedItem;
|
||||
_server.Multiplayer.BanPlayer(player.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -10,21 +10,26 @@
|
||||
<UserControl.DataContext>
|
||||
<viewModels:PluginManagerViewModel/>
|
||||
</UserControl.DataContext>
|
||||
<DockPanel>
|
||||
<DockPanel>
|
||||
<Button Content="Open Folder" Margin="3" DockPanel.Dock="Bottom" IsEnabled="false"></Button>
|
||||
<ListView Width="150" ItemsSource="{Binding Plugins}" SelectedItem="{Binding SelectedPlugin}" Margin="3">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="150"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid Grid.Column="0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<ListView Grid.Row="0" ItemsSource="{Binding Plugins}" SelectedItem="{Binding SelectedPlugin}" Margin="3">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Name}"/>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</DockPanel>
|
||||
<StackPanel Margin="3">
|
||||
<Label Content="{Binding SelectedPlugin.Name}" FontSize="16"/>
|
||||
<Frame NavigationUIVisibility="Hidden" Content="{Binding SelectedPlugin.Control}"/>
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
<Button Grid.Row="1" Content="Open Folder" Margin="3" DockPanel.Dock="Bottom" IsEnabled="false"/>
|
||||
</Grid>
|
||||
<Frame Grid.Column="1" NavigationUIVisibility="Hidden" Content="{Binding SelectedPlugin.Control}"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
|
@@ -5,14 +5,22 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:Torch.Server"
|
||||
xmlns:views="clr-namespace:Torch.Server.Views"
|
||||
xmlns:converters="clr-namespace:Torch.Server.Views.Converters"
|
||||
mc:Ignorable="d"
|
||||
Title="Torch">
|
||||
<DockPanel>
|
||||
<StackPanel DockPanel.Dock="Top" Margin="5,5,5,5" Orientation="Horizontal">
|
||||
<Window.Resources>
|
||||
<converters:InverseBooleanConverter x:Key="InverseBool"/>
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Grid.Row="0" Margin="5,5,5,5" Orientation="Horizontal">
|
||||
<Button x:Name="BtnStart" Content="Start" Height="24" Width="75" Margin="5,0,5,0"
|
||||
HorizontalAlignment="Left" Click="BtnStart_Click" IsDefault="True" />
|
||||
HorizontalAlignment="Left" Click="BtnStart_Click" IsEnabled="{Binding IsRunning, Converter={StaticResource InverseBool}}"/>
|
||||
<Button x:Name="BtnStop" Content="Stop" Height="24" Width="75" Margin="5,0,5,0" HorizontalAlignment="Left"
|
||||
Click="BtnStop_Click" IsEnabled="False" />
|
||||
Click="BtnStop_Click" IsEnabled="{Binding IsRunning}" />
|
||||
<Label>
|
||||
<Label.Content>
|
||||
<TextBlock Text="{Binding State, StringFormat=Status: {0}}"></TextBlock>
|
||||
@@ -29,22 +37,34 @@
|
||||
</Label.Content>
|
||||
</Label>
|
||||
</StackPanel>
|
||||
<TabControl x:Name="TabControl" DockPanel.Dock="Bottom" Margin="5,0,5,5">
|
||||
<TabControl Grid.Row="1" Height="Auto" x:Name="TabControl" Margin="5,0,5,5">
|
||||
<TabItem Header="Configuration">
|
||||
<DockPanel>
|
||||
<DockPanel DockPanel.Dock="Top">
|
||||
<Label Content="Instance Path: " Margin="3" />
|
||||
<TextBox x:Name="InstancePathBox" Margin="3" Height="20"
|
||||
TextChanged="InstancePathBox_OnTextChanged" IsEnabled="False" />
|
||||
</DockPanel>
|
||||
<views:ConfigControl x:Name="ConfigControl" Margin="3" DockPanel.Dock="Bottom" />
|
||||
</DockPanel>
|
||||
<Grid IsEnabled="{Binding IsRunning, Converter={StaticResource InverseBool}}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid Grid.Row="0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="0" Content="Instance Path: " Margin="3" />
|
||||
<TextBox Grid.Column="1" x:Name="InstancePathBox" Margin="3" Height="20"
|
||||
LostKeyboardFocus="InstancePathBox_OnLostKeyboardFocus" />
|
||||
</Grid>
|
||||
<views:ConfigControl Grid.Row="1" x:Name="ConfigControl" Margin="3" DockPanel.Dock="Bottom" IsEnabled="{Binding IsRunning, Converter={StaticResource InverseBool}}"/>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
<TabItem Header="Chat/Players">
|
||||
<DockPanel>
|
||||
<local:PlayerListControl x:Name="PlayerList" DockPanel.Dock="Right" Width="250" IsEnabled="False" />
|
||||
<local:ChatControl x:Name="Chat" IsEnabled="False" />
|
||||
</DockPanel>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition Width="250"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<local:ChatControl Grid.Column="0" x:Name="Chat" IsEnabled="{Binding IsRunning}"/>
|
||||
<local:PlayerListControl Grid.Column="1" x:Name="PlayerList" DockPanel.Dock="Right"/>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
<TabItem Header="Entity Manager">
|
||||
<views:EntitiesControl />
|
||||
@@ -53,5 +73,5 @@
|
||||
<views:PluginsControl x:Name="Plugins" />
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
</DockPanel>
|
||||
</Grid>
|
||||
</Window>
|
@@ -19,6 +19,7 @@ using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using Sandbox;
|
||||
using Torch.API;
|
||||
using Torch.Server.Managers;
|
||||
using Timer = System.Timers.Timer;
|
||||
|
||||
namespace Torch.Server
|
||||
@@ -47,6 +48,7 @@ namespace Torch.Server
|
||||
Chat.BindServer(server);
|
||||
PlayerList.BindServer(server);
|
||||
Plugins.BindServer(server);
|
||||
LoadConfig((TorchConfig)server.Config);
|
||||
}
|
||||
|
||||
public void LoadConfig(TorchConfig config)
|
||||
@@ -57,30 +59,18 @@ namespace Torch.Server
|
||||
_config = config;
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
ConfigControl.LoadDedicatedConfig(config);
|
||||
InstancePathBox.Text = config.InstancePath;
|
||||
});
|
||||
}
|
||||
|
||||
private void BtnStart_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_config.Save();
|
||||
Chat.IsEnabled = true;
|
||||
PlayerList.IsEnabled = true;
|
||||
((Button) sender).IsEnabled = false;
|
||||
BtnStop.IsEnabled = true;
|
||||
ConfigControl.SaveConfig();
|
||||
_server.GetManager<InstanceManager>().SaveConfig();
|
||||
new Thread(_server.Start).Start();
|
||||
}
|
||||
|
||||
private void BtnStop_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_config.Save();
|
||||
Chat.IsEnabled = false;
|
||||
PlayerList.IsEnabled = false;
|
||||
((Button) sender).IsEnabled = false;
|
||||
//HACK: Uncomment when restarting is possible.
|
||||
//BtnStart.IsEnabled = true;
|
||||
_server.Stop();
|
||||
}
|
||||
|
||||
@@ -90,7 +80,6 @@ namespace Torch.Server
|
||||
_config.WindowSize = newSize;
|
||||
var newPos = new Point((int)Left, (int)Top);
|
||||
_config.WindowPosition = newPos;
|
||||
_config.Save();
|
||||
|
||||
if (_server?.State == ServerState.Running)
|
||||
_server.Stop();
|
||||
@@ -101,13 +90,15 @@ namespace Torch.Server
|
||||
//MySandboxGame.Static.Invoke(MySandboxGame.ReloadDedicatedServerSession); use i
|
||||
}
|
||||
|
||||
private void InstancePathBox_OnTextChanged(object sender, TextChangedEventArgs e)
|
||||
private void InstancePathBox_OnLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
|
||||
{
|
||||
var name = ((TextBox)sender).Text;
|
||||
|
||||
_config.InstancePath = name;
|
||||
if (!Directory.Exists(name))
|
||||
return;
|
||||
|
||||
LoadConfig(_config);
|
||||
_config.InstancePath = name;
|
||||
_server.GetManager<InstanceManager>().LoadInstance(_config.InstancePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Extended.Wpf.Toolkit" version="2.9" targetFramework="net461" />
|
||||
<package id="NLog" version="4.4.1" targetFramework="net461" />
|
||||
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" />
|
||||
<package id="NLog" version="4.4.11" targetFramework="net461" />
|
||||
</packages>
|
@@ -10,7 +10,7 @@ using VRage.Network;
|
||||
|
||||
namespace Torch
|
||||
{
|
||||
public struct ChatMessage : IChatMessage
|
||||
public class ChatMessage : IChatMessage
|
||||
{
|
||||
public DateTime Timestamp { get; }
|
||||
public ulong SteamId { get; }
|
||||
|
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
@@ -10,15 +9,18 @@ using System.Windows.Threading;
|
||||
|
||||
namespace Torch
|
||||
{
|
||||
[Obsolete("Use ObservableList<T>.")]
|
||||
public class MTObservableCollection<T> : ObservableCollection<T>
|
||||
{
|
||||
public override event NotifyCollectionChangedEventHandler CollectionChanged;
|
||||
|
||||
protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
NotifyCollectionChangedEventHandler collectionChanged = CollectionChanged;
|
||||
if (collectionChanged != null)
|
||||
foreach (NotifyCollectionChangedEventHandler nh in collectionChanged.GetInvocationList())
|
||||
foreach (var del in collectionChanged.GetInvocationList())
|
||||
{
|
||||
var nh = (NotifyCollectionChangedEventHandler)del;
|
||||
var dispObj = nh.Target as DispatcherObject;
|
||||
|
||||
var dispatcher = dispObj?.Dispatcher;
|
||||
|
63
Torch/Collections/ObservableDictionary.cs
Normal file
63
Torch/Collections/ObservableDictionary.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace Torch.Collections
|
||||
{
|
||||
[Serializable]
|
||||
public class ObservableDictionary<TKey, TValue> : Dictionary<TKey, TValue>, INotifyCollectionChanged, INotifyPropertyChanged
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public new void Add(TKey key, TValue value)
|
||||
{
|
||||
base.Add(key, value);
|
||||
var kv = new KeyValuePair<TKey, TValue>(key, value);
|
||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, kv));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public new bool Remove(TKey key)
|
||||
{
|
||||
if (!ContainsKey(key))
|
||||
return false;
|
||||
|
||||
var kv = new KeyValuePair<TKey, TValue>(key, this[key]);
|
||||
base.Remove(key);
|
||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, kv));
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
NotifyCollectionChangedEventHandler collectionChanged = CollectionChanged;
|
||||
if (collectionChanged != null)
|
||||
foreach (NotifyCollectionChangedEventHandler nh in collectionChanged.GetInvocationList())
|
||||
{
|
||||
var dispObj = nh.Target as DispatcherObject;
|
||||
|
||||
var dispatcher = dispObj?.Dispatcher;
|
||||
if (dispatcher != null && !dispatcher.CheckAccess())
|
||||
{
|
||||
dispatcher.BeginInvoke(
|
||||
(Action)(() => nh.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset))),
|
||||
DispatcherPriority.DataBind);
|
||||
continue;
|
||||
}
|
||||
|
||||
nh.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public event NotifyCollectionChangedEventHandler CollectionChanged;
|
||||
|
||||
/// <inheritdoc />
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
}
|
||||
}
|
186
Torch/Collections/ObservableList.cs
Normal file
186
Torch/Collections/ObservableList.cs
Normal file
@@ -0,0 +1,186 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace Torch
|
||||
{
|
||||
/// <summary>
|
||||
/// An observable version of <see cref="List{T}"/>.
|
||||
/// </summary>
|
||||
public class ObservableList<T> : IList<T>, INotifyCollectionChanged, INotifyPropertyChanged
|
||||
{
|
||||
private List<T> _internalList = new List<T>();
|
||||
|
||||
/// <inheritdoc />
|
||||
public event NotifyCollectionChangedEventHandler CollectionChanged;
|
||||
|
||||
/// <inheritdoc />
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Clear()
|
||||
{
|
||||
_internalList.Clear();
|
||||
OnPropertyChanged(nameof(Count));
|
||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Contains(T item)
|
||||
{
|
||||
return _internalList.Contains(item);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void CopyTo(T[] array, int arrayIndex)
|
||||
{
|
||||
_internalList.CopyTo(array, arrayIndex);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Remove(T item)
|
||||
{
|
||||
var oldIndex = _internalList.IndexOf(item);
|
||||
if (!_internalList.Remove(item))
|
||||
return false;
|
||||
|
||||
OnPropertyChanged(nameof(Count));
|
||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, oldIndex));
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Count => _internalList.Count;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsReadOnly => false;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Add(T item)
|
||||
{
|
||||
_internalList.Add(item);
|
||||
OnPropertyChanged(nameof(Count));
|
||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, Count - 1));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int IndexOf(T item) => _internalList.IndexOf(item);
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Insert(int index, T item)
|
||||
{
|
||||
_internalList.Insert(index, item);
|
||||
OnPropertyChanged(nameof(Count));
|
||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts an item in order based on the provided selector and comparer. This will only work properly on a pre-sorted list.
|
||||
/// </summary>
|
||||
public void Insert<TKey>(T item, Func<T, TKey> selector, IComparer<TKey> comparer = null)
|
||||
{
|
||||
comparer = comparer ?? Comparer<TKey>.Default;
|
||||
var key1 = selector(item);
|
||||
for (var i = 0; i < _internalList.Count; i++)
|
||||
{
|
||||
var key2 = selector(_internalList[i]);
|
||||
if (comparer.Compare(key1, key2) < 1)
|
||||
{
|
||||
Insert(i, item);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Add(item);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
var old = this[index];
|
||||
_internalList.RemoveAt(index);
|
||||
OnPropertyChanged(nameof(Count));
|
||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, old, index));
|
||||
}
|
||||
|
||||
public T this[int index]
|
||||
{
|
||||
get => _internalList[index];
|
||||
set
|
||||
{
|
||||
var old = _internalList[index];
|
||||
if (old.Equals(value))
|
||||
return;
|
||||
|
||||
_internalList[index] = value;
|
||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, value, old, index));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sorts the list using the given selector and comparer./>
|
||||
/// </summary>
|
||||
public void Sort<TKey>(Func<T, TKey> selector, IComparer<TKey> comparer = null)
|
||||
{
|
||||
comparer = comparer ?? Comparer<TKey>.Default;
|
||||
var sortedItems = _internalList.OrderBy(selector, comparer).ToList();
|
||||
|
||||
_internalList = sortedItems;
|
||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes all items that satisfy the given condition.
|
||||
/// </summary>
|
||||
public void RemoveWhere(Func<T, bool> condition)
|
||||
{
|
||||
for (var i = Count - 1; i > 0; i--)
|
||||
{
|
||||
if (condition?.Invoke(this[i]) ?? false)
|
||||
RemoveAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
var collectionChanged = CollectionChanged;
|
||||
if (collectionChanged != null)
|
||||
foreach (var del in collectionChanged.GetInvocationList())
|
||||
{
|
||||
var nh = (NotifyCollectionChangedEventHandler)del;
|
||||
var dispObj = nh.Target as DispatcherObject;
|
||||
|
||||
var dispatcher = dispObj?.Dispatcher;
|
||||
if (dispatcher != null && !dispatcher.CheckAccess())
|
||||
{
|
||||
dispatcher.BeginInvoke(() => nh.Invoke(this, e), DispatcherPriority.DataBind);
|
||||
continue;
|
||||
}
|
||||
|
||||
nh.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
return _internalList.GetEnumerator();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return ((IEnumerable)_internalList).GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,17 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace Torch
|
||||
{
|
||||
public class CommandLine
|
||||
/// <summary>
|
||||
/// Base class that adds tools for setting type properties through the command line.
|
||||
/// </summary>
|
||||
public abstract class CommandLine
|
||||
{
|
||||
private readonly string _argPrefix;
|
||||
private readonly Dictionary<ArgAttribute, PropertyInfo> _args = new Dictionary<ArgAttribute, PropertyInfo>();
|
||||
|
||||
public CommandLine(string argPrefix = "-")
|
||||
protected CommandLine(string argPrefix = "-")
|
||||
{
|
||||
_argPrefix = argPrefix;
|
||||
foreach (var prop in GetType().GetProperties())
|
||||
|
@@ -8,6 +8,7 @@ using NLog;
|
||||
using Torch.API;
|
||||
using Torch.API.Plugins;
|
||||
using Torch.Commands.Permissions;
|
||||
using VRage.Game;
|
||||
using VRage.Game.ModAPI;
|
||||
|
||||
namespace Torch.Commands
|
||||
@@ -26,6 +27,7 @@ namespace Torch.Commands
|
||||
private readonly MethodInfo _method;
|
||||
private ParameterInfo[] _parameters;
|
||||
private int? _requiredParamCount;
|
||||
private static readonly Logger Log = LogManager.GetLogger(nameof(Command));
|
||||
|
||||
public Command(ITorchPlugin plugin, MethodInfo commandMethod)
|
||||
{
|
||||
@@ -84,31 +86,41 @@ namespace Torch.Commands
|
||||
|
||||
public bool TryInvoke(CommandContext context)
|
||||
{
|
||||
var parameters = new object[_parameters.Length];
|
||||
|
||||
if (context.Args.Count < _requiredParamCount)
|
||||
return false;
|
||||
|
||||
//Convert args from string
|
||||
for (var i = 0; i < _parameters.Length && i < context.Args.Count; i++)
|
||||
try
|
||||
{
|
||||
if (context.Args[i].TryConvert(_parameters[i].ParameterType, out object obj))
|
||||
parameters[i] = obj;
|
||||
else
|
||||
var parameters = new object[_parameters.Length];
|
||||
|
||||
if (context.Args.Count < _requiredParamCount)
|
||||
return false;
|
||||
}
|
||||
|
||||
//Fill remaining parameters with default values
|
||||
for (var i = 0; i < parameters.Length; i++)
|
||||
//Convert args from string
|
||||
for (var i = 0; i < _parameters.Length && i < context.Args.Count; i++)
|
||||
{
|
||||
if (context.Args[i].TryConvert(_parameters[i].ParameterType, out object obj))
|
||||
parameters[i] = obj;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
//Fill remaining parameters with default values
|
||||
for (var i = 0; i < parameters.Length; i++)
|
||||
{
|
||||
if (parameters[i] == null)
|
||||
parameters[i] = _parameters[i].DefaultValue;
|
||||
}
|
||||
|
||||
var moduleInstance = (CommandModule)Activator.CreateInstance(Module);
|
||||
moduleInstance.Context = context;
|
||||
_method.Invoke(moduleInstance, parameters);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (parameters[i] == null)
|
||||
parameters[i] = _parameters[i].DefaultValue;
|
||||
context.Respond(e.Message, "Error", MyFontEnum.Red);
|
||||
Log.Error($"Command '{SyntaxHelp}' from '{Plugin.Name ?? "Torch"}' threw an exception. Args: {string.Join(", ", context.Args)}");
|
||||
Log.Error(e);
|
||||
return true;
|
||||
}
|
||||
|
||||
var moduleInstance = (CommandModule)Activator.CreateInstance(Module);
|
||||
moduleInstance.Context = context;
|
||||
_method.Invoke(moduleInstance, parameters);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -21,7 +21,7 @@ namespace Torch.Commands
|
||||
public CommandTree Commands { get; set; } = new CommandTree();
|
||||
private Logger _log = LogManager.GetLogger(nameof(CommandManager));
|
||||
|
||||
public CommandManager(ITorchBase torch, char prefix = '/') : base(torch)
|
||||
public CommandManager(ITorchBase torch, char prefix = '!') : base(torch)
|
||||
{
|
||||
Prefix = prefix;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ namespace Torch.Commands
|
||||
|
||||
public bool IsCommand(string command)
|
||||
{
|
||||
return command.Length > 1 && command[0] == Prefix;
|
||||
return !string.IsNullOrEmpty(command) && command[0] == Prefix;
|
||||
}
|
||||
|
||||
public void RegisterCommandModule(Type moduleType, ITorchPlugin plugin = null)
|
||||
@@ -76,6 +76,8 @@ namespace Torch.Commands
|
||||
{
|
||||
var cmdText = new string(message.Skip(1).ToArray());
|
||||
var command = Commands.GetCommand(cmdText, out string argText);
|
||||
if (command == null)
|
||||
return null;
|
||||
var cmdPath = string.Join(".", command.Path);
|
||||
|
||||
var splitArgs = Regex.Matches(argText, "(\"[^\"]+\"|\\S+)").Cast<Match>().Select(x => x.ToString().Replace("\"", "")).ToList();
|
||||
|
@@ -1,8 +1,11 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using Sandbox.ModAPI;
|
||||
using Torch;
|
||||
using Torch.Commands.Permissions;
|
||||
@@ -14,6 +17,7 @@ namespace Torch.Commands
|
||||
public class TorchCommands : CommandModule
|
||||
{
|
||||
[Command("help", "Displays help for a command")]
|
||||
[Permission(MyPromoteLevel.None)]
|
||||
public void Help()
|
||||
{
|
||||
var commandManager = ((TorchBase)Context.Torch).Commands;
|
||||
@@ -39,12 +43,48 @@ namespace Torch.Commands
|
||||
}
|
||||
else
|
||||
{
|
||||
var topNodeNames = commandManager.Commands.Root.Select(x => x.Key);
|
||||
Context.Respond($"Top level commands: {string.Join(", ", topNodeNames)}");
|
||||
Context.Respond($"Use the {commandManager.Prefix}longhelp command and check your Comms menu for a full list of commands.");
|
||||
}
|
||||
}
|
||||
|
||||
[Command("longhelp", "Get verbose help. Will send a long message, check the Comms tab.")]
|
||||
public void LongHelp()
|
||||
{
|
||||
var commandManager = Context.Torch.GetManager<CommandManager>();
|
||||
commandManager.Commands.GetNode(Context.Args, out CommandTree.CommandNode node);
|
||||
|
||||
if (node != null)
|
||||
{
|
||||
var command = node.Command;
|
||||
var children = node.Subcommands.Select(x => x.Key);
|
||||
|
||||
var sb = new StringBuilder();
|
||||
|
||||
if (command != null)
|
||||
{
|
||||
sb.AppendLine($"Syntax: {command.SyntaxHelp}");
|
||||
sb.Append(command.HelpText);
|
||||
}
|
||||
|
||||
if (node.Subcommands.Count() != 0)
|
||||
sb.Append($"\nSubcommands: {string.Join(", ", children)}");
|
||||
|
||||
Context.Respond(sb.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
var sb = new StringBuilder("Available commands:\n");
|
||||
foreach (var command in commandManager.Commands.WalkTree())
|
||||
{
|
||||
if (command.IsCommand)
|
||||
sb.AppendLine($"{command.Command.SyntaxHelp}\n {command.Command.HelpText}");
|
||||
}
|
||||
Context.Respond(sb.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[Command("ver", "Shows the running Torch version.")]
|
||||
[Permission(MyPromoteLevel.None)]
|
||||
public void Version()
|
||||
{
|
||||
var ver = Context.Torch.TorchVersion;
|
||||
@@ -52,6 +92,7 @@ namespace Torch.Commands
|
||||
}
|
||||
|
||||
[Command("plugins", "Lists the currently loaded plugins.")]
|
||||
[Permission(MyPromoteLevel.None)]
|
||||
public void Plugins()
|
||||
{
|
||||
var plugins = Context.Torch.Plugins.Select(p => p.Name);
|
||||
@@ -59,11 +100,68 @@ namespace Torch.Commands
|
||||
}
|
||||
|
||||
[Command("stop", "Stops the server.")]
|
||||
[Permission(MyPromoteLevel.Admin)]
|
||||
public void Stop()
|
||||
public void Stop(bool save = true)
|
||||
{
|
||||
Context.Respond("Stopping server.");
|
||||
if (save)
|
||||
Context.Torch.Save(Context.Player?.IdentityId ?? 0).Wait();
|
||||
Context.Torch.Stop();
|
||||
}
|
||||
|
||||
[Command("restart", "Restarts the server.")]
|
||||
public void Restart(int countdownSeconds = 10, bool save = true)
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
var countdown = RestartCountdown(countdownSeconds).GetEnumerator();
|
||||
while (countdown.MoveNext())
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private IEnumerable RestartCountdown(int countdown)
|
||||
{
|
||||
for (var i = countdown; i >= 0; i--)
|
||||
{
|
||||
if (i >= 60 && i % 60 == 0)
|
||||
{
|
||||
Context.Torch.Multiplayer.SendMessage($"Restarting server in {i / 60} minute{Pluralize(i / 60)}.");
|
||||
yield return null;
|
||||
}
|
||||
else if (i > 0)
|
||||
{
|
||||
if (i < 11)
|
||||
Context.Torch.Multiplayer.SendMessage($"Restarting server in {i} second{Pluralize(i)}.");
|
||||
yield return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
Context.Torch.Invoke(() =>
|
||||
{
|
||||
Context.Torch.Save(0).Wait();
|
||||
Context.Torch.Restart();
|
||||
});
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string Pluralize(int num)
|
||||
{
|
||||
return num == 1 ? "" : "s";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a save of the game.
|
||||
/// Caller id defaults to 0 in the case of triggering the chat command from server.
|
||||
/// </summary>
|
||||
[Command("save", "Saves the game.")]
|
||||
public void Save()
|
||||
{
|
||||
Context.Respond("Saving game.");
|
||||
Context.Torch.Save(Context.Player?.IdentityId ?? 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
17
Torch/DispatcherExtensions.cs
Normal file
17
Torch/DispatcherExtensions.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace Torch
|
||||
{
|
||||
public static class DispatcherExtensions
|
||||
{
|
||||
public static DispatcherOperation BeginInvoke(this Dispatcher dispatcher, Action action, DispatcherPriority priority = DispatcherPriority.Normal)
|
||||
{
|
||||
return dispatcher.BeginInvoke(priority, action);
|
||||
}
|
||||
}
|
||||
}
|
@@ -45,7 +45,7 @@ namespace Torch.Managers
|
||||
}
|
||||
}
|
||||
|
||||
private void Static_ChatMessageReceived(ulong arg1, string arg2, SteamSDK.ChatEntryTypeEnum arg3)
|
||||
private void Static_ChatMessageReceived(ulong arg1, string arg2)
|
||||
{
|
||||
var msg = new ChatMsg {Author = arg1, Text = arg2};
|
||||
var sendToOthers = true;
|
||||
|
51
Torch/Managers/FilesystemManager.cs
Normal file
51
Torch/Managers/FilesystemManager.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Torch.API;
|
||||
|
||||
namespace Torch.Managers
|
||||
{
|
||||
public class FilesystemManager : Manager
|
||||
{
|
||||
/// <summary>
|
||||
/// Temporary directory for Torch that is cleared every time the program is started.
|
||||
/// </summary>
|
||||
public string TempDirectory { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Directory that contains the current Torch assemblies.
|
||||
/// </summary>
|
||||
public string TorchDirectory { get; }
|
||||
|
||||
public FilesystemManager(ITorchBase torchInstance) : base(torchInstance)
|
||||
{
|
||||
var temp = Path.Combine(Path.GetTempPath(), "Torch");
|
||||
TempDirectory = Directory.CreateDirectory(temp).FullName;
|
||||
var torch = new FileInfo(typeof(FilesystemManager).Assembly.Location).Directory.FullName;
|
||||
TorchDirectory = torch;
|
||||
|
||||
ClearTemp();
|
||||
}
|
||||
|
||||
private void ClearTemp()
|
||||
{
|
||||
foreach (var file in Directory.GetFiles(TempDirectory, "*", SearchOption.AllDirectories))
|
||||
File.Delete(file);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move the given file (if it exists) to a temporary directory that will be cleared the next time the application starts.
|
||||
/// </summary>
|
||||
public void SoftDelete(string file)
|
||||
{
|
||||
if (!File.Exists(file))
|
||||
return;
|
||||
var rand = Path.GetRandomFileName();
|
||||
var dest = Path.Combine(TempDirectory, rand);
|
||||
File.Move(file, dest);
|
||||
}
|
||||
}
|
||||
}
|
@@ -16,37 +16,40 @@ using NLog;
|
||||
using Torch;
|
||||
using Sandbox;
|
||||
using Sandbox.Engine.Multiplayer;
|
||||
using Sandbox.Game.Entities.Character;
|
||||
using Sandbox.Game.Multiplayer;
|
||||
using Sandbox.Game.World;
|
||||
using Sandbox.ModAPI;
|
||||
using SharpDX.Toolkit.Collections;
|
||||
using SteamSDK;
|
||||
using Torch.API;
|
||||
using Torch.API.Managers;
|
||||
using Torch.Collections;
|
||||
using Torch.Commands;
|
||||
using Torch.ViewModels;
|
||||
using VRage.Game;
|
||||
using VRage.Game.ModAPI;
|
||||
using VRage.GameServices;
|
||||
using VRage.Library.Collections;
|
||||
using VRage.Network;
|
||||
using VRage.Utils;
|
||||
|
||||
namespace Torch.Managers
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides a proxy to the game's multiplayer-related functions.
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public class MultiplayerManager : Manager, IMultiplayerManager
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public event Action<IPlayer> PlayerJoined;
|
||||
/// <inheritdoc />
|
||||
public event Action<IPlayer> PlayerLeft;
|
||||
/// <inheritdoc />
|
||||
public event MessageReceivedDel MessageReceived;
|
||||
|
||||
public MTObservableCollection<IChatMessage> ChatHistory { get; } = new MTObservableCollection<IChatMessage>();
|
||||
public IList<IChatMessage> ChatHistory { get; } = new ObservableList<IChatMessage>();
|
||||
public ObservableDictionary<ulong, PlayerViewModel> Players { get; } = new ObservableDictionary<ulong, PlayerViewModel>();
|
||||
public IMyPlayer LocalPlayer => MySession.Static.LocalHumanPlayer;
|
||||
private static readonly Logger _log = LogManager.GetLogger(nameof(MultiplayerManager));
|
||||
private static readonly Logger _chatLog = LogManager.GetLogger("Chat");
|
||||
private static readonly Logger Log = LogManager.GetLogger(nameof(MultiplayerManager));
|
||||
private static readonly Logger ChatLog = LogManager.GetLogger("Chat");
|
||||
private Dictionary<MyPlayer.PlayerId, MyPlayer> _onlinePlayers;
|
||||
|
||||
internal MultiplayerManager(ITorchBase torch) : base(torch)
|
||||
@@ -65,12 +68,14 @@ namespace Torch.Managers
|
||||
{
|
||||
var message = ChatMessage.FromChatMsg(msg);
|
||||
ChatHistory.Add(message);
|
||||
_chatLog.Info($"{message.Name}: {message.Message}");
|
||||
ChatLog.Info($"{message.Name}: {message.Message}");
|
||||
MessageReceived?.Invoke(message, ref sendToOthers);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void KickPlayer(ulong steamId) => Torch.Invoke(() => MyMultiplayer.Static.KickClient(steamId));
|
||||
|
||||
/// <inheritdoc />
|
||||
public void BanPlayer(ulong steamId, bool banned = true)
|
||||
{
|
||||
Torch.Invoke(() =>
|
||||
@@ -81,12 +86,14 @@ namespace Torch.Managers
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IMyPlayer GetPlayerByName(string name)
|
||||
{
|
||||
ValidateOnlinePlayersList();
|
||||
return _onlinePlayers.FirstOrDefault(x => x.Value.DisplayName == name).Value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IMyPlayer GetPlayerBySteamId(ulong steamId)
|
||||
{
|
||||
ValidateOnlinePlayersList();
|
||||
@@ -94,27 +101,47 @@ namespace Torch.Managers
|
||||
return p;
|
||||
}
|
||||
|
||||
public ulong GetSteamId(long identityId)
|
||||
{
|
||||
foreach (var kv in _onlinePlayers)
|
||||
{
|
||||
if (kv.Value.Identity.IdentityId == identityId)
|
||||
return kv.Key.SteamId;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public string GetSteamUsername(ulong steamId)
|
||||
{
|
||||
return MyMultiplayer.Static.GetMemberName(steamId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a message in chat.
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public void SendMessage(string message, string author = "Server", long playerId = 0, string font = MyFontEnum.Red)
|
||||
{
|
||||
ChatHistory.Add(new ChatMessage(DateTime.Now, 0, "Server", message));
|
||||
if (string.IsNullOrEmpty(message))
|
||||
return;
|
||||
|
||||
ChatHistory.Add(new ChatMessage(DateTime.Now, 0, author, message));
|
||||
var commands = Torch.GetManager<CommandManager>();
|
||||
if (commands.IsCommand(message))
|
||||
{
|
||||
var response = commands.HandleCommandFromServer(message);
|
||||
ChatHistory.Add(new ChatMessage(DateTime.Now, 0, "Server", response));
|
||||
ChatHistory.Add(new ChatMessage(DateTime.Now, 0, author, response));
|
||||
}
|
||||
else
|
||||
{
|
||||
var msg = new ScriptedChatMsg { Author = author, Font = font, Target = playerId, Text = message };
|
||||
MyMultiplayerBase.SendScriptedChatMessage(ref msg);
|
||||
var character = MySession.Static.Players.TryGetIdentity(playerId)?.Character;
|
||||
var steamId = GetSteamId(playerId);
|
||||
if (character == null)
|
||||
return;
|
||||
|
||||
var addToGlobalHistoryMethod = typeof(MyCharacter).GetMethod("OnGlobalMessageSuccess", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
Torch.GetManager<NetworkManager>().RaiseEvent(addToGlobalHistoryMethod, character, steamId, steamId, message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,6 +153,7 @@ namespace Torch.Managers
|
||||
|
||||
private void OnSessionLoaded()
|
||||
{
|
||||
Log.Info("Initializing Steam auth");
|
||||
MyMultiplayer.Static.ClientKicked += OnClientKicked;
|
||||
MyMultiplayer.Static.ClientLeft += OnClientLeft;
|
||||
|
||||
@@ -137,18 +165,21 @@ namespace Torch.Managers
|
||||
SteamServerAPI.Instance.GameServer.UserGroupStatus += UserGroupStatus;
|
||||
_members = (List<ulong>)typeof(MyDedicatedServerBase).GetField("m_members", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(MyMultiplayer.Static);
|
||||
_waitingForGroup = (HashSet<ulong>)typeof(MyDedicatedServerBase).GetField("m_waitingForGroup", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(MyMultiplayer.Static);
|
||||
Log.Info("Steam auth initialized");
|
||||
}
|
||||
|
||||
private void OnClientKicked(ulong steamId)
|
||||
{
|
||||
OnClientLeft(steamId, ChatMemberStateChangeEnum.Kicked);
|
||||
OnClientLeft(steamId, MyChatMemberStateChangeEnum.Kicked);
|
||||
}
|
||||
|
||||
private void OnClientLeft(ulong steamId, ChatMemberStateChangeEnum stateChange)
|
||||
private void OnClientLeft(ulong steamId, MyChatMemberStateChangeEnum stateChange)
|
||||
{
|
||||
_log.Info($"{GetSteamUsername(steamId)} disconnected ({(ConnectionState)stateChange}).");
|
||||
Players.TryGetValue(steamId, out PlayerViewModel vm);
|
||||
PlayerLeft?.Invoke(vm ?? new PlayerViewModel(steamId));
|
||||
if (vm == null)
|
||||
vm = new PlayerViewModel(steamId);
|
||||
Log.Info($"{vm.Name} ({vm.SteamId}) {(ConnectionState)stateChange}.");
|
||||
PlayerLeft?.Invoke(vm);
|
||||
Players.Remove(steamId);
|
||||
}
|
||||
|
||||
@@ -174,6 +205,7 @@ namespace Torch.Managers
|
||||
if (handle.Method.Name == "GameServer_ValidateAuthTicketResponse")
|
||||
{
|
||||
SteamServerAPI.Instance.GameServer.ValidateAuthTicketResponse -= handle as ValidateAuthTicketResponse;
|
||||
Log.Debug("Removed GameServer_ValidateAuthTicketResponse");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -186,6 +218,7 @@ namespace Torch.Managers
|
||||
if (handle.Method.Name == "GameServer_UserGroupStatus")
|
||||
{
|
||||
SteamServerAPI.Instance.GameServer.UserGroupStatus -= handle as UserGroupStatus;
|
||||
Log.Debug("Removed GameServer_UserGroupStatus");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -194,16 +227,16 @@ namespace Torch.Managers
|
||||
//Largely copied from SE
|
||||
private void ValidateAuthTicketResponse(ulong steamID, AuthSessionResponseEnum response, ulong ownerSteamID)
|
||||
{
|
||||
_log.Info($"Server ValidateAuthTicketResponse ({response}), owner: {ownerSteamID}");
|
||||
Log.Info($"Server ValidateAuthTicketResponse ({response}), owner: {ownerSteamID}");
|
||||
|
||||
if (steamID != ownerSteamID)
|
||||
{
|
||||
_log.Info($"User {steamID} is using a game owned by {ownerSteamID}. Tracking...");
|
||||
Log.Info($"User {steamID} is using a game owned by {ownerSteamID}. Tracking...");
|
||||
_gameOwnerIds[steamID] = ownerSteamID;
|
||||
|
||||
if (MySandboxGame.ConfigDedicated.Banned.Contains(ownerSteamID))
|
||||
{
|
||||
_log.Info($"Game owner {ownerSteamID} is banned. Banning and rejecting client {steamID}...");
|
||||
Log.Info($"Game owner {ownerSteamID} is banned. Banning and rejecting client {steamID}...");
|
||||
UserRejected(steamID, JoinResult.BannedByAdmins);
|
||||
BanPlayer(steamID);
|
||||
}
|
||||
@@ -299,7 +332,8 @@ namespace Torch.Managers
|
||||
private void UserAccepted(ulong steamId)
|
||||
{
|
||||
typeof(MyDedicatedServerBase).GetMethod("UserAccepted", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(MyMultiplayer.Static, new object[] {steamId});
|
||||
var vm = new PlayerViewModel(steamId);
|
||||
var vm = new PlayerViewModel(steamId) {State = ConnectionState.Connected};
|
||||
Log.Info($"Player {vm.Name} joined ({vm.SteamId})");
|
||||
Players.Add(steamId, vm);
|
||||
PlayerJoined?.Invoke(vm);
|
||||
}
|
||||
|
@@ -64,6 +64,11 @@ namespace Torch.Managers
|
||||
/// Loads the network intercept system
|
||||
/// </summary>
|
||||
public override void Init()
|
||||
{
|
||||
Torch.SessionLoaded += OnSessionLoaded;
|
||||
}
|
||||
|
||||
private void OnSessionLoaded()
|
||||
{
|
||||
if (_init)
|
||||
return;
|
||||
@@ -121,8 +126,7 @@ namespace Torch.Managers
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Fatal(ex);
|
||||
_log.Fatal(ex, "~Error processing event!");
|
||||
_log.Error(ex);
|
||||
//crash after logging, bad things could happen if we continue on with bad data
|
||||
throw;
|
||||
}
|
||||
@@ -195,8 +199,8 @@ namespace Torch.Managers
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Fatal(ex);
|
||||
_log.Fatal(ex, "Error when returning control to game server!");
|
||||
_log.Error(ex, "Error processing network event!");
|
||||
_log.Error(ex);
|
||||
//crash after logging, bad things could happen if we continue on with bad data
|
||||
throw;
|
||||
}
|
||||
@@ -306,7 +310,7 @@ namespace Torch.Managers
|
||||
var parameters = method.GetParameters();
|
||||
for (var i = 0; i < parameters.Length; i++)
|
||||
{
|
||||
if (argTypes[i] != parameters[i].ParameterType)
|
||||
if (argTypes[i + 1] != parameters[i].ParameterType)
|
||||
throw new TypeLoadException($"Type mismatch on method parameters. Expected {string.Join(", ", parameters.Select(p => p.ParameterType.ToString()))} got {string.Join(", ", argTypes.Select(t => t.ToString()))}");
|
||||
}
|
||||
|
||||
|
@@ -5,42 +5,30 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NLog;
|
||||
using Sandbox;
|
||||
using Sandbox.ModAPI;
|
||||
using Torch.API;
|
||||
using Torch.API.Managers;
|
||||
using Torch.API.Plugins;
|
||||
using Torch.Commands;
|
||||
using Torch.Managers;
|
||||
using Torch.Updater;
|
||||
using VRage.Plugins;
|
||||
using VRage.Collections;
|
||||
using VRage.Library.Collections;
|
||||
|
||||
namespace Torch.Managers
|
||||
{
|
||||
public class PluginManager : IPluginManager
|
||||
/// <inheritdoc />
|
||||
public class PluginManager : Manager, IPluginManager
|
||||
{
|
||||
private readonly ITorchBase _torch;
|
||||
private static Logger _log = LogManager.GetLogger(nameof(PluginManager));
|
||||
public readonly string PluginDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins");
|
||||
private UpdateManager _updateManager;
|
||||
|
||||
public List<ITorchPlugin> Plugins { get; } = new List<ITorchPlugin>();
|
||||
/// <inheritdoc />
|
||||
public IList<ITorchPlugin> Plugins { get; } = new ObservableList<ITorchPlugin>();
|
||||
|
||||
public float LastUpdateMs => _lastUpdateMs;
|
||||
private volatile float _lastUpdateMs;
|
||||
public event Action<IList<ITorchPlugin>> PluginsLoaded;
|
||||
|
||||
public event Action<List<ITorchPlugin>> PluginsLoaded;
|
||||
|
||||
public PluginManager(ITorchBase torch)
|
||||
public PluginManager(ITorchBase torchInstance) : base(torchInstance)
|
||||
{
|
||||
_torch = torch;
|
||||
|
||||
if (!Directory.Exists(PluginDir))
|
||||
Directory.CreateDirectory(PluginDir);
|
||||
}
|
||||
@@ -50,11 +38,8 @@ namespace Torch.Managers
|
||||
/// </summary>
|
||||
public void UpdatePlugins()
|
||||
{
|
||||
var s = Stopwatch.StartNew();
|
||||
foreach (var plugin in Plugins)
|
||||
plugin.Update();
|
||||
s.Stop();
|
||||
_lastUpdateMs = (float)s.Elapsed.TotalMilliseconds;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -70,40 +55,42 @@ namespace Torch.Managers
|
||||
|
||||
private void DownloadPlugins()
|
||||
{
|
||||
_log.Info("Downloading plugins");
|
||||
var updater = new PluginUpdater(this);
|
||||
|
||||
var folders = Directory.GetDirectories(PluginDir);
|
||||
var taskList = new List<Task>();
|
||||
if (_torch.Config.RedownloadPlugins)
|
||||
_log.Warn("Force downloading all plugins because the RedownloadPlugins flag is set in the config");
|
||||
|
||||
//Copy list because we don't want to modify the config.
|
||||
var toDownload = Torch.Config.Plugins.ToList();
|
||||
|
||||
foreach (var folder in folders)
|
||||
{
|
||||
var manifestPath = Path.Combine(folder, "manifest.xml");
|
||||
if (!File.Exists(manifestPath))
|
||||
{
|
||||
_log.Info($"No manifest in {folder}, skipping");
|
||||
_log.Debug($"No manifest in {folder}, skipping");
|
||||
continue;
|
||||
}
|
||||
|
||||
_log.Info($"Checking for updates for {folder}");
|
||||
var manifest = PluginManifest.Load(manifestPath);
|
||||
taskList.Add(updater.CheckAndUpdate(manifest, _torch.Config.RedownloadPlugins));
|
||||
toDownload.RemoveAll(x => string.Compare(manifest.Repository, x, StringComparison.InvariantCultureIgnoreCase) == 0);
|
||||
taskList.Add(_updateManager.CheckAndUpdatePlugin(manifest));
|
||||
}
|
||||
|
||||
foreach (var repository in toDownload)
|
||||
{
|
||||
var manifest = new PluginManifest {Repository = repository, Version = "0.0"};
|
||||
taskList.Add(_updateManager.CheckAndUpdatePlugin(manifest));
|
||||
}
|
||||
|
||||
Task.WaitAll(taskList.ToArray());
|
||||
_torch.Config.RedownloadPlugins = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads and creates instances of all plugins in the <see cref="PluginDir"/> folder.
|
||||
/// </summary>
|
||||
public void Init()
|
||||
/// <inheritdoc />
|
||||
public void LoadPlugins()
|
||||
{
|
||||
var commands = ((TorchBase)_torch).Commands;
|
||||
_updateManager = Torch.GetManager<UpdateManager>();
|
||||
var commands = Torch.GetManager<CommandManager>();
|
||||
|
||||
if (_torch.Config.AutomaticUpdates)
|
||||
if (Torch.Config.ShouldUpdatePlugins)
|
||||
DownloadPlugins();
|
||||
else
|
||||
_log.Warn("Automatic plugin updates are disabled.");
|
||||
@@ -129,22 +116,23 @@ namespace Torch.Managers
|
||||
throw new TypeLoadException($"Plugin '{type.FullName}' is missing a {nameof(PluginAttribute)}");
|
||||
|
||||
_log.Info($"Loading plugin {plugin.Name} ({plugin.Version})");
|
||||
plugin.StoragePath = new FileInfo(asm.Location).Directory.FullName;
|
||||
plugin.StoragePath = Torch.Config.InstancePath;
|
||||
Plugins.Add(plugin);
|
||||
|
||||
commands.RegisterPluginCommands(plugin);
|
||||
}
|
||||
catch
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.Error($"Error loading plugin '{type.FullName}'");
|
||||
_log.Error(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Plugins.ForEach(p => p.Init(_torch));
|
||||
PluginsLoaded?.Invoke(Plugins);
|
||||
Plugins.ForEach(p => p.Init(Torch));
|
||||
PluginsLoaded?.Invoke(Plugins.ToList());
|
||||
}
|
||||
|
||||
public IEnumerator<ITorchPlugin> GetEnumerator()
|
||||
|
@@ -1,28 +1,148 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.IO.Packaging;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NLog;
|
||||
using Octokit;
|
||||
using SteamSDK;
|
||||
using Torch.API;
|
||||
|
||||
namespace Torch.Managers
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles updating of the DS and Torch plugins.
|
||||
/// </summary>
|
||||
public class UpdateManager : IDisposable
|
||||
public class UpdateManager : Manager, IDisposable
|
||||
{
|
||||
private Timer _updatePollTimer;
|
||||
private GitHubClient _gitClient = new GitHubClient(new ProductHeaderValue("Torch"));
|
||||
private string _torchDir = new FileInfo(typeof(UpdateManager).Assembly.Location).DirectoryName;
|
||||
private Logger _log = LogManager.GetLogger(nameof(UpdateManager));
|
||||
private FilesystemManager _fsManager;
|
||||
|
||||
public UpdateManager()
|
||||
public UpdateManager(ITorchBase torchInstance) : base(torchInstance)
|
||||
{
|
||||
_updatePollTimer = new Timer(CheckForUpdates, this, TimeSpan.Zero, TimeSpan.FromMinutes(5));
|
||||
//_updatePollTimer = new Timer(TimerElapsed, this, TimeSpan.Zero, TimeSpan.FromMinutes(5));
|
||||
}
|
||||
|
||||
private void CheckForUpdates(object state)
|
||||
/// <inheritdoc />
|
||||
public override void Init()
|
||||
{
|
||||
|
||||
_fsManager = Torch.GetManager<FilesystemManager>();
|
||||
CheckAndUpdateTorch();
|
||||
}
|
||||
|
||||
private void TimerElapsed(object state)
|
||||
{
|
||||
CheckAndUpdateTorch();
|
||||
}
|
||||
|
||||
private async Task<Tuple<Version, string>> GetLatestRelease(string owner, string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
var latest = await _gitClient.Repository.Release.GetLatest(owner, name).ConfigureAwait(false);
|
||||
if (latest == null)
|
||||
return new Tuple<Version, string>(new Version(), null);
|
||||
|
||||
var zip = latest.Assets.FirstOrDefault(x => x.Name.Contains(".zip"));
|
||||
var versionName = Regex.Match(latest.TagName, "(\\d+\\.)+\\d+").ToString();
|
||||
return new Tuple<Version, string>(new Version(string.IsNullOrWhiteSpace(versionName) ? versionName : "0.0"), zip?.BrowserDownloadUrl);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.Error($"An error occurred getting release information for '{owner}/{name}'");
|
||||
_log.Error(e);
|
||||
return new Tuple<Version, string>(new Version(), null);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CheckAndUpdatePlugin(PluginManifest manifest)
|
||||
{
|
||||
if (!Torch.Config.GetPluginUpdates)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var name = manifest.Repository.Split('/');
|
||||
if (name.Length != 2)
|
||||
{
|
||||
_log.Error($"'{manifest.Repository}' is not a valid GitHub repository.");
|
||||
return;
|
||||
}
|
||||
|
||||
var currentVersion = new Version(manifest.Version);
|
||||
var releaseInfo = await GetLatestRelease(name[0], name[1]).ConfigureAwait(false);
|
||||
if (releaseInfo.Item1 > currentVersion)
|
||||
{
|
||||
_log.Warn($"Updating {manifest.Repository} from version {currentVersion} to version {releaseInfo.Item1}");
|
||||
var updateName = Path.Combine(_fsManager.TempDirectory, $"{name[0]}_{name[1]}.zip");
|
||||
var updatePath = Path.Combine(_torchDir, "Plugins");
|
||||
await new WebClient().DownloadFileTaskAsync(new Uri(releaseInfo.Item2), updateName).ConfigureAwait(false);
|
||||
UpdateFromZip(updateName, updatePath);
|
||||
File.Delete(updateName);
|
||||
}
|
||||
else
|
||||
{
|
||||
_log.Info($"{manifest.Repository} is up to date. ({currentVersion})");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.Error($"An error occured downloading the plugin update for {manifest.Repository}.");
|
||||
_log.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
private async void CheckAndUpdateTorch()
|
||||
{
|
||||
if (!Torch.Config.GetTorchUpdates)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var releaseInfo = await GetLatestRelease("TorchAPI", "Torch").ConfigureAwait(false);
|
||||
if (releaseInfo.Item1 > Torch.TorchVersion)
|
||||
{
|
||||
_log.Warn($"Updating Torch from version {Torch.TorchVersion} to version {releaseInfo.Item1}");
|
||||
var updateName = Path.Combine(_fsManager.TempDirectory, "torchupdate.zip");
|
||||
new WebClient().DownloadFile(new Uri(releaseInfo.Item2), updateName);
|
||||
UpdateFromZip(updateName, _torchDir);
|
||||
File.Delete(updateName);
|
||||
_log.Warn($"Torch version {releaseInfo.Item1} has been installed, please restart Torch to finish the process.");
|
||||
}
|
||||
else
|
||||
{
|
||||
_log.Info("Torch is up to date.");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.Error("An error occured downloading the Torch update.");
|
||||
_log.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateFromZip(string zipFile, string extractPath)
|
||||
{
|
||||
using (var zip = ZipFile.OpenRead(zipFile))
|
||||
{
|
||||
foreach (var file in zip.Entries)
|
||||
{
|
||||
_log.Debug($"Unzipping {file.FullName}");
|
||||
var targetFile = Path.Combine(extractPath, file.FullName);
|
||||
_fsManager.SoftDelete(targetFile);
|
||||
}
|
||||
|
||||
zip.ExtractToDirectory(extractPath);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@@ -1,15 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace Torch
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple class that manages saving <see cref="Persistent{T}.Data"/> to disk using JSON serialization.
|
||||
/// Simple class that manages saving <see cref="Persistent{T}.Data"/> to disk using XML serialization.
|
||||
/// Can automatically save on changes by implementing <see cref="INotifyPropertyChanged"/> in the data class.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Data class type</typeparam>
|
||||
public sealed class Persistent<T> : IDisposable where T : new()
|
||||
@@ -26,6 +29,13 @@ namespace Torch
|
||||
{
|
||||
Path = path;
|
||||
Data = data;
|
||||
if (Data is INotifyPropertyChanged npc)
|
||||
npc.PropertyChanged += OnPropertyChanged;
|
||||
}
|
||||
|
||||
private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
Save();
|
||||
}
|
||||
|
||||
public void Save(string path = null)
|
||||
@@ -33,11 +43,10 @@ namespace Torch
|
||||
if (path == null)
|
||||
path = Path;
|
||||
|
||||
var ser = new XmlSerializer(typeof(T));
|
||||
using (var f = File.Create(path))
|
||||
{
|
||||
var writer = new StreamWriter(f);
|
||||
writer.Write(JsonConvert.SerializeObject(Data, Formatting.Indented));
|
||||
writer.Flush();
|
||||
ser.Serialize(f, Data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,10 +56,10 @@ namespace Torch
|
||||
|
||||
if (File.Exists(path))
|
||||
{
|
||||
var ser = new XmlSerializer(typeof(T));
|
||||
using (var f = File.OpenRead(path))
|
||||
{
|
||||
var reader = new StreamReader(f);
|
||||
config.Data = JsonConvert.DeserializeObject<T>(reader.ReadToEnd());
|
||||
config.Data = (T)ser.Deserialize(f);
|
||||
}
|
||||
}
|
||||
else if (saveIfNew)
|
||||
@@ -65,6 +74,8 @@ namespace Torch
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Data is INotifyPropertyChanged npc)
|
||||
npc.PropertyChanged -= OnPropertyChanged;
|
||||
Save();
|
||||
}
|
||||
catch
|
||||
|
28
Torch/SaveGameStatus.cs
Normal file
28
Torch/SaveGameStatus.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
namespace Torch
|
||||
{
|
||||
/// <summary>
|
||||
/// Describes the possible outcomes when attempting to save the game progress.
|
||||
/// </summary>
|
||||
public enum SaveGameStatus : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// The game was saved.
|
||||
/// </summary>
|
||||
Success = 0,
|
||||
|
||||
/// <summary>
|
||||
/// A save operation is already in progress.
|
||||
/// </summary>
|
||||
SaveInProgress = 1,
|
||||
|
||||
/// <summary>
|
||||
/// The game is not in a save-able state.
|
||||
/// </summary>
|
||||
GameNotReady = 2,
|
||||
|
||||
/// <summary>
|
||||
/// The save operation timed out.
|
||||
/// </summary>
|
||||
TimedOut = 3
|
||||
};
|
||||
}
|
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SteamSDK;
|
||||
using VRage.Steam;
|
||||
using Sandbox;
|
||||
|
||||
namespace Torch
|
||||
@@ -16,34 +17,48 @@ namespace Torch
|
||||
/// </summary>
|
||||
public class SteamService : MySteamService
|
||||
{
|
||||
public SteamService(bool isDedicated, uint appId) : base(true, appId)
|
||||
public SteamService(bool isDedicated, uint appId)
|
||||
: base(true, appId)
|
||||
{
|
||||
// TODO: Add protection for this mess... somewhere
|
||||
SteamServerAPI.Instance.Dispose();
|
||||
SteamSDK.SteamServerAPI.Instance.Dispose();
|
||||
var steam = typeof(MySteamService);
|
||||
steam.GetField("SteamServerAPI").SetValue(this, null);
|
||||
|
||||
steam.GetProperty("SteamServerAPI").GetSetMethod(true).Invoke(this, new object[] { null });
|
||||
steam.GetField("m_gameServer", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).SetValue(this, null);
|
||||
|
||||
steam.GetProperty("AppId").GetSetMethod(true).Invoke(this, new object[] { appId });
|
||||
if (isDedicated)
|
||||
{
|
||||
steam.GetField("SteamServerAPI").SetValue(this, SteamServerAPI.Instance);
|
||||
steam.GetProperty("SteamServerAPI").GetSetMethod(true).Invoke(this, new object[] { null });
|
||||
steam.GetField("m_gameServer").SetValue(this, new MySteamGameServer());
|
||||
}
|
||||
else
|
||||
{
|
||||
var steamApi = SteamAPI.Instance;
|
||||
steam.GetField("SteamAPI").SetValue(this, SteamAPI.Instance);
|
||||
steam.GetProperty("IsActive").GetSetMethod(true).Invoke(this, new object[] { SteamAPI.Instance != null });
|
||||
var SteamAPI = SteamSDK.SteamAPI.Instance;
|
||||
steam.GetProperty("API").GetSetMethod(true).Invoke(this, new object[] { SteamAPI.Instance });
|
||||
steam.GetProperty("IsActive").GetSetMethod(true).Invoke(this, new object[] {
|
||||
SteamAPI.Instance.Init()
|
||||
});
|
||||
|
||||
if (steamApi != null)
|
||||
if (IsActive)
|
||||
{
|
||||
steam.GetProperty("UserId").GetSetMethod(true).Invoke(this, new object[] { steamApi.GetSteamUserId() });
|
||||
steam.GetProperty("UserName").GetSetMethod(true).Invoke(this, new object[] { steamApi.GetSteamName() });
|
||||
steam.GetProperty("OwnsGame").GetSetMethod(true).Invoke(this, new object[] { steamApi.HasGame() });
|
||||
steam.GetProperty("UserUniverse").GetSetMethod(true).Invoke(this, new object[] { steamApi.GetSteamUserUniverse() });
|
||||
steam.GetProperty("BranchName").GetSetMethod(true).Invoke(this, new object[] { steamApi.GetBranchName() });
|
||||
steamApi.LoadStats();
|
||||
steam.GetProperty("UserId").GetSetMethod(true).Invoke(this, new object[] { SteamAPI.GetSteamUserId() });
|
||||
steam.GetProperty("UserName").GetSetMethod(true).Invoke(this, new object[] { SteamAPI.GetSteamName() });
|
||||
steam.GetProperty("OwnsGame").GetSetMethod(true).Invoke(this, new object[] { SteamAPI.HasGame() });
|
||||
steam.GetProperty("UserUniverse").GetSetMethod(true).Invoke(this, new object[] { SteamAPI.GetSteamUserUniverse() });
|
||||
steam.GetProperty("BranchName").GetSetMethod(true).Invoke(this, new object[] { SteamAPI.GetBranchName() });
|
||||
SteamAPI.LoadStats();
|
||||
|
||||
steam.GetProperty("InventoryAPI").GetSetMethod(true).Invoke(this, new object[] { new MySteamInventory() });
|
||||
|
||||
steam.GetMethod("RegisterCallbacks",
|
||||
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)
|
||||
.Invoke(this, null);
|
||||
}
|
||||
}
|
||||
|
||||
steam.GetProperty("Peer2Peer").GetSetMethod(true).Invoke(this, new object[] { new MySteamPeer2Peer() });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -81,6 +81,8 @@
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.IO.Compression.FileSystem" />
|
||||
<Reference Include="System.Xaml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
@@ -140,11 +142,18 @@
|
||||
<HintPath>..\GameBinaries\VRage.Scripting.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="VRage.Steam">
|
||||
<HintPath>..\..\..\..\..\..\..\steamcmd\steamapps\common\SpaceEngineersDedicatedServer\DedicatedServer64\VRage.Steam.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ChatMessage.cs" />
|
||||
<Compile Include="Collections\ObservableList.cs" />
|
||||
<Compile Include="DispatcherExtensions.cs" />
|
||||
<Compile Include="SaveGameStatus.cs" />
|
||||
<Compile Include="Collections\KeyTree.cs" />
|
||||
<Compile Include="Collections\ObservableDictionary.cs" />
|
||||
<Compile Include="Collections\RollingAverage.cs" />
|
||||
<Compile Include="CommandLine.cs" />
|
||||
<Compile Include="Commands\CategoryAttribute.cs" />
|
||||
@@ -159,19 +168,19 @@
|
||||
<Compile Include="Commands\TorchCommands.cs" />
|
||||
<Compile Include="Managers\ChatManager.cs" />
|
||||
<Compile Include="Managers\EntityManager.cs" />
|
||||
<Compile Include="Managers\FilesystemManager.cs" />
|
||||
<Compile Include="Managers\Manager.cs" />
|
||||
<Compile Include="Managers\NetworkManager\NetworkHandlerBase.cs" />
|
||||
<Compile Include="Managers\NetworkManager\NetworkManager.cs" />
|
||||
<Compile Include="Managers\MultiplayerManager.cs" />
|
||||
<Compile Include="Managers\UpdateManager.cs" />
|
||||
<Compile Include="Persistent.cs" />
|
||||
<Compile Include="Updater\PluginManifest.cs" />
|
||||
<Compile Include="PluginManifest.cs" />
|
||||
<Compile Include="Reflection.cs" />
|
||||
<Compile Include="Managers\ScriptingManager.cs" />
|
||||
<Compile Include="TorchBase.cs" />
|
||||
<Compile Include="SteamService.cs" />
|
||||
<Compile Include="TorchPluginBase.cs" />
|
||||
<Compile Include="Updater\PluginUpdater.cs" />
|
||||
<Compile Include="ViewModels\ModViewModel.cs" />
|
||||
<Compile Include="Collections\MTObservableCollection.cs" />
|
||||
<Compile Include="Extensions\MyPlayerCollectionExtensions.cs" />
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
@@ -41,22 +41,38 @@ namespace Torch
|
||||
/// Use only if necessary, prefer dependency injection.
|
||||
/// </summary>
|
||||
public static ITorchBase Instance { get; private set; }
|
||||
/// <inheritdoc />
|
||||
public ITorchConfig Config { get; protected set; }
|
||||
protected static Logger Log { get; } = LogManager.GetLogger("Torch");
|
||||
/// <inheritdoc />
|
||||
public Version TorchVersion { get; protected set; }
|
||||
/// <inheritdoc />
|
||||
public Version GameVersion { get; private set; }
|
||||
/// <inheritdoc />
|
||||
public string[] RunArgs { get; set; }
|
||||
/// <inheritdoc />
|
||||
public IPluginManager Plugins { get; protected set; }
|
||||
/// <inheritdoc />
|
||||
public IMultiplayerManager Multiplayer { get; protected set; }
|
||||
/// <inheritdoc />
|
||||
public EntityManager Entities { get; protected set; }
|
||||
/// <inheritdoc />
|
||||
public INetworkManager Network { get; protected set; }
|
||||
/// <inheritdoc />
|
||||
public CommandManager Commands { get; protected set; }
|
||||
/// <inheritdoc />
|
||||
public event Action SessionLoading;
|
||||
/// <inheritdoc />
|
||||
public event Action SessionLoaded;
|
||||
/// <inheritdoc />
|
||||
public event Action SessionUnloading;
|
||||
/// <inheritdoc />
|
||||
public event Action SessionUnloaded;
|
||||
private readonly List<IManager> _managers;
|
||||
|
||||
/// <summary>
|
||||
/// Common log for the Torch instance.
|
||||
/// </summary>
|
||||
protected static Logger Log { get; } = LogManager.GetLogger("Torch");
|
||||
private readonly List<IManager> _managers;
|
||||
private bool _init;
|
||||
|
||||
/// <summary>
|
||||
@@ -79,22 +95,25 @@ namespace Torch
|
||||
Network = new NetworkManager(this);
|
||||
Commands = new CommandManager(this);
|
||||
|
||||
_managers = new List<IManager> {Network, Commands, Plugins, Multiplayer, Entities, new ChatManager(this)};
|
||||
_managers = new List<IManager> { new FilesystemManager(this), new UpdateManager(this), Network, Commands, Plugins, Multiplayer, Entities, new ChatManager(this), };
|
||||
|
||||
|
||||
TorchAPI.Instance = this;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ListReader<IManager> GetManagers()
|
||||
{
|
||||
return new ListReader<IManager>(_managers);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public T GetManager<T>() where T : class, IManager
|
||||
{
|
||||
return _managers.FirstOrDefault(m => m is T) as T;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool AddManager<T>(T manager) where T : class, IManager
|
||||
{
|
||||
if (_managers.Any(x => x is T))
|
||||
@@ -109,33 +128,31 @@ namespace Torch
|
||||
return Thread.CurrentThread.ManagedThreadId == MySandboxGame.Static.UpdateThread.ManagedThreadId;
|
||||
}
|
||||
|
||||
public async Task SaveGameAsync()
|
||||
public Task SaveGameAsync(Action<SaveGameStatus> callback)
|
||||
{
|
||||
Log.Info("Saving game");
|
||||
if (MySandboxGame.IsGameReady && !MyAsyncSaving.InProgress && Sync.IsServer && !(MySession.Static.LocalCharacter?.IsDead ?? true))
|
||||
|
||||
if (!MySandboxGame.IsGameReady)
|
||||
{
|
||||
using (var e = new AutoResetEvent(false))
|
||||
{
|
||||
MyAsyncSaving.Start(() =>
|
||||
{
|
||||
MySector.ResetEyeAdaptation = true;
|
||||
e.Set();
|
||||
});
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
if (e.WaitOne(60000))
|
||||
return;
|
||||
|
||||
Log.Error("Save failed!");
|
||||
Multiplayer.SendMessage("Save timed out!", "Error");
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
callback?.Invoke(SaveGameStatus.GameNotReady);
|
||||
}
|
||||
else if(MyAsyncSaving.InProgress)
|
||||
{
|
||||
callback?.Invoke(SaveGameStatus.SaveInProgress);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error("Cannot save");
|
||||
var e = new AutoResetEvent(false);
|
||||
MyAsyncSaving.Start(() => e.Set());
|
||||
|
||||
return Task.Run(() =>
|
||||
{
|
||||
callback?.Invoke(e.WaitOne(5000) ? SaveGameStatus.Success : SaveGameStatus.TimedOut);
|
||||
e.Dispose();
|
||||
});
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
#region Game Actions
|
||||
@@ -201,6 +218,7 @@ namespace Torch
|
||||
|
||||
#endregion
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void Init()
|
||||
{
|
||||
Debug.Assert(!_init, "Torch instance is already initialized.");
|
||||
@@ -208,19 +226,9 @@ namespace Torch
|
||||
SpaceEngineersGame.SetupBasicGameInfo();
|
||||
SpaceEngineersGame.SetupPerGameSettings();
|
||||
|
||||
/*
|
||||
if (Directory.Exists("DedicatedServer64"))
|
||||
{
|
||||
Log.Debug("Inserting DedicatedServer64 before MyPerGameSettings assembly paths");
|
||||
MyPerGameSettings.GameModAssembly = $"DedicatedServer64\\{MyPerGameSettings.GameModAssembly}";
|
||||
MyPerGameSettings.GameModObjBuildersAssembly = $"DedicatedServer64\\{MyPerGameSettings.GameModObjBuildersAssembly}";
|
||||
MyPerGameSettings.SandboxAssembly = $"DedicatedServer64\\{MyPerGameSettings.SandboxAssembly}";
|
||||
MyPerGameSettings.SandboxGameAssembly = $"DedicatedServer64\\{MyPerGameSettings.SandboxGameAssembly}";
|
||||
}*/
|
||||
|
||||
TorchVersion = Assembly.GetEntryAssembly().GetName().Version;
|
||||
GameVersion = new Version(new MyVersion(MyPerGameSettings.BasicGameInfo.GameVersion.Value).FormattedText.ToString().Replace("_", "."));
|
||||
var verInfo = $"Torch {TorchVersion}, SE {GameVersion}";
|
||||
var verInfo = $"{Config.InstanceName} - Torch {TorchVersion}, SE {GameVersion}";
|
||||
Console.Title = verInfo;
|
||||
#if DEBUG
|
||||
Log.Info("DEBUG");
|
||||
@@ -231,15 +239,40 @@ namespace Torch
|
||||
Log.Info($"Executing assembly: {Assembly.GetEntryAssembly().FullName}");
|
||||
Log.Info($"Executing directory: {AppDomain.CurrentDomain.BaseDirectory}");
|
||||
|
||||
MySession.OnLoading += () => SessionLoading?.Invoke();
|
||||
MySession.AfterLoading += () => SessionLoaded?.Invoke();
|
||||
MySession.OnUnloading += () => SessionUnloading?.Invoke();
|
||||
MySession.OnUnloaded += () => SessionUnloaded?.Invoke();
|
||||
MySession.OnLoading += OnSessionLoading;
|
||||
MySession.AfterLoading += OnSessionLoaded;
|
||||
MySession.OnUnloading += OnSessionUnloading;
|
||||
MySession.OnUnloaded += OnSessionUnloaded;
|
||||
RegisterVRagePlugin();
|
||||
|
||||
foreach (var manager in _managers)
|
||||
manager.Init();
|
||||
_init = true;
|
||||
}
|
||||
|
||||
private void OnSessionLoading()
|
||||
{
|
||||
Log.Debug("Session loading");
|
||||
SessionLoading?.Invoke();
|
||||
}
|
||||
|
||||
private void OnSessionLoaded()
|
||||
{
|
||||
Log.Debug("Session loaded");
|
||||
SessionLoaded?.Invoke();
|
||||
}
|
||||
|
||||
private void OnSessionUnloading()
|
||||
{
|
||||
Log.Debug("Session unloading");
|
||||
SessionUnloading?.Invoke();
|
||||
}
|
||||
|
||||
private void OnSessionUnloaded()
|
||||
{
|
||||
Log.Debug("Session unloaded");
|
||||
SessionUnloaded?.Invoke();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hook into the VRage plugin system for updates.
|
||||
/// </summary>
|
||||
@@ -253,12 +286,29 @@ namespace Torch
|
||||
pluginList.Add(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual Task Save(long callerId)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void Stop() { }
|
||||
/// <inheritdoc />
|
||||
public virtual void Stop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void Restart()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void Dispose()
|
||||
@@ -269,8 +319,7 @@ namespace Torch
|
||||
/// <inheritdoc />
|
||||
public virtual void Init(object gameInstance)
|
||||
{
|
||||
foreach (var manager in _managers)
|
||||
manager.Init();
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@@ -1,93 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NLog;
|
||||
using Octokit;
|
||||
using Torch.API;
|
||||
using Torch.Managers;
|
||||
using VRage.Compression;
|
||||
|
||||
namespace Torch.Updater
|
||||
{
|
||||
public class PluginUpdater
|
||||
{
|
||||
private readonly PluginManager _pluginManager;
|
||||
private static readonly Logger Log = LogManager.GetLogger("PluginUpdater");
|
||||
|
||||
public PluginUpdater(PluginManager pm)
|
||||
{
|
||||
_pluginManager = pm;
|
||||
}
|
||||
|
||||
public async Task CheckAndUpdate(PluginManifest manifest, bool force = false)
|
||||
{
|
||||
Log.Info($"Checking for update at {manifest.Repository}");
|
||||
var split = manifest.Repository.Split('/');
|
||||
|
||||
if (split.Length != 2)
|
||||
{
|
||||
Log.Warn($"Manifest has an invalid repository name: {manifest.Repository}");
|
||||
return;
|
||||
}
|
||||
|
||||
var gitClient = new GitHubClient(new ProductHeaderValue("Torch"));
|
||||
var releases = await gitClient.Repository.Release.GetAll(split[0], split[1]).ConfigureAwait(false);
|
||||
|
||||
if (releases.Count == 0)
|
||||
{
|
||||
Log.Debug("No releases in repo");
|
||||
return;
|
||||
}
|
||||
|
||||
Version currentVersion;
|
||||
Version latestVersion;
|
||||
|
||||
try
|
||||
{
|
||||
currentVersion = new Version(manifest.Version);
|
||||
latestVersion = new Version(releases[0].TagName);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Log.Warn("Invalid version number on manifest or GitHub release");
|
||||
return;
|
||||
}
|
||||
|
||||
if (force || latestVersion > currentVersion)
|
||||
{
|
||||
var webClient = new WebClient();
|
||||
var assets = await gitClient.Repository.Release.GetAllAssets(split[0], split[1], releases[0].Id).ConfigureAwait(false);
|
||||
foreach (var asset in assets)
|
||||
{
|
||||
if (asset.Name.EndsWith(".zip"))
|
||||
{
|
||||
Log.Debug(asset.BrowserDownloadUrl);
|
||||
var localPath = Path.Combine(Path.GetTempPath(), asset.Name);
|
||||
await webClient.DownloadFileTaskAsync(new Uri(asset.BrowserDownloadUrl), localPath).ConfigureAwait(false);
|
||||
UnzipPlugin(localPath);
|
||||
Log.Info($"Downloaded update for {manifest.Repository}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Info($"{manifest.Repository} is up to date.");
|
||||
}
|
||||
}
|
||||
|
||||
public void UnzipPlugin(string zipName)
|
||||
{
|
||||
if (!File.Exists(zipName))
|
||||
return;
|
||||
|
||||
MyZipArchive.ExtractToDirectory(zipName, _pluginManager.PluginDir);
|
||||
}
|
||||
}
|
||||
}
|
@@ -3,8 +3,10 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Sandbox.Engine.Multiplayer;
|
||||
using SteamSDK;
|
||||
using Torch.API;
|
||||
using VRage.Replication;
|
||||
|
||||
namespace Torch.ViewModels
|
||||
{
|
||||
@@ -18,7 +20,7 @@ namespace Torch.ViewModels
|
||||
public PlayerViewModel(ulong steamId, string name = null)
|
||||
{
|
||||
SteamId = steamId;
|
||||
Name = name ?? SteamAPI.Instance?.Friends?.GetPersonaName(steamId) ?? "???";
|
||||
Name = name ?? ((MyDedicatedServerBase)MyMultiplayerMinimalBase.Instance).GetMemberName(steamId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ namespace Torch
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected void OnPropertyChanged([CallerMemberName] string propName = "")
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propName = "")
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
|
||||
}
|
||||
|
1
docs/_config.yml
Normal file
1
docs/_config.yml
Normal file
@@ -0,0 +1 @@
|
||||
theme: jekyll-theme-modernist
|
1
docs/index.md
Normal file
1
docs/index.md
Normal file
@@ -0,0 +1 @@
|
||||
# Torch
|
Reference in New Issue
Block a user