diff --git a/README.md b/README.md index 1495e2f9..6f0f1d94 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,7 @@ Replay - [x] Make replay bots dead if there's no replay data loaded. - [x] Clear player cache on spawn/death. - [x] Add admin interface. (delete replay data, `sm_deletereplay` for RCON admins. +- [ ] Bonus replay for default style. Stats -- @@ -132,8 +133,8 @@ Stats - [x] Redo *everything*. - [x] Add 'last online' field. - [x] Add `Shavit_GetWRCount(int client)`. +- [x] Stop calculating points on the fly and grab everything from the table. - [ ] Rework on points sorting and show weighting percentages. -- [ ] Stop calculating points on the fly and grab everything from the table. Miscellaneous -- @@ -172,16 +173,18 @@ Rankings **(NEW!)** - [x] Add natives. `float Shavit_GetPoints(int client)` `int Shavit_GetRank(int client)` `void Shavit_GetMapValues(float &points, float &idealtime)` - [x] Add native that checks the total amount of players with over 0 points. - [x] Add map tiers. `sm_tier` `sm_settier` -- [ ] Redirect to stats menu from `sm_top`. -- [ ] Deprecate the tables, use a `playertimes` column for map points and a `users` column for total points. -- [ ] Find a way to update newly calculated points for all records on a map with the least amount of queries possible. -- [ ] Remove idealtime and use the WR time for the default time instead. -- [ ] Remove deleted records from `playerpoints`. +- [x] Redirect to stats menu from `sm_top`. +- [x] Deprecate the tables, use a `playertimes` column for map points and a `users` column for total points. +- [x] Find a way to update newly calculated points for all records on a map with the least amount of queries possible. +- [x] Remove idealtime and use the WR time for the default time instead. +- [x] Remove deleted records from `playerpoints`. +- [x] Update every player's total points once per map. (MySQL only) Web Interface -- - [x] Implement points. - [x] Compatibility for unix timestamps. +- [ ] Compatibility for new points. Chat **(NEW!)** -- @@ -220,7 +223,7 @@ World Records - [x] Add `sm_recent` `sm_recentrecords` `sm_rr`. - [x] Add strafes/sync to the WR menu where available. - [x] Add 'player stats' to submenu. -- [ ] Grab points from `playertimes` instead of calculating on the fly. +- [x] Grab points from `playertimes` instead of calculating on the fly. - [ ] Add `sm_bwr` `sm_bonuswr` `sm_bonusworldrecord`. Time Limits diff --git a/scripting/include/shavit.inc b/scripting/include/shavit.inc index e49f5ef8..7959c9ad 100644 --- a/scripting/include/shavit.inc +++ b/scripting/include/shavit.inc @@ -167,7 +167,7 @@ char gS_ShortBhopStyles[MAX_STYLES][] = #if defined USES_STYLE_MULTIPLIERS // ranking system -float gI_RankingMultipliers[MAX_STYLES] = +float gF_RankingMultipliers[MAX_STYLES] = { 1.00, // Normal 1.30, // Sideways @@ -670,27 +670,6 @@ native float Shavit_GetPoints(int client); */ native int Shavit_GetRank(int client); -/** - * Gets ranking values for the current map. - * See CalculatePoints() in shavit-rankings. - * - * @param points Reference to map points. -1.0 if not set. - * @param idealtime Reference to ideal time. 0.0 if not set. - * @noreturn - */ -native void Shavit_GetMapValues(float &points, float &idealtime); - -/** - * Gets ranking values for a given map. - * See CalculatePoints() in shavit-rankings. - * - * @param map Map to get values from. - * @param points Reference to map points. -1.0 if not set. - * @param idealtime Reference to ideal time. 0.0 if not set. - * @noreturn - */ -native void Shavit_GetGivenMapValues(const char[] map, float &points, float &idealtime); - /** * Gets the amount of players with over 0 points. * @@ -698,17 +677,6 @@ native void Shavit_GetGivenMapValues(const char[] map, float &points, float &ide */ native int Shavit_GetRankedPlayers(); -/** - * Calculates points for given time, style, ideal time and points for the ideal time. - * - * @param time Time. - * @param idealtime Ideal time. - * @param style Bhop style. - * @param mappoints Points for the ideal time - * @return Calculated poiints. - */ -native float Shavit_CalculatePoints(float time, BhopStyle style, float idealtime, float mappoints); - /** * Force an HUD update for a player. Requires shavit-hud. * @@ -795,15 +763,12 @@ public SharedPlugin __pl_shavit = #if !defined REQUIRE_PLUGIN public void __pl_shavit_SetNTVOptional() { - MarkNativeAsOptional("Shavit_CalculatePoints"); MarkNativeAsOptional("Shavit_FinishMap"); MarkNativeAsOptional("Shavit_ForceHUDUpdate"); MarkNativeAsOptional("Shavit_FormatChat"); MarkNativeAsOptional("Shavit_GetBhopStyle"); MarkNativeAsOptional("Shavit_GetClientTime"); MarkNativeAsOptional("Shavit_GetClientJumps"); - MarkNativeAsOptional("Shavit_GetGivenMapValues"); - MarkNativeAsOptional("Shavit_GetMapValues"); MarkNativeAsOptional("Shavit_GetPlayerPB"); MarkNativeAsOptional("Shavit_GetPoints"); MarkNativeAsOptional("Shavit_GetRank"); diff --git a/scripting/shavit-chat.sp b/scripting/shavit-chat.sp index f3e2acb1..39c5b784 100644 --- a/scripting/shavit-chat.sp +++ b/scripting/shavit-chat.sp @@ -261,6 +261,8 @@ public void LoadChatCache(int client) strcopy(gS_Cached_ClanTag[client], 32, sBuffer); } } + + UpdateClanTag(client); } public void ResetCache() diff --git a/scripting/shavit-core.sp b/scripting/shavit-core.sp index 122816cb..0399ded8 100644 --- a/scripting/shavit-core.sp +++ b/scripting/shavit-core.sp @@ -978,8 +978,8 @@ public void SQL_DBConnect() gH_SQL.Driver.GetIdentifier(sDriver, 8); gB_MySQL = StrEqual(sDriver, "mysql", false); - char[] sQuery = new char[256]; - FormatEx(sQuery, 256, "CREATE TABLE IF NOT EXISTS `%susers` (`auth` VARCHAR(32) NOT NULL, `name` VARCHAR(32), `country` VARCHAR(128), `ip` VARCHAR(64), `lastlogin` %s NOT NULL DEFAULT -1, PRIMARY KEY (`auth`));", gS_MySQLPrefix, gB_MySQL? "INT":"INTEGER"); + char[] sQuery = new char[512]; + FormatEx(sQuery, 512, "CREATE TABLE IF NOT EXISTS `%susers` (`auth` VARCHAR(32) NOT NULL, `name` VARCHAR(32), `country` VARCHAR(128), `ip` VARCHAR(64), `lastlogin` %s NOT NULL DEFAULT -1, `points` FLOAT NOT NULL DEFAULT 0, PRIMARY KEY (`auth`));", gS_MySQLPrefix, gB_MySQL? "INT":"INTEGER"); // CREATE TABLE IF NOT EXISTS gH_SQL.Query(SQL_CreateTable_Callback, sQuery); @@ -997,6 +997,9 @@ public void SQL_CreateTable_Callback(Database db, DBResultSet results, const cha char[] sQuery = new char[64]; FormatEx(sQuery, 64, "SELECT lastlogin FROM %susers LIMIT 1;", gS_MySQLPrefix); gH_SQL.Query(SQL_TableMigration1_Callback, sQuery, 0, DBPrio_High); + + FormatEx(sQuery, 64, "SELECT points FROM %susers LIMIT 1;", gS_MySQLPrefix); + gH_SQL.Query(SQL_TableMigration2_Callback, sQuery, 0, DBPrio_High); } public void SQL_TableMigration1_Callback(Database db, DBResultSet results, const char[] error, any data) @@ -1019,6 +1022,26 @@ public void SQL_AlterTable1_Callback(Database db, DBResultSet results, const cha } } +public void SQL_TableMigration2_Callback(Database db, DBResultSet results, const char[] error, any data) +{ + if(results == null) + { + char[] sQuery = new char[128]; + FormatEx(sQuery, 128, "ALTER TABLE `%susers` ADD %s;", gS_MySQLPrefix, gB_MySQL? "(`points` FLOAT NOT NULL DEFAULT 0)":"COLUMN `points` FLOAT NOT NULL DEFAULT 0"); + gH_SQL.Query(SQL_AlterTable2_Callback, sQuery); + } +} + +public void SQL_AlterTable2_Callback(Database db, DBResultSet results, const char[] error, any data) +{ + if(results == null) + { + LogError("Timer error! Table alteration 2 (core) failed. Reason: %s", error); + + return; + } +} + public void PreThink(int client) { sv_airaccelerate.IntValue = (gI_StyleProperties[gBS_Style[client]] & STYLE_100AA)? 100:gI_CachedDefaultAA; diff --git a/scripting/shavit-rankings.sp b/scripting/shavit-rankings.sp index 23c39a41..1127d45f 100644 --- a/scripting/shavit-rankings.sp +++ b/scripting/shavit-rankings.sp @@ -21,6 +21,7 @@ #include #undef REQUIRE_PLUGIN +#define USES_STYLE_PROPERTIES #define USES_STYLE_MULTIPLIERS #include @@ -35,27 +36,22 @@ Handle gH_Forwards_OnRankUpdated = null; // cache char gS_Map[256]; -float gF_IdealTime = 0.0; -float gF_MapPoints = -1.0; -int gI_NeededRecordsAmount = 0; -int gI_CachedRecordsAmount = 0; int gI_RankedPlayers = 0; char gS_CachedMap[MAXPLAYERS+1][192]; -int gI_MapTier = -1; +float gF_MapTier = 1.0; bool gB_ChatMessage[MAXPLAYERS+1]; float gF_PlayerPoints[MAXPLAYERS+1]; int gI_PlayerRank[MAXPLAYERS+1]; -bool gB_PointsToChat[MAXPLAYERS+1]; bool gB_CheckRankedPlayers = false; -StringMap gSM_Points = null; -StringMap gSM_Time = null; - // convars ConVar gCV_TopAmount = null; +ConVar gCV_TiersDB = null; +ConVar gCV_PointsPerTier = null; +ConVar gCV_PlayersToCalculate = null; // database handles Database gH_SQL = null; @@ -72,7 +68,7 @@ public Plugin myinfo = { name = "[shavit] Rankings", author = "shavit", - description = "Ranking system for shavit's bhop timer.", + description = "Rankings system for shavit's bhop timer.", version = SHAVIT_VERSION, url = "https://github.com/shavitush/bhoptimer" } @@ -81,10 +77,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max { CreateNative("Shavit_GetPoints", Native_GetPoints); CreateNative("Shavit_GetRank", Native_GetRank); - CreateNative("Shavit_GetMapValues", Native_GetMapValues); - CreateNative("Shavit_GetGivenMapValues", Native_GetGivenMapValues); CreateNative("Shavit_GetRankedPlayers", Native_GetRankedPlayers); - CreateNative("Shavit_CalculatePoints", Native_CalculatePoints); RegPluginLibrary("shavit-rankings"); @@ -101,20 +94,11 @@ public void OnAllPluginsLoaded() public void OnPluginStart() { - // cache - gSM_Points = new StringMap(); - gSM_Time = new StringMap(); - // forwards gH_Forwards_OnRankUpdated = CreateGlobalForward("Shavit_OnRankUpdated", ET_Event, Param_Cell); - // database connections - Shavit_GetDB(gH_SQL); - SQL_SetPrefix(); - SetSQLInfo(); - // player commands - RegConsoleCmd("sm_points", Command_Points, "Prints the points and ideal time for the map."); + RegConsoleCmd("sm_points", Command_Points, "Prints the points you will get for a time on the default style."); RegConsoleCmd("sm_rank", Command_Rank, "Shows your current rank."); RegConsoleCmd("sm_prank", Command_Rank, "Shows your current rank. (sm_rank alias)"); RegConsoleCmd("sm_top", Command_Top, "Shows the top players menu."); @@ -123,24 +107,25 @@ public void OnPluginStart() RegConsoleCmd("sm_maptier", Command_Tier, "Prints the map's tier to chat. (sm_tier alias)"); // admin commands - RegAdminCmd("sm_setpoints", Command_SetPoints, ADMFLAG_ROOT, "Set points for a defined ideal time. sm_setpoints