Пример #1
0
        public static NetCharacter FromDb(long id, GameServer game)
        {
            var character = game.Database.GetCharacter(id);

            var nc = new NetCharacter();

            nc.Name      = character.Name;
            nc.gData     = game.GameData;
            nc.charId    = id;
            nc.Base      = character.Base;
            nc.Ship      = game.GameData.GetShip(character.Ship);
            nc.Credits   = character.Money;
            nc.Equipment = new List <NetEquipment>(character.Equipment.Count);
            foreach (var equip in character.Equipment)
            {
                var resolved = game.GameData.GetEquipment(equip.EquipmentNickname);
                if (resolved == null)
                {
                    continue;
                }
                nc.Equipment.Add(new NetEquipment()
                {
                    Hardpoint = equip.EquipmentHardpoint,
                    Equipment = resolved,
                    Health    = 1f
                });
            }
            return(nc);
        }
Пример #2
0
 Task <bool> IServerPlayer.SelectCharacter(int index)
 {
     if (index >= 0 && index < CharacterList.Count)
     {
         var sc = CharacterList[index];
         FLLog.Info("Server", $"opening id {sc.Id}");
         Character = NetCharacter.FromDb(sc.Id, Game);
         Name      = Character.Name;
         rpcClient.UpdateBaselinePrices(Game.BaselineGoodPrices);
         rpcClient.UpdateInventory(Character.Credits, GetShipWorth(), Character.EncodeLoadout());
         Base     = Character.Base;
         System   = Character.System;
         Position = Character.Position;
         if (Base != null)
         {
             PlayerEnterBase();
         }
         else
         {
             SpaceInitialSpawn(null);
         }
         return(Task.FromResult(false));
     }
     else
     {
         return(Task.FromResult(true));
     }
 }
Пример #3
0
        public static NetCharacter FromDb(long id, GameServer game)
        {
            var db = game.Database.GetCharacter(id);
            var nc = new NetCharacter();

            nc.Name     = db.Character.Name;
            nc.gData    = game.GameData;
            nc.dbChar   = db;
            nc.charId   = id;
            nc.Base     = db.Character.Base;
            nc.System   = db.Character.System;
            nc.Position = new Vector3(db.Character.X, db.Character.Y, db.Character.Z);
            nc.Ship     = game.GameData.GetShip(db.Character.Ship);
            nc.Credits  = db.Character.Money;
            nc.Items    = new List <NetCargo>();
            foreach (var cargo in db.Character.Items)
            {
                var resolved = game.GameData.GetEquipment(cargo.ItemName);
                if (resolved == null)
                {
                    continue;
                }
                nc.Items.Add(new NetCargo()
                {
                    Count     = (int)cargo.ItemCount,
                    Hardpoint = cargo.Hardpoint,
                    Health    = cargo.Health,
                    Equipment = resolved,
                    DbItem    = cargo
                });
            }
            return(nc);
        }
Пример #4
0
        public static string WriteSave(NetCharacter ch, string description, int ids, DateTime?timeStamp)
        {
            var builder = new StringBuilder();

            builder.AppendLine("[Player]");
            if (timeStamp != null)
            {
                var fileTime = timeStamp?.ToFileTime();
                builder.Append("tstamp = ");
                builder.Append((fileTime >> 32).ToString());
                builder.Append(", ");
                builder.AppendLine((fileTime & 0xFFFFFFFF).ToString());
            }
            if (description != null)
            {
                builder.Append("description = ").AppendLine(SavePlayer.EncodeName(description));
            }
            else
            {
                builder.Append("descrip_strid = ").AppendLine(ids.ToString());
            }
            if (!string.IsNullOrWhiteSpace(ch.Name))
            {
                builder.Append("name = ").AppendLine(SavePlayer.EncodeName(ch.Name));
            }
            if (!string.IsNullOrWhiteSpace(ch.Base))
            {
                builder.Append("base = ").AppendLine(ch.Base);
            }
            if (!string.IsNullOrWhiteSpace(ch.System))
            {
                builder.Append("system = ").AppendLine(ch.System);
            }
            builder.Append("pos = ").AppendLine(Vector3(ch.Position));
            builder.Append("money = ").AppendLine(ch.Credits.ToString());
            if (ch.Ship != null)
            {
                builder.Append("ship_archetype = ").AppendLine(ch.Ship.Nickname);
            }
            foreach (var item in ch.Items)
            {
                if (!string.IsNullOrEmpty(item.Hardpoint))
                {
                    var hp = item.Hardpoint.Equals("internal", StringComparison.OrdinalIgnoreCase)
                        ? ""
                        : item.Hardpoint;
                    builder.Append("equip = ").Append(item.Equipment.Nickname).Append(",")
                    .Append(hp).Append(",").AppendLine("1");
                }
                else
                {
                    builder.Append("cargo = ");
                    builder.AppendLine($"{item.Equipment.Nickname}, {item.Count}, , , 0");
                }
            }
            return(builder.ToString());
        }
