diff --git a/discord_verificiation/scripting/unloze_player_time.sp b/discord_verificiation/scripting/unloze_player_time.sp index 12b0f77..a4623d9 100644 --- a/discord_verificiation/scripting/unloze_player_time.sp +++ b/discord_verificiation/scripting/unloze_player_time.sp @@ -19,6 +19,8 @@ int g_iPlayerRTVCapacity; int g_iAvgHour_Contribution_per_player; int g_iPlayerTier[MAXPLAYERS + 1]; +StringMap g_GroupOverrides; // group name -> comma-separated override list + static Handle g_hForwardPlayerHours; static Handle g_hForwardPlayerTier; @@ -77,13 +79,80 @@ public Action time_query_activity(Handle timer, any data) return Plugin_Continue; } +public void LoadGroupOverrides() +{ + KeyValues kv = new KeyValues("Groups"); + char path[PLATFORM_MAX_PATH]; + BuildPath(Path_SM, path, sizeof(path), "configs/admin_groups.cfg"); + + if (!kv.ImportFromFile(path)) + { + delete kv; + return; + } + + // collect group names first + char groupNames[32][64]; + int groupCount = 0; + + if (kv.GotoFirstSubKey()) + { + do + { + char sName[64]; + kv.GetSectionName(sName, sizeof(sName)); + if (StrContains(sName, "tier", false) == 0) + { + strcopy(groupNames[groupCount], 64, sName); + groupCount++; + } + } + while (kv.GotoNextKey() && groupCount < 32); + } + + // now for each group, rewind and re-navigate fresh + for (int i = 0; i < groupCount; i++) + { + kv.Rewind(); + + if (!kv.JumpToKey(groupNames[i])) + continue; + + if (!kv.JumpToKey("Overrides")) + continue; + + if (!kv.GotoFirstSubKey(false)) + continue; + + char overrideList[512]; + overrideList[0] = '\0'; + + do + { + char cmd[64]; + kv.GetSectionName(cmd, sizeof(cmd)); + if (overrideList[0] != '\0') + StrCat(overrideList, sizeof(overrideList), ", "); + StrCat(overrideList, sizeof(overrideList), cmd); + } + while (kv.GotoNextKey(false)); + + g_GroupOverrides.SetString(groupNames[i], overrideList); + } + + delete kv; +} + public void OnPluginStart() { + g_GroupOverrides = new StringMap(); + LoadGroupOverrides(); if (!g_hDatabase) { Database.Connect(SQL_OnDatabaseConnect, "unloze_playtimestats"); } RegConsoleCmd("sm_playtime", Command_Time, "retreives total connection time on all connected servers"); + RegConsoleCmd("sm_tier", Command_Tier, "shows what tier features you have"); RegConsoleCmd("sm_topplaytime", Command_TopTime, "retreives top 1000 playtime highscores on all connected servers"); g_h_time_activity = CreateTimer(10.0, time_query_activity, INVALID_HANDLE, TIMER_REPEAT); @@ -258,7 +327,7 @@ public void OnClientPostAdminCheck(int client) { GetClientAuthId(client, AuthId_Steam2, g_csSID[client], sizeof(g_csSID[])); is_bot_player[client] = false; - g_iPlayerTier[client] = 0; + g_iPlayerTier[client] = -1; g_iPlayerTimeServer[client] = 0; if(!IsValidClient(client) || IsFakeClient(client)) return; @@ -344,8 +413,11 @@ public void SQL_OnQueryCompletedTimeServer(Database db, DBResultSet results, con Call_PushCell(iMinutes_Server); Call_Finish(); - SetPlayerTier(client); - SetTierRewards(client); + if (g_iPlayerTier[client] == -1) + { + SetPlayerTier(client); + SetTierRewards(client); + } } public void SetTierRewards(int client) @@ -400,6 +472,7 @@ public void SetPlayerTier(int client) return; } + int next_hours = 0; do { char sKey[16], sVal[16]; @@ -408,6 +481,7 @@ public void SetPlayerTier(int client) int tier = StringToInt(sVal); int hours = StringToInt(sKey); + next_hours = hours; if (hours > g_iPlayerTimeServer[client]) { break; @@ -416,17 +490,26 @@ public void SetPlayerTier(int client) } while (kv.GotoNextKey(false)); + if (g_iPlayerTier[client] == -1) + { + g_iPlayerTier[client] = 0; + } + Call_StartForward(g_hForwardPlayerTier); Call_PushCell(client); Call_PushCell(g_iPlayerTier[client]); Call_Finish(); + if (g_iPlayerTimeServer[client] < next_hours) + { + PrintToChat(client, "You need %i hours to reach next tier. Check your features with !sm_tier", next_hours - g_iPlayerTimeServer[client]); + } delete kv; } public void OnClientDisconnect(int client) { - g_iPlayerTier[client] = 0; + g_iPlayerTier[client] = -1; Format(g_csSID[client], sizeof(g_csSID[]), ""); is_bot_player[client] = false; g_iPlayerTimeServer[client] = 0; @@ -526,6 +609,43 @@ public Action Command_TopTime(int client, int args) return Plugin_Handled; } +public void PrintClientGroupOverrides(int client) +{ + AdminId id = GetUserAdmin(client); + if (id == INVALID_ADMIN_ID) + { + PrintToChat(client, "You have no tiers."); + return; + } + + int groupCount = GetAdminGroupCount(id); + if (groupCount == 0) + { + PrintToChat(client, "You have no tiers."); + return; + } + + for (int i = 0; i < groupCount; i++) + { + char groupName[64]; + GroupId grp = GetAdminGroup(id, i, groupName, sizeof(groupName)); + + if (grp == INVALID_GROUP_ID) + continue; + + char overrides[512]; + if (g_GroupOverrides.GetString(groupName, overrides, sizeof(overrides))) + PrintToChat(client, "access: %s", overrides); + } + PrintToChat(client, "Extra playermodels in !zclass."); +} + +public Action Command_Tier(int client, int args) +{ + PrintClientGroupOverrides(client); + return Plugin_Handled; +} + public Action Command_Time(int client, int args) { if (!g_hDatabase)