Example #1
0
int
v_makeloc(struct command *c)
{
  int n;
  int sk;
  int kind;

  sk = lookup(subkind_s, c->parse[1]);

  if (sk < 0) {
    wout(c->who, "Unknown subkind.");
    return FALSE;
  }

  if (sk == sub_galley || sk == sub_roundship)
    kind = T_ship;
  else
    kind = T_loc;

  n = new_ent(kind, sk);

  if (n < 0) {
    wout(c->who, "Out of boxes.");
    return FALSE;
  }

  set_where(n, subloc(c->who));

  wout(c->who, "Created %s", box_name(n));

  if (sk == sub_temple)
    ilist_append(&p_subloc(n)->teaches, sk_religion);

  return TRUE;
}
Example #2
0
void configuration::sanity_check_values()
{
	if(conf[MAX_UDP_SIZE] > UINT16_MAX || conf[MAX_UDP_SIZE] < 512) {
		wout() << "Invalid max UDP bufsize (" << conf[MAX_UDP_SIZE] << "), reverting to default (65535)";
		assign_value(MAX_UDP_SIZE, UINT16_MAX);
	}
	if(conf[MAX_CLIENT_UDP_RESPONSE] > UINT16_MAX || conf[MAX_CLIENT_UDP_RESPONSE] < 512) {
		wout() << "Invalid max client UDP response size (" << conf[MAX_CLIENT_UDP_RESPONSE] << "), reverting to default value (8192)";
		assign_value(MAX_CLIENT_UDP_RESPONSE, 8192);
	}
	if(conf[QUERY_RETRY_MS] > 5000 || conf[QUERY_RETRY_MS] < 10) {
		wout() << "Invalid query retry timeout (" << conf[QUERY_RETRY_MS] << " ms), reverting to default (500 ms)";
		assign_value(QUERY_RETRY_MS, 500);
	}
	if(conf[DNS_PORT] > UINT16_MAX || conf[DNS_PORT] == 0) {
		wout() << "Invalid DNS port (" << conf[DNS_PORT] << "), reverting to default port (53)";
		assign_value(DNS_PORT, 53);
	}
	if(conf[SNOW_NAMESERV_PORT] > UINT16_MAX || conf[SNOW_NAMESERV_PORT] == 0) {
		wout() << "Invalid snow nameserv port (" << conf[SNOW_NAMESERV_PORT] << "), reverting to default port (8)";
		assign_value(SNOW_NAMESERV_PORT, 8);
	}
	if(conf[MAX_TTL] > 604800)
		assign_value(MAX_TTL, 604800);
	if(conf[DEFAULT_STATIC_TTL] > conf[MAX_TTL])
		assign_value(DEFAULT_STATIC_TTL, conf[MAX_TTL]);
	if(conf[CACHE_SIZE] < 1024)
		assign_value(CACHE_SIZE, 1024);
	if(conf[CACHE_SIZE] > 1024*1024*1024)
		assign_value(CACHE_SIZE, 1024*1024*1024);
}
static int
keep_undead_check(struct command *c, int check_bond)
{
	int target = c->a;

	if (kind(target) != T_char || subkind(target) != sub_demon_lord)
	{
	    wout(c->who, "%s is not a demon lord.", box_code(target));
	    return FALSE;
	}

	if (subloc(target) != subloc(c->who))
	{
		wout(c->who, "%s is not here.", box_code(target));
		return FALSE;
	}

	if (check_bond && loyal_kind(target) != LOY_summon)
	{
		wout(c->who, "%s is no longer bonded.", box_code(target));
		return FALSE;
	}

	return TRUE;
}
Example #4
0
int
d_adv_med(struct command *c)
{
  struct char_magic *p;
  int chance;
  int m_a;
  int bonus;

  chance = hinder_med_chance(c->who);

  p = p_magic(c->who);
  p->hinder_meditation = 0;
  m_a = max_eff_aura(c->who);

  bonus = max(2, max_eff_aura(c->who) / 10);

  if (rnd(1, 100) <= chance) {
    wout(c->who, "Disturbing images and unquiet thoughts "
         "hamper the meditative trance.");
    bonus = 1;
  }

  p->cur_aura += bonus;

  if (p->cur_aura >= max_eff_aura(c->who) + 2)
    p->cur_aura = max_eff_aura(c->who) + 2;

  wout(c->who, "Current aura is now %d.", p->cur_aura);
  return TRUE;
}
int
d_adv_med(struct command *c)
{
  struct char_magic *p;
  int chance;
  int m_a;

  if (subkind(subloc(c->who)) != sub_tower ||
      !alone_here(c->who)) {
    wout(c->who, "You must be alone in a tower to use Advanced Meditation.");
    return FALSE;
  };
    
  if (c->wait != 0) return TRUE;

  chance = hinder_med_chance(c->who);

  p = p_magic(c->who);
  p->hinder_meditation = 0;
  m_a = max_eff_aura(c->who);

  if (rnd(1, 100) <= chance) {
    wout(c->who, "Disturbing images and unquiet thoughts "
	 "hamper the meditative trance!");
    return FALSE;
  };

  p->max_aura++;
  wout(c->who, "Maximum aura is now %d.", p->max_aura);
  return TRUE;
}
int
v_reveal_mage(struct command *c)
{
	int target = c->a;
	int category = c->b;
	int aura;

	if (c->c < 1)
		c->c = 1;
	aura = c->c;

	if (!cast_check_char_here(c->who, target))
		return FALSE;

	if (!check_aura(c->who, aura))
		return FALSE;

	if (!category || !magic_skill(category) ||
	    skill_school(category) != category)
	{
		wout(c->who, "%s is not a magical skill category.",
					box_code(category));
		wout(c->who , "Assuming %s.", box_name(sk_basic));

		c->b = sk_basic;
		category = sk_basic;
	}

	wout(c->who, "Attempt to scry the magical abilities of %s within %s.",
				box_name(target), box_name(category));

	return TRUE;
}
void
hinder_med_omen(int who, int other)
{

  if (rnd(1,100) < 50) return;

	switch (rnd(1,3))
	{
	case 1:
		wout(who, "A disturbing image of %s appeared last "
				"night in a dream.", box_name(other));
		break;

	case 2:
		wout(who, "As a cloud drifts across the moon, it seems "
			"for an instant that it takes the shape of a "
			"ghoulish face, looking straight at you.");
		break;

	case 3:
		wout(who, "You are shocked out of your slumber in the "
			"middle of the night by cold fingers touching your "
			"neck, but when you glance about, there is no one "
			"to be seen.");
		break;

	default:
		assert(FALSE);
	}
}
int
d_dispel_abil(struct command *c)
{
	int target = c->a;
	struct char_magic *p;

	p = rp_magic(target);

	if (p && p->ability_shroud > 0)
	{
		if (!charge_aura(c->who, 3))
			return FALSE;

		wout(c->who, "Dispeled an aura %s ability shroud from %s.",
						nice_num(p->ability_shroud),
						box_name(target));
		p->ability_shroud = 0;
		wout(target, "The magical ability shroud has dissipated.");
	}
	else
	{
		wout(c->who, "%s had no ability shroud.", box_name(target));
	}

	return TRUE;
}
Example #9
0
int
d_meditate(struct command *c)
{
  struct char_magic *p;
  int chance;
  int bonus;

  chance = hinder_med_chance(c->who);

  p = p_magic(c->who);
  p->hinder_meditation = 0;

  if (rnd(1, 100) <= chance) {
    wout(c->who, "Disturbing images and unquiet thoughts "
         "ruin the meditative trance.  Meditation fails.");
    return FALSE;
  }

  bonus = max(1, max_eff_aura(c->who) / 20);

  p->cur_aura += bonus;

  if (p->cur_aura >= max_eff_aura(c->who) + 1)
    p->cur_aura = max_eff_aura(c->who) + 1;

  wout(c->who, "Current aura is now %d.", p->cur_aura);
  return TRUE;
}
int
v_view_aura(struct command *c)
{
	int aura;
	int where;

	if (c->a < 1)
		c->a = 1;
	aura = c->a;

	if (!check_aura(c->who, aura))
		return FALSE;

	if (crosses_ocean(cast_where(c->who),c->who)) {
	  wout(c->who,"Something seems to block your magic.");
	  return FALSE;
	};

	where = reset_cast_where(c->who);
	c->d = where;

	wout(c->who, "Will scry the current aura ratings of other "
		"mages in %s.", box_name(where));

	return TRUE;
}
Example #11
0
int
v_scry_region(struct command *c)
{
  int targ_loc = c->a;
  int aura = c->b;

  if (!is_loc_or_ship(targ_loc)) {
    wout(c->who, "%s is not a location.", box_code(targ_loc));
    return FALSE;
  }

  if (crosses_ocean(targ_loc, c->who)) {
    wout(c->who, "Something seems to block your magic.");
    return FALSE;
  };

  if (c->b < 1)
    c->b = 1;
  aura = c->b;

  if (!check_aura(c->who, aura))
    return FALSE;

  return TRUE;
}
Example #12
0
void
alert_scry_attempt(int who, int where, char *t)
{
  int n;
  int has_detect;
  char *source;

  loop_char_here(where, n) {
    has_detect = has_skill(n, sk_detect_scry);

    if (has_detect > exp_novice)
      source = box_name(who);
    else
      source = "Someone";

    if (has_detect)
      wout(n, "%s%s cast %s on this location.",
           source, t, box_name(sk_scry_region));

    if (has_detect >= exp_master)
      wout(n, "%s is in %s.", box_name(who), char_rep_location(who));
/*
 *  If another exp gradient is wanted, use box_name for the loc,
 *  then graduate to char_rep_location, since the latter gives
 *  more info
 */

  }
int
d_bird_spy(struct command *c)
{
	int targ = c->d;

	if (!has_holy_symbol(c->who)) {
	  wout(c->who, "A holy symbol is required to bird spy.");
	  return FALSE;
	};

	if (!use_piety(c->who, skill_piety(c->use_skill))) {
	  wout(c->who, "You don't have the piety required to use that prayer.");
	  return FALSE;
	};

	if (!is_loc_or_ship(targ))
	{
		wout(c->who, "%s is not a location.", box_code(targ));
		return FALSE;
	}

	wout(c->who, "The bird returns with a report:");
	out(c->who, "");
	show_loc(c->who, targ);

	return TRUE;
}
Example #14
0
void configuration::sanity_check_values()
{
	if(conf[DTLS_BIND_PORT] == 0 || conf[DTLS_OUTGOING_PORT] == 0) {
		// use random but persistent ports for these
		std::ofstream conffile(conf[CONFIG_FILE], std::ios_base::out | std::ios_base::binary | std::ios_base::app);
		if(conf[DTLS_BIND_PORT] == 0) {
			uint16_t port = ntohs(get_random_port());
			iout() << "Assigned DTLS_BIND_PORT random port " << port;
			conffile << "\nDTLS_BIND_PORT=" << port << '\n';
			assign_value(DTLS_BIND_PORT, port);
		}
		if(conf[DTLS_OUTGOING_PORT] == 0) {
			uint16_t port = ntohs(get_random_port());
			iout() << "Assigned DTLS_OUTGOING_PORT random port " << port;
			conffile << "\nDTLS_OUTGOING_PORT=" << port << '\n';
			assign_value(DTLS_OUTGOING_PORT, port);
		}
	}
	if(conf[DTLS_BIND_PORT] == conf[DTLS_OUTGOING_PORT] || conf[DTLS_BIND6_PORT] == conf[DTLS_OUTGOING_PORT]) {
		eout() << "DTLS_BIND_PORT or DTLS_OUTGOING_PORT not initialized to separate valid ports, these should have been set to random ports during installation."
			<< " You must set DTLS_BIND_PORT and DTLS_OUTGOING_PORT to separate port numbers in the snow configuration file."
			   << " If you have more than one device try to choose different ports for each device.";
		abort();
	}
	check_port(conf[DTLS_OUTGOING_PORT], "DTLS_OUTGOING_PORT");
	check_port(conf[DTLS_BIND_PORT], "DTLS_BIND_PORT");
	check_port(conf[DTLS_BIND6_PORT], "DTLS_BIND6_PORT");
	check_port(conf[DHT_PORT], "DHT_PORT");
	check_port(conf[NAMESERV_PORT], "NAMESERV_PORT");
	check_nonzero(conf[NAMESERV_TIMEOUT_SECS], "NAMESERV_TIMEOUT_SECS");
	check_nonzero(conf[DTLS_IDLE_TIMEOUT_SECS], "DTLS_IDLE_TIMEOUT_SECS");
	check_nonzero(conf[HEARTBEAT_SECONDS], "HEARTBEAT_SECONDS");
	check_nonzero(conf[HEARTBEAT_RETRIES], "HEARTBEAT_RETRIES");
	if(conf[NAT_IP_GRACE_PERIOD_SECONDS] < 1800) {
		wout() << "NAT IP grace period of " << conf[NAT_IP_GRACE_PERIOD_SECONDS] << " from configuration file is too short, using minimum grace period of 1800 seconds";
		assign_value(NAT_IP_GRACE_PERIOD_SECONDS, 1800);
	}
	if(conf[DHT_BOOTSTRAP_TARGET]==0) {
		wout() << "DHT_BOOTSTRAP_TARGET cannot be zero, using default value";
		assign_value(DHT_BOOTSTRAP_TARGET, 6);
	}
	if(conf[DHT_MAX_PEERS] <= 3) {
		wout() << "DHT_MAX_PEERS cannot be " << conf[DHT_MAX_PEERS] << ", must be at least 4, using default value of 99";
		assign_value(DHT_MAX_PEERS, 99);
	}
	if(conf[NATPOOL_NETMASK_BITS] > 20 || conf[NATPOOL_NETMASK_BITS] < 4) {
		eout() << "NATPOOL_NETMASK_BITS must be between 4 and 20";
		abort();
	}
	uint32_t addr, netmask = ~htonl((1 << (32 - conf[NATPOOL_NETMASK_BITS])) - 1);
	if(inet_pton(AF_INET, conf[NATPOOL_NETWORK].c_str(), &addr) != 1 || (addr & ~netmask) != 0) {
		eout() << "NATPOOL_NETWORK/NATPOOL_NETMASK_BITS as " << conf[NATPOOL_NETWORK] << "/" << conf[NATPOOL_NETMASK_BITS] << " is not a valid subnet.";
		abort();
	}
	if(conf[VIRTUAL_INTERFACE_MTU] > 65535 || conf[VIRTUAL_INTERFACE_MTU] < 576) {
		eout() << "VIRTUAL_INTERFACE_MTU cannot be " << conf[VIRTUAL_INTERFACE_MTU];
		abort();
	}
}
Example #15
0
int
d_undead_lord(struct command *c)
{
  int where = subloc(c->who);
  int aura = c->a;
  int undead;
  int rating;

  if (!may_cookie_npc(c->who, where, item_undead_cookie))
    return FALSE;

  if (!charge_aura(c->who, aura))
    return FALSE;

  undead = do_cookie_npc(c->who, where, item_undead_cookie, c->who);

  if (undead == 0) {
    log_write(LOG_CODE, "d_undead_lord: why not?");
    wout(c->who, "Unable to summon a demon lord.");
    return FALSE;
  }

  switch (aura) {
  case 3:
    rating = 100;
    break;
  case 4:
    rating = 150;
    break;
  case 5:
    rating = 190;
    break;
  case 6:
    rating = 220;
    break;
  case 7:
    rating = 240;
    break;
  case 8:
    rating = 250;
    break;

  default:
    assert(FALSE);
  }

  p_char(undead)->attack = rating;
  p_char(undead)->defense = rating;

  set_loyal(undead, LOY_summon, 5);

  wout(c->who, "Summoned %s.", box_name(undead));
  wout(where, "%s has summoned %s.", box_name(c->who), liner_desc(undead));

  return TRUE;
}
Example #16
0
int
d_heal(struct command *c)
{
  int target = c->a;
  int aura = c->b;
  int chance;

  if (kind(target) != T_char) {
    wout(c->who, "%s is no longer a character.", box_code(target));
    return FALSE;
  }

  if (!char_sick(target)) {
    wout(c->who, "%s is not sick.", box_name(target));
    return FALSE;
  }

  if (!charge_aura(c->who, aura))
    return FALSE;

  switch (aura) {
  case 1:
    chance = 30;
    break;

  case 2:
    chance = 15;
    break;

  case 3:
    chance = 5;
    break;

  default:
    assert(FALSE);
  }

  vector_clear();
  vector_add(c->who);
  vector_add(target);

  wout(VECT, "%s casts Heal on %s:", box_name(c->who), box_name(target));

  if (rnd(1, 100) <= chance) {
    wout(VECT, "Spell fails.");
    return FALSE;
  }

  p_char(target)->sick = FALSE;

  wout(VECT, "%s has been cured, and should now recover.", box_name(target));

  return TRUE;
}
int
v_adv_med(struct command *c)
{
  if (subkind(subloc(c->who)) != sub_tower ||
      !alone_here(c->who)) {
    wout(c->who, "You must be alone in a tower to use Advanced Meditation.");
    return FALSE;
  };
    
  wout(c->who, "Advanced meditation for %s.", weeks(c->wait));
  return TRUE;
}
Example #18
0
int
v_credit(struct command *c)
{
  int target = c->a;
  int amount = c->b;
  int item = c->c;
  int pl;
  extern int gold_times;

  if (amount) {
    if (kind(target) != T_char && kind(target) != T_player) {
      wout(c->who, "%s not a character or player.", c->parse[1]);
      return FALSE;
    }

    if (numargs(c) >= 3 && i_strcmp(c->parse[3], "np") == 0) {
      if (kind(target) != T_player) {
        wout(c->who, "%s not a player.", box_code(target));
        return FALSE;
      }

      add_np(target, amount);
      wout(c->who, "Credited %s %d NP.", box_name(target), amount);
      wout(target, "Received GM credit of %d NP.", amount);
      return TRUE;
    }

    if (item == 0)
      item = 1;

    gen_item(target, item, amount);
    wout(c->who, "Credited %s %s.", box_name(target),
         box_name_qty(item, amount));
    wout(target, "Received CLAIM credit of %s.", box_name_qty(item, amount));
    return TRUE;
  }

  if (kind(target) != T_char) {
    wout(c->who, "%s not a character.", c->parse[1]);
    return FALSE;
  }

  pl = player(target);

  if (times_paid(pl)) {
    wout(c->who, "Already paid faction %s.", box_name(pl));
    return FALSE;
  }

  p_player(pl)->times_paid = TRUE;

  wout(target, "The Times pays %s %s.", box_name(target), gold_s(25));

  gen_item(target, item_gold, 25);
  gold_times += 25;

  return TRUE;
}
int
d_meditate(struct command *c)
{
	struct char_magic *p;
	int chance;

	if (!char_alone(c->who)) {
	  wout(c->who, "You cannot meditate unless completely alone.");
	  return FALSE;
	};

	if (char_cur_aura(c->who) >= max_eff_aura(c->who))
	{
		wout(c->who, "Current aura is already %d.  It may not "
			"be increased further via meditation.",
					char_cur_aura(c->who));
		return FALSE;
	}

	if (c->wait != 0) return TRUE;

	chance = hinder_med_chance(c->who);

	p = p_magic(c->who);
	p->hinder_meditation = 0;

	if (rnd(1, 100) <= chance)
	{
		wout(c->who, "Disturbing images and unquiet thoughts "
			"ruin the meditative trance.  Meditation fails.");
		return FALSE;
	}

	/*
	 *  How much should we add?  2, 4 if alone in a tower,
	 *  and 2 additional if has an auraculum.
	 *
	 */
	add_aura(c->who,2);

	if (subkind(subloc(c->who)) == sub_tower &&
	    alone_here(c->who)) 
	  add_aura(c->who,2);

	if (has_auraculum(c->who))
	  add_aura(c->who,2);

	wout(c->who, "Current aura is now %d.", p->cur_aura);
	return TRUE;
}
Example #20
0
void dtls_dispatch::add_peer_visible_ipaddr(const ip_info& addr)
{
	// TODO: detect when peer is providing the same ipaddr as several other peers but a different port
		// it is possible that the peer is behind a NAPT which is translating the source port of the incoming packet(s)
		// and advertising that port to other peers would almost certaily be non-useful
		// using popular voting to determine which port to advertise on an address would probably be effective, as multiple peers seeing same addr+port probably means it's right
		// but democracy implies possible DoS by Sybil; any mitigation? maybe advertise any addr+port seen by at least two peers?
	if(addr.port == 0) {
		dout() << "Not adding peer visible addr with zero port " << addr;
		return;
	}
	size_t& entry = peer_visible_addrs.emplace(addr,0).first->second;
	++entry;
	// do nothing more if address is already known
	if(entry > 1)
		return;
	if(snow::conf[snow::PUBLIC_IPV4_ADDRS].size() > 0) {
		dout() << "Peer sees our address as " << addr << " which is ignored because config file specified PUBLIC_IPV4_ADDRS";
		return;
	}
	ip_info natpmp_ip(natpmp_addr, natpmp_port);
	const ip_union* non_rfc1918 = (natpmp_addr == 0 || natpmp_ip.addr.is_rfc1918()) ? nullptr : &natpmp_ip.addr;
	if(addr == natpmp_ip)
		return;
	for(const ip_union& ip : local_interface_addrs) {
		if(memcmp(ip.ip6.s6_addr, addr.addr.ip6.s6_addr, sizeof(in6_addr::s6_addr)) == 0)
			return;
		if(ip.is_ip4map6() && ip.is_rfc1918() == false)
			non_rfc1918 = &ip;
	}
	// peer sees our ipaddr as different than any known address, maybe ipaddr has changed and we are going to lose most/all existing connections
	vn->check_all_connections();
	char addr_buf[INET6_ADDRSTRLEN], addr_buf2[INET6_ADDRSTRLEN];
	if(non_rfc1918) {
		wout() << "Peer claims that this node's publicly visible IP address is " << inet_ntop(AF_INET6, addr.addr.ip6.s6_addr, addr_buf, INET6_ADDRSTRLEN)
			<< " even though it is known to be " << inet_ntop(AF_INET6, non_rfc1918->ip6.s6_addr, addr_buf2, INET6_ADDRSTRLEN)
		   << " (peer-provided IP will not be advertised to other peers)";
	} else if(snow::conf[snow::NEVER_TRUST_PEER_VISIBLE_IPADDRS] == false) {
		// going to trust peer because we don't know any better, but complain about it first
		wout() << "Trusting peer that this node's public IP is " << inet_ntop(AF_INET6, addr.addr.ip6.s6_addr, addr_buf, INET6_ADDRSTRLEN)
					  << ", consider manually specifying PUBLIC_IPV4_ADDRS in the snow configuration file or procuring a NAT-PMP or PCP enabled gateway."
					  << " Note that some versions of snow also support UPnP gateways, but the recommendation upon encountering a UPnP-only gateway is that you"
					  << " tender it to a local recycling firm such that it may be converted into lawn furniture.";
		update_dht_local_ipaddrs();
	} else {
		dout() << "Peer says this node's public IP address is " << inet_ntop(AF_INET6, addr.addr.ip6.s6_addr, addr_buf, INET6_ADDRSTRLEN) << " and actual address is unknown"
			   << " but this node is set for NEVER_TRUST_PEER_VISIBLE_IPADDRS";
	}
}
Example #21
0
int
v_save_quick(struct command *c)
{

  if (char_quick_cast(c->who) < 1) {
    wout(c->who, "No stored spell cast speedup.");
    return FALSE;
  }

  if (!check_aura(c->who, 3))
    return FALSE;

  wout(c->who, "Attempt to save speeded cast state.");
  return TRUE;
}
Example #22
0
int
v_heal(struct command *c)
{
  int target = c->a;
  int aura;

  if (c->b < 1)
    c->b = 1;
  if (c->b > 3)
    c->b = 3;
  aura = c->b;

  if (!cast_check_char_here(c->who, target))
    return FALSE;

  if (!char_sick(target)) {
    wout(c->who, "%s is not sick.", box_name(target));
    return FALSE;
  }

  if (!check_aura(c->who, aura))
    return FALSE;

  return TRUE;
}
Example #23
0
int
v_adv_med(struct command *c)
{

  wout(c->who, "Meditate for %s.", weeks(c->wait));
  return TRUE;
}
Example #24
0
BSONObj MozJSImplScope::callThreadArgs(const BSONObj& args) {
    MozJSEntry entry(this);

    JS::RootedValue function(_context);
    ValueReader(_context, &function).fromBSONElement(args.firstElement(), args, true);

    int argc = args.nFields() - 1;

    JS::AutoValueVector argv(_context);
    BSONObjIterator it(args);
    it.next();
    JS::RootedValue value(_context);

    for (int i = 0; i < argc; ++i) {
        ValueReader(_context, &value).fromBSONElement(*it, args, true);
        argv.append(value);
        it.next();
    }

    JS::RootedValue out(_context);
    JS::RootedObject thisv(_context);

    _checkErrorState(JS::Call(_context, thisv, function, argv, &out), false, true);

    JS::RootedObject rout(_context, JS_NewPlainObject(_context));
    ObjectWrapper wout(_context, rout);
    wout.setValue("ret", out);

    return wout.toBSON();
}
Example #25
0
int
cast_check_char_here(int who, int target)
{
  int where;
  int basic;
  int pl;

  basic = char_proj_cast(who);

  if (is_loc_or_ship(basic))
    where = basic;
  else
    where = subloc(who);

#if 1
  p_magic(who)->project_cast = 0;
#endif

  if (crosses_ocean(where, who)) {
    wout(who, "Something seems to block your magic.");
    return FALSE;
  };

  if (kind(target) != T_char || where != subloc(target)) {
    wout(who, "%s is not a character in range of this cast.",
         box_code(target));
    return FALSE;
  }

  if (char_really_hidden(target)) {
    pl = player(who);
    if (pl == player(target))
      return TRUE;

    if (contacted(target, who))
      return TRUE;

    return FALSE;
  }

#if 0
  if (basic == where)
    p_magic(who)->project_cast = 0;
#endif

  return TRUE;
}
Example #26
0
int
v_los(struct command *c)
{
  int target = c->a;
  int d;

  if (!is_loc_or_ship(target)) {
    wout(c->who, "%s is not a location.", box_code(target));
    return FALSE;
  }

  d = los_province_distance(subloc(c->who), target);

  wout(c->who, "distance=%d", d);

  return TRUE;
}
int
v_meditate(struct command *c)
{
  if (!char_alone(c->who)) {
    wout(c->who, "You cannot meditate unless completely alone.");
    return FALSE;
  };

  if (char_cur_aura(c->who) >= max_eff_aura(c->who)) {
    wout(c->who, "Current aura is already %d.  It may not "
	       "be increased further via meditation.",
	       char_cur_aura(c->who));
    return FALSE;
  }

  wout(c->who, "Meditate for %s.", weeks(c->wait));
  return TRUE;
}
int
v_detect_abil(struct command *c)
{

	if (!check_aura(c->who, 1))
		return FALSE;

	wout(c->who, "Will practice ability scry detection.");
	return TRUE;
}
Example #29
0
int
v_poof(struct command *c)
{

  if (!is_loc_or_ship(c->a)) {
    wout(c->who, "%s is not a location.", c->parse[1]);
    return FALSE;
  }

  move_stack(c->who, c->a);

  wout(c->who, ">poof!<  A cloud of orange smoke appears and "
       "wisks you away...");
  out(c->who, "");

  show_loc(c->who, loc(c->who));

  return TRUE;
}
//#include "/uscms_data/d3/cvernier/DiH_13TeV/CMSSW_7_1_5/src/HiggsAnalysis/CombinedLimit/interface/RooMultiPdf.h"
//#include "HiggsAnalysis/CombinedLimit/interface/RooMultiPdf.h"
void makeRooMultiPdfWorkspace(){

   // Load the combine Library 
   gSystem->Load("libHiggsAnalysisCombinedLimit.so");

   // Open the dummy H->gg workspace 
   TFile *f_hgg = TFile::Open("w_background_Bern.root");
   RooWorkspace *w_hgg = (RooWorkspace*)f_hgg->Get("HbbHbb");
   // The observable (CMS_hgg_mass in the workspace)
   RooRealVar *mass =  w_hgg->var("x");

   // Get three of the functions inside, exponential, linear polynomial, power law
   RooAbsPdf *pdf_exp = w_hgg->pdf("bg_exp");
   RooAbsPdf *pdf_pol = w_hgg->pdf("bg");


   // Fit the functions to the data to set the "prefit" state (note this can and should be redone with combine when doing 
   // bias studies as one typically throws toys from the "best-fit"
   RooAbsData *data = w_hgg->data("data_obs");
   pdf_exp->fitTo(*data);  // index 0
   pdf_pol->fitTo(*data);   // index 2

   // Make a plot (data is a toy dataset)
   RooPlot *plot = mass->frame();   data->plotOn(plot);
   pdf_exp->plotOn(plot,RooFit::LineColor(kBlue));
   pdf_pol->plotOn(plot,RooFit::LineColor(kRed));
   plot->SetTitle("PDF fits to toy data");
   plot->Draw();

   // Make a RooCategory object. This will control which of the pdfs is "active"
   RooCategory cat("pdf_index","Index of Pdf which is active");

   // Make a RooMultiPdf object. The order of the pdfs will be the order of their index, ie for below 
   // 0 == exponential
   // 1 == linear function
   // 2 == powerlaw
   RooArgList mypdfs;
   mypdfs.add(*pdf_exp);
   mypdfs.add(*pdf_pol);
   
   RooMultiPdf multipdf("roomultipdf","All Pdfs",cat,mypdfs);
   
   // As usual make an extended term for the background with _norm for freely floating yield
   RooRealVar norm("roomultipdf_norm","Number of background events",0,10000);
   
   // Save to a new workspace
   TFile *fout = new TFile("background_pdfs.root","RECREATE");
   RooWorkspace wout("backgrounds","backgrounds");
   wout.import(cat);
   wout.import(norm);
   wout.import(multipdf);
   wout.Print();
   wout.Write();

}