add chat properties for rank ranges

@ntoxin66 I really appreciate Dynamic, this is fantastic!
also added Shavit_OnRankUpdated() forward
This commit is contained in:
shavitush 2016-07-12 03:45:22 +03:00
parent 7c60a38fc2
commit 89a100d867
5 changed files with 166 additions and 66 deletions

View File

@ -14,6 +14,7 @@ a bhop server should be simple
* [SourceMod 1.8 and above](http://www.sourcemod.net/downloads.php)
* `clientprefs` plugin/extension. Comes built-in with SourceMod.
* [The RTLer](https://forums.alliedmods.net/showthread.php?p=1649882) is required to *compile* `shavit-chat` and you don't need Simple Chat Processor as listed in Ther RTLer's requirements.
* [Dynamic](https://forums.alliedmods.net/showthread.php?t=270519) for compilation and runtime of `shavit-chat`.
# Optional requirements:
* [DHooks](http://users.alliedmods.net/~drifter/builds/dhooks/2.0/) - required for static 250 prestrafe (bhoptimer 1.2b and above)
@ -70,6 +71,7 @@ General
- [x] Migrate DBI to the 1.7 transitional syntax.
- [x] Migrate events to the 1.7 transitional syntax.
- [x] Migrate ADT_Arrays to ArrayList.
- [ ] **ENDGAME**: Migrate all the cached stuff (timer variables, HUD, chat cache) to Dynamic if I find it good and simple enough.
Core
--
@ -113,6 +115,7 @@ Stats
- [x] Make style names editable from shavit.inc (like I did to the rest of modules) (dynamic!)
- [x] Make a submenu per style, for aesthetics.
- [x] [rankings] Points implementation.
- [ ] Make MVP count the amount of WRs the player has.
Miscellaneous
--
@ -150,7 +153,7 @@ Chat **(NEW!)**
- [x] Add logic that processes chat without requiring an external plugin such as `Simple Chat Processor (Redux)`.
- [x] [RTLer](https://forums.alliedmods.net/showthread.php?p=1649882) support.
- [x] Custom chat titles/colors per individual player.
- [ ] Custom chat titles/colors for rank ranges.
- [ ] Update cache for everyone when a player finishes a map.
- [x] Custom chat titles/colors for rank ranges.
- [x] Update cache for a player when his rank updates.
- [ ] Add `sm_ranks` `sm_chatranks`
- [ ] Add `Shavit_FormatChat` native

View File

@ -1,12 +1,12 @@
// Use SteamID3 for a value if you want a per-client setting.
// "Custom" is for per-client settings.
// "Ranks" is for rank range settings.
// "Ranks" is for rank range settings. (Limited to 64 entries)
//
// Available settings:
// "rank_from" - rank range to start with
// "rank_to" - rank range to end with; you can use "infinity" if it's for every player below "rank_from".
//
// "prefix" - prefix before the name
// "prefix" - prefix before the name (don't add a space after it)
// "name" - custom name appearance
// "message" - the message itself
//
@ -47,17 +47,9 @@
{
"prefix" "{green}/dev{green}/"
"name" "{default}{team}{clan}{name}"
"message" "{message}"
}
"[U:1:108640137]" // friend
{
"prefix" "{green}noob "
"name" "{team}{name}"
"message" "{message}"
}
"-1" // lookup is due
"-1" // lookup is due, shouldn't happen unless there's some error!
{
"rank_from" "-1"
"rank_to" "-1"
@ -82,28 +74,33 @@
"rank_from" "1"
"rank_to" "1"
"prefix" "{default}One True God"
"name" "{team}{name}"
"message" "{message}"
"prefix" "{green}ONE TRUE GOD"
"name" "{clan}{team}{name}"
}
"2"
{
"rank_from" "2"
"rank_to" "3"
"rank_to" "2"
"prefix" "{default}Decent"
"name" "{team}{name}"
"message" "{message}"
"prefix" "LEGENDARY"
"name" "{name}"
}
"3"
{
"rank_from" "3"
"rank_to" "3"
"prefix" "HERO"
"name" "{team}{name}"
}
"4"
{
"rank_from" "4"
"rank_to" "infinity"
"prefix" "{default}Noob"
"name" "{team}{name}"
"message" "{message}"
"prefix" "scrub!"
}
}

View File

@ -389,6 +389,15 @@ forward void Shavit_OnPause(int client);
*/
forward void Shavit_OnResume(int client);
/**
* Called when a player's rank has updated or was just looked up.
* Will be called on initial rank lookup.
*
* @param client Client index.
* @noreturn
*/
forward void Shavit_OnRankUpdated(int client);
/**
* Returns the game type the server is running.
*

View File

@ -20,6 +20,7 @@
#include <sourcemod>
#include <cstrike>
#include <dynamic>
#define USES_CHAT_COLORS
#include <shavit>
@ -35,14 +36,17 @@
// cache
float gF_LastMessage[MAXPLAYERS+1];
char gS_Custom_Prefix[MAXPLAYERS+1][32];
char gS_Custom_Name[MAXPLAYERS+1][MAX_NAME_LENGTH*2];
char gS_Custom_Message[MAXPLAYERS+1][255];
char gS_Cached_Prefix[MAXPLAYERS+1][32];
char gS_Cached_Name[MAXPLAYERS+1][MAX_NAME_LENGTH*2];
char gS_Cached_Message[MAXPLAYERS+1][255];
StringMap gSM_Custom_Prefix = null;
StringMap gSM_Custom_Name = null;
StringMap gSM_Custom_Message = null;
int gI_TotalChatRanks = 0;
Dynamic gD_ChatRanks[64]; // limited to 64 chat ranks right now, i really don't think there's a need for more.
// modules
bool gB_BaseComm = false;
bool gB_RTLer = false;
@ -58,6 +62,7 @@ public Plugin myinfo =
version = SHAVIT_VERSION,
url = "https://github.com/shavitush/bhoptimer"
}
public void OnAllPluginsLoaded()
{
if(!LibraryExists("shavit-rankings"))
@ -86,11 +91,6 @@ public void OnMapStart()
public void OnClientPutInServer(int client)
{
gF_LastMessage[client] = GetEngineTime();
if(IsClientAuthorized(client))
{
LoadChatCache(client);
}
}
public void OnLibraryAdded(const char[] name)
@ -119,26 +119,56 @@ public void OnLibraryRemoved(const char[] name)
}
}
public void Shavit_OnRankUpdated(int client)
{
LoadChatCache(client);
}
public void LoadChatCache(int client)
{
char[] sAuthID = new char[32];
GetClientAuthId(client, AuthId_Steam3, sAuthID, 32);
// assign rank properties
int iRank = Shavit_GetRank(client);
char[] sBuffer = new char[255];
if(gSM_Custom_Prefix.GetString(sAuthID, sBuffer, 255))
for(int i = 0; i < gI_TotalChatRanks; i++)
{
strcopy(gS_Custom_Prefix[client], 32, sBuffer);
if(gD_ChatRanks[i].IsValid)
{
int iFrom = gD_ChatRanks[i].GetInt("rank_from");
int iTo = gD_ChatRanks[i].GetInt("rank_to");
if(iRank < iFrom || iRank > iTo)
{
continue;
}
gD_ChatRanks[i].GetString("prefix", gS_Cached_Prefix[client], 32);
gD_ChatRanks[i].GetString("name", gS_Cached_Name[client], MAX_NAME_LENGTH*2);
gD_ChatRanks[i].GetString("message", gS_Cached_Message[client], 255);
}
}
if(gSM_Custom_Name.GetString(sAuthID, sBuffer, 255))
if(IsClientAuthorized(client))
{
strcopy(gS_Custom_Name[client], MAX_NAME_LENGTH*2, sBuffer);
}
// lookup custom properties in addition to the rank properties
char[] sAuthID = new char[32];
GetClientAuthId(client, AuthId_Steam3, sAuthID, 32);
if(gSM_Custom_Message.GetString(sAuthID, sBuffer, 255))
{
strcopy(gS_Custom_Message[client], 255, sBuffer);
char[] sBuffer = new char[255];
if(gSM_Custom_Prefix.GetString(sAuthID, sBuffer, 255))
{
strcopy(gS_Cached_Prefix[client], 32, sBuffer);
}
if(gSM_Custom_Name.GetString(sAuthID, sBuffer, 255))
{
strcopy(gS_Cached_Name[client], MAX_NAME_LENGTH*2, sBuffer);
}
if(gSM_Custom_Message.GetString(sAuthID, sBuffer, 255))
{
strcopy(gS_Cached_Message[client], 255, sBuffer);
}
}
}
@ -152,6 +182,16 @@ public void LoadConfig()
gSM_Custom_Name = new StringMap();
gSM_Custom_Message = new StringMap();
for(int i = 0; i < 64; i++)
{
if(gD_ChatRanks[i].IsValid)
{
gD_ChatRanks[i].Dispose();
}
}
gI_TotalChatRanks = 0;
KeyValues kvConfig = new KeyValues("Chat");
char[] sFile = new char[PLATFORM_MAX_PATH];
@ -170,30 +210,67 @@ public void LoadConfig()
{
kvConfig.GetSectionName(sBuffer, 255);
char[] sPrefix = new char[32];
kvConfig.GetString("prefix", sPrefix, 32);
char[] sName = new char[MAX_NAME_LENGTH*2];
kvConfig.GetString("name", sName, MAX_NAME_LENGTH*2);
char[] sMessage = new char[255];
kvConfig.GetString("message", sMessage, 255);
// custom
if(StrContains(sBuffer[0], "[U:") != -1)
{
char[] sProperty = new char[255];
kvConfig.GetString("prefix", sProperty, 255);
if(strlen(sProperty) > 0)
if(strlen(sPrefix) > 0)
{
gSM_Custom_Prefix.SetString(sBuffer, sProperty);
gSM_Custom_Prefix.SetString(sBuffer, sPrefix);
}
kvConfig.GetString("name", sProperty, 255);
if(strlen(sProperty) > 0)
if(strlen(sName) > 0)
{
gSM_Custom_Name.SetString(sBuffer, sProperty);
gSM_Custom_Name.SetString(sBuffer, sName);
}
kvConfig.GetString("message", sProperty, 255);
if(strlen(sProperty) > 0)
if(strlen(sMessage) > 0)
{
gSM_Custom_Message.SetString(sBuffer, sProperty);
gSM_Custom_Message.SetString(sBuffer, sMessage);
}
}
// ranks
else
{
int iFrom = kvConfig.GetNum("rank_from", -2);
if(iFrom == -2)
{
LogError("Invalid \"rank_from\" value for \"%s\": %d or non-existant.", sBuffer, iFrom);
continue;
}
char[] sTo = new char[6];
kvConfig.GetString("rank_to", sTo, 6, "-2");
int iTo = StrEqual(sTo, "infinity")? 2147483647:StringToInt(sTo);
if(iTo == -2)
{
LogError("Invalid \"rank_to\" value for \"%s\": %d or non-existant.", sBuffer, iTo);
continue;
}
gD_ChatRanks[gI_TotalChatRanks] = Dynamic();
gD_ChatRanks[gI_TotalChatRanks].SetInt("rank_from", iFrom);
gD_ChatRanks[gI_TotalChatRanks].SetInt("rank_to", iTo);
gD_ChatRanks[gI_TotalChatRanks].SetString("prefix", sPrefix, 32);
gD_ChatRanks[gI_TotalChatRanks].SetString("name", sName, MAX_NAME_LENGTH*2);
gD_ChatRanks[gI_TotalChatRanks].SetString("message", sMessage, 255);
gI_TotalChatRanks++;
}
}
while(kvConfig.GotoNextKey());
@ -208,9 +285,11 @@ public void LoadConfig()
for(int i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i))
if(IsValidClient(i)) // late loading
{
OnClientPutInServer(i); // late loading
gF_LastMessage[i] = GetEngineTime();
Shavit_OnRankUpdated(i);
}
}
}
@ -306,17 +385,19 @@ public void FormatChat(int client, const char[] sMessage, bool bAlive, int iTeam
char[] sBuffer = new char[255];
char[] sNewPrefix = new char[32];
if(strlen(gS_Custom_Prefix[client]) > 0)
if(strlen(gS_Cached_Prefix[client]) > 0)
{
FormatVariables(client, sBuffer, 255, gS_Custom_Prefix[client], sMessage);
FormatVariables(client, sBuffer, 255, gS_Cached_Prefix[client], sMessage);
int iLen = strlen(sBuffer);
sBuffer[iLen] = (iLen > 0)? ' ':'\0';
strcopy(sNewPrefix, 32, sBuffer);
}
char[] sNewName = new char[MAX_NAME_LENGTH*2];
if(strlen(gS_Custom_Name[client]) > 0)
if(strlen(gS_Cached_Name[client]) > 0)
{
FormatVariables(client, sBuffer, 255, gS_Custom_Name[client], sMessage);
FormatVariables(client, sBuffer, 255, gS_Cached_Name[client], sMessage);
strcopy(sNewName, MAX_NAME_LENGTH*2, sBuffer);
}
@ -338,9 +419,9 @@ public void FormatChat(int client, const char[] sMessage, bool bAlive, int iTeam
RTLify(sFormattedText, maxlen, sFormattedText);
}
if(strlen(gS_Custom_Message[client]) > 0)
if(strlen(gS_Cached_Message[client]) > 0)
{
FormatVariables(client, sBuffer, 255, gS_Custom_Message[client], sFormattedText);
FormatVariables(client, sBuffer, 255, gS_Cached_Message[client], sFormattedText);
strcopy(sFormattedText, 255, sBuffer);
}
@ -359,7 +440,7 @@ public void FormatVariables(int client, char[] buffer, int maxlen, const char[]
char[] sClanTag = new char[32];
CS_GetClientClanTag(client, sClanTag, 32);
int iLen = strlen(sClanTag);
sClanTag[iLen] = iLen > 0? ' ':'\0'; // add spacing after the clan tag if there is one
sClanTag[iLen] = (iLen > 0)? ' ':'\0';
ReplaceString(sTempFormattingRules, maxlen, "{clan}", sClanTag);
ReplaceString(sTempFormattingRules, maxlen, "{message}", message);

View File

@ -29,6 +29,9 @@
// #define DEBUG
// forwards
Handle gH_Forwards_OnRankUpdated = null;
// cache
char gS_Map[256];
float gF_IdealTime = 0.0;
@ -83,6 +86,9 @@ public void OnAllPluginsLoaded()
public void OnPluginStart()
{
// forwards
gH_Forwards_OnRankUpdated = CreateGlobalForward("Shavit_OnRankUpdated", ET_Event, Param_Cell);
// database connections
Shavit_GetDB(gH_SQL);
SQL_SetPrefix();
@ -747,7 +753,11 @@ public void SQL_UpdatePlayerRank_Callback(Database db, DBResultSet results, cons
if(results.FetchRow())
{
gI_PlayerRank[client] = results.FetchInt(0);
gI_PlayerRank[client] = results.FetchInt(0);
Call_StartForward(gH_Forwards_OnRankUpdated);
Call_PushCell(client);
Call_Finish();
}
}