SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 10/04/2018, 01:59 PM   #1
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,987
Reputation: 1558
Default UUID4 - Universal Unique Identifiers

pawn-uuid



uuid provides a simple UUID version 4 generator function.

Whatís a UUID? A UUID (Universal Unique Identifier) is a standardised implementation of generating unique byte sequences. In string format, these UUIDs look like this:
  • e338fae6-9df9-4e21-bb59-667c29e419cf
  • 0149476c-cf42-4432-b946-d9695656aec0
  • dcd2d8bd-0fb8-44db-93fd-b00efaa610ae


Youíll probably see these style strings all over the place from newsletters to website account IDs. They are very useful for uniquely identifying things without falling back to user-defined names or incrementing IDs.

What are these useful for?

Identifiers like this are perfect for identifying players without relying on their username - this allows players to freely change their username without changing a ton of database relations.

Itís also perfect for identifying entities such as vehicles, pickups, items, etc. A good example of this is the Scavenge and Survive gamemode: on each server restart, around 10-20,000 items are generated and placed in the world, each of these items is assigned a unique identifier so if a player picks one up and keeps it in their inventory or in a vehicle trunk, the unique identifier persists throughout the itemís lifetime and everywhere it goes can be tracked. This is very useful for auditing and anti-cheat.

Why not use an incrementing ID?

If youíre an SQL user you probably use AUTOINCREMENT to assign unique identifiers to entities you persist in the database.

The problem with this is youíre relying on the database implementation to handle the uniqueness. This locks you into using that database and also means thereís a reliance on sequentiality in the identifiers.

Why not use a random integer?

Sure there are 2^32 valid states you can use in a Pawn cell (integer), whatís the chance of a collision? Thatís not actually a whole lot of entropy, especially if youíre creating new entities on every server restart/multiple times a day. Itís best to be safe when trying to generate unique identifiers.

Installation

Source and Binaries on GitHub

Simply install to your project:

Code:
sampctl package install Southclaws/pawn-uuid
Include in your code and begin using the library:

Code:

#include <uuid>
And add to your runtime configuration:

PHP Code:
{
  
"plugins": ["Southclaws/pawn-uuid"]

Usage

Thereís only one function and one constant, the following example should be enough documentation for usage:

Code:

new uuid[UUID_LEN];
UUID(uuid, UUID_LEN);
printf("UUID: '%s'", uuid);
// prints a nice unique string shaped like: 00000000-0000-0000-0000-000000000000
Testing

Run unit tests with:

Windows

Code:
make test-windows
Linux

Requires Docker to be installed and available at the command line. If youíre actually on a Linux machine, just run the Windows makefile command above and itíll still run fine on Linux!

Code:
make test-debian
__________________
Tools:

Plugins:

Links:

[HLF]Southclaw is offline   Reply With Quote
Old 10/04/2018, 02:19 PM   #2
Xportaler
Banned
 
Join Date: Feb 2017
Posts: 100
Reputation: 4
Default Re: UUID4 - Universal Unique Identifiers

Really Awesome! OMG I really need this. Can you make some tutorials how to use this. For Newbies
Xportaler is offline   Reply With Quote
Old 10/04/2018, 03:09 PM   #3
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,987
Reputation: 1558
Default Re: UUID4 - Universal Unique Identifiers

Quote:
Originally Posted by Xportaler View Post
Really Awesome! OMG I really need this. Can you make some tutorials how to use this. For Newbies
I'm not sure this warrants even one tutorial, let alone multiple tutorials...

__________________
Tools:

Plugins:

Links:

[HLF]Southclaw is offline   Reply With Quote
Old 10/04/2018, 05:35 PM   #4
DeitY
Huge Clucker
 
DeitY's Avatar
 
Join Date: Aug 2012
Location: Serbia
Posts: 317
Reputation: 14
Default Re: UUID4 - Universal Unique Identifiers

u are fkn God
__________________
Serbian RolePlay Server! 5+ Years SAMP server, 3+ years highest number of players!

DeitY is offline   Reply With Quote
Old 10/04/2018, 06:01 PM   #5
RogueDrifter
High-roller
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 1,170
Reputation: 351
Default Re: UUID4 - Universal Unique Identifiers

Nice nice serves its purpose well, u r on fire mate gj ;d
__________________

[Github]:Link [Gists]:Link [Forum]:Link [Server]:Link [Discord]:Link


RogueDrifter is offline   Reply With Quote
Old 10/04/2018, 06:32 PM   #6
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,310
Reputation: 3191
Default Re: UUID4 - Universal Unique Identifiers

Can I use this with dini?
Y_Less is offline   Reply With Quote
Old 10/04/2018, 07:40 PM   #7
Kar
High-roller
 
Kar's Avatar
 
Join Date: May 2010
Location: Black Asylum
Posts: 3,156
Reputation: 511
Default Re: UUID4 - Universal Unique Identifiers

Quote:
Originally Posted by Y_Less View Post
Can I use this with dini?
or LuxAdmin?
Kar is offline   Reply With Quote
Old 10/04/2018, 07:54 PM   #8
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,310
Reputation: 3191
Default Re: UUID4 - Universal Unique Identifiers

Quote:
Originally Posted by Kar View Post
or LuxAdmin?
I don't care about that, I just want to use this in my new strcmp UCP. It looks brilliant, and exactly what I need.

Just one question - what is it?
Y_Less is offline   Reply With Quote
Old 10/04/2018, 08:37 PM   #9
FinStar
Big Clucker
 
Join Date: Nov 2013
Location: You know
Posts: 151
Reputation: 0
Default Re: UUID4 - Universal Unique Identifiers

many users will think that it is also a 'GPCI' replacement, but i think is so good. Good job y+
FinStar is offline   Reply With Quote
Old 10/04/2018, 08:51 PM   #10
RogueDrifter
High-roller
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 1,170
Reputation: 351
Default Re: UUID4 - Universal Unique Identifiers

Quote:
Originally Posted by FinStar View Post
many users will think that it is also a 'GPCI' replacement, but i think is so good. Good job y+
It's a random string generator "uses the operating system's source of entropy for good quality randomness and a conformant implementation of the UUID algorithm" , nothing to do with players (according to southclaws).
__________________

[Github]:Link [Gists]:Link [Forum]:Link [Server]:Link [Discord]:Link


RogueDrifter is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dialogs unique identifiers (no longer maintained) Donny_k Help Archive 67 27/11/2009 11:40 PM


All times are GMT. The time now is 05:47 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.