Jump to content
  • 0
Habilis

Delay not respected

Question

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 by Habilis

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

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.

Share this post


Link to post
Share on other sites
  • 0

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.

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...

×
×
  • Create New...

Important Information

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