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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
"use strict";
cc._RF.push(module, 'e3218URp9BHeqDf5i/2UjvX', 'game-core-js-min');
// Scripts/sys/game-core-js-min.js
 
"use strict";
 
var gcore = gcore || {};
module.exports = gcore;
var BaseEvent = cc.Class({
  ctor: function ctor() {
    this._evt_idx = 0, this._evt_list = {};
  },
  bind: function bind(t, e, i) {
    if (t) {
      if (e) {
        this._evt_list.hasOwnProperty(t) || (this._evt_list[t] = {});
        var s = this._evt_idx++;
        return this._evt_list[t][s] = {
          f: e,
          o: i
        }, {
          evt: t,
          id: s
        };
      }
 
      cc.log("evt_func===null");
    } else cc.log("evt_label===null");
  },
  unbind: function unbind(t) {
    this._evt_list.hasOwnProperty(t.evt) && (delete this._evt_list[t.evt][t.id], 0 == Object.keys(this._evt_list[t.evt]).length && delete this._evt_list[t.evt]);
  },
  fire: function fire(t) {
    if (this._evt_list.hasOwnProperty(t)) {
      var e = this._evt_list[t],
          i = Array.prototype.slice.apply(arguments);
 
      for (var s in i.shift(), e) {
        e[s].f.apply(e[s].o, i);
      }
    }
  }
});
gcore.BaseEvent = BaseEvent;
 
