예제 #1
0
파일: fread.c 프로젝트: Onirik79/bardmud
/*
 * Funzione fopen creata appositamente per gestire meglio la tipologia di file del BARD: MUD_FILE
 *
 * bool msg indica se visualizzare o meno il messaggio di errore apertura file
 *	gli sì dà un valore FALSE per i file aperti molto spesso oppure che non è
 *	obbligatorio che esistano
 */
MUD_FILE *mud_fopen( const char *dirname, const char *filename, const char *modes, bool msg )
{
	MUD_FILE	*fp;
	char		 buf[MIL];

	CREATE( fp, MUD_FILE, 1 );

	/* Ha bisogno di filename non nullo perché lo utilizza per stamparlo nel messaggio di bug
	 *	in caso di fallimento apertura mud_fopen */
	if ( !VALID_STR(filename) )
	{
		send_log( NULL, LOG_BUG, "mud_fopen: filename passato non valido. dirname: %s modes:%s",
			(dirname)  ?  dirname  :  "?",
			(modes)    ?  modes    :  "?" );
		filename = "?";
	}

	sprintf( buf, "%s%s", dirname, filename );
	fp->path = str_dup( buf );

	fp->file = fopen( fp->path, modes );
	if ( !fp->file )
	{
		if ( msg )
		{
			send_log( NULL, LOG_FP, "mud_fopen: errore nell'apertura del file %s in modalità %s", fp->path, modes );
			send_log( NULL, LOG_FP, "mud_fopen: strerror: %s", strerror(errno) );
		}

		MUD_FCLOSE( fp );
		return NULL;
	}

	return fp;
}
예제 #2
0
/* Temporarily disables listening on all of the proxy's listeners. Upon
 * success, the proxy enters the PR_PAUSED state. If disabling at least one
 * listener returns an error, then the proxy state is set to PR_STERROR
 * because we don't know how to resume from this. The function returns 0
 * if it fails, or non-zero on success.
 */
int pause_proxy(struct proxy *p)
{
	struct listener *l;

	if (!(p->cap & PR_CAP_FE) || p->state == PR_STERROR ||
	    p->state == PR_STSTOPPED || p->state == PR_STPAUSED)
		return 1;

	Warning("Pausing %s %s.\n", proxy_cap_str(p->cap), p->id);
	send_log(p, LOG_WARNING, "Pausing %s %s.\n", proxy_cap_str(p->cap), p->id);

	for (l = p->listen; l != NULL; l = l->next) {
		if (!pause_listener(l))
			p->state = PR_STERROR;
	}

	if (p->state == PR_STERROR) {
		Warning("%s %s failed to enter pause mode.\n", proxy_cap_str(p->cap), p->id);
		send_log(p, LOG_WARNING, "%s %s failed to enter pause mode.\n", proxy_cap_str(p->cap), p->id);
		return 0;
	}

	p->state = PR_STPAUSED;
	return 1;
}
예제 #3
0
/*
 * This function temporarily disables listening so that another new instance
 * can start listening. It is designed to be called upon reception of a
 * SIGTTOU, after which either a SIGUSR1 can be sent to completely stop
 * the proxy, or a SIGTTIN can be sent to listen again.
 */
void pause_proxies(void)
{
	int err;
	struct proxy *p;

	err = 0;
	p = proxy;
	tv_update_date(0,1); /* else, the old time before select will be used */
	while (p) {
		if (p->cap & PR_CAP_FE &&
		    p->state != PR_STERROR &&
		    p->state != PR_STSTOPPED &&
		    p->state != PR_STPAUSED) {
			Warning("Pausing %s %s.\n", proxy_cap_str(p->cap), p->id);
			send_log(p, LOG_WARNING, "Pausing %s %s.\n", proxy_cap_str(p->cap), p->id);
			pause_proxy(p);
			if (p->state != PR_STPAUSED) {
				err |= 1;
				Warning("%s %s failed to enter pause mode.\n", proxy_cap_str(p->cap), p->id);
				send_log(p, LOG_WARNING, "%s %s failed to enter pause mode.\n", proxy_cap_str(p->cap), p->id);
			}
		}
		p = p->next;
	}
	if (err) {
		Warning("Some proxies refused to pause, performing soft stop now.\n");
		send_log(p, LOG_WARNING, "Some proxies refused to pause, performing soft stop now.\n");
		soft_stop();
	}
}
예제 #4
0
파일: fread.c 프로젝트: Onirik79/bardmud
/*
 * Read a letter from a file.
 */
