private void UpdateItemInDB(ItemEntity item) { using (var db = new DataBase.AppContext()) { var md = db.Items.Where(x => x.Id == item.ItemID).FirstOrDefault(); md.OwnerId = item.OwnerID; md.Type = item.ItemType; md.Amount = item.ItemAmount; md.Slot = item.InvenrorySlot; db.SaveChanges(); } /* * string query = $"" + * $"UPDATE `items` SET " + * $"`owner_id` = '{item.OwnerID}', " + * $"`item_type` = '{item.ItemType}', " + * $"`item_amount` = '{item.ItemAmount}'," + * $"`inventory_slot` = '{item.InvenrorySlot}' " + * $"WHERE `item_id` = '{item.ItemID}'"; * new MySqlConnector().RequestExecuteNonQuery(query); */ }
public void LoadPlayerItemsFromDB(Player player, int playerDbId) { try { using (var db = new DataBase.AppContext()) { var mds = db.Items.Where(x => x.OwnerId == playerDbId).ToList(); if (mds.Any()) { foreach (var i in mds) { ItemsList.Add(new ItemEntity(i.Id, i.OwnerId, i.Type, i.Amount, i.Slot)); } NAPI.Util.ConsoleOutput($"[{playerDbId}]: Загружено {mds.Count} предметов."); } else { NAPI.Util.ConsoleOutput($"[Ахтунг]: Предметы для игрока {playerDbId} не найдены в базе данных!"); } } } catch (Exception e) { NAPI.Util.ConsoleOutput(e.ToString()); } }
public void CMD_hdl(Player client, int houseid) { if (!HouseList.Exists(x => x.HouseID == houseid)) { client.SendChatMessage("Дом с таким ID не найден!"); return; } House h = HouseList.Where(x => x.HouseID == houseid).First(); h.HouseColShape.Delete(); h.HouseMarker.Delete(); h.HouseBlip.Delete(); h.HouseText.Delete(); HouseList.Remove(h); // new MySqlConnector().RequestExecuteNonQuery($"DELETE FROM house WHERE h_id = {houseid}"); using (DataBase.AppContext db = new DataBase.AppContext()) { HouseModel md = new HouseModel() { Id = houseid }; db.House.Attach(md); db.House.Remove(md); db.SaveChanges(); } client.SendChatMessage($"Дом {houseid} успешно был удален!"); }
public void SetCurrentIP(string ip) { //new DBConnection.MySqlConnector().RequestExecuteNonQuery($"UPDATE `accounts` SET `p_lastip` = '{ip}' WHERE `p_id` = '{GetDbID()}'"); using (DataBase.AppContext db = new DataBase.AppContext()) { db.Accounts.Where(x => x.Id == GetDbID()).FirstOrDefault().LastIP = ip; db.SaveChanges(); } player.SetData <string>(EntityData.PLAYER_IP, ip); }
public void AddToPayCheck(double money, string reason = null) { double paycheck = Math.Round(GetPayCheck() + money, 2); //new DBConnection.MySqlConnector().RequestExecuteNonQuery($"UPDATE `accounts` SET `p_paycheck` = '{paycheck}' WHERE `p_id` = '{GetDbID()}'"); using (DataBase.AppContext db = new DataBase.AppContext()) { db.Accounts.Where(x => x.Id == GetDbID()).FirstOrDefault().PayCheck = paycheck; db.SaveChanges(); } player.SetData <double>(EntityData.PLAYER_PAYCHECK, paycheck); }
public void SetLastJoin(string date) { //string query = $"UPDATE `accounts` SET `p_lastjoin` = '{date}' WHERE `p_id` = '{GetDbID()}'"; //new DBConnection.MySqlConnector().RequestExecuteNonQuery(query); using (DataBase.AppContext db = new DataBase.AppContext()) { db.Accounts.Where(x => x.Id == GetDbID()).FirstOrDefault().DateLastJoin = date; db.SaveChanges(); } player.SetData <string>(EntityData.PLAYER_LASTJOIN, date); }
public void GiveBankMoney(double money, string reason = null, bool updateindb = true) { player.SetData <double>(EntityData.PLAYER_BANK, Math.Round(money, 2) + (player.GetData <double>(EntityData.PLAYER_BANK))); if (updateindb) { //string query = $"UPDATE `accounts` SET `p_bank` = '{Convert.ToString(GetBankMoney()).Replace(',', '.')}' WHERE `p_id` = '{GetDbID()}'"; //new DBConnection.MySqlConnector().RequestExecuteNonQuery(query); using (DataBase.AppContext db = new DataBase.AppContext()) { db.Accounts.Where(x => x.Id == GetDbID()).FirstOrDefault().Bank = GetBankMoney(); db.SaveChanges(); } } new Inventory(player).UpdateBar(); Utils.UtilityFuncs.UpdatePlayerHud(player); }
public ItemEntity CreateItem(string type, int amount) { using (DataBase.AppContext db = new DataBase.AppContext()) { var md = new ItemModel(); md.Type = type; md.Amount = amount; db.Items.Add(md); db.SaveChanges(); ItemEntity item = new ItemEntity(md.Id, md.OwnerId, md.Type, md.Amount, md.Slot); ItemsList.Add(item); return(item); } }
public void DeleteItem(int itemID) { ItemEntity item = ItemsList.Where(x => x.ItemID == itemID).FirstOrDefault(); if (item != null) { ItemsList.Remove(item); using (var db = new DataBase.AppContext()) { var md = db.Items.Where(x => x.Id == itemID).FirstOrDefault(); if (md != null) { db.Items.Remove(md); } db.SaveChanges(); } return; } NAPI.Util.ConsoleOutput($"[Item Exception]: Не удалось удалить объект (ID: {itemID}), т.к. он не был найден в списке."); }
public static void InitHouses() { using (DataBase.AppContext db = new DataBase.AppContext()) { var hs = db.House.Select(x => x).ToList(); if (!hs.Any()) { NAPI.Util.ConsoleOutput("[MySQL]: Дома не найдены."); return; } foreach (var i in hs) { House h = new House(i.Id, i.Class, i.Price, i.Rent, i.Days, i.Doors, i.Owner, new Vector3(i.EnterPointX, i.EnterPointY, i.EnterPointZ), i.EnterRotation, i.Status, i.Interior); ColShape cs = NAPI.ColShape.CreateCylinderColShape(h.HouseEnterPosition, 1.0f, 2f, dimension: 0); cs.SetData <int>("CSHouseID", h.HouseID); h.HouseColShape = cs; h.HouseMarker = NAPI.Marker.CreateMarker(1, new Vector3(h.HouseEnterPosition.X, h.HouseEnterPosition.Y, h.HouseEnterPosition.Z - 1f), new Vector3(), new Vector3(), 1.0f, new Color(139, 201, 131, 100)); h.HouseBlip = NAPI.Blip.CreateBlip(h.HouseStatus == true ? 375 : 374, h.HouseEnterPosition, 1f, 2, drawDistance: 15.0f, dimension: 0, shortRange: true, name: $"Дом № {h.HouseID}"); h.HouseText = NAPI.TextLabel.CreateTextLabel($"Номер дома: {h.HouseID}\nВладелец: Нет\nЦена: {h.HousePrice}\nКласс: {h.HouseClass}\nСтатус: {h.HouseStatus}", h.HouseEnterPosition, 3f, 3f, 10, new Color(255, 255, 255)); HouseList.Add(h); } NAPI.Util.ConsoleOutput("[Houses]: Домов загружено: {0}", hs.Count); } /* * using (MySqlConnection con = new MySqlConnector().GetDBConnection()) * { * con.Open(); * * int cc = 0; * MySqlCommand cmd = new MySqlCommand("SELECT * FROM house", con); * * using (MySqlDataReader read = cmd.ExecuteReader()) * { * if (!read.HasRows) * NAPI.Util.ConsoleOutput("[MySQL]: Дома не найдены."); * * else * { * while (read.Read()) * { * cc++; * * House hd = new House(); * * for (int i = 0; i < read.FieldCount; i++) * { * hd.HouseID = (int)read["h_id"]; * hd.HouseClass = (int)read["h_class"]; * hd.HousePrice = (int)read["h_price"]; * hd.HouseRent = (int)read["h_price"] * (1 / 100); * hd.HouseOwner = (string)read["h_owner"]; * hd.HouseDays = (int)read["h_days"]; * hd.HouseStatus = Convert.ToString(read["h_owner"]).Contains("None") ? false : true; * hd.HouseDoors = (bool)read["h_lock"]; * hd.HouseInterior = (int)read["h_interior"]; * hd.HouseEnterPosition = new Vector3((float)read["h_enterposX"], (float)read["h_enterposY"], (float)read["h_enterposZ"]); * hd.HouseEnterRotation = (float)read["h_enterposR"]; * } * * ColShape cs = NAPI.ColShape.CreateCylinderColShape(hd.HouseEnterPosition, 1.0f, 2f, dimension: 0); * cs.SetData<int>("CSHouseID", hd.HouseID); * hd.HouseColShape = cs; * hd.HouseMarker = NAPI.Marker.CreateMarker(1, new Vector3(hd.HouseEnterPosition.X, hd.HouseEnterPosition.Y, hd.HouseEnterPosition.Z - 1f), new Vector3(), new Vector3(), 1.0f, new Color(139, 201, 131, 100)); * hd.HouseBlip = NAPI.Blip.CreateBlip(hd.HouseStatus == true ? 375 : 374, hd.HouseEnterPosition, 1f, 2, drawDistance: 15.0f, dimension: 0, shortRange: true, name: $"Дом № {hd.HouseID}"); * hd.HouseText = NAPI.TextLabel.CreateTextLabel($"House ID: {hd.HouseID}\nHouse Owner: None\nHouse Price: {hd.HousePrice}\nHouse Class: {hd.HouseClass}\nHouse Status: {hd.HouseStatus}", hd.HouseEnterPosition, 3f, 3f, 10, new Color(255, 255, 255)); * * HouseList.Add(hd); * } * * NAPI.Util.ConsoleOutput("[MySQL]: Домов загружено: {0} | Домов в списке: {1}", cc, HouseList.Count); * } * read.Close(); * } * con.Close(); * } */ }
public void CreateHouse(Vector3 HousePosition, float rotation, int HousePrice, int HouseClass) { int tempID = -1; HouseList.Sort(); if (!HouseList.Exists(x => x.HouseID == 1)) { tempID = 1; } else { for (int i = 0; i < HouseList.Count; i++) { if (i != HouseList.Count - 1) { if ((HouseList[i].HouseID + 1) != HouseList[i + 1].HouseID) { tempID = HouseList[i].HouseID + 1; break; } } else { tempID = HouseList[i].HouseID + 1; } } } HouseList.Sort(); ColShape tempShape = NAPI.ColShape.CreateCylinderColShape(HousePosition, 1.0f, 2f, dimension: 0); tempShape.SetData <int>("CSHouseID", tempID); House h = new House() { HouseID = tempID, HouseClass = HouseClass, HousePrice = HousePrice, HouseRent = HousePrice * (1 / 100), HouseOwner = "None", HouseEnterPosition = HousePosition, HouseEnterRotation = rotation, HouseDays = 0, HouseStatus = false, HouseDoors = false, HouseInterior = 0, HouseColShape = tempShape, HouseMarker = NAPI.Marker.CreateMarker(1, new Vector3(HousePosition.X, HousePosition.Y, HousePosition.Z - 1f), new Vector3(), new Vector3(), 1.0f, new Color(139, 201, 131, 100)), HouseBlip = NAPI.Blip.CreateBlip(374, HousePosition, 1f, 2, drawDistance: 15.0f, dimension: 0, shortRange: true, name: $"Дом №{tempID}"), HouseText = NAPI.TextLabel.CreateTextLabel($"House ID: {tempID}\nHouse Owner: None\nHouse Price: {HousePrice}\nHouse Class: {HouseClass}\nHouse Status: {HouseStatus}", HousePosition, 3f, 3f, 10, new Color(255, 255, 255)) }; HouseList.Add(h); using (DataBase.AppContext db = new DataBase.AppContext()) { HouseModel md = new HouseModel(); md.Owner = h.HouseOwner; md.Days = h.HouseDays; md.Doors = h.HouseDoors; md.Price = h.HousePrice; md.Class = h.HouseClass; md.Interior = h.HouseInterior; md.EnterPointX = h.HouseEnterPosition.X; md.EnterPointY = h.HouseEnterPosition.Y; md.EnterPointZ = h.HouseEnterPosition.Z; md.EnterRotation = h.HouseEnterRotation; db.House.Add(md); db.SaveChanges(); } /* * using(MySqlConnection con = new MySqlConnector().GetDBConnection()) * { * con.Open(); * string query = * $"INSERT INTO `house`(`h_id`, `h_owner`, `h_days`, `h_lock`, `h_price`, `h_class`, `h_interior`, `h_enterposX`, `h_enterposY`, `h_enterposZ`, `h_enterposR`) " + * $"VALUES ('{h.HouseID}', '{h.HouseOwner}', '{h.HouseDays}', '{Convert.ToInt32(h.HouseDoors)}', '{h.HousePrice}', '{h.HouseClass}', '{h.HouseInterior}'," + * $"'{Math.Round(h.HouseEnterPosition.X, 4).ToString().Replace(",",".")}', " + * $"'{Math.Round(h.HouseEnterPosition.Y, 4).ToString().Replace(",", ".")}', " + * $"'{Math.Round(h.HouseEnterPosition.Z, 4).ToString().Replace(",", ".")}', " + * $"'{Math.Round(h.HouseEnterRotation, 4).ToString().Replace(",", ".")}')"; * MySqlCommand cmd = new MySqlCommand(query, con); * cmd.ExecuteNonQuery(); * } */ }
public void GetAccountFromBD(Player player, int type, string login, string password, string email) { using (DataBase.AppContext db = new DataBase.AppContext()) { var authData = db.Accounts.Where(x => x.Login == login).FirstOrDefault(); switch (type) { case 0: // auth { if (authData == null) { NAPI.ClientEvent.TriggerClientEvent(player, "authSendError", "Ошибка: Данный аккаунт не зарегистрирован!"); break; } else if (authData.Password != password) { NAPI.ClientEvent.TriggerClientEvent(player, "authSendError", "Ошибка: Неверный пароль!"); break; } LogInPlayerAccount(player, authData); break; } case 1: // reg { if (authData != null) { NAPI.ClientEvent.TriggerClientEvent(player, "authSendError", "Ошибка: Данный аккаунт уже зарегистрирован!"); break; } player.SetData <string>("R_TempLogin", login); player.SetData <string>("R_TempPassword", password); player.SetData <string>("R_TempMail", email); NAPI.ClientEvent.TriggerClientEvent(player, "destroyAuthBrowser"); JumpToCustomizeStep(player); break; } } } /* * try * { * MySqlConnection con = new MySqlConnector().GetDBConnection(); * con.Open(); * * MySqlCommand cmd = new MySqlCommand("SELECT * FROM `accounts` WHERE `p_login` = '" + args[1] + "'", con); * MySqlDataReader read = cmd.ExecuteReader(); * * * switch (args[0]) * { * case 0: // auth * { * AuthData auth = new AuthData(); * * if (!read.HasRows) * { * NAPI.ClientEvent.TriggerClientEvent(client, "authSendError", "Ошибка: Данный аккаунт не зарегистрирован!"); * read.Close(); * break; * } * * while (read.Read()) * { * auth.dbID = (int)read["p_id"]; * auth.Login = (string)read["p_login"]; * auth.Password = (string)read["p_password"]; * auth.IP = (string)read["p_ip"]; * auth.Mail = (string)read["p_mail"]; * auth.LVL = (int)read["p_lvl"]; * auth.Cash = (double)read["p_money"]; * auth.BankMoney = (double)read["p_bank"]; * auth.Age = (int)read["p_age"]; * auth.Name = (string)read["p_name"]; * auth.SocialName = (string)read["p_socialclub"]; * auth.DateReg = (string)read["p_datereg"]; * auth.PayCheck = (double)read["p_paycheck"]; * auth.Satiety = (int)read["p_satiety"]; * auth.Thirst = (int)read["p_thirst"]; * * client.SetData<object>("pCustomize", read["p_customize"]); * client.SetData<object>("pClothes", read["p_clothes"]); * } * read.Close(); * * if (auth.Password != args[2].ToString()) * { * NAPI.ClientEvent.TriggerClientEvent(client, "authSendError", "Ошибка: Неверный пароль!"); * break; * } * * LogInPlayerAccount(client, auth); * * break; * } * case 1: // reg * { * if (read.HasRows) * { * NAPI.ClientEvent.TriggerClientEvent(client, "authSendError", "Ошибка: Данный аккаунт уже зарегистрирован!"); * read.Close(); * break; * } * read.Close(); * * client.SetData<string>("R_TempLogin", (string)args[1]); * client.SetData<string>("R_TempPassword", (string)args[2]); * client.SetData<string>("R_TempMail", (string)args[3]); * * NAPI.ClientEvent.TriggerClientEvent(client, "destroyAuthBrowser"); * * JumpToCustomizeStep(client); * * break; * } * } * con.Close(); * * } * catch (Exception e) * { * NAPI.Util.ConsoleOutput($"[MySQL Error (#{++exceptionCount})]: " + e.Message); * NAPI.ClientEvent.TriggerClientEvent(client, "authSendError", $"Ошибка: MySQL Exception! Обратитесь к администрации сервера. (#{exceptionCount})"); * } */ }
public void EndPlayerCustomize(Player player, string basedata, string customize, string clothes) { using (DataBase.AppContext db = new DataBase.AppContext()) { dynamic based = NAPI.Util.FromJson(basedata); dynamic cust = NAPI.Util.FromJson(customize); PlayerModel md = new PlayerModel(); md.Name = $"{based["name"]} {based["subname"]}"; md.SClubName = player.SocialClubName; md.SClubId = player.SocialClubId; md.Serial = player.Serial; md.Login = player.GetData <string>("R_TempLogin"); md.Password = player.GetData <string>("R_TempPassword"); md.Mail = player.GetData <string>("R_TempMail"); md.RegIP = player.Address; md.DateReg = DateTime.Now.ToString(); md.Age = (int)based["old"]; md.Sex = (bool)cust["sex"]; md.Customize = customize; md.Clothes = clothes; db.Accounts.Add(md); db.SaveChanges(); NAPI.ClientEvent.TriggerClientEvent(player, "disableCustomize"); LogInPlayerAccount(player, md); } /* * try * { * using(MySqlConnection con = new MySqlConnector().GetDBConnection()) * { * con.Open(); * * dynamic based = NAPI.Util.FromJson(basedata); * dynamic cust = NAPI.Util.FromJson(customize); * * string name = $"{based["name"]} {based["subname"]}"; * string sc = client.SocialClubName; * * string currentTime = DateTime.Now.ToString(); * * if (sc == null) * sc = "-"; * * string query = "INSERT INTO `accounts` (`p_login`, `p_socialclub`, `p_password`, `p_ip`, `p_mail`, `p_name`, `p_age`, `p_sex`, `p_customize`, `p_clothes`, `p_datereg`) * VALUES ('" + client.GetData<string>("R_TempLogin") + "', '" + sc + "', '" + client.GetData<string>("R_TempPassword") + "', '" + client.Address + "', '" + client.GetData<string>("R_TempMail") + "', '" + name + "', '" + based["old"] + "', '" + (int)cust["sex"] + "', '" + customize + "', '" + clothes + "', '" + currentTime + "')"; * MySqlCommand cmd = new MySqlCommand(query, con); * cmd.ExecuteNonQuery(); * * cmd = new MySqlCommand("SELECT * FROM `accounts` WHERE `p_id` = LAST_INSERT_ID()", con); * MySqlDataReader read = cmd.ExecuteReader(); * * AuthData auth = new AuthData(); * * while (read.Read()) * { * auth.dbID = (int)read["p_id"]; * auth.Login = (string)read["p_login"]; * auth.Password = (string)read["p_password"]; * auth.IP = (string)read["p_ip"]; * auth.Mail = (string)read["p_mail"]; * auth.LVL = (int)read["p_lvl"]; * auth.Cash = (double)read["p_money"]; * auth.BankMoney = (double)read["p_bank"]; * auth.Age = (int)read["p_age"]; * auth.Name = (string)read["p_name"]; * auth.SocialName = (string)read["p_socialclub"]; * auth.DateReg = (string)read["p_datereg"]; * auth.PayCheck = (double)read["p_paycheck"]; * auth.Satiety = (int)read["p_satiety"]; * auth.Thirst = (int)read["p_thirst"]; * * client.SetData<object>("pCustomize", read["p_customize"]); * client.SetData<object>("pClothes", read["p_clothes"]); * } * * NAPI.ClientEvent.TriggerClientEvent(client, "disableCustomize"); * LogInPlayerAccount(client, auth); * * read.Close(); * con.Close(); * } * } * catch (Exception e) { NAPI.Util.ConsoleOutput(e.ToString()); } */ }