Example #1
0
SslOptions::SslOptions() : qpid::Options("SSL Settings"), 
                           certName(defaultCertName()),
                           exportPolicy(false)
{
    addOptions()
        ("ssl-use-export-policy", optValue(exportPolicy), "Use NSS export policy")
        ("ssl-cert-password-file", optValue(certPasswordFile, "PATH"), "File containing password to use for accessing certificate database")
        ("ssl-cert-db", optValue(certDbPath, "PATH"), "Path to directory containing certificate database")
        ("ssl-cert-name", optValue(certName, "NAME"), "Name of the certificate to use");
}
Example #2
0
    DaemonOptions() : qpid::Options("Daemon options"), daemon(false), quit(false), check(false), wait(600), transport(TCP)
    {
        char *home = ::getenv("HOME");

        if (home == 0)
            piddir += "/tmp";
        else
            piddir += home;
        piddir += "/.qpidd";

        addOptions()
            ("daemon,d", pure_switch(daemon), "Run as a daemon. Logs to syslog by default in this mode.")
            ("transport", optValue(transport, "TRANSPORT"), "The transport for which to return the port")
            ("pid-dir", optValue(piddir, "DIR"), "Directory where port-specific PID file is stored")
            ("wait,w", optValue(wait, "SECONDS"), "Sets the maximum wait time to initialize or shutdown the daemon. If the daemon fails to initialize/shutdown, prints an error and returns 1")
            ("check,c", pure_switch(check), "Prints the daemon's process ID to stdout and returns 0 if the daemon is running, otherwise returns 1")
            ("quit,q", pure_switch(quit), "Tells the daemon to shut down");
    }
Example #3
0
 Options() : qpid::Options("AMQP 1.0 Options") {
     addOptions()
         ("domain", optValue(domain, "DOMAIN"), "Domain of this broker");
 }
