From f342ccff4a9ca763b5ba8ea122a6b33511534d11 Mon Sep 17 00:00:00 2001 From: NIANIANKNIA Date: Wed, 19 Jul 2023 22:40:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96NIAHttpBOT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 48 ++++--------------- NIAHttpBOT/src/NIAHttpBOT.cpp | 41 ++++------------ .../NIA_V4.0_BP/scripts/API/scoreboard.js | 0 .../NIA_V4.0_BP/scripts/config.js | 8 ++-- .../NIA_V4.0_BP/scripts/customFunction.js | 18 +------ .../NIA_V4.0_BP/scripts/main.js | 24 ---------- .../NIA_V4.0_BP/scripts/market.js | 4 ++ 7 files changed, 29 insertions(+), 114 deletions(-) delete mode 100644 development_behavior_packs/NIA_V4.0_BP/scripts/API/scoreboard.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 7069d3a..fcde991 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,53 +5,25 @@ **版本说明:本次script-api出现部分变动,与老版本不相兼容,请及时更新本版本!** -## 适配 - -BDS && Minecraft BedRock-1.20.10.02 - -Liteloader 2.14.1 - ## 新增 -1.全新的NIAHttpBOT!基于c++编写,相比旧方案内存占用更小,性能更好!(特别感谢[**@jiansyuan**](https://github.com/jiansyuan)在编写中给予的帮助!) +1.NIAHttpBOT新增部分API(具体使用方法请前往**NIA服务器官方文档站**查看) -2.玩家交易市场部分功能(制作中,预计将在v1.4.0发布正式版) +- `/CheckFile` +- `/RunCmd` +- `/WriteLineToFile` +- `/OverwriteFile` +- `/CheckDir` -已完成模块: +2.NIAHttpBOT新增配置文件 -- 玩家上线市场逻辑(服务器本地) -- 玩家上线物品依赖服务器存储数据 -- 玩家可以初步查看市场商品 +3.行为包现在可以自动检查是否为最新版本了 ## 优化 -1.由于qq机器人暂时不稳定,在找到稳定的解决方案前暂时停止qq机器人的使用 - -2.自本版本之后,**停止对NIA-Server-BOT的更新与维护**,转而使用全新的**NIAHttpBOT**实现对原有功能的替代。 - -3.飞行系统授权码算法优化 [**@jiansyuan**](https://github.com/jiansyuan) - -4.优化商城id生成逻辑 - -## 修复 - -1.商店系统&&回收系统无法正常购买&&回收的bug - -2.传送系统无法正常同意的bug - -3.转账系统无法正常使用的bug - -4.飞行系统无法正常验证的bug - -5.玩家上架物品时不填写详细项目仍可以正常上架的bug - -6.玩家上架物品不为物品最大数量时显示仍为最大数量的bug - -7.在部分情况下无法正常上架商品的bug - -8.每晚12点更新时传送指令的错误 +1.NIAHttpBOT部分情况下报错信息更加详细 -9.(llse)扫地机插件无法正常恢复被扫物品的bug +2.正式移除`NIA-Server-BOT`项目及其所有文件 **配置说明:您可以前往[NIA服务器官方文档站](https://docs.mcnia.top/zh-CN/deploy.html)查看具体部署过程!** diff --git a/NIAHttpBOT/src/NIAHttpBOT.cpp b/NIAHttpBOT/src/NIAHttpBOT.cpp index 2c5f957..4811396 100644 --- a/NIAHttpBOT/src/NIAHttpBOT.cpp +++ b/NIAHttpBOT/src/NIAHttpBOT.cpp @@ -78,7 +78,7 @@ int main() { UseCmd = par.getBool("UseCmd"); INFO("已成功读取配置文件!"); } - + INFO("NIAHttpBOT 已在 " + IPAddress + ":" + std::to_string(PORT) + " 上成功启动!"); INFO("项目地址:https://github.com/NIANIANKNIA/NIASERVER-V4/tree/main/NIAHttpBOT"); INFO("项目作者:@NIANIANKNIA @jiansyuan"); @@ -134,22 +134,20 @@ int main() { //创建新的文件 svr.Post("/CreateNewFile", [](const httplib::Request& req, httplib::Response& res) { INFO("接收到创建文件的请求! "); + res.status = 200; //解析字符串并创建一个json对象 rapidjson::Document NewFileData; NewFileData.Parse(req.body.c_str()); //判断是否解析成功 if (NewFileData.HasParseError()) { - res.status = 200; res.set_content("Data parsing failed", "text/plain"); return ; } if(!NewFileData.HasMember("fileName")){ - res.status = 200; res.set_content("The fileName key for the json object was not found! Please recheck and send again.", "text/plain"); return ; } if(!NewFileData.HasMember("fileContent")){ - res.status = 200; res.set_content("The fileContent key for the json object was not found! Please recheck and send again.", "text/plain"); return ; } @@ -163,7 +161,6 @@ int main() { // 检测${fileName}文件是否存在,如果不存在,就创建一个新的文件,并写入内容 std::ifstream file(fileName); if(file){ - res.status = 200; res.set_content("The target file already exists and cannot be regenerated.", "text/plain"); return ; } @@ -171,7 +168,6 @@ int main() { std::ofstream outFile(fileName); outFile << fileContent; outFile.close(); - res.status = 200; res.set_content("success", "text/plain"); file.close(); }); @@ -180,22 +176,20 @@ int main() { //创建新的json文件 svr.Post("/CreateNewJsonFile", [](const httplib::Request& req, httplib::Response& res) { INFO("接收到创建json文件的请求! "); + res.status = 200; //解析字符串并创建一个json对象 rapidjson::Document NewFileData; NewFileData.Parse(req.body.c_str()); //判断是否解析成功 if (NewFileData.HasParseError()) { - res.status = 200; res.set_content("Data parsing failed", "text/plain"); return ; } if(!NewFileData.HasMember("fileName")){ - res.status = 200; res.set_content("The fileName key for the json object was not found! Please recheck and send again.", "text/plain"); return ; } if(!NewFileData.HasMember("fileContent")){ - res.status = 200; res.set_content("The fileContent key for the json object was not found! Please recheck and send again.", "text/plain"); return ; } @@ -214,7 +208,6 @@ int main() { // 检测${fileName}文件是否存在,如果不存在,就创建一个新的文件,并写入内容 std::ifstream file(fileName); if(file){ - res.status = 200; res.set_content("The target file already exists and cannot be regenerated.", "text/plain"); return ; } @@ -222,7 +215,6 @@ int main() { std::ofstream out(fileName); out << buffer.GetString(); out.close(); - res.status = 200; res.set_content("success", "text/plain"); file.close(); }); @@ -230,13 +222,13 @@ int main() { //获取json文件数据 svr.Post("/GetJsonFileData", [](const httplib::Request& req, httplib::Response& res) { INFO("接收到获取文件数据的请求,请求获取的文件名称为: " << req.body); + res.status = 200; //初始化文件名称 std::string fileName = req.body; //判断文件存不存在 std::ifstream file(fileName); if(!file) { //文件打开失败 - res.status = 200; res.set_content("The target file does not exist", "text/plain"); return ; } @@ -251,7 +243,6 @@ int main() { rapidjson::Writer writer(buffer); doc.Accept(writer); std::string jsonStr = buffer.GetString(); - res.status = 200; res.set_content(jsonStr, "text/plain"); file.close(); }); @@ -259,22 +250,20 @@ int main() { //覆盖json文件内容 svr.Post("/OverwriteJsonFile", [](const httplib::Request& req, httplib::Response& res) { INFO("接收到覆写json文件的请求!"); + res.status = 200; //解析字符串并创建一个json对象 rapidjson::Document overWriteFileData; overWriteFileData.Parse(req.body.c_str()); //判断是否解析成功 if (overWriteFileData.HasParseError()) { - res.status = 200; res.set_content("Data parsing failed", "text/plain"); return ; } if(!overWriteFileData.HasMember("fileName")){ - res.status = 200; res.set_content("The fileName key for the json object was not found! Please recheck and send again.", "text/plain"); return ; } if(!overWriteFileData.HasMember("fileData")){ - res.status = 200; res.set_content("The fileData key for the json object was not found! Please recheck and send again.", "text/plain"); return ; } @@ -293,14 +282,12 @@ int main() { // 检测${fileName}文件是否存在,如果不存在,就创建一个新的文件,并写入内容 std::ifstream file(fileName); if(!file) { - res.status = 200; res.set_content("The target file does not exist.", "text/plain"); return ; } std::ofstream out(fileName); out << buffer.GetString(); out.close(); - res.status = 200; res.set_content("success", "text/plain"); file.close(); @@ -308,39 +295,36 @@ int main() { //执行cmd命令 svr.Post("/RunCmd", [](const httplib::Request& req, httplib::Response& res) { + res.status = 200; //首先判断配置文件是否启用 if (!UseCmd) { WARN("执行DOS命令的功能暂未启用!请在启用后使用!"); - res.status = 200; res.set_content("feature not enabled!", "text/plain"); return ; } std::string cmd = req.body; WARN("收到一条执行DOS命令的请求:" + cmd); system(cmd.c_str()); - res.status = 200; res.set_content("success", "text/plain"); }); //向目标文件写入一行内容 svr.Post("/WriteLineToFile", [](const httplib::Request& req, httplib::Response& res) { INFO("接收到向目标文件写入一行内容的请求!"); + res.status = 200; //解析字符串并创建一个json对象 rapidjson::Document WriteLineData; WriteLineData.Parse(req.body.c_str()); //判断是否解析成功 if (WriteLineData.HasParseError()) { - res.status = 200; res.set_content("Data parsing failed", "text/plain"); return ; } if(!WriteLineData.HasMember("fileName")){ - res.status = 200; res.set_content("The fileName key for the json object was not found! Please recheck and send again.", "text/plain"); return ; } if(!WriteLineData.HasMember("content")){ - res.status = 200; res.set_content("The content key for the json object was not found! Please recheck and send again.", "text/plain"); return ; } @@ -353,7 +337,6 @@ int main() { // 检测${fileName}文件是否存在,如果不存在,就创建一个新的文件,并写入内容 std::ifstream file(fileName); if(!file) { - res.status = 200; res.set_content("The target file does not exist.", "text/plain"); return ; } @@ -361,7 +344,6 @@ int main() { std::ofstream outFile(fileName, std::ios_base::app); outFile << fileContent; outFile.close(); - res.status = 200; res.set_content("success", "text/plain"); file.close(); }); @@ -369,22 +351,20 @@ int main() { //向目标文件覆盖内容 svr.Post("/OverwriteFile", [](const httplib::Request& req, httplib::Response& res) { INFO("接收到覆写文件的请求!"); + res.status = 200; //解析字符串并创建一个json对象 rapidjson::Document OverwriteFileData; OverwriteFileData.Parse(req.body.c_str()); //判断是否解析成功 if (OverwriteFileData.HasParseError()) { - res.status = 200; res.set_content("Data parsing failed", "text/plain"); return ; } if(!OverwriteFileData.HasMember("fileName")){ - res.status = 200; res.set_content("The fileName key for the json object was not found! Please recheck and send again.", "text/plain"); return ; } if(!OverwriteFileData.HasMember("content")){ - res.status = 200; res.set_content("The content key for the json object was not found! Please recheck and send again.", "text/plain"); return ; } @@ -397,7 +377,6 @@ int main() { // 检测${fileName}文件是否存在 std::ifstream file(fileName); if(!file) { - res.status = 200; res.set_content("The target file does not exist.", "text/plain"); return ; } @@ -405,19 +384,17 @@ int main() { std::ofstream outFile(fileName); outFile << fileContent; outFile.close(); - res.status = 200; res.set_content("success", "text/plain"); file.close(); }); //检测指定文件夹是否存在 svr.Post("/CheckDir", [](const httplib::Request& req, httplib::Response& res) { + res.status = 200; std::filesystem::path p{req.body}; if (std::filesystem::exists(p)) { - res.status = 200; res.set_content("true", "text/plain"); } else { - res.status = 200; res.set_content("false", "text/plain"); } }); diff --git a/development_behavior_packs/NIA_V4.0_BP/scripts/API/scoreboard.js b/development_behavior_packs/NIA_V4.0_BP/scripts/API/scoreboard.js deleted file mode 100644 index e69de29..0000000 diff --git a/development_behavior_packs/NIA_V4.0_BP/scripts/config.js b/development_behavior_packs/NIA_V4.0_BP/scripts/config.js index eaa8f05..0963441 100644 --- a/development_behavior_packs/NIA_V4.0_BP/scripts/config.js +++ b/development_behavior_packs/NIA_V4.0_BP/scripts/config.js @@ -1,6 +1,3 @@ -//这里是配置文件,你可以根据自己的需求更改相应的配置项目 -//配置文件每一项的详细作用前往 https://docs.mcnia.top/zh-CN/deploy.html 查看 -//当前配置文件版本号;v1.0.0 const config = { "ServerMode": "Island", @@ -16,7 +13,12 @@ const config = { "CX": 402, "CY": 100, "CZ": 547 + }, + "HttpCfg": { + "IPAddress": "http://127.0.0.1", + "Port": 10086 } } + export const cfg = config \ No newline at end of file diff --git a/development_behavior_packs/NIA_V4.0_BP/scripts/customFunction.js b/development_behavior_packs/NIA_V4.0_BP/scripts/customFunction.js index 619224c..4d9ec37 100644 --- a/development_behavior_packs/NIA_V4.0_BP/scripts/customFunction.js +++ b/development_behavior_packs/NIA_V4.0_BP/scripts/customFunction.js @@ -51,6 +51,7 @@ export function AddScoreboard(scoreboardName,showName) { export function GetTime() { //创建一个Date对象 let nowTime = new Date() + //这里是或得北京时间 let addedTime = new Date(nowTime.getTime() + 28800000); //获取年份 let year = addedTime.getFullYear (); @@ -99,31 +100,14 @@ export function GetScore(scoreboardName,targets) { } -// function getNumberInNormalDistribution(mean,std_dev){ -// return mean+(uniform2NormalDistribution()*std_dev); -// } - -// function uniform2NormalDistribution(){ -// var sum=0.0; -// for(var i=0; i<12; i++){ -// sum=sum+Math.random(); -// } -// return sum-6.0; -// } - function randomNormalDistribution(){ var u=0.0, v=0.0, w=0.0, c=0.0; do{ - //获得两个(-1,1)的独立随机变量 u=Math.random()*2-1.0; v=Math.random()*2-1.0; w=u*u+v*v; }while(w==0.0||w>=1.0) - //这里就是 Box-Muller转换 c=Math.sqrt((-2*Math.log(w))/w); - //返回2个标准正态分布的随机数,封装进一个数组返回 - //当然,因为这个函数运行较快,也可以扔掉一个 - //return [u*c,v*c]; return u*c; } diff --git a/development_behavior_packs/NIA_V4.0_BP/scripts/main.js b/development_behavior_packs/NIA_V4.0_BP/scripts/main.js index 0de5ca2..062cb02 100644 --- a/development_behavior_packs/NIA_V4.0_BP/scripts/main.js +++ b/development_behavior_packs/NIA_V4.0_BP/scripts/main.js @@ -268,30 +268,6 @@ system.runInterval(() => { // RunCmd(`tag ${playerList[i].nameTag} remove GetIsland`) // } - // Broadcast(`§c[NKillHacker]§r\nspeed:${((Math.pow(playerList[i].velocity.x,2) + Math.pow(playerList[i].velocity.y,2) + Math.pow(playerList[i].velocity.z,2))).toFixed(5)} \npos:${playerList[i].location.x.toFixed(4)} ${playerList[i].location.y.toFixed(4)} ${playerList[i].location.z.toFixed(4)}`) - // let pos = {} - // if (posData[playerList[i].nameTag]) { - // //Broadcast((Math.pow(playerList[i].location.x.toFixed(4) - posData[playerList[i].nameTag].x,2) + Math.pow(playerList[i].location.y.toFixed(4) - posData[playerList[i].nameTag].y,2) + Math.pow(playerList[i].location.z.toFixed(4) - posData[playerList[i].nameTag].z,2)).toString()) - // if (((Math.pow(playerList[i].velocity.x,2) + Math.pow(playerList[i].velocity.y,2) + Math.pow(playerList[i].velocity.z,2))) >= 0.045 && (Math.pow(playerList[i].location.x.toFixed(4) - posData[playerList[i].nameTag].x,2) + Math.pow(playerList[i].location.y.toFixed(4) - posData[playerList[i].nameTag].y,2) + Math.pow(playerList[i].location.z.toFixed(4) - posData[playerList[i].nameTag].z,2)) <= 0.5) { - // world.getDimension("overworld").runCommandAsync(`tellraw @a[tag=op] {\"rawtext\":[{\"text\":\"§c>> 疑似 §e${playerList[i].nameTag} §c正在使用自由视角,如果本消息短期多次出现建议前往查看!注意:本消息可能是个误判!以下为该玩家的异常数据§r\nspeed:${((Math.pow(playerList[i].velocity.x,2) + Math.pow(playerList[i].velocity.y,2) + Math.pow(playerList[i].velocity.z,2))).toFixed(3)} \npos:${playerList[i].location.x.toFixed(3)} ${playerList[i].location.y.toFixed(3)} ${playerList[i].location.z.toFixed(3)}\ndistance:${(Math.pow(playerList[i].location.x.toFixed(4) - posData[playerList[i].nameTag].x,2) + Math.pow(playerList[i].location.y.toFixed(4) - posData[playerList[i].nameTag].y,2) + Math.pow(playerList[i].location.z.toFixed(4) - posData[playerList[i].nameTag].z,2)).toFixed(3).toString()}\"}]}`); - // posData[playerList[i].nameTag].num++ - // if (posData[playerList[i].nameTag].num >= 8) { - // posData[playerList[i].nameTag].num = 0 - // RunCmd(`ban ${playerList[i].nameTag} 1 违规使用自由视角(灵魂出窍)`) - // } - // //RunCmd(`ban ${playerList[i].nameTag} 1 违规使用自由视角(灵魂出窍)`) - // } - // posData[playerList[i].nameTag].x = playerList[i].location.x.toFixed(4) - // posData[playerList[i].nameTag].y = playerList[i].location.y.toFixed(4) - // posData[playerList[i].nameTag].z = playerList[i].location.z.toFixed(4) - // } else { - // //Broadcast("1") - // pos.num = 0 - // pos.x = playerList[i].location.x.toFixed(4) - // pos.y = playerList[i].location.y.toFixed(4) - // pos.z = playerList[i].location.z.toFixed(4) - // posData[playerList[i].nameTag] = pos - // } if ((Math.pow(playerList[i].getVelocity().x,2) + Math.pow(playerList[i].getVelocity().y,2) + Math.pow(playerList[i].getVelocity().z,2)) > 0.07 && GetScore("equLevel",playerList[i].nameTag) <= 10) { RunCmd(`scoreboard players add @e[name="${playerList[i].nameTag}",type=player] oxygen -1`); } diff --git a/development_behavior_packs/NIA_V4.0_BP/scripts/market.js b/development_behavior_packs/NIA_V4.0_BP/scripts/market.js index ecc56c6..9d5c507 100644 --- a/development_behavior_packs/NIA_V4.0_BP/scripts/market.js +++ b/development_behavior_packs/NIA_V4.0_BP/scripts/market.js @@ -134,6 +134,10 @@ const MarketGUI = { }) }, + Preview(player) { + + }, + //上架商品菜单 Shelf(player) { let InventoryData = ["-无-"]