Ejemplo n.º 1
0
        //Gets a packet from the client, passes it onto whatever function is registered to handle whatever type of packet it is
        public static void HandlePacket(int ClientID, byte[] PacketData)
        {
            ByteBuffer.ByteBuffer PacketReader = new ByteBuffer.ByteBuffer(); //start the packet reader
            PacketReader.WriteBytes(PacketData);                              //fill it with the data from the packet that was sent to us
            int PacketType = PacketReader.ReadInteger();                      //find out what type of packet this is

            //Ignore empty packets
            if (PacketType == 0)
            {
                return;
            }
            //Invoke whatever function has been registered to this packet type in our dictionary
            Packet NetworkPacket;

            if (Packets.TryGetValue(PacketType, out NetworkPacket))
            {
                NetworkPacket.Invoke(ClientID, PacketData);
            }
        }