Skip to content

Commit

Permalink
Check spawn_and_move_media permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
johnshaughnessy committed Jun 27, 2023
1 parent 6aa7ca9 commit 55358e7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 18 additions & 4 deletions src/prefabs/prefabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,29 @@ type CameraPrefabT = () => EntityDef;
type CubeMediaPrefabT = () => EntityDef;
type MediaPrefabT = (params: MediaLoaderParams) => EntityDef;

type Permission =
| "spawn_camera"
| "spawn_and_move_media"
| "update_hub"
| "pin_objects"
| "spawn_emoji"
| "amplify_audio"
| "fly"
| "voice_chat"
| "spawn_drawing"
| "tweet"
| "kick_users"
| "mute_users";

export type PrefabDefinition = {
permission?: "spawn_camera";
permission: Permission;
template: CameraPrefabT | CubeMediaPrefabT | MediaPrefabT;
};

export type PrefabName = "camera" | "cube" | "media" | "duck";

export const prefabs = new Map<PrefabName, PrefabDefinition>();
prefabs.set("camera", { permission: "spawn_camera", template: CameraPrefab });
prefabs.set("cube", { template: CubeMediaFramePrefab });
prefabs.set("media", { template: MediaPrefab });
prefabs.set("duck", { template: DuckPrefab });
prefabs.set("cube", { permission: "spawn_and_move_media", template: CubeMediaFramePrefab });
prefabs.set("media", { permission: "spawn_and_move_media", template: MediaPrefab });
prefabs.set("duck", { permission: "spawn_and_move_media", template: DuckPrefab });
2 changes: 1 addition & 1 deletion src/utils/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import type { ClientID } from "./networking-types";
export function hasPermissionToSpawn(creator: ClientID, prefabName: PrefabName) {
if (creator === "reticulum") return true;
const perm = prefabs.get(prefabName)!.permission;
return !perm || APP.hubChannel!.userCan(creator, perm);
return APP.hubChannel!.userCan(creator, perm);
}

0 comments on commit 55358e7

Please sign in to comment.