Пример #5
0
        void ListAction(CharacterListActionPacket pkt)
        {
            switch (pkt.Action)
            {
            case CharacterListAction.RequestCharacterDB:
            {
                var m = server.NetServer.CreateMessage();
                m.Write(new NewCharacterDBPacket()
                    {
                        Factions = server.GameData.Ini.NewCharDB.Factions,
                        Packages = server.GameData.Ini.NewCharDB.Packages,
                        Pilots   = server.GameData.Ini.NewCharDB.Pilots
                    });
                server.NetServer.SendMessage(m, connection, NetDeliveryMethod.ReliableOrdered);
                break;
            }

            case CharacterListAction.SelectCharacter:
            {
                var m  = server.NetServer.CreateMessage();
                var sc = Account.Characters[pkt.IntArg];
                Character = NetCharacter.FromDb(sc, server.GameData);
                Base      = Character.Base;
                m.Write(new BaseEnterPacket()
                    {
                        Base = Character.Base,
                        Ship = Character.EncodeLoadout()
                    });
                server.NetServer.SendMessage(m, connection, NetDeliveryMethod.ReliableOrdered);
                break;
            }

            case CharacterListAction.CreateNewCharacter:
            {
                var m  = server.NetServer.CreateMessage();
                var ac = new ServerCharacter()
                {
                    Name    = pkt.StringArg,
                    Base    = "li01_01_base",
                    Credits = 2000,
                    ID      = 0,
                    Ship    = "ge_fighter"
                };
                Account.Characters.Add(ac);
                m.Write(new AddCharacterPacket()
                    {
                        Character = NetCharacter.FromDb(ac, server.GameData).ToSelectable()
                    });
                server.NetServer.SendMessage(m, connection, NetDeliveryMethod.ReliableOrdered);
                break;
            }
            }
        }
Пример #6
0
 Task <bool> IServerPlayer.CreateNewCharacter(string name, int index)
 {
     FLLog.Info("Player", $"New char {name}");
     if (!Game.Database.NameInUse(name))
     {
         Character ch = null;
         Game.Database.AddCharacter(playerGuid, (db) =>
         {
             ch            = db;
             var sg        = Game.NewCharacter(name, index);
             db.Name       = sg.Player.Name;
             db.Base       = sg.Player.Base;
             db.System     = sg.Player.System;
             db.Rank       = 1;
             db.Costume    = sg.Player.Costume;
             db.ComCostume = sg.Player.ComCostume;
             db.Money      = sg.Player.Money;
             db.Ship       = sg.Player.ShipArchetype;
             db.Items      = new List <CargoItem>();
             foreach (var eq in sg.Player.Equip)
             {
                 db.Items.Add(new CargoItem()
                 {
                     ItemName  = eq.EquipName,
                     Hardpoint = string.IsNullOrEmpty(eq.Hardpoint) ? "internal" : eq.Hardpoint,
                     ItemCount = 1
                 });
             }
             foreach (var cg in sg.Player.Cargo)
             {
                 db.Items.Add(new CargoItem()
                 {
                     ItemName  = cg.CargoName,
                     ItemCount = cg.Count
                 });
             }
         });
         var sel = NetCharacter.FromDb(ch.Id, Game).ToSelectable();
         CharacterList.Add(sel);
         Client.SendPacket(new AddCharacterPacket()
         {
             Character = sel
         }, PacketDeliveryMethod.ReliableOrdered);
         return(Task.FromResult(true));
     }
     else
     {
         return(Task.FromResult(false));
     }
 }
