-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathArguments.cs
118 lines (106 loc) · 4.82 KB
/
Arguments.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using System.Text;
using System.Reflection;
namespace PhValheim.Arguments
{
public class PhValheim
{
//get our local Steam installation directory and execuatable
public static void Usage()
{
var phvalheimLauncherVersion = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute> ().InformationalVersion;
Console.WriteLine(
"\n" +
"PhValheim Client Version " + phvalheimLauncherVersion +
"\n\n" +
"Usage: phvalheim-client.exe [OPTION...] [OPTION]...\n" +
"'phvalheim-client' syncs and launches Valheim client contexts with remote server contexts.\n" +
"\n" +
"Examples:\n" +
"\n" +
" phvalheim-client.exe 'mode' 'worldname' 'hostname' 'password' 'port'\n" +
" phvalheim-client.exe 'textures' 'worldname' 'texture_pack'\n" +
" phvalheim-client.exe 'launch' 'Valhalla' 'valheim.mydomain.com' 'myValhallaPassword' 'port'\n" +
" phvalheim-client.exe 'textures' 'Valhalla' 'coco'\n" +
" phvalheim-client.exe 'textures' 'Valhalla' 'willybach'\n" +
"\n" +
"");
}
public static bool argHandler(ref string[] args, ref string[] argumentsPassed, ref string command, ref string worldName, ref string worldPassword, ref string worldHost, ref string worldPort, ref string texturePack, ref string phvalheimHost, ref string httpScheme)
{
//all arguments missing, print usage and exit
if (args.Length == 0)
{
Arguments.PhValheim.Usage();
Console.Write("ERROR: No arguments passed.");
return false;
}
else
{
if (args[0] == "phvalheim:///?")
{
Console.WriteLine("Launch URL provided: " + args[0]);
Console.WriteLine("ERROR: malformed phvalheim URL, exiting...");
return false;
}
argumentsPassed = args[0].Split('?');
string decodedLaunchString;
try
{
byte[] data = Convert.FromBase64String(argumentsPassed[1]);
decodedLaunchString = Encoding.UTF8.GetString(data);
}
catch
{
Console.WriteLine("Launch URL provided: " + args[0]);
Console.WriteLine("ERROR: malformed phvalheim URL, exiting...");
return false;
}
argumentsPassed = decodedLaunchString.Split('?');
if (argumentsPassed.Length < 2)
{
Console.WriteLine("Launch URL provided: " + decodedLaunchString);
Console.WriteLine("ERROR: malformed phvalheim URL, exiting...");
return false;
}
else
{
command = argumentsPassed[0];
}
if (command == "launch")
{
if (argumentsPassed.Length < 7)
{
Console.WriteLine("Launch URL provided: " + decodedLaunchString);
Console.WriteLine("ERROR: malformed phvalheim URL, exiting...");
return false;
}
else
{
worldName = argumentsPassed[1];
worldPassword = argumentsPassed[2];
worldHost = argumentsPassed[3];
worldPort = argumentsPassed[4];
phvalheimHost = argumentsPassed[5];
httpScheme = argumentsPassed[6];
return true;
}
}
if (command == "textures")
{
if (argumentsPassed.Length < 3)
{
Console.WriteLine("Launch URL provided: " + decodedLaunchString);
Console.WriteLine("ERROR: malformed phvalheim URL, exiting...");
return false;
}
else
{
worldName = argumentsPassed[1];
texturePack = argumentsPassed[2];
}
}
return true;
}
}
}
}