Repository: tjensen/dayz-dev-tools (language: python)

Issue:
Add tool for converting Steam IDs to DayZ GUIDs
**Is your feature request related to a problem? Please describe.**
Many DayZ mods require DayZ GUIDs instead of a Steam IDs for assigning roles and permissions to users. DayZ GUIDs are URL-safe Base64-encoded SHA256 hashes of their corresponding Steam IDs, however many server admins don't know how to perform the conversion.

**Describe the solution you'd like**
It would be nice to have a simple tool for converting Steam IDs to DayZ GUIDs.

**Describe alternatives you've considered**
N/A

**Additional context**
N/A


Discussion / hints:

Fix patch:
diff --git a/dayz_dev_tools/guid.py b/dayz_dev_tools/guid.py
new file mode 100644
index 0000000..fd207c2
--- /dev/null
+++ b/dayz_dev_tools/guid.py
@@ -0,0 +1,28 @@
+import argparse
+import base64
+import hashlib
+
+
+def guid_for_steamid64(steamid64: int) -> str:
+    """Convert a SteamID64 identifier to a DayZ GUID identifier.
+
+    :Parameters:
+      - `steamid64`: A 64-bit SteamID used to uniquely identify a Steam account.
+
+    :Returns:
+      The DayZ GUID corresponding to the given 64-bit SteamID.
+    """
+    return base64.urlsafe_b64encode(hashlib.sha256(str(steamid64).encode()).digest()).decode()
+
+
+def main() -> None:
+    parser = argparse.ArgumentParser()
+    parser.add_argument(
+        "steamid64", type=int, help="A 64-bit SteamID to convert to a DayZ GUID")
+    args = parser.parse_args()
+
+    print(f"DayZ GUID: {guid_for_steamid64(args.steamid64)}")
+
+
+if __name__ == "__main__":
+    main()
diff --git a/setup.py b/setup.py
index 9c78515..3647588 100644
--- a/setup.py
+++ b/setup.py
@@ -51,7 +51,8 @@
     entry_points={
         "console_scripts": [
             "unpbo=dayz_dev_tools.unpbo:main",
-            "run-server=dayz_dev_tools.run_server:main"
+            "run-server=dayz_dev_tools.run_server:main",
+            "guid=dayz_dev_tools.guid:main"
         ]
     },
     ext_modules=[


Test patch:
diff --git a/tests/test_guid.py b/tests/test_guid.py
new file mode 100644
index 0000000..d97fef8
--- /dev/null
+++ b/tests/test_guid.py
@@ -0,0 +1,39 @@
+import unittest
+from unittest import mock
+
+from dayz_dev_tools import guid
+
+from tests import helpers
+
+
+main = helpers.call_main(guid)
+
+
+class TestGUIDForSteamID64(unittest.TestCase):
+    def test_returns_dayz_guid_for_provided_steam_id64(self) -> None:
+        assert guid.guid_for_steamid64(0) \
+            == "X-zrZv_IbzjZUnhsbWlsecLbwjndTpG0ZynXOif7V-k="
+
+        assert guid.guid_for_steamid64(1234567890) \
+            == "x3Xnt1ft5jDNCqERO9ECZhqziCnKUqZCKreChi8mhkY="
+
+        assert guid.guid_for_steamid64(76561197970002375) \
+            == "hYJaNGoMDv2QEno2R7tXKUSj8eXefMiv_UvAF_EUKto="
+
+        assert guid.guid_for_steamid64(0xffffffffffffffff) \
+            == "LNsmJltNxl47RNaU8SH9bembnkuK5_CNhL-pU3Y1rkM="
+
+
+class TestMain(unittest.TestCase):
+    @mock.patch("builtins.print")
+    def test_prints_dayz_guid_for_given_steamid64(self, mock_print: mock.Mock) -> None:
+        main(
+            [
+                "ignored",
+                "76561197970002375"
+            ],
+            {}
+        )
+
+        mock_print.assert_called_once_with(
+            "DayZ GUID: hYJaNGoMDv2QEno2R7tXKUSj8eXefMiv_UvAF_EUKto=")