Ejemplo n.º 1
0
_export void module_cleanup() {

	struct iterator it = list_iterator(&items);
	item_t *i;
	
	while ((i = iterator_next(&it))) {

		if (!is_blocked(i)) {
			logitem("failed to pick ");
			if (i->amount > 1) logitem("%i ", i->amount);
			if (i->ethereal) logitem("ethereal ");
			if (i->quality != 0x00) logitem("%s ", qualities[i->quality]);
			logitem("%s", lookup_item(i));
			if (i->quality != 0x00) logitem(" (%i)", i->level);
			if (i->sockets > 0) logitem(" [%i]", i->sockets);
			if (setting("Debug")->b_var) logitem(" distance: %i", i->distance); // test pickit
			logitem("\n");
		}

	}

	list_clear(&items);

	gold = 0;

	routine_scheduled = FALSE;
}
Ejemplo n.º 2
0
void reply_to_method_call(DBusMessage* msg, DBusConnection* conn)
{
    DBusMessage* reply;
    DBusMessageIter args;
    dbus_uint32_t serial = 0;
    char* param = "";
    dbus_uint32_t login_perm = 0;

    if (!dbus_message_iter_init(msg, &args))
        log_err("Message has no arguments!"); 
    else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) 
        log_err("Argument is not string!"); 
    else 
        dbus_message_iter_get_basic(&args, &param);

    log("Got request from sshd for user[ %s ]", param);
    reply = dbus_message_new_method_return(msg);
    dbus_message_iter_init_append(reply, &args);
	login_perm = is_blocked(param);
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &login_perm)) { 
        log_err("Out Of Memory!"); 
        exit(1);
    }
    if (!dbus_connection_send(conn, reply, &serial)) {
        log_err("Out Of Memory!"); /* The only reason to Fail */
        exit(1);
    }

    dbus_connection_flush(conn);
    dbus_message_unref(reply);
}
Ejemplo n.º 3
0
//----------- Begin of function UnitB::process_idle----------//
//
// when a unit is idling, if it is block, process block
// if it is in formation but fnot yet reach destination, go there again
//
void UnitB::process_idle()
{
	cur_action = SPRITE_IDLE;
	if(is_blocked() && cur_order.mode != UNIT_ATTACK)
		process_blocked();
	else
	if(/*is_in_formation() && */
		is_blocked() &&
		((next_x_loc() != move_to_loc_x) || (next_y_loc() != move_to_loc_y)) &&
		can_move(move_to_loc_x, move_to_loc_y))

		move_to(move_to_loc_x, move_to_loc_y);
	
	else
		Sprite::process_idle();
}
Ejemplo n.º 4
0
void sig_ctrl_c( struct terminal *term )
{
  if ( is_blocked(  ) )
  {
    return;
  }
}
Ejemplo n.º 5
0
void place_outd_wand_monst(location where,cOutdoors::cWandering group,short forced)
{
	short i = 0,j = 0;
	location l;
				
	
			while (i < 10) {
			////
				if ((univ.party.out_c[i].exists == false) || ((i == 9) && (forced > 0))) {
					if ((sd_legit(group.end_spec1,group.end_spec2) == true) && (PSD[group.end_spec1][group.end_spec2] > 0))
						return;
					univ.party.out_c[i].exists = true;
					univ.party.out_c[i].direction = 0;
					univ.party.out_c[i].what_monst = group;
					univ.party.out_c[i].which_sector = univ.party.i_w_c;
					univ.party.out_c[i].m_loc = where;
				if (univ.party.out_c[i].which_sector.x == 1)
					univ.party.out_c[i].m_loc.x += 48;
				if (univ.party.out_c[i].which_sector.y == 1)
					univ.party.out_c[i].m_loc.y += 48;
				l = univ.party.out_c[i].m_loc;
				while ((forced == true) && (is_blocked(l)) && (j < 50)) {
					l = univ.party.out_c[i].m_loc;
					l.x += get_ran(1,0,2) - 1;
					l.y += get_ran(1,0,2) - 1;
					j++;
					}
				univ.party.out_c[i].m_loc = l;
				
				i = 50;
				}
				i++;
				}

}
Ejemplo n.º 6
0
// Looks at all spaces within 2, looking for a spot which is clear of nastiness and beings
// returns {0,0} if none found
// THIS MAKES NO ADJUSTMENTS FOR BIG MONSTERS!!!
location find_clear_spot(location from_where,short mode)
//mode; // 0 - normal  1 - prefer adjacent space
{
	location loc,store_loc;
	short num_tries = 0,r1;
	
	while (num_tries < 75) {
		num_tries++;
		loc = from_where;
		r1 = get_ran(1,-2,2);
		loc.x = loc.x + r1;
		r1 = get_ran(1,-2,2);
		loc.y = loc.y + r1;
		if ((loc_off_act_area(loc) == false) && (is_blocked(loc) == false)
			&& (can_see(from_where,loc,1) == 0)
			&& (!(is_combat()) || (pc_there(loc) == 6))
			&& (!(is_town()) || (loc != univ.town.p_loc))
			 && (!(univ.town.misc_i(loc.x,loc.y) & 248)) && // check for crate, barrel, barrier, quickfire
			(!(univ.town.explored(loc.x,loc.y) & 254))) { // check for fields, clouds
				if ((mode == 0) || ((mode == 1) && (adjacent(from_where,loc) == true)))
					return loc;
					else store_loc = loc;			
				}
		}
	return store_loc;
}
Ejemplo n.º 7
0
bool User::can_send_message(const UserPtr& to) const {
    return to && self() != to &&
           (admin_rights() ||
            (online_time() >= to->filter_min_online() &&
             Comment::can_create(self(), Comment::PRIVATE_MESSAGE) &&
             !is_blocked(self(), to)));
}
Ejemplo n.º 8
0
static int pthread_rwlock_lock(pthread_rwlock_t *rwlock,
                               bool (*is_blocked)(const pthread_rwlock_t *rwlock),
                               bool is_writer,
                               int incr_when_held,
                               bool allow_spurious)
{
    if (rwlock == NULL) {
        DEBUG("Thread %" PRIkernel_pid": pthread_rwlock_%s(): is_writer=%u, allow_spurious=%u %s\n",
              thread_getpid(), "lock", is_writer, allow_spurious, "rwlock=NULL");
        return EINVAL;
    }

    mutex_lock(&rwlock->mutex);
    if (!is_blocked(rwlock)) {
        DEBUG("Thread %" PRIkernel_pid ": pthread_rwlock_%s(): is_writer=%u, allow_spurious=%u %s\n",
              thread_getpid(), "lock", is_writer, allow_spurious, "is open");
        rwlock->readers += incr_when_held;
    }
    else {
        DEBUG("Thread %" PRIkernel_pid ": pthread_rwlock_%s(): is_writer=%u, allow_spurious=%u %s\n",
              thread_getpid(), "lock", is_writer, allow_spurious, "is locked");

        /* queue for the lock */
        __pthread_rwlock_waiter_node_t waiting_node = {
            .is_writer = is_writer,
            .thread = (thread_t *) sched_active_thread,
            .qnode = {
                .next = NULL,
                .data = (uintptr_t) &waiting_node,
                .priority = sched_active_thread->priority,
            },
            .continue_ = false,
        };
        priority_queue_add(&rwlock->queue, &waiting_node.qnode);

        while (1) {
            /* wait to be unlocked, so this thread can try to acquire the lock again */
            mutex_unlock_and_sleep(&rwlock->mutex);

            mutex_lock(&rwlock->mutex);
            if (waiting_node.continue_) {
                /* pthread_rwlock_unlock() already set rwlock->readers */
                DEBUG("Thread %" PRIkernel_pid ": pthread_rwlock_%s(): is_writer=%u, allow_spurious=%u %s\n",
                      thread_getpid(), "lock", is_writer, allow_spurious, "continued");
                break;
            }
            else if (allow_spurious) {
                DEBUG("Thread %" PRIkernel_pid ": pthread_rwlock_%s(): is_writer=%u, allow_spurious=%u %s\n",
                      thread_getpid(), "lock", is_writer, allow_spurious, "is timed out");
                priority_queue_remove(&rwlock->queue, &waiting_node.qnode);
                mutex_unlock(&rwlock->mutex);
                return ETIMEDOUT;
            }
        }
    }
    mutex_unlock(&rwlock->mutex);

    return 0;
}
Ejemplo n.º 9
0
void erase_screen(struct terminal *term)
{
    if (!term->master || !is_blocked()) {
        if (term->master) want_draw();
        hard_write(term->fdout, "\033[2J\033[1;1H", 10);
        if (term->master) done_draw();
    }
}
Ejemplo n.º 10
0
Archivo: kbd.c Proyecto: Efreak/elinks
static void inline
safe_hard_write(int fd, unsigned char *buf, int len)
{
	if (is_blocked()) return;

	want_draw();
	hard_write(fd, buf, len);
	done_draw();
}
Ejemplo n.º 11
0
void redraw_screen(struct terminal *term)
{
    int x, y, p = 0;
    int cx = term->lcx, cy = term->lcy;
    unsigned char *a;
    int attrib = -1;
    int mode = -1;
    int l = 0;
    struct term_spec *s;
    if (!term->dirty || (term->master && is_blocked())) return;
    a = init_str();
    s = term->spec;
    for (y = 0; y < term->y; y++)
        for (x = 0; x < term->x; x++, p++) {
            if (y == term->y - 1 && x == term->x - 1) break;
            if (term->screen[p] == term->last_screen[p]) continue;
            if ((term->screen[p] & 0x3800) == (term->last_screen[p] & 0x3800) && ((term->screen[p] & 0xff) == 0 || (term->screen[p] & 0xff) == 1 || (term->screen[p] & 0xff) == ' ') && ((term->last_screen[p] & 0xff) == 0 || (term->last_screen[p] & 0xff) == 1 || (term->last_screen[p] & 0xff) == ' ') && (x != term->cx || y != term->cy)) continue;
            term->last_screen[p] = term->screen[p];
            if (cx == x && cy == y) goto pc;/*PRINT_CHAR(p)*/
            else if (cy == y && x - cx < 10 && x - cx > 0) {
                int i;
                for (i = x - cx; i >= 0; i--) PRINT_CHAR(p - i);
            } else {
                add_to_str(&a, &l, "\033[");
                add_num_to_str(&a, &l, y + 1);
                add_to_str(&a, &l, ";");
                add_num_to_str(&a, &l, x + 1);
                add_to_str(&a, &l, "H");
                cx = x;
                cy = y;
pc:
                PRINT_CHAR(p);
            }
        }
    if (l) {
        if (s->col) add_to_str(&a, &l, "\033[37;40m");
        add_to_str(&a, &l, "\033[0m");
        if (s->mode == TERM_LINUX && s->m11_hack) add_to_str(&a, &l, "\033[10m");
        if (s->mode == TERM_VT100) add_to_str(&a, &l, "\x0f");
    }
    term->lcx = cx;
    term->lcy = cy;
    if (term->cx != term->lcx || term->cy != term->lcy) {
        term->lcx = term->cx;
        term->lcy = term->cy;
        add_to_str(&a, &l, "\033[");
        add_num_to_str(&a, &l, term->cy + 1);
        add_to_str(&a, &l, ";");
        add_num_to_str(&a, &l, term->cx + 1);
        add_to_str(&a, &l, "H");
    }
    if (l && term->master) want_draw();
    hard_write(term->fdout, a, l);
    if (l && term->master) done_draw();
    mem_free(a);
    term->dirty = 0;
}
Ejemplo n.º 12
0
bool Board::is_opp_blocked(SpotStatus opp)
{
	bool all_blocked = true;
	for(int i = 0; i < BOARD_SPOT; i++)
	{
		if(spot[i]->status == opp && !is_blocked(spot[i]))
			all_blocked = false;
	}
	return all_blocked;
}
int unlockScreen(void)
{
	if (dsp == NULL)
		return -1;
	if (is_blocked()) {
		write_log_fmt("Unlocking Screen\n");
		XDestroyWindow(dsp, wnd1);
		XCloseDisplay(dsp);
		set_blocked(0);
	}
	return (0);
}
Ejemplo n.º 14
0
void create_wand_monst()
{
	short r1,r2,r3,i = 0,num_tries = 0;
	location p_loc;

	r1 = get_ran(1,0,3);
	if (overall_mode == MODE_OUTDOORS)
		if (!univ.out.outdoors[univ.party.i_w_c.x][univ.party.i_w_c.y].wandering[r1].isNull()) {
			r2 = get_ran(1,0,3);
			while ((point_onscreen(univ.out.outdoors[univ.party.i_w_c.x][univ.party.i_w_c.y].wandering_locs[r2],
					global_to_local(univ.party.p_loc))) && (num_tries++ < 100))
				r2 = get_ran(1,0,3);
			if (!is_blocked(univ.out.outdoors[univ.party.i_w_c.x][univ.party.i_w_c.y].wandering_locs[r2]))
				place_outd_wand_monst(univ.out.outdoors[univ.party.i_w_c.x][univ.party.i_w_c.y].wandering_locs[r2],
					univ.out.outdoors[univ.party.i_w_c.x][univ.party.i_w_c.y].wandering[r1],0);
			}
	else // won't place wandering is more than 50 monsters
		if ((!univ.town->wandering[r1].isNull()) && (univ.town.countMonsters() <= 50)
			&& (univ.party.m_killed[univ.town.num] < univ.town->max_num_monst)) {
			r2 = get_ran(1,0,3);
			while (point_onscreen(univ.town->wandering_locs[r2],univ.town.p_loc) && 
					!loc_off_act_area(univ.town->wandering_locs[r2]) && (num_tries++ < 100))
				r2 = get_ran(1,0,3);
			for (i = 0; i < 4; i++) {
				if (univ.town->wandering[r1].monst[i] != 0) { // place a monster
					p_loc = univ.town->wandering_locs[r2];
					p_loc.x += get_ran(1,0,4) - 2;
					p_loc.y += get_ran(1,0,4) - 2;
					if (!is_blocked(p_loc))
						place_monster(univ.town->wandering[r1].monst[i],p_loc);
				}
				p_loc = univ.town->wandering_locs[r2];
				p_loc.x += get_ran(1,0,4) - 2;
				p_loc.y += get_ran(1,0,4) - 2;
				r3 = get_ran(1,0,3);
				if ((r3 >= 2) && (!is_blocked(p_loc))) // place extra monsters?
					place_monster(univ.town->wandering[r1].monst[3],p_loc);					
				}
		}
}
Ejemplo n.º 15
0
static void visit_coords(map_t *m,int startX, int startY, int x, int y, int dx, int dy,
                         TCOD_list_t active_views, bool light_walls) {
    // top left
    int tlx=x, tly=y+STEP_SIZE;
    // bottom right
    int brx=x+STEP_SIZE, bry=y;
    view_t *view=NULL;
    while (current_view != (view_t **)TCOD_list_end(active_views)) {
        view=*current_view;
        if ( ! BELOW_OR_COLINEAR(&view->steep_line,brx,bry) ) {
            break;
        }
        current_view++;
    }
    if ( current_view == (view_t **)TCOD_list_end(active_views) || ABOVE_OR_COLINEAR(&view->shallow_line,tlx,tly)) {
        // no more active view
        return;
    }
    if ( !is_blocked(m,view,startX,startY,x,y,dx,dy,light_walls) ) return;
    if (  ABOVE(&view->shallow_line,brx,bry)
            && BELOW(&view->steep_line,tlx,tly)) {
        // view blocked
        // slow !
        TCOD_list_remove_iterator(active_views,(void **)current_view);
    } else if ( ABOVE(&view->shallow_line,brx,bry)) {
        // shallow bump
        add_shallow_bump(tlx,tly,view);
        check_view(active_views,current_view);
    } else if (BELOW(&view->steep_line,tlx,tly)) {
        // steep bump
        add_steep_bump(brx,bry,view);
        check_view(active_views,current_view);
    } else {
        // view splitted
        int offset=startX+x*dx/STEP_SIZE + (startY+y*dy/STEP_SIZE)*m->width;
        view_t *shallower_view= & views[offset];
        int view_index=current_view - (view_t **)TCOD_list_begin(active_views);
        view_t **shallower_view_it;
        view_t **steeper_view_it;
        *shallower_view=**current_view;
        // slow !
        shallower_view_it = (view_t **)TCOD_list_insert_before(active_views,shallower_view,view_index);
        steeper_view_it=shallower_view_it+1;
        current_view=shallower_view_it;
        add_steep_bump(brx,bry,shallower_view);
        if (!check_view(active_views,shallower_view_it)) steeper_view_it--;
        add_shallow_bump(tlx,tly,*steeper_view_it);
        check_view(active_views,steeper_view_it);
        if ( view_index > TCOD_list_size(active_views)) current_view=(view_t **)TCOD_list_end(active_views);
    }
}
/** Attempt to write on a connected socket.
 * @param[in] fd File descriptor to write to.
 * @param[in] buf Output buffer to send from.
 * @param[in] length Number of bytes to write.
 * @param[out] count_out Receives number of bytes actually written.
 * @return An IOResult value indicating status.
 */
