Пример #1
0
        public static uiTables.ShipEquipDataTable GetTable(Character curCharacter,LogDispatcher.LogDispatcher log)
        {
            var eqList = new uiTables.ShipEquipDataTable();

            var shipHP = Universe.Gis.Ships.FindByHash(curCharacter.ShipArch);
            if (shipHP != null)
                foreach (var hp in shipHP.GetHardpointsRows())
                {
                    eqList.AddShipEquipRow(hp.Name, hp.EquipType, "",hp.HPType);
                }

            foreach (var equip in curCharacter.EquipmentList)
            {
                var eq = Universe.Gis.Equipment.FindByHash(equip.Item1);
                string eqNick;
                var eqType = "";
                if (eq == null)
                {
                    eqNick = equip.Item1.ToString(CultureInfo.InvariantCulture);
                    if (!Universe.IsAttached)
                        log.NewMessage(LogType.Warning, "Equip {0} not found while reading character {1}!", equip.Item1,
                            curCharacter.Name);
                }
                else
                {
                    eqNick = eq.Nickname;
                    eqType = eq.Type;
                }

                //ID,HP,health

                //internal HP
                if (equip.Item2 == "")
                {
                    eqList.AddShipEquipRow("", eqType, eqNick, "");
                    continue;
                }

                var firstOrDefault = eqList.FirstOrDefault(w => w.HPName == equip.Item2);
                if (firstOrDefault != null)
                    firstOrDefault[2] = eqNick;
                else
                {
                    eqList.AddShipEquipRow(equip.Item2, eqType, eqNick, "");
                }
            }

            return eqList;
        }
Пример #2
0
        public CharLocation(Character ch)
        {
            InitializeComponent();
            systemsBindingSource.DataSource = Universe.Gis.Systems;
            basesBindingSource.DataSource = Universe.Gis.Bases;

            Char = ch;
            textNick.Text = Char.Name;
            comboSystem.SelectedValue = ch.System;

            var formheight = Height - ClientSize.Height;
            Height = groupBox1.Height + groupDocked.Height + formheight;

            if (ch.Base != null) return;
            checkSpace.Checked = true;
            numX.Value = (decimal)ch.Position[0];
            numY.Value = (decimal)ch.Position[1];
            numZ.Value = (decimal)ch.Position[2];
        }
Пример #3
0
 private void AddMetadata(Character md, string accountID)
 {
     using (var comm = new SQLiteCommand(InsertText, _db.Queue.Conn))
     {
         comm.Parameters.AddWithValue("@CharPath", md.CharPath);
         comm.Parameters.AddWithValue("@CharName", md.Name);
         comm.Parameters.AddWithValue("@AccID", accountID);
         comm.Parameters.AddWithValue("@CharCode", md.CharID);
         comm.Parameters.AddWithValue("@Money", md.Money);
         comm.Parameters.AddWithValue("@Rank", md.Rank);
         comm.Parameters.AddWithValue("@Ship", md.ShipArch);
         comm.Parameters.AddWithValue("@Location", md.System);
         comm.Parameters.AddWithValue("@Base", md.Base);
         comm.Parameters.AddWithValue("@Equipment", md.Equipment);
         comm.Parameters.AddWithValue("@Created", DateTime.Now);
         comm.Parameters.AddWithValue("@LastOnline", md.LastOnline);
         comm.Parameters.AddWithValue("@OnLineTime", md.OnlineTime);
         comm.Parameters.AddWithValue("@IsAdmin", md.AdminRights != "");
         comm.Parameters.AddWithValue("@IsBanned", md.IsBanned);
         if (_db.Queue != null)
             _db.Queue.Execute(comm);
     }
 }
