mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
Rcon Command Changes
- moved the rcon commands to the gamedata files, so they can be extended.
This commit is contained in:
parent
f3ff807cd0
commit
e7100e6323
18 changed files with 266 additions and 152 deletions
|
|
@ -47,5 +47,19 @@
|
|||
"RegionNumber": "5",
|
||||
"Description": "Japan"
|
||||
}
|
||||
],
|
||||
"RconInputModes": [
|
||||
{
|
||||
"Command": "Broadcast",
|
||||
"Description": "Broadcast"
|
||||
},
|
||||
{
|
||||
"Command": "Alert",
|
||||
"Description": "Alert (requires Pippi mod)"
|
||||
},
|
||||
{
|
||||
"Command": "Server",
|
||||
"Description": "Server (requires Pippi mod)"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -81,6 +81,14 @@
|
|||
<sys:String x:Key="DiscordBotLogLevel_Debug">Debug</sys:String>
|
||||
<!--#endregion-->
|
||||
|
||||
<!--#region Rcon Message Modes -->
|
||||
<sys:String x:Key="InputMode_Command">Command</sys:String>
|
||||
<sys:String x:Key="InputMode_Global">Global</sys:String>
|
||||
<sys:String x:Key="InputMode_Broadcast">Broadcast</sys:String>
|
||||
<sys:String x:Key="InputMode_Alert">Alert (requires Pippi mod)</sys:String>
|
||||
<sys:String x:Key="InputMode_Server">Server (requires Pippi mod)</sys:String>
|
||||
<!--#endregion-->
|
||||
|
||||
<!--#region Unit strings -->
|
||||
<sys:String x:Key="SliderUnits_Multiplier">x</sys:String>
|
||||
<sys:String x:Key="SliderUnits_Percentage">%</sys:String>
|
||||
|
|
@ -565,12 +573,6 @@
|
|||
<sys:String x:Key="RCON_ViewLogs_ErrorTitle">Can't open logs</sys:String>
|
||||
<sys:String x:Key="RCON_ViewLogs_ErrorLabel">Unable to open the logs directory at {0}. Please make sure this directory exists and that you have permission to access it.\nException: {1}</sys:String>
|
||||
|
||||
<sys:String x:Key="InputMode_Command">Command</sys:String>
|
||||
<sys:String x:Key="InputMode_Global">Global</sys:String>
|
||||
<sys:String x:Key="InputMode_Broadcast">Broadcast</sys:String>
|
||||
<sys:String x:Key="InputMode_Alert">Alert (requires Pippi mod)</sys:String>
|
||||
<sys:String x:Key="InputMode_Server">Server (requires Pippi mod)</sys:String>
|
||||
|
||||
<sys:String x:Key="ConsoleStatus_Disconnected">Disconnected</sys:String>
|
||||
<sys:String x:Key="ConsoleStatus_Connected">Connected</sys:String>
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ namespace ServerManagerTool.Lib
|
|||
{
|
||||
public static class GameData
|
||||
{
|
||||
public const string RCONINPUTMODE_COMMAND = "Command";
|
||||
|
||||
public static string MainDataFolder = Path.Combine(Environment.CurrentDirectory, Config.Default.GameDataRelativePath);
|
||||
public static string UserDataFolder = Path.Combine(Config.Default.DataPath, Config.Default.GameDataRelativePath);
|
||||
|
||||
|
|
@ -59,6 +61,17 @@ namespace ServerManagerTool.Lib
|
|||
|
||||
serverRegions = allServerRegions.ToArray();
|
||||
}
|
||||
|
||||
// rcon input modes
|
||||
gameData.RconInputModes.AddRange(userGameData.RconInputModes);
|
||||
|
||||
if (gameData.RconInputModes.Count > 0)
|
||||
{
|
||||
var modes1 = rconInputModes.ToList();
|
||||
modes1.AddRange(gameData.RconInputModes.Select(item => new ComboBoxItem { ValueMember = item.Command, DisplayMember = item.Description }));
|
||||
|
||||
rconInputModes = modes1.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public static string FriendlyNameForClass(string className, bool returnNullIfNotFound = false) => string.IsNullOrWhiteSpace(className) ? (returnNullIfNotFound ? null : string.Empty) : GlobalizedApplication.Instance.GetResourceString(className) ?? (returnNullIfNotFound ? null : className);
|
||||
|
|
@ -94,5 +107,18 @@ namespace ServerManagerTool.Lib
|
|||
|
||||
public static string FriendlyServerRegionName(string regionNumber, bool returnEmptyIfNotFound = false) => string.IsNullOrWhiteSpace(regionNumber) ? string.Empty : GlobalizedApplication.Instance.GetResourceString($"ServerRegion_{regionNumber}") ?? gameData?.ServerRegions?.FirstOrDefault(i => i.RegionNumber.Equals(regionNumber))?.Description ?? (returnEmptyIfNotFound ? string.Empty : regionNumber);
|
||||
#endregion
|
||||
|
||||
#region Rcon Message Modes
|
||||
private static ComboBoxItem[] rconInputModes = new[]
|
||||
{
|
||||
new ComboBoxItem { ValueMember=RCONINPUTMODE_COMMAND, DisplayMember=FriendlyNameForClass($"InputMode_{RCONINPUTMODE_COMMAND}") },
|
||||
};
|
||||
|
||||
public static IEnumerable<ComboBoxItem> GetAllRconInputModes() => rconInputModes.Select(m => m.Duplicate());
|
||||
|
||||
public static IEnumerable<ComboBoxItem> GetMessageRconInputModes() => rconInputModes.Where(m => !m.ValueMember.Equals(RCONINPUTMODE_COMMAND, StringComparison.OrdinalIgnoreCase)).Select(m => m.Duplicate());
|
||||
|
||||
public static string FriendlyRconInputModeName(string rconInputMode, bool returnEmptyIfNotFound = false) => string.IsNullOrWhiteSpace(rconInputMode) ? string.Empty : GlobalizedApplication.Instance.GetResourceString("InputMode_" + rconInputMode) ?? gameData?.RconInputModes?.FirstOrDefault(i => i.Command.Equals(rconInputMode))?.Description ?? (returnEmptyIfNotFound ? string.Empty : rconInputMode);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2306,17 +2306,7 @@ namespace ServerManagerTool.Lib
|
|||
|
||||
private static string GetRconMessageCommand(string commandValue)
|
||||
{
|
||||
switch (commandValue.ToLower())
|
||||
{
|
||||
case "alert":
|
||||
return ServerRcon.RCON_COMMAND_ALERT;
|
||||
|
||||
case "server":
|
||||
return ServerRcon.RCON_COMMAND_SERVER;
|
||||
|
||||
default:
|
||||
return ServerRcon.RCON_COMMAND_BROADCAST;
|
||||
}
|
||||
return commandValue.ToLower();
|
||||
}
|
||||
|
||||
public static string GetServerBackupFolder(ServerProfile profile)
|
||||
|
|
|
|||
|
|
@ -26,9 +26,6 @@ namespace ServerManagerTool.Lib
|
|||
private const string NoResponseMatch = "Server received, But no response!!";
|
||||
public const string NoResponseOutput = "NO_RESPONSE";
|
||||
|
||||
public const string RCON_COMMAND_BROADCAST = "broadcast";
|
||||
public const string RCON_COMMAND_ALERT = "alert";
|
||||
public const string RCON_COMMAND_SERVER = "server";
|
||||
public const string RCON_COMMAND_LISTPLAYERS = "listplayers";
|
||||
|
||||
public event EventHandler PlayersCollectionUpdated;
|
||||
|
|
@ -274,22 +271,13 @@ namespace ServerManagerTool.Lib
|
|||
command.suppressOutput = command.lines.Count() == 0;
|
||||
}
|
||||
|
||||
if (command?.command?.Equals(RCON_COMMAND_BROADCAST, StringComparison.OrdinalIgnoreCase) ?? false)
|
||||
foreach (var item in GameData.GetMessageRconInputModes())
|
||||
{
|
||||
LogEvent(LogEventType.Chat, command.rawCommand);
|
||||
command.suppressOutput = true;
|
||||
}
|
||||
|
||||
if (command?.command?.Equals(RCON_COMMAND_ALERT, StringComparison.OrdinalIgnoreCase) ?? false)
|
||||
{
|
||||
LogEvent(LogEventType.Chat, command.rawCommand);
|
||||
command.suppressOutput = true;
|
||||
}
|
||||
|
||||
if (command?.command?.Equals(RCON_COMMAND_SERVER, StringComparison.OrdinalIgnoreCase) ?? false)
|
||||
{
|
||||
LogEvent(LogEventType.Chat, command.rawCommand);
|
||||
command.suppressOutput = true;
|
||||
if (command?.command?.Equals(item.ValueMember, StringComparison.OrdinalIgnoreCase) ?? false)
|
||||
{
|
||||
LogEvent(LogEventType.Chat, command.rawCommand);
|
||||
command.suppressOutput = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using ServerManagerTool.Common;
|
|||
using ServerManagerTool.Common.Lib;
|
||||
using ServerManagerTool.Common.Model;
|
||||
using ServerManagerTool.Common.Utils;
|
||||
using ServerManagerTool.Lib;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
|
@ -550,13 +551,10 @@ namespace ServerManagerTool
|
|||
var selectedValue = this.RconMessageModesComboBox?.SelectedValue ?? Config.RCON_MessageCommand;
|
||||
var list = new ComboBoxItemList();
|
||||
|
||||
foreach (InputMode inputMode in Enum.GetValues(typeof(InputMode)))
|
||||
foreach (var item in GameData.GetMessageRconInputModes())
|
||||
{
|
||||
if (inputMode == InputMode.Command)
|
||||
continue;
|
||||
|
||||
var displayMember = _globalizer.GetResourceString($"InputMode_{inputMode}") ?? inputMode.ToString();
|
||||
list.Add(new Common.Model.ComboBoxItem(inputMode.ToString(), displayMember));
|
||||
item.DisplayMember = GameData.FriendlyRconInputModeName(item.ValueMember);
|
||||
list.Add(item);
|
||||
}
|
||||
|
||||
this.RconMessageModes = list;
|
||||
|
|
|
|||
|
|
@ -20,12 +20,6 @@
|
|||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<sm:ScrollToBottomAction x:Key="ScrollToBottomAction" />
|
||||
|
||||
<ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="InputModes">
|
||||
<ObjectDataProvider.MethodParameters>
|
||||
<x:Type TypeName="sm:InputMode" />
|
||||
</ObjectDataProvider.MethodParameters>
|
||||
</ObjectDataProvider>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
|
||||
|
|
@ -215,7 +209,7 @@
|
|||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Label Grid.Column="0" Content="{DynamicResource RCON_ModeLabel}"/>
|
||||
<ComboBox Name="InputModesComboBox" Grid.Column="1" ItemsSource="{Binding Source={StaticResource InputModes}}" SelectedItem="{Binding CurrentInputMode, Mode=TwoWay}" Margin="0,0,2,0"/>
|
||||
<ComboBox Name="InputModesComboBox" Grid.Column="1" ItemsSource="{Binding ElementName=RCON, Path=RconInputModes}" SelectedValue="{Binding ElementName=RCON, Path=CurrentInputMode, Mode=TwoWay}" SelectedValuePath="ValueMember" DisplayMemberPath="DisplayMember" Margin="0,0,2,0"/>
|
||||
<TextBox Name="ConsoleInput" TabIndex="0" Grid.Column="2" KeyUp="ConsoleInput_KeyUp" BorderBrush="LightGray" VerticalContentAlignment="Center" IsTabStop="True"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
using ServerManagerTool.Common.Enums;
|
||||
using ServerManagerTool.Common.Extensions;
|
||||
using ServerManagerTool.Common.Extensions;
|
||||
using ServerManagerTool.Common.Lib;
|
||||
using ServerManagerTool.Common.Model;
|
||||
using ServerManagerTool.Common.Utils;
|
||||
using ServerManagerTool.Enums;
|
||||
using ServerManagerTool.Lib;
|
||||
|
|
@ -23,15 +23,6 @@ using WPFSharp.Globalizer;
|
|||
|
||||
namespace ServerManagerTool
|
||||
{
|
||||
[TypeConverter(typeof(EnumDescriptionTypeConverter))]
|
||||
public enum InputMode
|
||||
{
|
||||
Command,
|
||||
Broadcast,
|
||||
Alert,
|
||||
Server,
|
||||
}
|
||||
|
||||
public enum InputWindowMode
|
||||
{
|
||||
None,
|
||||
|
|
@ -169,7 +160,7 @@ namespace ServerManagerTool
|
|||
private GlobalizedApplication _globalizer = GlobalizedApplication.Instance;
|
||||
|
||||
public static readonly DependencyProperty ConfigProperty = DependencyProperty.Register(nameof(Config), typeof(Config), typeof(RconWindow), new PropertyMetadata(Config.Default));
|
||||
public static readonly DependencyProperty CurrentInputModeProperty = DependencyProperty.Register(nameof(CurrentInputMode), typeof(InputMode), typeof(RconWindow), new PropertyMetadata(InputMode.Command));
|
||||
public static readonly DependencyProperty CurrentInputModeProperty = DependencyProperty.Register(nameof(CurrentInputMode), typeof(string), typeof(RconWindow), new PropertyMetadata(GameData.RCONINPUTMODE_COMMAND));
|
||||
public static readonly DependencyProperty PlayerFilteringProperty = DependencyProperty.Register(nameof(PlayerFiltering), typeof(PlayerFilterType), typeof(RconWindow), new PropertyMetadata(PlayerFilterType.Online | PlayerFilterType.Offline));
|
||||
public static readonly DependencyProperty PlayerFilterStringProperty = DependencyProperty.Register(nameof(PlayerFilterString), typeof(string), typeof(RconWindow), new PropertyMetadata(string.Empty));
|
||||
public static readonly DependencyProperty PlayerSortingProperty = DependencyProperty.Register(nameof(PlayerSorting), typeof(PlayerSortType), typeof(RconWindow), new PropertyMetadata(PlayerSortType.Online));
|
||||
|
|
@ -177,12 +168,15 @@ namespace ServerManagerTool
|
|||
public static readonly DependencyProperty RconParametersProperty = DependencyProperty.Register(nameof(RconParameters), typeof(RconParameters), typeof(RconWindow), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty ScrollOnNewInputProperty = DependencyProperty.Register(nameof(ScrollOnNewInput), typeof(bool), typeof(RconWindow), new PropertyMetadata(true));
|
||||
public static readonly DependencyProperty ServerRconProperty = DependencyProperty.Register(nameof(ServerRcon), typeof(ServerRcon), typeof(RconWindow), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty RconInputModesProperty = DependencyProperty.Register(nameof(RconInputModes), typeof(ComboBoxItemList), typeof(RconWindow), new PropertyMetadata(null));
|
||||
|
||||
public RconWindow(RconParameters parameters)
|
||||
{
|
||||
InitializeComponent();
|
||||
WindowUtils.RemoveDefaultResourceDictionary(this, Config.Default.DefaultGlobalizationFile);
|
||||
|
||||
PopulateRconInputModesComboBox();
|
||||
|
||||
this.CurrentInputWindowMode = InputWindowMode.None;
|
||||
this.PlayerFiltering = (PlayerFilterType)Config.Default.RCON_PlayerListFilter;
|
||||
this.PlayerSorting = (PlayerSortType)Config.Default.RCON_PlayerListSort;
|
||||
|
|
@ -215,8 +209,7 @@ namespace ServerManagerTool
|
|||
_globalizer.GetResourceString("RCON_Comments_Line2"),
|
||||
_globalizer.GetResourceString("RCON_Comments_Line3"),
|
||||
_globalizer.GetResourceString("RCON_Comments_Line4"),
|
||||
_globalizer.GetResourceString("RCON_Comments_Line5"),
|
||||
String.Format(_globalizer.GetResourceString("RCON_Comments_Line6"), _globalizer.GetResourceString("RCON_Help_Keyword"))
|
||||
_globalizer.GetResourceString("RCON_Comments_Line5")
|
||||
);
|
||||
|
||||
if (this.RconParameters.WindowExtents.Width > 50 && this.RconParameters.WindowExtents.Height > 50)
|
||||
|
|
@ -254,9 +247,9 @@ namespace ServerManagerTool
|
|||
set { SetValue(ConfigProperty, value); }
|
||||
}
|
||||
|
||||
public InputMode CurrentInputMode
|
||||
public string CurrentInputMode
|
||||
{
|
||||
get { return (InputMode)GetValue(CurrentInputModeProperty); }
|
||||
get { return (string)GetValue(CurrentInputModeProperty); }
|
||||
set { SetValue(CurrentInputModeProperty, value); }
|
||||
}
|
||||
|
||||
|
|
@ -301,6 +294,12 @@ namespace ServerManagerTool
|
|||
get { return (ServerRcon)GetValue(ServerRconProperty); }
|
||||
set { SetValue(ServerRconProperty, value); }
|
||||
}
|
||||
|
||||
public ComboBoxItemList RconInputModes
|
||||
{
|
||||
get { return (ComboBoxItemList)GetValue(RconInputModesProperty); }
|
||||
set { SetValue(RconInputModesProperty, value); }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Commands
|
||||
|
|
@ -557,13 +556,7 @@ namespace ServerManagerTool
|
|||
|
||||
private void ResourceDictionaryChangedEvent(object source, ResourceDictionaryChangedEventArgs e)
|
||||
{
|
||||
// refresh the InputModes combobox list
|
||||
this.InputModesComboBox.Items.Refresh();
|
||||
|
||||
// refresh the InputModes combobox value
|
||||
var currentInputMode = CurrentInputMode;
|
||||
this.InputModesComboBox.SelectedItem = null;
|
||||
this.InputModesComboBox.SelectedItem = currentInputMode;
|
||||
PopulateRconInputModesComboBox();
|
||||
}
|
||||
|
||||
protected override void OnClosed(EventArgs e)
|
||||
|
|
@ -630,26 +623,18 @@ namespace ServerManagerTool
|
|||
|
||||
if (commandText.StartsWith("/"))
|
||||
{
|
||||
effectiveMode = InputMode.Command;
|
||||
effectiveMode = GameData.RCONINPUTMODE_COMMAND;
|
||||
commandText = commandText.Substring(1);
|
||||
}
|
||||
|
||||
switch (effectiveMode)
|
||||
{
|
||||
case InputMode.Command:
|
||||
case GameData.RCONINPUTMODE_COMMAND:
|
||||
this.ServerRcon.IssueCommand(commandText);
|
||||
break;
|
||||
|
||||
case InputMode.Broadcast:
|
||||
this.ServerRcon.IssueCommand($"{ServerRcon.RCON_COMMAND_BROADCAST} {commandText}");
|
||||
break;
|
||||
|
||||
case InputMode.Alert:
|
||||
this.ServerRcon.IssueCommand($"{ServerRcon.RCON_COMMAND_ALERT} {commandText}");
|
||||
break;
|
||||
|
||||
case InputMode.Server:
|
||||
this.ServerRcon.IssueCommand($"{ServerRcon.RCON_COMMAND_SERVER} {commandText}");
|
||||
default:
|
||||
this.ServerRcon.IssueCommand($"{effectiveMode} {commandText}");
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -708,6 +693,24 @@ namespace ServerManagerTool
|
|||
this.playerListColumn.Width = new GridLength(value, GridUnitType.Pixel);
|
||||
}
|
||||
|
||||
private void PopulateRconInputModesComboBox()
|
||||
{
|
||||
var selectedValue = this.InputModesComboBox?.SelectedValue ?? GameData.RCONINPUTMODE_COMMAND;
|
||||
var list = new ComboBoxItemList();
|
||||
|
||||
foreach (var item in GameData.GetAllRconInputModes())
|
||||
{
|
||||
item.DisplayMember = GameData.FriendlyRconInputModeName(item.ValueMember);
|
||||
list.Add(item);
|
||||
}
|
||||
|
||||
this.RconInputModes = list;
|
||||
if (this.InputModesComboBox != null)
|
||||
{
|
||||
this.InputModesComboBox.SelectedValue = selectedValue;
|
||||
}
|
||||
}
|
||||
|
||||
public void SortPlayers()
|
||||
{
|
||||
this.PlayersView.SortDescriptions.Clear();
|
||||
|
|
@ -744,19 +747,23 @@ namespace ServerManagerTool
|
|||
|
||||
private IEnumerable<Inline> FormatCommandInput(ConsoleCommand command)
|
||||
{
|
||||
if (command.command.Equals(ServerRcon.RCON_COMMAND_BROADCAST, StringComparison.OrdinalIgnoreCase))
|
||||
var commandValue = command?.command?.ToLower() ?? string.Empty;
|
||||
if (string.IsNullOrWhiteSpace(commandValue))
|
||||
{
|
||||
yield return new RconOutput_Broadcast(command.args);
|
||||
yield return new LineBreak();
|
||||
}
|
||||
else if(command.command.Equals(ServerRcon.RCON_COMMAND_ALERT, StringComparison.OrdinalIgnoreCase))
|
||||
|
||||
var found = false;
|
||||
foreach (var item in GameData.GetMessageRconInputModes())
|
||||
{
|
||||
yield return new RconOutput_Broadcast(command.args);
|
||||
if (item.ValueMember.Equals(commandValue, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
found = true;
|
||||
yield return new RconOutput_Broadcast(command.args);
|
||||
}
|
||||
}
|
||||
else if(command.command.Equals(ServerRcon.RCON_COMMAND_SERVER, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
yield return new RconOutput_Broadcast(command.args);
|
||||
}
|
||||
else
|
||||
|
||||
if (!found)
|
||||
{
|
||||
yield return new RconOutput_Command($"> {command.rawCommand}");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue