LobbyDatabase.cpp 18 KB

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