Example #4
0
bool TGOParser::validate(const int &argc, const char **argv)
{
	bool escape_mode = false;
	for(int i = 1; i < argc; i++)
	{
		printf("arg: %s\n", argv[i]);
		int len = strlen(argv[i]);
		if(!escape_mode && len >= 2)
		{
			if(argv[i][0] == '-')
			{
				if(argv[i][1] == '-')
				{
					printf("long opt: %s\n", argv[i]);
					// long option, or -- separator
					if(len == 2) // -- separator
					{
						// all following command line parameters are passed in as is.
						// no parsing options
						escape_mode = true;
						continue;
					}
					else
					{
						char *eq = (char *)index(argv[i], '=');
						if(eq)
						{
							int name_len = eq - argv[i] - 2;
							int value_len = len - name_len;
							std::string optName(argv[i]+2, name_len);
							std::string optValue(eq+1, value_len);
							
							printf("opt: '%s'='%s'\n", optName.c_str(), optValue.c_str());
							
							if(!longOptMap.count(optName))
							{
								printf("unknown option %s.\n", optName.c_str());
								return false;
							}
							
							TGOOptionBase *opt = longOptMap[optName];
							if(opt->valueRequired())
							{
								if(!optValue.size())
								{
									printf("option %s requires a value.\n", optName.c_str());
									return false;
								}
								
								if(opt->validate(optValue))
									opt->setOptionValue(optValue);
								else
								{
									printf("option %s value is invalue.\n", argv[i]);
									return false;
								}
							}
							else
							{
								opt->setOptionValue("1");
							}
								
						}
						else
						{
							if(longOptMap.count(argv[i]+2))
							{
								TGOOptionBase *opt = longOptMap[argv[i]+2];
								if(opt->valueRequired())
								{
									if(i+1 >= argc)
									{
										printf("option %s requires a value.\n", argv[i]);
										return false;
									}
									
									const char *nextArg = argv[i+1];
									size_t nextArgLen = strlen(nextArg);
									const char *nextArgValue = 0;
									
									if(nextArgLen)
									{
										if(nextArg[0] == '-')
										{
											if(nextArgLen == 2 && nextArg[1] == '-')
											{
												// -- escape arg, pull in argv[i+2]
												if(i+2 >= argc)
												{
													printf("option %s requires a value.\n", argv[i]);
													return false;
												}
												
												nextArgValue = argv[i+2];
												i += 2;
											}
											else if(nextArgLen > 1)
											{
												printf("option %s requires a value.\n", argv[i]);
												return false;
											}
											else
											{
												// singular - (dash) signifies stdin
												nextArgValue = argv[i+1];
												i++;
											}
										}
										else
										{
											nextArgValue = argv[i+1];
											i++;
										}
									}
									else
									{
										printf("option %s requires a value.\n", argv[i]);
										return false;
									}
									
									if(opt->validate(nextArgValue))
										opt->setOptionValue(nextArgValue);
									else
										printf("option %s value is invalid.\n", argv[i]);
								}
								else
								{
									opt->setOptionValue("1");
								}
							}
							else
							{
								printf("unknown option %s\n", argv[i]);
								return false;
							}
						}
					}
				}
				else
				{
					// short option, or - stdin marker
					if(len == 1)
					{
						// stdin marker
						extra_parameters.push_back(argv[i]);
					}
					else
					{
						for(int j = 1; j < len; j++)
						{
							if(!shortOptMap.count(argv[i][j]))
							{
								printf("unknown option %c\n", argv[i][j]);
								return false;
							}
								
							if(shortOptMap[argv[i][j]]->valueRequired())
							{
								if(j <= len)
								{
									printf("option %c requires a value.\n", argv[i][j]);
									return false;
								}
								
								if(shortOptMap[argv[i][j]]->validate(argv[i+1]))
								{
									shortOptMap[argv[i][j]]->setOptionValue(argv[i+1]);
									printf("opt: '%c'='%s'\n", argv[i][j], argv[i+1]);
									i++;
								}
								else
								{
									printf("option %c value is invalid.\n", argv[i][j]);
									return false;
								}
							}
							else
							{
								shortOptMap[argv[i][j]]->setOptionValue("1");
							}
							
						}
					}
				}
			}
		}
		else
			extra_parameters.push_back(argv[i]);
	}
	
	return true;
}
Example #5
0
/*!
** @brief Xsocket implemention of the standard getsockopt function.
**
** Xgetsockopt is used to retrieve the settings of the underlying Xsocket
** in the Click layer. It does not access the settings of the actual
** socket passed in which is used by the API to communicate with Click.
**
** Supported Options:
**	\n XOPT_HLIM	Retrieves the 'hop limit' element of the XIA header as an integer value
**	\n XOPT_NEXT_PROTO Gets the next proto field in the XIA header
**	\n SO_TYPE 		Returns the type of socket (SOCK_STREAM, etc...)
**
** @param sockfd	The control socket
** @param optname	The socket option to set (currently must be IP_TTL)
** @param optval	A pointer to the value to retrieve
** @param optlen	A pointer to the length of optval. On input this
**	should be set to the length of the data passed in. If optlen is not
**	large enough, Xgetsockopt will set it to the size needed and return
**	with errno set to EINVAL. If larger than needed, Xgetsockopt will set
**	it to the actual length of the returned data.
**
** @returns  0 on success
** @returns -1 on error with errno set
** @returns errno values:
** @returns EBADF: The socket descriptor is invalid
** @returns EINVAL: Either optval is null, or optlen is invalid, or optval is out of range
** @returns ENOPROTOOPT: the specified optname is not recognized
*/
int Xgetsockopt(int sockfd, int optname, void *optval, socklen_t *optlen)
{
	int rc = 0;

	if (getSocketType(sockfd) == XSOCK_INVALID) {
		errno = EBADF;
		return -1;
	}

	if (!optval || !optlen) {
		errno = EINVAL;
		return -1;
	}

	switch (optname) {

		// get these values from click ******************************
		case XOPT_HLIM:
		case XOPT_NEXT_PROTO:
		case XOPT_ERROR_PEEK:
		case SO_ACCEPTCONN:
		case SO_ERROR:
			rc = ssoGetInt(sockfd, optname, (int *)optval, optlen);
			break;

		case SO_DEBUG:
			// stored in the API & in click, return from the API
			rc = ssoGetParam(getDebug(sockfd), optval, optlen);
			break;

		case SO_DOMAIN:
			// FIXME: conver this to AF_INET in wrapper
			rc = ssoGetParam(AF_XIA, optval, optlen);
			break;

		case SO_PROTOCOL:
			rc = ssoGetParam(getProtocol(sockfd), optval, optlen);
			break;

		case SO_TYPE:
			ssoGetParam(getSocketType(sockfd), optval, optlen);
			break;


		// SHOIULD IMPLEMENT! ***************************************
		// FIXME: implement these!
		case SO_SNDBUF:
		case SO_RCVBUF:
		case SO_SNDTIMEO:
		case SO_RCVTIMEO:
		case SO_LINGER:
			LOGF("Uh Oh, we need support for %s in XIA\n", optValue(optname));
			rc = -1;
			break;

		// FIXME: MAY NEED ******************************************

		case SO_BROADCAST:
			// FIXME: can we just go ahead and mark this as success?
			// or do we need to do something to check to see if bradcast DAGS are allowed on this socket?
			if (getSocketType(sockfd) == SOCK_DGRAM) {
				rc = -1;
				errno = ENOPROTOOPT;
				break;
			}
			// else silently ignore
			break;

		case SO_REUSEADDR:
			// just say it's not enabled
			ssoGetParam(0, optval, optlen);
			rc = 0;
			break;

		case SO_RCVLOWAT:
		case SO_SNDLOWAT:
			// Probably will never need to support this
			// return the default linux value of 1
			rc = ssoGetParam(1, optval, optlen);
			break;


		// CAN SAFELY IGNORE ****************************************

		case SO_KEEPALIVE:
			// we don't have keepalive so lie and say we do
			ssoGetParam(0, optval, optlen);
			rc = 0;
			break;

		case SO_BSDCOMPAT:
			// safe to mark as unsupported, being phased out on linux anyway
			errno = ENOPROTOOPT;
			rc = -1;
			break;

		// NOT SUPPORTED/DOESN"T MAKE SENSE IN XIA ******************
		case SO_BINDTODEVICE:	// should we support this one when we get multihoming?
		case SO_DONTROUTE:
		case SO_MARK:
		case SO_OOBINLINE:
		case SO_PASSCRED:
		case SO_PEERCRED:
		case SO_PRIORITY:
		case SO_RCVBUFFORCE:
		case SO_SNDBUFFORCE:
		case SO_TIMESTAMP:
		default:
			// return generic error
			LOGF("Option %s not supported in XIA\n", optValue(optname));
			errno = ENOPROTOOPT;
			rc = -1;
	}

	return rc;
}
Example #6
0
/*!
** @brief Xsocket implemention of the standard setsockopt function.
**
** Xsetsockopt is used to set options on the underlying Xsocket in
** the Click layer. It does not affect the actual socket passed in which
** used by the API to communicate with Click.
**
** Supported Options:
**	\n XOPT_HLIM	Sets the 'hop limit' (hlim) element of the XIA header to the
**		specified integer value. (Default is 250)
**	\n XOPT_NEXT_PROTO Sets the next proto field in the XIA header
**
** @param sockfd	The control socket
** @param optname	The socket option to set
** @param optval	A pointer to the value to set
** @param optlen	The length of the option being set
**
** @returns 0 on success
** @returns -1 on error with errno set
** @returns errno values:
** @returns EBADF: The socket descriptor is invalid
** @returns EINVAL: Either optval is null, or optlen is invalid, or optval is out of range
** @returns ENOPROTOOPT: the specified optname is not recognized
*/
int Xsetsockopt(int sockfd, int optname, const void *optval, socklen_t optlen)
{
	int rc = 0;

	/* TODO: we may need to check the type of the socket at some point, but for now
	** treat them all the same as far as options go.
	*/
	if (getSocketType(sockfd) == XSOCK_INVALID) {
		errno = EBADF;
		return -1;
	}

	if (!optval) {
		errno = EINVAL;
		return -1;
	}
	switch (optname) {

		// send these values to click *******************************

		case XOPT_HLIM:
		{
			int hlim = *(const int *)optval;

			if (hlim < 0 || hlim > 255) {
				LOGF("HLIM (%d) out of range", hlim);
				errno = EINVAL;
				rc = -1;
			} else {
				rc = ssoPutInt(sockfd, optname, (const int *)optval, optlen);
			}
			break;
		}

		case XOPT_NEXT_PROTO:
		{
			int next = *(const int *)optval;

			if (next != XPROTO_XCMP) {
				LOGF("Invalid next protocol specified (%d)", next);
				errno = EINVAL;
				rc = -1;
			} else {
				rc = ssoPutInt(sockfd, optname, (const int *)optval, optlen);
			}
			break;
		}

		case XOPT_BLOCK:
		{
			rc = ssoPutInt(sockfd, optname, (const int *)optval, optlen);
			break;
		}

		// this is handled in the API & in click ********************

		case SO_DEBUG:
			if (ssoCheckSize(&optlen, sizeof(int)) < 0) {
				rc = -1;
			}
			else {
				setDebug(sockfd, *(int *)optval);
				rc = ssoPutInt(sockfd, optname, (const int *)optval, optlen);
			}
			break;


		// SHOIULD IMPLEMENT! ***************************************
		// FIXME: implement these!
		case SO_SNDBUF:
		case SO_RCVBUF:
		case SO_SNDTIMEO:
		case SO_RCVTIMEO:
		case SO_LINGER:
		case SO_REUSEADDR:
			LOGF("Uh Oh, we need support for %s in XIA\n", optValue(optname));
			rc = 0;
			break;

		// FIXME: MAY NEED ******************************************

		case SO_BROADCAST:
			// FIXME: can we just go ahead and mark this as success?
			// or do we need to do something to check to see if bradcast DAGS are allowed on this socket?
			if (getSocketType(sockfd) == SOCK_DGRAM) {
				rc = -1;
				errno = ENOPROTOOPT;
				break;
			}
			// else silently ignore
			break;

		case SO_RCVLOWAT:
		case SO_SNDLOWAT:
			// Probably will never need to support this
			// return the default linux value of 1
			rc = 0;
			break;


		// CAN SAFELY IGNORE ****************************************

		case SO_KEEPALIVE:
			// we don't have keepalive so lie and say we did it
			rc = 0;
			break;

		case SO_BSDCOMPAT:
			// safe to mark as unsupported, being phased out on linux anyway
			errno = ENOPROTOOPT;
			rc = -1;
			break;

		// READ ONLY OPTIONS ****************************************
		case SO_ACCEPTCONN:
		case SO_DOMAIN:
		case SO_PROTOCOL:
		case SO_TYPE:
			LOGF("Option %s is read only\n", optValue(optname));
			errno = ENOPROTOOPT;
			rc = -1;
			break;

		// NOT SUPPORTED/DOESN"T MAKE SENSE IN XIA ******************
		case SO_BINDTODEVICE:	// should we support this one when we get multihoming?
		case SO_DONTROUTE:
		case SO_MARK:
		case SO_OOBINLINE:
		case SO_PASSCRED:
		case SO_PEERCRED:
		case SO_PRIORITY:
		case SO_RCVBUFFORCE:
		case SO_SNDBUFFORCE:
		case SO_TIMESTAMP:
		default:
			// return generic error
			LOGF("Option %s not supported in XIA\n", optValue(optname));
			errno = ENOPROTOOPT;
			rc = -1;
	}

	return rc;
}
Example #7
0
 TestStoreOptions() : Options("Test Store Options") {
     addOptions()
         ("test-store-name", optValue(name, "NAME"), "Name of test store instance.")
         ("test-store-dump", optValue(dump, "FILE"), "File to dump enqueued messages.")
         ;
 }
