first commit

This commit is contained in:
Philipp 2022-08-28 23:45:31 +02:00
parent 85ac7e509e
commit 4023b68bc9
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 276B613AF9DBE9C3
3 changed files with 83 additions and 0 deletions

11
main.v Normal file
View file

@ -0,0 +1,11 @@
module main
import steamid as s
fn main() {
steamid := s.to_steamid32("STEAM_0:1:37792218")
assert steamid == s.SteamID32 { 0, 1, 37792218 }
assert steamid.str() == "STEAM_0:1:37792218"
assert steamid.to_steamid3() == s.SteamID3 { "U", 1, 75584437 }
assert steamid.to_steamid64() == s.SteamID64 { 76561198035850165 }
}

52
steamid/methods.v Normal file
View file

@ -0,0 +1,52 @@
module steamid
pub fn steamid() {
steamid := to_steamid32("STEAM_0:1:37792218")
assert steamid == SteamID32 { 0, 1, 37792218 }
assert steamid.str() == "STEAM_0:1:37792218"
assert steamid.to_steamid3() == SteamID3 { "U", 1, 75584437 }
assert steamid.to_steamid64() == SteamID64 { 76561198035850165 }
}
pub fn to_steamid32(s string) SteamID32 {
if s.contains("STEAM_") && s.count(":") == 2 {
mut s_parts := s.split(":")
x := s_parts[0].all_after("_").i8()
y := s_parts[1].i8()
z := s_parts[2].int()
return SteamID32{ x, y, z }
}
return SteamID32 { 1, 1, 1 }
}
// Methods for SteamID32 struct
// Convert your SteamID32 to SteamID3
pub fn (s SteamID32) to_steamid3() SteamID3 {
mut letter := 'I'
if s.id == 1 {
letter = 'U'
} else if s.id == 7 {
letter = 'g'
} else {
letter = 'I'
}
w := s.account_number * 2 + s.id
return SteamID3 { letter, 1, w }
}
// Convert your SteamID32 to a string
pub fn (s SteamID32) str() string {
return "STEAM_" + s.universe.str() + ":" + s.id.str() + ":" + s.account_number.str()
}
// Convert your SteamID32 to a SteamID64
pub fn (s SteamID32) to_steamid64() SteamID64 {
mut v := i64(0)
if s.id == 1 {
v = 76561197960265728
} else {
v = 103582791429521408
}
w := s.account_number * 2 + v + s.id
return SteamID64 { w }
}

20
steamid/structs.v Normal file
View file

@ -0,0 +1,20 @@
module steamid
pub struct SteamID32 {
pub:
universe int
id int
account_number int
}
pub struct SteamID3 {
pub:
letter string
id int
account_number int
}
pub struct SteamID64 {
pub:
w i64
}