HousingDB.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "../WorldDatabase.h"
  2. #include "../World.h"
  3. extern World world;
  4. void WorldDatabase::LoadHouseZones() {
  5. Query query;
  6. MYSQL_ROW row;
  7. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT * FROM `houses`");
  8. if (result && mysql_num_rows(result) > 0) {
  9. while ((row = mysql_fetch_row(result))) {
  10. world.AddHouseZone(atoul(row[0]), row[1], atoi64(row[2]), atoul(row[3]), atoi64(row[4]), atoul(row[5]), atoi(row[6]), atoi(row[7]), atoi(row[8]), atoul(row[9]), atoul(row[10]), atof(row[11]), atof(row[12]), atof(row[13]), atof(row[14]));
  11. }
  12. }
  13. }
  14. int64 WorldDatabase::AddPlayerHouse(int32 char_id, int32 house_id, int32 instance_id, int32 upkeep_due) {
  15. Query query;
  16. string insert = string("INSERT INTO character_houses (char_id, house_id, instance_id, upkeep_due) VALUES (%u, %u, %u, %u) ");
  17. query.RunQuery2(Q_INSERT, insert.c_str(), char_id, house_id, instance_id, upkeep_due);
  18. int64 unique_id = query.GetLastInsertedID();
  19. return unique_id;
  20. }
  21. void WorldDatabase::SetHouseUpkeepDue(int32 char_id, int32 house_id, int32 instance_id, int32 upkeep_due) {
  22. Query query;
  23. string update = string("UPDATE character_houses set upkeep_due=%u where char_id = %u and house_id = %u and instance_id = %u");
  24. query.RunQuery2(Q_UPDATE, update.c_str(), upkeep_due, char_id, house_id, instance_id);
  25. }
  26. void WorldDatabase::UpdateHouseEscrow(int32 house_id, int32 instance_id, int64 amount) {
  27. Query query;
  28. string update = string("UPDATE character_houses set escrow_coins = %I64u where house_id = %u and instance_id = %u");
  29. query.RunQuery2(Q_UPDATE, update.c_str(), amount, house_id, instance_id);
  30. }
  31. void WorldDatabase::RemovePlayerHouse(int32 char_id, int32 house_id) {
  32. }
  33. void WorldDatabase::LoadPlayerHouses() {
  34. Query query;
  35. MYSQL_ROW row;
  36. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "SELECT h.id, h.char_id, h.house_id, h.instance_id, h.upkeep_due, h.escrow_coins, h.escrow_status, c.name FROM character_houses h, characters c WHERE h.char_id = c.id");
  37. if (result && mysql_num_rows(result) > 0) {
  38. while ((row = mysql_fetch_row(result))) {
  39. world.AddPlayerHouse(atoul(row[1]), atoul(row[2]), atoi64(row[0]), atoul(row[3]), atoul(row[4]), atoi64(row[5]), atoul(row[6]), row[7]);
  40. }
  41. }
  42. }
  43. void WorldDatabase::LoadDeposits(PlayerHouse* ph)
  44. {
  45. if (!ph)
  46. return;
  47. ph->deposits.clear();
  48. ph->depositsMap.clear();
  49. Query query;
  50. MYSQL_ROW row;
  51. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "select timestamp, amount, last_amount, status, last_status, name from character_house_deposits where house_id = %u and instance_id = %u order by timestamp asc", ph->house_id, ph->instance_id);
  52. if (result && mysql_num_rows(result) > 0) {
  53. while ((row = mysql_fetch_row(result))) {
  54. Deposit d;
  55. d.timestamp = atoul(row[0]);
  56. int64 outVal = strtoull(row[1], NULL, 0);
  57. d.amount = outVal;
  58. outVal = strtoull(row[2], NULL, 0);
  59. d.last_amount = outVal;
  60. d.status = atoul(row[3]);
  61. d.last_status = atoul(row[4]);
  62. d.name = string(row[5]);
  63. ph->deposits.push_back(d);
  64. ph->depositsMap.insert(make_pair(d.name, d));
  65. }
  66. }
  67. }