Skip to content

Commit

Permalink
首次增加log系统框架
Browse files Browse the repository at this point in the history
  • Loading branch information
NIANIANKNIA committed Jul 24, 2024
1 parent c7a8616 commit 3f65aab
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 23 deletions.
22 changes: 13 additions & 9 deletions CHANGELOG-PRE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# v1.5.0-pre-3 更新日志

[![BDS VERSION](https://img.shields.io/badge/BDS-1.20.61.01-green?style=for-the-badge&logo=appveyor)](https://www.minecraft.net/en-us/download/server/bedrock)
[![BDS VERSION](https://img.shields.io/badge/BDS-1.21.3.01-green?style=for-the-badge&logo=appveyor)](https://www.minecraft.net/en-us/download/server/bedrock)


> **预发布版本提醒**:这是一个**预览版本**,可能存在一些bug,仅供测试,请勿在正式生产环境使用本版本!
Expand All @@ -9,23 +9,27 @@
## 优化


优化NIAHttpBOT的QQ机器人的指令解析逻辑

## 新增

1.基于[LLoneBOT](https://github.com/LLOneBot/LLOneBot)使用[onebot-11](https://github.com/botuniverse/onebot-11/)为NIAHttpBOT&&Nia-Server-Core新增部分QQ机器人功能

2.NIAHttpBOT增加QQ机器人相关配置文件
1.NIAHttpBOT增加聊天违禁词检测

3.NIAHttpBOT增加主人QQ相关功能
2.NIAHttpBOT增加自动检查更新功能

4.NIAHttpBOT增加QQ权限检测
3.NIAHttpBOT增加https支持

## 修复

1.NIAHttpBOT收到私聊消息时崩溃
1.NIAHttpBOT输入reload指令后不能正确重载

2.NIAHttpBOT启动log ip信息显示错误

3.NIAHttpBOT违禁词检查错误撤回图片等其他非消息内容

4.NIAHttpBOT部分API有返回值,调用函数时确没有返回值

2.在QQ客户端没有开启的情况下,开始NiaHttp-BOT导致的报错
5.NIAHttpBOT的qq功能无法正常显示@人



Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
一个基于BDS的基岩版服务器,这里开源了由服务器开发团队制作的addons(包括基于script-api的脚本)

**以下插件由于部分原因不再进更新维护:**

运行于LiteLoader的插件(部分LiteLoader插件源码可以点击前往 [NIAServerPlugin@jiansyuan](https://github.com/jiansyuan/NIAServerPlugin) 查看)
**以下插件由于部分原因不再进更新维护:** 运行于LiteLoader的插件(部分LiteLoader插件源码可以点击前往 [NIAServerPlugin@jiansyuan](https://github.com/jiansyuan/NIAServerPlugin) 查看)

我们并不是专业的开发人员,所以难免会出现部分bug、代码不规范、逻辑混乱等错误,也欢迎各位大佬pr,我们也一定会仔细查看、学习、回复每一条pr

Expand Down Expand Up @@ -60,7 +58,6 @@
- [x] 兑换码系统
- [x] 回收系统
- [x] 传送系统
- [x] 氧气值玩法
- [x] 支持修改配置文件
- [x] 玩家交易市场
- [x] 圈地系统
Expand All @@ -69,6 +66,9 @@

## 关于NIAHttpBOT

> [!IMPORTANT]
> 自v1.6.0版本开始,NIAHttpBOT将作为[子项目](https://github.com/Nia-Server/NIAHttpBOT)分离主项目进行更新,主项目将不再包含NIAHttpBOT的相关源码
新版机器人基于c++制作(特别感谢[**@jiansyuan**](https://github.com/jiansyuan)),使用HTTP实现对文件的一系列操作,并基于[LLoneBOT](https://github.com/LLOneBot/LLOneBot)为NIAHttpBOT新增部分QQ机器人功能,具体使用示例,请前往[NIA服务器文档站](https://docs.mcnia.com/dev/Http-Bot.html)查看使用说明!

**NIAHttpBOT**可以在windows/Linux环境下运行,windows环境下请下载**NIAHttpBOT.exe**,双击**NIAHttpBOT.exe**即可运行;Linux环境下请下载**NIAHttpBOT**然后使用`./NIAHttpBOT`命令运行即可!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export function log(info) {
console.log("\x1b[33m[\x1b[36mNiaServer-Core\x1b[33m] " + info + "\x1b[0m")
}

export function warn(info) {
console.warn("\x1b[33m[\x1b[36mNiaServer-Core\x1b[33m] " + info + "\x1b[0m")
}

/**
* 将Msg消息广播至整个游戏
Expand Down Expand Up @@ -51,7 +54,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 ();
Expand Down
80 changes: 79 additions & 1 deletion development_behavior_packs/NIA_V4.0_BP/scripts/log.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,86 @@
import { system, world } from "@minecraft/server";
import { ExternalFS } from "./API/filesystem";
import { log,GetTime, Broadcast } from "./customFunction";
import { log, GetTime, Broadcast, warn } from "./customFunction";

const fs = new ExternalFS();

//定义文件名称
var log_file_name = `2024-07-24.csv`;

//定义日志文件存放文件夹
const log_folder = "./log/";

//配置文件

const config = {
"chat_send": true,
}

var log_file = log_folder + log_file_name;

//创建日志文件夹
fs.RunCmd(`mkdir "${log_folder}"`)

//检查日志文件是否存在,如果不存在则创建
fs.CheckFile(`${log_file}`).then((result) => {
if (result === "true") {
log(`[log] The log file ${log_file} already exists!`);
} else if (result === "false") {
fs.CreateNewFile(log_file,"时间,维度,主体,X,Y,Z,事件,目标,x,y,z,附加信息\n").then((result) => {
log("ssss" + result)
if (result === "success") {
log(`[log] The log file ${log_file} has been successfully created!`);
} else {
warn("Failed to create log file!");
}
})
} else if (result === -1) {
warn("Failed to connect to the server!");
}
})

//判断时间日期是否切换
// system.runInterval(() => {
// if (log_file_name !== `log_${GetTime()}.csv`) {
// log_file_name = `log_${GetTime()}.csv`;
// log_file = log_folder + log_file_name;
// log(`[log] The log file has been successfully switched to ${log_file}!`);
// //创建新的日志文件
// fs.CreateNewFile(log_file).then((result) => {
// if (result === "success") {
// log(`[log] The log file ${log_file} has been successfully created!`);
// } else {
// warn("Failed to create new log file!");
// }
// })
// }
// },100)

//启动检测特定文件是否存在
const log_API = {
WriteToLog(dimension,subject,x0,y0,z0,event,target,x1,y1,z1,extra) {
fs.WriteLineToFile(log_file,`${GetTime()},${dimension},${subject},${x0},${y0},${z0},${event},${target},${x1},${y1},${z1},${extra}\n`).then((result) => {
if (result === "success") {
log(`[log][${dimension}] ${subject}${GetTime()} 发生了 ${event} 事件,目标为 ${target},附加信息为 ${extra}`);
} else {
warn("Failed to write to log file!");
}
})
}
}

//监听玩家聊天事件
world.beforeEvents.chatSend.subscribe((event) => {
if (config.chat_send) {
system.run(() => {
log_API.WriteToLog(event.sender.dimension.id,event.sender.nameTag,event.sender.location.x,event.sender.location.y,event.sender.location.z,"玩家聊天事件","","","","",event.message);
})
}
})

//
world.afterEvents.explosion.subscribe((event) => {
log(event.source.location.x)
log_API.WriteToLog(event.dimension.id,event.source.typeId,event.source.location.x,event.source.location.y,event.source.location.z,"实体爆炸事件","","","","","");
})

6 changes: 3 additions & 3 deletions development_behavior_packs/NIA_V4.0_BP/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ import './market.js'
import './land.js'
import './basic.js'
import './newFunction.js'
import './log.js'
//import './log.js'
import './qqBot.js'
//import './AntiCheats.js'

export const VERSION = "v1.5.0-pre-3";
export const BDS_VERSION = "1.21.1.03";
export const LAST_UPGRATE = "2024/07/09";
export const BDS_VERSION = "1.21.3.01";
export const LAST_UPGRATE = "2024/07/24";
export const CODE_BRANCH = "dev";


Expand Down
10 changes: 5 additions & 5 deletions development_behavior_packs/NIA_V4.0_BP/scripts/qqBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ const fs = new ExternalFS();

console.log(`\x1b[33m[\x1b[36mNiaServer-Core\x1b[33m] QQBot has been successfully started on this server!\x1b[0m\n`);

world.afterEvents.worldInitialize.subscribe((event) => {
bot.send_group_msg(`服务器已与机器人成功连接!\nBDS当前版本:${BDS_VERSION}\nCore版本:${VERSION}\n上次更新时间:${LAST_UPGRATE}`,"724360499").then((result) => {
console.log(result);
})
})
// world.afterEvents.worldInitialize.subscribe((event) => {
// bot.send_group_msg(`服务器已与机器人成功连接!\nBDS当前版本:${BDS_VERSION}\nCore版本:${VERSION}\n上次更新时间:${LAST_UPGRATE}`,"724360499").then((result) => {
// console.log(result);
// })
// })



Expand Down

0 comments on commit 3f65aab

Please sign in to comment.