ソースを参照

feat:抖音添加桌面功能

pigflower 3 ヶ月 前
コミット
e187a54476

+ 32 - 0
script/common/CommonDB.lua

@@ -42,6 +42,7 @@ KEY_COMMERCEACT_INFO = "commerceActInfo"				-- 跨服活动信息
 KEY_JJCLADDER_INFO = "jjcNewladderInfo"					-- 天梯赛信息
 KEY_COMMERCEACT_MIDDLE_INFO = "commerceMiddleActInfo"	-- 中心服跨服商业活动信息
 KEY_BAN_DATA = "banData"								-- 封禁数据
+KEY_DESKTOP_DATA = "desktopData"					-- 桌面添加数据(账号级)
 KEY_REBATE_DATA = "rebateData"							-- 渠道返利数据
 KEY_ANOTHERWORLDBATTLE_START_TI = "anotherWorldBattleStart" -- 最近一轮异界之战开启时间
 
@@ -567,4 +568,35 @@ function SetCommerceMiddleAct_ByKey(nKey, tData)
 	db.commerceMiddleActInfo[nKey] = tData
 
 	updateValue(KEY_COMMERCEACT_MIDDLE_INFO, db.commerceMiddleActInfo)
+end
+
+-- 桌面添加数据(账号级,多区服共享)
+-- 结构:{ [newUniqueTag] = { ["channelId_platform"] = true, ... }, ... }
+
+local function makeDesktopAccountKey(channelId, serverId, account)
+	return tostring(channelId) .. "|" .. tostring(serverId) .. "|" .. tostring(account)
+end
+
+function GetDesktopData(channelId, serverId, account)
+	local data = db[KEY_DESKTOP_DATA]
+	if not data then return nil end
+	local accountKey = makeDesktopAccountKey(channelId, serverId, account)
+	return data[accountKey]
+end
+
+function SetDesktopData(channelId, serverId, account, platform)
+	local accountKey = makeDesktopAccountKey(channelId, serverId, account)
+	local platformKey = tostring(channelId) .. "_" .. tostring(platform)
+	local data = db[KEY_DESKTOP_DATA] or {}
+	data[accountKey] = data[accountKey] or {}
+	data[accountKey][platformKey] = true
+	db[KEY_DESKTOP_DATA] = data
+	updateValue(KEY_DESKTOP_DATA, data)
+end
+
+function IsDesktopAdded(channelId, serverId, account, platform)
+	local accountData = GetDesktopData(channelId, serverId, account)
+	if not accountData then return false end
+	local platformKey = tostring(channelId) .. "_" .. tostring(platform)
+	return accountData[platformKey] == true
 end

+ 24 - 1
script/common/InnerHandler.lua

@@ -23,6 +23,7 @@ local MiddleCommonLogic = require("middle.MiddleCommonLogic")
 local CommerceMiddle = require("serverCommerce.ServerCommerceMiddle")
 local MiddleCommonRank = require("middle.MiddleCommonRank")
 local BanLogic = require("scene.BanLogic")
+local ZhuanpanLogic = require("zhuanpan.ZhuanpanLogic")
 local JjcNewLadderMidder = require("jjcnewladder.jjcNewLadderMiddle")
 local RebateLogic = require("platform.RebateLogic")
 local ServerCommerceActPeakBettleMiddle = require("serverCommerce.ServerCommerceActPeakBettleMiddle")
@@ -1032,4 +1033,26 @@ function LW_ANOTHERWORLDBATTLE_UIONMORALE_DO(fd, msg)
 end
 function WL_ANOTHERWORLDBATTLE_UIONMORALE_DO(fd, msg)
     AnotherWorldBattleNS.C2N_MyUnionMoraleInfo_Response(msg)
-end
+end
+
+
+----------------------- 桌面添加开始 ---------------------------
+
+-- 普通服→中心服:上报添加桌面,中心服写入并返回最新状态
+function LW_DESKTOP_SET(fd, msg)
+    if _G.is_middle ~= true then return end
+    ZhuanpanLogic.CS_DesktopSet(msg)
+end
+
+-- 普通服→中心服:查询桌面状态
+function LW_DESKTOP_QUERY(fd, msg)
+    if _G.is_middle ~= true then return end
+    ZhuanpanLogic.CS_DesktopQuery(msg)
+end
+
+-- 中心服→普通服:查询结果回包,普通服转发给客户端
+function WL_DESKTOP_QUERY(fd, msg)
+    ZhuanpanLogic.NS_DesktopQueryResult(msg)
+end
+
+----------------------- 桌面添加结束 ---------------------------

