示例#1
0
        public PlayerSpawnPacket(int id, Vector2f pos)
        {
            packetType = PACKET_TYPES.PLAYER_SPAWN;

            this.id  = id;
            position = pos;
        }
示例#2
0
        public PlayerShootPacket(int id, Vector2f origin, Vector2f direction)
        {
            packetType = PACKET_TYPES.PLAYER_SHOOT;

            this.id        = id;
            this.origin    = origin;
            this.direction = direction;
        }
示例#3
0
        public LobbyInfoPacket(State state, int playerCount, int countdown)
        {
            packetType = PACKET_TYPES.LOBBY_INFO;

            this.state       = state;
            this.playerCount = playerCount;
            this.countdown   = countdown;
        }
示例#4
0
        //REQUEST_CHANNEL_LIST:
        public byte[] CreatePacket(string password, PACKET_TYPES type)
        {
            try
            {
                byte[] hdrBytes = null;
                byte[] packet   = null;
                switch (type)
                {
                case PACKET_TYPES.REQUEST_CHANNEL_LIST:
                {
                    PACKET_HEADER_STRUCT hdr = new PACKET_HEADER_STRUCT();

                    hdr.PACKET_TYPE     = (uint)type;
                    hdr.PACKET_LEN      = (uint)0;
                    hdr.SEQUENCE_NUMBER = (uint)m_OutBoundSequenceNumber++;
                    hdrBytes            = new byte[Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT))];
                    string seqNumS = ((byte)hdr.SEQUENCE_NUMBER).ToString();
                    hdr.PasswordHash    = EncyptGetHostPassword(password + "," + seqNumS);
                    hdr.START_OF_PACKET = 0xaa55aa55;

                    packet = new byte[Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT))];

                    GCHandle handle = GCHandle.Alloc(packet, GCHandleType.Pinned);
                    Marshal.StructureToPtr(hdr, handle.AddrOfPinnedObject(), true);
                    handle.Free();
                }
                break;

                case PACKET_TYPES.REQUEST_STATS:
                {
                    PACKET_HEADER_STRUCT hdr = new PACKET_HEADER_STRUCT();

                    hdr.PACKET_TYPE     = (uint)type;
                    hdr.PACKET_LEN      = (uint)0;
                    hdr.SEQUENCE_NUMBER = (uint)m_OutBoundSequenceNumber++;
                    hdrBytes            = new byte[Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT))];
                    string seqNumS = ((byte)hdr.SEQUENCE_NUMBER).ToString();
                    hdr.PasswordHash    = EncyptGetHostPassword(password + "," + seqNumS);
                    hdr.START_OF_PACKET = 0xaa55aa55;

                    packet = new byte[Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT))];

                    GCHandle handle = GCHandle.Alloc(packet, GCHandleType.Pinned);
                    Marshal.StructureToPtr(hdr, handle.AddrOfPinnedObject(), true);
                    handle.Free();
                }
                break;
                }
                return(packet);
            }
            catch (Exception ex)
            {
                m_Log.Log("CreatePacket: " + ex.Message, ErrorLog.LOG_TYPE.INFORMATIONAL);
                return(null);
            }
        }
示例#5
0
        public PlayerUpdatePacket(int id, float hp, Vector2f pos, Vector2f vel, Vector2f dir)
        {
            packetType = PACKET_TYPES.PLAYER_UPDATE;

            this.id   = id;
            health    = hp;
            position  = pos;
            velocity  = vel;
            direction = dir;
        }
