项目仓库初始化
This commit is contained in:
39
account/get_account.js
Normal file
39
account/get_account.js
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
// @ts-ignore 获取账号信息
|
||||||
|
export async function execute(http_message) {
|
||||||
|
let username = HttpReQUtils.check_auth(http_message);
|
||||||
|
if (username && username.length > 0) {
|
||||||
|
try {
|
||||||
|
// 从数据库查询完整的账号信息
|
||||||
|
// @ts-ignore
|
||||||
|
let accounts = await _database_.execute_sql_by_name("accounts",`
|
||||||
|
SELECT * FROM accounts WHERE username = '${username}'
|
||||||
|
`);
|
||||||
|
|
||||||
|
// 检查查询结果
|
||||||
|
if (!accounts || accounts === "[]") {
|
||||||
|
return HttpResUtils.err_code(404, "账号不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解析查询结果
|
||||||
|
let accountData = JSON.parse(accounts)[0];
|
||||||
|
|
||||||
|
// 返回完整的账号信息
|
||||||
|
return HttpResUtils.ok({
|
||||||
|
id: accountData.id,
|
||||||
|
username: accountData.username,
|
||||||
|
invite_code: accountData.invite_code || "",
|
||||||
|
reg_time: accountData.reg_time || "",
|
||||||
|
login_time: accountData.login_time || "",
|
||||||
|
out_time: accountData.out_time || "",
|
||||||
|
last_login_time: accountData.last_login_time || "",
|
||||||
|
status: accountData.status ? 1 : 0, // 1为启用,0为禁用
|
||||||
|
is_online: accountData.is_online ? 1 : 0, // 1为在线,0为离线
|
||||||
|
json_data: accountData.json_data || {}
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("获取账号信息失败:", error);
|
||||||
|
return HttpResUtils.err_code(500, "获取账号信息失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return HttpResUtils.err_code(402);
|
||||||
|
}
|
||||||
57
account/get_account_list.js
Normal file
57
account/get_account_list.js
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
// @ts-ignore 获取用户列表接口
|
||||||
|
export async function execute(http_message) {
|
||||||
|
// 验证请求头中的PSK
|
||||||
|
let psk_valid = HttpReQUtils.check_psk(http_message);
|
||||||
|
|
||||||
|
if (!psk_valid) {
|
||||||
|
// 直接返回错误响应
|
||||||
|
return { code: 401, success: false, message: "未授权", data: null };
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 获取所有用户数据
|
||||||
|
// @ts-ignore
|
||||||
|
let accounts = await _database_.execute_sql_by_name("accounts", 'select * from accounts');
|
||||||
|
|
||||||
|
// 格式化用户列表数据
|
||||||
|
let userList = [];
|
||||||
|
if (accounts && accounts !== "[]") {
|
||||||
|
try {
|
||||||
|
// 解析查询结果JSON数组
|
||||||
|
let accountsList = JSON.parse(accounts);
|
||||||
|
|
||||||
|
for (let account of accountsList) {
|
||||||
|
// 解析账户数据
|
||||||
|
let accountData = account;
|
||||||
|
|
||||||
|
// 添加到用户列表,返回必要的信息
|
||||||
|
userList.push({
|
||||||
|
id: accountData.id,
|
||||||
|
username: accountData.username,
|
||||||
|
invite_code: accountData.invite_code || "无",
|
||||||
|
reg_time: accountData.reg_time || "无",
|
||||||
|
login_time: accountData.login_time || "无",
|
||||||
|
out_time: accountData.out_time || "无",
|
||||||
|
last_login_time: accountData.last_login_time || "无",
|
||||||
|
status: accountData.status ? 1 : 0, // 1为正常,0为禁用
|
||||||
|
is_online: accountData.is_online ? 1 : 0 // 1为在线,0为离线
|
||||||
|
// json_data 字段暂时不返回,如需返回可在此处添加
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("解析账户列表失败:", e);
|
||||||
|
return { code: 500, success: false, message: "解析账户数据失败", data: null };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回成功响应
|
||||||
|
return { code: 200, success: true, message: "ok", data: {
|
||||||
|
user_list: userList,
|
||||||
|
total: userList.length
|
||||||
|
} };
|
||||||
|
} catch (error) {
|
||||||
|
console.error("获取用户列表失败:", error);
|
||||||
|
// 返回错误响应
|
||||||
|
return { code: 500, success: false, message: "获取用户列表失败: " + (error.message || "未知错误"), data: null };
|
||||||
|
}
|
||||||
|
}
|
||||||
62
activity/activity_list.js
Normal file
62
activity/activity_list.js
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
// @ts-ignore 获取活动列表接口
|
||||||
|
/**
|
||||||
|
* 获取活动列表接口
|
||||||
|
* 通过PSK验证后,读取activity_data.js文件中的活动数据
|
||||||
|
* 返回所有活动的详细信息
|
||||||
|
*/
|
||||||
|
export async function execute(http_message) {
|
||||||
|
// 验证请求头中的PSK
|
||||||
|
let psk_valid = HttpReQUtils.check_psk(http_message);
|
||||||
|
|
||||||
|
if (!psk_valid) {
|
||||||
|
// 直接返回错误响应
|
||||||
|
return { code: 401, success: false, message: "未授权", data: null };
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 获取已导入的活动数据
|
||||||
|
// @ts-ignore
|
||||||
|
let activityData = G.ActivityData.default;
|
||||||
|
|
||||||
|
if (!activityData) {
|
||||||
|
console.error("活动数据未加载");
|
||||||
|
return { code: 404, success: false, message: "活动数据未加载", data: null };
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式化活动数据为列表
|
||||||
|
let activityList = [];
|
||||||
|
for (let activityId in activityData) {
|
||||||
|
if (activityData.hasOwnProperty(activityId)) {
|
||||||
|
let activity = activityData[activityId];
|
||||||
|
activityList.push({
|
||||||
|
id: activityId,
|
||||||
|
名称: activity.名称 || "",
|
||||||
|
类型: activity.类型 || "",
|
||||||
|
最高等级: activity.最高等级 || 0,
|
||||||
|
最低等级: activity.最低等级 || 0,
|
||||||
|
防修: activity.防修 || 0,
|
||||||
|
攻修: activity.攻修 || 0,
|
||||||
|
系数: activity.系数 || 1,
|
||||||
|
主怪: activity.主怪 || [],
|
||||||
|
数量平衡: activity.数量平衡 || false,
|
||||||
|
最大数量: activity.最大数量 || 1,
|
||||||
|
最小数量: activity.最小数量 || 1,
|
||||||
|
小怪: activity.小怪 || [],
|
||||||
|
小怪规则: activity.小怪规则 || "随机",
|
||||||
|
喽啰编号2: activity.喽啰编号2 || 0,
|
||||||
|
几率: activity.几率 || 100
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回成功响应
|
||||||
|
return { code: 200, success: true, message: "ok", data: {
|
||||||
|
activity_list: activityList,
|
||||||
|
total: activityList.length
|
||||||
|
} };
|
||||||
|
} catch (error) {
|
||||||
|
console.error("获取活动列表失败:", error);
|
||||||
|
// 返回错误响应
|
||||||
|
return { code: 500, success: false, message: "获取活动列表失败: " + (error.message || "未知错误"), data: null };
|
||||||
|
}
|
||||||
|
}
|
||||||
36
auth/login.js
Normal file
36
auth/login.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
// @ts-ignore 运营后台登录
|
||||||
|
export async function execute(http_message) {
|
||||||
|
// {"username":"123123","password":"123123","autoLogin":true,"code":"login","type":"account"}
|
||||||
|
let body = http_message["body"];
|
||||||
|
if (body["username"] === undefined) {
|
||||||
|
return HttpResUtils.err_msg("账号不能为空");
|
||||||
|
}
|
||||||
|
if (body["password"] === undefined) {
|
||||||
|
return HttpResUtils.err_msg("密码不能为空");
|
||||||
|
}
|
||||||
|
// 查询游戏账号
|
||||||
|
let accounts = await G.Accounts.query_accounts_db(body["username"]);
|
||||||
|
if (accounts.length > 0) {
|
||||||
|
let accounts_json = JSON.parse(accounts);
|
||||||
|
// 确保accounts_json是数组且有数据
|
||||||
|
if (Array.isArray(accounts_json) && accounts_json.length > 0) {
|
||||||
|
let account = accounts_json[0];
|
||||||
|
if (body["password"] !== account["password"]) {
|
||||||
|
return HttpResUtils.err_msg("密码错误")
|
||||||
|
}
|
||||||
|
// 删除之前缓存的token
|
||||||
|
if(_AdminUserTokenCache.has(account["username"])){
|
||||||
|
_AdminTokenUserCache.delete(_AdminUserTokenCache.get(account["username"]));
|
||||||
|
}
|
||||||
|
// 缓存新的token
|
||||||
|
let token = _jwt_.gen(account["username"], `${account["id"]}`);
|
||||||
|
_AdminTokenUserCache.set(token, account["username"]);
|
||||||
|
_AdminUserTokenCache.set(account["username"], token);
|
||||||
|
return HttpResUtils.ok(token);
|
||||||
|
} else {
|
||||||
|
return HttpResUtils.err_msg("账号不存在");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return HttpResUtils.err_msg("账号不存在");
|
||||||
|
}
|
||||||
|
}
|
||||||
9
auth/out_login.js
Normal file
9
auth/out_login.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
// @ts-ignore 退出登录
|
||||||
|
export async function execute(http_message) {
|
||||||
|
let username = HttpReQUtils.check_auth(http_message);
|
||||||
|
if (username.length > 0) {
|
||||||
|
_AdminUserTokenCache.delete(HttpReQUtils.get_token(http_message));
|
||||||
|
_AdminTokenUserCache.delete(username);
|
||||||
|
}
|
||||||
|
return HttpResUtils.all(null,402,null,true);
|
||||||
|
}
|
||||||
82
characters/get_characters.js
Normal file
82
characters/get_characters.js
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
// @ts-ignore 获取角色列表接口
|
||||||
|
/**
|
||||||
|
* 获取角色列表接口
|
||||||
|
* 通过PSK验证后,从数据库characters表获取角色数据
|
||||||
|
* 支持通过uid参数过滤特定账号的角色数据
|
||||||
|
*/
|
||||||
|
export async function execute(http_message) {
|
||||||
|
// 验证请求头中的PSK
|
||||||
|
let psk_valid = HttpReQUtils.check_psk(http_message);
|
||||||
|
|
||||||
|
if (!psk_valid) {
|
||||||
|
// 直接返回错误响应
|
||||||
|
return { code: 401, success: false, message: "未授权", data: null };
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 获取请求参数(支持从根对象或body字段获取uid参数)
|
||||||
|
let uid = http_message["uid"] || (http_message["body"] ? http_message["body"]["uid"] : null);
|
||||||
|
|
||||||
|
// 构建SQL查询语句
|
||||||
|
let sql = "SELECT * FROM characters";
|
||||||
|
|
||||||
|
if (uid) {
|
||||||
|
sql += ` WHERE uid = ${uid}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取角色数据
|
||||||
|
// @ts-ignore
|
||||||
|
let characters = await _database_.execute_sql_by_name("accounts", sql);
|
||||||
|
|
||||||
|
// 格式化数据
|
||||||
|
let charactersList = [];
|
||||||
|
if (characters && characters !== "[]") {
|
||||||
|
try {
|
||||||
|
// 解析查询结果JSON数组
|
||||||
|
let charsList = JSON.parse(characters);
|
||||||
|
|
||||||
|
for (let char of charsList) {
|
||||||
|
// 解析角色数据
|
||||||
|
let charData = char;
|
||||||
|
|
||||||
|
// 解析json_data字段(如果有)
|
||||||
|
let extraData = {};
|
||||||
|
if (charData.json_data && charData.json_data !== "") {
|
||||||
|
try {
|
||||||
|
extraData = JSON.parse(charData.json_data);
|
||||||
|
} catch (e) {
|
||||||
|
console.error("解析角色json_data失败:", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加到角色列表
|
||||||
|
charactersList.push({
|
||||||
|
id: charData.id,
|
||||||
|
uid: charData.uid,
|
||||||
|
name: charData.name,
|
||||||
|
level: charData.level,
|
||||||
|
job: charData.job,
|
||||||
|
sex: charData.sex,
|
||||||
|
created_at: extraData.created_at || "未知",
|
||||||
|
last_login: extraData.last_login || "未知",
|
||||||
|
status: extraData.status !== undefined ? (extraData.status ? 1 : 0) : 1, // 1为正常,0为禁用
|
||||||
|
extra_data: extraData
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("解析角色列表失败:", e);
|
||||||
|
return { code: 500, success: false, message: "解析角色数据失败", data: null };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回成功响应
|
||||||
|
return { code: 200, success: true, message: "ok", data: {
|
||||||
|
characters_list: charactersList,
|
||||||
|
total: charactersList.length
|
||||||
|
} };
|
||||||
|
} catch (error) {
|
||||||
|
console.error("获取角色列表失败:", error);
|
||||||
|
// 返回错误响应
|
||||||
|
return { code: 500, success: false, message: "获取角色列表失败: " + (error.message || "未知错误"), data: null };
|
||||||
|
}
|
||||||
|
}
|
||||||
5
debug.js
Normal file
5
debug.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
// @ts-ignore http调试消息处理
|
||||||
|
export async function execute(http_message) {
|
||||||
|
console.log(`收到调试信息`)
|
||||||
|
return HttpResUtils.ok("收到调试信息");
|
||||||
|
}
|
||||||
14
doc.js
Normal file
14
doc.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// @ts-ignore 获取游戏事件说明文档
|
||||||
|
export async function execute(http_message) {
|
||||||
|
let result = [];
|
||||||
|
for (let [key, value] of _MessageHandlerData) {
|
||||||
|
if (value.desc) {
|
||||||
|
result.push({
|
||||||
|
"key": key,
|
||||||
|
...value.desc,
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return HttpResUtils.ok(result);
|
||||||
|
}
|
||||||
10
get_current_user.js
Normal file
10
get_current_user.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
// @ts-ignore 获取账号信息
|
||||||
|
export async function execute(http_message) {
|
||||||
|
let username = HttpReQUtils.check_auth(http_message);
|
||||||
|
if (username && username.length > 0) {
|
||||||
|
return HttpResUtils.ok({
|
||||||
|
username: username,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return HttpResUtils.err_code(402);
|
||||||
|
}
|
||||||
16
gitee_web_hook.js
Normal file
16
gitee_web_hook.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
// gitee webhook 处理
|
||||||
|
export async function execute(http_message) {
|
||||||
|
if(http_message["headers"] && http_message["headers"]["x-gitee-token"] === "123123"){
|
||||||
|
let body = JSON.parse(http_message["body"]);
|
||||||
|
if(body["hook_name"] === "push_hooks"){
|
||||||
|
let git_http_url = body["repository"]["git_http_url"];
|
||||||
|
let repository_name = body["repository"]["name"];
|
||||||
|
let message = body["head_commit"]["message"];
|
||||||
|
console.log(message)
|
||||||
|
let send_message = `仓库[${repository_name}]收到新的提交, ${message} . 仓库地址: ${git_http_url}`;
|
||||||
|
console.log(send_message)
|
||||||
|
G.OneBotUtils.send_ws_group_text_message(1037049599, send_message);
|
||||||
|
G.OneBotUtils.send_ws_group_text_message(154213998, send_message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
74
item/item_list.js
Normal file
74
item/item_list.js
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
// @ts-ignore 获取物品列表接口
|
||||||
|
/**
|
||||||
|
* 获取物品列表接口
|
||||||
|
* 通过PSK验证后,读取all_item_data.js文件中的物品数据
|
||||||
|
* 返回所有物品的详细信息
|
||||||
|
*/
|
||||||
|
export async function execute(http_message) {
|
||||||
|
// 验证请求头中的PSK
|
||||||
|
let psk_valid = HttpReQUtils.check_psk(http_message);
|
||||||
|
|
||||||
|
if (!psk_valid) {
|
||||||
|
// 直接返回错误响应
|
||||||
|
return HttpResUtils.err_code(401, "未授权");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 获取已导入的物品数据
|
||||||
|
// @ts-ignore
|
||||||
|
let itemData = G.AllItemData.default;
|
||||||
|
|
||||||
|
if (!itemData) {
|
||||||
|
console.error("物品数据未加载");
|
||||||
|
return HttpResUtils.err_code(404, "物品数据未加载");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式化物品数据为列表
|
||||||
|
let itemList = [];
|
||||||
|
for (let itemName in itemData) {
|
||||||
|
if (itemData.hasOwnProperty(itemName)) {
|
||||||
|
let item = itemData[itemName];
|
||||||
|
// 确保wp_7是数组类型
|
||||||
|
let wp7Value = item.wp_7;
|
||||||
|
if (wp7Value === undefined || wp7Value === null) {
|
||||||
|
wp7Value = [];
|
||||||
|
} else if (!Array.isArray(wp7Value)) {
|
||||||
|
// 如果不是数组,转换为数组
|
||||||
|
wp7Value = [wp7Value];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确保数组中的所有元素都是字符串类型
|
||||||
|
wp7Value = wp7Value.map(element => {
|
||||||
|
if (element === null || element === undefined) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return String(element);
|
||||||
|
});
|
||||||
|
|
||||||
|
itemList.push({
|
||||||
|
name: itemName,
|
||||||
|
wp_1: item.wp_1 || "",
|
||||||
|
wp_2: item.wp_2 || 0,
|
||||||
|
wp_3: item.wp_3 || 0,
|
||||||
|
wp_4: item.wp_4 || 0,
|
||||||
|
wp_5: item.wp_5 || 0,
|
||||||
|
wp_7: wp7Value,
|
||||||
|
wp_8: item.wp_8 || "",
|
||||||
|
wp_11: item.wp_11 || "",
|
||||||
|
wp_12: item.wp_12 || "",
|
||||||
|
wp_13: item.wp_13 || ""
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回成功响应
|
||||||
|
return HttpResUtils.ok({
|
||||||
|
item_list: itemList,
|
||||||
|
total: itemList.length
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("获取物品列表失败:", error);
|
||||||
|
// 返回错误响应
|
||||||
|
return HttpResUtils.err_data_msg(null, "获取物品列表失败: " + (error.message || "未知错误"));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user