Jump to content
  • 0
Sign in to follow this  
Twix

Block npc by IP adress

Question

Hi !

I want to add a cooldown on a npc by IP adress.

I found to put a cooldown by account, but nothing by IP.

Someone can explain how to code it ?

Edited by Twix

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

You could use getcharip() for that, then use some structure like this inside of a NPC:

 

// NPC Variables used:// .blockedips$ for storing the blocked IPs;// .ipunblocktime for storing the unblock time at the same index as .blockedips$// WARNING!! Up to 128 IP blocks at a time!//Little config you'll need:set .@blocktime, 60; // Block time (in seconds)set .@ip$, getcharip();if ( .@ip$ != "" ) {	set .@array_size, getarraysize(.blockedips$); // Getting the array size for the calculations	for ( set .@i, 0; .@i < .@array_size; set .@i, .@i + 1 ) { // Checking and removing timed out blocks and if the player is still blocked		while ( .ipunblocktime[.@i] < gettimetick(2) && .@i < .@array_size ) { // Bulk removing timed out blocks if more than one in a row, caring not to go outside of the array			deletearray .blockedips$[.@i],1;			deletearray .ipunblocktime[.@i],1;			set .@array_size, .@array_size - 1; // Correction for the array size		}		if ( .blockedips$[.@i] == .@ip$ ) { // No need to check if outside the array since these values will be "" and forcefully .@i <= 127. Also no need to check if outdated since it should have been removed before			set .@blockedtime, gettimetick(2) - .ipunblocktime[.@i]; // Remaining time in seconds of the block			// break; // Uncomment if you don't want the loop to finish checking for timed out blocks after finding the player if it's on the list		}	}	if ( .@blockedtime ) {		mes "Oh, your IP is still blocked.";		mes "You still can't use me for the next " + .@blockedtime + " seconds.";		close;	}	mes "OK, I'll give you an apple and block you for " + .@blocktime + " seconds.";	close2;	getitem 512,1;	set .blockedips$[.@array_size],.@ip$;	set .ipunblocktime[.@array_size], gettimetick(2) + .@blocktime;	end;}

 

You can modify it the way you want to accomplish your needs.

Share this post


Link to post
Share on other sites
  • 0

you can try save the IP address  and cooldown into a new SQL table...

and your npc will retrieve the cooldown of specific IP from the SQL table ...

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.