예제 #1
0
        public void LoginByAccount(string key, string password)
        {
            this.key      = key;
            this.password = password;

            string mixed = null;

            //加密密码
            if (!string.IsNullOrEmpty(password))
            {
                string aesKey = Encoding.UTF8.GetString(AESUtils.GetRandomKey(32));
                string pwMD5  = MD5Tool.GetObjectMD5(password);
                string md5Ery = AESUtils.AESEncrypt(pwMD5, aesKey);
                string length = md5Ery.Length.ToString().PadLeft(4, '0');
                mixed = length + md5Ery + aesKey;
                //Debug.Log("aesKey:" + aesKey);
                //Debug.Log("md5Ery:" + md5Ery);
                //Debug.Log("Mixed:" + mixed);
            }
            Login2Server msg = new Login2Server();

            msg.loginType = LoginType.Account;
            msg.key       = key;
            msg.password  = mixed;
            bool res = netManager.Send(msg);

            Debug.Log("Send Res:" + res);
        }
예제 #3
0
        private void OnLoginMsg(NetMessageData messageHandler)
        {
            Debug.Log("接受到登陆消息!");
            Login2Server msg = messageHandler.GetMessage <Login2Server>();

            bool isRightDecryptPW = true;

            //密码解码
            if (!string.IsNullOrEmpty(msg.password))
            {
                try
                {
                    string temp = msg.password;
                    //获得密码md5串长度
                    int length = int.Parse(temp.Substring(0, 4));
                    //Debug.Log("length:" + temp.Substring(0, 4));

                    string md5Ery = temp.Substring(4, length);
                    //Debug.Log("md5Ery:" + md5Ery);
                    string aesKey = temp.Substring(4 + length);
                    //Debug.Log("aesKey:" + aesKey);
                    string pwMD5 = AESUtils.AESDecrypt(md5Ery, aesKey);
                    //Debug.Log("pwMD5:" + pwMD5);
                    msg.password = pwMD5;
                }
                catch (Exception e)
                {
                    Debug.LogError("password Decrypt error:" + msg.password + "\n" + e);
                    isRightDecryptPW = false;
                }
            }

            Login2Client resMsg = new Login2Client();

            resMsg.appData = new AppData();
            resMsg.appData.serverAppName    = Application.productName;
            resMsg.appData.serverAppVersion = Application.version;
            resMsg.appData.bundleIdentifier = Application.identifier;

            Player player = null;

            if (isRightDecryptPW)
            {
                if (SimpleNetManager.PlayerManager.IsLogin(messageHandler.session))
                {
                    //重复登陆
                    resMsg.code = 100;
                }

                else if (playerLoginHandler != null)
                {
                    resMsg.code = playerLoginHandler.LoginLogic(msg, messageHandler.session, out player);
                    // player = new Player(messageHandler.connectionId);
                    //player.playerID = "1000";
                    if (resMsg.code == 0)
                    {
                        if (SimpleNetManager.PlayerManager.IsLogin(player.playerID))
                        {
                            //当前账号已登录
                            resMsg.code = 103;
                        }
                        else
                        {
                            resMsg.playerID = player.playerID;
                        }
                    }
                }
                else
                {
                    //其他错误
                    resMsg.code = 101;
                }
            }
            else
            {
                //密码解析错误
                resMsg.code = 104;
            }

            netManager.Send(messageHandler.session, resMsg);
            SimpleNetManager.PlayerManager.AddPlayer(player);
            if (resMsg.code == 0)
            {
                if (OnPlayerLogin != null)
                {
                    OnPlayerLogin(player);
                }

                if (OnPlayerLoginAfter != null)
                {
                    OnPlayerLoginAfter(player);
                }
            }
        }