Skip to content

Commit 1fb0cfb

Browse files
committed
add uid generator page and donate buttons
1 parent 686cc08 commit 1fb0cfb

File tree

2 files changed

+105
-6
lines changed

2 files changed

+105
-6
lines changed

frontend/docusaurus.config.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import {
2-
NormalizedSidebarItem
3-
} from "@docusaurus/plugin-content-docs/src/sidebars/types.js";
1+
import { NormalizedSidebarItem } from "@docusaurus/plugin-content-docs/src/sidebars/types.js";
42
import type * as Preset from "@docusaurus/preset-classic";
53
import type { Config } from "@docusaurus/types";
64
import { themes as prismThemes } from "prism-react-renderer";
@@ -209,12 +207,17 @@ const config: Config = {
209207
{ to: "/servers", label: "Servers", position: "right" },
210208
{ to: "/partners", label: "Partners", position: "right" },
211209
{
212-
type: "localeDropdown", // This adds the language switcher
210+
href: "https://github.com/openmultiplayer",
211+
label: "GitHub",
213212
position: "right",
214213
},
215214
{
216-
href: "https://github.com/openmultiplayer",
217-
label: "GitHub",
215+
href: "https://opencollective.com/openmultiplayer",
216+
label: "Donate",
217+
position: "right",
218+
},
219+
{
220+
type: "localeDropdown", // This adds the language switcher
218221
position: "right",
219222
},
220223
],
@@ -254,6 +257,10 @@ const config: Config = {
254257
label: "GitHub",
255258
href: "https://github.com/openmultiplayer/open.mp",
256259
},
260+
{
261+
label: "Donate",
262+
href: "https://opencollective.com/openmultiplayer",
263+
},
257264
{
258265
label: "YouTube",
259266
href: "https://youtube.com/openmultiplayer",
@@ -275,6 +282,10 @@ const config: Config = {
275282
label: "Blog",
276283
to: "/blog",
277284
},
285+
{
286+
label: "UID Generator",
287+
to: "/uid",
288+
},
278289
{
279290
label: "SA-MP",
280291
href: "https://sa-mp.mp/",

frontend/src/pages/uid.tsx

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import Layout from "@theme/Layout";
2+
import { ReactNode, useEffect, useState } from "react";
3+
import { ToastContainer } from "../components/Toast";
4+
5+
const Page = (): ReactNode => {
6+
const [uid, setUID] = useState<string>("");
7+
8+
useEffect(() => {
9+
const rnd = randomBytes(8);
10+
11+
function toHex(number: number): string {
12+
return ("00" + number.toString(16)).slice(-2).toUpperCase();
13+
}
14+
15+
const serialised = `0x${toHex(rnd[0])}${toHex(rnd[1])}${toHex(
16+
rnd[2]
17+
)}${toHex(rnd[3])}${toHex(rnd[4])}${toHex(rnd[5])}${toHex(rnd[6])}${toHex(
18+
rnd[7]
19+
)}`;
20+
21+
setUID(serialised);
22+
}, []);
23+
24+
return (
25+
<div>
26+
<Layout
27+
title={`UID Generator`}
28+
description="Generate UID to use for IComponent or IExtension unique identifiers"
29+
>
30+
<section className="servers-container">
31+
<h1>Component UID Generator</h1>
32+
Copy the <code>PROVIDE_UID</code> macro below in to your new
33+
component, in place of the default UID provider macro. Each component
34+
should have a unique UID, hence the <em>U</em> in <em>UID</em> (
35+
<em>Unique IDentifier</em>). The default <code>PROVIDE_UID</code> is
36+
invalid and will not compile, to avoid duplicates when creating new
37+
components from templates.
38+
<br />
39+
<br />
40+
Find this placeholder:
41+
<pre>PROVIDE_UID(/* UID GOES HERE */);</pre>
42+
<br />
43+
And replace it with:
44+
<pre>{`PROVIDE_UID(${uid});`}</pre>
45+
<br />
46+
If you are modifying an existing component still do remember to
47+
replace the existing UID, which will be a valid value not a
48+
placeholder.
49+
</section>
50+
</Layout>
51+
<ToastContainer />
52+
</div>
53+
);
54+
};
55+
56+
export default Page;
57+
58+
function randomBytes(size: number): Uint8Array {
59+
// Input validation
60+
if (!Number.isInteger(size) || size < 0) {
61+
throw new TypeError("Size must be a non-negative integer");
62+
}
63+
64+
// Use Web Crypto API which provides cryptographically secure random values
65+
if (typeof window !== "undefined" && window.crypto) {
66+
// Browser environment
67+
const buffer = new Uint8Array(size);
68+
window.crypto.getRandomValues(buffer);
69+
return buffer;
70+
} else if (typeof global !== "undefined" && global.crypto) {
71+
// Node.js environment with Web Crypto API
72+
const buffer = new Uint8Array(size);
73+
global.crypto.getRandomValues(buffer);
74+
return buffer;
75+
} else {
76+
// Fallback for environments without Web Crypto API
77+
const buffer = new Uint8Array(size);
78+
for (let i = 0; i < size; i++) {
79+
// Generate random bytes using Math.random()
80+
// Note: This is NOT cryptographically secure!
81+
buffer[i] = Math.floor(Math.random() * 256);
82+
}
83+
console.warn(
84+
"Warning: Using non-cryptographically secure random number generation"
85+
);
86+
return buffer;
87+
}
88+
}

0 commit comments

Comments
 (0)