Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

SceneID enforced #7094 #9108

Merged
merged 7 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import DialogTitle from '@etherealengine/ui/src/primitives/mui/DialogTitle'
import Grid from '@etherealengine/ui/src/primitives/mui/Grid'

import { useFind, useMutation } from '@etherealengine/engine/src/common/functions/FeathersHooks'
import { SceneID } from '@etherealengine/engine/src/schemas/projects/scene.schema'
import { locationTypePath } from '@etherealengine/engine/src/schemas/social/location-type.schema'
import { NotificationService } from '../../../common/services/NotificationService'
import { AuthState } from '../../../user/services/AuthService'
Expand Down Expand Up @@ -170,7 +171,7 @@ const LocationDrawer = ({ open, mode, selectedLocation, onClose }: Props) => {
const data: LocationData = {
name: state.name.value,
slugifiedName: '',
sceneId: state.scene.value,
sceneId: state.scene.value as SceneID,
maxUsersPerInstance: state.maxUsers.value,
locationSetting: {
id: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import Button from '@etherealengine/ui/src/primitives/mui/Button'
import Chip from '@etherealengine/ui/src/primitives/mui/Chip'

import { useFind, useMutation } from '@etherealengine/engine/src/common/functions/FeathersHooks'
import { SceneID } from '@etherealengine/engine/src/schemas/projects/scene.schema'
import { locationTypePath } from '@etherealengine/engine/src/schemas/social/location-type.schema'
import TableComponent from '../../common/Table'
import { locationColumns } from '../../common/variables/location'
Expand Down Expand Up @@ -90,7 +91,7 @@ const LocationTable = ({ className, search }: Props) => {
el: LocationType,
id: string,
name: string,
sceneId: string,
sceneId: SceneID,
maxUsersPerInstance: string,
scene: string,
locationType: string,
Expand Down Expand Up @@ -132,7 +133,7 @@ const LocationTable = ({ className, search }: Props) => {
el,
el.id,
el.name,
el.sceneId,
el.sceneId as SceneID,
el.maxUsersPerInstance.toString(),
el.slugifiedName,
//@ts-ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { defineState, getMutableState, getState, useState } from '@etherealengin
import { Engine } from '@etherealengine/engine/src/ecs/classes/Engine'
import { instanceProvisionPath } from '@etherealengine/engine/src/schemas/networking/instance-provision.schema'
import { InstanceID, instancePath, InstanceType } from '@etherealengine/engine/src/schemas/networking/instance.schema'
import { SceneID } from '@etherealengine/engine/src/schemas/projects/scene.schema'
import { RoomCode } from '@etherealengine/engine/src/schemas/social/location.schema'
import { API } from '../../API'
import { SocketWebRTCClientNetwork } from '../../transports/SocketWebRTCClientFunctions'
Expand All @@ -43,7 +44,7 @@ export type InstanceState = {
ipAddress: string
port: string
locationId: string | null
sceneId: string | null
sceneId: SceneID | null
roomCode: RoomCode
}

Expand Down Expand Up @@ -72,7 +73,7 @@ export const LocationInstanceConnectionService = {
provisionServer: async (
locationId?: string,
instanceId?: InstanceID,
sceneId?: string,
sceneId?: SceneID,
roomCode?: RoomCode,
createPrivateRoom?: boolean
) => {
Expand Down Expand Up @@ -116,7 +117,7 @@ export const LocationInstanceConnectionService = {
}, 1000)
}
},
provisionExistingServer: async (locationId: string, instanceId: InstanceID, sceneId: string) => {
provisionExistingServer: async (locationId: string, instanceId: InstanceID, sceneId: SceneID) => {
logger.info({ locationId, instanceId, sceneId }, 'Provision Existing World Server')
const token = getState(AuthState).authUser.accessToken
const instance = (await API.instance.client.service(instancePath).find({
Expand Down Expand Up @@ -157,7 +158,7 @@ export const LocationInstanceConnectionService = {
console.warn('Failed to connect to expected existing instance')
}
},
provisionExistingServerByRoomCode: async (locationId: string, roomCode: RoomCode, sceneId: string) => {
provisionExistingServerByRoomCode: async (locationId: string, roomCode: RoomCode, sceneId: SceneID) => {
logger.info({ locationId, roomCode, sceneId }, 'Provision Existing World Server')
const token = getState(AuthState).authUser.accessToken
const instance = (await API.instance.client.service(instancePath).find({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { Engine } from '@etherealengine/engine/src/ecs/classes/Engine'
import { locationPath, LocationType } from '@etherealengine/engine/src/schemas/social/location.schema'
import { defineState, getMutableState } from '@etherealengine/hyperflux'

import { SceneID } from '@etherealengine/engine/src/schemas/projects/scene.schema'
import { locationBanPath } from '@etherealengine/engine/src/schemas/social/location-ban.schema'
import { UserID } from '@etherealengine/engine/src/schemas/user/user.schema'
import { API } from '../../API'
Expand All @@ -39,7 +40,7 @@ export const LocationSeed: LocationType = {
name: '',
slugifiedName: '',
maxUsersPerInstance: 10,
sceneId: '',
sceneId: '' as SceneID,
isLobby: false,
isFeatured: false,
locationSetting: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
} from '@etherealengine/engine/src/schemas/networking/instance-active.schema'
import { instanceProvisionPath } from '@etherealengine/engine/src/schemas/networking/instance-provision.schema'
import { InstanceID } from '@etherealengine/engine/src/schemas/networking/instance.schema'
import { SceneID } from '@etherealengine/engine/src/schemas/projects/scene.schema'
import { defineState, getMutableState, getState } from '@etherealengine/hyperflux'

export const EditorActiveInstanceState = defineState({
Expand All @@ -45,7 +46,7 @@ export const EditorActiveInstanceState = defineState({
fetching: false
}),

provisionServer: async (locationId: string, instanceId: InstanceID, sceneId: string) => {
provisionServer: async (locationId: string, instanceId: InstanceID, sceneId: SceneID) => {
logger.info({ locationId, instanceId, sceneId }, 'Provision World Server Editor')
const token = getState(AuthState).authUser.accessToken
const provisionResult = await Engine.instance.api.service(instanceProvisionPath).find({
Expand All @@ -69,7 +70,7 @@ export const EditorActiveInstanceState = defineState({
}
},

getActiveInstances: async (sceneId: string) => {
getActiveInstances: async (sceneId: SceneID) => {
getMutableState(EditorActiveInstanceState).merge({ fetching: true })
const activeInstances = await Engine.instance.api.service(instanceActivePath).find({
query: { sceneId }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { NetworkState } from '@etherealengine/engine/src/networking/NetworkState
import { getMutableState, getState } from '@etherealengine/hyperflux'

import { EngineState } from '@etherealengine/engine/src/ecs/classes/EngineState'
import { SceneID } from '@etherealengine/engine/src/schemas/projects/scene.schema'
import { EditorState } from '../../services/EditorServices'
import { EditorActiveInstanceState } from './EditorActiveInstanceService'

Expand All @@ -43,7 +44,7 @@ const execute = () => {

if (accumulator > 5) {
accumulator = 0
const sceneId = `${editorState.projectName}/${editorState.sceneName}`
const sceneId = `${editorState.projectName}/${editorState.sceneName}` as SceneID
EditorActiveInstanceState.getActiveInstances(sceneId)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import DirectionsRun from '@mui/icons-material/DirectionsRun'
import DoneIcon from '@mui/icons-material/Done'

import { NetworkState } from '@etherealengine/engine/src/networking/NetworkState'
import { SceneID } from '@etherealengine/engine/src/schemas/projects/scene.schema'
import { EditorState } from '../../services/EditorServices'
import SelectInput from '../inputs/SelectInput'
import { InfoTooltip } from '../layout/Tooltip'
Expand All @@ -65,7 +66,7 @@ export const WorldInstanceConnection = () => {
)

const editorState = useHookstate(getMutableState(EditorState))
const sceneId = `${editorState.projectName.value}/${editorState.sceneName.value}`
const sceneId = `${editorState.projectName.value}/${editorState.sceneName.value}` as SceneID

const onSelectInstance = (selectedInstance: string) => {
if (selectedInstance === 'None' || (worldNetworkHostId && selectedInstance !== worldNetworkHostId)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/functions/sceneFunctions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import multiLogger from '@etherealengine/engine/src/common/functions/logger'
import { serializeWorld } from '@etherealengine/engine/src/scene/functions/serializeWorld'
import { sceneDataPath } from '@etherealengine/engine/src/schemas/projects/scene-data.schema'
import { sceneUploadPath } from '@etherealengine/engine/src/schemas/projects/scene-upload.schema'
import { scenePath } from '@etherealengine/engine/src/schemas/projects/scene.schema'
import { SceneID, scenePath } from '@etherealengine/engine/src/schemas/projects/scene.schema'

const logger = multiLogger.child({ component: 'editor:sceneFunctions' })

Expand Down Expand Up @@ -73,7 +73,7 @@ export const getScene = async (projectName: string, sceneName: string, metadataO
/**
* deleteScene used to delete project using projectId.
*
* @param {any} sceneId
* @param {SceneID} sceneId
* @return {Promise}
*/
export const deleteScene = async (projectName, sceneName): Promise<any> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Ethereal Engine. All Rights Reserved.
// For more information about this file see https://dove.feathersjs.com/guides/cli/service.schemas.html
import type { Static } from '@feathersjs/typebox'
import { getValidator, querySyntax, Type } from '@feathersjs/typebox'
import { TypedString } from '../../common/types/TypeboxUtils'
import { SceneID } from '../projects/scene.schema'
import { dataValidator, queryValidator } from '../validators'
import { instanceSchema } from './instance.schema'

Expand All @@ -48,7 +50,14 @@ export const instanceActiveQuerySchema = Type.Intersect(
[
querySyntax(instanceActiveQueryProperties),
// Add additional query properties here
Type.Object({ sceneId: Type.String() }, { additionalProperties: false })
Type.Object(
{
sceneId: TypedString<SceneID>({
format: 'uuid'
})
},
{ additionalProperties: false }
)
],
{ additionalProperties: false }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { UserID } from '@etherealengine/engine/src/schemas/user/user.schema'
import type { Static } from '@feathersjs/typebox'
import { getValidator, querySyntax, Type } from '@feathersjs/typebox'
import { TypedString } from '../../common/types/TypeboxUtils'
import { SceneID } from '../projects/scene.schema'
import { dataValidator, queryValidator } from '../validators'
import { InstanceID } from './instance.schema'

Expand All @@ -41,7 +42,9 @@ export const instanceAttendanceSchema = Type.Object(
id: Type.String({
format: 'uuid'
}),
sceneId: Type.String(),
sceneId: TypedString<SceneID>({
format: 'uuid'
}),
isChannel: Type.Boolean(),
ended: Type.Boolean(),
instanceId: TypedString<InstanceID>({
Expand Down
3 changes: 3 additions & 0 deletions packages/engine/src/schemas/projects/scene.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Ethereal Engine. All Rights Reserved.

// For more information about this file see https://dove.feathersjs.com/guides/cli/service.schemas.html
import { EntityUUID } from '@etherealengine/common/src/interfaces/EntityUUID'
import { OpaqueType } from '@etherealengine/common/src/interfaces/OpaqueType'
import type { Static } from '@feathersjs/typebox'
import { Type, getValidator, querySyntax } from '@feathersjs/typebox'
import { TypedRecord, TypedString } from '../../common/types/TypeboxUtils'
Expand All @@ -29,6 +30,8 @@ export const scenePath = 'scene'

export const sceneMethods = ['get', 'update', 'create', 'find', 'patch', 'remove'] as const

export type SceneID = OpaqueType<'SceneID'> & string

export const componentJsonSchema = Type.Object(
{
name: Type.String(),
Expand Down
8 changes: 6 additions & 2 deletions packages/engine/src/schemas/social/location.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import type { Static } from '@feathersjs/typebox'
import { getValidator, querySyntax, Type } from '@feathersjs/typebox'

import { OpaqueType } from '@etherealengine/common/src/interfaces/OpaqueType'
import { TypedString } from '../../common/types/TypeboxUtils'
import { SceneID } from '../projects/scene.schema'
import { dataValidator, queryValidator } from '../validators'
import { locationAdminSchema } from './location-admin.schema'
import { locationAuthorizedUserSchema } from './location-authorized-user.schema'
Expand All @@ -47,7 +49,7 @@ export const locationSchema = Type.Object(
format: 'uuid'
}),
name: Type.String(),
sceneId: Type.String({
sceneId: TypedString<SceneID>({
format: 'uuid'
}),
slugifiedName: Type.String(),
Expand Down Expand Up @@ -100,7 +102,9 @@ export const locationQuerySchema = Type.Intersect(
$like: Type.String()
},
sceneId: {
$like: Type.String()
$like: TypedString<SceneID>({
format: 'uuid'
})
}
}),
// Add additional query properties here
Expand Down
16 changes: 10 additions & 6 deletions packages/instanceserver/src/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import {
instancePath
} from '@etherealengine/engine/src/schemas/networking/instance.schema'
import { projectsPath } from '@etherealengine/engine/src/schemas/projects/projects.schema'
import { scenePath } from '@etherealengine/engine/src/schemas/projects/scene.schema'
import { SceneID, scenePath } from '@etherealengine/engine/src/schemas/projects/scene.schema'
import { ChannelUserType, channelUserPath } from '@etherealengine/engine/src/schemas/social/channel-user.schema'
import { ChannelID, ChannelType, channelPath } from '@etherealengine/engine/src/schemas/social/channel.schema'
import { RoomCode, locationPath } from '@etherealengine/engine/src/schemas/social/location.schema'
Expand Down Expand Up @@ -76,7 +76,7 @@ interface PrimusConnectionType {
provider: string
headers: any
socketQuery?: {
sceneId: string
sceneId: SceneID
locationId?: string
instanceID?: InstanceID
channelId?: string
Expand Down Expand Up @@ -233,7 +233,7 @@ const initializeInstance = async (
* @param sceneId
*/

const loadEngine = async (app: Application, sceneId: string) => {
const loadEngine = async (app: Application, sceneId: SceneID) => {
const instanceServerState = getState(InstanceServerState)

const hostId = instanceServerState.instance.id as UserID & InstanceID
Expand Down Expand Up @@ -385,7 +385,7 @@ const createOrUpdateInstance = async (
status: InstanceserverStatus,
locationId: string,
channelId: ChannelID,
sceneId: string,
sceneId: SceneID,
userId?: UserID
) => {
const instanceServerState = getState(InstanceServerState)
Expand Down Expand Up @@ -633,7 +633,10 @@ const onConnection = (app: Application) => async (connection: PrimusConnectionTy
return logger.warn('got a connection to the wrong room code', instanceServerState.instance.roomCode, roomCode)
}

const sceneId = locationId ? (await app.service(locationPath).get(locationId)).sceneId : ''
let sceneId = '' as SceneID
if (locationId) {
sceneId = (await app.service(locationPath).get(locationId)).sceneId
}

/**
* Now that we have verified the connecting user and that they are connecting to the correct instance, load the instance
Expand Down Expand Up @@ -708,7 +711,8 @@ export default (app: Application): void => {
}

app.service('instanceserver-load').on('patched', async (params) => {
const { id, ipAddress, podName, locationId, sceneId } = params
const { id, ipAddress, podName, locationId, sceneId }: { id; ipAddress; podName; locationId; sceneId: SceneID } =
params

const serverState = getState(ServerState)
const instanceServerState = getState(InstanceServerState)
Expand Down
3 changes: 2 additions & 1 deletion packages/projects/createLocations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import fs from 'fs'
import path from 'path'
import { v4 as generateUUID } from 'uuid'

import { SceneID } from '@etherealengine/engine/src/schemas/projects/scene.schema'
import { LocationSettingType } from '@etherealengine/engine/src/schemas/social/location-setting.schema'
import { LocationData, locationPath, LocationType } from '@etherealengine/engine/src/schemas/social/location.schema'
import { Application } from '@etherealengine/server-core/declarations'
Expand Down Expand Up @@ -64,7 +65,7 @@ export const createLocations = async (app: Application, projectName: string) =>
name: locationName,
slugifiedName: sceneName,
maxUsersPerInstance: 30,
sceneId: `${projectName}/${sceneName}`,
sceneId: `${projectName}/${sceneName}` as SceneID,
locationSetting,
isLobby: false,
isFeatured: false
Expand Down
3 changes: 2 additions & 1 deletion packages/server-core/src/bot/bot/bot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { avatarPath } from '@etherealengine/engine/src/schemas/user/avatar.schem

import { BotType, botPath } from '@etherealengine/engine/src/schemas/bot/bot.schema'
import { InstanceType, instancePath } from '@etherealengine/engine/src/schemas/networking/instance.schema'
import { SceneID } from '@etherealengine/engine/src/schemas/projects/scene.schema'
import { LocationType, RoomCode, locationPath } from '@etherealengine/engine/src/schemas/social/location.schema'
import { UserType, userPath } from '@etherealengine/engine/src/schemas/user/user.schema'
import { Application } from '../../../declarations'
Expand Down Expand Up @@ -58,7 +59,7 @@ describe('bot.service', () => {
{
name: 'test-bot-location-' + v1(),
slugifiedName: '',
sceneId: 'test-bot-scene-id-' + v1(),
sceneId: ('test-bot-scene-id-' + v1()) as SceneID,
maxUsersPerInstance: 30,
locationSetting: {
id: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { matchTicketAssignmentPath } from '@etherealengine/matchmaking/src/match
import { matchTicketPath, MatchTicketType } from '@etherealengine/matchmaking/src/match-ticket.schema'

import { instancePath } from '@etherealengine/engine/src/schemas/networking/instance.schema'
import { SceneID } from '@etherealengine/engine/src/schemas/projects/scene.schema'
import { LocationSettingType } from '@etherealengine/engine/src/schemas/social/location-setting.schema'
import { identityProviderPath } from '@etherealengine/engine/src/schemas/user/identity-provider.schema'
import { userPath } from '@etherealengine/engine/src/schemas/user/user.schema'
Expand Down Expand Up @@ -108,7 +109,7 @@ describe.skip('matchmaking match-instance service', () => {
name: `game-${gameMode}`,
slugifiedName: `game-${gameMode}`,
maxUsersPerInstance: 30,
sceneId: `test/game-${gameMode}`,
sceneId: `test/game-${gameMode}` as SceneID,
locationSetting: commonlocationSetting,
isLobby: false,
isFeatured: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
instanceProvisionPath
} from '@etherealengine/engine/src/schemas/networking/instance-provision.schema'
import { InstanceID } from '@etherealengine/engine/src/schemas/networking/instance.schema'
import { SceneID } from '@etherealengine/engine/src/schemas/projects/scene.schema'
import { Application } from '../../../declarations'
import logger from '../../ServerLogger'
import { InstanceProvisionService } from './instance-provision.class'
Expand Down Expand Up @@ -64,7 +65,7 @@ export default (app: Application): void => {
ipAddress: data.ipAddress,
port: data.port,
locationId: data.locationId,
sceneId: data.sceneId,
sceneId: data.sceneId as SceneID,
channelId: data.channelId,
instanceId: data.instanceId as InstanceID
})
Expand Down
Loading
Loading