Skip to content

Commit

Permalink
- experimental ZeroMQ code to RCON QuakeLiveTesting servers
Browse files Browse the repository at this point in the history
- show max bot count for TOXIKK when the server is currently empty
- don't try to start TOXIKK again when its window is currently minimized
- when geo-ip lookup failed, remove it from cache so it can be retried
  • Loading branch information
PredatH0r committed Jul 27, 2015
1 parent 5b08977 commit e0a9b88
Show file tree
Hide file tree
Showing 20 changed files with 525 additions and 73 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ ServerBrowser/phgp/
Main/bin/
Main/obj/
ServerBrowser/images/flags/*
packages/*
ServerBrowser/amd64/
ServerBrowser/i386/
8 changes: 6 additions & 2 deletions CreateDistribZip.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ set target=%cd%\SteamServerBrowser_%curdate%
mkdir "%target%" 2>nul
del /s /q "%target%\*"

cd "%cwd%\Main\bin\debug"
cd "%cwd%\Main\bin\x86\debug"
copy ServerBrowser.exe "%target%"
copy ServerBrowser.Core.dll "%target%"
copy QueryMaster.dll "%target%"
copy Ionic.BZip2.dll "%target%"
copy libsodium.dll "%target%"
copy libzmq.dll "%target%"
copy ZeroMQ.dll "%target%"

copy "%cwd%\ServerBrowser\bin\debug\DevExpress*.dll" "%target%"
del "%target%\*BonusSkins*"
cd "%target%"
Expand All @@ -19,7 +23,7 @@ call :CodeSigning
cd "%cwd%"
copy *.md "%target%"

del "%target%.zip"
del "%target%.zip" >nul
"c:\program files\7-Zip\7z.exe" a -tzip "%target%.zip" SteamServerBrowser_%curdate%

cd "%cwd%"
Expand Down
37 changes: 37 additions & 0 deletions Main/Main.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@
<PropertyGroup>
<ApplicationIcon>App.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="DevExpress.Utils.v15.1, Version=15.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
<Reference Include="DevExpress.XtraEditors.v15.1, Version=15.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
Expand All @@ -48,6 +66,10 @@
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="ZeroMQ, Version=4.1.0.3848, Culture=neutral, PublicKeyToken=4a9630883fd6c563, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\ZeroMQ.4.1.0.15\lib\net40\ZeroMQ.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
Expand All @@ -69,7 +91,12 @@
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="amd64\libsodium.so" />
<None Include="amd64\libzmq.so" />
<None Include="App.config" />
<None Include="i386\libsodium.so" />
<None Include="i386\libzmq.so" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand All @@ -88,6 +115,16 @@
<ItemGroup>
<EmbeddedResource Include="App.ico" />
</ItemGroup>
<ItemGroup>
<Content Include="amd64\libsodium.dll" />
<Content Include="amd64\libzmq.dll" />
<None Include="libsodium.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="libzmq.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
2 changes: 1 addition & 1 deletion Main/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Main
{
public static class Program
{
private const string Version = "1.12";
private const string Version = "1.12.2";

[STAThread]
static void Main()
Expand Down
Binary file added Main/libsodium.dll
Binary file not shown.
Binary file added Main/libzmq.dll
Binary file not shown.
4 changes: 4 additions & 0 deletions Main/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ZeroMQ" version="4.1.0.15" targetFramework="net40-Client" />
</packages>
12 changes: 12 additions & 0 deletions ServerBrowser/Games/GameExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ public virtual object GetServerCellValue(ServerRow row, string fieldName)
}
#endregion

#region GetBotCount()
public virtual int? GetBotCount(ServerRow row)
{
return row.ServerInfo != null ? row.ServerInfo.Bots : (int?)null;
}
#endregion

// player list UI

#region CustomizePlayerGridColumns()
Expand Down Expand Up @@ -181,6 +188,11 @@ public GridColumn AddColumn(GridView view, string fieldName, string caption, str
return col;
}
#endregion

public virtual void Rcon(ServerRow row, int port, string password, string command)
{
}

}
#endregion

Expand Down
108 changes: 108 additions & 0 deletions ServerBrowser/Games/QuakeLive.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.Threading;
using System.Windows.Forms;
using DevExpress.Data;
using DevExpress.Utils.Drawing.Helpers;
using DevExpress.XtraGrid.Views.Grid;
using ZeroMQ;
using ZeroMQ.Monitoring;

namespace ServerBrowser
{
Expand Down Expand Up @@ -150,5 +154,109 @@ private void SkipIntro(IntPtr win)
}
#endregion


// ZeroMQ rcon stuff

#region Rcon()

public override void Rcon(ServerRow row, int port, string password, string command)
{
using (var ctx = ZContext.Create())
{
ZSocket client, monitor;
var endpoint = new IPEndPoint(row.EndPoint.Address, port);
this.CreateClientAndMonitorSockets(ctx, endpoint, password, out client, out monitor);
using (client)
using (monitor)
{
while (true)
{
ZMessage msg = new ZMessage();
ZError err;
var poll = ZPollItem.CreateReceiver();
var ev = client.Poll(poll, ZPoll.In | ZPoll.Out | ZPoll.Err, ref msg, out err, TimeSpan.FromMilliseconds(500));
if (err == ZError.ETERM)
break;

var evMonitor = CheckMonitor(monitor);
if (evMonitor != null)
{
if (evMonitor.Item1 == ZMonitorEvents.Connected)
{
client.Send(new ZFrame("register"));
client.Send(new ZFrame(command));
return;
}
if (evMonitor.Item1 == ZMonitorEvents.Closed || evMonitor.Item1 == ZMonitorEvents.Disconnected)
return;
}

if (!ev)
continue;

while (true)
{
client.ReceiveMessage(ref msg, ZSocketFlags.DontWait, out err);
if (err != ZError.None)
{
if (err != ZError.EAGAIN)
Console.WriteLine(err);
break;
}
Console.WriteLine(msg);
}
}
}
}
}
#endregion

#region CreateClientAndMonitorSockets()
private void CreateClientAndMonitorSockets(ZContext ctx, IPEndPoint endPoint, string password, out ZSocket client, out ZSocket monitor)
{
client = new ZSocket(ctx, ZSocketType.DEALER);
monitor = new ZSocket(ctx, ZSocketType.PAIR);
client.Monitor("inproc://monitor-client", ZMonitorEvents.AllEvents);
monitor.Connect("inproc://monitor-client");

if (!string.IsNullOrEmpty(password))
{
client.PlainUserName = "rcon";
client.PlainPassword = password;
client.ZAPDomain = "rcon";
}

var ident = new Guid().ToByteArray();
client.Identity = ident;
client.SetOption(ZSocketOption.IDENTITY, ident);
client.Connect("tcp://" + endPoint);
}
#endregion

#region CheckMonitor()
private Tuple<ZMonitorEvents,object> CheckMonitor(ZSocket monitor)
{
try
{
ZMessage msg = new ZMessage();
ZError err;
monitor.ReceiveMessage(ref msg, ZSocketFlags.DontWait, out err);
if (err == ZError.EAGAIN)
return null;

var id = msg[0].ReadUInt16();
var val = msg[0].ReadUInt32();

var data = new byte[msg[1].Length];
msg[1].Read(data, 0, data.Length);

return new Tuple<ZMonitorEvents, object>((ZMonitorEvents)id, val);
}
catch (ZException)
{
return null;
}
}
#endregion
}
}
41 changes: 41 additions & 0 deletions ServerBrowser/Games/Toxikk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
using System.Threading;
using System.Windows.Forms;
using DevExpress.Data;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using QueryMaster;

namespace ServerBrowser
{
public class Toxikk : GameExtension
{
private const string MinCombatants = "p268435703";
private const string ScoreLimit = "p268435704";
private const string TimeLimit = "p268435705";
private const string IsOfficial = "s15";
Expand Down Expand Up @@ -70,6 +72,20 @@ public override object GetServerCellValue(ServerRow row, string fieldName)
}
#endregion

#region GetBotCount()
public override int? GetBotCount(ServerRow row)
{
if (row.ServerInfo == null)
return null;
int bots = row.ServerInfo.Bots;
if (bots != 0)
return bots;
if (row.Rules != null && int.TryParse(row.GetRule(MinCombatants), out bots))
return bots;
return 0;
}
#endregion

#region GetBestPlayerSC()
private decimal GetBestPlayerSC(ServerRow row)
{
Expand All @@ -90,6 +106,24 @@ private decimal GetBestPlayerSC(ServerRow row)

public override bool Connect(ServerRow server, string password, bool spectate)
{
// servers with skill restrictions neither allow connections with "steam://connect" nor with an "open ip:port" console command
if ((string) this.GetServerCellValue(server, "_skillclass") != "1-12")
{
var res = XtraMessageBox.Show("This server has a skill restriction.\nOnly the in-game browser can connect to such servers.\nLaunch TOXIKK anyway?",
"Toxikk Server", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
if (res == DialogResult.No)
return false;
if (FindToxikkWindow() == IntPtr.Zero)
{
var hWnd = StartToxikk();
if (hWnd == IntPtr.Zero)
return false;
SkipIntro(hWnd);
}
return true;
}


if (consoleKey == Keys.None)
{
using (var dlg = new KeyBindForm("Please press your Toxikk console key..."))
Expand Down Expand Up @@ -153,9 +187,16 @@ private static IntPtr FindToxikkWindow()
{
var hWnd = proc.MainWindowHandle;
Win32.RECT rect;

// wait for the main window and ignore the smaller splash screen
Win32.GetWindowRect(hWnd, out rect);
if (rect.Height >= 600)
return hWnd;

// when the window is minimized, it can't be the splash screen
var placement = Win32.GetWindowPlacement(hWnd);
if (placement.showCmd == Win32.ShowWindowCommands.Minimized)
return hWnd;
}
return IntPtr.Zero;
}
Expand Down
2 changes: 2 additions & 0 deletions ServerBrowser/GeoIpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ private void ProcessLoop()
}
catch
{
lock (this.cache)
this.cache.Remove(ipInt);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ServerBrowser/PlayerCountInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void Update()
RealPlayers = Bots = MaxPlayers = null;
else
{
Bots = row.ServerInfo.Bots;
Bots = row.GameExtension.GetBotCount(row);
MaxPlayers = row.ServerInfo.MaxPlayers;
RealPlayers = row.ServerInfo.Players;
}
Expand Down
15 changes: 15 additions & 0 deletions ServerBrowser/ServerBrowser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="ZeroMQ">
<HintPath>..\packages\ZeroMQ.4.1.0.15\lib\net40\ZeroMQ.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Games\CounterStrikeGO.cs" />
Expand Down Expand Up @@ -184,7 +188,12 @@
<EmbeddedResource Include="SkinPicker.resx">
<DependentUpon>SkinPicker.cs</DependentUpon>
</EmbeddedResource>
<None Include="amd64\libsodium.so" />
<None Include="amd64\libzmq.so" />
<None Include="app.config" />
<None Include="i386\libsodium.so" />
<None Include="i386\libzmq.so" />
<None Include="packages.config" />
<None Include="Properties\DataSources\Form1.ServerRow.datasource" />
<None Include="Properties\DataSources\QueryMaster.Player.datasource" />
<None Include="Properties\DataSources\QueryMaster.Rule.datasource" />
Expand Down Expand Up @@ -224,6 +233,12 @@
<ItemGroup>
<Folder Include="DLL\" />
</ItemGroup>
<ItemGroup>
<Content Include="amd64\libsodium.dll" />
<Content Include="amd64\libzmq.dll" />
<Content Include="i386\libsodium.dll" />
<Content Include="i386\libzmq.dll" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy "$(ProjectDir)\DLL\*BonusSkin*.dll" "$(TargetDir)"</PostBuildEvent>
Expand Down
Loading

0 comments on commit e0a9b88

Please sign in to comment.