Skip to content

Commit

Permalink
Merge pull request #766 from shavitush/very_good_yes
Browse files Browse the repository at this point in the history
2.5.0
  • Loading branch information
shavitush authored Mar 28, 2019
2 parents 2f58cca + 40d4431 commit 95d9cad
Show file tree
Hide file tree
Showing 16 changed files with 1,237 additions and 803 deletions.
5 changes: 5 additions & 0 deletions addons/sourcemod/configs/shavit-styles.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
{
"0"
{
// Accessibility
"enabled" "1" // When disabled, style will be unusable. -1 to also make the style not show in menus.
"inaccessible" "0" // This setting makes it so you can't manually switch to this style but only by functionality from timer modules.
// Strings
"name" "Normal" // Style name.
"shortname" "NM" // Short style name.
Expand Down Expand Up @@ -41,6 +45,7 @@
"block_pleft" "0" // Block +left. 2 to stop timer.
"block_pright" "0" // Block +right. 2 to stop timer.
"block_pstrafe" "0" // Prevent button inconsistencies (including +pstrafe). May have false positives when players lag. Will prevent some strafe hacks too. Set this to 2 to also stop the timer.
"kzcheckpoints" "0" // KZ styled checkpoints. They reset upon timer start and you don't get reverted to a save state, and you cannot save when airborne or someone else's checkpoints.

// Feature excluding
"unranked" "0" // Unranked style. No ranking points and no records.
Expand Down
21 changes: 19 additions & 2 deletions 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.4.1"
#define SHAVIT_VERSION "2.5.0"
#define STYLE_LIMIT 256
#define MAX_ZONES 64
#define MAX_NAME_LENGTH_SQL 32
Expand Down Expand Up @@ -157,6 +157,9 @@ enum struct stylesettings_t
float fRankingMultiplier;
int iSpecial;
int iOrdering;
bool bInaccessible;
int iEnabled;
bool bKZCheckpoints;
}

enum struct chatstrings_t
Expand Down Expand Up @@ -495,6 +498,20 @@ forward void Shavit_OnDatabaseLoaded();
*/
forward void Shavit_OnChatConfigLoaded();

/**
* Called when a player teleports with checkpoints.
*
* @return Plugin_Continue to allow teleporting, anything else to prevent.
*/
forward Action Shavit_OnTeleport(int client);

/**
* Called when a player teleports with checkpoints.
*
* @return Plugin_Continue to allow teleporting, anything else to prevent.
*/
forward Action Shavit_OnSave(int client);

/**
* Called when a player enters a zone.
*
Expand Down Expand Up @@ -701,7 +718,7 @@ native void Shavit_Rankings_DeleteMap(const char[] map);
*
* @param client Client index.
* @param style Style.
* @param force Ignore style permissions.
* @param force Ignore style permissions. This being true will bypass the `inaccessible` style setting as well.
* @param manual Is it a manual style change? (Was it caused by user interaction?)
* @param noforward Bypasses the call to `Shavit_OnStyleChanged`.
* @return False if failed due to lack of access, true otherwise.
Expand Down
69 changes: 46 additions & 23 deletions addons/sourcemod/scripting/shavit-chat.sp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public Action Hook_SayText2(UserMsg msg_id, any msg, const int[] players, int pl
char sName[MAXLENGTH_NAME];
char sCMessage[MAXLENGTH_CMESSAGE];

if((gCV_CustomChat.IntValue > 0 && (CheckCommandAccess(client, "shavit_chat", ADMFLAG_CHAT) || gCV_CustomChat.IntValue == 2)) && gI_ChatSelection[client] == -1)
if(HasCustomChat(client) && gI_ChatSelection[client] == -1)
{
if(gB_NameEnabled[client])
{
Expand Down Expand Up @@ -614,11 +614,19 @@ public void OnClientCookiesCached(int client)

public void OnClientPutInServer(int client)
{
gB_NameEnabled[client] = false;
strcopy(gS_CustomName[client], 128, "");
gB_NameEnabled[client] = true;
strcopy(gS_CustomName[client], 128, "{team}{name}");

gB_MessageEnabled[client] = true;
strcopy(gS_CustomMessage[client], 128, "{default}");
}

gB_MessageEnabled[client] = false;
strcopy(gS_CustomMessage[client], 128, "");
public void OnClientDisconnect(int client)
{
if(HasCustomChat(client))
{
SaveToDatabase(client);
}
}

public void OnClientPostAdminCheck(int client)
Expand Down Expand Up @@ -669,7 +677,7 @@ public Action Command_CCName(int client, int args)
return Plugin_Handled;
}

if(!(gCV_CustomChat.IntValue > 0 && (CheckCommandAccess(client, "shavit_chat", ADMFLAG_CHAT) || gCV_CustomChat.IntValue == 2)))
if(!HasCustomChat(client))
{
Shavit_PrintToChat(client, "%T", "NoCommandAccess", client);

Expand All @@ -694,8 +702,6 @@ public Action Command_CCName(int client, int args)

gB_NameEnabled[client] = false;

SaveToDatabase(client);

return Plugin_Handled;
}

Expand All @@ -704,8 +710,6 @@ public Action Command_CCName(int client, int args)
gB_NameEnabled[client] = true;
strcopy(gS_CustomName[client], 128, sArgs);

SaveToDatabase(client);

return Plugin_Handled;
}

Expand All @@ -718,7 +722,7 @@ public Action Command_CCMessage(int client, int args)
return Plugin_Handled;
}

if(!(gCV_CustomChat.IntValue > 0 && (CheckCommandAccess(client, "shavit_chat", ADMFLAG_CHAT) || gCV_CustomChat.IntValue == 2)))
if(!HasCustomChat(client))
{
Shavit_PrintToChat(client, "%T", "NoCommandAccess", client);

Expand All @@ -743,8 +747,6 @@ public Action Command_CCMessage(int client, int args)

gB_MessageEnabled[client] = false;

SaveToDatabase(client);

return Plugin_Handled;
}

Expand All @@ -753,8 +755,6 @@ public Action Command_CCMessage(int client, int args)
gB_MessageEnabled[client] = true;
strcopy(gS_CustomMessage[client], 16, sArgs);

SaveToDatabase(client);

return Plugin_Handled;
}

Expand All @@ -777,7 +777,7 @@ Action ShowChatRanksMenu(int client, int item)
FormatEx(sDisplay, MAXLENGTH_DISPLAY, "%T\n ", "AutoAssign", client);
menu.AddItem("-2", sDisplay, (gI_ChatSelection[client] == -2)? ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);

if(gCV_CustomChat.IntValue > 0 && (CheckCommandAccess(client, "shavit_chat", ADMFLAG_CHAT) || gCV_CustomChat.IntValue == 2))
if(HasCustomChat(client))
{
FormatEx(sDisplay, MAXLENGTH_DISPLAY, "%T\n ", "CustomChat", client);
menu.AddItem("-1", sDisplay, (gI_ChatSelection[client] == -1)? ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
Expand Down Expand Up @@ -1058,12 +1058,15 @@ void PreviewChat(int client, int rank)
EndMessage();
}

bool HasRankAccess(int client, int rank)
bool HasCustomChat(int client)
{
bool bAllowCustom = gCV_CustomChat.IntValue > 0 && (CheckCommandAccess(client, "shavit_chat", ADMFLAG_CHAT) || gCV_CustomChat.IntValue == 2);
return (gCV_CustomChat.IntValue > 0 && (CheckCommandAccess(client, "shavit_chat", ADMFLAG_CHAT) || gCV_CustomChat.IntValue == 2));
}

bool HasRankAccess(int client, int rank)
{
if(rank == -2 ||
(rank == -1 && bAllowCustom))
(rank == -1 && HasCustomChat(client)))
{
return true;
}
Expand Down Expand Up @@ -1329,9 +1332,22 @@ void SQL_DBConnect()
bool bMySQL = StrEqual(sDriver, "mysql", false);

char sQuery[512];
FormatEx(sQuery, 512, "CREATE TABLE IF NOT EXISTS `%schat` (`auth` CHAR(32) NOT NULL, `name` INT NOT NULL DEFAULT 0, `ccname` CHAR(128) COLLATE 'utf8mb4_unicode_ci', `message` INT NOT NULL DEFAULT 0, `ccmessage` CHAR(16) COLLATE 'utf8mb4_unicode_ci', PRIMARY KEY (`auth`))%s;", gS_MySQLPrefix, (bMySQL)? " ENGINE=INNODB":"");

if(bMySQL)
{
FormatEx(sQuery, 512,
"CREATE TABLE IF NOT EXISTS `%schat` (`auth` VARCHAR(32) NOT NULL, `name` INT NOT NULL DEFAULT 0, `ccname` VARCHAR(128) COLLATE 'utf8mb4_unicode_ci', `message` INT NOT NULL DEFAULT 0, `ccmessage` VARCHAR(16) COLLATE 'utf8mb4_unicode_ci', PRIMARY KEY (`auth`), CONSTRAINT `ch_auth` FOREIGN KEY (`auth`) REFERENCES `users` (`auth`) ON UPDATE CASCADE ON DELETE CASCADE) ENGINE=INNODB;",
gS_MySQLPrefix);
}

else
{
FormatEx(sQuery, 512,
"CREATE TABLE IF NOT EXISTS `%schat` (`auth` VARCHAR(32) NOT NULL, `name` INT NOT NULL DEFAULT 0, `ccname` VARCHAR(128), `message` INT NOT NULL DEFAULT 0, `ccmessage` VARCHAR(16), PRIMARY KEY (`auth`), CONSTRAINT `ch_auth` FOREIGN KEY (`auth`) REFERENCES `users` (`auth`) ON UPDATE CASCADE ON DELETE CASCADE);",
gS_MySQLPrefix);
}

gH_SQL.Query(SQL_CreateTable_Callback, sQuery, 0, DBPrio_High);
gH_SQL.Query(SQL_CreateTable_Callback, sQuery);
}
}

Expand Down Expand Up @@ -1376,9 +1392,11 @@ void SaveToDatabase(int client)
gH_SQL.Escape(gS_CustomMessage[client], sEscapedMessage, iLength);

char sQuery[512];
FormatEx(sQuery, 512, "REPLACE INTO %schat (auth, name, ccname, message, ccmessage) VALUES ('%s', %d, '%s', %d, '%s');", gS_MySQLPrefix, sAuthID3, gB_NameEnabled[client], sEscapedName, gB_MessageEnabled[client], sEscapedMessage);
FormatEx(sQuery, 512,
"REPLACE INTO %schat (auth, name, ccname, message, ccmessage) VALUES ('%s', %d, '%s', %d, '%s');",
gS_MySQLPrefix, sAuthID3, gB_NameEnabled[client], sEscapedName, gB_MessageEnabled[client], sEscapedMessage);

gH_SQL.Query(SQL_UpdateUser_Callback, sQuery, 0, DBPrio_High);
gH_SQL.Query(SQL_UpdateUser_Callback, sQuery, 0, DBPrio_Low);
}

public void SQL_UpdateUser_Callback(Database db, DBResultSet results, const char[] error, any data)
Expand All @@ -1393,6 +1411,11 @@ public void SQL_UpdateUser_Callback(Database db, DBResultSet results, const char

void LoadFromDatabase(int client)
{
if(IsFakeClient(client))
{
return;
}

char sAuthID3[32];

if(!GetClientAuthId(client, AuthId_Steam3, sAuthID3, 32))
Expand Down
Loading

0 comments on commit 95d9cad

Please sign in to comment.