|
|
Re: [SSGM Plugin] InvalidChars [message #489011 is a reply to message #489010] |
Thu, 14 August 2014 05:18 |
Neijwiert
Messages: 124 Registered: October 2009
Karma: 0
|
Recruit |
|
|
iRANian wrote on Thu, 14 August 2014 00:26 | Instead of using Console_Input PAMSG you can use Send_Client_Text. It uses less resources on the server.
|
If you don't know how to do that:
Send_Client_Text(L"insert bullshit here", TEXT_MESSAGE_PRIVATE, true, -1, ClientReceiverID, true, true);
Not tested but it should look like that sort of.
Also when you use a certain function that iterates over a list ('Find_Player') then I advise you to store that result in a variable. Since you use it like a few times in a row on the same ID in the same function. It gets rid of unnecessary iterations.
[Updated on: Thu, 14 August 2014 05:21] Report message to a moderator
|
|
|
|
Re: [SSGM Plugin] CheckPlayerName [message #489015 is a reply to message #489009] |
Fri, 15 August 2014 02:17 |
iRANian
Messages: 4308 Registered: April 2011
Karma: 0
|
General (4 Stars) |
|
|
In CheckName() instead of looping over every player to see if the name you want to set a player's name to is already used you can just use the function to get a cPlayer*, GameObject* or playerID by player name. If any of those functions don't return anything valid the name isn't in use.
There's also another thing you can speed up in the CheckName() function, isntead of doing:
if(stristr(StringClass::getFormattedString("%ls",name),bad_words[i]))
You should store the WideStringClass of 'name' before entering the loop, as you're executing getFormattedString to create a StringClass from the WideStringClass everytime when entering the loop.
While reading in the bad words list instead of using WordCount= to find out how many bad words there are in the list you can use the following two INIClass functions:
int Entry_Count(char const *section) const;
const char *Get_Entry(char const *section,int index) const;
Is this function call in OnLoadGlobalINISettings() needed?:
If you want to make the 'check chars' functionality quicker you can create a bool array of 256, and setting the value of the array to 0 ('false') in the global INI, using memcpy(). Then read in the InvalidChars string from the INI and loop over every character of the InvalidChars string, convert each character to int and use this int as index in the bool array, to set the index to 'true'. Then in the CheckChars() function simply loop over every character of the player name, convert the character to int and use the int as index into the global bool array, if the bool at that index is set to 'true' then the player name contains an invalid char.
Something like this:
bool CharacterInvalidArray[256];
void CheckPlayerName::OnLoadGlobalINISettings(INIClass *SSGMIni)
{
memcpy((char*)&CharacterInvalidArray, 0x0, 256 * sizeof(bool))
StringClass InvalidCharsString;
SSGMIni->Get_String(InvalidCharsString, "InvalidChars", "Invalid", "");
for (int i = 0; i < InvalidCharsString.Get_Length(); i++)
{
int Index = (int)InvalidCharsString[i];
CharacterInvalidArray[Index] = true;
}
}
bool checkChars(WideStringClass name, int ID)
{
StringClass SimpleName = StringClass(name);
bool change_name = false;
for (int i = 0; i < Simplename.Get_Length(); i++)
{
int Index = (int)SimpleName[i];
if ( CharacterInvalidArray[Index ]== true )
{
SimpleName[i] = '_';
change_name = true;
}
}
if (change_name)
{
Find_Player(ID)->Set_Name(SimpleName);
}
return(change_name);
}
Note that you can justserveers with Chinese characters (hence why PlayerName is WideStringClass instead of just StringClass) so you should also check if the playername only contains ANSI characters when joining.
You can get the WideStringClass player name on join and use WideStringClass::Is_ANSI() to check if there are non-ANSI/ASCII characters. The definition for Is_ANSI() is
bool WideStringClass::Is_ANSI()
{
if (m_Buffer)
{
for (int i = 0;m_Buffer[i] != 0;i++)
{
unsigned short value = m_Buffer[i];
if (value > 255)
{
return false;
}
}
}
return true;
}
You can create your own function which will replace non-ANSI characters, variable 'value' > 255 in the above function, with underscores or something.
What Dragonade does (in the connection request event )is:
for (int i = 0;i < Request.clientName.Get_Length();i++) {
if (Request.clientName[i] < 33 || Request.clientName[i] > 126) {
Request.clientName.RemoveSubstring(i,1);
i--;
}
Where Request.clientName is WideStringClass.
Long time and well respected Renegade community member, programmer, modder and tester.
Scripts 4.0 private beta tester since May 2011.
My Renegade server plugins releases
[Updated on: Fri, 15 August 2014 02:31] Report message to a moderator
|
|
|
|
|
Re: [SSGM Plugin] CheckPlayerName [message #489021 is a reply to message #489009] |
Fri, 15 August 2014 08:11 |
iRANian
Messages: 4308 Registered: April 2011
Karma: 0
|
General (4 Stars) |
|
|
They're useful tips for future use, if you apply them now you'll internalize thinking that way. The use of a boolean array for every possible ASCII value (i.e. array of 256 bools) to check if a character is invalid also looks simpler and cleaner.
Long time and well respected Renegade community member, programmer, modder and tester.
Scripts 4.0 private beta tester since May 2011.
My Renegade server plugins releases
|
|
|
Re: [SSGM Plugin] InvalidChars [message #489023 is a reply to message #489010] |
Fri, 15 August 2014 12:52 |
|
Jerad2142
Messages: 3811 Registered: July 2006 Location: USA
Karma: 6
|
General (3 Stars) |
|
|
iRANian wrote on Thu, 14 August 2014 01:26 | Instead of using Console_Input PAMSG you can use Send_Client_Text. It uses less resources on the server.
|
You must have some really shitty servers if your concerned about something that happens ~50 times in a half hour period (less than ~50 because it would only happen on bad player names, and in all honesty I sort of feel like ~50 joins in 30 minutes still seems like a lot).
Visit Jerad's deer sweat shop
[Updated on: Fri, 15 August 2014 12:54] Report message to a moderator
|
|
|
|
|
|
|