Habilis 119 Posted June 18, 2016 (edited) Hello I was about to release popular commands in Russian comunity such as @emotion @heart (Emotions without delay) as plugins for herc But i encountered a problem with chat flood (3 times one word phrase, even if command) So, I decided to make it configurable how many times command will be executed The comand is executed ex: 20 times but so fast, emotions merge one into another. I made a function to delay a bit, but it seems delay is not respected, no matter how much time i set as delay.... waitDelay is my delay function... /* ============================================= @emo Converted by: samsudin Original Made by: OnPlay inspired by: Anarchist ================================================ v1.0 Initial Release Displays the emotions without delay */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <time.h> #include "../common/HPMi.h" #include "../common/nullpo.h" #include "../map/clif.h" #include "../map/atcommand.h" #include "../map/script.h" #include "../map/pc.h" #include "../common/timer.h" #include "../common/HPMDataCheck.h" HPExport struct hplugin_info pinfo = { "@emo", // Plugin name SERVER_TYPE_MAP,// Which server types this plugin works with? "0.1", // Plugin version HPM_VERSION, // HPM Version (don't change, macro is automatically updated) }; /*========================================== * @emo by OnNplay * inspired by Anarchist * => Displays the emotions without delay *------------------------------------------ */ int emotion_max_repeat = 20; //max repeat without delay int emotion_max = 81; int delay_repeats = 5000; void waitDelay (void) { unsigned int tick; tick = timer->gettick()+delay_repeats; while (timer->gettick() < tick); } ACMD(emo) { int emotion = 0, repeat = 0, nbargs=0; char err_msg[1024]; nbargs=sscanf(message, "%d %d", &emotion, &repeat); if (!message || !*message || nbargs != 2 || emotion < 1 || emotion > emotion_max || repeat < 1 || repeat > emotion_max_repeat) { sprintf(err_msg, "usage: @emo <emotion (1-%d)> <repeat (max %d)>", emotion_max, emotion_max_repeat); clif->message(fd, err_msg); return -1; } for (int i = 0; i < repeat; i++) { clif->emotion(&sd->bl, emotion); waitDelay(); } return 1; } /* Server Startup */ HPExport void plugin_init (void) { addAtcommand("emo",emo); } Edited June 18, 2016 by Habilis Quote Share this post Link to post Share on other sites
0 Habilis 119 Posted June 18, 2016 On the second thought, I doubt if it is wise having 'sleeping' threads on the server side. I will explore more how to separate @ commands from spam limit and add their own limit of 5-8. Perhaps, this would be more reasonable. Quote Share this post Link to post Share on other sites
0 4144 366 Posted June 18, 2016 Yes lock server thread is bad idea. If you want global delay for any player, simply add static variable in your .c file, and store last time to it. On each @emo invoke check time from this var and allow or not depend how often this command was used. 1 Habilis reacted to this Quote Share this post Link to post Share on other sites
Hello I was about to release popular commands in Russian comunity
such as @emotion @heart (Emotions without delay) as plugins for herc
But i encountered a problem with chat flood (3 times one word phrase, even if command)
So, I decided to make it configurable how many times command will be executed
The comand is executed ex: 20 times but so fast, emotions merge one into another.
I made a function to delay a bit, but it seems delay is not respected, no matter how much time i set as delay....
waitDelay is my delay function...
Share this post
Link to post
Share on other sites