From 7356e583270cfda8e46be6118b508ed261de745d Mon Sep 17 00:00:00 2001 From: zqj <582132116@qq.com> Date: Thu, 2 Dec 2021 10:51:40 +0800 Subject: [PATCH] feat: 增加角色注销协议 --- src/ProtocolCode.lua | 1 + src/actions/RoleAction.lua | 14 ++++++++++++++ src/models/Role.lua | 1 + src/utils/MysqlUtil.lua | 12 ++++++++++-- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 5a0cb92..2581da2 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -65,6 +65,7 @@ actionCodes = { Role_worldLineRouletteRpc = 146, --世界线抽轮盘 Role_worldLineRewardRpc = 147, -- 世界线一键领取奖励 Role_itemConvertDevilTicketRpc = 148, -- 兑换魔鬼训练营门票 + Role_unRegisterRpc = 149, --注销账号 Adv_startAdvRpc = 151, Adv_startHangRpc = 152, diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index 3b65183..6c43b19 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -506,6 +506,20 @@ function _M.createRpc(agent, data) return true end +function _M.unRegisterRpc(agent, data) + local role = agent.role + local roleId = role:getProperty("id") + local msg = MsgPack.unpack(data) + local id = msg.roleId + if id ~= roleId then + return 0 + end + + if not roleUnRegister(roleId) then return 1 end + SendPacket(actionCodes.Role_unRegisterRpc, MsgPack.pack({})) + return true +end + function _M.changeNameRpc(agent, data) local role = agent.role local roleId = role:getProperty("id") diff --git a/src/models/Role.lua b/src/models/Role.lua index a47884e..1049b2b 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -217,6 +217,7 @@ Role.schema = { worldChangePoints = {"table", {}}, -- 世界变动积分 {[1]= 转盘抽取次数, [2]= 获得的积分, [3]=魔导石消耗, [4]= 虹光玉消耗} worldLineReward = {"table", {}}, -- 世界积分 领取记录 {[id] = 1} + del = {"number", 0}, -- 标记删除 0=未删除,1=已删除 } diff --git a/src/utils/MysqlUtil.lua b/src/utils/MysqlUtil.lua index c5d146f..78e6232 100644 --- a/src/utils/MysqlUtil.lua +++ b/src/utils/MysqlUtil.lua @@ -51,7 +51,7 @@ function delFriend(roleId, friendId) end function roleExists(roleId) - local res = mysqlproxy:query(string.format("SELECT `id` FROM `Role` WHERE `id` = %s", roleId)) + local res = mysqlproxy:query(string.format("SELECT `id` FROM `Role` WHERE `del` = 0 and `id` = %s", roleId)) if res["errno"] or not next(res) then return false end @@ -60,10 +60,18 @@ function roleExists(roleId) end function roleUidExists(uid) - local res = mysqlproxy:query(string.format("SELECT `name` FROM `Role` WHERE `uid` = '%s'", uid)) + local res = mysqlproxy:query(string.format("SELECT `name` FROM `Role` WHERE `del` = 0 and `uid` = '%s'", uid)) if res["errno"] or not next(res) then return false end return true, res[1]["name"] +end + +function roleUnRegister(roleId) + local res = mysqlproxy:query(string.format("UPDATE`Role` SET `del` = 1 WHERE `id` = %s", roleId)) + if res["errno"] or not next(res) then + return false + end + return true end \ No newline at end of file -- libgit2 0.21.2