Exemplo n.º 1
0
    public void FixedUpdate()
    {
        if (net_manager.Connected())
        {
            net_manager.Receive(buffer_recv, out se);
        }
        //Debug.Log("!!!!!!" + buffer_recv.GetDataSize() + " " + buffer_recv.GetStart() + " " + buffer_recv.GetEnd());
        while (true)
        {
            if (buffer_recv.IsHeaderReadable(3 * sizeof(Int32)) == false)
            {
                break;
            }

            msgInfo = buffer_recv.Decode();

            if (buffer_recv.IsHeaderAndPayloadReadable(3 * sizeof(Int32) + msgInfo.GetPacLen()) == false)
            {
                break;
            }


            buffer_recv.GetPayload(msgInfo);
            switch (msgInfo.GetMsgID())
            {
            case 1006:
                msgtemp = MSG_PLAYER_MOVE.Parser.ParseFrom(msgInfo.GetPayload());
                Debug.LogError("Recv mov: x = " + msgtemp.X + ", z = " + msgtemp.Z + ".    ry = " + msgtemp.Ry);

                update_player(msgtemp.Playerid, ((float)msgtemp.X) / 100000, ((float)msgtemp.Z) / 100000, ((float)msgtemp.Ry) / 100000, msgtemp.State);
                break;

            case 1008:
                msgtemp_register_recv = MSG_PLAYER_REGISTER.Parser.ParseFrom(msgInfo.GetPayload());
                Debug.LogError("Recv reg: x = " + msgtemp_register_recv.X + ", z = " + msgtemp_register_recv.Z + ".    Ry = ");

                update_player(msgtemp_register_recv.Playerid, ((float)msgtemp_register_recv.X) / 100000, ((float)msgtemp_register_recv.Z) / 100000, ((float)msgtemp_register_recv.Ry) / 100000, 0);
                break;
            }
        }



        m_PlayerSelf.FixedUpdate();
    }
Exemplo n.º 2
0
        private void LoginButton_Click(object sender, EventArgs e)
        {
            string name     = Username.Text.Trim();
            string password = Password.Text.Trim();

            if (String.IsNullOrEmpty(name) || String.IsNullOrEmpty(password))
            {
                RemindLable.Text      = "请输入合法的用户名密码!";
                RemindLable.ForeColor = Color.Red;
                return;
            }
            CtlMsgLoginReq login = new CtlMsgLoginReq();

            login.Name     = name;
            login.Password = password;

            Byte[] temp = new byte[1024];
            byte[] data = new byte[1024];
            using (CodedOutputStream cos = new CodedOutputStream(temp))
            {
                login.Name     = name;
                login.Password = password;
                login.WriteTo(cos);
            }

            Buffers.Encode(data, 9999, 1, login.CalculateSize());
            for (int i = 0; i < login.CalculateSize(); i++)
            {
                data[sizeof(Int32) * 3 + i] = temp[i];
            }

            if (tcpSocket.Connected())
            {
                tcpSocket.Send(data, 0, sizeof(Int32) * 3 + login.CalculateSize(), out socketError);
            }

            MsgInfo msg = null;

            while (true)
            {
                int ret = tcpSocket.Receive(buffers, out socketError);
                if (buffers.IsHeaderReadable(sizeof(Int32) * 3))
                {
                    msg = buffers.Decode();
                    if (buffers.IsHeaderAndPayloadReadable(msg.GetPacLen() + sizeof(Int32) * 3))
                    {
                        buffers.GetPayload(msg);
                        buffers.SetStartByLen(msg.GetPacLen() + sizeof(Int32) * 3);
                        break;
                    }
                }
            }

            CtlMsgLoginRsp loginRsp = CtlMsgLoginRsp.Parser.ParseFrom(msg.GetPayload());

            if (loginRsp.ErrCode != ErrorCode.ErrorNoError)
            {
                RemindLable.Text      = "登录失败!";
                RemindLable.ForeColor = Color.Red;
                return;
            }
            RemindLable.Text      = "登录成功!";
            RemindLable.ForeColor = Color.Green;
            isLogined             = true;
            player = loginRsp.Player;
            LoginButton.Visible = false;
            checkBox.Visible    = false;

            InitBagInfo();
            foreach (var curitem in player.Bags.Currency)
            {
                if (curitem.ItemID == -1)
                {
                    continue;
                }
                switch (curitem.TypeID)
                {
                case 0:
                    label7.Text = "金币:" + curitem.Count;
                    break;

                case 1:
                    label10.Text = "银币:" + curitem.Count;
                    break;

                case 2:
                    label11.Text = "钻石:" + curitem.Count;
                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (isLogined == false)
            {
                RemindLable.Text      = "请正确登陆后操作!";
                RemindLable.ForeColor = Color.Red;
                return;
            }

            int id;
            int count;

            if (!Int32.TryParse(RemoveItemText.Text.Trim(), out id) || !Int32.TryParse(RemoveItemCount.Text.Trim(), out count))
            {
                RemindLable.Text      = "请输入正确的id和count!";
                RemindLable.ForeColor = Color.Red;
                return;
            }
            RemindLable.Text      = "删除成功!";
            RemindLable.ForeColor = Color.Green;
            Byte[]     temp = new byte[1024];
            byte[]     data = new byte[1024];
            AddItemReq item = new AddItemReq();

            item.ItemID = id;
            item.Count  = count;
            using (CodedOutputStream cos = new CodedOutputStream(temp))
            {
                item.WriteTo(cos);
            }
            Buffers.Encode(data, 10001, player.Id, item.CalculateSize());
            for (int i = 0; i < item.CalculateSize(); i++)
            {
                data[sizeof(Int32) * 3 + i] = temp[i];
            }

            if (tcpSocket.Connected())
            {
                tcpSocket.Send(data, 0, sizeof(Int32) * 3 + item.CalculateSize(), out socketError);
            }

            MsgInfo msg = null;

            while (true)
            {
                int ret = tcpSocket.Receive(buffers, out socketError);
                if (buffers.IsHeaderReadable(sizeof(Int32) * 3))
                {
                    msg = buffers.Decode();
                    if (buffers.IsHeaderAndPayloadReadable(msg.GetPacLen() + sizeof(Int32) * 3))
                    {
                        buffers.GetPayload(msg);
                        buffers.SetStartByLen(msg.GetPacLen() + sizeof(Int32) * 3);
                        break;
                    }
                }
            }

            RemoveItemRsp addRsp = RemoveItemRsp.Parser.ParseFrom(msg.GetPayload());

            if (addRsp.ErrCode != ErrorCode.ErrorNoError)
            {
                RemindLable.Text      = "删除失败!";
                RemindLable.ForeColor = Color.Red;
                return;
            }

            BagInfo bag = player.Bags;

            for (int i = 0; i < bag.Bag.Count; i++)
            {
                if (bag.Bag[i] == null)
                {
                    continue;
                }
                if (bag.Bag[i].ItemID == item.ItemID)
                {
                    bag.Bag[i].Count -= item.Count;  // 我发送的请求生效,则在客户端同步
                    if (bag.Bag[i].Count <= 0)
                    {
                        bag.Bag.RemoveAt(i);
                    }
                    break;
                }
            }
            InitBagInfo();
        }