Skip to content

Commit

Permalink
improved auto-detection of steam ID and allow manual override in extr…
Browse files Browse the repository at this point in the history
…aQL.ini
  • Loading branch information
PredatH0r committed Feb 7, 2016
1 parent 735a18e commit a72c056
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 20 deletions.
5 changes: 3 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ Changelog

Version 2.24
---
- added qlstats userscript (formerly the inofficial _elo userscript)
- added indicator for deactivated accounts to /whois (cheaters or otherwise special people)
- improved auto-detection of steam ID and allow manual override in extraQL.ini

Version 2.23
---
- use Steamworks API to determine current user's Steam-ID. Use that Steam-ID for QL's user config folder (\<steamid\>\baseq3)
- added qlstats userscript (formerly the inofficial _elo userscript)
- added indicator for deactivated accounts to /whois (cheaters or otherwise special people)

Version 2.22
---
Expand Down
1 change: 1 addition & 0 deletions source/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void LoadSettings()
this.settings["nickSteam"] = "";
this.settings["skipWorkshopNotice"] = "0";
this.settings["steamAppId"] = "349090";
this.settings["steamId"] = "";
this.settings["startServerBrowser"] = "0";
this.settings["closeServerBrowser"] = "0";
this.settings["webpakWorkshopItem"] = "0";
Expand Down
44 changes: 34 additions & 10 deletions source/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ namespace ExtraQL
{
public partial class MainForm : Form
{
public const string Version = "2.23";
public const string Version = "2.24";

private readonly Config config;
private readonly HttpServer server;
private readonly Servlets servlets;
private readonly ScriptRepository scriptRepository;
private readonly Steamworks steam = new Steamworks();
private bool qlStarted;
private bool skipWorkshopNotice;
private int steamAppId;
Expand Down Expand Up @@ -53,7 +54,7 @@ public MainForm(Config config)
this.scriptRepository = new ScriptRepository(config.AppBaseDir);
this.scriptRepository.Log = this.Log;

this.servlets = new Servlets(this.server, this.scriptRepository, this.Log, this, config.AppBaseDir);
this.servlets = new Servlets(this.server, this.scriptRepository, this.Log, this, config.AppBaseDir, this.steam);
this.UpdateServletSettings();

this.miStartServerBrowser.Visible = this.GetServerBrowserExe() != null;
Expand Down Expand Up @@ -103,7 +104,6 @@ protected override void OnClosed(EventArgs e)
// make sure the window can be closed even if there are exceptions
try { this.SaveSettings(); } catch { }
try { this.server.Stop(); } catch { }
try { this.servlets.Dispose(); } catch { }
try
{
if (this.cbCloseServerBrowser.Checked)
Expand Down Expand Up @@ -409,6 +409,7 @@ private void LoadSettings()
this.cbAutoQuit.Checked = config.GetBool("autoquit");
this.skipWorkshopNotice = config.GetBool("skipWorkshopNotice");
int.TryParse(config.GetString("steamAppId"), out this.steamAppId);
ulong.TryParse(config.GetString("steamId"), out this.steamClientId);
this.cbStartServerBrowser.Checked = config.GetBool("startServerBrowser");
this.cbCloseServerBrowser.Checked = config.GetBool("closeServerBrowser");
}
Expand Down Expand Up @@ -468,10 +469,9 @@ private void Startup()
this.CheckIfStartedFromWorkshopFolder();
this.FillScriptList();

this.StartSteamClient();
if (this.cbAutostart.Checked)
this.Launch();
else
this.StartSteamClient();

this.startupCompleted = true;
}
Expand Down Expand Up @@ -569,7 +569,7 @@ private void RestartHttpServer()
#region OpenConfigFolder()
private void OpenConfigFolder(bool extraQlConfig)
{
var dir = extraQlConfig ? this.GetSteamWorkshopPath() : this.GetConfigFolder();
var dir = extraQlConfig ? config.AppBaseDir : this.GetConfigFolder();
if (dir != null)
Process.Start("explorer.exe", "/e," + dir);
}
Expand Down Expand Up @@ -644,14 +644,38 @@ private void FillScriptList()
#region StartSteamClient()
private void StartSteamClient()
{
using (var steam = new Steamworks())
if (!steam.IsSteamRunning())
{
if (!steam.IsSteamRunning())
this.btnStartQL.Enabled = false;
Log("starting Steam Client...");
Process.Start("steam://preload/" + QuakeLiveAppId);
for (int i = 0; i < 600; i++)
{
Log("starting Steam Client...");
Process.Start("steam://preload/" + QuakeLiveAppId);
if (steam.IsSteamRunning())
break;
System.Threading.Thread.Sleep(100);
Application.DoEvents();
}

// wait 7.5sec to the Steam Client GUI to be fully loaded. Otherwise trying to start QL would fail.
for (int i = 0; i < 75; i++)
{
System.Threading.Thread.Sleep(100);
Application.DoEvents();
}
}

if (this.steamClientId == 0)
this.steamClientId = steam.GetUserID();

if (this.steamClientId != 0)
{
this.Log("Using QL config folder for steam ID " + this.steamClientId);
this.btnStartQL.Enabled = true;
}
else
{
this.Log("Unable to auto-detect your steam ID (needed for the QL config folder). You can manually set steamId=... in extraQL.ini");
}
}
#endregion
Expand Down
12 changes: 4 additions & 8 deletions source/Servlets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace ExtraQL
{
internal class Servlets : IDisposable
internal class Servlets
{
private static readonly string[] DomainsAllowedForProxy = { "esreality.com", "quakelive.com", "github.com" };
private const string AddScriptRoute = "/addScript";
Expand All @@ -21,19 +21,20 @@ internal class Servlets : IDisposable
private readonly StringBuilder indexBuilder = new StringBuilder();
private readonly string baseDir;
private readonly ScriptRepository scriptRepository;
private readonly Steamworks steamworks = new Steamworks();
private readonly Steamworks steamworks;
private readonly Form form;
private string joinServer, joinPass;

public Action<string> Log;

#region ctor()

public Servlets(HttpServer server, ScriptRepository scriptRepository, Action<string> logger, Form form, string baseDir)
public Servlets(HttpServer server, ScriptRepository scriptRepository, Action<string> logger, Form form, string baseDir, Steamworks steam)
{
this.server = server;
this.scriptRepository = scriptRepository;
this.form = form;
this.steamworks = steam;
this.EnableScripts = true;
this.EnablePrivateServlets = true;
server.Log = logger;
Expand All @@ -44,11 +45,6 @@ public Servlets(HttpServer server, ScriptRepository scriptRepository, Action<str

#endregion

public void Dispose()
{
this.steamworks.Dispose();
}

public bool EnablePrivateServlets { get; set; }

public string QuakeConfigFolder { get; set; }
Expand Down

0 comments on commit a72c056

Please sign in to comment.