示例#6
0
        public byte[] CreatePacket(PACKET_TYPES type)
        {
            try
            {
                byte[] hdrBytes = null;

                switch (type)
                {
                case PACKET_TYPES.REPLY_VALID_ADMIN_PASSWORD:
                {
                    PACKET_HEADER_STRUCT hdr = new PACKET_HEADER_STRUCT();


                    hdr.PACKET_TYPE     = (uint)type;
                    hdr.PACKET_LEN      = (uint)0;
                    hdr.SEQUENCE_NUMBER = (uint)m_OutBoundSequenceNumber++;
                    hdr.START_OF_PACKET = 0xaa55aa55;

                    hdrBytes = new byte[Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT))];

                    GCHandle handle = GCHandle.Alloc(hdrBytes, GCHandleType.Pinned);
                    Marshal.StructureToPtr(hdr, handle.AddrOfPinnedObject(), true);
                    handle.Free();
                }
                break;

                case PACKET_TYPES.REPLY_VALID_VIEWER_PASSWORD:
                {
                    PACKET_HEADER_STRUCT hdr = new PACKET_HEADER_STRUCT();


                    hdr.PACKET_TYPE     = (uint)type;
                    hdr.PACKET_LEN      = (uint)0;
                    hdr.SEQUENCE_NUMBER = (uint)m_OutBoundSequenceNumber++;
                    hdr.START_OF_PACKET = 0xaa55aa55;
                    hdrBytes            = new byte[Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT))];

                    GCHandle handle = GCHandle.Alloc(hdrBytes, GCHandleType.Pinned);
                    Marshal.StructureToPtr(hdr, handle.AddrOfPinnedObject(), true);
                    handle.Free();
                }
                break;
                }
                return(hdrBytes);
            }
            catch (Exception ex)
            {
                m_Log.Log("CreatePacket: " + ex.Message, ErrorLog.LOG_TYPE.INFORMATIONAL);
                return(null);
            }
        }
示例#7
0
        bool CheckAllPacketTypes(PACKET_TYPES pktTpye)
        {
            foreach (PACKET_TYPES item in Enum.GetValues(typeof(PACKET_TYPES)))
            {
                if (item == PACKET_TYPES.INVALID_PACKET)
                {
                    continue;
                }

                if (pktTpye == item)
                {
                    return(true);
                }
            }

            return(false);
        }
        public void OnPacket(byte[] data)
        {
            if (data.Length == 0)
            {
                return;
            }

            PACKET_TYPES type = Packet.GetType(data);

            if (type == PACKET_TYPES.LOBBY_INFO)
            {
                LobbyInfoPacket packet = Packet.Deserialize <LobbyInfoPacket>(data);
                if (packet.state == LobbyInfoPacket.State.LOBBY_CLOSED)
                {
                    RequestNewState(new Game(_serverConnection));
                }


                if (packet.state == LobbyInfoPacket.State.STARTING)
                {
                    _statusText.DisplayedString = "Game is starting in " + packet.countdown + " seconds!";
                }


                if (packet.state == LobbyInfoPacket.State.GAME_IN_PROGRESS)
                {
                    _statusText.DisplayedString = "Game is currently in progress, please wait.";
                }


                if (packet.state == LobbyInfoPacket.State.WAITING_FOR_PLAYERS)
                {
                    _statusText.DisplayedString = "Waiting for players...";
                }

                _playerCountText.DisplayedString = "Players in lobby: " + packet.playerCount;
            }
        }
示例#9
0
 public EpicVictoryRoyalePacket(int useless_but_required_because_this_is_a_struct_OwO)
 {
     packetType = PACKET_TYPES.EPIC_VICTORY_ROYALE;
 }
示例#10
0
 public PlayerDisconnectPacket(int id)
 {
     packetType = PACKET_TYPES.PLAYER_DISCONNECT;
     this.id    = id;
 }
