/// <summary>
 /// Inserts new account info into DB.
 /// </summary>
 /// <param name="id">Player ID</param>
 /// <param name="charname">Character name</param>
 /// <returns>True if insert suceeds; otherwise false.</returns>
 public static bool AddAccount(string id, string charname)
 {
     using (var cmd = new SQLiteCommand(Sqladdquery, _conn))
     {
         cmd.Parameters.AddWithValue("@CharName", charname);
         cmd.Parameters.AddWithValue("@ID", id);
         cmd.Parameters.AddWithValue("@CharCode", FLMsgType.FLNameToFile(charname));
         cmd.Parameters.AddWithValue("@Money", _defAcct.Money);
         cmd.Parameters.AddWithValue("@ShipArch", _defAcct.Ship);
         cmd.Parameters.AddWithValue("@System", _defAcct.System);
         cmd.Parameters.AddWithValue("@Location", UniverseDB.FindSystem(_defAcct.System).Nickname);
         cmd.Parameters.AddWithValue("@LastOnline", DateTime.UtcNow);
         cmd.Parameters.AddWithValue("@Rank", _defAcct.Rank);
         cmd.Parameters.AddWithValue("@IsBanned", _defAcct.IsBanned);
         cmd.Parameters.AddWithValue("@Settings", _defAcct.Settings);
         cmd.Parameters.AddWithValue("@ShipState", _defAcct.ShipState);
         cmd.Parameters.AddWithValue("@Appearance", _defAcct.Appearance);
         cmd.Parameters.AddWithValue("@Equipment", _defAcct.Equipment);
         cmd.Parameters.AddWithValue("@Cargo", _defAcct.Cargo);
         cmd.Parameters.AddWithValue("@RepList", _defAcct.RepList);
         cmd.Parameters.AddWithValue("@Visits", _defAcct.Visits);
         cmd.Parameters.AddWithValue("@MinutesOnline", 0u);
         cmd.Parameters.AddWithValue("@UID", Guid.NewGuid().ToString());
         return(cmd.ExecuteNonQuery() == 1);
     }
 }
 /// <summary>
 /// Modifies account in database.
 /// </summary>
 /// <param name="acc">Modified account</param>
 /// <returns>True if mod suceeds; otherwise false.</returns>
 public static bool ModifyAccount(Account acc)
 {
     using (var cmd = new SQLiteCommand(SQLModQuery, _conn))
     {
         cmd.Parameters.AddWithValue("@UID", acc.UID);
         cmd.Parameters.AddWithValue("@CharName", acc.CharName);
         cmd.Parameters.AddWithValue("@CharCode", FLMsgType.FLNameToFile(acc.CharName));
         cmd.Parameters.AddWithValue("@Money", acc.Money);
         cmd.Parameters.AddWithValue("@ShipArch", acc.Ship);
         cmd.Parameters.AddWithValue("@System", acc.System);
         cmd.Parameters.AddWithValue("@Location", UniverseDB.FindSystem(acc.System).Nickname);
         cmd.Parameters.AddWithValue("@LastOnline", DateTime.UtcNow);
         cmd.Parameters.AddWithValue("@Rank", acc.Rank);
         cmd.Parameters.AddWithValue("@IsBanned", acc.IsBanned);
         cmd.Parameters.AddWithValue("@Settings", acc.Settings);
         cmd.Parameters.AddWithValue("@ShipState", acc.ShipState);
         cmd.Parameters.AddWithValue("@Appearance", acc.Appearance);
         cmd.Parameters.AddWithValue("@Equipment", acc.Equipment);
         cmd.Parameters.AddWithValue("@Cargo", acc.Cargo);
         cmd.Parameters.AddWithValue("@RepList", acc.RepList);
         cmd.Parameters.AddWithValue("@Visits", acc.Visits);
         cmd.Parameters.AddWithValue("@MinutesOnline", acc.TimeOnline);
         return(cmd.ExecuteNonQuery() == 1);
     }
 }