var Proto = require("proto_mate"),
    SmartSocket = {
  idx: 0,
  ws: null,
  buffer: null,
  cmd_func_list: [],
  msg_list: [],
  diff_time: 0,
  wait_time: 0,
  getInstance: function getInstance() {
    return this;
  },
  getTime: function getTime() {
    return this.diff_time + parseInt(Date.now() / 1e3);
  },
  getMsTime: function getMsTime() {
    return 1e3 * this.diff_time + Date.now();
  },
  setTime: function setTime(t) {
    this.diff_time = t - parseInt(Date.now() / 1e3);
  },
  init: function init() {
    this.is_init || (this.is_init = !0, Uint8Array.prototype.slice || (Uint8Array.prototype.slice = Array.prototype.slice), this.bindCmd(1199, this.on1199.bind(this)));
  },
  on1199: function on1199(t) {
    this.restHeartbeat(), this.setTime(t.time);
  },
  tick: function tick() {
    this.send(1199, {}), this.setTickTimer();
  },
  restHeartbeat: function restHeartbeat() {
    this.wait_time = 0;
  },
  updateTimer: function updateTimer() {
    this.ws && (this.wait_time += 1), 10 <= this.wait_time ? this.close() : 6 <= this.wait_time && this.send(1199, {});
  },
  setTickTimer: function setTickTimer() {
    this.heart_timer || (this.heart_timer = gcore.Timer.set(this.updateTimer.bind(this), 1e3, -1));
  },
  stopHeart: function stopHeart() {
    this.heart_timer && (gcore.Timer.del(this.heart_timer), this.heart_timer = null);
  },
  clearTickTimer: function clearTickTimer() {
    this.tick_timer && (window.clearTimeout(this.tick_timer), this.tick_timer = null);
  },
  connect: function connect(t, e, i) {
    i = i || "ws", OUT_NET && (i = "wss"), this.host = t, this.port = e, this.ws = i, this.buffer = null, this.msg_list = [], (i = new WebSocket(i + "://" + t + ":" + e + "/websocket")).binaryType = "arraybuffer";
    var s = i.net_id = ++this.idx;
    this.ws = i, Log.debug("socket_connect start", i, t, e, s), i.onopen = function (t) {
      s == this.idx && (Log.debug("socket_connected", t, i), this.ws = i, gcore.GlobalEvent.fire(gcore.GlobalEvent.EVT_SOCKET_CONNECT), this.setTickTimer(), this.restHeartbeat());
    }.bind(this), i.onclose = function (t) {
      s == this.idx && (Log.debug("socket_close", t), gcore.GlobalEvent.fire(gcore.GlobalEvent.EVT_SOCKET_DISCONNECT), this.clearTickTimer(), this.ws = null);
    }.bind(this), i.onerror = function (t) {}.bind(this), i.onmessage = function (t) {
      this.restHeartbeat(), this.doRecv(t.data);
    }.bind(this);
  },
  close: function close() {
    this.ws && (this.ws.close(), this.ws = null);
  },
  bindCmd: function bindCmd(t, e) {
    this.cmd_func_list.hasOwnProperty(t) || (this.cmd_func_list[t] = []), this.cmd_func_list[t].push(e);
  },
  send: function send(t, e) {
    try {
      if (null == this.ws) return void Log.debug("send_msg_socket_not_connect");
      var i = this.packData(t, e),
          s = new ArrayBuffer(i.length + 4),
          r = new DataView(s);
      r.setUint32(0, i.length);
 
      for (var n = 0; n < i.length; n++) {
        r.setUint8(n + 4, i[n]);
      }
 
      Log.socket("send_cmd:" + t), this.ws.send(r.buffer);
    } catch (t) {
      Log.error("send_msg_error:" + t.message, t.stack);
    }
  },
  handleMsg: function handleMsg() {
    if (0 != this.msg_list.length) for (var t = 0; t < 5; t++) {
      var e = this.msg_list.shift();
      if (this.onCmdCallback(e.cmd, e.data), 0 == this.msg_list.length) return;
    }
  },
  onCmdCallback: function onCmdCallback(e, i) {
    try {
      for (var t = this.cmd_func_list[e], s = 0; s < t.length; s++) {
        (0, t[s])(i);
      }
    } catch (t) {
      Log.error("handle_msg_error:" + e + ", err=" + t.message + ", data=" + i, t, t.stack);
    }
  },
  doRecv: function doRecv(t) {
    this.ws && this.ws.net_id == this.idx ? "string" != typeof t ? (t = null == this.buffer ? new Uint8Array(t) : this.buffer.concat(Array.from(new Uint8Array(t))), this.unpackBuffer(t)) : Log.info("recv=text= " + t) : Log.error("网络切换 本协议数据无效", this.ws, this.idx);
  },
  unpackBuffer: function unpackBuffer(e) {
    if (e.length < 6) this.buffer = e;else {
      var t = new DataView(new Uint8Array(e).buffer),
          i = t.getUint32(0, !1);
      8e4 < i && (Log.error("data_to_long:" + i), this.ws.close());
      var s = e.length;
 
      if (!(s < i + 4)) {
        var r = 0;
 
        try {
          r = t.getUint16(4, !1), this.unpackData(t, r, e, i);
        } catch (t) {
          Log.error(r + ": unpackData_error:" + t.message, e, t.stack);
        }
 
        i + 4 < s ? (Log.socket("data_length==", r, i), this.unpackBuffer(e.slice(i + 4))) : this.buffer = null;
      }
    }
  },
  unpackData: function unpackData(t, e, i, s) {
    if (!Proto.recv.hasOwnProperty(e)) throw new Error("unpackData查找不到协议定义:" + e);
 
    if (this.cmd_func_list.hasOwnProperty(e)) {
      Log.socket("unpackData==start===== " + e, s);
      var r = {},
          n = Proto.recv[e];
      return this.unpackData_(t, i, r, n, 6, s), this.msg_list.push({
        cmd: e,
        data: r
      }), Log.socket("unpackData==end===== " + e, s), r;
    }
 
    Log.socket("协议处理函数未定义:" + e);
  },
  unpackData_: function unpackData_(t, e, i, s, r, n) {
    for (var a = 0, o = s.length; a < o; a++) {
      var c = s[a];
 
      switch (c.t) {
        case 1:
          i[c.s] = t.getInt8(r, !1), r += 1;
          break;
 
        case 2:
          i[c.s] = t.getUint8(r, !1), r += 1;
          break;
 
        case 3:
          i[c.s] = t.getInt16(r, !1), r += 2;
          break;
 
        case 4:
          i[c.s] = t.getUint16(r, !1), r += 2;
          break;
 
        case 5:
          i[c.s] = t.getInt32(r, !1), r += 4;
          break;
 
        case 6:
          i[c.s] = t.getUint32(r, !1), r += 4;
          break;
 
        case 7:
          var h = t.getUint16(r, !1);
          r += 2;
          var u = new Uint8Array(e.slice(r, r + h)),
              f = String.fromCharCode.apply(null, u);
          i[c.s] = decodeURIComponent(escape(f)), r += h;
          break;
 
        case 8:
          h = t.getUint32(r, !1);
          r += 4, i[c.s] = e.slice(r, r + h), r += h;
          break;
 
        case 9:
          h = t.getUint16(r, !1);
          r += 2;
          var l = [];
          i[c.s] = l;
 
          for (var g = 0; g < h; g++) {
            var d = {};
            l[g] = d, r = this.unpackData_(t, e, d, c.f, r, n);
          }
 
      }
    }
 
    return r;
  },
  packData: function packData(t, e) {
    if (!Proto.send.hasOwnProperty(t)) throw new Error("unpackData查找不到协议定义:" + t);
    Log.socket("pack_data2:" + t);
    var i = Proto.send[t],
        s = [];
    return this.i16ToBytes(s, t), this.packData_(s, i, e), s;
  },
  packData_: function packData_(t, e, i) {
    for (var s = 0, r = e.length; s < r; s++) {
      var n = e[s],
          a = i[n.s];
 
      switch (n.t) {
        case 1:
        case 2:
          t.push(new Uint8Array([a])[0]);
          break;
 
        case 3:
        case 4:
          this.i16ToBytes(t, a);
          break;
 
        case 5:
        case 6:
          this.i32ToBytes(t, a);
          break;
 
        case 7:
          this.strToBytes(t, a);
          break;
 
        case 8:
          var o = a.length;
          this.i32ToBytes(t, o);
 
          for (var c = 0; c < o; c++) {
            t.push(a[c]);
          }
 
          break;
 
        case 9:
          o = a.length;
          this.i16ToBytes(t, o);
 
          for (c = 0; c < o; c++) {
            this.packData_(t, n.f, a[c]);
          }
 
      }
    }
  },
  strToBytes: function strToBytes(t, e) {
    var i = unescape(encodeURIComponent(e)),
        s = i.length;
    this.i16ToBytes(t, s);
 
    for (var r = 0; r < s; r++) {
      t.push(i.charCodeAt(r));
    }
  },
  i16ToBytes: function i16ToBytes(t, e) {
    var i = new Uint8Array(new Uint16Array([e]).buffer);
    t.push(i[1]), t.push(i[0]);
  },
  i32ToBytes: function i32ToBytes(t, e) {
    var i = new Uint8Array(new Uint32Array([e]).buffer);
    t.push(i[3]), t.push(i[2]), t.push(i[1]), t.push(i[0]);
  }
};
 
