This commit is contained in:
BotoX
2019-09-18 12:36:08 +02:00
parent 3807248278
commit add15450df
4 changed files with 238 additions and 66 deletions
@@ -105,6 +105,7 @@ ConVar g_Cvar_ExtendTimeStep;
ConVar g_Cvar_ExtendRoundStep;
ConVar g_Cvar_ExtendFragStep;
ConVar g_Cvar_ExcludeMaps;
ConVar g_Cvar_ExcludeMapsTime;
ConVar g_Cvar_IncludeMaps;
ConVar g_Cvar_IncludeMapsReserved;
ConVar g_Cvar_NoVoteMode;
@@ -122,6 +123,7 @@ Handle g_MapList = INVALID_HANDLE;
Handle g_NominateList = INVALID_HANDLE;
Handle g_NominateOwners = INVALID_HANDLE;
StringMap g_OldMapList;
StringMap g_TimeMapList;
Handle g_NextMapList = INVALID_HANDLE;
Handle g_VoteMenu = INVALID_HANDLE;
KeyValues g_Config;
@@ -224,6 +226,7 @@ public void OnPluginStart()
g_NominateList = CreateArray(arraySize);
g_NominateOwners = CreateArray(1);
g_OldMapList = new StringMap();
g_TimeMapList = new StringMap();
g_NextMapList = CreateArray(arraySize);
g_OfficialList = CreateArray(arraySize);
@@ -238,6 +241,7 @@ public void OnPluginStart()
g_Cvar_ExtendRoundStep = CreateConVar("mce_extend_roundstep", "5", "Specifies how many more rounds each extension makes", _, true, 1.0);
g_Cvar_ExtendFragStep = CreateConVar("mce_extend_fragstep", "10", "Specifies how many more frags are allowed when map is extended.", _, true, 5.0);
g_Cvar_ExcludeMaps = CreateConVar("mce_exclude", "5", "Specifies how many past maps to exclude from the vote.", _, true, 0.0);
g_Cvar_ExcludeMapsTime = CreateConVar("mce_exclude_time", "5", "Specifies how long in minutes an old map is excluded from the vote.", _, true, 0.0);
g_Cvar_IncludeMaps = CreateConVar("mce_include", "5", "Specifies how many maps to include in the vote.", _, true, 2.0, true, 7.0);
g_Cvar_IncludeMapsReserved = CreateConVar("mce_include_reserved", "2", "Specifies how many private/random maps to include in the vote.", _, true, 0.0, true, 5.0);
g_Cvar_NoVoteMode = CreateConVar("mce_novote", "1", "Specifies whether or not MapChooser should pick a map if no votes are received.", _, true, 0.0, true, 1.0);
@@ -406,7 +410,9 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
CreateNative("IsMapOfficial", Native_IsMapOfficial);
CreateNative("CanNominate", Native_CanNominate);
CreateNative("ExcludeMap", Native_ExcludeMap);
CreateNative("ExcludeMapTime", Native_ExcludeMapTime);
CreateNative("GetMapCooldown", Native_GetMapCooldown);
CreateNative("GetMapCooldownTime", Native_GetMapCooldownTime);
CreateNative("GetMapMinTime", Native_GetMapMinTime);
CreateNative("GetMapMaxTime", Native_GetMapMaxTime);
CreateNative("GetMapMinPlayers", Native_GetMapMinPlayers);
@@ -534,6 +540,9 @@ public void OnMapEnd()
GetCurrentMap(map, PLATFORM_MAX_PATH);
Cooldown = InternalGetMapCooldown(map);
g_OldMapList.SetValue(map, Cooldown, true);
Cooldown = InternalGetMapCooldownTime(map);
g_TimeMapList.SetValue(map, Cooldown, true);
}
StringMapSnapshot OldMapListSnapshot = g_OldMapList.Snapshot();
@@ -548,8 +557,20 @@ public void OnMapEnd()
else
g_OldMapList.Remove(map);
}
InternalStoreMapCooldowns();
delete OldMapListSnapshot;
StringMapSnapshot TimeMapListSnapshot = g_TimeMapList.Snapshot();
for(int i = 0; i < TimeMapListSnapshot.Length; i++)
{
TimeMapListSnapshot.GetKey(i, map, sizeof(map));
g_TimeMapList.GetValue(map, Cooldown);
if(Cooldown < GetTime())
g_TimeMapList.Remove(map);
}
delete OldMapListSnapshot;
InternalStoreMapCooldowns();
}
public void OnClientPutInServer(int client)
@@ -1552,7 +1573,7 @@ void CreateNextVote()
GetCurrentMap(map, PLATFORM_MAX_PATH);
RemoveStringFromArray(tempMaps, map);
if((GetConVarInt(g_Cvar_ExcludeMaps) && GetArraySize(tempMaps) > GetConVarInt(g_Cvar_ExcludeMaps)) && (InternalAreRestrictionsActive()))
if(GetConVarInt(g_Cvar_ExcludeMaps) && GetArraySize(tempMaps) > GetConVarInt(g_Cvar_ExcludeMaps) && InternalAreRestrictionsActive())
{
StringMapSnapshot OldMapListSnapshot = g_OldMapList.Snapshot();
for(int i = 0; i < OldMapListSnapshot.Length; i++)
@@ -1563,6 +1584,21 @@ void CreateNextVote()
delete OldMapListSnapshot;
}
if(GetConVarInt(g_Cvar_ExcludeMapsTime) && InternalAreRestrictionsActive())
{
StringMapSnapshot TimeMapListSnapshot = g_TimeMapList.Snapshot();
for(int i = 0; i < TimeMapListSnapshot.Length; i++)
{
TimeMapListSnapshot.GetKey(i, map, sizeof(map));
int Cooldown;
g_TimeMapList.GetValue(map, Cooldown);
if(Cooldown > GetTime())
RemoveStringFromArray(tempMaps, map);
}
delete TimeMapListSnapshot;
}
int voteSize = GetVoteSize(2);
int limit = (voteSize < GetArraySize(tempMaps) ? voteSize : GetArraySize(tempMaps));
@@ -2031,8 +2067,51 @@ public int Native_ExcludeMap(Handle plugin, int numParams)
return true;
}
public int Native_ExcludeMapTime(Handle plugin, int numParams)
{
if(!InternalAreRestrictionsActive())
return true;
int len;
GetNativeStringLength(1, len);
if(len <= 0)
return false;
char[] map = new char[len+1];
GetNativeString(1, map, len+1);
int Cooldown;
int Mode = GetNativeCell(3);
if(Mode == 0)
{
Cooldown = InternalGetMapCooldownTime(map);
}
else if(Mode == 1)
{
Cooldown = GetNativeCell(2) * 60;
}
else if(Mode == 2)
{
g_TimeMapList.GetValue(map, Cooldown);
int NewCooldown = GetTime() + GetNativeCell(2) * 60;
if(NewCooldown > Cooldown)
Cooldown = GetNativeCell(2) * 60;
}
Cooldown += GetTime();
g_TimeMapList.SetValue(map, Cooldown, true);
InternalStoreMapCooldowns();
return true;
}
public int Native_GetMapCooldown(Handle plugin, int numParams)
{
if(!InternalAreRestrictionsActive())
return 0;
int len;
GetNativeStringLength(1, len);
@@ -2048,6 +2127,26 @@ public int Native_GetMapCooldown(Handle plugin, int numParams)
return Cooldown;
}
public int Native_GetMapCooldownTime(Handle plugin, int numParams)
{
if(!InternalAreRestrictionsActive())
return 0;
int len;
GetNativeStringLength(1, len);
if(len <= 0)
return false;
char[] map = new char[len+1];
GetNativeString(1, map, len+1);
int Cooldown = 0;
g_TimeMapList.GetValue(map, Cooldown);
return Cooldown;
}
public int Native_GetMapMinTime(Handle plugin, int numParams)
{
int len;
@@ -2304,6 +2403,19 @@ stock int InternalGetMapCooldown(const char[] map)
return Cooldown;
}
stock int InternalGetMapCooldownTime(const char[] map)
{
int Cooldown = g_Cvar_ExcludeMapsTime.IntValue;
if(g_Config && g_Config.JumpToKey(map))
{
Cooldown = g_Config.GetNum("CooldownTime", Cooldown);
g_Config.Rewind();
}
return Cooldown;
}
void CheckMapRestrictions(bool time = false, bool players = false)
{
if(!InternalAreRestrictionsActive())
@@ -2513,10 +2625,10 @@ stock int InternalGetMapPlayerRestriction(const char[] map)
return 0;
}
stock int InternalAreRestrictionsActive()
stock bool InternalAreRestrictionsActive()
{
if (!GetConVarBool(g_Cvar_NoRestrictionTimeframeEnable))
return 1;
return true;
char sTime[8];
FormatTime(sTime, sizeof(sTime), "%H%M");
@@ -2531,10 +2643,10 @@ stock int InternalAreRestrictionsActive()
if ((MinTime <= CurTime <= MaxTime))
{
return 0;
return false;
}
return 1;
return true;
}
stock int FindIntInArray(int[] array, int size, int value)
@@ -2605,6 +2717,12 @@ stock void InternalRestoreMapCooldowns()
LogMessage("Restored cooldown: %s -> %d", map, Cooldown);
g_OldMapList.SetValue(map, Cooldown, true);
}
if((Cooldown = Cooldowns.GetNum("CooldownTime", -1)) > 0)
{
LogMessage("Restored time cooldown: %s -> %d", map, Cooldown);
g_TimeMapList.SetValue(map, Cooldown, true);
}
} while(Cooldowns.GotoNextKey(true));
delete Cooldowns;
@@ -2643,15 +2761,33 @@ stock void InternalStoreMapCooldowns()
Cooldowns.SetNum("Cooldown", Cooldown);
Cooldowns.Rewind();
}
delete OldMapListSnapshot;
StringMapSnapshot TimeMapListSnapshot = g_TimeMapList.Snapshot();
for(int i = 0; i < TimeMapListSnapshot.Length; i++)
{
TimeMapListSnapshot.GetKey(i, map, sizeof(map));
g_TimeMapList.GetValue(map, Cooldown);
if (!Cooldowns.JumpToKey(map, true))
{
LogMessage("Unable to create/find key: %s", map);
delete TimeMapListSnapshot;
delete Cooldowns;
return;
}
Cooldowns.SetNum("CooldownTime", Cooldown);
Cooldowns.Rewind();
}
delete TimeMapListSnapshot;
if(!Cooldowns.ExportToFile(sCooldownFile))
{
LogMessage("Unable to export cooldown file: \"%s\"", sCooldownFile);
delete OldMapListSnapshot;
delete Cooldowns;
return;
}
delete OldMapListSnapshot;
delete Cooldowns;
}