char fread_letter( MUD_FILE *fp )
{
	char		c;

	if ( !fp || !fp->file )
	{
		send_log( NULL, LOG_FREAD, "fread_letter: la struttura di fp è NULL" );
		if ( fBootDb )
			exit( EXIT_FAILURE );
		return '\0';
	}

	do
	{
		if ( feof(fp->file) )
		{
			send_log( fp, LOG_FREAD, "fread_letter: EOF incontrato nella lettura." );
			if ( fBootDb )
				exit( EXIT_FAILURE );
			return '\0';
		}
		c = getc( fp->file );
	} while ( isspace(c) );

	return c;
}
예제 #5
0
/*
 * Cerca nella scacchiera il pezzo passato impostando le coordinate passate
 * Ritorna TRUE se lo ha trovato, altrimenti FALSE
 */
bool find_piece( CHESSBOARD_DATA *board, int *x, int *y, int piece )
{
	int	a;
	int	b;

	if ( !board )
	{
		send_log( NULL, LOG_BUG, "find_piece: board passata è NULL" );
		return FALSE;
	}

	if ( piece < 0 || piece >= PIECE_NONE )
	{
		send_log( NULL, LOG_BUG, "find_piece: piece passato è errato: %d", piece );
		return FALSE;
	}

	for ( a = 0;  a < 8;  a++ )
	{
		for ( b = 0;  b < 8;  b++ )
		{
			if ( board->piece[a][b] == piece )
				break;
		}
	}

	*x = a;
	*y = b;

	if ( board->piece[a][b] == piece )
		return TRUE;

	return FALSE;
}
예제 #6
0
파일: fread.c 프로젝트: Onirik79/bardmud
/*
 * Legge fino a fine riga
 * Viene più utilizzata per leggere i commenti che per ritornare valori
 */
void fread_to_eol( MUD_FILE *fp )
{
	char		c;

	if ( !fp || !fp->file )
	{
		send_log( NULL, LOG_FREAD, "fread_to_eol: la struttura di fp è NULL" );
		if ( fBootDb )
			exit( EXIT_FAILURE );
		return;
	}

	do
	{
		if ( feof(fp->file) )
		{
			send_log( fp, LOG_FREAD, "fread_to_eol: EOF incontrato nella lettura." );
			if ( fBootDb )
				exit( EXIT_FAILURE );
			return;
		}
		c = getc( fp->file );
	} while ( c != '\r' && c != '\n' );

	do
	{
		c = getc( fp->file );
	} while ( c == '\r' || c == '\n' );

	ungetc( c, fp->file );
}
예제 #7
0
/*
 * This function reactivates listening. This can be used after a call to
 * sig_pause(), for example when a new instance has failed starting up.
 * It is designed to be called upon reception of a SIGTTIN.
 */
