Ejemplo n.º 1
0
void hh_move(value key1, value key2) {
  unsigned int slot1 = find_slot(key1);
  unsigned int slot2 = find_slot(key2);

  assert(my_pid == master_pid);
  assert(hashtbl[slot1].hash == get_hash(key1));
  assert(hashtbl[slot2].addr == NULL);
  hashtbl[slot2].hash = get_hash(key2);
  hashtbl[slot2].addr = hashtbl[slot1].addr;
  hashtbl[slot1].addr = NULL;
}
Ejemplo n.º 2
0
// gathers discounted reward for a state
void rl_tabulate_reward_value_for_goal( agent *my_agent, Symbol *goal )
{
	rl_data *data = goal->id.rl_info;	
	
	if ( !data->prev_op_rl_rules->empty() )
	{
		slot *s = find_slot( goal->id.reward_header, my_agent->rl_sym_reward );
		slot *t;
		wme *w, *x;
		
		double reward = 0.0;
		double discount_rate = my_agent->rl_params->discount_rate->get_value();

		if ( s )
		{			
			for ( w=s->wmes; w; w=w->next )
			{
				if ( w->value->common.symbol_type == IDENTIFIER_SYMBOL_TYPE )
				{
					t = find_slot( w->value, my_agent->rl_sym_value );
					if ( t )
					{
						for ( x=t->wmes; x; x=x->next )
						{
							if ( ( x->value->common.symbol_type == FLOAT_CONSTANT_SYMBOL_TYPE ) || ( x->value->common.symbol_type == INT_CONSTANT_SYMBOL_TYPE ) )
							{
								reward += get_number_from_symbol( x->value );
							}
						}
					}
				}
			}
			
			// if temporal_discount is off, don't discount for gaps
			unsigned int effective_age = data->hrl_age;
			if (my_agent->rl_params->temporal_discount->get_value() == soar_module::on) {
				effective_age += data->gap_age;
			}

			data->reward += ( reward * pow( discount_rate, static_cast< double >( effective_age ) ) );
		}

		// update stats
		double global_reward = my_agent->rl_stats->global_reward->get_value();
		my_agent->rl_stats->total_reward->set_value( reward );
		my_agent->rl_stats->global_reward->set_value( global_reward + reward );

		if ( ( goal != my_agent->bottom_goal ) && ( my_agent->rl_params->hrl_discount->get_value() == soar_module::on ) )
		{
			data->hrl_age++;
		}
	}
}
Ejemplo n.º 3
0
void hh_remove(value key) {
  unsigned int slot = find_slot(key);

  assert(my_pid == master_pid);
  assert(hashtbl[slot].hash == get_hash(key));
  hashtbl[slot].addr = NULL;
}
Ejemplo n.º 4
0
void
NSR_HandleBadSource(IPAddr *address)
{
  static struct timeval last_replacement;
  struct timeval now;
  NTP_Remote_Address remote_addr;
  SourceRecord *record;
  int slot, found;
  double diff;

  remote_addr.ip_addr = *address;
  remote_addr.port = 0;

  find_slot(&remote_addr, &slot, &found);
  if (!found)
    return;

  record = get_record(slot);

  /* Only sources with a name can be replaced */
  if (!record->name)
    return;

  /* Don't resolve names too frequently */
  SCH_GetLastEventTime(NULL, NULL, &now);
  UTI_DiffTimevalsToDouble(&diff, &now, &last_replacement);
  if (fabs(diff) < RESOLVE_INTERVAL_UNIT * (1 << MIN_REPLACEMENT_INTERVAL)) {
    DEBUG_LOG(LOGF_NtpSources, "replacement postponed");
    return;
  }
  last_replacement = now;

  resolve_source_replacement(record);
}
Ejemplo n.º 5
0
int find_slot(CK_BBOOL with_token, CK_SLOT_ID_PTR slot) {
	CK_RV rv;
	CK_ULONG count = 0;
	CK_SLOT_ID_PTR list = NULL;

	ckrv_mod m[] = { CKR_BUFFER_TOO_SMALL, TEST_RV_OK };
	check_rv_long(C_GetSlotList(with_token, NULL_PTR, &count), m);
	printf("slots %sfound: %lu\n", with_token ? "with token " : "", count);
	if(count == 0 && with_token) {
		if(have_robot()) {
			robot_insert_card();
			return find_slot(with_token, slot);
		}
		printf("Need at least one token to run this test\n");
		return TEST_RV_SKIP;
	}

	do {
		list = (CK_SLOT_ID_PTR)realloc(list, sizeof(CK_SLOT_ID) * count);
	} while((rv = C_GetSlotList(with_token, list, &count) == CKR_BUFFER_TOO_SMALL));
	check_rv_late("C_GetSlotList");

	if(count > 1) {
		printf("INFO: multiple slots found, using slot %lu\n", list[0]);
	}

	*slot = list[0];
	free(list);

	return TEST_RV_OK;
}
Ejemplo n.º 6
0
oop slotsMap::copy_add_argument_slot(slotsOop obj,
                                     stringOop name, 
                                     slotType type,
                                     oop contents,
                                     oop anno,
                                     bool mustAllocate) {
  assert_smi(contents, "arg data must be position");

  if (!name->is_unary())
    return ErrorCodes::vmString_prim_error(ARGUMENTCOUNTERROR);

  slotDesc* old = find_slot(name);
  slotsOop result;
  if (old == NULL)
    result= obj;
  else if (old->is_arg_slot()) {
    // No need to remove and reinsert because order is the same.
    // Only the annotation might be really different.
    // The index will be off by one (assumes that added slot is new)
    assert(smiOop(contents)->value() == smiOop(old->data)->value() + 1,
           "arg index wrong");
    return change_slot(obj, old, type, old->data, anno, mustAllocate);
  } else {
    result= (slotsOop)copy_remove_slot(obj, name, mustAllocate);
    if (oop(result) == failedAllocationOop || result->is_mark()) return result;
    assert(result->is_slots(), "just checking");
  }
  assert(smiOop(contents)->value() == arg_count(), "arg index wrong");
  return ((slotsMap*)result->map())->copy_add_new_slot(result, 
                                                       name, 
                                                       type, 
                                                       contents,
                                                       anno,
                                                       mustAllocate);
}
Ejemplo n.º 7
0
static void
rehash_records(void)
{
  SourceRecord *temp_records;
  unsigned int i, old_size, new_size;
  int slot, found;

  old_size = ARR_GetSize(records);

  temp_records = MallocArray(SourceRecord, old_size);
  memcpy(temp_records, ARR_GetElements(records), old_size * sizeof (SourceRecord));

  /* The size of the hash table is always a power of two */
  for (new_size = 1; !check_hashtable_size(n_sources, new_size); new_size *= 2)
    ;

  ARR_SetSize(records, new_size);

  for (i = 0; i < new_size; i++)
    get_record(i)->remote_addr = NULL;

  for (i = 0; i < old_size; i++) {
    if (!temp_records[i].remote_addr)
      continue;

    find_slot(temp_records[i].remote_addr, &slot, &found);
    assert(!found);

    *get_record(slot) = temp_records[i];
  }

  Free(temp_records);
}
Ejemplo n.º 8
0
/*
 * release the midi device if it was registered
 */
