void ReciveCallBack(IAsyncResult ar)
    {
        IAsyncClient obj     = (IAsyncClient)ar.AsyncState;
        Socket       handler = obj.sck;

        Debug.Log("Receive Message");

        int bytesRead = handler.EndReceive(ar);

        obj.recvbyte += bytesRead;

        if (obj.recvbyte > 0 || bytesRead > 0)
        {
            if (true == obj.signalread)
            {
                obj.recv_signal = obj.recvbuf[0];
                Buffer.BlockCopy(obj.recvbuf, 1, obj.recvbuf, 0, obj.recvbyte - 1);
                if (obj.recv_signal == NetworkController.SC_SELECT)
                {
                    select_scene   = true;
                    obj.recvbyte  -= 1;
                    obj.signalread = true;
                }
                else
                {
                    obj.recvbyte  -= 1;
                    obj.signalread = false;
                }

                Debug.Log(Convert.ToString(obj.recvbuf[0]) + " / " + Convert.ToString(obj.recv_signal));
                Debug.Log(obj.signalread);
            }
            else
            {
                if (obj.recv_signal == NetworkController.SC_CHARACTERINFOSET && obj.recvbyte >= 404)
                {
                    Buffer.BlockCopy(obj.recvbuf, 0, obj.cbuf, 0, 404);
                    object recvobj = NetFunc.ByteToObj(obj.cbuf);
                    Buffer.BlockCopy(obj.recvbuf, 404, obj.recvbuf, 0, obj.recvbyte - 404);
                    obj.recvbyte -= 404;


                    //캐릭터 인포 셋 수신
                    scinf         = (SC_CHARACTERINFOSET_PACKET)recvobj;
                    recv_charinfo = true;

                    //Debug.Log("type : " + Convert.ToString(res.characterinfo[].ch_type) + " / vit : " + Convert.ToString(res.ch_vit));

                    obj.recv_signal = NetworkController.S_NULL;
                    obj.signalread  = true;
                }
            }
        }
        obj.sck.BeginReceive(obj.recvbuf, obj.recvbyte, NetworkController.MAXBUFFERSIZE - obj.recvbyte, 0, new AsyncCallback(ReciveCallBack), obj);
    }
