Various chat commands now follow sm_show_activity (bug 2080, r=pred).

Added FormatActivitySource() native to assist in emulating ShowActivity().
This commit is contained in:
David Anderson 2008-09-23 01:17:15 -05:00
parent 187ff255bd
commit 4001b0f804
3 changed files with 189 additions and 47 deletions

View File

@ -1467,6 +1467,90 @@ static cell_t ProcessTargetString(IPluginContext *pContext, const cell_t *params
} }
} }
static cell_t FormatActivitySource(IPluginContext *pContext, const cell_t *params)
{
int value;
int client;
int target;
CPlayer *pTarget;
AdminId aidTarget;
const char *identity[2] = {"Console", "ADMIN"};
client = params[1];
target = params[2];
if ((pTarget = g_Players.GetPlayerByIndex(target)) == NULL)
{
return pContext->ThrowNativeError("Invalid client index %d", target);
}
if (!pTarget->IsConnected())
{
return pContext->ThrowNativeError("Client %d not connected", target);
}
value = sm_show_activity.GetInt();
if (client != 0)
{
CPlayer *pPlayer;
if ((pPlayer = g_Players.GetPlayerByIndex(client)) == NULL)
{
return pContext->ThrowNativeError("Invalid client index %d", client);
}
if (!pPlayer->IsConnected())
{
return pContext->ThrowNativeError("Client %d not connected", client);
}
identity[0] = pPlayer->GetName();
AdminId id = pPlayer->GetAdminId();
if (id == INVALID_ADMIN_ID
|| !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective))
{
identity[1] = "PLAYER";
}
}
int mode = 1;
bool bShowActivity = false;
if ((aidTarget = pTarget->GetAdminId()) == INVALID_ADMIN_ID
|| !g_Admins.GetAdminFlag(aidTarget, Admin_Generic, Access_Effective))
{
/* Treat this as a normal user */
if ((value & 1) || (value & 2))
{
if ((value & 2) || (target == client))
{
mode = 0;
}
bShowActivity = true;
}
}
else
{
/* Treat this as an admin user */
bool is_root = g_Admins.GetAdminFlag(aidTarget, Admin_Root, Access_Effective);
if ((value & 4)
|| (value & 8)
|| ((value & 16) && is_root))
{
if ((value & 8) || ((value & 16) && is_root) || (target == client))
{
mode = 0;
}
bShowActivity = true;
}
}
/* Otherwise, send it back to the script. */
pContext->StringToLocalUTF8(params[3], params[4], identity[mode], NULL);
return bShowActivity ? 1 : 0;
}
REGISTER_NATIVES(playernatives) REGISTER_NATIVES(playernatives)
{ {
{"AddUserFlags", AddUserFlags}, {"AddUserFlags", AddUserFlags},
@ -1519,6 +1603,7 @@ REGISTER_NATIVES(playernatives)
{"NotifyPostAdminCheck", NotifyPostAdminCheck}, {"NotifyPostAdminCheck", NotifyPostAdminCheck},
{"IsClientInKickQueue", IsClientInKickQueue}, {"IsClientInKickQueue", IsClientInKickQueue},
{"ProcessTargetString", ProcessTargetString}, {"ProcessTargetString", ProcessTargetString},
{"FormatActivitySource", FormatActivitySource},
{NULL, NULL} {NULL, NULL}
}; };

View File

