Example #1
0
 public PACKET_REQ_MULTI_ROOM(PACKET_HEADER packetHeader, GAME_INDEX _gameIndex, int _charIndex, int _itemIndex)
 {
     header             = packetHeader;
     gameIndex          = (int)_gameIndex;
     charInfo.charIndex = _charIndex;
     charInfo.item      = _itemIndex;
 }
Example #2
0
    public void SendRequsetRank(GAME_INDEX currentGameIndex)
    {
        PACKET_HEADER   headerPacket = MakeHeaderPacket(PACKET_INDEX.REQ_RANK);
        PACKET_REQ_RANK packet       = new PACKET_REQ_RANK
        {
            header    = headerPacket,
            gameIndex = (int)currentGameIndex,
        };

        SendToServerPacket(packet);
    }
Example #3
0
    public void SendRequestRopePull(float pullPower)
    {
        PACKET_HEADER headerPacket           = MakeHeaderPacket(PACKET_INDEX.REQ_RES_ROPE_PULL_GAME);
        PACKET_REQ_RES_ROPE_PULL_GAME packet = new PACKET_REQ_RES_ROPE_PULL_GAME
        {
            header  = headerPacket,
            ropePos = pullPower,
        };

        SendToServerPacket(packet);
    }
Example #4
0
    public void SendRequestEarnGold(int goldAmount)
    {
        PACKET_HEADER       headerPacket = MakeHeaderPacket(PACKET_INDEX.REQ_SET_GOLD);
        PACKET_REQ_RES_GOLD packet       = new PACKET_REQ_RES_GOLD
        {
            header = headerPacket,
            gold   = goldAmount,
        };

        SendToServerPacket(packet);
    }
Example #5
0
    public void SendRequestExitRoom(GAME_INDEX roomIndex, bool isRoomEndGame)
    {
        PACKET_HEADER        headerPacket = MakeHeaderPacket(PACKET_INDEX.REQ_INIT_ROOM);
        PACKET_REQ_INIT_ROOM packet       = new PACKET_REQ_INIT_ROOM
        {
            header    = headerPacket,
            gameIndex = (int)roomIndex,
            isEndGame = isRoomEndGame,
        };

        SendToServerPacket(packet);
    }
Example #6
0
    public void SendRequestMove(float posX, float posY, float posZ)
    {
        PACKET_HEADER       headerPacket = MakeHeaderPacket(PACKET_INDEX.REQ_RES_MOVE);
        PACKET_REQ_RES_MOVE packet       = new PACKET_REQ_RES_MOVE
        {
            header    = headerPacket,
            positionX = posX,
            positionY = posY,
            positionZ = posZ,
        };

        SendToServerPacket(packet);
    }
Example #7
0
    public void SendRequestFireBall(float firePower, float fireAngleX, float fireAngleY)
    {
        PACKET_HEADER headerPacket             = MakeHeaderPacket(PACKET_INDEX.REQ_RES_BASKET_BALL_GAME);
        PACKET_REQ_RES_BASKET_BALL_GAME packet = new PACKET_REQ_RES_BASKET_BALL_GAME
        {
            header = headerPacket,
            power  = firePower,
            angleX = fireAngleX,
            angleY = fireAngleY,
        };

        SendToServerPacket(packet);
    }
Example #8
0
    public void SendNickName(string playerNickName)
    {
        if (_sock == null)
        {
            Connect();
        }
        PACKET_HEADER headerPacket = MakeHeaderPacket(PACKET_INDEX.REQ_IN);
        PACKET_REQ_IN packet       = new PACKET_REQ_IN {
            header = headerPacket, name = playerNickName, clientID = ResourceManager.Instance.ClientId
        };

        SendToServerPacket(packet);
    }
Example #9
0
    // Start is called before the first frame update
    void Start()
    {
        sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
        if (sock == null)
        {
            Debug.Log("소켓생성 실패");
        }
        sock.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 31400));

        {
            var headerPacket = new PACKET_HEADER {
                packetIndex = 206, packetSize = 10
            };
            var p = new PACKET_MULTI_ROOM {
                header = headerPacket, gameIndex = 21
            };
            string json;
            json  = JsonConvert.SerializeObject(p); //객체를 json직렬화
            json += '\0';                           //서버에서 널문자까지 읽기 위해 널문자붙이기
            byte[] bufSend = new byte[128];         //전송을 위해 바이트단위로 변환
            bufSend = Encoding.UTF8.GetBytes(json);
            sock.Send(bufSend);
        }


        byte[] bufRecv = new byte[300]; //수신을 위해 바이트단위로 변환
        int    n       = sock.Receive(bufRecv);

        int bufLen = bufRecv.Length;

        string recvData = Encoding.UTF8.GetString(bufRecv, 0, n);

        Debug.Log(recvData);

        var data = JsonConvert.DeserializeObject <TempPacket>(recvData);

        if (data.header.packetIndex == 207) //JsonExample
        {
            JObject         jobj = JObject.Parse(recvData);
            PACKET_RES_RANK packetTemp;
            packetTemp = JsonConvert.DeserializeObject <PACKET_RES_RANK>(recvData);
            Debug.Log(recvData);

            for (int i = 0; i < 5; i++)
            {
                Debug.Log(packetTemp.rank[i].name);
                Debug.Log(packetTemp.rank[i].winRecord);
            }
        }
    }