示例#2
0
    //5.15 끝

    //받은 데이터 체크 꼭 할것!!!!
    public void DataReceive(IAsyncResult ar)
    {
        IAsyncClient obj     = (IAsyncClient)ar.AsyncState;
        Socket       handler = obj.s;

        int bytesRead = handler.EndReceive(ar);

        obj.recvbyte += bytesRead;

        //길이 맞는지 확인해보고
        if (obj.recvbyte > 0 || bytesRead > 0)
        {
            Debug.Log("DataRecived");
            if (true == obj.signalread)
            {
                //5.14 홍승준 수정
                obj.recv_signal = obj.recvbuf[0];
                Buffer.BlockCopy(obj.recvbuf, 1, obj.recvbuf, 0, obj.recvbyte - 1);

                switch (obj.recv_signal)
                {
                case NetworkController.CS_REQCHR:
                    //캐릭터 정보 요청 신호 일 때
                    Debug.Log("Requset signal");
                    SC_CHARACTERINFOSET_PACKET chset = new SC_CHARACTERINFOSET_PACKET();
                    chset.characterinfo = new SC_CHARACTERINFO_PACKET[4];

                    int i = 0;
                    for (i = 0; i < 4; i++)
                    {
                        if (connected[i])
                        {
                            chset.characterinfo[i]    = GS.PC[i].CharacterInfo();
                            chset.characterinfo[i].id = (byte)i;
                        }
                        else
                        {
                            chset.characterinfo[i].id = 125;
                        }
                    }

                    NC.net_send_signal(NetworkController.SC_CHARACTERINFOSET, obj.s);
                    NC.net_send(chset, obj.s, NetworkController.SC_CHARACTERINFOSET);

                    Debug.Log("Ch_info_set_packet : " + NC.ObjToByte(chset).Length);
                    //다시 시그널 리시브 하도록 초기화
                    obj.recvbyte  -= 1;
                    obj.signalread = true;

                    break;

                default:
                    obj.recvbyte  -= 1;
                    obj.signalread = false;
                    break;
                }
            }
            //5.14 홍승준 수정 끝
            if (false == obj.signalread)
            {
                if (obj.recv_signal == NetworkController.CS_DISCONNECT)
                {
                    client_sock.Remove(obj.s);
                    obj.s.Disconnect(false);

                    if (false == isgamescene)
                    {
                        CC.disconnected(obj.id);
                    }
                    else
                    {
                        GS.disconnected(obj.id);
                    }
                    return;
                }

                else if (obj.recv_signal == NetworkController.CS_CONNECT && obj.recvbyte >= 116)
                {
                    Buffer.BlockCopy(obj.recvbuf, 0, obj.cbuf, 0, 116);
                    object recvobj = NC.ByteToObj(obj.cbuf);
                    Buffer.BlockCopy(obj.recvbuf, 116, obj.recvbuf, 0, obj.recvbyte - 116);
                    obj.recvbyte -= 116;
                    CS_CONNECT_PACKET res = (CS_CONNECT_PACKET)recvobj;

                    CC.nickname[res.id] = res.nickname;
                    obj.recv_signal     = NetworkController.S_NULL;
                    obj.signalread      = true;
                }

                else if (obj.recv_signal == NetworkController.CS_MOVE && obj.recvbyte >= 89)
                {
                    Buffer.BlockCopy(obj.recvbuf, 0, obj.cbuf, 0, 89);
                    object recvobj = NC.ByteToObj(obj.cbuf);
                    Buffer.BlockCopy(obj.recvbuf, 89, obj.recvbuf, 0, obj.recvbyte - 89);
                    obj.recvbyte -= 89;
                    CS_MOVE_PACKET res = (CS_MOVE_PACKET)recvobj;

                    if (false == isgamescene)
                    {
                        CC.move(res.x, res.y, res.id);
                    }
                    else
                    {
                        GS.move(res.x, res.y, res.id);
                    }
                    obj.recv_signal = NetworkController.S_NULL;
                    obj.signalread  = true;
                }
                else if (obj.recv_signal == NetworkController.CS_BTN && obj.recvbyte >= 89)
                {
                    Buffer.BlockCopy(obj.recvbuf, 0, obj.cbuf, 0, 89);
                    object recvobj = NC.ByteToObj(obj.cbuf);
                    Buffer.BlockCopy(obj.recvbuf, 89, obj.recvbuf, 0, obj.recvbyte - 89);
                    obj.recvbyte -= 89;
                    CS_BUTTON_PACKET res = (CS_BUTTON_PACKET)recvobj;

                    if (false == isgamescene)
                    {
                        CC.click(res.id, res.btn_number);
                    }
                    else
                    {
                        GS.click(res.id, res.btn_number);
                    }
                    obj.recv_signal = NetworkController.S_NULL;
                    obj.signalread  = true;
                }//5.15 홍승준 추가//5.18 홍승준 수정
                else if (obj.recv_signal == NetworkController.CS_SKILL && obj.recvbyte >= 104)
                {
                    Buffer.BlockCopy(obj.recvbuf, 0, obj.cbuf, 0, 104);
                    object recvobj = NC.ByteToObj(obj.cbuf);
                    Buffer.BlockCopy(obj.recvbuf, 104, obj.recvbuf, 0, obj.recvbyte - 104);
                    obj.recvbyte -= 104;

                    CS_SKILLSET_PACKET sc = (CS_SKILLSET_PACKET)recvobj;
                    sm.MakeCharacter(0, sc.id, sc);
                    obj.recv_signal = NetworkController.S_NULL;
                    obj.signalread  = true;

                    /*
                     * Debug.Log("id : "+ Convert.ToString(sc.sk_id));
                     * Debug.Log(" 1 : "+(short)sc.sk_id[0]);
                     * Debug.Log(" 2 : " + (short)sc.sk_id[1]);
                     * Debug.Log(" 3 : " + (short)sc.sk_id[2]);
                     * Debug.Log(" 4 : " + (short)sc.sk_id[3]);*/
                }//여기까지
                else if (obj.recv_signal == NetworkController.CS_UPGRADE && obj.recvbyte >= 85)
                {
                    Debug.Log("UPGRADE RECEIVE");
                    Buffer.BlockCopy(obj.recvbuf, 0, obj.cbuf, 0, 85);
                    object recvobj = NC.ByteToObj(obj.cbuf);
                    Buffer.BlockCopy(obj.recvbuf, 85, obj.recvbuf, 0, obj.recvbyte - 85);
                    obj.recvbyte -= 85;

                    Ms.Upgrade_reciev(recvobj);
                    obj.recv_signal = NetworkController.S_NULL;
                    obj.signalread  = true;
                }
            }
        }


        handler.BeginReceive(obj.recvbuf, obj.recvbyte, NetworkController.MAXBUFFERSIZE - obj.recvbyte, 0, new AsyncCallback(DataReceive), obj);
    }