示例#11
0
        public byte[] CreatePacket(string remoteHostIP, PACKET_TYPES type, string ViewerPassword, string jpegInfo)
        {
            if (remoteHostIP == null)
            {
                remoteHostIP = " ";
            }
            if (ViewerPassword == null)
            {
                ViewerPassword = "******";
            }

            try
            {
                byte[] bytes = null;

                switch (type)
                {
                case PACKET_TYPES.REQUEST_LIVE_VIEW:
                {
                    LIVE_VIEW_COMBINED_PACKET_STRUCT pkt = new LIVE_VIEW_COMBINED_PACKET_STRUCT();

                    pkt.InfoString         = jpegInfo;
                    pkt.header.PACKET_TYPE = (uint)type;
                    pkt.header.PACKET_LEN  = (uint)(Marshal.SizeOf(typeof(LIVE_VIEW_COMBINED_PACKET_STRUCT)) - Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT)));

                    pkt.header.SEQUENCE_NUMBER = (uint)m_OutBoundSequenceNumber++;

                    byte   seqNum  = (byte)(pkt.header.SEQUENCE_NUMBER & 0xff);
                    string seqNumS = seqNum.ToString();
                    pkt.header.PasswordHash    = EncyptGetHostPassword(ViewerPassword + "," + seqNumS);
                    pkt.header.START_OF_PACKET = 0xaa55aa55;



                    bytes = new byte[Marshal.SizeOf(typeof(LIVE_VIEW_COMBINED_PACKET_STRUCT))];

                    GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
                    Marshal.StructureToPtr(pkt, handle.AddrOfPinnedObject(), true);
                    handle.Free();
                }
                break;

                case PACKET_TYPES.REQUEST_HOST_NAME:
                {
                    REQUEST_HOST_NAME pkt = new REQUEST_HOST_NAME();


                    pkt.header.PACKET_TYPE     = (int)PACKET_TYPES.REQUEST_HOST_NAME;
                    pkt.header.PACKET_LEN      = (uint)0;
                    pkt.header.SEQUENCE_NUMBER = (uint)m_OutBoundSequenceNumber++;
                    byte   seqNum  = (byte)(pkt.header.SEQUENCE_NUMBER & 0xff);
                    string seqNumS = seqNum.ToString();
                    pkt.header.PasswordHash    = EncyptGetHostPassword(remoteHostIP + "," + seqNumS);
                    pkt.header.START_OF_PACKET = 0xaa55aa55;

                    bytes = new byte[Marshal.SizeOf(typeof(REQUEST_HOST_NAME))];

                    GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
                    Marshal.StructureToPtr(pkt, handle.AddrOfPinnedObject(), true);
                    handle.Free();
                }
                break;
                }
                return(bytes);
            }
            catch (Exception ex)
            {
                m_Log.Log("CreatePacket: " + ex.Message, ErrorLog.LOG_TYPE.INFORMATIONAL);
                return(null);
            }
        }
