From aec4e7f3df2d884070acc4c0274608a03b081d91 Mon Sep 17 00:00:00 2001 From: Bara Date: Sat, 4 Mar 2023 01:20:18 +0100 Subject: [PATCH] Filling up ck_players --- addons/sourcemod/scripting/SurfTimer.sp | 2 +- .../scripting/surftimer/db/queries.sp | 28 +-- .../scripting/surftimer/db/updater.sp | 199 +++++++++++++++++- addons/sourcemod/scripting/surftimer/sql.sp | 5 +- addons/sourcemod/scripting/test.sp | 23 -- 5 files changed, 216 insertions(+), 41 deletions(-) delete mode 100644 addons/sourcemod/scripting/test.sp diff --git a/addons/sourcemod/scripting/SurfTimer.sp b/addons/sourcemod/scripting/SurfTimer.sp index 374ac4e5..09f91b81 100644 --- a/addons/sourcemod/scripting/SurfTimer.sp +++ b/addons/sourcemod/scripting/SurfTimer.sp @@ -1232,4 +1232,4 @@ public void OnPluginStart() public Action ItemFoundMsg(UserMsg msg_id, Protobuf msg, const int[] players, int playersNum, bool reliable, bool init) { return Plugin_Handled; -} \ No newline at end of file +} diff --git a/addons/sourcemod/scripting/surftimer/db/queries.sp b/addons/sourcemod/scripting/surftimer/db/queries.sp index d39bee1b..f1e067bf 100644 --- a/addons/sourcemod/scripting/surftimer/db/queries.sp +++ b/addons/sourcemod/scripting/surftimer/db/queries.sp @@ -7,13 +7,13 @@ char sql_createAnnouncements[] = "CREATE TABLE IF NOT EXISTS `ck_announcements` // ck_bonus char sql_createBonus[] = "CREATE TABLE IF NOT EXISTS ck_bonus (steamid VARCHAR(32), name VARCHAR(64), mapname VARCHAR(32), runtime decimal(12,6) NOT NULL DEFAULT '-1.000000', velStartXY SMALLINT(6) NOT NULL DEFAULT 0, velStartXYZ SMALLINT(6) NOT NULL DEFAULT 0, velStartZ SMALLINT(6) NOT NULL DEFAULT 0, zonegroup INT(12) NOT NULL DEFAULT 1, style INT(11) NOT NULL DEFAULT 0, PRIMARY KEY(steamid, mapname, zonegroup, style)) DEFAULT CHARSET=utf8mb4;"; -char sql_createBonusIndex[] = "CREATE INDEX bonusrank ON ck_bonus (mapname,runtime,zonegroup,style);"; +char sql_createBonusIndex[] = "CREATE INDEX bonusrank ON ck_bonus (mapname,runtime,zonegroup,style)"; char sql_insertBonus[] = "INSERT INTO ck_bonus (steamid, name, mapname, runtime, zonegroup, velStartXY, velStartXYZ, velStartZ) VALUES ('%s', '%s', '%s', '%f', '%i', '%i', '%i', '%i')"; char sql_updateBonus[] = "UPDATE ck_bonus SET runtime = '%f', name = '%s', velStartXY = %i, velStartXYZ = %i, velStartZ = %i WHERE steamid = '%s' AND mapname = '%s' AND zonegroup = %i AND style = 0"; char sql_selectBonusCount[] = "SELECT zonegroup, style, count(1) FROM ck_bonus WHERE mapname = '%s' GROUP BY zonegroup, style;"; char sql_selectPersonalBonusRecords[] = "SELECT runtime, zonegroup, style FROM ck_bonus WHERE steamid = '%s' AND mapname = '%s' AND runtime > '0.0'"; char sql_selectPlayerRankBonus[] = "SELECT name FROM ck_bonus WHERE runtime <= (SELECT runtime FROM ck_bonus WHERE steamid = '%s' AND mapname= '%s' AND runtime > 0.0 AND zonegroup = %i AND style = 0) AND mapname = '%s' AND zonegroup = %i AND style = 0;"; -char sql_selectFastestBonus[] = "SELECT t1.name, t1.runtime, t1.zonegroup, t1.style, t1.velStartXY, t1.velStartXYZ, t1.velstartZ from ck_bonus t1 where t1.mapname = '%s' and t1.runtime = (select min(t2.runtime) from ck_bonus t2 where t2.mapname = t1.mapname and t2.zonegroup = t1.zonegroup and t2.style = t1.style);"; +char sql_selectFastestBonus[] = "SELECT t1.name, t1.runtime, t1.zonegroup, t1.style, t1.velStartXY, t1.velStartXYZ, t1.velstartZ from ck_bonus t1 where t1.mapname = '%s' and t1.runtime = (select min(t2.runtime) from ck_bonus t2 where t2.mapname = t1.mapname and t2.zonegroup = t1.zonegroup and t2.style = t1.style)"; char sql_deleteBonus[] = "DELETE FROM ck_bonus WHERE mapname = '%s'"; char sql_selectAllBonusTimesinMap[] = "SELECT zonegroup, runtime from ck_bonus WHERE mapname = '%s';"; char sql_selectTopBonusSurfers[] = "SELECT db2.steamid, db1.name, db2.runtime as overall, db1.steamid, db2.mapname FROM ck_bonus as db2 INNER JOIN ck_playerrank as db1 on db2.steamid = db1.steamid WHERE db2.mapname = '%s' AND db2.style = %i AND db1.style = %i AND db2.runtime > -1.0 AND zonegroup = %i ORDER BY overall ASC LIMIT 100;"; @@ -31,19 +31,19 @@ char sql_selectStageAttempts[] = "SELECT cp, stage_attempts FROM ck_checkpoints // ck_latestrecords char sql_createLatestRecords[] = "CREATE TABLE IF NOT EXISTS ck_latestrecords (steamid VARCHAR(32), name VARCHAR(64), runtime decimal(12,6) NOT NULL DEFAULT '-1.000000', map VARCHAR(32), date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(steamid,map,date)) DEFAULT CHARSET=utf8mb4;"; -char sql_insertLatestRecords[] = "INSERT INTO ck_latestrecords (steamid, name, runtime, map) VALUES('%s','%s','%f','%s');"; +char sql_insertLatestRecords[] = "INSERT INTO ck_latestrecords (steamid, name, runtime, map) VALUES('%s','%s','%f','%s')"; char sql_selectLatestRecords[] = "SELECT name, runtime, map, date FROM ck_latestrecords ORDER BY date DESC LIMIT 50"; // ck_maptier char sql_createMapTier[] = "CREATE TABLE IF NOT EXISTS ck_maptier (mapname VARCHAR(54) NOT NULL, tier INT(12), maxvelocity FLOAT NOT NULL DEFAULT '3500.0', announcerecord INT(11) NOT NULL DEFAULT '0', gravityfix INT(11) NOT NULL DEFAULT '1', ranked INT(11) NOT NULL DEFAULT '1', PRIMARY KEY(mapname)) DEFAULT CHARSET=utf8mb4;"; char sql_selectMapTier[] = "SELECT tier, ranked, mapper FROM ck_maptier WHERE mapname = '%s'"; -char sql_insertmaptier[] = "INSERT INTO ck_maptier (mapname, tier) VALUES ('%s', '%i');"; +char sql_insertmaptier[] = "INSERT INTO ck_maptier (mapname, tier) VALUES ('%s', '%i')"; char sql_updatemaptier[] = "UPDATE ck_maptier SET tier = %i WHERE mapname ='%s'"; char sql_updateMapperName[] = "UPDATE ck_maptier SET mapper = '%s' WHERE mapname = '%s'"; // ck_playeroptions2 char sql_createPlayerOptions[] = "CREATE TABLE IF NOT EXISTS `ck_playeroptions2` (`steamid` varchar(32) NOT NULL DEFAULT '', `timer` int(11) NOT NULL DEFAULT '1', `hide` int(11) NOT NULL DEFAULT '0', `sounds` int(11) NOT NULL DEFAULT '1', `chat` int(11) NOT NULL DEFAULT '0', `viewmodel` int(11) NOT NULL DEFAULT '1', `autobhop` int(11) NOT NULL DEFAULT '1', `checkpoints` int(11) NOT NULL DEFAULT '1', `gradient` int(11) NOT NULL DEFAULT '3', `speedmode` int(11) NOT NULL DEFAULT '0', `centrespeed` int(11) NOT NULL DEFAULT '0', `centrehud` int(11) NOT NULL DEFAULT '1', teleside int(11) NOT NULL DEFAULT '0', `module1c` int(11) NOT NULL DEFAULT '1', `module2c` int(11) NOT NULL DEFAULT '2', `module3c` int(11) NOT NULL DEFAULT '3', `module4c` int(11) NOT NULL DEFAULT '4', `module5c` int(11) NOT NULL DEFAULT '5', `module6c` int(11) NOT NULL DEFAULT '6', `sidehud` int(11) NOT NULL DEFAULT '1', `module1s` int(11) NOT NULL DEFAULT '5', `module2s` int(11) NOT NULL DEFAULT '0', `module3s` int(11) NOT NULL DEFAULT '0', `module4s` int(11) NOT NULL DEFAULT '0', `module5s` int(11) NOT NULL DEFAULT '0', prestrafe int(11) NOT NULL DEFAULT '0', cpmessages int(11) NOT NULL DEFAULT '1', wrcpmessages int(11) NOT NULL DEFAULT '1', hints int(11) NOT NULL DEFAULT '1', csd_update_rate int(11) NOT NULL DEFAULT '1' , csd_pos_x float(11) NOT NULL DEFAULT '0.5' , csd_pos_y float(11) NOT NULL DEFAULT '0.3' , csd_r int(11) NOT NULL DEFAULT '255', csd_g int(11) NOT NULL DEFAULT '255', csd_b int(11) NOT NULL DEFAULT '255', PRIMARY KEY (`steamid`)) DEFAULT CHARSET=utf8mb4;"; -char sql_insertPlayerOptions[] = "INSERT INTO ck_playeroptions2 (steamid) VALUES ('%s');"; +char sql_insertPlayerOptions[] = "INSERT INTO ck_playeroptions2 (steamid) VALUES ('%s')"; char sql_selectPlayerOptions[] = "SELECT timer, hide, sounds, chat, viewmodel, autobhop, checkpoints, gradient, speedmode, centrespeed, centrehud, teleside, module1c, module2c, module3c, module4c, module5c, module6c, sidehud, module1s, module2s, module3s, module4s, module5s, prestrafe, cpmessages, wrcpmessages, hints, csd_update_rate, csd_pos_x, csd_pos_y, csd_r, csd_g, csd_b, prespeedmode FROM ck_playeroptions2 where steamid = '%s';"; char sql_updatePlayerOptions[] = "UPDATE ck_playeroptions2 SET timer = %i, hide = %i, sounds = %i, chat = %i, viewmodel = %i, autobhop = %i, checkpoints = %i, gradient = %i, speedmode = %i, centrespeed = %i, centrehud = %i, teleside = %i, module1c = %i, module2c = %i, module3c = %i, module4c = %i, module5c = %i, module6c = %i, sidehud = %i, module1s = %i, module2s = %i, module3s = %i, module4s = %i, module5s = %i, prestrafe = %i, cpmessages = %i, wrcpmessages = %i, hints = %i, csd_update_rate = %i, csd_pos_x = %f, csd_pos_y = %f, csd_r= %i, csd_g = %i, csd_b = %i, prespeedmode = %i where steamid = '%s'"; @@ -66,16 +66,16 @@ char sql_selectPlayerProfile[] = "SELECT steamid, steamid64, name, country, poin // ck_playertemp char sql_createPlayertmp[] = "CREATE TABLE IF NOT EXISTS ck_playertemp (steamid VARCHAR(32), mapname VARCHAR(32), cords1 FLOAT NOT NULL DEFAULT '-1.0', cords2 FLOAT NOT NULL DEFAULT '-1.0', cords3 FLOAT NOT NULL DEFAULT '-1.0', angle1 FLOAT NOT NULL DEFAULT '-1.0',angle2 FLOAT NOT NULL DEFAULT '-1.0',angle3 FLOAT NOT NULL DEFAULT '-1.0', EncTickrate INT(12) DEFAULT '-1.0', runtimeTmp decimal(12,6) NOT NULL DEFAULT '-1.000000', Stage INT, zonegroup INT NOT NULL DEFAULT 0, PRIMARY KEY(steamid,mapname)) DEFAULT CHARSET=utf8mb4;"; -char sql_insertPlayerTmp[] = "INSERT INTO ck_playertemp (cords1, cords2, cords3, angle1,angle2,angle3,runtimeTmp,steamid,mapname,EncTickrate,Stage,zonegroup) VALUES ('%f','%f','%f','%f','%f','%f','%f','%s', '%s', '%i', %i, %i);"; +char sql_insertPlayerTmp[] = "INSERT INTO ck_playertemp (cords1, cords2, cords3, angle1,angle2,angle3,runtimeTmp,steamid,mapname,EncTickrate,Stage,zonegroup) VALUES ('%f','%f','%f','%f','%f','%f','%f','%s', '%s', '%i', %i, %i)"; char sql_updatePlayerTmp[] = "UPDATE ck_playertemp SET cords1 = '%f', cords2 = '%f', cords3 = '%f', angle1 = '%f', angle2 = '%f', angle3 = '%f', runtimeTmp = '%f', mapname ='%s', EncTickrate='%i', Stage = %i, zonegroup = %i WHERE steamid = '%s';"; char sql_deletePlayerTmp[] = "DELETE FROM ck_playertemp where steamid = '%s';"; char sql_selectPlayerTmp[] = "SELECT cords1,cords2,cords3, angle1, angle2, angle3,runtimeTmp, EncTickrate, Stage, zonegroup FROM ck_playertemp WHERE steamid = '%s' AND mapname = '%s';"; // ck_playertimes char sql_createPlayertimes[] = "CREATE TABLE IF NOT EXISTS ck_playertimes (steamid VARCHAR(32), mapname VARCHAR(32), name VARCHAR(64), runtimepro decimal(12,6) NOT NULL DEFAULT '-1.000000', velStartXY SMALLINT(6) NOT NULL DEFAULT 0, velStartXYZ SMALLINT(6) NOT NULL DEFAULT 0, velStartZ SMALLINT(6) NOT NULL DEFAULT 0, style INT(11) NOT NULL DEFAULT '0', PRIMARY KEY(steamid, mapname, style)) DEFAULT CHARSET=utf8mb4;"; -char sql_createPlayertimesIndex[] = "CREATE INDEX maprank ON ck_playertimes (mapname, runtimepro, style);"; -char sql_insertPlayer[] = "INSERT INTO ck_playertimes (steamid, mapname, name) VALUES('%s', '%s', '%s');"; -char sql_insertPlayerTime[] = "INSERT INTO ck_playertimes (steamid, mapname, name, runtimepro, style, velStartXY, velStartXYZ, velStartZ) VALUES('%s', '%s', '%s', '%f', %i, %i, %i, %i);"; +char sql_createPlayertimesIndex[] = "CREATE INDEX maprank ON ck_playertimes (mapname, runtimepro, style)"; +char sql_insertPlayer[] = "INSERT INTO ck_playertimes (steamid, mapname, name) VALUES('%s', '%s', '%s')"; +char sql_insertPlayerTime[] = "INSERT INTO ck_playertimes (steamid, mapname, name, runtimepro, style, velStartXY, velStartXYZ, velStartZ) VALUES('%s', '%s', '%s', '%f', %i, %i, %i, %i)"; char sql_updateRecordPro[] = "UPDATE ck_playertimes SET name = '%s', runtimepro = '%f', velStartXY = '%i', velStartXYZ = '%i', velStartZ = '%i' WHERE steamid = '%s' AND mapname = '%s' AND style = %i;"; char sql_selectPlayer[] = "SELECT steamid FROM ck_playertimes WHERE steamid = '%s' AND mapname = '%s';"; char sql_selectMapRecord[] = "SELECT t1.runtimepro, t1.name, t1.steamid, t1.style, t1.velStartXY, t1.velStartXYZ, t1.velstartZ FROM ck_playertimes t1 JOIN ( SELECT MIN(runtimepro) AS min_runtime, style, mapname FROM ck_playertimes GROUP BY mapname, style ) AS t2 ON t1.runtimepro = t2.min_runtime AND t1.mapname = t2.mapname AND t1.style = t2.style WHERE t1.mapname = '%s'"; @@ -89,7 +89,7 @@ char sql_selectAllMapTimesinMap[] = "SELECT runtimepro from ck_playertimes WHERE char sql_selectMapRankUnknownWithMap[] = "SELECT `steamid`, `name`, `mapname`, `runtimepro` FROM `ck_playertimes` WHERE `mapname` = '%s' AND style = 0 ORDER BY `runtimepro` ASC LIMIT %i, 1;"; // ck_spawnlocations char sql_createSpawnLocations[] = "CREATE TABLE IF NOT EXISTS ck_spawnlocations (mapname VARCHAR(54) NOT NULL, pos_x FLOAT NOT NULL, pos_y FLOAT NOT NULL, pos_z FLOAT NOT NULL, ang_x FLOAT NOT NULL, ang_y FLOAT NOT NULL, ang_z FLOAT NOT NULL, `vel_x` float NOT NULL DEFAULT '0', `vel_y` float NOT NULL DEFAULT '0', `vel_z` float NOT NULL DEFAULT '0', zonegroup INT(12) DEFAULT 0, stage INT(12) DEFAULT 0, teleside INT(11) DEFAULT 0, PRIMARY KEY(mapname, zonegroup, stage, teleside)) DEFAULT CHARSET=utf8mb4;"; -char sql_insertSpawnLocations[] = "INSERT INTO ck_spawnlocations (mapname, pos_x, pos_y, pos_z, ang_x, ang_y, ang_z, vel_x, vel_y, vel_z, zonegroup, teleside) VALUES ('%s', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', %i, %i);"; +char sql_insertSpawnLocations[] = "INSERT INTO ck_spawnlocations (mapname, pos_x, pos_y, pos_z, ang_x, ang_y, ang_z, vel_x, vel_y, vel_z, zonegroup, teleside) VALUES ('%s', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', %i, %i)"; char sql_updateSpawnLocations[] = "UPDATE ck_spawnlocations SET pos_x = '%f', pos_y = '%f', pos_z = '%f', ang_x = '%f', ang_y = '%f', ang_z = '%f', vel_x = '%f', vel_y = '%f', vel_z = '%f' WHERE mapname = '%s' AND zonegroup = %i AND teleside = %i;"; char sql_selectSpawnLocations[] = "SELECT mapname, pos_x, pos_y, pos_z, ang_x, ang_y, ang_z, vel_x, vel_y, vel_z, zonegroup, stage, teleside FROM ck_spawnlocations WHERE mapname ='%s';"; char sql_deleteSpawnLocations[] = "DELETE FROM ck_spawnlocations WHERE mapname = '%s' AND zonegroup = %i AND stage = 1 AND teleside = %i;"; @@ -122,7 +122,7 @@ char sql_MainDeleteQeury[] = "DELETE From %s where mapname='%s' and style='%i' a //ck_prinfo char sql_CreatePrinfo[] = "CREATE TABLE IF NOT EXISTS ck_prinfo (steamid VARCHAR(32), name VARCHAR(64), mapname VARCHAR(32), runtime decimal(12,6) NOT NULL DEFAULT '-1.000000', zonegroup INT(12) NOT NULL DEFAULT '0', PRtimeinzone decimal(12,6) NOT NULL DEFAULT '-1.000000', PRcomplete FLOAT NOT NULL DEFAULT '0.0', PRattempts FLOAT NOT NULL DEFAULT '0.0', PRstcomplete FLOAT NOT NULL DEFAULT '0.0', PRIMARY KEY(steamid, mapname, zonegroup)) DEFAULT CHARSET=utf8mb4;"; char sql_selectPR[] = "SELECT steamid, name, mapname, zonegroup, PRtimeinzone, PRcomplete, PRattempts, PRstcomplete FROM ck_prinfo WHERE steamid = '%s' AND mapname = '%s' AND zonegroup= '%i';"; -char sql_insertPR[] = "INSERT INTO ck_prinfo (steamid, name, mapname, runtime, zonegroup, PRtimeinzone, PRcomplete, PRattempts, PRstcomplete) VALUES('%s', '%s', '%s', '%f', '%i', '%f', '%f', '%f', '%f');"; +char sql_insertPR[] = "INSERT INTO ck_prinfo (steamid, name, mapname, runtime, zonegroup, PRtimeinzone, PRcomplete, PRattempts, PRstcomplete) VALUES('%s', '%s', '%s', '%f', '%i', '%f', '%f', '%f', '%f')"; char sql_selectBonusPR[] = "SELECT steamid, name, mapname, zonegroup, PRtimeinzone, PRcomplete, PRattempts, PRstcomplete FROM ck_prinfo WHERE steamid = '%s' AND mapname = '%s' AND zonegroup = '%i';"; char sql_updatePrinfo[] = "UPDATE ck_prinfo SET PRtimeinzone = '%f', PRcomplete = '%f', PRattempts = '%f', PRstcomplete = '%f' WHERE steamid = '%s' AND mapname = '%s' AND zonegroup = '%i';"; char sql_updatePrinfo_withruntime[] = "UPDATE ck_prinfo SET PRtimeinzone = '%f', PRcomplete = '%f', PRattempts = '%f', PRstcomplete = '%f', runtime = '%f' WHERE steamid = '%s' AND mapname = '%s' AND zonegroup = '%i';"; @@ -139,6 +139,6 @@ char sql_checkDataType[] = "SELECT DATA_TYPE, NUMERIC_PRECISION, NUMERIC_SCALE F // ck_players char sql_createPlayers[] = "CREATE TABLE IF NOT EXISTS ck_players (accountid INT NOT NULL, steamid2 VARCHAR(32) NULL, steamid64 VARCHAR(64) NULL, name VARCHAR(64) NULL, PRIMARY KEY(accountid)) DEFAULT CHARSET=utf8mb4;"; -// char sql_insertPlayersAS2[] = "INSERT IGNORE INTO ck_players (accountid, steamid2) VALUES ('%d', '%s');"; -// char sql_insertPlayersAN[] = "INSERT IGNORE INTO ck_players (accountid, name) VALUES ('%d', '%s');"; -// char sql_insertPlayersAS64[] = "INSERT IGNORE INTO ck_players (accountid, steamid64) VALUES ('%d', '%s');"; +char sql_insertPlayersAS2[] = "INSERT ck_players (accountid, steamid2) VALUES ('%d', '%s') ON DUPLICATE KEY UPDATE steamid2 = '%s'"; +char sql_insertPlayersAS2N[] = "INSERT ck_players (accountid, steamid2, name) VALUES ('%d', '%s', '%s') ON DUPLICATE KEY UPDATE steamid2 = '%s', name = '%s'"; +char sql_insertPlayersAS2S64[] = "INSERT ck_players (accountid, steamid2, steamid64) VALUES ('%d', '%s', '%s') ON DUPLICATE KEY UPDATE steamid2 = '%s', steamid64 = '%s'"; diff --git a/addons/sourcemod/scripting/surftimer/db/updater.sp b/addons/sourcemod/scripting/surftimer/db/updater.sp index 94c87e69..bdc855a3 100644 --- a/addons/sourcemod/scripting/surftimer/db/updater.sp +++ b/addons/sourcemod/scripting/surftimer/db/updater.sp @@ -334,7 +334,7 @@ public void SQLCheckDataType(Handle owner, Handle hndl, const char[] error, Data void ConvertDataTypeToDecimal(const char[] table, const char[] column, int precision, int scale) { - PrintToServer("Converting %s-%s to decimal(%d, %d)...", table, column, precision, scale); + LogMessage("Converting %s-%s to decimal(%d, %d)...", table, column, precision, scale); char sQuery[128]; Format(sQuery, sizeof(sQuery), "ALTER TABLE %s MODIFY %s DECIMAL(%d, %d);", table, column, precision, scale); @@ -385,3 +385,200 @@ public void SQLCleanUpTables(Handle owner, Handle hndl, const char[] error, any return; } } + +void SelectPlayersStuff() +{ + Transaction tTransaction = new Transaction(); + + char sQuery[256]; + FormatEx(sQuery, sizeof(sQuery), "SELECT steamid, name FROM ck_bonus GROUP BY steamid;"); + tTransaction.AddQuery(sQuery, 0); + + FormatEx(sQuery, sizeof(sQuery), "SELECT steamid FROM ck_checkpoints GROUP BY steamid;"); + tTransaction.AddQuery(sQuery, 1); + + FormatEx(sQuery, sizeof(sQuery), "SELECT steamid, name FROM ck_latestrecords GROUP BY steamid;"); + tTransaction.AddQuery(sQuery, 2); + + FormatEx(sQuery, sizeof(sQuery), "SELECT steamid FROM ck_playeroptions2 GROUP BY steamid;"); + tTransaction.AddQuery(sQuery, 3); + + FormatEx(sQuery, sizeof(sQuery), "SELECT steamid, steamid64 FROM ck_playerrank GROUP BY steamid;"); + tTransaction.AddQuery(sQuery, 4); + + FormatEx(sQuery, sizeof(sQuery), "SELECT steamid FROM ck_playertemp GROUP BY steamid;"); + tTransaction.AddQuery(sQuery, 5); + + FormatEx(sQuery, sizeof(sQuery), "SELECT steamid, name FROM ck_playertimes GROUP BY steamid;"); + tTransaction.AddQuery(sQuery, 6); + + FormatEx(sQuery, sizeof(sQuery), "SELECT steamid, name FROM ck_prinfo GROUP BY steamid;"); + tTransaction.AddQuery(sQuery, 7); + + FormatEx(sQuery, sizeof(sQuery), "SELECT steamid FROM ck_vipadmins GROUP BY steamid;"); + tTransaction.AddQuery(sQuery, 8); + + SQL_ExecuteTransaction(g_hDb, tTransaction, SQLTxn_GetPlayerDataSuccess, SQLTxn_GetPlayerDataFailed, .priority=DBPrio_High); +} + +public void SQLTxn_GetPlayerDataSuccess(Database db, any data, int numQueries, DBResultSet[] results, any[] queryData) +{ + for (int i = 0; i < numQueries; i++) + { + int iQueries = 0; + Transaction tTransaction = new Transaction(); + char sSteamId2[32], sName[64], sSteamId64[128], sQuery[1024]; + // ck_bonus + if (g_sSteamIdTablesCleanup[i][3] == 'b') + { + while (results[i].FetchRow()) + { + results[i].FetchString(0, sSteamId2, sizeof(sSteamId2)); + results[i].FetchString(1, sName, sizeof(sName)); + + int iAccountId = SteamId2ToAccountId(sSteamId2); + + FormatEx(sQuery, sizeof(sQuery), sql_insertPlayersAS2N, iAccountId, sSteamId2, sName, sSteamId2, sName); + tTransaction.AddQuery(sQuery); + iQueries++; + } + } + // ck_checkpoints + else if (g_sSteamIdTablesCleanup[i][3] == 'c') + { + while (results[i].FetchRow()) + { + results[i].FetchString(0, sSteamId2, sizeof(sSteamId2)); + + int iAccountId = SteamId2ToAccountId(sSteamId2); + + FormatEx(sQuery, sizeof(sQuery), sql_insertPlayersAS2, iAccountId, sSteamId2, sSteamId2); + tTransaction.AddQuery(sQuery); + iQueries++; + } + } + // ck_latestrecords + else if (g_sSteamIdTablesCleanup[i][3] == 'l') + { + while (results[i].FetchRow()) + { + results[i].FetchString(0, sSteamId2, sizeof(sSteamId2)); + results[i].FetchString(1, sName, sizeof(sName)); + + int iAccountId = SteamId2ToAccountId(sSteamId2); + + FormatEx(sQuery, sizeof(sQuery), sql_insertPlayersAS2N, iAccountId, sSteamId2, sName, sSteamId2, sName); + tTransaction.AddQuery(sQuery); + iQueries++; + } + } + // ck_playeroptions2 + else if (g_sSteamIdTablesCleanup[i][3] == 'p' && g_sSteamIdTablesCleanup[i][10] == 'p') + { + while (results[i].FetchRow()) + { + results[i].FetchString(0, sSteamId2, sizeof(sSteamId2)); + + int iAccountId = SteamId2ToAccountId(sSteamId2); + + FormatEx(sQuery, sizeof(sQuery), sql_insertPlayersAS2, iAccountId, sSteamId2, sSteamId2); + tTransaction.AddQuery(sQuery); + iQueries++; + } + } + // ck_playerrank + else if (g_sSteamIdTablesCleanup[i][3] == 'p' && g_sSteamIdTablesCleanup[i][10] == 'a') + { + while (results[i].FetchRow()) + { + results[i].FetchString(0, sSteamId2, sizeof(sSteamId2)); + results[i].FetchString(1, sSteamId64, sizeof(sSteamId64)); + + int iAccountId = SteamId2ToAccountId(sSteamId2); + + FormatEx(sQuery, sizeof(sQuery), sql_insertPlayersAS2S64, iAccountId, sSteamId2, sSteamId64, sSteamId2, sSteamId64); + tTransaction.AddQuery(sQuery); + iQueries++; + } + } + // ck_playertemp + else if (g_sSteamIdTablesCleanup[i][3] == 'p' && g_sSteamIdTablesCleanup[i][10] == 'e') + { + while (results[i].FetchRow()) + { + results[i].FetchString(0, sSteamId2, sizeof(sSteamId2)); + + int iAccountId = SteamId2ToAccountId(sSteamId2); + + FormatEx(sQuery, sizeof(sQuery), sql_insertPlayersAS2, iAccountId, sSteamId2, sSteamId2); + tTransaction.AddQuery(sQuery); + iQueries++; + } + } + // ck_playertimes + else if (g_sSteamIdTablesCleanup[i][3] == 'p' && g_sSteamIdTablesCleanup[i][10] == 'i') + { + while (results[i].FetchRow()) + { + results[i].FetchString(0, sSteamId2, sizeof(sSteamId2)); + results[i].FetchString(1, sName, sizeof(sName)); + + int iAccountId = SteamId2ToAccountId(sSteamId2); + + FormatEx(sQuery, sizeof(sQuery), sql_insertPlayersAS2N, iAccountId, sSteamId2, sName, sSteamId2, sName); + tTransaction.AddQuery(sQuery); + iQueries++; + } + } + // ck_prinfo + else if (g_sSteamIdTablesCleanup[i][3] == 'p' && g_sSteamIdTablesCleanup[i][4] == 'r') + { + while (results[i].FetchRow()) + { + results[i].FetchString(0, sSteamId2, sizeof(sSteamId2)); + results[i].FetchString(1, sName, sizeof(sName)); + + int iAccountId = SteamId2ToAccountId(sSteamId2); + + FormatEx(sQuery, sizeof(sQuery), sql_insertPlayersAS2N, iAccountId, sSteamId2, sName, sSteamId2, sName); + tTransaction.AddQuery(sQuery); + iQueries++; + } + } + // ck_vipadmins + else if (g_sSteamIdTablesCleanup[i][3] == 'v') + { + while (results[i].FetchRow()) + { + results[i].FetchString(0, sSteamId2, sizeof(sSteamId2)); + + int iAccountId = SteamId2ToAccountId(sSteamId2); + + FormatEx(sQuery, sizeof(sQuery), sql_insertPlayersAS2, iAccountId, sSteamId2, sSteamId2); + tTransaction.AddQuery(sQuery); + iQueries++; + } + } + + if (iQueries == 0) + { + delete tTransaction; + + // TODO: Call upgrade again? + continue; + } + + PrintToServer("Transaction for %s with %d queries started...", g_sSteamIdTablesCleanup[i], iQueries); + SQL_ExecuteTransaction(g_hDb, tTransaction, _, SQLTxn_InsertToPlayersFailed, .priority=DBPrio_High); + } +} + +public void SQLTxn_InsertToPlayersFailed(Database db, any data, int numQueries, const char[] error, int failIndex, any[] queryData) +{ + SetFailState("[SurfTimer] Failed while adding data to table ck_players! Error: %s", error); +} + +public void SQLTxn_GetPlayerDataFailed(Database db, any data, int numQueries, const char[] error, int failIndex, any[] queryData) +{ + SetFailState("[SurfTimer] Failed while getting data from table %s! Error: %s", g_sSteamIdTablesCleanup[failIndex], error); +} diff --git a/addons/sourcemod/scripting/surftimer/sql.sp b/addons/sourcemod/scripting/surftimer/sql.sp index f492ccba..19355cfe 100644 --- a/addons/sourcemod/scripting/surftimer/sql.sp +++ b/addons/sourcemod/scripting/surftimer/sql.sp @@ -54,6 +54,7 @@ public void db_setupDatabase() SQL_UnlockDatabase(g_hDb_Updates); LoopFloatDecimalTables(); CleanUpTablesRetvalsSteamId(); + SelectPlayersStuff(); // TODO: Remove this, is just for testing for (int i = 0; i < sizeof(g_failedTransactions); i++) g_failedTransactions[i] = 0; @@ -5515,14 +5516,14 @@ public void db_deleteZone(int client, int zoneid) public void SQLTxn_ZoneRemovalSuccess(Handle db, any client, int numQueries, Handle[] results, any[] queryData) { if (IsValidClient(client)) - CPrintToChat(client, "%t", "SQL9", g_szChatPrefix); + CPrintToChat(client, "%t", "SQL9", g_szChatPrefix); PrintToServer("[SurfTimer] Zone Removed Succesfully"); } public void SQLTxn_ZoneRemovalFailed(Handle db, any client, int numQueries, const char[] error, int failIndex, any[] queryData) { if (IsValidClient(client)) - CPrintToChat(client, "%t", "SQL10", g_szChatPrefix, error); + CPrintToChat(client, "%t", "SQL10", g_szChatPrefix, error); PrintToServer("[SurfTimer] Zone Removal Failed. Error: %s", error); return; } diff --git a/addons/sourcemod/scripting/test.sp b/addons/sourcemod/scripting/test.sp deleted file mode 100644 index 7594c199..00000000 --- a/addons/sourcemod/scripting/test.sp +++ /dev/null @@ -1,23 +0,0 @@ -#include - -char g_sSteamIdTablesCleanup[][] = { - "ck_bonus", - "ck_checkpoints", - "ck_latestrecords", - "ck_playeroptions2", - "ck_playerrank", - "ck_playertemp", - "ck_playertimes", - "ck_prinfo", - "ck_vipadmins" -}; - -public void OnPluginStart() -{ - char sQuery[256]; - for (int i = 0; i < sizeof(g_sSteamIdTablesCleanup); i++) - { - FormatEx(sQuery, sizeof(sQuery), "DELETE FROM \"%s\" WHERE steamid = \"STEAM_ID_STOP_IGNORING_RETVALS\";", g_sSteamIdTablesCleanup[i]); - LogMessage(sQuery); - } -} \ No newline at end of file