Merge branch 'Patron'
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using VRage.Game.ModAPI;
|
||||||
|
|
||||||
namespace Torch.API.Managers
|
namespace Torch.API.Managers
|
||||||
{
|
{
|
||||||
@@ -21,6 +22,25 @@ namespace Torch.API.Managers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
void BanPlayer(ulong steamId, bool banned = true);
|
void BanPlayer(ulong steamId, bool banned = true);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Promotes user if possible.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="steamId"></param>
|
||||||
|
void PromoteUser(ulong steamId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Demotes user if possible.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="steamId"></param>
|
||||||
|
void DemoteUser(ulong steamId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a user's promote level.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="steamId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
MyPromoteLevel GetUserPromoteLevel(ulong steamId);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// List of the banned SteamID's
|
/// List of the banned SteamID's
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -42,5 +62,10 @@ namespace Torch.API.Managers
|
|||||||
/// Raised when a player is banned or unbanned. Passes SteamID of player, and true if banned, false if unbanned.
|
/// Raised when a player is banned or unbanned. Passes SteamID of player, and true if banned, false if unbanned.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
event Action<ulong, bool> PlayerBanned;
|
event Action<ulong, bool> PlayerBanned;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Raised when a player is promoted or demoted. Passes SteamID of player, and new promote level.
|
||||||
|
/// </summary>
|
||||||
|
event Action<ulong, MyPromoteLevel> PlayerPromoted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,9 +4,11 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Sandbox.Engine.Multiplayer;
|
using Sandbox.Engine.Multiplayer;
|
||||||
|
using Sandbox.Game.World;
|
||||||
using Torch.API;
|
using Torch.API;
|
||||||
using Torch.API.Managers;
|
using Torch.API.Managers;
|
||||||
using Torch.Managers;
|
using Torch.Managers;
|
||||||
|
using VRage.Game.ModAPI;
|
||||||
|
|
||||||
namespace Torch.Client.Manager
|
namespace Torch.Client.Manager
|
||||||
{
|
{
|
||||||
@@ -24,6 +26,34 @@ namespace Torch.Client.Manager
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void BanPlayer(ulong steamId, bool banned = true) => Torch.Invoke(() => MyMultiplayer.Static.BanClient(steamId, banned));
|
public void BanPlayer(ulong steamId, bool banned = true) => Torch.Invoke(() => MyMultiplayer.Static.BanClient(steamId, banned));
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void PromoteUser(ulong steamId)
|
||||||
|
{
|
||||||
|
Torch.Invoke(() =>
|
||||||
|
{
|
||||||
|
var p = MySession.Static.GetUserPromoteLevel(steamId);
|
||||||
|
if (p < MyPromoteLevel.Admin) //cannot promote to owner by design
|
||||||
|
MySession.Static.SetUserPromoteLevel(steamId, p + 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void DemoteUser(ulong steamId)
|
||||||
|
{
|
||||||
|
Torch.Invoke(() =>
|
||||||
|
{
|
||||||
|
var p = MySession.Static.GetUserPromoteLevel(steamId);
|
||||||
|
if (p > MyPromoteLevel.None && p < MyPromoteLevel.Owner) //owner cannot be demoted by design
|
||||||
|
MySession.Static.SetUserPromoteLevel(steamId, p - 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public MyPromoteLevel GetUserPromoteLevel(ulong steamId)
|
||||||
|
{
|
||||||
|
return MySession.Static.GetUserPromoteLevel(steamId);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool IsBanned(ulong steamId) => false;
|
public bool IsBanned(ulong steamId) => false;
|
||||||
|
|
||||||
@@ -41,6 +71,13 @@ namespace Torch.Client.Manager
|
|||||||
remove => throw new NotImplementedException();
|
remove => throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public event Action<ulong, MyPromoteLevel> PlayerPromoted
|
||||||
|
{
|
||||||
|
add => throw new NotImplementedException();
|
||||||
|
remove => throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override void Attach()
|
public override void Attach()
|
||||||
{
|
{
|
||||||
|
@@ -10,6 +10,7 @@ using NLog.Fluent;
|
|||||||
using Sandbox;
|
using Sandbox;
|
||||||
using Sandbox.Engine.Multiplayer;
|
using Sandbox.Engine.Multiplayer;
|
||||||
using Sandbox.Engine.Networking;
|
using Sandbox.Engine.Networking;
|
||||||
|
using Sandbox.Game.Gui;
|
||||||
using Sandbox.Game.World;
|
using Sandbox.Game.World;
|
||||||
using Steamworks;
|
using Steamworks;
|
||||||
using Torch.API;
|
using Torch.API;
|
||||||
@@ -62,6 +63,36 @@ namespace Torch.Server.Managers
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void PromoteUser(ulong steamId)
|
||||||
|
{
|
||||||
|
Torch.Invoke(() =>
|
||||||
|
{
|
||||||
|
var p = MySession.Static.GetUserPromoteLevel(steamId);
|
||||||
|
if (p < MyPromoteLevel.Admin) //cannot promote to owner by design
|
||||||
|
//MySession.Static.SetUserPromoteLevel(steamId, p + 1);
|
||||||
|
MyGuiScreenPlayers.PromoteImplementation(steamId, true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void DemoteUser(ulong steamId)
|
||||||
|
{
|
||||||
|
Torch.Invoke(() =>
|
||||||
|
{
|
||||||
|
var p = MySession.Static.GetUserPromoteLevel(steamId);
|
||||||
|
if (p > MyPromoteLevel.None && p < MyPromoteLevel.Owner) //owner cannot be demoted by design
|
||||||
|
//MySession.Static.SetUserPromoteLevel(steamId, p - 1);
|
||||||
|
MyGuiScreenPlayers.PromoteImplementation(steamId, false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public MyPromoteLevel GetUserPromoteLevel(ulong steamId)
|
||||||
|
{
|
||||||
|
return MySession.Static.GetUserPromoteLevel(steamId);
|
||||||
|
}
|
||||||
|
|
||||||
internal void RaiseClientBanned(ulong user, bool banned)
|
internal void RaiseClientBanned(ulong user, bool banned)
|
||||||
{
|
{
|
||||||
PlayerBanned?.Invoke(user, banned);
|
PlayerBanned?.Invoke(user, banned);
|
||||||
@@ -87,6 +118,14 @@ namespace Torch.Server.Managers
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public event Action<ulong, bool> PlayerBanned;
|
public event Action<ulong, bool> PlayerBanned;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public event Action<ulong, MyPromoteLevel> PlayerPromoted;
|
||||||
|
|
||||||
|
internal void RaisePromoteChanged(ulong steamId, MyPromoteLevel level)
|
||||||
|
{
|
||||||
|
PlayerPromoted?.Invoke(steamId, level);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override void Attach()
|
public override void Attach()
|
||||||
{
|
{
|
||||||
|
38
Torch.Server/Patches/PromotePatch.cs
Normal file
38
Torch.Server/Patches/PromotePatch.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using NLog;
|
||||||
|
using Sandbox.Game.World;
|
||||||
|
using Torch.Managers.PatchManager;
|
||||||
|
using VRage.Game.ModAPI;
|
||||||
|
using Torch.API.Managers;
|
||||||
|
using Torch.Server.Managers;
|
||||||
|
|
||||||
|
namespace Torch.Patches
|
||||||
|
{
|
||||||
|
[PatchShim]
|
||||||
|
internal static class PromotePatch
|
||||||
|
{
|
||||||
|
private static Logger _log = LogManager.GetCurrentClassLogger();
|
||||||
|
private static IMultiplayerManagerServer _backing;
|
||||||
|
|
||||||
|
private static IMultiplayerManagerServer ServerManager => _backing ?? (_backing = TorchBase.Instance?.CurrentSession?.Managers.GetManager<IMultiplayerManagerServer>());
|
||||||
|
|
||||||
|
public static void Patch(PatchContext ctx)
|
||||||
|
{
|
||||||
|
_log.Info("patching promote");
|
||||||
|
ctx.GetPattern(typeof(MySession).GetMethod("OnPromoteLevelSet", BindingFlags.NonPublic | BindingFlags.Static)).Prefixes.Add(typeof(PromotePatch).GetMethod(nameof(PromotePrefix)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void PromotePrefix(ulong steamId, MyPromoteLevel level)
|
||||||
|
{
|
||||||
|
if (ServerManager is MultiplayerManagerDedicated d)
|
||||||
|
d.RaisePromoteChanged(steamId, level);
|
||||||
|
else
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -227,6 +227,7 @@
|
|||||||
<Compile Include="Managers\MultiplayerManagerDedicatedPatchShim.cs" />
|
<Compile Include="Managers\MultiplayerManagerDedicatedPatchShim.cs" />
|
||||||
<Compile Include="NativeMethods.cs" />
|
<Compile Include="NativeMethods.cs" />
|
||||||
<Compile Include="Initializer.cs" />
|
<Compile Include="Initializer.cs" />
|
||||||
|
<Compile Include="Patches\PromotePatch.cs" />
|
||||||
<Compile Include="Properties\Annotations.cs" />
|
<Compile Include="Properties\Annotations.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="TorchConfig.cs" />
|
<Compile Include="TorchConfig.cs" />
|
||||||
|
@@ -46,9 +46,9 @@ namespace Torch.Server
|
|||||||
|
|
||||||
private void OnIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
|
private void OnIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
_log.Info($"VisibleChanged: {IsVisible}");
|
|
||||||
if (IsVisible)
|
if (IsVisible)
|
||||||
{
|
{
|
||||||
|
//I hate this and I hate myself. You should hate me too
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
|
@@ -6,14 +6,28 @@
|
|||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
<DockPanel>
|
<DockPanel>
|
||||||
<StackPanel DockPanel.Dock="Bottom">
|
<StackPanel DockPanel.Dock="Bottom">
|
||||||
<Button x:Name="KickButton" Content="Kick" Margin="5,5,5,5" Click="KickButton_Click"/>
|
<Grid>
|
||||||
<Button x:Name="BanButton" Content="Ban" Margin="5,5,5,5" Click="BanButton_Click"/>
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="*"/>
|
||||||
|
<RowDefinition Height="*"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
<Button x:Name="KickButton" Grid.Column="0" Grid.Row="0" Content="Kick" Margin="5,5,5,5" Click="KickButton_Click"/>
|
||||||
|
<Button x:Name="BanButton" Grid.Column="1" Grid.Row="0" Content="Ban" Margin="5,5,5,5" Click="BanButton_Click"/>
|
||||||
|
<Button x:Name="PromoteButton" Grid.Column="0" Grid.Row="1" Content ="Promote" Margin="5,5,5,5" Click="PromoteButton_OnClick"/>
|
||||||
|
<Button x:Name="DemoteButton" Grid.Column="1" Grid.Row="1" Content ="Demote" Margin="5,5,5,5" Click="DemoteButton_OnClick"/>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<ListView x:Name="PlayerList" ItemsSource="{Binding Players}" DockPanel.Dock="Top" Margin="5,5,5,5">
|
<ListView x:Name="PlayerList" ItemsSource="{Binding Players}" DockPanel.Dock="Top" Margin="5,5,5,5">
|
||||||
<ListView.ItemTemplate>
|
<ListView.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<WrapPanel>
|
<WrapPanel>
|
||||||
<TextBlock Text="{Binding Value.Name}" FontWeight="Bold"/>
|
<TextBlock Text="{Binding Value.PromotedName}" FontWeight="Bold"/>
|
||||||
<TextBlock Text=" ("/>
|
<TextBlock Text=" ("/>
|
||||||
<TextBlock Text="{Binding Value.State}"/>
|
<TextBlock Text="{Binding Value.State}"/>
|
||||||
<TextBlock Text=")"/>
|
<TextBlock Text=")"/>
|
||||||
|
@@ -16,6 +16,7 @@ using NLog;
|
|||||||
using Torch;
|
using Torch;
|
||||||
using Sandbox;
|
using Sandbox;
|
||||||
using Sandbox.Engine.Multiplayer;
|
using Sandbox.Engine.Multiplayer;
|
||||||
|
using Sandbox.Game.Gui;
|
||||||
using Sandbox.Game.Multiplayer;
|
using Sandbox.Game.Multiplayer;
|
||||||
using Sandbox.Game.World;
|
using Sandbox.Game.World;
|
||||||
using Sandbox.ModAPI;
|
using Sandbox.ModAPI;
|
||||||
@@ -24,6 +25,7 @@ using Torch.API.Managers;
|
|||||||
using Torch.API.Session;
|
using Torch.API.Session;
|
||||||
using Torch.Managers;
|
using Torch.Managers;
|
||||||
using Torch.Server.Managers;
|
using Torch.Server.Managers;
|
||||||
|
using Torch.Utils;
|
||||||
using Torch.ViewModels;
|
using Torch.ViewModels;
|
||||||
using VRage.Game.ModAPI;
|
using VRage.Game.ModAPI;
|
||||||
|
|
||||||
@@ -37,12 +39,18 @@ namespace Torch.Server
|
|||||||
private static readonly Logger _log = LogManager.GetCurrentClassLogger();
|
private static readonly Logger _log = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
private ITorchServer _server;
|
private ITorchServer _server;
|
||||||
|
private IMultiplayerManagerServer _mpServer;
|
||||||
|
|
||||||
public PlayerListControl()
|
public PlayerListControl()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnPlayerPromoted(ulong arg1, MyPromoteLevel arg2)
|
||||||
|
{
|
||||||
|
Dispatcher.InvokeAsync(() => PlayerList.Items.Refresh());
|
||||||
|
}
|
||||||
|
|
||||||
public void BindServer(ITorchServer server)
|
public void BindServer(ITorchServer server)
|
||||||
{
|
{
|
||||||
_server = server;
|
_server = server;
|
||||||
@@ -61,6 +69,8 @@ namespace Torch.Server
|
|||||||
{
|
{
|
||||||
case TorchSessionState.Loaded:
|
case TorchSessionState.Loaded:
|
||||||
Dispatcher.InvokeAsync(() => DataContext = _server?.CurrentSession?.Managers.GetManager<MultiplayerManagerDedicated>());
|
Dispatcher.InvokeAsync(() => DataContext = _server?.CurrentSession?.Managers.GetManager<MultiplayerManagerDedicated>());
|
||||||
|
_mpServer = _server.CurrentSession.Managers.GetManager<IMultiplayerManagerServer>();
|
||||||
|
_mpServer.PlayerPromoted += OnPlayerPromoted;
|
||||||
break;
|
break;
|
||||||
case TorchSessionState.Unloading:
|
case TorchSessionState.Unloading:
|
||||||
Dispatcher.InvokeAsync(() => DataContext = null);
|
Dispatcher.InvokeAsync(() => DataContext = null);
|
||||||
@@ -93,5 +103,31 @@ namespace Torch.Server
|
|||||||
_log.Warn(ex);
|
_log.Warn(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void PromoteButton_OnClick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var player = (KeyValuePair<ulong, PlayerViewModel>)PlayerList.SelectedItem;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_server.CurrentSession.Managers.GetManager<IMultiplayerManagerServer>().PromoteUser(player.Key);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_log.Warn(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DemoteButton_OnClick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var player = (KeyValuePair<ulong, PlayerViewModel>)PlayerList.SelectedItem;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_server.CurrentSession.Managers.GetManager<IMultiplayerManagerServer>().DemoteUser(player.Key);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_log.Warn(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,9 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Sandbox.Engine.Multiplayer;
|
using Sandbox.Engine.Multiplayer;
|
||||||
|
using Sandbox.Game.World;
|
||||||
using Torch.API;
|
using Torch.API;
|
||||||
|
using VRage.Game.ModAPI;
|
||||||
using VRage.Replication;
|
using VRage.Replication;
|
||||||
|
|
||||||
namespace Torch.ViewModels
|
namespace Torch.ViewModels
|
||||||
@@ -15,6 +17,19 @@ namespace Torch.ViewModels
|
|||||||
public string Name { get; }
|
public string Name { get; }
|
||||||
private ConnectionState _state;
|
private ConnectionState _state;
|
||||||
public ConnectionState State { get => _state; set { _state = value; OnPropertyChanged(); } }
|
public ConnectionState State { get => _state; set { _state = value; OnPropertyChanged(); } }
|
||||||
|
public MyPromoteLevel PromoteLevel => MySession.Static.GetUserPromoteLevel(SteamId);
|
||||||
|
|
||||||
|
public string PromotedName
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var p = PromoteLevel;
|
||||||
|
if (p <= MyPromoteLevel.None)
|
||||||
|
return Name;
|
||||||
|
else
|
||||||
|
return $"{Name} ({p})";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public PlayerViewModel(ulong steamId, string name = null)
|
public PlayerViewModel(ulong steamId, string name = null)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user