44 lines
1 KiB
V
44 lines
1 KiB
V
module steamid
|
|
|
|
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 }
|
|
}
|