+ 31 - 0
script/common/InnerProto.lua

@@ -750,6 +750,37 @@ WL_REBATE_OK = {
 }
 -------------------- 返利结束 -----------------------------------
 
+-------------------- 桌面添加开始 -----------------------------------
+
+-- 普通服→中心服:上报添加桌面(仅写入,无需回包)
+LW_DESKTOP_SET = {
+  {"nSrcServerID",  "int"},     -- 来源区服ID
+  {"channelId",     "int"},     -- 渠道ID
+  {"serverId",      "int"},     -- 区服ID
+  {"account",       "string"},  -- 账号
+  {"platform",      "string"},  -- 平台标识
+}
+
+-- 普通服→中心服:查询桌面状态
+LW_DESKTOP_QUERY = {
+  {"nSrcServerID",  "int"},     -- 来源区服ID(用于路由回包)
+  {"channelId",     "int"},     -- 渠道ID
+  {"serverId",      "int"},     -- 区服ID
+  {"account",       "string"},  -- 账号
+  {"platform",      "string"},  -- 平台标识
+}
+
+-- 中心服→普通服:查询结果回包
+WL_DESKTOP_QUERY = {
+  {"channelId",       "int"},     -- 渠道ID
+  {"serverId",        "int"},     -- 区服ID
+  {"account",         "string"},  -- 账号
+  {"platform",        "string"},  -- 平台标识
+  {"isDesktopAdded",  "int"},     -- 是否已添加 0否 1是
+}
+
+-------------------- 桌面添加结束 -----------------------------------
+
 
 --------------------------诸神圣域------------------------------------
 -- 普通服向跨服请求排行榜数据

+ 4 - 0
script/common/InnerProtoID.lua

@@ -189,3 +189,7 @@ _ENV[175] = 'LW_BATTLEGROUND_MATCHLIST_QUERY'
 _ENV[176] = 'WL_BATTLEGROUND_MATCHLIST_QUERY'
 _ENV[177] = 'LW_BATTLEGROUND_ACT_END'
 
+_ENV[178] = 'LW_DESKTOP_SET'       -- 普通服→中心服:上报添加桌面
+_ENV[179] = 'LW_DESKTOP_QUERY'     -- 普通服→中心服:查询桌面状态
+_ENV[180] = 'WL_DESKTOP_QUERY'     -- 中心服→普通服:查询结果回包
+

+ 4 - 0
script/common/ProtoID.lua

@@ -1823,3 +1823,7 @@ _ENV[1901]="CG_ZHUANPAN_YOUXI_TASK_QUERY"
 _ENV[1902]="GC_ZHUANPAN_YOUXI_TASK_QUERY"
 _ENV[1903]="CG_ZHUANPAN_YOUXI_TASK_GET"
 
+_ENV[1904]="CG_ZHUANPAN_DY_DESKTOP_SET"
+_ENV[1905]="CG_ZHUANPAN_DY_DESKTOP_QUERY"
+_ENV[1906]="GC_ZHUANPAN_DY_DESKTOP_QUERY"
+

+ 13 - 0
script/module/zhuanpan/Handler.lua

@@ -98,4 +98,17 @@ end
 -- 游戏圈任务领取
 function CG_ZHUANPAN_YOUXI_TASK_GET(human, msg)
 	ZhuanpanLogic.youxiTaskGetReward(human, msg.taskId)
+end
+
+
+-----------------------添加桌面-----------------------
+
+-- 上报添加桌面
+function CG_ZHUANPAN_DY_DESKTOP_SET(human, msg)
+	ZhuanpanLogic.dyDesktopSetLocal(human, msg.channelId, msg.platform)
+end
+
+-- 查询桌面添加状态
+function CG_ZHUANPAN_DY_DESKTOP_QUERY(human, msg)
+	ZhuanpanLogic.dyDesktopQueryLocal(human, msg.channelId, msg.platform)
 end

+ 21 - 0
script/module/zhuanpan/Proto.lua

@@ -211,3 +211,24 @@ CG_ZHUANPAN_YOUXI_TASK_GET = {
 	{"taskId",  1,  "byte"},  -- 任务ID (1-5)
 }
 
+
+-----------------------添加桌面-----------------------
+
+-- 上报添加桌面(前端确认添加后调用)
+CG_ZHUANPAN_DY_DESKTOP_SET = {
+	{"channelId",  1,  "int"},     -- 渠道ID
+	{"platform",   1,  "string"},  -- 平台标识(如 "douyin"、"meituan" 等)
+}
+
+-- 查询桌面添加状态
+CG_ZHUANPAN_DY_DESKTOP_QUERY = {
+	{"channelId",  1,  "int"},     -- 渠道ID
+	{"platform",   1,  "string"},  -- 平台标识
+}
+
+GC_ZHUANPAN_DY_DESKTOP_QUERY = {
+	{"channelId",      1,  "int"},     -- 渠道ID
+	{"platform",       1,  "string"},  -- 平台标识
+	{"isDesktopAdded", 1,  "byte"},    -- 是否已添加桌面 0否 1是
+}
+

