From 01be2d786592758b20977989b1486d5509b7e63e Mon Sep 17 00:00:00 2001 From: liuzujun <307836273@qq.com> Date: Tue, 30 Mar 2021 20:28:43 +0800 Subject: [PATCH] 修改mysql链接断开重连的bug --- src/actions/RoleAction.lua | 7 ++++--- src/csvdata | 2 +- src/models/RolePlugin.lua | 6 +++--- src/services/agent_ctrl.lua | 6 ++++-- src/services/mysqld.lua | 7 ++++--- src/shared/ModelBaseMysql.lua | 4 ++-- src/utils/MysqlUtil.lua | 9 +++++++++ 7 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index 7b49144..83369a7 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -343,7 +343,8 @@ function _M.createRpc(agent, data) -- 再次检查uid local uid = tostring(msg.uid) - local user = redisproxy:get(string_format("uid:%s", uid)) + --local user = redisproxy:get(string_format("uid:%s", uid)) + local res, user = roleUidExists(uid) if user then response.result = "SUCCESS" response.roleName = user @@ -1367,7 +1368,7 @@ function _M.goldBuyRpc(agent, data) if not costD then return 1 end - if costD ~= 0 and not role:checkItemEnough({[ItemId.Jade] = costD}) then + if costD ~= 0 and not role:checkItemEnough({[ItemId.Diamond] = costD}) then return 2 end local goldC = 0 @@ -1389,7 +1390,7 @@ function _M.goldBuyRpc(agent, data) local coef = role.storeData:getGearExchangeCoef() goldC = goldC * coef role.dailyData:updateProperty({field = "goldBuyT", value = curT + 1}) - role:costItems({[ItemId.Jade] = costD}, {log = {desc = "goldBuy"}}) + role:costItems({[ItemId.Diamond] = costD}, {log = {desc = "goldBuy"}}) local reward, change = role:award({[ItemId.Gold] = math.floor(goldC)}, {log = {desc = "goldBuy"}}) SendPacket(actionCodes.Role_goldBuyRpc, MsgPack.pack(role:packReward(reward, change))) return true diff --git a/src/csvdata b/src/csvdata index 7253317..9a02ff3 160000 --- a/src/csvdata +++ b/src/csvdata @@ -1 +1 @@ -Subproject commit 7253317be1301eaa5c45dc1d7d71f17d2f180a18 +Subproject commit 9a02ff3040615ea6f1eae4ed857b20ab35ea39f1 diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index ab78d21..967509b 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -410,14 +410,14 @@ function RolePlugin.bind(Role) function Role:costItems(itemCountT, params) local pms = clone(params or {}) - if itemCountT[ItemId.Jade] then --优先扣除钻石 - pms.count = itemCountT[ItemId.Jade] + if itemCountT[ItemId.Diamond] then --优先扣除钻石 + pms.count = itemCountT[ItemId.Diamond] if not self:costDiamond(pms) then return end end for itemId, count in pairs(itemCountT) do - if itemId ~= ItemId.Jade then + if itemId ~= ItemId.Diamond then pms.itemId = itemId pms.count = - count self:addItem(pms) diff --git a/src/services/agent_ctrl.lua b/src/services/agent_ctrl.lua index ebfaf05..22480c9 100644 --- a/src/services/agent_ctrl.lua +++ b/src/services/agent_ctrl.lua @@ -10,6 +10,7 @@ local logproxy = require "shared.logproxy" local pcall = pcall local string_format = string.format +require "utils.MysqlUtil" local poold @@ -236,8 +237,9 @@ function _M:query_agent(fd, uid, isQueue) local response = {} - local user = redisproxy:get(string_format("uid:%s", uid)) - if user then + --local user = redisproxy:get(string_format("uid:%s", uid)) + local res, user = roleUidExists(uid) + if res then response.ret = "RET_HAS_EXISTED" response.name = user else diff --git a/src/services/mysqld.lua b/src/services/mysqld.lua index ec78528..32e9bd2 100644 --- a/src/services/mysqld.lua +++ b/src/services/mysqld.lua @@ -8,12 +8,15 @@ local command = {} function command.open(conf) local function on_connect(db) + local servId = skynet.getenv("servId") db:query("set charset utf8mb4"); + db:query(string.format("use server_%s", servId)) end + local servId = skynet.getenv("servId") db=mysql.connect({ host=conf.host, port=conf.port, - database="mysql", + database= "mysql", user=conf.user, password=conf.pwd, max_packet_size = 5 * 1024 * 1024, @@ -22,8 +25,6 @@ function command.open(conf) if not db then print("failed to connect") end - local servId = skynet.getenv("servId") - db:query(string.format("use server_%s", servId)) end skynet.start(function() diff --git a/src/shared/ModelBaseMysql.lua b/src/shared/ModelBaseMysql.lua index c2255d1..d3cea5c 100644 --- a/src/shared/ModelBaseMysql.lua +++ b/src/shared/ModelBaseMysql.lua @@ -143,7 +143,7 @@ function ModelBaseMysql:save() local res = mysqlproxy:query(sql) if res["errno"] then skynet.error(sql) - skynet.error(res["error"]) + skynet.error(res["err"]) end end end @@ -502,7 +502,7 @@ function ModelBaseMysql:updateFields(fields) local res = mysqlproxy:query(sql) if res["errno"] then skynet.error(sql) - skynet.error(res["error"]) + skynet.error(res["err"]) return false end end diff --git a/src/utils/MysqlUtil.lua b/src/utils/MysqlUtil.lua index 160d488..768995d 100644 --- a/src/utils/MysqlUtil.lua +++ b/src/utils/MysqlUtil.lua @@ -54,4 +54,13 @@ function roleExists(roleId) end return true +end + +function roleUidExists(uid) + local res = mysqlproxy:query(string.format("SELECT `name` FROM `Role` WHERE `uid` = %s", uid)) + if res["errno"] or not next(res) then + return false + end + + return true, res[1]["name"] end \ No newline at end of file -- libgit2 0.21.2