void listen_proxies(void)
{
	struct proxy *p;
	struct listener *l;

	p = proxy;
	tv_update_date(0,1); /* else, the old time before select will be used */
	while (p) {
		if (p->state == PR_STPAUSED) {
			Warning("Enabling %s %s.\n", proxy_cap_str(p->cap), p->id);
			send_log(p, LOG_WARNING, "Enabling %s %s.\n", proxy_cap_str(p->cap), p->id);

			for (l = p->listen; l != NULL; l = l->next) {
				if (listen(l->fd, p->backlog ? p->backlog : p->maxconn) == 0) {
					if (actconn < global.maxconn && p->feconn < p->maxconn) {
						EV_FD_SET(l->fd, DIR_RD);
						p->state = PR_STRUN;
					}
					else
						p->state = PR_STIDLE;
				} else {
					int port;

					if (l->addr.ss_family == AF_INET6) {
						port = ntohs(((struct sockaddr_in6 *)(&l->addr))->sin6_port);
						Warning("Port %d busy while trying to enable %s %s.\n",
							port, proxy_cap_str(p->cap), p->id);
						send_log(p, LOG_WARNING, "Port %d busy while trying to enable %s %s.\n",
							 port, proxy_cap_str(p->cap), p->id);
					}
					else if (l->addr.ss_family == AF_INET) {
						port = ntohs(((struct sockaddr_in *)(&l->addr))->sin_port);
						Warning("Port %d busy while trying to enable %s %s.\n",
							port, proxy_cap_str(p->cap), p->id);
						send_log(p, LOG_WARNING, "Port %d busy while trying to enable %s %s.\n",
							 port, proxy_cap_str(p->cap), p->id);
					}
					else {
						Warning("Bind on socket %d busy while trying to enable %s %s.\n",
							l->luid, proxy_cap_str(p->cap), p->id);
						send_log(p, LOG_WARNING, "Bind on socket %d busy while trying to enable %s %s.\n",
							 l->luid, proxy_cap_str(p->cap), p->id);
					}

					/* Another port might have been enabled. Let's stop everything. */
					pause_proxy(p);
					break;
				}
			}
		}
		p = p->next;
	}
}
예제 #8
0
/* This function kills an existing embryonic session. It stops the connection's
 * transport layer, releases assigned resources, resumes the listener if it was
 * disabled and finally kills the file descriptor. This function requires that
 * sess->origin points to the incoming connection.
 */
static void session_kill_embryonic(struct session *sess)
{
	int level = LOG_INFO;
	struct connection *conn = __objt_conn(sess->origin);
	struct task *task = sess->task;
	unsigned int log = sess->fe->to_log;
	const char *err_msg;

	if (sess->fe->options2 & PR_O2_LOGERRORS)
		level = LOG_ERR;

	if (log && (sess->fe->options & PR_O_NULLNOLOG)) {
		/* with "option dontlognull", we don't log connections with no transfer */
		if (!conn->err_code ||
		    conn->err_code == CO_ER_PRX_EMPTY || conn->err_code == CO_ER_PRX_ABORT ||
		    conn->err_code == CO_ER_CIP_EMPTY || conn->err_code == CO_ER_CIP_ABORT ||
		    conn->err_code == CO_ER_SSL_EMPTY || conn->err_code == CO_ER_SSL_ABORT)
			log = 0;
	}

	if (log) {
		if (!conn->err_code && (task->state & TASK_WOKEN_TIMER)) {
			if (conn->flags & CO_FL_ACCEPT_PROXY)
				conn->err_code = CO_ER_PRX_TIMEOUT;
			else if (conn->flags & CO_FL_ACCEPT_CIP)
				conn->err_code = CO_ER_CIP_TIMEOUT;
			else if (conn->flags & CO_FL_SSL_WAIT_HS)
				conn->err_code = CO_ER_SSL_TIMEOUT;
		}

		session_prepare_log_prefix(sess);
		err_msg = conn_err_code_str(conn);
		if (err_msg)
			send_log(sess->fe, level, "%s: %s\n", trash.str, err_msg);
		else
			send_log(sess->fe, level, "%s: unknown connection error (code=%d flags=%08x)\n",
				 trash.str, conn->err_code, conn->flags);
	}

	/* kill the connection now */
	conn_stop_tracking(conn);
	conn_full_close(conn);
	conn_free(conn);

	task_delete(task);
	task_free(task);
	session_free(sess);
}
예제 #9
0
/*
 * this function disables health-check servers so that the process will quickly be ignored
 * by load balancers. Note that if a proxy was already in the PAUSED state, then its grace
 * time will not be used since it would already not listen anymore to the socket.
 */