Example #10
0
    public void SendFriendFarmDataRequest(int clientId)
    {
        if (_sock == null)
        {
            return;
        }

        PACKET_HEADER         headerPacket = MakeHeaderPacket(PACKET_INDEX.REQ_ENTER_FARM);
        PACKET_REQ_ENTER_FARM packet       = new PACKET_REQ_ENTER_FARM
        {
            header   = headerPacket,
            clientID = clientId
        };

        SendToServerPacket(packet);
    }
Example #11
0
    public void SendCheckClientIsExist(int clientId)
    {
        if (_sock == null)
        {
            return;
        }

        PACKET_HEADER headerPacket        = MakeHeaderPacket(PACKET_INDEX.REQ_CHECK_CLIENT_ID);
        PACKET_REQ_CHECK_CLIENT_ID packet = new PACKET_REQ_CHECK_CLIENT_ID
        {
            header   = headerPacket,
            clientID = clientId
        };

        SendToServerPacket(packet);
    }
Example #12
0
    public void SendRequestRoom(GAME_INDEX roomIndex)
    {
        if (_sock == null)
        {
            Connect();
        }

        PACKET_HEADER         headerPacket = MakeHeaderPacket(PACKET_INDEX.REQ_MULTI_ROOM);
        PACKET_REQ_MULTI_ROOM packet       = new PACKET_REQ_MULTI_ROOM
                                             (
            headerPacket,
            roomIndex,
            InventoryManager.Instance.CurrentCharacter.Type,
            InventoryManager.Instance.CurrentEquipment.Type
                                             );

        SendToServerPacket(packet);
    }
Example #13
0
    public bool SendFarmSaveData(MapData.ESaveType index, string data)
    {
        if (_sock == null)
        {
            return(false);
        }

        PACKET_HEADER       headerPacket = MakeHeaderPacket(PACKET_INDEX.REQ_SAVE_FARM);
        PACKET_REQ_RES_FARM packet       = new PACKET_REQ_RES_FARM
        {
            header    = headerPacket,
            saveIndex = (int)index,
            saveData  = data
        };

        SendToServerPacket(packet);
        return(true);
    }
Example #14
0
            public SENSOR_MESSAGE_PACKET(UInt32 addr, byte[] packet)
            {
                if (packet == null || packet.Length != 32)
                {
                    throw new BadPacketException();
                }

                Header = new PACKET_HEADER(PacketType.SensorMessage, (UInt16)Marshal.SizeOf(typeof(SENSOR_MESSAGE_PACKET)));
                SensorId = addr;
                MsgData = packet;
            }
Example #15
0
 public STATUSREPORT_PACKET(UInt16 dummy)
 {
     Header = new PACKET_HEADER(PacketType.Status, (UInt16)Marshal.SizeOf(typeof(STATUSREPORT_PACKET)));
 }
Example #16
0
 public REGISTER_PACKET(Guid gatewayId, UInt32 addr, UInt32 networkKey)
 {
     Header = new PACKET_HEADER(PacketType.Register, (UInt16)Marshal.SizeOf(typeof(REGISTER_PACKET)));
     GatewayId = gatewayId;
     NetworkKey = networkKey;
     GatewayAddr = addr;
 }