IOResult os_send_nonb(int fd, const char* buf, unsigned int length, 
                 unsigned int* count_out)
{
  int res;
  assert(0 != buf);
  assert(0 != count_out);

  if (-1 < (res = send(fd, buf, length, 0))) {
    *count_out = (unsigned) res;
    return IO_SUCCESS;
  } else {
    *count_out = 0;
    return is_blocked(errno) ? IO_BLOCKED : IO_FAILURE;
  }
}
Ejemplo n.º 17
0
void		add_neighboors(t_map *map, t_paths **paths)
{
  int		tiles[4][2];
  int		i;

  tiles[0][0] = (*paths)->pos[0] - 1;
  tiles[1][0] = (*paths)->pos[0];
  tiles[2][0] = (*paths)->pos[0] + 1;
  tiles[3][0] = (*paths)->pos[0];
  tiles[0][1] = (*paths)->pos[1];
  tiles[1][1] = (*paths)->pos[1] + 1;
  tiles[2][1] = (*paths)->pos[1];
  tiles[3][1] = (*paths)->pos[1] - 1;
  for (i = 0; i < 4; i++)
    if (!is_blocked(map, tiles[i][0], tiles[i][1], 1))
      add_neighboor(paths, tiles[i][0], tiles[i][1]);
}
Ejemplo n.º 18
0
bool monst_can_be_there(location loc,short m_num) {
	short i,j;
	location destination;
	
	// First clear monst away so it doesn't block itself
	univ.town.monst[m_num].cur_loc.x += 100;
	
	for(i = 0; i < univ.town.monst[m_num].x_width; i++)
		for(j = 0; j < univ.town.monst[m_num].y_width; j++) {
			destination.x = loc.x + i; destination.y = loc.y + j;
			if((is_blocked(destination))
				|| (loc_off_act_area(destination))) {
				univ.town.monst[m_num].cur_loc.x -= 100;
				return false;
			}
		}
	univ.town.monst[m_num].cur_loc.x -= 100;
	return true;
}
/** Attempt to read from a non-blocking socket.
 * @param[in] fd File descriptor to read from.
 * @param[out] buf Output buffer to read into.
 * @param[in] length Number of bytes to read.
 * @param[out] count_out Receives number of bytes actually read.
 * @return An IOResult value indicating status.
 */
