From 5e805706ba1c9a4d176d9ae8dec2963c8e089612 Mon Sep 17 00:00:00 2001 From: neverbot Date: Thu, 2 May 2024 19:08:28 +0200 Subject: [PATCH] feat(uuid): uuid package --- mudlib/.gitignore | 1 + mudlib/packages/uuid/master.c | 2 ++ mudlib/packages/uuid/readme.md | 22 ++++++++++++++++++++++ mudlib/packages/uuid/src/uuid.c | 11 +++++++++++ 4 files changed, 36 insertions(+) create mode 100644 mudlib/packages/uuid/master.c create mode 100644 mudlib/packages/uuid/readme.md create mode 100644 mudlib/packages/uuid/src/uuid.c diff --git a/mudlib/.gitignore b/mudlib/.gitignore index 7778885..20250ea 100644 --- a/mudlib/.gitignore +++ b/mudlib/.gitignore @@ -33,6 +33,7 @@ !/packages/json !/packages/test !/packages/time +!/packages/uuid # ignore games, except the common ones diff --git a/mudlib/packages/uuid/master.c b/mudlib/packages/uuid/master.c new file mode 100644 index 0000000..a7a5de1 --- /dev/null +++ b/mudlib/packages/uuid/master.c @@ -0,0 +1,2 @@ + +inherit "/packages/uuid/src/uuid.c"; diff --git a/mudlib/packages/uuid/readme.md b/mudlib/packages/uuid/readme.md new file mode 100644 index 0000000..5b22698 --- /dev/null +++ b/mudlib/packages/uuid/readme.md @@ -0,0 +1,22 @@ + +# uuid.c + +Found in: + +[LPCsnippets Github Repository](https://github.com/atari2600tim/LPCsnippets/blob/master/uuid.c). + +## Info + +This is a "version 4" uuid. This is based on random numbers, the others use time. +https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_(random) +supposed to use lower case but accept upper case (so run lower_case when comparing incoming stuff) + +Author unknown. + +Example: + +``` +> exec return "/packages/uuid/src/uuid.c"->uuid() +Result: + "be97d609-4d5d-4e35-9b17-00a2f85d353f" +``` diff --git a/mudlib/packages/uuid/src/uuid.c b/mudlib/packages/uuid/src/uuid.c new file mode 100644 index 0000000..cdd5987 --- /dev/null +++ b/mudlib/packages/uuid/src/uuid.c @@ -0,0 +1,11 @@ + +string uuid() +{ + // This is a "version 4" uuid. This is based on random numbers, the others use time. + // https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_(random) + // supposed to use lower case but accept upper case (so run lower_case when comparing incoming stuff) + + return sprintf("%04x%04x-%04x-4%03x-%0x%03x-%04x%04x%04x", + random(0x10000),random(0x10000),random(0x10000),random(0x1000), + (8+random(4)), random(0x1000),random(0x10000),random(0x10000),random(0x10000)); +}