Beispiel #1
0
        public void HandlePacket(PacketServer.Packet packet)
        {
            Console.WriteLine("[MATRIX] " + packet.RemoteEndpoint.ToString() + " sent " + packet.PacketData.Length.ToString() + " bytes.");

            var matrixPkt = Utils.ReadStruct <MatrixPacketBase>(packet.PacketData);

            switch (matrixPkt?.Type)
            {
            case 0x454B4F50:                // POKE
                var poke = Utils.ReadStruct <MatrixPacketPoke>(packet.PacketData);
                if (poke == null)
                {
                    return;
                }
                Console.WriteLine("[POKE]");
                Parent.Send(new MatrixPacketHehe(0, GenerateSocketID()), packet.RemoteEndpoint);
                break;

            case 0x5353494B:                // KISS
                var kiss = Utils.ReadStruct <MatrixPacketKiss>(packet.PacketData);
                if (kiss == null)
                {
                    return;
                }
                Console.WriteLine("[KISS]");
                Parent.Send(new MatrixPacketHugg(0, 25001, 1), packet.RemoteEndpoint);
                break;

            case 0x53524241:                // ABRT
                var abrt = Utils.ReadStruct <MatrixPacketAbrt>(packet.PacketData);
                if (abrt == null)
                {
                    return;
                }
                Console.WriteLine("[ABRT]");
                break;

            default:
                Console.WriteLine("Unknown Matrix Packet Type: " + matrixPkt?.Type.ToString());
                return;
            }
        }
Beispiel #2
0
        public void HandlePacket(PacketServer.Packet packet)
        {
            Console.WriteLine("[GAME] " + packet.RemoteEndpoint.ToString() + " sent " + packet.PacketData.Length.ToString() + " bytes.");

            int packetSize = 0;
            var gamePkt    = Utils.ReadStruct <GamePacketBase>(packet.PacketData, ref packetSize);

            if (gamePkt == null)
            {
                return;
            }

            // TODO: Handle split and/or out of order packets
            if (packet.PacketData.Length < packetSize + gamePkt?.PacketHeader.Length)
            {
                return;
            }

            var dataMem = packet.PacketData.Slice(packetSize, (int)gamePkt?.PacketHeader.Length);

            packetSize += (int)gamePkt?.PacketHeader.Length;

            Console.WriteLine("[GAME] " + packetSize.ToString() + " bytes");
        }