-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommandLine.cs
71 lines (63 loc) · 2.49 KB
/
CommandLine.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
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Steamworks;
using UnityEngine;
namespace SharkkitDedicated
{
public static class CommandLine
{
// TODO: The SteamId should be determined at the initial handshake, so it doesn't need to be known pre-connect.
// but then, what do we pass as fakeSteamId?
public static bool ParseIpConnect(string arg, out string address, out ushort port, out CSteamID fakeSteamId)
{
if (!arg.StartsWith("ConIp:"))
{
address = null;
port = 0;
fakeSteamId = CSteamID.Nil;
return false;
}
// ConIp:127.0.0.1:1337:987654321 -> IP:Port:SteamId
var parts = arg.Substring("ConIp:".Length).Split(':');
if (parts.Length != 3)
{
Debug.LogWarning($"Invalid ConIp Format \"{arg}\". {parts.Length} parts.");
address = null;
port = 0;
fakeSteamId = CSteamID.Nil;
return false;
}
address = parts[0];
port = ushort.Parse(parts[1]);
fakeSteamId = new CSteamID(ulong.Parse(parts[2]));
return true;
}
public static bool ParseDedicated(ICollection<string> args, out ListenArguments listenArguments)
{
var portArg = args.FirstOrDefault(x => x.StartsWith("--dedicated-port="));
if (portArg == null)
{
listenArguments = null;
return false;
}
if (!ushort.TryParse(portArg.Substring("--dedicated-port=".Length), out var port))
{
Debug.LogError($"Invalid dedicated port specified. Check your syntax near {portArg}");
listenArguments = null;
return false;
}
listenArguments = new ListenArguments(port)
{
GsUserToken = ExtractArg(args, "--dedicated-with-user-token="),
ListenIp = ExtractArg(args, "--dedicated-with-listen-ip=")
};
//listenArguments.AdvertiseInSteamBrowser = ExtractArg("--dedicated-steam-advertise=")
return true;
}
private static string ExtractArg(IEnumerable<string> args, string argName)
{
return args.Where(x => x.StartsWith(argName)).Select(x => x.Substring(argName.Length)).FirstOrDefault();
}
}
}