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)); } }
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; } } }