difenduandada
2024-12-31 34abe6963b344c882358274957f4b992456fee40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
"use strict";
cc._RF.push(module, 'bfba6w+qEdKqbSx0rq3BbHq', 'chat_controller');
// Scripts/mod/chat/chat_controller.js
 
"use strict";
 
var ChatConst = require("chat_const");
 
var ChatController = cc.Class({
  "extends": BaseController,
  ctor: function ctor() {
    var ChatModel = require("chat_model");
 
    this.model = new ChatModel(this);
    this.model.initConfig();
    this.chat_time = {};
  },
  registerEvents: function registerEvents() {
    this.init_role_event = gcore.GlobalEvent.bind(EventId.EVT_ROLE_CREATE_SUCCESS, function () {
      gcore.GlobalEvent.unbind(this.init_role_event);
      this.model.initPrivatreTargets();
    }.bind(this));
  },
  openChatPanel: function openChatPanel(channel, form, data) {
    var open_parame = {};
 
    if (!this.chat_window) {
      var ChatWindow = require("chat_window");
 
      this.chat_window = new ChatWindow();
    }
 
    open_parame.channel = form;
 
    if (form == "friend") {
      this.model.addPrivateTarget(data);
      open_parame.channel = ChatConst.Channel.Friend;
      open_parame.friend_data = data;
    }
 
    if (!this.chat_window.getVisible()) {
      this.chat_window.setVisible(true, open_parame);
    } else {
      this.chat_window.open(open_parame);
    }
  },
  closeChatPanel: function closeChatPanel() {
    if (this.chat_window) {
      var PromptController = require("prompt_controller");
 
      var PromptTypeConst = require("prompt_type_const");
 
      PromptController.getInstance().getModel().removePromptDataByTpye(PromptTypeConst.Private_chat);
      PromptController.getInstance().getModel().removePromptDataByTpye(PromptTypeConst.At_notice); // this.chat_window.close();
      // this.chat_window = null;
 
      this.chat_window.setVisible(false);
 
      var MainUIController = require("mainui_controller");
 
      MainUIController.getInstance().showChatBtn(true);
    }
  },
  initData: function initData() {},
  getModel: function getModel() {
    return this.model;
  },
  initConfig: function initConfig() {
    var ChatModel = require("chat_model");
 
    this.model = new ChatModel();
    this.model.initConfig();
    this.is_first = true;
    this.pro_12766 = true;
    this.stack_id = 0;
  },
  registerProtocals: function registerProtocals() {
    this.RegisterProtocal(12720, this.handle12720); // 私聊
 
    this.RegisterProtocal(12721, this.handle12721); // 推送私聊消息
 
    this.RegisterProtocal(12722, this.handle12722); // 登陆推送私聊信息
 
    this.RegisterProtocal(12725, this.handle12725); // 语音信息
 
    this.RegisterProtocal(12726, this.handle12726); // 下载语音信息
 
    this.RegisterProtocal(12741, this.handle12741); // 提示
 
    this.RegisterProtocal(12743, this.handle12743); // 系统提示&聊天提示
 
    this.RegisterProtocal(12799, this.handle12799); // 消息发送
 
    this.RegisterProtocal(12761, this.handle12761); // 接受通用聊天
 
    this.RegisterProtocal(12762, this.handle12762); // 发送通用聊天
 
    this.RegisterProtocal(12763, this.handle12763); // 服务端分发翻译
 
    this.RegisterProtocal(12766, this.handle12766); // 登录聊天记录
 
    this.RegisterProtocal(12771, this.handle12771); // 聊天玩家队伍id
 
    this.RegisterProtocal(12767, this.handle12767); // 聊天@
 
    this.RegisterProtocal(12768, this.handle12768); // 已查看
  },
  isChatOpen: function isChatOpen() {
    if (this.chat_window) {
      return this.chat_window.getVisible();
    }
 
    return false;
  },
 
  /**
   * 发送翻译后的文字消息
   * @author zhanghuxing 2019-01-03
   * @param  {[type]} msg       [description]
   * @param  {[type]} channel   [description]
   * @param  {[type]} taken_obj [description]
   * @return {[type]}           [description]
   */
  sendVoidMsg: function sendVoidMsg(msg, channel, taken_obj) {
    if (channel == ChatConst.Channel.Friend) {
      this.sender12720();
    } else {
      this.sender12762();
    }
  },
 
  /**
   * 发送文字信息
   * @author zhanghuxing 2019-01-03
   * @param  {[type]} msg       [description]
   * @param  {[type]} channel   频道
   * @param  {[type]} taken_obj [description]
   * @param  {[type]} len       [description]
   * @return {[type]}           [description]
   */
  sendMessage: function sendMessage(channel, msg, len, to_srv_id, to_rid, name) {
    cc.log("chat__________", msg, channel, len, to_srv_id, to_rid);
 
    if (channel == ChatConst.Channel.Friend) {
      this.sender12720(to_srv_id, to_rid, msg, len, name);
    } else {
      this.sender12762(channel, msg, len);
    }
  },
  sender12720: function sender12720(to_srv_id, to_rid, msg, len, name) {
    // 发起私聊
    var msg_data = {};
    msg_data.to_srv_id = to_srv_id;
    msg_data.to_rid = to_rid;
    msg_data.msg = msg;
    msg_data.len = len;
    this.SendProtocal(12720, msg_data); // cc.log("sl---------------",to_rid.split("_"))
    //爱微游渠道聊天监控
 
    if (window.CHANNEL == "AIWEIYOU_PID") {
      var rid = null;
      to_rid = String(to_rid);
      var arr = to_rid.split("_");
      rid = arr[1];
      sdk.chatMonitor({
        to_srv_id: to_srv_id,
        to_rid: rid,
        type: 1,
        //1表示私聊
        name: name,
        msg: msg
      });
    }
  },
  handle12720: function handle12720(data) {
    // 私聊失败提示
    cc.log("私聊失败");
    cc.log(data);
 
    if (data.code == 0) {
      message(data.msg);
    }
  },
  handle12721: function handle12721(data) {
    // 收到私聊消息
    cc.log("私聊消息");
    cc.log(data);
    if (data) this.model.addPrivateMsg(data);
  },
  handle12722: function handle12722(msg_datas) {
    // 登陆推送离线私聊信息
    cc.log("离线私聊消息");
    cc.log(msg_datas);
 
    if (msg_datas && msg_datas.offline_list.length > 0) {
      var offline_Info = null;
 
      for (var offline_i = 0; offline_i < msg_datas.offline_list.length; offline_i++) {
        offline_Info = msg_datas.offline_list[offline_i];
 
        if (offline_Info.msg_list && offline_Info.msg_list) {
          for (var msg_i = 0; msg_i < offline_Info.msg_list.length; msg_i++) {
            var msg_info = Utils.deepCopy(offline_Info);
            delete msg_info.msg_list;
            msg_info.msg = offline_Info.msg_list[msg_i].msg;
            msg_info.len = offline_Info.msg_list[msg_i].len;
            msg_info.tick = offline_Info.msg_list[msg_i].tick;
            msg_info.offline = true;
            msg_info.flag = 2;
            this.model.addOutlinePrivateMsg(msg_info);
          }
        }
      }
    }
  },
  // 通知服务端已读消息
  sender12723: function sender12723(srv_id, rid) {
    if (srv_id === null || rid === null) return;
    var protocal = {};
    protocal.rid = rid;
    protocal.srv_id = srv_id;
    this.SendProtocal(12723, protocal);
  },
  handle12725: function handle12725(data) {// 语音信息
  },
  handle12726: function handle12726(data) {// 下载语音信息
  },
  handle12741: function handle12741(data) {
    // 提示
    // 消耗<assets=3/><div fontcolor=#ef3a3a>1600</div>,获得<div fontcolor=#c26706>荣光符石</div>
    // 消耗,获得<div fontcolor=#c26706>魔力符石</div>
    message(data.msg);
  },
  handle12743: function handle12743(data) {
    // 系统提示&聊天提示(在聊天框显示)
    message(data.msg);
    var sys_msg = {};
    sys_msg.len = 0;
    sys_msg.channel = ChatConst.Channel.System;
    sys_msg.role_list = {};
    sys_msg.msg = data.msg;
    this.handle12761(sys_msg, true);
  },
  handle12799: function handle12799(data) {// 消息发送
  },
  handle12761: function handle12761(data) {
    // 接受通用聊天
    if (!data) return;
    if (this.pro_12766 && !this.is_first) this.pro_12766 = false;
    this.is_first = false;
    this.model.addNormalChatMsg(data.channel, data);
    this.handle12761__(data);
  },
  handle12761__: function handle12761__(data) {
    var channel = data.channel;
 
    if (channel == ChatConst.Channel.System || channel == ChatConst.Channel.NoticeTop || channel == ChatConst.Channel.System1 || channel == ChatConst.Channel.SystemTop) {
      var msg = data.msg;
      msg = StringUtil.parseStr(msg).string;
      GlobalMessageMgr.getInstance().showMoveHorizontal(msg, new cc.Color(255, 255, 255));
    }
  },
  sender12762: function sender12762(channel, msg, len) {
    // 发起通用聊天
    if (!channel || !msg || !len) return;
    var sender_data = {};
    sender_data.channel = channel;
    sender_data.msg = msg;
    sender_data.len = len; // 判断时间
 
    var canSend = this.canSend(channel);
 
    if (canSend) {
      this.SendProtocal(12762, sender_data);
      this.saveChatTime(channel);
    } else {
      var cur_time = gcore.SmartSocket.getTime();
      var last_time = this.chat_time["sec_" + channel];
      var time_index = ChatConst.ChatTimeIndex[channel];
      var time_info = SayConfig[time_index];
 
      if (time_info) {
        var time = time_info.val + last_time - cur_time;
        time = time || 1;
        message(Utils.TI18N("距离下次发言还剩下" + time + "秒"));
      }
    }
  },
  canSend: function canSend(channel) {
    if (!this.chat_time["sec_" + channel]) return true;
    var last_time = this.chat_time["sec_" + channel];
    var cur_time = gcore.SmartSocket.getTime();
    var time_index = ChatConst.ChatTimeIndex[channel];
    var time_info = SayConfig[time_index];
 
    if (time_info) {
      if (time_info.val + last_time < cur_time) return true;
    }
 
    return false;
  },
  saveChatTime: function saveChatTime(channel) {
    var cur_time = gcore.SmartSocket.getTime();
    var chat_index = "sec_" + channel; // if (!this.chat_time[chat_index])
 
    this.chat_time[chat_index] = cur_time;
  },
  handle12762: function handle12762(data) {
    // 发送通用聊天结果
    cc.log("发送通用聊天结果");
    cc.log(data);
    if (data.code == 0) message(data.msg);
  },
  handle12763: function handle12763(data) {// 服务端分发翻译
  },
  handle12766: function handle12766(data) {
    // 登录聊天记录
    if (this.pro_12766) {
      this.pro_12766 = false;
 
      for (var msg_i in data.msg_list) {
        this.handle12761(data.msg_list[msg_i]);
      }
 
      this.pro_12766 = true;
    }
  },
  handle12771: function handle12771(data) {// 聊天玩家队伍id
  },
  handle12767: function handle12767(data) {
    // 聊天@
    this.model.setAtData(data);
 
    if (this.chat_window) {
      this.chat_window.showAtNotice(true, data);
    }
  },
  // 已查看艾特信息
  sender12768: function sender12768(rid, srv_id, channel, msg) {
    var protocal = {};
    protocal.rid = rid;
    protocal.srv_id = srv_id;
    protocal.channel = channel;
    protocal.msg = msg;
    this.SendProtocal(12768, protocal);
  },
  handle12768: function handle12768(data) {// 已查看@
  },
  // 聊天记录唯一ID
  getUniqueId: function getUniqueId() {
    if (this.stack_id == null) {
      this.stack_id = 0;
    }
 
    this.stack_id = this.stack_id + 1;
    return this.stack_id;
  },
  // 打开好友信息界面
  openFriendInfo: function openFriendInfo(data) {
    var FriendController = require("friend_controller");
 
    FriendController.getInstance().openFriendCheckPanel(true, data);
  },
  // 返回聊天的输入组件
  getChatInput: function getChatInput() {
    if (this.chat_window) {
      if (this.chat_window.chat_input_panel) {
        return this.chat_window.chat_input_panel;
      }
    }
  },
  //  @人
  chatAtPeople: function chatAtPeople(name, srv_id) {
    var chatInput = this.getChatInput();
 
    if (chatInput) {
      chatInput.setInputText("@" + name + " ", srv_id);
    }
  },
  // 返回信息的id
  getId: function getId(channel, srv_id, rid, name, msg) {
    var list = this.model.getChannelMsgs(channel);
    var id = 1;
 
    for (var i = 0, l = list.length; i < l; i++) {
      if (list[i].role_list && list[i].role_list[0]) {
        var v = list[i].role_list[0];
 
        if (srv_id == v.srv_id && rid == v.rid && name == v.name && msg == list[i].msg) {
          id = list[i].id;
        }
      }
    }
 
    return id;
  }
});
module.exports = ChatController;
 
cc._RF.pop();