diff options
| author | navewindre <nw@moneybot.cc> | 2023-12-04 18:06:10 +0100 |
|---|---|---|
| committer | navewindre <nw@moneybot.cc> | 2023-12-04 18:06:10 +0100 |
| commit | aef0d1c1268ab7d4bc18996c9c6b4da16a40aadc (patch) | |
| tree | 43e766b51704f4ab8b383583bdc1871eeeb9c698 /sourcemod/scripting/gokz-localranks/db/update_ranked_map_pool.sp | |
| parent | 38f1140c11724da05a23a10385061200b907cf6e (diff) | |
bbbbbbbbwaaaaaaaaaaa
Diffstat (limited to 'sourcemod/scripting/gokz-localranks/db/update_ranked_map_pool.sp')
| -rw-r--r-- | sourcemod/scripting/gokz-localranks/db/update_ranked_map_pool.sp | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/sourcemod/scripting/gokz-localranks/db/update_ranked_map_pool.sp b/sourcemod/scripting/gokz-localranks/db/update_ranked_map_pool.sp new file mode 100644 index 0000000..ee9bd6d --- /dev/null +++ b/sourcemod/scripting/gokz-localranks/db/update_ranked_map_pool.sp @@ -0,0 +1,104 @@ +/* + Inserts a list of maps read from a file into the Maps table, + and updates them to be part of the ranked map pool. +*/ + + + +void DB_UpdateRankedMapPool(int client) +{ + File file = OpenFile(LR_CFG_MAP_POOL, "r"); + if (file == null) + { + LogError("Failed to load file: '%s'.", LR_CFG_MAP_POOL); + if (IsValidClient(client)) + { + GOKZ_PrintToChat(client, true, "%t", "Ranked Map Pool - Error"); + } + return; + } + + char map[256]; + int mapsCount = 0; + + Transaction txn = new Transaction(); + + // Reset all maps to be unranked + txn.AddQuery(sql_maps_reset_mappool); + + // Insert/Update maps in gokz-localranks-mappool.cfg to be ranked + while (file.ReadLine(map, sizeof(map))) + { + TrimString(map); + String_ToLower(map, map, sizeof(map)); + + // Ignore blank lines and comments + if (map[0] == '\0' || map[0] == ';' || (map[0] == '/' && map[1] == '/')) + { + continue; + } + + mapsCount++; + + switch (g_DBType) + { + case DatabaseType_SQLite: + { + char updateQuery[512]; + gH_DB.Format(updateQuery, sizeof(updateQuery), sqlite_maps_updateranked, 1, map); + + char insertQuery[512]; + gH_DB.Format(insertQuery, sizeof(insertQuery), sqlite_maps_insertranked, 1, map); + + txn.AddQuery(updateQuery); + txn.AddQuery(insertQuery); + } + case DatabaseType_MySQL: + { + char query[512]; + gH_DB.Format(query, sizeof(query), mysql_maps_upsertranked, 1, map); + + txn.AddQuery(query); + } + } + } + + delete file; + + if (mapsCount == 0) + { + LogError("No maps found in file: '%s'.", LR_CFG_MAP_POOL); + + if (IsValidClient(client)) + { + GOKZ_PrintToChat(client, true, "%t", "Ranked Map Pool - No Maps In File"); + GOKZ_PlayErrorSound(client); + } + + delete txn; + return; + } + + // Pass client user ID (or -1) as data + int data = -1; + if (IsValidClient(client)) + { + data = GetClientUserId(client); + } + + gH_DB.Execute(txn, DB_TxnSuccess_UpdateRankedMapPool, DB_TxnFailure_Generic, data); +} + +public void DB_TxnSuccess_UpdateRankedMapPool(Handle db, int userid, int numQueries, Handle[] results, any[] queryData) +{ + int client = GetClientOfUserId(userid); + if (IsValidClient(client)) + { + LogMessage("The ranked map pool was updated by %L.", client); + GOKZ_PrintToChat(client, true, "%t", "Ranked Map Pool - Success"); + } + else + { + LogMessage("The ranked map pool was updated."); + } +} |
