Beta Release
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using Microsoft.Win32;
|
||||
using MSCLoader;
|
||||
|
||||
namespace MSCO
|
||||
{
|
||||
/// <summary>
|
||||
/// "msco://connect/<host>:<port>"-Links (JOIN-Button auf der Website).
|
||||
/// Die Mod registriert den Link-Typ in Windows so, dass ein Klick Steam direkt mit
|
||||
/// "-applaunch 516750 +msco_connect <link>" startet - ohne cmd/Skript dazwischen, damit
|
||||
/// präparierte Links keine Befehle ausführen können. Die Mod liest die Adresse beim Start
|
||||
/// aus der Kommandozeile und fragt im Hauptmenü, ob verbunden werden soll.
|
||||
/// (Läuft das Spiel schon, gibt Steam den Link nicht weiter - dann den Server-Browser nutzen.)
|
||||
/// </summary>
|
||||
public static class JoinLinks
|
||||
{
|
||||
const string Scheme = "msco";
|
||||
const string Argument = "+msco_connect";
|
||||
const int MySummerCarAppId = 516750;
|
||||
|
||||
/// <summary>Link-Typ msco:// für den aktuellen Windows-Benutzer eintragen (kein Admin nötig).</summary>
|
||||
public static void Register()
|
||||
{
|
||||
try
|
||||
{
|
||||
string steamExe = SteamExePath();
|
||||
if (steamExe == null)
|
||||
{
|
||||
ModConsole.Warning("[MSCO] Steam not found - JOIN links from the website are not available.");
|
||||
return;
|
||||
}
|
||||
string command = "\"" + steamExe + "\" -applaunch " + MySummerCarAppId + " " + Argument + " \"%1\"";
|
||||
|
||||
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\Classes\" + Scheme))
|
||||
{
|
||||
key.SetValue("", "URL:MSCO Join Link");
|
||||
key.SetValue("URL Protocol", "");
|
||||
using (RegistryKey cmd = key.CreateSubKey(@"shell\open\command"))
|
||||
cmd.SetValue("", command);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ModConsole.Warning("[MSCO] Could not register msco:// links: " + e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
static string SteamExePath()
|
||||
{
|
||||
using (RegistryKey steam = Registry.CurrentUser.OpenSubKey(@"Software\Valve\Steam"))
|
||||
{
|
||||
string exe = steam != null ? steam.GetValue("SteamExe") as string : null;
|
||||
return string.IsNullOrEmpty(exe) ? null : exe.Replace('/', '\\');
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Wurde das Spiel über einen JOIN-Link gestartet?</summary>
|
||||
public static bool TryGetFromCommandLine(out string host, out int port)
|
||||
{
|
||||
host = null;
|
||||
port = 0;
|
||||
string[] args = Environment.GetCommandLineArgs();
|
||||
for (int i = 0; i < args.Length - 1; i++)
|
||||
if (args[i] == Argument) return TryParse(args[i + 1], out host, out port);
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>"msco://connect/1.2.3.4:7777/" -> Host und Port (nur Buchstaben, Ziffern, . - :).</summary>
|
||||
static bool TryParse(string text, out string host, out int port)
|
||||
{
|
||||
host = null;
|
||||
port = 0;
|
||||
text = text.Trim().Trim('"').Trim();
|
||||
const string prefix = "msco://connect/";
|
||||
if (!text.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) return false;
|
||||
string address = text.Substring(prefix.Length).TrimEnd('/');
|
||||
|
||||
foreach (char c in address)
|
||||
if (!char.IsLetterOrDigit(c) && c != '.' && c != '-' && c != ':') return false;
|
||||
|
||||
return ServerBrowser.TryParseAddress(address, out host, out port);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user