本文整理汇总了C++中OTSYS_TIME函数的典型用法代码示例。如果您正苦于以下问题:C++ OTSYS_TIME函数的具体用法?C++ OTSYS_TIME怎么用?C++ OTSYS_TIME使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了OTSYS_TIME函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: OTSYS_TIME
void Raids::checkRaids()
{
if (!getRunning()) {
uint64_t now = OTSYS_TIME();
for (auto it = raidList.begin(), end = raidList.end(); it != end; ++it) {
Raid* raid = *it;
if (now >= (getLastRaidEnd() + raid->getMargin())) {
if (((MAX_RAND_RANGE * CHECK_RAIDS_INTERVAL) / raid->getInterval()) >= static_cast<uint32_t>(uniform_random(0, MAX_RAND_RANGE))) {
setRunning(raid);
raid->startRaid();
if (!raid->canBeRepeated()) {
raidList.erase(it);
}
break;
}
}
}
}
checkRaidsEvent = g_scheduler.addEvent(createSchedulerTask(CHECK_RAIDS_INTERVAL * 1000, std::bind(&Raids::checkRaids, this)));
}
开发者ID:Zbizu,项目名称:forgottenserver,代码行数:23,代码来源:raids.cpp
示例2: useItem
bool Actions::useItem(Player* player, const Position& pos, uint8_t index, Item* item, bool isHotkey)
{
if (!player->canDoAction()) {
return false;
}
player->setNextActionTask(nullptr);
player->setNextAction(OTSYS_TIME() + g_config.getNumber(ConfigManager::ACTIONS_DELAY_INTERVAL));
player->stopWalk();
if (isHotkey) {
showUseHotkeyMessage(player, item->getID(), player->__getItemTypeCount(item->getID(), -1));
}
ReturnValue ret = internalUseItem(player, pos, index, item, 0);
if (ret != RET_NOERROR) {
player->sendCancelMessage(ret);
return false;
}
return true;
}
开发者ID:caiohp,项目名称:forgottenserver,代码行数:23,代码来源:actions.cpp
示例3: lockClass
bool Ban::acceptConnection(uint32_t clientip)
{
std::lock_guard<std::recursive_mutex> lockClass(lock);
uint64_t currentTime = OTSYS_TIME();
auto it = ipConnectMap.find(clientip);
if (it == ipConnectMap.end()) {
ConnectBlock cb;
cb.lastAttempt = currentTime;
cb.blockTime = 0;
cb.count = 1;
ipConnectMap[clientip] = cb;
return true;
}
ConnectBlock& connectBlock = it->second;
if (connectBlock.blockTime > currentTime) {
connectBlock.blockTime += 250;
return false;
}
int64_t timeDiff = currentTime - connectBlock.lastAttempt;
connectBlock.lastAttempt = currentTime;
if (timeDiff <= 5000) {
if (++connectBlock.count > 5) {
connectBlock.count = 0;
if (timeDiff <= 500) {
connectBlock.blockTime = currentTime + 3000;
return false;
}
}
} else {
connectBlock.count = 1;
}
return true;
}
开发者ID:caiohp,项目名称:forgottenserver,代码行数:37,代码来源:ban.cpp
示例4: getLeader
bool Party::canUseSharedExperience(const Player* player) const
{
uint32_t highestLevel = getLeader()->getLevel();
for(PlayerVector::const_iterator it = memberList.begin(); it != memberList.end(); ++it){
if( (*it)->getLevel() > highestLevel){
highestLevel = (*it)->getLevel();
}
}
uint32_t minLevel = (int32_t)std::ceil(((float)(highestLevel) * 2) / 3);
if(player->getLevel() < minLevel){
return false;
}
const Position& leaderPos = getLeader()->getPosition();
const Position& memberPos = player->getPosition();
if(!Position::areInRange<30,30,1>(leaderPos, memberPos)){
return false;
}
if(!player->hasFlag(PlayerFlag_NotGainInFight)){
//check if the player has healed/attacked anything recently
CountMap::const_iterator it = pointMap.find(player->getID());
if(it == pointMap.end()){
return false;
}
uint64_t timeDiff = OTSYS_TIME() - it->second.ticks;
if(timeDiff > g_game.getInFightTicks()){
//player has not attacked or healed anyone for a period of infight ticks
return false;
}
}
return true;
}
开发者ID:Ablankzin,项目名称:server,代码行数:37,代码来源:party.cpp
示例5: getKind
void MagicField::onStepInField(const CreatureP& creature)
{
if(getId() == ITEM_MAGICWALL_SAFE || getId() == ITEM_WILDGROWTH_SAFE || isBlocking(creature.get()))
{
if(!creature->isGhost())
server.game().internalRemoveItem(creature.get(), this, 1);
return;
}
if(!getKind()->condition)
return;
Condition* condition = getKind()->condition->clone();
uint32_t ownerId = getOwner();
if(ownerId && !getTile()->hasFlag(TILESTATE_PVPZONE))
{
if(auto owner = server.world().getCreatureById(ownerId))
{
bool harmful = true;
if((server.game().getWorldType() == WORLD_TYPE_NO_PVP || getTile()->hasFlag(TILESTATE_NOPVPZONE))
&& (owner->getPlayer() || owner->hasController()))
harmful = false;
else if(Player* targetPlayer = creature->getPlayer())
{
if(owner->getPlayer() && Combat::isProtected(owner->getPlayer(), targetPlayer))
harmful = false;
}
if(!harmful || (OTSYS_TIME() - createTime) <= (uint32_t)server.configManager().getNumber(
ConfigManager::FIELD_OWNERSHIP) || creature->hasBeenAttacked(ownerId))
condition->setParam(CONDITIONPARAM_OWNER, ownerId);
}
}
creature->addCondition(condition);
}
开发者ID:novasdream,项目名称:tyano-core,代码行数:37,代码来源:combat.cpp
示例6: onWalk
void Creature::onWalk(Direction& dir)
{
int32_t drunk = -1;
if(!isSuppress(CONDITION_DRUNK))
{
Condition* condition = NULL;
for(ConditionList::const_iterator it = conditions.begin(); it != conditions.end(); ++it)
{
if(!(condition = *it) || condition->getType() != CONDITION_DRUNK)
continue;
int32_t subId = condition->getSubId();
if((!condition->getEndTime() || condition->getEndTime() >= OTSYS_TIME()) && subId > drunk)
drunk = subId;
}
}
if(drunk < 0)
return;
drunk += 25;
int32_t r = random_range(1, 100);
if(r > drunk)
return;
int32_t tmp = (drunk / 5);
if(r <= tmp)
dir = NORTH;
else if(r <= (tmp * 2))
dir = WEST;
else if(r <= (tmp * 3))
dir = SOUTH;
else if(r <= (tmp * 4))
dir = EAST;
g_game.internalCreatureSay(this, MSG_SPEAK_MONSTER_SAY, "Hicks!", isGhost());
}
开发者ID:Azuen,项目名称:RealOTX-7.72,代码行数:37,代码来源:creature.cpp
示例7: OTSYS_TIME
bool Party::canUseSharedExperience(const Player* player) const
{
if (memberList.empty()) {
return false;
}
uint32_t highestLevel = leader->getLevel();
for (Player* member : memberList) {
if (member->getLevel() > highestLevel) {
highestLevel = member->getLevel();
}
}
uint32_t minLevel = static_cast<int32_t>(std::ceil((static_cast<float>(highestLevel) * 2) / 3));
if (player->getLevel() < minLevel) {
return false;
}
if (!Position::areInRange<30, 30, 1>(leader->getPosition(), player->getPosition())) {
return false;
}
if (!player->hasFlag(PlayerFlag_NotGainInFight)) {
//check if the player has healed/attacked anything recently
auto it = ticksMap.find(player->getID());
if (it == ticksMap.end()) {
return false;
}
uint64_t timeDiff = OTSYS_TIME() - it->second;
if (timeDiff > static_cast<uint64_t>(g_config.getNumber(ConfigManager::PZ_LOCKED))) {
return false;
}
}
return true;
}
开发者ID:Alexo25,项目名称:forgottenserver,代码行数:36,代码来源:party.cpp
示例8: OTSYS_TIME
void Spawn::cleanup()
{
Monster* monster;
uint32_t spawnId;
for (SpawnedMap::iterator it = spawnedMap.begin(); it != spawnedMap.end();) {
spawnId = it->first;
monster = it->second;
if (monster->isRemoved()) {
if (spawnId != 0) {
spawnMap[spawnId].lastSpawn = OTSYS_TIME();
}
monster->releaseThing2();
spawnedMap.erase(it++);
} else if (!isInSpawnZone(monster->getPosition()) && spawnId != 0) {
spawnedMap.insert(spawned_pair(0, monster));
spawnedMap.erase(it++);
} else {
++it;
}
}
}
开发者ID:nclx,项目名称:forgottenserver,代码行数:24,代码来源:spawn.cpp
示例9: monster_ptr
bool Spawn::spawnMonster(uint32_t spawnId, MonsterType* mType, const Position& pos, Direction dir, bool startup /*= false*/)
{
std::unique_ptr<Monster> monster_ptr(new Monster(mType));
if (startup) {
//No need to send out events to the surrounding since there is no one out there to listen!
if (!g_game.internalPlaceCreature(monster_ptr.get(), pos, true)) {
return false;
}
} else {
if (!g_game.placeCreature(monster_ptr.get(), pos, false, true)) {
return false;
}
}
Monster* monster = monster_ptr.release();
monster->setDirection(dir);
monster->setSpawn(this);
monster->setMasterPos(pos);
monster->incrementReferenceCounter();
spawnedMap.insert(spawned_pair(spawnId, monster));
spawnMap[spawnId].lastSpawn = OTSYS_TIME();
return true;
}
开发者ID:Alissonfgp,项目名称:forgottenserver,代码行数:24,代码来源:spawn.cpp
示例10: OTSYS_TIME
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__
std::cout << formatDate(time(NULL)) << " [Notice] Raids: Starting raid " << (*it)->getName() << std::endl;
#endif
setRunning(*it);
(*it)->startRaid();
break;
}
}
}
}
checkRaidsEvent = g_scheduler.addEvent(createSchedulerTask(CHECK_RAIDS_INTERVAL * 1000, boost::bind(&Raids::checkRaids, this)));
}
开发者ID:armadaazteca,项目名称:tfs0.2.15,代码行数:24,代码来源:raids.cpp
示例11: getConnection
void ProtocolStatus::sendStatusString()
{
OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false);
if (!output) {
getConnection()->close();
return;
}
setRawMessages(true);
pugi::xml_document doc;
pugi::xml_node decl = doc.prepend_child(pugi::node_declaration);
decl.append_attribute("version") = "1.0";
pugi::xml_node tsqp = doc.append_child("tsqp");
tsqp.append_attribute("version") = "1.0";
pugi::xml_node serverinfo = tsqp.append_child("serverinfo");
uint64_t uptime = (OTSYS_TIME() - ProtocolStatus::start) / 1000;
serverinfo.append_attribute("uptime") = std::to_string(uptime).c_str();
serverinfo.append_attribute("ip") = g_config.getString(ConfigManager::IP).c_str();
serverinfo.append_attribute("servername") = g_config.getString(ConfigManager::SERVER_NAME).c_str();
serverinfo.append_attribute("port") = std::to_string(g_config.getNumber(ConfigManager::LOGIN_PORT)).c_str();
serverinfo.append_attribute("location") = g_config.getString(ConfigManager::LOCATION).c_str();
serverinfo.append_attribute("url") = g_config.getString(ConfigManager::URL).c_str();
serverinfo.append_attribute("server") = STATUS_SERVER_NAME;
serverinfo.append_attribute("version") = STATUS_SERVER_VERSION;
serverinfo.append_attribute("client") = CLIENT_VERSION_STR;
pugi::xml_node owner = tsqp.append_child("owner");
owner.append_attribute("name") = g_config.getString(ConfigManager::OWNER_NAME).c_str();
owner.append_attribute("email") = g_config.getString(ConfigManager::OWNER_EMAIL).c_str();
pugi::xml_node players = tsqp.append_child("players");
players.append_attribute("online") = std::to_string(g_game.getPlayersOnline()).c_str();
players.append_attribute("max") = std::to_string(g_config.getNumber(ConfigManager::MAX_PLAYERS)).c_str();
players.append_attribute("peak") = std::to_string(g_game.getPlayersRecord()).c_str();
pugi::xml_node monsters = tsqp.append_child("monsters");
monsters.append_attribute("total") = std::to_string(g_game.getMonstersOnline()).c_str();
pugi::xml_node npcs = tsqp.append_child("npcs");
npcs.append_attribute("total") = std::to_string(g_game.getNpcsOnline()).c_str();
pugi::xml_node rates = tsqp.append_child("rates");
rates.append_attribute("experience") = std::to_string(g_config.getNumber(ConfigManager::RATE_EXPERIENCE)).c_str();
rates.append_attribute("skill") = std::to_string(g_config.getNumber(ConfigManager::RATE_SKILL)).c_str();
rates.append_attribute("loot") = std::to_string(g_config.getNumber(ConfigManager::RATE_LOOT)).c_str();
rates.append_attribute("magic") = std::to_string(g_config.getNumber(ConfigManager::RATE_MAGIC)).c_str();
rates.append_attribute("spawn") = std::to_string(g_config.getNumber(ConfigManager::RATE_SPAWN)).c_str();
pugi::xml_node map = tsqp.append_child("map");
map.append_attribute("name") = g_config.getString(ConfigManager::MAP_NAME).c_str();
map.append_attribute("author") = g_config.getString(ConfigManager::MAP_AUTHOR).c_str();
uint32_t mapWidth, mapHeight;
g_game.getMapDimensions(mapWidth, mapHeight);
map.append_attribute("width") = std::to_string(mapWidth).c_str();
map.append_attribute("height") = std::to_string(mapHeight).c_str();
pugi::xml_node motd = tsqp.append_child("motd");
motd.text() = g_config.getString(ConfigManager::MOTD).c_str();
std::ostringstream ss;
doc.save(ss, "", pugi::format_raw);
std::string data = ss.str();
output->addBytes(data.c_str(), data.size());
OutputMessagePool::getInstance()->send(output);
getConnection()->close();
}
开发者ID:CyCu991,项目名称:forgottenserver,代码行数:72,代码来源:protocolstatus.cpp
示例12: OTSYS_TIME
#include "otpch.h"
#include "protocolstatus.h"
#include "configmanager.h"
#include "game.h"
#include "connection.h"
#include "networkmessage.h"
#include "outputmessage.h"
#include "tools.h"
#include "tasks.h"
extern ConfigManager g_config;
extern Game g_game;
std::map<uint32_t, int64_t> ProtocolStatus::ipConnectMap;
const uint64_t ProtocolStatus::start = OTSYS_TIME();
enum RequestedInfo_t : uint16_t {
REQUEST_BASIC_SERVER_INFO = 1 << 0,
REQUEST_OWNER_SERVER_INFO = 1 << 1,
REQUEST_MISC_SERVER_INFO = 1 << 2,
REQUEST_PLAYERS_INFO = 1 << 3,
REQUEST_MAP_INFO = 1 << 4,
REQUEST_EXT_PLAYERS_INFO = 1 << 5,
REQUEST_PLAYER_STATUS_INFO = 1 << 6,
REQUEST_SERVER_SOFTWARE_INFO = 1 << 7,
};
void ProtocolStatus::onRecvFirstMessage(NetworkMessage& msg)
{
uint32_t ip = getIP();
开发者ID:CyCu991,项目名称:forgottenserver,代码行数:31,代码来源:protocolstatus.cpp
示例13: OTSYS_TIME
void Creature::onCreatureMove(const Creature* creature, const Tile* newTile, const Position& newPos,
const Tile* oldTile, const Position& oldPos, bool teleport)
{
if (creature == this) {
lastStep = OTSYS_TIME();
lastStepCost = 1;
if (!teleport) {
if (oldPos.z != newPos.z) {
//floor change extra cost
lastStepCost = 2;
} else if (Position::getDistanceX(newPos, oldPos) >= 1 && Position::getDistanceY(newPos, oldPos) >= 1) {
//diagonal extra cost
lastStepCost = 2;
}
} else {
stopEventWalk();
}
if (!summons.empty()) {
//check if any of our summons is out of range (+/- 2 floors or 30 tiles away)
std::list<Creature*> despawnList;
std::list<Creature*>::iterator cit;
for (cit = summons.begin(); cit != summons.end(); ++cit) {
const Position pos = (*cit)->getPosition();
if (Position::getDistanceZ(newPos, pos) > 2 || (std::max<int32_t>(Position::getDistanceX(newPos, pos), Position::getDistanceY(newPos, pos)) > 30)) {
despawnList.push_back((*cit));
}
}
for (cit = despawnList.begin(); cit != despawnList.end(); ++cit) {
g_game.removeCreature((*cit), true);
}
}
if (newTile->getZone() != oldTile->getZone()) {
onChangeZone(getZone());
}
//update map cache
if (isMapLoaded) {
if (teleport || oldPos.z != newPos.z) {
updateMapCache();
} else {
Tile* tile;
const Position& myPos = getPosition();
Position pos;
if (oldPos.y > newPos.y) { //north
//shift y south
for (int32_t y = mapWalkHeight - 1 - 1; y >= 0; --y) {
memcpy(localMapCache[y + 1], localMapCache[y], sizeof(localMapCache[y]));
}
//update 0
for (int32_t x = -((mapWalkWidth - 1) / 2); x <= ((mapWalkWidth - 1) / 2); ++x) {
tile = g_game.getTile(myPos.getX() + x, myPos.getY() - ((mapWalkHeight - 1) / 2), myPos.z);
updateTileCache(tile, x, -((mapWalkHeight - 1) / 2));
}
} else if (oldPos.y < newPos.y) { // south
//shift y north
for (int32_t y = 0; y <= mapWalkHeight - 1 - 1; ++y) {
memcpy(localMapCache[y], localMapCache[y + 1], sizeof(localMapCache[y]));
}
//update mapWalkHeight - 1
for (int32_t x = -((mapWalkWidth - 1) / 2); x <= ((mapWalkWidth - 1) / 2); ++x) {
tile = g_game.getTile(myPos.getX() + x, myPos.getY() + ((mapWalkHeight - 1) / 2), myPos.z);
updateTileCache(tile, x, (mapWalkHeight - 1) / 2);
}
}
if (oldPos.x < newPos.x) { // east
//shift y west
int32_t starty = 0;
int32_t endy = mapWalkHeight - 1;
int32_t dy = Position::getDistanceY(oldPos, newPos);
if (dy < 0) {
endy += dy;
} else if (dy > 0) {
starty = dy;
}
for (int32_t y = starty; y <= endy; ++y) {
for (int32_t x = 0; x <= mapWalkWidth - 2; ++x) {
localMapCache[y][x] = localMapCache[y][x + 1];
}
}
//update mapWalkWidth - 1
for (int32_t y = -((mapWalkHeight - 1) / 2); y <= ((mapWalkHeight - 1) / 2); ++y) {
tile = g_game.getTile(myPos.x + ((mapWalkWidth - 1) / 2), myPos.y + y, myPos.z);
updateTileCache(tile, (mapWalkWidth - 1) / 2, y);
}
} else if (oldPos.x > newPos.x) { // west
//shift y east
int32_t starty = 0;
int32_t endy = mapWalkHeight - 1;
//.........这里部分代码省略.........
开发者ID:afsdadsfdsa,项目名称:forgottenserver,代码行数:101,代码来源:creature.cpp
示例14: vectorAtoi
bool GlobalEvent::configureEvent(const pugi::xml_node& node)
{
pugi::xml_attribute nameAttribute = node.attribute("name");
if (!nameAttribute) {
std::cout << "[Error - GlobalEvent::configureEvent] Missing name for a globalevent" << std::endl;
return false;
}
name = nameAttribute.as_string();
eventType = GLOBALEVENT_NONE;
pugi::xml_attribute attr;
if ((attr = node.attribute("time"))) {
std::vector<int32_t> params = vectorAtoi(explodeString(attr.as_string(), ":"));
int32_t hour = params.front();
if (hour < 0 || hour > 23) {
std::cout << "[Error - GlobalEvent::configureEvent] Invalid hour \"" << attr.as_string() << "\" for globalevent with name: " << name << std::endl;
return false;
}
interval |= hour << 16;
int32_t min = 0;
int32_t sec = 0;
if (params.size() > 1) {
min = params[1];
if (min < 0 || min > 59) {
std::cout << "[Error - GlobalEvent::configureEvent] Invalid minute \"" << attr.as_string() << "\" for globalevent with name: " << name << std::endl;
return false;
}
if (params.size() > 2) {
sec = params[2];
if (sec < 0 || sec > 59) {
std::cout << "[Error - GlobalEvent::configureEvent] Invalid second \"" << attr.as_string() << "\" for globalevent with name: " << name << std::endl;
return false;
}
}
}
time_t current_time = time(nullptr);
tm* timeinfo = localtime(¤t_time);
timeinfo->tm_hour = hour;
timeinfo->tm_min = min;
timeinfo->tm_sec = sec;
time_t difference = static_cast<time_t>(difftime(mktime(timeinfo), current_time));
if (difference < 0) {
difference += 86400;
}
nextExecution = current_time + difference;
eventType = GLOBALEVENT_TIMER;
} else if ((attr = node.attribute("type"))) {
const char* value = attr.value();
if (strcasecmp(value, "startup") == 0) {
eventType = GLOBALEVENT_STARTUP;
} else if (strcasecmp(value, "shutdown") == 0) {
eventType = GLOBALEVENT_SHUTDOWN;
} else if (strcasecmp(value, "record") == 0) {
eventType = GLOBALEVENT_RECORD;
} else {
std::cout << "[Error - GlobalEvent::configureEvent] No valid type \"" << attr.as_string() << "\" for globalevent with name " << name << std::endl;
return false;
}
} else if ((attr = node.attribute("interval"))) {
interval = std::max<int32_t>(SCHEDULER_MINTICKS, pugi::cast<int32_t>(attr.value()));
nextExecution = OTSYS_TIME() + interval;
} else {
std::cout << "[Error - GlobalEvent::configureEvent] No interval for globalevent with name " << name << std::endl;
return false;
}
return true;
}
开发者ID:EvilHero90,项目名称:forgottenserver,代码行数:75,代码来源:globalevent.cpp
示例15: OTSYS_TIME
void Creature::onDeath()
{
bool lastHitUnjustified = false;
bool mostDamageUnjustified = false;
Creature* lastHitCreature = g_game.getCreatureByID(lastHitCreatureId);
Creature* lastHitCreatureMaster;
if (lastHitCreature) {
lastHitUnjustified = lastHitCreature->onKilledCreature(this);
lastHitCreatureMaster = lastHitCreature->getMaster();
} else {
lastHitCreatureMaster = nullptr;
}
Creature* mostDamageCreature = nullptr;
const int64_t timeNow = OTSYS_TIME();
const uint32_t inFightTicks = g_config.getNumber(ConfigManager::PZ_LOCKED);
int32_t mostDamage = 0;
std::map<Creature*, uint64_t> experienceMap;
for (const auto& it : damageMap) {
if (Creature* attacker = g_game.getCreatureByID(it.first)) {
CountBlock_t cb = it.second;
if ((cb.total > mostDamage && (timeNow - cb.ticks <= inFightTicks))) {
mostDamage = cb.total;
mostDamageCreature = attacker;
}
if (attacker != this) {
uint64_t gainExp = getGainedExperience(attacker);
if (Player* player = attacker->getPlayer()) {
Party* party = player->getParty();
if (party && party->getLeader() && party->isSharedExperienceActive() && party->isSharedExperienceEnabled()) {
attacker = party->getLeader();
}
}
auto tmpIt = experienceMap.find(attacker);
if (tmpIt == experienceMap.end()) {
experienceMap[attacker] = gainExp;
} else {
tmpIt->second += gainExp;
}
}
}
}
for (const auto& it : experienceMap) {
it.first->onGainExperience(it.second, this);
}
if (mostDamageCreature) {
if (mostDamageCreature != lastHitCreature && mostDamageCreature != lastHitCreatureMaster) {
Creature* mostDamageCreatureMaster = mostDamageCreature->getMaster();
if (lastHitCreature != mostDamageCreatureMaster && (lastHitCreatureMaster == nullptr || mostDamageCreatureMaster != lastHitCreatureMaster)) {
mostDamageUnjustified = mostDamageCreature->onKilledCreature(this, false);
}
}
}
bool droppedCorpse = dropCorpse(lastHitCreature, mostDamageCreature, lastHitUnjustified, mostDamageUnjustified);
death(lastHitCreature);
if (master) {
master->removeSummon(this);
}
if (droppedCorpse) {
g_game.removeCreature(this, false);
}
}
开发者ID:A-Syntax,项目名称:forgottenserver,代码行数:70,代码来源:creature.cpp
示例16: OTSYS_TIME
void Condition::setTicks(int32_t _ticks)
{
ticks = _ticks;
if(_ticks > 0)
endTime = OTSYS_TIME() + _ticks;
}
开发者ID:Codex-NG,项目名称:thecrystalserver,代码行数:6,代码来源:condition.cpp
示例17: srand
void Dispatcher::dispatcherThread(void* p)
{
#if defined __EXCEPTION_TRACER__
ExceptionHandler dispatcherExceptionHandler;
dispatcherExceptionHandler.InstallHandler();
#endif
srand((unsigned int)OTSYS_TIME());
#ifdef __DEBUG_SCHEDULER__
std::cout << "Starting Dispatcher" << std::endl;
#endif
OutputMessagePool* outputPool;
// NOTE: second argument defer_lock is to prevent from immediate locking
boost::unique_lock<boost::mutex> taskLockUnique(getDispatcher().m_taskLock, boost::defer_lock);
while(Dispatcher::m_threadState != Dispatcher::STATE_TERMINATED){
Task* task = NULL;
// check if there are tasks waiting
taskLockUnique.lock();//getDispatcher().m_taskLock.lock();
if(getDispatcher().m_taskList.empty()){
//if the list is empty wait for signal
#ifdef __DEBUG_SCHEDULER__
std::cout << "Dispatcher: Waiting for task" << std::endl;
#endif
getDispatcher().m_taskSignal.wait(taskLockUnique);
}
#ifdef __DEBUG_SCHEDULER__
std::cout << "Dispatcher: Signalled" << std::endl;
#endif
if(!getDispatcher().m_taskList.empty() && (Dispatcher::m_threadState != Dispatcher::STATE_TERMINATED)){
// take the first task
task = getDispatcher().m_taskList.front();
getDispatcher().m_taskList.pop_front();
}
taskLockUnique.unlock();
// finally execute the task...
if(task){
OutputMessagePool::getInstance()->startExecutionFrame();
(*task)();
delete task;
outputPool = OutputMessagePool::getInstance();
if(outputPool){
outputPool->sendAll();
}
g_game.clearSpectatorCache();
#ifdef __DEBUG_SCHEDULER__
std::cout << "Dispatcher: Executing task" << std::endl;
#endif
}
}
#if defined __EXCEPTION_TRACER__
dispatcherExceptionHandler.RemoveHandler();
#endif
}
开发者ID:Codex-NG,项目名称:avesta74,代码行数:63,代码来源:tasks.cpp
示例18: main
int main(int argc, char *argv[])
{
std::srand((uint32_t)OTSYS_TIME());
StringVec args = StringVec(argv, argv + argc);
if(argc > 1 && !argumentsHandler(args))
return 0;
#else
void serverMain(void* param)
{
std::cout.rdbuf(&g_logger);
std::cerr.rdbuf(&g_logger);
std::clog.rdbuf(&g_logger);
#endif
std::set_new_handler(allocationHandler);
ServiceManager servicer;
g_config.startup();
#ifdef __OTSERV_ALLOCATOR_STATS__
//boost::thread(boost::bind(&allocatorStatsThread, (void*)NULL));
// TODO: this thread needs a shutdown (timed_lock + interrupt? .interrupt + .unlock)
#endif
#ifdef __EXCEPTION_TRACER__
ExceptionHandler mainExceptionHandler;
mainExceptionHandler.InstallHandler();
#endif
#ifndef WINDOWS
// ignore sigpipe...
struct sigaction sigh;
sigh.sa_handler = SIG_IGN;
sigh.sa_flags = 0;
sigemptyset(&sigh.sa_mask);
sigaction(SIGPIPE, &sigh, NULL);
// register signals
signal(SIGHUP, signalHandler); //save
signal(SIGTRAP, signalHandler); //clean
signal(SIGCHLD, signalHandler); //refresh
signal(SIGUSR1, signalHandler); //close server
signal(SIGUSR2, signalHandler); //open server
signal(SIGCONT, signalHandler); //reload all
signal(SIGQUIT, signalHandler); //save & shutdown
signal(SIGTERM, signalHandler); //shutdown
#endif
Dispatcher::getInstance().addTask(createTask(boost::bind(otserv,
#if !defined(WINDOWS) || defined(_CONSOLE)
args,
#endif
&servicer)));
g_loaderSignal.wait(g_loaderUniqueLock);
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
if(servicer.isRunning())
{
Status::getInstance();
std::clog << ">> " << g_config.getString(ConfigManager::SERVER_NAME) << " server Online!" << std::endl << std::endl;
#if defined(WINDOWS) && !defined(_CONSOLE)
SendMessage(GUI::getInstance()->m_statusBar, WM_SETTEXT, 0, (LPARAM)">> server Online!");
GUI::getInstance()->m_connections = true;
#endif
servicer.run();
}
else
{
Status::getInstance();
std::clog << ">> " << g_config.getString(ConfigManager::SERVER_NAME) << " server Offline! No services available..." << std::endl << std::endl;
#if defined(WINDOWS) && !defined(_CONSOLE)
SendMessage(GUI::getInstance()->m_statusBar, WM_SETTEXT, 0, (LPARAM)">> server Offline! No services available...");
GUI::getInstance()->m_connections = true;
#endif
}
Dispatcher::getInstance().exit();
Scheduler::getInstance().exit();
#ifdef __EXCEPTION_TRACER__
mainExceptionHandler.RemoveHandler();
#endif
#if !defined(WINDOWS) || defined(_CONSOLE)
return 0;
#endif
}
开发者ID:081421,项目名称:otxserver,代码行数:86,代码来源:otserv.cpp
示例19: mainLoader
void mainLoader(int, char*[], ServiceManager* services)
{
//dispatcher thread
g_game.setGameState(GAME_STATE_STARTUP);
srand(static_cast<unsigned int>(OTSYS_TIME()));
#ifdef _WIN32
SetConsoleTitle(STATUS_SERVER_NAME);
#endif
std::cout << "The " << STATUS_SERVER_NAME << " Version: (" << STATUS_SERVER_VERSION << "." << MINOR_VERSION << " . " << REVISION_VERSION << ") - Codename: ( " << SOFTWARE_CODENAME << " )" << std::endl;
std::cout << "Compiled with: " << BOOST_COMPILER << std::endl;
std::cout << "Compiled on " << __DATE__ << ' ' << __TIME__ << " for platform ";
#if defined(__amd64__) || defined(_M_X64)
std::cout << "x64" << std::endl;
#elif defined(__i386__) || defined(_M_IX86) || defined(_X86_)
std::cout << "x86" << std::endl;
#elif defined(__arm__)
std::cout << "ARM" << std::endl;
#else
std::cout << "unknown" << std::endl;
#endif
std::cout << std::endl;
std::cout << "A server developed by " << STATUS_SERVER_DEVELOPERS << "." << std::endl;
std::cout << "Visit our forum for updates, support, and resources: " << GIT_REPO <<"." << std::endl;
std::cout << std::endl;
// read global config
std::cout << ">> Loading config" << std::endl;
if (!g_config.load()) {
startupErrorMessage("Unable to load config.lua!");
return;
}
#ifdef _WIN32
const std::string& defaultPriority = g_config.getString(ConfigManager::DEFAULT_PRIORITY);
if (strcasecmp(defaultPriority.c_str(), "high") == 0) {
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
} else if (strcasecmp(defaultPriority.c_str(), "above-normal") == 0) {
SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS);
}
#endif
//set RSA key
const char* p("14299623962416399520070177382898895550795403345466153217470516082934737582776038882967213386204600674145392845853859217990626450972452084065728686565928113");
const char* q("7630979195970404721891201847792002125535401292779123937207447574596692788513647179235335529307251350570728407373705564708871762033017096809910315212884101");
g_RSA.setKey(p, q);
std::cout << ">> Establishing database connection..." << std::flush;
Database* db = Database::getInstance();
if (!db->connect()) {
startupErrorMessage("Failed to connect to database.");
return;
}
std::cout << " MySQL " << Database::getClientVersion() << std::endl;
// run database manager
std::cout << ">> Running database manager" << std::endl;
if (!DatabaseManager::isDatabaseSetup()) {
startupErrorMessage("The database you have specified in config.lua is empty, please import the schema.sql to your database.");
return;
}
g_databaseTasks.start();
DatabaseManager::updateDatabase();
if (g_config.getBoolean(ConfigManager::OPTIMIZE_DATABASE) && !DatabaseManager::optimizeTables()) {
std::cout << "> No tables were optimized." << std::endl;
}
//load vocations
std::cout << ">> Loading vocations" << std::endl;
if (!g_vocations.loadFromXml()) {
startupErrorMessage("Unable to load vocations!");
return;
}
// load item data
std::cout << ">> Loading items" << std::endl;
if (Item::items.loadFromOtb("data/items/items.otb") != ERROR_NONE) {
startupErrorMessage("Unable to load items (OTB)!");
return;
}
if (!Item::items.loadFromXml()) {
startupErrorMessage("Unable to load items (XML)!");
return;
}
std::cout << ">> Loading script systems" << std::endl;
if (!ScriptingManager::getInstance()->loadScriptSystems()) {
startupErrorMessage("Failed to load script systems");
return;
}
std::cout << ">> Loading monsters" << std::endl;
//.........这里部分代码省略.........
开发者ID:Casster,项目名称:otxserver,代码行数:101,代码来源:otserv.cpp
示例20: mainLoader
void mainLoader(int, char*[], ServiceManager* services)
{
srand(static_cast<unsigned int>(OTSYS_TIME()));
#ifdef _WIN32
SetConsoleTitle(STATUS_SERVER_NAME);
#endif
std::cout << STATUS_SERVER_NAME << " - Version " << STATUS_SERVER_VERSION << std::endl;
std::cout << "Compiled with " << BOOST_COMPILER << std::endl;
std::cout << "Compiled on " << __DATE__ << ' ' << __TIME__ << " for platform ";
#if defined(__amd64__) || defined(_M_X64)
std::cout << "x64" << std::endl;
#elif defined(__i386__) || defined(_M_IX86) || defined(_X86_)
std::cout << "x86" << std::endl;
#elif defined(__arm__)
std::cout << "ARM" << std::endl;
#else
std::cout << "unknown" << std::endl;
#endif
std::cout << std::endl;
std::cout << "A server developed by " << STATUS_SERVER_DEVELOPERS << std::endl;
std::cout << "Visit our forum for updates, support, and resources: http://otland.net/." << std::endl;
std::cout << std::endl;
// read global config
std::cout << ">> Loading config" << std::endl;
if (!g_config.load()) {
startupErrorMessage("Unable to load config.lua!");
return;
}
std::cout << ">> Loading gameserver config..." << std::endl;
if (!g_gameserver.load()) {
startupErrorMessage("Unable to load gameservers!");
return;
}
#ifdef _WIN32
const std::string& defaultPriority = g_config.getString(ConfigManager::DEFAULT_PRIORITY);
if (strcasecmp(defaultPriority.c_str(), "high") == 0) {
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
} else if (strcasecmp(defaultPriority.c_str(), "above-normal") == 0) {
SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS);
}
#endif
//set RSA key
const char* p("14299623962416399520070177382898895550795403345466153217470516082934737582776038882967213386204600674145392845853859217990626450972452084065728686565928113");
const char* q("7630979195970404721891201847792002125535401292779123937207447574596692788513647179235335529307251350570728407373705564708871762033017096809910315212884101");
g_RSA.setKey(p, q);
std::cout << ">> Establishing database connection..." << std::flush;
Database* db = Database::getInstance();
if (!db->connect()) {
startupErrorMessage("Failed to connect to database.");
return;
}
std::cout << " MySQL " << Database::getClientVersion() << std::endl;
// run database manager
std::cout << ">> Running database manager" << std::endl;
if (!DatabaseManager::isDatabaseSetup()) {
startupErrorMessage("The database you have specified in config.lua is empty, please import the schema.sql to your database.");
return;
}
g_databaseTasks.start();
if (g_config.getBoolean(ConfigManager::OPTIMIZE_DATABASE) && !DatabaseManager::optimizeTables()) {
std::cout << "> No tables were optimized." << std::endl;
}
services->add<ProtocolLogin>(g_config.getNumber(ConfigManager::LOGIN_PORT));
services->add<ProtocolOld>(g_config.getNumber(ConfigManager::LOGIN_PORT));
std::cout << ">> Loaded all modules, server starting up..." << std::endl;
#ifndef _WIN32
if (getuid() == 0 || geteuid() == 0) {
std::cout << "> Warning: " << STATUS_SERVER_NAME << " has been executed as root user, please consider running it as a normal user." << std::endl;
}
#endif
g_loaderSignal.notify_all();
}
开发者ID:Cavitt,项目名称:forgottenloginserver,代码行数:90,代码来源:otserv.cpp
注:本文中的OTSYS_TIME函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论