Blame view

src/actions/FriendAction.lua 18.4 KB
c384626d   zhouhaihai   好友
1
2
3
4
5
6
7
8
9
10
11
12
13
  local ipairs = ipairs
  local table = table
  local math = math
  local string = string
  local redisproxy = redisproxy
  local MsgPack = MsgPack
  local string_format = string.format
  local tonumber = tonumber
  local table_insert = table.insert
  local table_unpack = table.unpack
  local table_find = table.find
  local table_nums = table.nums
  local math_random = math.randomInt
6136eaca   liuzujun   添加好友表
14
  require "utils.MysqlUtil"
c384626d   zhouhaihai   好友
15
16
17
18
19
20
21
22
23
24
25
26
  
  local _M = {}
  
  local function formatArray(tb)
  	tb = tb or {}
  	local t = {}
  	for _, objectId in ipairs(tb) do
  		t[tonumber(objectId)] = 1
  	end
  	return t
  end
  
c384626d   zhouhaihai   好友
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
  
  local function addAndCheckApplyLimit(roleId, objId)
  	roleId = tonumber(roleId)
  	local dbKey = FRIEND_APPLY_KEY:format(roleId)
  	local redret = redisproxy:pipelining(function (red)
  		red:zadd(dbKey, skynet.timex(), objId)
  		red:zremrangebyrank(dbKey, 0, -(globalCsv.friendApplyLimit + 1))
  	end)
  end
  
  local function checkBlackLimit(roleId)
  	roleId = tonumber(roleId)
  	local count = redisproxy:scard(FRIEND_BLACK_KEY:format(roleId))
  	return count < globalCsv.friendListLimit
  end
  
  local function getRoleInfo(roleId)
  	local online, info = rpcRole(roleId, "friendSInfo")
  	return online, info
  end
  
  local function getRoleAllInfo(roleId)
  	local online, info = rpcRole(roleId, "friendInfo")
  	return online, info
  end
  
  local function table_merge(tab1, tab2, filter)
  	tab1 = tab1 or {}
  	tab2 = tab2 or {}
  	filter = filter or {}
  	for k_, v_ in pairs(tab2) do
  		if not filter[k_] then
  			tab1[k_] = v_
  		end
  	end
  	return tab1
  end
  
  function _M.searchRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  	local msg = MsgPack.unpack(data)
  	local key = msg.key
  
  	if not key then return end
  
  	local objIds = {}
  	local tempId = tonumber(key)
  	if tempId then
6136eaca   liuzujun   添加好友表
76
  		if roleExists(tempId) then
c384626d   zhouhaihai   好友
77
78
79
80
81
82
83
84
85
86
87
88
89
  			objIds[tempId] = 1
  		end
  	end
  	local tempId = redisproxy:get(string_format("user:%s", string.upper(key)))
  	if tempId then
  		objIds[tonumber(tempId)] = 1
  	end
  	objIds[roleId] = nil --不能有自己
  
  	local searchList = {}
  	for objId, _ in pairs(objIds) do
  		local online, info = getRoleInfo(objId)
  		local redret = redisproxy:pipelining(function (red)
c384626d   zhouhaihai   好友
90
91
92
  			red:zscore(FRIEND_APPLY_KEY:format(objId), roleId)
  			red:sismember(FRIEND_BLACK_KEY:format(roleId), objId)
  		end)
6136eaca   liuzujun   添加好友表
93
94
95
96
  		
  		local isFriend = role.friends[objId] and 1 or nil
  		local hadApply = redret[1] and 1 or nil
  		local inBlack = redret[2] == 1 and 1 or nil
c384626d   zhouhaihai   好友
97
98
99
100
101
102
103
104
105
106
107
  
  		table.insert(searchList, table_merge({
  			roleId = objId, 
  			online = online, 
  			isFriend = isFriend, 
  			hadApply = hadApply,
  			inBlack = inBlack,
  		}, info, {
  
  		}))
  	end
3133cb76   zhouhaihai   日志
108
  
f22a33af   zhouhaihai   自己的日志
109
  	role:mylog("role_action", {desc = "searchFriend"})
