From a975b355b28e5ef081a5c2dcdbdb298ae58c17e4 Mon Sep 17 00:00:00 2001 From: Francois G Date: Tue, 11 Apr 2023 18:29:27 +0200 Subject: [PATCH] Make puzzle response accept no fileName and sourceCode --- .../peeratcode/routes/PuzzleResponse.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/be/jeffcheasey88/peeratcode/routes/PuzzleResponse.java b/src/be/jeffcheasey88/peeratcode/routes/PuzzleResponse.java index 90b2656..489c8eb 100644 --- a/src/be/jeffcheasey88/peeratcode/routes/PuzzleResponse.java +++ b/src/be/jeffcheasey88/peeratcode/routes/PuzzleResponse.java @@ -38,7 +38,11 @@ public class PuzzleResponse implements Response { @Route(path = "^\\/puzzleResponse\\/([0-9]+)$", type = POST, needLogin = true) public void exec(Matcher matcher, User user, HttpReader reader, HttpWriter writer) throws Exception{ ReceivedResponse received = new ReceivedResponse(matcher, reader); - saveSourceCode(received, databaseRepo.getPlayer(user.getId())); + if (received.getResponse() == null) { + HttpUtil.responseHeaders(writer, 400, "Access-Control-Allow-Origin: *"); + return; + } + //saveSourceCode(received, databaseRepo.getPlayer(user.getId())); JSONObject responseJSON = new JSONObject(); Puzzle currentPuzzle = databaseRepo.getPuzzle(received.getPuzzleId()); @@ -87,9 +91,13 @@ class ReceivedResponse { puzzleId = Integer.parseInt(matcher.group(1)); List multiPartData = HttpUtil.readMultiPartData(reader); - this.response = multiPartData.get(0).getBytes(); - this.fileName = multiPartData.get(1); - this.sourceCode = multiPartData.get(2).getBytes(); + if (multiPartData != null && multiPartData.size() > 0) { + this.response = multiPartData.get(0).getBytes(); + if (multiPartData.size() == 3) { + this.fileName = multiPartData.get(1); + this.sourceCode = multiPartData.get(2).getBytes(); + } + } } public int getPuzzleId() {