Exemplo n.º 3
0
        public void GetLoadout()
        {
            Loadout = UniverseDB.FindLoadout(Arch.Nickname);
            if (Loadout != null)
            {
                AI = new AI.SolarAI();
                var firstOrDefault = Loadout.Items.FirstOrDefault(item => item.arch.GetType() == typeof(PowerArchetype));
                if (firstOrDefault != null)
                {
                    PowerGen = new PowerSim(this, (PowerArchetype)firstOrDefault.arch, firstOrDefault);
                }
                else
                {
                    return;
                }

                firstOrDefault =
                    Loadout.Items.FirstOrDefault(item => item.arch.GetType() == typeof(ShieldGeneratorArchetype));
                if (firstOrDefault != null)
                {
                    ShieldSim = new ShieldGeneratorSim(this, (ShieldGeneratorArchetype)firstOrDefault.arch, PowerGen)
                    {
                        Power = PowerGen
                    };
                }
            }
        }
        /// <summary>
        ///     FLPACKET_SERVER_GFCOMPLETENEWSBROADCASTLIST
        /// </summary>
        /// <param name="player"></param>
        /// <param name="baseid"></param>
        public static void SendGFCompleteNewsBroadcastList(Player player, uint baseid)
        {
            player.Log.AddLog(LogType.FL_MSG, "tx FLPACKET_SERVER_NEWS");
            BaseData bd = UniverseDB.FindBase(baseid);

            uint newsid = 0;

            foreach (NewsItem ni in bd.News)
            {
                byte[] omsg = { 0x1E, 0x02 };
                FLMsgType.AddUInt32(ref omsg, 40 + (uint)ni.Logo.Length);  // size goes here

                FLMsgType.AddUInt32(ref omsg, newsid++);
                FLMsgType.AddUInt32(ref omsg, baseid);
                FLMsgType.AddUInt16(ref omsg, 0);

                FLMsgType.AddUInt32(ref omsg, ni.Icon);
                FLMsgType.AddUInt32(ref omsg, ni.Category);
                FLMsgType.AddUInt16(ref omsg, 0);
                FLMsgType.AddUInt32(ref omsg, ni.Headline);
                FLMsgType.AddUInt16(ref omsg, 0);
                FLMsgType.AddUInt32(ref omsg, ni.Text);
                FLMsgType.AddUInt16(ref omsg, 0);
                FLMsgType.AddAsciiStringLen32(ref omsg, ni.Logo);
                FLMsgType.AddUInt32(ref omsg, 0); // unknown hash, 0 seems to work

                player.SendMsgToClient(omsg);
            }

            // Send "news list complete" message
            {
                byte[] omsg = { 0x0e, 0x02 };
                FLMsgType.AddUInt32(ref omsg, baseid);
                player.SendMsgToClient(omsg);
            }
        }