void soft_stop(void)
{
	struct proxy *p;
	struct peers *prs;

	stopping = 1;
	p = proxy;
	tv_update_date(0,1); /* else, the old time before select will be used */
	while (p) {
		if (p->state != PR_STSTOPPED) {
			Warning("Stopping %s %s in %d ms.\n", proxy_cap_str(p->cap), p->id, p->grace);
			send_log(p, LOG_WARNING, "Stopping %s %s in %d ms.\n", proxy_cap_str(p->cap), p->id, p->grace);
			p->stop_time = tick_add(now_ms, p->grace);
		}
		if (p->table.size && p->table.sync_task)
			 task_wakeup(p->table.sync_task, TASK_WOKEN_MSG);

		/* wake every proxy task up so that they can handle the stopping */
		task_wakeup(p->task, TASK_WOKEN_MSG);
		p = p->next;
	}

	prs = peers;
	while (prs) {
		stop_proxy((struct proxy *)prs->peers_fe);
		prs = prs->next;
	}
	/* signal zero is used to broadcast the "stopping" event */
	signal_handler(0);
}
예제 #10
0
void				fork_call(void *(*procedure)(void *), char *info)
{
  pthread_t			proc;
  t_call			call;
  void				*to_pass;
  int				ret;

  call=procedure;
  to_pass=*(void **)(&call); /* HAHAHA ! Try to know why I did that ! :-) */
  if (IS_VERBOSE)
    send_log(LOG_INFO, "Scheduler create  thread %d to [%s]\n", ++gl_nbr_thread, info);
  ret=pthread_create(&proc, NULL, thread_and_exit, to_pass);
  pthread_detach(proc);
  if (ret != ZERO)
    send_log(LOG_EMERG, "[28] Can't create Thread for scheduling\n");
}
예제 #11
0
/*
 * Libera la struttura di una scacchiera
 */
void free_chessboard( CHESSBOARD_DATA *board )
{
	char	buf[MSL];

	if ( !board )
	{
		send_log( NULL, LOG_BUG, "free_board: board passata è NULL" );
		return;
	}

	sprintf( buf, "Il gioco è terminato dopo %d mosse.\r\n", board->moves );

	if ( board->player1 )
		send_to_char( board->player1, buf );

	if ( board->player2 )
		send_to_char( board->player2, buf );

	UNLINK( board, first_chessboard, last_chessboard, next, prev );
	top_chessboard--;

	board->player1 = NULL;
	board->player2 = NULL;
	board->turn	   = NULL;
	destroybv( board->flags1 );
	destroybv( board->flags2 );
	DISPOSE( board );
}
예제 #12
0
/*
 * This function reactivates listening. This can be used after a call to
 * sig_pause(), for example when a new instance has failed starting up.
 * It is designed to be called upon reception of a SIGTTIN.
 */
void resume_proxies(void)
{
	int err;
	struct proxy *p;
	struct peers *prs;

	err = 0;
	p = proxy;
	tv_update_date(0,1); /* else, the old time before select will be used */
	while (p) {
		err |= !resume_proxy(p);
		p = p->next;
	}

	prs = peers;
	while (prs) {
		p = prs->peers_fe;
		err |= !resume_proxy(p);
		prs = prs->next;
        }

	if (err) {
		Warning("Some proxies refused to resume, a restart is probably needed to resume safe operations.\n");
		send_log(p, LOG_WARNING, "Some proxies refused to resume, a restart is probably needed to resume safe operations.\n");
	}
}
예제 #13
0
/*
 * This function temporarily disables listening so that another new instance
 * can start listening. It is designed to be called upon reception of a
 * SIGTTOU, after which either a SIGUSR1 can be sent to completely stop
 * the proxy, or a SIGTTIN can be sent to listen again.
 */
