Пример #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();
    }
Пример #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;
                }
            }
        }