Пример #4
0
        /// <summary>
        /// Handles account checking.
        /// </summary>
        /// <param name="ch"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        static Character Scan_AccountScanned(Character ch, System.ComponentModel.CancelEventArgs e)
        {
            //nothing to scan against
            if (!Universe.IsAttached)
            {
                e.Cancel = true;
                return ch;
            }

            //indicates if character was altered in any way
            var changedAcc = false;

            //get the ship of character
            var shipdata = Universe.Gis.Ships.FindByHash(
                ch.ShipArch
                );

            if (shipdata == null)
            {
                _log.NewMessage(LogType.Warning, "Unknown shiparch: {0} for {1}",
                    ch.ShipArch,
                ch.Name);
                e.Cancel = true;
                //TODO: add to non-parsed charlist
                return ch;
            }

            //var acc = meta.GetCharacter(Properties.Settings.Default.FLDBPath,_log);
            var defaults = shipdata.GetShipDefaultInternalsRows();

            //probably shouldn't fire at all in stable mod builds
            if (defaults.Length == 0)
            {
                _log.NewMessage(LogType.Error,"No default loadout for {0} {1} ({2})",ch.Name,shipdata.Nickname,shipdata.Name);
                return ch;
            }

            var hpData = Universe.Gis.Ships.FindByHash(ch.ShipArch).GetHardpointsRows();

            if (hpData == null)
            {
                _log.NewMessage(LogType.Error, "No hardpoint data for {0} {1} ({2})", ch.Name, shipdata.Nickname, shipdata.Name);
                return ch;
            }

            var foundEngine = false;
            var foundPower = false;
            Tuple<uint, string, float> powerToReplace = null;
            var equipToRemove = new List<Tuple<uint, string, float>>();

            foreach (var equip in ch.EquipmentList)
            {
                var eqItem = Universe.Gis.Equipment.FindByHash(equip.Item1);

                if (eqItem == null)
                {
                    _log.NewMessage(LogType.Error, "Unknown equipment: {0} {1} on {2}", ch.Name, equip.Item1, equip.Item2);
                    continue;
                }

                if (eqItem.Type == EquipTypes.Engine.ToString())
                {
                    //remove engine on standard hardpoint if
                    if (equip.Item2 == "")
                        if (hpData.FirstOrDefault(w => w.HPType == EquipTypes.Engine.ToString()) != null)
                        {
                            equipToRemove.Add(equip);
                            continue;
                        }
                    foundEngine = true;
                }
                else if (eqItem.Type == EquipTypes.Powerplant.ToString())
                {
                    foundPower = true;
                    if (eqItem.Hash != defaults[0].DPower)
                    {
                        _log.NewMessage(LogType.Warning,
                        "Non-standard powerplant for {0}: {1}, should be {2}",
                        ch.Name,
                        eqItem.Nickname,
                        Universe.Gis.Equipment.FindByHash(defaults[0].DPower).Nickname
                        );
                        if (Properties.Settings.Default.FLDBGoForDefaultPPlant)
                            powerToReplace = equip;

                    }
                }

                if (!Properties.Settings.Default.FLDBCheckIncompatibleHardpoints) continue;

                if (equip.Item2 == "") continue;
                var firstOrDefault = hpData.FirstOrDefault(row => row.Name == equip.Item2);
                if (firstOrDefault == null) continue;
                if (firstOrDefault.HPType.Contains(eqItem.Hardpoint)) continue;

                //Unmount incompatible equip
                equipToRemove.Add(equip);
                _log.NewMessage(LogType.Info, "Unmounting {0} on {1} ({2}), ship {3} ({4})...",eqItem.Nickname,equip.Item2,ch.Name,shipdata.Nickname,shipdata.Name);
                ch.Cargo.Add(new WTuple<uint, uint>(equip.Item1,1));
                changedAcc = true;
            }

            if (!foundEngine)
            {
                _log.NewMessage(LogType.Warning,"No engine for char {0}! Adding default...",ch.Name);
                // Get first engine HP available
                var engineHp = shipdata.GetHardpointsRows().FirstOrDefault(w => w.EquipType == EquipTypes.Engine.ToString());

                //fallback to internal if none found
                var hp = "";

                if (engineHp != null)
                    hp = engineHp.Name;
                ch.EquipmentList.Add(new Tuple<uint, string, float>(defaults[0].DEngine,hp,1));
                changedAcc = true;
            }

            if (!foundPower | (powerToReplace != null))
            {
                if (powerToReplace != null)
                    ch.EquipmentList.Remove(powerToReplace);

                _log.NewMessage(LogType.Warning, "Adding default powerplant for char {0}...", ch.Name);

                var powerHp =
                    shipdata.GetHardpointsRows().FirstOrDefault(w => w.EquipType == EquipTypes.Powerplant.ToString());
                var hp = "";

                if (powerHp != null)
                    hp = powerHp.Name;
                ch.EquipmentList.Add(new Tuple<uint, string, float>(defaults[0].DPower, hp, 1));
                changedAcc = true;
            }

            if ((!changedAcc) | Properties.Settings.Default.FLDBReadOnlyChecks) return ch;

            //remove everything we marked
            foreach (var rEq in equipToRemove)
                ch.EquipmentList.Remove(rEq);

            ch.SaveCharacter(Properties.Settings.Default.FLDBPath, _log);
            return ch;
        }
Пример #5
0
        private void FillPlayerData(Character ch)
        {
            _curCharacter = ch;

            foreach (var b in GetAll(tabPage2, typeof(Button)))
            {
                b.Enabled = true;
            }
            tabPage5.Enabled = true;
            //TODO: background
            DBiFace.AccDB.LoginDB.IPDataReady.Add((sender, e) => olvIP.SetObjects((List<IPData>)sender));
            DBiFace.AccDB.LoginDB.GetIPByAccID(_curCharacter.AccountID);
            DBiFace.AccDB.LoginDB.IDDataReady.Add((sender, e) => olvID.SetObjects((List<IDData>)sender));
            DBiFace.AccDB.LoginDB.GetIDByAccID(_curCharacter.AccountID);

            //olvIP.SetObjects();
            textBoxName.Text = _curCharacter.Name;
            textBoxMoney.Text = _curCharacter.Money.ToString(CultureInfo.InvariantCulture);
            //comboBoxSystem.SelectedValue = _curCharacter.System.ToLowerInvariant();
            comboBoxShip.SelectedValue = _curCharacter.ShipArch;
            checkBanned.Checked = ch.IsBanned;
            checkBanned2.Checked = checkBanned.Checked;
            rtbBanReason.Text = DBiFace.AccDB.Bans.GetAccBanReason(_curCharacter.AccountID);

            textAccID.Text = ch.AccountID;
            textAdminRights.Text = ch.AdminRights;

            FillLocationBox(ch.System, ch.Base);

            var ship = Universe.Gis.Ships.FindByHash(_curCharacter.ShipArch);

            if (ship != null)
                labelHoldSize.Text = String.Format("Hold size: {0}", ship.HoldSize);
            RefreshCargoSpace();

            dateLastOnline.MaxDate = DateTime.Now;
            dateLastOnline.Value = _curCharacter.LastOnline;
            olvRep.SetObjects(_curCharacter.Reputation.ToList());
            olvCargo.SetObjects(null);
            olvCargo.SetObjects(_curCharacter.Cargo);

            var eqList = EquipTable.GetTable(_curCharacter, _log);
            dlvEquipment.DataSource = eqList;
            if (DBiFace.IsHookAvailable())
                checkIsOnline.Checked = DBiFace.HookTransport.IsOnServer(_curCharacter.Name);

            textCreatedAt.Text = _curCharacter.Created.ToLongDateString();
        }
Пример #6
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;
        }
Пример #7
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;
        }