void pause_proxies(void)
{
	int err;
	struct proxy *p;
	struct peers *prs;

	err = 0;
	p = proxy;
	tv_update_date(0,1); /* else, the old time before select will be used */
	while (p) {
		err |= !pause_proxy(p);
		p = p->next;
	}

	prs = peers;
	while (prs) {
		p = prs->peers_fe;
		err |= !pause_proxy(p);
		prs = prs->next;
        }

	if (err) {
		Warning("Some proxies refused to pause, performing soft stop now.\n");
		send_log(p, LOG_WARNING, "Some proxies refused to pause, performing soft stop now.\n");
		soft_stop();
	}
}
// format of sending header
void send_headers(FILE *f, char *path, int status, char *title, char *extra, char *mime, int length, time_t date) {
	 time_t now;
	 char timebuf[128];
	
	send_log(path, status, title, extra, mime, length, date);
	fprintf(f, "%s %d %s\r\n", PROTOCOL, status, title);
	fprintf(f, "Server: %s\r\n", SERVER);
	now = time(NULL);
	strftime(timebuf, sizeof(timebuf), RFC1123FMT, gmtime(&now));
	fprintf(f, "Date: %s\r\n", timebuf);
  
	if (extra) 
		fprintf(f, "%s\r\n", extra);
 	if (mime) 
		fprintf(f, "Content-Type: %s\r\n", mime);
 	if (length >= 0) 
		fprintf(f, "Content-Length: %d\r\n", length);
 	if (date != -1) {
		strftime(timebuf, sizeof(timebuf), RFC1123FMT, gmtime(&date));
    		fprintf(f, "Last-Modified: %s\r\n", timebuf);
  	}	
  
	fprintf(f, "Connection: close\r\n");
	fprintf(f, "\r\n");

/////////////// send_log
//	send_log(path, status, title, extra, mime, length, date);
//////////////

}
예제 #15
0
파일: special.c 프로젝트: Onirik79/bardmud
SPEC_RET spec_executioner( CHAR_DATA *ch )
{
	MOB_PROTO_DATA *cityguard;
	CHAR_DATA	   *victim;
	CHAR_DATA	   *v_next;
	char		   *crime;
	char			buf[MSL];

	if ( !is_awake(ch) )	return FALSE;
	if ( ch->fighting )		return FALSE;

	crime = "";
	for ( victim = ch->in_room->first_person;  victim;  victim = v_next )
	{
		v_next = victim->next_in_room;

		if ( IS_PG(victim) && HAS_BIT_PLR(victim, PLAYER_KILLER) )
		{
			crime = "assassino";
			break;
		}

		if ( IS_PG(victim) && HAS_BIT_PLR(victim, PLAYER_THIEF) )
		{
			crime = "ladro";
			break;
		}
	}

	if ( !victim )
		return FALSE;

	if ( HAS_BIT(ch->in_room->flags, ROOM_SAFE) )
	{
		sprintf( buf, "yell codardo di un %s!", crime );	/* (GR) articolo */
		send_command( ch, buf, CO );
		return TRUE;
	}

	sprintf( buf, "yell Proteggiamo l'innocente dal %s!!", crime );	/* (GR) articolo dal dall' */
	send_command( ch, buf, CO );
	multi_hit( ch, victim, TYPE_UNDEFINED );

	if ( char_died(ch) )
		return TRUE;

	/* Aggiunto il log nel caso che venga a mancare la guardia cittadina */
	cityguard = get_mob_index( NULL, VNUM_MOB_CITYGUARD );

	if ( !cityguard )
	{
		send_log( NULL, LOG_BUG, "spec_executioner: Guardia cittadina mancante - Vnum:[%d]", VNUM_MOB_CITYGUARD );
		return TRUE;
	}

	char_to_room( make_mobile(cityguard), ch->in_room );
	char_to_room( make_mobile(cityguard), ch->in_room );
	return TRUE;
}
예제 #16
0
/* sends a log message when a backend goes down, and also sets last
 * change date.
 */
void set_backend_down(struct proxy *be)
{
	be->last_change = now.tv_sec;
	be->down_trans++;

	Alert("%s '%s' has no server available!\n", proxy_type_str(be), be->id);
	send_log(be, LOG_EMERG, "%s %s has no server available!\n", proxy_type_str(be), be->id);
}
예제 #17
0
파일: fread.c 프로젝트: Onirik79/bardmud
char *print_bool( const bool value )
{
	if ( value == TRUE )
		return "True";
	else
		return "False";

	send_log( NULL, LOG_FWRITE, "print_bool: valore non booleano: %d.", value );
}
예제 #18
0
	void log( const plugin::log_msg_t type, const char* tag, const char* format, va_list vars ){
		static char msg_buffer[ 1024 ];

		if( g_logger ){
			memset( msg_buffer, 0, 1024 );
			vsprintf_s( msg_buffer, format, vars );
			send_log( type, tag, msg_buffer );
		};
	};