Пример #7
0
        public static NetCharacter FromDb(ServerCharacter character, GameDataManager gameData)
        {
            var nc = new NetCharacter();

            nc.Name      = character.Name;
            nc.gData     = gameData;
            nc.Base      = character.Base;
            nc.Ship      = gameData.GetShip(character.Ship);
            nc.Credits   = character.Credits;
            nc.Equipment = new List <NetEquipment>(character.Equipment.Count);
            foreach (var equip in character.Equipment)
            {
                nc.Equipment.Add(new NetEquipment()
                {
                    Hardpoint = equip.Hardpoint,
                    Equipment = gameData.GetEquipment(equip.Equipment),
                    Health    = equip.Health
                });
            }
            return(nc);
        }
Пример #8
0
        public void OpenSaveGame(Data.Save.SaveGame sg)
        {
            Orientation       = Quaternion.Identity;
            Position          = sg.Player.Position;
            Base              = sg.Player.Base;
            System            = sg.Player.System;
            Character         = new NetCharacter();
            Character.Credits = sg.Player.Money;
            string ps;

            if (sg.Player.ShipArchetype != null)
            {
                ps = sg.Player.ShipArchetype;
            }
            else
            {
                ps = game.GameData.GetShip(sg.Player.ShipArchetypeCrc).Nickname;
            }
            Character.Ship      = game.GameData.GetShip(ps);
            Character.Equipment = new List <NetEquipment>();
            foreach (var eq in sg.Player.Equip)
            {
                var       hp = eq.Hardpoint;
                Equipment equip;
                if (eq.EquipName != null)
                {
                    equip = game.GameData.GetEquipment(eq.EquipName);
                }
                else
                {
                    equip = game.GameData.GetEquipment(eq.EquipHash);
                }
                if (equip != null)
                {
                    Character.Equipment.Add(new NetEquipment()
                    {
                        Equipment = equip, Hardpoint = hp, Health = 1
                    });
                }
            }
            if (Base != null)
            {
                lock (rtcs)
                {
                    Client.SendPacket(new BaseEnterPacket()
                    {
                        Base = Base,
                        Ship = Character.EncodeLoadout(),
                        RTCs = rtcs.ToArray()
                    }, PacketDeliveryMethod.ReliableOrdered);
                }
                InitStory(sg);
            }
            else
            {
                var sys = game.GameData.GetSystem(System);
                game.RequestWorld(sys, (world) =>
                {
                    World = world;
                    Client.SendPacket(new SpawnPlayerPacket()
                    {
                        System      = System,
                        Position    = Position,
                        Orientation = Orientation,
                        Ship        = Character.EncodeLoadout()
                    }, PacketDeliveryMethod.ReliableOrdered);
                    world.SpawnPlayer(this, Position, Orientation);
                    //work around race condition where world spawns after player has been sent to a base
                    InitStory(sg);
                });
            }
        }
