Permalink
Browse files

switch to array list (#363)

* Update block_messages.sp

* Tabs to Spaces
  • Loading branch information...
e54385991 authored and Bara committed Aug 15, 2018
1 parent b559a32 commit aa4466a523143bddfde736fa31717010fda87158
Showing with 56 additions and 37 deletions.
  1. +56 −37 addons/sourcemod/scripting/block_messages.sp
@@ -3,51 +3,70 @@
#include <sourcemod>
ArrayList g_aMessages = null;
public Plugin myinfo =
{
name = "Block messages",
author = "Bara",
description = "",
version = "1.0.0",
url = "csgottt.com"
name = "Block messages",
author = "Bara",
description = "",
version = "1.0.0",
url = "csgottt.com"
};
public void OnPluginStart()
{
CreateConVar("block_messages_version", "1.0.0", "Plugin to block some usermessage messages", FCVAR_NOTIFY | FCVAR_DONTRECORD | FCVAR_REPLICATED);
HookUserMessage(GetUserMessageId("TextMsg"), UserMsg_TextMsg, true);
g_aMessages = new ArrayList(64);
CreateConVar("block_messages_version", "1.0.0", "Plugin to block some usermessage messages", FCVAR_NOTIFY | FCVAR_DONTRECORD | FCVAR_REPLICATED);
HookUserMessage(GetUserMessageId("TextMsg"), UserMsg_TextMsg, true);
}
public Action UserMsg_TextMsg(UserMsg msg_id, Protobuf msg, const int[] players, int playersNum, bool reliable, bool init)
public void OnConfigsExecuted()
{
if(reliable)
{
char sText[64], sFileText[64];
msg.ReadString("params", sText, sizeof(sText), 0);
char sPath[PLATFORM_MAX_PATH + 1];
BuildPath(Path_SM, sPath, sizeof(sPath), "configs/ttt/block_messages.ini");
Handle hFile = OpenFile(sPath, "rt");
g_aMessages.Clear();
char sPath[PLATFORM_MAX_PATH + 1], sFileText[64];
BuildPath(Path_SM, sPath, sizeof(sPath), "configs/ttt/block_messages.ini");
if (!FileExists(sPath))
{
SetFailState("Can't find the following file: \"configs/ttt/block_messages.ini\"");
}
File hFile = OpenFile(sPath, "rt");
if(hFile != null)
{
while(!hFile.EndOfFile() && hFile.ReadLine(sFileText, sizeof(sFileText)))
{
g_aMessages.PushString(sFileText);
}
}
delete hFile;
}
if (!FileExists(sPath))
{
SetFailState("Can't find the following file: \"configs/ttt/block_messages.ini\"");
delete hFile;
return Plugin_Continue;
}
while(!IsEndOfFile(hFile) && ReadFileLine(hFile, sFileText, sizeof(sFileText)))
{
if (StrContains(sText, sFileText, false) != -1)
{
delete hFile;
return Plugin_Handled;
}
}
delete hFile;
}
return Plugin_Continue;
}
public Action UserMsg_TextMsg(UserMsg msg_id, Protobuf msg, const int[] players, int playersNum, bool reliable, bool init)
{
if(reliable)
{
char sText[64];
msg.ReadString("params", sText, sizeof(sText), 0);
char sBuffer[64];
for (int i = 0; i < g_aMessages.Length; i++)
{
g_aMessages.GetString(i, sBuffer, sizeof(sBuffer));
if (StrContains(sBuffer, sText, false) != -1)
{
return Plugin_Handled;
}
}
}
return Plugin_Continue;
}

0 comments on commit aa4466a

Please sign in to comment.