-
-
Notifications
You must be signed in to change notification settings - Fork 143
/
Copy pathTsVersion.cs
102 lines (88 loc) · 3.16 KB
/
TsVersion.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
// TSLib - A free TeamSpeak 3 and 5 client library
// Copyright (C) 2017 TSLib contributors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the Open Software License v. 3.0
//
// You should have received a copy of the Open Software License along with this
// program. If not, see <https://opensource.org/licenses/OSL-3.0>.
using System.Collections.Generic;
using System.Text.RegularExpressions;
using TSLib.Full;
namespace TSLib
{
/// <summary>Describes a version tuple of version and platform.</summary>
public class TsVersion
{
protected static readonly Regex VersionPattern = new Regex(@"([^ ])* \[Build: (\d+)\]", RegexOptions.ECMAScript | RegexOptions.Compiled);
private static readonly Dictionary<string, ClientPlatform> Platforms = new Dictionary<string, ClientPlatform> {
{ "Windows", ClientPlatform.Windows },
{ "Linux", ClientPlatform.Linux },
{ "OS X", ClientPlatform.MacOs },
{ "macOS", ClientPlatform.MacOs },
{ "Android", ClientPlatform.Android },
{ "iOS", ClientPlatform.Ios },
};
protected static ClientPlatform GetPlatform(string platform)
=> Platforms.TryGetValue(platform, out var enu) ? enu : ClientPlatform.Other;
public string Version { get; }
public string Platform { get; }
public ClientPlatform PlatformType { get; }
public ulong Build { get; }
public TsVersion(string rawVersion, string platform, ulong build)
: this(rawVersion, platform, GetPlatform(platform), build) { }
public TsVersion(string rawVersion, string platform, ClientPlatform platformType, ulong build)
{
Version = rawVersion;
Platform = platform;
PlatformType = platformType;
Build = build;
}
public static TsVersion? TryParse(string version, string platform)
{
var match = VersionPattern.Match(version);
if (!match.Success)
return null;
if (!ulong.TryParse(match.Groups[2].Value, out var build))
return null;
return new TsVersion(version, platform, build);
}
}
/// <summary>
/// Describes a triple of version, platform and a cryptographical signature (usually distributed by "TeamSpeak Systems").
/// Each triple has to match and is not interchangeable with other triple parts.
/// </summary>
public sealed partial class TsVersionSigned : TsVersion
{
public string Sign { get; }
public TsVersionSigned(string rawVersion, string platform, ulong build, string sign)
: this(rawVersion, platform, GetPlatform(platform), build, sign) { }
public TsVersionSigned(string rawVersion, string platform, ClientPlatform platformType, ulong build, string sign)
: base(rawVersion, platform, platformType, build)
{
Sign = sign;
}
public static TsVersionSigned? TryParse(string version, string platform, string sign)
{
var match = VersionPattern.Match(version);
if (!match.Success)
return null;
if (!ulong.TryParse(match.Groups[2].Value, out var build))
return null;
var prelim = new TsVersionSigned(version, platform, build, sign);
if (!prelim.CheckValid())
return null;
return prelim;
}
public bool CheckValid() => TsCrypt.EdCheck(this);
}
public enum ClientPlatform
{
Other = 0,
Windows,
Linux,
MacOs,
Android,
Ios,
}
}