Example #8
0
/**
 * Calculates the effects of the explosion.
 */
void ExplosionBState::explode()
{
	bool terrainExplosion = false;
	SavedBattleGame *save = _parent->getSave();
	// last minute adjustment: determine if we actually
	if (_hit)
	{
		if (_unit && !_unit->isOut())
		{
			_unit->aim(false);
		}

		if (_power <= 0)
		{
			_parent->popState();
			return;
		}

		int sound = _item->getRules()->getMeleeHitSound();
		if (!_pistolWhip)
		{
			// melee weapon with ammo
			BattleItem *ammo = _item->getAmmoItem();
			if (ammo)
			{
				optValue(sound, ammo->getRules()->getMeleeHitSound());
			}
		}
		_parent->playSound(sound, _action.target);
	}
	// after the animation is done, the real explosion/hit takes place
	if (_item)
	{
		if (!_unit && _item->getPreviousOwner())
		{
			_unit = _item->getPreviousOwner();
		}
	}

	bool range = !(_hit || (_item && _item->getRules()->getBattleType() == BT_PSIAMP));

	if (_areaOfEffect)
	{
		save->getTileEngine()->explode(_center, _power, _damageType, _radius, _unit, _item, range);
	}
	else
	{
		BattleUnit *victim = save->getTileEngine()->hit(_center, _power, _damageType, _unit, _item, range);
		// check if this unit turns others into zombies
		if (!_item->getRules()->getZombieUnit().empty()
			&& RNG::percent(_item->getRules()->getSpecialChance())
			&& victim
			&& victim->getArmor()->getZombiImmune() == false
			&& victim->getSpawnUnit().empty()
			&& victim->getOriginalFaction() != FACTION_HOSTILE)
		{
			// converts the victim to a zombie on death
			victim->setRespawn(true);
			victim->setSpawnUnit(_item->getRules()->getZombieUnit());
		}
	}

	if (_tile)
	{
		terrainExplosion = true;
	}
	if (!_tile && !_item)
	{
		terrainExplosion = true;
	}

	// now check for new casualties
	_parent->checkForCasualties(_item ? _damageType : 0, _item, _unit, false, terrainExplosion);
	// revive units if damage could give hp or reduce stun
	_parent->getSave()->reviveUnconsciousUnits(true);

	// if this explosion was caused by a unit shooting, now it's the time to put the gun down
	if (_unit && !_unit->isOut() && _lowerWeapon)
	{
		_unit->aim(false);
	}

	if (_item && (_item->getRules()->getBattleType() == BT_GRENADE || _item->getRules()->getBattleType() == BT_PROXIMITYGRENADE))
	{
		_parent->getSave()->removeItem(_item);
	}

	_parent->popState();

	// check for terrain explosions
	Tile *t = save->getTileEngine()->checkForTerrainExplosions();
	if (t)
	{
		Position p = t->getPosition().toVexel();
		p += Position(8,8,0);
		_parent->statePushFront(new ExplosionBState(_parent, p, BA_NONE, 0, _unit, t));
	}
}
Example #9
0
/**
 * Initializes the explosion.
 * The animation and sound starts here.
 * If the animation is finished, the actual effect takes place.
 */
