Commit 01be2d786592758b20977989b1486d5509b7e63e
1 parent
ca77b8d1
修改mysql链接断开重连的bug
Showing
7 changed files
with
27 additions
and
14 deletions
Show diff stats
src/actions/RoleAction.lua
| @@ -343,7 +343,8 @@ function _M.createRpc(agent, data) | @@ -343,7 +343,8 @@ function _M.createRpc(agent, data) | ||
| 343 | 343 | ||
| 344 | -- 再次检查uid | 344 | -- 再次检查uid |
| 345 | local uid = tostring(msg.uid) | 345 | local uid = tostring(msg.uid) |
| 346 | - local user = redisproxy:get(string_format("uid:%s", uid)) | 346 | + --local user = redisproxy:get(string_format("uid:%s", uid)) |
| 347 | + local res, user = roleUidExists(uid) | ||
| 347 | if user then | 348 | if user then |
| 348 | response.result = "SUCCESS" | 349 | response.result = "SUCCESS" |
| 349 | response.roleName = user | 350 | response.roleName = user |
| @@ -1367,7 +1368,7 @@ function _M.goldBuyRpc(agent, data) | @@ -1367,7 +1368,7 @@ function _M.goldBuyRpc(agent, data) | ||
| 1367 | if not costD then | 1368 | if not costD then |
| 1368 | return 1 | 1369 | return 1 |
| 1369 | end | 1370 | end |
| 1370 | - if costD ~= 0 and not role:checkItemEnough({[ItemId.Jade] = costD}) then | 1371 | + if costD ~= 0 and not role:checkItemEnough({[ItemId.Diamond] = costD}) then |
| 1371 | return 2 | 1372 | return 2 |
| 1372 | end | 1373 | end |
| 1373 | local goldC = 0 | 1374 | local goldC = 0 |
| @@ -1389,7 +1390,7 @@ function _M.goldBuyRpc(agent, data) | @@ -1389,7 +1390,7 @@ function _M.goldBuyRpc(agent, data) | ||
| 1389 | local coef = role.storeData:getGearExchangeCoef() | 1390 | local coef = role.storeData:getGearExchangeCoef() |
| 1390 | goldC = goldC * coef | 1391 | goldC = goldC * coef |
| 1391 | role.dailyData:updateProperty({field = "goldBuyT", value = curT + 1}) | 1392 | role.dailyData:updateProperty({field = "goldBuyT", value = curT + 1}) |
| 1392 | - role:costItems({[ItemId.Jade] = costD}, {log = {desc = "goldBuy"}}) | 1393 | + role:costItems({[ItemId.Diamond] = costD}, {log = {desc = "goldBuy"}}) |
| 1393 | local reward, change = role:award({[ItemId.Gold] = math.floor(goldC)}, {log = {desc = "goldBuy"}}) | 1394 | local reward, change = role:award({[ItemId.Gold] = math.floor(goldC)}, {log = {desc = "goldBuy"}}) |
| 1394 | SendPacket(actionCodes.Role_goldBuyRpc, MsgPack.pack(role:packReward(reward, change))) | 1395 | SendPacket(actionCodes.Role_goldBuyRpc, MsgPack.pack(role:packReward(reward, change))) |
| 1395 | return true | 1396 | return true |
src/models/RolePlugin.lua
| @@ -410,14 +410,14 @@ function RolePlugin.bind(Role) | @@ -410,14 +410,14 @@ function RolePlugin.bind(Role) | ||
| 410 | 410 | ||
| 411 | function Role:costItems(itemCountT, params) | 411 | function Role:costItems(itemCountT, params) |
| 412 | local pms = clone(params or {}) | 412 | local pms = clone(params or {}) |
| 413 | - if itemCountT[ItemId.Jade] then --优先扣除钻石 | ||
| 414 | - pms.count = itemCountT[ItemId.Jade] | 413 | + if itemCountT[ItemId.Diamond] then --优先扣除钻石 |
| 414 | + pms.count = itemCountT[ItemId.Diamond] | ||
| 415 | if not self:costDiamond(pms) then | 415 | if not self:costDiamond(pms) then |
| 416 | return | 416 | return |
| 417 | end | 417 | end |
| 418 | end | 418 | end |
| 419 | for itemId, count in pairs(itemCountT) do | 419 | for itemId, count in pairs(itemCountT) do |
| 420 | - if itemId ~= ItemId.Jade then | 420 | + if itemId ~= ItemId.Diamond then |
| 421 | pms.itemId = itemId | 421 | pms.itemId = itemId |
| 422 | pms.count = - count | 422 | pms.count = - count |
| 423 | self:addItem(pms) | 423 | self:addItem(pms) |
src/services/agent_ctrl.lua
| @@ -10,6 +10,7 @@ local logproxy = require "shared.logproxy" | @@ -10,6 +10,7 @@ local logproxy = require "shared.logproxy" | ||
| 10 | 10 | ||
| 11 | local pcall = pcall | 11 | local pcall = pcall |
| 12 | local string_format = string.format | 12 | local string_format = string.format |
| 13 | +require "utils.MysqlUtil" | ||
| 13 | 14 | ||
| 14 | local poold | 15 | local poold |
| 15 | 16 | ||
| @@ -236,8 +237,9 @@ function _M:query_agent(fd, uid, isQueue) | @@ -236,8 +237,9 @@ function _M:query_agent(fd, uid, isQueue) | ||
| 236 | 237 | ||
| 237 | local response = {} | 238 | local response = {} |
| 238 | 239 | ||
| 239 | - local user = redisproxy:get(string_format("uid:%s", uid)) | ||
| 240 | - if user then | 240 | + --local user = redisproxy:get(string_format("uid:%s", uid)) |
| 241 | + local res, user = roleUidExists(uid) | ||
| 242 | + if res then | ||
| 241 | response.ret = "RET_HAS_EXISTED" | 243 | response.ret = "RET_HAS_EXISTED" |
| 242 | response.name = user | 244 | response.name = user |
| 243 | else | 245 | else |
src/services/mysqld.lua
| @@ -8,12 +8,15 @@ local command = {} | @@ -8,12 +8,15 @@ local command = {} | ||
| 8 | 8 | ||
| 9 | function command.open(conf) | 9 | function command.open(conf) |
| 10 | local function on_connect(db) | 10 | local function on_connect(db) |
| 11 | + local servId = skynet.getenv("servId") | ||
| 11 | db:query("set charset utf8mb4"); | 12 | db:query("set charset utf8mb4"); |
| 13 | + db:query(string.format("use server_%s", servId)) | ||
| 12 | end | 14 | end |
| 15 | + local servId = skynet.getenv("servId") | ||
| 13 | db=mysql.connect({ | 16 | db=mysql.connect({ |
| 14 | host=conf.host, | 17 | host=conf.host, |
| 15 | port=conf.port, | 18 | port=conf.port, |
| 16 | - database="mysql", | 19 | + database= "mysql", |
| 17 | user=conf.user, | 20 | user=conf.user, |
| 18 | password=conf.pwd, | 21 | password=conf.pwd, |
| 19 | max_packet_size = 5 * 1024 * 1024, | 22 | max_packet_size = 5 * 1024 * 1024, |
| @@ -22,8 +25,6 @@ function command.open(conf) | @@ -22,8 +25,6 @@ function command.open(conf) | ||
| 22 | if not db then | 25 | if not db then |
| 23 | print("failed to connect") | 26 | print("failed to connect") |
| 24 | end | 27 | end |
| 25 | - local servId = skynet.getenv("servId") | ||
| 26 | - db:query(string.format("use server_%s", servId)) | ||
| 27 | end | 28 | end |
| 28 | 29 | ||
| 29 | skynet.start(function() | 30 | skynet.start(function() |
src/shared/ModelBaseMysql.lua
| @@ -143,7 +143,7 @@ function ModelBaseMysql:save() | @@ -143,7 +143,7 @@ function ModelBaseMysql:save() | ||
| 143 | local res = mysqlproxy:query(sql) | 143 | local res = mysqlproxy:query(sql) |
| 144 | if res["errno"] then | 144 | if res["errno"] then |
| 145 | skynet.error(sql) | 145 | skynet.error(sql) |
| 146 | - skynet.error(res["error"]) | 146 | + skynet.error(res["err"]) |
| 147 | end | 147 | end |
| 148 | end | 148 | end |
| 149 | end | 149 | end |
| @@ -502,7 +502,7 @@ function ModelBaseMysql:updateFields(fields) | @@ -502,7 +502,7 @@ function ModelBaseMysql:updateFields(fields) | ||
| 502 | local res = mysqlproxy:query(sql) | 502 | local res = mysqlproxy:query(sql) |
| 503 | if res["errno"] then | 503 | if res["errno"] then |
| 504 | skynet.error(sql) | 504 | skynet.error(sql) |
| 505 | - skynet.error(res["error"]) | 505 | + skynet.error(res["err"]) |
| 506 | return false | 506 | return false |
| 507 | end | 507 | end |
| 508 | end | 508 | end |
src/utils/MysqlUtil.lua
| @@ -54,4 +54,13 @@ function roleExists(roleId) | @@ -54,4 +54,13 @@ function roleExists(roleId) | ||
| 54 | end | 54 | end |
| 55 | 55 | ||
| 56 | return true | 56 | return true |
| 57 | +end | ||
| 58 | + | ||
| 59 | +function roleUidExists(uid) | ||
| 60 | + local res = mysqlproxy:query(string.format("SELECT `name` FROM `Role` WHERE `uid` = %s", uid)) | ||
| 61 | + if res["errno"] or not next(res) then | ||
| 62 | + return false | ||
| 63 | + end | ||
| 64 | + | ||
| 65 | + return true, res[1]["name"] | ||
| 57 | end | 66 | end |
| 58 | \ No newline at end of file | 67 | \ No newline at end of file |