rework !ccmsg off & !ccname off slightly

This commit is contained in:
rtldg 2022-06-10 07:29:01 +00:00
parent 4cf01f5ec4
commit bfa9aa45e4

View File

@ -103,11 +103,7 @@ bool gB_ChatRanksMenuOnlyUnlocked[MAXPLAYERS+1];
bool gB_ChangedSinceLogin[MAXPLAYERS+1];
bool gB_CCAccess[MAXPLAYERS+1];
bool gB_NameEnabled[MAXPLAYERS+1];
char gS_CustomName[MAXPLAYERS+1][128];
bool gB_MessageEnabled[MAXPLAYERS+1];
char gS_CustomMessage[MAXPLAYERS+1][16];
chatstrings_t gS_ChatStrings;
@ -639,12 +635,8 @@ public void OnClientCookiesCached(int client)
public void OnClientConnected(int client)
{
gB_CCAccess[client] = false;
gB_NameEnabled[client] = true;
strcopy(gS_CustomName[client], 128, "{team}{name}");
gB_MessageEnabled[client] = true;
strcopy(gS_CustomMessage[client], 128, "{default}");
strcopy(gS_CustomName[client], sizeof(gS_CustomName[]), "{team}{name}");
strcopy(gS_CustomMessage[client], sizeof(gS_CustomMessage[]), "{default}");
}
public void OnClientDisconnect(int client)
@ -716,27 +708,25 @@ public Action Command_CCName(int client, int args)
if(args == 0 || strlen(sArgs) == 0)
{
Shavit_PrintToChat(client, "%T", "ArgumentsMissing", client, "sm_ccname <text>");
Shavit_PrintToChat(client, "%T", "ChatCurrent", client, !strlen(gS_CustomName[client]) ? "off" : gS_CustomName[client]);
Shavit_PrintToChat(client, "%T", "ChatCurrent", client, gS_CustomName[client]);
return Plugin_Handled;
}
else if(StrEqual(sArgs, "off"))
{
Shavit_PrintToChat(client, "%T", "NameOff", client, sArgs);
gB_NameEnabled[client] = false;
return Plugin_Handled;
sArgs = "{team}{name}";
}
else
{
Shavit_PrintToChat(client, "%T", "ChatUpdated", client);
}
Shavit_PrintToChat(client, "%T", "ChatUpdated", client);
if(!StrEqual(gS_CustomName[client], sArgs))
{
gB_ChangedSinceLogin[client] = true;
}
gB_NameEnabled[client] = true;
strcopy(gS_CustomName[client], 128, sArgs);
return Plugin_Handled;
@ -765,27 +755,25 @@ public Action Command_CCMessage(int client, int args)
if(args == 0 || strlen(sArgs) == 0)
{
Shavit_PrintToChat(client, "%T", "ArgumentsMissing", client, "sm_ccmsg <text>");
Shavit_PrintToChat(client, "%T", "ChatCurrent", client, !strlen(gS_CustomMessage[client]) ? "off" : gS_CustomMessage[client]);
Shavit_PrintToChat(client, "%T", "ChatCurrent", client, gS_CustomMessage[client]);
return Plugin_Handled;
}
else if(StrEqual(sArgs, "off"))
{
Shavit_PrintToChat(client, "%T", "MessageOff", client, sArgs);
gB_MessageEnabled[client] = false;
return Plugin_Handled;
sArgs = "{default}";
}
else
{
Shavit_PrintToChat(client, "%T", "ChatUpdated", client);
}
Shavit_PrintToChat(client, "%T", "ChatUpdated", client);
if(!StrEqual(gS_CustomMessage[client], sArgs))
{
gB_ChangedSinceLogin[client] = true;
}
gB_MessageEnabled[client] = true;
strcopy(gS_CustomMessage[client], 16, sArgs);
return Plugin_Handled;
@ -1144,20 +1132,9 @@ void GetPlayerChatSettings(int client, char[] name, char[] message, int iRank)
if (iRank == -1)
{
if (gB_NameEnabled[client])
{
strcopy(name, MAXLENGTH_NAME, gS_CustomName[client]);
}
if (gB_MessageEnabled[client])
{
strcopy(message, MAXLENGTH_NAME, gS_CustomMessage[client]);
}
if (name[0] && message[0])
{
return;
}
strcopy(name, MAXLENGTH_NAME, gS_CustomName[client]);
strcopy(message, MAXLENGTH_NAME, gS_CustomMessage[client]);
return;
}
// if we auto-assign, start looking for an available rank starting from index 0
@ -1427,7 +1404,7 @@ void SaveToDatabase(int client)
char sQuery[512];
FormatEx(sQuery, 512,
"REPLACE INTO %schat (auth, name, ccname, message, ccmessage) VALUES (%d, %d, '%s', %d, '%s');",
gS_MySQLPrefix, iSteamID, gB_NameEnabled[client], sEscapedName, gB_MessageEnabled[client], sEscapedMessage);
gS_MySQLPrefix, iSteamID, 1, sEscapedName, 1, sEscapedMessage);
gH_SQL.Query2(SQL_UpdateUser_Callback, sQuery, 0, DBPrio_Low);
}
@ -1489,10 +1466,7 @@ public void SQL_GetChat_Callback(Database db, DBResultSet results, const char[]
return;
}
gB_NameEnabled[client] = view_as<bool>(results.FetchInt(0));
results.FetchString(1, gS_CustomName[client], 128);
gB_MessageEnabled[client] = view_as<bool>(results.FetchInt(2));
results.FetchString(3, gS_CustomMessage[client], 16);
}
}
@ -1526,7 +1500,7 @@ public int Native_GetPlainChatrank(Handle handler, int numParams)
bool includename = !(GetNativeCell(4) == 0);
int iChatrank = gI_ChatSelection[client];
if (HasCustomChat(client) && iChatrank == -1 && gB_NameEnabled[client])
if (iChatrank == -1 && HasCustomChat(client))
{
strcopy(buf, sizeof(buf), gS_CustomName[client]);
}