Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions HyuuSeeker/HyuuSeeker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.11.21" />
<PackageReference Include="Microsoft.Packaging.Tools.Trimming" Version="1.1.0-preview1-26619-01" />
</ItemGroup>

Expand Down
137 changes: 126 additions & 11 deletions HyuuSeeker/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using HtmlAgilityPack;
using System.Diagnostics;

namespace HyuuSeeker
{
Expand Down Expand Up @@ -225,6 +227,10 @@ public static void ClearCurrentConsoleLine()

static void Main(string[] args)
{
string hostname = "";
int intchoice;
int port = 0;

if (!File.Exists("maps.kart")) {
Console.WriteLine("Close this program and move it to your SRB2Kart folder. Then try again.");
Console.ReadKey();
Expand Down Expand Up @@ -258,7 +264,43 @@ static void Main(string[] args)
Console.WriteLine("\"like wadseeker but written by chimpanzees\"");
Console.WriteLine("");

Console.WriteLine("Enter a hostname to fetch files for, or leave blank to read your log.txt.");
List<string> servers = new List<string>();
HtmlWeb web = new HtmlWeb();
HtmlDocument document;

try
{
document = web.Load("http://hyuu.cc");
}
catch
{
Console.WriteLine("Couldn't connect to http://hyuu.cc");
Console.ReadKey();
return;
}

HtmlNodeCollection nodes = document.DocumentNode.SelectNodes("//div[@class='hyuuseeker-enabled']/li");

Console.WriteLine("Choose a hyuuseeker supported server to play on!\n");

int listnumber = 1;
foreach (HtmlNode node in nodes)
{
HtmlNode linknode = node.SelectSingleNode("a");
HtmlNode descnode = node.SelectSingleNode("div[@class='desc']");
servers.Add(linknode.Attributes.First().Value);


Console.WriteLine(listnumber + " : " + linknode.InnerText);
if (descnode != null)
{
Console.WriteLine("\t" + descnode.InnerText);
}
Console.WriteLine("");
listnumber++;
}

Console.WriteLine("Enter a number to select a HyuuSeeker supported server.\nOr, you can type an unsupported hostname directly and HyuuSeeker will try its best.\nYou can also enter nothing and HyuuSeeker will scan your log for previous connections.");
string target = Console.ReadLine();

List<string> targets = new List<string>();
Expand All @@ -283,16 +325,36 @@ static void Main(string[] args)
}
}
}
} else
}
else
{
string hostname = target;
int port = 5029;
string[] parts = hostname.Split(':');
if (parts.Length == 2)
if (Int32.TryParse(target, out intchoice))
{
if (servers[intchoice-1] != null)
{
Uri uri = new Uri(servers[intchoice-1]);
hostname = uri.Host;
}
else
{
Console.WriteLine("You entered a number out of the list range, exiting ...");
Console.ReadKey();
return;
}
}
else
{
hostname = parts[0];
port = Int32.Parse(parts[1]);
//Support both bare hostnames and ones with uri
if (!target.Contains(Uri.SchemeDelimiter)) {
target = string.Concat(Uri.UriSchemeHttp, Uri.SchemeDelimiter, target);
}
Uri uri = new Uri(target);
hostname = uri.Host;
port = uri.Port;
}

if (port == 0 || port == -1) {port = 5029;}

UdpClient udpClient = new UdpClient(port);
udpClient.Client.ReceiveTimeout = 10000;
Console.WriteLine();
Expand All @@ -305,7 +367,7 @@ static void Main(string[] args)
} catch
{
Console.WriteLine("Couldn't connect.");
Console.ReadLine();
Console.ReadKey();
return;
}
//Console.WriteLine("Connected.");
Expand Down Expand Up @@ -447,7 +509,10 @@ static void Main(string[] args)
Console.WriteLine("Downloaded all available files, but some couldn't be retrieved:");
Console.WriteLine(String.Join(", ", failed.ToArray()));
Console.WriteLine("You can now close this window.");
} else
Console.ReadKey();
return;
}
else
{
Console.WriteLine("__ ______ _ _ _ _____ _____ ____ ____ _ ");
Console.WriteLine("\\ \\ / / __ \\| | | ( ) /\\ | __ \\ / ____/ __ \\ / __ \\| | ");
Expand All @@ -456,9 +521,59 @@ static void Main(string[] args)
Console.WriteLine(" | | | |__| | |__| | / ____ \\| | \\ \\ | |___| |__| | |__| | |____ ");
Console.WriteLine(" |_| \\____/ \\____/ /_/ \\_\\_| \\_\\ \\_____\\____/ \\____/|______|");
Console.WriteLine();
}


if (hostname != "")
{
Console.WriteLine("\nNow launching SRB2Kart and connecting to " + hostname);
Console.WriteLine("Which renderer would you like to use? (Use Software if unsure)");
Console.WriteLine("\t1 : Software (Default)");
Console.WriteLine("\t2 : OpenGL");
Console.WriteLine("\t3 : Cancel Launch");

string choice = Console.ReadLine();
string opengl = "";

if (Int32.TryParse(choice, out intchoice))
{
if (intchoice >= 3 || intchoice <= 0)
{
Console.WriteLine("Cancelling launch ...");
Console.ReadKey();
return;
}
else if (intchoice == 2)
{
opengl = "-opengl";
}
}
else
{
Console.WriteLine("Numbers allowed only ... exiting ...");
Console.ReadKey();
return;
}

ProcessStartInfo startinfo = new ProcessStartInfo();
startinfo.FileName = "srb2kart.exe";
startinfo.Arguments = "-connect " + hostname + " " + opengl;
try
{
Process.Start(startinfo);
}
catch
{
Console.WriteLine("Couldn't start " + startinfo.FileName + " " + startinfo.Arguments);
Console.ReadKey();
}
}
else
{
Console.WriteLine("Downloaded all missing files. You can now close this window.");
Console.ReadKey();
return;
}
Console.ReadKey();
}
}
}