Skip to content

Commit

Permalink
- Added another server
Browse files Browse the repository at this point in the history
- Added interface selection, filtering devices having a defined NetMask
-Start button gets disabled when starting Serve and enabled when exited
-Added another server
  • Loading branch information
Pablo Bernal Modino committed Dec 19, 2018
1 parent c80b331 commit 06330ef
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 23 deletions.
14 changes: 0 additions & 14 deletions LanPlayGui.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ VisualStudioVersion = 15.0.28307.102
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LanPlayGui", "LanPlayGui\LanPlayGui.csproj", "{4B020714-89B6-4AB6-9785-597E9CF5FDB4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SyncBindingSourceLib", "SyncBindingSourceLib\SyncBindingSourceLib.csproj", "{A116588A-717B-40EC-96A1-D19984FD8C80}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -29,18 +27,6 @@ Global
{4B020714-89B6-4AB6-9785-597E9CF5FDB4}.Release|x64.Build.0 = Release|x64
{4B020714-89B6-4AB6-9785-597E9CF5FDB4}.Release|x86.ActiveCfg = Release|x86
{4B020714-89B6-4AB6-9785-597E9CF5FDB4}.Release|x86.Build.0 = Release|x86
{A116588A-717B-40EC-96A1-D19984FD8C80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A116588A-717B-40EC-96A1-D19984FD8C80}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A116588A-717B-40EC-96A1-D19984FD8C80}.Debug|x64.ActiveCfg = Debug|x64
{A116588A-717B-40EC-96A1-D19984FD8C80}.Debug|x64.Build.0 = Debug|x64
{A116588A-717B-40EC-96A1-D19984FD8C80}.Debug|x86.ActiveCfg = Debug|x86
{A116588A-717B-40EC-96A1-D19984FD8C80}.Debug|x86.Build.0 = Debug|x86
{A116588A-717B-40EC-96A1-D19984FD8C80}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A116588A-717B-40EC-96A1-D19984FD8C80}.Release|Any CPU.Build.0 = Release|Any CPU
{A116588A-717B-40EC-96A1-D19984FD8C80}.Release|x64.ActiveCfg = Release|x64
{A116588A-717B-40EC-96A1-D19984FD8C80}.Release|x64.Build.0 = Release|x64
{A116588A-717B-40EC-96A1-D19984FD8C80}.Release|x86.ActiveCfg = Release|x86
{A116588A-717B-40EC-96A1-D19984FD8C80}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
24 changes: 24 additions & 0 deletions LanPlayGui/Extensions/ControlExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LanPlayGui.Extensions
{
public static class ControlExtensions
{
public static void InvokeIfRequired<T>(this T c, Action<T> action) where T : Control
{
if (c.InvokeRequired)
{
c.Invoke(new Action(() => action(c)));
}
else
{
action(c);
}
}
}
}
7 changes: 1 addition & 6 deletions LanPlayGui/LanPlayGui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Extensions\ControlExtensions.cs" />
<Compile Include="Extensions\HttpContentExtensions.cs" />
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
Expand Down Expand Up @@ -158,11 +159,5 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SyncBindingSourceLib\SyncBindingSourceLib.csproj">
<Project>{a116588a-717b-40ec-96a1-d19984fd8c80}</Project>
<Name>SyncBindingSourceLib</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
1 change: 1 addition & 0 deletions LanPlayGui/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 22 additions & 2 deletions LanPlayGui/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using LanPlayGui.Extensions;

namespace LanPlayGui
{
Expand All @@ -32,7 +33,18 @@ public MainForm()
private async void Form1_LoadAsync(object sender, EventArgs e)
{
// Retrieve the device list from the local machine
IList<LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine;
IList<LivePacketDevice> allDevices = new List<LivePacketDevice>();
try
{
allDevices = LivePacketDevice.AllLocalMachine;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "WinPcap not found", MessageBoxButtons.OK);
button1.Enabled = false;
Close();
}


if (allDevices.Count == 0)
{
Expand Down Expand Up @@ -97,7 +109,8 @@ private async void DownloadOrUpdateLanPlay()

private void InitializeComboBox(IList<LivePacketDevice> allDevices)
{
interfaceSource.DataSource = new BindingList<LivePacketDevice>(allDevices);
interfaceSource.DataSource = new BindingList<LivePacketDevice>(allDevices
.Where(i => i.Addresses.Any(a => a.Netmask.Family != SocketAddressFamily.Unspecified)).ToList());
comboBox1.DisplayMember = "Description";
comboBox1.DataSource = interfaceSource;
comboBox1.DropDownWidth = DropDownWidth(comboBox1);
Expand Down Expand Up @@ -141,6 +154,13 @@ private void Button1_Click(object sender, EventArgs e)
string value = (comboBox1.SelectedValue as LivePacketDevice).Name;
value = value.Substring(value.IndexOf('\\'));
lanPlayService.Start(currentServer, value);
lanPlayService.Exited += LanPlayService_Exited;
button1.Enabled = false;
}

private void LanPlayService_Exited(object sender, EventArgs e)
{
button1.InvokeIfRequired(b => b.Enabled = true);
}

private void DataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
Expand Down
9 changes: 9 additions & 0 deletions LanPlayGui/Service/LanPlayService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,18 @@ public class LanPlayService
private HttpClient httpClient = new HttpClient();
private Process lanPlayProcess;

public event EventHandler Exited;

public void Start(ILanPlayServer server, string interfaceName)
{
lanPlayProcess = Process.Start(executableName, $"--relay-server-addr {server.Uri.AbsoluteUri} --netif {interfaceName}");
lanPlayProcess.EnableRaisingEvents = true;
lanPlayProcess.Exited += LanPlayProcess_Exited;
}

private void LanPlayProcess_Exited(object sender, EventArgs e)
{
Exited?.Invoke(this, e);
}

public void Stop()
Expand Down
3 changes: 2 additions & 1 deletion LanPlayGui/serverlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ memehouse.de:11451
relay.it-cybergate.club:11451
euplay.secretalgorithm.com:11451
slp.rush-hour.wo.tc:11451
lithium2g.ddns.net:11451
lithium2g.ddns.net:11451
35.236.10.223:11451

0 comments on commit 06330ef

Please sign in to comment.