@ -114,12 +114,12 @@ public Action:Command_SayChat(client, args)
if (msgStart == 1 && CheckCommandAccess(client, "sm_say", ADMFLAG_CHAT)) // sm_say alias if (msgStart == 1 && CheckCommandAccess(client, "sm_say", ADMFLAG_CHAT)) // sm_say alias
{ {
SendChatToAll(name, message); SendChatToAll(client, message);
LogAction(client, -1, "%L triggered sm_say (text %s)", client, message); LogAction(client, -1, "%L triggered sm_say (text %s)", client, message);
} }
else if (msgStart == 3 && CheckCommandAccess(client, "sm_csay", ADMFLAG_CHAT)) // sm_csay alias else if (msgStart == 3 && CheckCommandAccess(client, "sm_csay", ADMFLAG_CHAT)) // sm_csay alias
{ {
PrintCenterTextAll("%s: %s", name, message); DisplayCenterTextToAll(client, message);
LogAction(client, -1, "%L triggered sm_csay (text %s)", client, text); LogAction(client, -1, "%L triggered sm_csay (text %s)", client, text);
} }
else if (msgStart == 2 && CheckCommandAccess(client, "sm_psay", ADMFLAG_CHAT)) // sm_psay alias else if (msgStart == 2 && CheckCommandAccess(client, "sm_psay", ADMFLAG_CHAT)) // sm_psay alias
@ -200,10 +200,7 @@ public Action:Command_SmSay(client, args)
decl String:text[192]; decl String:text[192];
GetCmdArgString(text, sizeof(text)); GetCmdArgString(text, sizeof(text));
decl String:name[64]; SendChatToAll(client, text);
GetClientName(client, name, sizeof(name));
SendChatToAll(name, text);
LogAction(client, -1, "%L triggered sm_say (text %s)", client, text); LogAction(client, -1, "%L triggered sm_say (text %s)", client, text);
return Plugin_Handled; return Plugin_Handled;
@ -220,10 +217,8 @@ public Action:Command_SmCsay(client, args)
decl String:text[192]; decl String:text[192];
GetCmdArgString(text, sizeof(text)); GetCmdArgString(text, sizeof(text));
new String:name[64]; DisplayCenterTextToAll(client, text);
GetClientName(client, name, sizeof(name));
PrintCenterTextAll("%s: %s", name, text);
LogAction(client, -1, "%L triggered sm_csay (text %s)", client, text); LogAction(client, -1, "%L triggered sm_csay (text %s)", client, text);
return Plugin_Handled; return Plugin_Handled;
@ -240,10 +235,19 @@ public Action:Command_SmHsay(client, args)
decl String:text[192]; decl String:text[192];
GetCmdArgString(text, sizeof(text)); GetCmdArgString(text, sizeof(text));
decl String:name[64]; decl String:nameBuf[MAX_NAME_LENGTH];
GetClientName(client, name, sizeof(name));
new maxClients = GetMaxClients();
for (new i = 1; i <= maxClients; i++)
{
if (!IsClientConnected(i) || IsFakeClient(i))
{
continue;
}
FormatActivitySource(client, i, nameBuf, sizeof(nameBuf));
PrintHintText(i, "%s: %s", nameBuf, text);
}
PrintHintTextToAll("%s: %s", name, text);
LogAction(client, -1, "%L triggered sm_hsay (text %s)", client, text); LogAction(client, -1, "%L triggered sm_hsay (text %s)", client, text);
return Plugin_Handled; return Plugin_Handled;
@ -266,11 +270,24 @@ public Action:Command_SmTsay(client, args)
GetClientName(client, name, sizeof(name)); GetClientName(client, name, sizeof(name));
new color = FindColor(colorStr); new color = FindColor(colorStr);
new maxClients = GetMaxClients();
new String:nameBuf[MAX_NAME_LENGTH];
if (color == -1) if (color == -1)
SendDialogToAll(_, "%s: %s", name, text); {
else color = 0;
SendDialogToAll(color, "%s: %s", name, text[len]); len = 0;
}
for (new i = 1; i <= maxClients; i++)
{
if (!IsClientConnected(i) || IsFakeClient(i))
{
continue;
}
FormatActivitySource(client, i, nameBuf, sizeof(nameBuf));
SendDialogToOne(i, color, "%s: %s", nameBuf, text[len]);
}
LogAction(client, -1, "%L triggered sm_tsay (text %s)", client, text); LogAction(client, -1, "%L triggered sm_tsay (text %s)", client, text);
@ -388,15 +405,44 @@ FindColor(String:color[])
return -1; return -1;
} }
SendChatToAll(String:name[], String:message[]) SendChatToAll(client, String:message[])
{ {
if (g_DoColor) new maxClients;
new String:nameBuf[MAX_NAME_LENGTH];
maxClients = GetMaxClients();
for (new i = 1; i <= maxClients; i++)
{ {
PrintToChatAll("\x04(ALL) %s: \x01%s", name, message); if (!IsClientConnected(i) || IsFakeClient(i))
{
continue;
}
FormatActivitySource(client, i, nameBuf, sizeof(nameBuf));
if (g_DoColor)
{
PrintToChat(i, "\x04(ALL) %s: \x01%s", nameBuf, message);
}
else
{
PrintToChat(i, "%s: %s", nameBuf, message);
}
} }
else }
DisplayCenterTextToAll(client, String:message[])
{
new String:nameBuf[MAX_NAME_LENGTH];
new maxClients = GetMaxClients();
for (new i = 1; i < maxClients; i++)
{ {
PrintToChatAll("(ALL) %s: %s", name, message); if (!IsClientConnected(i) || IsFakeClient(i))
{
continue;
}
FormatActivitySource(client, i, nameBuf, sizeof(nameBuf));
PrintCenterText(i, "%s: %s", nameBuf, message);
} }
} }
@ -423,26 +469,19 @@ SendChatToAdmins(String:name[], String:message[])
} }
} }
SendDialogToAll(color = 0, String:text[], any:...) SendDialogToOne(client, color, String:text[], any:...)
{ {
new String:message[100]; new String:message[100];
VFormat(message, sizeof(message), text, 3); VFormat(message, sizeof(message), text, 4);
new MaxClients = GetMaxClients(); new Handle:kv = CreateKeyValues("Stuff", "title", message);
for(new i = 1; i < MaxClients; i++) KvSetColor(kv, "color", g_Colors[color][0], g_Colors[color][1], g_Colors[color][2], 255);
{ KvSetNum(kv, "level", 1);
if(IsClientInGame(i)) KvSetNum(kv, "time", 10);
{
new Handle:kv = CreateKeyValues("Stuff", "title", message);
KvSetColor(kv, "color", g_Colors[color][0], g_Colors[color][1], g_Colors[color][2], 255);
KvSetNum(kv, "level", 1);
KvSetNum(kv, "time", 10);
CreateDialog(i, kv, DialogType_Msg); CreateDialog(client, kv, DialogType_Msg);
CloseHandle(kv); CloseHandle(kv);
}
}
} }
SendPanelToAll(String:name[], String:message[]) SendPanelToAll(String:name[], String:message[])

View File

@ -286,6 +286,24 @@ native ShowActivity(client, const String:format[], any:...);
*/ */
native ShowActivityEx(client, const String:tag[], const String:format[], any:...); native ShowActivityEx(client, const String:tag[], const String:format[], any:...);
/**
* Given an originating client and a target client, returns the string
* that describes the originating client according to the sm_show_activity cvar.
*
* For example, "ADMIN", "PLAYER", or a player's name could be placed in this buffer.
*
* @param client Originating client; may be 0 for server console.
* @param target Targeted client.
* @param namebuf Name buffer.
* @param maxlength Maximum size of the name buffer.
* @return True if activity should be shown. False otherwise. In either
* case, the name buffer is filled. The return value can be used
* to broadcast a "safe" name to all players regardless of the
* sm_show_activity filters.
* @error Invalid client index or client not connected.
*/
native FormatActivitySource(client, target, const String:namebuf[], maxlength);
/** /**
* Called when a server-only command is invoked. * Called when a server-only command is invoked.
* *