瀏覽代碼

【修改】修改登录注册

DESKTOP-VHLO35R\Administrator 1 年之前
父節點
當前提交
6449249633

+ 4 - 0
assets/script/app/AppInit.js

@@ -33,5 +33,9 @@ module.exports = {
33 33
         // 登录数据管理器
34 34
         ns.LoginMgr = require('LoginMgr');
35 35
         ns.LoginMgr.init();
36
+
37
+        // 玩家数据管理器
38
+        ns.UserMgr = require('UserMgr');
39
+        ns.UserMgr.init();
36 40
     }
37 41
 };

+ 3 - 12
assets/script/app/model/PublicMgr.js

@@ -173,19 +173,10 @@ let PublicMgr = {
173 173
     },
174 174
 
175 175
     // # 玩家系统信息
176
-    // on_h5user_system_info 20100 {
176
+    // on_user_system_info 2000 {
177 177
     //     request {
178
-    //        briefs 0: DataModuleBriefInfo           # 功能简讯
179
-    //        confVerInfo 1: DataConfig               # 配置版本信息
180
-    //        clusteringInfo 2: DataClustering        # 分群信息
181
-    //        payInfo 3: DataPayInfo                  # 支付信息
182
-    //        dayStatementList 4: *DataDayStatement   # 活跃天统计信息列表
183
-    //        dayInfo 5: DataDayInfo                  # 玩家当天信息
184
-    //        sheildList 6: *integer                  # 功能ID列表
185
-    //        payRecord 7: *DataPayRecord             # 支付记录
186
-    //        hbcEntrance 8: *integer                 # 红包场入口
187
-    //        antiInfo 9: DataAntiAddiction           # 防沉迷信息
188
-    //    }
178
+    //         sheildList 0: *integer          # 功能ID列表
179
+    //     }
189 180
     // }
