Commit 248570a02e9dd8e6966d28581d644366a84c0798
Merge branch 'cn/develop' into cn/publish/preview
Showing
44 changed files
with
1808 additions
and
424 deletions
Show diff stats
config/develop.lua
@@ -16,3 +16,8 @@ redis_host = "127.0.0.1" | @@ -16,3 +16,8 @@ redis_host = "127.0.0.1" | ||
16 | redis_port = 6100 | 16 | redis_port = 6100 |
17 | redis_db = 1 | 17 | redis_db = 1 |
18 | redis_auth = nil | 18 | redis_auth = nil |
19 | + | ||
20 | +mysql_host = "127.0.0.1" | ||
21 | +mysql_port = 3306 | ||
22 | +mysql_user = "root" | ||
23 | +mysql_password = "123456" | ||
19 | \ No newline at end of file | 24 | \ No newline at end of file |
@@ -10,10 +10,10 @@ fi | @@ -10,10 +10,10 @@ fi | ||
10 | pid=`cat skynet.pid` | 10 | pid=`cat skynet.pid` |
11 | run=`ps aux | grep skynet | grep -v grep | grep -c $pid` | 11 | run=`ps aux | grep skynet | grep -v grep | grep -c $pid` |
12 | 12 | ||
13 | -if [ $run = 1 ]; then | 13 | +if [[ $run = 1 ]]; then |
14 | echo "服务端正在运行" | 14 | echo "服务端正在运行" |
15 | exit 0 | 15 | exit 0 |
16 | fi | 16 | fi |
17 | 17 | ||
18 | skynet/skynet config/${config}.lua | 18 | skynet/skynet config/${config}.lua |
19 | -echo "服务端启动完毕" | ||
20 | \ No newline at end of file | 19 | \ No newline at end of file |
20 | +echo "服务端启动完毕" |
src/GlobalVar.lua
@@ -27,7 +27,11 @@ STRUCT_VERSION = 3 -- 数据结构版本 | @@ -27,7 +27,11 @@ STRUCT_VERSION = 3 -- 数据结构版本 | ||
27 | IOS_SID = 4 -- 判断是不是ios设备 | 27 | IOS_SID = 4 -- 判断是不是ios设备 |
28 | UO_SID = 6 -- 判断是不是联运渠道 | 28 | UO_SID = 6 -- 判断是不是联运渠道 |
29 | 29 | ||
30 | +MAX_SVR_ID = 10000 | ||
30 | MAX_ROLE_NUM = 1000000 | 31 | MAX_ROLE_NUM = 1000000 |
32 | +MAX_HERO_NUM = 1000000 -- 英雄的id = roleId * MAX_HERO_NUM + index | ||
33 | +MAX_RUNE_NUM = 1000000 -- 铭文的id = roleId * MAX_RUNE_NUM + index | ||
34 | +MAX_SPARK_NUM = 1000000 -- 火花的id = roleId * MAX_SPARK_NUM + index | ||
31 | -- 属性枚举 | 35 | -- 属性枚举 |
32 | AttsEnum = { | 36 | AttsEnum = { |
33 | hp = 1, -- 血量 | 37 | hp = 1, -- 血量 |
@@ -130,9 +134,10 @@ ItemStartId = { | @@ -130,9 +134,10 @@ ItemStartId = { | ||
130 | ItemId = { | 134 | ItemId = { |
131 | Gold = 1, -- 金币 | 135 | Gold = 1, -- 金币 |
132 | Exp = 2, -- 经验 | 136 | Exp = 2, -- 经验 |
133 | - Diamond = 3, -- 钻石 | 137 | + Jade = 3, -- 虹光玉 |
134 | PlayerExp = 4, -- 突破材料 | 138 | PlayerExp = 4, -- 突破材料 |
135 | FriendPoint = 5, -- 友情点 | 139 | FriendPoint = 5, -- 友情点 |
140 | + Diamond = 8, -- 钻石 | ||
136 | BreakCost = 10, -- 突破材料 | 141 | BreakCost = 10, -- 突破材料 |
137 | EquipUp = 11, -- 装备升级材料 | 142 | EquipUp = 11, -- 装备升级材料 |
138 | DinerCoin = 12, --后勤物资 | 143 | DinerCoin = 12, --后勤物资 |
@@ -144,6 +149,7 @@ ItemId = { | @@ -144,6 +149,7 @@ ItemId = { | ||
144 | PvpKey = 22, -- pvp钥匙 | 149 | PvpKey = 22, -- pvp钥匙 |
145 | LunchFragment = 23, | 150 | LunchFragment = 23, |
146 | RuneFragment = 24, | 151 | RuneFragment = 24, |
152 | + RecruitmentCard = 70, -- 招募券 | ||
147 | HeroFC = {700, 701, 702, 703}, --通用角色碎片 | 153 | HeroFC = {700, 701, 702, 703}, --通用角色碎片 |
148 | AdvKey = 80, -- 冒险钥匙 | 154 | AdvKey = 80, -- 冒险钥匙 |
149 | AdvPower = 4701, -- 拾荒体力 | 155 | AdvPower = 4701, -- 拾荒体力 |
src/ProtocolCode.lua
@@ -53,6 +53,8 @@ actionCodes = { | @@ -53,6 +53,8 @@ actionCodes = { | ||
53 | Role_accuseRpc = 137, -- 举报 | 53 | Role_accuseRpc = 137, -- 举报 |
54 | Role_loadSparks = 138, | 54 | Role_loadSparks = 138, |
55 | Role_updateSpark = 139, -- 更新火花 | 55 | Role_updateSpark = 139, -- 更新火花 |
56 | + Role_diamondConvertRpc = 140, -- 钻石兑换成别的物品 | ||
57 | + Role_getTimeGiftRpc = 141, | ||
56 | 58 | ||
57 | Adv_startAdvRpc = 151, | 59 | Adv_startAdvRpc = 151, |
58 | Adv_startHangRpc = 152, | 60 | Adv_startHangRpc = 152, |
@@ -125,6 +127,7 @@ actionCodes = { | @@ -125,6 +127,7 @@ actionCodes = { | ||
125 | Hang_endWorkBattleRpc = 267, | 127 | Hang_endWorkBattleRpc = 267, |
126 | Hang_workBattleInfoRpc = 268, | 128 | Hang_workBattleInfoRpc = 268, |
127 | Hang_getWorkRewardRpc = 269, | 129 | Hang_getWorkRewardRpc = 269, |
130 | + Hang_unlockChapterRpc = 270, | ||
128 | 131 | ||
129 | Diner_updateProperty = 300, | 132 | Diner_updateProperty = 300, |
130 | Diner_addSellRpc = 301, | 133 | Diner_addSellRpc = 301, |
@@ -251,6 +254,7 @@ actionCodes = { | @@ -251,6 +254,7 @@ actionCodes = { | ||
251 | Activity_advLevelRpc = 671, | 254 | Activity_advLevelRpc = 671, |
252 | Activity_buyBattleCommandLvlRpc = 672, | 255 | Activity_buyBattleCommandLvlRpc = 672, |
253 | Activity_returnerTaskRpc = 673, | 256 | Activity_returnerTaskRpc = 673, |
257 | + Activity_actNewUserTaskRpc = 674, | ||
254 | 258 | ||
255 | Radio_startQuestRpc = 700, | 259 | Radio_startQuestRpc = 700, |
256 | Radio_finishQuestRpc = 701, | 260 | Radio_finishQuestRpc = 701, |
src/actions/ActivityAction.lua
@@ -320,6 +320,47 @@ function _M.actBattleCommandTaskRpc(agent, data) | @@ -320,6 +320,47 @@ function _M.actBattleCommandTaskRpc(agent, data) | ||
320 | return true | 320 | return true |
321 | end | 321 | end |
322 | 322 | ||
323 | +function _M.actNewUserTaskRpc(agent, data) | ||
324 | + local role = agent.role | ||
325 | + local msg = MsgPack.unpack(data) | ||
326 | + local taskId = msg.id | ||
327 | + local calTask = role:getProperty("nbTask") or {} | ||
328 | + local record = calTask["r"] or {} | ||
329 | + local flag = record[taskId] or 0 | ||
330 | + if flag == 1 then return 1 end | ||
331 | + local open, actId = role.activity:isOpen("NewUserTask") | ||
332 | + local actData = csvdb["activity_ctrlCsv"][actId] | ||
333 | + if not open then return 2 end | ||
334 | + if not actData then return 3 end | ||
335 | + | ||
336 | + local taskList = csvdb["activity_taskCsv"][actData.condition] | ||
337 | + if not taskList then return 4 end | ||
338 | + local taskCfg = taskList[taskId] | ||
339 | + if not taskCfg then return 5 end | ||
340 | + if taskCfg.key ~= actData.condition then return 6 end | ||
341 | + | ||
342 | + if (calTask[taskId] or 0) < taskCfg.condition1 then return 7 end | ||
343 | + | ||
344 | + record[taskId] = 1 | ||
345 | + calTask["r"] = record | ||
346 | + | ||
347 | + role:updateProperty({field = "nbTask", value = calTask}) | ||
348 | + | ||
349 | + local reward, change = role:award(taskCfg.reward, {log = {desc = "newUserTask"}}) | ||
350 | + | ||
351 | + role:log("activity", { | ||
352 | + activity_id = taskId, -- 活动ID(或活动指定任务的ID) | ||
353 | + activity_type = role.activity.ActivityType.NewUserTask, -- 活动类型,见活动类型枚举表 | ||
354 | + activity_reward = reward, -- 活动奖励,json格式记录,{'itemid1':123,'itemid2':456,………...} | ||
355 | + }) | ||
356 | + | ||
357 | + role:checkTaskEnter("FinishSpeTask", {taskId = taskId, actId = actId}) | ||
358 | + | ||
359 | + SendPacket(actionCodes.Activity_actNewUserTaskRpc, MsgPack.pack(role:packReward(reward, change))) | ||
360 | + | ||
361 | + return true | ||
362 | +end | ||
363 | + | ||
323 | function _M.exchangeRpc(agent, data) | 364 | function _M.exchangeRpc(agent, data) |
324 | local role = agent.role | 365 | local role = agent.role |
325 | local msg = MsgPack.unpack(data) | 366 | local msg = MsgPack.unpack(data) |
@@ -1013,16 +1054,6 @@ function _M.friendHelpRpc(agent, data) | @@ -1013,16 +1054,6 @@ function _M.friendHelpRpc(agent, data) | ||
1013 | 1054 | ||
1014 | local actData = role.activity:getActData("FriendEnergy") or {} | 1055 | local actData = role.activity:getActData("FriendEnergy") or {} |
1015 | 1056 | ||
1016 | - local function getIds() | ||
1017 | - local ids = {} | ||
1018 | - local friends = redisproxy:hgetall(FRIEND_KEY:format(roleId)) | ||
1019 | - for i = 1, #friends , 2 do | ||
1020 | - local objId = tonumber(friends[i]) | ||
1021 | - ids[objId] = 1 | ||
1022 | - end | ||
1023 | - return ids | ||
1024 | - end | ||
1025 | - | ||
1026 | if oper == 1 then -- 赠送好友能量 | 1057 | if oper == 1 then -- 赠送好友能量 |
1027 | local giveAE = actData.giveAE or {} | 1058 | local giveAE = actData.giveAE or {} |
1028 | local objId = msg.roleId | 1059 | local objId = msg.roleId |
@@ -1032,7 +1063,7 @@ function _M.friendHelpRpc(agent, data) | @@ -1032,7 +1063,7 @@ function _M.friendHelpRpc(agent, data) | ||
1032 | if not objId then | 1063 | if not objId then |
1033 | return 3 | 1064 | return 3 |
1034 | end | 1065 | end |
1035 | - if not redisproxy:hexists(FRIEND_KEY:format(roleId), objId) then | 1066 | + if not role.friends[objId] then |
1036 | result = 2 | 1067 | result = 2 |
1037 | end | 1068 | end |
1038 | if giveAE[objId] then | 1069 | if giveAE[objId] then |
@@ -1078,7 +1109,6 @@ function _M.friendHelpRpc(agent, data) | @@ -1078,7 +1109,6 @@ function _M.friendHelpRpc(agent, data) | ||
1078 | local gift2 = gifts[2] | 1109 | local gift2 = gifts[2] |
1079 | local limit = actData.limit or 0 | 1110 | local limit = actData.limit or 0 |
1080 | local cmd1, cmd2 = 0, 0 | 1111 | local cmd1, cmd2 = 0, 0 |
1081 | - local ids = getIds() | ||
1082 | 1112 | ||
1083 | local members = {} | 1113 | local members = {} |
1084 | local temp = redisproxy:smembers(FRIEND_ENERGY:format(roleId)) | 1114 | local temp = redisproxy:smembers(FRIEND_ENERGY:format(roleId)) |
@@ -1087,7 +1117,7 @@ function _M.friendHelpRpc(agent, data) | @@ -1087,7 +1117,7 @@ function _M.friendHelpRpc(agent, data) | ||
1087 | end | 1117 | end |
1088 | 1118 | ||
1089 | redisproxy:pipelining(function(red) | 1119 | redisproxy:pipelining(function(red) |
1090 | - for friendId, _ in pairs(ids) do | 1120 | + for friendId, _ in pairs(role.friends) do |
1091 | if not giveAE[friendId] then | 1121 | if not giveAE[friendId] then |
1092 | giveAE[friendId] = 1 | 1122 | giveAE[friendId] = 1 |
1093 | award[gift1[1]] = (award[gift1[1]] or 0) + gift1[2] | 1123 | award[gift1[1]] = (award[gift1[1]] or 0) + gift1[2] |
@@ -1153,13 +1183,12 @@ function _M.friendHelpRpc(agent, data) | @@ -1153,13 +1183,12 @@ function _M.friendHelpRpc(agent, data) | ||
1153 | 1183 | ||
1154 | local ids = {} | 1184 | local ids = {} |
1155 | local members = {} | 1185 | local members = {} |
1156 | - local friendIds = getIds() | ||
1157 | local temp = redisproxy:smembers(FRIEND_ENERGY:format(roleId)) | 1186 | local temp = redisproxy:smembers(FRIEND_ENERGY:format(roleId)) |
1158 | for _, id in pairs(temp) do | 1187 | for _, id in pairs(temp) do |
1159 | members[tonumber(id)] = 1 | 1188 | members[tonumber(id)] = 1 |
1160 | end | 1189 | end |
1161 | 1190 | ||
1162 | - for id, _ in pairs(friendIds) do | 1191 | + for id, _ in pairs(role.friends) do |
1163 | if members[id] then | 1192 | if members[id] then |
1164 | ids[id] = 1 | 1193 | ids[id] = 1 |
1165 | end | 1194 | end |
@@ -1294,8 +1323,8 @@ function _M.buyBattleCommandLvlRpc(agent, data) | @@ -1294,8 +1323,8 @@ function _M.buyBattleCommandLvlRpc(agent, data) | ||
1294 | end | 1323 | end |
1295 | if cost == 0 then return 5 end | 1324 | if cost == 0 then return 5 end |
1296 | 1325 | ||
1297 | - if not role:checkItemEnough({[ItemId.Diamond] = cost}) then return 6 end | ||
1298 | - role:costItems({[ItemId.Diamond] = cost}, {log = {desc = "actBuyBpLevel", int1 = curLvl}}) | 1326 | + if not role:checkItemEnough({[ItemId.Jade] = cost}) then return 6 end |
1327 | + role:costItems({[ItemId.Jade] = cost}, {log = {desc = "actBuyBpLevel", int1 = curLvl}}) | ||
1299 | actData["lvl"] = nextLvl | 1328 | actData["lvl"] = nextLvl |
1300 | role.activity:updateActData("BattleCommand", actData) | 1329 | role.activity:updateActData("BattleCommand", actData) |
1301 | 1330 |
src/actions/AdvAction.lua
@@ -381,8 +381,8 @@ function _M.quickHangRpc(agent, data) | @@ -381,8 +381,8 @@ function _M.quickHangRpc(agent, data) | ||
381 | 381 | ||
382 | local cost = math.ceil((info.time - skynet.timex()) / 3600 * globalCsv.adv_idle_quicken) | 382 | local cost = math.ceil((info.time - skynet.timex()) / 3600 * globalCsv.adv_idle_quicken) |
383 | 383 | ||
384 | - if not role:checkItemEnough({[ItemId.Diamond] = cost}) then return end | ||
385 | - role:costItems({[ItemId.Diamond] = cost}, {log = {desc = "advQuickHang", int1 = chapterId}}) | 384 | + if not role:checkItemEnough({[ItemId.Jade] = cost}) then return end |
385 | + role:costItems({[ItemId.Jade] = cost}, {log = {desc = "advQuickHang", int1 = chapterId}}) | ||
386 | info.time = 0 | 386 | info.time = 0 |
387 | role:changeUpdates({{type = "advHang", field = chapterId, value = info}}) | 387 | role:changeUpdates({{type = "advHang", field = chapterId, value = info}}) |
388 | 388 | ||
@@ -494,6 +494,7 @@ function _M.endHangRpc(agent, data) | @@ -494,6 +494,7 @@ function _M.endHangRpc(agent, data) | ||
494 | 494 | ||
495 | role:checkTaskEnter("AdvHang", {}) | 495 | role:checkTaskEnter("AdvHang", {}) |
496 | role:checkTaskEnter("AdvHangHeroCnt", {count = heroCnt}) | 496 | role:checkTaskEnter("AdvHangHeroCnt", {count = heroCnt}) |
497 | + role:checkTaskEnter("AdvHangTime", {count = math.ceil(adv_idle_time / 3600)}) | ||
497 | 498 | ||
498 | SendPacket(actionCodes.Adv_endHangRpc, MsgPack.pack({reward = reward, change = change, isFull = isFull, heroFaith = heroFaithMap})) | 499 | SendPacket(actionCodes.Adv_endHangRpc, MsgPack.pack({reward = reward, change = change, isFull = isFull, heroFaith = heroFaithMap})) |
499 | return true | 500 | return true |
@@ -508,10 +509,10 @@ function _M.buyAdvCountRpc(agent , data) | @@ -508,10 +509,10 @@ function _M.buyAdvCountRpc(agent , data) | ||
508 | local cost | 509 | local cost |
509 | if isEl then | 510 | if isEl then |
510 | if math.illegalNum(count, 1, globalCsv.adv_endless_daily_buy_count - role.dailyData:getProperty("advElBC")) then return end | 511 | if math.illegalNum(count, 1, globalCsv.adv_endless_daily_buy_count - role.dailyData:getProperty("advElBC")) then return end |
511 | - cost = {[ItemId.Diamond] = count * globalCsv.adv_endless_daily_buy_cost} | 512 | + cost = {[ItemId.Jade] = count * globalCsv.adv_endless_daily_buy_cost} |
512 | else | 513 | else |
513 | if math.illegalNum(count, 1, globalCsv.adv_daily_buy_count - role.dailyData:getProperty("advBC")) then return end | 514 | if math.illegalNum(count, 1, globalCsv.adv_daily_buy_count - role.dailyData:getProperty("advBC")) then return end |
514 | - cost = {[ItemId.Diamond] = count * globalCsv.adv_daily_buy_cost} | 515 | + cost = {[ItemId.Jade] = count * globalCsv.adv_daily_buy_cost} |
515 | end | 516 | end |
516 | 517 | ||
517 | 518 | ||
@@ -1029,8 +1030,8 @@ function _M.refreshSupportRpc(agent, data) | @@ -1029,8 +1030,8 @@ function _M.refreshSupportRpc(agent, data) | ||
1029 | if cr < al then --免费 | 1030 | if cr < al then --免费 |
1030 | role.dailyData:updateProperty({field = "advSupRe", delta = 1}) | 1031 | role.dailyData:updateProperty({field = "advSupRe", delta = 1}) |
1031 | else -- 付费 | 1032 | else -- 付费 |
1032 | - if not role:checkItemEnough({[ItemId.Diamond] = globalCsv.adv_support_refresh_cost}) then return end | ||
1033 | - role:costItems({[ItemId.Diamond] = globalCsv.adv_support_refresh_cost}, {log = {desc = "advReSupport"}}) | 1033 | + if not role:checkItemEnough({[ItemId.Jade] = globalCsv.adv_support_refresh_cost}) then return end |
1034 | + role:costItems({[ItemId.Jade] = globalCsv.adv_support_refresh_cost}, {log = {desc = "advReSupport"}}) | ||
1034 | end | 1035 | end |
1035 | 1036 | ||
1036 | role:advRandomSupportEffect() | 1037 | role:advRandomSupportEffect() |
src/actions/CarAction.lua
@@ -13,9 +13,28 @@ function _M.makePotionRpc( agent, data ) | @@ -13,9 +13,28 @@ function _M.makePotionRpc( agent, data ) | ||
13 | local count = msg.count | 13 | local count = msg.count |
14 | if count < 1 then return 0 end | 14 | if count < 1 then return 0 end |
15 | local potionBag = role:getProperty("potionBag") | 15 | local potionBag = role:getProperty("potionBag") |
16 | - local potionLv = role.dinerData:getProperty("dishTree"):getv(potionId, 1) | 16 | + local dishTree = role.dinerData:getProperty("dishTree") |
17 | + local potionLv = dishTree:getv(potionId, 1) | ||
17 | if potionLv < 1 then return 1 end | 18 | if potionLv < 1 then return 1 end |
18 | 19 | ||
20 | + local talentSet = csvdb["diner_talentCsv"][potionId] | ||
21 | + if not talentSet then | ||
22 | + return 10 | ||
23 | + end | ||
24 | + | ||
25 | + local talentData = talentSet[potionLv] | ||
26 | + if not talentData then | ||
27 | + return 11 | ||
28 | + end | ||
29 | + local limit = talentData.pointFront:toNumMap() | ||
30 | + for k,v in pairs(limit) do | ||
31 | + local lv = dishTree:getv(k, 0) | ||
32 | + if lv < v then | ||
33 | + return 12 | ||
34 | + end | ||
35 | + end | ||
36 | + | ||
37 | + | ||
19 | local potionSet = csvdb["adv_potionCsv"][potionId] | 38 | local potionSet = csvdb["adv_potionCsv"][potionId] |
20 | if not potionSet then return 2 end | 39 | if not potionSet then return 2 end |
21 | 40 |
src/actions/DinerAction.lua
@@ -253,7 +253,7 @@ function _M.expediteSellRpc( agent, data ) | @@ -253,7 +253,7 @@ function _M.expediteSellRpc( agent, data ) | ||
253 | end | 253 | end |
254 | local diamond = globalCsv.diner_sell_quick_cost[count] | 254 | local diamond = globalCsv.diner_sell_quick_cost[count] |
255 | if diamond > 0 then | 255 | if diamond > 0 then |
256 | - local cost = {[ItemId.Diamond] = diamond} | 256 | + local cost = {[ItemId.Jade] = diamond} |
257 | if not role:checkItemEnough(cost) then | 257 | if not role:checkItemEnough(cost) then |
258 | return 2 | 258 | return 2 |
259 | end | 259 | end |
@@ -612,7 +612,7 @@ function _M.refreshTaskRpc( agent, data ) | @@ -612,7 +612,7 @@ function _M.refreshTaskRpc( agent, data ) | ||
612 | local role = agent.role | 612 | local role = agent.role |
613 | local msg = MsgPack.unpack(data) | 613 | local msg = MsgPack.unpack(data) |
614 | 614 | ||
615 | - --local cost = {[ItemId.Diamond] = 40} | 615 | + --local cost = {[ItemId.Jade] = 40} |
616 | --if not role:checkItemEnough(cost) then | 616 | --if not role:checkItemEnough(cost) then |
617 | -- return 1 | 617 | -- return 1 |
618 | --end | 618 | --end |
@@ -709,6 +709,20 @@ function _M.addWantFoodRpc(agent , data) | @@ -709,6 +709,20 @@ function _M.addWantFoodRpc(agent , data) | ||
709 | local foodData = csvdb["diner_materialCsv"][itemId] | 709 | local foodData = csvdb["diner_materialCsv"][itemId] |
710 | if not foodData then return 3 end | 710 | if not foodData then return 3 end |
711 | if foodData.unlock ~= 0 then | 711 | if foodData.unlock ~= 0 then |
712 | + -- 遍历adv_potion | ||
713 | + for potionId, _ in pairs(csvdb["adv_potionCsv"]) do | ||
714 | + local potionLv = role.dinerData:getProperty("dishTree"):getv(potionId, 0) | ||
715 | + if potionLv < 1 then return 4 end | ||
716 | + | ||
717 | + local potionSet = csvdb["adv_potionCsv"][potionId] | ||
718 | + if not potionSet then return 5 end | ||
719 | + | ||
720 | + local potionData = potionSet[potionLv] | ||
721 | + if not potionData then return 6 end | ||
722 | + | ||
723 | + local cost = potionData.material:toNumMap() | ||
724 | + if not cost[itemId] then return 7 end | ||
725 | + end | ||
712 | if not role:checkHangPass(foodData.unlock) then | 726 | if not role:checkHangPass(foodData.unlock) then |
713 | return 4 | 727 | return 4 |
714 | end | 728 | end |
src/actions/EmailAction.lua
@@ -3,22 +3,32 @@ local tarr2tab = table.array2Table | @@ -3,22 +3,32 @@ local tarr2tab = table.array2Table | ||
3 | 3 | ||
4 | local function loadEmails(roleId) | 4 | local function loadEmails(roleId) |
5 | local emails = {} | 5 | local emails = {} |
6 | - local rds = string.format(R_EMAIL, roleId) | ||
7 | - local ids = redisproxy:lrange(rds, 0, EMAIL_LIMIT - 1) | ||
8 | - local redret = redisproxy:pipelining(function (red) | ||
9 | - for _, id in ipairs(ids) do | ||
10 | - red:hgetall(string.format("email:%d:%s", roleId, id)) | ||
11 | - end | ||
12 | - end) | ||
13 | - for index, id in ipairs(ids) do | ||
14 | - local email = require("models.Email").new({key = string.format("email:%d:%s", roleId, id)}) | ||
15 | - if email:load(tarr2tab(redret[index])) then | 6 | + local res = mysqlproxy:query(string.format("SELECT * FROM `Email` WHERE `roleId` = %s", roleId)) |
7 | + for _, data in ipairs(res) do | ||
8 | + local email = require("models.Email").new({key = string.format("%d",data.id), id=data.id}) | ||
9 | + if email:load(data) then | ||
16 | table.insert(emails, email) | 10 | table.insert(emails, email) |
17 | end | 11 | end |
18 | end | 12 | end |
19 | return emails | 13 | return emails |
20 | end | 14 | end |
21 | 15 | ||
16 | +local function delExpireEmails(roleId) | ||
17 | + local sql = [[ | ||
18 | + DELETE FROM Email | ||
19 | + WHERE id IN ( | ||
20 | + SELECT id FROM ( | ||
21 | + SELECT id | ||
22 | + FROM Email WHERE roleId=%s | ||
23 | + ORDER BY createtime DESC, id desc | ||
24 | + LIMIT %s, 100000 | ||
25 | + ) a | ||
26 | + ); | ||
27 | + ]] | ||
28 | + sql = string.format(sql, roleId, EMAIL_LIMIT) | ||
29 | + mysqlproxy:query(sql) | ||
30 | +end | ||
31 | + | ||
22 | function _M.listRpc(agent, data) | 32 | function _M.listRpc(agent, data) |
23 | local role = agent.role | 33 | local role = agent.role |
24 | local roleId = role:getProperty("id") | 34 | local roleId = role:getProperty("id") |
@@ -51,7 +61,7 @@ function _M.listRpc(agent, data) | @@ -51,7 +61,7 @@ function _M.listRpc(agent, data) | ||
51 | if flag and ( not email.mid or tonum(email.mid) == mid ) | 61 | if flag and ( not email.mid or tonum(email.mid) == mid ) |
52 | and ( not email.endtime or tonum(email.endtime) > now )then | 62 | and ( not email.endtime or tonum(email.endtime) > now )then |
53 | local time = math.max(tonum(email.timestamp, 0) , tonum(email.createtime)) | 63 | local time = math.max(tonum(email.timestamp, 0) , tonum(email.createtime)) |
54 | - redisproxy:insertEmail({ | 64 | + mysqlproxy:insertEmail({ |
55 | roleId = roleId, | 65 | roleId = roleId, |
56 | emailId = 0, | 66 | emailId = 0, |
57 | createtime = time, | 67 | createtime = time, |
@@ -64,6 +74,7 @@ function _M.listRpc(agent, data) | @@ -64,6 +74,7 @@ function _M.listRpc(agent, data) | ||
64 | end | 74 | end |
65 | end | 75 | end |
66 | end | 76 | end |
77 | + delExpireEmails(roleId) | ||
67 | 78 | ||
68 | local emails = loadEmails(roleId) | 79 | local emails = loadEmails(roleId) |
69 | for _, email in ipairs(emails) do | 80 | for _, email in ipairs(emails) do |
@@ -100,7 +111,7 @@ function _M.drawAllAttachRpc(agent, data) | @@ -100,7 +111,7 @@ function _M.drawAllAttachRpc(agent, data) | ||
100 | for _, email in ipairs(emails) do | 111 | for _, email in ipairs(emails) do |
101 | local attachments = getEmailAttachments(email) | 112 | local attachments = getEmailAttachments(email) |
102 | if attachments ~= "" then | 113 | if attachments ~= "" then |
103 | - email:setProperty("status", 2) | 114 | + email:setProperty("status", 2, true) |
104 | email:log(role, 2) | 115 | email:log(role, 2) |
105 | ids[email:getProperty("id")] = 1 | 116 | ids[email:getProperty("id")] = 1 |
106 | for key, v in pairs(attachments:toNumMap()) do | 117 | for key, v in pairs(attachments:toNumMap()) do |
@@ -120,16 +131,15 @@ function _M.drawAttachRpc(agent, data) | @@ -120,16 +131,15 @@ function _M.drawAttachRpc(agent, data) | ||
120 | local msg = MsgPack.unpack(data) | 131 | local msg = MsgPack.unpack(data) |
121 | local id = msg.id | 132 | local id = msg.id |
122 | 133 | ||
123 | - local rds = string.format(R_EMAIL_ITEM, roleId, id) | ||
124 | 134 | ||
125 | - local email = require("models.Email").new({key = rds}) | 135 | + local email = require("models.Email").new({key = string.format("%d", id), id = id}) |
126 | if not email:load() then return end | 136 | if not email:load() then return end |
127 | 137 | ||
128 | local attachments = getEmailAttachments(email) | 138 | local attachments = getEmailAttachments(email) |
129 | if attachments == "" then return end | 139 | if attachments == "" then return end |
130 | 140 | ||
131 | local reward, change = role:award(attachments, {log = {desc = "draw_attach", int1 = id}}) | 141 | local reward, change = role:award(attachments, {log = {desc = "draw_attach", int1 = id}}) |
132 | - email:setProperty("status", 2) | 142 | + email:setProperty("status", 2, true) |
133 | email:log(role, 2) | 143 | email:log(role, 2) |
134 | SendPacket(actionCodes.Email_drawAttachRpc, MsgPack.pack({reward = reward, change = change})) | 144 | SendPacket(actionCodes.Email_drawAttachRpc, MsgPack.pack({reward = reward, change = change})) |
135 | role:mylog("mail_action", {desc = "draw_attach", int1 = id, key1 = email:getProperty("title"), key2 = attachments}) | 145 | role:mylog("mail_action", {desc = "draw_attach", int1 = id, key1 = email:getProperty("title"), key2 = attachments}) |
@@ -143,11 +153,10 @@ function _M.checkRpc(agent, data) | @@ -143,11 +153,10 @@ function _M.checkRpc(agent, data) | ||
143 | local msg = MsgPack.unpack(data) | 153 | local msg = MsgPack.unpack(data) |
144 | local id = msg.id | 154 | local id = msg.id |
145 | 155 | ||
146 | - local emailRds = string.format("email:%d:%s", roleId, id) | ||
147 | - local email = require("models.Email").new({key = emailRds}) | 156 | + local email = require("models.Email").new({key = string.format("%d", id), id = id}) |
148 | if not email:load() then return end | 157 | if not email:load() then return end |
149 | 158 | ||
150 | - email:setProperty("status", 1) | 159 | + email:setProperty("status", 1, true) |
151 | email:log(role, 1) | 160 | email:log(role, 1) |
152 | role:mylog("mail_action", {desc = "check_mail", int1 = id}) | 161 | role:mylog("mail_action", {desc = "check_mail", int1 = id}) |
153 | 162 | ||
@@ -158,33 +167,21 @@ end | @@ -158,33 +167,21 @@ end | ||
158 | function _M.delRpc(agent, data) | 167 | function _M.delRpc(agent, data) |
159 | local role = agent.role | 168 | local role = agent.role |
160 | local roleId = role:getProperty("id") | 169 | local roleId = role:getProperty("id") |
161 | - | ||
162 | - local rds = string.format(R_EMAIL, roleId) | ||
163 | - local ids = redisproxy:lrange(rds, 0, EMAIL_LIMIT - 1) | ||
164 | - local now = skynet.timex() | ||
165 | local result = {} | 170 | local result = {} |
166 | - local emailSet = csvdb["emailCsv"] | ||
167 | - | ||
168 | - redisproxy:pipelining(function (red) | ||
169 | - for _, id in ipairs(ids) do | ||
170 | - local emailRds = string.format("email:%d:%s", roleId, id) | ||
171 | - local email = require("models.Email").new({key = emailRds}) | ||
172 | - if email:load() then | ||
173 | - local status = email:getProperty("status") | ||
174 | - local attachments = email:getProperty("attachments") | ||
175 | - local emailData = emailSet[email:getProperty("emailId")] | ||
176 | - if emailData and attachments:len() == 0 then | ||
177 | - attachments = emailData.attachment | ||
178 | - end | ||
179 | - if status == 2 or (status == 1 and attachments:len() == 0) then | ||
180 | - email:log(role, 3) | ||
181 | - red:lrem(rds, 0, id) | ||
182 | - red:del(emailRds) | ||
183 | - result[tonum(id)] = 1 | ||
184 | - end | ||
185 | - end | 171 | + local tmp = {} |
172 | + local emails = loadEmails(roleId) | ||
173 | + for _, email in ipairs(emails) do | ||
174 | + local attachments = getEmailAttachments(email) | ||
175 | + | ||
176 | + if email:getProperty("status") == 2 or (attachments == "" and email:getProperty("status") == 1) then | ||
177 | + result[email:getProperty("id")] = 1 | ||
178 | + email:log(role, 3) | ||
179 | + table.insert(tmp, email:getProperty("id")) | ||
186 | end | 180 | end |
187 | - end) | 181 | + end |
182 | + | ||
183 | + mysqlproxy:query(string.format("DELETE FROM `Email` WHERE `id` in (%s)", table.concat(tmp, ","))) | ||
184 | + | ||
188 | for delId, _ in ipairs(result) do | 185 | for delId, _ in ipairs(result) do |
189 | role:mylog("mail_action", {desc = "del_mail", int1 = delId}) | 186 | role:mylog("mail_action", {desc = "del_mail", int1 = delId}) |
190 | end | 187 | end |
src/actions/FriendAction.lua
@@ -11,6 +11,7 @@ local table_unpack = table.unpack | @@ -11,6 +11,7 @@ local table_unpack = table.unpack | ||
11 | local table_find = table.find | 11 | local table_find = table.find |
12 | local table_nums = table.nums | 12 | local table_nums = table.nums |
13 | local math_random = math.randomInt | 13 | local math_random = math.randomInt |
14 | +require "utils.MysqlUtil" | ||
14 | 15 | ||
15 | local _M = {} | 16 | local _M = {} |
16 | 17 | ||
@@ -23,12 +24,6 @@ local function formatArray(tb) | @@ -23,12 +24,6 @@ local function formatArray(tb) | ||
23 | return t | 24 | return t |
24 | end | 25 | end |
25 | 26 | ||
26 | -local function checkFriendLimit(roleId) | ||
27 | - roleId = tonumber(roleId) | ||
28 | - local count = redisproxy:hlen(FRIEND_KEY:format(roleId)) | ||
29 | - return count < globalCsv.friendListLimit | ||
30 | -end | ||
31 | - | ||
32 | 27 | ||
33 | local function addAndCheckApplyLimit(roleId, objId) | 28 | local function addAndCheckApplyLimit(roleId, objId) |
34 | roleId = tonumber(roleId) | 29 | roleId = tonumber(roleId) |
@@ -78,7 +73,7 @@ function _M.searchRpc(agent, data) | @@ -78,7 +73,7 @@ function _M.searchRpc(agent, data) | ||
78 | local objIds = {} | 73 | local objIds = {} |
79 | local tempId = tonumber(key) | 74 | local tempId = tonumber(key) |
80 | if tempId then | 75 | if tempId then |
81 | - if redisproxy:exists(string_format("role:%d", tempId)) then | 76 | + if roleExists(tempId) then |
82 | objIds[tempId] = 1 | 77 | objIds[tempId] = 1 |
83 | end | 78 | end |
84 | end | 79 | end |
@@ -92,13 +87,13 @@ function _M.searchRpc(agent, data) | @@ -92,13 +87,13 @@ function _M.searchRpc(agent, data) | ||
92 | for objId, _ in pairs(objIds) do | 87 | for objId, _ in pairs(objIds) do |
93 | local online, info = getRoleInfo(objId) | 88 | local online, info = getRoleInfo(objId) |
94 | local redret = redisproxy:pipelining(function (red) | 89 | local redret = redisproxy:pipelining(function (red) |
95 | - red:hexists(FRIEND_KEY:format(roleId), objId) | ||
96 | red:zscore(FRIEND_APPLY_KEY:format(objId), roleId) | 90 | red:zscore(FRIEND_APPLY_KEY:format(objId), roleId) |
97 | red:sismember(FRIEND_BLACK_KEY:format(roleId), objId) | 91 | red:sismember(FRIEND_BLACK_KEY:format(roleId), objId) |
98 | end) | 92 | end) |
99 | - local isFriend = redret[1] == 1 and 1 or nil | ||
100 | - local hadApply = redret[2] and 1 or nil | ||
101 | - local inBlack = redret[3] == 1 and 1 or nil | 93 | + |
94 | + local isFriend = role.friends[objId] and 1 or nil | ||
95 | + local hadApply = redret[1] and 1 or nil | ||
96 | + local inBlack = redret[2] == 1 and 1 or nil | ||
102 | 97 | ||
103 | table.insert(searchList, table_merge({ | 98 | table.insert(searchList, table_merge({ |
104 | roleId = objId, | 99 | roleId = objId, |
@@ -123,6 +118,7 @@ function _M.applyRpc(agent, data) | @@ -123,6 +118,7 @@ function _M.applyRpc(agent, data) | ||
123 | 118 | ||
124 | local msg = MsgPack.unpack(data) | 119 | local msg = MsgPack.unpack(data) |
125 | local objectId = msg.roleId | 120 | local objectId = msg.roleId |
121 | + dump(msg) | ||
126 | 122 | ||
127 | if objectId == roleId then | 123 | if objectId == roleId then |
128 | return | 124 | return |
@@ -130,44 +126,41 @@ function _M.applyRpc(agent, data) | @@ -130,44 +126,41 @@ function _M.applyRpc(agent, data) | ||
130 | 126 | ||
131 | local result = nil | 127 | local result = nil |
132 | local redret = redisproxy:pipelining(function (red) | 128 | local redret = redisproxy:pipelining(function (red) |
133 | - red:exists(string_format("role:%d", objectId)) | ||
134 | - red:hexists(FRIEND_KEY:format(roleId), objectId) | ||
135 | red:zscore(FRIEND_APPLY_KEY:format(objectId), roleId) | 129 | red:zscore(FRIEND_APPLY_KEY:format(objectId), roleId) |
136 | red:sismember(FRIEND_BLACK_KEY:format(objectId), roleId) | 130 | red:sismember(FRIEND_BLACK_KEY:format(objectId), roleId) |
137 | red:sismember(FRIEND_BLACK_KEY:format(roleId), objectId) | 131 | red:sismember(FRIEND_BLACK_KEY:format(roleId), objectId) |
138 | - red:hlen(FRIEND_KEY:format(roleId)) | ||
139 | - red:hlen(FRIEND_KEY:format(objectId)) | ||
140 | end) | 132 | end) |
133 | + dump(redret) | ||
141 | 134 | ||
142 | -- 玩家id不存在 | 135 | -- 玩家id不存在 |
143 | - if not result and redret[1] ~= 1 then | 136 | + if not result and not roleExists(objectId) then |
144 | result = 1 | 137 | result = 1 |
145 | end | 138 | end |
146 | 139 | ||
147 | -- 已经有这个好友 | 140 | -- 已经有这个好友 |
148 | - if not result and redret[2] == 1 then | 141 | + if not result and role.friends[objectId] then |
149 | result = 2 | 142 | result = 2 |
150 | end | 143 | end |
151 | -- 已经申请 | 144 | -- 已经申请 |
152 | - if not result and redret[3] then | 145 | + if not result and redret[1] then |
153 | result = 3 | 146 | result = 3 |
154 | end | 147 | end |
155 | -- 对方把你拉黑 | 148 | -- 对方把你拉黑 |
156 | - if not result and redret[4] == 1 then | 149 | + if not result and redret[2] == 1 then |
157 | result = 4 | 150 | result = 4 |
158 | end | 151 | end |
159 | 152 | ||
160 | -- 你把对方拉黑了 | 153 | -- 你把对方拉黑了 |
161 | - if not result and redret[5] == 1 then | 154 | + if not result and redret[3] == 1 then |
162 | result = 5 | 155 | result = 5 |
163 | end | 156 | end |
164 | 157 | ||
165 | -- 自己好友已经满 | 158 | -- 自己好友已经满 |
166 | - if not result and redret[6] >= globalCsv.friendListLimit then | 159 | + if not result and table.numbers(role.friends) >= globalCsv.friendListLimit then |
167 | result = 6 | 160 | result = 6 |
168 | end | 161 | end |
169 | -- 对方的好友已满 | 162 | -- 对方的好友已满 |
170 | - if not result and redret[7] >= globalCsv.friendListLimit then | 163 | + if not result and getFriendCount(objectId) >= globalCsv.friendListLimit then |
171 | result = 7 | 164 | result = 7 |
172 | end | 165 | end |
173 | 166 | ||
@@ -209,29 +202,28 @@ function _M.applyListRpc(agent, data) | @@ -209,29 +202,28 @@ function _M.applyListRpc(agent, data) | ||
209 | return true | 202 | return true |
210 | end | 203 | end |
211 | 204 | ||
212 | -local function checkHandleApply(roleId, objectId, needAddNew) | 205 | +local function checkHandleApply(role, objectId, needAddNew) |
213 | needAddNew = needAddNew or 0 | 206 | needAddNew = needAddNew or 0 |
207 | + local roleId = role:getProperty("id") | ||
214 | local redret = redisproxy:pipelining(function (red) | 208 | local redret = redisproxy:pipelining(function (red) |
215 | - red:hlen(FRIEND_KEY:format(roleId)) | ||
216 | - red:hlen(FRIEND_KEY:format(objectId)) | ||
217 | red:sismember(FRIEND_BLACK_KEY:format(objectId), roleId) | 209 | red:sismember(FRIEND_BLACK_KEY:format(objectId), roleId) |
218 | red:sismember(FRIEND_BLACK_KEY:format(roleId), objectId) | 210 | red:sismember(FRIEND_BLACK_KEY:format(roleId), objectId) |
219 | end) | 211 | end) |
220 | 212 | ||
221 | --自己好友满了 | 213 | --自己好友满了 |
222 | - if (redret[1] + needAddNew) >= globalCsv.friendListLimit then | 214 | + if (table.numbers(role.friends) + needAddNew) >= globalCsv.friendListLimit then |
223 | return 1 | 215 | return 1 |
224 | end | 216 | end |
225 | -- 对方好友满了 | 217 | -- 对方好友满了 |
226 | - if redret[2] >= globalCsv.friendListLimit then | 218 | + if getFriendCount(objectId) >= globalCsv.friendListLimit then |
227 | return 2 | 219 | return 2 |
228 | end | 220 | end |
229 | -- 对方把你拉黑 | 221 | -- 对方把你拉黑 |
230 | - if redret[3] == 1 then | 222 | + if redret[1] == 1 then |
231 | return 3 | 223 | return 3 |
232 | end | 224 | end |
233 | -- 你把对方拉黑了 | 225 | -- 你把对方拉黑了 |
234 | - if redret[4] == 1 then | 226 | + if redret[2] == 1 then |
235 | return 4 | 227 | return 4 |
236 | end | 228 | end |
237 | 229 | ||
@@ -255,14 +247,13 @@ function _M.handleApplyRpc(agent, data) | @@ -255,14 +247,13 @@ function _M.handleApplyRpc(agent, data) | ||
255 | return | 247 | return |
256 | end | 248 | end |
257 | local curCount | 249 | local curCount |
258 | - result, curCount = checkHandleApply(roleId, objectId) | 250 | + result, curCount = checkHandleApply(role, objectId) |
259 | 251 | ||
260 | if not result then | 252 | if not result then |
261 | redisproxy:pipelining(function (red) | 253 | redisproxy:pipelining(function (red) |
262 | red:ZREM(FRIEND_APPLY_KEY:format(roleId), objectId) | 254 | red:ZREM(FRIEND_APPLY_KEY:format(roleId), objectId) |
263 | red:ZREM(FRIEND_APPLY_KEY:format(objectId), roleId) | 255 | red:ZREM(FRIEND_APPLY_KEY:format(objectId), roleId) |
264 | - red:hsetnx(FRIEND_KEY:format(roleId), objectId, newTag) | ||
265 | - red:hsetnx(FRIEND_KEY:format(objectId), roleId, newTag)--告知对放有新好友 | 256 | + addFriend(roleId, objectId) |
266 | end) | 257 | end) |
267 | local myInfo = role:friendSInfo() | 258 | local myInfo = role:friendSInfo() |
268 | myInfo.online = true | 259 | myInfo.online = true |
@@ -310,7 +301,7 @@ function _M.handleApplyRpc(agent, data) | @@ -310,7 +301,7 @@ function _M.handleApplyRpc(agent, data) | ||
310 | local needAddInfo = {} | 301 | local needAddInfo = {} |
311 | for _, objId in ipairs(allIds) do | 302 | for _, objId in ipairs(allIds) do |
312 | objId = tonumber(objId) | 303 | objId = tonumber(objId) |
313 | - local cr, curCount = checkHandleApply(roleId, objId, #needAdd) | 304 | + local cr, curCount = checkHandleApply(role, objId, #needAdd) |
314 | if not cr then | 305 | if not cr then |
315 | table.insert(needAdd, objId) | 306 | table.insert(needAdd, objId) |
316 | table.insert(needAddMy, objId) | 307 | table.insert(needAddMy, objId) |
@@ -335,12 +326,9 @@ function _M.handleApplyRpc(agent, data) | @@ -335,12 +326,9 @@ function _M.handleApplyRpc(agent, data) | ||
335 | red:ZREM(FRIEND_APPLY_KEY:format(roleId), table_unpack(needAdd)) | 326 | red:ZREM(FRIEND_APPLY_KEY:format(roleId), table_unpack(needAdd)) |
336 | for _, objectId in pairs(needAdd) do | 327 | for _, objectId in pairs(needAdd) do |
337 | red:ZREM(FRIEND_APPLY_KEY:format(objectId), roleId) | 328 | red:ZREM(FRIEND_APPLY_KEY:format(objectId), roleId) |
338 | - red:hsetnx(FRIEND_KEY:format(objectId), roleId, newTag)--告知对放有新好友 | 329 | + addFriend(roleId, objectId) |
339 | end | 330 | end |
340 | end | 331 | end |
341 | - if next(needAddMy) then | ||
342 | - red:HMSET(FRIEND_KEY:format(roleId), table_unpack(needAddMy)) | ||
343 | - end | ||
344 | end) | 332 | end) |
345 | local myInfo = role:friendSInfo() | 333 | local myInfo = role:friendSInfo() |
346 | myInfo.roleId = roleId | 334 | myInfo.roleId = roleId |
@@ -373,27 +361,21 @@ function _M.listRpc(agent, data) | @@ -373,27 +361,21 @@ function _M.listRpc(agent, data) | ||
373 | 361 | ||
374 | local friendList = {} | 362 | local friendList = {} |
375 | local redret = redisproxy:pipelining(function (red) | 363 | local redret = redisproxy:pipelining(function (red) |
376 | - red:hgetall(FRIEND_KEY:format(roleId)) | ||
377 | red:SMEMBERS(FRIEND_POINT:format(roleId)) | 364 | red:SMEMBERS(FRIEND_POINT:format(roleId)) |
378 | end) | 365 | end) |
379 | 366 | ||
380 | - local friends = redret[1] | ||
381 | - local fpoint = formatArray(redret[2]) | 367 | + local fpoint = formatArray(redret[1]) |
382 | local hadGet = role.dailyData:getProperty("getFP") | 368 | local hadGet = role.dailyData:getProperty("getFP") |
383 | local hadGive = role.dailyData:getProperty("giveFP") | 369 | local hadGive = role.dailyData:getProperty("giveFP") |
384 | 370 | ||
385 | - local clearRed = {} | ||
386 | - for i = 1, #friends, 2 do | ||
387 | - local id = friends[i] | ||
388 | - local data = friends[i + 1] | ||
389 | - local friendInfo = MsgPack.unpack(data) | ||
390 | - id = tonumber(id) | 371 | + local addNew = false |
372 | + for id, friend in pairs(role.friends) do | ||
391 | local online, info = getRoleInfo(id) | 373 | local online, info = getRoleInfo(id) |
392 | local roleInfo = { | 374 | local roleInfo = { |
393 | roleId = id, | 375 | roleId = id, |
394 | online = online, | 376 | online = online, |
395 | - addTime = friendInfo[1], | ||
396 | - isNew = friendInfo[2], | 377 | + addTime = friend:getProperty("addTime"), |
378 | + isNew = friend:getProperty("isNew"), | ||
397 | pGive = hadGive[id], | 379 | pGive = hadGive[id], |
398 | pGet = hadGet[id] and -1 or (fpoint[id] and 1 or nil) | 380 | pGet = hadGet[id] and -1 or (fpoint[id] and 1 or nil) |
399 | } | 381 | } |
@@ -401,14 +383,12 @@ function _M.listRpc(agent, data) | @@ -401,14 +383,12 @@ function _M.listRpc(agent, data) | ||
401 | 383 | ||
402 | friendList[#friendList + 1] = roleInfo | 384 | friendList[#friendList + 1] = roleInfo |
403 | 385 | ||
404 | - if friendInfo[2] then | ||
405 | - friendInfo[2] = nil --清除新好友标记 | ||
406 | - clearRed[#clearRed + 1] = id | ||
407 | - clearRed[#clearRed + 1] = MsgPack.pack(friendInfo) | 386 | + if roleInfo.isNew then |
387 | + friend:setProperty("isNew", 0) | ||
388 | + addNew = true | ||
408 | end | 389 | end |
409 | end | 390 | end |
410 | - if next(clearRed) then | ||
411 | - redisproxy:hmset(FRIEND_KEY:format(roleId), table_unpack(clearRed)) --清除新好友标记 | 391 | + if addNew then |
412 | role:checkTaskEnter("AddFriend", {count = #friendList}) | 392 | role:checkTaskEnter("AddFriend", {count = #friendList}) |
413 | end | 393 | end |
414 | 394 | ||
@@ -421,14 +401,14 @@ function _M.deleteRpc(agent, data) | @@ -421,14 +401,14 @@ function _M.deleteRpc(agent, data) | ||
421 | local roleId = role:getProperty("id") | 401 | local roleId = role:getProperty("id") |
422 | local msg = MsgPack.unpack(data) | 402 | local msg = MsgPack.unpack(data) |
423 | local objectId = msg.roleId | 403 | local objectId = msg.roleId |
424 | - if not redisproxy:exists(string_format("role:%d", objectId)) then | 404 | + if not roleExists(objectId) then |
425 | return | 405 | return |
426 | end | 406 | end |
427 | -- 是否在好友列表中 | 407 | -- 是否在好友列表中 |
428 | - if redisproxy:hexists(FRIEND_KEY:format(roleId), objectId) then | 408 | + if role.friends[objectId] then |
409 | + role.friends[objectId] = nil | ||
429 | redisproxy:pipelining(function (red) | 410 | redisproxy:pipelining(function (red) |
430 | - red:hdel(FRIEND_KEY:format(roleId), objectId) | ||
431 | - red:hdel(FRIEND_KEY:format(objectId), roleId) | 411 | + delFriend(roleId, objectId) |
432 | red:ZREM(FRIEND_APPLY_KEY:format(roleId), objectId) | 412 | red:ZREM(FRIEND_APPLY_KEY:format(roleId), objectId) |
433 | red:ZREM(FRIEND_APPLY_KEY:format(objectId), roleId) | 413 | red:ZREM(FRIEND_APPLY_KEY:format(objectId), roleId) |
434 | end) | 414 | end) |
@@ -450,7 +430,7 @@ function _M.blockRpc(agent, data) | @@ -450,7 +430,7 @@ function _M.blockRpc(agent, data) | ||
450 | local msg = MsgPack.unpack(data) | 430 | local msg = MsgPack.unpack(data) |
451 | local cmd = msg.cmd | 431 | local cmd = msg.cmd |
452 | local objectId = msg.roleId | 432 | local objectId = msg.roleId |
453 | - if not redisproxy:exists(string_format("role:%d", objectId)) then | 433 | + if not roleExists(objectId) then |
454 | return | 434 | return |
455 | end | 435 | end |
456 | 436 | ||
@@ -463,8 +443,7 @@ function _M.blockRpc(agent, data) | @@ -463,8 +443,7 @@ function _M.blockRpc(agent, data) | ||
463 | -- 删除好友 | 443 | -- 删除好友 |
464 | if not result then | 444 | if not result then |
465 | redisproxy:pipelining(function (red) | 445 | redisproxy:pipelining(function (red) |
466 | - red:hdel(FRIEND_KEY:format(roleId), objectId) | ||
467 | - red:hdel(FRIEND_KEY:format(objectId), roleId) | 446 | + delFriend(roleId, objectId) |
468 | red:ZREM(FRIEND_APPLY_KEY:format(roleId), objectId) | 447 | red:ZREM(FRIEND_APPLY_KEY:format(roleId), objectId) |
469 | red:ZREM(FRIEND_APPLY_KEY:format(objectId), roleId) | 448 | red:ZREM(FRIEND_APPLY_KEY:format(objectId), roleId) |
470 | red:sadd(FRIEND_BLACK_KEY:format(roleId), objectId) | 449 | red:sadd(FRIEND_BLACK_KEY:format(roleId), objectId) |
@@ -511,19 +490,19 @@ function _M.infoRpc(agent, data) | @@ -511,19 +490,19 @@ function _M.infoRpc(agent, data) | ||
511 | local roleId = role:getProperty("id") | 490 | local roleId = role:getProperty("id") |
512 | local msg = MsgPack.unpack(data) | 491 | local msg = MsgPack.unpack(data) |
513 | local objectId = msg.roleId | 492 | local objectId = msg.roleId |
514 | - if not redisproxy:exists(string_format("role:%d", objectId)) then | 493 | + |
494 | + if not roleExists(objectId) then | ||
515 | return | 495 | return |
516 | end | 496 | end |
517 | 497 | ||
518 | local online, info = getRoleAllInfo(objectId) | 498 | local online, info = getRoleAllInfo(objectId) |
519 | local redret = redisproxy:pipelining(function (red) | 499 | local redret = redisproxy:pipelining(function (red) |
520 | - red:hexists(FRIEND_KEY:format(roleId), objectId) | ||
521 | red:zscore(FRIEND_APPLY_KEY:format(objectId), roleId) | 500 | red:zscore(FRIEND_APPLY_KEY:format(objectId), roleId) |
522 | red:sismember(FRIEND_BLACK_KEY:format(roleId), objectId) | 501 | red:sismember(FRIEND_BLACK_KEY:format(roleId), objectId) |
523 | end) | 502 | end) |
524 | - local isFriend = redret[1] == 1 and 1 or nil | ||
525 | - local hadApply = redret[2] == 1 and 1 or nil | ||
526 | - local inBlack = redret[3] == 1 and 1 or nil | 503 | + local isFriend = role.friends[objectId] and 1 or nil |
504 | + local hadApply = redret[1] == 1 and 1 or nil | ||
505 | + local inBlack = redret[2] == 1 and 1 or nil | ||
527 | 506 | ||
528 | local objInfo = table_merge({ | 507 | local objInfo = table_merge({ |
529 | roleId = objectId, | 508 | roleId = objectId, |
@@ -551,7 +530,7 @@ function _M.pointRpc(agent, data) | @@ -551,7 +530,7 @@ function _M.pointRpc(agent, data) | ||
551 | if not result and giveP[objId] then | 530 | if not result and giveP[objId] then |
552 | result = 1 | 531 | result = 1 |
553 | end | 532 | end |
554 | - if not result and not redisproxy:hexists(FRIEND_KEY:format(roleId), objId) then | 533 | + if not result and not role.friends[objId] then |
555 | result = 2 | 534 | result = 2 |
556 | end | 535 | end |
557 | if not result then | 536 | if not result then |
@@ -586,11 +565,9 @@ function _M.pointRpc(agent, data) | @@ -586,11 +565,9 @@ function _M.pointRpc(agent, data) | ||
586 | elseif cmd == 3 then -- 一键赠送领取 | 565 | elseif cmd == 3 then -- 一键赠送领取 |
587 | -- 赠送 | 566 | -- 赠送 |
588 | local giveP = role.dailyData:getProperty("giveFP") | 567 | local giveP = role.dailyData:getProperty("giveFP") |
589 | - local friends = redisproxy:hgetall(FRIEND_KEY:format(roleId)) | ||
590 | local change = 0 | 568 | local change = 0 |
591 | redisproxy:pipelining(function(red) | 569 | redisproxy:pipelining(function(red) |
592 | - for i = 1, #friends , 2 do | ||
593 | - local objId = tonumber(friends[i]) | 570 | + for objId, friend in pairs(role.friends) do |
594 | if not giveP[objId] then | 571 | if not giveP[objId] then |
595 | giveP[objId] = 1 | 572 | giveP[objId] = 1 |
596 | change = change + 1 | 573 | change = change + 1 |
@@ -645,22 +622,17 @@ function _M.randomRpc(agent, data) | @@ -645,22 +622,17 @@ function _M.randomRpc(agent, data) | ||
645 | local roleId = role:getProperty("id") | 622 | local roleId = role:getProperty("id") |
646 | 623 | ||
647 | local redret = redisproxy:pipelining(function (red) | 624 | local redret = redisproxy:pipelining(function (red) |
648 | - red:hgetall(FRIEND_KEY:format(roleId)) | ||
649 | red:zrevrange(FRIEND_RECOMMEND, 0, globalCsv.friendRecommendLimit + globalCsv.friendListLimit + 10) --扩充10个 | 625 | red:zrevrange(FRIEND_RECOMMEND, 0, globalCsv.friendRecommendLimit + globalCsv.friendListLimit + 10) --扩充10个 |
650 | red:SMEMBERS(FRIEND_BLACK_KEY:format(roleId)) | 626 | red:SMEMBERS(FRIEND_BLACK_KEY:format(roleId)) |
651 | end) | 627 | end) |
652 | - local friends = {} | ||
653 | - for i = 1, #redret[1], 2 do | ||
654 | - friends[tonumber(redret[1][i])] = redret[1][i + 1] | ||
655 | - end | ||
656 | 628 | ||
657 | - local newList = redret[2] | ||
658 | - local hadBlack = formatArray(redret[3]) | 629 | + local newList = redret[1] |
630 | + local hadBlack = formatArray(redret[2]) | ||
659 | 631 | ||
660 | local needRoleIds = {} | 632 | local needRoleIds = {} |
661 | for _, newId in pairs(newList) do | 633 | for _, newId in pairs(newList) do |
662 | local numNewId = tonumber(newId) | 634 | local numNewId = tonumber(newId) |
663 | - if numNewId ~= roleId and not friends[numNewId] and not hadBlack[numNewId] then | 635 | + if numNewId ~= roleId and not role.friends[numNewId] and not hadBlack[numNewId] then |
664 | table.insert(needRoleIds, numNewId) | 636 | table.insert(needRoleIds, numNewId) |
665 | end | 637 | end |
666 | end | 638 | end |
src/actions/GmAction.lua
@@ -519,7 +519,7 @@ table.insert(helpDes, {"发送邮件", "email", "id", "奖励"}) | @@ -519,7 +519,7 @@ table.insert(helpDes, {"发送邮件", "email", "id", "奖励"}) | ||
519 | function _M.email(role, pms) | 519 | function _M.email(role, pms) |
520 | local id = tonum(pms.pm1, 0) | 520 | local id = tonum(pms.pm1, 0) |
521 | local reward = pms.pm2 | 521 | local reward = pms.pm2 |
522 | - redisproxy:insertEmail({ | 522 | + mysqlproxy:insertEmail({ |
523 | roleId = role:getProperty("id"), | 523 | roleId = role:getProperty("id"), |
524 | emailId = id, | 524 | emailId = id, |
525 | createtime = skynet.timex(), | 525 | createtime = skynet.timex(), |
src/actions/HangAction.lua
@@ -22,7 +22,8 @@ local function checkReward(role) | @@ -22,7 +22,8 @@ local function checkReward(role) | ||
22 | return false | 22 | return false |
23 | end | 23 | end |
24 | local carbonData = csvdb["idle_battleCsv"][hangInfo.carbonId] | 24 | local carbonData = csvdb["idle_battleCsv"][hangInfo.carbonId] |
25 | - local expCarbonData = csvdb["idle_battleCsv"][hangInfo.expCarbonId] | 25 | + --local expCarbonData = csvdb["idle_battleCsv"][hangInfo.expCarbonId] |
26 | + local expCarbonData = hangInfo.expData or {} | ||
26 | local nowCoinTime = math.min(skynet.timex(), hangInfo.endCoinTime or 0) | 27 | local nowCoinTime = math.min(skynet.timex(), hangInfo.endCoinTime or 0) |
27 | local nowItemTime = math.min(skynet.timex(), hangInfo.endItemTime or 0) | 28 | local nowItemTime = math.min(skynet.timex(), hangInfo.endItemTime or 0) |
28 | 29 | ||
@@ -42,9 +43,9 @@ local function checkReward(role) | @@ -42,9 +43,9 @@ local function checkReward(role) | ||
42 | 43 | ||
43 | local items = role:getProperty("hangBag") | 44 | local items = role:getProperty("hangBag") |
44 | coinCount = (coinCount + coinDoubleCount) * expCoef | 45 | coinCount = (coinCount + coinDoubleCount) * expCoef |
45 | - items[ItemId.Gold] = math.floor((items[ItemId.Gold] or 0) + coinCount * expCarbonData.money) | ||
46 | - items[ItemId.Exp] = math.floor((items[ItemId.Exp] or 0) + coinCount * expCarbonData.exp) | ||
47 | - items[ItemId.PlayerExp] = math.floor((items[ItemId.PlayerExp] or 0) + coinCount * expCarbonData.playerExp) | 46 | + items[ItemId.Gold] = math.floor((items[ItemId.Gold] or 0) + coinCount * (expCarbonData.money or 0)) |
47 | + items[ItemId.Exp] = math.floor((items[ItemId.Exp] or 0) + coinCount * (expCarbonData.exp or 0)) | ||
48 | + items[ItemId.PlayerExp] = math.floor((items[ItemId.PlayerExp] or 0) + (coinCount * expCarbonData.playerExp or 0)) | ||
48 | 49 | ||
49 | local pool = {} | 50 | local pool = {} |
50 | for _, temp in pairs(carbonData.item:toArray()) do | 51 | for _, temp in pairs(carbonData.item:toArray()) do |
@@ -137,6 +138,15 @@ function _M.startRpc( agent, data ) | @@ -137,6 +138,15 @@ function _M.startRpc( agent, data ) | ||
137 | if not role:checkHangPass(preCarbonId) then return 2 end | 138 | if not role:checkHangPass(preCarbonId) then return 2 end |
138 | end | 139 | end |
139 | 140 | ||
141 | + local carbonId = msg.carbonId -- 解锁章节id | ||
142 | + local condition = globalCsv.idle_chapter_unlock[carbonId] | ||
143 | + if condition then | ||
144 | + local unlockChapter = role:getProperty("unlockChap") | ||
145 | + if not unlockChapter[carbonId] then | ||
146 | + return 3 | ||
147 | + end | ||
148 | + end | ||
149 | + | ||
140 | if checkReward(role) then | 150 | if checkReward(role) then |
141 | role:updateProperty({field = "hangBag", value = role:getProperty("hangBag")}) | 151 | role:updateProperty({field = "hangBag", value = role:getProperty("hangBag")}) |
142 | end | 152 | end |
@@ -144,7 +154,7 @@ function _M.startRpc( agent, data ) | @@ -144,7 +154,7 @@ function _M.startRpc( agent, data ) | ||
144 | local hangInfo = role:getProperty("hangInfo") | 154 | local hangInfo = role:getProperty("hangInfo") |
145 | local isNew = not hangInfo.carbonId | 155 | local isNew = not hangInfo.carbonId |
146 | hangInfo.carbonId = carbonId | 156 | hangInfo.carbonId = carbonId |
147 | - hangInfo.expCarbonId = isNew and carbonId or hangInfo.expCarbonId | 157 | + --hangInfo.expCarbonId = isNew and carbonId or hangInfo.expCarbonId |
148 | local nowTime = skynet.timex() | 158 | local nowTime = skynet.timex() |
149 | if isNew then | 159 | if isNew then |
150 | hangInfo.coinTime = nowTime | 160 | hangInfo.coinTime = nowTime |
@@ -279,15 +289,25 @@ function _M.endBattleRpc(agent, data) | @@ -279,15 +289,25 @@ function _M.endBattleRpc(agent, data) | ||
279 | local nextCarbonId = role:getNextCarbonId(carbonId) | 289 | local nextCarbonId = role:getNextCarbonId(carbonId) |
280 | -- 设置挂机关卡 | 290 | -- 设置挂机关卡 |
281 | if isWin then --and (hangInfo.carbonId or 0) < nextCarbonId then | 291 | if isWin then --and (hangInfo.carbonId or 0) < nextCarbonId then |
282 | - if not hangInfo.expCarbonId then | ||
283 | - hangInfo.expCarbonId = carbonId | ||
284 | - else | ||
285 | - local oldCarbonData = csvdb["idle_battleCsv"][hangInfo.expCarbonId] | ||
286 | - local newCarbonData = csvdb["idle_battleCsv"][carbonId] | ||
287 | - if oldCarbonData.money < newCarbonData.money then | ||
288 | - hangInfo.expCarbonId = carbonId | ||
289 | - end | 292 | + local newCarbonData = csvdb["idle_battleCsv"][carbonId] |
293 | + if newCarbonData then | ||
294 | + local expData = hangInfo.expData or {} | ||
295 | + expData.exp = (expData.exp or 0) + newCarbonData.exp | ||
296 | + expData.money = (expData.money or 0) + newCarbonData.money | ||
297 | + expData.playerExp = (expData.playerExp or 0) + newCarbonData.playerExp | ||
298 | + hangInfo.expData = expData | ||
290 | end | 299 | end |
300 | + | ||
301 | + --if not hangInfo.expCarbonId then | ||
302 | + -- hangInfo.expCarbonId = carbonId | ||
303 | + --else | ||
304 | + -- local oldCarbonData = csvdb["idle_battleCsv"][hangInfo.expCarbonId] | ||
305 | + -- local newCarbonData = csvdb["idle_battleCsv"][carbonId] | ||
306 | + -- if oldCarbonData.money < newCarbonData.money then | ||
307 | + -- hangInfo.expCarbonId = carbonId | ||
308 | + -- end | ||
309 | + --end | ||
310 | + | ||
291 | --local cfg = csvdb["idle_battleCsv"][nextCarbonId] | 311 | --local cfg = csvdb["idle_battleCsv"][nextCarbonId] |
292 | --if cfg then | 312 | --if cfg then |
293 | -- hangInfo.bossTime = skynet.timex() + cfg.idle_time | 313 | -- hangInfo.bossTime = skynet.timex() + cfg.idle_time |
@@ -418,14 +438,15 @@ function _M.quickRpc(agent , data) | @@ -418,14 +438,15 @@ function _M.quickRpc(agent , data) | ||
418 | local hangInfo = role:getProperty("hangInfo") | 438 | local hangInfo = role:getProperty("hangInfo") |
419 | if not hangInfo.carbonId then return end | 439 | if not hangInfo.carbonId then return end |
420 | local carbonData = csvdb["idle_battleCsv"][hangInfo.carbonId] | 440 | local carbonData = csvdb["idle_battleCsv"][hangInfo.carbonId] |
421 | - local expCarbonData = csvdb["idle_battleCsv"][hangInfo.expCarbonId] | 441 | + --local expCarbonData = csvdb["idle_battleCsv"][hangInfo.expCarbonId] |
442 | + local expCarbonData = hangInfo.expData or {} | ||
422 | 443 | ||
423 | local curCount = role.dailyData:getProperty("hangQC") + 1 | 444 | local curCount = role.dailyData:getProperty("hangQC") + 1 |
424 | local costs = globalCsv.idle_quickproduce_cost:toArray(true, "=") | 445 | local costs = globalCsv.idle_quickproduce_cost:toArray(true, "=") |
425 | if not costs[curCount] then return end | 446 | if not costs[curCount] then return end |
426 | if costs[curCount] > 0 then | 447 | if costs[curCount] > 0 then |
427 | - if not role:checkItemEnough({[ItemId.Diamond] = costs[curCount]}) then return end | ||
428 | - role:costItems({[ItemId.Diamond] = costs[curCount]}, {log = {desc = "quickHang", int1 = hangInfo.carbonId}}) | 448 | + if not role:checkItemEnough({[ItemId.Jade] = costs[curCount]}) then return end |
449 | + role:costItems({[ItemId.Jade] = costs[curCount]}, {log = {desc = "quickHang", int1 = hangInfo.carbonId}}) | ||
429 | end | 450 | end |
430 | 451 | ||
431 | role.dailyData:updateProperty({field = "hangQC", value = curCount}) | 452 | role.dailyData:updateProperty({field = "hangQC", value = curCount}) |
@@ -435,9 +456,9 @@ function _M.quickRpc(agent , data) | @@ -435,9 +456,9 @@ function _M.quickRpc(agent , data) | ||
435 | 456 | ||
436 | local coinCount = math.floor(time / globalCsv.idle_money_produce_cd) | 457 | local coinCount = math.floor(time / globalCsv.idle_money_produce_cd) |
437 | local itemCount = math.floor(time / globalCsv.idle_item_produce_cd) | 458 | local itemCount = math.floor(time / globalCsv.idle_item_produce_cd) |
438 | - reward[ItemId.Gold] = math.floor((reward[ItemId.Gold] or 0) + coinCount * expCarbonData.money) | ||
439 | - reward[ItemId.Exp] = math.floor((reward[ItemId.Exp] or 0) + coinCount * expCarbonData.exp) | ||
440 | - reward[ItemId.PlayerExp] = math.floor((reward[ItemId.PlayerExp] or 0) + coinCount * expCarbonData.playerExp) | 459 | + reward[ItemId.Gold] = math.floor((reward[ItemId.Gold] or 0) + coinCount * (expCarbonData.money or 0)) |
460 | + reward[ItemId.Exp] = math.floor((reward[ItemId.Exp] or 0) + coinCount * (expCarbonData.exp or 0)) | ||
461 | + reward[ItemId.PlayerExp] = math.floor((reward[ItemId.PlayerExp] or 0) + coinCount * (expCarbonData.playerExp or 0)) | ||
441 | 462 | ||
442 | local pool = {} | 463 | local pool = {} |
443 | for _, temp in pairs(carbonData.item:toArray()) do | 464 | for _, temp in pairs(carbonData.item:toArray()) do |
@@ -502,9 +523,9 @@ function _M.buyBonusCountRpc(agent, data) | @@ -502,9 +523,9 @@ function _M.buyBonusCountRpc(agent, data) | ||
502 | local lastCount = globalCsv.bonus_daily_buy_count * coef + extraCnt - bonusC[btype]["b"] | 523 | local lastCount = globalCsv.bonus_daily_buy_count * coef + extraCnt - bonusC[btype]["b"] |
503 | if math.illegalNum(count, 1, lastCount) then return 1 end | 524 | if math.illegalNum(count, 1, lastCount) then return 1 end |
504 | 525 | ||
505 | - if not role:checkItemEnough({[ItemId.Diamond] = globalCsv.bonus_buy_cost * count}) then return 2 end | 526 | + if not role:checkItemEnough({[ItemId.Jade] = globalCsv.bonus_buy_cost * count}) then return 2 end |
506 | 527 | ||
507 | - role:costItems({[ItemId.Diamond] = globalCsv.bonus_buy_cost * count}, {log = {desc = "buyBonusCount", int1 = btype, int2 = count}}) | 528 | + role:costItems({[ItemId.Jade] = globalCsv.bonus_buy_cost * count}, {log = {desc = "buyBonusCount", int1 = btype, int2 = count}}) |
508 | bonusC[btype]["b"] = bonusC[btype]["b"] + count | 529 | bonusC[btype]["b"] = bonusC[btype]["b"] + count |
509 | bonusC[btype]["c"] = bonusC[btype]["c"] - count | 530 | bonusC[btype]["c"] = bonusC[btype]["c"] - count |
510 | 531 | ||
@@ -1022,11 +1043,11 @@ function _M.bagFieldRpc(agent, data) | @@ -1022,11 +1043,11 @@ function _M.bagFieldRpc(agent, data) | ||
1022 | if not costD then | 1043 | if not costD then |
1023 | return 1 | 1044 | return 1 |
1024 | end | 1045 | end |
1025 | - if costD ~= 0 and not role:checkItemEnough({[ItemId.Diamond] = costD}) then | 1046 | + if costD ~= 0 and not role:checkItemEnough({[ItemId.Jade] = costD}) then |
1026 | return 2 | 1047 | return 2 |
1027 | end | 1048 | end |
1028 | role:updateProperty({field = "hangBagLimit", value = curBL + 1}) | 1049 | role:updateProperty({field = "hangBagLimit", value = curBL + 1}) |
1029 | - role:costItems({[ItemId.Diamond] = costD}, {log = {desc = "bagField"}}) | 1050 | + role:costItems({[ItemId.Jade] = costD}, {log = {desc = "bagField"}}) |
1030 | SendPacket(actionCodes.Hang_bagFieldRpc, '') | 1051 | SendPacket(actionCodes.Hang_bagFieldRpc, '') |
1031 | return true | 1052 | return true |
1032 | end | 1053 | end |
@@ -1080,4 +1101,28 @@ function _M.selectTeamRpc(agent, data) | @@ -1080,4 +1101,28 @@ function _M.selectTeamRpc(agent, data) | ||
1080 | return true | 1101 | return true |
1081 | end | 1102 | end |
1082 | 1103 | ||
1104 | +function _M.unlockChapterRpc(agent, data) | ||
1105 | + local role = agent.role | ||
1106 | + local msg = MsgPack.unpack(data) | ||
1107 | + local carbonId = msg.carbonId -- 解锁章节id | ||
1108 | + local condition = globalCsv.idle_chapter_unlock[carbonId] | ||
1109 | + if not condition then return 1 end | ||
1110 | + local conditionMap = condition:toArray(true, "=") | ||
1111 | + local count, level = conditionMap[1],conditionMap[2] | ||
1112 | + local cnt = 0 | ||
1113 | + for _, hero in pairs(role.heros) do | ||
1114 | + if hero:getProperty("level") >= level then | ||
1115 | + cnt = cnt + 1 | ||
1116 | + end | ||
1117 | + end | ||
1118 | + if cnt < count then return 2 end | ||
1119 | + | ||
1120 | + local unlockChapter = role:getProperty("unlockChap") | ||
1121 | + unlockChapter[carbonId] = 1 | ||
1122 | + role:updateProperty({field="unlockChap", value = unlockChapter}) | ||
1123 | + | ||
1124 | + SendPacket(actionCodes.Hang_unlockChapterRpc, '') | ||
1125 | + return true | ||
1126 | +end | ||
1127 | + | ||
1083 | return _M | 1128 | return _M |
src/actions/HeroAction.lua
@@ -35,10 +35,18 @@ function _M.levelUpRpc( agent, data ) | @@ -35,10 +35,18 @@ function _M.levelUpRpc( agent, data ) | ||
35 | local hero = role.heros[msg.id] | 35 | local hero = role.heros[msg.id] |
36 | if not hero then return 1 end | 36 | if not hero then return 1 end |
37 | 37 | ||
38 | - if hero:getProperty("level") >= hero:getMaxLevel() then return 2 end | ||
39 | - local curData = csvdb["unit_expCsv"][hero:getProperty("level")] | 38 | + local level = hero:getProperty("level") |
39 | + if level >= hero:getMaxLevel() then return 2 end | ||
40 | + local curData = csvdb["unit_expCsv"][level] | ||
40 | local cost = {[ItemId.Exp] = curData.exp, [ItemId.Gold] = curData.gold} | 41 | local cost = {[ItemId.Exp] = curData.exp, [ItemId.Gold] = curData.gold} |
41 | if not role:checkItemEnough(cost) then return 3 end | 42 | if not role:checkItemEnough(cost) then return 3 end |
43 | + | ||
44 | + -- 通过指定关卡后才能升级英雄等级 | ||
45 | + local pass = globalCsv.unit_exp_level_pass[level + 1] | ||
46 | + if pass then | ||
47 | + if not role:checkHangPass(pass) then return 4 end | ||
48 | + end | ||
49 | + | ||
42 | role:costItems(cost, {log = {desc = "heroLevelUp", int1 = msg.id, int2 = hero:getProperty("type")}}) | 50 | role:costItems(cost, {log = {desc = "heroLevelUp", int1 = msg.id, int2 = hero:getProperty("type")}}) |
43 | 51 | ||
44 | local oldAttr = hero:getTotalAttrs() | 52 | local oldAttr = hero:getTotalAttrs() |
@@ -69,12 +77,20 @@ function _M.breakRpc( agent, data ) | @@ -69,12 +77,20 @@ function _M.breakRpc( agent, data ) | ||
69 | local hero = role.heros[msg.id] | 77 | local hero = role.heros[msg.id] |
70 | if not hero then return 1 end | 78 | if not hero then return 1 end |
71 | 79 | ||
80 | + local breakL = hero:getProperty("breakL") | ||
72 | if hero:getProperty("level") < hero:getMaxLevel() then return 2 end | 81 | if hero:getProperty("level") < hero:getMaxLevel() then return 2 end |
73 | - if hero:getProperty("breakL") >= #csvdb["unit_breakCsv"] then return 3 end | ||
74 | - local curData = csvdb["unit_breakCsv"][hero:getProperty("breakL")] | 82 | + if breakL >= #csvdb["unit_breakCsv"] then return 3 end |
83 | + local curData = csvdb["unit_breakCsv"][breakL] | ||
75 | if hero:getProperty("wakeL") < curData["starLimit"] then return 4 end | 84 | if hero:getProperty("wakeL") < curData["starLimit"] then return 4 end |
76 | local cost = {[ItemId.BreakCost] = curData.cost, [ItemId.Gold] = curData.gold} | 85 | local cost = {[ItemId.BreakCost] = curData.cost, [ItemId.Gold] = curData.gold} |
77 | if not role:checkItemEnough(cost) then return 4 end | 86 | if not role:checkItemEnough(cost) then return 4 end |
87 | + | ||
88 | + -- 通过指定关卡后才能突破英雄 | ||
89 | + local pass = globalCsv.unit_break_level_pass[breakL + 1] | ||
90 | + if pass then | ||
91 | + if not role:checkHangPass(pass) then return 4 end | ||
92 | + end | ||
93 | + | ||
78 | role:costItems(cost, {log = {desc = "heroBreak", int1 = msg.id, int2 = hero:getProperty("type")}}) | 94 | role:costItems(cost, {log = {desc = "heroBreak", int1 = msg.id, int2 = hero:getProperty("type")}}) |
79 | local oldAttr = hero:getTotalAttrs() | 95 | local oldAttr = hero:getTotalAttrs() |
80 | hero:updateProperty({field = "breakL", delta = 1}) | 96 | hero:updateProperty({field = "breakL", delta = 1}) |
@@ -131,7 +147,7 @@ function _M.wakeRpc(agent, data) | @@ -131,7 +147,7 @@ function _M.wakeRpc(agent, data) | ||
131 | local oldBattleV = hero:getProperty("battleV") | 147 | local oldBattleV = hero:getProperty("battleV") |
132 | hero:updateProperty({field = "wakeL", delta = 1}) | 148 | hero:updateProperty({field = "wakeL", delta = 1}) |
133 | 149 | ||
134 | - role:checkTaskEnter("Wake", {heroType = typ, wakeL = curLevel}) | 150 | + role:checkTaskEnter("Wake", {heroType = typ, wakeL = curLevel + 1}) |
135 | if curLevel == 3 then -- 解锁cg | 151 | if curLevel == 3 then -- 解锁cg |
136 | role:checkTaskEnter("WakeCG", {heroType = typ}) | 152 | role:checkTaskEnter("WakeCG", {heroType = typ}) |
137 | end | 153 | end |
@@ -648,11 +664,11 @@ function _M.getResetRewardRpc(agent, data) | @@ -648,11 +664,11 @@ function _M.getResetRewardRpc(agent, data) | ||
648 | totalCost[costArr[1]] = costArr[2] | 664 | totalCost[costArr[1]] = costArr[2] |
649 | else | 665 | else |
650 | local diamond = (costArr[2] - itemCount) * costArr[3] | 666 | local diamond = (costArr[2] - itemCount) * costArr[3] |
651 | - if role:getItemCount(ItemId.Diamond) < diamond then | 667 | + if role:getItemCount(ItemId.Jade) < diamond then |
652 | return 1 | 668 | return 1 |
653 | end | 669 | end |
654 | totalCost[costArr[1]] = itemCount | 670 | totalCost[costArr[1]] = itemCount |
655 | - totalCost[ItemId.Diamond] = diamond | 671 | + totalCost[ItemId.Jade] = diamond |
656 | end | 672 | end |
657 | 673 | ||
658 | --if pay and not role:costDiamond({count = globalCsv.unit_heroBack_cost or 200, log = {desc = "resetHero", int1 = msg.id}}) then | 674 | --if pay and not role:costDiamond({count = globalCsv.unit_heroBack_cost or 200, log = {desc = "resetHero", int1 = msg.id}}) then |
src/actions/HttpAction.lua
@@ -134,7 +134,37 @@ function _M.gm_action(query) | @@ -134,7 +134,37 @@ function _M.gm_action(query) | ||
134 | return isOn | 134 | return isOn |
135 | end | 135 | end |
136 | -- 离线操作 | 136 | -- 离线操作 |
137 | - local role = require("models.Role").new({key = string.format("role:%d", query.id)}) | 137 | + local role = require("models.Role").new({key = string.format("%d", query.id)}) |
138 | + local ret = role:load() | ||
139 | + if not ret then | ||
140 | + return "角色不存在" | ||
141 | + end | ||
142 | + role:loadAll() | ||
143 | + role:startActionUcode() | ||
144 | + local status = gmFuncs[query.cmd](role, query) | ||
145 | + role:endActionUcode() | ||
146 | + | ||
147 | + return status | ||
148 | +end | ||
149 | + | ||
150 | +function _M.pay_action(query) | ||
151 | + local gmFuncs = require "actions.GmAction" | ||
152 | + if not query.cmd or not query.order or not gmFuncs[query.cmd] then return "指令不存在" end | ||
153 | + local mysqlproxy = require "shared.mysqlproxy" | ||
154 | + local res = mysqlproxy:query(string.format("SELECT roleid FROM `Order` WHERE `id` = %s", query.order)) | ||
155 | + if res[1] then | ||
156 | + query.id = res[1]["roleid"] | ||
157 | + else | ||
158 | + return "订单非法" | ||
159 | + end | ||
160 | + -- 在线操作 | ||
161 | + query.id = tonumber(query.id) | ||
162 | + local isOn = proc_online(query.cmd, query.id, query) | ||
163 | + if isOn ~= "not_online" then | ||
164 | + return isOn | ||
165 | + end | ||
166 | + -- 离线操作 | ||
167 | + local role = require("models.Role").new({key = string.format("%d", query.id)}) | ||
138 | local ret = role:load() | 168 | local ret = role:load() |
139 | if not ret then | 169 | if not ret then |
140 | return "角色不存在" | 170 | return "角色不存在" |
src/actions/PvpAction.lua
@@ -241,7 +241,7 @@ function _M.buyCountRpc(agent, data) | @@ -241,7 +241,7 @@ function _M.buyCountRpc(agent, data) | ||
241 | return 1 | 241 | return 1 |
242 | end | 242 | end |
243 | 243 | ||
244 | - local cost = {[ItemId.Diamond] = globalCsv.pvp_buy_cost * count} | 244 | + local cost = {[ItemId.Jade] = globalCsv.pvp_buy_cost * count} |
245 | if not role:checkItemEnough(cost) then return 2 end | 245 | if not role:checkItemEnough(cost) then return 2 end |
246 | role:costItems(cost, {log = {desc = "buyPvpKey"}}) | 246 | role:costItems(cost, {log = {desc = "buyPvpKey"}}) |
247 | role:award({[ItemId.PvpKey] = count}, {log = {desc = "buyPvpKey"}}) | 247 | role:award({[ItemId.PvpKey] = count}, {log = {desc = "buyPvpKey"}}) |
src/actions/RoleAction.lua
@@ -14,6 +14,8 @@ local table_insert = table.insert | @@ -14,6 +14,8 @@ local table_insert = table.insert | ||
14 | local tconcat = table.concat | 14 | local tconcat = table.concat |
15 | local httpc = require("http.httpc") | 15 | local httpc = require("http.httpc") |
16 | 16 | ||
17 | +require "utils.MysqlUtil" | ||
18 | + | ||
17 | local WAVE_HERO_NUMS = 150 | 19 | local WAVE_HERO_NUMS = 150 |
18 | local WAVE_RUNE_NUMS = 150 | 20 | local WAVE_RUNE_NUMS = 150 |
19 | local WAVE_SPARK_NUMS = 150 | 21 | local WAVE_SPARK_NUMS = 150 |
@@ -85,8 +87,8 @@ function _M.loginRpc( agent, data ) | @@ -85,8 +87,8 @@ function _M.loginRpc( agent, data ) | ||
85 | local role = agent.role | 87 | local role = agent.role |
86 | -- 2 | 88 | -- 2 |
87 | if not role then | 89 | if not role then |
88 | - local roleKey = string_format("role:%d", roleId) | ||
89 | - if not redisproxy:exists(roleKey) then | 90 | + local roleKey = string_format("%d", roleId) |
91 | + if not roleExists(roleId) then | ||
90 | response.result = "DB_ERROR" | 92 | response.result = "DB_ERROR" |
91 | SendPacket(actionCodes.Role_loginRpc, MsgPack.pack(response)) | 93 | SendPacket(actionCodes.Role_loginRpc, MsgPack.pack(response)) |
92 | return true | 94 | return true |
@@ -155,7 +157,7 @@ function _M.loginRpc( agent, data ) | @@ -155,7 +157,7 @@ function _M.loginRpc( agent, data ) | ||
155 | end | 157 | end |
156 | end | 158 | end |
157 | 159 | ||
158 | - SERV_OPEN = redisproxy:hget("autoincrement_set", "server_start") | 160 | + SERV_OPEN = getDbCfgVal("server_info", "server_start", "str_value") |
159 | 161 | ||
160 | role:changeStructVersion() -- 数据结构 版本更新 | 162 | role:changeStructVersion() -- 数据结构 版本更新 |
161 | role:getAdvData(true) -- 清掉不合格的数据 | 163 | role:getAdvData(true) -- 清掉不合格的数据 |
@@ -344,7 +346,8 @@ function _M.createRpc(agent, data) | @@ -344,7 +346,8 @@ function _M.createRpc(agent, data) | ||
344 | 346 | ||
345 | -- 再次检查uid | 347 | -- 再次检查uid |
346 | local uid = tostring(msg.uid) | 348 | local uid = tostring(msg.uid) |
347 | - local user = redisproxy:get(string_format("uid:%s", uid)) | 349 | + --local user = redisproxy:get(string_format("uid:%s", uid)) |
350 | + local res, user = roleUidExists(uid) | ||
348 | if user then | 351 | if user then |
349 | response.result = "SUCCESS" | 352 | response.result = "SUCCESS" |
350 | response.roleName = user | 353 | response.roleName = user |
@@ -367,7 +370,7 @@ function _M.createRpc(agent, data) | @@ -367,7 +370,7 @@ function _M.createRpc(agent, data) | ||
367 | end | 370 | end |
368 | local roleName = setRoleName(msg.uid, roleId) | 371 | local roleName = setRoleName(msg.uid, roleId) |
369 | local newRole = require("models.Role").new({ | 372 | local newRole = require("models.Role").new({ |
370 | - key = string_format("role:%d", roleId), | 373 | + key = string_format("%d", roleId), |
371 | id = roleId, | 374 | id = roleId, |
372 | uid = tostring(msg.uid), | 375 | uid = tostring(msg.uid), |
373 | sid = msg.subId or 0, | 376 | sid = msg.subId or 0, |
@@ -387,6 +390,7 @@ function _M.createRpc(agent, data) | @@ -387,6 +390,7 @@ function _M.createRpc(agent, data) | ||
387 | SendPacket(actionCodes.Role_createRpc, MsgPack.pack(response)) | 390 | SendPacket(actionCodes.Role_createRpc, MsgPack.pack(response)) |
388 | return true | 391 | return true |
389 | end | 392 | end |
393 | + --newRole:loadRoleIncre() | ||
390 | newRole:startActionUcode() | 394 | newRole:startActionUcode() |
391 | newRole.sysVersion = msg.sysVersion | 395 | newRole.sysVersion = msg.sysVersion |
392 | newRole.ip = agent.ip:toArray(false, ":")[1] | 396 | newRole.ip = agent.ip:toArray(false, ":")[1] |
@@ -395,7 +399,7 @@ function _M.createRpc(agent, data) | @@ -395,7 +399,7 @@ function _M.createRpc(agent, data) | ||
395 | 399 | ||
396 | newRole:award(globalCsv.birthItem, {log = {desc = "birth"}, notNotify = true}) | 400 | newRole:award(globalCsv.birthItem, {log = {desc = "birth"}, notNotify = true}) |
397 | -- 欢迎邮件 | 401 | -- 欢迎邮件 |
398 | - redisproxy:insertEmail({roleId = roleId, emailId = 1}) | 402 | + mysqlproxy:insertEmail({roleId = roleId, emailId = 1}) |
399 | 403 | ||
400 | if msg.newuser then | 404 | if msg.newuser then |
401 | newRole:log("onCreateAccount") | 405 | newRole:log("onCreateAccount") |
@@ -405,6 +409,8 @@ function _M.createRpc(agent, data) | @@ -405,6 +409,8 @@ function _M.createRpc(agent, data) | ||
405 | if msg.newdevice then | 409 | if msg.newdevice then |
406 | newRole:mylog("newdevice", {key1 = agent.ip:toArray(false, ":")[1]}) | 410 | newRole:mylog("newdevice", {key1 = agent.ip:toArray(false, ":")[1]}) |
407 | end | 411 | end |
412 | + -- 整体保存一次 | ||
413 | + newRole:update() | ||
408 | 414 | ||
409 | SendPacket(actionCodes.Role_createRpc, MsgPack.pack(response)) | 415 | SendPacket(actionCodes.Role_createRpc, MsgPack.pack(response)) |
410 | 416 | ||
@@ -425,9 +431,9 @@ function _M.createRpc(agent, data) | @@ -425,9 +431,9 @@ function _M.createRpc(agent, data) | ||
425 | reward = reward:setv(itemId, count) | 431 | reward = reward:setv(itemId, count) |
426 | end | 432 | end |
427 | if back.reward[70] then | 433 | if back.reward[70] then |
428 | - redisproxy:insertEmail({roleId = roleId, emailId = MailId.CBBackAward2, contentPms = {back.money}, createtime = skynet.timex(), attachments = reward}) | 434 | + mysqlproxy:insertEmail({roleId = roleId, emailId = MailId.CBBackAward2, contentPms = {back.money}, createtime = skynet.timex(), attachments = reward}) |
429 | else | 435 | else |
430 | - redisproxy:insertEmail({roleId = roleId, emailId = MailId.CBBackAward, contentPms = {back.money}, createtime = skynet.timex(), attachments = reward}) | 436 | + mysqlproxy:insertEmail({roleId = roleId, emailId = MailId.CBBackAward, contentPms = {back.money}, createtime = skynet.timex(), attachments = reward}) |
431 | end | 437 | end |
432 | newRole:mylog("cbback", {key1 = uid, int2 = roleId}) | 438 | newRole:mylog("cbback", {key1 = uid, int2 = roleId}) |
433 | end | 439 | end |
@@ -487,6 +493,7 @@ function _M.changeNameRpc(agent, data) | @@ -487,6 +493,7 @@ function _M.changeNameRpc(agent, data) | ||
487 | }) | 493 | }) |
488 | 494 | ||
489 | role:changeCrossServerPvpSelfInfo("name") | 495 | role:changeCrossServerPvpSelfInfo("name") |
496 | + role:checkTaskEnter("Rename", {}) | ||
490 | SendPacket(actionCodes.Role_changeNameRpc, MsgPack.pack({result = 0})) | 497 | SendPacket(actionCodes.Role_changeNameRpc, MsgPack.pack({result = 0})) |
491 | return true | 498 | return true |
492 | end | 499 | end |
@@ -525,14 +532,19 @@ function _M.saleItemRpc(agent, data) | @@ -525,14 +532,19 @@ function _M.saleItemRpc(agent, data) | ||
525 | local role = agent.role | 532 | local role = agent.role |
526 | local msg = MsgPack.unpack(data) | 533 | local msg = MsgPack.unpack(data) |
527 | local backs = msg.backs | 534 | local backs = msg.backs |
528 | - if not backs then return end | 535 | + if not backs or not next(backs) then return 0 end |
536 | + | ||
537 | + for itemId, count in pairs(backs) do | ||
538 | + if math.illegalNum(count, 1, role:getItemCount(itemId)) then return 1 end | ||
539 | + if globalCsv.unit_paster_ban[itemId] then return 2 end | ||
540 | + local itemData = csvdb["itemCsv"][itemId] | ||
541 | + if itemData.sell_effect == "" then return 3 end | ||
542 | + end | ||
529 | 543 | ||
530 | local reward = {} | 544 | local reward = {} |
531 | local fragCount = 0 | 545 | local fragCount = 0 |
532 | for itemId, count in pairs(backs) do | 546 | for itemId, count in pairs(backs) do |
533 | - if math.illegalNum(count, 1, role:getItemCount(itemId)) then return end | ||
534 | local itemData = csvdb["itemCsv"][itemId] | 547 | local itemData = csvdb["itemCsv"][itemId] |
535 | - if itemData.sell_effect == "" then return end | ||
536 | if itemData.type == ItemType.HeroFragment or itemData.type == ItemType.HeroFCommon then | 548 | if itemData.type == ItemType.HeroFragment or itemData.type == ItemType.HeroFCommon then |
537 | fragCount = fragCount + count | 549 | fragCount = fragCount + count |
538 | end | 550 | end |
@@ -643,8 +655,8 @@ function _M.openTimeBoxRpc(agent, data) | @@ -643,8 +655,8 @@ function _M.openTimeBoxRpc(agent, data) | ||
643 | stopTime = nowTime + quick | 655 | stopTime = nowTime + quick |
644 | local cost_pre = globalCsv.box_timeOpen_diamond:toArray(true, "=") | 656 | local cost_pre = globalCsv.box_timeOpen_diamond:toArray(true, "=") |
645 | local costKey = math.ceil(quick / (cost_pre[1] * 60)) * cost_pre[2] | 657 | local costKey = math.ceil(quick / (cost_pre[1] * 60)) * cost_pre[2] |
646 | - if not role:checkItemEnough({[ItemId.Diamond] = costKey}) then return 5 end | ||
647 | - role:costItems({[ItemId.Diamond] = costKey}, {log = {desc = "openTimeBox", int1 = slot, int2 = oper}}) | 658 | + if not role:checkItemEnough({[ItemId.Jade] = costKey}) then return 5 end |
659 | + role:costItems({[ItemId.Jade] = costKey}, {log = {desc = "openTimeBox", int1 = slot, int2 = oper}}) | ||
648 | else | 660 | else |
649 | stopTime = math.min(nowTime,time + globalCsv.box_productLine_time * 3600) | 661 | stopTime = math.min(nowTime,time + globalCsv.box_productLine_time * 3600) |
650 | end | 662 | end |
@@ -753,18 +765,14 @@ function _M.openSpeedUpBoxRpc(agent, data) | @@ -753,18 +765,14 @@ function _M.openSpeedUpBoxRpc(agent, data) | ||
753 | 765 | ||
754 | if useType == 1 then -- 挂机齿轮 | 766 | if useType == 1 then -- 挂机齿轮 |
755 | local hangInfo = role:getProperty("hangInfo") | 767 | local hangInfo = role:getProperty("hangInfo") |
756 | - if not hangInfo.expCarbonId then | ||
757 | - return 2 | ||
758 | - end | ||
759 | - local carbonData = csvdb["idle_battleCsv"][hangInfo.expCarbonId] | ||
760 | - reward[ItemId.Gold] = (reward[ItemId.Gold] or 0) + math.floor(time / globalCsv.idle_money_produce_cd) * carbonData.money * count | 768 | + local expData = hangInfo.expData or {} |
769 | + --local carbonData = csvdb["idle_battleCsv"][hangInfo.expCarbonId] | ||
770 | + reward[ItemId.Gold] = (reward[ItemId.Gold] or 0) + math.floor(time / globalCsv.idle_money_produce_cd) * (expData.money or 0) * count | ||
761 | elseif useType == 2 then -- 挂机经验 | 771 | elseif useType == 2 then -- 挂机经验 |
762 | local hangInfo = role:getProperty("hangInfo") | 772 | local hangInfo = role:getProperty("hangInfo") |
763 | - if not hangInfo.expCarbonId then | ||
764 | - return 3 | ||
765 | - end | ||
766 | - local carbonData = csvdb["idle_battleCsv"][hangInfo.expCarbonId] | ||
767 | - reward[ItemId.Exp] = (reward[ItemId.Exp] or 0) + math.floor(time / globalCsv.idle_money_produce_cd) * carbonData.exp * count | 773 | + local expData = hangInfo.expData or {} |
774 | + --local carbonData = csvdb["idle_battleCsv"][hangInfo.expCarbonId] | ||
775 | + reward[ItemId.Exp] = (reward[ItemId.Exp] or 0) + math.floor(time / globalCsv.idle_money_produce_cd) * (expData.exp or 0) * count | ||
768 | elseif useType == 3 then -- 食材商人收入 | 776 | elseif useType == 3 then -- 食材商人收入 |
769 | local buildType = 6 | 777 | local buildType = 6 |
770 | local level = role.dinerData:getProperty("buildL"):getv(buildType, 1) | 778 | local level = role.dinerData:getProperty("buildL"):getv(buildType, 1) |
@@ -833,8 +841,8 @@ function _M.storyBookRewardRpc(agent, data) | @@ -833,8 +841,8 @@ function _M.storyBookRewardRpc(agent, data) | ||
833 | role:log("carriage_video", { | 841 | role:log("carriage_video", { |
834 | carriage_video_type = storyBookData.type, --放映室类型,剧情CG:0, 角色CG:1, 主线剧情:2, 角色剧情:3, 活动剧情:4, 图鉴:5 | 842 | carriage_video_type = storyBookData.type, --放映室类型,剧情CG:0, 角色CG:1, 主线剧情:2, 角色剧情:3, 活动剧情:4, 图鉴:5 |
835 | carriage_video_id = storyId, --放映室片段ID | 843 | carriage_video_id = storyId, --放映室片段ID |
836 | - carriage_video_coinid = reward[ItemId.Diamond] and ItemId.Diamond or 0, --放映奖励货币类型,无奖励则填写0 | ||
837 | - carriage_video_coinnum = reward[ItemId.Diamond] or 0, --放映奖励货币数量,无奖励则填写0 | 844 | + carriage_video_coinid = reward[ItemId.Jade] and ItemId.Jade or 0, --放映奖励货币类型,无奖励则填写0 |
845 | + carriage_video_coinnum = reward[ItemId.Jade] or 0, --放映奖励货币数量,无奖励则填写0 | ||
838 | carriage_video_item = reward, --放映奖励其他物品数量,json格式记录,{'itemid1':10,'itemid2':5,…………..},无奖励则填写0 | 846 | carriage_video_item = reward, --放映奖励其他物品数量,json格式记录,{'itemid1':10,'itemid2':5,…………..},无奖励则填写0 |
839 | }) | 847 | }) |
840 | 848 | ||
@@ -1153,21 +1161,20 @@ function _M.chatRpc(agent, data) | @@ -1153,21 +1161,20 @@ function _M.chatRpc(agent, data) | ||
1153 | local objectId = msg.roleId | 1161 | local objectId = msg.roleId |
1154 | response.objId = objectId | 1162 | response.objId = objectId |
1155 | local redret = redisproxy:pipelining(function(red) | 1163 | local redret = redisproxy:pipelining(function(red) |
1156 | - red:exists(string.format("role:%d", objectId)) | ||
1157 | red:sismember(FRIEND_BLACK_KEY:format(roleId), objectId) | 1164 | red:sismember(FRIEND_BLACK_KEY:format(roleId), objectId) |
1158 | red:sismember(FRIEND_BLACK_KEY:format(objectId), roleId) | 1165 | red:sismember(FRIEND_BLACK_KEY:format(objectId), roleId) |
1159 | end) | 1166 | end) |
1160 | - if redret[1] ~= 1 then | 1167 | + if not roleExists(objectId) then |
1161 | result = 1 | 1168 | result = 1 |
1162 | return | 1169 | return |
1163 | end | 1170 | end |
1164 | -- 你把对方拉黑拉黑 | 1171 | -- 你把对方拉黑拉黑 |
1165 | - if redret[2] == 1 then | 1172 | + if redret[1] == 1 then |
1166 | result = 2 | 1173 | result = 2 |
1167 | return | 1174 | return |
1168 | end | 1175 | end |
1169 | -- 对方把你拉黑 | 1176 | -- 对方把你拉黑 |
1170 | - local isBlock = redret[3] == 1 | 1177 | + local isBlock = redret[2] == 1 |
1171 | 1178 | ||
1172 | local bin = MsgPack.pack(response) | 1179 | local bin = MsgPack.pack(response) |
1173 | if not isBlock then | 1180 | if not isBlock then |
@@ -1402,6 +1409,48 @@ function _M.goldBuyRpc(agent, data) | @@ -1402,6 +1409,48 @@ function _M.goldBuyRpc(agent, data) | ||
1402 | return true | 1409 | return true |
1403 | end | 1410 | end |
1404 | 1411 | ||
1412 | +function _M.diamondConvertRpc(agent, data) | ||
1413 | + local role = agent.role | ||
1414 | + local msg = MsgPack.unpack(data) | ||
1415 | + | ||
1416 | + local oper = msg.oper | ||
1417 | + if oper ~= 1 and oper ~= 2 then return 0 end | ||
1418 | + | ||
1419 | + local cost = math.ceil(msg.cost or 0) | ||
1420 | + if cost <= 0 then return 1 end | ||
1421 | + if role:getAllDiamond() < cost then return 2 end | ||
1422 | + | ||
1423 | + local get = globalCsv.legal_tender_cost * cost | ||
1424 | + role:costDiamond({count = cost, log = {desc = "convert", int1 = oper, int2 = get}}) | ||
1425 | + local reward, change | ||
1426 | + if oper == 1 then -- 钻石兑换成虹光玉 | ||
1427 | + reward, change = role:award({[ItemId.Jade] = get}, {log = {desc = "convert"}}) | ||
1428 | + elseif oper == 2 then -- 钻石兑换成虹光玉再兑换成招募券 | ||
1429 | + local old = role:getItemCount(ItemId.Jade) | ||
1430 | + get = old + get | ||
1431 | + | ||
1432 | + local quan = math.floor(get/globalCsv.recruit_cost) | ||
1433 | + local remain = get - quan * globalCsv.recruit_cost | ||
1434 | + | ||
1435 | + local allReward = {} | ||
1436 | + if remain > old then | ||
1437 | + allReward[ItemId.Jade] = remain - old | ||
1438 | + elseif remain == old then | ||
1439 | + else | ||
1440 | + role:costItems({[ItemId.Jade] = old - remain}, {log = {desc = "convert"}}) | ||
1441 | + end | ||
1442 | + | ||
1443 | + if quan > 0 then | ||
1444 | + allReward[ItemId.RecruitmentCard] = quan | ||
1445 | + end | ||
1446 | + | ||
1447 | + reward, change = role:award(allReward, {log = {desc = "convert"}}) | ||
1448 | + end | ||
1449 | + | ||
1450 | + SendPacket(actionCodes.Role_diamondConvertRpc, MsgPack.pack(role:packReward(reward, change))) | ||
1451 | + return true | ||
1452 | +end | ||
1453 | + | ||
1405 | function _M.getDownloadCvRewardRpc(agent, data) | 1454 | function _M.getDownloadCvRewardRpc(agent, data) |
1406 | local role = agent.role | 1455 | local role = agent.role |
1407 | local flag = role:getProperty("downCvR") or 0 | 1456 | local flag = role:getProperty("downCvR") or 0 |
@@ -1489,4 +1538,26 @@ function _M.accuseRpc(agent, data) | @@ -1489,4 +1538,26 @@ function _M.accuseRpc(agent, data) | ||
1489 | return true | 1538 | return true |
1490 | end | 1539 | end |
1491 | 1540 | ||
1541 | +function _M.getTimeGiftRpc(agent, data) | ||
1542 | + local role = agent.role | ||
1543 | + | ||
1544 | + local GiftCsv = csvdb["time_giftCsv"] | ||
1545 | + local timeGift = role:getProperty("timeGift") | ||
1546 | + if timeGift >= #GiftCsv then return 0 end | ||
1547 | + | ||
1548 | + local nextL = timeGift + 1 | ||
1549 | + local gift = GiftCsv[nextL] | ||
1550 | + if not gift then return 1 end | ||
1551 | + | ||
1552 | + local createtime = role:getProperty("ctime") | ||
1553 | + if skynet.timex() - createtime < gift.time then return 2 end | ||
1554 | + | ||
1555 | + role:updateProperty({field = "timeGift", value = nextL}) | ||
1556 | + local reward, change = role:award(gift.gift, {log = {desc = "giftTime", int1 = nextL}}) | ||
1557 | + role:mylog("role_action", {desc = "giftTime", int1 = nextL}) | ||
1558 | + | ||
1559 | + SendPacket(actionCodes.Role_getTimeGiftRpc, MsgPack.pack(role:packReward(reward, change))) | ||
1560 | + return true | ||
1561 | +end | ||
1562 | + | ||
1492 | return _M | 1563 | return _M |
1493 | \ No newline at end of file | 1564 | \ No newline at end of file |
src/actions/SeaportAction.lua
@@ -198,13 +198,13 @@ function _M.taskRpc(agent, data) | @@ -198,13 +198,13 @@ function _M.taskRpc(agent, data) | ||
198 | 198 | ||
199 | if quick and remainT > 0 then | 199 | if quick and remainT > 0 then |
200 | local cost = math.ceil(remainT / 3600) * globalCsv.seaport_task_quick | 200 | local cost = math.ceil(remainT / 3600) * globalCsv.seaport_task_quick |
201 | - if not role:checkItemEnough({[ItemId.Diamond] = cost}) then return 8 end | ||
202 | - role:costItems({[ItemId.Diamond] = cost}, {log = {desc = "seaportTask", int1 = taskId, int2 = level}}) | 201 | + if not role:checkItemEnough({[ItemId.Jade] = cost}) then return 8 end |
202 | + role:costItems({[ItemId.Jade] = cost}, {log = {desc = "seaportTask", int1 = taskId, int2 = level}}) | ||
203 | end | 203 | end |
204 | 204 | ||
205 | local carbonCsv = csvdb["idle_battleCsv"] | 205 | local carbonCsv = csvdb["idle_battleCsv"] |
206 | - local expCarbonId = role:getProperty("hangInfo").expCarbonId | ||
207 | - if not carbonCsv[expCarbonId] then return 7 end | 206 | + local expData = role:getProperty("hangInfo").expData or {} |
207 | + --if not carbonCsv[expCarbonId] then return 7 end | ||
208 | 208 | ||
209 | local totalCoef = 0 | 209 | local totalCoef = 0 |
210 | for _, heroId in ipairs(collect.team:toArray(true,"=")) do | 210 | for _, heroId in ipairs(collect.team:toArray(true,"=")) do |
@@ -222,8 +222,8 @@ function _M.taskRpc(agent, data) | @@ -222,8 +222,8 @@ function _M.taskRpc(agent, data) | ||
222 | bigSuccess = true | 222 | bigSuccess = true |
223 | end | 223 | end |
224 | 224 | ||
225 | - local money = math.ceil(carbonCsv[expCarbonId].money / 5 * data.time * data.money_clear) | ||
226 | - local exp = math.ceil(carbonCsv[expCarbonId].exp / 5 * data.time * data.exp_clear) | 225 | + local money = math.ceil((expData.money or 0) / 5 * data.time * data.money_clear) |
226 | + local exp = math.ceil((expData.exp or 0) / 5 * data.time * data.exp_clear) | ||
227 | local itemReward = data.item_clear_special:toNumMap() | 227 | local itemReward = data.item_clear_special:toNumMap() |
228 | itemReward[ItemId.Gold] = (itemReward[ItemId.Gold] or 0) + money | 228 | itemReward[ItemId.Gold] = (itemReward[ItemId.Gold] or 0) + money |
229 | itemReward[ItemId.Exp] = (itemReward[ItemId.Exp] or 0) + exp | 229 | itemReward[ItemId.Exp] = (itemReward[ItemId.Exp] or 0) + exp |
src/actions/StoreAction.lua
@@ -20,7 +20,6 @@ function _M.rechargeRpc(agent , data) | @@ -20,7 +20,6 @@ function _M.rechargeRpc(agent , data) | ||
20 | end | 20 | end |
21 | SendPacket(actionCodes.Store_rechargeRpc, MsgPack.pack({ order = partnerOrderId })) | 21 | SendPacket(actionCodes.Store_rechargeRpc, MsgPack.pack({ order = partnerOrderId })) |
22 | 22 | ||
23 | - | ||
24 | -- 测试的 直接发奖励了 | 23 | -- 测试的 直接发奖励了 |
25 | skynet.timeout(10, function () | 24 | skynet.timeout(10, function () |
26 | role:handlePurchase({ | 25 | role:handlePurchase({ |
src/actions/TowerAction.lua
@@ -107,8 +107,13 @@ function _M.endBattleRpc(agent, data) | @@ -107,8 +107,13 @@ function _M.endBattleRpc(agent, data) | ||
107 | --排行榜 | 107 | --排行榜 |
108 | role:setTowerRank(curLevel % 10000, towerType + 1) | 108 | role:setTowerRank(curLevel % 10000, towerType + 1) |
109 | 109 | ||
110 | + local rewardStr = curTower.reward | ||
111 | + if curTower.special_award ~= "" then | ||
112 | + rewardStr = rewardStr .. " " .. curTower.special_award | ||
113 | + end | ||
114 | + | ||
110 | curLevel = curLevel + 1 | 115 | curLevel = curLevel + 1 |
111 | - reward, change = role:award(curTower.reward, {log = {desc = "towerBattle", int1 = id}}) | 116 | + reward, change = role:award(rewardStr, {log = {desc = "towerBattle", int1 = id}}) |
112 | if towerType == 0 then | 117 | if towerType == 0 then |
113 | role:checkTaskEnter("TowerPass", {level = towerInfo.l}) | 118 | role:checkTaskEnter("TowerPass", {level = towerInfo.l}) |
114 | end | 119 | end |
src/agent.lua
@@ -12,6 +12,7 @@ local xxtea = require "xxtea" | @@ -12,6 +12,7 @@ local xxtea = require "xxtea" | ||
12 | 12 | ||
13 | skynet = require "skynet" | 13 | skynet = require "skynet" |
14 | redisproxy = require "shared.redisproxy" | 14 | redisproxy = require "shared.redisproxy" |
15 | +mysqlproxy = require "shared.mysqlproxy" | ||
15 | datacenter = require "skynet.datacenter" | 16 | datacenter = require "skynet.datacenter" |
16 | mcast_util = require "services/mcast_util" | 17 | mcast_util = require "services/mcast_util" |
17 | csvdb = require "shared.csvdata" | 18 | csvdb = require "shared.csvdata" |
src/main.lua
@@ -21,6 +21,17 @@ skynet.start(function() | @@ -21,6 +21,17 @@ skynet.start(function() | ||
21 | }) | 21 | }) |
22 | end | 22 | end |
23 | 23 | ||
24 | + -- 启动mysql | ||
25 | + for i = 1, work_count do | ||
26 | + local redisd = skynet.newservice("services/mysqld", i) | ||
27 | + skynet.call(redisd, "lua", "open", { | ||
28 | + host = skynet.getenv("mysql_host"), | ||
29 | + port = tonumber(skynet.getenv("mysql_port")), | ||
30 | + user = skynet.getenv("mysql_user"), | ||
31 | + pwd = skynet.getenv("mysql_password"), | ||
32 | + }) | ||
33 | + end | ||
34 | + | ||
24 | --启动log | 35 | --启动log |
25 | if use_logd == 1 then | 36 | if use_logd == 1 then |
26 | for i = 1, work_count * 2 do | 37 | for i = 1, work_count * 2 do |
src/models/Activity.lua
1 | -local Activity = class("Activity", require("shared.ModelBase")) | 1 | +local Activity = class("Activity", require("shared.ModelBaseMysql")) |
2 | local string_format = string.format | 2 | local string_format = string.format |
3 | 3 | ||
4 | -- activity_ctr showType | 4 | -- activity_ctr showType |
@@ -39,6 +39,7 @@ Activity.ActivityType = { | @@ -39,6 +39,7 @@ Activity.ActivityType = { | ||
39 | HeroBackFree = 37, -- 无损耗归还 | 39 | HeroBackFree = 37, -- 无损耗归还 |
40 | 40 | ||
41 | BattleCommandTask = 38, -- 战令任务活动 | 41 | BattleCommandTask = 38, -- 战令任务活动 |
42 | + NewUserTask = 41, -- 新用户任务 | ||
42 | } | 43 | } |
43 | 44 | ||
44 | local function checkActivityType(activityType) | 45 | local function checkActivityType(activityType) |
@@ -64,6 +65,7 @@ end | @@ -64,6 +65,7 @@ end | ||
64 | 65 | ||
65 | 66 | ||
66 | Activity.schema = { | 67 | Activity.schema = { |
68 | + id = {"number", 0, "pri"}, -- 角色id | ||
67 | actime = {"table", {}}, -- 最近检查某项活动的开始时间 {id = time} | 69 | actime = {"table", {}}, -- 最近检查某项活动的开始时间 {id = time} |
68 | round = {"table", {}}, -- 记录活动到了第几轮 {id = roundnum} | 70 | round = {"table", {}}, -- 记录活动到了第几轮 {id = roundnum} |
69 | act4 = {"table", {}}, -- {0 = day, 1= -1, 2 = -1} == 签到活动 | 71 | act4 = {"table", {}}, -- {0 = day, 1= -1, 2 = -1} == 签到活动 |
@@ -640,6 +642,110 @@ activityFunc[Activity.ActivityType.Exchange] = { | @@ -640,6 +642,110 @@ activityFunc[Activity.ActivityType.Exchange] = { | ||
640 | end, | 642 | end, |
641 | } | 643 | } |
642 | 644 | ||
645 | +-- 新用户活动任务 | ||
646 | +activityFunc[Activity.ActivityType.NewUserTask] = { | ||
647 | + ["init"] = function(self, actType, isCrossDay, notify) | ||
648 | + local nbTask = self.owner:getProperty("nbTask") | ||
649 | + nbTask = {} | ||
650 | + self.owner:updateProperty({field="nbTask", value=nbTask}) | ||
651 | + local role = self.owner | ||
652 | + local buildL = role.dinerData:getProperty("buildL") | ||
653 | + local curLevel = buildL:getv(1, 1) | ||
654 | + role:checkTaskEnter("DinerLevelUp", {level = curLevel}) | ||
655 | + | ||
656 | + role:checkTaskEnter("HeroLvlCollect", {}) | ||
657 | + role:checkTaskEnter("HeroQualityCollect", {}) | ||
658 | + | ||
659 | + local curPopular = role.dinerData:getProperty("popular") | ||
660 | + role:checkTaskEnter("DinerPopular", {count = curPopular}) | ||
661 | + | ||
662 | + local rLevel = role:getProperty("level") | ||
663 | + role:checkTaskEnter("RoleLevelUp", {level = rLevel}) | ||
664 | + | ||
665 | + local towerInfo = role:getProperty("towerInfo") | ||
666 | + role:checkTaskEnter("TowerPass", {count = towerInfo.l, type = 1}) | ||
667 | + --"PvpWin" | ||
668 | + --role:checkTaskEnter("HangPass", {id = 0}) | ||
669 | + role:checkCalendaTask(true, 15, 3) | ||
670 | + role:checkTaskEnter("HeroStarCollect", {}) | ||
671 | + role:checkTaskEnter("RuneQualityCollect", {}) | ||
672 | + | ||
673 | + end, | ||
674 | + ["crossDay"] = function(self, actType, notify, actId) | ||
675 | + local actData = self.owner:getProperty("nbTask") or {} | ||
676 | + local record = actData["r"] or {} | ||
677 | + local actCfg = csvdb["activity_taskCsv"][actId] | ||
678 | + if not actCfg then return end | ||
679 | + local change = false | ||
680 | + for taskId, cfg in pairs(actCfg) do | ||
681 | + if cfg["resetType"] == 1 then -- 每日重置 | ||
682 | + record[taskId] = nil | ||
683 | + actData[taskId] = nil | ||
684 | + change = true | ||
685 | + end | ||
686 | + end | ||
687 | + if change then | ||
688 | + self.owner:updateProperty({field="nbTask", value=actData}) | ||
689 | + end | ||
690 | + end, | ||
691 | + ["crossWeek"] = function(self, actType, notify, actId) | ||
692 | + local actData = self.owner:getProperty("nbTask") or {} | ||
693 | + local record = actData["r"] or {} | ||
694 | + local actCfg = csvdb["activity_taskCsv"][actId] | ||
695 | + if not actCfg then return end | ||
696 | + local change = false | ||
697 | + for taskId, cfg in pairs(actCfg) do | ||
698 | + if cfg["resetType"] == 2 then -- 每周重置 | ||
699 | + record[taskId] = nil | ||
700 | + actData[taskId] = nil | ||
701 | + change = true | ||
702 | + end | ||
703 | + end | ||
704 | + if change then | ||
705 | + self.owner:updateProperty({field="nbTask", value=actData}) | ||
706 | + end | ||
707 | + end, | ||
708 | + ["close"] = function(self, actType, notify) | ||
709 | + self.owner:updateProperty({field="nbTask", value={}}) | ||
710 | + end, | ||
711 | +} | ||
712 | + | ||
713 | +-- 兑换 | ||
714 | +activityFunc[Activity.ActivityType.Exchange] = { | ||
715 | + ["init"] = function(self, actType, isCrossDay, notify, actId) | ||
716 | + local actData = self:getActData(actType) or {} | ||
717 | + actData[actId] = {} | ||
718 | + self:updateActData(actType, actData, not notify) | ||
719 | + end, | ||
720 | + ["login"] = function(self, actType, actId) | ||
721 | + activityFunc[Activity.ActivityType.Exchange]["crossDay"](self, actType, true, actId) | ||
722 | + end, | ||
723 | + ["crossDay"] = function(self, actType, notify, actId) | ||
724 | + local actData = self:getActData(actType) or {} | ||
725 | + local lastTs = actData["ts"] or 0 | ||
726 | + local timeNow = skynet.timex() | ||
727 | + local cfg = csvdb["activity_ctrlCsv"][actId] | ||
728 | + if not cfg then return end | ||
729 | + local refreshTimes = cfg.condition2:toArray(false, "=") | ||
730 | + for i = 1, #refreshTimes do | ||
731 | + local rt = toUnixtime(refreshTimes[i]..string_format("%02x", RESET_TIME)) | ||
732 | + if timeNow >= rt and rt > lastTs then | ||
733 | + lastTs = rt | ||
734 | + actData = {} | ||
735 | + end | ||
736 | + end | ||
737 | + if not next(actData) then | ||
738 | + actData["ts"] = timeNow | ||
739 | + self:updateActData(actType, actData, not notify) | ||
740 | + end | ||
741 | + end, | ||
742 | + ["close"] = function(self, actType, notify, actId) | ||
743 | + local actData = self:getActData(actType) or {} | ||
744 | + actData[actId] = nil | ||
745 | + self:updateActData(actType, actData, not notify) | ||
746 | + end, | ||
747 | +} | ||
748 | + | ||
643 | -- 扭蛋机 | 749 | -- 扭蛋机 |
644 | activityFunc[Activity.ActivityType.Gachakon] = { | 750 | activityFunc[Activity.ActivityType.Gachakon] = { |
645 | ["init"] = function(self, actType, isCrossDay, notify, actId) | 751 | ["init"] = function(self, actType, isCrossDay, notify, actId) |
@@ -942,17 +1048,11 @@ activityFunc[Activity.ActivityType.FriendEnergy] = { | @@ -942,17 +1048,11 @@ activityFunc[Activity.ActivityType.FriendEnergy] = { | ||
942 | 1048 | ||
943 | function Activity:getActFriendNew() | 1049 | function Activity:getActFriendNew() |
944 | local roleId = self.owner:getProperty("id") | 1050 | local roleId = self.owner:getProperty("id") |
945 | - local friendIds = {} | ||
946 | - local friends = redisproxy:hgetall(FRIEND_KEY:format(roleId)) | ||
947 | - for i = 1, #friends , 2 do | ||
948 | - local objId = tonumber(friends[i]) | ||
949 | - friendIds[objId] = 1 | ||
950 | - end | ||
951 | 1051 | ||
952 | local ids = {} | 1052 | local ids = {} |
953 | local members = redisproxy:smembers(FRIEND_ENERGY:format(roleId)) | 1053 | local members = redisproxy:smembers(FRIEND_ENERGY:format(roleId)) |
954 | for _, id in pairs(members) do | 1054 | for _, id in pairs(members) do |
955 | - if friendIds[tonumber(id)] then | 1055 | + if self.owner.friends[tonumber(id)] then |
956 | ids[tonumber(id)] = 1 | 1056 | ids[tonumber(id)] = 1 |
957 | end | 1057 | end |
958 | end | 1058 | end |
@@ -986,7 +1086,7 @@ activityFunc[Activity.ActivityType.Crisis] = { | @@ -986,7 +1086,7 @@ activityFunc[Activity.ActivityType.Crisis] = { | ||
986 | status = -1 | 1086 | status = -1 |
987 | end | 1087 | end |
988 | 1088 | ||
989 | - self.owner:award(reward, {log = {desc = "activity_crisis"}, notNotify = not notify}) | 1089 | + self.owner:award(reward, {log = {desc = "activityCrisis"}, notNotify = not notify}) |
990 | end | 1090 | end |
991 | actData.task[id] = status | 1091 | actData.task[id] = status |
992 | change = true | 1092 | change = true |
src/models/Daily.lua
1 | -- 日常数据 | 1 | -- 日常数据 |
2 | 2 | ||
3 | -local Daily = class("Daily", require("shared.ModelBase")) | 3 | +local Daily = class("Daily", require("shared.ModelBaseMysql")) |
4 | 4 | ||
5 | function Daily:ctor(properties) | 5 | function Daily:ctor(properties) |
6 | Daily.super.ctor(self, properties) | 6 | Daily.super.ctor(self, properties) |
7 | end | 7 | end |
8 | 8 | ||
9 | Daily.schema = { | 9 | Daily.schema = { |
10 | - commentHero = {"string", ""}, -- 单日评论食灵记录 type=1 | 10 | + id = {"number", 0, "pri"}, -- 角色id |
11 | + commentHero = {"string", "", "blob"}, -- 单日评论食灵记录 type=1 | ||
11 | hangQC = {"number", 0}, -- 挂机快速次数 | 12 | hangQC = {"number", 0}, -- 挂机快速次数 |
12 | dinerQC = {"number", 0}, -- 贩卖加速次数 | 13 | dinerQC = {"number", 0}, -- 贩卖加速次数 |
13 | advElC = {"number", 0}, -- 无尽次数(消耗体力) | 14 | advElC = {"number", 0}, -- 无尽次数(消耗体力) |
src/models/Diner.lua
1 | -local Diner = class("Diner", require("shared.ModelBase")) | 1 | +local Diner = class("Diner", require("shared.ModelBaseMysql")) |
2 | 2 | ||
3 | function Diner:ctor(properties) | 3 | function Diner:ctor(properties) |
4 | Diner.super.ctor(self, properties) | 4 | Diner.super.ctor(self, properties) |
5 | end | 5 | end |
6 | 6 | ||
7 | Diner.schema = { | 7 | Diner.schema = { |
8 | + id = {"number", 0, "pri"}, -- 角色id | ||
8 | buildL = {"string", ""}, -- 家具等级 1=1 2=1 3=1 | 9 | buildL = {"string", ""}, -- 家具等级 1=1 2=1 3=1 |
9 | - order = {"string", "[]"}, -- 特殊订单 | ||
10 | - sells = {"string", "[]"}, -- 贩卖位置 | ||
11 | - dishTree = {"string", "1=1 101=1 201=1"}, -- 料理天赋 | ||
12 | - skillTree = {"string", ""}, -- 支援天赋 | 10 | + order = {"string", "[]", "blob"}, -- 特殊订单 |
11 | + sells = {"string", "[]", "blob"}, -- 贩卖位置 | ||
12 | + dishTree = {"string", "1=1 101=1 201=1", "blob"}, -- 料理天赋 | ||
13 | + skillTree = {"string", "", "blob"}, -- 支援天赋 | ||
13 | popular = {"number",0}, -- 累计人气 | 14 | popular = {"number",0}, -- 累计人气 |
14 | expedite = {"number",1}, --每日加速次数 | 15 | expedite = {"number",1}, --每日加速次数 |
15 | gfood = {"table", {}}, -- 愿望食材 {{id = 123, st = 1232144},} | 16 | gfood = {"table", {}}, -- 愿望食材 {{id = 123, st = 1232144},} |
src/models/Email.lua
1 | -local Email = class("Email", require("shared.ModelBase")) | 1 | +local Email = class("Email", require("shared.ModelBaseMysql")) |
2 | 2 | ||
3 | function Email:ctor(properties) | 3 | function Email:ctor(properties) |
4 | Email.super.ctor(self, properties) | 4 | Email.super.ctor(self, properties) |
5 | end | 5 | end |
6 | 6 | ||
7 | Email.schema = { | 7 | Email.schema = { |
8 | - key = {"string"}, -- redis key | ||
9 | - id = {"number", 0}, -- 数据库ID | 8 | + id = {"number", 0, "pri_auto"}, -- 数据库ID |
9 | + roleId = {"number", 0, "index"}, -- 角色 ID | ||
10 | emailId = {"number", 0}, -- 邮件csv ID | 10 | emailId = {"number", 0}, -- 邮件csv ID |
11 | title = {"string", ""}, -- 邮件标题 | 11 | title = {"string", ""}, -- 邮件标题 |
12 | stitle = {"string", ""}, -- 小标题 | 12 | stitle = {"string", ""}, -- 小标题 |
13 | content = {"string", ""}, -- 邮件正文 | 13 | content = {"string", ""}, -- 邮件正文 |
14 | - attachments = {"string", ""}, | 14 | + attachments = {"string", "", 512}, |
15 | status = {"number", 0}, -- 邮件状态: 未读, 已读, 已领取 | 15 | status = {"number", 0}, -- 邮件状态: 未读, 已读, 已领取 |
16 | createtime = {"number", skynet.timex()}, | 16 | createtime = {"number", skynet.timex()}, |
17 | contentPms = {"table", {}}, | 17 | contentPms = {"table", {}}, |
@@ -0,0 +1,15 @@ | @@ -0,0 +1,15 @@ | ||
1 | +local Friend = class("Friend", require("shared.ModelBaseMysql")) | ||
2 | + | ||
3 | +function Friend:ctor(properties) | ||
4 | + Friend.super.ctor(self, properties) | ||
5 | +end | ||
6 | + | ||
7 | +Friend.schema = { | ||
8 | + id = {"number", 0, "pri_auto"}, | ||
9 | + roleid = {"number", 0, "index"}, | ||
10 | + fid = {"number", 0, "index"}, | ||
11 | + isNew = {"number", 1}, | ||
12 | + addTime = {"number", skynet.timex()}, | ||
13 | +} | ||
14 | + | ||
15 | +return Friend | ||
0 | \ No newline at end of file | 16 | \ No newline at end of file |
src/models/Hero.lua
1 | -local Hero = class("Hero", require("shared.ModelBase")) | 1 | +local Hero = class("Hero", require("shared.ModelBaseMysql")) |
2 | 2 | ||
3 | local HeroPlugin = import(".HeroPlugin") | 3 | local HeroPlugin = import(".HeroPlugin") |
4 | HeroPlugin.bind(Hero) | 4 | HeroPlugin.bind(Hero) |
5 | 5 | ||
6 | Hero.schema = { | 6 | Hero.schema = { |
7 | - id = {"number"}, | 7 | + id = {"number", 0, "pri"}, |
8 | + roleid = {"number", 0, "index"}, | ||
8 | type = {"number", 0}, | 9 | type = {"number", 0}, |
9 | level = {"number", 1}, -- 等级 | 10 | level = {"number", 1}, -- 等级 |
10 | breakL = {"number", 0}, -- 突破等级 | 11 | breakL = {"number", 0}, -- 突破等级 |
@@ -37,9 +38,13 @@ function Hero:notifyUpdateProperty(field, newValue, oldValue) | @@ -37,9 +38,13 @@ function Hero:notifyUpdateProperty(field, newValue, oldValue) | ||
37 | self:notifyUpdateProperties(datas) | 38 | self:notifyUpdateProperties(datas) |
38 | end | 39 | end |
39 | 40 | ||
41 | +function Hero:getSimpleHeroId() | ||
42 | + return self:getProperty("id") % (self:getProperty("roleid") * MAX_HERO_NUM) | ||
43 | +end | ||
44 | + | ||
40 | function Hero:notifyUpdateProperties(params) | 45 | function Hero:notifyUpdateProperties(params) |
41 | local updateData = { | 46 | local updateData = { |
42 | - id = self:getProperty("id"), | 47 | + id = self:getSimpleHeroId(), |
43 | datas = params | 48 | datas = params |
44 | } | 49 | } |
45 | SendPacket(actionCodes.Hero_updateProperty, MsgPack.pack(updateData)) | 50 | SendPacket(actionCodes.Hero_updateProperty, MsgPack.pack(updateData)) |
src/models/Order.lua
1 | -local Order = class("Order", require("shared.ModelBase")) | 1 | +local Order = class("Order", require("shared.ModelBaseMysql")) |
2 | 2 | ||
3 | function Order:ctor(properties) | 3 | function Order:ctor(properties) |
4 | - Order.super.ctor(self, properties) | 4 | + Order.super.ctor(self, properties) |
5 | end | 5 | end |
6 | 6 | ||
7 | Order.schema = { | 7 | Order.schema = { |
8 | - key = {"string"}, -- redis key | ||
9 | - order = {"string"}, -- 自己订单号 | 8 | + id = {"number", 0, "pri"}, -- 自己的订单号 |
9 | + roleid = {"number", 0, "index"}, | ||
10 | + --order = {"string"}, -- 自己订单号 | ||
10 | rechargeId = {"number", 0}, | 11 | rechargeId = {"number", 0}, |
11 | transactionId = {"string", ""}, | 12 | transactionId = {"string", ""}, |
12 | createTime = {"number", skynet.timex()}, -- 订单创建时间 | 13 | createTime = {"number", skynet.timex()}, -- 订单创建时间 |
src/models/Role.lua
1 | -local Role = class("Role", require("shared.ModelBase")) | 1 | +local Role = class("Role", require("shared.ModelBaseMysql")) |
2 | 2 | ||
3 | local RoleLog = import(".RoleLog") --日志相关 | 3 | local RoleLog = import(".RoleLog") --日志相关 |
4 | local RolePlugin = import(".RolePlugin") --基础功能 | 4 | local RolePlugin = import(".RolePlugin") --基础功能 |
@@ -25,6 +25,7 @@ function Role:ctor( properties ) | @@ -25,6 +25,7 @@ function Role:ctor( properties ) | ||
25 | self.storeData = nil | 25 | self.storeData = nil |
26 | self.heros = {} | 26 | self.heros = {} |
27 | self.runeBag = {} | 27 | self.runeBag = {} |
28 | + self.friends = {} | ||
28 | self.sparkBag = {} | 29 | self.sparkBag = {} |
29 | self.advData = nil | 30 | self.advData = nil |
30 | self.activity = nil | 31 | self.activity = nil |
@@ -41,11 +42,12 @@ function Role:ctor( properties ) | @@ -41,11 +42,12 @@ function Role:ctor( properties ) | ||
41 | self.sendMailFlag = false --发送邮件标识 | 42 | self.sendMailFlag = false --发送邮件标识 |
42 | end | 43 | end |
43 | 44 | ||
45 | +-- type, default value, key type, length | ||
44 | Role.schema = { | 46 | Role.schema = { |
45 | - id = {"number"}, | 47 | + id = {"number", 0, "pri"}, |
46 | uid = {"string", ""}, | 48 | uid = {"string", ""}, |
47 | name = {"string", ""}, | 49 | name = {"string", ""}, |
48 | - intro = {"string", ""}, | 50 | + intro = {"string", "", "", 1024}, |
49 | headId = {"number", globalCsv.defaultHead}, | 51 | headId = {"number", globalCsv.defaultHead}, |
50 | sid = {"number", 0}, | 52 | sid = {"number", 0}, |
51 | device = {"string", ""}, | 53 | device = {"string", ""}, |
@@ -60,27 +62,29 @@ Role.schema = { | @@ -60,27 +62,29 @@ Role.schema = { | ||
60 | ignoreMt = {"number", 0}, -- 忽略维护拦截 | 62 | ignoreMt = {"number", 0}, -- 忽略维护拦截 |
61 | sversion = {"number", STRUCT_VERSION or 0}, -- 重整数据版本 | 63 | sversion = {"number", STRUCT_VERSION or 0}, -- 重整数据版本 |
62 | timeReset = {"table", {}}, --重置轮回记录 | 64 | timeReset = {"table", {}}, --重置轮回记录 |
65 | + jade = {"number", 0}, -- 虹光玉 | ||
63 | diamond = {"number", 0}, -- 免费钻 | 66 | diamond = {"number", 0}, -- 免费钻 |
64 | reDiamond = {"number", 0}, -- android充值钻 | 67 | reDiamond = {"number", 0}, -- android充值钻 |
65 | reDiamondIos = {"number", 0}, -- ios充值钻 | 68 | reDiamondIos = {"number", 0}, -- ios充值钻 |
66 | setting = {"table", {}}, --设置 | 69 | setting = {"table", {}}, --设置 |
67 | - codeStr = {"string", ""}, --已经领过的礼包码 | 70 | + codeStr = {"string", "", "blob"}, --已经领过的礼包码 |
68 | -- roleInfo | 71 | -- roleInfo |
69 | level = {"number", 1}, | 72 | level = {"number", 1}, |
70 | exp = {"number", 0}, | 73 | exp = {"number", 0}, |
71 | - items = {"string", ""}, | 74 | + items = {"string", "", "blob"}, |
72 | expireItem = {"table", {}}, --物品过期检查 | 75 | expireItem = {"table", {}}, --物品过期检查 |
73 | funcOpen = {"table", {}}, --功能是否开放 | 76 | funcOpen = {"table", {}}, --功能是否开放 |
74 | funcLv = {"table", {}}, --功能等级 | 77 | funcLv = {"table", {}}, --功能等级 |
75 | -- loveStatus = {"string", ""}, --统计角色的最高 好感度等级 类型相关 -- type=loveL type=loveL | 78 | -- loveStatus = {"string", ""}, --统计角色的最高 好感度等级 类型相关 -- type=loveL type=loveL |
76 | crown = {"number", 0}, -- 看伴娘 | 79 | crown = {"number", 0}, -- 看伴娘 |
77 | silent = {"number", 0}, --禁言解禁时间 | 80 | silent = {"number", 0}, --禁言解禁时间 |
81 | + timeGift = {"number", 0}, -- 创建角色时间礼包 | ||
78 | 82 | ||
79 | bagLimit = {"table", globalCsv.store_limit_max}, | 83 | bagLimit = {"table", globalCsv.store_limit_max}, |
80 | 84 | ||
81 | --冒险相关 | 85 | --冒险相关 |
82 | advPass = {"table", {}}, -- 通关记录 {chapterId = layer} | 86 | advPass = {"table", {}}, -- 通关记录 {chapterId = layer} |
83 | - advItems = {"string", ""}, -- 冒险临时背包 | 87 | + advItems = {"string", "", "blob"}, -- 冒险临时背包 |
84 | advInfo = {"table", {}}, -- 冒险关卡信息 | 88 | advInfo = {"table", {}}, -- 冒险关卡信息 |
85 | advTeam = {"table", {}}, -- 冒险玩家队伍信息 | 89 | advTeam = {"table", {}}, -- 冒险玩家队伍信息 |
86 | advHang = {"table", {}}, -- 挂机信息 -- {chapterId = {format = teaminfo, time = endtime}} | 90 | advHang = {"table", {}}, -- 挂机信息 -- {chapterId = {format = teaminfo, time = endtime}} |
@@ -124,8 +128,8 @@ Role.schema = { | @@ -124,8 +128,8 @@ Role.schema = { | ||
124 | workBattle = {"table", {}}, -- 夜间玩法记录 {[1] = 1, [2] = 1, [3] = 1, [4] = 1, round = 10} -- 第N天打了多少次 round 轮次 | 128 | workBattle = {"table", {}}, -- 夜间玩法记录 {[1] = 1, [2] = 1, [3] = 1, [4] = 1, round = 10} -- 第N天打了多少次 round 轮次 |
125 | 129 | ||
126 | --引导相关 | 130 | --引导相关 |
127 | - newerGuide = {"string","1=1"}, -- 新手引导 master=slave | ||
128 | - funcGuide = {"string",""}, -- 功能引导 0=0跳过次数(999永久跳过) 1=1功能1触发情况 | 131 | + newerGuide = {"string","1=1", "", 10}, -- 新手引导 master=slave |
132 | + funcGuide = {"string","", "blob"}, -- 功能引导 0=0跳过次数(999永久跳过) 1=1功能1触发情况 | ||
129 | 133 | ||
130 | pvpTC = {"table", {}}, -- pvp 编队普通 | 134 | pvpTC = {"table", {}}, -- pvp 编队普通 |
131 | pvpTSC = {"table", {}}, -- pvp 他人可读的队伍信息 | 135 | pvpTSC = {"table", {}}, -- pvp 他人可读的队伍信息 |
@@ -189,13 +193,18 @@ Role.schema = { | @@ -189,13 +193,18 @@ Role.schema = { | ||
189 | downCvR = {"number", 0}, -- 下载cv扩展包奖励 | 193 | downCvR = {"number", 0}, -- 下载cv扩展包奖励 |
190 | feedback = {"table", {}}, -- 反馈相关信息 {flag = false, count = 0} flag是否评论过,count 提示次数 | 194 | feedback = {"table", {}}, -- 反馈相关信息 {flag = false, count = 0} flag是否评论过,count 提示次数 |
191 | 195 | ||
192 | - calTask = {"table", {}}, -- 英雄令活动 日历任务活动 | 196 | + calTask = {"table", {}}, -- 英雄帖活动 日历任务活动 |
193 | bcTask = {"table", {}}, -- 英雄令活动 日历任务活动 临时使用 | 197 | bcTask = {"table", {}}, -- 英雄令活动 日历任务活动 临时使用 |
198 | + nbTask = {"table", {}}, -- 新用户活动 | ||
194 | radioTask = {"table", {}}, -- 电台任务 {id = {time=end_ts,heros=heros}} 表crusadeCsv | 199 | radioTask = {"table", {}}, -- 电台任务 {id = {time=end_ts,heros=heros}} 表crusadeCsv |
195 | 200 | ||
196 | seaport = {"table", {}}, -- 海岛贸易季 {time = 1234567890, donate = {}, collect = {[1] = {team = "1=2=3", time = 1234567890}}, shop = {}} | 201 | seaport = {"table", {}}, -- 海岛贸易季 {time = 1234567890, donate = {}, collect = {[1] = {team = "1=2=3", time = 1234567890}}, shop = {}} |
197 | 202 | ||
198 | returner = {"table", {}}, -- 回归者 {time = 12334233423, [1] = 1, [2] = 2, status = {[1] = 1}} | 203 | returner = {"table", {}}, -- 回归者 {time = 12334233423, [1] = 1, [2] = 2, status = {[1] = 1}} |
204 | + | ||
205 | + roleIncre = {"table", {}}, -- 角色英雄,铭文,火花自增序列 {heroId = 1, runeId = 1, sparkId = 1} | ||
206 | + | ||
207 | + unlockChap = {"table", {}}, -- 解锁的章节 | ||
199 | } | 208 | } |
200 | 209 | ||
201 | 210 | ||
@@ -345,6 +354,7 @@ function Role:data() | @@ -345,6 +354,7 @@ function Role:data() | ||
345 | diamond = self:getAllDiamond(), | 354 | diamond = self:getAllDiamond(), |
346 | bagLimit = self:getProperty("bagLimit"), | 355 | bagLimit = self:getProperty("bagLimit"), |
347 | silent = self:getProperty("silent"), | 356 | silent = self:getProperty("silent"), |
357 | + timeGift = self:getProperty("timeGift"), | ||
348 | 358 | ||
349 | advPass = self:getProperty("advPass"), | 359 | advPass = self:getProperty("advPass"), |
350 | advInfo = self:getProperty("advInfo"), | 360 | advInfo = self:getProperty("advInfo"), |
@@ -427,10 +437,13 @@ function Role:data() | @@ -427,10 +437,13 @@ function Role:data() | ||
427 | ctime = self:getProperty("ctime"), | 437 | ctime = self:getProperty("ctime"), |
428 | calTask = self:getProperty("calTask"), | 438 | calTask = self:getProperty("calTask"), |
429 | bcTask = self:getProperty("bcTask"), | 439 | bcTask = self:getProperty("bcTask"), |
440 | + nbTask = self:getProperty("nbTask"), | ||
430 | radioTask = self:getProperty("radioTask"), | 441 | radioTask = self:getProperty("radioTask"), |
431 | 442 | ||
432 | seaport = self:getProperty("seaport"), | 443 | seaport = self:getProperty("seaport"), |
433 | returner = self:getProperty("returner"), | 444 | returner = self:getProperty("returner"), |
445 | + | ||
446 | + unlockChap = self:getProperty("unlockChap"), -- 解锁的章节 | ||
434 | } | 447 | } |
435 | end | 448 | end |
436 | 449 |
src/models/RoleCross.lua
@@ -24,6 +24,20 @@ RoleCross.bind = function (Role) | @@ -24,6 +24,20 @@ RoleCross.bind = function (Role) | ||
24 | return info | 24 | return info |
25 | end | 25 | end |
26 | 26 | ||
27 | + function Role:addFriend(friendId) | ||
28 | + local res = mysqlproxy:query(string.format("SELECT * FROM `Friend` WHERE `roleid` = %s AND `fid` = %s;", self:getProperty("id"), friendId)) | ||
29 | + for _, data in ipairs(res) do | ||
30 | + local friend = require("models.Friend").new({key = string.format("%d",data.id), id = data.id}) | ||
31 | + if friend:load(data) then | ||
32 | + self.friends[friend:getProperty("fid")] = friend | ||
33 | + end | ||
34 | + end | ||
35 | + end | ||
36 | + | ||
37 | + function Role:delFriend(friendId) | ||
38 | + self.friends[friendId] = nil | ||
39 | + end | ||
40 | + | ||
27 | -- 好友队伍战斗信息 | 41 | -- 好友队伍战斗信息 |
28 | function Role:friendBattleInfo() | 42 | function Role:friendBattleInfo() |
29 | return self:getProperty("pvpTBVC") ~= 0 and self:getProperty("pvpTBC") or self:getProperty("hangTB") | 43 | return self:getProperty("pvpTBVC") ~= 0 and self:getProperty("pvpTBC") or self:getProperty("hangTB") |
@@ -231,33 +245,30 @@ local function getRoleKey(roleId) | @@ -231,33 +245,30 @@ local function getRoleKey(roleId) | ||
231 | end | 245 | end |
232 | 246 | ||
233 | function CMD.setProperty(roleId, field, value) | 247 | function CMD.setProperty(roleId, field, value) |
234 | - local value = packRoleField(field, value) | ||
235 | - if not value then return end | ||
236 | - return redisproxy:hset(getRoleKey(roleId), field, value) | 248 | + local tb = {} |
249 | + tb[field] = value | ||
250 | + return CMD.setProperties(roleId, tb) | ||
237 | end | 251 | end |
238 | 252 | ||
239 | 253 | ||
240 | function CMD.setProperties(roleId, fields) | 254 | function CMD.setProperties(roleId, fields) |
241 | - local result = {} | ||
242 | - for k,v in pairs(fields) do | ||
243 | - local value = packRoleField(k, v) | ||
244 | - if value then | ||
245 | - result[#result + 1] = k | ||
246 | - result[#result + 1] = value | ||
247 | - end | ||
248 | - end | ||
249 | - return redisproxy:hmset(getRoleKey(roleId), table.unpack(result)) | 255 | + local role = require("models.Role").new({key = string.format("%s",roleId), id = roleId}) |
256 | + return role:updateFields(fields) | ||
250 | end | 257 | end |
251 | 258 | ||
252 | function CMD.getProperty(roleId, field) | 259 | function CMD.getProperty(roleId, field) |
253 | - return unpackRoleField(field ,redisproxy:hget(getRoleKey(roleId), field)) | 260 | + local ret = CMD.getProperties(roleId, {field}) |
261 | + return ret[field] | ||
254 | end | 262 | end |
255 | 263 | ||
256 | function CMD.getProperties(roleId, fields) | 264 | function CMD.getProperties(roleId, fields) |
257 | - local returnValue = redisproxy:hmget(getRoleKey(roleId), table.unpack(fields)) | 265 | + local role = require("models.Role").new({key = string.format("%s",roleId), id = roleId}) |
258 | local ret = {} | 266 | local ret = {} |
259 | - for index, key in ipairs(fields) do | ||
260 | - ret[key] = unpackRoleField(key, returnValue[index]) | 267 | + local datas = role:loadFields(fields) |
268 | + if datas then | ||
269 | + for index, key in ipairs(fields) do | ||
270 | + ret[key] = unpackRoleField(key, datas[key]) | ||
271 | + end | ||
261 | end | 272 | end |
262 | return ret | 273 | return ret |
263 | end | 274 | end |
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +local RoleIncre = class("RoleIncre", require("shared.ModelBaseMysql")) | ||
2 | + | ||
3 | +function RoleIncre:ctor( properties ) | ||
4 | + RoleIncre.super.ctor(self, properties) | ||
5 | +end | ||
6 | + | ||
7 | + | ||
8 | +RoleIncre.schema = { | ||
9 | + id = {"number", 0, "pri"}, | ||
10 | + heroId = {"number", 0}, | ||
11 | + runeId = {"number", 0}, | ||
12 | + sparkId = {"number", 0}, | ||
13 | +} | ||
14 | + | ||
15 | +function RoleIncre:increBy(keyName, val) | ||
16 | + local curId = self:getProperty(keyName) | ||
17 | + self:setProperty(keyName, curId + val) | ||
18 | + return curId + val | ||
19 | +end | ||
20 | + | ||
21 | +return RoleIncre | ||
0 | \ No newline at end of file | 22 | \ No newline at end of file |
src/models/RoleLog.lua
@@ -59,7 +59,9 @@ local ItemReason = { | @@ -59,7 +59,9 @@ local ItemReason = { | ||
59 | advLevelStage = 143, -- 拾荒活动阶段奖励 | 59 | advLevelStage = 143, -- 拾荒活动阶段奖励 |
60 | towerBnous = 144, -- 爬塔到一定层数对某些功能的奖励 | 60 | towerBnous = 144, -- 爬塔到一定层数对某些功能的奖励 |
61 | unknowShop = 145, -- 未知商店 | 61 | unknowShop = 145, -- 未知商店 |
62 | - | 62 | + convert = 146, -- 钻石兑换其他物品 |
63 | + giftTime = 147, -- 创角后的时间礼包 | ||
64 | + activityCrisis = 148, -- 物资危机奖励 | ||
63 | 65 | ||
64 | advHang = 301, -- 拾荒挂机 | 66 | advHang = 301, -- 拾荒挂机 |
65 | hangBattle = 302, -- 挂机战斗 | 67 | hangBattle = 302, -- 挂机战斗 |
@@ -103,6 +105,7 @@ local ItemReason = { | @@ -103,6 +105,7 @@ local ItemReason = { | ||
103 | calendaTask = 1009, -- 英雄帖 | 105 | calendaTask = 1009, -- 英雄帖 |
104 | actMilecrisis = 1010, -- 物资危机 | 106 | actMilecrisis = 1010, -- 物资危机 |
105 | battleCommandTask = 1011, -- 将军令任务 | 107 | battleCommandTask = 1011, -- 将军令任务 |
108 | + newUserTask = 1012, -- 新玩家任务 | ||
106 | 109 | ||
107 | -- 餐厅 | 110 | -- 餐厅 |
108 | greenHourse = 1101, -- 食材获得 | 111 | greenHourse = 1101, -- 食材获得 |
src/models/RolePlugin.lua
@@ -15,6 +15,8 @@ function RolePlugin.bind(Role) | @@ -15,6 +15,8 @@ function RolePlugin.bind(Role) | ||
15 | self:loadDiner() | 15 | self:loadDiner() |
16 | self:loadActivity() | 16 | self:loadActivity() |
17 | self:loadStoreInfo() | 17 | self:loadStoreInfo() |
18 | + --self:loadRoleIncre() | ||
19 | + self:loadFriends() | ||
18 | self:loadSparks() | 20 | self:loadSparks() |
19 | end | 21 | end |
20 | 22 | ||
@@ -250,7 +252,7 @@ function RolePlugin.bind(Role) | @@ -250,7 +252,7 @@ function RolePlugin.bind(Role) | ||
250 | local headData = csvdb["player_iconCsv"][itemId] | 252 | local headData = csvdb["player_iconCsv"][itemId] |
251 | -- pvp 跨服竞技场奖励 | 253 | -- pvp 跨服竞技场奖励 |
252 | if headData and headData.path == 2 then | 254 | if headData and headData.path == 2 then |
253 | - redisproxy:insertEmail({roleId = self:getProperty("id"), emailId = 19}) | 255 | + mysqlproxy:insertEmail({roleId = self:getProperty("id"), emailId = 19}) |
254 | end | 256 | end |
255 | end | 257 | end |
256 | end | 258 | end |
@@ -459,7 +461,8 @@ function RolePlugin.bind(Role) | @@ -459,7 +461,8 @@ function RolePlugin.bind(Role) | ||
459 | 461 | ||
460 | function Role:getAllDiamond() | 462 | function Role:getAllDiamond() |
461 | local diamond = self:getProperty("sid") == IOS_SID and self:getProperty("reDiamondIos") or self:getProperty("reDiamond") | 463 | local diamond = self:getProperty("sid") == IOS_SID and self:getProperty("reDiamondIos") or self:getProperty("reDiamond") |
462 | - return self:getProperty("diamond") + diamond | 464 | + --return self:getProperty("diamond") + diamond |
465 | + return diamond | ||
463 | end | 466 | end |
464 | 467 | ||
465 | function Role:gainDiamond(params) | 468 | function Role:gainDiamond(params) |
@@ -468,18 +471,18 @@ function RolePlugin.bind(Role) | @@ -468,18 +471,18 @@ function RolePlugin.bind(Role) | ||
468 | if isnan(count) then | 471 | if isnan(count) then |
469 | return false | 472 | return false |
470 | end | 473 | end |
471 | - local origind = self:getProperty("diamond") | 474 | + local origind = 0 -- self:getProperty("diamond") |
472 | local originr = self:getProperty("sid") == IOS_SID and self:getProperty("reDiamondIos") or self:getProperty("reDiamond") | 475 | local originr = self:getProperty("sid") == IOS_SID and self:getProperty("reDiamondIos") or self:getProperty("reDiamond") |
473 | local origin = origind + originr | 476 | local origin = origind + originr |
474 | - if params.isRecharge then | 477 | + --if params.isRecharge then |
475 | if params.sid == IOS_SID then | 478 | if params.sid == IOS_SID then |
476 | self:incrProperty("reDiamondIos", count) | 479 | self:incrProperty("reDiamondIos", count) |
477 | else | 480 | else |
478 | self:incrProperty("reDiamond", count) | 481 | self:incrProperty("reDiamond", count) |
479 | end | 482 | end |
480 | - else | ||
481 | - self:incrProperty("diamond", count) | ||
482 | - end | 483 | + --else |
484 | + --self:incrProperty("diamond", count) | ||
485 | + --end | ||
483 | 486 | ||
484 | self:logItems(ItemId.Diamond, origin, count, params.log) | 487 | self:logItems(ItemId.Diamond, origin, count, params.log) |
485 | if params.log then | 488 | if params.log then |
@@ -508,7 +511,7 @@ function RolePlugin.bind(Role) | @@ -508,7 +511,7 @@ function RolePlugin.bind(Role) | ||
508 | return false | 511 | return false |
509 | end | 512 | end |
510 | local isIos = self:getProperty("sid") == IOS_SID | 513 | local isIos = self:getProperty("sid") == IOS_SID |
511 | - local origind = self:getProperty("diamond") | 514 | + local origind = 0 -- self:getProperty("diamond") |
512 | local originr = isIos and self:getProperty("reDiamondIos") or self:getProperty("reDiamond") | 515 | local originr = isIos and self:getProperty("reDiamondIos") or self:getProperty("reDiamond") |
513 | local origin = origind + originr | 516 | local origin = origind + originr |
514 | 517 | ||
@@ -518,18 +521,20 @@ function RolePlugin.bind(Role) | @@ -518,18 +521,20 @@ function RolePlugin.bind(Role) | ||
518 | if origin < count then | 521 | if origin < count then |
519 | return false | 522 | return false |
520 | end | 523 | end |
521 | - local last = count | ||
522 | - local costFirst = isIos and {"diamond", "reDiamondIos"} or {"diamond", "reDiamond"} | ||
523 | - if params.isRecharge then | ||
524 | - costFirst = isIos and {"reDiamondIos", "diamond"} or {"reDiamond", "diamond"} | ||
525 | - end | ||
526 | - last = math.max(last - self:getProperty(costFirst[1]), 0) | ||
527 | - if last < count then | ||
528 | - self:incrProperty(costFirst[1], last - count) | ||
529 | - end | ||
530 | - if last > 0 then | ||
531 | - self:incrProperty(costFirst[2], -last) | ||
532 | - end | 524 | + local diamondKey = isIos and "reDiamondIos" or "reDiamond" |
525 | + self:incrProperty(diamondKey, -count) | ||
526 | + --local last = count | ||
527 | + --local costFirst = isIos and {"diamond", "reDiamondIos"} or {"diamond", "reDiamond"} | ||
528 | + --if params.isRecharge then | ||
529 | + -- costFirst = isIos and {"reDiamondIos", "diamond"} or {"reDiamond", "diamond"} | ||
530 | + --end | ||
531 | + --last = math.max(last - self:getProperty(costFirst[1]), 0) | ||
532 | + --if last < count then | ||
533 | + -- self:incrProperty(costFirst[1], last - count) | ||
534 | + --end | ||
535 | + --if last > 0 then | ||
536 | + -- self:incrProperty(costFirst[2], -last) | ||
537 | + --end | ||
533 | 538 | ||
534 | 539 | ||
535 | self:logItems(ItemId.Diamond, origin, count, params.log) | 540 | self:logItems(ItemId.Diamond, origin, count, params.log) |
@@ -551,6 +556,14 @@ function RolePlugin.bind(Role) | @@ -551,6 +556,14 @@ function RolePlugin.bind(Role) | ||
551 | return true | 556 | return true |
552 | end | 557 | end |
553 | 558 | ||
559 | + function Role:increBy(field, val) | ||
560 | + local roleIncre = self:getProperty("roleIncre") | ||
561 | + local curId = roleIncre[field] or 0 | ||
562 | + roleIncre[field] = curId + val | ||
563 | + self:setProperty("roleIncre", roleIncre) | ||
564 | + return curId + val | ||
565 | + end | ||
566 | + | ||
554 | function Role:addHero(params) | 567 | function Role:addHero(params) |
555 | local roleId = self:getProperty("id") | 568 | local roleId = self:getProperty("id") |
556 | local heroType = params.type | 569 | local heroType = params.type |
@@ -558,13 +571,12 @@ function RolePlugin.bind(Role) | @@ -558,13 +571,12 @@ function RolePlugin.bind(Role) | ||
558 | local unitData = csvdb["unitCsv"][heroType] | 571 | local unitData = csvdb["unitCsv"][heroType] |
559 | if not unitData then return false end | 572 | if not unitData then return false end |
560 | 573 | ||
561 | - local heroId = tonum(redisproxy:hincrby(string.format(R_INCR, roleId), "hero", 1)) | ||
562 | - | ||
563 | - redisproxy:sadd(string.format(R_HEROS, roleId), heroId) | 574 | + local heroId = self:increBy("heroId" , 1) |
564 | 575 | ||
565 | local heroInfo = { | 576 | local heroInfo = { |
566 | - key = string.format(R_HERO, roleId, heroId), | ||
567 | - id = heroId, | 577 | + key = string.format("%d",roleId * MAX_HERO_NUM + heroId), |
578 | + id = roleId * MAX_HERO_NUM + heroId, | ||
579 | + roleid = roleId, | ||
568 | type= heroType, | 580 | type= heroType, |
569 | wakeL = globalCsv.unit_wake_initLevel[unitData.rare], | 581 | wakeL = globalCsv.unit_wake_initLevel[unitData.rare], |
570 | } | 582 | } |
@@ -627,27 +639,33 @@ function RolePlugin.bind(Role) | @@ -627,27 +639,33 @@ function RolePlugin.bind(Role) | ||
627 | 639 | ||
628 | function Role:loadHeros() | 640 | function Role:loadHeros() |
629 | local roleId = self:getProperty("id") | 641 | local roleId = self:getProperty("id") |
630 | - local heroIds = redisproxy:smembers(string.format(R_HEROS, roleId)) | ||
631 | - local redret = redisproxy:pipelining(function (red) | ||
632 | - for _, heroId in ipairs(heroIds) do | ||
633 | - red:hgetall(string.format(R_HERO, roleId, heroId)) | ||
634 | - end | ||
635 | - end) | ||
636 | - for index, heroId in ipairs(heroIds) do | ||
637 | - local hero = require("models.Hero").new({key = string.format(R_HERO, roleId, heroId)}) | ||
638 | - if hero:load(table.array2Table(redret[index])) then | 642 | + local res = mysqlproxy:query(string.format("SELECT * FROM `Hero` WHERE `roleid` = %s", roleId)) |
643 | + for _, data in ipairs(res) do | ||
644 | + local hero = require("models.Hero").new({key = string.format("%d",data.id), id=data.id}) | ||
645 | + if hero:load(data) then | ||
639 | hero.owner = self | 646 | hero.owner = self |
640 | - self.heros[tonumber(heroId)] = hero | 647 | + self.heros[hero:getSimpleHeroId()] = hero |
648 | + end | ||
649 | + end | ||
650 | + end | ||
651 | + | ||
652 | + function Role:loadFriends() | ||
653 | + local roleId = self:getProperty("id") | ||
654 | + local res = mysqlproxy:query(string.format("SELECT * FROM `Friend` WHERE `roleid` = %s", roleId)) | ||
655 | + for _, data in ipairs(res) do | ||
656 | + local friend = require("models.Friend").new({key = string.format("%d",data.id), id = data.id}) | ||
657 | + if friend:load(data) then | ||
658 | + self.friends[friend:getProperty("fid")] = friend | ||
641 | end | 659 | end |
642 | end | 660 | end |
643 | end | 661 | end |
644 | 662 | ||
645 | function Role:loadDaily() | 663 | function Role:loadDaily() |
646 | local roleId = self:getProperty("id") | 664 | local roleId = self:getProperty("id") |
647 | - local dataKey = string.format(R_DAILY, roleId) | ||
648 | - self.dailyData = require("models.Daily").new({key = dataKey}) | 665 | + local dataKey = string.format("%d", roleId) |
666 | + self.dailyData = require("models.Daily").new({key = dataKey, id = roleId}) | ||
649 | self.dailyData.owner = self | 667 | self.dailyData.owner = self |
650 | - if not redisproxy:exists(dataKey) then | 668 | + if not self.dailyData:checkKeyExists(dataKey) then |
651 | self.dailyData:create() | 669 | self.dailyData:create() |
652 | else | 670 | else |
653 | self.dailyData:load() | 671 | self.dailyData:load() |
@@ -656,10 +674,10 @@ function RolePlugin.bind(Role) | @@ -656,10 +674,10 @@ function RolePlugin.bind(Role) | ||
656 | 674 | ||
657 | function Role:loadActivity() | 675 | function Role:loadActivity() |
658 | local roleId = self:getProperty("id") | 676 | local roleId = self:getProperty("id") |
659 | - local dataKey = string.format(R_ACTIVITY, roleId) | ||
660 | - self.activity = require("models.Activity").new({key = dataKey}) | 677 | + local dataKey = string.format("%d", roleId) |
678 | + self.activity = require("models.Activity").new({key = dataKey, id = roleId}) | ||
661 | self.activity.owner = self | 679 | self.activity.owner = self |
662 | - if not redisproxy:exists(dataKey) then | 680 | + if not self.activity:checkKeyExists(dataKey) then |
663 | self.activity:create() | 681 | self.activity:create() |
664 | else | 682 | else |
665 | self.activity:load() | 683 | self.activity:load() |
@@ -668,10 +686,10 @@ function RolePlugin.bind(Role) | @@ -668,10 +686,10 @@ function RolePlugin.bind(Role) | ||
668 | 686 | ||
669 | function Role:loadDiner() | 687 | function Role:loadDiner() |
670 | local roleId = self:getProperty("id") | 688 | local roleId = self:getProperty("id") |
671 | - local dataKey = string.format(R_DINER, roleId) | ||
672 | - self.dinerData = require("models.Diner").new({key = dataKey}) | 689 | + local dataKey = string.format("%d", roleId) |
690 | + self.dinerData = require("models.Diner").new({key = dataKey, id = roleId}) | ||
673 | self.dinerData.owner = self | 691 | self.dinerData.owner = self |
674 | - if not redisproxy:exists(dataKey) then | 692 | + if not self.dinerData:checkKeyExists(dataKey) then |
675 | self.dinerData:create() | 693 | self.dinerData:create() |
676 | else | 694 | else |
677 | self.dinerData:load() | 695 | self.dinerData:load() |
@@ -685,16 +703,28 @@ function RolePlugin.bind(Role) | @@ -685,16 +703,28 @@ function RolePlugin.bind(Role) | ||
685 | 703 | ||
686 | function Role:loadStoreInfo() | 704 | function Role:loadStoreInfo() |
687 | local roleId = self:getProperty("id") | 705 | local roleId = self:getProperty("id") |
688 | - local dataKey = string.format(R_STORE, roleId) | ||
689 | - self.storeData = require("models.Store").new({key = dataKey}) | 706 | + local dataKey = string.format("%d", roleId) |
707 | + self.storeData = require("models.Store").new({key = dataKey, id = roleId}) | ||
690 | self.storeData.owner = self | 708 | self.storeData.owner = self |
691 | - if not redisproxy:exists(dataKey) then | 709 | + if not self.storeData:checkKeyExists(dataKey) then |
692 | self.storeData:create() | 710 | self.storeData:create() |
693 | else | 711 | else |
694 | self.storeData:load() | 712 | self.storeData:load() |
695 | end | 713 | end |
696 | end | 714 | end |
697 | 715 | ||
716 | + --function Role:loadRoleIncre() | ||
717 | + -- local roleId = self:getProperty("id") | ||
718 | + -- local dataKey = string.format("%d", roleId) | ||
719 | + -- self.roleIncre = require("models.RoleIncre").new({key = dataKey, id = roleId}) | ||
720 | + -- self.roleIncre.owner = self | ||
721 | + -- if not self.roleIncre:checkKeyExists(dataKey) then | ||
722 | + -- self.roleIncre:create() | ||
723 | + -- else | ||
724 | + -- self.roleIncre:load() | ||
725 | + -- end | ||
726 | + --end | ||
727 | + | ||
698 | function Role:addEquip(equipType, equipLv, count, pms) | 728 | function Role:addEquip(equipType, equipLv, count, pms) |
699 | pms = pms or {} | 729 | pms = pms or {} |
700 | if count ~= count then return end | 730 | if count ~= count then return end |
@@ -750,34 +780,24 @@ function RolePlugin.bind(Role) | @@ -750,34 +780,24 @@ function RolePlugin.bind(Role) | ||
750 | 780 | ||
751 | function Role:loadRunes() | 781 | function Role:loadRunes() |
752 | local roleId = self:getProperty("id") | 782 | local roleId = self:getProperty("id") |
753 | - local runeIds = redisproxy:smembers(string.format(R_RUNEIDS, roleId)) | ||
754 | - local redret = redisproxy:pipelining(function (red) | ||
755 | - for _, runeId in ipairs(runeIds) do | ||
756 | - red:hgetall(string.format(R_RUNE, roleId, runeId)) | ||
757 | - end | ||
758 | - end) | ||
759 | - for index, runeId in ipairs(runeIds) do | ||
760 | - local rune = require("models.Rune").new({key = string.format(R_RUNE, roleId, runeId)}) | ||
761 | - if rune:load(table.array2Table(redret[index])) then | 783 | + local res = mysqlproxy:query(string.format("SELECT * FROM `Rune` WHERE `roleid` = %s", roleId)) |
784 | + for _, data in ipairs(res) do | ||
785 | + local rune = require("models.Rune").new({key = string.format("%d",data.uid), uid=data.uid}) | ||
786 | + if rune:load(data) then | ||
762 | rune.owner = self | 787 | rune.owner = self |
763 | - self.runeBag[tonumber(runeId)] = rune | 788 | + self.runeBag[data.uid] = rune |
764 | end | 789 | end |
765 | end | 790 | end |
766 | end | 791 | end |
767 | 792 | ||
768 | function Role:loadSparks() | 793 | function Role:loadSparks() |
769 | local roleId = self:getProperty("id") | 794 | local roleId = self:getProperty("id") |
770 | - local sparkIds = redisproxy:smembers(string.format(R_SPARKIDS, roleId)) | ||
771 | - local redret = redisproxy:pipelining(function (red) | ||
772 | - for _, sparkId in ipairs(sparkIds) do | ||
773 | - red:hgetall(string.format(R_SPARK, roleId, sparkId)) | ||
774 | - end | ||
775 | - end) | ||
776 | - for index, sparkId in ipairs(sparkIds) do | ||
777 | - local spark = require("models.Spark").new({key = string.format(R_SPARK, roleId, sparkId)}) | ||
778 | - if spark:load(table.array2Table(redret[index])) then | 795 | + local res = mysqlproxy:query(string.format("SELECT * FROM `Spark` WHERE `roleid` = %s", roleId)) |
796 | + for _, data in ipairs(res) do | ||
797 | + local spark = require("models.Spark").new({key = string.format("%d",data.id), id=data.id}) | ||
798 | + if spark:load(data) then | ||
779 | spark.owner = self | 799 | spark.owner = self |
780 | - self.sparkBag[tonumber(sparkId)] = spark | 800 | + self.sparkBag[data.id] = spark |
781 | end | 801 | end |
782 | end | 802 | end |
783 | end | 803 | end |
@@ -791,18 +811,17 @@ function RolePlugin.bind(Role) | @@ -791,18 +811,17 @@ function RolePlugin.bind(Role) | ||
791 | if not data then return 3 end | 811 | if not data then return 3 end |
792 | 812 | ||
793 | local roleId = self:getProperty("id") | 813 | local roleId = self:getProperty("id") |
794 | - local runeUid = tonum(redisproxy:hincrby(string.format(R_INCR, roleId), "rune", 1)) | 814 | + local runeUid = self:increBy("runeId" , 1) |
795 | 815 | ||
796 | - redisproxy:sadd(string.format(R_RUNEIDS, roleId), runeUid) | ||
797 | - | ||
798 | - local heroInfo = { | ||
799 | - key = string.format(R_RUNE, roleId, runeUid), | ||
800 | - uid = runeUid, | 816 | + local runeInfo = { |
817 | + key = string.format("%d",roleId * MAX_RUNE_NUM + runeUid), | ||
818 | + uid = roleId * MAX_RUNE_NUM + runeUid, | ||
819 | + roleid = roleId, | ||
801 | type = params.type, | 820 | type = params.type, |
802 | id = params.id, | 821 | id = params.id, |
803 | } | 822 | } |
804 | 823 | ||
805 | - local newRune = require("models.Rune").new(heroInfo) | 824 | + local newRune = require("models.Rune").new(runeInfo) |
806 | newRune:create() | 825 | newRune:create() |
807 | newRune:generateAttrs() | 826 | newRune:generateAttrs() |
808 | newRune.owner = self | 827 | newRune.owner = self |
@@ -845,16 +864,14 @@ function RolePlugin.bind(Role) | @@ -845,16 +864,14 @@ function RolePlugin.bind(Role) | ||
845 | if not data then return 3 end | 864 | if not data then return 3 end |
846 | 865 | ||
847 | local roleId = self:getProperty("id") | 866 | local roleId = self:getProperty("id") |
848 | - local sparkUid = tonum(redisproxy:hincrby(string.format(R_INCR, roleId), "spark", 1)) | ||
849 | - | ||
850 | - redisproxy:sadd(string.format(R_SPARKIDS, roleId), sparkUid) | 867 | + local sparkUid = self:increBy("sparkId" , 1) |
851 | 868 | ||
852 | local sparkInfo = { | 869 | local sparkInfo = { |
853 | - key = string.format(R_SPARK, roleId, sparkUid), | ||
854 | - id = sparkUid, | 870 | + key = string.format("%d",roleId * MAX_SPARK_NUM + sparkUid), |
871 | + id = roleId * MAX_SPARK_NUM + sparkUid, | ||
872 | + roleid = roleId, | ||
855 | cfg_id = params.id, | 873 | cfg_id = params.id, |
856 | } | 874 | } |
857 | - | ||
858 | local newSpark = require("models.Spark").new(sparkInfo) | 875 | local newSpark = require("models.Spark").new(sparkInfo) |
859 | newSpark:create() | 876 | newSpark:create() |
860 | newSpark:addAttr(data.attr:toNumMap()) | 877 | newSpark:addAttr(data.attr:toNumMap()) |
@@ -865,13 +882,14 @@ function RolePlugin.bind(Role) | @@ -865,13 +882,14 @@ function RolePlugin.bind(Role) | ||
865 | table.insert(response, newSpark:data()) | 882 | table.insert(response, newSpark:data()) |
866 | SendPacket(actionCodes.Role_loadSparks, MsgPack.pack(response)) | 883 | SendPacket(actionCodes.Role_loadSparks, MsgPack.pack(response)) |
867 | end | 884 | end |
868 | - --self:checkTaskEnter("AddRune", {id = params.id, type = params.type, rarity = data.rarity}, params.notNotify) | 885 | + |
886 | + --self:checkTaskEnter("AddSpark", {id = params.id, type = params.type, rarity = data.rarity}, params.notNotify) | ||
869 | 887 | ||
870 | self:logItems(params.id, 0, 1, params.log) | 888 | self:logItems(params.id, 0, 1, params.log) |
871 | if params.log then | 889 | if params.log then |
872 | local log = clone(params.log) | 890 | local log = clone(params.log) |
873 | if log["cint1"] or log["cint2"] or log["cint3"] then | 891 | if log["cint1"] or log["cint2"] or log["cint3"] then |
874 | - print("addRune error log have cint1 or cint2 or cint3 ", debug.traceback()) | 892 | + print("addSpark error log have cint1 or cint2 or cint3 ", debug.traceback()) |
875 | end | 893 | end |
876 | 894 | ||
877 | log["cint1"] = sparkUid | 895 | log["cint1"] = sparkUid |
@@ -916,12 +934,9 @@ function RolePlugin.bind(Role) | @@ -916,12 +934,9 @@ function RolePlugin.bind(Role) | ||
916 | end | 934 | end |
917 | end | 935 | end |
918 | 936 | ||
919 | - redisproxy:pipelining(function (red) | ||
920 | - for _, sparkId in pairs(bDel) do | ||
921 | - red:del(string.format(R_SPARK, roleId, sparkId)) | ||
922 | - red:srem(string.format(R_SPARKIDS, roleId), sparkId) | ||
923 | - end | ||
924 | - end) | 937 | + -- delete spark |
938 | + mysqlproxy:query(string.format("DELETE FROM `Spark` WHERE `id` in (%s)", table.concat(bDel, ","))) | ||
939 | + | ||
925 | local response = {} | 940 | local response = {} |
926 | for _, sparkId in pairs(bDel) do | 941 | for _, sparkId in pairs(bDel) do |
927 | table.insert(response, {id = sparkId, bDel = true}) | 942 | table.insert(response, {id = sparkId, bDel = true}) |
@@ -959,12 +974,9 @@ function RolePlugin.bind(Role) | @@ -959,12 +974,9 @@ function RolePlugin.bind(Role) | ||
959 | end | 974 | end |
960 | end | 975 | end |
961 | 976 | ||
962 | - redisproxy:pipelining(function (red) | ||
963 | - for _, runeId in pairs(bDel) do | ||
964 | - red:del(string.format(R_RUNE, roleId, runeId)) | ||
965 | - red:srem(string.format(R_RUNEIDS, roleId), runeId) | ||
966 | - end | ||
967 | - end) | 977 | + -- delete rune |
978 | + mysqlproxy:query(string.format("DELETE FROM `Rune` WHERE `uid` in (%s)", table.concat(bDel, ","))) | ||
979 | + | ||
968 | local response = {} | 980 | local response = {} |
969 | for _, runeId in pairs(bDel) do | 981 | for _, runeId in pairs(bDel) do |
970 | table.insert(response, {uid = runeId, bDel = true}) | 982 | table.insert(response, {uid = runeId, bDel = true}) |
@@ -1399,7 +1411,7 @@ function RolePlugin.bind(Role) | @@ -1399,7 +1411,7 @@ function RolePlugin.bind(Role) | ||
1399 | end | 1411 | end |
1400 | 1412 | ||
1401 | local carbonCsv = csvdb["idle_battleCsv"] | 1413 | local carbonCsv = csvdb["idle_battleCsv"] |
1402 | - local expCarbonId = self:getProperty("hangInfo").expCarbonId | 1414 | + local expData = self:getProperty("hangInfo").expData or {} |
1403 | local taskCsv = csvdb["seaport_taskCsv"] | 1415 | local taskCsv = csvdb["seaport_taskCsv"] |
1404 | local endTime = openTime0 + 86400 * 2 | 1416 | local endTime = openTime0 + 86400 * 2 |
1405 | local reward = {} | 1417 | local reward = {} |
@@ -1412,7 +1424,7 @@ function RolePlugin.bind(Role) | @@ -1412,7 +1424,7 @@ function RolePlugin.bind(Role) | ||
1412 | local teams = collect[slot].team | 1424 | local teams = collect[slot].team |
1413 | local time = collect[slot].time | 1425 | local time = collect[slot].time |
1414 | if time + data.time <= endTime then | 1426 | if time + data.time <= endTime then |
1415 | - if not carbonCsv[expCarbonId] then break end | 1427 | + --if not carbonCsv[expCarbonId] then break end |
1416 | 1428 | ||
1417 | local totalCoef = 0 | 1429 | local totalCoef = 0 |
1418 | for _, heroId in ipairs(teams:toArray(true,"=")) do | 1430 | for _, heroId in ipairs(teams:toArray(true,"=")) do |
@@ -1429,8 +1441,8 @@ function RolePlugin.bind(Role) | @@ -1429,8 +1441,8 @@ function RolePlugin.bind(Role) | ||
1429 | bigSuccess = true | 1441 | bigSuccess = true |
1430 | end | 1442 | end |
1431 | 1443 | ||
1432 | - local money = math.ceil(carbonCsv[expCarbonId].money / 5 * data.time * data.money_clear) | ||
1433 | - local exp = math.ceil(carbonCsv[expCarbonId].exp / 5 * data.time * data.exp_clear) | 1444 | + local money = math.ceil((expData.money or 0) / 5 * data.time * data.money_clear) |
1445 | + local exp = math.ceil((expData.exp or 0) / 5 * data.time * data.exp_clear) | ||
1434 | local itemReward = data.item_clear_special:toNumMap() | 1446 | local itemReward = data.item_clear_special:toNumMap() |
1435 | itemReward[ItemId.Gold] = (itemReward[ItemId.Gold] or 0) + money | 1447 | itemReward[ItemId.Gold] = (itemReward[ItemId.Gold] or 0) + money |
1436 | itemReward[ItemId.Exp] = (itemReward[ItemId.Exp] or 0) + exp | 1448 | itemReward[ItemId.Exp] = (itemReward[ItemId.Exp] or 0) + exp |
@@ -1891,6 +1903,21 @@ function RolePlugin.bind(Role) | @@ -1891,6 +1903,21 @@ function RolePlugin.bind(Role) | ||
1891 | function Role:onRecoverTimer(now) | 1903 | function Role:onRecoverTimer(now) |
1892 | self:updateTimeReset(now, true) | 1904 | self:updateTimeReset(now, true) |
1893 | self:checkNewEvent(now) | 1905 | self:checkNewEvent(now) |
1906 | + self:saveRoleData() | ||
1907 | + end | ||
1908 | + | ||
1909 | + function Role:saveRoleData() | ||
1910 | + self:update() | ||
1911 | + local objs = {self.activity, self.dailyData, self.dinerData, self.storeData, self.roleIncre} | ||
1912 | + for _, info in ipairs(objs) do | ||
1913 | + info:update() | ||
1914 | + end | ||
1915 | + local tbObjs = {self.friends, self.heros, self.runeBag, self.sparkBag} | ||
1916 | + for _, tbObj in ipairs(tbObjs) do | ||
1917 | + for _, info in pairs(tbObj) do | ||
1918 | + info:update() | ||
1919 | + end | ||
1920 | + end | ||
1894 | end | 1921 | end |
1895 | 1922 | ||
1896 | local function breath(sec, name) | 1923 | local function breath(sec, name) |
@@ -1950,21 +1977,10 @@ function RolePlugin.bind(Role) | @@ -1950,21 +1977,10 @@ function RolePlugin.bind(Role) | ||
1950 | end | 1977 | end |
1951 | 1978 | ||
1952 | local roleId = self:getProperty("id") | 1979 | local roleId = self:getProperty("id") |
1953 | - local email_rds = string.format(R_EMAIL, roleId) | ||
1954 | - | ||
1955 | - local emailIds = redisproxy:lrange(email_rds, 0, EMAIL_LIMIT - 1) or {} | ||
1956 | - local redret = redisproxy:pipelining(function (red) | ||
1957 | - for _, id in ipairs(emailIds) do | ||
1958 | - red:hget(string.format(R_EMAIL_ITEM, roleId, id), "status") | ||
1959 | - end | ||
1960 | - end) | 1980 | + local res = mysqlproxy:query(string.format("SELECT `id` FROM `Email` WHERE `roleId` = %d AND `status` = 0;", roleId)) |
1961 | 1981 | ||
1962 | self.SendMailFlag = false | 1982 | self.SendMailFlag = false |
1963 | - for index, id in ipairs(emailIds) do | ||
1964 | - if tonumber(redret[index]) == 0 then | ||
1965 | - return true | ||
1966 | - end | ||
1967 | - end | 1983 | + return next(res) |
1968 | end | 1984 | end |
1969 | 1985 | ||
1970 | checks["pvphg"] = function() | 1986 | checks["pvphg"] = function() |
@@ -2095,24 +2111,27 @@ function RolePlugin.bind(Role) | @@ -2095,24 +2111,27 @@ function RolePlugin.bind(Role) | ||
2095 | if not self.activity:isOpenById(rechargeData.activity_id, "ActShopGoods") then return "" end | 2111 | if not self.activity:isOpenById(rechargeData.activity_id, "ActShopGoods") then return "" end |
2096 | end | 2112 | end |
2097 | 2113 | ||
2098 | - local orderId = redisproxy:hget(string.format(R_ORDERS, roleId), rechargeId) | ||
2099 | - if orderId then | ||
2100 | - local orderObject = require("models.Order").new({ key = string.format(R_ORDER, roleId, orderId) }) | 2114 | + local orderId = redisproxy:hget(string.format(R_ORDERS, roleId), rechargeId) |
2115 | + if orderId then | ||
2116 | + local uid = orderId * MAX_SVR_ID + serverId | ||
2117 | + local orderObject = require("models.Order").new({ key = string.format("%d", uid), id = uid }) | ||
2101 | if orderObject:load() and orderObject:getProperty("rechargeId") == rechargeId and math.abs(skynet.timex() - orderObject:getProperty("createTime")) < 5 * 60 then | 2118 | if orderObject:load() and orderObject:getProperty("rechargeId") == rechargeId and math.abs(skynet.timex() - orderObject:getProperty("createTime")) < 5 * 60 then |
2102 | - return string.format("%d_%d_%d", serverId, roleId, orderId) | 2119 | + return string.format("%d", uid) |
2103 | end | 2120 | end |
2104 | - end | 2121 | + end |
2105 | 2122 | ||
2106 | orderId = redisproxy:hincrby("autoincrement_set", "order", 1) | 2123 | orderId = redisproxy:hincrby("autoincrement_set", "order", 1) |
2107 | - local partnerOrderId = string.format("%d_%d_%d", serverId, roleId, orderId) | 2124 | + local uid = orderId * MAX_SVR_ID + serverId |
2125 | + local partnerOrderId = string.format("%d", orderId * MAX_SVR_ID + serverId) | ||
2108 | local orderKey = string.format(R_ORDER, roleId, orderId) | 2126 | local orderKey = string.format(R_ORDER, roleId, orderId) |
2109 | redisproxy:del(orderKey) -- 删掉可能有了 | 2127 | redisproxy:del(orderKey) -- 删掉可能有了 |
2110 | local order = require("models.Order").new({ | 2128 | local order = require("models.Order").new({ |
2111 | - key = orderKey, | ||
2112 | - order = partnerOrderId, | 2129 | + key = partnerOrderId, |
2130 | + id = tonum(partnerOrderId), | ||
2113 | rechargeId = rechargeId, | 2131 | rechargeId = rechargeId, |
2114 | createTime = skynet.timex(), | 2132 | createTime = skynet.timex(), |
2115 | transactionId = transactionId, | 2133 | transactionId = transactionId, |
2134 | + roleid = roleId, | ||
2116 | sid = self:getProperty("sid"), | 2135 | sid = self:getProperty("sid"), |
2117 | choose = choose or "", | 2136 | choose = choose or "", |
2118 | }) | 2137 | }) |
@@ -2135,10 +2154,8 @@ function RolePlugin.bind(Role) | @@ -2135,10 +2154,8 @@ function RolePlugin.bind(Role) | ||
2135 | --]] | 2154 | --]] |
2136 | function Role:updatePurchaseOrder(partnerOrderStr, platformOrder, status) | 2155 | function Role:updatePurchaseOrder(partnerOrderStr, platformOrder, status) |
2137 | if not partnerOrderStr then return false end | 2156 | if not partnerOrderStr then return false end |
2138 | - local _, _, orderId = string.match(partnerOrderStr, "(.+)_(.+)_(.+)") | ||
2139 | - | ||
2140 | local roleId = self:getProperty("id") | 2157 | local roleId = self:getProperty("id") |
2141 | - local orderObject = require("models.Order").new({ key = string.format(R_ORDER, roleId, orderId) }) | 2158 | + local orderObject = require("models.Order").new({ key = string.format("%d", partnerOrderStr), id = tonum(partnerOrderStr)}) |
2142 | if not orderObject:load() then | 2159 | if not orderObject:load() then |
2143 | return false | 2160 | return false |
2144 | end | 2161 | end |
@@ -2147,6 +2164,14 @@ function RolePlugin.bind(Role) | @@ -2147,6 +2164,14 @@ function RolePlugin.bind(Role) | ||
2147 | local dataSet = csvdb["shop_rechargeCsv"][rechargeId] | 2164 | local dataSet = csvdb["shop_rechargeCsv"][rechargeId] |
2148 | local sid = orderObject:getProperty("sid") | 2165 | local sid = orderObject:getProperty("sid") |
2149 | 2166 | ||
2167 | + if roleId ~= orderObject:getProperty("roleid") then | ||
2168 | + skynet.error(string.format("[recharge] with a different role id, current roleId:%d, order role Id:%d, order cpOrder: %s, platformOrder : %s, hadPlatformOrder: %s, id: %s, overTime : %s", | ||
2169 | + roleId, orderObject:getProperty("roleid"), | ||
2170 | + partnerOrderStr, platformOrder, orderObject:getProperty("transactionId"), rechargeId, orderObject:getProperty("finishTime") | ||
2171 | + )) | ||
2172 | + return false, "unknow" | ||
2173 | + end | ||
2174 | + | ||
2150 | if orderObject:getProperty("finishTime") > 0 then | 2175 | if orderObject:getProperty("finishTime") > 0 then |
2151 | skynet.error(string.format("[recharge] is a finish order cpOrder: %s, platformOrder : %s, hadPlatformOrder: %s, id: %s, overTime : %s", | 2176 | skynet.error(string.format("[recharge] is a finish order cpOrder: %s, platformOrder : %s, hadPlatformOrder: %s, id: %s, overTime : %s", |
2152 | partnerOrderStr, platformOrder, orderObject:getProperty("transactionId"), rechargeId, orderObject:getProperty("finishTime") | 2177 | partnerOrderStr, platformOrder, orderObject:getProperty("transactionId"), rechargeId, orderObject:getProperty("finishTime") |
@@ -2168,6 +2193,8 @@ function RolePlugin.bind(Role) | @@ -2168,6 +2193,8 @@ function RolePlugin.bind(Role) | ||
2168 | redisproxy:hdel(string.format(R_ORDERS, roleId), rechargeId) | 2193 | redisproxy:hdel(string.format(R_ORDERS, roleId), rechargeId) |
2169 | end | 2194 | end |
2170 | 2195 | ||
2196 | + orderObject:update() | ||
2197 | + | ||
2171 | if status ~= "unknow" then | 2198 | if status ~= "unknow" then |
2172 | self:log("setOrder", { | 2199 | self:log("setOrder", { |
2173 | order_status = ({success = 100, finsh = 200, fail = 300})[status] or 1000, -- "订单状态:100 - 开始下单(玩家还未开始付费行为记录)200 - 支付完成并发货(SDK通知可以发货时记录),300 - 订单被取消,1000 - 其他" | 2200 | order_status = ({success = 100, finsh = 200, fail = 300})[status] or 1000, -- "订单状态:100 - 开始下单(玩家还未开始付费行为记录)200 - 支付完成并发货(SDK通知可以发货时记录),300 - 订单被取消,1000 - 其他" |
@@ -2313,7 +2340,7 @@ function RolePlugin.bind(Role) | @@ -2313,7 +2340,7 @@ function RolePlugin.bind(Role) | ||
2313 | for k, v in pairs(tgift) do | 2340 | for k, v in pairs(tgift) do |
2314 | gift = gift .. k.."="..v.." " | 2341 | gift = gift .. k.."="..v.." " |
2315 | end | 2342 | end |
2316 | - redisproxy:insertEmail({roleId = self:getProperty("id"), emailId = mailId, createtime = createTime, attachments = gift, contentPms = contentPms}) | 2343 | + mysqlproxy:insertEmail({roleId = self:getProperty("id"), emailId = mailId, createtime = createTime, attachments = gift, contentPms = contentPms}) |
2317 | self.sendMailFlag = true | 2344 | self.sendMailFlag = true |
2318 | end | 2345 | end |
2319 | 2346 |
src/models/RoleTask.lua
@@ -60,6 +60,7 @@ local TaskType = { | @@ -60,6 +60,7 @@ local TaskType = { | ||
60 | AdvUseItem = 419, -- 使用道具 - itemId count | 60 | AdvUseItem = 419, -- 使用道具 - itemId count |
61 | AdvBuild = 420, -- 建筑交互 - buildId | 61 | AdvBuild = 420, -- 建筑交互 - buildId |
62 | AdvKill = 421, -- 拾荒击败敌人 | 62 | AdvKill = 421, -- 拾荒击败敌人 |
63 | + AdvHangTime = 422, -- 代理拾荒时间 - count | ||
63 | 64 | ||
64 | --爬塔相关 | 65 | --爬塔相关 |
65 | TowerPass = 501, -- 爬塔通关 - level | 66 | TowerPass = 501, -- 爬塔通关 - level |
@@ -110,6 +111,7 @@ local TaskType = { | @@ -110,6 +111,7 @@ local TaskType = { | ||
110 | WeekTask = 910, -- 完成每周活跃任务 | 111 | WeekTask = 910, -- 完成每周活跃任务 |
111 | ActBattlePass = 911, -- 活动关卡通关 -- chapterId | 112 | ActBattlePass = 911, -- 活动关卡通关 -- chapterId |
112 | Appoint = 912, -- 触发限时礼包,指定id | 113 | Appoint = 912, -- 触发限时礼包,指定id |
114 | + Rename = 913, -- 重命名 | ||
113 | 115 | ||
114 | --功能未实现 todo | 116 | --功能未实现 todo |
115 | AdvShop = 1002, -- 冒险商城 | 117 | AdvShop = 1002, -- 冒险商城 |
@@ -235,6 +237,7 @@ local SudokuListener = { | @@ -235,6 +237,7 @@ local SudokuListener = { | ||
235 | [TaskType.PvpWin] = {{15, 1}}, | 237 | [TaskType.PvpWin] = {{15, 1}}, |
236 | [TaskType.DinerTalentUp] = {{16, f("level"), f("type")}}, | 238 | [TaskType.DinerTalentUp] = {{16, f("level"), f("type")}}, |
237 | [TaskType.RuneUp] = {{17, 1}}, | 239 | [TaskType.RuneUp] = {{17, 1}}, |
240 | + [TaskType.Rename] = {{20, 1}}, | ||
238 | } | 241 | } |
239 | } | 242 | } |
240 | 243 | ||
@@ -253,6 +256,8 @@ local ActivityListener = { | @@ -253,6 +256,8 @@ local ActivityListener = { | ||
253 | [TaskType.AdvCostPower] = {{Activity.ActivityType.Crisis, 3, f("count")}}, | 256 | [TaskType.AdvCostPower] = {{Activity.ActivityType.Crisis, 3, f("count")}}, |
254 | [TaskType.DailyTask] = {{Activity.ActivityType.CommonSignIn, f("pre"), f("cur")}}, | 257 | [TaskType.DailyTask] = {{Activity.ActivityType.CommonSignIn, f("pre"), f("cur")}}, |
255 | [TaskType.AddItem] = {{Activity.ActivityType.BattleCommand, f("id"), f("count")}}, | 258 | [TaskType.AddItem] = {{Activity.ActivityType.BattleCommand, f("id"), f("count")}}, |
259 | + [TaskType.AdvHangTime] = {{Activity.ActivityType.Crisis, 4, f("count")}}, | ||
260 | + [TaskType.AdvKillBoss] = {{Activity.ActivityType.Crisis, 5}}, | ||
256 | } | 261 | } |
257 | } | 262 | } |
258 | 263 | ||
@@ -321,6 +326,11 @@ local BattleCommandTaskListener = { | @@ -321,6 +326,11 @@ local BattleCommandTaskListener = { | ||
321 | listen = CalendaTaskListener["listen"] | 326 | listen = CalendaTaskListener["listen"] |
322 | } | 327 | } |
323 | 328 | ||
329 | +local NewUserTaskListener = { | ||
330 | + func = "checkNewUserTask", | ||
331 | + listen = CalendaTaskListener["listen"] | ||
332 | +} | ||
333 | + | ||
324 | local ReturnerTask = { | 334 | local ReturnerTask = { |
325 | func = "checkReturnerTask", | 335 | func = "checkReturnerTask", |
326 | listen = CalendaTaskListener["listen"] | 336 | listen = CalendaTaskListener["listen"] |
@@ -336,6 +346,7 @@ local TaskListeners = { | @@ -336,6 +346,7 @@ local TaskListeners = { | ||
336 | CalendaTaskListener, | 346 | CalendaTaskListener, |
337 | BattleCommandTaskListener, | 347 | BattleCommandTaskListener, |
338 | ReturnerTask, | 348 | ReturnerTask, |
349 | + NewUserTaskListener, | ||
339 | } | 350 | } |
340 | 351 | ||
341 | local RoleTask = {} | 352 | local RoleTask = {} |
@@ -833,6 +844,19 @@ function RoleTask.bind(Role) | @@ -833,6 +844,19 @@ function RoleTask.bind(Role) | ||
833 | self:checkActTask(notNotify, keyName, actData, mainType, subType, param1, param2) | 844 | self:checkActTask(notNotify, keyName, actData, mainType, subType, param1, param2) |
834 | end | 845 | end |
835 | 846 | ||
847 | + function Role:checkNewUserTask(notNotify, mainType, subType, param1, param2) | ||
848 | + --print("check new user task", mainType, subType, param1, param2) | ||
849 | + local actEnum = "NewUserTask" | ||
850 | + local keyName = "nbTask" | ||
851 | + if not self.activity then return end | ||
852 | + local open, actId = self.activity:isOpen(actEnum) | ||
853 | + local actData = csvdb["activity_ctrlCsv"][actId] | ||
854 | + if not actData then return end | ||
855 | + if not open then return end | ||
856 | + | ||
857 | + self:checkActTask(notNotify, keyName, actData, mainType, subType, param1, param2) | ||
858 | + end | ||
859 | + | ||
836 | function Role:checkReturnerTask(notNotify, mainType, subType, param1, param2) | 860 | function Role:checkReturnerTask(notNotify, mainType, subType, param1, param2) |
837 | -- print("check returner task", mainType, subType, param1, param2) | 861 | -- print("check returner task", mainType, subType, param1, param2) |
838 | local returner = self:getProperty("returner") or {} | 862 | local returner = self:getProperty("returner") or {} |
src/models/Rune.lua
1 | -local Rune = class("Rune", require("shared.ModelBase")) | 1 | +local Rune = class("Rune", require("shared.ModelBaseMysql")) |
2 | Rune.schema = { | 2 | Rune.schema = { |
3 | - uid = {"number"}, -- 唯一自增id | 3 | + uid = {"number", 0, "pri"}, -- 唯一自增id |
4 | + roleid = {"number", 0, "index"}, | ||
4 | type = {"number"}, -- 装备位置 | 5 | type = {"number"}, -- 装备位置 |
5 | id = {"number"}, | 6 | id = {"number"}, |
6 | level = {"number", 0}, -- 等级 | 7 | level = {"number", 0}, -- 等级 |
src/models/Spark.lua
1 | -local Spark = class("Spark", require("shared.ModelBase")) | 1 | +local Spark = class("Spark", require("shared.ModelBaseMysql")) |
2 | Spark.schema = { | 2 | Spark.schema = { |
3 | - id = {"number"}, -- 唯一自增id | 3 | + id = {"number", 0, "pri"}, -- 唯一自增id |
4 | + roleid = {"number", 0, "index"}, -- 唯一自增id | ||
4 | cfg_id = {"number"}, | 5 | cfg_id = {"number"}, |
5 | level = {"number", 0}, -- 等级 | 6 | level = {"number", 0}, -- 等级 |
6 | attrs = {"table", {}} -- 基础属性值 id=value | 7 | attrs = {"table", {}} -- 基础属性值 id=value |
src/models/Store.lua
1 | -- 商店数据 | 1 | -- 商店数据 |
2 | 2 | ||
3 | -local Store = class("Store", require("shared.ModelBase")) | 3 | +local Store = class("Store", require("shared.ModelBaseMysql")) |
4 | 4 | ||
5 | function Store:ctor(properties) | 5 | function Store:ctor(properties) |
6 | Store.super.ctor(self, properties) | 6 | Store.super.ctor(self, properties) |
@@ -33,6 +33,7 @@ ActGoodsType = { | @@ -33,6 +33,7 @@ ActGoodsType = { | ||
33 | } | 33 | } |
34 | 34 | ||
35 | Store.schema = { | 35 | Store.schema = { |
36 | + id = {"number", 0, "pri"}, -- 角色id | ||
36 | buyR = {"table", {}}, -- 购买商品记录 {id=count} | 37 | buyR = {"table", {}}, -- 购买商品记录 {id=count} |
37 | payR = {"table", {}}, -- 充值记录 {id=count} | 38 | payR = {"table", {}}, -- 充值记录 {id=count} |
38 | growFund = {"number", 0}, -- 成长基金 | 39 | growFund = {"number", 0}, -- 成长基金 |
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/dbseed.lua
@@ -4,44 +4,250 @@ require "GlobalVar" | @@ -4,44 +4,250 @@ require "GlobalVar" | ||
4 | require "RedisKeys" | 4 | require "RedisKeys" |
5 | require "ProtocolCode" | 5 | require "ProtocolCode" |
6 | require "skynet.manager" | 6 | require "skynet.manager" |
7 | +require "utils.MysqlUtil" | ||
7 | 8 | ||
8 | skynet = require "skynet" | 9 | skynet = require "skynet" |
9 | 10 | ||
10 | redisproxy = require("shared.redisproxy") | 11 | redisproxy = require("shared.redisproxy") |
12 | +mysqlproxy = require "shared.mysqlproxy" | ||
11 | 13 | ||
12 | SendPacket = function ( ... ) end | 14 | SendPacket = function ( ... ) end |
13 | 15 | ||
16 | +local function initSeaportTask() | ||
17 | + local keys = {[SEAPORT_TRADE_TASK_1] = "seaport_task_1", [SEAPORT_TRADE_TASK_2] = "seaport_task_2"} | ||
18 | + | ||
19 | + for key, tb_name in pairs(keys) do | ||
20 | + local res = mysqlproxy:query(string.format("SELECT `id`,`value` FROM %s;", tb_name)) | ||
21 | + for _, v in pairs(res) do | ||
22 | + redisproxy:hset(key, v.id, v.value) | ||
23 | + end | ||
24 | + end | ||
25 | +end | ||
26 | + | ||
14 | local function initRedisDb( ... ) | 27 | local function initRedisDb( ... ) |
28 | + local function initAutoIncrementUid(tbName, keyName, fieldName) | ||
29 | + if not fieldName then fieldName = "value" end | ||
30 | + local mysqlVal = getDbCfgVal(tbName, keyName, fieldName) | ||
31 | + if not mysqlVal then | ||
32 | + skynet.error(string.format("get db cfg fail, table %s, key %s, field %s", tbName, keyName, fieldName)) | ||
33 | + return | ||
34 | + end | ||
35 | + local redisVal = tonum(redisproxy:hget(tbName, keyName)) | ||
36 | + if redisVal < mysqlVal then | ||
37 | + redisproxy:hset(tbName, keyName, mysqlVal) | ||
38 | + end | ||
39 | + end | ||
40 | + | ||
41 | + initAutoIncrementUid("autoincrement_set", "role") | ||
42 | + initAutoIncrementUid("autoincrement_set", "union") | ||
43 | + initAutoIncrementUid("autoincrement_set", "order") | ||
44 | + initAutoIncrementUid("autoincrement_set", "email") | ||
45 | + initAutoIncrementUid("autoincrement_set", "emailTimestamp") | ||
46 | + initAutoIncrementUid("autoincrement_set", "delay_email") | ||
47 | + initAutoIncrementUid("autoincrement_set", "stopcreate") | ||
48 | + initAutoIncrementUid("autoincrement_set", "maintain") | ||
49 | + initAutoIncrementUid("autoincrement_set", "seaportTime0") | ||
50 | + initAutoIncrementUid("autoincrement_set", "seaportTime1") | ||
51 | + initAutoIncrementUid("autoincrement_set", "seaportTime2") | ||
52 | + | ||
53 | + redisproxy:hsetnx("adv_season", "idx", 0) | ||
54 | + redisproxy:hsetnx("adv_season", "chapter", globalCsv.adv_endless_default_chapter) | ||
55 | + redisproxy:hsetnx("adv_season", "overTime", 0) | ||
56 | +end | ||
57 | + | ||
58 | +-- 初始化服务器数据库以及服务器信息表 | ||
59 | +local function initServerDatabase() | ||
60 | + local servId = skynet.getenv("servId") | ||
61 | + mysqlproxy:query(string.format("CREATE DATABASE IF NOT EXISTS server_%s DEFAULT CHARSET = utf8mb4 COLLATE utf8mb4_general_ci;", servId)) | ||
62 | + mysqlproxy:query(string.format("use server_%s", servId)) | ||
63 | + | ||
64 | + -- 服务器信息表 开服时间 | ||
65 | + mysqlproxy:query [[ | ||
66 | + CREATE TABLE IF NOT EXISTS `server_info` ( | ||
67 | + `key` varchar(45) NOT NULL, | ||
68 | + `int_value` int(11) DEFAULT NULL, | ||
69 | + `str_value` varchar(128) DEFAULT NULL, | ||
70 | + PRIMARY KEY (`key`) | ||
71 | + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; | ||
72 | + ]] | ||
73 | + | ||
74 | + local res = mysqlproxy:query("SELECT * FROM `server_info` where `key` = 'server_start';") | ||
75 | + if not next(res) then | ||
76 | + mysqlproxy:query(string.format("INSERT INTO `server_info`(`key`, `str_value`) VALUES('server_start', '%s');", | ||
77 | + os.date("%Y%m%d", skynet.timex()))) | ||
78 | + end | ||
79 | +end | ||
80 | + | ||
81 | +local function initAutoIncreUidTable() | ||
82 | + mysqlproxy:query [[ | ||
83 | + CREATE TABLE IF NOT EXISTS `autoincrement_set` ( | ||
84 | + `key` varchar(45) NOT NULL, | ||
85 | + `value` int(11) DEFAULT NULL, | ||
86 | + PRIMARY KEY (`key`) | ||
87 | + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; | ||
88 | + ]] | ||
15 | local servId = tonumber(skynet.getenv("servId")) | 89 | local servId = tonumber(skynet.getenv("servId")) |
16 | if servId then | 90 | if servId then |
17 | - redisproxy:hsetnx("autoincrement_set", "role", servId * MAX_ROLE_NUM) | ||
18 | - redisproxy:hsetnx("autoincrement_set", "union", servId * MAX_ROLE_NUM) | ||
19 | - redisproxy:hsetnx("autoincrement_set", "trade", servId * MAX_ROLE_NUM * 100) | ||
20 | - redisproxy:hsetnx("autoincrement_set", "email", 0) | ||
21 | - redisproxy:hsetnx("autoincrement_set", "emailTimestamp", 0) | ||
22 | - redisproxy:hsetnx("autoincrement_set", "delay_email", 0) | ||
23 | - redisproxy:hsetnx("adv_season", "idx", 0) | ||
24 | - redisproxy:hsetnx("adv_season", "chapter", globalCsv.adv_endless_default_chapter) | ||
25 | - redisproxy:hsetnx("adv_season", "overTime", 0) | 91 | + local tpl = "INSERT INTO `autoincrement_set`(`key`, `value`) values('%s', %d)" |
92 | + mysqlproxy:query(string.format(tpl, "role", servId * MAX_ROLE_NUM)) | ||
93 | + mysqlproxy:query(string.format(tpl, "union", servId * MAX_ROLE_NUM)) | ||
94 | + mysqlproxy:query(string.format(tpl, "order", 0)) | ||
95 | + mysqlproxy:query(string.format(tpl, "email", 0)) | ||
96 | + mysqlproxy:query(string.format(tpl, "emailTimestamp", 0)) | ||
97 | + mysqlproxy:query(string.format(tpl, "delay_email", 0)) | ||
98 | + mysqlproxy:query(string.format(tpl, "stopcreate", 0)) | ||
99 | + mysqlproxy:query(string.format(tpl, "maintain", 0)) | ||
100 | + mysqlproxy:query(string.format(tpl, "seaportTime0", 0)) | ||
101 | + mysqlproxy:query(string.format(tpl, "seaportTime1", 0)) | ||
102 | + mysqlproxy:query(string.format(tpl, "seaportTime2", 0)) | ||
26 | end | 103 | end |
27 | end | 104 | end |
28 | 105 | ||
106 | +local function initSeaportTable() | ||
107 | + -- 海港贸易任务 | ||
108 | + mysqlproxy:query [[ | ||
109 | + CREATE TABLE IF NOT EXISTS `seaport_task_1` ( | ||
110 | + `id` int NOT NULL, | ||
111 | + `value` int(11) DEFAULT 0, | ||
112 | + PRIMARY KEY (`id`) | ||
113 | + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; | ||
114 | + ]] | ||
115 | + mysqlproxy:query [[ | ||
116 | + CREATE TABLE IF NOT EXISTS `seaport_task_2` ( | ||
117 | + `id` int NOT NULL, | ||
118 | + `value` int(11) DEFAULT 0, | ||
119 | + PRIMARY KEY (`id`) | ||
120 | + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; | ||
121 | + ]] | ||
122 | +end | ||
123 | + | ||
124 | +local function initAdvSeasonTable() | ||
125 | + --mysqlproxy:query [[ | ||
126 | + -- CREATE TABLE IF NOT EXISTS `adv_season` ( | ||
127 | + -- `key` varchar(45) NOT NULL, | ||
128 | + -- `value` int(11) DEFAULT NULL, | ||
129 | + -- PRIMARY KEY (`key`) | ||
130 | + -- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; | ||
131 | + --]] | ||
132 | + --local servId = tonumber(skynet.getenv("servId")) | ||
133 | + --if servId then | ||
134 | + -- local tpl = "INSERT INTO `adv_season`(`key`, `value`) values('%s', %d)" | ||
135 | + | ||
136 | + -- mysqlproxy:query(string.format(tpl, "idx", 0)) | ||
137 | + -- mysqlproxy:query(string.format(tpl, "chapter", globalCsv.adv_endless_default_chapter)) | ||
138 | + -- mysqlproxy:query(string.format(tpl, "overTime", 0)) | ||
139 | + --end | ||
140 | +end | ||
141 | + | ||
142 | +local function checkRoleTables() | ||
143 | + local list = {"Role", "Daily", "Activity", "Diner", "Store", "Hero", "Rune", "Order", "Email", "Friend", "Spark"} | ||
144 | + for _, name in ipairs(list) do | ||
145 | + local obj = require("models."..name).new({key = "key"}) | ||
146 | + print("check table [" .. name .. "] begin.") | ||
147 | + obj:checkTableSchema() | ||
148 | + print("check table [" .. name .. "] end.") | ||
149 | + end | ||
150 | +end | ||
151 | + | ||
152 | +local function createMysqlSp() | ||
153 | + mysqlproxy:query "DROP PROCEDURE IF EXISTS `add_friends`" | ||
154 | + mysqlproxy:query [[ | ||
155 | + CREATE PROCEDURE `add_friends`(IN role_id bigint, IN friend_id bigint, IN add_time int) | ||
156 | + BEGIN | ||
157 | + DECLARE t_error INTEGER DEFAULT 0; | ||
158 | + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET t_error=1; | ||
159 | + | ||
160 | + START TRANSACTION; | ||
161 | + INSERT INTO `Friend`(`roleid`,`fid`,`addTime`) VALUES(role_id, friend_id, add_time); | ||
162 | + INSERT INTO `Friend`(`roleid`,`fid`,`addTime`) VALUES(friend_id, role_id, add_time); | ||
163 | + | ||
164 | + IF t_error = 1 THEN | ||
165 | + ROLLBACK; | ||
166 | + ELSE | ||
167 | + COMMIT; | ||
168 | + END IF; | ||
169 | + select t_error; | ||
170 | + END | ||
171 | + ]] | ||
172 | + | ||
173 | + mysqlproxy:query "DROP PROCEDURE IF EXISTS `del_friends`" | ||
174 | + mysqlproxy:query [[ | ||
175 | + CREATE PROCEDURE `del_friends`(IN role_id bigint, IN friend_id bigint) | ||
176 | + BEGIN | ||
177 | + DECLARE t_error INTEGER DEFAULT 0; | ||
178 | + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET t_error=1; | ||
179 | + | ||
180 | + START TRANSACTION; | ||
181 | + DELETE FROM `Friend` WHERE `roleid` = role_id AND `fid` = friend_id; | ||
182 | + DELETE FROM `Friend` WHERE `roleid` = friend_id AND `fid` = role_id; | ||
183 | + | ||
184 | + IF t_error = 1 THEN | ||
185 | + ROLLBACK; | ||
186 | + ELSE | ||
187 | + COMMIT; | ||
188 | + END IF; | ||
189 | + select t_error; | ||
190 | + END | ||
191 | + ]] | ||
192 | +end | ||
193 | + | ||
194 | + | ||
29 | local steps = { | 195 | local steps = { |
30 | [1] = { | 196 | [1] = { |
31 | - handler = initRedisDb, | ||
32 | - desc = "initialize redis database " | ||
33 | - } | 197 | + handler = initServerDatabase, |
198 | + desc = "initialize server database " | ||
199 | + }, | ||
200 | + [2] = { | ||
201 | + handler = initAutoIncreUidTable, | ||
202 | + desc = "initialize auto_increment_uid table " | ||
203 | + }, | ||
204 | + [3] = { | ||
205 | + handler = initAdvSeasonTable, | ||
206 | + desc = "initialize adv_season table " | ||
207 | + }, | ||
208 | + [4] = { | ||
209 | + handler = checkRoleTables, | ||
210 | + desc = "check role tables " | ||
211 | + }, | ||
212 | + [5] = { | ||
213 | + handler = createMysqlSp, | ||
214 | + desc = "create mysql store procedure " | ||
215 | + }, | ||
216 | + [6] = { | ||
217 | + handler = initSeaportTable, | ||
218 | + desc = "initialize seaport table " | ||
219 | + }, | ||
34 | } | 220 | } |
35 | 221 | ||
36 | -skynet.start(function () | ||
37 | - redisproxy = require("shared.redisproxy") | ||
38 | - | ||
39 | - local new = redisproxy:hsetnx("autoincrement_set", "server_start", os.date("%Y%m%d", skynet.timex())) == 1 | ||
40 | - if not new then | ||
41 | - print("server has been initialized...") | ||
42 | - skynet.exit() | ||
43 | - return | 222 | +local function loadAllUserInfo() |
223 | + local maxId = 0 | ||
224 | + local sql = "SELECT `id`, `uid`, `name` FROM `Role` WHERE `id` > %d ORDER BY `id` LIMIT 1000;" | ||
225 | + while true do | ||
226 | + local res = mysqlproxy:query(string.format(sql, maxId)) | ||
227 | + if not next(res) then | ||
228 | + return | ||
229 | + else | ||
230 | + for _, info in ipairs(res) do | ||
231 | + if info["id"] > maxId then | ||
232 | + maxId = info["id"] | ||
233 | + end | ||
234 | + redisproxy:pipelining(function (red) | ||
235 | + local dbName = string.upper(info["name"]) | ||
236 | + red:set(string.format("user:%s", dbName), info["id"]) | ||
237 | + red:set(string.format("uid:%s", info["uid"]), dbName) | ||
238 | + end) | ||
239 | + end | ||
240 | + end | ||
44 | end | 241 | end |
242 | +end | ||
243 | + | ||
244 | +skynet.start(function () | ||
245 | + --local new = redisproxy:hsetnx("autoincrement_set", "server_start", os.date("%Y%m%d", skynet.timex())) == 1 | ||
246 | + --if not new then | ||
247 | + -- print("server has been initialized...") | ||
248 | + -- skynet.exit() | ||
249 | + -- return | ||
250 | + --end | ||
45 | csvdb = require "shared.csvdata" | 251 | csvdb = require "shared.csvdata" |
46 | globalCsv = csvdb["GlobalDefineCsv"] | 252 | globalCsv = csvdb["GlobalDefineCsv"] |
47 | 253 | ||
@@ -50,5 +256,8 @@ skynet.start(function () | @@ -50,5 +256,8 @@ skynet.start(function () | ||
50 | action.handler() | 256 | action.handler() |
51 | print(action.desc .. "finished ...") | 257 | print(action.desc .. "finished ...") |
52 | end | 258 | end |
259 | + initRedisDb() | ||
260 | + initSeaportTask() -- 海港任务数据初始化 | ||
261 | + loadAllUserInfo() | ||
53 | skynet.exit() | 262 | skynet.exit() |
54 | end) | 263 | end) |
55 | \ No newline at end of file | 264 | \ No newline at end of file |
src/services/globald.lua
@@ -2,12 +2,14 @@ local skynet = require "skynet" | @@ -2,12 +2,14 @@ local skynet = require "skynet" | ||
2 | local harbor = require "skynet.harbor" | 2 | local harbor = require "skynet.harbor" |
3 | local json = require("shared.json") | 3 | local json = require("shared.json") |
4 | local redisproxy = require("shared.redisproxy") | 4 | local redisproxy = require("shared.redisproxy") |
5 | +local mysqlproxy = require("shared.mysqlproxy") | ||
5 | 6 | ||
6 | require "shared.init" | 7 | require "shared.init" |
7 | require "utils.init" | 8 | require "utils.init" |
8 | require "RedisKeys" | 9 | require "RedisKeys" |
9 | require "skynet.manager" | 10 | require "skynet.manager" |
10 | require "GlobalVar" | 11 | require "GlobalVar" |
12 | +require "utils.MysqlUtil" | ||
11 | 13 | ||
12 | 14 | ||
13 | local ipairs = ipairs | 15 | local ipairs = ipairs |
@@ -18,6 +20,7 @@ local string_format = string.format | @@ -18,6 +20,7 @@ local string_format = string.format | ||
18 | 20 | ||
19 | local CHECK_MAIL_STATUS_INTERVAL = 100 * 60 | 21 | local CHECK_MAIL_STATUS_INTERVAL = 100 * 60 |
20 | local CHECK_BATTLE_ACT_CLOSE_INTERVAL = 100 * 1 | 22 | local CHECK_BATTLE_ACT_CLOSE_INTERVAL = 100 * 1 |
23 | +local SAVE_AUTOINCREMENT_SET_INTERVAL = 100 * 2 | ||
21 | local function mailQuene() | 24 | local function mailQuene() |
22 | local delayEmail = tonum(redisproxy:hget("autoincrement_set", "delay_email")) | 25 | local delayEmail = tonum(redisproxy:hget("autoincrement_set", "delay_email")) |
23 | if delayEmail == 0 then | 26 | if delayEmail == 0 then |
@@ -133,7 +136,7 @@ local function check_battle_act_close() | @@ -133,7 +136,7 @@ local function check_battle_act_close() | ||
133 | rankIndex = rankIndex + 1 | 136 | rankIndex = rankIndex + 1 |
134 | for _, cfg in pairs(actData) do | 137 | for _, cfg in pairs(actData) do |
135 | if rankIndex <= cfg.rank then | 138 | if rankIndex <= cfg.rank then |
136 | - redisproxy:insertEmail({ | 139 | + mysqlproxy:insertEmail({ |
137 | roleId = roleId, | 140 | roleId = roleId, |
138 | emailId = cfg.email_1, | 141 | emailId = cfg.email_1, |
139 | attachments = cfg.reward_1, | 142 | attachments = cfg.reward_1, |
@@ -153,6 +156,48 @@ local function check_battle_act_close() | @@ -153,6 +156,48 @@ local function check_battle_act_close() | ||
153 | skynet.timeout(CHECK_BATTLE_ACT_CLOSE_INTERVAL, check_battle_act_close) | 156 | skynet.timeout(CHECK_BATTLE_ACT_CLOSE_INTERVAL, check_battle_act_close) |
154 | end | 157 | end |
155 | 158 | ||
159 | +local function save_autoincrement_timer() | ||
160 | + local function saveUidToMysql(tbName, keyName, fieldName, ignore) | ||
161 | + if not fieldName then fieldName = "value" end | ||
162 | + local mysqlVal = getDbCfgVal(tbName, keyName, fieldName) or 0 | ||
163 | + local redisVal = tonum(redisproxy:hget(tbName, keyName)) | ||
164 | + if (not ignore) and redisVal > mysqlVal then | ||
165 | + setDbCfgVal(tbName, keyName, fieldName, redisVal) | ||
166 | + end | ||
167 | + end | ||
168 | + | ||
169 | + saveUidToMysql("autoincrement_set", "role") | ||
170 | + saveUidToMysql("autoincrement_set", "union") | ||
171 | + saveUidToMysql("autoincrement_set", "order") | ||
172 | + saveUidToMysql("autoincrement_set", "email") | ||
173 | + saveUidToMysql("autoincrement_set", "emailTimestamp") | ||
174 | + saveUidToMysql("autoincrement_set", "delay_email") | ||
175 | + saveUidToMysql("autoincrement_set", "stopcreate", true) | ||
176 | + saveUidToMysql("autoincrement_set", "maintain", true) | ||
177 | + saveUidToMysql("autoincrement_set", "seaportTime0", true) | ||
178 | + saveUidToMysql("autoincrement_set", "seaportTime1", true) | ||
179 | + saveUidToMysql("autoincrement_set", "seaportTime2", true) | ||
180 | + | ||
181 | + skynet.timeout(SAVE_AUTOINCREMENT_SET_INTERVAL, save_autoincrement_timer) | ||
182 | +end | ||
183 | + | ||
184 | +local function save_seaport_task() | ||
185 | + local keys = {[SEAPORT_TRADE_TASK_1] = "seaport_task_1", [SEAPORT_TRADE_TASK_2] = "seaport_task_2"} | ||
186 | + local sql = "INSERT INTO `%s` VALUES (%d, %d) ON DUPLICATE KEY UPDATE `value` = %d;" | ||
187 | + for k, tb_name in pairs(keys) do | ||
188 | + local data = redisproxy:hgetall(k) | ||
189 | + if not next(data) then | ||
190 | + mysqlproxy:query(string_format("DELETE FROM %s;", tb_name)) | ||
191 | + end | ||
192 | + local infos = tarr2tab(data) | ||
193 | + for id, value in pairs(infos) do | ||
194 | + mysqlproxy:query(string_format(sql, tb_name, id, value, value)) | ||
195 | + end | ||
196 | + end | ||
197 | + | ||
198 | + skynet.timeout(SAVE_AUTOINCREMENT_SET_INTERVAL, save_seaport_task) | ||
199 | +end | ||
200 | + | ||
156 | -- @desc: 检查海港贸易开启、关闭 | 201 | -- @desc: 检查海港贸易开启、关闭 |
157 | local function check_trade_seaport_status() | 202 | local function check_trade_seaport_status() |
158 | local nowTime = skynet.timex() | 203 | local nowTime = skynet.timex() |
@@ -286,7 +331,9 @@ function CMD.start() | @@ -286,7 +331,9 @@ function CMD.start() | ||
286 | math.randomInit(skynet.timex()) | 331 | math.randomInit(skynet.timex()) |
287 | check_mail_queue() | 332 | check_mail_queue() |
288 | --check_battle_act_close() | 333 | --check_battle_act_close() |
334 | + save_autoincrement_timer() | ||
289 | check_trade_seaport_status() | 335 | check_trade_seaport_status() |
336 | + save_seaport_task() | ||
290 | check_trade_seaport_donate() | 337 | check_trade_seaport_donate() |
291 | check_work_battle() | 338 | check_work_battle() |
292 | end | 339 | end |
@@ -0,0 +1,45 @@ | @@ -0,0 +1,45 @@ | ||
1 | +local skynet = require "skynet" | ||
2 | +require "skynet.manager" | ||
3 | +local mysql = require "skynet.db.mysql" | ||
4 | + | ||
5 | +local db | ||
6 | +local idx = ... | ||
7 | +local command = {} | ||
8 | + | ||
9 | +function command.open(conf) | ||
10 | + local function on_connect(db) | ||
11 | + local servId = skynet.getenv("servId") | ||
12 | + db:query("set charset utf8mb4"); | ||
13 | + db:query(string.format("use server_%s", servId)) | ||
14 | + end | ||
15 | + local servId = skynet.getenv("servId") | ||
16 | + db=mysql.connect({ | ||
17 | + host=conf.host, | ||
18 | + port=conf.port, | ||
19 | + database= "mysql", | ||
20 | + user=conf.user, | ||
21 | + password=conf.pwd, | ||
22 | + max_packet_size = 5 * 1024 * 1024, | ||
23 | + on_connect = on_connect | ||
24 | + }) | ||
25 | + if not db then | ||
26 | + print("failed to connect") | ||
27 | + end | ||
28 | +end | ||
29 | + | ||
30 | +skynet.start(function() | ||
31 | + skynet.dispatch("lua", function(session, address, cmd, ...) | ||
32 | + if cmd == "open" then | ||
33 | + local f = command[string.lower(cmd)] | ||
34 | + skynet.ret(skynet.pack(f(...))) | ||
35 | + elseif string.lower(cmd) == "quote_sql_str" then | ||
36 | + skynet.ret(skynet.pack(db[string.lower(cmd)](...))) | ||
37 | + else | ||
38 | + skynet.ret(skynet.pack(db[string.lower(cmd)](db, ...))) | ||
39 | + end | ||
40 | + end) | ||
41 | + skynet.info_func(function() | ||
42 | + return skynet.stat("mqlen") | ||
43 | + end) | ||
44 | + skynet.register(".mysql" .. idx) | ||
45 | +end) | ||
0 | \ No newline at end of file | 46 | \ No newline at end of file |
@@ -0,0 +1,512 @@ | @@ -0,0 +1,512 @@ | ||
1 | +local ModelBaseMysql = class("ModelBaseMysql") | ||
2 | +ModelBaseMysql.key = "key" | ||
3 | +ModelBaseMysql.schema = {} | ||
4 | + | ||
5 | +local string_format = string.format | ||
6 | +local table_insert = table.insert | ||
7 | +local table_unpack = table.unpack | ||
8 | +local assert = assert | ||
9 | +local next = next | ||
10 | +local ipairs = ipairs | ||
11 | +local pairs = pairs | ||
12 | +local tostring = tostring | ||
13 | +local tonumber = tonumber | ||
14 | +local mysqlproxy = mysqlproxy | ||
15 | + | ||
16 | +local function filterProperties(properties, filter) | ||
17 | + for i, field in ipairs(filter) do | ||
18 | + properties[field] = nil | ||
19 | + end | ||
20 | +end | ||
21 | + | ||
22 | +function ModelBaseMysql:ctor(properties) | ||
23 | + self.cacheFields = {} --缓存字段 不更新数据库的字段 | ||
24 | + | ||
25 | + self[self.class.key .. "_"] = properties[self.class.key] --数据库key | ||
26 | + properties[self.class.key] = nil | ||
27 | + | ||
28 | + if not self:isValidKey() then | ||
29 | + print(string_format("%s [%s:key] should be give in new(ctor)", tostring(self), self.class.__cname)) | ||
30 | + return | ||
31 | + end | ||
32 | + | ||
33 | + if type(properties) ~= "table" then properties = {} end | ||
34 | + self:loadProperties(properties) --缺少的域将设置默认值 | ||
35 | + self:getPriKey() | ||
36 | +end | ||
37 | + | ||
38 | +--[[-- | ||
39 | + | ||
40 | +返回对象的 ID 值。 | ||
41 | + | ||
42 | +**Returns:** | ||
43 | + | ||
44 | +- ID 值 | ||
45 | + | ||
46 | +]] | ||
47 | +function ModelBaseMysql:getKey() | ||
48 | + local id = self[self.class.key .. "_"] | ||
49 | + assert(id ~= nil, string_format("%s [%s:getKey()] Invalid key", tostring(self), self.class.__cname)) | ||
50 | + return id | ||
51 | +end | ||
52 | + | ||
53 | +function ModelBaseMysql:getPriKey() | ||
54 | + for k, v in pairs(self.class.schema) do | ||
55 | + local objType, def, keyType, length = table_unpack(v) | ||
56 | + if keyType == "pri" or keyType == "pri_auto" then | ||
57 | + self.pri_key = k | ||
58 | + break | ||
59 | + end | ||
60 | + end | ||
61 | +end | ||
62 | + | ||
63 | +function ModelBaseMysql:load(properties) | ||
64 | + if not self:isValidKey() then | ||
65 | + print(string_format("%s [%s:id] should be set before load", tostring(self), self.class.__cname)) | ||
66 | + return false | ||
67 | + end | ||
68 | + local load = false | ||
69 | + if not properties then | ||
70 | + properties = mysqlproxy:query(string_format("SELECT * from `%s` where `%s` = %s;", self.class.__cname, self.pri_key, self:getKey())) | ||
71 | + load = true | ||
72 | + end | ||
73 | + if not next(properties) then return false end | ||
74 | + | ||
75 | + local data = load and properties[1] or properties | ||
76 | + | ||
77 | + self:loadProperties(data) | ||
78 | + | ||
79 | + self:onLoad() | ||
80 | + | ||
81 | + return true | ||
82 | +end | ||
83 | + | ||
84 | +--创建model对应的redis数据, 必须已经设置了ID | ||
85 | +function ModelBaseMysql:create() | ||
86 | + if not self:isValidKey() then | ||
87 | + print(string_format("%s [%s:key] should be set before create", tostring(self), self.class.__cname)) | ||
88 | + return nil | ||
89 | + end | ||
90 | + | ||
91 | + self:save() | ||
92 | + self:onCreate() | ||
93 | + | ||
94 | + return self | ||
95 | +end | ||
96 | + | ||
97 | +-- save 忽略 缓存配置 | ||
98 | +function ModelBaseMysql:save() | ||
99 | + local redisProperties = self:getProperties() | ||
100 | + | ||
101 | + local params = {} | ||
102 | + for fieldName, value in pairs(redisProperties) do | ||
103 | + local propname = fieldName .. "_" | ||
104 | + if self.class.schema[fieldName][1] == "table" then | ||
105 | + if not next(self[propname]) then | ||
106 | + params[fieldName] = "NULL" | ||
107 | + else | ||
108 | + local result = mysqlproxy:quote_sql_str(MsgPack.pack(self[propname])) | ||
109 | + --params[fieldName] = "'" .. MsgPack.pack(self[propname]) .. "'" | ||
110 | + params[fieldName] = result | ||
111 | + end | ||
112 | + elseif self.class.schema[fieldName][1] == "string" then | ||
113 | + local result = mysqlproxy:quote_sql_str(self[propname]) | ||
114 | + --params[fieldName] = "'" .. self[propname] .. "'" | ||
115 | + params[fieldName] = result | ||
116 | + else | ||
117 | + params[fieldName] = self[propname] | ||
118 | + end | ||
119 | + end | ||
120 | + if next(params) then | ||
121 | + -- insert update | ||
122 | + local sql = "INSERT INTO `%s` (%s) VALUES (%s) ON DUPLICATE KEY UPDATE %s;" | ||
123 | + local tbName = self.class.__cname | ||
124 | + local key_list = "" | ||
125 | + local value_list = "" | ||
126 | + local update_list = "" | ||
127 | + for k, v in pairs(params) do | ||
128 | + if key_list ~= "" then | ||
129 | + key_list = key_list .. "," | ||
130 | + end | ||
131 | + if value_list ~= "" then | ||
132 | + value_list = value_list .. "," | ||
133 | + end | ||
134 | + if update_list ~= "" then | ||
135 | + update_list = update_list .. "," | ||
136 | + end | ||
137 | + | ||
138 | + key_list = key_list .. "`" .. k .. "`" | ||
139 | + value_list = value_list .. v | ||
140 | + update_list = update_list .. "`" .. k .. "`=" .. v | ||
141 | + end | ||
142 | + sql = string_format(sql, tbName, key_list, value_list, update_list) | ||
143 | + local res = mysqlproxy:query(sql) | ||
144 | + if res["errno"] then | ||
145 | + skynet.error(sql) | ||
146 | + skynet.error(res["err"]) | ||
147 | + end | ||
148 | + end | ||
149 | +end | ||
150 | + | ||
151 | +--[[-- | ||
152 | + | ||
153 | +确定对象是否设置了有效的 key。 | ||
154 | + | ||
155 | +]] | ||
156 | +function ModelBaseMysql:isValidKey() | ||
157 | + local propname = self.class.key .. "_" | ||
158 | + local key = self[propname] | ||
159 | + return type(key) == "string" and key ~= "" | ||
160 | +end | ||
161 | + | ||
162 | +--[[-- | ||
163 | + | ||
164 | +加载对象的属性进内存。 | ||
165 | +NOTE: 如果properties缺少schema中的域, 将用默认值来填充 | ||
166 | + | ||
167 | +**Parameters:** | ||
168 | + | ||
169 | +- properties: 包含属性值的数组 | ||
170 | + | ||
171 | +]] | ||
172 | +function ModelBaseMysql:loadProperties(properties) | ||
173 | + assert(type(properties) == "table", "Invalid properties") | ||
174 | + for field, schema in pairs(self.class.schema) do | ||
175 | + local typ, def = table_unpack(schema) | ||
176 | + local propname = field .. "_" | ||
177 | + | ||
178 | + if typ == "table" and type(properties[field]) == "string" then | ||
179 | + properties[field] = MsgPack.unpack(properties[field]) | ||
180 | + end | ||
181 | + | ||
182 | + local val = properties[field] or def | ||
183 | + if val ~= nil then | ||
184 | + if typ == "number" then val = tonumber(val) end | ||
185 | + assert(type(val) == typ, | ||
186 | + string_format("%s [%s:loadProperties()] Type mismatch, %s expected %s, actual is %s", | ||
187 | + tostring(self), self.class.__cname, field, typ, type(val))) | ||
188 | + self[propname] = val | ||
189 | + end | ||
190 | + end | ||
191 | +end | ||
192 | + | ||
193 | +--[[-- | ||
194 | + | ||
195 | +取得对象的属性值。 | ||
196 | + | ||
197 | +**Parameters:** | ||
198 | + | ||
199 | +- fields: 要取得哪些属性的值,如果未指定该参数,则返回 fields 中设定的属性 | ||
200 | +- filter: 要从结果中过滤掉哪些属性,如果未指定则不过滤 | ||
201 | + | ||
202 | +**Returns:** | ||
203 | + | ||
204 | +- 包含属性值的数组 | ||
205 | + | ||
206 | +]] | ||
207 | +function ModelBaseMysql:getProperties(fields, filter) | ||
208 | + local schema = self.class.schema | ||
209 | + if type(fields) ~= "table" then fields = table.keys(self.class.schema) end | ||
210 | + | ||
211 | + local properties = {} | ||
212 | + for i, field in ipairs(fields) do | ||
213 | + local propname = field .. "_" | ||
214 | + local typ = schema[field][1] | ||
215 | + local val = self[propname] | ||
216 | + assert(type(val) == typ, | ||
217 | + string_format("%s [%s:getProperties()] Type mismatch, %s expected %s, actual is %s", | ||
218 | + tostring(self), self.class.__cname, field, typ, type(val))) | ||
219 | + properties[field] = val | ||
220 | + end | ||
221 | + | ||
222 | + if type(filter) == "table" then | ||
223 | + filterProperties(properties, filter) | ||
224 | + end | ||
225 | + | ||
226 | + return properties | ||
227 | +end | ||
228 | + | ||
229 | +function ModelBaseMysql:getProperty(property) | ||
230 | + if type(property) ~= "string" then return nil end | ||
231 | + if not self.class.schema[property] then return nil end | ||
232 | + return self:getProperties({property})[property] | ||
233 | +end | ||
234 | + | ||
235 | +function ModelBaseMysql:setProperty(property, value, forceSave) | ||
236 | + if not self.class.schema[property] then | ||
237 | + print(string_format("%s [%s:setProperty()] Invalid property : %s", | ||
238 | + tostring(self), self.class.__cname, property)) | ||
239 | + return | ||
240 | + end | ||
241 | + | ||
242 | + local typ, def = table_unpack(self.class.schema[property]) | ||
243 | + local propname = property .. "_" | ||
244 | + | ||
245 | + if typ == "number" then value = tonumber(value) end | ||
246 | + if typ == "table" and not value then | ||
247 | + value = self[propname] -- table 可以用自己的缓冲 | ||
248 | + end | ||
249 | + assert(type(value) == typ, | ||
250 | + string_format("%s [%s:setProperties()] Type mismatch, %s expected %s, actual is %s", | ||
251 | + tostring(self), self.class.__cname, property, typ, type(value))) | ||
252 | + | ||
253 | + if typ == "number" or typ == "string" then | ||
254 | + if self[propname] == value then | ||
255 | + return | ||
256 | + end | ||
257 | + end | ||
258 | + self[propname] = value | ||
259 | + --self:save() | ||
260 | + self.cacheFields[property] = self[propname] | ||
261 | + if forceSave then | ||
262 | + self:update() | ||
263 | + end | ||
264 | +end | ||
265 | + | ||
266 | +function ModelBaseMysql:setProperties(fields, forceSave) | ||
267 | + for property, value in pairs(fields) do | ||
268 | + if not self.class.schema[property] then | ||
269 | + print(string_format("%s [%s:setProperty()] Invalid property : %s", | ||
270 | + tostring(self), self.class.__cname, property)) | ||
271 | + else | ||
272 | + local typ, def = table_unpack(self.class.schema[property]) | ||
273 | + local propname = property .. "_" | ||
274 | + if typ == "number" then value = tonumber(value) end | ||
275 | + if typ == "table" and not value then | ||
276 | + value = self[propname] -- table 可以用自己的缓冲 | ||
277 | + end | ||
278 | + assert(type(value) == typ, | ||
279 | + string_format("%s [%s:setProperties()] Type mismatch, %s expected %s, actual is %s", | ||
280 | + tostring(self), self.class.__cname, property, typ, type(value))) | ||
281 | + | ||
282 | + if typ == "number" or typ == "string" then | ||
283 | + if self[propname] == value then | ||
284 | + return | ||
285 | + end | ||
286 | + end | ||
287 | + self[propname] = value | ||
288 | + self.cacheFields[property] = self[propname] | ||
289 | + end | ||
290 | + end | ||
291 | + if forceSave then | ||
292 | + self:update() | ||
293 | + end | ||
294 | + --self:save() | ||
295 | +end | ||
296 | + | ||
297 | +function ModelBaseMysql:incrProperty(property, value, forceSave) | ||
298 | + if not self.class.schema[property] then | ||
299 | + print(string_format("%s [%s:setProperty()] Invalid property : %s", | ||
300 | + tostring(self), self.class.__cname, property)) | ||
301 | + return | ||
302 | + end | ||
303 | + | ||
304 | + local typ, def = table_unpack(self.class.schema[property]) | ||
305 | + local propname = property .. "_" | ||
306 | + | ||
307 | + if typ == "table" or typ == "string" then return end | ||
308 | + if typ == "number" then value = tonumber(value) end | ||
309 | + | ||
310 | + self:setProperty(property, self[propname] + value, forceSave) | ||
311 | +end | ||
312 | + | ||
313 | +function ModelBaseMysql:onLoad() | ||
314 | +end | ||
315 | + | ||
316 | +function ModelBaseMysql:onCreate() | ||
317 | +end | ||
318 | + | ||
319 | +function ModelBaseMysql:checkKeyExists(key) | ||
320 | + local res = mysqlproxy:query(string_format("SELECT * FROM `%s` WHERE `%s` = %s", self.class.__cname, self.pri_key, key)) | ||
321 | + return next(res) | ||
322 | +end | ||
323 | + | ||
324 | +function ModelBaseMysql:checkTableSchema() | ||
325 | + -- 1.检测是否表存在 | ||
326 | + local typeMap = { | ||
327 | + number = {"int", 0}, | ||
328 | + string = {"varchar", "", 128}, | ||
329 | + table = {"blob", "NULL"}, | ||
330 | + pri = {"bigint", 0}, | ||
331 | + } | ||
332 | + local tbName = self.class.__cname | ||
333 | + local create_sql = [[ | ||
334 | + CREATE TABLE IF NOT EXISTS `%s` ( | ||
335 | + %s | ||
336 | + PRIMARY KEY (`%s`)%s | ||
337 | + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; | ||
338 | + ]] | ||
339 | + local index_tpl_str = [[,INDEX `%s_Index` (`%s`)]] | ||
340 | + | ||
341 | + local alter_sql = [[ | ||
342 | + ALTER TABLE `%s` ADD COLUMN ( | ||
343 | + %s | ||
344 | + ) ; | ||
345 | + ]] | ||
346 | + local field_tpl_str = "`%s` %s%s DEFAULT %s" | ||
347 | + local auto_increment_str = "`%s` %s NOT NULL AUTO_INCREMENT" | ||
348 | + local field_str = "" | ||
349 | + | ||
350 | + local res = mysqlproxy:query("desc `".. tbName .. "`;") | ||
351 | + local keyList = {} | ||
352 | + if res["err"] then -- 表不存在 | ||
353 | + local schema = {} | ||
354 | + for k, v in pairs(self.class.schema) do | ||
355 | + local keyType = v[3] | ||
356 | + if keyType == "pri" or keyType == "pri_auto" then | ||
357 | + self.pri_key = k | ||
358 | + table_insert(schema, 1, {k, v}) | ||
359 | + else | ||
360 | + if keyType == "index" then | ||
361 | + table_insert(keyList, k) | ||
362 | + end | ||
363 | + table_insert(schema, {k, v}) | ||
364 | + end | ||
365 | + end | ||
366 | + for _, tbl in ipairs(schema) do | ||
367 | + local k, v = tbl[1], tbl[2] | ||
368 | + local objType, def, keyType, length = table_unpack(v) | ||
369 | + local isAutoPriKey = false | ||
370 | + assert(typeMap[objType], string_format("schema invalid type, %s, %s", tbName, k)) | ||
371 | + -- 主键使用bigint存储 | ||
372 | + if keyType == "pri" then objType = "pri" end | ||
373 | + if keyType == "pri" or keyType == "pri_auto" then | ||
374 | + objType = "pri" | ||
375 | + if keyType == "pri_auto" then | ||
376 | + isAutoPriKey = true | ||
377 | + end | ||
378 | + end | ||
379 | + | ||
380 | + local info = typeMap[objType] | ||
381 | + local suffix = "" | ||
382 | + local fieldType = info[1] | ||
383 | + if objType == "table" or not def or def == "" then def = info[2] end | ||
384 | + if type(def) == "string" and def ~= "NULL" then def = "'" .. def .. "'" end | ||
385 | + if info[3] and not length then length = info[3] end | ||
386 | + -- 设置字段长度 | ||
387 | + if info[3] then suffix = string.format("(%d)", length) end | ||
388 | + -- 很长的string使用blob | ||
389 | + if keyType == "blob" then | ||
390 | + fieldType = keyType | ||
391 | + suffix = "" | ||
392 | + def = "NULL" | ||
393 | + end | ||
394 | + | ||
395 | + if not isAutoPriKey then | ||
396 | + field_str = field_str .. string.format(field_tpl_str..",", k, fieldType, suffix, def) | ||
397 | + else | ||
398 | + field_str = field_str .. string.format(auto_increment_str..",", k, fieldType) | ||
399 | + end | ||
400 | + end | ||
401 | + | ||
402 | + assert(self.pri_key, string_format("table not include primary key, [%s]", tbName)) | ||
403 | + local index_key_str = "" | ||
404 | + for _, k in ipairs(keyList) do | ||
405 | + index_key_str = index_key_str .. string_format(index_tpl_str, k, k) | ||
406 | + end | ||
407 | + -- 创建表格 | ||
408 | + print(string_format(create_sql, tbName, field_str, self.pri_key, index_key_str)) | ||
409 | + mysqlproxy:query(string_format(create_sql, tbName, field_str, self.pri_key, index_key_str)) | ||
410 | + else -- 检测是否有添加新字段 | ||
411 | + local addCol = {} | ||
412 | + local curCols = {} | ||
413 | + for _, col in ipairs(res) do | ||
414 | + curCols[col["Field"]] = 1 | ||
415 | + end | ||
416 | + for k, v in pairs(self.class.schema) do | ||
417 | + local objType, def, keyType, length = table_unpack(v) | ||
418 | + if not curCols[k] then | ||
419 | + print(string_format("table [%s] add new column [%s]", tbName, k)) | ||
420 | + assert(typeMap[objType], string_format("schema invalid type, [%s], [%s]", tbName, k)) | ||
421 | + | ||
422 | + local info = typeMap[objType] | ||
423 | + local suffix = "" | ||
424 | + local fieldType = info[1] | ||
425 | + if objType == "table" or not def or def == "" then def = info[2] end | ||
426 | + if type(def) == "string" and def ~= "NULL" then def = "'" .. def .. "'" end | ||
427 | + if info[3] and not length then length = info[3] end | ||
428 | + -- 设置字段长度 | ||
429 | + if info[3] then suffix = string.format("(%d)", length) end | ||
430 | + -- 很长的string使用blob | ||
431 | + if keyType == "blob" then | ||
432 | + fieldType = keyType | ||
433 | + suffix = "" | ||
434 | + def = "NULL" | ||
435 | + end | ||
436 | + local sep = "," | ||
437 | + if field_str == "" then | ||
438 | + sep = "" | ||
439 | + end | ||
440 | + field_str = field_str .. string.format(sep..field_tpl_str, k, fieldType, suffix, def) | ||
441 | + end | ||
442 | + end | ||
443 | + -- 添加新列 | ||
444 | + if field_str ~= "" then | ||
445 | + mysqlproxy:query(string_format(alter_sql, tbName, field_str)) | ||
446 | + end | ||
447 | + end | ||
448 | + | ||
449 | +end | ||
450 | + | ||
451 | +function ModelBaseMysql:loadFields(fields) | ||
452 | + if not self:isValidKey() then | ||
453 | + print(string_format("%s [%s:id] should be set before load", tostring(self), self.class.__cname)) | ||
454 | + return | ||
455 | + end | ||
456 | + if not next(fields) then | ||
457 | + return | ||
458 | + end | ||
459 | + local final = {} | ||
460 | + for _, v in ipairs(fields) do | ||
461 | + table.insert(final, '`'..v..'`') | ||
462 | + end | ||
463 | + local field_list = table.concat(final, ",") | ||
464 | + local res = mysqlproxy:query(string_format("SELECT %s from `%s` where `%s` = %s;", field_list, self.class.__cname, self.pri_key, self:getKey())) | ||
465 | + if res["errno"] then | ||
466 | + return | ||
467 | + end | ||
468 | + | ||
469 | + return res[1] | ||
470 | +end | ||
471 | + | ||
472 | +function ModelBaseMysql:update() | ||
473 | + if next(self.cacheFields) then | ||
474 | + self:updateFields(self.cacheFields) | ||
475 | + self.cacheFields = {} | ||
476 | + end | ||
477 | +end | ||
478 | + | ||
479 | +function ModelBaseMysql:updateFields(fields) | ||
480 | + local params = {} | ||
481 | + for field, value in pairs(fields) do | ||
482 | + if self.class.schema[field][1] == "table" then | ||
483 | + if next(value) then | ||
484 | + local result = mysqlproxy:quote_sql_str(MsgPack.pack(value)) | ||
485 | + params[field] = result | ||
486 | + end | ||
487 | + elseif self.class.schema[field][1] == "string" then | ||
488 | + local result = mysqlproxy:quote_sql_str(value) | ||
489 | + params[field] = result | ||
490 | + else | ||
491 | + params[field] = value | ||
492 | + end | ||
493 | + end | ||
494 | + if next(params) then | ||
495 | + local sql = "UPDATE `%s` SET %s WHERE `%s` = %s;" | ||
496 | + local tbName = self.class.__cname | ||
497 | + local tmp = {} | ||
498 | + for k, v in pairs(params) do | ||
499 | + table.insert(tmp, '`' .. k .. '` = ' .. v) | ||
500 | + end | ||
501 | + sql = string_format(sql, tbName, table.concat(tmp, ","), self.pri_key, self:getKey()) | ||
502 | + local res = mysqlproxy:query(sql) | ||
503 | + if res["errno"] then | ||
504 | + skynet.error(sql) | ||
505 | + skynet.error(res["err"]) | ||
506 | + return false | ||
507 | + end | ||
508 | + end | ||
509 | + return true | ||
510 | +end | ||
511 | + | ||
512 | +return ModelBaseMysql | ||
0 | \ No newline at end of file | 513 | \ No newline at end of file |
@@ -0,0 +1,53 @@ | @@ -0,0 +1,53 @@ | ||
1 | +local skynet = require "skynet" | ||
2 | +require "utils.init" | ||
3 | + | ||
4 | +local mysqld_count = tonumber(skynet.getenv("thread")) | ||
5 | +local mysqld | ||
6 | +skynet.init(function() | ||
7 | + local idx = math.randomInt(1, mysqld_count) | ||
8 | + mysqld = skynet.localname(".mysql" .. idx) | ||
9 | + | ||
10 | +end) | ||
11 | + | ||
12 | +local table_insert = table.insert | ||
13 | + | ||
14 | +local mysqlproxy = {} | ||
15 | + | ||
16 | + | ||
17 | +setmetatable(mysqlproxy, { __index = function(t, k) | ||
18 | + local cmd = string.upper(k) | ||
19 | + local f = function (self, ...) | ||
20 | + if k == "query" then | ||
21 | + --print(...) | ||
22 | + end | ||
23 | + local ok, result = pcall(skynet.call, mysqld, "lua", cmd, ...) | ||
24 | + if not ok then | ||
25 | + skynet.error(cmd, ..., "\n", debug.traceback(coroutine.running(), nil)) | ||
26 | + return | ||
27 | + end | ||
28 | + return result | ||
29 | + end | ||
30 | + t[k] = f | ||
31 | + return f | ||
32 | +end}) | ||
33 | + | ||
34 | +function mysqlproxy:insertEmail(params) | ||
35 | + local pms = { | ||
36 | + key = string.format("%s", 0), | ||
37 | + roleId = params.roleId, | ||
38 | + emailId = params.emailId, | ||
39 | + createtime = params.createtime or skynet.timex(), | ||
40 | + contentPms = params.contentPms or {}, | ||
41 | + rewardPms = params.rewardPms or {}, | ||
42 | + title = params.title or "", | ||
43 | + stitle = params.stitle or "", | ||
44 | + content = params.content or "", | ||
45 | + attachments = params.attachments or "", | ||
46 | + } | ||
47 | + | ||
48 | + local email = require("models.Email").new(pms) | ||
49 | + email:create() | ||
50 | + return true | ||
51 | +end | ||
52 | + | ||
53 | +return mysqlproxy | ||
0 | \ No newline at end of file | 54 | \ No newline at end of file |
@@ -0,0 +1,66 @@ | @@ -0,0 +1,66 @@ | ||
1 | +local skynet = require "skynet" | ||
2 | +local mysqlproxy = require "shared.mysqlproxy" | ||
3 | + | ||
4 | + | ||
5 | +function getDbCfgVal(tbName, keyName, fieldName) | ||
6 | + local sql = string.format("SELECT * FROM `%s` WHERE `key` = '%s';", tbName, keyName) | ||
7 | + local res = mysqlproxy:query(sql) | ||
8 | + if not next(res) or res.errno then | ||
9 | + return | ||
10 | + end | ||
11 | + | ||
12 | + return res[1][fieldName] | ||
13 | +end | ||
14 | + | ||
15 | +function setDbCfgVal(tbName, keyName, fieldName, fieldVal) | ||
16 | + if type(fieldVal) == "string" then fieldVal = string.format("'%s'", fieldVal) end | ||
17 | + local sql = string.format("UPDATE `%s` SET `%s` = %s WHERE `key` = '%s';", tbName, fieldName, fieldVal, keyName) | ||
18 | + mysqlproxy:query(sql) | ||
19 | +end | ||
20 | + | ||
21 | +function getFriendCount(roleId) | ||
22 | + local res = mysqlproxy:query(string.format("SELECT `id` FROM `Friend` WHERE `roleid` = %s", roleId)) | ||
23 | + if res["errno"] then | ||
24 | + return globalCsv.friendListLimit | ||
25 | + end | ||
26 | + | ||
27 | + return #res | ||
28 | +end | ||
29 | + | ||
30 | +function addFriend(roleId, friendId) | ||
31 | + local stmt_csp = mysqlproxy:prepare("call add_friends(?, ?, ?)") | ||
32 | + local r = mysqlproxy:execute(stmt_csp, roleId, friendId, skynet.timex()) | ||
33 | + if r[1][1]["t_error"] == 0 then | ||
34 | + rpcRole(roleId, "addFriend", friendId) | ||
35 | + rpcRole(friendId, "addFriend", roleId) | ||
36 | + end | ||
37 | + dump(r) | ||
38 | +end | ||
39 | + | ||
40 | +function delFriend(roleId, friendId) | ||
41 | + local stmt_csp = mysqlproxy:prepare("call del_friends(?, ?)") | ||
42 | + local r = mysqlproxy:execute(stmt_csp, roleId, friendId) | ||
43 | + if r[1][1]["t_error"] == 0 then | ||
44 | + rpcRole(roleId, "delFriend", friendId) | ||
45 | + rpcRole(friendId, "delFriend", roleId) | ||
46 | + end | ||
47 | + dump(r) | ||
48 | +end | ||
49 | + | ||
50 | +function roleExists(roleId) | ||
51 | + local res = mysqlproxy:query(string.format("SELECT `id` FROM `Role` WHERE `id` = %s", roleId)) | ||
52 | + if res["errno"] or not next(res) then | ||
53 | + return false | ||
54 | + end | ||
55 | + | ||
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"] | ||
66 | +end | ||
0 | \ No newline at end of file | 67 | \ No newline at end of file |