DS::Vault::Node v_fetch_node(uint32_t nodeIdx) { PostgresStrings<1> parm; parm.set(0, nodeIdx); PGresult* result = PQexecParams(s_postgres, "SELECT idx, \"CreateTime\", \"ModifyTime\", \"CreateAgeName\"," " \"CreateAgeUuid\", \"CreatorUuid\", \"CreatorIdx\", \"NodeType\"," " \"Int32_1\", \"Int32_2\", \"Int32_3\", \"Int32_4\"," " \"Uint32_1\", \"Uint32_2\", \"Uint32_3\", \"Uint32_4\"," " \"Uuid_1\", \"Uuid_2\", \"Uuid_3\", \"Uuid_4\"," " \"String64_1\", \"String64_2\", \"String64_3\", \"String64_4\"," " \"String64_5\", \"String64_6\", \"IString64_1\", \"IString64_2\"," " \"Text_1\", \"Text_2\", \"Blob_1\", \"Blob_2\"" " FROM vault.\"Nodes\" WHERE idx=$1", 1, 0, parm.m_values, 0, 0, 0); if (PQresultStatus(result) != PGRES_TUPLES_OK) { fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n", __FILE__, __LINE__, PQerrorMessage(s_postgres)); PQclear(result); return DS::Vault::Node(); } if (PQntuples(result) == 0) { PQclear(result); return DS::Vault::Node(); } DS_DASSERT(PQntuples(result) == 1); DS::Vault::Node node; node.set_NodeIdx(strtoul(PQgetvalue(result, 0, 0), 0, 10)); node.set_CreateTime(strtoul(PQgetvalue(result, 0, 1), 0, 10)); node.set_ModifyTime(strtoul(PQgetvalue(result, 0, 2), 0, 10)); if (!PQgetisnull(result, 0, 3)) node.set_CreateAgeName(PQgetvalue(result, 0, 3)); if (!PQgetisnull(result, 0, 4)) node.set_CreateAgeUuid(PQgetvalue(result, 0, 4)); if (!PQgetisnull(result, 0, 5)) node.set_CreatorUuid(PQgetvalue(result, 0, 5)); if (!PQgetisnull(result, 0, 6)) node.set_CreatorIdx(strtoul(PQgetvalue(result, 0, 6), 0, 10)); node.set_NodeType(strtoul(PQgetvalue(result, 0, 7), 0, 10)); if (!PQgetisnull(result, 0, 8)) node.set_Int32_1(strtol(PQgetvalue(result, 0, 8), 0, 10)); if (!PQgetisnull(result, 0, 9)) node.set_Int32_2(strtol(PQgetvalue(result, 0, 9), 0, 10)); if (!PQgetisnull(result, 0, 10)) node.set_Int32_3(strtol(PQgetvalue(result, 0, 10), 0, 10)); if (!PQgetisnull(result, 0, 11)) node.set_Int32_4(strtol(PQgetvalue(result, 0, 11), 0, 10)); if (!PQgetisnull(result, 0, 12)) node.set_Uint32_1(strtoul(PQgetvalue(result, 0, 12), 0, 10)); if (!PQgetisnull(result, 0, 13)) node.set_Uint32_2(strtoul(PQgetvalue(result, 0, 13), 0, 10)); if (!PQgetisnull(result, 0, 14)) node.set_Uint32_3(strtoul(PQgetvalue(result, 0, 14), 0, 10)); if (!PQgetisnull(result, 0, 15)) node.set_Uint32_4(strtoul(PQgetvalue(result, 0, 15), 0, 10)); if (!PQgetisnull(result, 0, 16)) node.set_Uuid_1(PQgetvalue(result, 0, 16)); if (!PQgetisnull(result, 0, 17)) node.set_Uuid_2(PQgetvalue(result, 0, 17)); if (!PQgetisnull(result, 0, 18)) node.set_Uuid_3(PQgetvalue(result, 0, 18)); if (!PQgetisnull(result, 0, 19)) node.set_Uuid_4(PQgetvalue(result, 0, 19)); if (!PQgetisnull(result, 0, 20)) node.set_String64_1(PQgetvalue(result, 0, 20)); if (!PQgetisnull(result, 0, 21)) node.set_String64_2(PQgetvalue(result, 0, 21)); if (!PQgetisnull(result, 0, 22)) node.set_String64_3(PQgetvalue(result, 0, 22)); if (!PQgetisnull(result, 0, 23)) node.set_String64_4(PQgetvalue(result, 0, 23)); if (!PQgetisnull(result, 0, 24)) node.set_String64_5(PQgetvalue(result, 0, 24)); if (!PQgetisnull(result, 0, 25)) node.set_String64_6(PQgetvalue(result, 0, 25)); if (!PQgetisnull(result, 0, 26)) node.set_IString64_1(PQgetvalue(result, 0, 26)); if (!PQgetisnull(result, 0, 27)) node.set_IString64_2(PQgetvalue(result, 0, 27)); if (!PQgetisnull(result, 0, 28)) node.set_Text_1(PQgetvalue(result, 0, 28)); if (!PQgetisnull(result, 0, 29)) node.set_Text_2(PQgetvalue(result, 0, 29)); if (!PQgetisnull(result, 0, 30)) node.set_Blob_1(DS::Base64Decode(PQgetvalue(result, 0, 30))); if (!PQgetisnull(result, 0, 31)) node.set_Blob_2(DS::Base64Decode(PQgetvalue(result, 0, 31))); PQclear(result); return node; }
std::tuple<uint32_t, uint32_t> v_create_age(AuthServer_AgeInfo age, uint32_t flags) { if (age.m_ageId.isNull()) age.m_ageId = gen_uuid(); int seqNumber = age.m_seqNumber; if (seqNumber < 0) { check_postgres(); PGresult* result = PQexec(s_postgres, "SELECT nextval('game.\"AgeSeqNumber\"'::regclass)"); if (PQresultStatus(result) != PGRES_TUPLES_OK) { fprintf(stderr, "%s:%d:\n Postgres SELECT error: %s\n", __FILE__, __LINE__, PQerrorMessage(s_postgres)); PQclear(result); return std::make_pair(0, 0); } DS_DASSERT(PQntuples(result) == 1); seqNumber = strtol(PQgetvalue(result, 0, 0), 0, 10); PQclear(result); } DS::Vault::Node node; node.set_NodeType(DS::Vault::e_NodeAge); node.set_CreatorUuid(age.m_ageId); node.set_Uuid_1(age.m_ageId); if (!age.m_parentId.isNull()) node.set_Uuid_2(age.m_parentId); node.set_String64_1(age.m_filename); uint32_t ageNode = v_create_node(node); if (ageNode == 0) return std::make_pair(0, 0); // TODO: Global SDL node node.clear(); node.set_NodeType(DS::Vault::e_NodeFolder); node.set_CreatorUuid(age.m_ageId); node.set_CreatorIdx(ageNode); node.set_Int32_1(DS::Vault::e_ChronicleFolder); uint32_t chronFolder = v_create_node(node); if (chronFolder == 0) return std::make_pair(0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodePlayerInfoList); node.set_CreatorUuid(age.m_ageId); node.set_CreatorIdx(ageNode); node.set_Int32_1(DS::Vault::e_PeopleIKnowAboutFolder); uint32_t knownFolder = v_create_node(node); if (knownFolder == 0) return std::make_pair(0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodeAgeInfoList); node.set_CreatorUuid(age.m_ageId); node.set_CreatorIdx(ageNode); node.set_Int32_1(DS::Vault::e_SubAgesFolder); uint32_t subAgesFolder = v_create_node(node); if (subAgesFolder == 0) return std::make_pair(0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodeAgeInfo); node.set_CreatorUuid(age.m_ageId); node.set_CreatorIdx(ageNode); node.set_Int32_1(seqNumber); node.set_Int32_2((flags & e_AgePublic) != 0 ? 1 : 0); node.set_Int32_3(age.m_language); node.set_Uint32_1(ageNode); node.set_Uint32_2(0); // Czar ID node.set_Uint32_3(0); // Flags node.set_Uuid_1(age.m_ageId); if (!age.m_parentId.isNull()) node.set_Uuid_2(age.m_parentId); node.set_String64_2(age.m_filename); if (!age.m_instName.isNull()) node.set_String64_3(age.m_instName); if (!age.m_userName.isEmpty()) node.set_String64_4(age.m_userName); if (!age.m_description.isEmpty()) node.set_Text_1(age.m_description); uint32_t ageInfoNode = v_create_node(node); if (ageInfoNode == 0) return std::make_pair(0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodeFolder); node.set_CreatorUuid(age.m_ageId); node.set_CreatorIdx(ageNode); node.set_Int32_1(DS::Vault::e_AgeDevicesFolder); uint32_t devsFolder = v_create_node(node); if (devsFolder == 0) return std::make_pair(0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodePlayerInfoList); node.set_CreatorUuid(age.m_ageId); node.set_CreatorIdx(ageNode); node.set_Int32_1(DS::Vault::e_CanVisitFolder); uint32_t canVisitList = v_create_node(node); if (canVisitList == 0) return std::make_pair(0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodeSDL); node.set_CreatorUuid(age.m_ageId); node.set_CreatorIdx(ageNode); node.set_Int32_1(0); node.set_String64_1(age.m_filename); node.set_Blob_1(gen_default_sdl(age.m_filename)); uint32_t ageSdlNode = v_create_node(node); if (ageSdlNode == 0) return std::make_pair(0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodePlayerInfoList); node.set_CreatorUuid(age.m_ageId); node.set_CreatorIdx(ageNode); node.set_Int32_1(DS::Vault::e_AgeOwnersFolder); uint32_t ageOwners = v_create_node(node); if (ageOwners == 0) return std::make_pair(0, 0); node.clear(); node.set_NodeType(DS::Vault::e_NodeAgeInfoList); node.set_CreatorUuid(age.m_ageId); node.set_CreatorIdx(ageNode); node.set_Int32_1(DS::Vault::e_ChildAgesFolder); uint32_t childAges = v_create_node(node); if (childAges == 0) return std::make_pair(0, 0); if (!v_ref_node(ageNode, s_systemNode, 0)) return std::make_pair(0, 0); if (!v_ref_node(ageNode, chronFolder, 0)) return std::make_pair(0, 0); if (!v_ref_node(ageNode, knownFolder, 0)) return std::make_pair(0, 0); if (!v_ref_node(ageNode, subAgesFolder, 0)) return std::make_pair(0, 0); if (!v_ref_node(ageNode, ageInfoNode, 0)) return std::make_pair(0, 0); if (!v_ref_node(ageNode, devsFolder, 0)) return std::make_pair(0, 0); if (!v_ref_node(ageInfoNode, canVisitList, 0)) return std::make_pair(0, 0); if (!v_ref_node(ageInfoNode, ageSdlNode, 0)) return std::make_pair(0, 0); if (!v_ref_node(ageInfoNode, ageOwners, 0)) return std::make_pair(0, 0); if (!v_ref_node(ageInfoNode, childAges, 0)) return std::make_pair(0, 0); // Register with the server database { DS::String agedesc = !age.m_description.isEmpty() ? age.m_description : !age.m_instName.isEmpty() ? age.m_instName : age.m_filename; PostgresStrings<5> parms; parms.set(0, age.m_ageId.toString()); parms.set(1, age.m_filename); parms.set(2, agedesc); parms.set(3, ageNode); parms.set(4, ageSdlNode); PGresult* result = PQexecParams(s_postgres, "INSERT INTO game.\"Servers\"" " (\"AgeUuid\", \"AgeFilename\", \"DisplayName\", \"AgeIdx\", \"SdlIdx\")" " VALUES ($1, $2, $3, $4, $5)", 5, 0, parms.m_values, 0, 0, 0); if (PQresultStatus(result) != PGRES_COMMAND_OK) { fprintf(stderr, "%s:%d:\n Postgres INSERT error: %s\n", __FILE__, __LINE__, PQerrorMessage(s_postgres)); PQclear(result); return std::make_pair(0, 0); } PQclear(result); } return std::make_tuple(ageNode, ageInfoNode); }