From f2ec79a286bdaca6ff445346b84977bfda40b9ce Mon Sep 17 00:00:00 2001 From: John Michael Gross Date: Fri, 16 Sep 2016 19:57:18 -0700 Subject: [PATCH] Basic framework - server loader, plugin manager, chat interface --- Piston.sln | 36 ++++ Piston/Logger.cs | 29 +++ Piston/MyPlayerCollectionExtensions.cs | 19 ++ Piston/Piston.csproj | 113 ++++++++++-- Piston/PluginManager.cs | 135 ++++++++++++++ PistonAPI/IPistonPlugin.cs | 16 ++ Piston/Class1.cs => PistonAPI/PistonAPI.cs | 5 +- PistonAPI/PistonAPI.csproj | 77 ++++++++ PistonAPI/Properties/AssemblyInfo.cs | 36 ++++ PistonClient/App.config | 6 + PistonClient/App.xaml | 9 + PistonClient/App.xaml.cs | 17 ++ PistonClient/MainWindow.xaml | 12 ++ PistonClient/MainWindow.xaml.cs | 28 +++ PistonClient/PistonClient.csproj | 127 +++++++++++++ PistonClient/Properties/AssemblyInfo.cs | 55 ++++++ PistonClient/Properties/Resources.Designer.cs | 63 +++++++ PistonClient/Properties/Resources.resx | 117 ++++++++++++ PistonClient/Properties/Settings.Designer.cs | 26 +++ PistonClient/Properties/Settings.settings | 7 + PistonServer/ChatControl.xaml | 15 ++ PistonServer/ChatControl.xaml.cs | 70 +++++++ PistonServer/MainWindow.xaml | 32 ++++ PistonServer/MainWindow.xaml.cs | 77 ++++++++ PistonServer/PistonServer.csproj | 173 ++++++++++++++++++ PistonServer/PlayersControl.xaml | 15 ++ PistonServer/PlayersControl.xaml.cs | 28 +++ PistonServer/Program.cs | 43 +++++ PistonServer/Properties/AssemblyInfo.cs | 55 ++++++ PistonServer/Properties/Resources.Designer.cs | 63 +++++++ PistonServer/Properties/Resources.resx | 117 ++++++++++++ PistonServer/Properties/Settings.Designer.cs | 26 +++ PistonServer/Properties/Settings.settings | 7 + PistonServer/ServerManager.cs | 126 +++++++++++++ PistonServer/SpaceEngineers.ico | Bin 0 -> 32038 bytes 35 files changed, 1758 insertions(+), 22 deletions(-) create mode 100644 Piston/Logger.cs create mode 100644 Piston/MyPlayerCollectionExtensions.cs create mode 100644 Piston/PluginManager.cs create mode 100644 PistonAPI/IPistonPlugin.cs rename Piston/Class1.cs => PistonAPI/PistonAPI.cs (71%) create mode 100644 PistonAPI/PistonAPI.csproj create mode 100644 PistonAPI/Properties/AssemblyInfo.cs create mode 100644 PistonClient/App.config create mode 100644 PistonClient/App.xaml create mode 100644 PistonClient/App.xaml.cs create mode 100644 PistonClient/MainWindow.xaml create mode 100644 PistonClient/MainWindow.xaml.cs create mode 100644 PistonClient/PistonClient.csproj create mode 100644 PistonClient/Properties/AssemblyInfo.cs create mode 100644 PistonClient/Properties/Resources.Designer.cs create mode 100644 PistonClient/Properties/Resources.resx create mode 100644 PistonClient/Properties/Settings.Designer.cs create mode 100644 PistonClient/Properties/Settings.settings create mode 100644 PistonServer/ChatControl.xaml create mode 100644 PistonServer/ChatControl.xaml.cs create mode 100644 PistonServer/MainWindow.xaml create mode 100644 PistonServer/MainWindow.xaml.cs create mode 100644 PistonServer/PistonServer.csproj create mode 100644 PistonServer/PlayersControl.xaml create mode 100644 PistonServer/PlayersControl.xaml.cs create mode 100644 PistonServer/Program.cs create mode 100644 PistonServer/Properties/AssemblyInfo.cs create mode 100644 PistonServer/Properties/Resources.Designer.cs create mode 100644 PistonServer/Properties/Resources.resx create mode 100644 PistonServer/Properties/Settings.Designer.cs create mode 100644 PistonServer/Properties/Settings.settings create mode 100644 PistonServer/ServerManager.cs create mode 100644 PistonServer/SpaceEngineers.ico diff --git a/Piston.sln b/Piston.sln index c2561cf..6831dd3 100644 --- a/Piston.sln +++ b/Piston.sln @@ -5,16 +5,52 @@ VisualStudioVersion = 15.0.25618.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Piston", "Piston\Piston.csproj", "{7E01635C-3B67-472E-BCD6-C5539564F214}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PistonAPI", "PistonAPI\PistonAPI.csproj", "{FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PistonClient", "PistonClient\PistonClient.csproj", "{E36DF745-260B-4956-A2E8-09F08B2E7161}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PistonServer", "PistonServer\PistonServer.csproj", "{CA50886B-7B22-4CD8-93A0-C06F38D4F77D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {7E01635C-3B67-472E-BCD6-C5539564F214}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7E01635C-3B67-472E-BCD6-C5539564F214}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7E01635C-3B67-472E-BCD6-C5539564F214}.Debug|x64.ActiveCfg = Debug|x64 + {7E01635C-3B67-472E-BCD6-C5539564F214}.Debug|x64.Build.0 = Debug|x64 {7E01635C-3B67-472E-BCD6-C5539564F214}.Release|Any CPU.ActiveCfg = Release|Any CPU {7E01635C-3B67-472E-BCD6-C5539564F214}.Release|Any CPU.Build.0 = Release|Any CPU + {7E01635C-3B67-472E-BCD6-C5539564F214}.Release|x64.ActiveCfg = Release|x64 + {7E01635C-3B67-472E-BCD6-C5539564F214}.Release|x64.Build.0 = Release|x64 + {FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}.Debug|x64.ActiveCfg = Debug|x64 + {FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}.Debug|x64.Build.0 = Debug|x64 + {FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}.Release|Any CPU.Build.0 = Release|Any CPU + {FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}.Release|x64.ActiveCfg = Release|x64 + {FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}.Release|x64.Build.0 = Release|x64 + {E36DF745-260B-4956-A2E8-09F08B2E7161}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E36DF745-260B-4956-A2E8-09F08B2E7161}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E36DF745-260B-4956-A2E8-09F08B2E7161}.Debug|x64.ActiveCfg = Debug|x64 + {E36DF745-260B-4956-A2E8-09F08B2E7161}.Debug|x64.Build.0 = Debug|x64 + {E36DF745-260B-4956-A2E8-09F08B2E7161}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E36DF745-260B-4956-A2E8-09F08B2E7161}.Release|Any CPU.Build.0 = Release|Any CPU + {E36DF745-260B-4956-A2E8-09F08B2E7161}.Release|x64.ActiveCfg = Release|x64 + {E36DF745-260B-4956-A2E8-09F08B2E7161}.Release|x64.Build.0 = Release|x64 + {CA50886B-7B22-4CD8-93A0-C06F38D4F77D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CA50886B-7B22-4CD8-93A0-C06F38D4F77D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CA50886B-7B22-4CD8-93A0-C06F38D4F77D}.Debug|x64.ActiveCfg = Debug|x64 + {CA50886B-7B22-4CD8-93A0-C06F38D4F77D}.Debug|x64.Build.0 = Debug|x64 + {CA50886B-7B22-4CD8-93A0-C06F38D4F77D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CA50886B-7B22-4CD8-93A0-C06F38D4F77D}.Release|Any CPU.Build.0 = Release|Any CPU + {CA50886B-7B22-4CD8-93A0-C06F38D4F77D}.Release|x64.ActiveCfg = Release|x64 + {CA50886B-7B22-4CD8-93A0-C06F38D4F77D}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Piston/Logger.cs b/Piston/Logger.cs new file mode 100644 index 0000000..0f7ceef --- /dev/null +++ b/Piston/Logger.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Sandbox; +using VRage.Utils; + +namespace Piston +{ + public static class Logger + { + public const string Prefix = "[PISTON]"; + + public static void Write(string message) + { + var msg = $"{Prefix}: {message}"; + MySandboxGame.Log.WriteLineAndConsole(msg); + if (!MySandboxGame.Log.LogEnabled) + { + try + { + MySandboxGame.Log.AppendToClosedLog(msg); + } + catch (Exception) { } + } + } + } +} diff --git a/Piston/MyPlayerCollectionExtensions.cs b/Piston/MyPlayerCollectionExtensions.cs new file mode 100644 index 0000000..a1c77c1 --- /dev/null +++ b/Piston/MyPlayerCollectionExtensions.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Sandbox.Game.Multiplayer; +using Sandbox.Game.World; + +namespace Piston +{ + public static class MyPlayerCollectionExtensions + { + public static MyPlayer TryGetPlayerBySteamId(this MyPlayerCollection collection, ulong steamId) + { + var id = collection.GetAllPlayers().FirstOrDefault(x => x.SteamId == steamId); + return id == default(MyPlayer.PlayerId) ? null : collection.GetPlayerById(id); + } + } +} diff --git a/Piston/Piston.csproj b/Piston/Piston.csproj index 946d6b2..1ec8ac5 100644 --- a/Piston/Piston.csproj +++ b/Piston/Piston.csproj @@ -1,16 +1,17 @@ - + Debug AnyCPU - 7e01635c-3b67-472e-bcd6-c5539564f214 + {7E01635C-3B67-472E-BCD6-C5539564F214} Library Properties Piston Piston - v4.5.2 + v4.6.1 512 + true @@ -29,26 +30,99 @@ prompt 4 + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + - - - - - - - - - - - - - - + + C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\Sandbox.Common.dll + + + C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\Sandbox.Game.dll + + + C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\Sandbox.Graphics.dll + + + C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\SpaceEngineers.Game.dll + + + C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\SpaceEngineers.ObjectBuilders.dll + + + C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\SpaceEngineers.ObjectBuilders.XmlSerializers.dll + + + + + + + + + + + C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.dll + + + C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Audio.dll + + + C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Game.dll + + + C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Game.XmlSerializers.dll + + + C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Input.dll + + + C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Library.dll + + + C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Math.dll + + + C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Native.dll + + + C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.OpenVRWrapper.dll + + + C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Render.dll + + + C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Render11.dll + + + C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.Scripting.dll + - + + + + + {fba5d932-6254-4a1e-baf4-e229fa94e3c2} + PistonAPI + + - - + \ No newline at end of file diff --git a/Piston/PluginManager.cs b/Piston/PluginManager.cs new file mode 100644 index 0000000..76a3e9d --- /dev/null +++ b/Piston/PluginManager.cs @@ -0,0 +1,135 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using PistonAPI; +using Sandbox; +using VRage.Plugins; +using VRage.Collections; +using VRage.Library.Collections; + +namespace Piston +{ + public class PluginManager + { + //TODO: Disable reloading if the plugin has static elements because they prevent a full reload. + + public static PluginManager Static { get; } = new PluginManager(); + public ListReader Plugins => MyPlugins.Plugins; + + private List _plugins; + public const string PluginDir = "Plugins"; + + private PluginManager() + { + if (!Directory.Exists(PluginDir)) + Directory.CreateDirectory(PluginDir); + + GetPluginList(); + } + + private void GetPluginList() + { + _plugins = typeof(MyPlugins).GetField("m_plugins", BindingFlags.Static | BindingFlags.NonPublic)?.GetValue(null) as List; + if (_plugins == null) + { + typeof(MyPlugins).TypeInitializer.Invoke(null, null); + GetPluginList(); + } + } + + /// + /// Load a plugin into the game. + /// + /// + public void LoadPlugin(IPlugin plugin) + { + plugin.Init(MySandboxGame.Static); + _plugins.Add(plugin); + } + + /// + /// Get the names of all the subfolders in the Plugins directory. + /// + /// + public string[] GetPluginFolders() + { + var dirs = Directory.GetDirectories(PluginDir); + for (var i = 0; i < dirs.Length; i++) + { + dirs[i] = dirs[i].Substring(PluginDir.Length + 1); + } + + return dirs; + } + + /// + /// Load all plugins in the specified folder. + /// + /// Folder in the directory + public void LoadPluginFolder(string folderName) + { + var relativeDir = Path.Combine(PluginDir, folderName); + if (!Directory.Exists(relativeDir)) + throw new FileNotFoundException($"Plugin {folderName} does not exist in the Plugins folder."); + + var fileNames = Directory.GetFiles(relativeDir, "*.dll"); + + foreach (var fileName in fileNames) + { + var fullPath = Path.Combine(Directory.GetCurrentDirectory(), fileName); + var asm = Assembly.LoadFrom(fullPath); + + foreach (var type in asm.GetTypes()) + { + if (type.GetInterfaces().Contains(typeof(IPlugin))) + { + var inst = Activator.CreateInstance(type); + LoadPlugin((IPlugin)inst); + } + } + } + } + + /// + /// Unload a plugin from the game. + /// + /// + public void UnloadPlugin(IPlugin plugin) + { + _plugins.Remove(plugin); + plugin.Dispose(); + } + + /// + /// Reload a plugin. + /// + /// + /// Reload a non-Piston plugin + public void ReloadPlugin(IPlugin plugin, bool forceNonPiston = false) + { + var p = plugin as IPistonPlugin; + if (p == null && forceNonPiston) + { + plugin.Dispose(); + plugin.Init(MySandboxGame.Static); + } + else + { + p?.Reload(); + } + } + + public void ReloadAll() + { + foreach (var plugin in _plugins) + { + var p = plugin as IPistonPlugin; + p?.Reload(); + } + } + } +} diff --git a/PistonAPI/IPistonPlugin.cs b/PistonAPI/IPistonPlugin.cs new file mode 100644 index 0000000..97f547c --- /dev/null +++ b/PistonAPI/IPistonPlugin.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Threading.Tasks; +using VRage.Plugins; + +namespace PistonAPI +{ + public interface IPistonPlugin : IPlugin + { + string Name { get; } + void Reload(); + } +} diff --git a/Piston/Class1.cs b/PistonAPI/PistonAPI.cs similarity index 71% rename from Piston/Class1.cs rename to PistonAPI/PistonAPI.cs index 9f6dbdd..d25bed9 100644 --- a/Piston/Class1.cs +++ b/PistonAPI/PistonAPI.cs @@ -4,9 +4,10 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Piston +namespace PistonAPI { - public class Class1 + public static class PistonAPI { + } } diff --git a/PistonAPI/PistonAPI.csproj b/PistonAPI/PistonAPI.csproj new file mode 100644 index 0000000..3b74a12 --- /dev/null +++ b/PistonAPI/PistonAPI.csproj @@ -0,0 +1,77 @@ + + + + + Debug + AnyCPU + {FBA5D932-6254-4A1E-BAF4-E229FA94E3C2} + Library + Properties + PistonAPI + PistonAPI + v4.6.1 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + + + + + + + + + + + + C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Bin64\VRage.dll + + + + + + + + + + \ No newline at end of file diff --git a/PistonAPI/Properties/AssemblyInfo.cs b/PistonAPI/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c198d75 --- /dev/null +++ b/PistonAPI/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("PistonAPI")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("PistonAPI")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("fba5d932-6254-4a1e-baf4-e229fa94e3c2")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/PistonClient/App.config b/PistonClient/App.config new file mode 100644 index 0000000..bae5d6d --- /dev/null +++ b/PistonClient/App.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/PistonClient/App.xaml b/PistonClient/App.xaml new file mode 100644 index 0000000..ffc6794 --- /dev/null +++ b/PistonClient/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/PistonClient/App.xaml.cs b/PistonClient/App.xaml.cs new file mode 100644 index 0000000..efb1a1a --- /dev/null +++ b/PistonClient/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace PistonClient +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/PistonClient/MainWindow.xaml b/PistonClient/MainWindow.xaml new file mode 100644 index 0000000..0af9433 --- /dev/null +++ b/PistonClient/MainWindow.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/PistonClient/MainWindow.xaml.cs b/PistonClient/MainWindow.xaml.cs new file mode 100644 index 0000000..3229824 --- /dev/null +++ b/PistonClient/MainWindow.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +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; + +namespace PistonClient +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + } +} diff --git a/PistonClient/PistonClient.csproj b/PistonClient/PistonClient.csproj new file mode 100644 index 0000000..912e140 --- /dev/null +++ b/PistonClient/PistonClient.csproj @@ -0,0 +1,127 @@ + + + + + Debug + AnyCPU + {E36DF745-260B-4956-A2E8-09F08B2E7161} + WinExe + Properties + PistonClient + PistonClient + v4.6.1 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + MainWindow.xaml + Code + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + + + \ No newline at end of file diff --git a/PistonClient/Properties/AssemblyInfo.cs b/PistonClient/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..7b43e53 --- /dev/null +++ b/PistonClient/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("PistonClient")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("PistonClient")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +//In order to begin building localizable applications, set +//CultureYouAreCodingWith in your .csproj file +//inside a . For example, if you are using US english +//in your source files, set the to en-US. Then uncomment +//the NeutralResourceLanguage attribute below. Update the "en-US" in +//the line below to match the UICulture setting in the project file. + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] + + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/PistonClient/Properties/Resources.Designer.cs b/PistonClient/Properties/Resources.Designer.cs new file mode 100644 index 0000000..7ff0a64 --- /dev/null +++ b/PistonClient/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace PistonClient.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PistonClient.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/PistonClient/Properties/Resources.resx b/PistonClient/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/PistonClient/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PistonClient/Properties/Settings.Designer.cs b/PistonClient/Properties/Settings.Designer.cs new file mode 100644 index 0000000..2a893da --- /dev/null +++ b/PistonClient/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace PistonClient.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/PistonClient/Properties/Settings.settings b/PistonClient/Properties/Settings.settings new file mode 100644 index 0000000..033d7a5 --- /dev/null +++ b/PistonClient/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/PistonServer/ChatControl.xaml b/PistonServer/ChatControl.xaml new file mode 100644 index 0000000..7f8727a --- /dev/null +++ b/PistonServer/ChatControl.xaml @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/PistonServer/ChatControl.xaml.cs b/PistonServer/ChatControl.xaml.cs new file mode 100644 index 0000000..2942407 --- /dev/null +++ b/PistonServer/ChatControl.xaml.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +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.Windows.Threading; +using Piston; +using Sandbox; +using Sandbox.Engine.Multiplayer; +using Sandbox.Game.World; + +namespace PistonServer +{ + /// + /// Interaction logic for ChatControl.xaml + /// + public partial class ChatControl : UserControl + { + public event Action MessageEntered; + public ChatControl() + { + InitializeComponent(); + } + + public void MessageReceived(ulong steamId, string message, SteamSDK.ChatEntryTypeEnum chatType) + { + //Messages sent from server loop back around. + if (steamId == MyMultiplayer.Static.ServerId) + return; + + var name = MySession.Static.Players.TryGetPlayerBySteamId(steamId)?.DisplayName ?? ""; + Dispatcher.Invoke(() => AddMessage(name, message), DispatcherPriority.Normal); + } + + public void AddMessage(string sender, string message) + { + Chat.Text += $"{DateTime.Now.ToLongTimeString()} | {sender}: {message}\n"; + } + + private void SendButton_Click(object sender, RoutedEventArgs e) + { + OnMessageEntered(); + + } + + private void OnMessageEntered() + { + var text = Message.Text; + AddMessage("Server", text); + MySandboxGame.Static.Invoke(() => MyMultiplayer.Static.SendChatMessage(text)); + MessageEntered?.Invoke(Message.Text); + Message.Text = ""; + } + + private void Message_OnKeyDown(object sender, KeyEventArgs e) + { + if (e.Key == Key.Enter) + OnMessageEntered(); + } + } +} diff --git a/PistonServer/MainWindow.xaml b/PistonServer/MainWindow.xaml new file mode 100644 index 0000000..b5b0f73 --- /dev/null +++ b/PistonServer/MainWindow.xaml @@ -0,0 +1,32 @@ + + + +