Exemplo n.º 1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (WebSocketManager.IsConnected() == false)
            {
                WebSocketManager.InitWebSocket();
                if (WebSocketManager.IsConnected() == false)
                {
                    string tips = string.Format("无法连接服务器,请确保服务器地址为{0},且处于开启状态", AppValues.SERVER_URL);
                    MessageBox.Show(this, tips, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            string inputUsername = txtUsername.Text.Trim();
            string inputPassword = txtPassword.Text.Trim();

            if (string.IsNullOrEmpty(inputUsername))
            {
                MessageBox.Show("用户名不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (string.IsNullOrEmpty(inputPassword))
            {
                MessageBox.Show("密码不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            LoginRequest.Builder builder = LoginRequest.CreateBuilder();
            builder.SetUsername(inputUsername);
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            string passwordMD5           = BitConverter.ToString(md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(inputPassword))).Replace("-", "").ToUpper();

            builder.SetPasswordMD5(passwordMD5);
            WebSocketManager.SendMessage(RpcNameEnum.Login, builder.Build().ToByteArray(), OnLoginCallback);
        }
Exemplo n.º 2
0
    private void Request(string userName)
    {
        LoginRequest.Builder request = LoginRequest.CreateBuilder();
        request.SetUserName(userName);
        var bytes = request.Build().ToByteArray();

        App.NetworkManager.Request("Login", bytes, Response);
    }
Exemplo n.º 3
0
        public ActionResult RobotLogon(Dictionary <string, string> queryvalues)
        {
            int gametype   = queryvalues.ContainsKey("gametype") ? Convert.ToInt32(queryvalues["gametype"]) : -1;
            int openmodule = queryvalues.ContainsKey("openmodule") ? Convert.ToInt32(queryvalues["openmodule"]) : -1;
            int second     = queryvalues.ContainsKey("second") ? Convert.ToInt32(queryvalues["second"]) : 0;
            int num        = queryvalues.ContainsKey("num") ? Convert.ToInt32(queryvalues["num"]) : 0;



            RobotControl robotCon = new RobotControl();

            LoginRequest LoginRequest;

            LoginRequest = LoginRequest.CreateBuilder()
                           .SetGameType((uint)gametype)
                           .SetLoginFrequency((uint)second)
                           .SetLoginCnt(num)
                           .SetStrategy((uint)openmodule)
                           .Build();

            Bind tbind = Cmd.runClientRobot(new Bind(ServiceCmd.SC_ROBOT_LOGIN, LoginRequest.ToByteArray()), 12001);

            switch ((CenterCmd)tbind.header.CommandID)
            {
            case CenterCmd.CS_ROBOT_STATU:

                return(Json(new
                {
                    res = 1,
                    Data = ""
                }));

            case CenterCmd.C2S_ROBOT_ERRMSG:
                ErrorMessage ErrorMessage = ErrorMessage.ParseFrom(tbind.body.ToBytes());
                return(Json(new
                {
                    res = 0,
                    Data = ErrorMessage.ErrorMessage_
                }));
            }
            return(Json(new
            {
                res = 0,
                Data = ""
            }));
        }