From 4023b68bc9b2659a609a4c8d05abc8a5a52432be Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 28 Aug 2022 23:45:31 +0200 Subject: [PATCH] first commit --- main.v | 11 ++++++++++ steamid/methods.v | 52 +++++++++++++++++++++++++++++++++++++++++++++++ steamid/structs.v | 20 ++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 main.v create mode 100644 steamid/methods.v create mode 100644 steamid/structs.v diff --git a/main.v b/main.v new file mode 100644 index 0000000..8a64e96 --- /dev/null +++ b/main.v @@ -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 } +} diff --git a/steamid/methods.v b/steamid/methods.v new file mode 100644 index 0000000..87c2e69 --- /dev/null +++ b/steamid/methods.v @@ -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 } +} diff --git a/steamid/structs.v b/steamid/structs.v new file mode 100644 index 0000000..a29266e --- /dev/null +++ b/steamid/structs.v @@ -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 +}