Skip to content

Commit

Permalink
Merge pull request #671 from shavitush/very_good_yes
Browse files Browse the repository at this point in the history
2.3.1
  • Loading branch information
shavitush authored Sep 22, 2018
2 parents c774f41 + 619e7da commit e9a203b
Show file tree
Hide file tree
Showing 7 changed files with 263 additions and 8 deletions.
42 changes: 41 additions & 1 deletion addons/sourcemod/scripting/include/shavit.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#endif
#define _shavit_included

#define SHAVIT_VERSION "2.3.0"
#define SHAVIT_VERSION "2.3.1"
#define STYLE_LIMIT 256
#define MAX_ZONES 64
#define MAX_NAME_LENGTH_SQL 32
Expand Down Expand Up @@ -599,6 +599,42 @@ native void Shavit_RestartTimer(int client, int track);
*/
native void Shavit_StopTimer(int client);

/**
* Deletes all map records for the specified map.
* Plugin will refresh if map is currently on.
*
* @param map Map name.
* @noreturn
*/
native void Shavit_WR_DeleteMap(const char[] map);

/**
* Deletes all map zones for the specified map.
* Plugin will refresh if map is currently on.
*
* @param map Map name.
* @noreturn
*/
native void Shavit_Zones_DeleteMap(const char[] map);

/**
* Deletes all replays for the specified map.
* Plugin will refresh if map is currently on.
*
* @param map Map name.
* @noreturn
*/
native void Shavit_Replay_DeleteMap(const char[] map);

/**
* Deletes tier setting for the specified map.
* Points recalculation will run right after this is finished.
*
* @param map Map name.
* @noreturn
*/
native void Shavit_Rankings_DeleteMap(const char[] map);