示例#12
0
        public byte[] CreatePacket(PACKET_TYPES type, string data)
        {
            try
            {
                byte[] hdrBytes = null;
                byte[] packet   = null;
                switch (type)
                {
                case PACKET_TYPES.REQUEST_CHECK_VIEWER_PASSWORD:
                case PACKET_TYPES.REQUEST_CHECK_ADMIN_PASSWORD:
                {
                    PACKET_HEADER_STRUCT hdr = new PACKET_HEADER_STRUCT();

                    hdr.PACKET_TYPE     = (uint)type;
                    hdr.PACKET_LEN      = (uint)0;
                    hdr.SEQUENCE_NUMBER = (uint)m_OutBoundSequenceNumber++;
                    hdrBytes            = new byte[Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT))];
                    string seqNumS = ((byte)hdr.SEQUENCE_NUMBER).ToString();
                    hdr.PasswordHash    = EncyptGetHostPassword(data + "," + seqNumS);
                    hdr.START_OF_PACKET = 0xaa55aa55;

                    packet = new byte[Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT))];

                    GCHandle handle = GCHandle.Alloc(packet, GCHandleType.Pinned);
                    Marshal.StructureToPtr(hdr, handle.AddrOfPinnedObject(), true);
                    handle.Free();
                }
                break;

                case PACKET_TYPES.SEND_HOST_NAME:
                case PACKET_TYPES.SEND_STATS:
                {
                    PACKET_HEADER_STRUCT hdr = new PACKET_HEADER_STRUCT();

                    hdr.PACKET_TYPE     = (uint)type;
                    hdr.PACKET_LEN      = (uint)data.Length;
                    hdr.SEQUENCE_NUMBER = (uint)m_OutBoundSequenceNumber++;
                    hdrBytes            = new byte[Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT))];
                    hdr.START_OF_PACKET = 0xaa55aa55;

                    GCHandle handle = GCHandle.Alloc(hdrBytes, GCHandleType.Pinned);
                    Marshal.StructureToPtr(hdr, handle.AddrOfPinnedObject(), true);
                    handle.Free();

                    if (data == null)
                    {
                        data = "0";
                    }

                    System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                    byte[] dataBytes = encoding.GetBytes(data);

                    packet = new byte[hdrBytes.Length + dataBytes.Length];


                    for (int i = 0; i < hdrBytes.Length; i++)
                    {
                        packet[i] = hdrBytes[i];
                    }
                    for (int i = hdrBytes.Length; i < hdrBytes.Length + dataBytes.Length; i++)
                    {
                        packet[i] = dataBytes[i - hdrBytes.Length];
                    }
                }
                break;

                case PACKET_TYPES.REPLY_INVALID_ADMIN_PASSWORD_ERROR:
                case PACKET_TYPES.REPLY_INVALID_VIEWER_PASSWORD_ERROR:
                case PACKET_TYPES.REPLY_INVALID_HOSTNAME_PASSWORD_ERROR:
                {
                    PACKET_HEADER_STRUCT hdr = new PACKET_HEADER_STRUCT();

                    hdr.PACKET_TYPE     = (uint)type;
                    hdr.PACKET_LEN      = (uint)data.Length;
                    hdr.SEQUENCE_NUMBER = (uint)m_OutBoundSequenceNumber++;
                    hdrBytes            = new byte[Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT))];
                    hdr.START_OF_PACKET = 0xaa55aa55;

                    GCHandle handle = GCHandle.Alloc(hdrBytes, GCHandleType.Pinned);
                    Marshal.StructureToPtr(hdr, handle.AddrOfPinnedObject(), true);

                    if (data == null)
                    {
                        data = "0";
                    }

                    System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                    byte[] dataBytes = encoding.GetBytes(data);

                    packet = new byte[hdrBytes.Length + dataBytes.Length];

                    for (int i = 0; i < hdrBytes.Length; i++)
                    {
                        packet[i] = hdrBytes[i];
                    }
                    for (int i = hdrBytes.Length; i < hdrBytes.Length + dataBytes.Length; i++)
                    {
                        packet[i] = dataBytes[i - hdrBytes.Length];
                    }
                }
                break;
                }
                return(packet);
            }
            catch (Exception ex)
            {
                m_Log.Log("CreatePacket: " + ex.Message, ErrorLog.LOG_TYPE.INFORMATIONAL);
                return(null);
            }
        }