void ExplosionBState::init()
{
	BattleType type = BT_NONE;
	BattleActionType action = _action.type;
	const RuleItem* itemRule = 0;
	bool miss = false;
	if (_item)
	{
		itemRule = _item->getRules();
		type = itemRule->getBattleType();

		_power = 0;
		_pistolWhip = (type != BT_MELEE && action == BA_HIT);
		if (_pistolWhip)
		{
			_power += itemRule->getMeleeBonus(_unit);

			_radius = 0;
			_damageType = itemRule->getMeleeType();
		}
		else
		{
			_power += itemRule->getPowerBonus(_unit);
			_power -= itemRule->getPowerRangeReduction(_range);

			_radius = itemRule->getExplosionRadius(_unit);
			_damageType = itemRule->getDamageType();
		}

		//testing if we hit target
		if (type == BT_PSIAMP && !_pistolWhip)
		{
			if (action != BA_USE)
			{
				_power = 0;
			}
			if (!_parent->psiAttack(&_action))
			{
				_power = 0;
				miss = true;
			}
		}
		else if (type == BT_MELEE || _pistolWhip)
		{
			if (!_parent->getTileEngine()->meleeAttack(&_action))
			{
				_power = 0;
				miss = true;
			}
		}
		else if (type == BT_FIREARM)
		{
			if (_power <= 0)
			{
				miss = true;
			}
		}

		_areaOfEffect = type != BT_MELEE && _radius != 0 &&
						(type != BT_PSIAMP || action == BA_USE) &&
						!_pistolWhip && !miss;
	}
	else if (_tile)
	{
		ItemDamageType DT;
		switch (_tile->getExplosiveType())
		{
		case 0:
			DT = DT_HE;
			break;
		case 5:
			DT = DT_IN;
			break;
		case 6:
			DT = DT_STUN;
			break;
		default:
			DT = DT_SMOKE;
			break;
		}
		_power = _tile->getExplosive();
		_tile->setExplosive(0, 0, true);
		_damageType = _parent->getMod()->getDamageType(DT);
		_radius = _power /10;
		_areaOfEffect = true;
	}
	else if (_unit && (_unit->getSpecialAbility() == SPECAB_EXPLODEONDEATH || _unit->getSpecialAbility() == SPECAB_BURN_AND_EXPLODE))
	{
		RuleItem* corpse = _parent->getMod()->getItem(_unit->getArmor()->getCorpseGeoscape());
		_power = corpse->getPowerBonus(_unit);
		_damageType = corpse->getDamageType();
		_radius = corpse->getExplosionRadius(_unit);
		_areaOfEffect = true;
		if (!RNG::percent(corpse->getSpecialChance()))
		{
			_power = 0;
		}
	}
	else
	{
		_power = 120;
		_damageType = _parent->getMod()->getDamageType(DT_HE);
		_areaOfEffect = true;
	}

	Tile *t = _parent->getSave()->getTile(_action.target);
	if (_areaOfEffect)
	{
		if (_power > 0)
		{
			int frame = Mod::EXPLOSION_OFFSET;
			if (_item)
			{
				frame = itemRule->getHitAnimation();
			}
			if (_parent->getDepth() > 0)
			{
				frame -= Explosion::EXPLODE_FRAMES;
			}
			int frameDelay = 0;
			int counter = std::max(1, (_power/5) / 5);
			_parent->getMap()->setBlastFlash(true);
			for (int i = 0; i < _power/5; i++)
			{
				int X = RNG::generate(-_power/2,_power/2);
				int Y = RNG::generate(-_power/2,_power/2);
				Position p = _center;
				p.x += X; p.y += Y;
				Explosion *explosion = new Explosion(p, frame, frameDelay, true);
				// add the explosion on the map
				_parent->getMap()->getExplosions()->push_back(explosion);
				if (i > 0 && i % counter == 0)
				{
					frameDelay++;
				}
			}
			_parent->setStateInterval(BattlescapeState::DEFAULT_ANIM_SPEED/2);
			// explosion sound
			int sound = _power <= 80 ? Mod::SMALL_EXPLOSION : Mod::LARGE_EXPLOSION;
			if (_item) optValue(sound, itemRule->getExplosionHitSound());
			_parent->playSound(sound);

			_parent->getMap()->getCamera()->centerOnPosition(t->getPosition(), false);
		}
		else
		{
			_parent->popState();
		}
	}
	else
	// create a bullet hit
	{
		_parent->setStateInterval(std::max(1, ((BattlescapeState::DEFAULT_ANIM_SPEED/2) - (10 * itemRule->getExplosionSpeed()))));
		_hit = _pistolWhip || type == BT_MELEE;
		bool psi = type == BT_PSIAMP && action != BA_USE && !_pistolWhip;
		int anim = -1;
		int sound = -1;

		// melee weapon with ammo
		BattleItem *ammo = !_pistolWhip && _hit ? _item->getAmmoItem() : 0;

		if (_hit || psi)
		{
			anim = itemRule->getMeleeAnimation();
			if (psi)
			{
				// psi attack sound is based weapon hit sound
				sound = itemRule->getHitSound();

				optValue(anim, itemRule->getPsiAnimation());
				optValue(sound, itemRule->getPsiSound());
			}
			else
			{
				sound = itemRule->getMeleeSound();
				if (ammo)
				{
					optValue(anim, ammo->getRules()->getMeleeAnimation());
					optValue(sound, ammo->getRules()->getMeleeSound());
				}
			}
		}
		else
		{
			anim = itemRule->getHitAnimation();
			sound = itemRule->getHitSound();
		}

		if (miss)
		{
			if (_hit || psi)
			{
				optValue(anim, itemRule->getMeleeMissAnimation());
				if (psi)
				{
					// psi attack sound is based weapon hit sound
					optValue(sound, itemRule->getHitMissSound());

					optValue(anim, itemRule->getPsiMissAnimation());
					optValue(sound, itemRule->getPsiMissSound());
				}
				else
				{
					optValue(sound, itemRule->getMeleeMissSound());
					if (ammo)
					{
						optValue(anim, ammo->getRules()->getMeleeMissAnimation());
						optValue(sound, ammo->getRules()->getMeleeMissSound());
					}
				}
			}
			else
			{
				optValue(anim, itemRule->getHitMissAnimation());
				optValue(sound, itemRule->getHitMissSound());
			}
		}

		if (anim != -1)
		{
			Explosion *explosion = new Explosion(_center, anim, 0, false, (_hit || psi)); // Don't burn the tile
			_parent->getMap()->getExplosions()->push_back(explosion);
		}
		_parent->getMap()->getCamera()->setViewLevel(_center.z / 24);

		BattleUnit *target = t->getUnit();
		if ((_hit || psi) && _parent->getSave()->getSide() == FACTION_HOSTILE && target && target->getFaction() == FACTION_PLAYER)
		{
			_parent->getMap()->getCamera()->centerOnPosition(t->getPosition(), false);
		}
		// bullet hit sound
		_parent->playSound(sound, _action.target);
	}
}
Example #10
0
 SocketOptions() :
 socketFds(0)
 {
     addOptions()
     ("socket-fd", optValue(socketFds, "FD"), "File descriptor for tcp listening socket");
 }
