Exemple #1
0
void			broadcast(t_env *e, t_bot *bot, char *msg)
{
	t_iterator		iter_t;
	t_iterator		iter_b;
	t_team			*t;
	t_bot			*b;
	char			buf[128];

	bot->action_timer = BROADCAST_TIME;
	iter_t = NULL;
	while ((t = (t_team *)ft_lst_iter_next_content(e->team, &iter_t)))
	{
		iter_b = NULL;
		while ((b = (t_bot *)ft_lst_iter_next_content(t->connected, &iter_b)))
		{
			if (b != bot)
			{
				b->action_timer = BROADCAST_TIME;
				sprintf(buf, "message %d,%s\n", get_sound_dir(e, b, bot), msg);
				buf_load(b->buf_action, buf);
			}
		}
	}
	buf_load(bot->buf_action, "ok\n");
}
Exemple #2
0
void NexuizCreditsList_configureNexuizCreditsList(entity me)
{
	me.configureNexuizListBox(me);
	// load the file
	me.bufferIndex = buf_load("nexuiz-credits.txt");
	me.nItems = buf_getsize(me.bufferIndex);
}
Exemple #3
0
void			pfk(t_env *e, int fd, t_bot *bot)
{
	char			buf[BUF_SIZE];

	sprintf(buf, "pfk #%d\n", bot->id);
	buf_load(e->fds[fd].buf_write, buf);
}
Exemple #4
0
void			fork_egg(t_env *e, t_bot *bot)
{
	bot->action_timer = FORK_TIME;
	bot->status = STATUS_FORK;
	notify_all_gfx_pfk(e, bot);
	buf_load(bot->buf_action, "ok\n");
}
Exemple #5
0
static void		dead(t_env *e, t_bot *bot)
{
	if (bot->parent == NULL)
		printf("BOT #%d is dead\n", bot->id);
	else
		printf("EGG #%d is dead\n", bot->id);
	buf_load(e->fds[bot->fd].buf_write, "mort\n");
}
Exemple #6
0
workout_t *
workout_read(char *filename)
{
    workout_t *w = NULL;
    BUF *buf;

    buf = buf_load(filename);
    if (buf) {
        w = workout_read_buf(buf);
        buf_free(buf);
    } else {
        log_info("workout_read: load error");
    }

    return w;
}
Exemple #7
0
void			plv(t_env *e, int fd, char **req, t_bot *b)
{
	char			buf[BUF_SIZE];
	t_bot			*bot;

	if (req != NULL)
	{
		if ((bot = get_bot_by_id_arg(e, fd, req)) == NULL)
			return ;
	}
	else
		bot = b;
	sprintf(buf, "plv #%d %d\n",
		bot->id,
		bot->level);
	buf_load(e->fds[fd].buf_write, buf);
}
Exemple #8
0
void			take(t_env *e, t_bot *bot, char *obj_name)
{
	int				sq;
	t_obj			*obj;
	int				type;

	bot->action_timer = TAKE_TIME;
	if ((type = get_obj_type(obj_name)) == -1)
		return (error(bot, "Invalid object"));
	if ((obj = get_obj(e, bot->sq, type)) == NULL)
		return (error(bot, "Object not found"));
	if (type == OBJ_FOOD)
	{
		bot->life_unit += FOOD_UNIT;
		sq = sq_rand(e);
		ft_lst_pushend(e->board[sq].obj, obj_new(OBJ_FOOD));
		notify_all_gfx_bct(e, sq);
	}
	else
		ft_lst_pushend(bot->inventory, obj);
	printf("BOT #%d take %s\n", bot->id, obj_name);
	notify_all_gfx_take(e, bot, type);
	buf_load(bot->buf_action, "ok\n");
}
Exemple #9
0
Fichier : put.c Projet : kube/zappy
void			put(t_env *e, t_bot *bot, char *obj_name)
{
	t_iterator		iter;
	t_obj			*obj;
	int				type;

	bot->action_timer = PUT_TIME;
	if ((type = get_obj_type(obj_name)) == -1)
		return (error(bot, "Invalid object"));
	iter = NULL;
	while ((obj = (t_obj *)ft_lst_iter_next_content(bot->inventory, &iter)))
	{
		if (obj->type == type)
		{
			ft_lst_del_atom(bot->inventory, iter, NULL);
			ft_lst_pushend(e->board[bot->sq].obj, obj);
			printf("BOT #%d put %s\n", bot->id, obj_name);
			notify_all_gfx_put(e, bot, type);
			buf_load(bot->buf_action, "ok\n");
			return ;
		}
	}
	return (error(bot, "Object not found"));
}
Exemple #10
0
static int
rcsdiff_file(RCSFILE *file, RCSNUM *rev, const char *filename, int dflags)
{
	int ret, fd;
	time_t t;
	struct stat st;
	char *path1, *path2;
	BUF *b1, *b2;
	char rbuf[RCS_REV_BUFSZ];
	struct tm *tb;
	struct timeval tv[2], tv2[2];

	memset(&tv, 0, sizeof(tv));
	memset(&tv2, 0, sizeof(tv2));

	ret = D_ERROR;
	b1 = b2 = NULL;

	diff_rev1 = rev;
	diff_rev2 = NULL;
	path1 = path2 = NULL;

	if ((fd = open(filename, O_RDONLY)) == -1) {
		warn("%s", filename);
		goto out;
	}

	rcsnum_tostr(rev, rbuf, sizeof(rbuf));
	if (!quiet) {
		fprintf(stderr, "retrieving revision %s\n", rbuf);
		fprintf(stderr, "%s -r%s %s\n", diffargs, rbuf, filename);
	}

	if ((b1 = rcs_getrev(file, rev)) == NULL) {
		warnx("failed to retrieve revision %s", rbuf);
		goto out;
	}

	b1 = rcs_kwexp_buf(b1, file, rev);
	tv[0].tv_sec = (long)rcs_rev_getdate(file, rev);
	tv[1].tv_sec = tv[0].tv_sec;

	if ((b2 = buf_load(filename)) == NULL) {
		warnx("failed to load file: `%s'", filename);
		goto out;
	}

	/* XXX - GNU uses GMT */
	if (fstat(fd, &st) == -1)
		err(D_ERROR, "%s", filename);

	tb = gmtime(&st.st_mtime);
	t = mktime(tb);

	tv2[0].tv_sec = t;
	tv2[1].tv_sec = t;

	(void)xasprintf(&path1, "%s/diff1.XXXXXXXXXX", rcs_tmpdir);
	buf_write_stmp(b1, path1);

	buf_free(b1);
	b1 = NULL;

	if (utimes(path1, (const struct timeval *)&tv) < 0)
		warn("utimes");

	(void)xasprintf(&path2, "%s/diff2.XXXXXXXXXX", rcs_tmpdir);
	buf_write_stmp(b2, path2);

	buf_free(b2);
	b2 = NULL;

	if (utimes(path2, (const struct timeval *)&tv2) < 0)
		warn("utimes");

	ret = diffreg(path1, path2, NULL, dflags);

out:
	if (fd != -1)
		(void)close(fd);
	if (b1 != NULL)
		buf_free(b1);
	if (b2 != NULL)
		buf_free(b2);
	if (path1 != NULL)
		xfree(path1);
	if (path2 != NULL)
		xfree(path2);

	return (ret);
}
Exemple #11
0
int
main(int argc,
     char *argv[])
{
    int i, rc, nerr = 0, e;
    char *to, *msg, *cp;
    BUFFER buf;
#if HAVE_DOORS
    struct door_info dib;
#endif
    
    for (i = 1; i < argc && argv[i][0] == '-'; i++)
	switch (argv[i][1])
	{
	  case 'V':
	    p_header();
	    exit(0);
	    
	  case 'm':
	    ++mailmode;
	    break;
	    
	  case 'd':
	    ++debug;
	    break;

#if HAVE_DOORS
	  case 'D':
	    door_path = strdup(argv[i]+2);
	    break;
#endif
	    
	  case 'F':
	    fifo_path = strdup(argv[i]+2);
	    break;
	    
	  case '-':
	    goto EndOptions;

	  case 'h':
	    usage(stdout, argv[0]);
	    exit(0);
	    
	  default:
	    fprintf(stderr, "%s: unknown switch: %s\n", argv[0], argv[i]);
	    exit(1);
	}

  EndOptions:
    if (i >= argc)
    {
	fprintf(stderr, "%s: Missing recipient of message\n", argv[0]);
	exit(1);
    }

#if HAVE_DOORS
    door_fd = open(door_path, O_RDONLY);
    if (door_fd < 0)
    {
	e = errno;
	if (errno != ENOENT) {
	    syslog(LOG_ERR, "%s: open: %s\n", door_path, strerror(e));
	    fprintf(stderr, "%s: open(%s): %s\n", argv[0], door_path, strerror(e));
	    exit(1);
	}
    }

    if (door_fd > 0) {
	if (door_info(door_fd, &dib) < 0)
	{
	    e = errno;
	    syslog(LOG_ERR, "%s: door_info: %s\n", door_path, strerror(e));
	    fprintf(stderr, "%s: %s: door_info: %s\n", argv[0], door_path, strerror(e));
	    exit(1);
	}
	
	if (debug)
	{
	    printf("door_info() -> server pid = %ld, uniquifier = %ld",
		   (long) dib.di_target,
		   (long) dib.di_uniquifier);
	    
	    if (dib.di_attributes & DOOR_LOCAL)
		printf(", LOCAL");
	    if (dib.di_attributes & DOOR_PRIVATE)
		printf(", PRIVATE");
	    if (dib.di_attributes & DOOR_REVOKED)
		printf(", REVOKED");
	    if (dib.di_attributes & DOOR_UNREF)
		printf(", UNREF");
	    putchar('\n');
	}
	
	if (dib.di_attributes & DOOR_REVOKED)
	{
	    syslog(LOG_ERR, "%s: door revoked\n", door_path);
	    fprintf(stderr, "%s: door revoked\n", argv[0]);
	    exit(1);
	}
    }
#endif

    if (isatty(fileno(stdin)))
	puts("Enter message:");
    
    buf_init(&buf);
    buf_load(&buf, stdin);

    msg = buf_getall(&buf);
    if (mailmode)
    {
	while (*msg && !((msg[0] == '\n' && msg[1] == '\n') ||
			 (msg[0] == '\r' && msg[1] == '\n' &&
			  msg[2] == '\r' && msg[3] == '\n')))
	    ++msg;
	
	switch (*msg)
	{
	  case '\r':
	    msg += 4;
	    break;
	    
	  case '\n':
	    msg += 2;
	}
    }

    while (i < argc)
    {
	to = s_dup(argv[i]);
	if (!to) {
	    fprintf(stderr, "%s: %s: s_dup: %s\n", argv[0], argv[i], strerror(errno));
	    exit(1);
	}
	    
	cp = strchr(to, '@');
	if (cp)
	    *cp = '\0';
	
	rc = send_sms(to, msg);
	if (rc != 0)
	{
	    ++nerr;
	    e = errno;
	    syslog(LOG_ERR, "%s: send failed (door_path=%s, rc=%d): %s", argv[i], door_path, strerror(e));
	    fprintf(stderr, "%s: %s: send failed (rc=%d): %s\n", argv[0], argv[i], rc, strerror(e));
	}
	
	++i;
    }
    
    exit(nerr);
}
Exemple #12
0
static void
rcsclean_file(char *fname, const char *rev_str)
{
	int fd, match;
	RCSFILE *file;
	char fpath[PATH_MAX], numb[RCS_REV_BUFSZ];
	RCSNUM *rev;
	BUF *b1, *b2;
	time_t rcs_mtime = -1;

	b1 = b2 = NULL;
	file = NULL;
	rev = NULL;

	if ((fd = rcs_choosefile(fname, fpath, sizeof(fpath))) < 0)
		goto out;

	if ((file = rcs_open(fpath, fd, RCS_RDWR)) == NULL)
		goto out;

	if (flags & PRESERVETIME)
		rcs_mtime = rcs_get_mtime(file);

	rcs_kwexp_set(file, kflag);

	if (rev_str == NULL)
		rev = file->rf_head;
	else if ((rev = rcs_getrevnum(rev_str, file)) == NULL) {
		warnx("%s: Symbolic name `%s' is undefined.", fpath, rev_str);
		goto out;
	}

	if ((b1 = rcs_getrev(file, rev)) == NULL) {
		warnx("failed to get needed revision");
		goto out;
	}
	if ((b2 = buf_load(fname)) == NULL) {
		warnx("failed to load `%s'", fname);
		goto out;
	}

	/* If buffer lengths are the same, compare contents as well. */
	if (buf_len(b1) != buf_len(b2))
		match = 0;
	else {
		size_t len, n;

		len = buf_len(b1);

		match = 1;
		for (n = 0; n < len; ++n)
			if (buf_getc(b1, n) != buf_getc(b2, n)) {
				match = 0;
				break;
			}
	}

	if (match == 1) {
		if (uflag == 1 && !TAILQ_EMPTY(&(file->rf_locks))) {
			if (!(flags & QUIET) && nflag == 0) {
				printf("rcs -u%s %s\n",
				    rcsnum_tostr(rev, numb, sizeof(numb)),
				    fpath);
			}
			(void)rcs_lock_remove(file, locker, rev);
		}

		if (TAILQ_EMPTY(&(file->rf_locks))) {
			if (!(flags & QUIET))
				printf("rm -f %s\n", fname);

			if (nflag == 0)
				(void)unlink(fname);
		}
	}

	rcs_write(file);
	if (flags & PRESERVETIME)
		rcs_set_mtime(file, rcs_mtime);

out:
	if (b1 != NULL)
		buf_free(b1);
	if (b2 != NULL)
		buf_free(b2);
	if (file != NULL)
		rcs_close(file);
}
Exemple #13
0
static void		error(t_bot *bot, char *msg)
{
	printf("Client #%d (BOT): %s\n", bot->fd, msg);
	buf_load(bot->buf_action, "ko\n");
}