int
snd_seq_oss_midi_check_exit_port(int client, int port)
{
	struct seq_oss_midi *mdev;
	unsigned long flags;
	int index;

	if ((mdev = find_slot(client, port)) != NULL) {
		spin_lock_irqsave(&register_lock, flags);
		midi_devs[mdev->seq_device] = NULL;
		spin_unlock_irqrestore(&register_lock, flags);
		snd_use_lock_free(&mdev->use_lock);
		snd_use_lock_sync(&mdev->use_lock);
		snd_midi_event_free(mdev->coder);
		kfree(mdev);
	}
	spin_lock_irqsave(&register_lock, flags);
	for (index = max_midi_devs - 1; index >= 0; index--) {
		if (midi_devs[index])
			break;
	}
	max_midi_devs = index + 1;
	spin_unlock_irqrestore(&register_lock, flags);
	return 0;
}
Ejemplo n.º 9
0
/*==========================================
 * delete_xref_if_present -- If record is listed
 *  as free, remove it from the free list
 *========================================*/
BOOLEAN
delete_xref_if_present (CNSTRING key)
{
	DELETESET set=0;
	INT keynum=0;
	INT lo=0;
	INT i=0;

	ASSERT(key);
	ASSERT(key[0]);
	ASSERT(key[1]);
	set = get_deleteset_from_type(key[0]);
	keynum = atoi(key + 1);
	ASSERT(keynum>0);
	lo = find_slot(keynum, set);
	if (!(lo < set->n && (set->recs)[lo] == keynum))
		return FALSE;
	/* removing xrefs[lo] -- move lo+ down */
	for (i=lo; i+1<set->n-1; ++i)
		(set->recs)[i] = (set->recs)[i+1];
	/* zero out the entry slipping off the top of the list */
	if (set->n > 1)
		set->recs[set->n - 1] = 0;
	--(set->n);
	ASSERT(writexrefs());
	maxkeynum=-1;
	return TRUE;

}
Ejemplo n.º 10
0
int sampgdk_timer_set(long interval, bool repeat,
                      sampgdk_timer_callback callback, void *param) {
  struct sampgdk_timer timer;
  int slot;
  int error;

  assert(callback != NULL);

  timer.is_set   = true;
  timer.interval = interval;
  timer.repeat   = repeat;
  timer.callback = callback;
  timer.param    = param;
  timer.started  = sampgdk_timer_clock();
  timer.plugin   = sampgdk_plugin_address_to_handle(callback);

  slot = find_slot();
  if (slot >= 0) {
    sampgdk_array_set(&timers, slot, &timer);
  } else {
    error = sampgdk_array_append(&timers, &timer);
    if (error < 0) {
      return -error;
    }
    slot = timers.count - 1;
  }

  /* Timer IDs returned by the SA:MP's SetTimer() API begin
   * with 1, and so do they here.
   */
  return slot + 1;
}
Ejemplo n.º 11
0
oop slotsMap::copy_add_data_slot(slotsOop obj,
                                 stringOop name, 
                                 slotType type,
                                 oop contents,
                                 oop anno,
                                 bool mustAllocate) {
  if (!name->is_unary()) {
    return ErrorCodes::vmString_prim_error(SLOTNAMEERROR);
  }

  slotDesc* old = find_slot(name);
  
  if (!old)
    return copy_add_new_slot(obj, name, type, contents, anno, mustAllocate);

  if (old->is_obj_slot())
    // change in place; if type is map_slot, just changes value
    return (slotsOop)change_slot(obj, old, OBJ_SLOT(type), contents, anno,
                                 mustAllocate);

  // remove then add obj slot
  slotsOop result= copy_remove_one_slot(obj, old, mustAllocate);
  if (oop(result) == failedAllocationOop) return result;
  slotsMap *new_map= (slotsMap*)result->map();
  
  return new_map->copy_add_new_slot(result, name, type, contents,
                                    anno, mustAllocate);
}
Ejemplo n.º 12
0
/**
 * do_identify
 * @brief  Main processor for the drslot_chrp_pci -i command
 *
 * Validate the user input,  a slot name. Call the routine which actually
 * does the call to set the LED. When we're done identifying, reset the
 * LED based on whether or not there's an OF node representing an adapter
 * connected to the slot.  If an adapter node exists, turn the LED on,
 * else turn if off.
 */
