From 95e8bf647551231b2fe9f8a817c47793a8759c38 Mon Sep 17 00:00:00 2001 From: neon <> Date: Sat, 22 Sep 2018 11:49:43 +0200 Subject: [PATCH] mapchooser_extended: make certain maps only available for VIPs --- .../scripting/include/mapchooser_extended.inc | 2 + .../scripting/mapchooser_extended.sp | 29 +++ .../scripting/nominations_extended.sp | 225 +++++++++++++++++- .../mapchooser_extended.phrases.txt | 10 + 4 files changed, 263 insertions(+), 3 deletions(-) diff --git a/mapchooser_extended/scripting/include/mapchooser_extended.inc b/mapchooser_extended/scripting/include/mapchooser_extended.inc index d1c3804e..f8f8e849 100644 --- a/mapchooser_extended/scripting/include/mapchooser_extended.inc +++ b/mapchooser_extended/scripting/include/mapchooser_extended.inc @@ -130,6 +130,8 @@ native int GetMapGroups(const char[] map, int[] groups, int size); // >=0 = Group _max -> Group full native int GetMapGroupRestriction(const char[] map, int client = 0); +native bool GetMapVIPRestriction(const char[] map); + public SharedPlugin __pl_mapchooser_extended = { name = "mapchooser", diff --git a/mapchooser_extended/scripting/mapchooser_extended.sp b/mapchooser_extended/scripting/mapchooser_extended.sp index 2b6c998a..2d7ab0f7 100644 --- a/mapchooser_extended/scripting/mapchooser_extended.sp +++ b/mapchooser_extended/scripting/mapchooser_extended.sp @@ -411,6 +411,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max CreateNative("GetMapPlayerRestriction", Native_GetMapPlayerRestriction); CreateNative("GetMapGroups", Native_GetMapGroups); CreateNative("GetMapGroupRestriction", Native_GetMapGroupRestriction); + CreateNative("GetMapVIPRestriction", Native_GetMapVIPRestriction); return APLRes_Success; } @@ -1691,6 +1692,9 @@ void CreateNextVote() b = GetRandomInt(0, GetArraySize(tempMaps) - 1); GetArrayString(tempMaps, b, map, PLATFORM_MAX_PATH); + if(!InternalGetMapVIPRestriction(map)) + continue; + if(InternalGetMapTimeRestriction(map) != 0) continue; @@ -2296,6 +2300,19 @@ public int Native_GetMapGroupRestriction(Handle plugin, int numParams) return -1; } +public int Native_GetMapVIPRestriction(Handle plugin, int numParams) +{ + int len; + GetNativeStringLength(1, len); + + if(len <= 0) + return false; + + char[] map = new char[len+1]; + GetNativeString(1, map, len+1); + + return InternalGetMapVIPRestriction(map); +} stock void AddMapItem(const char[] map) { @@ -2594,6 +2611,18 @@ stock int FindIntInArray(int[] array, int size, int value) return -1; } +stock bool InternalGetMapVIPRestriction(const char[] map) +{ + int VIP = 0; + + if(g_Config && g_Config.JumpToKey(map)) + { + VIP = g_Config.GetNum("VIP", VIP); + g_Config.Rewind(); + } + + return view_as(VIP); +} stock void InternalRestoreMapCooldowns() { diff --git a/mapchooser_extended/scripting/nominations_extended.sp b/mapchooser_extended/scripting/nominations_extended.sp index c22c6840..2916222a 100644 --- a/mapchooser_extended/scripting/nominations_extended.sp +++ b/mapchooser_extended/scripting/nominations_extended.sp @@ -58,6 +58,7 @@ Handle g_Cvar_ExcludeCurrent = INVALID_HANDLE; Handle g_MapList = INVALID_HANDLE; Handle g_AdminMapList = INVALID_HANDLE; Menu g_MapMenu; +Menu g_VIPMapMenu; Menu g_AdminMapMenu; int g_mapFileSerial = -1; int g_AdminMapFileSerial = -1; @@ -190,6 +191,11 @@ void UpdateMapMenus() g_MapMenu = BuildMapMenu(""); + if(g_VIPMapMenu != INVALID_HANDLE) + delete g_VIPMapMenu; + + g_VIPMapMenu = BuildVIPMapMenu(""); + if(g_AdminMapMenu != INVALID_HANDLE) delete g_AdminMapMenu; @@ -510,6 +516,14 @@ public Action Command_Nominate(int client, int args) return Plugin_Handled; } + bool VIPRestriction = GetMapVIPRestriction(mapname); + if((VIPRestriction) && !(CheckCommandAccess(client, "sm_tag", ADMFLAG_CUSTOM1) || CheckCommandAccess(client, "sm_kick", ADMFLAG_KICK))) + { + CPrintToChat(client, "[NE] %t", "Map Nominate VIP Error"); + + return Plugin_Handled; + } + int TimeRestriction = GetMapTimeRestriction(mapname); if(TimeRestriction) { @@ -628,8 +642,18 @@ public int Handler_NominateListMenu(Menu menu, MenuAction action, int param1, in void AttemptNominate(int client, const char[] filter = "") { Menu menu = g_MapMenu; - if(filter[0]) - menu = BuildMapMenu(filter); + + if(CheckCommandAccess(client, "sm_tag", ADMFLAG_CUSTOM1) || CheckCommandAccess(client, "sm_kick", ADMFLAG_KICK)) + { + menu = g_VIPMapMenu; + if(filter[0]) + menu = BuildVIPMapMenu(filter); + } + else + { + if(filter[0]) + menu = BuildMapMenu(filter); + } SetMenuTitle(menu, "%T", "Nominate Title", client); DisplayMenu(menu, client, MENU_TIME_FOREVER); @@ -670,6 +694,27 @@ Menu BuildMapMenu(const char[] filter) return menu; } +Menu BuildVIPMapMenu(const char[] filter) +{ + Menu menu = CreateMenu(Handler_VIPMapSelectMenu, MENU_ACTIONS_DEFAULT|MenuAction_DrawItem|MenuAction_DisplayItem); + + static char map[PLATFORM_MAX_PATH]; + + for(int i = 0; i < GetArraySize(g_MapList); i++) + { + GetArrayString(g_MapList, i, map, sizeof(map)); + + if(!filter[0] || StrContains(map, filter, false) != -1) + { + AddMenuItem(menu, map, map); + } + } + + SetMenuExitButton(menu, true); + + return menu; +} + Menu BuildAdminMapMenu(const char[] filter) { Menu menu = CreateMenu(Handler_AdminMapSelectMenu, MENU_ACTIONS_DEFAULT|MenuAction_DrawItem|MenuAction_DisplayItem); @@ -750,6 +795,181 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p g_Player_NominationDelay[param1] = GetTime() + GetConVarInt(g_Cvar_NominateDelay); } + case MenuAction_DrawItem: + { + static char map[PLATFORM_MAX_PATH]; + GetMenuItem(menu, param2, map, sizeof(map)); + + int status; + + if(!GetTrieValue(g_mapTrie, map, status)) + { + LogError("Menu selection of item not in trie. Major logic problem somewhere."); + return ITEMDRAW_DEFAULT; + } + + if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED) + return ITEMDRAW_DISABLED; + + if(GetMapTimeRestriction(map) || GetMapPlayerRestriction(map) || GetMapGroupRestriction(map, param1) >= 0 || GetMapVIPRestriction(map)) + return ITEMDRAW_DISABLED; + + return ITEMDRAW_DEFAULT; + } + + case MenuAction_DisplayItem: + { + static char map[PLATFORM_MAX_PATH]; + GetMenuItem(menu, param2, map, sizeof(map)); + + int mark = GetConVarInt(g_Cvar_MarkCustomMaps); + bool official; + + int status; + + if(!GetTrieValue(g_mapTrie, map, status)) + { + LogError("Menu selection of item not in trie. Major logic problem somewhere."); + return 0; + } + + static char buffer[100]; + static char display[150]; + + if(mark) + official = IsMapOfficial(map); + + if(mark && !official) + { + switch(mark) + { + case 1: + { + Format(buffer, sizeof(buffer), "%T", "Custom Marked", param1, map); + } + + case 2: + { + Format(buffer, sizeof(buffer), "%T", "Custom", param1, map); + } + } + } + else + strcopy(buffer, sizeof(buffer), map); + + if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED) + { + if((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT) + { + Format(display, sizeof(display), "%s (%T)", buffer, "Current Map", param1); + return RedrawMenuItem(display); + } + + if((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) + { + int Cooldown = GetMapCooldown(map); + Format(display, sizeof(display), "%s (%T %d)", buffer, "Recently Played", param1, Cooldown); + return RedrawMenuItem(display); + } + + if((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED) + { + Format(display, sizeof(display), "%s (%T)", buffer, "Nominated", param1); + return RedrawMenuItem(display); + } + } + + bool VIPRestriction = GetMapVIPRestriction(map); + if(VIPRestriction) + { + Format(display, sizeof(display), "%s (%T)", buffer, "VIP Restriction", param1); + return RedrawMenuItem(display); + } + + int TimeRestriction = GetMapTimeRestriction(map); + if(TimeRestriction) + { + Format(display, sizeof(display), "%s (%T)", buffer, "Map Time Restriction", param1, "+", RoundToFloor(float(TimeRestriction / 60)), TimeRestriction % 60); + return RedrawMenuItem(display); + } + + int PlayerRestriction = GetMapPlayerRestriction(map); + if(PlayerRestriction) + { + if(PlayerRestriction < 0) + Format(display, sizeof(display), "%s (%T)", buffer, "Map Player Restriction", param1, "+", PlayerRestriction * -1); + else + Format(display, sizeof(display), "%s (%T)", buffer, "Map Player Restriction", param1, "-", PlayerRestriction); + + return RedrawMenuItem(display); + } + + int GroupRestriction = GetMapGroupRestriction(map, param1); + if(GroupRestriction >= 0) + { + Format(display, sizeof(display), "%s (%T)", buffer, "Map Group Restriction", param1, GroupRestriction); + return RedrawMenuItem(display); + } + + if(mark && !official) + return RedrawMenuItem(buffer); + + return 0; + } + } + + return 0; +} + +public int Handler_VIPMapSelectMenu(Menu menu, MenuAction action, int param1, int param2) +{ + switch(action) + { + case MenuAction_End: + { + if(menu != g_MapMenu) + delete menu; + } + case MenuAction_Select: + { + if(g_Player_NominationDelay[param1] > GetTime()) + { + PrintToChat(param1, "[NE] Please wait %d seconds before you can nominate again", g_Player_NominationDelay[param1] - GetTime()); + DisplayMenuAtItem(menu, param1, GetMenuSelectionPosition(), MENU_TIME_FOREVER); + return 0; + } + + static char map[PLATFORM_MAX_PATH]; + char name[MAX_NAME_LENGTH]; + GetMenuItem(menu, param2, map, sizeof(map)); + + GetClientName(param1, name, MAX_NAME_LENGTH); + + NominateResult result = NominateMap(map, false, param1); + + /* Don't need to check for InvalidMap because the menu did that already */ + if(result == Nominate_AlreadyInVote) + { + PrintToChat(param1, "[NE] %t", "Map Already Nominated"); + return 0; + } + else if(result == Nominate_VoteFull) + { + PrintToChat(param1, "[NE] %t", "Max Nominations"); + return 0; + } + + SetTrieValue(g_mapTrie, map, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED); + + if(result == Nominate_Added) + PrintToChatAll("[NE] %t", "Map Nominated", name, map); + else if(result == Nominate_Replaced) + PrintToChatAll("[NE] %t", "Map Nomination Changed", name, map); + + LogMessage("%s nominated %s", name, map); + g_Player_NominationDelay[param1] = GetTime() + GetConVarInt(g_Cvar_NominateDelay); + } + case MenuAction_DrawItem: { static char map[PLATFORM_MAX_PATH]; @@ -838,7 +1058,6 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p if(TimeRestriction) { Format(display, sizeof(display), "%s (%T)", buffer, "Map Time Restriction", param1, "+", RoundToFloor(float(TimeRestriction / 60)), TimeRestriction % 60); - return RedrawMenuItem(display); } diff --git a/mapchooser_extended/translations/mapchooser_extended.phrases.txt b/mapchooser_extended/translations/mapchooser_extended.phrases.txt index 9d236787..c8e4e6e0 100644 --- a/mapchooser_extended/translations/mapchooser_extended.phrases.txt +++ b/mapchooser_extended/translations/mapchooser_extended.phrases.txt @@ -106,6 +106,11 @@ "en" "*{1}" } + "Map Nominate VIP Error" + { + "en" "Only VIPs can nominate this map." + } + "Map Nominate Time Error" { "#format" "{1:d},{2:d}" @@ -148,6 +153,11 @@ "en" "Group max: {1}" } + "VIP Restriction" + { + "en" "VIP only" + } + "Nomination Removed Time Error" { "#format" "{1:s}"