parent
fc9d9590d3
commit
73289de3aa
@ -1,2 +1,2 @@ |
||||
save0 = 641.829219, 1, 2, Ranger, Sig |
||||
save0 = 657.967859, 1, 2, Ranger, Sig |
||||
save1 = 107.824620, 1, 1, Wizard, WIZ |
||||
|
@ -0,0 +1,53 @@ |
||||
app.post("/AiL",function (req, res) { |
||||
var username=decodeURI(req.body.username) |
||||
var operation=decodeURI(req.body.operation) |
||||
var checksum=decodeURI(req.body.checksum) |
||||
var data=decodeURI(req.body.data) |
||||
const saveDir="files/AiLsaves/"; |
||||
if(username&&operation&&checksum&&data){ |
||||
if(username.length<=24&& |
||||
(operation==="GET_LOAD_FILES"||operation==="GET_FILE"||operation==="SAVE_FILE"||operation==="SAVE_METADATA_FILE")&& |
||||
data.length<=1000000&& |
||||
Number(checksum)===username.length*8+data.length*2+operation.length){ |
||||
//Checksum: Length of username*8+Length of data*2+Length of operation
|
||||
if(!fs.existsSync(`${saveDir+username}`)){ |
||||
fs.mkdirSync(`${saveDir+username}`); |
||||
} |
||||
switch(operation){ |
||||
case "GET_LOAD_FILES":{ |
||||
if(fs.existsSync(`${saveDir+username}/metadata.dat`)){ |
||||
res.status(200).send(fs.readFileSync(`${saveDir+username}/metadata.dat`)); |
||||
}else{ |
||||
res.status(404).send("Not Found!"); |
||||
} |
||||
}break; |
||||
case "GET_FILE":{ |
||||
if(fs.existsSync(`${saveDir+username}/save.${data.padStart(4,'0')}`)){ |
||||
res.status(200).send(fs.readFileSync(`${saveDir+username}/save.${data.padStart(4,'0')}`)); |
||||
}else{ |
||||
res.status(404).send("Not Found!"); |
||||
} |
||||
}break; |
||||
case "SAVE_FILE":{ |
||||
var fileData=data.split("|"); |
||||
var fileNumb=fileData[0]; |
||||
var saveFileData=fileData[1]; |
||||
|
||||
fs.writeFileSync(`${saveDir+username}/save.${fileNumb.padStart(4,'0')}`,saveFileData); |
||||
res.status(200).send("Saved!"); |
||||
}break; |
||||
case "SAVE_METADATA_FILE":{ |
||||
fs.writeFileSync(`${saveDir+username}/metadata.dat`,data); |
||||
res.status(200).send("Saved!"); |
||||
}break; |
||||
default:{ |
||||
res.status(418).send('I\'m definitely a teapot.'); |
||||
} |
||||
} |
||||
}else{ |
||||
res.status(418).send('I\'m definitely a teapot.'); |
||||
} |
||||
}else{ |
||||
res.status(400).send('Invalid input!'); |
||||
} |
||||
}); |
Loading…
Reference in new issue