static int
do_identify(struct options *opts, struct dr_node *all_nodes)
{
	struct dr_node *node;
	int usr_key;
	int led_state;

	node = find_slot(opts->usr_drc_name, all_nodes);
	if (node == NULL)
		return -1;

	usr_key = identify_slot(node);

	/* when we're done with identify, put the LED back
	 * where we think it ought to be. ON if an adapter is
	 * connected, OFF if not
	 */
	if (node->children == NULL)
		led_state = LED_OFF;
	else
		led_state = LED_ON;

	if (process_led(node, led_state))
		return -1;

	if (usr_key == USER_QUIT)
		return -1;

	return 0;	/* don't return anything on identify */
}
Ejemplo n.º 13
0
/*
 * lengthen:
 *	Increase the time until a fuse goes off
 */
void
lengthen(void (*func)(), int xtime)
{
    struct delayed_action *wire;

    if ((wire = find_slot(func)) == NULL)
	return;
    wire->d_time += xtime;
}
Ejemplo n.º 14
0
static fopen_function res_get_fopen(rloader_t *self, const char *protocol)
{
    unsigned int i =
        find_slot(self->protocols, self->f_next, self->f_max, protocol);
    if (i < self->f_next)
        return self->functions[i];
    else
        return NULL;
}
Ejemplo n.º 15
0
/*
 * extinguish:
 *	Put out a fuse
 */