IOResult os_recv_nonb(int fd, char* buf, unsigned int length,
                 unsigned int* count_out)
{
  int res;
  assert(0 != buf);
  assert(0 != count_out);

  if (0 < (res = recv(fd, buf, length, 0))) {
    *count_out = (unsigned) res;
    return IO_SUCCESS;
  } else if (res == 0) {
    *count_out = 0;
    errno = 0; /* or ECONNRESET? */
    return IO_FAILURE;
  } else {
    *count_out = 0;
    return is_blocked(errno) ? IO_BLOCKED : IO_FAILURE;
  }
}
/** Attempt to write on a non-blocking UDP socket.
 * @param[in] fd File descriptor to write to.
 * @param[in] buf Output buffer to send from.
 * @param[in] length Number of bytes to write.
 * @param[out] count_out Receives number of bytes actually written.
 * @param[in] flags Flags for call to sendto().
 * @param[in] peer Destination address of the message.
 * @return An IOResult value indicating status.
 */
IOResult os_sendto_nonb(int fd, const char* buf, unsigned int length,
                        unsigned int* count_out, unsigned int flags,
                        const struct irc_sockaddr* peer)
{
  struct sockaddr_native addr;
  int res, size;
  assert(0 != buf);

  size = sockaddr_from_irc(&addr, peer, fd, 0);
  assert((addr.sn_family == AF_INET) == irc_in_addr_is_ipv4(&peer->addr));
  if (-1 < (res = sendto(fd, buf, length, flags, (struct sockaddr*)&addr, size))) {
    if (count_out)
      *count_out = (unsigned) res;
    return IO_SUCCESS;
  } else {
    if (count_out)
      *count_out = 0;
    return is_blocked(errno) ? IO_BLOCKED : IO_FAILURE;
  }
}
Ejemplo n.º 21
0
static int pthread_rwlock_trylock(pthread_rwlock_t *rwlock,
                                  bool (*is_blocked)(const pthread_rwlock_t *rwlock),
                                  int incr_when_held)
{
    if (rwlock == NULL) {
        DEBUG("Thread %" PRIkernel_pid ": pthread_rwlock_%s(): rwlock=NULL supplied\n", thread_getpid(), "trylock");
        return EINVAL;
    }
    else if (mutex_trylock(&rwlock->mutex) == 0) {
        return EBUSY;
    }
    else if (is_blocked(rwlock)) {
        mutex_unlock(&rwlock->mutex);
        return EBUSY;
    }

    rwlock->readers += incr_when_held;

    mutex_unlock(&rwlock->mutex);
    return 0;
}
/** Attempt to read from a non-blocking UDP socket.
 * @param[in] fd File descriptor to read from.
 * @param[out] buf Output buffer to read into.
 * @param[in] length Number of bytes to read.
 * @param[out] length_out Receives number of bytes actually read.
 * @param[out] addr_out Peer address that sent the message.
 * @return An IOResult value indicating status.
 */
