Add promote/demote buttons to player tab.

Add player promoted event to IMultiplayerManagerServer
This commit is contained in:
Brant Martin
2019-01-03 15:41:41 -05:00
parent 34e5f4df49
commit a059d18195
9 changed files with 196 additions and 3 deletions

View File

@@ -16,6 +16,7 @@ using NLog;
using Torch;
using Sandbox;
using Sandbox.Engine.Multiplayer;
using Sandbox.Game.Gui;
using Sandbox.Game.Multiplayer;
using Sandbox.Game.World;
using Sandbox.ModAPI;
@@ -24,6 +25,7 @@ using Torch.API.Managers;
using Torch.API.Session;
using Torch.Managers;
using Torch.Server.Managers;
using Torch.Utils;
using Torch.ViewModels;
using VRage.Game.ModAPI;
@@ -37,16 +39,22 @@ namespace Torch.Server
private static readonly Logger _log = LogManager.GetCurrentClassLogger();
private ITorchServer _server;
private IMultiplayerManagerServer _mpServer;
public PlayerListControl()
{
InitializeComponent();
}
private void OnPlayerPromoted(ulong arg1, MyPromoteLevel arg2)
{
Dispatcher.InvokeAsync(() => PlayerList.Items.Refresh());
}
public void BindServer(ITorchServer server)
{
_server = server;
_server.Initialized += Server_Initialized ;
_server.Initialized += Server_Initialized;
}
private void Server_Initialized(ITorchServer obj)
@@ -61,6 +69,8 @@ namespace Torch.Server
{
case TorchSessionState.Loaded:
Dispatcher.InvokeAsync(() => DataContext = _server?.CurrentSession?.Managers.GetManager<MultiplayerManagerDedicated>());
_mpServer = _server.CurrentSession.Managers.GetManager<IMultiplayerManagerServer>();
_mpServer.PlayerPromoted += OnPlayerPromoted;
break;
case TorchSessionState.Unloading:
Dispatcher.InvokeAsync(() => DataContext = null);
@@ -93,5 +103,31 @@ namespace Torch.Server
_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);
}
}
}
}