Skip to content

Commit

Permalink
- added About / Version History menu item
Browse files Browse the repository at this point in the history
- using Lock icon instead of a checkbox for private (password protected) servers
- Quake Live: added option to automatically start extraQL when connecting to match
- Quake Live: gametype column "GT" now has a prefixed "i" for InstaGib matches. The Instagib checkbox column was removed
- Quake Live: added columns "Lo" and "Ti" to indicate enabled loadouts and item timers
- Quake Live: removed redundant "FT" column (full teams), as this is already indicated by the traffic light
- moved ServerBrowser.ini and locations.txt from %appdata%\..\Local\ServerBrowser to local directory
  • Loading branch information
PredatH0r committed Nov 13, 2015
1 parent 8b11e47 commit f707b4a
Show file tree
Hide file tree
Showing 16 changed files with 346 additions and 105 deletions.
2 changes: 2 additions & 0 deletions ServerBrowser/Games/GameExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace ServerBrowser
/// </summary>
public class GameExtension
{
public static string SteamWorkshopFolder = null;

protected bool supportsRulesQuery = true;
protected bool supportsPlayersQuery = true;
protected bool supportsConnectAsSpectator = false;
Expand Down
85 changes: 73 additions & 12 deletions ServerBrowser/Games/QuakeLive.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using DevExpress.Data;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
using QueryMaster;
Expand Down Expand Up @@ -42,6 +45,8 @@ public class QuakeLive : GameExtension
private static readonly Regex NameColors = new Regex("\\^[0-9]");
private readonly Game steamAppId;
private bool useKeystrokesToConnect;
private bool startExtraQL;
private string extraQlPath;

#region ctor()

Expand All @@ -60,6 +65,8 @@ public override void LoadConfig(IniFile ini)
{
var sec = ini.GetSection("QuakeLive", true);
this.useKeystrokesToConnect = sec.GetBool("useKeystrokesToConnect");
this.startExtraQL = sec.GetBool("startExtraQL");
this.extraQlPath = sec.GetString("extraQlPath");
}
#endregion

Expand All @@ -69,6 +76,8 @@ public override void SaveConfig(StringBuilder ini)
ini.AppendLine();
ini.AppendLine("[QuakeLive]");
ini.AppendLine($"useKeystrokesToConnect={this.useKeystrokesToConnect}");
ini.AppendLine($"startExtraQL={this.startExtraQL}");
ini.AppendLine($"extraQlPath={this.extraQlPath}");
}
#endregion

Expand All @@ -78,9 +87,11 @@ public override void OnOptionMenuClick()
using (var dlg = new QuakeLiveOptionsDialog())
{
dlg.UseKeystrokes = this.useKeystrokesToConnect;
dlg.StartExtraQL = this.startExtraQL;
if (dlg.ShowDialog(Form.ActiveForm) != DialogResult.OK)
return;
this.useKeystrokesToConnect = dlg.UseKeystrokes;
this.startExtraQL = dlg.StartExtraQL;
}
}
#endregion
Expand All @@ -100,13 +111,41 @@ public override void CustomizeServerGridColumns(GridView view)

idx = view.Columns["PlayerCount"].VisibleIndex;
AddColumn(view, "_teamsize", "TS", "Team Size", 30, ++idx, UnboundColumnType.Integer);
idx = view.Columns["JoinStatus"].VisibleIndex;
AddColumn(view, "_fullTeams", "FT", "Full Teams", 30, ++idx, UnboundColumnType.Boolean);

idx = view.Columns["ServerInfo.Ping"].VisibleIndex;
AddColumn(view, "_goalscore", "SL", "Score Limit", 30, idx, UnboundColumnType.Integer);
AddColumn(view, "timelimit", "TL", "Time Limit", 30, ++idx, UnboundColumnType.Integer);
AddColumn(view, "g_instagib", "Insta", "Instagib", 35, ++idx, UnboundColumnType.Boolean);
//AddColumn(view, "g_instaGib", "Insta", "Instagib", 35, ++idx, UnboundColumnType.Boolean);

var col = AddColumn(view, "g_loadout", "Lo", "Loadout", 20, ++idx, UnboundColumnType.Boolean);
var ed = view.GridControl.RepositoryItems["riLoadout"] as RepositoryItemImageComboBox;
if (ed == null)
{
ed = new RepositoryItemImageComboBox();
ed.BeginInit();
ed.Name = "riLoadout";
ed.SmallImages = view.Images;
ed.Items.Add(new ImageComboBoxItem("No Loadouts", false, -1));
ed.Items.Add(new ImageComboBoxItem("Loadouts", true, 28));
ed.EndInit();
view.GridControl.RepositoryItems.Add(ed);
}
col.ColumnEdit = ed;

col = AddColumn(view, "g_itemTimers", "Ti", "Item Timers", 20, ++idx, UnboundColumnType.Boolean);
ed = view.GridControl.RepositoryItems["riItemTimer"] as RepositoryItemImageComboBox;
if (ed == null)
{
ed = new RepositoryItemImageComboBox();
ed.BeginInit();
ed.Name = "riItemTimer";
ed.SmallImages = view.Images;
ed.Items.Add(new ImageComboBoxItem("No Item Timers", false, -1));
ed.Items.Add(new ImageComboBoxItem("Item Timers", true, 26));
ed.EndInit();
view.GridControl.RepositoryItems.Add(ed);
}
col.ColumnEdit = ed;
}

