Jump to content
Eternal Lands Official Forums
The_Piper

Tradebot owners

Recommended Posts

It happens from time to time that 2 or 3 trade bots advertise at the same second in market channel.

 

This happens obviously because the trade bots are looking at the game_minute to advertise. To get rid of that "bot spam", i suggest that you add a small delay like 1-7 seconds, before the bot advertises in channel, like

 

a=rand()%7;

sleep(a);

 

So, please, add such a delay to your bot in the next days, and everybody will be happy again :devlish:

 

(if your bot doesnt use the game_minute the server sends, ignore this post :icon13: )

 

Piper

Share this post


Link to post
Share on other sites

Here's how the_piper and I solved the problem using fork(), as adding a sleep() will stall any trades:

{
				pid_t pid;
				switch(pid=fork()){
					case -1:
						log_error("fork() failed\n");
						break;
					case 0:
						sprintf(zwi, "#jc %d",cfg.outchannel);
						piper_send_text(zwi);
						sprintf(zwi, "@@%d Selling %d %s for %.2f gc each. %s",cfg.outchannel,itemcount,
						   get_item_name(inv[a].id, (itemcount>1)?1:0), cfg.sell[i].price,cfg.sale_message);
						printf("Beginning sleep\n");
						sleep(rand()%60);
						printf("Ending sleep\n");
						piper_send_text(zwi);
						sprintf(zwi, "#lc %d",cfg.outchannel);
						piper_send_text(zwi);
						printf(">%s<\n", zwi);
						exit(0);
						break;
					default:
						break;
				}
			}

What the fork()does basically is:

#JC 3

sleep(rand()%60)

@@3 I am selling teh 1337 ch33p st00f

#lc 3

Share this post


Link to post
Share on other sites

Or, you IGNORE the minute tick and use something like this in the main loop:

// has enough time elapsed to place an ad?
if (cur_time >= last_advert+(cfg.advertise_time*1000)) {
	send_advert(cfg.advertise_channel, on_chann);
	last_advert= cur_time+Random(5000); lets add some randomness as well
}

No sleeps or forks are needed, and the bot advertising becomes async with the game time.

Share this post


Link to post
Share on other sites

Or, you IGNORE the minute tick and use something like this in the main loop:

// has enough time elapsed to place an ad?
if (cur_time >= last_advert+(cfg.advertise_time*1000)) {
	send_advert(cfg.advertise_channel, on_chann);
	last_advert= cur_time+Random(5000); lets add some randomness as well
}

No sleeps or forks are needed, and the bot advertising becomes async with the game time.

 

This ^^ code is bugged, better is:

 

// has enough time elapsed to place an ad?
if (cur_time >= last_advert+(cfg.advertise_time*1000) && (last_advert+(cfg.advertise_time*1000) >= last_advert)) {
	send_advert(cfg.advertise_channel, on_chann);
	last_advert= cur_time+Random(5000); lets add some randomness as well
}

Share this post


Link to post
Share on other sites

Or, you IGNORE the minute tick and use something like this in the main loop:

// has enough time elapsed to place an ad?
if (cur_time >= last_advert+(cfg.advertise_time*1000)) {
	send_advert(cfg.advertise_channel, on_chann);
	last_advert= cur_time+Random(5000); lets add some randomness as well
}

No sleeps or forks are needed, and the bot advertising becomes async with the game time.

 

This ^^ code is bugged, better is:

 

// has enough time elapsed to place an ad?
if (cur_time >= last_advert+(cfg.advertise_time*1000) && (last_advert+(cfg.advertise_time*1000) >= last_advert)) {
	send_advert(cfg.advertise_channel, on_chann);
	last_advert= cur_time+Random(5000); lets add some randomness as well
}

 

correct, what I posted was intended of a sample of the concept, your change tries to take into account the wrap that happens with SDL after a little over 49 days.

Share this post


Link to post
Share on other sites

how it currently works in vakana:

each bot has a thread, as does main()... main, once it has launched the bots, is only responsible for central control messages and sending ticks to each bot, which happens about 10 times a second (using a sleep, so in higher demand times, it'll be less frequent).

that tick goes through to the announcement setup, which uses a size_t (64bit int) in an auto-incrementing counter.

as it stands now, there are 8 'slots' for messages, which alternate between trade and games/info (one of the info ones is below as an example). at some stage I'll probably make it a list or something

#define ATDELAY 6100
//length in ticks of a announce cycle (6k is about 10-11min)
void yaelbot::announce_tick(void){
	++announce_ticker;
	if(switches.info && !((announce_ticker+ATDELAY)%(8*ATDELAY))){
			msg = "@@4" + time_greet()+", need some information about EL? PM me, for example, 'def fire essence', or 'search hydrogenium'";
	}

if the bot is running long enough to wrap around the counter (2^64 deciseconds? pshaw, only about 60 million millennium. but, if a system it's running on uses a 32bit size_t, we're down to a decade or so... ), then the worst that should be able to happen is that one of the messages is reposted early, because wrapping around to 0 will still let it take remainder to check if it's time (as opposed to marwen's code, which I believe will stop ads entirely at the wraparound point)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×