Reuse delay on voiced commands?

Support for the latest build of L2J Server, get help here with installations, upgrades, problems.
Do not post bugs reports here, use viewforum.php?f=77 instead.
There is no support for other server builds than the official provided by l2jserver.com
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
JMD
Advanced User
Advanced User
Posts: 1440
Joined: Wed Apr 15, 2009 10:07 am

Reuse delay on voiced commands?

Post by JMD »

Havent tried that before, any ideas how to begin, is there an example?
User avatar
guillermokiss
Posts: 99
Joined: Mon May 24, 2010 2:19 pm
Location: Argentina
Contact:

Re: Reuse delay on voiced commands?

Post by guillermokiss »

See chat handlers and floodprotectors, there you may find some clues..
User avatar
Zoey76
L2j Inner Circle
L2j Inner Circle
Posts: 7008
Joined: Tue Aug 11, 2009 3:36 am

Re: Reuse delay on voiced commands?

Post by Zoey76 »

What do you mean by "reuse delay"?
Powered by Eclipse 4.34 🌌 | Eclipse Temurin 21 ☕ | MariaDB 11.3.2 🗃️ | L2J Server 2.6.3.0 - High Five 🚀

🔗 Join our Discord! 🎮💬
JMD
Advanced User
Advanced User
Posts: 1440
Joined: Wed Apr 15, 2009 10:07 am

Re: Reuse delay on voiced commands?

Post by JMD »

Zoey76 wrote:What do you mean by "reuse delay"?
For example after someone has used the command he cant use it again after 30 seconds or something like that.
User avatar
Zoey76
L2j Inner Circle
L2j Inner Circle
Posts: 7008
Joined: Tue Aug 11, 2009 3:36 am

Re: Reuse delay on voiced commands?

Post by Zoey76 »

It's very simple to implement.
Powered by Eclipse 4.34 🌌 | Eclipse Temurin 21 ☕ | MariaDB 11.3.2 🗃️ | L2J Server 2.6.3.0 - High Five 🚀

🔗 Join our Discord! 🎮💬
User avatar
Zoey76
L2j Inner Circle
L2j Inner Circle
Posts: 7008
Joined: Tue Aug 11, 2009 3:36 am

Re: Reuse delay on voiced commands?

Post by Zoey76 »

This is just an example, restart/shutdown will reset reuse and as long as the server is on the memory for this records will be used.
Gist by: Zoey76
diff --git a/L2J_DataPack/dist/game/data/scripts/handlers/voicedcommandhandlers/ChangePassword.java b/L2J_DataPack/dist/game/data/scripts/handlers/voicedcommandhandlers/ChangePassword.java
index f31bf55..ced0f5a 100644
--- a/L2J_DataPack/dist/game/data/scripts/handlers/voicedcommandhandlers/ChangePassword.java
+++ b/L2J_DataPack/dist/game/data/scripts/handlers/voicedcommandhandlers/ChangePassword.java
@@ -18,7 +18,9 @@
*/
package handlers.voicedcommandhandlers;
+import java.util.Map;
import java.util.StringTokenizer;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import com.l2jserver.gameserver.LoginServerThread;
@@ -32,6 +34,8 @@
*/
public class ChangePassword implements IVoicedCommandHandler
{
+ private static final Map<Integer, Long> REUSES = new ConcurrentHashMap<>();
+ private static final int REUSE = 30 * 60 * 1000; // 30 Min
private static final String[] _voicedCommands =
{
"changepassword"
@@ -77,6 +81,13 @@
return false;
}
+ final Long timeStamp = REUSES.get(activeChar.getObjectId());
+ if ((timeStamp != null) && ((System.currentTimeMillis() - REUSE) < timeStamp.longValue()))
+ {
+ activeChar.sendMessage("You cannot change the password so often!");
+ return false;
+ }
+ REUSES.put(activeChar.getObjectId(), System.currentTimeMillis());
LoginServerThread.getInstance().sendChangePassword(activeChar.getAccountName(), activeChar.getName(), curpass, newpass);
}
else
view raw gistfile1.diff hosted with ❤ by GitHub
Powered by Eclipse 4.34 🌌 | Eclipse Temurin 21 ☕ | MariaDB 11.3.2 🗃️ | L2J Server 2.6.3.0 - High Five 🚀

🔗 Join our Discord! 🎮💬
JMD
Advanced User
Advanced User
Posts: 1440
Joined: Wed Apr 15, 2009 10:07 am

Re: Reuse delay on voiced commands?

Post by JMD »

Zoey76 wrote:This is just an example, restart/shutdown will reset reuse and as long as the server is on the memory for this records will be used.
Gist by: Zoey76
diff --git a/L2J_DataPack/dist/game/data/scripts/handlers/voicedcommandhandlers/ChangePassword.java b/L2J_DataPack/dist/game/data/scripts/handlers/voicedcommandhandlers/ChangePassword.java
index f31bf55..ced0f5a 100644
--- a/L2J_DataPack/dist/game/data/scripts/handlers/voicedcommandhandlers/ChangePassword.java
+++ b/L2J_DataPack/dist/game/data/scripts/handlers/voicedcommandhandlers/ChangePassword.java
@@ -18,7 +18,9 @@
*/
package handlers.voicedcommandhandlers;
+import java.util.Map;
import java.util.StringTokenizer;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import com.l2jserver.gameserver.LoginServerThread;
@@ -32,6 +34,8 @@
*/
public class ChangePassword implements IVoicedCommandHandler
{
+ private static final Map<Integer, Long> REUSES = new ConcurrentHashMap<>();
+ private static final int REUSE = 30 * 60 * 1000; // 30 Min
private static final String[] _voicedCommands =
{
"changepassword"
@@ -77,6 +81,13 @@
return false;
}
+ final Long timeStamp = REUSES.get(activeChar.getObjectId());
+ if ((timeStamp != null) && ((System.currentTimeMillis() - REUSE) < timeStamp.longValue()))
+ {
+ activeChar.sendMessage("You cannot change the password so often!");
+ return false;
+ }
+ REUSES.put(activeChar.getObjectId(), System.currentTimeMillis());
LoginServerThread.getInstance().sendChangePassword(activeChar.getAccountName(), activeChar.getName(), curpass, newpass);
}
else
view raw gistfile1.diff hosted with ❤ by GitHub
Thats what i needed, thanks.
Post Reply