#endregion
Expand Down Expand Up @@ -138,7 +177,7 @@ public override object GetServerCellValue(ServerRow row, string fieldName)
case "_gametype":
{
var gt = row.GetRule("g_gametype");
var instaPrefix = row.GetRule("g_instagib") == "1" ? "i" : "";
var instaPrefix = row.GetRule("g_instaGib") == "1" ? "i" : "";
int num;
string name;
if (int.TryParse(gt, out num) && gameTypeName.TryGetValue(num, out name))
Expand All @@ -151,13 +190,11 @@ public override object GetServerCellValue(ServerRow row, string fieldName)
int.TryParse(row.GetRule("teamsize") ?? "0", out ts);
return ts == 0 ? null : (object) ts;
}
case "_fullTeams":
{
int ts;
int.TryParse(row.GetRule("teamsize") ?? "0", out ts);
return row.PlayerCount.RealPlayers >= row.PlayerCount.MaxPlayers || ts != 0 && row.PlayerCount.RealPlayers >= ts*2;
}
case "g_instagib":
case "g_instaGib":
return row.GetRule(fieldName) == "1";
case "g_loadout":
return row.GetRule(fieldName) == "1";
case "g_itemTimers":
return row.GetRule(fieldName) == "1";
}
return base.GetServerCellValue(row, fieldName);
Expand Down Expand Up @@ -209,7 +246,21 @@ public override string GetCleanPlayerName(Player player)

public override bool Connect(ServerRow server, string password, bool spectate)
{
if (useKeystrokesToConnect)
if (this.startExtraQL)
{
var extraQlExe = this.GetExtaQlPath();
if (extraQlExe != null)
{
//using (var cli = new XWebClient(500))
//{
// var response = cli.DownloadString("http://localhost:27963/version");
// if (response == null)
Process.Start(extraQlExe);
//}
}
}

if (this.useKeystrokesToConnect)
{
// don't use the ThreadPool b/c it might be full with waiting server update requests
new Thread(ctx => { ConnectInBackground(server, password, spectate); }).Start();
Expand All @@ -221,6 +272,16 @@ public override bool Connect(ServerRow server, string password, bool spectate)

#endregion

#region GetExtraQlPath()
private string GetExtaQlPath()
{
if (!string.IsNullOrEmpty(this.extraQlPath) && File.Exists(this.extraQlPath))
return this.extraQlPath;
var extraQlExe = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(this.GetType().Assembly.Location)), @"539252269\extraQL.exe");
return File.Exists(extraQlExe) ? extraQlExe : null;
}
#endregion

#region ConnectInBackground()

private void ConnectInBackground(ServerRow server, string password, bool spectate)
Expand Down
33 changes: 30 additions & 3 deletions ServerBrowser/Games/QuakeLiveOptionsDialog.Designer.cs

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

12 changes: 12 additions & 0 deletions ServerBrowser/Games/QuakeLiveOptionsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,24 @@ public partial class QuakeLiveOptionsDialog : XtraForm
public QuakeLiveOptionsDialog()
{
InitializeComponent();
this.linkExtraQL.Appearance.LinkColor = ServerBrowserForm.LinkControlColor;
}

public bool UseKeystrokes
{
get { return this.cbSendKeystrokes.Checked; }
set { this.cbSendKeystrokes.Checked = value; }
}

public bool StartExtraQL
{
get { return this.cbStartExtraQL.Checked; }
set { this.cbStartExtraQL.Checked = value; }
}

private void linkExtraQL_Click(object sender, System.EventArgs e)
{
System.Diagnostics.Process.Start("steam://url/CommunityFilePage/539252269");
}
}
}
14 changes: 6 additions & 8 deletions ServerBrowser/GeoIpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Net;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace ServerBrowser
{
Expand All @@ -20,11 +19,13 @@ class GeoIpClient
/// </summary>
private readonly Dictionary<uint,object> cache = new Dictionary<uint, object>();
private readonly BlockingCollection<IPAddress> queue = new BlockingCollection<IPAddress>();
private readonly string cacheFile;

public string ServiceUrlFormat { get; set; }

public GeoIpClient()
public GeoIpClient(string cacheFile)
{
this.cacheFile = cacheFile;
this.ServiceUrlFormat = DefaultServiceUrlFormat;
for (int i=0; i<ThreadCount; i++)
ThreadPool.QueueUserWorkItem(context => this.ProcessLoop());
Expand Down Expand Up @@ -145,15 +146,12 @@ public void CancelPendingRequests()
}
#endregion

private string CacheFile => Path.Combine(Application.LocalUserAppDataPath, "locations.txt");

#region LoadCache()
public void LoadCache()
{
var path = this.CacheFile;
if (!File.Exists(path))
if (!File.Exists(this.cacheFile))
return;
foreach (var line in File.ReadAllLines(path))
foreach (var line in File.ReadAllLines(this.cacheFile))
{
try
{
Expand Down Expand Up @@ -192,7 +190,7 @@ public void SaveCache()
info.Iso2, info.Country, info.State, info.Region, info.City, info.Latitude, info.Longitude);
}
}
File.WriteAllText(this.CacheFile, sb.ToString());
File.WriteAllText(this.cacheFile, sb.ToString());
}
catch { }
}
Expand Down
Loading

0 comments on commit f707b4a

Please sign in to comment.