Esempio n. 1
0
        public static Packet ChangePacketClass(Packet pak, float newVersion)
        {
            LogPacketData packetData = GetPacketData(newVersion, pak.Code, pak.Direction);

            if (packetData != null && pak.GetType().Equals(packetData.Type))
            {
                pak.Attribute = packetData.Attribute;
                return(pak);
            }

            Packet newPacket = CreatePacket(packetData, (int)pak.Length);

            newPacket.CopyFrom(pak);
            return(newPacket);
        }
Esempio n. 2
0
        public static string GetPacketDescription(float version, int code, ePacketDirection dir)
        {
            SortedList packets =
                dir == ePacketDirection.ClientToServer
                                        ? m_ctosConstrsByCode[code]
                                        : m_stocConstrsByCode[code];

            LogPacketData c = (LogPacketData)packets[version];

            if (c == null)
            {
                return(null);
            }
            return(c.Attribute.Description);
        }
Esempio n. 3
0
        private static Packet CreatePacket(LogPacketData packetData, int capacity)
        {
            if (packetData == null)
            {
                return(new Packet(capacity));
            }

            try
            {
                Packet pak = (Packet)packetData.CapacityConstructor.Invoke(new object[] { capacity });
                pak.Attribute = packetData.Attribute;
                return(pak);
            }
            catch (Exception)
            {
                return(new Packet(capacity));
            }
        }
Esempio n. 4
0
        private static LogPacketData GetPacketData(float version, byte code, ePacketDirection dir)
        {
            SortedList typesByVersion =
                dir == ePacketDirection.ClientToServer
                                        ? m_ctosConstrsByCode[code]
                                        : m_stocConstrsByCode[code];

            LogPacketData packetData = null;

            foreach (DictionaryEntry entry in typesByVersion)
            {
                float ver = (float)entry.Key;
                if (ver > version)
                {
                    break;
                }
                packetData = (LogPacketData)entry.Value;
            }
            return(packetData);
        }
Esempio n. 5
0
        public static void Save()
        {
            if (File.Exists(FilePath))
            {
                File.Delete(FilePath);
            }

            using (var writer = new XmlTextWriter(FilePath, Encoding.UTF8))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("Settings");

                writer.WriteElementString(AllowConnectionsFromOtherMachinesKey, AllowConnectionsFromOtherMachines.ToString());
                writer.WriteElementString(SendFastestLapToServerKey, SendFastestLapToServer.ToString());
                writer.WriteElementString(APIKeyKey, APIKey);
                writer.WriteElementString(LogPacketDataKey, LogPacketData.ToString());

                writer.WriteEndElement();
                writer.WriteEndDocument();

                writer.Flush();
            }
        }
Esempio n. 6
0
        public static Packet CreatePacket(float version, byte code, ePacketDirection dir, int capacity)
        {
            LogPacketData packetData = GetPacketData(version, code, dir);

            return(CreatePacket(packetData, capacity));
        }
        private static Packet CreatePacket(LogPacketData packetData, int capacity)
        {
            if (packetData == null)
                return new Packet(capacity);

            try
            {
                Packet pak = (Packet)packetData.CapacityConstructor.Invoke(new object[] {capacity});
                pak.Attribute = packetData.Attribute;
                return pak;
            }
            catch(Exception)
            {
                return new Packet(capacity);
            }
        }