Example #11
0
void Logger::configure(int argc, const char* argv[], const string& pre)
try
{
    bool logToStdout = false;
    bool logToStderr = false;
    string logFile;
    std::vector<std::string> selectors;
    std::vector<std::string> deselectors;
    bool time = false;
    bool level = false;
    bool thread = false;
    bool source = false;
    bool function = false;
    bool hiresTs = false;

    selectors.push_back("notice+"); // Set this for the usage message default

    string prefix = pre.empty() ? pre : pre+"-";
    qpid::Options myOptions;
    myOptions.addOptions()
    ((prefix+"log-enable").c_str(), optValue(selectors, "RULE"),
     ("Enables logging for selected levels and components. "
     "RULE is in the form 'LEVEL[+-][:PATTERN]'\n"
     "LEVEL is one of: \n\t "+qpid::log::getLevels()+"\n"
     "PATTERN is a logging category name, or a namespace-qualified "
     "function name or name fragment. "
     "Logging category names are: \n\t "+qpid::log::getCategories()+"\n"
     "The category \"Application\" contains all messages logged by the application.\n"
     "For example:\n"
     "\t'--log-enable warning+'\n"
     "logs all warning, error and critical messages.\n"
     "\t'--log-enable trace+:Application --log-enable notice+'\n"
     "logs all application messages, but only notice or higher for the qpid library messages\n"
     "\t'--log-enable debug:framing'\n"
     "logs debug messages from all functions with 'framing' in the namespace or function name.\n"
     "This option can be used multiple times").c_str())
    ((prefix+"log-disable").c_str(), optValue(deselectors, "RULE"),
     ("Disables logging for selected levels and components. "
     "RULE is in the form 'LEVEL[+-][:PATTERN]'\n"
     "LEVEL is one of: \n\t "+qpid::log::getLevels()+"\n"
     "PATTERN is a logging category name, or a namespace-qualified "
     "function name or name fragment. "
     "Logging category names are: \n\t "+qpid::log::getCategories()+"\n"
     "For example:\n"
     "\t'--log-disable warning-'\n"
     "disables logging all warning, notice, info, debug, and trace messages.\n"
     "\t'--log-disable trace:Application'\n"
     "disables all application trace messages.\n"
     "\t'--log-disable debug-:qmf::'\n"
     "disables logging debug and trace messages from all functions with 'qmf::' in the namespace.\n"
     "This option can be used multiple times").c_str())
    ((prefix+"log-time").c_str(), optValue(time, "yes|no"), "Include time in log messages")
    ((prefix+"log-level").c_str(), optValue(level,"yes|no"), "Include severity level in log messages")
    ((prefix+"log-source").c_str(), optValue(source,"yes|no"), "Include source file:line in log messages")
    ((prefix+"log-thread").c_str(), optValue(thread,"yes|no"), "Include thread ID in log messages")
    ((prefix+"log-function").c_str(), optValue(function,"yes|no"), "Include function signature in log messages")
    ((prefix+"log-hires-timestamp").c_str(), optValue(hiresTs,"yes|no"), "Use hi-resolution timestamps in log messages")
    ((prefix+"log-to-stderr").c_str(), optValue(logToStderr, "yes|no"), "Send logging output to stderr")
    ((prefix+"log-to-stdout").c_str(), optValue(logToStdout, "yes|no"), "Send logging output to stdout")
    ((prefix+"log-to-file").c_str(), optValue(logFile, "FILE"), "Send log output to FILE.")
    ;

    std::ostringstream loggerSStream;
    myOptions.print(loggerSStream);

    loggerUsage=loggerSStream.str();

    selectors.clear(); // Clear to give passed in options precedence

    // Parse the command line not failing for unrecognised options
    myOptions.parse(argc, argv, std::string(), true);

    // If no passed in enable or disable log specification then go back to default
    if (selectors.empty() && deselectors.empty())
        selectors.push_back("notice+");
    // Set the logger options according to what we just parsed
    qpid::log::Options logOptions;
    logOptions.selectors = selectors;
    logOptions.deselectors = deselectors;
    logOptions.time = time;
    logOptions.level = level;
    logOptions.category = false;
    logOptions.thread = thread;
    logOptions.source = source;
    logOptions.function = function;
    logOptions.hiresTs = hiresTs;

    loggerSelector = qpid::log::Selector(logOptions);
    logger().clear(); // Need to clear before configuring as it will have been initialised statically already
    logger().format(logOptions);
    logger().select(loggerSelector);

    // Have to set up the standard output sinks manually
    if (logToStderr)
        logger().output(std::auto_ptr<qpid::log::Logger::Output>
                       (new qpid::log::OstreamOutput(std::clog)));
    if (logToStdout)
        logger().output(std::auto_ptr<qpid::log::Logger::Output>
                       (new qpid::log::OstreamOutput(std::cout)));

    if (logFile.length() > 0)
        logger().output(std::auto_ptr<qpid::log::Logger::Output>
                         (new qpid::log::OstreamOutput(logFile)));
}
catch (std::exception& e)
{
    throw MessagingException(e.what());
}
Example #12
0
 PingOptions() : timeout(1), quiet(false) {
     addOptions()
         ("timeout,t", optValue(timeout, "SECONDS"), "Max time to wait.")
         ("quiet,q", optValue(quiet), "Don't print anything to stderr/stdout.");
 }