+ 187 - 0
script/module/zhuanpan/ZhuanpanLogic.lua

@@ -1,6 +1,10 @@
 local Lang  = require("common.Lang")
 local Msg = require("core.Msg")
 local ObjHuman = require("core.ObjHuman")
+local InnerMsg = require("core.InnerMsg")
+local Config = require("Config")
+local MiddleManager = require("middle.MiddleManager")
+local CommonDB = require("common.CommonDB")
 local ZhuanpanExcel = require("excel.zhuanpan")
 local ItemDefine = require("bag.ItemDefine")
 local BagLogic = require("bag.BagLogic")
@@ -1958,6 +1962,189 @@ function youxiTaskGetReward(human, taskId)
 	youxiTaskQuery(human, nil)
 end
 
+-----------------------添加桌面(本地存储,账号级,同游戏圈写法)-----------------------
+
+-- 检查账号下所有角色是否已添加过桌面(查本服MongoDB)
+local function checkAccountDesktopAdded(account, channelId, platform)
+	if not account then return false end
+	local key = tostring(channelId) .. "_" .. tostring(platform)
+	LuaMongo.find(DB.db_char, {account = account}, {zhuanpan = 1})
+	while true do
+		local data = {}
+		if not LuaMongo.next(data) then break end
+		local da = data.zhuanpan and data.zhuanpan.desktopAdded
+		if da and da[key] then return true end
+	end
+	return false
+end
+
+-- 上报添加桌面
+function dyDesktopSetLocal(human, channelId, platform)
+	if not channelId or not platform or platform == "" then
+		return Broadcast.sendErr(human, "参数缺失")
+	end
+
+	human.db.zhuanpan = human.db.zhuanpan or {}
+	human.db.zhuanpan.desktopAdded = human.db.zhuanpan.desktopAdded or {}
+	local key = tostring(channelId) .. "_" .. tostring(platform)
+	human.db.zhuanpan.desktopAdded[key] = true
+
+	Log.write(Log.LOGID_DEBUG, "[dyDesktopSetLocal] 添加桌面 account=" .. tostring(human.db.account)
+		.. " channelId=" .. tostring(channelId) .. " platform=" .. tostring(platform))
+
+	local ok, err = pcall(function()
+		dyDesktopQueryLocal(human, channelId, platform)
+	end)
+	if not ok then
+		Log.write(Log.LOGID_DEBUG, "[dyDesktopSetLocal] 错误: 下发查询失败: " .. tostring(err))
+	end
+end
+
+-- 查询桌面添加状态
+function dyDesktopQueryLocal(human, channelId, platform)
+	if not channelId or not platform or platform == "" then
+		return Broadcast.sendErr(human, "参数缺失")
+	end
+
+	local msgRet = Msg.gc.GC_ZHUANPAN_DY_DESKTOP_QUERY
+	if not msgRet then return end
+
+	human.db.zhuanpan = human.db.zhuanpan or {}
+	human.db.zhuanpan.desktopAdded = human.db.zhuanpan.desktopAdded or {}
+	local key = tostring(channelId) .. "_" .. tostring(platform)
+
+	local added = human.db.zhuanpan.desktopAdded[key]
+	if not added then
+		added = checkAccountDesktopAdded(human.db.account, channelId, platform)
+	end
+
+	msgRet.channelId      = channelId
+	msgRet.platform       = platform
+	msgRet.isDesktopAdded = added and 1 or 0
+
+	Log.write(Log.LOGID_DEBUG, "[dyDesktopQueryLocal] account=" .. tostring(human.db.account)
+		.. " channelId=" .. tostring(channelId) .. " platform=" .. tostring(platform)
+		.. " isDesktopAdded=" .. tostring(msgRet.isDesktopAdded))
+
+	if human.fd then
+		Msg.send(msgRet, human.fd)
+	end
+end
+
+
+-----------------------添加桌面(跨服中心服存储,账号级多区服共享)-----------------------
+--
+---- 从 newUniqueTag 解析出 serverId 和 account(格式: "channelID|serverTag|account")
+--local function parseUniqueTag(newUniqueTag)
+--	local parts = {}
+--	for part in string.gmatch(newUniqueTag, "([^|]+)") do
+--		table.insert(parts, part)
+--	end
+--	return tonumber(parts[2]), parts[3]  -- serverId, account
+--end
+--
+---- 普通服:上报添加桌面 → 发消息给中心服写入
+--function dyDesktopSet(human, channelId, platform)
+--	if not channelId or not platform or platform == "" then
+--		return Broadcast.sendErr(human, "参数缺失")
+--	end
+--
+--	local newUniqueTag = human.db.newUniqueTag or human.newUniqueTag
+--	if not newUniqueTag then
+--		return Broadcast.sendErr(human, "账号标识缺失")
+--	end
+--	local serverId, account = parseUniqueTag(newUniqueTag)
+--
+--	local tMsg = InnerMsg.lw.LW_DESKTOP_SET
+--	tMsg.nSrcServerID = Config.SVR_INDEX
+--	tMsg.channelId    = channelId
+--	tMsg.serverId     = serverId or 0
+--	tMsg.account      = account or ""
+--	tMsg.platform     = platform
+--	InnerMsg.sendMsg(0, tMsg)
+--
+--	Log.write(Log.LOGID_DEBUG, "[dyDesktopSet] 发送中心服 channelId=" .. tostring(channelId)
+--		.. " serverId=" .. tostring(serverId) .. " account=" .. tostring(account) .. " platform=" .. tostring(platform))
+--end
+--
+---- 普通服:查询桌面添加状态 → 发消息给中心服查询
+--function dyDesktopQuery(human, channelId, platform)
+--	if not channelId or not platform or platform == "" then
+--		return Broadcast.sendErr(human, "参数缺失")
+--	end
+--
+--	local newUniqueTag = human.db.newUniqueTag or human.newUniqueTag
+--	if not newUniqueTag then
+--		return Broadcast.sendErr(human, "账号标识缺失")
+--	end
+--	local serverId, account = parseUniqueTag(newUniqueTag)
+--
+--	local tMsg = InnerMsg.lw.LW_DESKTOP_QUERY
+--	tMsg.nSrcServerID = Config.SVR_INDEX
+--	tMsg.channelId    = channelId
+--	tMsg.serverId     = serverId or 0
+--	tMsg.account      = account or ""
+--	tMsg.platform     = platform
+--	InnerMsg.sendMsg(0, tMsg)
+--
+--	Log.write(Log.LOGID_DEBUG, "[dyDesktopQuery] 发送中心服 channelId=" .. tostring(channelId)
+--		.. " serverId=" .. tostring(serverId) .. " account=" .. tostring(account) .. " platform=" .. tostring(platform))
+--end
+--
+---- 普通服:收到中心服查询回包,找到玩家下发 GC 协议
+--function NS_DesktopQueryResult(msg)
+--	-- 用三个字段重新拼出 newUniqueTag 来查找在线玩家
+--	local newUniqueTag = tostring(msg.channelId) .. "|" .. tostring(msg.serverId) .. "|" .. tostring(msg.account)
+--	local human = ObjHuman.onlineNewUniqueTag[newUniqueTag]
+--	if not human or not human.fd then
+--		Log.write(Log.LOGID_DEBUG, "[NS_DesktopQueryResult] 玩家不在线 newUniqueTag=" .. newUniqueTag)
+--		return
+--	end
+--
+--	local msgRet = Msg.gc.GC_ZHUANPAN_DY_DESKTOP_QUERY
+--	if not msgRet then return end
+--
+--	msgRet.channelId      = msg.channelId
+--	msgRet.platform       = msg.platform
+--	msgRet.isDesktopAdded = msg.isDesktopAdded
+--
+--	Msg.send(msgRet, human.fd)
+--end
+--
+---- 中心服:收到普通服上报,写入 MongoDB 后回包最新状态
+--function CS_DesktopSet(msg)
+--	CommonDB.SetDesktopData(msg.channelId, msg.serverId, msg.account, msg.platform)
+--
+--	Log.write(Log.LOGID_DEBUG, "[CS_DesktopSet] 写入完成 channelId=" .. tostring(msg.channelId)
+--		.. " serverId=" .. tostring(msg.serverId) .. " account=" .. tostring(msg.account) .. " platform=" .. tostring(msg.platform))
+--
+--	local tMsg = InnerMsg.wl.WL_DESKTOP_QUERY
+--	tMsg.channelId      = msg.channelId
+--	tMsg.serverId       = msg.serverId
+--	tMsg.account        = msg.account
+--	tMsg.platform       = msg.platform
+--	tMsg.isDesktopAdded = 1
+--
+--	local fd = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
+--	InnerMsg.sendMsg(fd, tMsg)
+--end
+--
+---- 中心服:收到普通服查询请求,读 MongoDB 后回包
+--function CS_DesktopQuery(msg)
+--	local added = CommonDB.IsDesktopAdded(msg.channelId, msg.serverId, msg.account, msg.platform)
+--
+--	local tMsg = InnerMsg.wl.WL_DESKTOP_QUERY
+--	tMsg.channelId      = msg.channelId
+--	tMsg.serverId       = msg.serverId
+--	tMsg.account        = msg.account
+--	tMsg.platform       = msg.platform
+--	tMsg.isDesktopAdded = added and 1 or 0
+--
+--	local fd = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
+--	InnerMsg.sendMsg(fd, tMsg)
+--end
+
+
 -- SDK 回调奖励发放(内部调用,与任务奖励独立)
 -- items: {{itemId, count}, ...}
 function youxiSdkReward(human, items)