190 181
     _onPublishUserSystemInfo (data) {
191 182
         // 数据_onUserInfo统一处理

+ 17 - 0
assets/script/app/view/login/LoginPanel.js

@@ -41,7 +41,24 @@ cc.Class({
41 41
     },
42 42
 
43 43
     gotoLoginOnClicked () {
44
+        var phoneNum = this.phoneEditor.string;
45
+        if (phoneNum.length == 0 && !G.FuncUtils.isMobile(phoneNum)) {
46
+            G.AppUtils.getSceneCtrl().addToast("手机号码格式不正确");
47
+            return;
48
+        }
49
+
50
+        var password = this.passwordEditor.string;
51
+        if (password.length == 0) {
52
+            G.AppUtils.getSceneCtrl().addToast("密码不能不填");
53
+            return;
54
+        }
55
+
56
+        if (password.length > 16) {
57
+            G.AppUtils.getSceneCtrl().addToast("密码过长");
58
+            return;
59
+        }
44 60
 
61
+        G.LoginMgr.requestLoginByPhone(phoneNum, password);
45 62
     },
46 63
 
47 64
     gotoRegisterOnClicked () {

+ 103 - 2
assets/script/core/model/login/LoginMgr.js

@@ -61,11 +61,18 @@ let LoginMgr = {
61 61
         G.PublicMgr.emit(JMC.PUBLIC_MSG.DISCONNECTED);
62 62
     },
63 63
 
64
+    //* ************* 事件侦听 ************* *//
65
+    _handleSocketOnConected () {
66
+        this._stopKeepalive();
67
+        // 请求授权令牌
68
+        this.requestAuthToken();
69
+    },
70
+
64 71
     /**
65 72
      * 收到登录成功事件
66 73
      *
67 74
      */
68
-      handleDidLoginSuccess () {
75
+    handleDidLoginSuccess () {
69 76
         // 标记在线状态
70 77
         this.isOnline = true;
71 78
         // 重连计数重置
@@ -302,7 +309,7 @@ let LoginMgr = {
302 309
             password: password
303 310
         };
304 311
 
305
-        G.NetworkMgr.sendHttpRequestToLoginServer('usr_login', info, this._responseLogin.bind(this));
312
+        G.NetworkMgr.sendHttpRequestToLoginServer('usr_login_by_phone', info, this._responseLogin.bind(this));
306 313
     },
307 314
 
308 315
     /**
@@ -363,6 +370,100 @@ let LoginMgr = {
363 370
         // 将消息下发到ctrl中处理
364 371
         cc.game.emit('e_nwk_usr_login', data);
365 372
     },
373
+
374
+    /**
375
+     * 请求授权令牌
376
+     *
377
+     * @author Wetion
378
+     * @date 2019-03-26
379
+     */
380
+    requestAuthToken () {
381
+        let info = {
382
+            uid: this.loginData.uid,
383
+            token: this.loginData.token
384
+        };
385
+
386
+        G.NetworkMgr.sendSocketRequest('usr_auth_token', info, this._responseAuthToken.bind(this));
387
+    },
388
+    _responseAuthToken (data) {
389
+        let responseInfo = data.responseInfo;
390
+        if (responseInfo.code === 200) {
391
+            this.keepaliveTime = this.loginData.sysTime;
392
+            this._startKeepalive();
393
+
394
+            G.UserMgr.requestSelfInfo();
395
+        }
396
+    },
397
+
398
+    // 启动心跳,4 * 30秒后发出第一条心跳
399
+    _startKeepalive () {
400
+        this._stopKeepalive();
401
+
402
+        this.keepaliveTimeoutCount = 0;
403
+        this._keepaliveIntervalId = setInterval(() => {
404
+            this.keepaliveTimeoutCount++;
405
+
406
+            /**
407
+             * 定时器30秒执行一次
408
+             * 4 * 30秒间隔发一次保活请求
409
+             * 发送保活请求后30秒没返回断开当前连接进行重连
410
+             */
411
+            if (this.keepaliveTimeoutCount == 4) {
412
+                // G.LogUtils.log('发送心跳');
413
+                this._requestKeepalive();
414
+            } else if (this.keepaliveTimeoutCount == 5) {
415
+                // G.LogUtils.log('心跳不通');
416
+                // 清空心跳定时器
417
+                clearInterval(this._keepaliveIntervalId);
418
+                this._keepaliveIntervalId = undefined;
419
+
420
+                // 断开网络并且弹出重连窗口
421
+                G.NetworkMgr.closeSocket();
422
+                G.AppUtils.getSceneCtrl().showOfflineAlert();
423
+            }
424
+        }, 30 * 1000);
425
+    },
426
+
427
+     /**
428
+     * 连接保活, 客户端主动60s发送一次
429
+     *
430
+     * @author Wetion
431
+     * @date 2019-03-26
432
+     */
433
+     _requestKeepalive () {
434
+        G.NetworkMgr.sendSocketRequest('h5user_keepalive', undefined, this._responseKeepalive.bind(this));
435
+    },
436
+    _responseKeepalive (data) {
437
+        let responseInfo = data.responseInfo;
438
+        if (responseInfo && responseInfo.systemTime) {
439
+            this.keepaliveTime = responseInfo.systemTime;
440
+
441
+            // 间隔多少秒请求一次保活
442
+            this.keepaliveTimeoutCount = 0;
443
+        }
444
+    },
445
+
446
+    // 重置心跳定时器
447
+    _stopKeepalive () {
448
+        if (this._keepaliveIntervalId) {
449
+            clearInterval(this._keepaliveIntervalId);
450
+            this._keepaliveIntervalId = undefined;
451
+        }
452
+    },
453
+
454
+    _connectGameServer (host, port) {
455
+        // 链接SOCKET
456
+        G.NetworkMgr.connectSocket(host, port);
457
+
458
+        // 增加HTTP_GAME连接
459
+        G.NetworkMgr.addConnection({
460
+            alias: '游戏服',
461
+            name: 'HTTP_GAME',
462
+            host: host,
463
+            port: port,
464
+            path: 'pb'
465
+        });
466
+    },
366 467
 }
367 468
 
368 469
 module.exports = LoginMgr;

+ 42 - 0
assets/script/core/model/user/UserMgr.js

@@ -42,6 +42,48 @@ let UserMgr = {
42 42
     setUid (uid) {
43 43
         this._uid = uid;
44 44
     },
45
+
46
+    /**
47
+     * 设置玩家系统信息
48
+     *
49
+     * @param {Object} data
50
+     */
51
+    setUserSystemInfo (data) {
52
+    },
53
+
54
+    /**
55
+     * 请求自己的用户信息
56
+     *
57
+     * @param {Number} uid
58
+     * @param {Number} sysTime
59
+     */
60
+    requestSelfInfo () {
61
+        G.LogUtils.log('----> UserMgr requestSelfInfo()');
62
+        G.NetworkMgr.sendSocketRequest('user_self_info', {}, this._responseSelfInfo.bind(this));
63
+    },
64
+
65
+    _responseSelfInfo (data) {
66
+        G.LogUtils.log('<---- UserMgr _responseSelfInfo()');
67
+
68
+        let responseInfo = data.responseInfo;
69
+        if (responseInfo.code === 200) {
70
+            // 玩家基础信息
71
+            this._baseInfo = responseInfo.baseInfo;
72
+
73
+            // 登录完成判断
74
+            G.PublicMgr.isDoneUserSelfInfo = true;
75
+            if (G.PublicMgr.isDoneSystemInfo) {
76
+                G.PublicMgr.isDoneUserSelfInfo = false;
77
+                G.PublicMgr.isDoneSystemInfo = false;
78
+
79
+                G.PublicMgr.emit(JMC.PUBLIC_MSG.LOGIN_SUCCESS);
80
+            }
81
+        } else {
82
+            // 断开网络并且弹出重连窗口
83
+            G.NetworkMgr.closeSocket();
84
+            G.AppUtils.getSceneCtrl().showOfflineAlert();
85
+        }
86
+    },
45 87
 }
46 88
 
47 89
 

+ 8 - 7
assets/script/core/socket/SocketClient.js

@@ -1,4 +1,5 @@
1 1
 const sproto = require('sproto');
2
+const SocketUtil = require('./SocketUtil');
2 3
 
3 4
 cc.Class({
4 5
     name: 'SocketClient',
@@ -33,7 +34,7 @@ cc.Class({
33 34
      * @param {Array} protoPaths
34 35
      */
35 36
     loadProtoFiles(protoPaths) {
36
-        if (this._clientHost && this._clientSender) {
37
+        if (SocketUtil.clientHost && SocketUtil.clientSender) {
37 38
             G.LogUtils.warn('Warn:SocketClient协议文件已经加载过');
38 39
             return;
39 40
         }
@@ -58,8 +59,8 @@ cc.Class({
58 59
                 protos[proto._name] = data;
59 60
             });
60 61
 
61
-            this._clientHost = protos.socket_s2c.host();
62
-            this._clientSender = this._clientHost.attach(protos.socket_c2s);
62
+            SocketUtil.clientHost = protos.socket_s2c.host();
63
+            SocketUtil.clientSender = SocketUtil.clientHost.attach(protos.socket_c2s);
63 64
 
64 65
             G.LogUtils.log('Info:SocketClient协议文件加载成功');
65 66
             cc.game.emit('e_nwk_socket_sproto_done');
@@ -78,7 +79,7 @@ cc.Class({
78 79
      * @returns {boolean}
79 80
      */
80 81
     isReadyDone() {
81
-        return this._ws && this._ws.readyState === WebSocket.OPEN && this._clientHost && this._clientSender;
82
+        return this._ws && this._ws.readyState === WebSocket.OPEN && SocketUtil.clientHost && SocketUtil.clientSender;
82 83
     },
83 84
 
84 85
     _isValidURLArgs(host, port) {
@@ -116,7 +117,7 @@ cc.Class({
116 117
         }
117 118
         url = cc.js.formatStr('ws://%s:%s', host, port);
118 119
 
119
-        this._ws = new WebSocket(url, 'chat', cc.url.raw('resources/res_text/proto/cacert.pem'));
120
+        this._ws = new WebSocket(url);
120 121
         this._ws.binaryType = 'arraybuffer';
121 122
         this._ws.onopen = this._onConnect.bind(this);
122 123
         this._ws.onmessage = this._onMessage.bind(this);
@@ -125,7 +126,7 @@ cc.Class({
125 126
     },
126 127
 
127 128
     _send(protoName, info, session) {
128
-        let requestBuffer = G.FuncUtils.uint8ToBuffer(this._clientSender(protoName, info, session));
129
+        let requestBuffer = G.FuncUtils.uint8ToBuffer(SocketUtil.clientSender(protoName, info, session));
129 130
         this._ws.send(requestBuffer); // 发送数据
130 131
     },
131 132
 
@@ -208,7 +209,7 @@ cc.Class({
208 209
 
209 210
     _onMessage(evt) {
210 211
         // 解析数据
211
-        let buffer = this._clientHost.dispatch(G.FuncUtils.bufferToUint8(evt.data));
212
+        let buffer = SocketUtil.clientHost.dispatch(G.FuncUtils.bufferToUint8(evt.data));
212 213
         if (buffer.type === 'REQUEST') {
213 214
             // 避免native释放buffer导致 object already destroyed
214 215
             buffer.result = G.FuncUtils.clone(buffer.result);

+ 8 - 0
assets/script/core/socket/SocketUtil.js

@@ -0,0 +1,8 @@
1
+let SocketUtil = {
2
+    init() {
3
+        this.clientHost = {};
4
+        this.clientSender = {}
5
+    }
6
+}
7
+
8
+module.exports = SocketUtil;

+ 9 - 0
assets/script/core/socket/SocketUtil.js.meta

@@ -0,0 +1,9 @@
1
+{
2
+  "ver": "1.0.8",
3
+  "uuid": "baeaae9d-58ba-4d85-9abd-8bb3ba81aaf8",
4
+  "isPlugin": false,
5
+  "loadPluginInWeb": true,
6
+  "loadPluginInNative": true,
7
+  "loadPluginInEditor": false,
8
+  "subMetas": {}
9
+}