IOResult os_recvfrom_nonb(int fd, char* buf, unsigned int length,
                          unsigned int* length_out,
                          struct irc_sockaddr* addr_out)
{
  struct sockaddr_native addr;
  unsigned int len = sizeof(addr);
  int    res;
  assert(0 != buf);
  assert(0 != length_out);
  assert(0 != addr_out);

  res = recvfrom(fd, buf, length, 0, (struct sockaddr*) &addr, &len);
  if (-1 < res) {
    sockaddr_to_irc(&addr, addr_out);
    *length_out = res;
    return IO_SUCCESS;
  } else {
    *length_out = 0;
    return is_blocked(errno) ? IO_BLOCKED : IO_FAILURE;
  }
}
/** Attempt a vectored write on a connected socket.
 * @param[in] fd File descriptor to write to.
 * @param[in] buf Message queue to send from.
 * @param[out] count_in Number of bytes mapped from \a buf.
 * @param[out] count_out Receives number of bytes actually written.
 * @return An IOResult value indicating status.
 */
IOResult os_sendv_nonb(int fd, struct MsgQ* buf, unsigned int* count_in,
		       unsigned int* count_out)
{
  int res;
  int count;
  struct iovec iov[IOV_MAX];

  assert(0 != buf);
  assert(0 != count_in);
  assert(0 != count_out);

  *count_in = 0;
  count = msgq_mapiov(buf, iov, IOV_MAX, count_in);

  if (-1 < (res = writev(fd, iov, count))) {
    *count_out = (unsigned) res;
    return IO_SUCCESS;
  } else {
    *count_out = 0;
    return is_blocked(errno) ? IO_BLOCKED : IO_FAILURE;
  }
}
Ejemplo n.º 24
0
//--------- Begin of function UnitB::move_to ---------//
//
// Move a unit to a specified location
//
// <int>  destXLoc - the x-coordinate of the destination
// <int>  destYLoc - the y-coordinate of the destination
// <bool> raiseDest - default is true, if not want to raise destination, false
// 
void UnitB::move_to(int destXLoc, int destYLoc, bool raiseDest)
{
	// ###### begin Gilbert 22/3 #######//
	// other people may ask this unit to move away while it is dead

	if( hit_points <= 0 || cur_action == SPRITE_DIE )
		return;
	// ###### end Gilbert 22/3 #######//

//	err_when(destXLoc < 0 || destXLoc >= MAX_WORLD_X_LOC || destYLoc < 0 || destYLoc >= MAX_WORLD_Y_LOC);
	destXLoc = min(destXLoc, MAX_WORLD_X_LOC-1);
	destXLoc = max(destXLoc, 0);
	destYLoc = min(destYLoc, MAX_WORLD_Y_LOC-1);
	destYLoc = max(destYLoc, 0);

	stop_move();

	//--- save the destination for later possible retries in searching when it is blocked ----//

	move_to_loc_x = destXLoc;
	move_to_loc_y = destYLoc;

	if((destXLoc == next_x_loc()) && (destYLoc == next_y_loc()))
		return;

	//------- search the path ---------//

//#ifdef DEBUG
//	unsigned long pathFinderStartTime = m.get_time();
//#endif
	path_finder.set_attribute(loc_width, loc_height, mobile_type, 0);

	// ###### begin Gilbert 31/5 #######//
	err_when( cur_order.mode == UNIT_ATTACK && !cast_to_Unit() );
	int stopAtRange = cur_order.mode == UNIT_ATTACK ? cast_to_Unit()->attack_range()-1 : 0;
	// subtract one attack_range so close attack can search near the target
	// and range attack search a little closer
	// ###### end Gilbert 31/5 #######//

	//----- code for handle nation power option -----//

	bool handlePowerNationFlag = false;

	path_finder.set_handle_power_nation(0);

	if( nation_recno )
	{
		Nation *nationPtr = nation_array[nation_recno];

		int srcLocPowerNation  = world.get_loc(next_x_loc(), next_y_loc())->power_nation_recno;
		int destLocPowerNation = world.get_loc(destXLoc, destYLoc)->power_nation_recno;

		//--- only if unit stands on a passable location and the destination is passable, we handle power nation ---//

		if( (!srcLocPowerNation  || nationPtr->get_relation_passable(srcLocPowerNation)) &&
			 (!destLocPowerNation || nationPtr->get_relation_passable(destLocPowerNation)) )
		{
			path_finder.set_handle_power_nation(1, nationPtr->relation_passable_array );
			handlePowerNationFlag = true;
		}
	}

	//--------- find the path now ---------//

	int rangeX1, rangeY1, rangeX2, rangeY2;

	get_object_range(destXLoc, destYLoc, rangeX1, rangeY1, rangeX2, rangeY2);

	// ######## begin Gilbert 31/5 ##########//
	path_finder.find_path(next_x_loc(), next_y_loc(), destXLoc, destYLoc,
								 rangeX1, rangeY1, rangeX2, rangeY2, 1, raiseDest,
								 0, stopAtRange );
	// ######## end Gilbert 31/5 ##########//

	if( path_finder.is_path_found() )
	{
		set_no_longer_blocked();

		seek_path_fail_count=0;		// reset the failure counter
	}
	else	//---- path searching failed ----//
	{
		if(!is_blocked())
			set_not_seriously_blocked();

		//--- if the path search failed, increase the failure counter ---//

//		if( seek_path_fail_count < 100 )		// prevent numeric overflow
//			seek_path_fail_count++;
	}

	//-----------------------------------------//

	int pathNodeCount;
	int totalSteps;			// total number of steps to walk through the whole path.

	if( cur_path )
		mem_del( cur_path );

	cur_path = path_finder.retrieve(pathNodeCount, totalSteps);  // retrieves the path

	// ###### begin Gilbert 11/5 #########//
	if( cur_path )
	{
		cur_path_result_id = pathNodeCount;		// start with the last node
		steps_remaining = totalSteps;
	}
	else
	{
		cur_path_result_id = 0;
		steps_remaining = 0;
	}
	// ###### end Gilbert 11/5 #########//

//#ifdef DEBUG
//	// ######## begin Gilbert 27/4 #######//
//	pathFinderStartTime = m.get_time() - pathFinderStartTime;
//	pathfind_profile_time += pathFinderStartTime;
//	pathfind_count++;
//	if( pathFinderStartTime > longest_pathfind_profile_time )
//	{
//		longest_pathfind_profile_time = pathFinderStartTime;
//		longest_pathfind_unit_recno = sprite_recno;
//	}
//	// ######## begin Gilbert 27/4 #######//
//#endif

	if(!cur_path)
	{
		if(handlePowerNationFlag)
		{
			// ##### begin Gilber 27/4 ########//
//#ifdef DEBUG
			// unsigned long pathFinderStartTime = m.get_time();
			// pathFinderStartTime = m.get_time();
//#endif
			// ##### end Gilber 27/4 ########//
			// ###### begin Gilbert 12/5 ########//
			// path_finder.set_attribute(loc_width, loc_height, mobile_type, PFIND_IGNORE_UNIT );
			// ###### end Gilbert 12/5 ########//
			path_finder.set_handle_power_nation(0);
			handlePowerNationFlag = false;

			// ######## begin Gilbert 31/5 ##########//
			path_finder.find_path(next_x_loc(), next_y_loc(), destXLoc, destYLoc,
								 rangeX1, rangeY1, rangeX2, rangeY2, 1, raiseDest,
								 0, stopAtRange );
			// ######## end Gilbert 31/5 ##########//

			if( path_finder.is_path_found() )
			{
				set_no_longer_blocked();

				seek_path_fail_count=0;		// reset the failure counter
			}
			else	//---- path searching failed ----//
			{
				if(!is_blocked())
					set_not_seriously_blocked();
			}
			if( cur_path )
				mem_del( cur_path );

			cur_path = path_finder.retrieve(pathNodeCount, totalSteps);  // retrieves the path

			// ###### begin Gilbert 11/5 #########//
			if( cur_path )
			{
				cur_path_result_id = pathNodeCount;		// start with the last node
				steps_remaining = totalSteps;
			}
			else
			{
				cur_path_result_id = 0;
				steps_remaining = 0;
			}
			// ###### end Gilbert 11/5 #########//
//#ifdef DEBUG
//			// ######## begin Gilbert 27/4 #######//
//			pathFinderStartTime = m.get_time() - pathFinderStartTime;
//			pathfind_profile_time += pathFinderStartTime;
//			pathfind_count++;
//			if( pathFinderStartTime > longest_pathfind_profile_time )
//			{
//				longest_pathfind_profile_time = pathFinderStartTime;
//				longest_pathfind_unit_recno = sprite_recno;
//			}
//			// ######## begin Gilbert 27/4 #######//
//#endif
			if(!cur_path)
			{
				if(!handle_blocking())
					set_no_longer_blocked();	
				if(seek_path_fail_count <= 100*SEEK_PATH_FAIL_INCREMENT)
					seek_path_fail_count+=SEEK_PATH_FAIL_INCREMENT;		// 10 is the single increment unit. It will be reduce by 1 each time in Unit::attack()
			}
		}
		else
		{
			if(!handle_blocking())
				set_no_longer_blocked();
			if(seek_path_fail_count <= 100*SEEK_PATH_FAIL_INCREMENT)
				seek_path_fail_count+=SEEK_PATH_FAIL_INCREMENT;
		}
	}

	//--------- start the first move ---------//

	if( cur_path && cur_action != SPRITE_MOVE )			// if it is previously moving, don't call next_move() as it has still yet to finish its remaining pixel move to snap to grids
	{
		cur_action = SPRITE_MOVE;
		cur_frame = 1;
		retry_state = 0;
	}
	else
	{
		// ###### begin Gilbert 15/5 #########//
		if( cur_x == next_x && cur_y == next_y )
		{
			wait_count = 0;
			set_wait(); 
		}
		// ###### end Gilbert 15/5 #########//
	}
}
Ejemplo n.º 25
0
Archivo: main.c Proyecto: ebichu/dd-wrt
void sig_ctrl_c(struct terminal *t)
{
	if (!is_blocked()) kbd_ctrl_c();
}
Ejemplo n.º 26
0
/**
Tries to find a (high-level) path from sourcePos in sourcePoly to destPos in destPoly.

@param sourcePos	The source position
@param sourcePoly	The source nav polygon
@param destPos		The destination position
@param destPoly		The destination nav polygon
@param path			Used to return the path (if found) to the caller
@return				true, if a path was found, or false otherwise
*/
bool GlobalPathfinder::find_path(const Vector3d& sourcePos, int sourcePoly,
								 const Vector3d& destPos, int destPoly,
								 std::list<int>& path) const
{
	// Step 1:	If the source position and dest position are both in the same nav polygon,
	//			the high-level path is empty (the entity just needs to go in a straight line).
	if(sourcePoly == destPoly)
	{
		return true;
	}

	// Step 2:	Find the shortest unblocked path-table path from a source navlink to a dest navlink.
	//			If such a path is found, and it's no more than (say) 25% longer than the optimal path
	//			we'd have if we ignored blocks, then use it.
	const std::vector<NavLink_Ptr>& links = m_navMesh->links();
	const std::vector<NavPolygon_Ptr>& polygons = m_navMesh->polygons();
	const std::vector<int>& sourceLinkIndices = polygons[sourcePoly]->out_links();
	const std::vector<int>& destLinkIndices = polygons[destPoly]->in_links();

	// Work out the costs of all the possible paths and get them ready to be processed in ascending order of cost.
	std::priority_queue<PathDescriptor, std::vector<PathDescriptor>, std::greater<PathDescriptor> > pq;
	int sourceLinkCount = static_cast<int>(sourceLinkIndices.size());
	int destLinkCount = static_cast<int>(destLinkIndices.size());
	for(int i=0; i<sourceLinkCount; ++i)
	{
		int sourceLinkIndex = sourceLinkIndices[i];
		const NavLink_Ptr& sourceLink = links[sourceLinkIndex];
		float sourceCost = static_cast<float>(sourcePos.distance(sourceLink->source_position()));

		for(int j=0; j<destLinkCount; ++j)
		{
			// The cost of going from sourcePos to destPos via the shortest path-table path
			// between the two navlinks is the sum of the cost of going to the source navlink,
			// the cost of going from the source navlink to the dest navlink, and the cost of
			// going from the dest navlink to destPos.
			int destLinkIndex = destLinkIndices[j];
			const NavLink_Ptr& destLink = links[destLinkIndex];
			float destCost = static_cast<float>(destPos.distance(destLink->dest_position()));
			float interlinkCost = m_pathTable->cost(sourceLinkIndex, destLinkIndex);
			pq.push(PathDescriptor(sourceCost + interlinkCost + destCost, sourceLinkIndex, destLinkIndex));
		}
	}

	// Starting from the least costly path (if any), construct it and see whether it's blocked or not. If not, use it.
	if(!pq.empty())
	{
		// We accept path-table paths which are no more than 25% longer than the shortest
		// path-table path we found without considering blocks: they are "good enough",
		// and are MUCH quicker to calculate than paths we might find using A*.
		const float WORST_ACCEPTABLE_COST = 1.25f * pq.top().cost;

		while(!pq.empty())
		{
			PathDescriptor desc = pq.top();
			if(desc.cost > WORST_ACCEPTABLE_COST) break;
			pq.pop();

			path = m_pathTable->construct_path(desc.sourceLink, desc.destLink);

			if(!is_blocked(sourcePos, path, destPos))
				return true;	// note that the path to be returned has already been stored in the out parameter
		}
	}

	// Step 3:	If a reasonable unblocked path-table path does not exist, do an A* search on
	//			the adjacency list representation of the navigation graph. Use a temporary node
	//			in both the source and destination polygons to represent the actual position of
	//			the player.
	// TODO

	// Step 4:	If an A* path was found, use it. Otherwise, no valid path exists.
	// TODO

	// NYI
	return false;
}
Ejemplo n.º 27
0
/* computes the minimum a-expansion configuration */
void Match::KZ1_Expand(Coord a)
{
	Coord p, q, d, dq;
	Energy::Var var, qvar;
	int E_old, delta, E00, E0a, Ea0, Eaa;
	int k;

	Energy *e = new Energy(KZ1_error_function);

	/* initializing */
	for (p.y=0; p.y<im_size.y; p.y++)
	for (p.x=0; p.x<im_size.x; p.x++)
	{
		d = Coord(IMREF(x_left, p), IMREF(y_left, p));
		if (a == d) IMREF(node_vars_left, p) = VAR_ACTIVE;
		else
		{
			IMREF(node_vars_left, p) = var = e -> add_variable();
			if (d.x == OCCLUDED) e -> ADD_TERM1(var, KZ1_OCCLUSION_PENALTY, 0);
		}

		d = Coord(IMREF(x_right, p), IMREF(y_right, p));
		if (a == -d) IMREF(node_vars_right, p) = VAR_ACTIVE;
		else
		{
			IMREF(node_vars_right, p) = var = e -> add_variable();
			if (d.x == OCCLUDED) e -> ADD_TERM1(var, KZ1_OCCLUSION_PENALTY, 0);
		}
	}

	for (p.y=0; p.y<im_size.y; p.y++)
	for (p.x=0; p.x<im_size.x; p.x++)
	{
		/* data and visibility terms */
		d = Coord(IMREF(x_left, p), IMREF(y_left, p));
		var = (Energy::Var) IMREF(node_vars_left, p);
		if (d != a && d.x != OCCLUDED)
		{
			q = p + d;
			if (q>=Coord(0,0) && q<im_size)
			{
				qvar = (Energy::Var) IMREF(node_vars_right, q);
				dq = Coord(IMREF(x_right, q), IMREF(y_right, q));
				if (d == -dq)
				{
					delta = (is_blocked(a, d)) ? INFINITY : 0;
					e -> ADD_TERM2(var, qvar, KZ1_data_penalty(p, q), delta, delta, 0);
				}
				else if (is_blocked(a, d))
				{
					e -> ADD_TERM2(var, qvar, 0, INFINITY, 0, 0);
				}
			}
		}

		q = p + a;
		if (q>=Coord(0,0) && q<im_size)
		{
			qvar = (Energy::Var) IMREF(node_vars_right, q);
			dq = Coord(IMREF(x_right, q), IMREF(y_right, q));

			E0a = (is_blocked(d, a)) ? INFINITY : 0;
			Ea0 = (is_blocked(-dq, a)) ? INFINITY : 0;
			Eaa = KZ1_data_penalty(p, q);

			if (var != VAR_ACTIVE)
			{
				if (qvar != VAR_ACTIVE) e -> ADD_TERM2(var, qvar, 0, E0a, Ea0, Eaa);
				else                    e -> ADD_TERM1(var, E0a, Eaa);
			}
			else
			{
				if (qvar != VAR_ACTIVE) e -> ADD_TERM1(qvar, Ea0, Eaa);
				else                    e -> add_constant(Eaa);
			}
		}

		/* left smoothness term */
		for (k=0; k<NEIGHBOR_NUM; k++)
		{
			q = p + NEIGHBORS[k];
			if ( ! ( q>=Coord(0,0) && q<im_size ) ) continue;
			qvar = (Energy::Var) IMREF(node_vars_left, q);
			dq = Coord(IMREF(x_left, q), IMREF(y_left, q));

			if (var != VAR_ACTIVE && qvar != VAR_ACTIVE)
				E00 = KZ1_smoothness_penalty_left(p, q, d, dq);
			if (var != VAR_ACTIVE)
				E0a = KZ1_smoothness_penalty_left(p, q, d, a);
			if (qvar != VAR_ACTIVE)
				Ea0 = KZ1_smoothness_penalty_left(p, q, a, dq);

			if (var != VAR_ACTIVE)
			{
				if (qvar != VAR_ACTIVE) e -> ADD_TERM2(var, qvar, E00, E0a, Ea0, 0);
				else                    e -> ADD_TERM1(var, E0a, 0);
			}
			else
			{
				if (qvar != VAR_ACTIVE) e -> ADD_TERM1(qvar, Ea0, 0);
				else                    {}
			}
		}

		/* right smoothness term */
		d = Coord(IMREF(x_right, p), IMREF(y_right, p));
		var = (Energy::Var) IMREF(node_vars_right, p);
		for (k=0; k<NEIGHBOR_NUM; k++)
		{
			q = p + NEIGHBORS[k];
			if ( ! ( q>=Coord(0,0) && q<im_size ) ) continue;
			qvar = (Energy::Var) IMREF(node_vars_right, q);
			dq = Coord(IMREF(x_right, q), IMREF(y_right, q));

			if (var != VAR_ACTIVE && qvar != VAR_ACTIVE)
				E00 = KZ1_smoothness_penalty_right(p, q, d, dq);
			if (var != VAR_ACTIVE)
				E0a = KZ1_smoothness_penalty_right(p, q, d, -a);
			if (qvar != VAR_ACTIVE)
				Ea0 = KZ1_smoothness_penalty_right(p, q, -a, dq);

			if (var != VAR_ACTIVE)
			{
				if (qvar != VAR_ACTIVE) e -> ADD_TERM2(var, qvar, E00, E0a, Ea0, 0);
				else                    e -> ADD_TERM1(var, E0a, 0);
			}
			else
			{
				if (qvar != VAR_ACTIVE) e -> ADD_TERM1(qvar, Ea0, 0);
				else                    {}
			}
		}

		/* visibility term */
		if (d.x != OCCLUDED && is_blocked(a, -d))
		{
			q = p + d;
			if (q>=Coord(0,0) && q<im_size)
			{
				if (d.x != -IMREF(x_left, q) || d.y != -IMREF(y_left, q))
					e -> ADD_TERM2(var, (Energy::Var) IMREF(node_vars_left, q),
					               0, INFINITY, 0, 0);
			}
		}
	}

	E_old = E;
	E = e -> minimize();

	if (E < E_old)
	{
		for (p.y=0; p.y<im_size.y; p.y++)
		for (p.x=0; p.x<im_size.x; p.x++)
		{
			var = (Energy::Var) IMREF(node_vars_left, p);

			if (var != VAR_ACTIVE && e->get_var(var)==VALUE1)
			{
				IMREF(x_left, p) = a.x; IMREF(y_left, p) = a.y;
			}

			var = (Energy::Var) IMREF(node_vars_right, p);

			if (var != VAR_ACTIVE && e->get_var(var)==VALUE1)
			{
				IMREF(x_right, p) = -a.x; IMREF(y_right, p) = -a.y;
			}
		}
	}

	delete e;
}
int lockScreen(void)
{
	XSetWindowAttributes attr, attr1, attr2;
	Pixmap shape, pic, lock, shp, bg_pic, bg_shp;
	int screen_number = 0;
	long win_mask = CWBackPixel | CWBorderPixel | CWOverrideRedirect;

	if (is_blocked())
		return 0;


	set_blocked(1);

	x = 5;
	y = 35;
	(dsp) = XOpenDisplay(":0.0");

	if ((dsp) == NULL) {
		write_log("Could not open Display 0:0\n");
		return (-1);
	}
	dW = XDisplayWidth(dsp, screen_number);
	dH = XDisplayHeight(dsp, screen_number);
	root = XRootWindow(dsp, screen_number);

	/* If a extern XPM background file specified on the command line */
	if (background_filename != NULL) {
		if (XpmReadFileToPixmap
				(dsp, root, background_filename, &bg_pic, &bg_shp,
				 NULL) != XpmOpenFailed)
			win_mask = CWBackPixmap | CWBorderPixel | CWOverrideRedirect;
	}

	attr.background_pixel = 700;
	attr.background_pixmap = bg_pic;
	attr.border_pixel = 100;
	attr.override_redirect = True;

	(wnd1) = XCreateWindow(dsp, root, 0, 0, dW, dH, 0, CopyFromParent, 
			       CopyFromParent, CopyFromParent, win_mask, &attr);
	XMapRaised(dsp, wnd1);

	if (logo_filename != NULL) {
		XpmReadFileToPixmap(dsp, root, logo_filename, &pic, &shape, NULL);
	}

	attr1.background_pixmap = pic;
	logo = XCreateWindow(dsp, wnd1, dW - 150, 0, 150, 30, 0, 
			CopyFromParent, CopyFromParent,
			CopyFromParent, CWBackPixmap, &attr1);
	XMapWindow(dsp, logo);
	logo2 = XCreateSimpleWindow(dsp, wnd1, 0, 0, dW - 150, 30, 0, 0, 300);
	XMapWindow(dsp, logo2);

	if (foreground_filename != NULL) {
		XpmReadFileToPixmap(dsp, root, foreground_filename, &lock, &shp, NULL);
	}

	attr2.background_pixmap = lock;
	wnd = XCreateWindow(dsp, wnd1, dW / 2 - 150, dH / 2 - 100, 300, 200, 0,
			CopyFromParent, CopyFromParent,
			CopyFromParent, CWBackPixmap, &attr2);
	//wnd = XCreateSimpleWindow(dsp, wnd1, x, y, 200, 200, 1, 0, 400);
	XMapWindow(dsp, wnd);

	XGrabPointer(dsp, wnd1, False,
			ButtonPressMask | ButtonReleaseMask |
			PointerMotionMask, GrabModeAsync, GrabModeAsync, None,
			None, CurrentTime);
	XGrabKeyboard(dsp, wnd1, False, GrabModeAsync, 
			GrabModeAsync, CurrentTime);
	XSelectInput(dsp, wnd1, KeyPressMask | KeyReleaseMask | 
			ButtonPressMask | ButtonReleaseMask | 
			PointerMotionMask | ShiftMask |
			LockMask | ControlMask | Mod1Mask 
			| Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);

	write_log_fmt("locking screen\n");

	return (0);
}
Ejemplo n.º 29
0
/* computes current energy */
int Match::KZ1_ComputeEnergy()
{
	int k;
	Coord p, d, q, dq;

	E = 0;

	for (p.y=0; p.y<im_size.y; p.y++)
	for (p.x=0; p.x<im_size.x; p.x++)
	{
		/* left image and data penalty */
		d = Coord(IMREF(x_left, p), IMREF(y_left, p));

		if (d.x == OCCLUDED) E += KZ1_OCCLUSION_PENALTY;
		else
		{
			q = p + d;
			if (q>=Coord(0,0) && q<im_size)
			{
				dq = Coord(IMREF(x_right, q), IMREF(y_right, q));
				if (d == -dq)
				{
					E += KZ1_data_penalty(p, q);
				}
#ifndef NDEBUG
				/* check visibility constaint */
				if (dq.x != OCCLUDED && is_blocked(-dq, d))
				{
					fprintf(stderr, "KZ1: Visibility constraint is violated!\n");
					exit(1);
				}
#endif
			}
		}

		for (k=0; k<NEIGHBOR_NUM; k++)
		{
			q = p + NEIGHBORS[k];

			if (q>=Coord(0,0) && q<im_size)
			{
				dq = Coord(IMREF(x_left, q), IMREF(y_left, q));
				E += KZ1_smoothness_penalty_left(p, q, d, dq);
			}
		}


		/* right image */
		d = Coord(IMREF(x_right, p), IMREF(y_right, p));

		if (d.x == OCCLUDED) E += KZ1_OCCLUSION_PENALTY;
#ifndef NDEBUG
		else
		{
			/* check visibility constaint */
			q = p + d;
			if (q>=Coord(0,0) && q<im_size)
			{
				dq = Coord(IMREF(x_left, q), IMREF(y_left, q));
				if (dq.x != OCCLUDED && is_blocked(dq, -d))
				{
					fprintf(stderr, "KZ1: Visibility constraint is violated!\n");
					exit(1);
				}
			}
		}
#endif

		for (k=0; k<NEIGHBOR_NUM; k++)
		{
			q = p + NEIGHBORS[k];

			if (q>=Coord(0,0) && q<im_size)
			{
				dq = Coord(IMREF(x_right, q), IMREF(y_right, q));
				E += KZ1_smoothness_penalty_right(p, q, d, dq);
			}
		}
	}

	return E;
}
Ejemplo n.º 30
0
TEST(ban, add)
{
  test_core pr_core;
  cryptonote::t_cryptonote_protocol_handler<test_core> cprotocol(pr_core, NULL);
  Server server(cprotocol);
  cprotocol.set_p2p_endpoint(&server);

  // starts empty
  ASSERT_TRUE(server.get_blocked_hosts().empty());
  ASSERT_FALSE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,4)));
  ASSERT_FALSE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,5)));

  // add an IP
  ASSERT_TRUE(server.block_host(MAKE_IPV4_ADDRESS(1,2,3,4)));
  ASSERT_TRUE(server.get_blocked_hosts().size() == 1);
  ASSERT_TRUE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,4)));
  ASSERT_FALSE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,5)));

  // add the same, should not change
  ASSERT_TRUE(server.block_host(MAKE_IPV4_ADDRESS(1,2,3,4)));
  ASSERT_TRUE(server.get_blocked_hosts().size() == 1);
  ASSERT_TRUE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,4)));
  ASSERT_FALSE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,5)));

  // remove an unblocked IP, should not change
  ASSERT_FALSE(server.unblock_host(MAKE_IPV4_ADDRESS(1,2,3,5)));
  ASSERT_TRUE(server.get_blocked_hosts().size() == 1);
  ASSERT_TRUE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,4)));
  ASSERT_FALSE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,5)));

  // remove the IP, ends up empty
  ASSERT_TRUE(server.unblock_host(MAKE_IPV4_ADDRESS(1,2,3,4)));
  ASSERT_TRUE(server.get_blocked_hosts().size() == 0);
  ASSERT_FALSE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,4)));
  ASSERT_FALSE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,5)));

  // remove the IP from an empty list, still empty
  ASSERT_FALSE(server.unblock_host(MAKE_IPV4_ADDRESS(1,2,3,4)));
  ASSERT_TRUE(server.get_blocked_hosts().size() == 0);
  ASSERT_FALSE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,4)));
  ASSERT_FALSE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,5)));

  // add two for known amounts of time, they're both blocked
  ASSERT_TRUE(server.block_host(MAKE_IPV4_ADDRESS(1,2,3,4), 1));
  ASSERT_TRUE(server.block_host(MAKE_IPV4_ADDRESS(1,2,3,5), 3));
  ASSERT_TRUE(server.get_blocked_hosts().size() == 2);
  ASSERT_TRUE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,4)));
  ASSERT_TRUE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,5)));
  ASSERT_TRUE(server.unblock_host(MAKE_IPV4_ADDRESS(1,2,3,4)));
  ASSERT_TRUE(server.unblock_host(MAKE_IPV4_ADDRESS(1,2,3,5)));

  // these tests would need to call is_remote_ip_allowed, which is private