Exemplo n.º 5
0
        private static void LoadNewsFile(FLDataFile ini, ILogController log)
        {
            foreach (FLDataFile.Section sec in ini.Sections)
            {
                string section_name = sec.SectionName.ToLowerInvariant();
                if (section_name == "newsitem")
                {
                    var item = new NewsItem
                    {
                        Category = sec.GetSetting("category").UInt(0),
                        Headline = sec.GetSetting("headline").UInt(0)
                    };

                    var icon = sec.GetSetting("icon").Str(0);
                    switch (icon)
                    {
                    case "critical":
                        item.Icon = 1;
                        break;

                    case "world":
                        item.Icon = 2;
                        break;

                    case "mission":
                        item.Icon = 3;
                        break;

                    case "system":
                        item.Icon = 4;
                        break;

                    case "faction":
                        item.Icon = 5;
                        break;

                    case "universe":
                        item.Icon = 6;
                        break;

                    default:
                        item.Icon = 0;
                        break;
                    }

                    item.Text  = sec.GetSetting("text").UInt(0);
                    item.Audio = sec.SettingExists("audio");
                    item.Logo  = sec.GetSetting("logo").Str(0);
                    foreach (var set in sec.Settings)
                    {
                        if (set.SettingName != "base")
                        {
                            continue;
                        }
                        var basename = set.Str(0);

                        var bd = UniverseDB.FindBase(basename);
                        if (bd == null)
                        {
                            log.AddLog(LogType.ERROR, "basename in news item not found, category={0} base={1}",
                                       item.Category, basename);
                        }
                        else
                        {
                            bd.News.Add(item);
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// </summary>
        /// <param name="ini"></param>
        /// <param name="log"></param>
        /// First value is "minimum" mission difficulty. Second value is "maximum" mission difficulty.
        /// The server uses a funky formula for that, but preferably (and I've requested a hack applied
        /// to FLServer) it should just use those bare values. Third value is only used in the faction
        /// headers, and is the percentage chance for a mission for that faction to appear - the total
        /// of all mission lines of all factions for any given base should be 100.
        /// The difficulty then determines the payout and the various ships and solars that may appear.
        /// - Get as close to the max value of the difficulty by adding ships and solars in the waves
        /// in that mission, using the NPCRankToDiff.ini and MissionSolars.ini file for guidance
        /// - Then calculate the actual difficulty of the mission, and use the Diff2Money.ini file
        /// for calculating the mission payout. Then post the mission.
        private static void LoadMBaseFile(FLDataFile ini, ILogController log)
        {
            BaseData bd = null;

            foreach (var sec in ini.Sections)
            {
                string sectionName = sec.SectionName.ToLowerInvariant();
                if (sectionName == "mbase")
                {
                    string nickname = sec.GetSetting("nickname").Str(0);
                    bd = UniverseDB.FindBase(nickname);
                }
                else if (sectionName == "mvendor")
                {
                }
                else if (sectionName == "basefaction")
                {
                    var bf = new BaseFaction
                    {
                        Faction        = UniverseDB.FindFaction(sec.GetSetting("faction").Str(0)),
                        Weight         = sec.GetSetting("weight").Float(0),
                        OffersMissions = sec.SettingExists("offers_missions")
                    };

                    foreach (FLDataFile.Setting set in sec.Settings)
                    {
                        if (set.SettingName == "mission_type")
                        {
                            string mission_type = set.Str(0);
                        }
                        else if (set.SettingName == "npc")
                        {
                            string npcname = set.Str(0);
                        }
                    }
                }
                else if (sectionName == "gf_npc")
                {
                    var bc = new BaseCharacter {
                        Nickname = sec.GetSetting("nickname").Str(0).ToLowerInvariant()
                    };

                    if (sec.SettingExists("base_appr"))
                    {
                        // fixme
                        // var body;
                        // var head;
                        // var lefthead;
                        // var righthand;
                    }
                    else
                    {
                        bc.Body      = Utilities.CreateID(sec.GetSetting("body").Str(0));
                        bc.Head      = Utilities.CreateID(sec.GetSetting("head").Str(0));
                        bc.Lefthand  = Utilities.CreateID(sec.GetSetting("lefthand").Str(0));
                        bc.Righthand = Utilities.CreateID(sec.GetSetting("righthand").Str(0));
                    }

                    bc.IndividualName = sec.GetSetting("individual_name").UInt(0);
                    bc.Faction        = UniverseDB.FindFaction(sec.GetSetting("affiliation").Str(0));
                    bc.Voice          = Utilities.CreateID(sec.GetSetting("voice").Str(0));
                    if (sec.SettingExists("room"))
                    {
                        bc.Room   = String.Format("{0:x}_{1}", bd.BaseID, sec.GetSetting("room").Str(0));
                        bc.RoomID = Utilities.CreateID(bc.Room);
                    }

                    foreach (var set in sec.Settings)
                    {
                        if (set.SettingName == "bribe")
                        {
                            var bb = new BaseBribe
                            {
                                Faction = UniverseDB.FindFaction(set.Str(0)),
                                Cost    = set.UInt(1),
                                Text    = set.UInt(2)
                            };
                            bc.Bribes.Add(bb);
                        }
                        else if (set.SettingName == "rumor")
                        {
                            var br = new BaseRumor {
                                Text = set.UInt(3)
                            };
                            bc.Rumors.Add(br);
                        }
                    }

                    if (bd != null)
                    {
                        bd.Chars[bc.Nickname] = bc;
                    }
                    else
                    {
                        log.AddLog(LogType.ERROR, "Character {0} can't find base", bc.Nickname);
                    }
                }
                else if (sectionName == "mroom")
                {
                    string nickname = sec.GetSetting("nickname").Str(0).ToLowerInvariant();
                    if (sec.SettingExists("character_density"))
                    {
                        bd.Rooms[nickname].CharacterDensity = sec.GetSetting("character_density").UInt(0);
                    }

                    foreach (FLDataFile.Setting set in sec.Settings)
                    {
                        if (set.SettingName == "fixture")
                        {
                            string name          = set.Str(0).ToLowerInvariant();
                            string roomLocation  = set.Str(1);
                            string fidget_script = set.Str(2);
                            string type          = set.Str(3).ToLowerInvariant();

                            if (!bd.Chars.ContainsKey(name))
                            {
                                log.AddLog(LogType.ERROR, "character not found at {0}", set.Desc);
                                continue;
                            }

                            bd.Chars[name].Room         = String.Format("{0:x}_{1}", bd.BaseID, nickname);
                            bd.Chars[name].RoomID       = Utilities.CreateID(bd.Chars[name].Room);
                            bd.Chars[name].RoomLocation = roomLocation;
                            bd.Chars[name].FidgetScript = fidget_script;
                            bd.Chars[name].Type         = type;
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
            public override void HandleTimerEvent(double deltaSeconds)
            {
                if (runner.System == UniverseDB.FindSystem("li01"))
                {
                    //TODO: AI debug here
                    for (int i = 0; i < 1; i++)
                    {
                        var npc = new Old.Object.Ship.Ship(runner);
                        npc.AI   = new AI.DebugAI(npc);
                        npc.Arch = ArchetypeDB.Find(FLUtility.CreateID("dsy_csv"));
                        if (npc.Arch == null)
                        {
                            return;
                        }

                        npc.Position = new Vector(-30000 + i * 300, i * 100, -25000);
                        //npc.orientation = ;
                        npc.Rank    = 20;
                        npc.System  = runner.System;
                        npc.Health  = 1.0f;
                        npc.faction = UniverseDB.FindFaction("fc_wild");
                        Loadout loadout = UniverseDB.FindLoadout("fc_j_ge_csv_loadout01");
                        if (loadout != null)
                        {
                            uint hpid = 34;
                            foreach (ShipItem item in loadout.Items)
                            {
                                var new_item = new ShipItem();
                                new_item.arch    = item.arch;
                                new_item.count   = item.count;
                                new_item.health  = 1.0f;
                                new_item.hpid    = hpid++;
                                new_item.hpname  = item.hpname;
                                new_item.mounted = item.mounted;
                                npc.Items.Add(new_item.hpid, new_item);
                            }
                        }
                        npc.InitialiseEquipmentSimulation();
                        runner.CreateSimObject(npc);
                    }
                }
                //    int total = 0;
                //    if (runner.players.Count > 0)
                //    {
                //        if (delta_seconds > 1.5)
                //            runner.log.AddLog(LogType.FL_MSG, "bad delta " + delta_seconds);

                //        // wow, this'll really suck if there are lots of NPCs
                //        foreach (Zone z in runner.system.zones)
                //        {
                //            if (z.shape != null && z.density > 0)
                //            {
                //                while (z.interference < z.density) // borrow this
                //                {
                //                    Ship npc = new Ship(runner);
                //                    npc.position = z.shape.position;
                //                    npc.orientation = z.shape.orientation;
                //                    npc.rank = 20;
                //                    npc.arch = ArchetypeDB.Find(FLUtility.CreateID("dsy_csv"));
                //                    npc.system = runner.system;
                //                    npc.health = 1.0f;
                //                    runner.CreateSimObject(npc);

                //                    z.interference++;
                //                    total++;
                //                }
                //            }
                //        }

                //        int working_npcs = 0;
                //        foreach (SimObject o in runner.objects.Values)
                //        {
                //            if (o.health > 0)
                //            {
                //                working_npcs++;

                //                foreach (Player player in runner.players.Values)
                //                {
                //                    if (player.ship != o)
                //                    {
                //                        Vector position = player.ship.position;
                //                        position.x += rand.Next(100);
                //                        position.z += rand.Next(100);
                //                        o.SetUpdateObject(position, player.ship.orientation, 1.0f, 0);
                //                    }
                //                }
                //            }
                //        }

                //        runner.log.AddLog(LogType.GENERAL, "system={0} npcs={1} objects={2} running={3}",
                //            runner.system.nickname, total, runner.objects.Count, working_npcs));

                //    }

                //    ExpireAfter(1);
            }
Exemplo n.º 8
0
        /// <summary>
        ///     Process an admin command.
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="chat"></param>
        /// <returns>Returns true if the command was processed and further processing should be stopped</returns>
        public static bool ProcessAdminCommands(Player.Player from, uint to, string chat)
        {
            // If this is an admin command and the player has admin permissions
            // then dispatch
            if (chat[0] == '.')
            {
                // Echo the chat back to the player.
                SendEcho(from, chat);

                string[] args = chat.Split(' ');

                // Figure out if the charname argument for the command is for
                // a partial, FL ID match or exact match.
                int searchMode = 2;
                if (args.Length > 0 && args[0].EndsWith("&"))
                {
                    args[0]    = args[0].Substring(0, args[0].Length - 1);
                    searchMode = 1;
                }
                else if (args.Length > 0 && args[0].EndsWith("$"))
                {
                    args[0]    = args[0].Substring(0, args[0].Length - 1);
                    searchMode = 0;
                }

                // Process the command.
                if (args.Length == 3 && args[0] == ".beam")
                {
                    Player.Player player = FindActivePlayerByCharname(from.Runner, args[1], searchMode);
                    if (player == null)
                    {
                        SendEcho(from, "ERR charname not found");
                        return(true);
                    }

                    string   basename = args[2];
                    BaseData basedata = UniverseDB.FindBase(basename);
                    if (basedata == null)
                    {
                        SendEcho(from, "ERR base not found");
                        return(true);
                    }

                    if (player.Ship.Basedata != null)
                    {
                        SendEcho(from, "ERR player not in space");
                        return(true);
                    }


                    player.Runner.AddEvent(new DPGRBeam(player, basedata));
                    SendEcho(from, "OK"); // fixme: need feedback.
                }
                else if (args.Length == 3 && args[0] == ".addcash")
                {
                    Player.Player player = FindActivePlayerByCharname(from.Runner, args[1], searchMode);
                    if (player == null)
                    {
                        SendEcho(from, "ERR charname not found");
                        return(true);
                    }

                    int money = 0;
                    if (!Int32.TryParse(args[2], out money))
                    {
                        SendEcho(from, "ERR invalid money");
                        return(true);
                    }

                    player.Runner.AddEvent(new DPGRAddCash(player, money));
                    SendEcho(from, "OK");
                    // fixme: SendChatToPlayer(from, "OK cash=" + player.money);
                }
                else if (args.Length == 3 && args[0] == ".setcash")
                {
                    Player.Player player = FindActivePlayerByCharname(from.Runner, args[1], searchMode);
                    if (player == null)
                    {
                        SendEcho(from, "ERR charname not found");
                        return(true);
                    }

                    int money = 0;
                    if (!Int32.TryParse(args[2], out money))
                    {
                        SendEcho(from, "ERR invalid money count");
                        return(true);
                    }

                    player.Runner.AddEvent(new DPGRSetCash(player, money));
                    SendEcho(from, "OK");
                    // fixme: SendChatToPlayer(from, "OK cash=" + player.money);
                }
                else if (args.Length == 3 && args[0] == ".setcash")
                {
                    Player.Player player = FindActivePlayerByCharname(from.Runner, args[1], searchMode);
                    if (player == null)
                    {
                        SendEcho(from, "ERR charname not found");
                        return(true);
                    }

                    int money = Int32.Parse(args[2]);
                    player.Money += money;
                    player.SendSetMoney();

                    SendEcho(from, "OK cash=" + player.Money);
                }
                else if (args.Length == 3 && args[0] == ".getrep")
                {
                    Player.Player player = FindActivePlayerByCharname(from.Runner, args[1], searchMode);
                    if (player == null)
                    {
                        SendEcho(from, "ERR charname not found");
                        return(true);
                    }

                    string  factionname = args[2];
                    Faction faction     = UniverseDB.FindFaction(factionname);
                    if (faction == null)
                    {
                        SendEcho(from, "ERR not found faction=" + factionname);
                        return(true);
                    }

                    float attitude = player.Ship.GetAttitudeTowardsFaction(faction);
                    SendEcho(from, "OK faction=" + factionname + " rep=" + attitude);
                }
                else if (args.Length == 4 && args[0] == ".setrep")
                {
                    Player.Player player = FindActivePlayerByCharname(from.Runner, args[1], searchMode);
                    if (player == null)
                    {
                        SendEcho(from, "ERR charname not found");
                        return(true);
                    }

                    string  factionname = args[2];
                    Faction faction     = UniverseDB.FindFaction(factionname);
                    if (faction == null)
                    {
                        SendEcho(from, "ERR not found faction=" + factionname);
                        return(true);
                    }

                    float attitude = 0;
                    if (!float.TryParse(args[3], out attitude))
                    {
                        SendEcho(from, "ERR invalid rep=" + args[3]);
                        return(true);
                    }

                    player.Ship.SetReputation(faction, attitude);
                    SendEcho(from,
                             "OK faction=" + faction.Nickname + " rep=" + player.Ship.GetAttitudeTowardsFaction(faction));
                }
                else if (args.Length == 3 && args[0] == ".setrept")
                {
                    var player = FindActivePlayerByCharname(from.Runner, args[1], searchMode);
                    if (player == null)
                    {
                        SendEcho(from, "ERR charname not found");
                        return(true);
                    }

                    float attitude = 0;
                    if (!float.TryParse(args[2], out attitude))
                    {
                        SendEcho(from, "ERR invalid rep=" + args[3]);
                        return(true);
                    }

                    Object.Solar.Solar solar = UniverseDB.FindSolar(player.Ship.TargetObjID);
                    if (solar != null)
                    {
                        SendEcho(from, "OK solar=" + solar.Faction + " rep=" + attitude);
                        player.Ship.SetReputation(solar.Faction, attitude);
                        return(true);
                    }

                    SendEcho(from, "ERR only solar's supported cause I was lazy");
                }
                else if (args.Length == 2 && args[0] == ".kill")
                {
                    Player.Player player = FindActivePlayerByCharname(from.Runner, args[1], searchMode);
                    if (player == null)
                    {
                        SendEcho(from, "ERR charname not found");
                        return(true);
                    }

                    if (player.Ship.Basedata != null)
                    {
                        SendEcho(from, "ERR player not in space");
                        return(true);
                    }

                    player.Ship.Destroy(DeathCause.Command);
                    SendEcho(from, "OK");
                }
                else if (args.Length == 4 && args[0] == ".move")
                {
                    float x = 0;
                    float y = 0;
                    float z = 0;
                    if (!float.TryParse(args[1], out x) ||
                        !float.TryParse(args[2], out y) ||
                        !float.TryParse(args[3], out z))
                    {
                        SendEcho(from, String.Format("ERR invalid position={0:0} {1:0} {2:0}", x, y, z));
                        return(true);
                    }

                    var dummyAction = new LaunchInSpaceAction
                    {
                        Position    = new Vector(x, y, z),
                        Orientation = Quaternion.MatrixToQuaternion(@from.Ship.Orientation)
                    };
                    from.Ship.CurrentAction = dummyAction;
                    from.SendServerLaunch();
                    from.Ship.CurrentAction = null;
                    SendEcho(from, String.Format("OK position={0:0} {1:0} {2:0}", x, y, z));
                }
                else if (args.Length == 1 && args[0] == ".help")
                {
                    from.SendInfocardUpdate(500000, "Admin Commands");
                    from.SendInfocardUpdate(500001, from.Runner.Server.AdminHelpMsg);
                    from.SendPopupDialog(new FLFormatString(500000), new FLFormatString(500001),
                                         Player.Player.PopupDialogButtons.POPUPDIALOG_BUTTONS_CENTER_OK);
                }
                else
                {
                    SendEcho(from, "ERR command invalid, type .help for valid commands");
                }
                return(true);
            }
            return(false);
        }
        /// <summary>
        ///     Load the specified character file, resetting all character specific
        ///     content for this player and notifying all players of the name.
        /// </summary>
        /// <param name="account">Player account</param>
        /// <param name="log"></param>
        /// <returns>Returns null on successful load otherwise returns error message as a string.</returns>
        public string LoadCharFile(Account account, ILogController log)
        {
            if (account == null)
            {
                log.AddLog(LogType.ERROR, "Broken account found!");
                return("Account is null!");
            }
            //null checks made earlier
            // ReSharper disable once PossibleInvalidOperationException
            PlayerAccount = account;
            Wgrp          = new WeaponGroup();

// ReSharper disable once PossibleNullReferenceException
            Name  = PlayerAccount.CharName;
            Money = PlayerAccount.Money;

            var arch = ArchetypeDB.Find(PlayerAccount.Ship);

            if (arch is ShipArchetype)
            {
                Ship.Arch = arch;
            }
            else
            {
                return("invalid ship");
            }

            if (ShipState.RepGroup == "")
            {
                Ship.faction = new Faction();
            }
            else
            {
                Ship.faction = UniverseDB.FindFaction(ShipState.RepGroup);
                if (Ship.faction == null)
                {
                    return("invalid faction");
                }
            }

            Ship.System = UniverseDB.FindSystem(PlayerAccount.System);
            if (Ship.System == null)
            {
                return("invalid system");
            }

            if (ShipState.Base == null)
            {
                Ship.Basedata = null;
            }
            else
            {
                Ship.Basedata = UniverseDB.FindBase(ShipState.Base);
                if (Ship.Basedata == null)
                {
                    return("invalid base");
                }
            }

            if (ShipState.LastBase == "")
            {
                Ship.RespawnBasedata = null;
                return("no respawn base");
            }

            Ship.RespawnBasedata = UniverseDB.FindBase(ShipState.LastBase);
            if (Ship.RespawnBasedata == null)
            {
                return("invalid respawn base");
            }



            if (Ship.Basedata == null)
            {
                if (ShipState.Position != null)
                {
                    Ship.Position = ShipState.Position;
                }

                if (ShipState.Rotate != null)
                {
                    Ship.Orientation = Matrix.EulerDegToMatrix(ShipState.Rotate);
                }
            }

            //TODO: why ShipState.Hull is always true
            Ship.Health = ShipState.Hull;
            if (Ship.Health <= 0)
            {
                Ship.Health = 0.05f;
            }

            Ship.voiceid = FLUtility.CreateID(Appearance.Voice);

            //TODO: calculate rank
// ReSharper disable once PossibleNullReferenceException
            Ship.Rank = PlayerAccount.Rank;

            Ship.com_body      = Appearance.Body;
            Ship.com_head      = Appearance.Head;
            Ship.com_lefthand  = Appearance.LeftHand;
            Ship.com_righthand = Appearance.RightHand;

            Ship.Items.Clear();

            uint hpid = 34;

            foreach (var set in Equipment)
            {
                var si = new ShipItem
                {
                    arch    = ArchetypeDB.Find(set.Arch),
                    hpname  = set.HpName,
                    health  = set.Health,
                    count   = 1,
                    mission = false,
                    mounted = true,
                    hpid    = hpid++
                };
                Ship.Items[si.hpid] = si;
            }

            foreach (var set in Cargo)
            {
                var si = new ShipItem
                {
                    arch    = ArchetypeDB.Find(set.Arch),
                    hpname  = "",
                    count   = set.Count,
                    health  = 1.0f,
                    mission = false,
                    mounted = false,
                    hpid    = hpid++
                };
                Ship.Items[si.hpid] = si;
            }

            Ship.Reps.Clear();


            foreach (var set in RepDictionary)
            {
                float rep     = set.Value;
                var   faction = UniverseDB.FindFaction(set.Key);
                if (faction == null)
                {
// ReSharper disable once PossibleNullReferenceException
                    log.AddLog(LogType.ERROR, "error: faction not found char={0} faction={1}", account.CharName,
                               set.Value);
                }
                else
                {
                    Ship.Reps[faction] = rep;
                }
            }


            //Visits.Clear();
            //foreach (var set in Visits)
            //{
            //    Visits[set.Key] = set.Value;
            //}

            Ship.CurrentAction = null;

            return(null);
        }