예제 #19
0
int remote_playloop(void) {

  Status s;

  /* Check the status. If the player should pause,
     then signal that the command has been processed
     and wait for a new status. A new status will end
     the player and return control to the main loop.
     The main loop will signal that the new command
     has been processed.
   */
  
  pthread_mutex_lock (&main_lock);
  s = getstatus();
  pthread_mutex_unlock (&main_lock);

  send_log("playloop entry s=%d", s);

  if (s == PAUSE) {

    /* Send "pause on" */
    send_msg("P 1");

    while (s == PAUSE) {

      sem_post(&sem_processed);
      sem_wait(&sem_command);
      pthread_mutex_lock (&main_lock);
      s = getstatus();
      pthread_mutex_unlock (&main_lock);
    }

    /* Send "pause off" */
    send_msg("P 2");
  }

    /* Send stop msg to the frontend */
    /* this probably should be done after the audio buffer is flushed and no audio is actually playing, but don't know how */
  if ((s == STOP) || (s == QUIT)) send_msg("P 0");

  send_log("playloop exit s=%d", s);

  return ((s == NEXT) || (s == STOP) || (s == QUIT));
}
예제 #20
0
파일: fread.c 프로젝트: Onirik79/bardmud
/*
 * Funzione di lettura delle liste, cioè dei file *.lst.
 */
void fread_list( const char *list_file, const char *section, FREAD_FUN *freadfun, bool unique )
{
	MUD_FILE *fp;

	fp = mud_fopen( "", list_file, "r", TRUE );
	if ( !fp )
	{
		if ( fBootDb )
			exit( EXIT_FAILURE );
		return;
	}

	for ( ; ; )
	{
		char   *filename;

		if ( feof(fp->file) )
		{
			send_log( fp, LOG_FREAD, "fread_: fine del file prematuro nella lettura" );
			if ( fBootDb )
				exit( EXIT_FAILURE );
		}

		filename = fread_word( fp );

		if ( filename[0] == '*' )	/* Salta i commenti */
		{
			fread_to_eol( fp );
			continue;
		}

		/* Se arrivato alla fine esce */
		if ( !str_cmp(filename, "End") )
			break;

		/* Legge l'area se si tratta di una sezione file di area */
		if ( !str_cmp(section, "AREA_FILE") && freadfun == NULL )
		{
			MUD_FILE *fp_area;

			fp_area = mud_fopen( "", filename, "r", TRUE );
			if ( !fp_area )
			{
				if ( fBootDb )
					exit( EXIT_FAILURE );
				return;
			}

			load_area_file( NULL, fp_area );
		}
		else
			fread_section( filename, section, freadfun, unique );	/* Legge la sezione relativa al file ricavato dalla lista */
	}

	MUD_FCLOSE( fp );
}
예제 #21
0
/* This function resumes listening on the specified proxy. It scans all of its
 * listeners and tries to enable them all. If any of them fails, the proxy is
 * put back to the paused state. It returns 1 upon success, or zero if an error
 * is encountered.
 */
int resume_proxy(struct proxy *p)
{
	struct listener *l;
	int fail;

	if (p->state != PR_STPAUSED)
		return 1;

	Warning("Enabling %s %s.\n", proxy_cap_str(p->cap), p->id);
	send_log(p, LOG_WARNING, "Enabling %s %s.\n", proxy_cap_str(p->cap), p->id);

	fail = 0;
	for (l = p->listen; l != NULL; l = l->next) {
		if (!resume_listener(l)) {
			int port;

			port = get_host_port(&l->addr);
			if (port) {
				Warning("Port %d busy while trying to enable %s %s.\n",
					port, proxy_cap_str(p->cap), p->id);
				send_log(p, LOG_WARNING, "Port %d busy while trying to enable %s %s.\n",
					 port, proxy_cap_str(p->cap), p->id);
			}
			else {
				Warning("Bind on socket %d busy while trying to enable %s %s.\n",
					l->luid, proxy_cap_str(p->cap), p->id);
				send_log(p, LOG_WARNING, "Bind on socket %d busy while trying to enable %s %s.\n",
					 l->luid, proxy_cap_str(p->cap), p->id);
			}

			/* Another port might have been enabled. Let's stop everything. */
			fail = 1;
			break;
		}
	}

	p->state = PR_STREADY;
	if (fail) {
		pause_proxy(p);
		return 0;
	}
	return 1;
}
예제 #22
0
/*
 * Libera dalla memoria tutte le scacchiere
 */
void free_all_chessboards( void )
{
	CHESSBOARD_DATA *chess;

	for ( chess = first_chessboard;  chess;  chess = chess->next )
		free_chessboard( chess );

	if ( top_chessboard != 0 )
		send_log( NULL, LOG_BUG, "free_all_chessboards: top_chessboard non è 0 dopo aver liberato le scacchiere: %d", top_chessboard );
}
예제 #23
0
파일: fread.c 프로젝트: Onirik79/bardmud
/*
 * Libera dalla memoria un sinonimo
 */