void
extinguish(void (*func)())
{
    struct delayed_action *wire;

    if ((wire = find_slot(func)) == NULL)
	return;
    wire->d_type = EMPTY;
}
Ejemplo n.º 16
0
void Board_write_message(int board_type, struct char_data * ch, char *arg)
{
  char *tmstr;
  int len;
  time_t ct;
  char buf[MAX_INPUT_LENGTH], buf2[MAX_INPUT_LENGTH];

  if (WRITE_LVL(board_type) != 0 && !COM_FLAGGED(ch, WRITE_LVL(board_type))) {
    send_to_char("You are not holy enough to write on this board.\r\n", ch);
    return;
  }
  if (num_of_msgs[board_type] >= MAX_BOARD_MESSAGES) {
    send_to_char("The board is full.\r\n", ch);
    return;
  }
  if ((NEW_MSG_INDEX(board_type).slot_num = find_slot()) == -1) {
    send_to_char("The board is malfunctioning - sorry.\r\n", ch);
    stderr_log("SYSERR: Board: failed to find empty slot on write.");
    return;
  }
  /* skip blanks */
  skip_spaces(&arg);
  delete_doubledollar(arg);

  if (!*arg) {
    send_to_char("We must have a headline!\r\n", ch);
    return;
  }
  ct = time(0);
  tmstr = (char *) asctime(localtime(&ct));
  *(tmstr + strlen(tmstr) - 1) = '\0';

  sprintf(buf2, "(%s)", GET_NAME(ch));
  sprintf(buf, "%6.10s %-12s :: %s", tmstr, buf2, arg);
  len = strlen(buf) + 1;
  if (!(NEW_MSG_INDEX(board_type).heading = (char *) malloc(sizeof(char) * len))) {
    send_to_char("The board is malfunctioning - sorry.\r\n", ch);
    return;
  }
  strcpy(NEW_MSG_INDEX(board_type).heading, buf);
  NEW_MSG_INDEX(board_type).heading[len - 1] = '\0';
  NEW_MSG_INDEX(board_type).level = GET_LEVEL(ch);
  sprintf(logbuffer, "%s writing new message (%s) on board in #%d", GET_NAME(ch), buf, world[ch->in_room].number);
  mudlog(logbuffer, 'B', COM_ADMIN, FALSE);
  send_to_char("Write your message. (/s saves /h for help)\r\n\r\n", ch);
  act("$n starts to write a message.", TRUE, ch, 0, 0, TO_ROOM);

  if (!IS_NPC(ch))
    SET_BIT(PLR_FLAGS(ch), PLR_WRITING);

  ch->desc->str = &(msg_storage[NEW_MSG_INDEX(board_type).slot_num]);
  ch->desc->max_str = MAX_MESSAGE_LENGTH;
  ch->desc->mail_to = (char*) board_type + BOARD_MAGIC;

  num_of_msgs[board_type]++;
}
Ejemplo n.º 17
0
static int install_variables(const char *esp_path,
                             uint32_t part, uint64_t pstart, uint64_t psize,
                             sd_id128_t uuid, const char *path,
                             bool first) {
        char *p = NULL;
        uint16_t *options = NULL;
        uint16_t slot;
        int r;

        if (!is_efi_boot()) {
                fprintf(stderr, "Not booted with EFI, skipping EFI variable setup.\n");
                return 0;
        }

        if (asprintf(&p, "%s%s", esp_path, path) < 0) {
                fprintf(stderr, "Out of memory.\n");
                return -ENOMEM;
        }

        if (access(p, F_OK) < 0) {
                if (errno == ENOENT)
                        r = 0;
                else
                        r = -errno;
                goto finish;
        }

        r = find_slot(uuid, path, &slot);
        if (r < 0) {
                if (r == -ENOENT)
                        fprintf(stderr, "Failed to access EFI variables. Is the \"efivarfs\" filesystem mounted?\n");
                else
                        fprintf(stderr, "Failed to determine current boot order: %s\n", strerror(-r));
                goto finish;
        }

        if (first || r == false) {
                r = efi_add_boot_option(slot, "Linux Boot Manager",
                                        part, pstart, psize,
                                        uuid, path);
                if (r < 0) {
                        fprintf(stderr, "Failed to create EFI Boot variable entry: %s\n", strerror(-r));
                        goto finish;
                }
                fprintf(stderr, "Created EFI boot entry \"Linux Boot Manager\".\n");
        }

        insert_into_order(slot, first);

finish:
        free(p);
        free(options);
        return r;
}
Ejemplo n.º 18
0
/*
 * kill_daemon:
 *	Remove a daemon from the list
 */
