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 | 343 | |
344 | 344 | -- 再次检查uid |
345 | 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 | 348 | if user then |
348 | 349 | response.result = "SUCCESS" |
349 | 350 | response.roleName = user |
... | ... | @@ -1367,7 +1368,7 @@ function _M.goldBuyRpc(agent, data) |
1367 | 1368 | if not costD then |
1368 | 1369 | return 1 |
1369 | 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 | 1372 | return 2 |
1372 | 1373 | end |
1373 | 1374 | local goldC = 0 |
... | ... | @@ -1389,7 +1390,7 @@ function _M.goldBuyRpc(agent, data) |
1389 | 1390 | local coef = role.storeData:getGearExchangeCoef() |
1390 | 1391 | goldC = goldC * coef |
1391 | 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 | 1394 | local reward, change = role:award({[ItemId.Gold] = math.floor(goldC)}, {log = {desc = "goldBuy"}}) |
1394 | 1395 | SendPacket(actionCodes.Role_goldBuyRpc, MsgPack.pack(role:packReward(reward, change))) |
1395 | 1396 | return true | ... | ... |
src/models/RolePlugin.lua
... | ... | @@ -410,14 +410,14 @@ function RolePlugin.bind(Role) |
410 | 410 | |
411 | 411 | function Role:costItems(itemCountT, params) |
412 | 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 | 415 | if not self:costDiamond(pms) then |
416 | 416 | return |
417 | 417 | end |
418 | 418 | end |
419 | 419 | for itemId, count in pairs(itemCountT) do |
420 | - if itemId ~= ItemId.Jade then | |
420 | + if itemId ~= ItemId.Diamond then | |
421 | 421 | pms.itemId = itemId |
422 | 422 | pms.count = - count |
423 | 423 | self:addItem(pms) | ... | ... |
src/services/agent_ctrl.lua
... | ... | @@ -10,6 +10,7 @@ local logproxy = require "shared.logproxy" |
10 | 10 | |
11 | 11 | local pcall = pcall |
12 | 12 | local string_format = string.format |
13 | +require "utils.MysqlUtil" | |
13 | 14 | |
14 | 15 | local poold |
15 | 16 | |
... | ... | @@ -236,8 +237,9 @@ function _M:query_agent(fd, uid, isQueue) |
236 | 237 | |
237 | 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 | 243 | response.ret = "RET_HAS_EXISTED" |
242 | 244 | response.name = user |
243 | 245 | else | ... | ... |
src/services/mysqld.lua
... | ... | @@ -8,12 +8,15 @@ local command = {} |
8 | 8 | |
9 | 9 | function command.open(conf) |
10 | 10 | local function on_connect(db) |
11 | + local servId = skynet.getenv("servId") | |
11 | 12 | db:query("set charset utf8mb4"); |
13 | + db:query(string.format("use server_%s", servId)) | |
12 | 14 | end |
15 | + local servId = skynet.getenv("servId") | |
13 | 16 | db=mysql.connect({ |
14 | 17 | host=conf.host, |
15 | 18 | port=conf.port, |
16 | - database="mysql", | |
19 | + database= "mysql", | |
17 | 20 | user=conf.user, |
18 | 21 | password=conf.pwd, |
19 | 22 | max_packet_size = 5 * 1024 * 1024, |
... | ... | @@ -22,8 +25,6 @@ function command.open(conf) |
22 | 25 | if not db then |
23 | 26 | print("failed to connect") |
24 | 27 | end |
25 | - local servId = skynet.getenv("servId") | |
26 | - db:query(string.format("use server_%s", servId)) | |
27 | 28 | end |
28 | 29 | |
29 | 30 | skynet.start(function() | ... | ... |
src/shared/ModelBaseMysql.lua
... | ... | @@ -143,7 +143,7 @@ function ModelBaseMysql:save() |
143 | 143 | local res = mysqlproxy:query(sql) |
144 | 144 | if res["errno"] then |
145 | 145 | skynet.error(sql) |
146 | - skynet.error(res["error"]) | |
146 | + skynet.error(res["err"]) | |
147 | 147 | end |
148 | 148 | end |
149 | 149 | end |
... | ... | @@ -502,7 +502,7 @@ function ModelBaseMysql:updateFields(fields) |
502 | 502 | local res = mysqlproxy:query(sql) |
503 | 503 | if res["errno"] then |
504 | 504 | skynet.error(sql) |
505 | - skynet.error(res["error"]) | |
505 | + skynet.error(res["err"]) | |
506 | 506 | return false |
507 | 507 | end |
508 | 508 | end | ... | ... |
src/utils/MysqlUtil.lua
... | ... | @@ -54,4 +54,13 @@ function roleExists(roleId) |
54 | 54 | end |
55 | 55 | |
56 | 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 | 66 | end |
58 | 67 | \ No newline at end of file | ... | ... |