Пример #1
0
    //토탈 버퍼에 담아서 받은 패킷 나눠주는 처리 한다.
    void Total_Recv_Operation(int _Recv_Buffer_Size, byte[] _Recv_Buffer)
    {
        try
        {
            //토탈 버퍼에 현재 받은 데이터 담기
            Array.Copy(_Recv_Buffer, 0, Total_Recv_Buffer, Total_Buffer_Max_Index, _Recv_Buffer_Size);
            Total_Buffer_Max_Index += _Recv_Buffer_Size;
            ByteData _Buffer_Data = new ByteData(Total_Recv_Buffer);

            while (true)
            {
                //헤더검사를 할수 있을만큼 남았는지 체크
                if (Total_Buffer_Max_Index <= (_Buffer_Data.DataIndex + 4))
                {
                    break;
                }

                //헤더 문자열 일치 체크
                if (_Buffer_Data.Getbyte() != HeaderData[0])
                {
                    continue;
                }
                if (_Buffer_Data.Getbyte() != HeaderData[1])
                {
                    _Buffer_Data.DataIndex--; continue;
                }

                //헤더 길이 만큼 전체 데이터 받았는지 체크
                short _Data_Length = _Buffer_Data.Getshort();

                if (Total_Buffer_Max_Index < _Buffer_Data.DataIndex + _Data_Length)
                {
                    _Buffer_Data.DataIndex -= 4;
                    break;
                }

                //길이 읽은거 다시 감소
                _Buffer_Data.DataIndex -= 2;

                Receive_Delegate(_Buffer_Data.GetBytes());
            }

            //처리한 버퍼 지우고 뒤에 남은 버퍼 앞으로 땡기자
            Total_Buffer_Max_Index -= _Buffer_Data.DataIndex;

            byte[] Temp_Array = new byte[Total_Buffer_Max_Index];
            Array.Copy(Total_Recv_Buffer, _Buffer_Data.DataIndex, Temp_Array, 0, Temp_Array.Length);
            Array.Copy(Temp_Array, 0, Total_Recv_Buffer, 0, Temp_Array.Length);
        }
        catch (Exception ex)
        {
            Error_DisConnect(ex);
        }
    }
    public void ReciveData_Delegate(byte[] packet_Data)
    {
        RecieveBuffer    = new ByteData(packet_Data);
        Recieved_NetKind = (NETKIND)RecieveBuffer.Getbyte();

        if (IsOwnRecieveNetKind(Recieved_NetKind))
        {
            lock (Lockobject)
            {
                RecieveBuffer.DataIndex--;
                Que_Bytedata.Enqueue(RecieveBuffer);
            }
        }
        else if (Recieved_NetKind == NETKIND.STC_CONNECTION_RETENTION)
        {
            lock (Lockobject)
            {
                RecieveBuffer.DataIndex--;
                Que_Bytedata.Enqueue(RecieveBuffer);
            }

            Link_Script.i.GamePlay_Receive_Data(packet_Data);
        }
        else
        {
            //나머지는 배틀 쪽 KIND다 그쪽으로 보내서 처리토록하자
            Link_Script.i.GamePlay_Receive_Data(packet_Data);
        }
    }
    void Chk_RecieveProcess()
    {
        while (Chk_readBuffer() == true)
        {
            RecieveBuffer    = Read_ByteBuffer();
            Recieved_NetKind = (NETKIND)RecieveBuffer.Getbyte();

            switch (Recieved_NetKind)
            {
            case NETKIND.NONE:
                break;

            case NETKIND.STC_LOGIN:
                Recieve_STC_Login();
                break;

            case NETKIND.STC_CONNECTION_RETENTION:
                Recieve_STC_Retention();
                break;

            case NETKIND.STC_ROOM_MAKE:
                Recieve_STC_RoomMake();
                break;

            case NETKIND.STC_OPEN_ROOM:
                Recieve_STC_OpenRoom(RecieveBuffer);
                break;

            case NETKIND.STC_INVITE_ROOM:
                Recieve_STC_InviteRoom(RecieveBuffer);
                break;

            case NETKIND.STC_READYROOM_INFO:
                Recieve_STC_RoomInfo(RecieveBuffer);
                break;

            case NETKIND.STC_FRIEND_ROOM_JOIN:
                Recieve_STC_FriendRoomjoin(RecieveBuffer);
                break;

            case NETKIND.STC_CHAT_MESSAGE:
                Recieve_STC_ChatMessage(RecieveBuffer);
                break;

            case NETKIND.STC_TOAST_MSG:
                Recieve_STC_ToastMsg(RecieveBuffer);
                break;

            case NETKIND.STC_POPUP_MSG:
                Recieve_STC_PopupMsg(RecieveBuffer);
                break;

            case NETKIND.STC_ERROR_CODE:
                Recieve_STC_ERROR(RecieveBuffer);
                break;
            }
        }
    }
    void Recieve_STC_FriendRoomjoin(ByteData _recieveBuffer)
    {
        User _user = UserDataManager.instance.user;


        //byte : 참여 실패 사유
        //  0:성공
        //	1:친구가 접속중이지 않음
        //	2:친구가 방에 들어가 있지 않음
        //	3:방 입장 유저수 초과
        //byte : 성공시 방상태값 들어감
        _user.User_RcvJoinTogether.Init();
        _user.User_RcvJoinTogether.JoinResult       = _recieveBuffer.Getbyte();
        _user.User_RcvJoinTogether.JoinSuccessState = _recieveBuffer.Getbyte();


        RecieveComplete_FriendJoin();
    }
    void Recieve_STC_ChatMessage(ByteData _recieveBuffer)
    {
        User _user = UserDataManager.instance.user;

        _user.user_RecieveChat.Init();
        //byte : 종류 (1:방 채팅)
        //uint : WebUserID 유저아이디
        //ushort : 클랜 마크
        //string : 닉네임
        //string : 메세지 내용

        _user.user_RecieveChat.msgTp    = (ChatMessageType)_recieveBuffer.Getbyte();
        _user.user_RecieveChat.UesrID   = _recieveBuffer.Getuint();
        _user.user_RecieveChat.ClanMark = _recieveBuffer.Getushort();
        _user.user_RecieveChat.NkNm     = _recieveBuffer.Getstring();
        _user.user_RecieveChat.chatMsg  = _recieveBuffer.Getstring();

        ReciveComplete_Chatmessage();

        //MainMenuNetwork_State = MMSERVER_STATE.CHAT_MESSAGE;
    }
    void Recieve_STC_RoomInfo(ByteData _recieveBuffer)
    {
        User _user = UserDataManager.instance.user;


        // uint : 방장 UserID
        // byte : 맵 인덱스
        // bool : (true : 비공개, false : 공개)
        // byte : 유저수
        //		uint : 방 유저 WebUserID
        //		byte : 방 슬롯 위치 1~12
        //		string : 닉네임
        //		byte : 팀 (Red:0, Blue:1, Draw:2)
        //		ushort : 클랜 마크
        _user.User_readyRoomInfo.Init();
        _user.User_readyRoomInfo.RoomMsterUserID = _recieveBuffer.Getuint();
        _user.User_readyRoomInfo.MapIndex        = _recieveBuffer.Getbyte();
        _user.User_readyRoomInfo.isCloseRoom     = _recieveBuffer.Getbool();
        _user.User_readyRoomInfo.PersonCnt       = _recieveBuffer.Getbyte();

        byte[] _CtyCd = new byte[2];

        _user.User_RoomUserInfos.Clear();
        for (int i = 0; i < _user.User_readyRoomInfo.PersonCnt; i++)
        {
            User_RoomInfo roomUser = new User_RoomInfo();

            roomUser.roomUserID       = _recieveBuffer.Getuint();
            roomUser.roomUserSlot     = _recieveBuffer.Getbyte();
            roomUser.roomUserNkNm     = _recieveBuffer.Getstring();
            roomUser.roomUserTeam     = _recieveBuffer.Getbyte();
            roomUser.roomUserClanMark = _recieveBuffer.Getushort();
            _CtyCd[0]             = _recieveBuffer.Getbyte();
            _CtyCd[1]             = _recieveBuffer.Getbyte();
            roomUser.roomUserFlag = Encoding.UTF8.GetString(_CtyCd, 0, _CtyCd.Length);

            _user.User_RoomUserInfos[roomUser.roomUserID] = roomUser;
        }


        RecieveComplete_RoomInfo();

        //MainMenuNetwork_State = MMSERVER_STATE.ROOM_INFO;
    }