Example #13
0
/**
 * Initializes the explosion.
 * The animation and sound starts here.
 * If the animation is finished, the actual effect takes place.
 */
void ExplosionBState::init()
{
	_animationTimer = new Timer(BattlescapeState::DEFAULT_ANIM_SPEED / 4);
	_animationTimer->onTimer((BattleStateHandler)&ExplosionBState::thinkTimer);
	_animationTimer->start();

	BattleType type = BT_NONE;
	BattleActionType action = _attack.type;
	const RuleItem* itemRule = 0;
	bool miss = false;
	if (_attack.damage_item)
	{
		itemRule = _attack.damage_item->getRules();
		type = itemRule->getBattleType();
		 
		_power = 0;
		_hit = action == BA_HIT;
		_psi = type == BT_PSIAMP && action != BA_USE && !_hit;
		if (_hit && type != BT_MELEE)
		{
			_power += itemRule->getMeleeBonus(_attack.attacker);

			_radius = 0;
			_damageType = itemRule->getMeleeType();
		}
		else
		{
			_power += itemRule->getPowerBonus(_attack.attacker);
			_power -= itemRule->getPowerRangeReduction(_range);

			_radius = itemRule->getExplosionRadius(_attack.attacker);
			_damageType = itemRule->getDamageType();
		}

		if (type == BT_PSIAMP || _hit)
		{
			Position targetPos = _center.toTile();
			_targetPsiOrHit = _parent->getSave()->getTile(targetPos)->getUnit();
			if (!_targetPsiOrHit && targetPos.z > 0)
			{
				_targetPsiOrHit = _parent->getSave()->getTile(targetPos - Position(0, 0, 1))->getUnit();
			}
		}

		//testing if we hit target
		if (type == BT_PSIAMP && !_hit)
		{
			if (action != BA_USE)
			{
				_power = 0;
			}
			if (!_parent->getTileEngine()->psiAttack(_attack, _targetPsiOrHit))
			{
				_power = 0;
				miss = true;
			}
			else
			{
				_parent->psiAttackMessage(_attack, _targetPsiOrHit);
			}
		}
		else if (type == BT_MELEE || _hit)
		{
			if (!_parent->getTileEngine()->meleeAttack(_attack, _targetPsiOrHit))
			{
				_power = 0;
				miss = true;
			}
		}
		else if (type == BT_FIREARM)
		{
			if (_power <= 0)
			{
				miss = true;
			}
		}

		_areaOfEffect = type != BT_MELEE && _radius != 0 &&
			(type != BT_PSIAMP || action == BA_USE) &&
			!_hit && !miss;
	}
	else if (_tile)
	{
		ItemDamageType DT;
		switch (_tile->getExplosiveType())
		{
		case 0:
			DT = DT_HE;
			break;
		case 5:
			DT = DT_IN;
			break;
		case 6:
			DT = DT_STUN;
			break;
		default:
			DT = DT_SMOKE;
			break;
		}
		_power = _tile->getExplosive();
		_tile->setExplosive(0, 0, true);
		_damageType = _parent->getMod()->getDamageType(DT);
		_radius = _power / 10;
		_areaOfEffect = true;
	}
	else if (_attack.attacker && (_attack.attacker->getSpecialAbility() == SPECAB_EXPLODEONDEATH || _attack.attacker->getSpecialAbility() == SPECAB_BURN_AND_EXPLODE))
	{
		RuleItem* corpse = _parent->getMod()->getItem(_attack.attacker->getArmor()->getCorpseGeoscape(), true);
		_power = corpse->getPowerBonus(_attack.attacker);
		_damageType = corpse->getDamageType();
		_radius = corpse->getExplosionRadius(_attack.attacker);
		_areaOfEffect = true;
		if (!RNG::percent(corpse->getSpecialChance()))
		{
			_power = 0;
		}
	}
	else
	{
		_power = 120;
		_damageType = _parent->getMod()->getDamageType(DT_HE);
		_areaOfEffect = true;
	}

	//Tile *t = _parent->getSave()->getTile(Position(_center.x/16, _center.y/16, _center.z/24));
	if (_areaOfEffect)
	{
		if (_power > 0)
		{
			int frame = Mod::EXPLOSION_OFFSET;
			int sound = _power <= 80 ? Mod::SMALL_EXPLOSION : Mod::LARGE_EXPLOSION;

			if (itemRule)
			{
				frame = itemRule->getHitAnimation();
				optValue(sound, itemRule->getExplosionHitSound());
			}
			if (_parent->getDepth() > 0)
			{
				frame -= Explosion::EXPLODE_FRAMES;
			}
			int frameDelay = 0;
			int explosionSkew = itemRule ? (itemRule->getExplosionRadius(_attack.attacker) * 20) : _power;
			int counter = std::max(1, (explosionSkew / 5) / 5);
			_parent->getMap()->setBlastFlash(true);
			for (int i = 0; i < explosionSkew / 5; i++)
			{
				int X = RNG::generate(-explosionSkew / 2, explosionSkew / 2);
				int Y = RNG::generate(-explosionSkew / 2, explosionSkew / 2);
				Position p = _center;
				p.x += X; p.y += Y;
				Explosion *explosion = new Explosion(p, frame, frameDelay, true);
				// add the explosion on the map
				_parent->getMap()->getExplosions()->push_back(explosion);
				_explosions.push_back(explosion);
				if (i > 0 && i % counter == 0)
				{
					frameDelay++;
				}
			}
			//if(!_subState) { _parent->setStateInterval(BattlescapeState::DEFAULT_ANIM_SPEED/2); }
			//_parent->setStateInterval(BattlescapeState::DEFAULT_ANIM_SPEED/2);
			// explosion sound
			_parent->playSound(sound);
			/*if (_power <= 80)
				_parent->getMod()->getSoundByDepth(_parent->getDepth(), Mod::SMALL_EXPLOSION)->play();
			else
				_parent->getMod()->getSoundByDepth(_parent->getDepth(), Mod::LARGE_EXPLOSION)->play();*/

			_parent->getMap()->getCamera()->centerOnPosition(_center.toTile(), false);
		}
		else
		{
			_finished = true;
			if (!_subState) _parent->popState();
			return;
		}
	}
	else
		// create a bullet hit
	{
		if (itemRule && (_dropoffDistance >= 0))
		{
			float voxelDropoff = itemRule->getDamageType()->DistanceDropoff;
			if (voxelDropoff > 0.0f)
			{
				int powerLoss = (int)floor(_dropoffDistance * voxelDropoff / 16.0);
				//Log(LOG_INFO) << "Distance: [" << _dropoffDistance << "] dropoff: [" << powerLoss << "]";
				_power -= powerLoss;
				if (_power < 0) _power = 0;
			}
		}

		//if(!_subState) { _parent->setStateInterval(std::max(1, ((BattlescapeState::DEFAULT_ANIM_SPEED/2) - (10 * _item->getRules()->getExplosionSpeed())))); }
		_animationTimer->setInterval(std::max(1, ((BattlescapeState::DEFAULT_ANIM_SPEED / 4) - (10 * itemRule->getExplosionSpeed()))));
		int anim = -1;
		int sound = -1;

		const RuleItem *weaponRule = _attack.weapon_item->getRules();
		const RuleItem *damageRule = _attack.weapon_item != _attack.damage_item ? itemRule : nullptr;

		if (_hit || _psi)
		{
			anim = weaponRule->getMeleeAnimation();
			if (_psi)
			{
				// psi attack sound is based weapon hit sound
				sound = weaponRule->getHitSound();

				optValue(anim, weaponRule->getPsiAnimation());
				optValue(sound, weaponRule->getPsiSound());
			}
			else
			{
				sound = weaponRule->getMeleeSound();
				if (damageRule)
				{
					optValue(anim, damageRule->getMeleeAnimation());
					optValue(sound, damageRule->getMeleeSound());
				}
			}
		}
		else
		{
			anim = itemRule->getHitAnimation();
			sound = itemRule->getHitSound();
		}

		if (miss)
		{
			if (_hit || _psi)
			{
				optValue(anim, weaponRule->getMeleeMissAnimation());
				if (_psi)
				{
					// psi attack sound is based weapon hit sound
					optValue(sound, weaponRule->getHitMissSound());

					optValue(anim, weaponRule->getPsiMissAnimation());
					optValue(sound, weaponRule->getPsiMissSound());
				}
				else
				{
					optValue(sound, weaponRule->getMeleeMissSound());
					if (damageRule)
					{
						optValue(anim, damageRule->getMeleeMissAnimation());
						optValue(sound, damageRule->getMeleeMissSound());
					}
				}
			}
			else
			{
				optValue(anim, itemRule->getHitMissAnimation());
				optValue(sound, itemRule->getHitMissSound());
			}
		}

		if (anim != -1)
		{
			Explosion *explosion = new Explosion(_center, anim, 0, false, (_hit || _psi)); // Don't burn the tile
			_parent->getMap()->getExplosions()->push_back(explosion);
			_explosions.push_back(explosion);
		}

		_parent->getMap()->getCamera()->setViewLevel(_center.z / 24);

		if (_targetPsiOrHit && _parent->getSave()->getSide() == FACTION_HOSTILE && _targetPsiOrHit->getFaction() == FACTION_PLAYER)
		{
			_parent->getMap()->getCamera()->centerOnPosition(_center.toTile(), false);
		}
		// bullet hit sound
		_parent->playSound(sound, _center.toTile());
	}

	if (_action.type != BA_MINDCONTROL && _action.type != BA_PANIC && _action.type != BA_CLAIRVOYANCE && _action.type != BA_MINDBLAST)
	{
		explode();
	}
	else
	{
		_delayExplosion = true;
	}
}
Example #14
0
/**
 * Calculates the effects of the explosion.
 */