Пример #9
0
        void ListAction(CharacterListActionPacket pkt)
        {
            switch (pkt.Action)
            {
            case CharacterListAction.RequestCharacterDB:
            {
                Client.SendPacket(new NewCharacterDBPacket()
                    {
                        Factions = game.GameData.Ini.NewCharDB.Factions,
                        Packages = game.GameData.Ini.NewCharDB.Packages,
                        Pilots   = game.GameData.Ini.NewCharDB.Pilots
                    }, PacketDeliveryMethod.ReliableOrdered);
                break;
            }

            case CharacterListAction.SelectCharacter:
            {
                if (pkt.IntArg > 0 && pkt.IntArg < CharacterList.Count)
                {
                    var sc = CharacterList[pkt.IntArg];
                    FLLog.Info("Server", $"opening id {sc.Id}");
                    Character = NetCharacter.FromDb(sc.Id, game);
                    FLLog.Info("Server", $"sending packet");
                    Base = Character.Base;
                    Client.SendPacket(new BaseEnterPacket()
                        {
                            Base = Character.Base,
                            Ship = Character.EncodeLoadout()
                        }, PacketDeliveryMethod.ReliableOrdered);
                }
                else
                {
                    Client.SendPacket(new CharacterListActionResponsePacket()
                        {
                            Action = CharacterListAction.SelectCharacter,
                            Status = CharacterListStatus.ErrBadIndex
                        }, PacketDeliveryMethod.ReliableOrdered);
                }
                break;
            }

            case CharacterListAction.DeleteCharacter:
            {
                var sc = CharacterList[pkt.IntArg];
                game.Database.DeleteCharacter(sc.Id);
                CharacterList.Remove(sc);
                Client.SendPacket(new CharacterListActionResponsePacket()
                    {
                        Action = CharacterListAction.DeleteCharacter,
                        Status = CharacterListStatus.OK
                    }, PacketDeliveryMethod.ReliableOrdered);
                break;
            }

            case CharacterListAction.CreateNewCharacter:
            {
                if (!game.Database.NameInUse(pkt.StringArg))
                {
                    Character ch = null;
                    game.Database.AddCharacter(playerGuid, (db) =>
                        {
                            ch            = db;
                            var sg        = game.NewCharacter(pkt.StringArg, pkt.IntArg);
                            db.Name       = sg.Player.Name;
                            db.Base       = sg.Player.Base;
                            db.System     = sg.Player.System;
                            db.Rank       = 1;
                            db.Costume    = sg.Player.Costume;
                            db.ComCostume = sg.Player.ComCostume;
                            db.Money      = sg.Player.Money;
                            db.Ship       = sg.Player.ShipArchetype;
                            db.Equipment  = new HashSet <EquipmentEntity>();
                            db.Cargo      = new HashSet <CargoItem>();
                            foreach (var eq in sg.Player.Equip)
                            {
                                db.Equipment.Add(new EquipmentEntity()
                                {
                                    EquipmentNickname  = eq.EquipName,
                                    EquipmentHardpoint = eq.Hardpoint
                                });
                            }
                            foreach (var cg in sg.Player.Cargo)
                            {
                                db.Cargo.Add(new CargoItem()
                                {
                                    ItemName  = cg.CargoName,
                                    ItemCount = cg.Count
                                });
                            }
                        });
                    var sel = NetCharacter.FromDb(ch.Id, game).ToSelectable();
                    CharacterList.Add(sel);
                    Client.SendPacket(new AddCharacterPacket()
                        {
                            Character = sel
                        }, PacketDeliveryMethod.ReliableOrdered);
                }
                else
                {
                    Client.SendPacket(new CharacterListActionResponsePacket()
                        {
                            Action = CharacterListAction.CreateNewCharacter,
                            Status = CharacterListStatus.ErrUnknown
                        }, PacketDeliveryMethod.ReliableOrdered);
                }
                break;
            }
            }
        }