示例#13
0
        public byte[] CreatePacket(string password, PACKET_TYPES type, string[] data)
        {
            try
            {
                byte[] hdrBytes = null;
                byte[] packet   = null;
                switch (type)
                {
                case PACKET_TYPES.REPLY_CHANNEL_LIST:
                {
                    // count the number of bytes needed for the payload

                    int count = 0;
                    foreach (string s in data)
                    {
                        count += (s.Length + 1);        // add one for the null terminator
                    }


                    // header
                    PACKET_HEADER_STRUCT hdr = new PACKET_HEADER_STRUCT();
                    hdr.PACKET_TYPE     = (uint)type;
                    hdr.PACKET_LEN      = (uint)count;
                    hdr.SEQUENCE_NUMBER = (uint)m_OutBoundSequenceNumber++;
                    hdrBytes            = new byte[Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT))];
                    string seqNumS = ((byte)hdr.SEQUENCE_NUMBER).ToString();
                    hdr.PasswordHash = EncyptGetHostPassword(password + "," + seqNumS);

                    hdr.START_OF_PACKET = 0xaa55aa55;

                    hdrBytes = new byte[hdrBytes.Length];

                    GCHandle handle = GCHandle.Alloc(hdrBytes, GCHandleType.Pinned);
                    Marshal.StructureToPtr(hdr, handle.AddrOfPinnedObject(), true);
                    handle.Free();



                    packet = new byte[hdrBytes.Length + count];

                    // now build the packet

                    int i   = 0;
                    int cnt = 0;
                    for (i = 0; i < hdrBytes.Length; i++)
                    {
                        packet[i] = hdrBytes[i];
                    }

                    foreach (string s in data)
                    {
                        System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                        byte[] dataBytes = encoding.GetBytes(s);

                        int end = s.Length + i;
                        cnt = 0;
                        for ( ; i < end; i++)
                        {
                            packet[i] = dataBytes[cnt];

                            cnt++;
                        }
                        packet[i++] = 0;        // null terminator for each string
                    }
                }
                break;
                }
                return(packet);
            }
            catch (Exception ex)
            {
                m_Log.Log("CreatePacket: " + ex.Message, ErrorLog.LOG_TYPE.INFORMATIONAL);
                return(null);
            }
        }
示例#14
0
        public byte[] CreatePacket(PACKET_TYPES type, byte[] data, string jpegInfo)
        {
            try
            {
                byte[] hdrBytes = null;
                byte[] packet   = null;
                switch (type)
                {
                case PACKET_TYPES.SEND_LIVE_VIEW:
                {
                    LIVE_VIEW_COMBINED_PACKET_STRUCT pkt = new LIVE_VIEW_COMBINED_PACKET_STRUCT();         // live view packet includes the common header

                    pkt.InfoString         = jpegInfo;
                    pkt.header.PACKET_TYPE = (uint)type;

                    pkt.header.START_OF_PACKET = 0xaa55aa55;

                    pkt.header.PACKET_LEN = (uint)(Marshal.SizeOf(typeof(LIVE_VIEW_COMBINED_PACKET_STRUCT)) - Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT))); // just the live view specific header bytes

                    pkt.JPEG_LENGTH = (uint)data.Length;                                                                                                     // the rest of the payload after the live view specific header bytes

                    //     pkt.header.PACKET_LEN = (uint)(data.Length + Marshal.SizeOf(typeof(LIVE_VIEW_PACKET)) - Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT)));

                    pkt.header.SEQUENCE_NUMBER = (uint)m_OutBoundSequenceNumber++;

                    byte   seqNum  = (byte)(pkt.header.SEQUENCE_NUMBER & 0xff);
                    string seqNumS = seqNum.ToString();
                    pkt.header.PasswordHash = " ";         // no outbound pw


                    // copy the combined headers  to the bytes array

                    hdrBytes = new byte[Marshal.SizeOf(typeof(LIVE_VIEW_COMBINED_PACKET_STRUCT))];

                    GCHandle handle = GCHandle.Alloc(hdrBytes, GCHandleType.Pinned);
                    Marshal.StructureToPtr(pkt, handle.AddrOfPinnedObject(), true);
                    handle.Free();

                    packet = new byte[hdrBytes.Length + data.Length];

                    int i = 0;
                    for (i = 0; i < hdrBytes.Length; i++)
                    {
                        packet[i] = hdrBytes[i];
                    }

                    for (i = hdrBytes.Length; i < hdrBytes.Length + data.Length; i++)
                    {
                        packet[i] = data[i - hdrBytes.Length];
                    }
                }
                break;
                }
                return(packet);
            }
            catch (Exception ex)
            {
                m_Log.Log("CreatePacket: " + ex.Message, ErrorLog.LOG_TYPE.INFORMATIONAL);
                return(null);
            }
        }
示例#15
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);
            }
        }