Skip to content

Commit

Permalink
#63 ability to send commands manually
Browse files Browse the repository at this point in the history
  • Loading branch information
tym32167 committed Dec 3, 2016
1 parent 1dffc6b commit 51f0697
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 6 deletions.
14 changes: 12 additions & 2 deletions src/Arma3BE.Client.Infrastructure/Events/BE/BECommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using Arma3BE.Server;
using Arma3BE.Server;
using System;

namespace Arma3BE.Client.Infrastructure.Events.BE
{
Expand All @@ -14,4 +14,14 @@ public BECommand(Guid serverId, CommandType commandType, string parameters = nul
public string Parameters { get; }
public CommandType CommandType { get; }
}

public class BECustomCommand : BEMessageBase<object>
{
public string Command { get; set; }

public BECustomCommand(Guid serverId, string command) : base(serverId)
{
Command = command;
}
}
}
12 changes: 12 additions & 0 deletions src/Arma3BE.Client.Modules.BEServerModule/BEService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public ServerItem(ServerInfo info, IBEServer beServer, IEventAggregator eventAgg
BEServer.MessageHandler += BEServer_MessageHandler;

_eventAggregator.GetEvent<BEMessageEvent<BECommand>>().Subscribe(Command);
_eventAggregator.GetEvent<BEMessageEvent<BECustomCommand>>().Subscribe(CustomCommand);
}

private void BEServer_MessageHandler(object sender, EventArgs e)
Expand Down Expand Up @@ -154,6 +155,7 @@ protected override void DisposeManagedResources()
BEServer.MessageHandler -= BEServer_MessageHandler;

_eventAggregator.GetEvent<BEMessageEvent<BECommand>>().Unsubscribe(Command);
_eventAggregator.GetEvent<BEMessageEvent<BECustomCommand>>().Unsubscribe(CustomCommand);

BEServer.Disconnect();
BEServer.Dispose();
Expand Down Expand Up @@ -193,6 +195,16 @@ private void Command(BECommand command)
}
}

private void CustomCommand(BECustomCommand command)
{
var server = BEServer;

if (Info.Id == command.ServerId && server != null && server.Connected)
{
server.SendCommand(command.Command);
}
}

private void BEServer_MissionHandler(object sender, BEClientEventArgs<IEnumerable<Server.Models.Mission>> e)
{
_eventAggregator.GetEvent<BEMessageEvent<BEItemsMessage<Server.Models.Mission>>>().Publish(new BEItemsMessage<Server.Models.Mission>(e.Data, Info.Id));
Expand Down
25 changes: 22 additions & 3 deletions src/Arma3BE.Client.Modules.ChatModule/Chat/ChatControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,28 @@

</TabItem>
<TabItem Header="Console">
<ScrollViewer Name="ConsoleScrollViewer">
<TextBox Name="msgConsole" FontSize="12" IsReadOnly="True" />
</ScrollViewer>

<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>


<ScrollViewer Name="ConsoleScrollViewer" Grid.ColumnSpan="2">
<TextBox Name="msgConsole" FontSize="12" IsReadOnly="True" />
</ScrollViewer>

<TextBox Grid.Row="1" Grid.Column="0" Margin="2"
Text="{Binding CommandMessage, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Height="20" />

<Button Grid.Row="1" Grid.Column="1" Content="Send" Margin="2" Command="{Binding SendCommandMessage}" />

</Grid>
</TabItem>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Arma3BE.Server.Models;
using Arma3BEClient.Libs.ModelCompact;
using Arma3BEClient.Libs.Tools;
using Prism.Commands;
using Prism.Events;
using System;
using System.Collections.Generic;
Expand All @@ -29,8 +30,11 @@ public class ServerMonitorChatViewModel : ViewModelBase
private bool _autoScroll;
private bool _enableChat;
private string _inputMessage;
private string _commandMessage;
private List<Player> _players = new List<Player>();

public DelegateCommand SendCommandMessage { get; set; }

public ServerMonitorChatViewModel(ServerInfo serverInfo, IEventAggregator eventAggregator, ISettingsStoreSource settingsStoreSource)
{
_serverId = serverInfo.Id;
Expand Down Expand Up @@ -67,10 +71,20 @@ public ServerMonitorChatViewModel(ServerInfo serverInfo, IEventAggregator eventA
wnd.Show();
wnd.Activate();
});
}

SendCommandMessage = new DelegateCommand(() => SendCommand(), () => string.IsNullOrEmpty(CommandMessage) == false);
}


private void SendCommand()
{
var local = CommandMessage;
if (!string.IsNullOrEmpty(local))
{
_eventAggregator.GetEvent<BEMessageEvent<BECustomCommand>>()
.Publish(new BECustomCommand(_serverId, local));
}
}

private void _beServer_PlayerHandler(BEItemsMessage<Player> e)
{
Expand Down Expand Up @@ -190,6 +204,17 @@ public string InputMessage
}
}

public string CommandMessage
{
get { return _commandMessage; }
set
{
_commandMessage = value;
OnPropertyChanged(nameof(CommandMessage));
SendCommandMessage.RaiseCanExecuteChanged();
}
}

public ICommand ShowHistoryCommand { get; set; }
public event EventHandler<ServerMonitorChatViewModelEventArgs> ChatMessageEventHandler;
public event EventHandler<ServerMonitorLogViewModelEventArgs> LogMessageEventHandler;
Expand Down
1 change: 1 addition & 0 deletions src/Arma3BE.Server/Abstract/IBEServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public interface IBEServer : IDisposable

//Task SendCommandAsync(CommandType type, string parameters = null);
void SendCommand(CommandType type, string parameters = null);
void SendCommand(string command);

void Connect();
void Disconnect();
Expand Down
7 changes: 7 additions & 0 deletions src/Arma3BE.Server/BEServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ public bool Connected
public event EventHandler DisconnectHandler;
public event EventHandler MessageHandler;


public void SendCommand(string command)
{
_log.Info($"SERVER: {_host}:{_port} - TRY TO RCON CUSTOM COMMAND {command}");
_battlEyeServer.SendCommand(command);
}

public void SendCommand(CommandType type, string parameters = null)
{
_log.Info($"SERVER: {_host}:{_port} - TRY TO RCON COMMAND {type} WITH PARAMS {parameters}");
Expand Down

0 comments on commit 51f0697

Please sign in to comment.