void ExplosionBState::explode()
{
	bool terrainExplosion = false;
	SavedBattleGame *save = _parent->getSave();
	// last minute adjustment: determine if we actually
	if (_hit)
	{
		if (_attack.attacker && !_attack.attacker->isOut())
		{
			_attack.attacker->aim(false);
		}

		if (_power <= 0)
		{
			_parent->popState();
			return;
		}

		int sound = _attack.weapon_item->getRules()->getMeleeHitSound();
		if (_attack.weapon_item != _attack.damage_item)
		{
			// melee weapon with ammo
			optValue(sound, _attack.damage_item->getRules()->getMeleeHitSound());
		}
		_parent->playSound(sound, _center.toTile());
	}

	bool range = !(_hit || (_attack.weapon_item && _attack.weapon_item->getRules()->getBattleType() == BT_PSIAMP));

	// after the animation is done, the real explosion/hit takes place
	/*if (_item)
	{
		if (!_unit && _item->getPreviousOwner())
		{
			_unit = _item->getPreviousOwner();
		}*/

	if (_areaOfEffect)
	{
		save->getTileEngine()->explode(_attack, _center, _power, _damageType, _radius, range);
	}
	else //if (!_cosmetic)
	{

		if (_damageType->ResistType == DT_TELEPORT)
		{
			Tile *destination = _tile ? _tile : save->getTile(Position(_center.x / 16, _center.y / 16, _center.z / 24));
			if (_attack.attacker && destination && !destination->getUnit())
			{
				save->getTile(_attack.attacker->getPosition())->setUnit(0);
				const Position& oldPosition = _attack.attacker->getPosition();
				_attack.attacker->setPosition(destination->getPosition());
				destination->setUnit(_attack.attacker);
				save->getTileEngine()->calculateFOV(oldPosition);
				save->getTileEngine()->calculateFOV(destination->getPosition());
			}
		}
		else
		{
			BattleUnit *victim = save->getTileEngine()->hit(_attack, _center, _power, _action.type, _damageType, range);

			const RuleItem *hitItem = _attack.damage_item->getRules();

			// check if this unit turns others into zombies
			if (!hitItem->getZombieUnit().empty()
				&& RNG::percent(hitItem->getSpecialChance())
				&& victim
				&& victim->getArmor()->getZombiImmune() == false
				&& victim->getSpawnUnit().empty()
				&& victim->getOriginalFaction() != FACTION_HOSTILE)
			{
				// converts the victim to a zombie on death
				victim->setRespawn(true);
				victim->setSpawnUnit(hitItem->getZombieUnit());
			}
		}
	}
	//}

	if (_tile)
	{
		/*ItemDamageType DT;
		switch (_tile->getExplosiveType())
		{
		case 0:
			DT = DT_HE;
			break;
		case 5:
			DT = DT_IN;
			break;
		case 6:
			DT = DT_STUN;
			break;
		default:
			DT = DT_SMOKE;
			break;
		}
		if (DT != DT_HE)
		{
			_tile->setExplosive(0, 0, true);
		}
		save->getTileEngine()->explode(_center, _power, _parent->getCurrentAction()->type, DT, _power / 10, 0);*/
		terrainExplosion = true;
	}
	if (!_tile && !_attack.damage_item)
	{
		/*int radius = 6;
		// explosion not caused by terrain or an item, must be by a unit (cyberdisc)
		if (_unit && (_unit->getSpecialAbility() == SPECAB_EXPLODEONDEATH || _unit->getSpecialAbility() == SPECAB_BURN_AND_EXPLODE))
		{
			radius = _parent->getMod()->getItem(_unit->getArmor()->getCorpseGeoscape(), true)->getExplosionRadius();
		}
		save->getTileEngine()->explode(_center, _power, _parent->getCurrentAction()->type, DT_HE, radius, 0);*/
		terrainExplosion = true;
	}

	// now check for new casualties
	_parent->checkForCasualties(_damageType, _attack, false, terrainExplosion, _subState);
	// revive units if damage could give hp or reduce stun
	_parent->getSave()->reviveUnconsciousUnits(true);

	// if this explosion was caused by a unit shooting, now it's the time to put the gun down
	if (_attack.attacker && !_attack.attacker->isOut() && _lowerWeapon)
	{
		_attack.attacker->aim(false);
	}

	if (_attack.damage_item && (_attack.damage_item->getRules()->getBattleType() == BT_GRENADE || _attack.damage_item->getRules()->getBattleType() == BT_PROXIMITYGRENADE))
	{
		_parent->getSave()->removeItem(_attack.damage_item);
	}
	//_finished = true;
	//if(!_subState) _parent->popState();

	// check for terrain explosions
	Tile *t = save->getTileEngine()->checkForTerrainExplosions();
	if (t)
	{
		Position p = t->getPosition().toVexel();
		p += Position(8, 8, 0);
		{
			//_parent->statePushFront(new ExplosionBState(_parent, p, BattleActionAttack{ BA_NONE, _attack.attacker, }, t));
			if (!_subState)
			{
				_parent->statePushFront(new ExplosionBState(_parent, p, BattleActionAttack{ BA_NONE, _attack.attacker, }, t));
			}
			else
			{
				_terrainExplosion = new ExplosionBState(_parent, p, BattleActionAttack{ BA_NONE, _attack.attacker, }, t, false, false, true);
			}
		}
	}
}