bool MemoryChunk::Free(void* memory)
    {
        if (Owns(memory))
        {
            available_blocks_.push_back(reinterpret_cast<char*>(memory));
            assert(available_blocks_.size() <= BlocksPerChunk);
            return true;
        }

        return false;
    }
Exemple #2
0
void PSPower::Gains(PSProvince* pPrv, BOOL bUpdateData)
{
	ASSERT(pPrv->GetSC());
	ASSERT(!Owns(pPrv));
	m_SCs.push_back(pPrv);
	if (!bUpdateData)
		return;

	SC* pSC = new SC;
	pSC->m_pPower = this;
	pSC->m_pProvince = pPrv;
	TG.GetData()->AddSC(pSC);
}
Exemple #3
0
static int
chown_ok(dbref player, dbref thing, dbref newowner, NEW_PE_INFO *pe_info)
{
  /* Can't touch garbage */
  if (IsGarbage(thing))
    return 0;

  /* Wizards can do it all */
  if (Wizard(player))
    return 1;

  /* In order for non-wiz player to @chown thing to newowner,
   * player must control newowner or newowner must be a Zone Master
   * and player must pass its zone lock.
   *
   * In addition, one of the following must apply:
   *   1.  player owns thing, or
   *   2.  player controls Owner(thing), newowner is a zone master,
   *       and Owner(thing) passes newowner's zone-lock, or
   *   3.  thing is CHOWN_OK, and player holds thing if it's an object.
   *
   * The third condition is syntactic sugar to handle the situation
   * where Joe owns Box, an ordinary object, and Tool, an inherit object,
   * and ZMP, a Zone Master Player, is zone-locked to =tool.
   * In this case, if Joe doesn't pass ZMP's lock, we don't want
   *   Joe to be able to @fo Tool=@chown Box=ZMP
   */

  /* Does player control newowner, or is newowner a Zone Master and player
   * passes the lock?
   */
  if (!(controls(player, newowner) ||
        (ZMaster(newowner) &&
         eval_lock_with(player, newowner, Zone_Lock, pe_info))))
    return 0;

  /* Target player is legitimate. Does player control the object? */
  if (Owns(player, thing))
    return 1;

  if (controls(player, Owner(thing)) && ZMaster(newowner) &&
      eval_lock_with(Owner(thing), newowner, Zone_Lock, pe_info))
    return 1;

  if ((!IsThing(thing) || (Location(thing) == player)) && ChownOk(thing) &&
      eval_lock_with(player, thing, Chown_Lock, pe_info))
    return 1;

  return 0;
}
Exemple #4
0
void PSPower::Loses(PSProvince* pPrv)
{
	ASSERT(pPrv->GetSC());
	ASSERT(Owns(pPrv));
	for (Provinces::iterator pIt = m_SCs.begin(); pIt < m_SCs.end(); pIt++)
	{
		if (*pIt == pPrv)
		{
			m_SCs.erase(pIt);
			PSData* pData = TG.GetData();
			pData->DeleteSC(pPrv, this);
			return;
		}
	}
	ASSERT(0);
}
/** Can a player control a thing?
 * The control rules are, in order:
 *   Only God controls God.
 *   Wizards control everything else.
 *   Nothing else controls a wizard, and only royalty control royalty.
 *   Mistrusted objects control only themselves.
 *   Objects with the same owner control each other, unless the
 *     target object is TRUST and the would-be controller isn't.
 *   If ZMOs allow control, and you pass the ZMO, you control.
 *   If the owner is a Zone Master, and you pass the ZM, you control.
 *   If you pass the control lock, you control.
 *   Otherwise, no dice.
 * \param who object attempting to control.
 * \param what object to be controlled.
 * \retval 1 who controls what.
 * \retval 0 who doesn't control what.
 */
int
controls(dbref who, dbref what)
{
  boolexp c;

  if (!GoodObject(what))
    return 0;

  if (Guest(who))
    return 0;

  if (what == who)
    return 1;

  if (God(what))
    return 0;

  if (Wizard(who))
    return 1;

  if (Wizard(what) || (Hasprivs(what) && !Hasprivs(who)))
    return 0;

  if (Mistrust(who))
    return 0;

  if (Owns(who, what) && (!Inheritable(what) || Inheritable(who)))
    return 1;

  if (Inheritable(what) || IsPlayer(what))
    return 0;

  if (!ZONE_CONTROL_ZMP && (Zone(what) != NOTHING) &&
      eval_lock(who, Zone(what), Zone_Lock))
    return 1;

  if (ZMaster(Owner(what)) && !IsPlayer(what) &&
      eval_lock(who, Owner(what), Zone_Lock))
    return 1;

  c = getlock_noparent(what, Control_Lock);
  if (c != TRUE_BOOLEXP) {
    if (eval_boolexp(who, c, what, NULL))
      return 1;
  }
  return 0;
}