26.05.2013, 22:10
Now, This may not be me asking for help, I realize that. However, I wasn't 100% sure where to post this, it doesn't exactly qualify as a Filterscript release, Nor does it qualify as a Gamemode release, Or a Tutorial. However, This is a help section, I am only attempting to help you, the user, by giving you a code that will stop Server Adverts in the simplest way.
Now, As you will notice, There are 2 different codes below. Why? Well. One checks for the ":" when someone enters a server IP address into chat. It works well, However, I have also made it so that when someone just puts the IP without the ending port.
Now, the first line, or second rather, contains this "if(strfind(szInput, ":", true) != -1) {" what this does is checks the users input (wherever you put it to be called at) and checks if ":" exists.
This, for those of you who know contains a "while" loop. This line "if('0' <= iChar <= '9') iCount++;" says that if the characters inside are of a numerical value, count how many numbers pop up.
The line underneath "else if(iChar == '.') iPeriod++;" says that, well hey, if any of the characters contain periods, count them up.
Which, if you have been following, are moved to the next line where it takes those numbers and does the following.
This line "if(iCount >= 8 && iPeriod >= 3) {" Checks if the number count is greater than or equal to 8 and the period count is also greater than or equal to 3.
000.000.000.000:7777
The above IP contains the basic format for an IP. notice the 8+ numbers (not counting the ":7777") and the 3 periods. this will trigger the "return 1;" and tell the code to go to the "return 0;" which will not send whatever IP the user was sending.
Now, This one looks...VERY similar to the last. Can you tell me why its different?
No?
Well, I'll tell you. Notice how in the first code, It had this line. "if(strfind(szInput, ":", true) != -1) {" well in this one it doesn't. So basically, we are saying, "don't bother with checking for the port."
Why does checking for the port matter if you can just check for the IP. Well, thats a good point. You can leave that. However, it sometimes doesnt get it just right and will let an IP through if the port is on. I use it for clarity.
Last but not least. How does one implement this code?
Simple.
My script checks for the admin status, so if the user is an admin, it will not block the user from showing an IP.
Take this code for example from my script.
Since I am sure most of this will be Copy/Pasted by those of you who just want the code and dont bother to read, I will wait.
*Jeopardy Theme Music Plays*
Done? Good.
This is put into your OnPlayerText, or it can also be use in OnPlayerCommandReceived.
When someone enters in an IP it will block the text they entered and show a warning to admins. Notice how I have both of those codes there? I bet you did, you clever kitty!
As I said before, This just provides clarity, But thats for me, if you have a way to put this all into one code, by all means. Do so.
So, To make your lives easier for those of you who want to Copy/Paste, Here is all the code together.
Last thing I ask of you, Please don't start yelling at me about how it can be made better etc. No offense intended, but I don't really care. This works for me, and it will help people who need something like this.
Now, As you will notice, There are 2 different codes below. Why? Well. One checks for the ":" when someone enters a server IP address into chat. It works well, However, I have also made it so that when someone just puts the IP without the ending port.
pawn Code:
stock CheckServerAd(szInput[]) {
if(strfind(szInput, ":", true) != -1) {
new
iCount,
iPeriod,
iPos,
iChar;
while((iChar = szInput[iPos++])) {
if('0' <= iChar <= '9') iCount++;
else if(iChar == '.') iPeriod++;
}
if(iCount >= 8 && iPeriod >= 3) {
return 1;
}
}
return 0;
}
pawn Code:
while((iChar = szInput[iPos++])) {
if('0' <= iChar <= '9') iCount++;
else if(iChar == '.') iPeriod++;
}
The line underneath "else if(iChar == '.') iPeriod++;" says that, well hey, if any of the characters contain periods, count them up.
Which, if you have been following, are moved to the next line where it takes those numbers and does the following.
This line "if(iCount >= 8 && iPeriod >= 3) {" Checks if the number count is greater than or equal to 8 and the period count is also greater than or equal to 3.
000.000.000.000:7777
The above IP contains the basic format for an IP. notice the 8+ numbers (not counting the ":7777") and the 3 periods. this will trigger the "return 1;" and tell the code to go to the "return 0;" which will not send whatever IP the user was sending.
Now, This one looks...VERY similar to the last. Can you tell me why its different?
No?
Well, I'll tell you. Notice how in the first code, It had this line. "if(strfind(szInput, ":", true) != -1) {" well in this one it doesn't. So basically, we are saying, "don't bother with checking for the port."
Why does checking for the port matter if you can just check for the IP. Well, thats a good point. You can leave that. However, it sometimes doesnt get it just right and will let an IP through if the port is on. I use it for clarity.
pawn Code:
stock CheckServerAd2(szInput[]) {
new
iCount,
iPeriod,
iPos,
iChar;
while((iChar = szInput[iPos++])) {
if('0' <= iChar <= '9') iCount++;
else if(iChar == '.') iPeriod++;
}
if(iCount >= 8 && iPeriod >= 3) {
return 1;
}
return 0;
}
Simple.
My script checks for the admin status, so if the user is an admin, it will not block the user from showing an IP.
Take this code for example from my script.
pawn Code:
if(pVar[playerid][pAdminLevel] < 2 && CheckServerAd(text) || pVar[playerid][pAdminLevel] < 2 && CheckServerAd2(text))
{
format(string,sizeof(string),"Warning: %s may be server advertising: '%s'.", GetPlayerNameEx(playerid),text);
sendToAdmins(string, COLOR_RED);
return 0;
}
*Jeopardy Theme Music Plays*
Done? Good.
This is put into your OnPlayerText, or it can also be use in OnPlayerCommandReceived.
When someone enters in an IP it will block the text they entered and show a warning to admins. Notice how I have both of those codes there? I bet you did, you clever kitty!
As I said before, This just provides clarity, But thats for me, if you have a way to put this all into one code, by all means. Do so.
So, To make your lives easier for those of you who want to Copy/Paste, Here is all the code together.
pawn Code:
stock CheckServerAd(szInput[]) {
if(strfind(szInput, ":", true) != -1) {
new
iCount,
iPeriod,
iPos,
iChar;
while((iChar = szInput[iPos++])) {
if('0' <= iChar <= '9') iCount++;
else if(iChar == '.') iPeriod++;
}
if(iCount >= 8 && iPeriod >= 3) {
return 1;
}
}
return 0;
}
stock CheckServerAd2(szInput[]) {
new
iCount,
iPeriod,
iPos,
iChar;
while((iChar = szInput[iPos++])) {
if('0' <= iChar <= '9') iCount++;
else if(iChar == '.') iPeriod++;
}
if(iCount >= 8 && iPeriod >= 3) {
return 1;
}
return 0;
}
pawn Code:
public OnPlayerText(playerid, text[])
{
new string[128];
if(pVar[playerid][pAdminLevel] < 2 && CheckServerAd(text) || pVar[playerid][pAdminLevel] < 2 && CheckServerAd2(text))
{
format(string,sizeof(string),"Warning: %s may be server advertising: '%s'.", GetPlayerNameEx(playerid),text);
submitToAdmins(string, COLOR_RED);
return 0;
}
return 0;
}
Last thing I ask of you, Please don't start yelling at me about how it can be made better etc. No offense intended, but I don't really care. This works for me, and it will help people who need something like this.