GithubHelp home page GithubHelp logo

southclaws / pawn-uuid Goto Github PK

View Code? Open in Web Editor NEW
16.0 6.0 2.0 27 KB

A Pawn plugin that provides a simple UUID version 4 generator function.

License: MIT License

CMake 7.56% Makefile 3.25% C++ 84.14% Pawn 3.72% Dockerfile 1.33%
pawn-package sa-mp sa-mp-plugin

pawn-uuid's Introduction

pawn-uuid

sampctl

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:

sampctl package install Southclaws/pawn-uuid

Include in your code and begin using the library:

#include <uuid>

And add to your runtime configuration:

{
  "plugins": ["Southclaws/pawn-uuid"]
}

Usage

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

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

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!

make test-linux

pawn-uuid's People

Contributors

adrfranklin avatar southclaws avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pawn-uuid's Issues

Crash on unload

I have seen this issue here, and I assume it was fixed, but I still got the crash on server exit or restart. Is there a solution to this? Nearly 3 years later, but I would use this plugin.

SA-MP Dedicated Server
----------------------
v0.3.7-R3, (C)2005-2019 SA-MP Team

[00:14:46] filterscripts = ""  (string)
[00:14:46] 
[00:14:46] Server Plugins
[00:14:46] --------------
[00:14:46]  Loading plugin: uuid
[00:14:46]   Loaded.
[00:14:46]  Loading plugin: crashdetect
[00:14:46]   CrashDetect plugin 4.20
[00:14:46]   Loaded.
[00:14:46]  Loading plugin: streamer
[00:14:46] 

*** Streamer Plugin v2.9.5 by Incognito loaded ***

[00:14:46]   Loaded.
[00:14:46]  Loading plugin: sscanf
[00:14:46] 

[00:14:46]  ===============================

[00:14:46]       sscanf plugin loaded.     

[00:14:46]          Version:  2.8.3        

[00:14:46]   (c) 2018 Alex "Y_Less" Cole  

[00:14:46]  ===============================

[00:14:46]   Loaded.
[00:14:46]  Loading plugin: chrono
[00:14:46]   Loaded.
[00:14:46]  Loading plugin: filemanager
[00:14:46] ******************
[00:14:46] ** FILE MANAGER **
[00:14:46] **    Loaded    **
[00:14:46] ** Version 1.5 **
[00:14:46] ******************
[00:14:46]   Loaded.
[00:14:46]  Loaded 6 plugins.

[00:14:46] 
[00:14:46] Filterscripts
[00:14:46] ---------------
[00:14:46]   Loaded 0 filterscripts.

