From b975165f1877f5785a94d4365b2a81e15100aa44 Mon Sep 17 00:00:00 2001 From: Stev_Wang <304865932@qq.com> Date: Thu, 25 Dec 2025 18:20:37 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E4=BB=93=E5=BA=93=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + account/get_account.js | 39 +++++++++++++++++ account/get_account_list.js | 57 +++++++++++++++++++++++++ activity/activity_list.js | 62 +++++++++++++++++++++++++++ auth/login.js | 36 ++++++++++++++++ auth/out_login.js | 9 ++++ characters/get_characters.js | 82 ++++++++++++++++++++++++++++++++++++ debug.js | 5 +++ doc.js | 14 ++++++ get_current_user.js | 10 +++++ gitee_web_hook.js | 16 +++++++ item/item_list.js | 74 ++++++++++++++++++++++++++++++++ 12 files changed, 405 insertions(+) create mode 100644 README.md create mode 100644 account/get_account.js create mode 100644 account/get_account_list.js create mode 100644 activity/activity_list.js create mode 100644 auth/login.js create mode 100644 auth/out_login.js create mode 100644 characters/get_characters.js create mode 100644 debug.js create mode 100644 doc.js create mode 100644 get_current_user.js create mode 100644 gitee_web_hook.js create mode 100644 item/item_list.js diff --git a/README.md b/README.md new file mode 100644 index 0000000..3452572 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +所有http请求处理 \ No newline at end of file diff --git a/account/get_account.js b/account/get_account.js new file mode 100644 index 0000000..6afc8cc --- /dev/null +++ b/account/get_account.js @@ -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); +} \ No newline at end of file diff --git a/account/get_account_list.js b/account/get_account_list.js new file mode 100644 index 0000000..025fe25 --- /dev/null +++ b/account/get_account_list.js @@ -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 }; + } +} diff --git a/activity/activity_list.js b/activity/activity_list.js new file mode 100644 index 0000000..3c6728a --- /dev/null +++ b/activity/activity_list.js @@ -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 }; + } +} \ No newline at end of file diff --git a/auth/login.js b/auth/login.js new file mode 100644 index 0000000..fc989b6 --- /dev/null +++ b/auth/login.js @@ -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("账号不存在"); + } +} \ No newline at end of file diff --git a/auth/out_login.js b/auth/out_login.js new file mode 100644 index 0000000..38ad0f4 --- /dev/null +++ b/auth/out_login.js @@ -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); +} \ No newline at end of file diff --git a/characters/get_characters.js b/characters/get_characters.js new file mode 100644 index 0000000..ec6387a --- /dev/null +++ b/characters/get_characters.js @@ -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 }; + } +} \ No newline at end of file diff --git a/debug.js b/debug.js new file mode 100644 index 0000000..96f651b --- /dev/null +++ b/debug.js @@ -0,0 +1,5 @@ +// @ts-ignore http调试消息处理 +export async function execute(http_message) { + console.log(`收到调试信息`) + return HttpResUtils.ok("收到调试信息"); +} \ No newline at end of file diff --git a/doc.js b/doc.js new file mode 100644 index 0000000..7787477 --- /dev/null +++ b/doc.js @@ -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); +} \ No newline at end of file diff --git a/get_current_user.js b/get_current_user.js new file mode 100644 index 0000000..1524f5c --- /dev/null +++ b/get_current_user.js @@ -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); +} \ No newline at end of file diff --git a/gitee_web_hook.js b/gitee_web_hook.js new file mode 100644 index 0000000..ae270f0 --- /dev/null +++ b/gitee_web_hook.js @@ -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); + } + } +} \ No newline at end of file diff --git a/item/item_list.js b/item/item_list.js new file mode 100644 index 0000000..7fa2e06 --- /dev/null +++ b/item/item_list.js @@ -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 || "未知错误")); + } +} \ No newline at end of file