Commit 6136eacad7d37a699e3994647f94751fa227421d
1 parent
6af09a92
添加好友表
Showing
16 changed files
with
351 additions
and
163 deletions
Show diff stats
@@ -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/actions/ActivityAction.lua
@@ -1006,16 +1006,6 @@ function _M.friendHelpRpc(agent, data) | @@ -1006,16 +1006,6 @@ function _M.friendHelpRpc(agent, data) | ||
1006 | 1006 | ||
1007 | local actData = role.activity:getActData("FriendEnergy") or {} | 1007 | local actData = role.activity:getActData("FriendEnergy") or {} |
1008 | 1008 | ||
1009 | - local function getIds() | ||
1010 | - local ids = {} | ||
1011 | - local friends = redisproxy:hgetall(FRIEND_KEY:format(roleId)) | ||
1012 | - for i = 1, #friends , 2 do | ||
1013 | - local objId = tonumber(friends[i]) | ||
1014 | - ids[objId] = 1 | ||
1015 | - end | ||
1016 | - return ids | ||
1017 | - end | ||
1018 | - | ||
1019 | if oper == 1 then -- 赠送好友能量 | 1009 | if oper == 1 then -- 赠送好友能量 |
1020 | local giveAE = actData.giveAE or {} | 1010 | local giveAE = actData.giveAE or {} |
1021 | local objId = msg.roleId | 1011 | local objId = msg.roleId |
@@ -1025,7 +1015,7 @@ function _M.friendHelpRpc(agent, data) | @@ -1025,7 +1015,7 @@ function _M.friendHelpRpc(agent, data) | ||
1025 | if not objId then | 1015 | if not objId then |
1026 | return 3 | 1016 | return 3 |
1027 | end | 1017 | end |
1028 | - if not redisproxy:hexists(FRIEND_KEY:format(roleId), objId) then | 1018 | + if not role.friends[objId] then |
1029 | result = 2 | 1019 | result = 2 |
1030 | end | 1020 | end |
1031 | if giveAE[objId] then | 1021 | if giveAE[objId] then |
@@ -1071,7 +1061,6 @@ function _M.friendHelpRpc(agent, data) | @@ -1071,7 +1061,6 @@ function _M.friendHelpRpc(agent, data) | ||
1071 | local gift2 = gifts[2] | 1061 | local gift2 = gifts[2] |
1072 | local limit = actData.limit or 0 | 1062 | local limit = actData.limit or 0 |
1073 | local cmd1, cmd2 = 0, 0 | 1063 | local cmd1, cmd2 = 0, 0 |
1074 | - local ids = getIds() | ||
1075 | 1064 | ||
1076 | local members = {} | 1065 | local members = {} |
1077 | local temp = redisproxy:smembers(FRIEND_ENERGY:format(roleId)) | 1066 | local temp = redisproxy:smembers(FRIEND_ENERGY:format(roleId)) |
@@ -1080,7 +1069,7 @@ function _M.friendHelpRpc(agent, data) | @@ -1080,7 +1069,7 @@ function _M.friendHelpRpc(agent, data) | ||
1080 | end | 1069 | end |
1081 | 1070 | ||
1082 | redisproxy:pipelining(function(red) | 1071 | redisproxy:pipelining(function(red) |
1083 | - for friendId, _ in pairs(ids) do | 1072 | + for friendId, _ in pairs(role.friends) do |
1084 | if not giveAE[friendId] then | 1073 | if not giveAE[friendId] then |
1085 | giveAE[friendId] = 1 | 1074 | giveAE[friendId] = 1 |
1086 | award[gift1[1]] = (award[gift1[1]] or 0) + gift1[2] | 1075 | award[gift1[1]] = (award[gift1[1]] or 0) + gift1[2] |
@@ -1146,13 +1135,12 @@ function _M.friendHelpRpc(agent, data) | @@ -1146,13 +1135,12 @@ function _M.friendHelpRpc(agent, data) | ||
1146 | 1135 | ||
1147 | local ids = {} | 1136 | local ids = {} |
1148 | local members = {} | 1137 | local members = {} |
1149 | - local friendIds = getIds() | ||
1150 | local temp = redisproxy:smembers(FRIEND_ENERGY:format(roleId)) | 1138 | local temp = redisproxy:smembers(FRIEND_ENERGY:format(roleId)) |
1151 | for _, id in pairs(temp) do | 1139 | for _, id in pairs(temp) do |
1152 | members[tonumber(id)] = 1 | 1140 | members[tonumber(id)] = 1 |
1153 | end | 1141 | end |
1154 | 1142 | ||
1155 | - for id, _ in pairs(friendIds) do | 1143 | + for id, _ in pairs(role.friends) do |
1156 | if members[id] then | 1144 | if members[id] then |
1157 | ids[id] = 1 | 1145 | ids[id] = 1 |
1158 | end | 1146 | end |
src/actions/EmailAction.lua
@@ -111,7 +111,7 @@ function _M.drawAllAttachRpc(agent, data) | @@ -111,7 +111,7 @@ function _M.drawAllAttachRpc(agent, data) | ||
111 | for _, email in ipairs(emails) do | 111 | for _, email in ipairs(emails) do |
112 | local attachments = getEmailAttachments(email) | 112 | local attachments = getEmailAttachments(email) |
113 | if attachments ~= "" then | 113 | if attachments ~= "" then |
114 | - email:setProperty("status", 2) | 114 | + email:setProperty("status", 2, true) |
115 | email:log(role, 2) | 115 | email:log(role, 2) |
116 | ids[email:getProperty("id")] = 1 | 116 | ids[email:getProperty("id")] = 1 |
117 | for key, v in pairs(attachments:toNumMap()) do | 117 | for key, v in pairs(attachments:toNumMap()) do |
@@ -139,7 +139,7 @@ function _M.drawAttachRpc(agent, data) | @@ -139,7 +139,7 @@ function _M.drawAttachRpc(agent, data) | ||
139 | if attachments == "" then return end | 139 | if attachments == "" then return end |
140 | 140 | ||
141 | 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}}) |
142 | - email:setProperty("status", 2) | 142 | + email:setProperty("status", 2, true) |
143 | email:log(role, 2) | 143 | email:log(role, 2) |
144 | SendPacket(actionCodes.Email_drawAttachRpc, MsgPack.pack({reward = reward, change = change})) | 144 | SendPacket(actionCodes.Email_drawAttachRpc, MsgPack.pack({reward = reward, change = change})) |
145 | 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}) |
@@ -156,7 +156,7 @@ function _M.checkRpc(agent, data) | @@ -156,7 +156,7 @@ function _M.checkRpc(agent, data) | ||
156 | local email = require("models.Email").new({key = string.format("%d", id), id = id}) | 156 | local email = require("models.Email").new({key = string.format("%d", id), id = id}) |
157 | if not email:load() then return end | 157 | if not email:load() then return end |
158 | 158 | ||
159 | - email:setProperty("status", 1) | 159 | + email:setProperty("status", 1, true) |
160 | email:log(role, 1) | 160 | email:log(role, 1) |
161 | role:mylog("mail_action", {desc = "check_mail", int1 = id}) | 161 | role:mylog("mail_action", {desc = "check_mail", int1 = id}) |
162 | 162 |
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/RoleAction.lua
@@ -87,11 +87,11 @@ function _M.loginRpc( agent, data ) | @@ -87,11 +87,11 @@ function _M.loginRpc( agent, data ) | ||
87 | -- 2 | 87 | -- 2 |
88 | if not role then | 88 | if not role then |
89 | local roleKey = string_format("%d", roleId) | 89 | local roleKey = string_format("%d", roleId) |
90 | - --if not redisproxy:exists(roleKey) then | ||
91 | - -- response.result = "DB_ERROR" | ||
92 | - -- SendPacket(actionCodes.Role_loginRpc, MsgPack.pack(response)) | ||
93 | - -- return true | ||
94 | - --end | 90 | + if not roleExists(roleId) then |
91 | + response.result = "DB_ERROR" | ||
92 | + SendPacket(actionCodes.Role_loginRpc, MsgPack.pack(response)) | ||
93 | + return true | ||
94 | + end | ||
95 | -- 2a | 95 | -- 2a |
96 | role = require("models.Role").new({key = roleKey}) | 96 | role = require("models.Role").new({key = roleKey}) |
97 | role:load() | 97 | role:load() |
@@ -156,7 +156,6 @@ function _M.loginRpc( agent, data ) | @@ -156,7 +156,6 @@ function _M.loginRpc( agent, data ) | ||
156 | end | 156 | end |
157 | end | 157 | end |
158 | 158 | ||
159 | - --SERV_OPEN = redisproxy:hget("autoincrement_set", "server_start") | ||
160 | SERV_OPEN = getDbCfgVal("server_info", "server_start", "str_value") | 159 | SERV_OPEN = getDbCfgVal("server_info", "server_start", "str_value") |
161 | 160 | ||
162 | role:changeStructVersion() -- 数据结构 版本更新 | 161 | role:changeStructVersion() -- 数据结构 版本更新 |
@@ -1107,21 +1106,20 @@ function _M.chatRpc(agent, data) | @@ -1107,21 +1106,20 @@ function _M.chatRpc(agent, data) | ||
1107 | local objectId = msg.roleId | 1106 | local objectId = msg.roleId |
1108 | response.objId = objectId | 1107 | response.objId = objectId |
1109 | local redret = redisproxy:pipelining(function(red) | 1108 | local redret = redisproxy:pipelining(function(red) |
1110 | - red:exists(string.format("role:%d", objectId)) | ||
1111 | red:sismember(FRIEND_BLACK_KEY:format(roleId), objectId) | 1109 | red:sismember(FRIEND_BLACK_KEY:format(roleId), objectId) |
1112 | red:sismember(FRIEND_BLACK_KEY:format(objectId), roleId) | 1110 | red:sismember(FRIEND_BLACK_KEY:format(objectId), roleId) |
1113 | end) | 1111 | end) |
1114 | - if redret[1] ~= 1 then | 1112 | + if not roleExists(objectId) then |
1115 | result = 1 | 1113 | result = 1 |
1116 | return | 1114 | return |
1117 | end | 1115 | end |
1118 | -- 你把对方拉黑拉黑 | 1116 | -- 你把对方拉黑拉黑 |
1119 | - if redret[2] == 1 then | 1117 | + if redret[1] == 1 then |
1120 | result = 2 | 1118 | result = 2 |
1121 | return | 1119 | return |
1122 | end | 1120 | end |
1123 | -- 对方把你拉黑 | 1121 | -- 对方把你拉黑 |
1124 | - local isBlock = redret[3] == 1 | 1122 | + local isBlock = redret[2] == 1 |
1125 | 1123 | ||
1126 | local bin = MsgPack.pack(response) | 1124 | local bin = MsgPack.pack(response) |
1127 | if not isBlock then | 1125 | if not isBlock then |
src/models/Activity.lua
@@ -938,17 +938,11 @@ activityFunc[Activity.ActivityType.FriendEnergy] = { | @@ -938,17 +938,11 @@ activityFunc[Activity.ActivityType.FriendEnergy] = { | ||
938 | 938 | ||
939 | function Activity:getActFriendNew() | 939 | function Activity:getActFriendNew() |
940 | local roleId = self.owner:getProperty("id") | 940 | local roleId = self.owner:getProperty("id") |
941 | - local friendIds = {} | ||
942 | - local friends = redisproxy:hgetall(FRIEND_KEY:format(roleId)) | ||
943 | - for i = 1, #friends , 2 do | ||
944 | - local objId = tonumber(friends[i]) | ||
945 | - friendIds[objId] = 1 | ||
946 | - end | ||
947 | 941 | ||
948 | local ids = {} | 942 | local ids = {} |
949 | local members = redisproxy:smembers(FRIEND_ENERGY:format(roleId)) | 943 | local members = redisproxy:smembers(FRIEND_ENERGY:format(roleId)) |
950 | for _, id in pairs(members) do | 944 | for _, id in pairs(members) do |
951 | - if friendIds[tonumber(id)] then | 945 | + if self.owner.friends[tonumber(id)] then |
952 | ids[tonumber(id)] = 1 | 946 | ids[tonumber(id)] = 1 |
953 | end | 947 | end |
954 | end | 948 | end |
src/models/Diner.lua
@@ -7,10 +7,10 @@ end | @@ -7,10 +7,10 @@ end | ||
7 | Diner.schema = { | 7 | Diner.schema = { |
8 | id = {"number", 0, "pri"}, -- 角色id | 8 | id = {"number", 0, "pri"}, -- 角色id |
9 | buildL = {"string", ""}, -- 家具等级 1=1 2=1 3=1 | 9 | buildL = {"string", ""}, -- 家具等级 1=1 2=1 3=1 |
10 | - order = {"string", "[]", 1024}, -- 特殊订单 | ||
11 | - sells = {"string", "[]", "", 1024}, -- 贩卖位置 | ||
12 | - dishTree = {"string", "1=1 101=1 201=1"}, -- 料理天赋 | ||
13 | - skillTree = {"string", ""}, -- 支援天赋 | 10 | + order = {"string", "[]", "blob"}, -- 特殊订单 |
11 | + sells = {"string", "[]", "blob"}, -- 贩卖位置 | ||
12 | + dishTree = {"string", "1=1 101=1 201=1", "blob"}, -- 料理天赋 | ||
13 | + skillTree = {"string", "", "blob"}, -- 支援天赋 | ||
14 | popular = {"number",0}, -- 累计人气 | 14 | popular = {"number",0}, -- 累计人气 |
15 | expedite = {"number",1}, --每日加速次数 | 15 | expedite = {"number",1}, --每日加速次数 |
16 | gfood = {"table", {}}, -- 愿望食材 {{id = 123, st = 1232144},} | 16 | gfood = {"table", {}}, -- 愿望食材 {{id = 123, st = 1232144},} |
@@ -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/Role.lua
@@ -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.advData = nil | 29 | self.advData = nil |
29 | self.activity = nil | 30 | self.activity = nil |
30 | self._pushToken = nil | 31 | self._pushToken = nil |
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 |
src/models/RolePlugin.lua
@@ -13,6 +13,7 @@ function RolePlugin.bind(Role) | @@ -13,6 +13,7 @@ function RolePlugin.bind(Role) | ||
13 | self:loadActivity() | 13 | self:loadActivity() |
14 | self:loadStoreInfo() | 14 | self:loadStoreInfo() |
15 | self:loadRoleIncre() | 15 | self:loadRoleIncre() |
16 | + self:loadFriends() | ||
16 | end | 17 | end |
17 | 18 | ||
18 | function Role:reloadWhenLogin() | 19 | function Role:reloadWhenLogin() |
@@ -621,6 +622,17 @@ function RolePlugin.bind(Role) | @@ -621,6 +622,17 @@ function RolePlugin.bind(Role) | ||
621 | end | 622 | end |
622 | end | 623 | end |
623 | 624 | ||
625 | + function Role:loadFriends() | ||
626 | + local roleId = self:getProperty("id") | ||
627 | + local res = mysqlproxy:query(string.format("SELECT * FROM `Friend` WHERE `roleid` = %s", roleId)) | ||
628 | + for _, data in ipairs(res) do | ||
629 | + local friend = require("models.Friend").new({key = string.format("%d",data.id), id = data.id}) | ||
630 | + if friend:load(data) then | ||
631 | + self.friends[friend:getProperty("fid")] = friend | ||
632 | + end | ||
633 | + end | ||
634 | + end | ||
635 | + | ||
624 | function Role:loadDaily() | 636 | function Role:loadDaily() |
625 | local roleId = self:getProperty("id") | 637 | local roleId = self:getProperty("id") |
626 | local dataKey = string.format("%d", roleId) | 638 | local dataKey = string.format("%d", roleId) |
@@ -834,12 +846,6 @@ function RolePlugin.bind(Role) | @@ -834,12 +846,6 @@ function RolePlugin.bind(Role) | ||
834 | end | 846 | end |
835 | 847 | ||
836 | -- delete rune | 848 | -- delete rune |
837 | - --redisproxy:pipelining(function (red) | ||
838 | - -- for _, runeId in pairs(bDel) do | ||
839 | - -- red:del(string.format(R_RUNE, roleId, runeId)) | ||
840 | - -- red:srem(string.format(R_RUNEIDS, roleId), runeId) | ||
841 | - -- end | ||
842 | - --end) | ||
843 | mysqlproxy:query(string.format("DELETE FROM `Rune` WHERE `uid` in (%s)", table.concat(bDel, ","))) | 849 | mysqlproxy:query(string.format("DELETE FROM `Rune` WHERE `uid` in (%s)", table.concat(bDel, ","))) |
844 | 850 | ||
845 | local response = {} | 851 | local response = {} |
@@ -1555,6 +1561,21 @@ function RolePlugin.bind(Role) | @@ -1555,6 +1561,21 @@ function RolePlugin.bind(Role) | ||
1555 | function Role:onRecoverTimer(now) | 1561 | function Role:onRecoverTimer(now) |
1556 | self:updateTimeReset(now, true) | 1562 | self:updateTimeReset(now, true) |
1557 | self:checkNewEvent(now) | 1563 | self:checkNewEvent(now) |
1564 | + self:saveRoleData() | ||
1565 | + end | ||
1566 | + | ||
1567 | + function Role:saveRoleData() | ||
1568 | + self:update() | ||
1569 | + local objs = {self.activity, self.dailyData, self.dinerData, self.storeData, self.roleIncre} | ||
1570 | + for _, info in ipairs(objs) do | ||
1571 | + info:update() | ||
1572 | + end | ||
1573 | + local tbObjs = {self.friends, self.heros, self.runeBag} | ||
1574 | + for _, tbObj in ipairs(tbObjs) do | ||
1575 | + for _, info in pairs(tbObj) do | ||
1576 | + tbObj:update() | ||
1577 | + end | ||
1578 | + end | ||
1558 | end | 1579 | end |
1559 | 1580 | ||
1560 | local function breath(sec, name) | 1581 | local function breath(sec, name) |
@@ -1812,6 +1833,8 @@ function RolePlugin.bind(Role) | @@ -1812,6 +1833,8 @@ function RolePlugin.bind(Role) | ||
1812 | redisproxy:hdel(string.format(R_ORDERS, roleId), rechargeId) | 1833 | redisproxy:hdel(string.format(R_ORDERS, roleId), rechargeId) |
1813 | end | 1834 | end |
1814 | 1835 | ||
1836 | + orderObject:update() | ||
1837 | + | ||
1815 | if status ~= "unknow" then | 1838 | if status ~= "unknow" then |
1816 | self:log("setOrder", { | 1839 | self:log("setOrder", { |
1817 | order_status = ({success = 100, finsh = 200, fail = 300})[status] or 1000, -- "订单状态:100 - 开始下单(玩家还未开始付费行为记录)200 - 支付完成并发货(SDK通知可以发货时记录),300 - 订单被取消,1000 - 其他" | 1840 | order_status = ({success = 100, finsh = 200, fail = 300})[status] or 1000, -- "订单状态:100 - 开始下单(玩家还未开始付费行为记录)200 - 支付完成并发货(SDK通知可以发货时记录),300 - 订单被取消,1000 - 其他" |
src/services/dbseed.lua
@@ -34,6 +34,8 @@ local function initRedisDb( ... ) | @@ -34,6 +34,8 @@ local function initRedisDb( ... ) | ||
34 | initAutoIncrementUid("autoincrement_set", "email") | 34 | initAutoIncrementUid("autoincrement_set", "email") |
35 | initAutoIncrementUid("autoincrement_set", "emailTimestamp") | 35 | initAutoIncrementUid("autoincrement_set", "emailTimestamp") |
36 | initAutoIncrementUid("autoincrement_set", "delay_email") | 36 | initAutoIncrementUid("autoincrement_set", "delay_email") |
37 | + initAutoIncrementUid("autoincrement_set", "stopcreate") | ||
38 | + initAutoIncrementUid("autoincrement_set", "maintain") | ||
37 | 39 | ||
38 | --redisproxy:hsetnx("adv_season", "idx", 0) | 40 | --redisproxy:hsetnx("adv_season", "idx", 0) |
39 | --redisproxy:hsetnx("adv_season", "chapter", globalCsv.adv_endless_default_chapter) | 41 | --redisproxy:hsetnx("adv_season", "chapter", globalCsv.adv_endless_default_chapter) |
@@ -80,6 +82,8 @@ local function initAutoIncreUidTable() | @@ -80,6 +82,8 @@ local function initAutoIncreUidTable() | ||
80 | mysqlproxy:query(string.format(tpl, "email", 0)) | 82 | mysqlproxy:query(string.format(tpl, "email", 0)) |
81 | mysqlproxy:query(string.format(tpl, "emailTimestamp", 0)) | 83 | mysqlproxy:query(string.format(tpl, "emailTimestamp", 0)) |
82 | mysqlproxy:query(string.format(tpl, "delay_email", 0)) | 84 | mysqlproxy:query(string.format(tpl, "delay_email", 0)) |
85 | + mysqlproxy:query(string.format(tpl, "stopcreate", 0)) | ||
86 | + mysqlproxy:query(string.format(tpl, "maintain", 0)) | ||
83 | end | 87 | end |
84 | end | 88 | end |
85 | 89 | ||
@@ -102,7 +106,7 @@ local function initAdvSeasonTable() | @@ -102,7 +106,7 @@ local function initAdvSeasonTable() | ||
102 | end | 106 | end |
103 | 107 | ||
104 | local function checkRoleTables() | 108 | local function checkRoleTables() |
105 | - local list = {"Role", "Daily", "Activity", "Diner", "Store", "Hero", "RoleIncre", "Rune", "Order", "Email"} | 109 | + local list = {"Role", "Daily", "Activity", "Diner", "Store", "Hero", "RoleIncre", "Rune", "Order", "Email", "Friend"} |
106 | for _, name in ipairs(list) do | 110 | for _, name in ipairs(list) do |
107 | local obj = require("models."..name).new({key = "key"}) | 111 | local obj = require("models."..name).new({key = "key"}) |
108 | print("check table [" .. name .. "] begin.") | 112 | print("check table [" .. name .. "] begin.") |
@@ -111,6 +115,48 @@ local function checkRoleTables() | @@ -111,6 +115,48 @@ local function checkRoleTables() | ||
111 | end | 115 | end |
112 | end | 116 | end |
113 | 117 | ||
118 | +local function createMysqlSp() | ||
119 | + mysqlproxy:query "DROP PROCEDURE IF EXISTS `add_friends`" | ||
120 | + mysqlproxy:query [[ | ||
121 | + CREATE PROCEDURE `add_friends`(IN role_id bigint, IN friend_id bigint, IN add_time int) | ||
122 | + BEGIN | ||
123 | + DECLARE t_error INTEGER DEFAULT 0; | ||
124 | + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET t_error=1; | ||
125 | + | ||
126 | + START TRANSACTION; | ||
127 | + INSERT INTO `Friend`(`roleid`,`fid`,`addTime`) VALUES(role_id, friend_id, add_time); | ||
128 | + INSERT INTO `Friend`(`roleid`,`fid`,`addTime`) VALUES(friend_id, role_id, add_time); | ||
129 | + | ||
130 | + IF t_error = 1 THEN | ||
131 | + ROLLBACK; | ||
132 | + ELSE | ||
133 | + COMMIT; | ||
134 | + END IF; | ||
135 | + select t_error; | ||
136 | + END | ||
137 | + ]] | ||
138 | + | ||
139 | + mysqlproxy:query "DROP PROCEDURE IF EXISTS `del_friends`" | ||
140 | + mysqlproxy:query [[ | ||
141 | + CREATE PROCEDURE `del_friends`(IN role_id bigint, IN friend_id bigint) | ||
142 | + BEGIN | ||
143 | + DECLARE t_error INTEGER DEFAULT 0; | ||
144 | + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET t_error=1; | ||
145 | + | ||
146 | + START TRANSACTION; | ||
147 | + DELETE FROM `Friend` WHERE `roleid` = role_id AND `fid` = friend_id; | ||
148 | + DELETE FROM `Friend` WHERE `roleid` = friend_id AND `fid` = role_id; | ||
149 | + | ||
150 | + IF t_error = 1 THEN | ||
151 | + ROLLBACK; | ||
152 | + ELSE | ||
153 | + COMMIT; | ||
154 | + END IF; | ||
155 | + select t_error; | ||
156 | + END | ||
157 | + ]] | ||
158 | +end | ||
159 | + | ||
114 | local steps = { | 160 | local steps = { |
115 | [1] = { | 161 | [1] = { |
116 | handler = initServerDatabase, | 162 | handler = initServerDatabase, |
@@ -127,9 +173,35 @@ local steps = { | @@ -127,9 +173,35 @@ local steps = { | ||
127 | [4] = { | 173 | [4] = { |
128 | handler = checkRoleTables, | 174 | handler = checkRoleTables, |
129 | desc = "check role tables " | 175 | desc = "check role tables " |
130 | - } | 176 | + }, |
177 | + [5] = { | ||
178 | + handler = createMysqlSp, | ||
179 | + desc = "create mysql store procedure " | ||
180 | + }, | ||
131 | } | 181 | } |
132 | 182 | ||
183 | +local function loadAllUserInfo() | ||
184 | + local maxId = 0 | ||
185 | + local sql = "SELECT `id`, `uid`, `name` FROM `Role` WHERE `id` > %d ORDER BY `id` LIMIT 1000;" | ||
186 | + while true do | ||
187 | + local res = mysqlproxy:query(string.format(sql, maxId)) | ||
188 | + if not next(res) then | ||
189 | + return | ||
190 | + else | ||
191 | + for _, info in ipairs(res) do | ||
192 | + if info["id"] > maxId then | ||
193 | + maxId = info["id"] | ||
194 | + end | ||
195 | + redisproxy:pipelining(function (red) | ||
196 | + local dbName = string.upper(info["name"]) | ||
197 | + red:set(string.format("user:%s", dbName), info["id"]) | ||
198 | + red:set(string.format("uid:%s", info["uid"]), dbName) | ||
199 | + end) | ||
200 | + end | ||
201 | + end | ||
202 | + end | ||
203 | +end | ||
204 | + | ||
133 | skynet.start(function () | 205 | skynet.start(function () |
134 | --local new = redisproxy:hsetnx("autoincrement_set", "server_start", os.date("%Y%m%d", skynet.timex())) == 1 | 206 | --local new = redisproxy:hsetnx("autoincrement_set", "server_start", os.date("%Y%m%d", skynet.timex())) == 1 |
135 | --if not new then | 207 | --if not new then |
@@ -146,5 +218,6 @@ skynet.start(function () | @@ -146,5 +218,6 @@ skynet.start(function () | ||
146 | print(action.desc .. "finished ...") | 218 | print(action.desc .. "finished ...") |
147 | end | 219 | end |
148 | initRedisDb() | 220 | initRedisDb() |
221 | + loadAllUserInfo() | ||
149 | skynet.exit() | 222 | skynet.exit() |
150 | end) | 223 | end) |
151 | \ No newline at end of file | 224 | \ No newline at end of file |
src/services/globald.lua
@@ -171,6 +171,8 @@ local function save_autoincrement_timer() | @@ -171,6 +171,8 @@ local function save_autoincrement_timer() | ||
171 | saveUidToMysql("autoincrement_set", "email") | 171 | saveUidToMysql("autoincrement_set", "email") |
172 | saveUidToMysql("autoincrement_set", "emailTimestamp") | 172 | saveUidToMysql("autoincrement_set", "emailTimestamp") |
173 | saveUidToMysql("autoincrement_set", "delay_email") | 173 | saveUidToMysql("autoincrement_set", "delay_email") |
174 | + saveUidToMysql("autoincrement_set", "stopcreate") | ||
175 | + saveUidToMysql("autoincrement_set", "maintain") | ||
174 | 176 | ||
175 | skynet.timeout(SAVE_AUTOINCREMENT_SET_INTERVAL, save_autoincrement_timer) | 177 | skynet.timeout(SAVE_AUTOINCREMENT_SET_INTERVAL, save_autoincrement_timer) |
176 | end | 178 | end |
src/services/mysqld.lua
@@ -31,6 +31,8 @@ skynet.start(function() | @@ -31,6 +31,8 @@ skynet.start(function() | ||
31 | if cmd == "open" then | 31 | if cmd == "open" then |
32 | local f = command[string.lower(cmd)] | 32 | local f = command[string.lower(cmd)] |
33 | skynet.ret(skynet.pack(f(...))) | 33 | skynet.ret(skynet.pack(f(...))) |
34 | + elseif string.lower(cmd) == "quote_sql_str" then | ||
35 | + skynet.ret(skynet.pack(db[string.lower(cmd)](...))) | ||
34 | else | 36 | else |
35 | skynet.ret(skynet.pack(db[string.lower(cmd)](db, ...))) | 37 | skynet.ret(skynet.pack(db[string.lower(cmd)](db, ...))) |
36 | end | 38 | end |
src/shared/ModelBaseMysql.lua
@@ -141,6 +141,10 @@ function ModelBaseMysql:save() | @@ -141,6 +141,10 @@ function ModelBaseMysql:save() | ||
141 | end | 141 | end |
142 | sql = string_format(sql, tbName, key_list, value_list, update_list) | 142 | sql = string_format(sql, tbName, key_list, value_list, update_list) |
143 | local res = mysqlproxy:query(sql) | 143 | local res = mysqlproxy:query(sql) |
144 | + if res["errno"] then | ||
145 | + skynet.error(sql) | ||
146 | + skynet.error(res["error"]) | ||
147 | + end | ||
144 | end | 148 | end |
145 | end | 149 | end |
146 | 150 | ||
@@ -228,7 +232,7 @@ function ModelBaseMysql:getProperty(property) | @@ -228,7 +232,7 @@ function ModelBaseMysql:getProperty(property) | ||
228 | return self:getProperties({property})[property] | 232 | return self:getProperties({property})[property] |
229 | end | 233 | end |
230 | 234 | ||
231 | -function ModelBaseMysql:setProperty(property, value) | 235 | +function ModelBaseMysql:setProperty(property, value, forceSave) |
232 | if not self.class.schema[property] then | 236 | if not self.class.schema[property] then |
233 | print(string_format("%s [%s:setProperty()] Invalid property : %s", | 237 | print(string_format("%s [%s:setProperty()] Invalid property : %s", |
234 | tostring(self), self.class.__cname, property)) | 238 | tostring(self), self.class.__cname, property)) |
@@ -245,13 +249,21 @@ function ModelBaseMysql:setProperty(property, value) | @@ -245,13 +249,21 @@ function ModelBaseMysql:setProperty(property, value) | ||
245 | assert(type(value) == typ, | 249 | assert(type(value) == typ, |
246 | string_format("%s [%s:setProperties()] Type mismatch, %s expected %s, actual is %s", | 250 | string_format("%s [%s:setProperties()] Type mismatch, %s expected %s, actual is %s", |
247 | tostring(self), self.class.__cname, property, typ, type(value))) | 251 | tostring(self), self.class.__cname, property, typ, type(value))) |
248 | - self[propname] = value | ||
249 | 252 | ||
250 | - self:save() | 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 | ||
251 | end | 264 | end |
252 | 265 | ||
253 | -function ModelBaseMysql:setProperties(fields) | ||
254 | - local result = {} | 266 | +function ModelBaseMysql:setProperties(fields, forceSave) |
255 | for property, value in pairs(fields) do | 267 | for property, value in pairs(fields) do |
256 | if not self.class.schema[property] then | 268 | if not self.class.schema[property] then |
257 | print(string_format("%s [%s:setProperty()] Invalid property : %s", | 269 | print(string_format("%s [%s:setProperty()] Invalid property : %s", |
@@ -266,20 +278,23 @@ function ModelBaseMysql:setProperties(fields) | @@ -266,20 +278,23 @@ function ModelBaseMysql:setProperties(fields) | ||
266 | assert(type(value) == typ, | 278 | assert(type(value) == typ, |
267 | string_format("%s [%s:setProperties()] Type mismatch, %s expected %s, actual is %s", | 279 | string_format("%s [%s:setProperties()] Type mismatch, %s expected %s, actual is %s", |
268 | tostring(self), self.class.__cname, property, typ, type(value))) | 280 | tostring(self), self.class.__cname, property, typ, type(value))) |
269 | - self[propname] = value | ||
270 | 281 | ||
271 | - table_insert(result, property) | ||
272 | - if typ == "table" then | ||
273 | - table_insert(result, MsgPack.pack(self[propname])) | ||
274 | - else | ||
275 | - table_insert(result, self[propname]) | 282 | + if typ == "number" or typ == "string" then |
283 | + if self[propname] == value then | ||
284 | + return | ||
285 | + end | ||
276 | end | 286 | end |
287 | + self[propname] = value | ||
288 | + self.cacheFields[property] = self[propname] | ||
277 | end | 289 | end |
278 | end | 290 | end |
279 | - self:save() | 291 | + if forceSave then |
292 | + self:update() | ||
293 | + end | ||
294 | + --self:save() | ||
280 | end | 295 | end |
281 | 296 | ||
282 | -function ModelBaseMysql:incrProperty(property, value) | 297 | +function ModelBaseMysql:incrProperty(property, value, forceSave) |
283 | if not self.class.schema[property] then | 298 | if not self.class.schema[property] then |
284 | print(string_format("%s [%s:setProperty()] Invalid property : %s", | 299 | print(string_format("%s [%s:setProperty()] Invalid property : %s", |
285 | tostring(self), self.class.__cname, property)) | 300 | tostring(self), self.class.__cname, property)) |
@@ -289,15 +304,10 @@ function ModelBaseMysql:incrProperty(property, value) | @@ -289,15 +304,10 @@ function ModelBaseMysql:incrProperty(property, value) | ||
289 | local typ, def = table_unpack(self.class.schema[property]) | 304 | local typ, def = table_unpack(self.class.schema[property]) |
290 | local propname = property .. "_" | 305 | local propname = property .. "_" |
291 | 306 | ||
292 | - if typ == "table" then return end | 307 | + if typ == "table" or typ == "string" then return end |
293 | if typ == "number" then value = tonumber(value) end | 308 | if typ == "number" then value = tonumber(value) end |
294 | 309 | ||
295 | - assert(type(value) == typ, | ||
296 | - string_format("%s [%s:setProperties()] Type mismatch, %s expected %s, actual is %s", | ||
297 | - tostring(self), self.class.__cname, property, typ, type(value))) | ||
298 | - self[propname] = self[propname] + value | ||
299 | - | ||
300 | - self:save() | 310 | + self:setProperty(property, self[propname] + value, forceSave) |
301 | end | 311 | end |
302 | 312 | ||
303 | function ModelBaseMysql:onLoad() | 313 | function ModelBaseMysql:onLoad() |
@@ -438,4 +448,65 @@ function ModelBaseMysql:checkTableSchema() | @@ -438,4 +448,65 @@ function ModelBaseMysql:checkTableSchema() | ||
438 | 448 | ||
439 | end | 449 | end |
440 | 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["error"]) | ||
506 | + return false | ||
507 | + end | ||
508 | + end | ||
509 | + return true | ||
510 | +end | ||
511 | + | ||
441 | return ModelBaseMysql | 512 | return ModelBaseMysql |
442 | \ No newline at end of file | 513 | \ No newline at end of file |
src/utils/MysqlUtil.lua
@@ -16,4 +16,42 @@ function setDbCfgVal(tbName, keyName, fieldName, fieldVal) | @@ -16,4 +16,42 @@ function setDbCfgVal(tbName, keyName, fieldName, fieldVal) | ||
16 | if type(fieldVal) == "string" then fieldVal = string.format("'%s'", fieldVal) end | 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) | 17 | local sql = string.format("UPDATE `%s` SET `%s` = %s WHERE `key` = '%s';", tbName, fieldName, fieldVal, keyName) |
18 | mysqlproxy:query(sql) | 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 | ||
19 | end | 57 | end |
20 | \ No newline at end of file | 58 | \ No newline at end of file |