public ActionResult Create([Bind(Include = "ServerID,ServerName,ServerType,ServerVersion,UserName,Password, ServerEnv,AppId")] Server server) { if (ModelState.IsValid) { using (ServerDbContext context = new ServerDbContext()) { server.CreatedDate = DateTime.Now; server.ModifiedDate = DateTime.Now; } db.Server.Add(server); db.SaveChanges(); if (Session["appid"] == null || Session["env"] == null) { return(RedirectToAction("Index")); } else { return(RedirectToAction("Index", new { app_id = Convert.ToInt32(Session["appid"].ToString()), env = Session["env"].ToString() })); } } ViewBag.ServerEnv = getServerEnv(); ViewBag.ServeTypeDL = getServerTypeDetails(); ViewBag.AppId = new SelectList(db.Applications, "AppId", "AppName", server.AppId); return(View(server)); }
private static void Lend(Player sender, Player target, int vehicle) { try { Vehicle veh = CmdHelper.GetCurrentVehicleOrID(sender, vehicle); if (!Helper.IsOwner(sender, veh)) { throw new Exception("Vous n'êtes pas propriétaire de ce véhicule."); } if (veh.Data.Borrowers.Select(b => b.Borrower).Any(b => b == target.ActiveCharacter)) { throw new Exception("Vous prêtez déjà votre véhicule à ce joueur."); } Helper.BorrowVehicle(veh, target); Chat.InfoChat(sender, "Vous avez prêté votre véhicule " + Constants.Chat.HIGHLIGHT + VehicleModelInfo.ForVehicle(veh).Name + Color.White + " à " + Constants.Chat.HIGHLIGHT + target.Name + Color.White + "."); ServerDbContext dbContext = ((GameMode)GameMode.Instance).DbContext; dbContext.SaveChanges(); } catch (Exception e) { Chat.ErrorChat(sender, e.Message); } }
private void NameSelect(object sender, MenuDialogItemEventArgs e) { InputDialog nameDialog = new InputDialog("Création de personnage / Nom", "Veuillez entrer un nom pour votre de personnage de la forme Prénom_Nom.", false, "Confirmer", "Retour"); nameDialog.Response += (sender, eventArg) => { if (eventArg.DialogButton == DialogButton.Right) { menu.Show(e.Player); return; } var regex = new Regex(@"[A-Z][a-z]+_[A-Z][a-z]+([A-Z][a-z]+)*"); if (!regex.IsMatch(eventArg.InputText)) { nameDialog.Show(eventArg.Player); return; } ServerDbContext dbContext = ((GameMode)GameMode.Instance).DbContext; if (dbContext.Accounts.Where(x => x.Username == eventArg.InputText).Any() || dbContext.Characters.Where(x => x.Name == eventArg.InputText).Any()) // if Account or Character already exist with this name { nameDialog.Show(eventArg.Player); return; } e.ParentData["name"] = eventArg.InputText; nameItem.Name = Color.Green + "Nom"; menu.Show(e.Player); }; nameDialog.Show(e.Player); }
public static Phone GivePhone(Player sender, Player target) { if (!sender.AccountData.HavePerm("admin.cmds.give.phone")) { throw new Exception("Vous n'avez pas les permissions pour cela."); } Phone phone = PhoneHelper.CreatePhone(); if (PhoneHelper.GetDefaultPhone(target.ActiveCharacter) == null) { phone.DefaultPhone = true; } try { InventoryHelper.AddItemToCharacter(target.ActiveCharacter, phone); ServerDbContext dbContext = ((GameMode)GameMode.Instance).DbContext; dbContext.SaveChanges(); return(phone); } catch { PhoneHelper.DeletePhone(phone); throw new Exception("Le téléphone n'a pas pu être ajouté à l'utilisateur."); } }
public PlayerCharacterChoice(Player player) { this.player = player; ServerDbContext dbContext = ((GameMode)GameMode.Instance).DbContext; playerChars = dbContext.Characters.Select(c => c).Where(c => c.Account == player.AccountData).ToList(); if (playerChars.Count == 0) { charCreationMenu = new PlayerCharacterCreation(); } else { charList = new ListDialog("Choix de personnage", "Confirmer", "Quitter"); charList.Response += ChoiceResponse; foreach (Character chr in playerChars) { charList.AddItem(chr.Name + " (Niveau " + chr.Level + " - " + Utils.SexUtils.SexToString(chr.Sex) + " de " + chr.Age + " ans)"); } if (playerChars.Count < SemiRP.Constants.MAX_CHARACTERS) { charList.AddItem(Color.DarkGray + "Créer un autre personnage..."); } } }
public PointStealTask(ServerDbContext gameDbContext, long pointId, long targetPointId, long quantity) { _gameDbContext = gameDbContext; _pointId = pointId; _targetPointId = targetPointId; _quantity = quantity; }
public void Execute() { this.queryParameters = FormQueryParametersDictionary(this.parameters); ServerDbContext server; DbCommand command; DbDataReader reader; using (server = new ServerDbContext()) { using (command = server.Database.Connection.CreateCommand()) { server.Database.Connection.Open(); this.AddParametersToQuery(ref command, query, this.queryParameters); command.CommandText = query; using (reader = command.ExecuteReader()) { this.Result = this.FormViewDataTable(reader).ToList(); } } } }
public static short AddPerm(PermissionSet permSet, string permname) { ServerDbContext dbContext = ((GameMode)GameMode.Instance).DbContext; dbContext.PermissionSets.Attach(permSet); if (!dbContext.Permissions.Any(p => p.Name == permname)) { return(1); } if (permSet.PermissionsSetPermission.Select(p => p.Permission).Any(p => p.Name == permname)) { return(2); } var perm = dbContext.Permissions.Single(p => p.Name == permname); if (perm.ChildPermissions == null || perm.ChildPermissions.Count == 0) { permSet.PermissionsSetPermission.Add(new PermissionSetPermission(permSet, perm)); } else { AddPerm_Rec(permSet, perm); } dbContext.SaveChanges(); return(0); }
public static List <string> ListAccountPermChildren(Account account, string permname) { List <string> result = new List <string>(); ServerDbContext dbContext = ((GameMode)GameMode.Instance).DbContext; dbContext.Accounts.Attach(account); if (!account.GetPerms().Any(p => p.Name == permname)) { return(result); } var perm = account.GetPerms().Where(p => p.Name == permname).First(); result.Add(permname); if (perm.ChildPermissions != null) { foreach (Permission child in perm.ChildPermissions) { result.AddRange(ListAccountPermChildren(account, child.Name)); } } return(result); }
public static short RemovePerm(PermissionSet permSet, string permname) { ServerDbContext dbContext = ((GameMode)GameMode.Instance).DbContext; dbContext.PermissionSets.Attach(permSet); if (!dbContext.Permissions.Any(p => p.Name == permname)) { return(1); } var perm = dbContext.Permissions.Single(p => p.Name == permname); if (perm.ChildPermissions == null || perm.ChildPermissions.Count == 0) { if (!permSet.PermissionsSetPermission.Select(p => p.Permission).Any(p => p.Name == permname)) { return(2); } var permSetPerm = dbContext.PermissionSetPermissions.Where(p => p.PermissionId == perm.Id && p.PermissionSetId == permSet.Id).SingleOrDefault(); permSet.PermissionsSetPermission.Remove(permSetPerm); } else { RemovePerm_Rec(permSet, perm, dbContext); } dbContext.SaveChanges(); return(0); }
public static void PutItemOnGround(Player player) { if (player.ActiveCharacter.ItemInHand == null) { throw new Exception("Aucun objet en main."); } if (player.ActiveCharacter.ItemInHand.ModelId == -1) { throw new Exception("Cet objet n'est pas posable."); } Item item = player.ActiveCharacter.ItemInHand; if (item is Gun) { player.SetArmedWeapon(((Gun)item).idWeapon); item.Quantity = player.WeaponAmmo; } Vector3 position = new Vector3(player.Position.X, player.Position.Y, player.Position.Z - 0.9); Vector3 rotation = new Vector3(); if (item is Gun) { rotation = new Vector3(90, 0, 0); } else { rotation = new Vector3(0, 0, 0); } item.SpawnLocation = new SpawnLocation(position, rotation, player.Interior, player.VirtualWorld); item.DynamicObject = new DynamicObject(item.ModelId, item.SpawnLocation.Position, item.SpawnLocation.Rotation, item.SpawnLocation.VirtualWorld, item.SpawnLocation.Interior); ServerDbContext dbContext = ((GameMode)GameMode.Instance).DbContext; dbContext.SaveChanges(); }
public static void DeleteItem(Item item) { ServerDbContext dbContext = ((GameMode)GameMode.Instance).DbContext; dbContext.Items.Remove(item); dbContext.SaveChanges(); }
// Запуск сервера public Server() { //Подключаем базу данныъ using (db = new ServerDbContext()) { // Создаем "слушателя" для указанного порта Listener = new HttpListener(); #if DEBUG Listener.Prefixes.Add($"http://+:80/"); #else Listener.Prefixes.Add("http://127.0.0.1/"); #endif // Запускаем его Listener.Start(); Console.WriteLine($"Server is run"); // В бесконечном цикле while (true) { // Принимаем новых клиентов Console.WriteLine($"Waiting connect"); HttpListenerContext context = Listener.GetContext(); //Создаем поток Thread Thread = new Thread(new ParameterizedThreadStart(ClientThread)); // И запускаем этот поток, передавая ему принятого клиента Thread.Start(context); } } }
public AcceptanceTestController() { context = new ServerDbContext(); repository = new AcceptanceTestRepository(context); userStoryRepository = new UserStoryRepository(context); service = new AcceptanceTestService(repository, userStoryRepository); }
public void FormDocument() { string fullQuery = unitOfWork .SqlQueries .Get(queryId) .SqlQueryContent; this.queryParameters = FormQueryParametersDictionary(this.parameters); List <string> queries = this.SplitQueryIntoPieces(fullQuery); this.CreateFile("csv"); ServerDbContext server; DbCommand command; DbDataReader reader; StreamWriter writer; using (server = new ServerDbContext()) { foreach (string query in queries) { using (command = server.Database.Connection.CreateCommand()) { server.Database.Connection.Open(); this.AddParametersToQuery(ref command, query, queryParameters); command.CommandText = query; using (reader = command.ExecuteReader()) { using (writer = new StreamWriter(this.FilePath, true, Encoding.UTF8)) { while (reader.Read()) { for (int i = 0; i < reader.FieldCount; i++) { string value = reader[i].ToString(); value = this.WrapItem(value); if (i != (reader.FieldCount - 1)) { writer.Write(value + ","); } else { writer.Write(value); } } writer.WriteLine(); } writer.Close(); } } server.Database.Connection.Close(); } } } }
public RepositoryTest() { var dbOption = new DbContextOptionsBuilder <ServerDbContext>() .UseSqlServer("Server=tcp:mvpwork01,1433;Initial Catalog=AuthServer;Persist Security Info=False;User ID=authadmin;Password=Password1;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=True;Connection Timeout=30") .Options; serverDbContext = new ServerDbContext(dbOption); repository = new Repository(serverDbContext); }
public MyAuthenticationHandler(IOptionsMonitor <MyAuthenticationOptions> options, ILoggerFactory loggerFactory, UrlEncoder encoder, ISystemClock clock, ServerDbContext database) : base( options, loggerFactory, encoder, clock) { _dbConnection = database; _logger = loggerFactory.CreateLogger <MyAuthenticationHandler>(); }
public NodeDALTest() { // create in-memory DB just for this test var dbOptions = new DbContextOptionsBuilder <ServerDbContext>().UseInMemoryDatabase("UnitTests").Options; _dbContext = new ServerDbContext(dbOptions); // this is important, in-mempry DB exists for the whole lifetime of the process _dbContext.Database.EnsureDeleted(); _dal = new NodeDAL(_dbContext); }
public void Show() { if (charCreationMenu != null) { charCreationMenu.GetMenu().Ended += (sender, e) => { if (!(e.Data.ContainsKey("name") && e.Data.ContainsKey("age") && e.Data.ContainsKey("sex"))) { charCreationMenu.Show(player); return; } ServerDbContext dbContext = ((GameMode)GameMode.Instance).DbContext; dbContext.Accounts.Attach(player.AccountData); SpawnLocation chrSpawn = new SpawnLocation(); chrSpawn.Interior = 0; chrSpawn.VirtualWorld = 0; chrSpawn.X = 1762.1357f; chrSpawn.Y = -1862.8958f; chrSpawn.Z = 13.5757f; chrSpawn.RotX = 0f; chrSpawn.RotY = 0f; chrSpawn.RotZ = 269.4686f; Inventory inv = new Inventory(); inv.MaxSpace = Constants.CHARACTER_INVENTORY_SIZE; Character chr = new Character(); chr.Account = player.AccountData; chr.Name = (string)e.Data["name"]; chr.Age = (uint)e.Data["age"]; chr.Sex = (Character.CharSex)e.Data["sex"]; chr.Skin = 26; chr.SpawnLocation = chrSpawn; chr.Inventory = inv; chr.PermsSet = new PermissionSet(); chr.GroupOwner = new List <Group>(); chr.GroupRanks = new List <GroupRank>(); chr.BuildingOwner = new List <Building>(); player.ActiveCharacter = chr; dbContext.Add(chr); dbContext.SaveChanges(); player.SpawnCharacter(); }; charCreationMenu.Show(player); return; } charList.Show(player); }
public static void DeletePhone(Phone phone) { if (phone == null) { return; } ServerDbContext dbContext = ((GameMode)GameMode.Instance).DbContext; dbContext.Phones.Remove(phone); dbContext.SaveChanges(); }
public static void SaveGunInHand(Player player) { if (!(player.ActiveCharacter.ItemInHand is Gun)) { throw new Exception("L'objet en main n'est pas une arme"); } player.ActiveCharacter.ItemInHand.Quantity = player.WeaponAmmo; ServerDbContext dbContext = ((GameMode)GameMode.Instance).DbContext; dbContext.SaveChanges(); }
public static void RemoveItemFromPlayerHand(Player player) { if (player.ActiveCharacter.ItemInHand == null) { throw new Exception("Aucun objet dans les mains."); } player.ActiveCharacter.ItemInHand = null; player.ResetWeapons(); ServerDbContext dbContext = ((GameMode)GameMode.Instance).DbContext; dbContext.SaveChanges(); }
public static Item RemoveItemFromGround(Player player) { Item item = GetNearestItemOfCharacter(player.ActiveCharacter); ItemIsCloseEnoughOfPlayer(player, item); item.SpawnLocation = null; item.DynamicObject.Dispose(); item.DynamicObject = null; ServerDbContext dbContext = ((GameMode)GameMode.Instance).DbContext; dbContext.SaveChanges(); return(item); }
public static void RemoveContactFromPhoneBook(String name, Phone phone) { if (phone.PhoneBook.RemoveAll(x => x.Name == name) > 0) { ServerDbContext dbContext = ((GameMode)GameMode.Instance).DbContext; dbContext.SaveChanges(); return; } else { throw new Exception("Le contact n'a pas été trouvé."); } }
public static void BorrowVehicle(Vehicle vehicle, Player borrower) { if (vehicle.Data.Borrowers.Select(b => b.Borrower).Any(b => b == borrower.ActiveCharacter)) { throw new Exception("Ce joueur a déjà emprunté ce véhicule."); } vehicle.Data.Borrowers.Add(new VehicleDataBorrower(vehicle.Data, borrower.ActiveCharacter)); ServerDbContext dbContext = ((GameMode)GameMode.Instance).DbContext; dbContext.SaveChanges(); }
public static void AddContactToPhoneBook(ContactPhone contactPhone, Phone phone) { if (phone.MaxContact >= phone.PhoneBook.Count()) { if (phone.PhoneBook.Any(x => x.Name == contactPhone.Name)) { throw new Exception("Contact avec le même nom déjà existant."); } phone.PhoneBook.Add(contactPhone); ServerDbContext dbContext = ((GameMode)GameMode.Instance).DbContext; dbContext.SaveChanges(); } }
public static List <string> ListAccountPerms(Account account) { List <string> result = new List <string>(); ServerDbContext dbContext = ((GameMode)GameMode.Instance).DbContext; dbContext.Accounts.Attach(account); foreach (Permission perm in account.GetPerms()) { result.AddRange(ListAccountPermChildren(account, perm.Name)); } return(result); }
public static void DestroyVehicle(int vehicle) { ServerDbContext dbContext = ((GameMode)GameMode.Instance).DbContext; if (!dbContext.Vehicles.Any(v => v.Id == vehicle)) { throw new Exception("La destruction du véhicule ID " + vehicle + " a échouée."); } var veh = dbContext.Vehicles.Single(v => v.Id == vehicle); dbContext.Vehicles.Remove(veh); dbContext.SaveChanges(); }
public static Phone CreatePhone() { ServerDbContext dbContext = ((GameMode)GameMode.Instance).DbContext; Random numberRandom = new Random(); String number = null; do { number = numberRandom.Next(10000, 99999).ToString(); } while (dbContext.Phones.Select(x => x).Where(x => x.Number == number).Any()); Phone phone = new Phone(number, false, false, null, false, 5); dbContext.SaveChanges(); return(phone); }
public static void UnBorrowVehicle(Vehicle vehicle, Player borrower) { if (!vehicle.Data.Borrowers.Select(b => b.Borrower).Any(b => b == borrower.ActiveCharacter)) { throw new Exception("Ce joueur n'emprunte pas ce véhicule."); } var vDataBorrower = vehicle.Data.Borrowers.Where(b => b.Borrower == borrower.ActiveCharacter).First(); vehicle.Data.Borrowers.Remove(vDataBorrower); ServerDbContext dbContext = ((GameMode)GameMode.Instance).DbContext; dbContext.SaveChanges(); }