-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
OnClientAuthorized
listener & steamid class
- Loading branch information
1 parent
54f3f9a
commit 4ccb091
Showing
11 changed files
with
137 additions
and
14 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
managed/CounterStrikeSharp.API/Core/Attributes/CastFromAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
|
||
namespace CounterStrikeSharp.API.Core.Attributes; | ||
|
||
/** | ||
* Indicates that the parameter should be pulled from the ScriptContext as the passed in type, | ||
* then cast/converted to the parameter type. | ||
*/ | ||
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)] | ||
public class CastFromAttribute : Attribute | ||
{ | ||
public Type Type { get; } | ||
|
||
public CastFromAttribute(Type type) | ||
{ | ||
Type = type; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
managed/CounterStrikeSharp.API/Modules/Entities/SteamID.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
|
||
namespace CounterStrikeSharp.API.Modules.Entities | ||
{ | ||
public class SteamID | ||
{ | ||
const long Base = 76561197960265728; | ||
public ulong SteamId64 { get; set; } | ||
|
||
public SteamID(ulong id) => SteamId64 = id; | ||
public SteamID(string id) => SteamId64 = id.StartsWith("[") ? ParseId3(id) : ParseId(id); | ||
|
||
public static explicit operator SteamID(ulong u) => new(u); | ||
public static explicit operator SteamID(string s) => new(s); | ||
|
||
ulong ParseId(string id) | ||
{ | ||
var parts = id.Split(':'); | ||
if (parts.Length != 3 || !ulong.TryParse(parts[2], out var num)) throw new FormatException(); | ||
return Base + num * 2 + (parts[1] == "1" ? 1UL : 0); | ||
} | ||
|
||
ulong ParseId3(string id) | ||
{ | ||
var parts = id.Replace("[", "").Replace("]", "").Split(':'); | ||
if (parts.Length != 3 || !ulong.TryParse(parts[2], out var num)) throw new FormatException(); | ||
return Base + num; | ||
} | ||
|
||
public string SteamId2 | ||
{ | ||
get => $"STEAM_0:{(SteamId64 - Base) % 2}:{(SteamId64 - Base) / 2}"; | ||
set => SteamId64 = ParseId(value); | ||
} | ||
|
||
public string SteamId3 | ||
{ | ||
get => $"[U:1:{SteamId64 - Base}]"; | ||
set => SteamId64 = ParseId3(value); | ||
} | ||
|
||
public override string ToString() => $"[SteamID {SteamId64}, {SteamId2}, {SteamId3}]"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters