diff --git a/gaseous-server/Classes/Metadata/Games.cs b/gaseous-server/Classes/Metadata/Games.cs index 516a43a..4eef302 100644 --- a/gaseous-server/Classes/Metadata/Games.cs +++ b/gaseous-server/Classes/Metadata/Games.cs @@ -477,48 +477,60 @@ namespace gaseous_server.Classes.Metadata private static async Task _SearchForGameRemote(string SearchString, long PlatformId, SearchType searchType) { - string searchBody = ""; - string searchFields = "fields id,name,slug,platforms,summary; "; - bool allowSearch = true; - switch (searchType) + switch (Communications.MetadataSource) { - case SearchType.searchNoPlatform: - searchBody = "search \"" + SearchString + "\"; "; + case HasheousClient.Models.MetadataModel.MetadataSources.None: + return new Game[0]; + case HasheousClient.Models.MetadataModel.MetadataSources.IGDB: + string searchBody = ""; + string searchFields = "fields id,name,slug,platforms,summary; "; + bool allowSearch = true; + switch (searchType) + { + case SearchType.searchNoPlatform: + searchBody = "search \"" + SearchString + "\"; "; - allowSearch = AllowNoPlatformSearch; - break; - case SearchType.search: - searchBody = "search \"" + SearchString + "\"; where platforms = (" + PlatformId + ");"; - break; - case SearchType.wherefuzzy: - searchBody = "where platforms = (" + PlatformId + ") & name ~ *\"" + SearchString + "\"*;"; - break; - case SearchType.where: - searchBody = "where platforms = (" + PlatformId + ") & name ~ \"" + SearchString + "\";"; - break; - } + allowSearch = AllowNoPlatformSearch; + break; + case SearchType.search: + searchBody = "search \"" + SearchString + "\"; where platforms = (" + PlatformId + ");"; + break; + case SearchType.wherefuzzy: + searchBody = "where platforms = (" + PlatformId + ") & name ~ *\"" + SearchString + "\"*;"; + break; + case SearchType.where: + searchBody = "where platforms = (" + PlatformId + ") & name ~ \"" + SearchString + "\";"; + break; + } - // check search cache - Game[]? games = Communications.GetSearchCache(searchFields, searchBody); + // check search cache + Game[]? games = Communications.GetSearchCache(searchFields, searchBody); - if (games == null) - { - // cache miss - // get Game metadata - Communications comms = new Communications(); - Game[]? results = new Game[0]; - if (allowSearch == true) - { - results = await comms.APIComm(IGDBClient.Endpoints.Games, searchFields, searchBody); + if (games == null) + { + // cache miss + // get Game metadata + Communications comms = new Communications(); + Game[]? results = new Game[0]; + if (allowSearch == true) + { + results = await comms.APIComm(IGDBClient.Endpoints.Games, searchFields, searchBody); - Communications.SetSearchCache(searchFields, searchBody, results); - } + Communications.SetSearchCache(searchFields, searchBody, results); + } - return results; - } - else - { - return games.ToArray(); + return results; + } + else + { + return games.ToArray(); + } + + case HasheousClient.Models.MetadataModel.MetadataSources.Hasheous: + return new Game[0]; + + default: + return new Game[0]; } } diff --git a/gaseous-server/Controllers/V1.0/GamesController.cs b/gaseous-server/Controllers/V1.0/GamesController.cs index b7b0a60..55dc3e9 100644 --- a/gaseous-server/Controllers/V1.0/GamesController.cs +++ b/gaseous-server/Controllers/V1.0/GamesController.cs @@ -704,6 +704,42 @@ namespace gaseous_server.Controllers } } + [MapToApiVersion("1.0")] + [MapToApiVersion("1.1")] + [HttpGet] + [Route("{GameId}/gamemode")] + [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ResponseCache(CacheProfileName = "7Days")] + public async Task GameMode(long GameId) + { + try + { + IGDB.Models.Game gameObject = Classes.Metadata.Games.GetGame(GameId, false, false, false); + if (gameObject != null) + { + List gameModeObjects = new List(); + if (gameObject.GameModes != null) + { + foreach (long gameModeId in gameObject.GameModes.Ids) + { + gameModeObjects.Add(Classes.Metadata.GameModes.GetGame_Modes(gameModeId)); + } + } + + return Ok(gameModeObjects); + } + else + { + return NotFound(); + } + } + catch + { + return NotFound(); + } + } + [MapToApiVersion("1.0")] [MapToApiVersion("1.1")] [HttpGet] diff --git a/gaseous-server/wwwroot/pages/game.js b/gaseous-server/wwwroot/pages/game.js index 3c74733..08e4110 100644 --- a/gaseous-server/wwwroot/pages/game.js +++ b/gaseous-server/wwwroot/pages/game.js @@ -406,7 +406,7 @@ function SetupPage() { function LoadGamePlatforms() { // get platforms - ajaxCall('/api/v1.1/Games/' + gameId + '/platforms', 'GET', function (result) { + ajaxCall('/api/v1.1/Games/' + gameId + '/platforms', 'GET', async function (result) { let platformContainer = document.getElementById('gamesummaryplatformscontent'); platformContainer.innerHTML = ''; for (let i = 0; i < result.length; i++) { @@ -437,7 +437,7 @@ function LoadGamePlatforms() { platformItem.setAttribute('isFavourite', true); platformItem.classList.add('platform_item_green'); - let launchLink = BuildLaunchLink(platformData.emulatorConfiguration.emulatorType, platformData.emulatorConfiguration.core, platformData.id, Number(gameId), platformData.favouriteRomId, platformData.favouriteRomIsMediagroup, platformData.favouriteRomName); + let launchLink = await BuildLaunchLink(platformData.emulatorConfiguration.emulatorType, platformData.emulatorConfiguration.core, platformData.id, Number(gameId), platformData.favouriteRomId, platformData.favouriteRomIsMediagroup, platformData.favouriteRomName); platformItem.addEventListener('click', () => { window.location.href = launchLink; @@ -450,7 +450,7 @@ function LoadGamePlatforms() { platformItem.setAttribute('isLastUsed', true); platformItem.classList.add('platform_item_green'); - let launchLink = BuildLaunchLink(platformData.emulatorConfiguration.emulatorType, platformData.emulatorConfiguration.core, platformData.id, Number(gameId), platformData.lastPlayedRomId, platformData.lastPlayedRomIsMediagroup, platformData.lastPlayedRomName); + let launchLink = await BuildLaunchLink(platformData.emulatorConfiguration.emulatorType, platformData.emulatorConfiguration.core, platformData.id, Number(gameId), platformData.lastPlayedRomId, platformData.lastPlayedRomIsMediagroup, platformData.lastPlayedRomName); platformItem.addEventListener('click', () => { window.location.href = launchLink; diff --git a/gaseous-server/wwwroot/scripts/main.js b/gaseous-server/wwwroot/scripts/main.js index 378bc04..4c06b92 100644 --- a/gaseous-server/wwwroot/scripts/main.js +++ b/gaseous-server/wwwroot/scripts/main.js @@ -699,25 +699,108 @@ class BackgroundImageRotator { } } -function BuildLaunchLink(engine, core, platformId, gameId, romId, isMediaGroup, filename) { +async function BuildLaunchLink(engine, core, platformId, gameId, romId, isMediaGroup, filename) { let launchLink = '/index.html?page=emulator&engine=&core=&platformid=&gameid=&romid=&mediagroup=&rompath='; - // http://localhost:5198/index.html?page=emulator&engine=EmulatorJS&core=amiga&platformid=16&gameid=5519&romid=19&mediagroup=1&rompath=%2Fapi%2Fv1.1%2FGames%2F5519%2Fromgroup%2F19%2FCannon%20Fodder.zip + let isValid = true; - // http://localhost:5198/index.html?page=emulator&engine=EmulatorJS&core=amiga&platformid=16&gameid=5519&romid=102&mediagroup=0&rompath=%2Fapi%2Fv1.1%2FGames%2F5519%2Froms%2F102%2FCannon%20Fodder%20(1993)(Virgin)(Disk%201%20of%203)%5Bcr%20CSL%5D.adf + console.log('Validating launch link: ' + engine + ' ' + core + ' ' + platformId + ' ' + gameId + ' ' + romId + ' ' + isMediaGroup + ' ' + filename); - launchLink = launchLink.replace('', engine); - launchLink = launchLink.replace('', core); - launchLink = launchLink.replace('', platformId); - launchLink = launchLink.replace('', gameId); - launchLink = launchLink.replace('', romId); - if (isMediaGroup == true) { - launchLink = launchLink.replace('', 1); - launchLink = launchLink.replace('', '/api/v1.1/Games/' + encodeURI(gameId) + '/romgroup/' + encodeURI(romId) + '/' + encodeURI(filename) + '.zip'); - } else { - launchLink = launchLink.replace('', 0); - launchLink = launchLink.replace('', '/api/v1.1/Games/' + encodeURI(gameId) + '/roms/' + encodeURI(romId) + '/' + encodeURI(filename)); + let returnLink = '/index.html'; + + // check if engine is valid + let validEngines = ['EmulatorJS']; + if (!validEngines.includes(engine)) { + isValid = false; + console.log('Engine is invalid!'); } - return launchLink; + // fetch valid cores from json file /emulators/EmulatorJS/data/cores.json + let validCores = []; + await fetch('/emulators/EmulatorJS/data/cores/cores.json', { + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }) + .then(response => response.json()) + .then(data => { + validCores = data; + + for (let i = 0; i < validCores.length; i++) { + if (validCores[i].name == core) { + isValid = true; + break; + } else { + isValid = false; + } + } + if (isValid == false) { + console.log('Core is invalid!'); + } + + // check if platformId is an int64 + if (!Number(platformId)) { + isValid = false; + console.log('PlatformId is invalid!'); + } + + // check if gameId is a an int64 + if (!Number(gameId)) { + isValid = false; + console.log('GameId is invalid!'); + } + + // check if romId is a an int64 + if (!Number(romId)) { + isValid = false; + console.log('RomId is invalid!'); + } + + // check if isMediaGroup is a boolean in a number format + if (typeof (isMediaGroup) == 'boolean' && (Number(isMediaGroup) == 0 || Number(isMediaGroup) == 1)) { + isValid = false; + console.log('IsMediaGroup is invalid!'); + } + + // check if filename is a string + if (typeof (filename) != 'string') { + isValid = false; + console.log('Filename is invalid!'); + } + + if (isValid == false) { + console.log('Link is invalid!'); + returnLink = '/index.html'; + return; + } + + // generate the launch link + launchLink = launchLink.replace('', engine); + launchLink = launchLink.replace('', core); + launchLink = launchLink.replace('', platformId); + launchLink = launchLink.replace('', gameId); + launchLink = launchLink.replace('', romId); + if (isMediaGroup == true) { + launchLink = launchLink.replace('', 1); + launchLink = launchLink.replace('', '/api/v1.1/Games/' + encodeURI(gameId) + '/romgroup/' + encodeURI(romId) + '/' + encodeURI(filename) + '.zip'); + } else { + launchLink = launchLink.replace('', 0); + launchLink = launchLink.replace('', '/api/v1.1/Games/' + encodeURI(gameId) + '/roms/' + encodeURI(romId) + '/' + encodeURI(filename)); + } + + console.log('Validated link: ' + launchLink); + + returnLink = launchLink; + + return; + }) + .catch(error => { + console.error('Error:', error); + isValid = false; + console.log('Link is invalid!'); + returnLink = '/index.html'; + }); + + return returnLink; } \ No newline at end of file diff --git a/gaseous-server/wwwroot/scripts/modals.js b/gaseous-server/wwwroot/scripts/modals.js index 8471c57..93c209e 100644 --- a/gaseous-server/wwwroot/scripts/modals.js +++ b/gaseous-server/wwwroot/scripts/modals.js @@ -503,20 +503,20 @@ class EmulatorStateManager { let stateControlsLaunch = document.createElement('span'); stateControlsLaunch.id = 'stateControlsLaunch_' + result[i].id; stateControlsLaunch.className = 'romstart'; - let emulatorTarget;// = '/index.html?page=emulator&engine=@engine&core=@core&platformid=@platformid&gameid=@gameid&romid=@romid&mediagroup=@mediagroup&rompath=@rompath&stateid=' + result[i].id; + let emulatorTarget; let mediagroupint = 0; if (thisObject.IsMediaGroup == true) { mediagroupint = 1; } switch (getQueryString('page', 'string')) { case 'emulator': - emulatorTarget = BuildLaunchLink(getQueryString('engine', 'string'), getQueryString('core', 'string'), getQueryString('platformid', 'string'), getQueryString('gameid', 'string'), getQueryString('romid', 'string'), mediagroupint, thisObject.rompath, result[i].id) + '&stateid=' + result[i].id; + emulatorTarget = await BuildLaunchLink(getQueryString('engine', 'string'), getQueryString('core', 'string'), getQueryString('platformid', 'string'), getQueryString('gameid', 'string'), getQueryString('romid', 'string'), mediagroupint, thisObject.rompath, result[i].id) + '&stateid=' + result[i].id; stateControlsLaunch.addEventListener('click', () => { window.location.replace(emulatorTarget); }); break; case 'game': - emulatorTarget = BuildLaunchLink(thisObject.engine, thisObject.core, thisObject.platformid, thisObject.gameid, thisObject.RomId, mediagroupint, thisObject.rompath, result[i].id) + '&stateid=' + result[i].id; + emulatorTarget = await BuildLaunchLink(thisObject.engine, thisObject.core, thisObject.platformid, thisObject.gameid, thisObject.RomId, mediagroupint, thisObject.rompath, result[i].id) + '&stateid=' + result[i].id; stateControlsLaunch.addEventListener('click', () => { window.location.href = emulatorTarget; }); diff --git a/gaseous-server/wwwroot/scripts/uploadrom.js b/gaseous-server/wwwroot/scripts/uploadrom.js index 6bc718b..d0da708 100644 --- a/gaseous-server/wwwroot/scripts/uploadrom.js +++ b/gaseous-server/wwwroot/scripts/uploadrom.js @@ -197,12 +197,12 @@ class UploadItem { // file name label this.filenameLabel = document.createElement('div'); this.filenameLabel.classList.add('uploadItem-Label'); - this.filenameLabel.innerHTML = this.Filename; + this.filenameLabel.textContent = this.Filename; // status label this.statusLabel = document.createElement('div'); this.statusLabel.classList.add('uploadItem-Status'); - this.statusLabel.innerHTML = UploadItem.StatusValues[this.Status]; + this.statusLabel.textContent = UploadItem.StatusValues[this.Status]; // game name label this.gameNameLabel = document.createElement('div');