Add launchable
This commit is contained in:
36
js/core/Auth.js
Normal file
36
js/core/Auth.js
Normal file
@@ -0,0 +1,36 @@
|
||||
export class Auth {
|
||||
constructor(baseUrl = "http://localhost:5000") {
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify a session token against the fake auth API.
|
||||
* Returns the user ID if valid, or null if invalid.
|
||||
*/
|
||||
async verifySessionToken(token) {
|
||||
try {
|
||||
const res = await fetch(`${this.baseUrl}/api/verify/${encodeURIComponent(token)}`);
|
||||
if (!res.ok) return null;
|
||||
const data = await res.json();
|
||||
return data.id ?? null;
|
||||
} catch (err) {
|
||||
console.warn("[Auth] verifySessionToken error:", err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up the user's display name by ID.
|
||||
*/
|
||||
async getUserNameById(id) {
|
||||
try {
|
||||
const res = await fetch(`${this.baseUrl}/api/users`);
|
||||
if (!res.ok) return "Unknown";
|
||||
const data = await res.json();
|
||||
return data[id] ?? `User${id}`;
|
||||
} catch (err) {
|
||||
console.warn("[Auth] getUserNameById error:", err);
|
||||
return `User${id}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
28
js/core/AuthStub.js
Normal file
28
js/core/AuthStub.js
Normal file
@@ -0,0 +1,28 @@
|
||||
// For whoever is going to use this engine later, please modify this file to actually do authentication.
|
||||
|
||||
export class Auth {
|
||||
/**
|
||||
* Verifies a session token and returns a user ID.
|
||||
* In this dummy version, it just returns a random numeric ID.
|
||||
*
|
||||
* @param {string} token - The player's session token.
|
||||
* @returns {number|null} - The verified user ID, or null if invalid.
|
||||
*/
|
||||
verifySessionToken(token) {
|
||||
// Dummy implementation: always "verifies" successfully.
|
||||
if (token === "fake") return null; // Simulate invalid token
|
||||
return Math.floor(Math.random() * 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a user's display name by their ID.
|
||||
* Replace this with a real lookup (e.g., database or API call).
|
||||
*
|
||||
* @param {number|string} userId - The player's user ID.
|
||||
* @returns {string} - The player's display name.
|
||||
*/
|
||||
getUserNameById(userId) {
|
||||
// Dummy implementation
|
||||
return `User${userId}`;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,16 @@ export class DataModel extends Instance {
|
||||
return this.Children.find(c => c.ClassName === name) || null;
|
||||
}
|
||||
GetDataModel() {return this;} // Override to return self
|
||||
|
||||
LuaBridge () {
|
||||
const obj = super.LuaBridge();
|
||||
obj.GetService = (name) => {
|
||||
if (name === "RunService") name = "RenderService"; // Alias
|
||||
const service = this.GetService(name);
|
||||
return service ? service.LuaBridge() : null;
|
||||
}
|
||||
}
|
||||
|
||||
} // Just a container for the whole instance tree
|
||||
// cuz this is an Entity Component System, we need a root entity
|
||||
// Assume all children of DataModel are services or top-level game objects
|
||||
@@ -134,6 +134,7 @@ function eulerDecoder(arr) { // Float32Array(3) to THREE.Euler
|
||||
const encoders = {
|
||||
Vector3: { encode: v3Encoder, decode: v3Decoder },
|
||||
Euler: { encode: eulerEncoder, decode: eulerDecoder },
|
||||
bool: { encode: (bool)=>bool, decode:(bool)=>bool}
|
||||
// Add more as needed
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user