void free_synonym( SYNO_DATA *synonym )
{
	if ( !synonym )
	{
		send_log( NULL, LOG_BUG, "free_synonym: synonym passato è NULL" );
		return;
	}

	DISPOSE( synonym->syn );
	DISPOSE( synonym );
}
예제 #24
0
void				*thread_and_exit(void *procedure)
{
  t_call			call;

  call=*(t_call *)(&procedure);
  call(NULL);
  if (IS_VERBOSE)
    send_log(LOG_INFO, "Scheduler exiting thread %d\n", --gl_nbr_thread);
  pthread_exit(NULL);

  return (NULL);
}
예제 #25
0
파일: fread.c 프로젝트: Onirik79/bardmud
/*
 * Scrive su file una struttura synonym.
 */
void fwrite_synonym( MUD_FILE *fp, SYNO_DATA *synonym, int type )
{
	if ( !synonym )
	{
		send_log( fp, LOG_FWRITE, "fwrite_synonym: synonym è NULL, type: %s",
			table_code[type].code.name );
		return;
	}

	fprintf( fp->file, "    %s", code_str(fp, synonym->cat, type) );
	fprintf( fp->file, " %s~\n", synonym->syn );
}
예제 #26
0
파일: calendar.c 프로젝트: Onirik79/bardmud
/* (RR) Anche questa come sopra rifarla con la data di inizio gioco.
 * Ritorna le ore giocate da un pg.
 */
int get_hours_played( CHAR_DATA *ch )
{
	if ( !ch )
	{
		send_log( NULL, LOG_BUG, "get_hours_played: ch è NULL" );
		return 0;
	}

	if ( IS_MOB(ch) )
		return 0;

	return ( ch->pg->played + (current_time - ch->pg->logon) ) / 3600;
}
예제 #27
0
파일: fread.c 프로젝트: Onirik79/bardmud
/*
 * Legge la parola e la ritorna come booleano.
 */
bool fread_bool( MUD_FILE *fp )
{
	char	   *word;

	if ( !fp || !fp->file )
	{
		send_log( NULL, LOG_FREAD, "fread_bool: la struttura di fp è NULL" );
		if ( fBootDb )
			exit( EXIT_FAILURE );
		return FALSE;
	}

	word = fread_word( fp );
	if		( !str_cmp(word, "False") )		return FALSE;
	else if ( !str_cmp(word, "True" ) )		return TRUE;

	/* Se giunge qui significa che c'è un errore */
	send_log( fp, LOG_FREAD, "fread_bool: Valore errato nella lettura." );
	if ( fBootDb )
		exit( EXIT_FAILURE );
	return FALSE;
}
예제 #28
0
파일: calendar.c 프로젝트: Onirik79/bardmud
/* (RR) con l'età iniziale scelta dal giocatore e la divisione del return differente basata sul nostro time
 * Ritorna l'età di un giocatore.
 */
int get_age( CHAR_DATA *ch, int type )
{
	if ( !ch )
	{
		send_log( NULL, LOG_BUG, "get_age: ch è NULL" );
		return 17;
	}

	if ( IS_MOB(ch) )
		return 17;

	switch ( type )
	{
	  default:
		send_log( NULL, LOG_BUG, "tipo di unità temporale errata per %s: %d", ch->name, type );
		return 17;

	  case TIME_YEAR:	return 17 + (  (current_time - ch->pg->creation_date) / SECONDS_IN_YEAR );						break;
	  case TIME_MONTH:	return  1 + ( ((current_time - ch->pg->creation_date) / SECONDS_IN_MONTH) % MONTHS_IN_YEAR );	break;
	  case TIME_DAY:	return  1 + ( ((current_time - ch->pg->creation_date) / SECONDS_IN_YEAR ) % DAYS_IN_MONTH  );	break;
	}
}
예제 #29
0
/*
 * stampa al pg il suo stato attuale di gioco
 */
