/* This is separate due to it being required from inside the tests. */
void setup_objects (void) {

	init_objects_command(1);
	cmd = create_command("my_command", "/bin/true");
	ck_assert(cmd != NULL);
	register_command(cmd);

	init_objects_host(1);
	hst = create_host(TARGET_HOST_NAME);
	ck_assert(hst != NULL);
	hst->check_command_ptr = cmd;
	hst->retain_status_information = TRUE;
	register_host(hst);

	init_objects_service(1);
	svc = create_service(hst, TARGET_SERVICE_NAME);
	ck_assert(svc != NULL);
	svc->check_command_ptr = cmd;
	svc->retain_status_information = TRUE;
	register_service(svc);

}
Exemple #2
0
// MAIN - you can check out any time you like, but you can never leave
int main(int argc, char **argv)
{
	struct timeval time;
	time_t time_slept=0;
	time_t processing_time=0, total_processing_time=0;
	long hotreboot = 0;

	if( argc > 1 )
	{
		if( !is_number(argv[1]) )
		{
			mudlog("Invalid port number!");
			exit(1);
		}
		else if( (port = atoi(argv[1])) <= 1024 )
		{
			mudlog("Port must be above 1024!");
			exit(1);
		}
		if(argc > 2 && !strcmp(argv[2], "hotreboot"))
			hotreboot = 1;
	}

// test stuff
	{
	}


	get_time(&time);
	current_time = time.tv_sec;

	if(!hotreboot)
		create_host(port);
	init_mud(hotreboot);

	while(!mud_shutdown)
	{
		// we want the mud to loop no more than (LOOPS) times a second.. but not to loop
		// (LOOPS) times in 1/10th of a second and then wait for 9/10ths... try to make it even
		if( tick % LOOPS_PER_SECOND == 0 )
		{
			if( time_slept > 1000000 )
			{
				mudlog("time_slept is over a second (%li) and total processing_time this tick (%li)", 
					time_slept, total_processing_time);
//				exit(1);
			}
			else
				mudsleep(1000000 - time_slept);

			time_slept = 0;
			total_processing_time = 0;
		}

		get_time( &time );
		processing_time = time.tv_usec;

		// do all the mud stuff here....
		check_connections();
		mud_update();
		// end mud stuff

		get_time( &time );
		if(time.tv_usec > processing_time)
			processing_time = time.tv_usec - processing_time;
		else
			processing_time = processing_time - time.tv_usec;
		total_processing_time += processing_time;
		current_time = time.tv_sec;
		time_slept += (1000000 / LOOPS_PER_SECOND)-(processing_time);
		tick++;
		mudsleep((1000000 / LOOPS_PER_SECOND)-(processing_time));
	}

	close(host);
	free_mud();
	mudlog("Mud terminated normally.");
	return 1;
}