void
kill_daemon(void (*func)())
{
    struct delayed_action *dev;

    if ((dev = find_slot(func)) == NULL)
	return;
    /*
     * Take it out of the list
     */
    dev->d_type = EMPTY;
}
Ejemplo n.º 19
0
CAMLprim value hh_get(value key) {
  CAMLparam1(key);
  CAMLlocal1(result);

  unsigned int slot = find_slot(key);
  assert(hashtbl[slot].hash == get_hash(key));
  size_t size = *(size_t*)(hashtbl[slot].addr - sizeof(size_t));
  result = caml_alloc_string(size);
  memcpy(String_val(result), hashtbl[slot].addr, size);

  CAMLreturn(result);
}
Ejemplo n.º 20
0
void movepassenger(struct floorQ* f)
{
	int slot = find_slot();
	//if -1, then something went terribly wrong
	if(slot!=-1)
	{
		elevator.rq[slot] = f->dest;
		elevator.pt[slot] = f->type;
	}
	elevator.curweight+=findweight(f->type);
	elevator.curload+=1;
}
Ejemplo n.º 21
0
void Board_write_message(int board_type, struct char_data *ch, char *arg)
{
    char buf[200], buf2[200];
    char *tmstr;
    int ct, len;

    if (GET_LEVEL(ch) < WRITE_LVL(board_type)) {
	send_to_char("You are not advanced enough to write on this board.\n\r", ch);
	return;
    }

   if (num_of_msgs[board_type] >= MAX_BOARD_MESSAGES) {
	send_to_char("The board is full.\n\r", ch);
	return;
   }

   if ((NEW_MSG_INDEX(board_type).slot_num = find_slot()) == -1) {
	send_to_char("The board is malfunctioning - sorry.\n\r", ch);
	log("Board: failed to find empty slot on write.");
	return;
   }

   /* skip blanks */
   /* RT removed for(; isspace(*arg); arg++); */
   if (!*arg) {
     send_to_char("We must have a headline!\n\r", ch);
     return;
   }

   ct = time(0);
   tmstr = (char *) asctime(localtime(&ct));
   *(tmstr + strlen(tmstr) - 1) = '\0';

   sprintf(buf2, "(%s)", GET_NAME(ch));
   sprintf(buf, "%6.10s %-12s :: %s", tmstr, buf2, arg);
   len = strlen(buf) + 1;
   if (!(NEW_MSG_INDEX(board_type).heading = (char *)malloc(sizeof(char)*len))) {
		send_to_char("The board is malfunctioning - sorry.\n\r", ch);
		return;
   }
   strcpy(NEW_MSG_INDEX(board_type).heading, buf);
   NEW_MSG_INDEX(board_type).heading[len-1] = '\0';
   NEW_MSG_INDEX(board_type).level = GET_LEVEL(ch);

   send_to_char("Write your message.  Terminate with a @.\n\r\n\r", ch);
   act("$n starts to write a message.", TRUE, ch, 0, 0, TO_ROOM);
 
   ch->desc->str = &(msg_storage[NEW_MSG_INDEX(board_type).slot_num]);
   ch->desc->max_str = MAX_MESSAGE_LENGTH;
   
   num_of_msgs[board_type]++;
}
Ejemplo n.º 22
0
void Board_load_board(int board_type)
{
   FILE *fl;
   int i, len1 = 0, len2 = 0;
   char *tmp1 = 0, *tmp2 = 0;


   if (!(fl = fopen(FILENAME(board_type), "rb"))) {
	perror("Error reading board");
	return;
   }

  fread(&(num_of_msgs[board_type]), sizeof(int), 1, fl);
  if (num_of_msgs[board_type] < 1 || num_of_msgs[board_type] > MAX_BOARD_MESSAGES) {
	log("Board file corrupt.  Resetting.");
	Board_reset_board(board_type);
	return;
  }

  for (i = 0; i < num_of_msgs[board_type]; i++) {
	fread(&(msg_index[board_type][i]),sizeof(struct board_msginfo),1,fl);
	if (!(len1 = msg_index[board_type][i].heading_len)) {
		log("Board file corrupt!  Resetting.");
		Board_reset_board(board_type);
		return;
	}

	if (!(tmp1 = (char *)malloc(sizeof(char) * len1))) {
		log("Error - malloc failed for board header");
		exit(1);
	}

	fread(tmp1, sizeof(char), len1, fl);
	MSG_HEADING(board_type, i) = tmp1;

	if ((len2 = msg_index[board_type][i].message_len)) {
		if ((MSG_SLOTNUM(board_type, i) = find_slot()) == -1) {
			log("Out of slots booting board!  Resetting..");
			Board_reset_board(board_type);
			return;
		}
		if (!(tmp2 = (char *)malloc(sizeof(char) * len2))) {
			log("Error - malloc failed for board text");
			exit(1);
		}
		fread(tmp2, sizeof(char), len2, fl);
		msg_storage[MSG_SLOTNUM(board_type, i)] = tmp2;
	}
   }

   fclose(fl);
}
Ejemplo n.º 23
0
/* Procedure to add a new source */
static NSR_Status
add_source(NTP_Remote_Address *remote_addr, char *name, NTP_Source_Type type, SourceParameters *params, int pool)
{
  SourceRecord *record;
  int slot, found;

  assert(initialised);

  /* Find empty bin & check that we don't have the address already */
  find_slot(remote_addr, &slot, &found);
  if (found) {
    return NSR_AlreadyInUse;
  } else {
    if (remote_addr->ip_addr.family != IPADDR_INET4 &&
               remote_addr->ip_addr.family != IPADDR_INET6) {
      return NSR_InvalidAF;
    } else {
      n_sources++;

      if (!check_hashtable_size(n_sources, ARR_GetSize(records))) {
        rehash_records();
        find_slot(remote_addr, &slot, &found);
      }

      assert(!found);
      record = get_record(slot);
      record->data = NCR_GetInstance(remote_addr, type, params);
      record->remote_addr = NCR_GetRemoteAddress(record->data);
      record->name = name ? Strdup(name) : NULL;
      record->pool = pool;
      record->tentative = 1;

      if (auto_start_sources)
        NCR_StartInstance(record->data);

      return NSR_Success;
    }
  }
}
Ejemplo n.º 24
0
value hh_mem(value key) {
  unsigned int slot = find_slot(key);
  if(hashtbl[slot].hash == get_hash(key) &&
     hashtbl[slot].addr != NULL) {
    // The data is currently in the process of being written, wait until it
    // actually is ready to be used before returning.
    while (hashtbl[slot].addr == (char*)1) {
      asm volatile("pause" : : : "memory");
    }
    return Val_bool(1);
  }
  return Val_bool(0);
}
Ejemplo n.º 25
0
/*
 * extinguish:
 *	Put out a fuse
 */