+ 20 - 7
webServer/src/controller/ApiController.ts

@@ -19,9 +19,10 @@ import {PaymentHelper} from "../utils/PaymentHelper";
 import {SignatureVerifier} from "../utils/SignatureVerifier";
 import {ChannelConfigManager} from "../utils/ChannelConfigManager";
 import {getRoleInfoByUidAndServerId} from "../mongo/mongodb";
+import {min} from "moment-timezone";
 
 // platform内存缓存,key: ip:device_no,TTL 5分钟
-const platformCache = new Map<string, {value: string; expireAt: number}>();
+const platformCache = new Map<string, { value: string; expireAt: number }>();
 const PLATFORM_CACHE_TTL = 60 * 1000; // 缓存1分钟
 
 function setPlatformCache(ip: string, platform: string) {
@@ -602,7 +603,7 @@ class ApiController {
                     // 发货成功
                     if (ctx.query.platform == "mtminiapp") {
                         ctx.body = {"code": 0, "msg": "ok"}
-                    }else {
+                    } else {
                         ctx.body = {errCode: 0};
                     }
                 } else {
@@ -797,8 +798,13 @@ class ApiController {
                         logger.error(`查询服务器${element.server_id}角色信息失败:`, error);
                     }
                 }
-                const sid = Number(element.server_id) || 1;
-                const minSid = Math.floor((sid - 1) / 10) * 10 + 1;
+                let minSid = 1
+                if (tag == 11) {
+                    const sid = Number(element.server_id) || 1;
+                    minSid = Math.floor((sid - 1) / 10) * 10 + 1;
+                }
+
+
                 data.push({
                     channel: channelConfig.name, //渠道固定
                     minSid: minSid, //最小服务器
@@ -844,10 +850,14 @@ class ApiController {
                         logger.error(`查询服务器${serverInfo.id}角色信息失败:`, error);
                     }
                 }
+                let minSid = 1
+                if (tag == 11) {
+                    minSid = Math.floor(((servers[0].sid || 1) - 1) / 10) * 10 + 1
+                }
 
                 data.push({
                     channel: channelConfig.name, //渠道固定
-                    minSid: Math.floor(((servers[0].sid || 1) - 1) / 10) * 10 + 1, //最小服务器
+                    minSid: minSid, //最小服务器
                     maxSid: servers.length, //最大服务器 这里会控制 服务器列表显示的数量
                     isNewAccount: isNewAccount, //1为新号 会弹出用户协议
                     //以下是最近登陆的服务器 (不可为空 如果没有参数可以填最后一个区)
@@ -896,7 +906,9 @@ class ApiController {
         // 所有组的minSid统一取最小值
         if (data.length > 0) {
             const globalMinSid = Math.min(...data.map(item => item.minSid));
-            data.forEach(item => { item.minSid = globalMinSid; });
+            data.forEach(item => {
+                item.minSid = globalMinSid;
+            });
         }
 
         // tag=11 时,找到第一个有角色的服,隐藏它之前的服;都没角色则只显示最新的1个服
@@ -1178,6 +1190,7 @@ class ApiController {
                 "VIP666",
                 "VIP777",
                 "VIP888",
+                "QINGMINGLB",
             ];
             let param: string = "";
 
@@ -1562,7 +1575,7 @@ class ApiController {
 
             // 验证必要参数
             const {serverId, gameServerId, serverName, startTime, channelId} = data;
-            
+
             if (!serverId || !gameServerId || !serverName || !startTime) {
                 logger.warn("mianyou开服同步失败: 缺少必要参数", {data});
                 ctx.body = ApiController.fail("缺少必要参数: serverId, gameServerId, serverName, startTime");