[00:14:46] Number of vehicle models: 0
Console input: gmx
[00:15:02] [debug] Server crashed due to an unknown error
[debug] Native backtrace:
[debug] #0 029482ff in ?? ()
[debug] Registers:
[debug] EAX: 0019fcdc EBX: 02948288 ECX: 00600fb8 EDX: 005f0000
[debug] ESI: 02948288 EDI: 00000000 EBP: 75a10f00 ESP: 02479760
[debug] EIP: 029482ff EFLAGS: 00010206
[debug] Stack:
[debug] ESP+00000000: c80469c9 8c001400 0000000c 00000001
[debug] ESP+00000020: c5b0d135 8c001500 0000000a 000002d2
[debug] ESP+00000040: c5b4d131 8c001600 0000000d 00000002
[debug] ESP+00000060: c588d13d 8c001700 0000001a 00000001
[debug] ESP+00000080: c58cd139 8c001800 00000012 00000001
[debug] ESP+000000a0: c580d0c5 8c001900 00000018 00000001
[debug] ESP+000000c0: c584d0c1 8c001a00 00000013 00000001
[debug] ESP+000000e0: c598d0cd 8c001b00 00000015 00000001
[debug] ESP+00000100: c59cd0c9 8c001c00 00000019 00000001
[debug] ESP+00000120: c590d0d5 88001d00 028c5d50 00000001
[debug] ESP+00000140: c594d0d1 8c001e00 0000001b 00000001
[debug] ESP+00000160: fedced43 08002807 63820000 00010200
[debug] ESP+00000180: 638226f0 63822720 9edced23 08002883
[debug] ESP+000001a0: 00000000 00000000 00000000 00000000
[debug] ESP+000001c0: 00000000 00000000 00000000 00000000
[debug] ESP+000001e0: 00000000 00000000 00000000 00000000
[debug] ESP+00000200: 00000000 00000000 00000000 00000000
[debug] ESP+00000220: 00000000 00000000 00000000 00000000
[debug] ESP+00000240: 00000000 00000000 00000000 00000000
[debug] ESP+00000260: 00000000 00000000 00000000 00000000
[debug] ESP+00000280: 00000000 00000000 00000000 00000000
[debug] ESP+000002a0: 00000000 00000000 00000000 00000000
[debug] ESP+000002c0: 00000000 00000000 00000000 00000000
[debug] ESP+000002e0: 00000000 00000000 00000000 00000000
[debug] ESP+00000300: 00000000 00000000 00000000 00000000
[debug] ESP+00000320: 00000000 00000000 00000000 00000000
[debug] ESP+00000340: 00000000 00000000 00000000 00000000
[debug] ESP+00000360: 00000000 00000000 00000000 00000000
[debug] ESP+00000380: 00000000 00000000 00000000 00000000
[debug] ESP+000003a0: 00000000 00000000 00000000 00000000
[debug] ESP+000003c0: 00000000 00000000 00000000 00000000
[debug] ESP+000003e0: 00000000 00000000 00000000 00000000
[debug] Loaded modules:
[debug] 00400000 - 00519000 samp-server.exe
[debug] 77650000 - 777f3000 ntdll.dll
[debug] 759f0000 - 75ae0000 KERNEL32.DLL
[debug] 772a0000 - 774b4000 KERNELBASE.dll
[debug] 76450000 - 76a03000 SHELL32.dll
[debug] 775c0000 - 7763b000 msvcp_win.dll
[debug] 757f0000 - 75910000 ucrtbase.dll
[debug] 75d60000 - 75ef6000 USER32.dll
[debug] 75ce0000 - 75cf8000 win32u.dll
[debug] 76290000 - 762b3000 GDI32.dll
[debug] 75680000 - 7575c000 gdi32full.dll
[debug] 75460000 - 75488000 WINMM.dll
[debug] 548c0000 - 548c8000 WSOCK32.dll
[debug] 75760000 - 757c3000 ws2_32.DLL
[debug] 76d90000 - 76e4f000 msvcrt.dll
[debug] 77500000 - 775c0000 RPCRT4.dll
[debug] 76310000 - 76335000 IMM32.DLL
[debug] 639a0000 - 639a7000 uuid.DLL
[debug] 76a90000 - 76b73000 ole32.dll
[debug] 75f10000 - 76191000 combase.dll
[debug] 6f0c0000 - 6f12d000 MSVCP140.dll
[debug] 6f130000 - 6f144000 VCRUNTIME140.dll
[debug] 541f0000 - 54241000 crashdetect.DLL
[debug] 54170000 - 541e1000 MSVCP120.dll
[debug] 520c0000 - 521ae000 MSVCR120.dll
[debug] 54010000 - 5407d000 streamer.DLL
[debug] 10000000 - 1000e000 sscanf.DLL
[debug] 557b0000 - 557d9000 chrono.DLL
[debug] 63820000 - 6382b000 filemanager.DLL
[debug] 52030000 - 520b5000 MSVCP110.dll
[debug] 53dc0000 - 53e96000 MSVCR110.dll
[debug] 70bf0000 - 70c42000 mswsock.dll
[debug] 50a20000 - 50a31000 napinsp.dll
[debug] 76b90000 - 76c05000 sechost.dll
[debug] 50a00000 - 50a16000 pnrpnsp.dll
[debug] 509f0000 - 50a00000 wshbth.dll
[debug] 586d0000 - 586e6000 NLAapi.dll
[debug] 70ed0000 - 70f02000 IPHLPAPI.DLL
[debug] 70e30000 - 70ec2000 DNSAPI.dll
[debug] 75f00000 - 75f07000 NSI.dll
[debug] 509e0000 - 509ee000 winrnr.dll
[debug] 678a0000 - 678f8000 fwpuclnt.dll
[debug] 757d0000 - 757e9000 bcrypt.dll
[debug] 6ea60000 - 6ea68000 rasadhlp.dll
[debug] 755b0000 - 7560f000 bcryptPrimitives.dll

makefile recipes

make test-debian doesn't exist.
make build-inside tries to cd in to build/, which also doesn't exist.

Debian erro

[18:03:51]  Loading plugin: uuid.so
[18:03:51]   Failed (/usr/lib/i386-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by plugins/uuid.so))

how to solve this?

OBS: debian 8 32bits

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.