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
479
480
481
482
483
484
// --------------------------------------------------------------------
// @author: shiraho@syg.com(必填, 创建模块的人员)
// @description:
//      登录控制器
// <br/>Create: new Date().toISOString()
// --------------------------------------------------------------------
 
// var MainSceneController = require("mainscene_controller");
var LoginEvent = require("login_event");
var RoleController = require("role_controller")
var LoginPlatform = require("login_platform");
 
var LoginController = cc.Class({
    extends: BaseController,
    ctor: function () {
    },
 
    // 初始化配置数据
    initConfig: function () {
        this.finish_loading = false;
        var LoginModel = require("login_model");
 
        this.model = new LoginModel();
        this.model.initConfig();
        this.enable_relogin = true;           // 是否允许重连
    },
 
    // 注册监听事件
    registerEvents: function () {
        gcore.GlobalEvent.bind(LoginEvent.LOGIN_EVENT_ACCOUNT_LOGIN_SUCCESS, (function () {
            this.model.requestDefaultServer();
        }).bind(this));
 
        gcore.GlobalEvent.bind(LoginEvent.LOGIN_EVENT_DEFSERVER_SUCCESS, (function () {
        }).bind(this));
 
        gcore.GlobalEvent.bind(gcore.GlobalEvent.EVT_SOCKET_CONNECT, (function () {
            this.enable_relogin = true;
            if (this.reconnect_timer) {
                gcore.Timer.del(this.reconnect_timer);
                this.reconnect_timer = null;
                game.updateWaitingStatus();
            }
            if (USE_SDK) {
                SDK.loginGame();
            } else {
                this.login();
            }
        }).bind(this));
 
        gcore.GlobalEvent.bind(gcore.GlobalEvent.EVT_SOCKET_DISCONNECT, (function () {
            this.reconnectServer();
        }).bind(this));
    },
 
    // 注册协议接受事件
    registerProtocals: function () {
        this.RegisterProtocal(1110, this.on1110);
        this.RegisterProtocal(10310, this.on10310);
        this.RegisterProtocal(10101, this.on10101);
        this.RegisterProtocal(10102, this.on10102);
        this.RegisterProtocal(10103, this.on10103);
    },
 
    // 获取模块
    getModel: function () {
        return this.model;
    },
 
    // 打开登录加载
    openLoginWindow: function (data) {
        if (data && data.status) {
            var LoginWindow = require("login_window");
 
            if (this.login_window == null) {
                this.login_window = new LoginWindow()
            }
            this.login_window.open(data);
        } else {
            if (this.login_window) {
                this.finish_loading = false;
                game.updateLoadingStatus(true);
                gcore.GlobalEvent.fire(EventId.LOADING_FINISH)
                this.login_window.close();
                this.login_window = null;
            }
        }
    },
 
    getTestAccount: function () {
        if (this.login_window)
            return this.login_window.getTestAccount();
    },
 
    // 切换登录窗体的面板状态
    changeLoginWindowIndex: function (index) {
        if (this.login_window) {
            this.login_window.changeSubPanel(index);
        }
    },
 
    // 连接服务器
    connectServer: function (host, port, ws) {
        if (NO_SOCKET) {
            this.openLoginWindow(false);
            return;
        }
        var loginInfo = this.model.getLoginInfo();
        host = host || loginInfo.host;
        port = port || loginInfo.port;
        ws = ws || loginInfo.ws;
 
        cc.log("建立socket链接");
        cc.log(loginInfo);
 
        if (host && port) {
            gcore.SmartSocket.connect(host, port, ws);
            // gcore.SmartSocket.connect("localhost", "9001");
        } else {
            message("服务器地址信息错误");
        }
    },
 
    // 断线重线处理
    reconnectServer: function () {
        if (!this.reconnect_timer && this.enable_relogin) {
            this.reconnect_timer = gcore.Timer.set(this.connectServer.bind(this), 3000, -1);
            game.updateWaitingStatus(WaitingStaus.CONNECT);
        }
    },
 
    // 登录服务器
    login: function () {
        var loginInfo = this.model.getLoginInfo();
        var data = [
            { key: "account", val: loginInfo.account }
            , { key: "channel", val: CHANNEL }
            , { key: "idfa", val: "windows" }
        ];
        this.SendProtocal(1110, { args: data });
    },
 
    sdkLogin: function () {
        // LoginPlatform
        var protocal = {}
        var account = this.model.getLoginData().usrName || "";
        var srv_id = this.model.getLoginData().srv_id || "";
        var device_id = "nicai"
        // var device_id = device.getDeviceName()
        var timestamp = LoginPlatform.getInstance().getTimestamp();
        var token = LoginPlatform.getInstance().getToken();
        var sign = LoginPlatform.getInstance().getSign();
        var channel = LoginPlatform.getInstance().getChannel();
        account = channel + "_" + account;
        var final_channel = LoginPlatform.getInstance().getFinalChannel();
        var gettui_cid = "meiyou";
        var device_type = "";
        // var gettui_cid = device.getuiId()
        var idfa = "meiyou";
        var is_emulator = "false";
        var os_ver = "";
        var carrier_name = "";
        var net_type = "";
        var app_name = GAME_NAME;
        var package_name = GAME_NAME;
        var package_version = "1.0.1";
        var os = "os";
 
        var logsign_str = account + device_id + idfa + channel + gettui_cid + is_emulator;
        var MD5 = require("md5.min");
        // cc.log("value_1==>", value);
        var logsign = MD5(logsign_str);
        logsign = logsign.toLowerCase();
 
        protocal.args = [
            { key: "account", val: account },
            { key: "timestamp", val: timestamp },
            { key: "enter_srv_id", val: srv_id },
            { key: "platform", val: PLATFORM_NAME },
            { key: "device_id", val: device_id },
            { key: "device_type", val: device_type },
            { key: "gettui_cid", val: gettui_cid },
            { key: "idfa", val: idfa },
            { key: "token", val: token },
            { key: "channel", val: final_channel },
            { key: "sign", val: sign },
            { key: "logsign", val: logsign },
            { key: "os_ver", os_ver },
            { key: "carrier_name", val: carrier_name },
            { key: "net_type", val: net_type },
            { key: "os", val: os },
            { key: "emulator", val: is_emulator },
            { key: "app_name", val: app_name },
            { key: "package_name", val: package_name },
            { key: "package_version", val: package_version }
        ];
 
        this.SendProtocal(1110, protocal);
    },
 
    //自定义参数的SDKLogin
    cusSDKLogin: function (data) {
        if (!data) return;
 
        var srv_id = this.model.getLoginData().srv_id || "";
        var account = data.account;
        var rawData = data.rawData;
        var signature = data.signature;
        var channel = data.channel;
        var device_id = "";
        var idfa = "";
        var gettui_cid = "";
        var is_emulator = "";
        var package_name = data.package_name;
        var package_version = data.package_version;
        var app_name = "";
        var platform = data.platform;
        var token = data.token ||"";
        var timestamp = data.timestamp || "";
        var sign = data.sign || "";
 
        var logsign_str = account + device_id + idfa + channel + gettui_cid + is_emulator;
        var MD5 = require("md5.min");
        var logsign = MD5(logsign_str);
        logsign = logsign.toLowerCase();
 
        var protocal = {}
        protocal.args = [
            { key: "account", val: account },
            { key: "enter_srv_id", val: srv_id },
            { key: "platform", val: platform },
            { key: "device_id", val: device_id },
            { key: "gettui_cid", val: gettui_cid },
            { key: "idfa", val: idfa },
            { key: "channel", val: channel },
            { key: "logsign", val: logsign },
            { key: "emulator", val: is_emulator },
            { key: "app_name", val: app_name },
            { key: "package_name", val: package_name },
            { key: "package_version", val: package_version },
            { key: "rawData", val: rawData },
            { key: "signature", val: signature },
            { key: "token", val: token },
            { key: "timestamp", val: timestamp },
            { key: "sign", val: sign }
        ];
 
        cc.log(protocal);
        this.SendProtocal(1110, protocal);
    },
 
    //自定义参数的SDKLogin
    //data:[]  看不同平台包传入不同的内容;
    cusSDKLogin_2: function (data) {
        if (!data) return
        var srv_id = this.model.getLoginData().srv_id || "";
        var device_id = "";
        var idfa = "";
        var gettui_cid = "";
        var is_emulator = "";
        var app_name = "";
        var logsign_str = data.account + device_id + idfa + data.channel + gettui_cid + is_emulator;
        var MD5 = require("md5.min");
        var logsign = MD5(logsign_str);
        logsign = logsign.toLowerCase();
 
        var args = [
            { key: "enter_srv_id", val: srv_id },
            { key: "device_id", val: device_id },
            { key: "gettui_cid", val: gettui_cid },
            { key: "idfa", val: idfa },
            { key: "logsign", val: logsign },
            { key: "emulator", val: is_emulator },
            { key: "app_name", val: app_name },
        ];
 
        var protocal = {};
        protocal.args = data.concat(args)
 
        cc.log("1110--protocal==>", protocal);
        this.SendProtocal(1110, protocal);
    },
 
    // 账号角色列表信息返回
    on1110: function (data) {
        cc.log("1110登录游戏返回");
        cc.log(data);
 
        // 1110返回错误则不需要重连
        if (data.code == 1) {
            if (this.model.auto_login == false) {//不需要主动进入服务器 比如在服务器列表中选择服
                return;
            }
            if (this.model.isSocket) {
                gcore.GlobalEvent.fire(LoginEvent.LOGIN_EVENT_PLAYER_INFO, data)
                return
            }
            if (data.roles.length == 0) {
                this.reqCreateRole();
            } else {
                var role = this.role = data.roles[0];
                this.reqLoginRole(role.rid, role.srv_id);
            }
 
            // 提交服务器信息
            if ((PLATFORM_TYPR == "WX_SDK" || PLATFORM_TYPR == "QQ_SDK") && USE_SDK) {
                var loginInfo = this.model.getLoginInfo();
                SDK.submitLogin(loginInfo.host);
            }
        } else if (data.code == 4) { //服务器维护或者被封或者未开服
            this.enable_relogin = false;
            require("notice_controller").getInstance().openNocticeWindow(true);
        } else {
            this.enable_relogin = false;
            message(data.msg);
        }
    },
 
    getCurRoleInfo: function() {
        return this.role;
    },
 
    // 掉线提示, 收到该协议后将不会进行重连
    on10310: function (data) {
        this.enable_relogin = false;
        gcore.SmartSocket.stopHeart();
        if (this.reconnect_timer) {
            gcore.Timer.del(this.reconnect_timer);
            this.reconnect_timer = null;
            game.updateWaitingStatus();
        }
 
        if (data.is_show == 1) {
            message(data.msg);
        }
 
        var GuideController = require("guide_controller");
        GuideController.getInstance().setGuideMainRootWnd(false);
        var CommonAlert = require("commonalert");
        CommonAlert.showItemApply(Utils.TI18N("该账号已在其他地方登录"),null,function(){
            game.relogin();
            if(PLATFORM_TYPR == "SH_RH"){
                SDK.logout();
            }
        }.bind(this),Utils.TI18N("确定"),null,null,Utils.TI18N("提示"),null,null,true,null, null,null,null,{off_y:-18,close_off:true})
        // game.relogin();
    },
 
    // 请求创建新角色
    reqCreateRole: function () {
        if(PLATFORM_TYPR == "SH_RH" || PLATFORM_TYPR == "SH_SDK"){
            this.SendProtocal(10101, { sex: 0, name: "", career: 1, playform: CHANNEL});
        }else{
            this.SendProtocal(10101, { sex: 0, name: "", career: 1, playform: PLATFORM });
        }
    },
 
    // 创建新角色返回
    on10101: function (data) {
        if (data.code == 1) {
            if (IS_SUBMIT) {
                SDK.sdkSubmitUserData(2, data)
            }
            if (PLATFORM_TYPR == "SH_RH" && PLATFORM_NAME == "sh"){
                SDK.createRole(data);
            }
            if (PLATFORM_TYPR == "SH_SDK"){
                SDK.createRole(data);
            }
            this.model.setFirstRoleData(data);
            this.reqLoginRole(data.rid, data.srv_id);
        } else {
            message(data.msg);
        }
    },
 
    // 请求登录角色
    reqLoginRole: function (rid, srv_id) {
        var loginInfo = this.model.getLoginInfo();
        loginInfo.login_rid = rid;
        loginInfo.login_srv_id = srv_id;
        cc.log(RoleController.getInstance().init_role);
        if (RoleController.getInstance().init_role) {// 角色已登录 断线重连处理
            this.SendProtocal(10103, { rid: rid, srv_id: srv_id });
        } else {
            this.SendProtocal(10102, { rid: rid, srv_id: srv_id });
        }
    },
 
    // 角色登录成功返回
    on10102: function (data) {
        if (data.code == 1) {
            if (this.login_window)
                this.login_window.showLoading();
 
            game.initConfigs(function () {
                this.SendProtocal(10300, {});
            }.bind(this));
            RoleController.getInstance().getModel().setWorldLev(data.world_lev || 0)
        } else {
            message(data.msg);
        }
        if (this.serverListWindow) {
            this.openServerList(false)
        }
    },
 
    sender10300: function() {
        this.SendProtocal(10300, {});
    },
 
    // 角色重连成功返回
    on10103: function (data) {
        if (data.code == 1) {
            var RoleController = require("role_controller")
            RoleController.getInstance().setReconnect(true)
            this.SendProtocal(10300, {});
        } else {
            message(data.msg);
        }
    },
 
    //打开选区列表
    openServerList(bool, data, callFunc) {
        if (bool) {
            if (!this.serverListWindow) {
                let serverListWindow = require("server_list_window")
                this.serverListWindow = new serverListWindow()
            }
            this.serverListWindow.open(data)
            this.serverListWindow.addCallBack(callFunc)
        } else {
            if (this.serverListWindow) {
                this.serverListWindow.close();
                this.serverListWindow = null
            }
        }
    },
 
    updateLoading: function (progerss) {
        if (this.login_window)
            this.login_window.updateLoading(progerss);
    },
 
    updateSeconLoading: function (progerss, isinit) {
        if (this.login_window)
            this.login_window.updateSeconLoading(progerss, isinit);
    },
 
    loginPlatformRequest: function (data) {
        var login_data = this.model.getLoginData();
        if (data.usrName != login_data.usrName) {
            gcore.SysEnv.set("user_name", data.usrName);
            gcore.SysEnv.set("password", data.password);
            login_data.usrName = data.usrName;
            login_data.password = data.password;
        }
        this.loginNewUserRequest(data)
    },
 
    loginNewUserRequest: function (data) {
        var info = {}
        info.code = 1;
        info.accName = data.usrName;
        info.platform = PLATFORM_NAME;
        info.msg = "";
        this.loginPlatformResult(info);
    },
 
    loginPlatformResult: function (data) {
        if (data.code == 1) {
            this.model.requestDefaultServerList(data.accName, data.platform)
        } else {
 
        }
    },
 
    //强制下线
    sender10312: function() {
        this.SendProtocal(10312, {});
    },
});
 
module.exports = LoginController;