Пример #7
0
    public void Receive_Delegate(byte[] Packet_Data)
    {
        try
        {
            Receive_Buffer   = new ByteData(Packet_Data);
            Receive_Protocol = (NETKIND)Receive_Buffer.Getbyte();

            switch (Receive_Protocol)
            {
            case NETKIND.STC_BATTLEROOM_INFO:

                Recv_Quick_Join(Receive_Buffer);

                break;

            case NETKIND.STC_BATTLEROOM_START_INFO:

                Recv_TeamPlay_Join(Receive_Buffer);

                break;

            case NETKIND.STC_KILL_WORDS:

                Recv_Killing_Message(Receive_Buffer);

                break;

            case NETKIND.STC_CONNECTION_RETENTION:

                Recv_HeartBeat();

                break;

            case NETKIND.STC_CONNECT_TIMEOVER:

                Recv_Connect_TimeOver();

                break;

            case NETKIND.STC_GAME_START:

                Recv_GamePlay_Start();

                break;

            case NETKIND.STC_GAMEDATA_RELAY:

                Recv_PTP_Data(Receive_Buffer);

                break;

            case NETKIND.STC_SET_HP:

                Recv_Set_HP(Receive_Buffer);

                break;

            case NETKIND.STC_GAME_ROOM_TIME:

                Recv_GetServerTime(Receive_Buffer);

                break;

            case NETKIND.STC_REVIVAL:

                Recv_Respawn_Data(Receive_Buffer);

                break;

            case NETKIND.STC_INSTANT_REVIVAL:

                Recv_Now_Respawn_Data(Receive_Buffer);

                break;

            case NETKIND.STC_SET_USERKILL:

                Recv_UserKill(Receive_Buffer);

                break;

            case NETKIND.STC_ROOM_JOIN_NOTICE:

                Recv_RoomIn_User(Receive_Buffer);

                break;

            case NETKIND.STC_ROOM_OUT_USER:    //플레이중에 나간 유저 체크

                Recv_RoomOut_User(Receive_Buffer);

                break;

            case NETKIND.STC_GAME_SCORE:

                Recv_Now_Total_Score(Receive_Buffer);

                break;

            case NETKIND.STC_MAINBASE_HP:

                Recv_Base_HP(Receive_Buffer);

                break;

            case NETKIND.STC_GAME_TIMEOVER:

                Recv_TimerOver(Receive_Buffer);

                break;

            case NETKIND.STC_GAME_REWRDEND:

                Recv_RewardEnd();

                break;
            //case NETKIND.STC_CHAT_MESSAGE:

            //    //인게임중 채팅 메세지를 받습니다 (서버에서 받은 byteData )
            //    SendManager.Instance.RecieveChatMessage_BattleGame(Receive_Buffer);

            //    break;
            //case NETKIND.STC_ERROR_CODE:

            //    byte Error_Code = 0;

            //    Receive_Buffer.OutPutVariable(ref Error_Code);

            //    Debug.LogError("서버에서 정의한 에러값 넘어왔다 : " + (ErrorCode)Error_Code);

            //    break;
            default:

                Disconnect("선언 되지 않은 프로토콜 : " + Receive_Protocol);

                break;
            }
        }
        catch (Exception ex)
        {
            Disconnect(ex.ToString());
        }
    }