c384626d   zhouhaihai   好友
110
111
112
113
114
115
116
117
118
119
120
  	SendPacket(actionCodes.Friend_searchRpc, MsgPack.pack({searchList = searchList}))
  	return true
  end
  
  
  function _M.applyRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  
  	local msg = MsgPack.unpack(data)
  	local objectId = msg.roleId
6136eaca   liuzujun   添加好友表
121
  	dump(msg)
c384626d   zhouhaihai   好友
122
123
124
125
126
127
128
  
  	if objectId == roleId then
  		return
  	end
  
  	local result = nil
  	local redret = redisproxy:pipelining(function (red)
c384626d   zhouhaihai   好友
129
130
131
  		red:zscore(FRIEND_APPLY_KEY:format(objectId), roleId)
  		red:sismember(FRIEND_BLACK_KEY:format(objectId), roleId)
  		red:sismember(FRIEND_BLACK_KEY:format(roleId), objectId)
c384626d   zhouhaihai   好友
132
  	end)
6136eaca   liuzujun   添加好友表
133
  	dump(redret)
5dfc4978   zhouhaihai   好友完善
134
  
c384626d   zhouhaihai   好友
135
  	-- 玩家id不存在
6136eaca   liuzujun   添加好友表
136
  	if not result and not roleExists(objectId) then
c384626d   zhouhaihai   好友
137
138
139
140
  		result = 1	
  	end
  
  	-- 已经有这个好友
6136eaca   liuzujun   添加好友表
141
  	if not result and role.friends[objectId] then
c384626d   zhouhaihai   好友
142
143
144
  		result = 2
  	end
  	-- 已经申请
6136eaca   liuzujun   添加好友表
145
  	if not result and redret[1] then
c384626d   zhouhaihai   好友
146
147
148
  		result = 3
  	end
  	-- 对方把你拉黑
6136eaca   liuzujun   添加好友表
149
  	if not result and redret[2] == 1 then
c384626d   zhouhaihai   好友
150
151
152
153
  		result = 4
  	end
  
  	-- 你把对方拉黑了
6136eaca   liuzujun   添加好友表
154
  	if not result and redret[3] == 1 then
c384626d   zhouhaihai   好友
155
156
157
158
  		result = 5
  	end
  
  	-- 自己好友已经满
6136eaca   liuzujun   添加好友表
159
  	if not result and table.numbers(role.friends) >= globalCsv.friendListLimit then
c384626d   zhouhaihai   好友
160
161
162
  		result = 6
  	end
  	-- 对方的好友已满
6136eaca   liuzujun   添加好友表
163
  	if not result and getFriendCount(objectId) >= globalCsv.friendListLimit then
c384626d   zhouhaihai   好友
164
165
166
167
168
169
170
171
172
  		result = 7
  	end
  
  	if not result then
  		addAndCheckApplyLimit(objectId, roleId)
  		local myInfo = role:friendSInfo()
  		myInfo.roleId = roleId
  		myInfo.online = true
  		myInfo.hadApply = true
3133cb76   zhouhaihai   日志
173
  
f22a33af   zhouhaihai   自己的日志
174
175
  		role:mylog("role_action", {desc = "addFriend", int1 = 1})
  
c384626d   zhouhaihai   好友
176
177
  		rpcRole(objectId, "SendPacket", actionCodes.Friend_updateProperty, MsgPack.pack({newApply = 1, info = {myInfo}})) 	-- 通知对方
  	end
3133cb76   zhouhaihai   日志
178
179
180
  
  	
  
c384626d   zhouhaihai   好友
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
  	SendPacket(actionCodes.Friend_applyRpc, MsgPack.pack({result = result}))
  	return true
  end
  
  function _M.applyListRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  
  	local applyList = {}
  
  	local friends = redisproxy:zrange(FRIEND_APPLY_KEY:format(roleId), 0, -1)
  	for _ , id in pairs(friends) do
  		id = tonumber(id)
  		local online, info = getRoleInfo(id)
  		table.insert(applyList, table_merge({
  			roleId = id, online = online
  		}, info, {
  
  		}))
  	end
  	SendPacket(actionCodes.Friend_applyListRpc, MsgPack.pack({list = applyList}))
  	return true
  end
  
