Exemplo n.º 1
0
        public IniBan(string path)
        {
            _filePath = path;
            Bans = new List<WTuple<string, string>>();

            if (!File.Exists(path))
            {
                _file = new DataFile();
                _file.Sections.Add(new Section("bans"));
                return;
            }

            _file = new DataFile(path);

            foreach (var set in _file.GetSettings("bans"))
            {
                Bans.Add(
                    new WTuple<string, string>(
                        set.Name,
                        String.Join(", ",set)
                        )
                        );
            }
        }
Exemplo n.º 2
0
        public string IsAdmin(string accID)
        {
            var path = Path.Combine(_db.AccPath, accID);
            if (!File.Exists(path + @"/flhookadmin.ini")) return "";
            var tmp = new DataFile(path + @"/flhookadmin.ini");

            return tmp.GetSetting("admin", "rights")[0];
        }
Exemplo n.º 3
0
        static void _bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            var flIni = (DataFile)((object[]) e.Argument)[0];
            var flPath = (string)((object[])e.Argument)[1];
            // Load the string dlls.
            LoadLibrary(flPath + @"\EXE\" + @"resources.dll");

            foreach (var flResName in flIni.GetSettings("Resources", "DLL"))
                LoadLibrary(flPath + @"\EXE\" + flResName[0]);

            //Scan INIs and bases
            //TODO there's only one universe entry, so do we need foreach universe?
            foreach (var entry in flIni.GetSettings("Data", "universe"))
            {
                //TODO: halt backgroundworker if needed

                var universeIni = new DataFile(_flDataPath + @"\" + entry[0]);

                //Load bases
                foreach (var baseSection in universeIni.GetSections("Base"))
                {

                    LoadBase(baseSection);
                }

                //Load systems
                foreach (var sysSection in universeIni.GetSections("system"))
                {
                    LoadSystem(sysSection);
                }
            }

            foreach (var entry in flIni.GetSettings("Data", "equipment"))
            {
                var equipFile = new DataFile(_flDataPath + @"\" + entry[0]);

                foreach (var eqSection in equipFile.Sections)
                {
                    LoadEquipSection(eqSection);
                }
            }

            foreach (var entry in flIni.GetSettings("Data", "groups"))
            {
                var facFile = new DataFile(_flDataPath + @"\" + entry[0]);

                foreach (var faSection in facFile.GetSections("Group"))
                {
                    LoadFaction(faSection);
                }
            }

            foreach (var entry in flIni.GetSettings("Data", "ships"))
            {
                var shFile = new DataFile(_flDataPath + @"\" + entry[0]);

                foreach (var shSection in shFile.GetSections("Ship"))
                {
                    LoadShip(shSection);
                }
            }

            _log.NewMessage(LogType.Debug, "Universe: Parsing loadouts...");
            var loFile = new DataFile(_flDataPath + @"\equipment\goods.ini");

            foreach (var loSection in loFile.GetSections("Good").Where(w => w.GetFirstOf("category")[0] == "ship"))
            {
                LoadLoadout(loSection, loFile);
            }

            if (!Properties.Settings.Default.FLDataUseCache) return;

            _log.NewMessage(LogType.Info, "Universe: Saving game cache...");
            Gis.WriteXml(flPath + @"/FLSAM_Data.xml");
            _log.NewMessage(LogType.Info, "Universe: Game cache saved.");
        }
Exemplo n.º 4
0
        private static void LoadSystem(Section sec)
        {
            var sysNick = sec.GetFirstOf("nickname")[0].ToLowerInvariant();
            _log.NewMessage(LogType.Garbage, "Universe: Parsing system {0}", sysNick);

            var stIDSName = GetIDSParm(sec.GetAnySetting("strid_name")[0]);

            var stIDSInfo1 = "";
            if (sec.ContainsAnyOf("ids_info1","ids_short_name"))
                stIDSInfo1 = GetIDSParm(sec.GetAnySetting("ids_info")[0]);

            Gis.Systems.AddSystemsRow(sysNick, stIDSName,stIDSInfo1);

            //string file = Directory.GetParent(ini.filePath).FullName + "\\" + section.GetSetting("file").Str(0);
            //TODO: Warning, hardcoded system path! :S
            var sysFile = new DataFile(_flDataPath + @"\Universe\" + sec.GetFirstOf("file")[0]);

            foreach (var obj in sysFile.GetSections("Object"))
            {
                Setting curset;
                //string pos;
                var idsInfo = "";
                var idsInfo1 = "";

                //TODO: do we need pos?
                //if (obj.TryGetFirstOf("pos", out curset))
                //    pos = string.Join(", ", curset);

                //get infocard for the object
                if (obj.TryGetFirstOf("ids_info", out curset))
                {
                    uint id;
                    if (!uint.TryParse(curset[0], out id))
                    {
                        _log.NewMessage(LogType.Warning, "Can't find ID for object: {0}", curset[0]);
                    }

                    idsInfo = GetIDString(id);
                    if (InfocardMap.ContainsKey(id))
                        idsInfo1 = GetIDString(InfocardMap[id]);
                }

                //add the icard to the base if object is base
                if (obj.TryGetFirstOf("base", out curset))
                    //TODO: really join the stuff, infos are in XML format.
                    Gis.Bases.FindByNickname(curset[0]).Infocard = idsInfo + idsInfo1;

            }

            //TODO: zones needed?
        }
Exemplo n.º 5
0
        private static void LoadLoadout(Section sec, DataFile file)
        {
            //if (sec.GetFirstOf("category")[0] != "ship") return;
            //done in LINQ
            var hullNickName = sec.GetFirstOf("hull")[0];

            //TODO: foreach or FirstOrDefault?
            var shSection = file.GetSections("Good").FirstOrDefault(w =>
                (w.GetFirstOf("category")[0] == "shiphull") &
                (w.GetFirstOf("nickname")[0] == hullNickName)
                );

            if (shSection == null)
            {
                _log.NewMessage(LogType.Warning, "Can't find package for shiphull {0}!", hullNickName);
                return;
            }

                var shipNickname = shSection.GetFirstOf("ship")[0];
                var shiphash = CreateID(shipNickname);

                uint defaultSound = 0;
                uint defaultPowerPlant = 0;
                uint defaultEngine = 0;

                foreach (var set in sec.GetSettings("addon"))
                {
                    if (set.Count != 3)
                    {
                        _log.NewMessage(LogType.Warning,
                            "Package for ship {0}: addon {1} has wrong arg count", shipNickname, set[0]);
                        continue;
                    }

                    var equipNick = set[0];
                    var item = Gis.Equipment.FindByHash(CreateID(equipNick));
                    if (item == null)
                    {
                        _log.NewMessage(LogType.Warning, @"Can't find {0} in DB: from loadout {1} \ {2}", equipNick,
                            hullNickName, shipNickname);
                        continue;
                    }

                    EquipTypes eqType;
                    Enum.TryParse(item.Type, out eqType);

                    switch (eqType)
                    {
                        case EquipTypes.Engine:
                            defaultEngine = item.Hash;
                            break;
                        case EquipTypes.Powerplant:
                            defaultPowerPlant = item.Hash;
                            break;
                        case EquipTypes.InternalFX:
                            defaultSound = item.Hash;
                            break;
                            case EquipTypes.Light:
                            if (set[1] == "internal")
                                _log.NewMessage(LogType.Warning, "Invalid hardpoint for light {0} (internal): {1}", equipNick, hullNickName);
                            break;
                        case EquipTypes.AttachedFX:
                             if (set[1] == "internal")
                                 _log.NewMessage(LogType.Warning, "Invalid hardpoint for attachedFX {0} (internal): {1}", equipNick, hullNickName);
                            break;
                    }

                }
                Gis.ShipDefaultInternals.AddShipDefaultInternalsRow(Gis.Ships.FindByHash(shiphash), defaultEngine,
                    defaultSound, defaultPowerPlant);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initiates the Universe DB. FLPath is the path to the Freelancer directory, not DATA\EXE etc.
        /// </summary>
        /// <param name="flPath"></param>
        /// <param name="log"></param>
        /// <param name="forceScan"></param>
        public static bool Parse(string flPath, LogDispatcher.LogDispatcher log, bool forceScan = false)
        {
            IsAttached = false;
            _log = log;
            Gis.Clear();
            if (flPath == "")
            {
                _log.NewMessage(LogType.Error, "Universe: Got empty FLPath!");
                if (DoneLoading != null)
                    DoneLoading(null, null);
                return false;
            }

            if (StartedLoading != null)
                StartedLoading(null, null);

            _log.NewMessage(LogType.Debug, "Universe: Parsing file {0} ...", flPath + @"\DataMaps.ini");
            if (!File.Exists(flPath + @"\DataMaps.ini"))
            {
                log.NewMessage(LogType.Error, "Universe: Can't find DataMaps.ini!");
                if (DoneLoading != null)
                    DoneLoading(null, null);
                return false;
            }
            var dMapIni = new DataFile(flPath + @"\DataMaps.ini");

            HpMap.Clear();
            foreach (var set in dMapIni.GetSettings("HPMap", "map"))
            {
                EquipTypes eqType;
                if (!Enum.TryParse(set[1], out eqType))
                {
                    log.NewMessage(LogType.Error, "Can't parse equipment type in DataMaps.ini: {0} {1}", set[0], set[1]);
                    continue;
                }
                HpMap.Add(set[0], eqType);
            }

            log.NewMessage(LogType.Debug, "Parsing file {0} ...", flPath + @"\EXE\Freelancer.ini");
            if (!File.Exists(flPath + @"\EXE\Freelancer.ini"))
            {
                log.NewMessage(LogType.Error, "Universe: Can't find Freelancer.ini!");
                if (DoneLoading != null)
                    DoneLoading(null, null);
                return false;
            }
            var flIni = new DataFile(flPath + @"\EXE\Freelancer.ini");
            _flDataPath = Path.GetFullPath(Path.Combine(flPath + @"\EXE", flIni.GetSetting("Freelancer", "data path")[0]));

            // Load the infocard map
            var ini = new DataFile(_flDataPath + @"\interface\infocardmap.ini");
            foreach (var set in ini.Sections.SelectMany(section => section.Settings))
            {
                uint map0, map1;
                if (!uint.TryParse(set[0], out map0) || !uint.TryParse(set[1], out map1))
                {
                    log.NewMessage(LogType.Error, "Can't parse infocard map: {0}", set.String());
                    continue;
                }

                //throw new Exception("Can't parse infocard map: " + set.String());
                InfocardMap[map0] = map1;
            }

            if (Properties.Settings.Default.FLDataUseCache & !forceScan)
            {
                if (File.Exists(flPath + @"/FLSAM_Data.xml"))
                {
                    _log.NewMessage(LogType.Info, "Universe: Loading game cache...");
                    Gis.ReadXml(flPath + @"/FLSAM_Data.xml");
                    IsAttached = true;
                    if (DoneLoading != null)
                        DoneLoading(null, null);

                    _log.NewMessage(LogType.Info, "Universe: Game cache loaded.");
                    return true;
                }
            }

            var bgw = new BackgroundWorker();
            bgw.DoWork += _bgw_DoWork;
            bgw.RunWorkerCompleted += _bgw_RunWorkerCompleted;
            bgw.RunWorkerAsync(new object[] { flIni,flPath});

            return true;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Returns a Player object associated with the charfile.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="log"></param>
        /// <returns></returns>
        public static Character GetAccount(string path,LogDispatcher.LogDispatcher log)
        {
            if (!File.Exists(path)) return null;
            var flFile = new DataFile(path);
            var player = new Character
            {
                Created = System.IO.File.GetCreationTime(path)
            };

            foreach (var set in flFile.GetFirstOf("Player").Settings)
                {
                    switch (set.Name)
                    {
                        case "money":
                            player.Money = uint.Parse(set[0]);
                            break;
                        case "name":
                            var name = "";
                            while (set[0].Length > 0)
                             {
                                 name += (char)Convert.ToUInt16(set[0].Substring(0, 4), 16);
                                 set[0] = set[0].Remove(0, 4);
                             }
                            player.Name = name;
                            break;
                        case "rank":
                            player.Rank = byte.Parse(set[0]);
                            break;
                        case "house":
                            player.Reputation.Add(
                                new ReputationItem(set[1],
                                    float.Parse(set[0], Nfi))
                                );
                            break;
                        case "description":
                            break;
                        case "tstamp":
                            long high = uint.Parse(set[0]);
                            long low = uint.Parse(set[1]);
                            player.LastOnline = DateTime.FromFileTimeUtc(high << 32 | low);
                            break;
                        case "rep_group":
                            player.ReputationIFF = set[0];
                            break;
                        case "system":
                            player.System = set[0];
                            break;
                        case "base":
                            player.Base = set[0];
                            break;
                        case "ship_archetype":
                            uint res;
                        if (uint.TryParse(set[0], out res))
                        {
                            player.ShipArch = res;
                            break;
                        }

                        if (Logger.LogDisp != null)
                            Logger.LogDisp.NewMessage(LogType.Warning, "Garbage shiparch: " + set[0] + " for " + flFile.Path);
                            return null;
                        case "base_hull_status":
                            player.Health = float.Parse(set[0], Nfi);
                            break;
                        case "equip":
                            player.EquipmentList.Add(
                                new Tuple<uint, string, float>(
                                    uint.Parse(set[0]),
                                    set[1],
                                    float.Parse(set[2], Nfi)
                                    )
                                    );
                            break;
                        case "cargo":
                            if (set[1].StartsWith("-"))
                                log.NewMessage(LogType.Error,"Player {0} bad setting: {1}",player.Name,set.String());
                            else
                                player.Cargo.Add(new WTuple<uint, uint>(uint.Parse(set[0]), uint.Parse(set[1])));
                            break;
                        case "last_base":
                            player.LastBase = set[0];
                            break;
                            //TODO: voice, com_body etc
                        case "pos":
                            player.Position = new[]
                            {
                                float.Parse(set[0],Nfi),
                                float.Parse(set[1],Nfi),
                                float.Parse(set[2],Nfi)
                            };
                            break;
                        case "rotate":
                            player.Rotation = new[]
                            {
                                float.Parse(set[0],Nfi),
                                float.Parse(set[1],Nfi),
                                float.Parse(set[2],Nfi)
                            };
                            break;
                        case "visit":
                            player.Visits.Add(uint.Parse(set[0]),byte.Parse(set[1]));
                            break;

                    }

            }

            foreach (var set in flFile.GetFirstOf("mPlayer").Settings)
            {
                switch (set.Name)
                {
                    case "sys_visited":
                        player.VisitedSystems.Add(uint.Parse(set[0]));
                        break;
                    case "base_visited":
                        player.VisitedBases.Add(uint.Parse(set[0]));
                        break;
                    case "total_time_played":
                        player.OnlineTime = Convert.ToUInt32(float.Parse(set[0], Nfi));
                        break;
                }
            }

            player.AccountID = path.Substring(path.Length - 26, 11);
            player.CharID = path.Substring(path.Length - 14, 11);
            player.CharPath = path.Substring(path.Length - 26, 23);

            return player;
        }
Exemplo n.º 8
0
        public static bool SaveCharacter(Character ch, string path)
        {
            var oldFile = new DataFile(path);
            var newFile = new DataFile();
            newFile.Sections.Add(new Section("Player"));
            var pSect = newFile.GetFirstOf("Player");

            pSect.Settings.Add(new Setting("description")
            {
                oldFile.GetSetting("Player", "description")[0]
            });

            pSect.Settings.Add(new Setting("tstamp")
            {
                ((ch.LastOnline.ToFileTime() >> 32) & 0xFFFFFFFF).ToString(CultureInfo.InvariantCulture),
                (ch.LastOnline.ToFileTime() & 0xFFFFFFFF).ToString(CultureInfo.InvariantCulture)
            });
            //TODO: name
            pSect.Settings.Add(oldFile.GetSetting("Player","name"));

            pSect.Settings.Add(new Setting("rank")
            {
                ch.Rank.ToString(CultureInfo.InvariantCulture)
            });

            foreach (var set in ch.Reputation.Select(rep => new Setting("house")
            {
                String.Format(Nfi, "{0:0.000;-0.000}", rep.Value),
                rep.Nickname
            }))
            {
                pSect.Settings.Add(set);
            }

            pSect.Settings.Add(new Setting("rep_group")
            {
                ch.ReputationIFF
            });

            pSect.Settings.Add(new Setting("money")
            {
                ch.Money.ToString(CultureInfo.InvariantCulture)
            });

            pSect.Settings.Add(oldFile.GetSetting("Player","num_kills"));
            pSect.Settings.Add(oldFile.GetSetting("Player", "num_misn_successes"));
            pSect.Settings.Add(oldFile.GetSetting("Player", "num_misn_failures"));

            pSect.Settings.Add(oldFile.GetSetting("Player", "voice"));
            pSect.Settings.Add(oldFile.GetSetting("Player", "com_body"));
            pSect.Settings.Add(oldFile.GetSetting("Player", "com_head"));
            pSect.Settings.Add(oldFile.GetSetting("Player", "com_lefthand"));
            pSect.Settings.Add(oldFile.GetSetting("Player", "com_righthand"));

            pSect.Settings.Add(oldFile.GetSetting("Player", "body"));
            pSect.Settings.Add(oldFile.GetSetting("Player", "head"));
            pSect.Settings.Add(oldFile.GetSetting("Player", "lefthand"));
            pSect.Settings.Add(oldFile.GetSetting("Player", "righthand"));

            //TODO: position if in space
            pSect.Settings.Add(new Setting("system")
            {
                ch.System
            });

            if (ch.Base != null)
                pSect.Settings.Add(new Setting("base")
                {
                    ch.Base
                });
            else
            {
                //in space
                pSect.Settings.Add(new Setting("pos")
                {
                    String.Format(Nfi,"{0:0.0}",ch.Position[0]),
                    String.Format(Nfi,"{0:0.0}",ch.Position[1]),
                    String.Format(Nfi,"{0:0.0}",ch.Position[2])
                });

                pSect.Settings.Add(new Setting("rotate")
                {
                    "0","0","0"
                });

            }

            pSect.Settings.Add(new Setting("ship_archetype")
            {
                ch.ShipArch.ToString(CultureInfo.InvariantCulture)
            });

            foreach (var eq in ch.EquipmentList)
            {
                pSect.Settings.Add(new Setting("equip")
            {
                eq.Item1.ToString(CultureInfo.InvariantCulture),eq.Item2,String.Format(Nfi, "{0:0.00}", eq.Item3)
            });

            }

            foreach (var cg in ch.Cargo.Where(cg => !((cg.Item1 == 0) | (cg.Item2 == 0))))
            {
                pSect.Settings.Add(new Setting("cargo")
                {
                    cg.Item1.ToString(CultureInfo.InvariantCulture),
                    cg.Item2.ToString(CultureInfo.InvariantCulture),
                    "",
                    "",
                    "0"
                });
            }

            pSect.Settings.Add(new Setting("last_base")
            {
                ch.LastBase
            });

            // base_hull_status

            pSect.Settings.Add(new Setting("base_hull_status")
            {
                String.Format(Nfi, "{0:0.00}", ch.Health)
            });

            //todo: base_collision_group

            foreach (var eq in ch.EquipmentList)
            {
                pSect.Settings.Add(new Setting("base_equip")
            {
                eq.Item1.ToString(CultureInfo.InvariantCulture),eq.Item2,String.Format(Nfi, "{0:0.00}", eq.Item3)
            });

            }

            foreach (var cg in ch.Cargo.Where(cg => !((cg.Item1 == 0) | (cg.Item2 == 0))))
            {
                pSect.Settings.Add(new Setting("base_cargo")
            {
                cg.Item1.ToString(CultureInfo.InvariantCulture),
                cg.Item2.ToString(CultureInfo.InvariantCulture),
                "",
                "",
                "0"
            });

            }

            pSect.Settings.AddRange(oldFile.GetSettings("Player", "wg"));

            foreach (var visit in ch.Visits)
            {
                pSect.Settings.Add(new Setting("visit")
            {
                visit.Key.ToString(CultureInfo.InvariantCulture),
                visit.Value.ToString(CultureInfo.InvariantCulture)
            });
            }

            pSect.Settings.Add(oldFile.GetSetting("Player","interface"));

            //todo: mPlayer, flhook
            newFile.Sections.Add(oldFile.GetFirstOf("mPlayer"));
            newFile.Sections.Add(oldFile.GetFirstOf("flhook"));

            newFile.Save(path);
            Logger.LogDisp.NewMessage(LogType.Info, "Saved profile {0}: {1}", ch.Name, path);
            return true;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Returns a Player object associated with the charfile.
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static Metadata GetMeta(string path)
        {
            var flFile = new DataFile(path);
            var player = new Metadata
            {
                LastOnline = DateTime.Now
            };

            //_equipList.Clear()
            var equipList = new StringBuilder();
            foreach (var set in flFile.GetFirstOf("Player").Settings)
            {
                switch (set.Name)
                {
                    case "money":
                        player.Money = uint.Parse(set[0]);
                        break;
                    case "name":
                        var name = "";
                        while (set[0].Length > 0)
                        {
                            name += (char)Convert.ToUInt16(set[0].Substring(0, 4), 16);
                            set[0] = set[0].Remove(0, 4);
                        }
                        player.Name = name;
                        break;
                    case "rank":
                        player.Rank = byte.Parse(set[0]);
                        break;
                    case "system":
                        player.System = set[0];
                        break;
                    case "base":
                        player.Base = set[0];
                        break;
                    case "ship_archetype":
                        uint res;
                        if (uint.TryParse(set[0], out res))
                        {
                            player.ShipArch = res;
                            break;
                        }
                        if (Logger.LogDisp != null)
                            Logger.LogDisp.NewMessage(LogType.Warning, "Garbage shiparch: " + set[0] + " for " + flFile.Path);

                        return null;

                        //break;
                    case "equip":
                        equipList.Append(" ");
                        equipList.Append(set[0]);
                        break;
                    case "tstamp":
                        long high = uint.Parse(set[0]);
                        long low = uint.Parse(set[1]);
                        player.LastOnline = DateTime.FromFileTimeUtc(high << 32 | low);
                        break;
                }

            }

            player.CharID = path.Substring(path.Length - 14, 11);
            player.CharPath = path.Substring(path.Length - 26, 23);
            player.Equipment = equipList.ToString();
            return player;
        }