Added GetLevelInfo for the GalaxyServer

This commit is contained in:
2023-11-22 17:18:28 -06:00
parent cf0d6c66d8
commit 68bac1455e
2 changed files with 33 additions and 1 deletions

View File

@@ -470,7 +470,10 @@ public class UserPlugin {
if (buddy != null) {
switch (plugin) {
case "5":
case "1": // Ace - Operation Flight Plan | Mulch - <GAME NAME>
break;
case "5": // Lucky - Rainbow Shootout
// Create new entry for the invitee
RainbowShootout newRS = RainbowShootout.builder()
.username(buddy.getUsername())

View File

@@ -235,6 +235,9 @@ public class GalaxyServer {
case "search":
response = search((Element)nodes.item(0));
break;
case "get_level_info":
response = getLevelInfo((Element)nodes.item(0));
break;
default:
System.out.println("[Galaxy][POST][ERROR] Unhandled type of request for: " + command);
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
@@ -672,4 +675,30 @@ public class GalaxyServer {
return new ResponseEntity<>(response.toString(), HttpStatus.OK);
}
/**
* Get the level info for a level by ID
* NOTES:
* - This method is only used when challenging a friend
* - The level should always exist from here as it must've been shared to challenge a friend
* @param element the request element extracted from the XML
* @return level info for the requested level
*/
private ResponseEntity<String> getLevelInfo(Element element) {
Integer levelId = Integer.valueOf(element.getAttribute("id"));
Level level = levelService.findLevelById(levelId).orElse(null);
String levelData = "";
try {
User creator = userService.findByUUID(level.getUserId()).orElse(null);
String creatorName = creator != null ? creator.getUsername() : "UNKNOWN";
levelData += "<level id=\"" + level.getId() + "\" sh=\"1\" ver=\"1\" n=\"" + level.getLevelName()
+ "\" v=\"" + level.getPlayCount() + "\" un=\"" + creatorName + "\" r=\"" + level.getRating()
+ "\" tnurl=\"" + level.getImagePath() + "\" pos=\"" + level.getPos() + "\"/>";
}
catch (NullPointerException e) {
return new ResponseEntity<>("<get_level_info r=\"0\" id=\"" + levelId + "\"><level tnurl=\"\" /></get_level_info>", HttpStatus.OK);
}
return new ResponseEntity<>("<get_level_info r=\"0\" id=\"" + levelId + "\">" + levelData + "</get_level_info>", HttpStatus.OK);
}
}