예제 #1
0
    //new player for me
    public static void sendCreateSelf()
    {
        // ====== 走pb 发送 ====== or 直接发送 =====
#if PROTOBUFF
        Rqst_CreateSelf data = new Rqst_CreateSelf();
        data.Account  = "" + 1000 + UnityEngine.Random.Range(1, 100);
        data.Password = "" + 123456;
        DebugTool.LogYellow("[TCP] sendCreateSelf 请求创建我方角色" + data.Account);
        connect_TCP.Send <Rqst_CreateSelf> ((short)NetCode.CreateSelf, data);
        GameProxy.mine        = new PlayerData();
        GameProxy.mine.userid = data.Account;
#else
        DebugTool.LogError("已经不许使用自写编码,请检察 UnityEngine里是否添加宏: PROTOBUFF");
        //===== 直接发送  自写的编码,无法对付可变长byte[]======
        SendBuffer.ResetIndex();
        SendBuffer.writeUshort(10000);         //cmd,  payload as below
        var r = UnityEngine.Random.Range(1, 100);
        SendBuffer.writeInt(9999 + r);         //accountid
//		SendBuffer.writeString ("gaohebing" + UnityEngine.Random.Range (0, 100));//nickname
//		SendBuffer.writeInt (1);//level
        SendBuffer.writeInt(123);         //password

        var    arr      = SendBuffer.GetBytes_HasData();
        byte[] sendbuff = new byte[arr.Length];
        Array.Copy(arr, sendbuff, sendbuff.Length);

        connect_TCP.SendBytes(sendbuff);
#endif
    }
예제 #2
0
        /// <summary>
        /// 获取数据比特流
        /// </summary>
        /// <returns></returns>
        public virtual void WriteMSG()
        {
//			SendBuf buf = BufferManager.getSendBuffer(opcode, true).writeUshort(cmd).writeBytes(bytes_strm).last();
            SendBuffer.writeShort(opcode);            //"WO"
            SendBuffer.writeInt(msgSize);             //uint
            SendBuffer.writeShort(cmd);
//			SendBuffer.sendbufIndex = 6;
        }
예제 #3
0
    public static void sendHeartBeating()     //msg.PlayerInfo playerinfo = )
    {
#if PROTOBUFF
        DebugTool.LogYellow("[TCP] sendHeartBeating");
        var data = new Rqst_HeartBeating();
        data.Status = 0;
        //		data.Player = playerinfo;
        connect_TCP.Send <Rqst_HeartBeating> ((short)NetCode.BeatHeart, data);
#else
        SendBuffer.ResetIndex();
        SendBuffer.writeUshort(110);     //cmd,  payload as below
        SendBuffer.writeInt(1);          // payload
        byte[] sendbuff = SendBuffer.GetBytes_HasData();
        connect_TCP.SendBytes(sendbuff);
#endif
    }