|
@@ -0,0 +1,271 @@
|
|
1
|
+--[[
|
|
2
|
+Descripttion:玩家埋点
|
|
3
|
+version:
|
|
4
|
+Author: Neo,Huang
|
|
5
|
+Date: 2022-05-26 19:45:58
|
|
6
|
+LastEditors: Neo,Huang
|
|
7
|
+LastEditTime: 2022-05-26 19:46:41
|
|
8
|
+--]]
|
|
9
|
+local skynet = require("skynet")
|
|
10
|
+local serverLogUtil = require("utils.serverLogUtil")
|
|
11
|
+local nodeMgr = require("nodeMgr")
|
|
12
|
+local code = require("code")
|
|
13
|
+local battleCode = require("battle.battleCode")
|
|
14
|
+
|
|
15
|
+local moduleData = require("data.module")
|
|
16
|
+
|
|
17
|
+local root = {}
|
|
18
|
+
|
|
19
|
+function root:makeItemsStr(itemss)
|
|
20
|
+ local str = ""
|
|
21
|
+ for _, value in ipairs(itemss or {}) do
|
|
22
|
+ if str == "" then
|
|
23
|
+ str = str .. value.id .. "," .. value.count
|
|
24
|
+ else
|
|
25
|
+ str = str .. "," .. value.id .. "," .. value.count
|
|
26
|
+ end
|
|
27
|
+ end
|
|
28
|
+ return str
|
|
29
|
+end
|
|
30
|
+
|
|
31
|
+-- 埋点 - 事件
|
|
32
|
+function root:log_event(uid, keyEvent, cnt)
|
|
33
|
+ if is_empty(uid) or is_empty(keyEvent) or is_empty(cnt) then
|
|
34
|
+ return
|
|
35
|
+ end
|
|
36
|
+
|
|
37
|
+ local version = moduleData:get_version(uid)
|
|
38
|
+ local channel = moduleData:get_channel(uid)
|
|
39
|
+
|
|
40
|
+ serverLogUtil.logEvent(uid, version, channel, keyEvent, cnt)
|
|
41
|
+end
|
|
42
|
+-- 埋点 - 资源变化
|
|
43
|
+function root:log_resource(uid, keyEvent, itemId, delta, total)
|
|
44
|
+ if is_empty(uid) or is_empty(keyEvent) or is_empty(itemId) then
|
|
45
|
+ return
|
|
46
|
+ end
|
|
47
|
+
|
|
48
|
+ local channel = moduleData:get_channel(uid)
|
|
49
|
+
|
|
50
|
+ serverLogUtil.logResource(uid, keyEvent, itemId, delta, total, channel)
|
|
51
|
+end
|
|
52
|
+-- 埋点 - 广告
|
|
53
|
+function root:log_ad(uid, pos, action)
|
|
54
|
+ if is_empty(uid) or is_empty(pos) or is_empty(action) then
|
|
55
|
+ return
|
|
56
|
+ end
|
|
57
|
+
|
|
58
|
+ local version = moduleData:get_version(uid)
|
|
59
|
+ local channel = moduleData:get_channel(uid)
|
|
60
|
+
|
|
61
|
+ serverLogUtil.logAdvertise(uid, channel, version, pos, action)
|
|
62
|
+end
|
|
63
|
+
|
|
64
|
+-- 通知
|
|
65
|
+function root:user_proto_notify(uid, protoName, msg)
|
|
66
|
+ if uid == nil or protoName == nil then
|
|
67
|
+ log.error("玩家消息推送失败 uid[%s] protoName[%s]", tostring(uid), tostring(protoName))
|
|
68
|
+ return false
|
|
69
|
+ end
|
|
70
|
+ if is_robot(uid) then
|
|
71
|
+ return false
|
|
72
|
+ end
|
|
73
|
+ local nodeInfo = self:user_get_cluster_info(uid, "gate")
|
|
74
|
+ if nodeMgr.is_node_info_valid(nodeInfo) then
|
|
75
|
+ nodeMgr.send_with_node_info(nodeInfo, "pushS2C", uid, protoName, msg)
|
|
76
|
+ return true
|
|
77
|
+ else
|
|
78
|
+ log.error("玩家消息推送失败 uid[%s] nodeInfo[%s] protoName[%s]", tostring(uid), tostring(nodeInfo), tostring(protoName))
|
|
79
|
+ end
|
|
80
|
+ return false
|
|
81
|
+end
|
|
82
|
+-- 推送 - 客户端日志
|
|
83
|
+function root:user_notify_client_log(uid, msg)
|
|
84
|
+ if uid == nil or is_empty(msg) then
|
|
85
|
+ return
|
|
86
|
+ end
|
|
87
|
+ if not IS_TEST then
|
|
88
|
+ return
|
|
89
|
+ end
|
|
90
|
+ -- self:user_proto_notify(uid, "on_log_client", {logStr = msg})
|
|
91
|
+end
|
|
92
|
+-- 踢玩家下线
|
|
93
|
+function root:user_kicked(uid, msg)
|
|
94
|
+ local nodeInfo = self:user_get_cluster_info(uid, "gate")
|
|
95
|
+ if nodeMgr.is_node_info_valid(nodeInfo) then
|
|
96
|
+ nodeMgr.send_with_node_info(nodeInfo, "kick", uid, msg)
|
|
97
|
+ end
|
|
98
|
+end
|
|
99
|
+
|
|
100
|
+-- 事件
|
|
101
|
+function root:user_dispatch_event(uid, eventId, evtParams)
|
|
102
|
+ if uid == nil or eventId == nil then
|
|
103
|
+ return false
|
|
104
|
+ end
|
|
105
|
+ -- log.info(
|
|
106
|
+ -- "user_dispatch_event uid[%s] eventId[%s] evtParams[%s]",
|
|
107
|
+ -- tostring(uid),
|
|
108
|
+ -- tostring(eventId),
|
|
109
|
+ -- tostring(evtParams)
|
|
110
|
+ -- )
|
|
111
|
+ if evtParams.times == nil then
|
|
112
|
+ evtParams.times = 1
|
|
113
|
+ end
|
|
114
|
+ local nodeInfo = self:user_get_cluster_info(uid, "game")
|
|
115
|
+ if nodeMgr.is_node_info_valid(nodeInfo) then
|
|
116
|
+ nodeMgr.send_with_node_info(nodeInfo, "userGameEvent", uid, eventId, evtParams)
|
|
117
|
+ return true
|
|
118
|
+ end
|
|
119
|
+ -- TODO: Debug 埋这么大的一个坑,做什么呢?
|
|
120
|
+ nodeMgr.send("game1_1", ".settleSrv", "user_game_event", uid, eventId, evtParams)
|
|
121
|
+ return false
|
|
122
|
+end
|
|
123
|
+
|
|
124
|
+----------------------------------------
|
|
125
|
+-- 节点分配
|
|
126
|
+----------------------------------------
|
|
127
|
+local function l_dispatch_server_node(nodeType, uid)
|
|
128
|
+ local funcName = "dispatchServer"
|
|
129
|
+ if IS_PARTITION then
|
|
130
|
+ -- TODO: Debug 分服逻辑,是否分区/分服?
|
|
131
|
+ funcName = "dispatchServerByPartition"
|
|
132
|
+ end
|
|
133
|
+
|
|
134
|
+ local ok, server = nodeMgr.call("master", ".server_mgr", funcName, nodeType, uid, PARTITION_ID)
|
|
135
|
+ if not ok then
|
|
136
|
+ return
|
|
137
|
+ end
|
|
138
|
+ return server
|
|
139
|
+end
|
|
140
|
+--- 分配网关节点
|
|
141
|
+function root:user_dispatch_gate_node(uid)
|
|
142
|
+ return l_dispatch_server_node("gate", uid)
|
|
143
|
+end
|
|
144
|
+
|
|
145
|
+--- 分配游戏节点
|
|
146
|
+function root:user_dispatch_game(uid)
|
|
147
|
+ local node = l_dispatch_server_node("game", uid)
|
|
148
|
+ if node == nil or is_empty(node.nodename) then
|
|
149
|
+ return
|
|
150
|
+ end
|
|
151
|
+ local gameAgentMgr = nodeMgr.query_node_service_addr(node.nodename, ".gameAgentMgr")
|
|
152
|
+ if not gameAgentMgr then
|
|
153
|
+ return
|
|
154
|
+ end
|
|
155
|
+
|
|
156
|
+ local ok, gameAgent = nodeMgr.call(node.nodename, gameAgentMgr, "newGameAgent")
|
|
157
|
+ if not ok or gameAgent == nil then
|
|
158
|
+ return
|
|
159
|
+ end
|
|
160
|
+ return {nodeName = node.nodename, agent = gameAgent}
|
|
161
|
+end
|
|
162
|
+-- 分配Business节点
|
|
163
|
+function root:user_dispatch_match_node(uid, conf)
|
|
164
|
+ local ok, matchNode = nodeMgr.call("battle_master", ".server_mgr", "dispatch_match_node", uid, conf)
|
|
165
|
+ if not ok or is_empty(matchNode) then
|
|
166
|
+ return
|
|
167
|
+ end
|
|
168
|
+
|
|
169
|
+ local ok, matchAgent = nodeMgr.call(matchNode, ".BattleMatch", "dispatch_match_agent", conf.battleType)
|
|
170
|
+ if not ok then
|
|
171
|
+ return
|
|
172
|
+ end
|
|
173
|
+ local nodeInfo = {}
|
|
174
|
+ nodeInfo.nodeName = matchNode
|
|
175
|
+ nodeInfo.agent = matchAgent
|
|
176
|
+ return nodeInfo
|
|
177
|
+end
|
|
178
|
+
|
|
179
|
+local MODULE_SESSION = "tb_session"
|
|
180
|
+-- 玩家节点信息
|
|
181
|
+function root:user_get_cluster_info(uid, clusterName)
|
|
182
|
+ if uid == nil or is_empty(clusterName) then
|
|
183
|
+ return
|
|
184
|
+ end
|
|
185
|
+ local nodeInfo = moduleData:hget_json(uid, MODULE_SESSION, clusterName)
|
|
186
|
+ if is_empty(nodeInfo) then
|
|
187
|
+ nodeInfo = nil
|
|
188
|
+ end
|
|
189
|
+ return nodeInfo
|
|
190
|
+end
|
|
191
|
+
|
|
192
|
+-- 玩家是否登录网关
|
|
193
|
+function root:user_is_online_gate(uid)
|
|
194
|
+ local nodeInfo = self:user_get_cluster_info(uid, "gate")
|
|
195
|
+ if nodeMgr.is_node_info_valid(nodeInfo) then
|
|
196
|
+ return true
|
|
197
|
+ end
|
|
198
|
+
|
|
199
|
+ return false
|
|
200
|
+end
|
|
201
|
+
|
|
202
|
+-- 玩家是否登录游戏
|
|
203
|
+function root:user_is_online_game(uid)
|
|
204
|
+ local nodeInfo = self:user_get_cluster_info(uid, "game")
|
|
205
|
+ if nodeMgr.is_node_info_valid(nodeInfo) then
|
|
206
|
+ return true
|
|
207
|
+ end
|
|
208
|
+ return false
|
|
209
|
+end
|
|
210
|
+----------------------------------------
|
|
211
|
+-- game
|
|
212
|
+----------------------------------------
|
|
213
|
+function root:user_send_game_agent(uid, interface, ...)
|
|
214
|
+ local nodeInfo = self:user_get_cluster_info(uid, "game")
|
|
215
|
+ if nodeMgr.is_node_info_valid(nodeInfo) then
|
|
216
|
+ nodeMgr.send_with_node_info(nodeInfo, "doCmd", uid, interface, ...)
|
|
217
|
+ end
|
|
218
|
+end
|
|
219
|
+
|
|
220
|
+function root:user_call_game_agent(uid, interface, ...)
|
|
221
|
+ local nodeInfo = self:user_get_cluster_info(uid, "game")
|
|
222
|
+ if nodeMgr.is_node_info_valid(nodeInfo) then
|
|
223
|
+ return nodeMgr.call_with_node_info(nodeInfo, "doCmd", uid, interface, ...)
|
|
224
|
+ end
|
|
225
|
+end
|
|
226
|
+
|
|
227
|
+----------------------------------------
|
|
228
|
+-- 中心服
|
|
229
|
+----------------------------------------
|
|
230
|
+local nodecluster = skynet.getenv("nodecluster")
|
|
231
|
+local nodename = skynet.getenv("node_name")
|
|
232
|
+-- 玩家登陆服务器
|
|
233
|
+function root:master_user_login(uid, ...)
|
|
234
|
+ return nodeMgr.call("master", ".server_mgr", "userLogin", nodecluster, nodename, uid, ...)
|
|
235
|
+end
|
|
236
|
+
|
|
237
|
+-- 玩家登出服务器
|
|
238
|
+function root:master_user_logout(uid, ...)
|
|
239
|
+ return nodeMgr.call("master", ".server_mgr", "userLogout", nodecluster, nodename, uid, ...)
|
|
240
|
+end
|
|
241
|
+
|
|
242
|
+----------------------------------------
|
|
243
|
+-- 战斗节点
|
|
244
|
+----------------------------------------
|
|
245
|
+function root:user_call_2_battle(uid, cmd, ...)
|
|
246
|
+ if uid == nil or cmd == nil then
|
|
247
|
+ return code.PARAMTER_ERROR
|
|
248
|
+ end
|
|
249
|
+ local nodeInfo = self:user_get_cluster_info(uid, "battle")
|
|
250
|
+ if not nodeMgr.is_node_info_valid(nodeInfo) or nodeInfo.battleId == nil then
|
|
251
|
+ return battleCode.BATTLE_NOT_EXIST
|
|
252
|
+ end
|
|
253
|
+ local ok, ret = nodeMgr.call_with_node_info(nodeInfo, "forward", nodeInfo.battleId, cmd, ...)
|
|
254
|
+ if not ok or ret == nil then
|
|
255
|
+ return battleCode.BATTLE_NOT_EXIST
|
|
256
|
+ end
|
|
257
|
+ return ret.code, ret
|
|
258
|
+end
|
|
259
|
+
|
|
260
|
+function root:user_send_2_battle(uid, cmd, ...)
|
|
261
|
+ if uid == nil or cmd == nil then
|
|
262
|
+ return code.PARAMTER_ERROR
|
|
263
|
+ end
|
|
264
|
+ local nodeInfo = self:user_get_cluster_info(uid, "battle")
|
|
265
|
+ if not nodeMgr.is_node_info_valid(nodeInfo) or nodeInfo.battleId == nil then
|
|
266
|
+ return battleCode.BATTLE_NOT_EXIST
|
|
267
|
+ end
|
|
268
|
+ nodeMgr.send_with_node_info(nodeInfo, "forward", nodeInfo.battleId, cmd, ...)
|
|
269
|
+end
|
|
270
|
+
|
|
271
|
+return root
|