Esempio n. 1
0
bool GlobalEvents::registerEvent(Event* event, const pugi::xml_node&)
{
	GlobalEvent* globalEvent = reinterpret_cast<GlobalEvent*>(event);
	if (globalEvent->getEventType() == GLOBALEVENT_TIMER) {
		auto result = timerMap.emplace(globalEvent->getName(), globalEvent);
		if (result.second) {
			if (timerEventId == 0) {
				timerEventId = g_scheduler.addEvent(createSchedulerTask(SCHEDULER_MINTICKS, std::bind(&GlobalEvents::timer, this)));
			}
			return true;
		}
	} else if (globalEvent->getEventType() != GLOBALEVENT_NONE) {
		auto result = serverMap.emplace(globalEvent->getName(), globalEvent);
		if (result.second) {
			return true;
		}
	} else { // think event
		auto result = thinkMap.emplace(globalEvent->getName(), globalEvent);
		if (result.second) {
			if (thinkEventId == 0) {
				thinkEventId = g_scheduler.addEvent(createSchedulerTask(SCHEDULER_MINTICKS, std::bind(&GlobalEvents::think, this)));
			}
			return true;
		}
	}

	std::cout << "[Warning - GlobalEvents::configureEvent] Duplicate registered globalevent with name: " << globalEvent->getName() << std::endl;
	return false;
}
Esempio n. 2
0
bool GlobalEvents::registerLuaEvent(Event* event)
{
	GlobalEvent_ptr globalEvent{ static_cast<GlobalEvent*>(event) }; //event is guaranteed to be a GlobalEvent
	if (globalEvent->getEventType() == GLOBALEVENT_TIMER) {
		auto result = timerMap.emplace(globalEvent->getName(), std::move(*globalEvent));
		if (result.second) {
			if (timerEventId == 0) {
				timerEventId = g_scheduler.addEvent(createSchedulerTask(SCHEDULER_MINTICKS, std::bind(&GlobalEvents::timer, this)));
			}
			return true;
		}
	} else if (globalEvent->getEventType() != GLOBALEVENT_NONE) {
		auto result = serverMap.emplace(globalEvent->getName(), std::move(*globalEvent));
		if (result.second) {
			return true;
		}
	} else { // think event
		auto result = thinkMap.emplace(globalEvent->getName(), std::move(*globalEvent));
		if (result.second) {
			if (thinkEventId == 0) {
				thinkEventId = g_scheduler.addEvent(createSchedulerTask(SCHEDULER_MINTICKS, std::bind(&GlobalEvents::think, this)));
			}
			return true;
		}
	}

	std::cout << "[Warning - GlobalEvents::configureEvent] Duplicate registered globalevent with name: " << globalEvent->getName() << std::endl;
	return false;
}
Esempio n. 3
0
void ServicePort::open(uint16_t port)
{
	m_serverPort = port;
	m_pendingStart = false;

	try{
		if(g_config.getNumber(ConfigManager::BIND_ONLY_GLOBAL_ADDRESS))
		{
			m_acceptor = new boost::asio::ip::tcp::acceptor(m_io_service, boost::asio::ip::tcp::endpoint(
				boost::asio::ip::address(boost::asio::ip::address_v4::from_string(g_config.getString(ConfigManager::IP))), m_serverPort));
		}
		else
		{
			m_acceptor = new boost::asio::ip::tcp::acceptor(m_io_service, boost::asio::ip::tcp::endpoint(
				boost::asio::ip::address(boost::asio::ip::address_v4(INADDR_ANY)), m_serverPort));
		}
		m_acceptor->set_option(boost::asio::ip::tcp::no_delay(true));
		accept();
	}
	catch(boost::system::system_error& e){
		if(m_logError){
			LOG_MESSAGE("NETWORK", LOGTYPE_ERROR, 1, e.what());
			m_logError = false;
		}

		m_pendingStart = true;
		g_scheduler.addEvent(createSchedulerTask(5000,
			boost::bind(&ServicePort::openAcceptor, boost::weak_ptr<ServicePort>(shared_from_this()), port)));
	}
}
Esempio n. 4
0
void Spawn::checkSpawn()
{
#ifdef __DEBUG_SPAWN__
	std::clog << "[Notice] Spawn::checkSpawn " << this << std::endl;
#endif
	Monster* monster;
	uint32_t spawnId;

	checkSpawnEvent = 0;
	for(SpawnedMap::iterator it = spawnedMap.begin(); it != spawnedMap.end();)
	{
		spawnId = it->first;
		monster = it->second;
		if(monster->isRemoved())
		{
			if(spawnId)
				spawnMap[spawnId].lastSpawn = OTSYS_TIME();

			monster->unRef();
			spawnedMap.erase(it++);
		}
		else
		{
			/*if(spawnId && !isInSpawnZone(monster->getPosition()) && monster->getIdleStatus())
				g_game.internalTeleport(monster, monster->getMasterPosition(), true);

			*/++it;
		}
	}

	uint32_t spawnCount = 0;
	for(SpawnMap::iterator it = spawnMap.begin(); it != spawnMap.end(); ++it)
	{
		spawnId = it->first;
		spawnBlock_t& sb = it->second;
		if(spawnedMap.count(spawnId))
			continue;

		if(OTSYS_TIME() < sb.lastSpawn + sb.interval)
			continue;

		if(findPlayer(sb.pos))
		{
			sb.lastSpawn = OTSYS_TIME();
			continue;
		}

		spawnMonster(spawnId, sb.mType, sb.pos, sb.direction);
		++spawnCount;
		if(spawnCount >= (uint32_t)g_config.getNumber(ConfigManager::RATE_SPAWN))
			break;
	}

	if(spawnedMap.size() < spawnMap.size())
		checkSpawnEvent = Scheduler::getInstance().addEvent(createSchedulerTask(getInterval(), boost::bind(&Spawn::checkSpawn, this)));
#ifdef __DEBUG_SPAWN__
	else
		std::clog << "[Notice] Spawn::checkSpawn stopped " << this << std::endl;
#endif
}
Esempio n. 5
0
void ServicePort::open(uint16_t port)
{
	close();

	m_serverPort = port;
	m_pendingStart = false;

	try {
		if (g_config.getBoolean(ConfigManager::BIND_ONLY_GLOBAL_ADDRESS)) {
			m_acceptor = new boost::asio::ip::tcp::acceptor(m_io_service, boost::asio::ip::tcp::endpoint(
			            boost::asio::ip::address(boost::asio::ip::address_v4::from_string(g_config.getString(ConfigManager::IP))), m_serverPort));
		} else {
			m_acceptor = new boost::asio::ip::tcp::acceptor(m_io_service, boost::asio::ip::tcp::endpoint(
			            boost::asio::ip::address(boost::asio::ip::address_v4(INADDR_ANY)), m_serverPort));
		}

		m_acceptor->set_option(boost::asio::ip::tcp::no_delay(true));

		accept();
	} catch (boost::system::system_error& e) {
		std::cout << "[ServicePort::open] Error: " << e.what() << std::endl;

		m_pendingStart = true;
		g_scheduler.addEvent(createSchedulerTask(15000,
		                     boost::bind(&ServicePort::openAcceptor, boost::weak_ptr<ServicePort>(shared_from_this()), port)));
	}
}
Esempio n. 6
0
bool ChatChannel::addUser(Player& player)
{
	if (users.find(player.getID()) != users.end()) {
		return false;
	}

	if (onJoinEvent && onJoinEvent->execute(player)) {
		return false;
	}

	if (id == CHANNEL_GUILD) {
		Guild* guild = player.getGuild();
		if (guild && !guild->getMotd().empty()) {
			g_scheduler.addEvent(createSchedulerTask(150, boost::bind(&Game::sendGuildMotd, &g_game, player.getID(), guild->getId())));
		}
	}

	if (publicChannel) {
		for (const auto& it : users) {
			it.second->sendChannelEvent(id, player.getName(), CHANNELEVENT_JOIN);
		}
	}

	users[player.getID()] = &player;
	return true;
}
Esempio n. 7
0
void ServicePort::open(IPAddressList ips, uint16_t port)
{
  m_serverPort = port;
  m_pendingStart = false;

  for(IPAddressList::iterator ip = ips.begin(); ip != ips.end(); ++ip){
    try{
      // std::cout << "\n" << ip->to_string() << "\n";
      Acceptor_ptr aptr(new boost::asio::ip::tcp::acceptor(m_io_service, boost::asio::ip::tcp::endpoint(*ip, m_serverPort)));

      aptr->set_option(boost::asio::ip::tcp::no_delay(true));

      accept(aptr);
      m_tcp_acceptors.push_back(aptr);
    }
    catch(boost::system::system_error& e){
      if(m_logError){
        LOG_MESSAGE("NETWORK", LOGTYPE_ERROR, 1, e.what());
        m_logError = false;
      }

      m_pendingStart = true;
      g_scheduler.addEvent(createSchedulerTask(5000,
        boost::bind(&ServicePort::openAcceptor, boost::weak_ptr<ServicePort>(shared_from_this()), *ip, port)));
    }
  }
}
Esempio n. 8
0
void Raids::checkRaids()
{
	if(!getRunning()){
		uint64_t now = OTSYS_TIME();
		for(RaidList::iterator it = raidList.begin(); it != raidList.end(); ++it){
			if(now >= (getLastRaidEnd() + (*it)->getMargin())){
				if(MAX_RAND_RANGE*CHECK_RAIDS_INTERVAL/(*it)->getInterval() >= (uint32_t)random_range(0, MAX_RAND_RANGE)){
#ifdef __DEBUG_RAID__
					char buffer[32];
					time_t tmp = time(NULL);
					formatDate(tmp, buffer);
					std::cout << buffer << " [Notice] Raids: Starting raid " << (*it)->getName() << std::endl;
#endif
					setRunning(*it);
					(*it)->startRaid();
					break;
				}
			}

		}
	}

	 checkRaidsEvent = Scheduler::getScheduler().addEvent(createSchedulerTask(CHECK_RAIDS_INTERVAL*1000, 
	     boost::bind(&Raids::checkRaids, this)));
}
Esempio n. 9
0
bool ChatChannel::addUser(Player& player)
{
	if (users.find(player.getID()) != users.end()) {
		return false;
	}

	if (!executeOnJoinEvent(player)) {
		return false;
	}

	// TODO: Move to script when guild channels can be scripted
	if (id == CHANNEL_GUILD) {
		Guild* guild = player.getGuild();
		if (guild && !guild->getMotd().empty()) {
			g_scheduler.addEvent(createSchedulerTask(150, std::bind(&Game::sendGuildMotd, &g_game, player.getID())));
		}
	}

	if (!publicChannel) {
		for (const auto& it : users) {
			it.second->sendChannelEvent(id, player.getName(), CHANNELEVENT_JOIN);
		}
	}

	users[player.getID()] = &player;
	return true;
}
Esempio n. 10
0
void Spawn::checkSpawn()
{
	checkSpawnEvent = 0;

	cleanup();

	uint32_t spawnCount = 0;
	uint32_t spawnId;

	for (SpawnMap::iterator it = spawnMap.begin(); it != spawnMap.end(); ++it) {
		spawnId = it->first;
		spawnBlock_t& sb = it->second;

		if (spawnedMap.find(spawnId) == spawnedMap.end()) {
			if (OTSYS_TIME() >= sb.lastSpawn + sb.interval) {
				if (findPlayer(sb.pos)) {
					sb.lastSpawn = OTSYS_TIME();
					continue;
				}

				spawnMonster(spawnId, sb.mType, sb.pos, sb.direction);

				++spawnCount;

				if (spawnCount >= (uint32_t)g_config.getNumber(ConfigManager::RATE_SPAWN)) {
					break;
				}
			}
		}
	}

	if (spawnedMap.size() < spawnMap.size()) {
		checkSpawnEvent = g_scheduler.addEvent(createSchedulerTask(getInterval(), boost::bind(&Spawn::checkSpawn, this)));
	}
}
Esempio n. 11
0
void ServicePort::handle(Acceptor_ptr acceptor, boost::asio::ip::tcp::socket* socket, const boost::system::error_code& error)
{
	if(!error)
	{
		if(m_services.empty())
		{
#ifdef __DEBUG_NET__
			std::clog << "[Error - ServerPort::handle] No services running!" << std::endl;
#endif
			return;
		}

		boost::system::error_code error;
		const boost::asio::ip::tcp::endpoint ip = socket->remote_endpoint(error);

		uint32_t remoteIp = 0;
		if(!error)
			remoteIp = htonl(ip.address().to_v4().to_ulong());

		Connection_ptr connection;
		if(remoteIp && ConnectionManager::getInstance()->acceptConnection(remoteIp) &&
			(connection = ConnectionManager::getInstance()->createConnection(
			socket, m_io_service, shared_from_this())))
		{
			if(m_services.front()->isSingleSocket())
				connection->handle(m_services.front()->makeProtocol(connection));
			else
				connection->accept();
		}
		else if(socket->is_open())
		{
			boost::system::error_code error;
			socket->shutdown(boost::asio::ip::tcp::socket::shutdown_both, error);

			socket->close(error);
			delete socket;
		}

#ifdef __DEBUG_NET_DETAIL__
		std::clog << "handle - OK" << std::endl;
#endif
		accept(acceptor);
	}
	else if(error != boost::asio::error::operation_aborted)
	{
		PRINT_ASIO_ERROR("Handling");
		close();
		if(!m_pendingStart)
		{
			m_pendingStart = true;
			Scheduler::getInstance().addEvent(createSchedulerTask(5000, boost::bind(
				&ServicePort::service, boost::weak_ptr<ServicePort>(shared_from_this()),
				m_acceptors[acceptor], m_serverPort)));
		}
	}
#ifdef __DEBUG_NET__
	else
		std::clog << "[Error - ServerPort::handle] Operation aborted." << std::endl;
#endif
}
void ServicePort::open(uint16_t port)
{
	m_serverPort = port;
	m_pendingStart = false;
	try
	{
		if(g_config.getBool(ConfigManager::BIND_IP_ONLY))
			m_acceptor = new boost::asio::ip::tcp::acceptor(m_io_service, boost::asio::ip::tcp::endpoint(
				boost::asio::ip::address(boost::asio::ip::address_v4::from_string(
				g_config.getString(ConfigManager::IP))), m_serverPort));
		else
			m_acceptor = new boost::asio::ip::tcp::acceptor(m_io_service, boost::asio::ip::tcp::endpoint(
				boost::asio::ip::address(boost::asio::ip::address_v4(INADDR_ANY)), m_serverPort));

		accept();
	}
	catch(boost::system::system_error& e)
	{
		if(m_logError)
		{
			LOG_MESSAGE(LOGTYPE_ERROR, e.what(), "NETWORK")
			m_logError = false;
		}

		m_pendingStart = true;
		Scheduler::getInstance().addEvent(createSchedulerTask(5000, boost::bind(
			&ServicePort::onOpen, boost::weak_ptr<ServicePort>(shared_from_this()), m_serverPort)));
	}
}
Esempio n. 13
0
bool ChatChannel::addUser(Player* player)
{
	if (m_users.find(player->getID()) != m_users.end()) {
		return false;
	}

	if (m_id == CHANNEL_GUILD) {
		Guild* guild = player->getGuild();

		if (guild && !guild->getMotd().empty()) {
			g_scheduler.addEvent(createSchedulerTask(150, boost::bind(
			                         &Game::sendGuildMotd, &g_game, player->getID(), guild->getId())));
		}
	}

	if (m_id == CHANNEL_GUILD || m_id == CHANNEL_PARTY || m_id == CHANNEL_PRIVATE) {
		for (UsersMap::const_iterator cit = m_users.begin(); cit != m_users.end(); ++cit) {
			Player* tmpPlayer = cit->second->getPlayer();
			if (tmpPlayer) {
				tmpPlayer->sendChannelEvent(m_id, player->getName(), CHANNELEVENT_JOIN);
			}
		}
	}

	m_users[player->getID()] = player;
	return true;
}
Esempio n. 14
0
void Creature::removeCondition(ConditionType_t type, ConditionId_t id, bool force/* = false*/)
{
	ConditionList::iterator it = conditions.begin();
	while (it != conditions.end()) {
		Condition* condition = *it;
		if (condition->getType() != type || condition->getId() != id) {
			++it;
			continue;
		}

		if (!force && condition->getType() == CONDITION_PARALYZE) {
			int64_t walkDelay = getWalkDelay();
			if (walkDelay > 0) {
				g_scheduler.addEvent(createSchedulerTask(walkDelay, boost::bind(&Game::forceRemoveCondition, &g_game, getID(), type)));
				return;
			}
		}

		it = conditions.erase(it);

		condition->endCondition(this, CONDITIONEND_ABORT);
		delete condition;

		onEndCondition(type);
	}
}
Esempio n. 15
0
void BedItem::sleep(Player* player)
{
	if(!house || !player || player->isRemoved())
		return;

	if(!sleeper)
	{
		Beds::getInstance().setBedSleeper(this, player->getGUID());
		internalSetSleeper(player);

		BedItem* nextBedItem = getNextBedItem();
		if(nextBedItem)
			nextBedItem->internalSetSleeper(player);

		updateAppearance(player);
		if(nextBedItem)
			nextBedItem->updateAppearance(player);

		player->getTile()->moveCreature(NULL, player, getTile());
		g_game.addMagicEffect(player->getPosition(), NM_ME_SLEEP);
		Scheduler::getScheduler().addEvent(createSchedulerTask(SCHEDULER_MINTICKS, boost::bind(&Game::kickPlayer, &g_game, player->getID(), false)));
	}
	else if(Item::items[getID()].transformToFree)
	{
		wakeUp();
		g_game.addMagicEffect(player->getPosition(), NM_ME_POFF);
	}
	else
		player->sendCancelMessage(RET_NOTPOSSIBLE);
}
Esempio n. 16
0
void Commands::forceRaid(Player& player, const std::string& param)
{
	Raid* raid = Raids::getInstance()->getRaidByName(param);
	if (!raid || !raid->isLoaded()) {
		player.sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "No such raid exists.");
		return;
	}

	if (Raids::getInstance()->getRunning()) {
		player.sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Another raid is already being executed.");
		return;
	}

	Raids::getInstance()->setRunning(raid);

	RaidEvent* event = raid->getNextRaidEvent();
	if (!event) {
		player.sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "The raid does not contain any data.");
		return;
	}

	raid->setState(RAIDSTATE_EXECUTING);

	uint32_t ticks = event->getDelay();
	if (ticks > 0) {
		g_scheduler.addEvent(createSchedulerTask(ticks, std::bind(&Raid::executeRaidEvent, raid, event)));
	} else {
		g_dispatcher.addTask(createTask(std::bind(&Raid::executeRaidEvent, raid, event)));
	}

	player.sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Raid started.");
}
Esempio n. 17
0
void GlobalEvents::think()
{
	int64_t now = OTSYS_TIME();

	int64_t nextScheduledTime = std::numeric_limits<int64_t>::max();
	for (auto& it : thinkMap) {
		GlobalEvent& globalEvent = it.second;

		int64_t nextExecutionTime = globalEvent.getNextExecution() - now;
		if (nextExecutionTime > 0) {
			if (nextExecutionTime < nextScheduledTime) {
				nextScheduledTime = nextExecutionTime;
			}
			continue;
		}

		if (!globalEvent.executeEvent()) {
			std::cout << "[Error - GlobalEvents::think] Failed to execute event: " << globalEvent.getName() << std::endl;
		}

		nextExecutionTime = globalEvent.getInterval();
		if (nextExecutionTime < nextScheduledTime) {
			nextScheduledTime = nextExecutionTime;
		}

		globalEvent.setNextExecution(globalEvent.getNextExecution() + nextExecutionTime);
	}

	if (nextScheduledTime != std::numeric_limits<int64_t>::max()) {
		thinkEventId = g_scheduler.addEvent(createSchedulerTask(nextScheduledTime, std::bind(&GlobalEvents::think, this)));
	}
}
Esempio n. 18
0
bool IOGuild::updateWar(War_t& war)
{
	Database* db = Database::getInstance();
	DBResult* result;

	DBQuery query;
	query << "SELECT `g`.`name` AS `guild_name`, `e`.`name` AS `enemy_name`, `w`.* FROM `guild_wars` w LEFT JOIN `guilds` g ON `w`.`guild_id` = `g`.`id` LEFT JOIN `guilds` e ON `w`.`enemy_id` = `e`.`id` WHERE `w`.`id` = " << war.war;
	if(!(result = db->storeQuery(query.str())))
		return false;

	war.ids[WAR_GUILD] = result->getDataInt("guild_id");
	war.ids[WAR_ENEMY] = result->getDataInt("enemy_id");
	war.names[WAR_GUILD] = result->getDataString("guild_name");
	war.names[WAR_ENEMY] = result->getDataString("enemy_name");

	war.frags[WAR_GUILD] = result->getDataInt("guild_kills");
	war.frags[WAR_ENEMY] = result->getDataInt("enemy_kills");
	war.frags[war.type]++;

	war.limit = result->getDataInt("frags");
	war.payment = result->getDataInt("payment");

	result->free();
	if(war.frags[WAR_GUILD] >= war.limit || war.frags[WAR_ENEMY] >= war.limit)
	{
		Scheduler::getInstance().addEvent(createSchedulerTask(1000,
			boost::bind(&IOGuild::finishWar, this, war, true)));
		return true;
	}

	query.str("");
	query << "UPDATE `guild_wars` SET `guild_kills` = " << war.frags[WAR_GUILD] << ", `enemy_kills` = " << war.frags[WAR_ENEMY] << " WHERE `id` = " << war.war;
	return db->query(query.str());
}
Esempio n. 19
0
void Spawn::checkSpawn()
{
	checkSpawnEvent = 0;

	cleanup();

	uint32_t spawnCount = 0;

	for (auto& it : spawnMap) {
		uint32_t spawnId = it.first;
		if (spawnedMap.find(spawnId) != spawnedMap.end()) {
			continue;
		}

		spawnBlock_t& sb = it.second;
		if (OTSYS_TIME() >= sb.lastSpawn + sb.interval) {
			if (findPlayer(sb.pos)) {
				sb.lastSpawn = OTSYS_TIME();
				continue;
			}

			spawnMonster(spawnId, sb.mType, sb.pos, sb.direction);
			if (++spawnCount >= static_cast<uint32_t>(g_config.getNumber(ConfigManager::RATE_SPAWN))) {
				break;
			}
		}
	}

	if (spawnedMap.size() < spawnMap.size()) {
		checkSpawnEvent = g_scheduler.addEvent(createSchedulerTask(getInterval(), std::bind(&Spawn::checkSpawn, this)));
	}
}
Esempio n. 20
0
void Creature::addEventWalk(bool firstStep)
{
	cancelNextWalk = false;

	if (getStepSpeed() <= 0) {
		return;
	}

	if (eventWalk != 0) {
		return;
	}

	int64_t ticks = getEventStepTicks(firstStep);

	if (ticks <= 0) {
		return;
	}

	// Take first step right away, but still queue the next
	if (ticks == 1) {
		g_game.checkCreatureWalk(getID());
	}

	eventWalk = g_scheduler.addEvent(createSchedulerTask(
	                                     std::max<int64_t>(SCHEDULER_MINTICKS, ticks), boost::bind(&Game::checkCreatureWalk, &g_game, getID())));
}
Esempio n. 21
0
void Creature::removeCondition(ConditionType_t type, bool force/* = false*/)
{
	auto it = conditions.begin(), end = conditions.end();
	while (it != end) {
		Condition* condition = *it;
		if (condition->getType() != type) {
			++it;
			continue;
		}

		if (!force && type == CONDITION_PARALYZE) {
			int64_t walkDelay = getWalkDelay();
			if (walkDelay > 0) {
				g_scheduler.addEvent(createSchedulerTask(walkDelay, std::bind(&Game::forceRemoveCondition, &g_game, getID(), type)));
				return;
			}
		}

		it = conditions.erase(it);

		condition->endCondition(this);
		delete condition;

		onEndCondition(type);
	}
}
Esempio n. 22
0
bool Creature::addCondition(Condition* condition, bool force/* = false*/)
{
	if (condition == NULL) {
		return false;
	}

	if (!force && condition->getType() == CONDITION_HASTE && hasCondition(CONDITION_PARALYZE)) {
		int64_t walkDelay = getWalkDelay();
		if (walkDelay > 0) {
			g_scheduler.addEvent(createSchedulerTask(walkDelay, boost::bind(&Game::forceAddCondition, &g_game, getID(), condition)));
			return false;
		}
	}

	Condition* prevCond = getCondition(condition->getType(), condition->getId(), condition->getSubId());
	if (prevCond) {
		prevCond->addCondition(this, condition);
		delete condition;
		return true;
	}

	if (condition->startCondition(this)) {
		conditions.push_back(condition);
		onAddCondition(condition->getType());
		return true;
	}

	delete condition;
	return false;
}
Esempio n. 23
0
void Connection::releaseConnection()
{
	if(m_refCount > 0) //Reschedule it and try again.
		Scheduler::getInstance().addEvent(createSchedulerTask(SCHEDULER_MINTICKS,
			boost::bind(&Connection::releaseConnection, this)));
	else
		deleteConnection();
}
Esempio n. 24
0
void Raid::startRaid()
{
    RaidEvent* raidEvent = getNextRaidEvent();
    if (raidEvent) {
        state = RAIDSTATE_EXECUTING;
        nextEventEvent = g_scheduler.addEvent(createSchedulerTask(raidEvent->getDelay(), std::bind(&Raid::executeRaidEvent, this, raidEvent)));
    }
}
Esempio n. 25
0
void Connection::releaseConnection()
{
	if (m_refCount > 0) {
		//Reschedule it and try again.
		g_scheduler.addEvent(createSchedulerTask(SCHEDULER_MINTICKS, std::bind(&Connection::releaseConnection, this)));
	} else {
		deleteConnectionTask();
	}
}
Esempio n. 26
0
void Creature::addEventWalk()
{
	if(eventWalk)
		return;

	int64_t ticks = getEventStepTicks();
	if(ticks > 0)
		eventWalk = Scheduler::getInstance().addEvent(createSchedulerTask(ticks,
			boost::bind(&Game::checkCreatureWalk, &g_game, getID())));
}
Esempio n. 27
0
bool GlobalEvents::registerEvent(Event* event, const pugi::xml_node& node)
{
	GlobalEvent* globalEvent = dynamic_cast<GlobalEvent*>(event);
	if (!globalEvent) {
		return false;
	}

	if (globalEvent->getEventType() == GLOBALEVENT_TIMER) {
		GlobalEventMap::iterator it = timerMap.find(globalEvent->getName());
		if (it == timerMap.end()) {
			timerMap.insert(std::make_pair(globalEvent->getName(), globalEvent));
			if (timerEventId == 0) {
				timerEventId = g_scheduler.addEvent(createSchedulerTask(SCHEDULER_MINTICKS,
				                                    boost::bind(&GlobalEvents::timer, this)));
			}

			return true;
		}
	} else if (globalEvent->getEventType() != GLOBALEVENT_NONE) {
		GlobalEventMap::iterator it = serverMap.find(globalEvent->getName());
		if (it == serverMap.end()) {
			serverMap.insert(std::make_pair(globalEvent->getName(), globalEvent));
			return true;
		}
	} else { // think event
		GlobalEventMap::iterator it = thinkMap.find(globalEvent->getName());

		if (it == thinkMap.end()) {
			thinkMap.insert(std::make_pair(globalEvent->getName(), globalEvent));

			if (thinkEventId == 0) {
				thinkEventId = g_scheduler.addEvent(createSchedulerTask(SCHEDULER_MINTICKS,
				                                    boost::bind(&GlobalEvents::think, this)));
			}

			return true;
		}
	}

	std::cout << "[Warning - GlobalEvents::configureEvent] Duplicate registered globalevent with name: " << globalEvent->getName() << std::endl;
	return false;
}
Esempio n. 28
0
void Creature::addEventWalk()
{
	if(eventWalk == 0){
		//std::cout << "addEventWalk() - " << getName() << std::endl;

		int64_t ticks = getEventStepTicks();
		if(ticks > 0){
			eventWalk = g_scheduler.addEvent(createSchedulerTask(
				ticks, boost::bind(&Game::checkCreatureWalk, &g_game, getID())));
		}
	}
}
Esempio n. 29
0
void Raids::startup()
{
	if(!isLoaded() || isStarted())
		return;

	setLastRaidEnd(OTSYS_TIME());

	checkRaidsEvent = Scheduler::getScheduler().addEvent(createSchedulerTask(CHECK_RAIDS_INTERVAL*1000,
        boost::bind(&Raids::checkRaids, this)));

	started = true;
}
Esempio n. 30
0
bool Raids::startup()
{
	if(!isLoaded() || isStarted())
		return false;

	setLastRaidEnd(OTSYS_TIME());

	checkRaidsEvent = g_scheduler.addEvent(createSchedulerTask(CHECK_RAIDS_INTERVAL * 1000, boost::bind(&Raids::checkRaids, this)));

	started = true;
	return started;
}