Example #17
0
    PACKET_HEADER MakeHeaderPacket(PACKET_INDEX packetIndex)
    {
        switch (packetIndex)
        {
        case PACKET_INDEX.REQ_IN:
        {
            int           packetSize = Marshal.SizeOf <PACKET_REQ_IN>();
            PACKET_HEADER headerPacket;
            headerPacket = new PACKET_HEADER(packetIndex, packetSize);
            return(headerPacket);
        }

        case PACKET_INDEX.REQ_MULTI_ROOM:
        {
            int           packetSize = Marshal.SizeOf <PACKET_REQ_MULTI_ROOM>();
            PACKET_HEADER headerPacket;
            headerPacket = new PACKET_HEADER(packetIndex, packetSize);
            return(headerPacket);
        }

        case PACKET_INDEX.REQ_INIT_ROOM:
        {
            int           packetSize = Marshal.SizeOf <PACKET_REQ_INIT_ROOM>();
            PACKET_HEADER headerPacket;
            headerPacket = new PACKET_HEADER(packetIndex, packetSize);
            return(headerPacket);
        }

        case PACKET_INDEX.REQ_RANK:
        {
            int           packetSize = Marshal.SizeOf <PACKET_REQ_RANK>();
            PACKET_HEADER headerPacket;
            headerPacket = new PACKET_HEADER(packetIndex, packetSize);
            return(headerPacket);
        }

        case PACKET_INDEX.REQ_RES_ROPE_PULL_GAME:
        {
            int           packetSize = Marshal.SizeOf <PACKET_REQ_RES_ROPE_PULL_GAME>();
            PACKET_HEADER headerPacket;
            headerPacket = new PACKET_HEADER(packetIndex, packetSize);
            return(headerPacket);
        }

        case PACKET_INDEX.REQ_RES_BASKET_BALL_GAME:
        {
            int           packetSize = Marshal.SizeOf <PACKET_REQ_RES_BASKET_BALL_GAME>();
            PACKET_HEADER headerPacket;
            headerPacket = new PACKET_HEADER(packetIndex, packetSize);
            return(headerPacket);
        }

        case PACKET_INDEX.REQ_RES_MOVE:
        {
            int           packetSize = Marshal.SizeOf <PACKET_REQ_RES_MOVE>();
            PACKET_HEADER headerPacket;
            headerPacket = new PACKET_HEADER(packetIndex, packetSize);
            return(headerPacket);
        }

        case PACKET_INDEX.REQ_SET_GOLD:
        {
            int           packetSize = Marshal.SizeOf <PACKET_REQ_RES_GOLD>();
            PACKET_HEADER headerPacket;
            headerPacket = new PACKET_HEADER(packetIndex, packetSize);
            return(headerPacket);
        }

        default:
        {
            int           packetSize = Marshal.SizeOf <PACKET_REQ_IN>();
            PACKET_HEADER headerPacket;
            headerPacket = new PACKET_HEADER(packetIndex, packetSize);
            return(headerPacket);
        }
        }
    }
Example #18
0
 public ACKNOWLEDGE_PACKET(UInt32 origPacketId)
 {
     Header = new PACKET_HEADER(PacketType.Acknowledge, (UInt16)Marshal.SizeOf(typeof(ACKNOWLEDGE_PACKET)));
     OrigPacketId = origPacketId;
 }
Example #19
0
        public PACKET_TYPES GetPacketType(byte[] packet, ref int payLoadLength, ref ERROR_CODES error, out PACKET_HEADER managedHeader)
        {
            managedHeader = new PACKET_HEADER();

            try
            {
                if (packet.Length < HeaderLessSOPLength)
                {
                    return(PACKET_TYPES.INVALID_PACKET);
                }

                PACKET_HEADER_LESS_SOP_STRUCT pktHdr = new PACKET_HEADER_LESS_SOP_STRUCT();

                int    size       = Marshal.SizeOf(typeof(PACKET_HEADER_LESS_SOP_STRUCT));
                byte[] headerPart = new byte[size];
                headerPart = (byte[])Slice(packet, 0, size);
                GCHandle handle = GCHandle.Alloc(headerPart, GCHandleType.Pinned);
                pktHdr = (PACKET_HEADER_LESS_SOP_STRUCT)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(PACKET_HEADER_LESS_SOP_STRUCT));
                handle.Free();

                payLoadLength = (int)pktHdr.PACKET_LEN;

                PACKET_TYPES pktTpye = (PACKET_TYPES)pktHdr.PACKET_TYPE;

                error = ERROR_CODES.NO_ERROR;

                if (!CheckAllPacketTypes(pktTpye))
                {
                    error = ERROR_CODES.BAD_PACKET;
                    return(PACKET_TYPES.INVALID_PACKET);
                }

                switch ((PACKET_TYPES)pktTpye)
                {
                case PACKET_TYPES.REQUEST_HOST_NAME:
                    m_Log.Log("GetPacketType, received REQUEST_HOST_NAME ", ErrorLog.LOG_TYPE.INFORMATIONAL);

                    if (!DoesGetHostPWMatch(pktHdr.PasswordHash))
                    {
                        m_Log.Log("GetPacketType, ERROR_CODES.INVALID_PASSWORD", ErrorLog.LOG_TYPE.INFORMATIONAL);

                        error = ERROR_CODES.INVALID_PASSWORD;
                    }

                    break;



                default:

                    managedHeader.Type           = (PACKET_TYPES)pktHdr.PACKET_TYPE;
                    managedHeader.PasswordHash   = pktHdr.PasswordHash;
                    managedHeader.SequenceNumber = (int)pktHdr.SEQUENCE_NUMBER;
                    managedHeader.Length         = (int)pktHdr.PACKET_LEN;
                    break;
                }



                return((PACKET_TYPES)pktHdr.PACKET_TYPE);
            }
            catch (Exception ex)
            {
                m_Log.Log("GetPacketTypeex: " + ex.Message, ErrorLog.LOG_TYPE.INFORMATIONAL);
                return((PACKET_TYPES)PACKET_TYPES.INVALID_PACKET);
            }
        }