LobbyDatabase.cpp 17 KB

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