Page 1 of 1

Reuse delay on voiced commands?

Posted: Fri Dec 12, 2014 8:19 am
by JMD
Havent tried that before, any ideas how to begin, is there an example?

Re: Reuse delay on voiced commands?

Posted: Fri Dec 12, 2014 3:48 pm
by guillermokiss
See chat handlers and floodprotectors, there you may find some clues..

Re: Reuse delay on voiced commands?

Posted: Fri Dec 12, 2014 11:01 pm
by Zoey76
What do you mean by "reuse delay"?

Re: Reuse delay on voiced commands?

Posted: Sat Dec 13, 2014 5:51 pm
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.

Re: Reuse delay on voiced commands?

Posted: Sat Dec 13, 2014 5:57 pm
by Zoey76
It's very simple to implement.

Re: Reuse delay on voiced commands?

Posted: Sat Dec 13, 2014 6:17 pm
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

Re: Reuse delay on voiced commands?

Posted: Sat Dec 13, 2014 6:53 pm
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.