void show_status( CHAR_DATA *ch, CHESSBOARD_DATA *board )
{
	if ( !ch )
	{
		send_log( NULL, LOG_BUG, "print_status: ch passato è NULL" );
		return;
	}

	if ( !board )
	{
		send_to_char( ch, "Non sto giocando a nessuna partita di scacchi.\r\n" );
		return;
	}

	if ( !board->player1 )
		send_to_char( ch, "Non ho nessun giocatore per i pezzi neri con cui gareggiare.\r\n" );
	else if ( board->player1 == ch )
		send_to_char( ch, "Sono io il giocatore dei pezzi neri.\r\n" );
	else
		ch_printf( ch, "%s è il giocatore che tiene i pezzi neri.\r\n", board->player1->name );

	if ( king_in_possible_checkmate(board, PIECE_KING, COLOR_BLACK) )
		send_to_char( ch, "Il re nero potrebbe essere sotto scacco matto.\r\n" );
	else if ( king_in_check(board, PIECE_KING, COLOR_BLACK) > 0 )
		send_to_char( ch, "Il re nero è sotto scacco.\r\n" );

	if ( !board->player2 )
		send_to_char( ch, "Non ho nessun giocatore per i pezzi bianchi con cui gareggiare.\r\n" );
	else if ( board->player2 == ch )
		send_to_char( ch, "Sono io il giocatore dei pezzi bianchi.\r\n" );
	else
		ch_printf( ch, "%s è il giocatore che tiene i pezzi bianchi.\r\n", board->player2->name );

	if ( king_in_possible_checkmate(board, PIECE_KING, COLOR_WHITE) )
		send_to_char( ch, "Il re bianco potrebbe essere sotto scacco matto.\r\n" );
	else if ( king_in_check(board, PIECE_KING, COLOR_WHITE) > 0 )
		send_to_char( ch, "Il re bianco è sotto scacco.\r\n" );

	if ( !board->player2 || !board->player1 )
		return;

	if ( board->moves < 0 )
		send_to_char( ch, "Il gioco non è ancora iniziato.\r\n" );
	else
		ch_printf( ch, "%d turni.\r\n", board->moves );

	if ( board->turn == ch )
		send_to_char( ch, "E' il mio turno.\r\n" );
	else
		ch_printf( ch, "E' il turno di %s.\r\n", board->turn->name );
}
예제 #30
0
/*
 * This function creates all proxy sockets. It should be done very early,
 * typically before privileges are dropped. The sockets will be registered
 * but not added to any fd_set, in order not to loose them across the fork().
 * The proxies also start in IDLE state, meaning that it will be
 * maintain_proxies that will finally complete their loading.
 *
 * Its return value is composed from ERR_NONE, ERR_RETRYABLE and ERR_FATAL.
 * Retryable errors will only be printed if <verbose> is not zero.
 */
int start_proxies(int verbose)
{
	struct proxy *curproxy;
	struct listener *listener;
	int lerr, err = ERR_NONE;
	int pxerr;
	char msg[100];

	for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) {
		if (curproxy->state != PR_STNEW)
			continue; /* already initialized */

		pxerr = 0;
		for (listener = curproxy->listen; listener != NULL; listener = listener->next) {
			if (listener->state != LI_ASSIGNED)
				continue; /* already started */

			lerr = tcp_bind_listener(listener, msg, sizeof(msg));

			/* errors are reported if <verbose> is set or if they are fatal */
			if (verbose || (lerr & (ERR_FATAL | ERR_ABORT))) {
				if (lerr & ERR_ALERT)
					Alert("Starting %s %s: %s\n",
					      proxy_type_str(curproxy), curproxy->id, msg);
				else if (lerr & ERR_WARN)
					Warning("Starting %s %s: %s\n",
						proxy_type_str(curproxy), curproxy->id, msg);
			}

			err |= lerr;
			if (lerr & (ERR_ABORT | ERR_FATAL)) {
				pxerr |= 1;
				break;
			}
			else if (lerr & ERR_CODE) {
				pxerr |= 1;
				continue;
			}
		}

		if (!pxerr) {
			curproxy->state = PR_STIDLE;
			send_log(curproxy, LOG_NOTICE, "Proxy %s started.\n", curproxy->id);
		}

		if (err & ERR_ABORT)
			break;
	}

	return err;
}