CloseHandle -> delete

This commit is contained in:
neon
2019-07-07 22:44:43 +02:00
parent 4dd4ff521b
commit eeba405984
18 changed files with 258 additions and 292 deletions
+65 -65
View File
@@ -29,11 +29,11 @@ static Handle sm_show_activity = INVALID_HANDLE;
/**
* Prints a message to a specific client in the chat area.
* Supports color tags.
*
*
* @param client Client index.
* @param message Message (formatting rules).
* @noreturn
*
*
* On error/Errors: If the client is not connected an error will be thrown.
*/
stock void MC_PrintToChat(int client, const char[] message, any ...) {
@@ -55,7 +55,7 @@ stock void MC_PrintToChat(int client, const char[] message, any ...) {
/**
* Prints a message to all clients in the chat area.
* Supports color tags.
*
*
* @param client Client index.
* @param message Message (formatting rules).
* @noreturn
@@ -79,12 +79,12 @@ stock void MC_PrintToChatAll(const char[] message, any ...) {
/**
* Prints a message to a specific client in the chat area.
* Supports color tags and teamcolor tag.
*
*
* @param client Client index.
* @param author Author index whose color will be used for teamcolor tag.
* @param message Message (formatting rules).
* @noreturn
*
*
* On error/Errors: If the client or author are not connected an error will be thrown
*/
stock void MC_PrintToChatEx(int client, int author, const char[] message, any ...) {
@@ -116,7 +116,7 @@ stock void MC_PrintToChatEx(int client, int author, const char[] message, any ..
* @param author Author index whose color will be used for teamcolor tag.
* @param message Message (formatting rules).
* @noreturn
*
*
* On error/Errors: If the author is not connected an error will be thrown.
*/
stock void MC_PrintToChatAllEx(int author, const char[] message, any ...) {
@@ -143,7 +143,7 @@ stock void MC_PrintToChatAllEx(int author, const char[] message, any ...) {
/**
* Sends a SayText2 usermessage
*
*
* @param client Client to send usermessage to
* @param message Message to send
* @noreturn
@@ -191,7 +191,7 @@ stock void MC_SendMessage(int client, const char[] message, int author = 0) {
* MC_PrintToChatAll or MC_PrintToChatAllEx. It causes those functions
* to skip the specified client when printing the message.
* After printing the message, the client will no longer be skipped.
*
*
* @param client Client index
* @noreturn
*/
@@ -204,7 +204,7 @@ stock void MC_SkipNextClient(int client) {
/**
* Checks if the colors trie is initialized and initializes it if it's not (used internally)
*
*
* @return No return
*/
stock void MC_CheckTrie() {
@@ -221,7 +221,7 @@ stock void MC_CheckTrie() {
* @param removeTags Optional boolean value to determine whether we're replacing tags with colors, or just removing tags, used by MC_RemoveTags
* @param maxlen Optional value for max buffer length, used by MC_RemoveTags
* @noreturn
*
*
* On error/Errors: If the client index passed for author is invalid or not in game.
*/
stock void MC_ReplaceColorCodes(char[] buffer, int author = 0, bool removeTags = false, int maxlen = MAX_BUFFER_LENGTH) {
@@ -243,16 +243,16 @@ stock void MC_ReplaceColorCodes(char[] buffer, int author = 0, bool removeTags =
}
int cursor = 0;
int value;
char tag[32], buff[32];
char tag[32], buff[32];
char[] output = new char[maxlen];
strcopy(output, maxlen, buffer);
// Since the string's size is going to be changing, output will hold the replaced string and we'll search buffer
Handle regex = CompileRegex("{[a-zA-Z0-9]+}");
for(int i = 0; i < 1000; i++) { // The RegEx extension is quite flaky, so we have to loop here :/. This loop is supposed to be infinite and broken by return, but conditions have been added to be safe.
if(MatchRegex(regex, buffer[cursor]) < 1) {
CloseHandle(regex);
delete regex;
strcopy(buffer, maxlen, output);
return;
}
@@ -262,11 +262,11 @@ stock void MC_ReplaceColorCodes(char[] buffer, int author = 0, bool removeTags =
strcopy(buff, sizeof(buff), tag);
ReplaceString(buff, sizeof(buff), "{", "");
ReplaceString(buff, sizeof(buff), "}", "");
if(!GetTrieValue(MC_Trie, buff, value)) {
continue;
}
if(removeTags) {
ReplaceString(output, maxlen, tag, "", false);
} else {
@@ -279,7 +279,7 @@ stock void MC_ReplaceColorCodes(char[] buffer, int author = 0, bool removeTags =
/**
* Gets a part of a string
*
*
* @param input String to get the part from
* @param output Buffer to write to
* @param maxlen Max length of output buffer
@@ -301,7 +301,7 @@ stock void CSubString(const char[] input, char[] output, int maxlen, int start,
/**
* Converts a string to lowercase
*
*
* @param buffer String to convert
* @noreturn
*/
@@ -334,7 +334,7 @@ stock bool MC_AddColor(const char[] name, int color) {
/**
* Removes color tags from a message
*
*
* @param message Message to remove tags from
* @param maxlen Maximum buffer length
* @noreturn
@@ -345,7 +345,7 @@ stock void MC_RemoveTags(char[] message, int maxlen) {
/**
* Replies to a command with colors
*
*
* @param client Client to reply to
* @param message Message (formatting rules)
* @noreturn
@@ -364,7 +364,7 @@ stock void MC_ReplyToCommand(int client, const char[] message, any ...) {
/**
* Replies to a command with colors
*
*
* @param client Client to reply to
* @param author Client to use for {teamcolor}
* @param message Message (formatting rules)
@@ -383,12 +383,12 @@ stock void MC_ReplyToCommandEx(int client, int author, const char[] message, any
}
/**
* Displays usage of an admin command to users depending on the
* setting of the sm_show_activity cvar.
* Displays usage of an admin command to users depending on the
* setting of the sm_show_activity cvar.
*
* This version does not display a message to the originating client
* if used from chat triggers or menus. If manual replies are used
* for these cases, then this function will suffice. Otherwise,
* This version does not display a message to the originating client
* if used from chat triggers or menus. If manual replies are used
* for these cases, then this function will suffice. Otherwise,
* MC_ShowActivity2() is slightly more useful.
* Supports color tags.
*
@@ -402,14 +402,14 @@ stock int MC_ShowActivity(int client, const char[] format, any ...)
{
if (sm_show_activity == INVALID_HANDLE)
sm_show_activity = FindConVar("sm_show_activity");
char tag[] = "[SM] ";
char szBuffer[MC_MAX_MESSAGE_LENGTH];
//char szCMessage[MC_MAX_MESSAGE_LENGTH];
int value = GetConVarInt(sm_show_activity);
ReplySource replyto = GetCmdReplySource();
char name[MAX_NAME_LENGTH] = "Console";
char sign[MAX_NAME_LENGTH] = "ADMIN";
bool display_in_chat = false;
@@ -417,7 +417,7 @@ stock int MC_ShowActivity(int client, const char[] format, any ...)
{
if (client < 0 || client > MaxClients || !IsClientConnected(client))
ThrowError("Client index %d is invalid", client);
GetClientName(client, name, sizeof(name));
AdminId id = GetUserAdmin(client);
if (id == INVALID_ADMIN_ID
@@ -425,13 +425,13 @@ stock int MC_ShowActivity(int client, const char[] format, any ...)
{
sign = "PLAYER";
}
/* Display the message to the client? */
if (replyto == SM_REPLY_TO_CONSOLE)
{
SetGlobalTransTarget(client);
VFormat(szBuffer, sizeof(szBuffer), format, 3);
MC_RemoveTags(szBuffer, sizeof(szBuffer));
PrintToConsole(client, "%s%s\n", tag, szBuffer);
display_in_chat = true;
@@ -441,16 +441,16 @@ stock int MC_ShowActivity(int client, const char[] format, any ...)
{
SetGlobalTransTarget(LANG_SERVER);
VFormat(szBuffer, sizeof(szBuffer), format, 3);
MC_RemoveTags(szBuffer, sizeof(szBuffer));
PrintToServer("%s%s\n", tag, szBuffer);
}
if (!value)
{
return 1;
}
MuCo_LoopClients(i)
{
if (i == 0
@@ -475,7 +475,7 @@ stock int MC_ShowActivity(int client, const char[] format, any ...)
newsign = name;
}
VFormat(szBuffer, sizeof(szBuffer), format, 3);
MC_PrintToChatEx(i, client, "%s%s: %s", tag, newsign, szBuffer);
}
}
@@ -494,12 +494,12 @@ stock int MC_ShowActivity(int client, const char[] format, any ...)
newsign = name;
}
VFormat(szBuffer, sizeof(szBuffer), format, 3);
MC_PrintToChatEx(i, client, "%s%s: %s", tag, newsign, szBuffer);
}
}
}
return 1;
}
@@ -518,12 +518,12 @@ stock int MC_ShowActivityEx(int client, const char[] tag, const char[] format, a
{
if (sm_show_activity == INVALID_HANDLE)
sm_show_activity = FindConVar("sm_show_activity");
char szBuffer[MC_MAX_MESSAGE_LENGTH];
//char szCMessage[MC_MAX_MESSAGE_LENGTH];
int value = GetConVarInt(sm_show_activity);
ReplySource replyto = GetCmdReplySource();
char name[MAX_NAME_LENGTH] = "Console";
char sign[MAX_NAME_LENGTH] = "ADMIN";
bool display_in_chat = false;
@@ -531,7 +531,7 @@ stock int MC_ShowActivityEx(int client, const char[] tag, const char[] format, a
{
if (client < 0 || client > MaxClients || !IsClientConnected(client))
ThrowError("Client index %d is invalid", client);
GetClientName(client, name, sizeof(name));
AdminId id = GetUserAdmin(client);
if (id == INVALID_ADMIN_ID
@@ -539,13 +539,13 @@ stock int MC_ShowActivityEx(int client, const char[] tag, const char[] format, a
{
sign = "PLAYER";
}
/* Display the message to the client? */
if (replyto == SM_REPLY_TO_CONSOLE)
{
SetGlobalTransTarget(client);
VFormat(szBuffer, sizeof(szBuffer), format, 4);
MC_RemoveTags(szBuffer, sizeof(szBuffer));
PrintToConsole(client, "%s%s\n", tag, szBuffer);
display_in_chat = true;
@@ -555,16 +555,16 @@ stock int MC_ShowActivityEx(int client, const char[] tag, const char[] format, a
{
SetGlobalTransTarget(LANG_SERVER);
VFormat(szBuffer, sizeof(szBuffer), format, 4);
MC_RemoveTags(szBuffer, sizeof(szBuffer));
PrintToServer("%s%s\n", tag, szBuffer);
}
if (!value)
{
return 1;
}
MuCo_LoopClients(i)
{
if (i == 0
@@ -589,7 +589,7 @@ stock int MC_ShowActivityEx(int client, const char[] tag, const char[] format, a
newsign = name;
}
VFormat(szBuffer, sizeof(szBuffer), format, 4);
MC_PrintToChatEx(i, client, "%s%s: %s", tag, newsign, szBuffer);
}
}
@@ -608,18 +608,18 @@ stock int MC_ShowActivityEx(int client, const char[] tag, const char[] format, a
newsign = name;
}
VFormat(szBuffer, sizeof(szBuffer), format, 4);
MC_PrintToChatEx(i, client, "%s%s: %s", tag, newsign, szBuffer);
}
}
}
return 1;
}
/**
* Displays usage of an admin command to users depending on the setting of the sm_show_activity cvar.
* All users receive a message in their chat text, except for the originating client,
* All users receive a message in their chat text, except for the originating client,
* who receives the message based on the current ReplySource.
* Supports color tags.
*
@@ -634,19 +634,19 @@ stock int MC_ShowActivity2(int client, const char[] tag, const char[] format, an
{
if (sm_show_activity == INVALID_HANDLE)
sm_show_activity = FindConVar("sm_show_activity");
char szBuffer[MC_MAX_MESSAGE_LENGTH];
//char szCMessage[MC_MAX_MESSAGE_LENGTH];
int value = GetConVarInt(sm_show_activity);
// ReplySource replyto = GetCmdReplySource();
char name[MAX_NAME_LENGTH] = "Console";
char sign[MAX_NAME_LENGTH] = "ADMIN";
if (client != 0)
{
if (client < 0 || client > MaxClients || !IsClientConnected(client))
ThrowError("Client index %d is invalid", client);
GetClientName(client, name, sizeof(name));
AdminId id = GetUserAdmin(client);
if (id == INVALID_ADMIN_ID
@@ -654,12 +654,12 @@ stock int MC_ShowActivity2(int client, const char[] tag, const char[] format, an
{
sign = "PLAYER";
}
SetGlobalTransTarget(client);
VFormat(szBuffer, sizeof(szBuffer), format, 4);
/* We don't display directly to the console because the chat text
* simply gets added to the console, so we don't want it to print
/* We don't display directly to the console because the chat text
* simply gets added to the console, so we don't want it to print
* twice.
*/
MC_PrintToChatEx(client, client, "%s%s", tag, szBuffer);
@@ -668,16 +668,16 @@ stock int MC_ShowActivity2(int client, const char[] tag, const char[] format, an
{
SetGlobalTransTarget(LANG_SERVER);
VFormat(szBuffer, sizeof(szBuffer), format, 4);
MC_RemoveTags(szBuffer, sizeof(szBuffer));
PrintToServer("%s%s\n", tag, szBuffer);
}
if (!value)
{
return 1;
}
MuCo_LoopClients(i)
{
if (i == 0
@@ -702,7 +702,7 @@ stock int MC_ShowActivity2(int client, const char[] tag, const char[] format, an
newsign = name;
}
VFormat(szBuffer, sizeof(szBuffer), format, 4);
MC_PrintToChatEx(i, client, "%s%s: %s", tag, newsign, szBuffer);
}
}
@@ -721,18 +721,18 @@ stock int MC_ShowActivity2(int client, const char[] tag, const char[] format, an
newsign = name;
}
VFormat(szBuffer, sizeof(szBuffer), format, 4);
MC_PrintToChatEx(i, client, "%s%s: %s", tag, newsign, szBuffer);
}
}
}
return 1;
return 1;
}
/**
* Determines whether a color name exists
*
*
* @param color The color name to check
* @return True if the color exists, false otherwise
*/