This commit is contained in:
Michael Green
2024-10-21 14:32:13 +11:00
parent 53c79287a9
commit b3ca94b217
6 changed files with 190 additions and 59 deletions

View File

@@ -477,6 +477,11 @@ namespace gaseous_server.Classes.Metadata
private static async Task<Game[]> _SearchForGameRemote(string SearchString, long PlatformId, SearchType searchType) private static async Task<Game[]> _SearchForGameRemote(string SearchString, long PlatformId, SearchType searchType)
{ {
switch (Communications.MetadataSource)
{
case HasheousClient.Models.MetadataModel.MetadataSources.None:
return new Game[0];
case HasheousClient.Models.MetadataModel.MetadataSources.IGDB:
string searchBody = ""; string searchBody = "";
string searchFields = "fields id,name,slug,platforms,summary; "; string searchFields = "fields id,name,slug,platforms,summary; ";
bool allowSearch = true; bool allowSearch = true;
@@ -520,6 +525,13 @@ namespace gaseous_server.Classes.Metadata
{ {
return games.ToArray(); return games.ToArray();
} }
case HasheousClient.Models.MetadataModel.MetadataSources.Hasheous:
return new Game[0];
default:
return new Game[0];
}
} }
public static List<AvailablePlatformItem> GetAvailablePlatforms(string UserId, long GameId) public static List<AvailablePlatformItem> GetAvailablePlatforms(string UserId, long GameId)

View File

@@ -704,6 +704,42 @@ namespace gaseous_server.Controllers
} }
} }
[MapToApiVersion("1.0")]
[MapToApiVersion("1.1")]
[HttpGet]
[Route("{GameId}/gamemode")]
[ProducesResponseType(typeof(List<GameMode>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "7Days")]
public async Task<ActionResult> GameMode(long GameId)
{
try
{
IGDB.Models.Game gameObject = Classes.Metadata.Games.GetGame(GameId, false, false, false);
if (gameObject != null)
{
List<IGDB.Models.GameMode> gameModeObjects = new List<GameMode>();
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.0")]
[MapToApiVersion("1.1")] [MapToApiVersion("1.1")]
[HttpGet] [HttpGet]

View File

@@ -406,7 +406,7 @@ function SetupPage() {
function LoadGamePlatforms() { function LoadGamePlatforms() {
// get platforms // 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'); let platformContainer = document.getElementById('gamesummaryplatformscontent');
platformContainer.innerHTML = ''; platformContainer.innerHTML = '';
for (let i = 0; i < result.length; i++) { for (let i = 0; i < result.length; i++) {
@@ -437,7 +437,7 @@ function LoadGamePlatforms() {
platformItem.setAttribute('isFavourite', true); platformItem.setAttribute('isFavourite', true);
platformItem.classList.add('platform_item_green'); 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', () => { platformItem.addEventListener('click', () => {
window.location.href = launchLink; window.location.href = launchLink;
@@ -450,7 +450,7 @@ function LoadGamePlatforms() {
platformItem.setAttribute('isLastUsed', true); platformItem.setAttribute('isLastUsed', true);
platformItem.classList.add('platform_item_green'); 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', () => { platformItem.addEventListener('click', () => {
window.location.href = launchLink; window.location.href = launchLink;

View File

@@ -699,13 +699,83 @@ 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=<ENGINE>&core=<CORE>&platformid=<PLATFORMID>&gameid=<GAMEID>&romid=<ROMID>&mediagroup=<ISMEDIAGROUP>&rompath=<FILENAME>'; let launchLink = '/index.html?page=emulator&engine=<ENGINE>&core=<CORE>&platformid=<PLATFORMID>&gameid=<GAMEID>&romid=<ROMID>&mediagroup=<ISMEDIAGROUP>&rompath=<FILENAME>';
// 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);
let returnLink = '/index.html';
// check if engine is valid
let validEngines = ['EmulatorJS'];
if (!validEngines.includes(engine)) {
isValid = false;
console.log('Engine is invalid!');
}
// 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>', engine); launchLink = launchLink.replace('<ENGINE>', engine);
launchLink = launchLink.replace('<CORE>', core); launchLink = launchLink.replace('<CORE>', core);
launchLink = launchLink.replace('<PLATFORMID>', platformId); launchLink = launchLink.replace('<PLATFORMID>', platformId);
@@ -719,5 +789,18 @@ function BuildLaunchLink(engine, core, platformId, gameId, romId, isMediaGroup,
launchLink = launchLink.replace('<FILENAME>', '/api/v1.1/Games/' + encodeURI(gameId) + '/roms/' + encodeURI(romId) + '/' + encodeURI(filename)); launchLink = launchLink.replace('<FILENAME>', '/api/v1.1/Games/' + encodeURI(gameId) + '/roms/' + encodeURI(romId) + '/' + encodeURI(filename));
} }
return launchLink; 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;
} }

View File

@@ -503,20 +503,20 @@ class EmulatorStateManager {
let stateControlsLaunch = document.createElement('span'); let stateControlsLaunch = document.createElement('span');
stateControlsLaunch.id = 'stateControlsLaunch_' + result[i].id; stateControlsLaunch.id = 'stateControlsLaunch_' + result[i].id;
stateControlsLaunch.className = 'romstart'; 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; let mediagroupint = 0;
if (thisObject.IsMediaGroup == true) { if (thisObject.IsMediaGroup == true) {
mediagroupint = 1; mediagroupint = 1;
} }
switch (getQueryString('page', 'string')) { switch (getQueryString('page', 'string')) {
case 'emulator': 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', () => { stateControlsLaunch.addEventListener('click', () => {
window.location.replace(emulatorTarget); window.location.replace(emulatorTarget);
}); });
break; break;
case 'game': 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', () => { stateControlsLaunch.addEventListener('click', () => {
window.location.href = emulatorTarget; window.location.href = emulatorTarget;
}); });

View File

@@ -197,12 +197,12 @@ class UploadItem {
// file name label // file name label
this.filenameLabel = document.createElement('div'); this.filenameLabel = document.createElement('div');
this.filenameLabel.classList.add('uploadItem-Label'); this.filenameLabel.classList.add('uploadItem-Label');
this.filenameLabel.innerHTML = this.Filename; this.filenameLabel.textContent = this.Filename;
// status label // status label
this.statusLabel = document.createElement('div'); this.statusLabel = document.createElement('div');
this.statusLabel.classList.add('uploadItem-Status'); this.statusLabel.classList.add('uploadItem-Status');
this.statusLabel.innerHTML = UploadItem.StatusValues[this.Status]; this.statusLabel.textContent = UploadItem.StatusValues[this.Status];
// game name label // game name label
this.gameNameLabel = document.createElement('div'); this.gameNameLabel = document.createElement('div');