LobbyDatabase.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. /*
  2. * LobbyServer.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "LobbyDatabase.h"
  12. #include "SQLiteConnection.h"
  13. void LobbyDatabase::createTables()
  14. {
  15. static const std::string createChatMessages = R"(
  16. CREATE TABLE IF NOT EXISTS chatMessages (
  17. id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  18. senderName TEXT,
  19. channelType TEXT,
  20. channelName TEXT,
  21. messageText TEXT,
  22. creationTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
  23. );
  24. )";
  25. static const std::string createTableGameRooms = R"(
  26. CREATE TABLE IF NOT EXISTS gameRooms (
  27. id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  28. roomID TEXT,
  29. hostAccountID TEXT,
  30. description TEXT NOT NULL DEFAULT '',
  31. status INTEGER NOT NULL DEFAULT 0,
  32. playerLimit INTEGER NOT NULL,
  33. creationTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
  34. );
  35. )";
  36. static const std::string createTableGameRoomPlayers = R"(
  37. CREATE TABLE IF NOT EXISTS gameRoomPlayers (
  38. id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  39. roomID TEXT,
  40. accountID TEXT
  41. );
  42. )";
  43. static const std::string createTableAccounts = R"(
  44. CREATE TABLE IF NOT EXISTS accounts (
  45. id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  46. accountID TEXT,
  47. displayName TEXT,
  48. online INTEGER NOT NULL,
  49. lastLoginTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
  50. creationTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
  51. );
  52. )";
  53. static const std::string createTableAccountCookies = R"(
  54. CREATE TABLE IF NOT EXISTS accountCookies (
  55. id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  56. accountID TEXT,
  57. cookieUUID TEXT,
  58. creationTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
  59. );
  60. )";
  61. static const std::string createTableGameRoomInvites = R"(
  62. CREATE TABLE IF NOT EXISTS gameRoomInvites (
  63. id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  64. roomID TEXT,
  65. accountID TEXT
  66. );
  67. )";
  68. database->prepare(createChatMessages)->execute();
  69. database->prepare(createTableGameRoomPlayers)->execute();
  70. database->prepare(createTableGameRooms)->execute();
  71. database->prepare(createTableAccounts)->execute();
  72. database->prepare(createTableAccountCookies)->execute();
  73. database->prepare(createTableGameRoomInvites)->execute();
  74. }
  75. void LobbyDatabase::clearOldData()
  76. {
  77. static const std::string removeActiveAccounts = R"(
  78. UPDATE accounts
  79. SET online = 0
  80. WHERE online <> 0
  81. )";
  82. //FIXME: set different status for rooms that never reached in game state
  83. static const std::string removeActiveRooms = R"(
  84. UPDATE gameRooms
  85. SET status = 5
  86. WHERE status <> 5
  87. )";
  88. database->prepare(removeActiveAccounts)->execute();
  89. database->prepare(removeActiveRooms)->execute();
  90. }
  91. void LobbyDatabase::prepareStatements()
  92. {
  93. // INSERT INTO
  94. static const std::string insertChatMessageText = R"(
  95. INSERT INTO chatMessages(senderName, messageText, channelType, channelName) VALUES( ?, ?, ?, ?);
  96. )";
  97. static const std::string insertAccountText = R"(
  98. INSERT INTO accounts(accountID, displayName, online) VALUES(?,?,0);
  99. )";
  100. static const std::string insertAccessCookieText = R"(
  101. INSERT INTO accountCookies(accountID, cookieUUID) VALUES(?,?);
  102. )";
  103. static const std::string insertGameRoomText = R"(
  104. INSERT INTO gameRooms(roomID, hostAccountID, status, playerLimit) VALUES(?, ?, 0, 8);
  105. )";
  106. static const std::string insertGameRoomPlayersText = R"(
  107. INSERT INTO gameRoomPlayers(roomID, accountID) VALUES(?,?);
  108. )";
  109. static const std::string insertGameRoomInvitesText = R"(
  110. INSERT INTO gameRoomInvites(roomID, accountID) VALUES(?,?);
  111. )";
  112. // DELETE FROM
  113. static const std::string deleteGameRoomPlayersText = R"(
  114. DELETE FROM gameRoomPlayers WHERE roomID = ? AND accountID = ?
  115. )";
  116. static const std::string deleteGameRoomInvitesText = R"(
  117. DELETE FROM gameRoomInvites WHERE roomID = ? AND accountID = ?
  118. )";
  119. // UPDATE
  120. static const std::string setAccountOnlineText = R"(
  121. UPDATE accounts
  122. SET online = ?
  123. WHERE accountID = ?
  124. )";
  125. static const std::string setGameRoomStatusText = R"(
  126. UPDATE gameRooms
  127. SET status = ?
  128. WHERE roomID = ?
  129. )";
  130. static const std::string updateAccountLoginTimeText = R"(
  131. UPDATE accounts
  132. SET lastLoginTime = CURRENT_TIMESTAMP
  133. WHERE accountID = ?
  134. )";
  135. static const std::string updateRoomDescriptionText = R"(
  136. UPDATE gameRooms
  137. SET description = ?
  138. WHERE roomID = ?
  139. )";
  140. static const std::string updateRoomPlayerLimitText = R"(
  141. UPDATE gameRooms
  142. SET playerLimit = ?
  143. WHERE roomID = ?
  144. )";
  145. // SELECT FROM
  146. static const std::string getRecentMessageHistoryText = R"(
  147. SELECT senderName, displayName, messageText, strftime('%s',CURRENT_TIMESTAMP)- strftime('%s',cm.creationTime) AS secondsElapsed
  148. FROM chatMessages cm
  149. LEFT JOIN accounts on accountID = senderName
  150. WHERE secondsElapsed < 60*60*18 AND channelType = ? AND channelName = ?
  151. ORDER BY cm.creationTime DESC
  152. LIMIT 100
  153. )";
  154. static const std::string getFullMessageHistoryText = R"(
  155. SELECT senderName, displayName, messageText, strftime('%s',CURRENT_TIMESTAMP)- strftime('%s',cm.creationTime) AS secondsElapsed
  156. FROM chatMessages cm
  157. LEFT JOIN accounts on accountID = senderName
  158. WHERE channelType = ? AND channelName = ?
  159. ORDER BY cm.creationTime DESC
  160. )";
  161. static const std::string getIdleGameRoomText = R"(
  162. SELECT roomID
  163. FROM gameRooms
  164. WHERE hostAccountID = ? AND status = 0
  165. LIMIT 1
  166. )";
  167. static const std::string getGameRoomStatusText = R"(
  168. SELECT status
  169. FROM gameRooms
  170. WHERE roomID = ?
  171. )";
  172. static const std::string getAccountGameHistoryText = R"(
  173. SELECT gr.roomID, hostAccountID, displayName, description, status, playerLimit, strftime('%s',CURRENT_TIMESTAMP)- strftime('%s',gr.creationTime) AS secondsElapsed
  174. FROM gameRoomPlayers grp
  175. LEFT JOIN gameRooms gr ON gr.roomID = grp.roomID
  176. LEFT JOIN accounts a ON gr.hostAccountID = a.accountID
  177. WHERE grp.accountID = ? AND status IN (4,5)
  178. ORDER BY secondsElapsed ASC
  179. )";
  180. static const std::string getAccountGameRoomText = R"(
  181. SELECT grp.roomID
  182. FROM gameRoomPlayers grp
  183. LEFT JOIN gameRooms gr ON gr.roomID = grp.roomID
  184. WHERE accountID = ? AND status IN (1, 2, 3)
  185. LIMIT 1
  186. )";
  187. static const std::string getActiveAccountsText = R"(
  188. SELECT accountID, displayName
  189. FROM accounts
  190. WHERE online = 1
  191. )";
  192. static const std::string getActiveGameRoomsText = R"(
  193. SELECT roomID, hostAccountID, displayName, description, status, playerLimit, strftime('%s',CURRENT_TIMESTAMP)- strftime('%s',gr.creationTime) AS secondsElapsed
  194. FROM gameRooms gr
  195. LEFT JOIN accounts a ON gr.hostAccountID = a.accountID
  196. WHERE status IN (1, 2, 3)
  197. ORDER BY secondsElapsed ASC
  198. )";
  199. static const std::string countRoomUsedSlotsText = R"(
  200. SELECT a.accountID, a.displayName
  201. FROM gameRoomPlayers grp
  202. LEFT JOIN accounts a ON a.accountID = grp.accountID
  203. WHERE roomID = ?
  204. )";
  205. static const std::string countRoomTotalSlotsText = R"(
  206. SELECT playerLimit
  207. FROM gameRooms
  208. WHERE roomID = ?
  209. )";
  210. static const std::string getAccountDisplayNameText = R"(
  211. SELECT displayName
  212. FROM accounts
  213. WHERE accountID = ?
  214. )";
  215. static const std::string isAccountCookieValidText = R"(
  216. SELECT COUNT(accountID)
  217. FROM accountCookies
  218. WHERE accountID = ? AND cookieUUID = ?
  219. )";
  220. static const std::string isGameRoomCookieValidText = R"(
  221. SELECT COUNT(roomID)
  222. FROM gameRooms
  223. LEFT JOIN accountCookies ON accountCookies.accountID = gameRooms.hostAccountID
  224. WHERE roomID = ? AND cookieUUID = ? AND strftime('%s',CURRENT_TIMESTAMP)- strftime('%s',creationTime) < ?
  225. )";
  226. static const std::string isPlayerInGameRoomText = R"(
  227. SELECT COUNT(accountID)
  228. FROM gameRoomPlayers grp
  229. LEFT JOIN gameRooms gr ON gr.roomID = grp.roomID
  230. WHERE accountID = ? AND grp.roomID = ?
  231. )";
  232. static const std::string isPlayerInAnyGameRoomText = R"(
  233. SELECT COUNT(accountID)
  234. FROM gameRoomPlayers grp
  235. LEFT JOIN gameRooms gr ON gr.roomID = grp.roomID
  236. WHERE accountID = ? AND status IN (1, 2, 3)
  237. )";
  238. static const std::string isAccountIDExistsText = R"(
  239. SELECT COUNT(accountID)
  240. FROM accounts
  241. WHERE accountID = ?
  242. )";
  243. static const std::string isAccountNameExistsText = R"(
  244. SELECT COUNT(displayName)
  245. FROM accounts
  246. WHERE displayName = ?
  247. )";
  248. insertChatMessageStatement = database->prepare(insertChatMessageText);
  249. insertAccountStatement = database->prepare(insertAccountText);
  250. insertAccessCookieStatement = database->prepare(insertAccessCookieText);
  251. insertGameRoomStatement = database->prepare(insertGameRoomText);
  252. insertGameRoomPlayersStatement = database->prepare(insertGameRoomPlayersText);
  253. insertGameRoomInvitesStatement = database->prepare(insertGameRoomInvitesText);
  254. deleteGameRoomPlayersStatement = database->prepare(deleteGameRoomPlayersText);
  255. setAccountOnlineStatement = database->prepare(setAccountOnlineText);
  256. setGameRoomStatusStatement = database->prepare(setGameRoomStatusText);
  257. updateAccountLoginTimeStatement = database->prepare(updateAccountLoginTimeText);
  258. updateRoomDescriptionStatement = database->prepare(updateRoomDescriptionText);
  259. updateRoomPlayerLimitStatement = database->prepare(updateRoomPlayerLimitText);
  260. getRecentMessageHistoryStatement = database->prepare(getRecentMessageHistoryText);
  261. getFullMessageHistoryStatement = database->prepare(getFullMessageHistoryText);
  262. getIdleGameRoomStatement = database->prepare(getIdleGameRoomText);
  263. getGameRoomStatusStatement = database->prepare(getGameRoomStatusText);
  264. getAccountGameHistoryStatement = database->prepare(getAccountGameHistoryText);
  265. getAccountGameRoomStatement = database->prepare(getAccountGameRoomText);
  266. getActiveAccountsStatement = database->prepare(getActiveAccountsText);
  267. getActiveGameRoomsStatement = database->prepare(getActiveGameRoomsText);
  268. getAccountDisplayNameStatement = database->prepare(getAccountDisplayNameText);
  269. countRoomUsedSlotsStatement = database->prepare(countRoomUsedSlotsText);
  270. countRoomTotalSlotsStatement = database->prepare(countRoomTotalSlotsText);
  271. isAccountCookieValidStatement = database->prepare(isAccountCookieValidText);
  272. isPlayerInGameRoomStatement = database->prepare(isPlayerInGameRoomText);
  273. isPlayerInAnyGameRoomStatement = database->prepare(isPlayerInAnyGameRoomText);
  274. isAccountIDExistsStatement = database->prepare(isAccountIDExistsText);
  275. isAccountNameExistsStatement = database->prepare(isAccountNameExistsText);
  276. }
  277. LobbyDatabase::~LobbyDatabase() = default;
  278. LobbyDatabase::LobbyDatabase(const boost::filesystem::path & databasePath)
  279. {
  280. database = SQLiteInstance::open(databasePath, true);
  281. createTables();
  282. clearOldData();
  283. prepareStatements();
  284. }
  285. void LobbyDatabase::insertChatMessage(const std::string & sender, const std::string & channelType, const std::string & channelName, const std::string & messageText)
  286. {
  287. insertChatMessageStatement->executeOnce(sender, messageText, channelType, channelName);
  288. }
  289. bool LobbyDatabase::isPlayerInGameRoom(const std::string & accountID)
  290. {
  291. bool result = false;
  292. isPlayerInAnyGameRoomStatement->setBinds(accountID);
  293. if(isPlayerInAnyGameRoomStatement->execute())
  294. isPlayerInAnyGameRoomStatement->getColumns(result);
  295. isPlayerInAnyGameRoomStatement->reset();
  296. return result;
  297. }
  298. bool LobbyDatabase::isPlayerInGameRoom(const std::string & accountID, const std::string & roomID)
  299. {
  300. bool result = false;
  301. isPlayerInGameRoomStatement->setBinds(accountID, roomID);
  302. if(isPlayerInGameRoomStatement->execute())
  303. isPlayerInGameRoomStatement->getColumns(result);
  304. isPlayerInGameRoomStatement->reset();
  305. return result;
  306. }
  307. std::vector<LobbyChatMessage> LobbyDatabase::getRecentMessageHistory(const std::string & channelType, const std::string & channelName)
  308. {
  309. std::vector<LobbyChatMessage> result;
  310. getRecentMessageHistoryStatement->setBinds(channelType, channelName);
  311. while(getRecentMessageHistoryStatement->execute())
  312. {
  313. LobbyChatMessage message;
  314. getRecentMessageHistoryStatement->getColumns(message.accountID, message.displayName, message.messageText, message.age);
  315. result.push_back(message);
  316. }
  317. getRecentMessageHistoryStatement->reset();
  318. return result;
  319. }
  320. std::vector<LobbyChatMessage> LobbyDatabase::getFullMessageHistory(const std::string & channelType, const std::string & channelName)
  321. {
  322. std::vector<LobbyChatMessage> result;
  323. getFullMessageHistoryStatement->setBinds(channelType, channelName);
  324. while(getFullMessageHistoryStatement->execute())
  325. {
  326. LobbyChatMessage message;
  327. getFullMessageHistoryStatement->getColumns(message.accountID, message.displayName, message.messageText, message.age);
  328. result.push_back(message);
  329. }
  330. getFullMessageHistoryStatement->reset();
  331. return result;
  332. }
  333. void LobbyDatabase::setAccountOnline(const std::string & accountID, bool isOnline)
  334. {
  335. setAccountOnlineStatement->executeOnce(isOnline ? 1 : 0, accountID);
  336. }
  337. void LobbyDatabase::setGameRoomStatus(const std::string & roomID, LobbyRoomState roomStatus)
  338. {
  339. setGameRoomStatusStatement->executeOnce(vstd::to_underlying(roomStatus), roomID);
  340. }
  341. void LobbyDatabase::insertPlayerIntoGameRoom(const std::string & accountID, const std::string & roomID)
  342. {
  343. insertGameRoomPlayersStatement->executeOnce(roomID, accountID);
  344. }
  345. void LobbyDatabase::deletePlayerFromGameRoom(const std::string & accountID, const std::string & roomID)
  346. {
  347. deleteGameRoomPlayersStatement->executeOnce(roomID, accountID);
  348. }
  349. void LobbyDatabase::deleteGameRoomInvite(const std::string & targetAccountID, const std::string & roomID)
  350. {
  351. deleteGameRoomInvitesStatement->executeOnce(roomID, targetAccountID);
  352. }
  353. void LobbyDatabase::insertGameRoomInvite(const std::string & targetAccountID, const std::string & roomID)
  354. {
  355. insertGameRoomInvitesStatement->executeOnce(roomID, targetAccountID);
  356. }
  357. void LobbyDatabase::insertGameRoom(const std::string & roomID, const std::string & hostAccountID)
  358. {
  359. insertGameRoomStatement->executeOnce(roomID, hostAccountID);
  360. }
  361. void LobbyDatabase::insertAccount(const std::string & accountID, const std::string & displayName)
  362. {
  363. insertAccountStatement->executeOnce(accountID, displayName);
  364. }
  365. void LobbyDatabase::insertAccessCookie(const std::string & accountID, const std::string & accessCookieUUID)
  366. {
  367. insertAccessCookieStatement->executeOnce(accountID, accessCookieUUID);
  368. }
  369. void LobbyDatabase::updateAccountLoginTime(const std::string & accountID)
  370. {
  371. updateAccountLoginTimeStatement->executeOnce(accountID);
  372. }
  373. void LobbyDatabase::updateRoomPlayerLimit(const std::string & gameRoomID, int playerLimit)
  374. {
  375. updateRoomPlayerLimitStatement->executeOnce(playerLimit, gameRoomID);
  376. }
  377. void LobbyDatabase::updateRoomDescription(const std::string & gameRoomID, const std::string & description)
  378. {
  379. updateRoomDescriptionStatement->executeOnce(description, gameRoomID);
  380. }
  381. std::string LobbyDatabase::getAccountDisplayName(const std::string & accountID)
  382. {
  383. std::string result;
  384. getAccountDisplayNameStatement->setBinds(accountID);
  385. if(getAccountDisplayNameStatement->execute())
  386. getAccountDisplayNameStatement->getColumns(result);
  387. getAccountDisplayNameStatement->reset();
  388. return result;
  389. }
  390. LobbyCookieStatus LobbyDatabase::getAccountCookieStatus(const std::string & accountID, const std::string & accessCookieUUID)
  391. {
  392. bool result = false;
  393. isAccountCookieValidStatement->setBinds(accountID, accessCookieUUID);
  394. if(isAccountCookieValidStatement->execute())
  395. isAccountCookieValidStatement->getColumns(result);
  396. isAccountCookieValidStatement->reset();
  397. return result ? LobbyCookieStatus::VALID : LobbyCookieStatus::INVALID;
  398. }
  399. LobbyInviteStatus LobbyDatabase::getAccountInviteStatus(const std::string & accountID, const std::string & roomID)
  400. {
  401. assert(0);
  402. return {};
  403. }
  404. LobbyRoomState LobbyDatabase::getGameRoomStatus(const std::string & roomID)
  405. {
  406. LobbyRoomState result;
  407. getGameRoomStatusStatement->setBinds(roomID);
  408. if(getGameRoomStatusStatement->execute())
  409. getGameRoomStatusStatement->getColumns(result);
  410. else
  411. result = LobbyRoomState::CLOSED;
  412. getGameRoomStatusStatement->reset();
  413. return result;
  414. }
  415. uint32_t LobbyDatabase::getGameRoomFreeSlots(const std::string & roomID)
  416. {
  417. uint32_t usedSlots = 0;
  418. uint32_t totalSlots = 0;
  419. countRoomUsedSlotsStatement->setBinds(roomID);
  420. if(countRoomUsedSlotsStatement->execute())
  421. countRoomUsedSlotsStatement->getColumns(usedSlots);
  422. countRoomUsedSlotsStatement->reset();
  423. countRoomTotalSlotsStatement->setBinds(roomID);
  424. if(countRoomTotalSlotsStatement->execute())
  425. countRoomTotalSlotsStatement->getColumns(totalSlots);
  426. countRoomTotalSlotsStatement->reset();
  427. if (totalSlots > usedSlots)
  428. return totalSlots - usedSlots;
  429. return 0;
  430. }
  431. bool LobbyDatabase::isAccountNameExists(const std::string & displayName)
  432. {
  433. bool result = false;
  434. isAccountNameExistsStatement->setBinds(displayName);
  435. if(isAccountNameExistsStatement->execute())
  436. isAccountNameExistsStatement->getColumns(result);
  437. isAccountNameExistsStatement->reset();
  438. return result;
  439. }
  440. bool LobbyDatabase::isAccountIDExists(const std::string & accountID)
  441. {
  442. bool result = false;
  443. isAccountIDExistsStatement->setBinds(accountID);
  444. if(isAccountIDExistsStatement->execute())
  445. isAccountIDExistsStatement->getColumns(result);
  446. isAccountIDExistsStatement->reset();
  447. return result;
  448. }
  449. std::vector<LobbyGameRoom> LobbyDatabase::getActiveGameRooms()
  450. {
  451. std::vector<LobbyGameRoom> result;
  452. while(getActiveGameRoomsStatement->execute())
  453. {
  454. LobbyGameRoom entry;
  455. getActiveGameRoomsStatement->getColumns(entry.roomID, entry.hostAccountID, entry.hostAccountDisplayName, entry.description, entry.roomState, entry.playerLimit, entry.age);
  456. result.push_back(entry);
  457. }
  458. getActiveGameRoomsStatement->reset();
  459. for (auto & room : result)
  460. {
  461. countRoomUsedSlotsStatement->setBinds(room.roomID);
  462. while(countRoomUsedSlotsStatement->execute())
  463. {
  464. LobbyAccount account;
  465. countRoomUsedSlotsStatement->getColumns(account.accountID, account.displayName);
  466. room.participants.push_back(account);
  467. }
  468. countRoomUsedSlotsStatement->reset();
  469. }
  470. return result;
  471. }
  472. std::vector<LobbyGameRoom> LobbyDatabase::getAccountGameHistory(const std::string & accountID)
  473. {
  474. std::vector<LobbyGameRoom> result;
  475. getAccountGameHistoryStatement->setBinds(accountID);
  476. while(getAccountGameHistoryStatement->execute())
  477. {
  478. LobbyGameRoom entry;
  479. getAccountGameHistoryStatement->getColumns(entry.roomID, entry.hostAccountID, entry.hostAccountDisplayName, entry.description, entry.roomState, entry.playerLimit, entry.age);
  480. result.push_back(entry);
  481. }
  482. getAccountGameHistoryStatement->reset();
  483. for (auto & room : result)
  484. {
  485. countRoomUsedSlotsStatement->setBinds(room.roomID);
  486. while(countRoomUsedSlotsStatement->execute())
  487. {
  488. LobbyAccount account;
  489. countRoomUsedSlotsStatement->getColumns(account.accountID, account.displayName);
  490. room.participants.push_back(account);
  491. }
  492. countRoomUsedSlotsStatement->reset();
  493. }
  494. return result;
  495. }
  496. std::vector<LobbyAccount> LobbyDatabase::getActiveAccounts()
  497. {
  498. std::vector<LobbyAccount> result;
  499. while(getActiveAccountsStatement->execute())
  500. {
  501. LobbyAccount entry;
  502. getActiveAccountsStatement->getColumns(entry.accountID, entry.displayName);
  503. result.push_back(entry);
  504. }
  505. getActiveAccountsStatement->reset();
  506. return result;
  507. }
  508. std::string LobbyDatabase::getIdleGameRoom(const std::string & hostAccountID)
  509. {
  510. std::string result;
  511. getIdleGameRoomStatement->setBinds(hostAccountID);
  512. if(getIdleGameRoomStatement->execute())
  513. getIdleGameRoomStatement->getColumns(result);
  514. getIdleGameRoomStatement->reset();
  515. return result;
  516. }
  517. std::string LobbyDatabase::getAccountGameRoom(const std::string & accountID)
  518. {
  519. std::string result;
  520. getAccountGameRoomStatement->setBinds(accountID);
  521. if(getAccountGameRoomStatement->execute())
  522. getAccountGameRoomStatement->getColumns(result);
  523. getAccountGameRoomStatement->reset();
  524. return result;
  525. }