#if 0
  // after two seconds, the first IP is unblocked, but not the second yet
  sleep(2);
  ASSERT_TRUE(server.get_blocked_hosts().size() == 1);
  ASSERT_FALSE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,4)));
  ASSERT_TRUE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,5)));

  // after two more seconds, the second IP is also unblocked
  sleep(2);
  ASSERT_TRUE(server.get_blocked_hosts().size() == 0);
  ASSERT_FALSE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,4)));
  ASSERT_FALSE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,5)));
#endif

  // add an IP again, then re-ban for longer, then shorter
  time_t t;
  ASSERT_TRUE(server.block_host(MAKE_IPV4_ADDRESS(1,2,3,4), 2));
  ASSERT_TRUE(server.get_blocked_hosts().size() == 1);
  ASSERT_TRUE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,4), &t));
  ASSERT_FALSE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,5)));
  ASSERT_TRUE(t >= 1);
  ASSERT_TRUE(server.block_host(MAKE_IPV4_ADDRESS(1,2,3,4), 9));
  ASSERT_TRUE(server.get_blocked_hosts().size() == 1);
  ASSERT_TRUE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,4), &t));
  ASSERT_FALSE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,5)));
  ASSERT_TRUE(t >= 8);
  ASSERT_TRUE(server.block_host(MAKE_IPV4_ADDRESS(1,2,3,4), 5));
  ASSERT_TRUE(server.get_blocked_hosts().size() == 1);
  ASSERT_TRUE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,4), &t));
  ASSERT_FALSE(is_blocked(server,MAKE_IPV4_ADDRESS(1,2,3,5)));
  ASSERT_TRUE(t >= 4);
}