void
extinguish(void (*func)())
{
	reg struct delayed_action *wire;

	if ((wire = find_slot(func)) == NULL)
		return;
	wire->d_type = EMPTY;
	wire->d_func = NULL;
	wire->d_arg = 0;
	wire->d_time = 0;
	fusecnt -= 1;
}
Ejemplo n.º 26
0
static void sell(int n)
{
   int   slot;

// Um welche waffe handelt es sich denn nun ?
   n = wmark[n];

// Where's the weapon positioned we want to sell.
   slot = weapons.weapon[n]->slot;

// S E L L.
   switch (w[n].type) {

// Try to sell a LIFE.
   case WT_LIFE:
      if (player[nowplayer].ships <= 1) return;
      player[nowplayer].ships--;
      shop_display();
      break;

// All other WEAPONS.
   default:
      if (w[n].you_own == 0) return;   // You don't own any -> nothing to do.
// If this weapon is part of a power up chain: Go back to weaker option.
      if (w[n].prev != -1) {
         n = w[n].prev;
         player[nowplayer].slot[slot] = n;
         shop_savepos();
         weapon_removeall(nowplayer);
         weapon_releaseall(nowplayer, wx, wy);
         shop_filter();
         shop_display();
      } else {
/// Find a slot which holds the weapon player wants to sell.
         slot = find_slot(slot, n);
         if ((slot != -1) && (weapons.weapon[n]->type != WT_SHIP)) {
// Add some money to player's account.
            player[nowplayer].slot[slot] = -1;
            shop_savepos();
            weapon_removeall(nowplayer);
            weapon_releaseall(nowplayer, wx, wy);
            shop_filter();
            shop_display();
         }
      }
   }
// Add some money to player's account.
   player[nowplayer].money += w[n].price;
   your_money(player[nowplayer].money);
}
Ejemplo n.º 27
0
static NSR_Status
replace_source(NTP_Remote_Address *old_addr, NTP_Remote_Address *new_addr)
{
  int slot1, slot2, found;
  SourceRecord *record;
  struct SourcePool *pool;

  find_slot(old_addr, &slot1, &found);
  if (!found)
    return NSR_NoSuchSource;

  find_slot(new_addr, &slot2, &found);
  if (found)
    return NSR_AlreadyInUse;

  record = get_record(slot1);
  NCR_ChangeRemoteAddress(record->data, new_addr);
  record->remote_addr = NCR_GetRemoteAddress(record->data);

  if (!record->tentative) {
    record->tentative = 1;

    if (record->pool != INVALID_POOL) {
      pool = ARR_GetElement(pools, record->pool);
      pool->sources--;
    }
  }

  /* The hash table must be rebuilt for the new address */
  rehash_records();

  LOG(LOGS_INFO, LOGF_NtpSources, "Source %s replaced with %s",
      UTI_IPToString(&old_addr->ip_addr),
      UTI_IPToString(&new_addr->ip_addr));

  return NSR_Success;
}
Ejemplo n.º 28
0
int Board_write_message(int board_type, struct char_data *ch, char *arg, struct obj_data *board)
{
  (void)board;
  char *tmstr;
  time_t ct;
  char buf[MAX_INPUT_LENGTH], buf2[MAX_NAME_LENGTH + 3];

  if (GET_LEVEL(ch) < WRITE_LVL(board_type)) {
    send_to_char(ch, "You are not holy enough to write on this board.\r\n");
    return (1);
  }
  if (num_of_msgs[board_type] >= MAX_BOARD_MESSAGES) {
    send_to_char(ch, "The board is full.\r\n");
    return (1);
  }
  if ((NEW_MSG_INDEX(board_type).slot_num = find_slot()) == -1) {
    send_to_char(ch, "The board is malfunctioning - sorry.\r\n");
    log("SYSERR: Board: failed to find empty slot on write.");
    return (1);
  }
  /* skip blanks */
  skip_spaces(&arg);
  delete_doubledollar(arg);

  /* JE 27 Oct 95 - Truncate headline at 80 chars if it's longer than that */
  arg[80] = '\0';

  if (!*arg) {
    send_to_char(ch, "We must have a headline!\r\n");
    return (1);
  }
  ct = time(0);
  tmstr = (char *) asctime(localtime(&ct));
  *(tmstr + strlen(tmstr) - 1) = '\0';

  snprintf(buf2, sizeof(buf2), "(%s)", GET_NAME(ch));
  snprintf(buf, sizeof(buf), "%6.10s %-12s :: %s", tmstr, buf2, arg);
  NEW_MSG_INDEX(board_type).heading = strdup(buf);
  NEW_MSG_INDEX(board_type).level = GET_LEVEL(ch);

  send_to_char(ch, "Write your message.  Terminate with a @ on a new line.\r\n\r\n");
  act("$n starts to write a message.", TRUE, ch, 0, 0, CommTarget::TO_ROOM);

  string_write(ch->desc, &(msg_storage[NEW_MSG_INDEX(board_type).slot_num]),
		MAX_MESSAGE_LENGTH, board_type + BOARD_MAGIC, NULL);

  num_of_msgs[board_type]++;
  return (1);
}
Ejemplo n.º 29
0
uint32_t
NSR_GetLocalRefid(IPAddr *address)
{
  NTP_Remote_Address remote_addr;
  int slot, found;

  remote_addr.ip_addr = *address;
  remote_addr.port = 0;

  find_slot(&remote_addr, &slot, &found);
  if (!found)
    return 0;

  return NCR_GetLocalRefid(get_record(slot)->data);
}
Ejemplo n.º 30
0
static void res_set_fopen(struct rloader_t *self, const char *protocol,
                          const fopen_function f)
{
    unsigned int i =
        find_slot(self->protocols, self->f_next, self->f_max, protocol);
    if (i >= self->f_max)
        WARNING1(__FILE__ ": reached static limit in set_fopen.");
    else {
        if (i == self->f_next)
            self->f_next++;

        self->protocols[i] = strdup(protocol);
        self->functions[i] = f;
    }
}