SmartSocket.init(), gcore.SmartSocket = SmartSocket;
var CoreUtils = {
  dataName: function dataName(n) {
    switch (window.DATA_TYPE || 1) {
      case 1:
        return n + ".json";
 
      case 2:
        return "jsc/" + n + ".json";
 
      case 3:
        return "jsc/" + n + ".zip";
    }
  },
  parseData: function parseData(n, o) {
    switch (window.DATA_TYPE || 1) {
      case 1:
      case 2:
        return void (Config[n] = o);
 
      case 3:
        var e = require("pako"),
            i = require("base64").Base64;
 
        return void (Config[n] = JSON.parse(e.inflate(i.atob(o), {
          to: "string"
        })));
    }
  },
  getDataKeyVal: function getDataKeyVal(n, o, e, i) {
    if (Config[n]) {
      if (Config[n][o]) {
        if (Config[n][o][e]) {
          var a = o + "_cache";
          Config[n][a] || (Config[n][a] = {});
          var r = Config[n][a][e];
 
          if (!r) {
            r = {};
            var t = o + "_fields",
                f = Config[n][o][e],
                g = Config[n][t];
            if (!g) return f;
 
            for (var s = 0, c = g.length; s < c; s++) {
              r[g[s]] = f[s];
            }
 
            Config[n][a][e] = r;
          }
 
          return r;
        }
 
        0 != i && Log.debug("config_data_not_found", n, o, e);
      } else 0 != i && Log.debug("config_data_not_found", n, o);
    } else 0 != i && Log.debug("config_data_not_found", n);
  }
};
gcore.CoreUtils = CoreUtils;
var GlobalEvent = {
  idx: 1,
  evts: {},
  getInstance: function getInstance() {
    return this;
  },
  bind: function bind(t, e, s) {
    if (t) {
      if (e) {
        this.evts.hasOwnProperty(t) || (this.evts[t] = {});
        var n = this.idx++;
        return this.evts[t][n] = {
          f: e,
          o: s
        }, {
          evt: t,
          id: n
        };
      }
 
      cc.log("evt_func===null");
    } else cc.log("evt_label===null");
  },
  unbind: function unbind(t) {
    this.evts.hasOwnProperty(t.evt) && (delete this.evts[t.evt][t.id], 0 == Object.keys(this.evts[t.evt]).length && delete this.evts[t.evt]);
  },
  fire: function fire(t) {
    if (this.evts.hasOwnProperty(t)) {
      var e = this.evts[t],
          s = cc.js.shiftArguments.apply(null, arguments);
 
      for (var n in e) {
        e[n].f.apply(e[n].o, s);
      }
    }
  },
  EVT_SOCKET_CONNECT: "EVT_SOCKET_CONNECT",
  EVT_SOCKET_DISCONNECT: "EVT_SOCKET_DISCONNECT"
};
gcore.GlobalEvent = GlobalEvent;
var Log = {
  debug: function debug() {
    if (DEBUG_LOG) return cc.log.apply(null, cc.js.array.appendObjectsAt(Array.prototype.slice.call(arguments), ["[debug]#"], 0));
  },
  info: function info() {
    if (INFO_LOG) return cc.log.apply(null, cc.js.array.appendObjectsAt(Array.prototype.slice.call(arguments), ["[info]#"], 0));
  },
  error: function error() {
    if (ERROR_LOG) return cc.error.apply(null, cc.js.array.appendObjectsAt(Array.prototype.slice.call(arguments), ["[error]#"], 0));
  },
  socket: function socket() {
    if (SOCKET_LOG) return cc.log.apply(null, cc.js.array.appendObjectsAt(Array.prototype.slice.call(arguments), ["[socket]#"], 0));
  }
};
gcore.Log = Log;
var SysEnv = {
  getInstance: function getInstance() {
    return this;
  },
  get: function get(t, e) {
    if (this[t]) return this[t];
    var n = cc.sys.localStorage.getItem(t);
    return n || (n = e), n && (this[t] = n), n;
  },
  set: function set(t, e, n) {
    this[t] = e, 0 != n && cc.sys.localStorage.setItem(t, this[t]);
  },
  del: function del(t) {
    delete this[t], cc.sys.localStorage.removeItem(t);
  },
  clear: function clear() {
    cc.sys.localStorage.clear();
  },
  setBool: function setBool(t, e, n) {
    this.set(t, e.toString(), n);
  },
  getBool: function getBool(t) {
    return "false" != this.get(t);
  },
  setInt: function setInt(t, e, n) {
    this.set(t, e.toString(), n);
  },
  getInt: function getInt(t) {
    return Number(this.get(t, "0"));
  },
  setObject: function setObject(t, e, n) {
    this.set(t, JSON.stringify(e), n);
  },
  getObject: function getObject(t) {
    return JSON.parse(this.get(t, "{}"));
  }
};
gcore.SysEnv = SysEnv;
var Timer = {
  idx: 1,
  timer: {},
  getInstance: function getInstance() {
    return this;
  },
  set: function set(t, i, e, r) {
    return i = i || 1e3, e = e || 1, r || (r = this.idx++), this.del(r), this.timer[r] = window.setTimeout(function () {
      1 == e ? this.del(r) : this.set(t, i, e - 1, r), t();
    }.bind(this), i), r;
  },
  del: function del(t) {
    this.timer.hasOwnProperty(t) && (window.clearTimeout(this.timer[t]), delete this.timer[t]);
  }
};
gcore.Timer = Timer;
 
cc._RF.pop();