/**
* Finishes the map for a player, with their current timer stats.
* Will not teleport the player to anywhere, it's handled inside the mapzones plugin.
Expand Down Expand Up @@ -1244,8 +1280,10 @@ public void __pl_shavit_SetNTVOptional()
MarkNativeAsOptional("Shavit_OpenStatsMenu");
MarkNativeAsOptional("Shavit_PauseTimer");
MarkNativeAsOptional("Shavit_PrintToChat");
MarkNativeAsOptional("Shavit_Rankings_DeleteMap");
MarkNativeAsOptional("Shavit_ReloadReplay");
MarkNativeAsOptional("Shavit_ReloadReplays");
MarkNativeAsOptional("Shavit_Replay_DeleteMap");
MarkNativeAsOptional("Shavit_RestartTimer");
MarkNativeAsOptional("Shavit_ResumeTimer");
MarkNativeAsOptional("Shavit_SaveSnapshot");
Expand All @@ -1254,6 +1292,8 @@ public void __pl_shavit_SetNTVOptional()
MarkNativeAsOptional("Shavit_StartTimer");
MarkNativeAsOptional("Shavit_StopChatSound");
MarkNativeAsOptional("Shavit_StopTimer");
MarkNativeAsOptional("Shavit_WR_DeleteMap");
MarkNativeAsOptional("Shavit_ZoneExists");
MarkNativeAsOptional("Shavit_Zones_DeleteMap");
}
#endif
9 changes: 5 additions & 4 deletions addons/sourcemod/scripting/shavit-chat.sp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#undef REQUIRE_EXTENSIONS
#include <cstrike>

#define MAGIC_NUMBER 2147483648.0
#define MAXLENGTH_NAME 192
#define MAXLENGTH_TEXT 192
#define MAXLENGTH_MESSAGE 255
Expand Down Expand Up @@ -235,7 +236,7 @@ bool LoadChatConfig()
float fRank = StringToFloat(sRanks);

aChatTitle[fCRFrom] = fRank;
aChatTitle[fCRTo] = (aChatTitle[iCRRangeType] == Rank_Flat)? fRank:2147483648.0;
aChatTitle[fCRTo] = (aChatTitle[iCRRangeType] == Rank_Flat)? fRank:MAGIC_NUMBER;
}

aChatTitle[bCRFree] = view_as<bool>(kv.GetNum("free", false));
Expand Down Expand Up @@ -913,15 +914,15 @@ Action ShowRanksMenu(int client, int item)

if(!aCache[bCRFree])
{
if(aCache[fCRFrom] == 0)
if(aCache[fCRFrom] == 0.0 && (aCache[fCRFrom] == aCache[fCRTo] || aCache[fCRTo] == MAGIC_NUMBER))
{
FormatEx(sRequirements, 64, "%T", "ChatRanksMenu_Unranked", client);
}

else
{
// this is really ugly
bool bRanged = (aCache[fCRFrom] != aCache[fCRTo] && aCache[fCRTo] != 2147483648.0);
bool bRanged = (aCache[fCRFrom] != aCache[fCRTo] && aCache[fCRTo] != MAGIC_NUMBER);

if(aCache[iCRRangeType] == Rank_Flat)
{
Expand Down Expand Up @@ -1336,7 +1337,7 @@ int RealRandomInt(int min, int max)
random++;
}

return (RoundToCeil(float(random) / (float(2147483647) / float(max - min + 1))) + min - 1);
return (RoundToCeil(float(random) / (2147483647.0 / float(max - min + 1))) + min - 1);
}

void SQL_DBConnect()
Expand Down
80 changes: 80 additions & 0 deletions addons/sourcemod/scripting/shavit-core.sp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ bool gB_Late = false;
// modules
bool gB_Zones = false;
bool gB_WR = false;
bool gB_Replay = false;
bool gB_Rankings = false;

// cvars
ConVar gCV_Restart = null;
Expand Down Expand Up @@ -136,6 +138,7 @@ bool gB_HookedJump = false;
char gS_LogPath[PLATFORM_MAX_PATH];
int gI_GroundTicks[MAXPLAYERS+1];
MoveType gMT_MoveType[MAXPLAYERS+1];
char gS_DeleteMap[MAXPLAYERS+1][160];

// flags
int gI_StyleFlag[STYLE_LIMIT];
Expand Down Expand Up @@ -294,6 +297,9 @@ public void OnPluginStart()
#if defined DEBUG
RegConsoleCmd("sm_finishtest", Command_FinishTest);
#endif

// admin
RegAdminCmd("sm_deletemap", Command_DeleteMap, ADMFLAG_ROOT, "Deletes all map data. Usage: sm_deletemap <map>");
// commands END

// logs
Expand Down Expand Up @@ -343,6 +349,8 @@ public void OnPluginStart()

gB_Zones = LibraryExists("shavit-zones");
gB_WR = LibraryExists("shavit-wr");
gB_Replay = LibraryExists("shavit-replay");
gB_Rankings = LibraryExists("shavit-rankings");
}

public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue)
Expand Down Expand Up @@ -372,6 +380,16 @@ public void OnLibraryAdded(const char[] name)
{
gB_WR = true;
}

else if(StrEqual(name, "shavit-replay"))
{
gB_Replay = true;
}

else if(StrEqual(name, "shavit-rankings"))
{
gB_Rankings = true;
}
}

public void OnLibraryRemoved(const char[] name)
Expand All @@ -385,6 +403,16 @@ public void OnLibraryRemoved(const char[] name)
{
gB_WR = false;
}

else if(StrEqual(name, "shavit-replay"))
{
gB_Replay = false;
}

else if(StrEqual(name, "shavit-rankings"))
{
gB_Rankings = false;
}
}

public void OnMapStart()
Expand Down Expand Up @@ -564,6 +592,57 @@ public Action Command_FinishTest(int client, int args)
}
#endif

public Action Command_DeleteMap(int client, int args)
{
if(args == 0)
{
ReplyToCommand(client, "Usage: sm_deletemap <map>\nOnce a map is chosen, \"sm_deletemap confirm\" to run the deletion.");

return Plugin_Handled;
}

char[] sArgs = new char[160];
GetCmdArgString(sArgs, 160);

if(StrEqual(sArgs, "confirm") && strlen(gS_DeleteMap[client]) > 0)
{
if(gB_WR)
{
Shavit_WR_DeleteMap(gS_DeleteMap[client]);
ReplyToCommand(client, "Deleted all records for %s.", gS_DeleteMap[client]);
}

if(gB_Zones)
{
Shavit_Zones_DeleteMap(gS_DeleteMap[client]);
ReplyToCommand(client, "Deleted all zones for %s.", gS_DeleteMap[client]);
}

if(gB_Replay)
{
Shavit_Replay_DeleteMap(gS_DeleteMap[client]);
ReplyToCommand(client, "Deleted all replay data for %s.", gS_DeleteMap[client]);
}

if(gB_Rankings)
{
Shavit_Rankings_DeleteMap(gS_DeleteMap[client]);
ReplyToCommand(client, "Deleted all rankings for %s.", gS_DeleteMap[client]);
}

ReplyToCommand(client, "Finished deleting data for %s.", gS_DeleteMap[client]);
strcopy(gS_DeleteMap[client], 160, "");
}

else
{
strcopy(gS_DeleteMap[client], 160, sArgs);
ReplyToCommand(client, "Map to delete is now %s.\nRun \"sm_deletemap confirm\" to delete all data regarding the map %s.", gS_DeleteMap[client], gS_DeleteMap[client]);
}

return Plugin_Handled;
}

public Action Command_AutoBhop(int client, int args)
{
if(!IsValidClient(client))
Expand Down Expand Up @@ -1368,6 +1447,7 @@ public void OnClientPutInServer(int client)
gI_SHSW_FirstCombination[client] = -1;
gI_Track[client] = 0;
gI_Style[client] = 0;
strcopy(gS_DeleteMap[client], 160, "");

if(AreClientCookiesCached(client))
{
Expand Down
29 changes: 29 additions & 0 deletions addons/sourcemod/scripting/shavit-rankings.sp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,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_GetRankedPlayers", Native_GetRankedPlayers);
CreateNative("Shavit_Rankings_DeleteMap", Native_Rankings_DeleteMap);

RegPluginLibrary("shavit-rankings");

Expand Down Expand Up @@ -964,3 +965,31 @@ public int Native_GetRankedPlayers(Handle handler, int numParams)
{
return gI_RankedPlayers;
}

public int Native_Rankings_DeleteMap(Handle handler, int numParams)
{
char[] sMap = new char[160];
GetNativeString(1, sMap, 160);

char[] sQuery = new char[256];
FormatEx(sQuery, 256, "DELETE FROM %smaptiers WHERE map = '%s';", gS_MySQLPrefix, sMap);
gH_SQL.Query(SQL_DeleteMap_Callback, sQuery, StrEqual(gS_Map, sMap, false), DBPrio_High);
}

public void SQL_DeleteMap_Callback(Database db, DBResultSet results, const char[] error, any data)
{
if(results == null)
{
LogError("Timer (rankings deletemap) SQL query failed. Reason: %s", error);

return;
}

if(view_as<bool>(data))
{
gI_Tier = 1;

UpdateAllPoints();
UpdateRankedPlayers();
}
}
52 changes: 50 additions & 2 deletions addons/sourcemod/scripting/shavit-replay.sp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ ConVar gCV_BotWeapon = null;
// cached cvars
bool gB_Enabled = true;
float gF_ReplayDelay = 5.0;
float gF_TimeLimit = 5400.0;
float gF_TimeLimit = 7200.0;
int gI_DefaultTeam = 3;
bool gB_CentralBot = true;
int gI_BotShooting = 3;
Expand Down Expand Up @@ -167,6 +167,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
CreateNative("Shavit_IsReplayDataLoaded", Native_IsReplayDataLoaded);
CreateNative("Shavit_ReloadReplay", Native_ReloadReplay);
CreateNative("Shavit_ReloadReplays", Native_ReloadReplays);
CreateNative("Shavit_Replay_DeleteMap", Native_Replay_DeleteMap);
CreateNative("Shavit_SetReplayData", Native_SetReplayData);

// registers library, check "bool LibraryExists(const char[] name)" in order to use with other plugins
Expand Down Expand Up @@ -211,7 +212,7 @@ public void OnPluginStart()
// plugin convars
gCV_Enabled = CreateConVar("shavit_replay_enabled", "1", "Enable replay bot functionality?", 0, true, 0.0, true, 1.0);
gCV_ReplayDelay = CreateConVar("shavit_replay_delay", "5.0", "Time to wait before restarting the replay after it finishes playing.", 0, true, 0.0, true, 10.0);
gCV_TimeLimit = CreateConVar("shavit_replay_timelimit", "5400.0", "Maximum amount of time (in seconds) to allow saving to disk.\nDefault is 5400.0 (1:30 hours)\n0 - Disabled");
gCV_TimeLimit = CreateConVar("shavit_replay_timelimit", "7200.0", "Maximum amount of time (in seconds) to allow saving to disk.\nDefault is 7200 (2 hours)\n0 - Disabled");
gCV_DefaultTeam = CreateConVar("shavit_replay_defaultteam", "3", "Default team to make the bots join, if possible.\n2 - Terrorists/RED\n3 - Counter Terrorists/BLU", 0, true, 2.0, true, 3.0);
gCV_CentralBot = CreateConVar("shavit_replay_centralbot", "1", "Have one central bot instead of one bot per replay.\nTriggered with !replay.\nRestart the map for changes to take effect.\nThe disabled setting is not supported - use at your own risk.\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
gCV_BotShooting = CreateConVar("shavit_replay_botshooting", "3", "Attacking buttons to allow for bots.\n0 - none\1 - +attack\n2 - +attack2\n3 - both", 0, true, 0.0, true, 3.0);
Expand Down Expand Up @@ -449,6 +450,8 @@ public int Native_SetReplayData(Handle handler, int numParams)

ArrayList frames = view_as<ArrayList>(CloneHandle(GetNativeCell(2)));
gA_PlayerFrames[client] = frames.Clone();
delete frames;

gI_PlayerFrames[client] = gA_PlayerFrames[client].Length;
}

Expand Down Expand Up @@ -532,6 +535,39 @@ public int Native_GetReplayBotType(Handle handler, int numParams)
return view_as<int>((gB_CentralBot)? Replay_Central:Replay_Legacy);
}

public int Native_Replay_DeleteMap(Handle handler, int numParams)
{
char[] sMap = new char[160];
GetNativeString(1, sMap, 160);

for(int i = 0; i < gI_Styles; i++)
{
if(!ReplayEnabled(i))
{
continue;
}

for(int j = 0; j < ((gB_CentralBot)? TRACKS_SIZE:1); j++)
{
char[] sTrack = new char[4];
FormatEx(sTrack, 4, "_%d", j);

char[] sPath = new char[PLATFORM_MAX_PATH];
FormatEx(sPath, PLATFORM_MAX_PATH, "%s/%d/%s%s.replay", gS_ReplayFolder, i, sMap, (j > 0)? sTrack:"");

if(FileExists(sPath))
{
DeleteFile(sPath);
}
}
}

if(StrEqual(gS_Map, sMap, false))
{
OnMapStart();
}
}

public void Shavit_OnDatabaseLoaded()
{
gH_SQL = Shavit_GetDatabase();
Expand Down Expand Up @@ -1407,6 +1443,7 @@ public void Shavit_OnFinish(int client, int style, float time, int jumps, int st
return;
}

delete gA_Frames[style][track];
gA_Frames[style][track] = gA_PlayerFrames[client].Clone();

char[] sAuthID = new char[32];
Expand Down Expand Up @@ -1645,6 +1682,17 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3

else if(ReplayEnabled(Shavit_GetBhopStyle(client)) && Shavit_GetTimerStatus(client) == Timer_Running)
{
if((gI_PlayerFrames[client] / gF_Tickrate) > gF_TimeLimit)
{
// in case of bad timing
if(gB_HijackFrame[client])
{
gB_HijackFrame[client] = false;
}

return Plugin_Continue;
}

gA_PlayerFrames[client].Resize(gI_PlayerFrames[client] + 1);

gA_PlayerFrames[client].Set(gI_PlayerFrames[client], vecCurrentPosition[0], 0);
Expand Down
Loading

0 comments on commit e9a203b

Please sign in to comment.