The open source repository for the action RPG game in development by Sig Productions titled 'Adventures in Lestoria'!
https://forums.lestoria.net
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.8 KiB
53 lines
1.8 KiB
11 months ago
|
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!');
|
||
|
}
|
||
|
});
|