6136eaca   liuzujun   添加好友表
205
  local function checkHandleApply(role, objectId, needAddNew) 
763d6396   zhouhaihai   批量增加好友bug
206
  	needAddNew = needAddNew or 0
6136eaca   liuzujun   添加好友表
207
  	local roleId = role:getProperty("id")
c384626d   zhouhaihai   好友
208
  	local redret = redisproxy:pipelining(function (red)
c384626d   zhouhaihai   好友
209
210
211
  		red:sismember(FRIEND_BLACK_KEY:format(objectId), roleId)
  		red:sismember(FRIEND_BLACK_KEY:format(roleId), objectId)
  	end)
c59e058b   zhouhaihai   新一批日志记录
212
  
c384626d   zhouhaihai   好友
213
  	--自己好友满了
6136eaca   liuzujun   添加好友表
214
  	if (table.numbers(role.friends) + needAddNew) >= globalCsv.friendListLimit then
763d6396   zhouhaihai   批量增加好友bug
215
  		return 1
c384626d   zhouhaihai   好友
216
217
  	end
  	-- 对方好友满了
6136eaca   liuzujun   添加好友表
218
  	if getFriendCount(objectId) >= globalCsv.friendListLimit then
763d6396   zhouhaihai   批量增加好友bug
219
  		return 2
c384626d   zhouhaihai   好友
220
221
  	end
  	-- 对方把你拉黑
6136eaca   liuzujun   添加好友表
222
  	if redret[1] == 1 then
763d6396   zhouhaihai   批量增加好友bug
223
  		return 3
c384626d   zhouhaihai   好友
224
225
  	end
  	-- 你把对方拉黑了
6136eaca   liuzujun   添加好友表
226
  	if redret[2] == 1 then
763d6396   zhouhaihai   批量增加好友bug
227
  		return 4
c384626d   zhouhaihai   好友
228
  	end
c59e058b   zhouhaihai   新一批日志记录
229
230
  
  	return nil, redret[1]
c384626d   zhouhaihai   好友
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
  end
  
  function _M.handleApplyRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  
  	local msg = MsgPack.unpack(data)
  	local cmd = msg.cmd
  
  	local newTag = MsgPack.pack({ skynet.timex(), 1})
  	local result = nil
  	if cmd == 1 then	--同意
  
  		local objectId = msg.roleId
  
  		if not redisproxy:zscore(FRIEND_APPLY_KEY:format(roleId), objectId) then
  			return
  		end
c59e058b   zhouhaihai   新一批日志记录
249
  		local curCount
6136eaca   liuzujun   添加好友表
250
  		result, curCount = checkHandleApply(role, objectId)
c384626d   zhouhaihai   好友
251
252
253
254
255
  
  		if not result then
  			redisproxy:pipelining(function (red)
  				red:ZREM(FRIEND_APPLY_KEY:format(roleId), objectId)
  				red:ZREM(FRIEND_APPLY_KEY:format(objectId), roleId)
6136eaca   liuzujun   添加好友表
256
  				addFriend(roleId, objectId)
c384626d   zhouhaihai   好友
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
  			end)
  			local myInfo = role:friendSInfo()
  			myInfo.online = true
  			myInfo.roleId = roleId
  			myInfo.isFriend = 1
  			local redret = redisproxy:pipelining(function (red)
  				red:sismember(FRIEND_POINT:format(objectId), roleId)
  				red:sismember(FRIEND_POINT:format(roleId), objectId)
  			end)
  			myInfo.pGet = redret[1] == 1 and 1 or nil
  			rpcRole(objectId, "SendPacket", actionCodes.Friend_updateProperty, MsgPack.pack({newFriend = 1, info = {myInfo}}))	-- 通知对方
  			local online , otherInfo = getRoleInfo(objectId)
  			otherInfo.roleId = objectId
  			otherInfo.online = online
  			otherInfo.isFriend = true
  			otherInfo.pGet = redret[2] == 1 and 1 or nil
  			SendPacket(actionCodes.Friend_updateProperty, MsgPack.pack({newFriend = 1, info = {otherInfo}}))
