Beispiel #1
0
        public static Tran_Head GetDataHead(byte[] data)
        {
            Tran_Head head = new Tran_Head();

            byte[] rcv_head = new byte[Marshal.SizeOf(head)];
            Array.ConstrainedCopy(data, 0, rcv_head, 0, Marshal.SizeOf(head));
            head = (Tran_Head)CStructBytesFormat.BytesToStruct <Tran_Head>(rcv_head);

            return(head);
        }
Beispiel #2
0
        public static byte[] BuildBytes <T>(Tran_Head hd, T obj)
        {
            byte[] head = CStructBytesFormat.StructToBytes(hd);
            byte[] data = CStructBytesFormat.StructToBytes(obj);

            byte[] rbyte = new byte[data.Length + head.Length];

            Array.ConstrainedCopy(head, 0, rbyte, 0, head.Length);
            Array.ConstrainedCopy(data, 0, rbyte, head.Length, data.Length);

            return(rbyte);
        }
Beispiel #3
0
        public static T GetDataObj <T>(byte[] data, Tran_Head head)
        {
            if (data == null)
            {
                return(default(T));
            }
            if (data.Length <= 0)
            {
                return(default(T));
            }
            int objLength = Marshal.SizeOf(typeof(T));

            byte[] rcv_data = new byte[head.length];
            T      obj;

            Array.ConstrainedCopy(data, Marshal.SizeOf(head), rcv_data, 0, rcv_data.Length);
            obj = (T)CStructBytesFormat.BytesToStruct <T>(rcv_data);

            return(obj);
        }
Beispiel #4
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);
            }
        }
Beispiel #5
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;
             *  }
             * }
             * */
        }
Beispiel #6
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("注册失败!");
            }
        }