Пример #10
0
        public void OpenSaveGame(Data.Save.SaveGame sg)
        {
            Orientation       = Quaternion.Identity;
            Position          = sg.Player.Position;
            Base              = sg.Player.Base;
            System            = sg.Player.System;
            Character         = new NetCharacter();
            Character.Credits = sg.Player.Money;
            string ps;

            if (sg.Player.ShipArchetype != null)
            {
                ps = sg.Player.ShipArchetype;
            }
            else
            {
                ps = game.GameData.GetShip(sg.Player.ShipArchetypeCrc).Nickname;
            }
            Character.Ship      = game.GameData.GetShip(ps);
            Character.Equipment = new List <NetEquipment>();
            foreach (var eq in sg.Player.Equip)
            {
                var       hp = eq.Hardpoint;
                Equipment equip;
                if (eq.EquipName != null)
                {
                    equip = game.GameData.GetEquipment(eq.EquipName);
                }
                else
                {
                    equip = game.GameData.GetEquipment(eq.EquipHash);
                }
                if (equip != null)
                {
                    Character.Equipment.Add(new NetEquipment()
                    {
                        Equipment = equip, Hardpoint = hp, Health = 1
                    });
                }
            }
            if (Base != null)
            {
                lock (rtcs)
                {
                    client.SendPacket(new BaseEnterPacket()
                    {
                        Base = Base,
                        Ship = Character.EncodeLoadout(),
                        RTCs = rtcs.ToArray()
                    }, NetDeliveryMethod.ReliableOrdered);
                }
            }
            else
            {
                var sys = game.GameData.GetSystem(System);
                game.RequestWorld(sys, (world) =>
                {
                    World = world;
                    client.SendPacket(new SpawnPlayerPacket()
                    {
                        System      = System,
                        Position    = Position,
                        Orientation = Orientation,
                        Ship        = Character.EncodeLoadout()
                    }, NetDeliveryMethod.ReliableOrdered);
                    world.SpawnPlayer(this, Position, Orientation);
                });
            }
            var missionNum = sg.StoryInfo?.MissionNum ?? 0;

            if (game.GameData.Ini.ContentDll.AlwaysMission13)
            {
                missionNum = 14;
            }
            if (missionNum != 0 && (missionNum - 1) < game.GameData.Ini.Missions.Count)
            {
                msnRuntime = new MissionRuntime(game.GameData.Ini.Missions[missionNum - 1], this);
                msnRuntime.Update(TimeSpan.Zero);
            }
        }
Пример #11
0
        public void OpenSaveGame(SaveGame sg)
        {
            Orientation = Quaternion.Identity;
            Position    = sg.Player.Position;
            Base        = sg.Player.Base;
            System      = sg.Player.System;
            Character   = new NetCharacter();
            Character.UpdateCredits(sg.Player.Money);
            string ps;

            if (sg.Player.ShipArchetype != null)
            {
                ps = sg.Player.ShipArchetype;
            }
            else
            {
                ps = Game.GameData.GetShip(sg.Player.ShipArchetypeCrc).Nickname;
            }
            Character.Ship  = Game.GameData.GetShip(ps);
            Character.Items = new List <NetCargo>();
            foreach (var eq in sg.Player.Equip)
            {
                var hp = eq.Hardpoint;
                if (string.IsNullOrEmpty(hp))
                {
                    hp = "internal";
                }
                Equipment equip;
                if (eq.EquipName != null)
                {
                    equip = Game.GameData.GetEquipment(eq.EquipName);
                }
                else
                {
                    equip = Game.GameData.GetEquipment(eq.EquipHash);
                }
                if (equip != null)
                {
                    Character.Items.Add(new NetCargo()
                    {
                        Equipment = equip, Hardpoint = hp, Health = 1, Count = 1
                    });
                }
            }
            foreach (var cg in sg.Player.Cargo)
            {
                Equipment equip;
                if (cg.CargoName != null)
                {
                    equip = Game.GameData.GetEquipment(cg.CargoName);
                }
                else
                {
                    equip = Game.GameData.GetEquipment(cg.CargoHash);
                }
                if (equip != null)
                {
                    Character.Items.Add(new NetCargo()
                    {
                        Equipment = equip, Count = cg.Count
                    });
                }
            }
            rpcClient.UpdateInventory(Character.Credits, GetShipWorth(), Character.EncodeLoadout());
            if (Base != null)
            {
                InitStory(sg);
                PlayerEnterBase();
            }
            else
            {
                InitStory(sg);
                SpaceInitialSpawn(sg);
            }
        }