3133cb76   zhouhaihai   日志
274
  
c59e058b   zhouhaihai   新一批日志记录
275
276
277
278
279
  			role:log("friend_opt", {
  				friend_opt_type = 100, -- 好友操作类型,见枚举表中 好友操作类型枚举表
  				friend_roleid = objectId, -- 好友账户下的角色id
  				friend_cnt = curCount + 1, -- 操作后好友数量
  			})
f22a33af   zhouhaihai   自己的日志
280
281
  			role:mylog("role_action", {desc = "addFriend", int1 = 1})
  
c384626d   zhouhaihai   好友
282
283
284
285
286
287
288
289
290
291
292
293
  		end
  
  	elseif cmd == 0 then	-- 不同意
  		local objectId = msg.roleId
  		if not redisproxy:zscore(FRIEND_APPLY_KEY:format(roleId), objectId) then
  			return
  		end
  		redisproxy:ZREM(FRIEND_APPLY_KEY:format(roleId), objectId)
  	elseif cmd == 2 then    -- 一键拒绝
  		redisproxy:del(FRIEND_APPLY_KEY:format(roleId))
  	elseif cmd == 3 then    -- 一键同意
  		local redret = redisproxy:pipelining(function(red)
5dfc4978   zhouhaihai   好友完善
294
  			red:zrange(FRIEND_APPLY_KEY:format(roleId), 0, -1)
c384626d   zhouhaihai   好友
295
296
297
298
299
300
301
302
303
  			red:SMEMBERS(FRIEND_POINT:format(roleId))
  		end)
  		local allIds = redret[1]
  		local fpoint = formatArray(redret[2])
  		local needAdd = {}
  		local needAddMy = {}
  		local needAddInfo = {}
  		for _, objId in ipairs(allIds) do
  			objId = tonumber(objId)
