Skip to content

Commit

Permalink
- allow custom master server addresses
Browse files Browse the repository at this point in the history
- fixed exception when custom master returns non-Toxikk servers despite filtering for Toxikk
  • Loading branch information
PredatH0r committed Jun 9, 2015
1 parent 49bb530 commit 3b1a44e
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 55 deletions.
2 changes: 1 addition & 1 deletion QueryMaster/QueryMaster/MasterServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class MasterServer
private static readonly IPEndPoint SeedEndpoint = new IPEndPoint(IPAddress.Any, 0);
private readonly IPEndPoint endPoint;

internal MasterServer(IPEndPoint endPoint)
public MasterServer(IPEndPoint endPoint)
{
this.endPoint = endPoint;
this.Retries = 5;
Expand Down
12 changes: 12 additions & 0 deletions ServerBrowser/Properties/Settings.Designer.cs

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

3 changes: 3 additions & 0 deletions ServerBrowser/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
<Setting Name="FavGameIDs" Type="System.String" Scope="User">
<Value Profile="(Default)">324810,328070,440</Value>
</Setting>
<Setting Name="MasterServer" Type="System.String" Scope="User">
<Value Profile="(Default)">hl2master.steampowered.com:27011</Value>
</Setting>
</Settings>
</SettingsFile>
188 changes: 141 additions & 47 deletions ServerBrowser/ServerBrowserForm.Designer.cs

Large diffs are not rendered by default.

78 changes: 72 additions & 6 deletions ServerBrowser/ServerBrowserForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ protected override void OnLoad(EventArgs e)
protected override void OnClosed(EventArgs e)
{
Properties.Settings.Default.InitialGameID = (int) this.SteamAppID;
Properties.Settings.Default.MasterServer = this.comboMasterServer.Text;
Properties.Settings.Default.Save();

this.shutdown = true;
Expand Down Expand Up @@ -203,6 +204,11 @@ private void InitAppSettings()
{
InitFavGameRadioButtons();
this.SteamAppID = (Game)Properties.Settings.Default.InitialGameID;

var info = Properties.Settings.Default.MasterServer;
if (string.IsNullOrEmpty(info))
info = "hl2master.steampowered.com:27011";
this.comboMasterServer.Text = info;
}
#endregion

Expand Down Expand Up @@ -274,6 +280,22 @@ private Game SteamAppID
}
#endregion

#region MasterServerEndpoint
private IPEndPoint MasterServerEndpoint
{
get
{
string info = this.comboMasterServer.Text;
var parts = info.Split(':');
int port;
if (parts.Length < 2 || !int.TryParse(parts[1], out port))
port = 27011;
var ips = Dns.GetHostAddresses(parts[0]);
return ips.Length == 0 ? new IPEndPoint(IPAddress.None, 0) : new IPEndPoint(ips[0], port);
}
}
#endregion

#region CreatedColumnsForGameExtender()
private void CreatedColumnsForGameExtender()
{
Expand Down Expand Up @@ -309,7 +331,7 @@ private void UpdateServerList()
this.gcServers.DataSource = this.servers;
this.gvServers.EndDataUpdate();

MasterServer master = MasterQuery.GetMasterServerInstance(EngineType.Source);
MasterServer master = new MasterServer(this.MasterServerEndpoint);
master.GetAddressesLimit = maxResults;
IpFilter filter = new IpFilter();
filter.App = this.SteamAppID;
Expand Down Expand Up @@ -426,9 +448,9 @@ private bool UpdateServerInfo(ServerRow row, Server server, int requestId)
#endregion

#region UpdatePlayers()
private bool UpdatePlayers(ServerRow row, Server server, int requestId)
private void UpdatePlayers(ServerRow row, Server server, int requestId)
{
return UpdateDetail(row, server, requestId, retryHandler =>
UpdateDetail(row, server, requestId, retryHandler =>
{
var players = server.GetPlayers(retryHandler);
row.Players = players == null ? null : new List<Player>(players);
Expand All @@ -437,11 +459,11 @@ private bool UpdatePlayers(ServerRow row, Server server, int requestId)
#endregion

#region UpdateRules()
private bool UpdateRules(ServerRow row, Server server, int requestId)
private void UpdateRules(ServerRow row, Server server, int requestId)
{
if (currentExtension != null && !currentExtension.SupportsRules)
return true;
return UpdateDetail(row, server, requestId, retryHandler =>
return;
UpdateDetail(row, server, requestId, retryHandler =>
{
row.Rules = new List<Rule>(server.GetRules(retryHandler));
});
Expand Down Expand Up @@ -582,6 +604,13 @@ private void btnQueryMaster_Click(object sender, EventArgs e)
}
#endregion

#region cbAdvancedOptions_CheckedChanged
private void cbAdvancedOptions_CheckedChanged(object sender, EventArgs e)
{
this.panelAdvancedOptions.Visible = this.cbAdvancedOptions.Checked;
}
#endregion

#region btnSkin_Click
private void btnSkin_Click(object sender, EventArgs e)
{
Expand Down Expand Up @@ -667,5 +696,42 @@ private void timerUpdateServerList_Tick(object sender, EventArgs e)
this.gvServers.EndDataUpdate();
}
#endregion

#region btnServerQuery_Click
private void btnServerQuery_Click(object sender, EventArgs e)
{
try
{
string[] parts = this.txtServerQuery.Text.Split(':');

var addr = Dns.GetHostAddresses(parts[0]);
if (addr.Length == 0) return;
var endpoint = new IPEndPoint(addr[0], parts.Length > 1 ? int.Parse(parts[1]) : 25785);
ServerRow serverRow = null;
foreach (var row in this.servers)
{
if (row.EndPoint.Equals(endpoint))
{
serverRow = row;
break;
}
}
++this.currentRequestId;
if (serverRow == null)
{
this.gvServers.BeginDataUpdate();
serverRow = new ServerRow(endpoint);
this.servers.Add(serverRow);
this.gvServers.EndDataUpdate();
this.gvServers.FocusedRowHandle = this.gvServers.GetRowHandle(this.servers.Count - 1);
}
this.UpdateServerDetails(serverRow, this.currentRequestId, () => this.UpdateGridDataSources(serverRow));
}
catch
{
}
}
#endregion

}
}
2 changes: 1 addition & 1 deletion ServerBrowser/Toxikk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public override object GetCellValue(ServerRow row, string fieldName)
return row.GetRule(fieldName) == "1";
case "_gametype":
var gt = row.ServerInfo.Description;
return gt.Contains("BloodLust") ? "BL" : gt.Contains("TeamGame") ? "SA" : gt.Contains("Cell") ? "CC" : gt;
return gt == null ? null : gt.Contains("BloodLust") ? "BL" : gt.Contains("TeamGame") ? "SA" : gt.Contains("Cell") ? "CC" : gt;
}
return base.GetCellValue(row, fieldName);
}
Expand Down
3 changes: 3 additions & 0 deletions ServerBrowser/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<setting name="FavGameIDs" serializeAs="String">
<value>324810,328070,440</value>
</setting>
<setting name="MasterServer" serializeAs="String">
<value>hl2master.steampowered.com:27011</value>
</setting>
</ServerBrowser.Properties.Settings>
</userSettings>
<runtime>
Expand Down

0 comments on commit 3b1a44e

Please sign in to comment.