From 15d6a89f9c1c252f23b8c6fd6d4516edf2c51736 Mon Sep 17 00:00:00 2001 From: John Michael Gross Date: Sun, 18 Sep 2016 07:04:32 -0700 Subject: [PATCH] Implement first iteration of players tab (chat/player list) and sketch API --- Piston/Piston.csproj | 1 + PistonAPI/IEnvironmentInfo.cs | 13 +++++ PistonAPI/IServerControls.cs | 10 ++++ PistonAPI/PistonAPI.cs | 4 +- PistonAPI/PistonAPI.csproj | 4 ++ PistonServer/ChatControl.xaml.cs | 22 ++++++-- PistonServer/MainWindow.xaml | 2 +- PistonServer/MainWindow.xaml.cs | 6 ++ PistonServer/PlayersControl.xaml | 4 +- PistonServer/PlayersControl.xaml.cs | 86 +++++++++++++++++++++++++++++ PistonServer/ServerManager.cs | 6 +- 11 files changed, 148 insertions(+), 10 deletions(-) create mode 100644 PistonAPI/IEnvironmentInfo.cs create mode 100644 PistonAPI/IServerControls.cs diff --git a/Piston/Piston.csproj b/Piston/Piston.csproj index 1ec8ac5..cece99f 100644 --- a/Piston/Piston.csproj +++ b/Piston/Piston.csproj @@ -114,6 +114,7 @@ + diff --git a/PistonAPI/IEnvironmentInfo.cs b/PistonAPI/IEnvironmentInfo.cs new file mode 100644 index 0000000..4a227fa --- /dev/null +++ b/PistonAPI/IEnvironmentInfo.cs @@ -0,0 +1,13 @@ +namespace PistonAPI +{ + public interface IEnvironmentInfo + { + EnvironmentType Type { get; } + } + + public enum EnvironmentType + { + DedicatedServer, + GameClient + } +} \ No newline at end of file diff --git a/PistonAPI/IServerControls.cs b/PistonAPI/IServerControls.cs new file mode 100644 index 0000000..a07ae50 --- /dev/null +++ b/PistonAPI/IServerControls.cs @@ -0,0 +1,10 @@ +using System.Windows.Controls; + +namespace PistonAPI +{ + public interface IServerControls + { + bool AddGUITab(string name, UserControl control); + bool RemoveGUITab(string name); + } +} \ No newline at end of file diff --git a/PistonAPI/PistonAPI.cs b/PistonAPI/PistonAPI.cs index d25bed9..4d558f8 100644 --- a/PistonAPI/PistonAPI.cs +++ b/PistonAPI/PistonAPI.cs @@ -3,11 +3,13 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Controls; namespace PistonAPI { public static class PistonAPI { - + public static IServerControls ServerControls { get; } + public static IEnvironmentInfo EnvironmentInfo { get; } } } diff --git a/PistonAPI/PistonAPI.csproj b/PistonAPI/PistonAPI.csproj index 3b74a12..f43e935 100644 --- a/PistonAPI/PistonAPI.csproj +++ b/PistonAPI/PistonAPI.csproj @@ -49,6 +49,8 @@ MinimumRecommendedRules.ruleset + + @@ -62,7 +64,9 @@ + + diff --git a/PistonServer/ChatControl.xaml.cs b/PistonServer/ChatControl.xaml.cs index 2942407..f8434a8 100644 --- a/PistonServer/ChatControl.xaml.cs +++ b/PistonServer/ChatControl.xaml.cs @@ -17,6 +17,7 @@ using Piston; using Sandbox; using Sandbox.Engine.Multiplayer; using Sandbox.Game.World; +using SteamSDK; namespace PistonServer { @@ -29,34 +30,45 @@ namespace PistonServer public ChatControl() { InitializeComponent(); + ServerManager.Static.SessionReady += InitChatHandler; } - public void MessageReceived(ulong steamId, string message, SteamSDK.ChatEntryTypeEnum chatType) + public void InitChatHandler() + { + MyMultiplayer.Static.ChatMessageReceived += MessageReceived; + } + + public void MessageReceived(ulong steamId, string message, ChatEntryTypeEnum chatType) { //Messages sent from server loop back around. if (steamId == MyMultiplayer.Static.ServerId) return; - var name = MySession.Static.Players.TryGetPlayerBySteamId(steamId)?.DisplayName ?? ""; + var name = MyMultiplayer.Static.GetMemberName(steamId); Dispatcher.Invoke(() => AddMessage(name, message), DispatcherPriority.Normal); } public void AddMessage(string sender, string message) { Chat.Text += $"{DateTime.Now.ToLongTimeString()} | {sender}: {message}\n"; + Program.UserInterface.Players.RefreshNames(); + } + + public void SendMessage(string message) + { + MyMultiplayer.Static.SendChatMessage(message); + Dispatcher.Invoke(() => AddMessage("Server", message)); } 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)); + SendMessage(text); MessageEntered?.Invoke(Message.Text); Message.Text = ""; } diff --git a/PistonServer/MainWindow.xaml b/PistonServer/MainWindow.xaml index b5b0f73..69e6342 100644 --- a/PistonServer/MainWindow.xaml +++ b/PistonServer/MainWindow.xaml @@ -19,7 +19,7 @@ - + diff --git a/PistonServer/MainWindow.xaml.cs b/PistonServer/MainWindow.xaml.cs index 4e521b6..c204c8b 100644 --- a/PistonServer/MainWindow.xaml.cs +++ b/PistonServer/MainWindow.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Linq; @@ -73,5 +74,10 @@ namespace PistonServer uiUpdate.Stop(); ServerManager.Static.StopServer(); } + + protected override void OnClosing(CancelEventArgs e) + { + ServerManager.Static.StopServer(); + } } } diff --git a/PistonServer/PlayersControl.xaml b/PistonServer/PlayersControl.xaml index 31843bd..c6453f9 100644 --- a/PistonServer/PlayersControl.xaml +++ b/PistonServer/PlayersControl.xaml @@ -7,8 +7,8 @@ mc:Ignorable="d"> -