6136eaca   liuzujun   添加好友表
304
  			local cr, curCount = checkHandleApply(role, objId, #needAdd)
c384626d   zhouhaihai   好友
305
306
307
308
309
310
311
312
313
314
  			if not cr then 
  				table.insert(needAdd, objId)
  				table.insert(needAddMy, objId)
  				table.insert(needAddMy, newTag)
  				local online, otherInfo = getRoleInfo(objId)
  				otherInfo.online = true
  				otherInfo.roleId = objId
  				otherInfo.isFriend = true
  				otherInfo.pGet = fpoint[objId] and 1 or nil
  				table.insert(needAddInfo, otherInfo)
c59e058b   zhouhaihai   新一批日志记录
315
316
317
318
319
320
  
  				role:log("friend_opt", {
  					friend_opt_type = 100, -- 好友操作类型,见枚举表中 好友操作类型枚举表
  					friend_roleid = objId, -- 好友账户下的角色id
  					friend_cnt = curCount + 1, -- 操作后好友数量
  				})
c384626d   zhouhaihai   好友
321
322
323
324
  			end
  		end
  
  		redisproxy:pipelining(function (red)
92d7d6ac   zhouhaihai   加一些数据保护
325
326
327
328
  			if next(needAdd) then
  				red:ZREM(FRIEND_APPLY_KEY:format(roleId), table_unpack(needAdd))
  				for _, objectId in pairs(needAdd) do
  					red:ZREM(FRIEND_APPLY_KEY:format(objectId), roleId)
6136eaca   liuzujun   添加好友表
329
  					addFriend(roleId, objectId)
92d7d6ac   zhouhaihai   加一些数据保护
330
331
  				end
  			end
c384626d   zhouhaihai   好友
332
333
334
335
336
337
338
339
340
341
342
  		end)
  		local myInfo = role:friendSInfo()
  		myInfo.roleId = roleId
  		myInfo.online = true
  		myInfo.isFriend = 1
  		local giveFP = role.dailyData:getProperty("giveFP")
  		for _, objectId in pairs(needAdd) do
  			myInfo.pGet = giveFP[objectId]
  			rpcRole(objectId, "SendPacket", actionCodes.Friend_updateProperty, MsgPack.pack({newFriend = 1, info = {myInfo}}))	-- 通知对方
  		end
  		if next(needAdd) then
f22a33af   zhouhaihai   自己的日志
343
344
  			role:mylog("role_action", {desc = "addFriend", int1 = #needAdd})
  
c384626d   zhouhaihai   好友
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
  			SendPacket(actionCodes.Friend_updateProperty, MsgPack.pack({newFriend = 1, info = needAddInfo}))
  		else
  			result = 1
  		end
  		
  	else 	--不存在
  		return
  	end
  
  	SendPacket(actionCodes.Friend_handleApplyRpc, MsgPack.pack({result = result}))
  	return true
  end
  
  function _M.listRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  
  	local friendList = {}
  	local redret = redisproxy:pipelining(function (red)
c384626d   zhouhaihai   好友
364
365
366
  		red:SMEMBERS(FRIEND_POINT:format(roleId))
  	end)
  
6136eaca   liuzujun   添加好友表
367
  	local fpoint = formatArray(redret[1])
c384626d   zhouhaihai   好友
368
369
370
  	local hadGet = role.dailyData:getProperty("getFP")
  	local hadGive = role.dailyData:getProperty("giveFP")
  
6136eaca   liuzujun   添加好友表
371
372
  	local addNew = false 
  	for id, friend in pairs(role.friends) do
c384626d   zhouhaihai   好友
373
374
375
376
  		local online, info = getRoleInfo(id)
  		local roleInfo = {
  			roleId = id, 
  			online = online, 
6136eaca   liuzujun   添加好友表
377
378
  			addTime = friend:getProperty("addTime"), 
  			isNew = friend:getProperty("isNew"),
c384626d   zhouhaihai   好友
379
380
381
382
383
384
385
  			pGive = hadGive[id],
  			pGet = hadGet[id] and -1 or (fpoint[id] and 1 or nil)
  		}
  		roleInfo = table_merge(roleInfo, info, {})
  
  		friendList[#friendList + 1] = roleInfo
  
6136eaca   liuzujun   添加好友表
386
387
388
  		if roleInfo.isNew then
  			friend:setProperty("isNew", 0)	
  			addNew = true
c384626d   zhouhaihai   好友
389
390
  		end
  	end
6136eaca   liuzujun   添加好友表
391
  	if addNew then
3dbbc9f3   zhouhaihai   加上新的任务
392
  		role:checkTaskEnter("AddFriend", {count = #friendList})
c384626d   zhouhaihai   好友
393
394
395
396
397
398
399
400
401
402
403
  	end
  
  	SendPacket(actionCodes.Friend_listRpc, MsgPack.pack({list = friendList}))
  	return true
  end
  
  function _M.deleteRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  	local msg = MsgPack.unpack(data)
  	local objectId = msg.roleId
6136eaca   liuzujun   添加好友表
404
  	if not roleExists(objectId) then
c384626d   zhouhaihai   好友
405
406
407
  		return
  	end
  	-- 是否在好友列表中
6136eaca   liuzujun   添加好友表
408
409
  	if role.friends[objectId] then
  		role.friends[objectId] = nil
c384626d   zhouhaihai   好友
410
  		redisproxy:pipelining(function (red)
6136eaca   liuzujun   添加好友表
411
  			delFriend(roleId, objectId)
c384626d   zhouhaihai   好友
412
413
414
415
416
417
  			red:ZREM(FRIEND_APPLY_KEY:format(roleId), objectId)
  			red:ZREM(FRIEND_APPLY_KEY:format(objectId), roleId)
  		end)
  	end
  	rpcRole(objectId, "SendPacket", actionCodes.Friend_updateProperty, MsgPack.pack({deleteFriend = 1, roleId = roleId}))
  
c59e058b   zhouhaihai   新一批日志记录
418
419
420
421
422
  	role:log("friend_opt", {
  		friend_opt_type = 200, -- 好友操作类型,见枚举表中 好友操作类型枚举表
  		friend_roleid = objectId, -- 好友账户下的角色id
  		friend_cnt = 0, -- 操作后好友数量
  	})
c384626d   zhouhaihai   好友
423
424
425
426
427
428
429
430
431
432
  	SendPacket(actionCodes.Friend_deleteRpc, MsgPack.pack(""))
  	return true
  end
  
  function _M.blockRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  	local msg = MsgPack.unpack(data)
  	local cmd = msg.cmd
  	local objectId = msg.roleId
6136eaca   liuzujun   添加好友表
433
  	if not roleExists(objectId) then
c384626d   zhouhaihai   好友
434
435
436
437
438
439
440
441
442
443
444
445
  		return
  	end
  
  	local result = nil
  	if cmd == 1 then
  		-- 黑名单满了
  		if not result and not checkBlackLimit(roleId) then 
  			result = 1
  		end
  		-- 删除好友
  		if not result then
  			redisproxy:pipelining(function (red)
6136eaca   liuzujun   添加好友表
446
  				delFriend(roleId, objectId)
85083dba   zhouhaihai   拉黑从申请列表移除
447
448
  				red:ZREM(FRIEND_APPLY_KEY:format(roleId), objectId)
  				red:ZREM(FRIEND_APPLY_KEY:format(objectId), roleId)
c384626d   zhouhaihai   好友
449
450
  				red:sadd(FRIEND_BLACK_KEY:format(roleId), objectId)
  			end)
c59e058b   zhouhaihai   新一批日志记录
451
452
453
454
455
456
  			rpcRole(objectId, "SendPacket", actionCodes.Friend_updateProperty, MsgPack.pack({deleteFriend = 1, roleId = roleId}))
  			role:log("friend_opt", {
  				friend_opt_type = 300, -- 好友操作类型,见枚举表中 好友操作类型枚举表
  				friend_roleid = objectId, -- 好友账户下的角色id
  				friend_cnt = 0, -- 操作后好友数量
  			})
c384626d   zhouhaihai   好友
457
458
459
460
461
462
  		end
  	elseif cmd == 2 then
  		redisproxy:SREM(FRIEND_BLACK_KEY:format(roleId), objectId)
  	else
  		return
  	end
c384626d   zhouhaihai   好友
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
  	SendPacket(actionCodes.Friend_blockRpc, MsgPack.pack({result = result}))
  	return true
  end
  
  function _M.blockListRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  
  	local blockList = {}
  
  	local friends = redisproxy:SMEMBERS(FRIEND_BLACK_KEY:format(roleId))
  	for _ , id in pairs(friends) do
  		id = tonumber(id)
  		local online, info = getRoleInfo(id)
  		table.insert(blockList, table_merge({
  			roleId = id, online = online
  		}, info, {
  
  		}))
  	end
5dfc4978   zhouhaihai   好友完善
483
  
c384626d   zhouhaihai   好友
484
485
486
487
488
489
490
491
492
  	SendPacket(actionCodes.Friend_blockListRpc, MsgPack.pack({list = blockList}))
  	return true
  end
  
  function _M.infoRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  	local msg = MsgPack.unpack(data)
  	local objectId = msg.roleId
6136eaca   liuzujun   添加好友表
493
494
  
  	if not roleExists(objectId) then
c384626d   zhouhaihai   好友
495
496
497
498
499
  		return
  	end
  
  	local online, info = getRoleAllInfo(objectId)
  	local redret = redisproxy:pipelining(function (red)
c384626d   zhouhaihai   好友
500
501
502
  		red:zscore(FRIEND_APPLY_KEY:format(objectId), roleId)
  		red:sismember(FRIEND_BLACK_KEY:format(roleId), objectId)
  	end)
6136eaca   liuzujun   添加好友表
503
504
505
  	local isFriend = role.friends[objectId] and 1 or nil
  	local hadApply = redret[1] == 1 and 1 or nil
  	local inBlack = redret[2] == 1 and 1 or nil
c384626d   zhouhaihai   好友
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
  
  	local objInfo = table_merge({
  		roleId = objectId, 
  		online = online, 
  		isFriend = isFriend, 
  		hadApply = hadApply,
  		inBlack = inBlack,
  	}, info, {
  
  	})
  	SendPacket(actionCodes.Friend_infoRpc, MsgPack.pack({info = objInfo}))
  	return true
  end
  
  function _M.pointRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  	local msg = MsgPack.unpack(data)
  	local cmd = msg.cmd
  	local result = nil
  	local reward = {}
  	if cmd == 1 then  -- 赠送
  		local objId = msg.roleId
  		local giveP = role.dailyData:getProperty("giveFP")
  		if not result and giveP[objId] then 
  			result = 1
  		end
6136eaca   liuzujun   添加好友表
533
  		if not result and not role.friends[objId] then
c384626d   zhouhaihai   好友
534
535
536
537
538
539
  			result = 2
  		end
  		if not result then
  			redisproxy:sadd(FRIEND_POINT:format(objId), roleId)
  			giveP[objId] = 1
  			role.dailyData:updateProperty({field = "giveFP", value = giveP})
3dbbc9f3   zhouhaihai   加上新的任务
540
  			role:checkTaskEnter("GiveFriendP", {count = 1})
c384626d   zhouhaihai   好友
541
  			rpcRole(objId, "SendPacket", actionCodes.Friend_updateProperty, MsgPack.pack({newPoint = 1, roleId = roleId}))
f22a33af   zhouhaihai   自己的日志
542
543
  
  			role:mylog("role_action", {desc = "giveFPoint", int1 = 1})
c384626d   zhouhaihai   好友
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
  		end
  	elseif cmd == 2 then -- 领取
  		local objId = msg.roleId
  		local getP = role.dailyData:getProperty("getFP")
  		if not result and table.numbers(getP) >= globalCsv.friendPointLimit then
  			result = 1
  		end
  		if not result and getP[objId] then
  			result = 2
  		end
  		if not redisproxy:sismember(FRIEND_POINT:format(roleId), objId) then
  			result = 3
  		end
  		if not result then
  			getP[objId] = 1
3133cb76   zhouhaihai   日志
559
  			reward = role:award({[ItemId.FriendPoint] = 1}, {log = {desc = "friendPoint"}})
c384626d   zhouhaihai   好友
560
  			role.dailyData:updateProperty({field = "getFP", value = getP})
3dbbc9f3   zhouhaihai   加上新的任务
561
  			role:checkTaskEnter("GetFriendP", {count = 1})
3133cb76   zhouhaihai   日志
562
  
f22a33af   zhouhaihai   自己的日志
563
  			role:mylog("role_action", {desc = "getFPoint", int1 = 1})
c384626d   zhouhaihai   好友
564
565
566
567
  		end
  	elseif cmd == 3 then -- 一键赠送领取
  		-- 赠送
  		local giveP = role.dailyData:getProperty("giveFP")
3dbbc9f3   zhouhaihai   加上新的任务
568
  		local change = 0
c384626d   zhouhaihai   好友
569
  		redisproxy:pipelining(function(red)
6136eaca   liuzujun   添加好友表
570
  			for objId, friend in pairs(role.friends) do
c384626d   zhouhaihai   好友
571
572
  				if not giveP[objId] then
  					giveP[objId] = 1
3dbbc9f3   zhouhaihai   加上新的任务
573
  					change = change + 1
c384626d   zhouhaihai   好友
574
575
576
577
578
  					red:sadd(FRIEND_POINT:format(objId), roleId)
  					rpcRole(objId, "SendPacket", actionCodes.Friend_updateProperty, MsgPack.pack({newPoint = 1, roleId = roleId}))
  				end
  			end
  		end)
3dbbc9f3   zhouhaihai   加上新的任务
579
  		if change > 0 then
c384626d   zhouhaihai   好友
580
  			role.dailyData:updateProperty({field = "giveFP", value = giveP})
3dbbc9f3   zhouhaihai   加上新的任务
581
  			role:checkTaskEnter("GiveFriendP", {count = change})
3133cb76   zhouhaihai   日志
582
  
f22a33af   zhouhaihai   自己的日志
583
584
  			role:mylog("role_action", {desc = "giveFPoint", int1 = change})
  
c384626d   zhouhaihai   好友
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
  		else
  			result = 1
  		end
  		
  		--领取
  		local getP = role.dailyData:getProperty("getFP")
  		local curCount = table.numbers(getP)
  		local getCount = 0
  		if curCount < globalCsv.friendPointLimit then
  			for _, objId in pairs(redisproxy:SMEMBERS(FRIEND_POINT:format(roleId))) do
  				local objId = tonumber(objId)
  				if not getP[objId] then
  					getCount = getCount + 1
  					curCount = curCount + 1
  					getP[objId] = 1
  					if curCount >= globalCsv.friendPointLimit then
  						break
  					end
  				end
  			end
  			if getCount > 0 then
3133cb76   zhouhaihai   日志
606
  				reward = role:award({[ItemId.FriendPoint] = getCount}, {log = {desc = "friendPoint"}})
c384626d   zhouhaihai   好友
607
  				role.dailyData:updateProperty({field = "getFP", value = getP})
3dbbc9f3   zhouhaihai   加上新的任务
608
  				role:checkTaskEnter("GetFriendP", {count = getCount})
f22a33af   zhouhaihai   自己的日志
609
  				role:mylog("role_action", {desc = "getFPoint", int1 = getCount})
c384626d   zhouhaihai   好友
610
  			else
8474ca36   zhouhaihai   聊天
611
  				result = (result or 0) + 2
c384626d   zhouhaihai   好友
612
613
614
615
616
617
618
619
620
621
622
623
624
  			end
  		end
  	else
  		return
  	end
  	SendPacket(actionCodes.Friend_pointRpc, MsgPack.pack({result = result, reward = reward}))
  	return true
  end
  function _M.randomRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  
  	local redret = redisproxy:pipelining(function (red)
5dfc4978   zhouhaihai   好友完善
625
626
  		red:zrevrange(FRIEND_RECOMMEND, 0, globalCsv.friendRecommendLimit + globalCsv.friendListLimit + 10) --扩充10个
  		red:SMEMBERS(FRIEND_BLACK_KEY:format(roleId))
c384626d   zhouhaihai   好友
627
  	end)
5dfc4978   zhouhaihai   好友完善
628
  
6136eaca   liuzujun   添加好友表
629
630
  	local newList = redret[1]
  	local hadBlack = formatArray(redret[2])
5dfc4978   zhouhaihai   好友完善
631
  
c384626d   zhouhaihai   好友
632
633
634
  	local needRoleIds = {}
  	for _, newId in pairs(newList) do
  		local numNewId = tonumber(newId)
6136eaca   liuzujun   添加好友表
635
  		if numNewId ~= roleId and not role.friends[numNewId] and not hadBlack[numNewId] then
c384626d   zhouhaihai   好友
636
637
638
639
640
  			table.insert(needRoleIds, numNewId)
  		end
  	end
  
  	local randomRoles = {}
5dfc4978   zhouhaihai   好友完善
641
642
  	local redret = redisproxy:pipelining(function (red)
  		for _, objId in ipairs(needRoleIds) do
c384626d   zhouhaihai   好友
643
  			red:zscore(FRIEND_APPLY_KEY:format(objId), roleId)
5dfc4978   zhouhaihai   好友完善
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
  		end
  	end)
  	for idx, objId in ipairs(needRoleIds) do
  		if not redret[idx] then
  			local online, info = getRoleInfo(objId)
  			table.insert(randomRoles, table_merge({
  				roleId = objId, 
  				online = online,  
  				hadApply = hadApply,
  				inBlack = inBlack,
  			}, info, {
  
  			}))
  			if #randomRoles >= globalCsv.friendRecommendLimit then break end
  		end
c384626d   zhouhaihai   好友
659
660
661
662
663
664
  	end
  
  	SendPacket(actionCodes.Friend_randomRpc, MsgPack.pack({list = randomRoles}))
  	return true
  end
  
f603a60f   zhouhaihai   支援技实装
665
666
667
668
669
670
671
672
673
674
  function _M.battleInfoRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  	local msg = MsgPack.unpack(data)
  	local objId = msg.roleId
  	local online, matchInfo = rpcRole(objId, "friendBattleInfo")
  	SendPacket(actionCodes.Friend_battleInfoRpc, MsgPack.pack({matchInfo = matchInfo}))
  	return true
  end
  
c384626d   zhouhaihai   好友
675
676
  
  return _M