示例#1
0
    private void OnButton_Binary_SendMsg()
    {
        ByteStreamBuff _tmpbuff = new ByteStreamBuff();

        _tmpbuff.Write_Int(1314);
        _tmpbuff.Write_Float(99.99f);
        _tmpbuff.Write_UniCodeString("Claine");
        _tmpbuff.Write_UniCodeString("123456");
        SocketManager.Instance.SendMsg(eProtocalCommand.sc_binary_login, _tmpbuff);
    }
示例#2
0
    private void CallBack_Binary_LoginServer(byte[] _msgData)
    {
        ByteStreamBuff _tmpbuff = new ByteStreamBuff(_msgData);

        Debug.Log(_tmpbuff.Read_Int());
        Debug.Log(_tmpbuff.Read_Float());
        Debug.Log(_tmpbuff.Read_UniCodeString());
        Debug.Log(_tmpbuff.Read_UniCodeString());
        _tmpbuff.Close();
        _tmpbuff = null;
    }
示例#3
0
    public static void GetObjByNetData <T>(byte[] data, out NetError err, out T tData) where T : new()
    {
        ByteStreamBuff _tmpbuff = new ByteStreamBuff(data);
        string         str      = _tmpbuff.Read_String();

        _tmpbuff.Close();
        _tmpbuff = null;

        Debug.Log(str);

        bool isError = str.IndexOf("err") != -1;

        err   = isError ? JsonUtility.FromJson <NetError> (str) : null;
        tData = isError ? new T() : JsonUtility.FromJson <T>(str);
    }
示例#4
0
    public void sendFromatToServer(int flag, byte dire)
    {
        ByteStreamBuff _tmpbuff = new ByteStreamBuff();

        /*_tmpbuff.Write_Int(1314);
         * _tmpbuff.Write_Float(99.99f);
         * _tmpbuff.Write_UniCodeString("Claine");
         * _tmpbuff.Write_UniCodeString("123456");
         * SocketManager.Instance.SendMsg(eProtocalCommand.sc_binary_login, _tmpbuff);*/

        switch (flag)
        {
        case MAP_FLAG:
            _tmpbuff.Write_Byte(MAP_FLAG);
            break;

        case JION_IN:
            _tmpbuff.Write_Byte(JION_IN);
            break;

        case TURN_FLAG:
            _tmpbuff.Write_Byte(TURN_FLAG);
            _tmpbuff.Write_Byte(dire);
            break;

        case GAME_STATE_FLAG:
            _tmpbuff.Write_Byte(GAME_STATE_FLAG);
            _tmpbuff.Write_Int(1);
            break;

        default:
            break;
        }

        SocketManager.Instance.SendMsg(_tmpbuff);

        return;
    }
示例#5
0
 /// <summary>
 /// 以二进制方式发送
 /// </summary>
 /// <param name="_protocalType"></param>
 /// <param name="_byteStreamBuff"></param>
 public void SendMsg(eProtocalCommand _protocalType, ByteStreamBuff _byteStreamBuff)
 {
     SendMsgBase(_protocalType, _byteStreamBuff.ToArray());
 }
示例#6
0
 /// <summary>
 /// 以二进制方式发送
 /// </summary>
 /// <param name="_protocalType"></param>
 /// <param name="_byteStreamBuff"></param>
 public void SendMsg(ushort _protocalType, ByteStreamBuff _byteStreamBuff)
 {
     //SendMsgBase(_protocalType, _byteStreamBuff.ToArray());
 }
 public void SendMsg(ByteStreamBuff _byteStreamBuff)
 {
     SendMsgBase(_byteStreamBuff.ToArray());
 }
示例#8
0
    private void gameCmd(byte[] data)
    {
        ByteStreamBuff _tmpbuff = new ByteStreamBuff(data);
        int            flag     = _tmpbuff.Read_Byte();

        switch (flag)
        {
        case MAP_FLAG:
            int[,] tmp_game_map = new int[GAME_H, GAME_W];
            List <Cooder> tmp_li_m = new List <Cooder>();
            List <Cooder> tmp_li_e = new List <Cooder>();
            int           nodeSum;
            int           x, y;
            nodeSum = _tmpbuff.Read_Int();
            for (int i = 0; i < nodeSum; i++)
            {
                x = _tmpbuff.Read_Byte();
                y = _tmpbuff.Read_Byte();
                tmp_game_map[x, y] = SER_FLAG;
                if (game_sc_mode == SER_FLAG)
                {
                    tmp_li_m.Add(new Cooder(x, y));
                }
                else
                {
                    tmp_li_e.Add(new Cooder(x, y));
                }
            }
            nodeSum = _tmpbuff.Read_Int();
            for (int i = 0; i < nodeSum; i++)
            {
                x = _tmpbuff.Read_Byte();
                y = _tmpbuff.Read_Byte();
                tmp_game_map[x, y] = CLI_FLAG;
                if (game_sc_mode == CLI_FLAG)
                {
                    tmp_li_m.Add(new Cooder(x, y));
                }
                else
                {
                    tmp_li_e.Add(new Cooder(x, y));
                }
            }

            food.x = _tmpbuff.Read_Byte();
            food.y = _tmpbuff.Read_Byte();

            game_map   = tmp_game_map;
            snake_li_m = tmp_li_m;
            snake_li_e = tmp_li_e;
            break;

        case COM_DONE:
            game_online_flag = 1;
            game_sc_mode     = _tmpbuff.Read_Byte();
            game_move_per_ms = _tmpbuff.Read_Int();
            // GAME_H = _tmpbuff.Read_Int();
            // GAME_W = _tmpbuff.Read_Int();
            game_map   = new int[GAME_H, GAME_W];
            snake_li_m = new List <Cooder>();
            snake_li_e = new List <Cooder>();
            food       = new Cooder(0, 0);


            // controlMap = new int[GAME_H, GAME_W];
            // for(int i=0;i<GAME_H;++i){
            //     for(int j=0;j<GAME_W;++j){
            //         controlMap[i,j]=_tmpbuff.Read_Byte();
            //     }
            // }
            //Debug.Log("COM_DOWN");
            break;

        case GAME_STATE_FLAG:
            win_los_flag = _tmpbuff.Read_Byte();
            break;

        case FOOD_FLAG:
            break;

        default:
            Debug.Log("Unknow flag!");
            break;
        }
    }
示例#9
0
 /// <summary>
 /// 以二进制方式发送
 /// </summary>
 /// <param name="_protocalType"></param>
 /// <param name="_byteStreamBuff"></param>
 public void SendMsg(UInt16 _protocalType, ByteStreamBuff _byteStreamBuff)
 {
     SendMsgBase(_protocalType, _byteStreamBuff.ToArray());
 }