9
3

HousingDB.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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_coins, int32 amount_status) {
  27. Query query;
  28. string update = string("UPDATE character_houses set escrow_coins = %llu, escrow_status = %u where house_id = %u and instance_id = %u");
  29. query.RunQuery2(Q_UPDATE, update.c_str(), amount_coins, amount_status, 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 limit 255", 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. }
  68. void WorldDatabase::LoadHistory(PlayerHouse* ph)
  69. {
  70. if (!ph)
  71. return;
  72. ph->history.clear();
  73. Query query;
  74. MYSQL_ROW row;
  75. MYSQL_RES* result = query.RunQuery2(Q_SELECT, "select timestamp, amount, status, reason, name, pos_flag from character_house_history where house_id = %u and instance_id = %u order by timestamp asc limit 255", ph->house_id, ph->instance_id);
  76. if (result && mysql_num_rows(result) > 0) {
  77. while ((row = mysql_fetch_row(result))) {
  78. HouseHistory h;
  79. h.timestamp = atoul(row[0]);
  80. int64 outVal = strtoull(row[1], NULL, 0);
  81. h.amount = outVal;
  82. h.status = atoul(row[2]);
  83. h.reason = string(row[3]);
  84. h.name = string(row[4]);
  85. h.pos_flag = atoul(row[5]);
  86. ph->history.push_back(h);
  87. }
  88. }
  89. }
  90. void WorldDatabase::AddHistory(PlayerHouse* house, char* name, char* reason, int32 timestamp, int64 amount, int32 status, int8 pos_flag)
  91. {
  92. if (!house)
  93. return;
  94. HouseHistory h(Timer::GetUnixTimeStamp(), amount, string(name), string(reason), status, pos_flag);
  95. house->history.push_back(h);
  96. Query query;
  97. string insert = string("INSERT INTO character_house_history (timestamp, house_id, instance_id, name, amount, status, reason, pos_flag) VALUES (%u, %u, %u, '%s', %llu, %u, '%s', %u) ");
  98. query.RunQuery2(Q_INSERT, insert.c_str(), timestamp, house->house_id, house->instance_id, name, amount, status, reason, pos_flag);
  99. }