Skip to content

Commit

Permalink
Fixed broken private invites by adding generateID_Base36()
Browse files Browse the repository at this point in the history
  • Loading branch information
Naviary2 committed Dec 22, 2024
1 parent 68d9e7c commit 9683151
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/client/scripts/esm/util/uuid.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ function generateID(length) {
return result;
}

/**
* Generates a random ID of the provided length, with the characters 0-9, a-z.
* @param {number} length - The length of the desired ID
* @returns {string} The ID
*/
function generateID_Base36(length) {
let result = '';
const characters = '0123456789abcdefghijklmnopqrstuvwxyz'; // Base 62 characters
const charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength)); // Coercing to an int with Math.floor
}
return result;
}

/**
* Generates a **UNIQUE** ID of the provided length, with the characters 0-9 and a-z.
* The provided object should contain the keys of the existing IDs.
Expand Down Expand Up @@ -99,6 +114,7 @@ function base62ToBase10(base62Str) {

export default {
generateID,
generateID_Base36,
genUniqueID,
generateNumbID,
base10ToBase62,
Expand Down
2 changes: 1 addition & 1 deletion src/server/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if (!DEV_BUILD && !ARE_RATE_LIMITING) throw new Error("ARE_RATE_LIMITING must be
* I recommend 2 seconds of latency for testing slow networks.
*/
const simulatedWebsocketLatencyMillis = 0;
// const simulatedWebsocketLatencyMillis = 1000; // 1 Second
// const simulatedWebsocketLatencyMillis = 2000; // 2 Seconds
if (!DEV_BUILD && simulatedWebsocketLatencyMillis !== 0) throw new Error("simulatedWebsocketLatencyMillis must be 0 in production!!");

/** The domain name of the production website. */
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/invitesmanager/createinvite.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async function createInvite(ws, messageContents, replyto) { // invite: { id, own
const owner = ws.metadata.memberInfo.signedIn ? { member: ws.metadata.memberInfo.username } : { browser: ws.metadata.cookies["browser-id"] };
invite.owner = owner;

do { invite.id = uuid.generateID(5); } while (existingInviteHasID(invite.id));
do { invite.id = uuid.generateID_Base36(5); } while (existingInviteHasID(invite.id));

addInvite(ws, invite, replyto);
}
Expand Down

0 comments on commit 9683151

Please sign in to comment.