Пример #1
0
        //开始游戏
        private void btn_login_Click(object sender, EventArgs e)
        {
            //开始游戏前进行版本矫正
            Ver_Info tran_data;

            tran_data.ver = "get_version";
            Tran_Head tran_head;

            byte[] data = CStructBytesFormat.StructToBytes(tran_data);

            tran_head.cmd    = 2;
            tran_head.length = data.Length;

            byte[] rbyte = CDataBuil.BuildBytes(tran_head, tran_data);

            if (ServerConnection())
            {
                SendMessage(rbyte);
            }
        }
Пример #2
0
        private void btn_login_Click(object sender, EventArgs e)
        {
            //send check version
            Ver_Info tran_data;

            tran_data.ver = "get_version";
            Tran_Head tran_head;

            byte[] data = CStructBytesFormat.StructToBytes(tran_data);

            tran_head.cmd    = 2;
            tran_head.length = data.Length;

            byte[] rbyte = CDataBuil.BuildBytes(tran_head, tran_data);

            if (ServerConnection())
            {
                SendMessage(rbyte);
            }

            /*
             * IPHostEntry host;
             * host = Dns.GetHostEntry(serverWeb);
             *
             * foreach (IPAddress ip in host.AddressList)
             * {
             *  serverIp = "192.168.0.102";//ip.ToString();
             *
             *  if (ServerConnection())
             *  {
             *      SendMessage(rbyte);
             *      break;
             *  }
             * }
             * */
        }
Пример #3
0
        private void btn_register_Click(object sender, EventArgs e)
        {
            if (!this.txtValidCode.Text.Equals(validCode.CheckCode))
            {
                MessageBox.Show(" 请输入正确的验证码!", this.Text);
                this.txtValidCode.Focus();
                validCode          = new ValidCode(5, ValidCode.CodeType.Numbers);
                picValidCode.Image = Bitmap.FromStream(validCode.CreateCheckCodeImage());
                return;
            }

            validCode          = new ValidCode(5, ValidCode.CodeType.Numbers);
            picValidCode.Image = Bitmap.FromStream(validCode.CreateCheckCodeImage());

            string reg_name = txt_name.Text;
            string reg_pwd  = txt_pwd.Text;
            string reg_pwd2 = txt_pwd2.Text;

            if (!IsNumAndEnCh(reg_name))
            {
                MessageBox.Show("用户名必须由字母或数字组成!");
                return;
            }
            if (!IsNumAndEnCh(reg_pwd))
            {
                MessageBox.Show("密码必须由字母或数字组成!");
                return;
            }

            if (reg_name.Length < 6 || reg_name.Length > 20)
            {
                MessageBox.Show("用户名长度必须为6~20位!");
                return;
            }

            if (reg_pwd.Length < 6 || reg_pwd.Length > 20)
            {
                MessageBox.Show("密码长度必须为6~20位!");
                return;
            }

            if (reg_pwd2 != reg_pwd)
            {
                MessageBox.Show("两次输入密码不一致,请确认!");
                return;
            }


            try
            {
                string keys = "";

                byte[] i_keys = getRandomNum(8, 48, 57);
                keys = System.Text.Encoding.Default.GetString(i_keys);

                Rg_Info   rg_info;
                Tran_Head tran_head;

                rg_info.name   = CSecurity.EncryptDES(reg_name, keys);
                rg_info.passwd = CSecurity.EncryptDES(reg_pwd, keys);
                rg_info.key    = keys;

                string _name   = CSecurity.DecryptDES(rg_info.name, keys);
                string _passwd = CSecurity.DecryptDES(rg_info.passwd, keys);
                if (_name == rg_info.name || _passwd == rg_info.passwd)
                {
                    throw (new Exception("注册失败!"));
                }

                byte[] data = CStructBytesFormat.StructToBytes(rg_info);

                tran_head.cmd    = 1;
                tran_head.length = data.Length;

                byte[] rbyte = CDataBuil.BuildBytes(tran_head, rg_info);

                if (ServerConnection())
                {
                    SendMessage(rbyte);
                }

                /*
                 * IPHostEntry host;
                 * host = Dns.GetHostEntry(serverWeb);
                 *
                 * foreach (IPAddress ip in host.AddressList)
                 * {
                 *  serverIp = "192.168.0.102";//ip.ToString();
                 *
                 *  if (ServerConnection())
                 *  {
                 *      SendMessage(rbyte);
                 *      break;
                 *  }
                 * }
                 * */
            }
            catch (Exception)
            {
                MessageBox.Show("注册失败!");
            }
        }