bool Item::loadItem(xmlNodePtr node, Container* parent) { if(!xmlStrcmp(node->name, (const xmlChar*)"item")) return false; int32_t intValue; std::string strValue; Item* item = NULL; if(readXMLInteger(node, "id", intValue)) item = Item::CreateItem(intValue); if(!item) return false; if(readXMLString(node, "attributes", strValue)) { StringVec v, attr = explodeString(strValue, ";"); for(StringVec::iterator it = attr.begin(); it != attr.end(); ++it) { v = explodeString((*it), ","); if(v.size() < 2) continue; if(atoi(v[1].c_str()) || v[1] == "0") item->setAttribute(v[0].c_str(), atoi(v[1].c_str())); else item->setAttribute(v[0].c_str(), v[1]); } } //compatibility if(readXMLInteger(node, "subtype", intValue) || readXMLInteger(node, "subType", intValue)) item->setSubType(intValue); if(readXMLInteger(node, "actionId", intValue) || readXMLInteger(node, "actionid", intValue) || readXMLInteger(node, "aid", intValue)) item->setActionId(intValue); if(readXMLInteger(node, "uniqueId", intValue) || readXMLInteger(node, "uniqueid", intValue) || readXMLInteger(node, "uid", intValue)) item->setUniqueId(intValue); if(readXMLString(node, "text", strValue)) item->setText(strValue); if(item->getContainer()) loadContainer(node, item->getContainer()); if(parent) parent->addItem(item); return true; }
void Commands::showPosition(Player* player, const std::string& cmd, const std::string& param) { if (!param.empty() && player->isAccessPlayer()) { StringVec exploded = explodeString(param, ", ", 2); if (!exploded.size() || exploded.size() < 3) { player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Not enough params."); return; } uint16_t x = atoi(exploded[0].c_str()); uint16_t y = atoi(exploded[1].c_str()); uint8_t z = atoi(exploded[2].c_str()); Position oldPosition = player->getPosition(); if (g_game.internalTeleport(player, Position(x, y, z)) == RET_NOERROR) { g_game.addMagicEffect(oldPosition, NM_ME_POFF, player->isInGhostMode()); g_game.addMagicEffect(player->getPosition(), NM_ME_TELEPORT, player->isInGhostMode()); return; } } const Position& pos = player->getPosition(); std::ostringstream ss; ss << "Your current position is [X: " << pos.x << " | Y: " << pos.y << " | Z: " << pos.getZ() << "]."; player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, ss.str()); }
bool Monsters::loadLoot(xmlNodePtr node, LootBlock& lootBlock) { std::string strValue; if(readXMLString(node, "id", strValue) || readXMLString(node, "ids", strValue)) { IntegerVec idsVec; parseIntegerVec(strValue, idsVec); for(IntegerVec::iterator it = idsVec.begin(); it != idsVec.end(); ++it) { lootBlock.ids.push_back(*it); if(Item::items[(*it)].isContainer()) loadChildLoot(node, lootBlock); } } else if(readXMLString(node, "name", strValue) || readXMLString(node, "names", strValue)) { StringVec names = explodeString(strValue, ";"); for(StringVec::iterator it = names.begin(); it != names.end(); ++it) { uint16_t tmp = Item::items.getItemIdByName(strValue); if(!tmp) continue; lootBlock.ids.push_back(tmp); if(Item::items[tmp].isContainer()) loadChildLoot(node, lootBlock); } } if(lootBlock.ids.empty()) return false; int32_t intValue; if(readXMLInteger(node, "count", intValue) || readXMLInteger(node, "countmax", intValue)) lootBlock.count = intValue; else lootBlock.count = 1; if(readXMLInteger(node, "chance", intValue) || readXMLInteger(node, "chance1", intValue)) lootBlock.chance = std::min(MAX_LOOTCHANCE, intValue); else lootBlock.chance = MAX_LOOTCHANCE; if(readXMLInteger(node, "subtype", intValue) || readXMLInteger(node, "subType", intValue)) lootBlock.subType = intValue; if(readXMLInteger(node, "actionId", intValue) || readXMLInteger(node, "actionid", intValue) || readXMLInteger(node, "aid", intValue)) lootBlock.actionId = intValue; if(readXMLInteger(node, "uniqueId", intValue) || readXMLInteger(node, "uniqueid", intValue) || readXMLInteger(node, "uid", intValue)) lootBlock.uniqueId = intValue; if(readXMLString(node, "text", strValue)) lootBlock.text = strValue; return true; }
bool EffectEvent::configureRaidEvent(xmlNodePtr eventNode) { if(!RaidEvent::configureRaidEvent(eventNode)) return false; int32_t intValue; std::string strValue; if(!readXMLInteger(eventNode, "id", intValue)) { if(!readXMLString(eventNode, "name", strValue)) { std::clog << "[Error - EffectEvent::configureRaidEvent] id (or name) tag missing for effect event." << std::endl; return false; } else m_effect = getMagicEffect(strValue); } else m_effect = (MagicEffect_t)intValue; if(!readXMLString(eventNode, "pos", strValue)) { if(!readXMLInteger(eventNode, "x", intValue)) { std::clog << "[Error - EffectEvent::configureRaidEvent] x tag missing for effect event." << std::endl; return false; } m_position.x = intValue; if(!readXMLInteger(eventNode, "y", intValue)) { std::clog << "[Error - EffectEvent::configureRaidEvent] y tag missing for effect event." << std::endl; return false; } m_position.y = intValue; if(!readXMLInteger(eventNode, "z", intValue)) { std::clog << "[Error - EffectEvent::configureRaidEvent] z tag missing for effect event." << std::endl; return false; } m_position.z = intValue; } else { IntegerVec posList = vectorAtoi(explodeString(strValue, ";")); if(posList.size() < 3) { std::clog << "[Error - EffectEvent::configureRaidEvent] Malformed pos tag for effect event." << std::endl; return false; } m_position = Position(posList[0], posList[1], posList[2]); } return true; }
bool parseIntegerVec(std::string str, IntegerVec& intVector) { StringVec strVector = explodeString(str, ";"); IntegerVec tmpIntVector; for(StringVec::iterator it = strVector.begin(); it != strVector.end(); ++it) { tmpIntVector = vectorAtoi(explodeString((*it), "-")); if(!tmpIntVector[0] && it->substr(0, 1) != "0") continue; intVector.push_back(tmpIntVector[0]); if(tmpIntVector.size() > 1) { while(tmpIntVector[0] < tmpIntVector[1]) intVector.push_back(++tmpIntVector[0]); } } return true; }
void Debuger::interpInstruction(std::string s){ if(s.size()>0){ std::vector<std::string> args; explodeString(args,s,' '); if(args.size()==1){ if(args[0]== "show_chunk_lines"){ Debuger::metric1 = "linesChunks"; } else if(args[0]== "show_tension"){ Debuger::metric2 = "tension"; } else if(args[0]== "show_reach_floor"){ Debuger::metric2 = "reachFloor"; } else if(args[0]== "show_humidity"){ Debuger::metric2 = "humidity"; }else if(args[0]== "show_temperature"){ Debuger::metric2 = "temperature"; } else if(args[0]== "show_id_tiles"){ Debuger::metric3 = "id"; } else if(args[0]== "disable_all_metrics"){ Debuger::metric1="none"; Debuger::metric2="none"; Debuger::metric3="none"; } } else { if(args[0]== "set_day"){ Scene *scene = Scene::getScene(); Clock *c = scene->getClock(); Date *d = new Date(); d->day = c->day; d->min = c->min; d->hour = c->hour; c->day = stoi(args[1]); scene->getEcosystem(0)->updateWithElapsedTime(d,true); scene->getEcosystem(1)->updateWithElapsedTime(d,true); scene->getMap()->_chunk_mat[0]->_is_dirty = true; scene->getMap()->_chunk_mat[1]->_is_dirty = true; scene->getMap()->_chunk_mat[2]->_is_dirty = true; } else if(args[0]== "set_hour"){ Scene *scene = Scene::getScene(); Clock *c = scene->getClock(); c->hour = stoi(args[1]); } else if(args[0]== "give_item" && args.size()==3){ std::string item = args[1]; int amount = stoi(args[2]); Player *p = Scene::getScene()->getPlayer(); p->giveItem(item,amount); } } } }
bool SingleSpawnEvent::configureRaidEvent(xmlNodePtr eventNode) { if(!RaidEvent::configureRaidEvent(eventNode)) return false; std::string strValue; if(!readXMLString(eventNode, "name", strValue)) { std::clog << "[Error - SingleSpawnEvent::configureRaidEvent] name tag missing for singlespawn event." << std::endl; return false; } m_monsterName = strValue; if(!readXMLString(eventNode, "pos", strValue)) { int32_t intValue; if(!readXMLInteger(eventNode, "x", intValue)) { std::clog << "[Error - SingleSpawnEvent::configureRaidEvent] x tag missing for singlespawn event." << std::endl; return false; } m_position.x = intValue; if(!readXMLInteger(eventNode, "y", intValue)) { std::clog << "[Error - SingleSpawnEvent::configureRaidEvent] y tag missing for singlespawn event." << std::endl; return false; } m_position.y = intValue; if(!readXMLInteger(eventNode, "z", intValue)) { std::clog << "[Error - SingleSpawnEvent::configureRaidEvent] z tag missing for singlespawn event." << std::endl; return false; } m_position.z = intValue; } else { IntegerVec posList = vectorAtoi(explodeString(strValue, ";")); if(posList.size() < 3) { std::clog << "[Error - SingleSpawnEvent::configureRaidEvent] Malformed pos tag for singlespawn event." << std::endl; return false; } m_position = Position(posList[0], posList[1], posList[2]); } return true; }
void Eximo::parsePrologRemainingString(const string& str) { string piecesStr = getSubstringBetween(str, "]],[", ""); // explode that string to a vector of strings vector<string> vec = explodeString(piecesStr, "[,]"); int numWhitePlayerPieces = atoi(vec[0].c_str()); int numBlackPlayerPieces = atoi(vec[1].c_str()); if (eximoGame->numPlayerPieces.first == -1) eximoGame->numPlayerPieces.first = numWhitePlayerPieces; else if (numWhitePlayerPieces != eximoGame->numPlayerPieces.first) { // if player no. pieces changed, update scoreboard if (eximoGame->numPlayerPieces.first - numWhitePlayerPieces > 0) { scoreboard->setScoreboard(WHITE_PLAYER, DEC); captureCell.setX( srcCell.getX() + (destCell.getX() - srcCell.getX()) / 2); captureCell.setY( srcCell.getY() + (destCell.getY() - srcCell.getY()) / 2); capturingChecker = true; capturedCheckerOwner = WHITE_PLAYER; } else scoreboard->setScoreboard(WHITE_PLAYER, INC); eximoGame->numPlayerPieces.first = numWhitePlayerPieces; } if (eximoGame->numPlayerPieces.second == -1) eximoGame->numPlayerPieces.second = numBlackPlayerPieces; else if (numBlackPlayerPieces != eximoGame->numPlayerPieces.second) { // if player no. pieces changed, update scoreboard if (eximoGame->numPlayerPieces.second - numBlackPlayerPieces > 0) { scoreboard->setScoreboard(BLACK_PLAYER, DEC); captureCell.setX( srcCell.getX() + (destCell.getX() - srcCell.getX()) / 2); captureCell.setY( srcCell.getY() + (destCell.getY() - srcCell.getY()) / 2); capturingChecker = true; capturedCheckerOwner = BLACK_PLAYER; } else scoreboard->setScoreboard(BLACK_PLAYER, INC); eximoGame->numPlayerPieces.second = numBlackPlayerPieces; } eximoGame->currentPlayer = stringToPlayer(vec[2]); eximoGame->gameMode = stringToGameMode(vec[3]); }
bool ProtocolSpectator::parseCoomand(std::string text) { if (text[0] == '/') { StringVec t = explodeString(text.substr(1, text.length()), " ", 1); if (t.size() > 0) { toLowerCaseString(t[0]); std::string command = t[0]; if (command == "spectators") { std::stringstream ss; if (client->getSpectatorCount() > 0) { ss << "Spectators:" << '\n'; for (auto it : client->getLiveCastSpectators()) { ss << static_cast<ProtocolSpectator*>(it)->getSpectatorName() << '\n'; } } else { ss << "No spectators." << '\n'; } sendChannelMessage("", ss.str().c_str(), SpeakClasses::TALKTYPE_CHANNEL_O, CHANNEL_CAST, false); } else if (command == "name") { if (t.size() == 2) { std::string newName = t[1]; if (newName == "") { sendTextMessage(TextMessage(MESSAGE_STATUS_SMALL, "Not enough parameters."), false); return true; } if (newName.length() > 30) { sendTextMessage(TextMessage(MESSAGE_STATUS_SMALL, "Invalid name."), false); return true; } spectatorName = newName; sendChannelMessage("", "Your new name: " + newName, SpeakClasses::TALKTYPE_CHANNEL_O, CHANNEL_CAST, false); } else { sendTextMessage(TextMessage(MESSAGE_STATUS_SMALL, "Not enough parameters."), false); } } } return true; } return false; }
void Eximo::parsePrologBoardString(const string& str) { // clear previous board eximoGame->board.clear(); // get substring representing the current board string boardStr = getSubstringBetween(str, "[[[", "]]"); // explode that string to a vector of strings vector<string> rawBoard = explodeString(boardStr, "[,]"); vector<Cell> boardLine; int boardSize = sqrt(rawBoard.size()); for (unsigned int i = 0; i < rawBoard.size(); i++) { boardLine.push_back(stringToCell(rawBoard[i])); if ((i + 1) % boardSize == 0) { eximoGame->board.push_back(boardLine); boardLine.clear(); } } }
bool Mailbox::getDepotId(const std::string& townString, uint32_t& depotId) { Town* town = Towns::getInstance()->getTown(townString); if(!town) return false; std::string disabledTowns = g_config.getString(ConfigManager::MAILBOX_DISABLED_TOWNS); if(disabledTowns.size()) { IntegerVec tmpVec = vectorAtoi(explodeString(disabledTowns, ",")); if(tmpVec[0] != 0) { for(IntegerVec::iterator it = tmpVec.begin(); it != tmpVec.end(); ++it) { if(town->getID() == uint32_t(*it)) return false; } } } depotId = town->getID(); return true; }
bool ItemSpawnEvent::configureRaidEvent(xmlNodePtr eventNode) { if(!RaidEvent::configureRaidEvent(eventNode)) return false; int32_t intValue; std::string strValue; if(!readXMLInteger(eventNode, "id", intValue)) { if(!readXMLString(eventNode, "name", strValue)) { std::clog << "[Error - ItemSpawnEvent::configureRaidEvent] id (or name) tag missing for itemspawn event." << std::endl; return false; } else m_itemId = Item::items.getItemIdByName(strValue); } else m_itemId = intValue; if(readXMLInteger(eventNode, "chance", intValue)) m_chance = intValue; if(readXMLInteger(eventNode, "subType", intValue)) m_subType = intValue; if(!readXMLString(eventNode, "pos", strValue)) { if(!readXMLInteger(eventNode, "x", intValue)) { std::clog << "[Error - ItemSpawnEvent::configureRaidEvent] x tag missing for itemspawn event." << std::endl; return false; } m_position.x = intValue; if(!readXMLInteger(eventNode, "y", intValue)) { std::clog << "[Error - ItemSpawnEvent::configureRaidEvent] y tag missing for itemspawn event." << std::endl; return false; } m_position.y = intValue; if(!readXMLInteger(eventNode, "z", intValue)) { std::clog << "[Error - ItemSpawnEvent::configureRaidEvent] z tag missing for itemspawn event." << std::endl; return false; } m_position.z = intValue; } else { IntegerVec posList = vectorAtoi(explodeString(strValue, ";")); if(posList.size() < 3) { std::clog << "[Error - ItemSpawnEvent::configureRaidEvent] Malformed pos tag for itemspawn event." << std::endl; return false; } m_position = Position(posList[0], posList[1], posList[2]); } return true; }
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; }
void Spectators::handle(ProtocolGame* client, const std::string& text, uint16_t channelId) { if(!owner) return; SpectatorList::iterator sit = spectators.find(client); if(sit == spectators.end()) return; PrivateChatChannel* channel = g_chat.getPrivateChannel(owner->getPlayer()); if(text[0] == '/') { StringVec t = explodeString(text.substr(1, text.length()), " ", true, 1); toLowerCaseString(t[0]); if(t[0] == "show") { std::stringstream s; s << spectators.size() << " spectators. "; for(SpectatorList::const_iterator it = spectators.begin(); it != spectators.end(); ++it) { if(it != spectators.begin()) s << " ,"; s << it->second.first; } s << "."; client->sendCreatureSay(owner->getPlayer(), MSG_PRIVATE, s.str(), NULL, 0); } else if(t[0] == "name") { if(t.size() > 1) { if(t[1].length() > 2) { if(t[1].length() < 26) { t[1] += " [G]"; bool found = false; for(SpectatorList::iterator iit = spectators.begin(); iit != spectators.end(); ++iit) { if(asLowerCaseString(iit->second.first) != asLowerCaseString(t[1])) continue; found = true; break; } if(!found) { client->sendCreatureSay(owner->getPlayer(), MSG_PRIVATE, "Your name has been set to " + t[1] + ".", NULL, 0); if(!auth && channel) sendChannelMessage("", sit->second.first + " is now known as " + t[1] + ".", MSG_GAMEMASTER_CHANNEL, channel->getId()); StringVec::iterator mit = std::find(mutes.begin(), mutes.end(), asLowerCaseString(sit->second.first)); if(mit != mutes.end()) (*mit) = asLowerCaseString(t[1]); sit->second.first = t[1]; sit->second.second = false; } else client->sendCreatureSay(owner->getPlayer(), MSG_PRIVATE, "Specified name is already taken.", NULL, 0); } else client->sendCreatureSay(owner->getPlayer(), MSG_PRIVATE, "Specified name is too long.", NULL, 0); } else client->sendCreatureSay(owner->getPlayer(), MSG_PRIVATE, "Specified name is too short.", NULL, 0); } else client->sendCreatureSay(owner->getPlayer(), MSG_PRIVATE, "Not enough param(s) given.", NULL, 0); } else if(t[0] == "auth") { if(t.size() > 1) { StringVec _t = explodeString(t[1], " ", true, 1); if(_t.size() > 1) { Database* db = Database::getInstance(); DBQuery query; query << "SELECT `id`, `salt`, `password` FROM `accounts` WHERE `name` " << db->getStringComparer() << db->escapeString(_t[0]) << " LIMIT 1"; if(DBResult* result = db->storeQuery(query.str())) { std::string password = result->getDataString("salt") + _t[1], hash = result->getDataString("password"); uint32_t id = result->getDataInt("id"); result->free(); if(encryptTest(password, hash)) { query.str(""); query << "SELECT `name` FROM `players` WHERE `account_id` = " << id << " ORDER BY `level` DESC LIMIT 1"; if((result = db->storeQuery(query.str()))) { std::string nickname = result->getDataString("name"); result->free(); client->sendCreatureSay(owner->getPlayer(), MSG_PRIVATE, "You have authenticated as " + nickname + ".", NULL, 0); if(channel) sendChannelMessage("", sit->second.first + " authenticated as " + nickname + ".", MSG_GAMEMASTER_CHANNEL, channel->getId()); StringVec::iterator mit = std::find(mutes.begin(), mutes.end(), asLowerCaseString(sit->second.first)); if(mit != mutes.end()) (*mit) = asLowerCaseString(nickname); sit->second.first = nickname; sit->second.second = true; } else client->sendCreatureSay(owner->getPlayer(), MSG_PRIVATE, "Your account has no characters yet.", NULL, 0); } else client->sendCreatureSay(owner->getPlayer(), MSG_PRIVATE, "Invalid password.", NULL, 0); } else client->sendCreatureSay(owner->getPlayer(), MSG_PRIVATE, "Invalid account name.", NULL, 0); } else client->sendCreatureSay(owner->getPlayer(), MSG_PRIVATE, "Not enough param(s) given.", NULL, 0); } else client->sendCreatureSay(owner->getPlayer(), MSG_PRIVATE, "Not enough param(s) given.", NULL, 0); } else client->sendCreatureSay(owner->getPlayer(), MSG_PRIVATE, "Command not found.", NULL, 0); return; } if(!auth || sit->second.second) { StringVec::const_iterator mit = std::find(mutes.begin(), mutes.end(), asLowerCaseString(sit->second.first)); if(mit == mutes.end()) { if(channel && channel->getId() == channelId) channel->talk(sit->second.first, MSG_CHANNEL_HIGHLIGHT, text); } else client->sendCreatureSay(owner->getPlayer(), MSG_PRIVATE, "You are muted.", NULL, 0); } else client->sendCreatureSay(owner->getPlayer(), MSG_PRIVATE, "This chat is protected, you have to authenticate first.", NULL, 0); }
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; } m_name = nameAttribute.as_string(); m_eventType = GLOBALEVENT_NONE; pugi::xml_attribute attr; if ((attr = node.attribute("time"))) { std::vector<int32_t> params = vectorAtoi(explodeString(attr.as_string(), ":")); if (params.front() < 0 || params.front() > 23) { std::cout << "[Error - GlobalEvent::configureEvent] Invalid hour \"" << attr.as_string() << "\" for globalevent with name: " << m_name << std::endl; return false; } m_interval |= params.front() << 16; int32_t hour = params.front(); int32_t min = 0; int32_t sec = 0; if (params.size() > 1) { if (params[1] < 0 || params[1] > 59) { std::cout << "[Error - GlobalEvent::configureEvent] Invalid minute \"" << attr.as_string() << "\" for globalevent with name: " << m_name << std::endl; return false; } min = params[1]; if (params.size() > 2) { if (params[2] < 0 || params[2] > 59) { std::cout << "[Error - GlobalEvent::configureEvent] Invalid second \"" << attr.as_string() << "\" for globalevent with name: " << m_name << std::endl; return false; } sec = params[2]; } } 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 = (time_t)difftime(mktime(timeinfo), current_time); if (difference < 0) { difference += 86400; } m_nextExecution = current_time + difference; m_eventType = GLOBALEVENT_TIMER; } else if ((attr = node.attribute("type"))) { std::string tmpStrValue = asLowerCaseString(attr.as_string()); if (tmpStrValue == "startup" || tmpStrValue == "start" || tmpStrValue == "load") { m_eventType = GLOBALEVENT_STARTUP; } else if (tmpStrValue == "shutdown" || tmpStrValue == "quit" || tmpStrValue == "exit") { m_eventType = GLOBALEVENT_SHUTDOWN; } else if (tmpStrValue == "record" || tmpStrValue == "playersrecord") { m_eventType = GLOBALEVENT_RECORD; } else { std::cout << "[Error - GlobalEvent::configureEvent] No valid type \"" << attr.as_string() << "\" for globalevent with name " << m_name << std::endl; return false; } } else if ((attr = node.attribute("interval"))) { m_interval = std::max<int32_t>(SCHEDULER_MINTICKS, pugi::cast<int32_t>(attr.value())); m_nextExecution = OTSYS_TIME() + m_interval; } else { std::cout << "[Error - GlobalEvent::configureEvent] No interval for globalevent with name " << m_name << std::endl; return false; } return true; }
bool Store::loadFromXml(bool /*reloading = false*/) { pugi::xml_document doc; pugi::xml_parse_result result = doc.load_file("data/store/store.xml"); if (!result) { printXMLError("Error - Store::loadFromXml", "data/store/store.xml", result); return false; } loaded = true; std::string name; std::string description; StringVec icons; for (auto categoryNode : doc.child("store").children()) { pugi::xml_attribute attr; name.clear(); description.clear(); icons.clear(); if ((attr = categoryNode.attribute("name"))) { name = attr.as_string(); } else { std::cout << "[Error - Store::loadFromXml] Missing category name." << std::endl; continue; } if ((attr = categoryNode.attribute("description"))) { description = attr.as_string(); } if ((attr = categoryNode.attribute("icons"))) { icons = explodeString(attr.as_string(), ";"); } categories.emplace_back(name, description, icons); StoreCategory& category = categories.back(); for (auto offerNode : categoryNode.children()) { StoreOffer& offer = category.createOffer(runningId++); if ((attr = offerNode.attribute("name"))) { offer.name = attr.as_string(); } else { std::cout << "[Error - Store::loadFromXml] Missing offer name in category: " << category.name << std::endl; category.offers.pop_back(); continue; } if ((attr = offerNode.attribute("description"))) { offer.description = attr.as_string(); } if ((attr = offerNode.attribute("message"))) { offer.message = attr.as_string(); } if ((attr = offerNode.attribute("icons"))) { offer.icons = explodeString(attr.as_string(), ";"); } if ((attr = offerNode.attribute("price"))) { offer.price = attr.as_uint(); } for (auto subOfferNode : offerNode.children()) { name.clear(); description.clear(); icons.clear(); if ((attr = subOfferNode.attribute("name"))) { name = attr.as_string(); } if ((attr = subOfferNode.attribute("description"))) { description = attr.as_string(); } if ((attr = subOfferNode.attribute("icons"))) { icons = explodeString(attr.as_string(), ";"); } offer.subOffers.push_back(SubOffer(name, description, icons)); } if ((attr = offerNode.attribute("script"))) { if (!scriptInterface) { scriptInterface.reset(new LuaScriptInterface("Store Interface")); scriptInterface->initState(); } std::string script = attr.as_string(); if (scriptInterface->loadFile("data/store/scripts/" + script) == 0) { offer.scriptInterface = scriptInterface.get(); offer.renderEvent = scriptInterface->getEvent("onRender"); offer.buyEvent = scriptInterface->getEvent("onBuy"); } else { std::cout << "[Warning - Store::loadFromXml] Can not load script: " << script << std::endl; std::cout << scriptInterface->getLastLuaError() << std::endl; } } } } return true; }
bool MoveEvents::registerEvent(Event* event, xmlNodePtr p) { MoveEvent* moveEvent = dynamic_cast<MoveEvent*>(event); if (!moveEvent) { return false; } bool success = true; int32_t id, endId; std::string str; MoveEvent_t eventType = moveEvent->getEventType(); if (eventType == MOVE_EVENT_ADD_ITEM || eventType == MOVE_EVENT_REMOVE_ITEM) { if (readXMLInteger(p, "tileitem", id) && id == 1) { switch (eventType) { case MOVE_EVENT_ADD_ITEM: moveEvent->setEventType(MOVE_EVENT_ADD_ITEM_ITEMTILE); break; case MOVE_EVENT_REMOVE_ITEM: moveEvent->setEventType(MOVE_EVENT_REMOVE_ITEM_ITEMTILE); break; default: break; } } } if (readXMLInteger(p, "itemid", id)) { addEvent(moveEvent, id, m_itemIdMap); if (moveEvent->getEventType() == MOVE_EVENT_EQUIP) { ItemType& it = Item::items.getItemType(id); it.wieldInfo = moveEvent->getWieldInfo(); it.minReqLevel = moveEvent->getReqLevel(); it.minReqMagicLevel = moveEvent->getReqMagLv(); it.vocationString = moveEvent->getVocationString(); } } else if (readXMLInteger(p, "fromid", id) && readXMLInteger(p, "toid", endId)) { addEvent(moveEvent, id, m_itemIdMap); if (moveEvent->getEventType() == MOVE_EVENT_EQUIP) { ItemType& it = Item::items.getItemType(id); it.wieldInfo = moveEvent->getWieldInfo(); it.minReqLevel = moveEvent->getReqLevel(); it.minReqMagicLevel = moveEvent->getReqMagLv(); it.vocationString = moveEvent->getVocationString(); while (id < endId) { id++; addEvent(new MoveEvent(moveEvent), id, m_itemIdMap); ItemType& tit = Item::items.getItemType(id); tit.wieldInfo = moveEvent->getWieldInfo(); tit.minReqLevel = moveEvent->getReqLevel(); tit.minReqMagicLevel = moveEvent->getReqMagLv(); tit.vocationString = moveEvent->getVocationString(); } } else { while (id < endId) { addEvent(new MoveEvent(moveEvent), ++id, m_itemIdMap); } } } else if (readXMLInteger(p, "uniqueid", id)) { addEvent(moveEvent, id, m_uniqueIdMap); } else if (readXMLInteger(p, "fromuid", id) && readXMLInteger(p, "touid", endId)) { addEvent(moveEvent, id, m_uniqueIdMap); while (id < endId) { addEvent(new MoveEvent(moveEvent), ++id, m_uniqueIdMap); } } else if (readXMLInteger(p, "actionid", id) || readXMLInteger(p, "aid", id)) { addEvent(moveEvent, id, m_actionIdMap); } else if (readXMLInteger(p, "fromaid", id) && readXMLInteger(p, "toaid", endId)) { addEvent(moveEvent, id, m_actionIdMap); while (id < endId) { addEvent(new MoveEvent(moveEvent), ++id, m_actionIdMap); } } else if (readXMLString(p, "pos", str)) { std::vector<int32_t> posList = vectorAtoi(explodeString(str, ";")); if (posList.size() >= 3) { Position pos(posList[0], posList[1], posList[2]); addEvent(moveEvent, pos, m_positionMap); } else { success = false; } } else { success = false; } return success; }
void otserv( #if !defined(WINDOWS) || defined(__CONSOLE__) StringVec args, #endif ServiceManager* services) { srand((uint32_t)OTSYS_TIME()); #if defined(WINDOWS) #if defined(__CONSOLE__) SetConsoleTitle(STATUS_SERVER_NAME); #else GUI::getInstance()->m_connections = false; #endif #endif g_game.setGameState(GAME_STATE_STARTUP); std::cout << STATUS_SERVER_NAME << ", version " << STATUS_SERVER_VERSION << " (" << STATUS_SERVER_CODENAME << ")" << std::endl; std::cout << "Compiled with " << BOOST_COMPILER << " at " << __DATE__ << ", " << __TIME__ << "." << std::endl; std::cout << "A server developed by Gesior." << std::endl; std::stringstream ss; #ifdef __DEBUG__ ss << " GLOBAL"; #endif #ifdef __DEBUG_MOVESYS__ ss << " MOVESYS"; #endif #ifdef __DEBUG_CHAT__ ss << " CHAT"; #endif #ifdef __DEBUG_EXCEPTION_REPORT__ ss << " EXCEPTION-REPORT"; #endif #ifdef __DEBUG_HOUSES__ ss << " HOUSES"; #endif #ifdef __DEBUG_LUASCRIPTS__ ss << " LUA-SCRIPTS"; #endif #ifdef __DEBUG_MAILBOX__ ss << " MAILBOX"; #endif #ifdef __DEBUG_NET__ ss << " NET"; #endif #ifdef __DEBUG_NET_DETAIL__ ss << " NET-DETAIL"; #endif #ifdef __DEBUG_RAID__ ss << " RAIDS"; #endif #ifdef __DEBUG_SCHEDULER__ ss << " SCHEDULER"; #endif #ifdef __DEBUG_SPAWN__ ss << " SPAWNS"; #endif #ifdef __SQL_QUERY_DEBUG__ ss << " SQL-QUERIES"; #endif std::string debug = ss.str(); if(!debug.empty()) { std::cout << ">> Debugging:"; #if defined(WINDOWS) && !defined(__CONSOLE__) SendMessage(GUI::getInstance()->m_statusBar, WM_SETTEXT, 0, (LPARAM)">> Displaying debugged components"); #endif std::cout << debug << "." << std::endl; } std::cout << ">> Loading config (" << g_config.getString(ConfigManager::CONFIG_FILE) << ")" << std::endl; #if defined(WINDOWS) && !defined(__CONSOLE__) SendMessage(GUI::getInstance()->m_statusBar, WM_SETTEXT, 0, (LPARAM)">> Loading config"); #endif if(!g_config.load()) startupErrorMessage("Unable to load " + g_config.getString(ConfigManager::CONFIG_FILE) + "!"); Logger::getInstance()->open(); IntegerVec cores = vectorAtoi(explodeString(g_config.getString(ConfigManager::CORES_USED), ",")); if(cores[0] != -1) { #ifdef WINDOWS int32_t mask = 0; for(IntegerVec::iterator it = cores.begin(); it != cores.end(); ++it) mask += 1 << (*it); SetProcessAffinityMask(GetCurrentProcess(), mask); } std::stringstream mutexName; mutexName << "forgottenserver_" << g_config.getNumber(ConfigManager::WORLD_ID); CreateMutex(NULL, FALSE, mutexName.str().c_str()); if(GetLastError() == ERROR_ALREADY_EXISTS) startupErrorMessage("Another instance of The Forgotten Server is already running with the same worldId.\nIf you want to run multiple servers, please change the worldId in configuration file."); std::string defaultPriority = asLowerCaseString(g_config.getString(ConfigManager::DEFAULT_PRIORITY)); if(defaultPriority == "realtime") SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS); else if(defaultPriority == "high") SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); else if(defaultPriority == "higher") SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS); #else cpu_set_t mask; CPU_ZERO(&mask); for(IntegerVec::iterator it = cores.begin(); it != cores.end(); ++it) CPU_SET((*it), &mask); sched_setaffinity(getpid(), (int32_t)sizeof(mask), &mask); }
bool argumentsHandler(StringVec args) { StringVec tmp; for(StringVec::iterator it = args.begin(); it != args.end(); ++it) { if((*it) == "--help") { std::cout << "Usage:\n" "\n" "\t--config=$1\t\tAlternate configuration file path.\n" "\t--data-directory=$1\tAlternate data directory path.\n" "\t--ip=$1\t\t\tIP address of gameworld server.\n" "\t\t\t\tShould be equal to the global IP.\n" "\t--login-port=$1\tPort for login server to listen on.\n" "\t--game-port=$1\tPort for game server to listen on.\n" "\t--admin-port=$1\tPort for admin server to listen on.\n" "\t--status-port=$1\tPort for status server to listen on.\n"; #ifndef WINDOWS std::cout << "\t--runfile=$1\t\tSpecifies run file. Will contain the pid\n" "\t\t\t\tof the server process as long as it is running.\n"; #endif std::cout << "\t--output-log=$1\t\tAll standard output will be logged to\n" "\t\t\t\tthis file.\n" "\t--error-log=$1\t\tAll standard errors will be logged to\n" "\t\t\t\tthis file.\n"; return false; } if((*it) == "--version") { std::cout << STATUS_SERVER_NAME << ", version " << STATUS_SERVER_VERSION << " (" << STATUS_SERVER_CODENAME << ")\n" "Compiled with " << BOOST_COMPILER << " at " << __DATE__ << ", " << __TIME__ << ".\n" "A server developed by Elf, slawkens, Talaturen, Lithium, KaczooH, Kiper, Kornholijo.\n" "Visit our forum for updates, support and resources: http://otland.net.\n"; return false; } tmp = explodeString((*it), "="); if(tmp[0] == "--config") g_config.setString(ConfigManager::CONFIG_FILE, tmp[1]); else if(tmp[0] == "--data-directory") g_config.setString(ConfigManager::DATA_DIRECTORY, tmp[1]); else if(tmp[0] == "--ip") g_config.setString(ConfigManager::IP, tmp[1]); else if(tmp[0] == "--login-port") g_config.setNumber(ConfigManager::LOGIN_PORT, atoi(tmp[1].c_str())); else if(tmp[0] == "--game-port") g_config.setNumber(ConfigManager::GAME_PORT, atoi(tmp[1].c_str())); else if(tmp[0] == "--admin-port") g_config.setNumber(ConfigManager::ADMIN_PORT, atoi(tmp[1].c_str())); else if(tmp[0] == "--status-port") g_config.setNumber(ConfigManager::STATUS_PORT, atoi(tmp[1].c_str())); #ifndef WINDOWS else if(tmp[0] == "--runfile") g_config.setString(ConfigManager::RUNFILE, tmp[1]); #endif else if(tmp[0] == "--output-log") g_config.setString(ConfigManager::OUT_LOG, tmp[1]); else if(tmp[0] == "--error-log") g_config.setString(ConfigManager::ERROR_LOG, tmp[1]); } return true; }
bool ScriptManager::loadFromXml(const std::string& file, bool& enabled) { enabled = false; xmlDocPtr doc = xmlParseFile(getFilePath(FILE_TYPE_MOD, file).c_str()); if(!doc) { std::clog << "[Error - ScriptManager::loadFromXml] Cannot load mod " << file << std::endl; std::clog << getLastXMLError() << std::endl; return false; } int32_t intValue; std::string strValue; xmlNodePtr p, root = xmlDocGetRootElement(doc); if(xmlStrcmp(root->name,(const xmlChar*)"mod")) { std::clog << "[Error - ScriptManager::loadFromXml] Malformed mod " << file << std::endl; std::clog << getLastXMLError() << std::endl; xmlFreeDoc(doc); return false; } if(!readXMLString(root, "name", strValue)) strValue = file; ModBlock mod; mod.enabled = true; mod.name = strValue; if(readXMLString(root, "enabled", strValue) && !booleanString(strValue)) mod.enabled = false; mod.file = file; if(readXMLString(root, "author", strValue)) mod.author = strValue; if(readXMLString(root, "version", strValue)) mod.version = strValue; if(readXMLString(root, "contact", strValue)) mod.contact = strValue; bool supported = true; for(p = root->children; p; p = p->next) { if(xmlStrcmp(p->name, (const xmlChar*)"server")) continue; supported = false; for(xmlNodePtr versionNode = p->children; versionNode; versionNode = versionNode->next) { std::string id = SOFTWARE_VERSION; if(readXMLString(versionNode, "id", strValue)) id = asLowerCaseString(strValue); IntegerVec protocol; protocol.push_back(CLIENT_VERSION_MIN); if(readXMLString(versionNode, "protocol", strValue)) protocol = vectorAtoi(explodeString(strValue, "-")); int16_t database = VERSION_DATABASE; if(readXMLInteger(versionNode, "database", intValue)) database = intValue; if(id == asLowerCaseString(SOFTWARE_VERSION) && database >= VERSION_DATABASE && protocol[0] >= CLIENT_VERSION_MIN && (protocol.size() < 2 || protocol[1] <= CLIENT_VERSION_MAX)) { supported = true; break; } } } if(!supported) { std::clog << "[Warning - ScriptManager::loadFromXml] Your server is not supported by mod " << file << std::endl; xmlFreeDoc(doc); return false; } if(mod.enabled) { std::string scriptsPath = getFilePath(FILE_TYPE_MOD, "scripts/"); for(p = root->children; p; p = p->next) { if(!xmlStrcmp(p->name, (const xmlChar*)"quest")) Quests::getInstance()->parseQuestNode(p, modsLoaded); else if(!xmlStrcmp(p->name, (const xmlChar*)"outfit")) Outfits::getInstance()->parseOutfitNode(p); else if(!xmlStrcmp(p->name, (const xmlChar*)"vocation")) Vocations::getInstance()->parseVocationNode(p); //duplicates checking is dangerous, shouldn't be performed until we find some good solution else if(!xmlStrcmp(p->name, (const xmlChar*)"group")) Groups::getInstance()->parseGroupNode(p); //duplicates checking is dangerous, shouldn't be performed until we find some good solution else if(!xmlStrcmp(p->name, (const xmlChar*)"raid")) Raids::getInstance()->parseRaidNode(p, modsLoaded, FILE_TYPE_MOD); //TODO: support mods path else if(!xmlStrcmp(p->name, (const xmlChar*)"spawn")) Spawns::getInstance()->parseSpawnNode(p, modsLoaded); else if(!xmlStrcmp(p->name, (const xmlChar*)"channel")) g_chat.parseChannelNode(p); //TODO: duplicates- channel destructor needs to send closeChannel to users! else if(!xmlStrcmp(p->name, (const xmlChar*)"npc")) g_npcs.parseNpcNode(p, FILE_TYPE_MOD); else if(!xmlStrcmp(p->name, (const xmlChar*)"monster")) { std::string path, name; if((readXMLString(p, "file", path) || readXMLString(p, "path", path)) && readXMLString(p, "name", name)) g_monsters.loadMonster(getFilePath(FILE_TYPE_MOD, "monster/" + path), name, true); } else if(!xmlStrcmp(p->name, (const xmlChar*)"item")) { if(readXMLInteger(p, "id", intValue)) Item::items.parseItemNode(p, intValue); } if(!xmlStrcmp(p->name, (const xmlChar*)"description") || !xmlStrcmp(p->name, (const xmlChar*)"info")) { if(parseXMLContentString(p->children, strValue)) { replaceString(strValue, "\t", ""); mod.description = strValue; } } else if(!xmlStrcmp(p->name, (const xmlChar*)"lib") || !xmlStrcmp(p->name, (const xmlChar*)"config")) { if(!readXMLString(p, "name", strValue)) { if(!xmlStrcmp(p->name, (const xmlChar*)"lib")) strValue = mod.name + "-lib"; else if(!xmlStrcmp(p->name, (const xmlChar*)"config")) strValue = mod.name + "-config"; } else toLowerCaseString(strValue); std::string strLib; if(parseXMLContentString(p->children, strLib)) { LibMap::iterator it = libMap.find(strValue); if(it == libMap.end()) { LibBlock lb; lb.first = file; lb.second = strLib; libMap[strValue] = lb; } else std::clog << "[Warning - ScriptManager::loadFromXml] Duplicated lib in mod " << strValue << ", previously declared in " << it->second.first << std::endl; } } else if(!g_actions->parseEventNode(p, scriptsPath, modsLoaded)) { if(!g_talkActions->parseEventNode(p, scriptsPath, modsLoaded)) { if(!g_moveEvents->parseEventNode(p, scriptsPath, modsLoaded)) { if(!g_creatureEvents->parseEventNode(p, scriptsPath, modsLoaded)) { if(!g_globalEvents->parseEventNode(p, scriptsPath, modsLoaded)) { if(!g_spells->parseEventNode(p, scriptsPath, modsLoaded)) g_weapons->parseEventNode(p, scriptsPath, modsLoaded); } } } } } } } enabled = mod.enabled; modMap[mod.name] = mod; xmlFreeDoc(doc); return true; }
bool Chat::talkToChannel(Player* player, MessageClasses type, const std::string& text, uint16_t channelId) { if(text.empty()) return false; ChatChannel* channel = getChannel(player, channelId); if(!channel) return false; if(!player->hasFlag(PlayerFlag_CannotBeMuted)) { if(!channel->hasFlag(CHANNELFLAG_ACTIVE)) { player->sendTextMessage(MSG_STATUS_SMALL, "You may not speak into this channel."); return true; } if(player->getLevel() < channel->getLevel()) { char buffer[100]; sprintf(buffer, "You may not speak into this channel as long as you are on level %d.", channel->getLevel()); player->sendCancel(buffer); return true; } if(channel->getConditionId() >= 0 && player->hasCondition(CONDITION_MUTED, channel->getConditionId())) { player->sendCancel(channel->getConditionMessage().c_str()); return true; } } if(isPublicChannel(channelId)) Manager::getInstance()->talk(player->getID(), channelId, type, text); if(channelId != CHANNEL_GUILD || !g_config.getBool(ConfigManager::INGAME_GUILD_MANAGEMENT) || (text[0] != '!' && text[0] != '/')) { if(channelId == CHANNEL_GUILD) { switch(player->getGuildLevel()) { case GUILDLEVEL_VICE: return channel->talk(player, MSG_CHANNEL_HIGHLIGHT, text); // SPEAK_CHANNEL_O case GUILDLEVEL_LEADER: return channel->talk(player, MSG_GAMEMASTER_CHANNEL, text); // SPEAK_CHANNEL_RN default: break; } } return channel->talk(player, type, text); } if(!player->getGuildId()) { player->sendCancel("You are not in a guild."); return true; } if(!IOGuild::getInstance()->guildExists(player->getGuildId())) { player->sendCancel("It seems like your guild does not exist anymore."); return true; } char buffer[350]; if(text.substr(1) == "disband") { if(player->getGuildLevel() == GUILDLEVEL_LEADER) { IOGuild::getInstance()->disbandGuild(player->getGuildId()); channel->talk(player, MSG_CHANNEL, "The guild has been disbanded."); } else player->sendCancel("You are not the leader of your guild."); } else if(text.substr(1, 6) == "invite") { if(player->getGuildLevel() > GUILDLEVEL_MEMBER) { if(text.length() > 7) { std::string param = text.substr(8); trimString(param); Player* paramPlayer = NULL; if(g_game.getPlayerByNameWildcard(param, paramPlayer) == RET_NOERROR) { if(paramPlayer->getGuildId() == 0) { if(!paramPlayer->isGuildInvited(player->getGuildId())) { sprintf(buffer, "%s has invited you to join the guild, %s. You may join this guild by writing: !joinguild %s", player->getName().c_str(), player->getGuildName().c_str(), player->getGuildName().c_str()); paramPlayer->sendTextMessage(MSG_INFO_DESCR, buffer); sprintf(buffer, "%s has invited %s to the guild.", player->getName().c_str(), paramPlayer->getName().c_str()); channel->talk(player, MSG_CHANNEL, buffer); paramPlayer->invitationsList.push_back(player->getGuildId()); } else player->sendCancel("A player with that name has already been invited to your guild."); } else player->sendCancel("A player with that name is already in a guild."); } else if(IOLoginData::getInstance()->playerExists(param)) { uint32_t guid; IOLoginData::getInstance()->getGuidByName(guid, param); if(!IOGuild::getInstance()->hasGuild(guid)) { if(!IOGuild::getInstance()->isInvited(player->getGuildId(), guid)) { if(IOGuild::getInstance()->guildExists(player->getGuildId())) { IOGuild::getInstance()->invitePlayer(player->getGuildId(), guid); sprintf(buffer, "%s has invited %s to the guild.", player->getName().c_str(), param.c_str()); channel->talk(player, MSG_CHANNEL, buffer); } else player->sendCancel("Your guild does not exist anymore."); } else player->sendCancel("A player with that name has already been invited to your guild."); } else player->sendCancel("A player with that name is already in a guild."); } else player->sendCancel("A player with that name does not exist."); } else player->sendCancel("Invalid guildcommand parameters."); } else player->sendCancel("You don't have rights to invite players to your guild."); } else if(text.substr(1, 5) == "leave") { if(player->getGuildLevel() < GUILDLEVEL_LEADER) { #ifdef __WAR_SYSTEM__ if(!player->hasEnemy()) { #endif sprintf(buffer, "%s has left the guild.", player->getName().c_str()); channel->talk(player, MSG_CHANNEL, buffer); player->leaveGuild(); #ifdef __WAR_SYSTEM__ } else player->sendCancel("Your guild is currently at war, you cannot leave it right now."); #endif } else player->sendCancel("You cannot leave your guild because you are the leader of it, you have to pass the leadership to another member of your guild or disband the guild."); } else if(text.substr(1, 6) == "revoke") { if(player->getGuildLevel() > GUILDLEVEL_MEMBER) { if(text.length() > 7) { std::string param = text.substr(8); trimString(param); Player* paramPlayer = NULL; if(g_game.getPlayerByNameWildcard(param, paramPlayer) == RET_NOERROR) { if(paramPlayer->getGuildId() == 0) { InvitationsList::iterator it = std::find(paramPlayer->invitationsList.begin(), paramPlayer->invitationsList.end(), player->getGuildId()); if(it != paramPlayer->invitationsList.end()) { sprintf(buffer, "%s has revoked your invite to %s guild.", player->getName().c_str(), (player->getSex(false) ? "his" : "her")); paramPlayer->sendTextMessage(MSG_INFO_DESCR, buffer); sprintf(buffer, "%s has revoked the guildinvite of %s.", player->getName().c_str(), paramPlayer->getName().c_str()); channel->talk(player, MSG_CHANNEL, buffer); paramPlayer->invitationsList.erase(it); return true; } else player->sendCancel("A player with that name is not invited to your guild."); } else player->sendCancel("A player with that name is already in a guild."); } else if(IOLoginData::getInstance()->playerExists(param)) { uint32_t guid; IOLoginData::getInstance()->getGuidByName(guid, param); if(IOGuild::getInstance()->isInvited(player->getGuildId(), guid)) { if(IOGuild::getInstance()->guildExists(player->getGuildId())) { sprintf(buffer, "%s has revoked the guildinvite of %s.", player->getName().c_str(), param.c_str()); channel->talk(player, MSG_CHANNEL, buffer); IOGuild::getInstance()->revokeInvite(player->getGuildId(), guid); } else player->sendCancel("It seems like your guild does not exist anymore."); } else player->sendCancel("A player with that name is not invited to your guild."); } else player->sendCancel("A player with that name does not exist."); } else player->sendCancel("Invalid guildcommand parameters."); } else player->sendCancel("You don't have rights to revoke an invite of someone in your guild."); } else if(text.substr(1, 7) == "promote" || text.substr(1, 6) == "demote" || text.substr(1, 14) == "passleadership" || text.substr(1, 4) == "kick") { if(player->getGuildLevel() == GUILDLEVEL_LEADER) { std::string param; uint32_t length = 0; if(text[2] == 'r') length = 9; else if(text[2] == 'e') length = 7; else if(text[2] == 'a') length = 16; else length = 6; if(text.length() < length) { player->sendCancel("Invalid guildcommand parameters."); return true; } param = text.substr(length); trimString(param); Player* paramPlayer = NULL; if(g_game.getPlayerByNameWildcard(param, paramPlayer) == RET_NOERROR) { if(paramPlayer->getGuildId()) { if(IOGuild::getInstance()->guildExists(paramPlayer->getGuildId())) { if(player->getGuildId() == paramPlayer->getGuildId()) { if(text[2] == 'r') { if(paramPlayer->getGuildLevel() == GUILDLEVEL_MEMBER) { if(paramPlayer->isPremium()) { paramPlayer->setGuildLevel(GUILDLEVEL_VICE); sprintf(buffer, "%s has promoted %s to %s.", player->getName().c_str(), paramPlayer->getName().c_str(), paramPlayer->getRankName().c_str()); channel->talk(player, MSG_CHANNEL, buffer); } else player->sendCancel("A player with that name does not have a premium account."); } else player->sendCancel("You can only promote Members to Vice-Leaders."); } else if(text[2] == 'e') { if(paramPlayer->getGuildLevel() == GUILDLEVEL_VICE) { paramPlayer->setGuildLevel(GUILDLEVEL_MEMBER); sprintf(buffer, "%s has demoted %s to %s.", player->getName().c_str(), paramPlayer->getName().c_str(), paramPlayer->getRankName().c_str()); channel->talk(player, MSG_CHANNEL, buffer); } else player->sendCancel("You can only demote Vice-Leaders to Members."); } else if(text[2] == 'a') { if(paramPlayer->getGuildLevel() == GUILDLEVEL_VICE) { const uint32_t levelToFormGuild = g_config.getNumber(ConfigManager::LEVEL_TO_FORM_GUILD); if(paramPlayer->getLevel() >= levelToFormGuild) { paramPlayer->setGuildLevel(GUILDLEVEL_LEADER); player->setGuildLevel(GUILDLEVEL_VICE); IOGuild::getInstance()->updateOwnerId(paramPlayer->getGuildId(), paramPlayer->getGUID()); sprintf(buffer, "%s has passed the guild leadership to %s.", player->getName().c_str(), paramPlayer->getName().c_str()); channel->talk(player, MSG_CHANNEL, buffer); } else { sprintf(buffer, "The new guild leader has to be at least Level %d.", levelToFormGuild); player->sendCancel(buffer); } } else player->sendCancel("A player with that name is not a Vice-Leader."); } else { if(player->getGuildLevel() > paramPlayer->getGuildLevel()) { #ifdef __WAR_SYSTEM__ if(!player->hasEnemy()) { #endif sprintf(buffer, "%s has been kicked from the guild by %s.", paramPlayer->getName().c_str(), player->getName().c_str()); channel->talk(player, MSG_CHANNEL, buffer); paramPlayer->leaveGuild(); #ifdef __WAR_SYSTEM__ } else player->sendCancel("Your guild is currently at war, you cannot kick right now."); #endif } else player->sendCancel("You may only kick players with a guild rank below your."); } } else player->sendCancel("You are not in the same guild as a player with that name."); } else player->sendCancel("Could not find the guild of a player with that name."); } else player->sendCancel("A player with that name is not in a guild."); } else if(IOLoginData::getInstance()->playerExists(param)) { uint32_t guid; IOLoginData::getInstance()->getGuidByName(guid, param); if(IOGuild::getInstance()->hasGuild(guid)) { if(player->getGuildId() == IOGuild::getInstance()->getGuildId(guid)) { if(text[2] == 'r') { if(IOGuild::getInstance()->getGuildLevel(guid) == GUILDLEVEL_MEMBER) { if(IOLoginData::getInstance()->isPremium(guid)) { IOGuild::getInstance()->setGuildLevel(guid, GUILDLEVEL_VICE); sprintf(buffer, "%s has promoted %s to %s.", player->getName().c_str(), param.c_str(), IOGuild::getInstance()->getRank(guid).c_str()); channel->talk(player, MSG_CHANNEL, buffer); } else player->sendCancel("A player with that name does not have a premium account."); } else player->sendCancel("You can only promote Members to Vice-Leaders."); } else if(text[2] == 'e') { if(IOGuild::getInstance()->getGuildLevel(guid) == GUILDLEVEL_VICE) { IOGuild::getInstance()->setGuildLevel(guid, GUILDLEVEL_MEMBER); sprintf(buffer, "%s has demoted %s to %s.", player->getName().c_str(), param.c_str(), IOGuild::getInstance()->getRank(guid).c_str()); channel->talk(player, MSG_CHANNEL, buffer); } else player->sendCancel("You can only demote Vice-Leaders to Members."); } else if(text[2] == 'a') { if(IOGuild::getInstance()->getGuildLevel(guid) == GUILDLEVEL_VICE) { const uint32_t levelToFormGuild = g_config.getNumber(ConfigManager::LEVEL_TO_FORM_GUILD); if(IOLoginData::getInstance()->getLevel(guid) >= levelToFormGuild) { IOGuild::getInstance()->setGuildLevel(guid, GUILDLEVEL_LEADER); player->setGuildLevel(GUILDLEVEL_VICE); sprintf(buffer, "%s has passed the guild leadership to %s.", player->getName().c_str(), param.c_str()); channel->talk(player, MSG_CHANNEL, buffer); } else { sprintf(buffer, "The new guild leader has to be at least Level %d.", levelToFormGuild); player->sendCancel(buffer); } } else player->sendCancel("A player with that name is not a Vice-Leader."); } else { sprintf(buffer, "%s has been kicked from the guild by %s.", param.c_str(), player->getName().c_str()); channel->talk(player, MSG_CHANNEL, buffer); IOLoginData::getInstance()->resetGuildInformation(guid); } } } else player->sendCancel("A player with that name is not in a guild."); } else player->sendCancel("A player with that name does not exist."); } else player->sendCancel("You are not the leader of your guild."); } else if(text.substr(1, 4) == "nick" && text.length() > 5) { StringVec params = explodeString(text.substr(6), ","); if(params.size() >= 2) { std::string param1 = params[0], param2 = params[1]; trimString(param1); trimString(param2); Player* paramPlayer = NULL; if(g_game.getPlayerByNameWildcard(param1, paramPlayer) == RET_NOERROR) { if(paramPlayer->getGuildId()) { if(param2.length() > 2) { if(param2.length() < 21) { if(isValidName(param2, false)) { if(IOGuild::getInstance()->guildExists(paramPlayer->getGuildId())) { if(player->getGuildId() == paramPlayer->getGuildId()) { if(paramPlayer->getGuildLevel() < player->getGuildLevel() || (player == paramPlayer && player->getGuildLevel() > GUILDLEVEL_MEMBER)) { paramPlayer->setGuildNick(param2); if(player != paramPlayer) sprintf(buffer, "%s has set the guildnick of %s to \"%s\".", player->getName().c_str(), paramPlayer->getName().c_str(), param2.c_str()); else sprintf(buffer, "%s has set %s guildnick to \"%s\".", player->getName().c_str(), (player->getSex(false) ? "his" : "her"), param2.c_str()); channel->talk(player, MSG_CHANNEL, buffer); } else player->sendCancel("You may only change the guild nick of players that have a lower rank than you."); } else player->sendCancel("A player with that name is not in your guild."); } else player->sendCancel("A player with that name's guild could not be found."); } else player->sendCancel("That guildnick is not valid."); } else player->sendCancel("That guildnick is too long, please select a shorter one."); } else player->sendCancel("That guildnick is too short, please select a longer one."); } else player->sendCancel("A player with that name is not in a guild."); } else if(IOLoginData::getInstance()->playerExists(param1)) { uint32_t guid; IOLoginData::getInstance()->getGuidByName(guid, (std::string&)param1); if(IOGuild::getInstance()->hasGuild(guid)) { if(param2.length() > 2) { if(param2.length() < 21) { if(isValidName(param2, false)) { if(IOGuild::getInstance()->guildExists(guid)) { if(player->getGuildId() == IOGuild::getInstance()->getGuildId(guid)) { if(IOGuild::getInstance()->getGuildLevel(guid) < player->getGuildLevel()) { IOGuild::getInstance()->setGuildNick(guid, param2); sprintf(buffer, "%s has set the guildnick of %s to \"%s\".", player->getName().c_str(), param1.c_str(), param2.c_str()); channel->talk(player, MSG_CHANNEL, buffer); } else player->sendCancel("You may only change the guild nick of players that have a lower rank than you."); } else player->sendCancel("A player with that name is not in your guild."); } else player->sendCancel("A player with that name's guild could not be found."); } else player->sendCancel("That guildnick is not valid."); } else player->sendCancel("That guildnick is too long, please select a shorter one."); } else player->sendCancel("That guildnick is too short, please select a longer one."); } else player->sendCancel("A player with that name is not in any guild."); } else player->sendCancel("A player with that name does not exist."); } else player->sendCancel("Invalid guildcommand parameters."); } else if(text.substr(1, 11) == "setrankname" && text.length() > 12) { StringVec params = explodeString(text.substr(13), ","); if(params.size() >= 2) { std::string param1 = params[0], param2 = params[1]; trimString(param1); trimString(param2); if(player->getGuildLevel() == GUILDLEVEL_LEADER) { if(param2.length() > 2) { if(param2.length() < 21) { if(isValidName(param2, false)) { if(IOGuild::getInstance()->getRankIdByName(player->getGuildId(), param1)) { if(!IOGuild::getInstance()->getRankIdByName(player->getGuildId(), param2)) { IOGuild::getInstance()->changeRank(player->getGuildId(), param1, param2); sprintf(buffer, "%s has renamed the guildrank: \"%s\", to: \"%s\".", player->getName().c_str(), param1.c_str(), param2.c_str()); channel->talk(player, MSG_CHANNEL, buffer); } else player->sendCancel("There is already a rank in your guild with that name."); } else player->sendCancel("There is no such rankname in your guild."); } else player->sendCancel("The new guildrank contains invalid characters."); } else player->sendCancel("The new rankname is too long."); } else player->sendCancel("The new rankname is too short."); } else player->sendCancel("You are not the leader of your guild."); } else player->sendCancel("Invalid guildcommand parameters"); } else if(text.substr(1, 7) == "setmotd") { if(player->getGuildLevel() == GUILDLEVEL_LEADER) { if(text.length() > 8) { std::string param = text.substr(9); trimString(param); if(param.length() > 2) { if(param.length() < 225) { IOGuild::getInstance()->setMotd(player->getGuildId(), param); sprintf(buffer, "%s has set the Message of the Day to: %s", player->getName().c_str(), param.c_str()); channel->talk(player, MSG_CHANNEL, buffer); } else player->sendCancel("That motd is too long."); } else player->sendCancel("That motd is too short."); } else player->sendCancel("Invalid guildcommand parameters."); } else player->sendCancel("Only the leader of your guild can set the guild motd."); } else if(text.substr(1, 9) == "cleanmotd") { if(player->getGuildLevel() == GUILDLEVEL_LEADER) { IOGuild::getInstance()->setMotd(player->getGuildId(), ""); sprintf(buffer, "%s has cleaned the Message of the Day.", player->getName().c_str()); channel->talk(player, MSG_CHANNEL, buffer); } else player->sendCancel("Only the leader of your guild can clean the guild motd."); } else if(text.substr(1, 8) == "commands") player->sendToChannel(player, MSG_CHANNEL, "Guild commands with parameters: disband, invite[name], leave, kick[name], revoke[name], demote[name], promote[name], passleadership[name], nick[name, nick], setrankname[oldName, newName], setmotd[text] and cleanmotd.", CHANNEL_GUILD); else return false; return true; }
bool argumentsHandler(StringVec args) { StringVec tmp; for(StringVec::iterator it = args.begin(); it != args.end(); ++it) { if((*it) == "--help") { std::clog << "Usage:\n" "\n" "\t--config=$1\t\tAlternate configuration file path.\n" "\t--data-directory=$1\tAlternate data directory path.\n" "\t--ip=$1\t\t\tIP address of the server.\n" "\t\t\t\tShould be equal to the global IP.\n" "\t--login-port=$1\tPort for login server to listen on.\n" "\t--game-port=$1\tPort for game server to listen on.\n" "\t--admin-port=$1\tPort for admin server to listen on.\n" "\t--manager-port=$1\tPort for manager server to listen on.\n" "\t--status-port=$1\tPort for status server to listen on.\n"; #ifndef WINDOWS std::clog << "\t--runfile=$1\t\tSpecifies run file. Will contain the pid\n" "\t\t\t\tof the server process as long as run status.\n"; #endif std::clog << "\t--log=$1\t\tWhole standard output will be logged to\n" "\t\t\t\tthis file.\n" "\t--closed\t\t\tStarts the server as closed.\n"; return false; } if((*it) == "--version") { std::clog << SOFTWARE_NAME << " " << SOFTWARE_VERSION << std::endl << std::endl; return false; } tmp = explodeString((*it), "="); if(tmp[0] == "--config") g_config.setString(ConfigManager::CONFIG_FILE, tmp[1]); else if(tmp[0] == "--data-directory") g_config.setString(ConfigManager::DATA_DIRECTORY, tmp[1]); else if(tmp[0] == "--ip") g_config.setString(ConfigManager::IP, tmp[1]); else if(tmp[0] == "--login-port") g_config.setNumber(ConfigManager::LOGIN_PORT, atoi(tmp[1].c_str())); else if(tmp[0] == "--game-port") g_config.setNumber(ConfigManager::GAME_PORT, atoi(tmp[1].c_str())); else if(tmp[0] == "--admin-port") g_config.setNumber(ConfigManager::ADMIN_PORT, atoi(tmp[1].c_str())); else if(tmp[0] == "--manager-port") g_config.setNumber(ConfigManager::MANAGER_PORT, atoi(tmp[1].c_str())); else if(tmp[0] == "--status-port") g_config.setNumber(ConfigManager::STATUS_PORT, atoi(tmp[1].c_str())); #ifndef WINDOWS else if(tmp[0] == "--runfile") g_config.setString(ConfigManager::RUNFILE, tmp[1]); #endif else if(tmp[0] == "--log") g_config.setString(ConfigManager::OUTPUT_LOG, tmp[1]); else if(tmp[0] == "--closed") g_config.setBool(ConfigManager::START_CLOSED, true); else if(tmp[0] == "--no-script") g_config.setBool(ConfigManager::SCRIPT_SYSTEM, false); } return true; }
bool argumentsHandler(StringVec args) { StringVec tmp; for(StringVec::iterator it = args.begin(); it != args.end(); ++it) { if((*it) == "--help") { std::clog << "Usage:\n" "\n" "\t--config=$1\t\tAlternate configuration file path.\n" "\t--data-directory=$1\tAlternate data directory path.\n" "\t--ip=$1\t\t\tIP address of the server.\n" "\t\t\t\tShould be equal to the global IP.\n" "\t--login-port=$1\tPort for login server to listen on.\n" "\t--game-port=$1\tPort for game server to listen on.\n" "\t--admin-port=$1\tPort for admin server to listen on.\n" "\t--manager-port=$1\tPort for manager server to listen on.\n" "\t--status-port=$1\tPort for status server to listen on.\n"; #ifndef WINDOWS std::clog << "\t--runfile=$1\t\tSpecifies run file. Will contain the pid\n" "\t\t\t\tof the server process as long as run status.\n"; #endif std::clog << "\t--log=$1\t\tWhole standard output will be logged to\n" "\t\t\t\tthis file.\n" "\t--closed\t\t\tStarts the server as closed.\n" "\t--no-script\t\t\tStarts the server without script system.\n"; return false; } if((*it) == "--version" || (*it) == "-v") { std::clog << "The " << SOFTWARE_NAME << " Version: (" << SOFTWARE_VERSION << "." << MINOR_VERSION << PATCH_VERSION << " - " << REVISION_VERSION << ") - Codename: (" << SOFTWARE_CODENAME << ")\n" "Compilied with " << BOOST_COMPILER << " for arch " #if defined(__amd64__) || defined(_M_X64) "64 Bits" #elif defined(__i386__) || defined(_M_IX86) || defined(_X86_) "32 Bits" #else "unk" #endif " at " << __DATE__ << " " << __TIME__ << "\n" "\n" "A server developed by: "SOFTWARE_DEVELOPERS".\n" "Visit our forums for updates, support, and resources:\n" ""FORUMS"\n"; return false; } tmp = explodeString((*it), "="); if(tmp[0] == "--config") g_config.setString(ConfigManager::CONFIG_FILE, tmp[1]); else if(tmp[0] == "--data-directory") g_config.setString(ConfigManager::DATA_DIRECTORY, tmp[1]); else if(tmp[0] == "--logs-directory") g_config.setString(ConfigManager::LOGS_DIRECTORY, tmp[1]); else if(tmp[0] == "--ip") g_config.setString(ConfigManager::IP, tmp[1]); else if(tmp[0] == "--login-port") g_config.setNumber(ConfigManager::LOGIN_PORT, atoi(tmp[1].c_str())); else if(tmp[0] == "--game-port") g_config.setNumber(ConfigManager::GAME_PORT, atoi(tmp[1].c_str())); else if(tmp[0] == "--status-port") g_config.setNumber(ConfigManager::STATUS_PORT, atoi(tmp[1].c_str())); #ifndef WINDOWS else if(tmp[0] == "--runfile" || tmp[0] == "--run-file" || tmp[0] == "--pidfile" || tmp[0] == "--pid-file") g_config.setString(ConfigManager::RUNFILE, tmp[1]); #endif else if(tmp[0] == "--log") g_config.setString(ConfigManager::OUTPUT_LOG, tmp[1]); #ifndef WINDOWS else if(tmp[0] == "--daemon" || tmp[0] == "-d") g_config.setBool(ConfigManager::DAEMONIZE, true); #endif else if(tmp[0] == "--closed") g_config.setBool(ConfigManager::START_CLOSED, true); else if(tmp[0] == "--no-script" || tmp[0] == "--noscript") g_config.setBool(ConfigManager::SCRIPT_SYSTEM, false); } return true; }
bool Spawns::parseSpawnNode(xmlNodePtr p, bool checkDuplicate) { if(xmlStrcmp(p->name, (const xmlChar*)"spawn")) return false; int32_t intValue; std::string strValue; Position centerPos; if(!readXMLString(p, "centerpos", strValue)) { if(!readXMLInteger(p, "centerx", intValue)) return false; centerPos.x = intValue; if(!readXMLInteger(p, "centery", intValue)) return false; centerPos.y = intValue; if(!readXMLInteger(p, "centerz", intValue)) return false; centerPos.z = intValue; } else { IntegerVec posVec = vectorAtoi(explodeString(",", strValue)); if(posVec.size() < 3) return false; centerPos = Position(posVec[0], posVec[1], posVec[2]); } if(!readXMLInteger(p, "radius", intValue)) return false; int32_t radius = intValue; Spawn* spawn = new Spawn(centerPos, radius); if(checkDuplicate) { for(SpawnList::iterator it = spawnList.begin(); it != spawnList.end(); ++it) { if((*it)->getPosition() == centerPos) delete *it; } } spawnList.push_back(spawn); xmlNodePtr tmpNode = p->children; while(tmpNode) { if(!xmlStrcmp(tmpNode->name, (const xmlChar*)"monster")) { std::string name; if(!readXMLString(tmpNode, "name", strValue)) { tmpNode = tmpNode->next; continue; } name = strValue; int32_t interval = MINSPAWN_INTERVAL / 1000; if(readXMLInteger(tmpNode, "spawntime", intValue) || readXMLInteger(tmpNode, "interval", intValue)) { if(intValue <= interval) { std::cout << "[Warning - Spawns::loadFromXml] " << name << " " << centerPos << " spawntime cannot"; std::cout << " be less than " << interval << " seconds." << std::endl; tmpNode = tmpNode->next; continue; } interval = intValue; } interval *= 1000; Position placePos = centerPos; if(readXMLInteger(tmpNode, "x", intValue)) placePos.x += intValue; if(readXMLInteger(tmpNode, "y", intValue)) placePos.y += intValue; if(readXMLInteger(tmpNode, "z", intValue)) placePos.z /*+*/= intValue; Direction direction = NORTH; if(readXMLInteger(tmpNode, "direction", intValue) && direction >= EAST && direction <= WEST) direction = (Direction)intValue; spawn->addMonster(name, placePos, direction, interval); } else if(!xmlStrcmp(tmpNode->name, (const xmlChar*)"npc")) { std::string name; if(!readXMLString(tmpNode, "name", strValue)) { tmpNode = tmpNode->next; continue; } name = strValue; Position placePos = centerPos; if(readXMLInteger(tmpNode, "x", intValue)) placePos.x += intValue; if(readXMLInteger(tmpNode, "y", intValue)) placePos.y += intValue; if(readXMLInteger(tmpNode, "z", intValue)) placePos.z /*+*/= intValue; Direction direction = NORTH; if(readXMLInteger(tmpNode, "direction", intValue) && direction >= EAST && direction <= WEST) direction = (Direction)intValue; Npc* npc = Npc::createNpc(name); if(!npc) { tmpNode = tmpNode->next; continue; } npc->setMasterPos(placePos, radius); npc->setDirection(direction); npcList.push_back(npc); } tmpNode = tmpNode->next; } return true; }
bool MoveEvents::registerEvent(Event* event, const pugi::xml_node& node) { MoveEvent* moveEvent = static_cast<MoveEvent*>(event); //event is guaranteed to be a MoveEvent const MoveEvent_t eventType = moveEvent->getEventType(); if (eventType == MOVE_EVENT_ADD_ITEM || eventType == MOVE_EVENT_REMOVE_ITEM) { pugi::xml_attribute tileItemAttribute = node.attribute("tileitem"); if (tileItemAttribute && pugi::cast<uint16_t>(tileItemAttribute.value()) == 1) { switch (eventType) { case MOVE_EVENT_ADD_ITEM: moveEvent->setEventType(MOVE_EVENT_ADD_ITEM_ITEMTILE); break; case MOVE_EVENT_REMOVE_ITEM: moveEvent->setEventType(MOVE_EVENT_REMOVE_ITEM_ITEMTILE); break; default: break; } } } pugi::xml_attribute attr; if ((attr = node.attribute("itemid"))) { int32_t id = pugi::cast<int32_t>(attr.value()); addEvent(moveEvent, id, m_itemIdMap); if (moveEvent->getEventType() == MOVE_EVENT_EQUIP) { ItemType& it = Item::items.getItemType(id); it.wieldInfo = moveEvent->getWieldInfo(); it.minReqLevel = moveEvent->getReqLevel(); it.minReqMagicLevel = moveEvent->getReqMagLv(); it.vocationString = moveEvent->getVocationString(); } } else if ((attr = node.attribute("fromid"))) { uint32_t id = pugi::cast<uint32_t>(attr.value()); uint32_t endId = pugi::cast<uint32_t>(node.attribute("toid").value()); addEvent(moveEvent, id, m_itemIdMap); if (moveEvent->getEventType() == MOVE_EVENT_EQUIP) { ItemType& it = Item::items.getItemType(id); it.wieldInfo = moveEvent->getWieldInfo(); it.minReqLevel = moveEvent->getReqLevel(); it.minReqMagicLevel = moveEvent->getReqMagLv(); it.vocationString = moveEvent->getVocationString(); while (++id <= endId) { addEvent(moveEvent, id, m_itemIdMap); ItemType& tit = Item::items.getItemType(id); tit.wieldInfo = moveEvent->getWieldInfo(); tit.minReqLevel = moveEvent->getReqLevel(); tit.minReqMagicLevel = moveEvent->getReqMagLv(); tit.vocationString = moveEvent->getVocationString(); } } else { while (++id <= endId) { addEvent(moveEvent, id, m_itemIdMap); } } } else if ((attr = node.attribute("uniqueid"))) { addEvent(moveEvent, pugi::cast<int32_t>(attr.value()), m_uniqueIdMap); } else if ((attr = node.attribute("fromuid"))) { uint32_t id = pugi::cast<uint32_t>(attr.value()); uint32_t endId = pugi::cast<uint32_t>(node.attribute("touid").value()); addEvent(moveEvent, id, m_uniqueIdMap); while (++id <= endId) { addEvent(moveEvent, id, m_uniqueIdMap); } } else if ((attr = node.attribute("actionid"))) { addEvent(moveEvent, pugi::cast<int32_t>(attr.value()), m_actionIdMap); } else if ((attr = node.attribute("fromaid"))) { uint32_t id = pugi::cast<uint32_t>(attr.value()); uint32_t endId = pugi::cast<uint32_t>(node.attribute("toaid").value()); addEvent(moveEvent, id, m_actionIdMap); while (++id <= endId) { addEvent(moveEvent, id, m_actionIdMap); } } else if ((attr = node.attribute("pos"))) { std::vector<int32_t> posList = vectorAtoi(explodeString(attr.as_string(), ";")); if (posList.size() < 3) { return false; } Position pos(posList[0], posList[1], posList[2]); addEvent(moveEvent, pos, m_positionMap); } else { return false; } return true; }
bool MoveEvents::registerEvent(Event* event, xmlNodePtr p) { MoveEvent* moveEvent = dynamic_cast<MoveEvent*>(event); if(!moveEvent) return false; bool success = true; int id; std::string str; MoveEvent_t eventType = moveEvent->getEventType(); if(eventType == MOVE_EVENT_ADD_ITEM || eventType == MOVE_EVENT_REMOVE_ITEM){ if(readXMLInteger(p,"tileitem",id) && id == 1){ switch(eventType){ case MOVE_EVENT_ADD_ITEM: moveEvent->setEventType(MOVE_EVENT_ADD_ITEM_ITEMTILE); break; case MOVE_EVENT_REMOVE_ITEM: moveEvent->setEventType(MOVE_EVENT_REMOVE_ITEM_ITEMTILE); break; default: break; } } } if(readXMLInteger(p,"itemid",id)){ if(moveEvent->getEventType() == MOVE_EVENT_EQUIP){ ItemType& it = Item::items.getItemType(id); it.wieldInfo = moveEvent->getWieldInfo(); it.minReqLevel = moveEvent->getReqLevel(); it.minReqMagicLevel = moveEvent->getReqMagLv(); it.vocationString = moveEvent->getVocationString(); } addEvent(moveEvent, id, m_itemIdMap); } else if(readXMLInteger(p,"uniqueid",id)){ addEvent(moveEvent, id, m_uniqueIdMap); } else if(readXMLInteger(p,"actionid",id)){ addEvent(moveEvent, id, m_actionIdMap); } else if(readXMLString(p,"pos",str)){ std::vector<std::string> posList = explodeString(str, ";"); if(posList.size() < 3){ success = false; } else{ Position pos; pos.x = atoi(posList[0].c_str()); pos.y = atoi(posList[1].c_str()); pos.z = atoi(posList[2].c_str()); addEvent(moveEvent, pos, m_positionMap); } } else{ success = false; } return success; }
bool AreaSpawnEvent::configureRaidEvent(xmlNodePtr eventNode) { if(!RaidEvent::configureRaidEvent(eventNode)) return false; int32_t intValue; std::string strValue; if(readXMLInteger(eventNode, "radius", intValue)) { int32_t radius = intValue; Position centerPos; if(readXMLString(eventNode, "centerPosition", strValue) || readXMLString(eventNode, "centerpos", strValue)) { IntegerVec posList = vectorAtoi(explodeString(strValue, ";")); if(posList.size() < 3) { std::clog << "[Error - AreaSpawnEvent::configureRaidEvent] Malformed centerPosition tag for areaspawn event." << std::endl; return false; } centerPos = Position(posList[0], posList[1], posList[2]); } else { if(!readXMLInteger(eventNode, "centerx", intValue)) { std::clog << "[Error - AreaSpawnEvent::configureRaidEvent] centerx tag missing for areaspawn event." << std::endl; return false; } centerPos.x = intValue; if(!readXMLInteger(eventNode, "centery", intValue)) { std::clog << "[Error - AreaSpawnEvent::configureRaidEvent] centery tag missing for areaspawn event." << std::endl; return false; } centerPos.y = intValue; if(!readXMLInteger(eventNode, "centerz", intValue)) { std::clog << "[Error - AreaSpawnEvent::configureRaidEvent] centerz tag missing for areaspawn event." << std::endl; return false; } centerPos.z = intValue; } m_fromPos.x = centerPos.x - radius; m_fromPos.y = centerPos.y - radius; m_fromPos.z = centerPos.z; m_toPos.x = centerPos.x + radius; m_toPos.y = centerPos.y + radius; m_toPos.z = centerPos.z; } else { if(readXMLString(eventNode, "fromPosition", strValue) || readXMLString(eventNode, "frompos", strValue)) { IntegerVec posList = vectorAtoi(explodeString(strValue, ";")); if(posList.size() < 3) { std::clog << "[Error - AreaSpawnEvent::configureRaidEvent] Malformed fromPosition tag for areaspawn event." << std::endl; return false; } m_fromPos = Position(posList[0], posList[1], posList[2]); } else { if(!readXMLInteger(eventNode, "fromx", intValue)) { std::clog << "[Error - AreaSpawnEvent::configureRaidEvent] fromx tag missing for areaspawn event." << std::endl; return false; } m_fromPos.x = intValue; if(!readXMLInteger(eventNode, "fromy", intValue)) { std::clog << "[Error - AreaSpawnEvent::configureRaidEvent] fromy tag missing for areaspawn event." << std::endl; return false; } m_fromPos.y = intValue; if(!readXMLInteger(eventNode, "fromz", intValue)) { std::clog << "[Error - AreaSpawnEvent::configureRaidEvent] fromz tag missing for areaspawn event." << std::endl; return false; } m_fromPos.z = intValue; } if(readXMLString(eventNode, "toPosition", strValue) || readXMLString(eventNode, "topos", strValue)) { IntegerVec posList = vectorAtoi(explodeString(strValue, ";")); if(posList.size() < 3) { std::clog << "[Error - AreaSpawnEvent::configureRaidEvent] Malformed toPosition tag for areaspawn event." << std::endl; return false; } m_toPos = Position(posList[0], posList[1], posList[2]); } else { if(!readXMLInteger(eventNode, "tox", intValue)) { std::clog << "[Error - AreaSpawnEvent::configureRaidEvent] tox tag missing for areaspawn event." << std::endl; return false; } m_toPos.x = intValue; if(!readXMLInteger(eventNode, "toy", intValue)) { std::clog << "[Error - AreaSpawnEvent::configureRaidEvent] toy tag missing for areaspawn event." << std::endl; return false; } m_toPos.y = intValue; if(!readXMLInteger(eventNode, "toz", intValue)) { std::clog << "[Error - AreaSpawnEvent::configureRaidEvent] toz tag missing for areaspawn event." << std::endl; return false; } m_toPos.z = intValue; } } xmlNodePtr monsterNode = eventNode->children; while(monsterNode) { if(!xmlStrcmp(monsterNode->name, (const xmlChar*)"monster")) { if(!readXMLString(monsterNode, "name", strValue)) { std::clog << "[Error - AreaSpawnEvent::configureRaidEvent] name tag missing for monster node." << std::endl; return false; } std::string name = strValue; int32_t min = 0, max = 0; if(readXMLInteger(monsterNode, "min", intValue) || readXMLInteger(monsterNode, "minamount", intValue)) min = intValue; if(readXMLInteger(monsterNode, "max", intValue) || readXMLInteger(monsterNode, "maxamount", intValue)) max = intValue; if(!min && !max) { if(!readXMLInteger(monsterNode, "amount", intValue)) { std::clog << "[Error - AreaSpawnEvent::configureRaidEvent] amount tag missing for monster node." << std::endl; return false; } min = max = intValue; } addMonster(name, min, max); } monsterNode = monsterNode->next; } return true; }
void otserv( #if !defined(WINDOWS) || defined(_CONSOLE) StringVec, #endif ServiceManager* services) { std::srand((uint32_t)OTSYS_TIME()); #if defined(WINDOWS) #if defined(_CONSOLE) SetConsoleTitle(SOFTWARE_NAME); #else GUI::getInstance()->m_connections = false; #endif #endif g_game.setGameState(GAMESTATE_STARTUP); #if !defined(WINDOWS) && !defined(__ROOT_PERMISSION__) if(!getuid() || !geteuid()) { std::clog << "> WARNING: " "The " << SOFTWARE_NAME << " has been executed as super user! It is " << "recommended to run as a normal user." << std::endl << "Continue? (y/N)" << std::endl; char buffer = OTSYS_getch(); if(buffer != 121 && buffer != 89) startupErrorMessage("Aborted."); } #endif std::clog << "The " << SOFTWARE_NAME << " Version: (" << SOFTWARE_VERSION << "." << MINOR_VERSION << PATCH_VERSION << " - " << REVISION_VERSION << ") - Codename: (" << SOFTWARE_CODENAME << ")" << std::endl << "Compilied with " << BOOST_COMPILER << " for arch " #if defined(__amd64__) || defined(_M_X64) "64 Bits" #elif defined(__i386__) || defined(_M_IX86) || defined(_X86_) "32 Bits" #else "unk" #endif " at " << __DATE__ << " " << __TIME__ << std::endl << std::endl << "A server developed by: "SOFTWARE_DEVELOPERS"." << std::endl << "Visit our forums for updates, support, and resources:" << std::endl << ""FORUMS"" << std::endl; std::stringstream ss; #ifdef __DEBUG__ ss << " GLOBAL"; #endif #ifdef __DEBUG_MOVESYS__ ss << " MOVESYS"; #endif #ifdef __DEBUG_CHAT__ ss << " CHAT"; #endif #ifdef __DEBUG_HOUSES__ ss << " HOUSES"; #endif #ifdef __DEBUG_LUASCRIPTS__ ss << " LUA-SCRIPTS"; #endif #ifdef __DEBUG_MAILBOX__ ss << " MAILBOX"; #endif #ifdef __DEBUG_NET__ ss << " NET"; #endif #ifdef __DEBUG_NET_DETAIL__ ss << " NET-DETAIL"; #endif #ifdef __DEBUG_RAID__ ss << " RAIDS"; #endif #ifdef __DEBUG_SCHEDULER__ ss << " SCHEDULER"; #endif #ifdef __DEBUG_SPAWN__ ss << " SPAWNS"; #endif #ifdef __SQL_QUERY_DEBUG__ ss << " SQL-QUERIES"; #endif std::string debug = ss.str(); if(!debug.empty()) { std::clog << ">> Debugging:"; #if defined(WINDOWS) && !defined(_CONSOLE) SendMessage(GUI::getInstance()->m_statusBar, WM_SETTEXT, 0, (LPARAM)">> Debugging:"); #endif std::clog << debug << "." << std::endl; } std::clog << std::endl; std::clog << ">> Loading config (" << g_config.getString(ConfigManager::CONFIG_FILE) << ")" << std::endl; #if defined(WINDOWS) && !defined(_CONSOLE) SendMessage(GUI::getInstance()->m_statusBar, WM_SETTEXT, 0, (LPARAM)">> Loading config"); #endif if(!g_config.load()) startupErrorMessage("Unable to load " + g_config.getString(ConfigManager::CONFIG_FILE) + "!"); #ifndef WINDOWS if(g_config.getBool(ConfigManager::DAEMONIZE)) { std::clog << "> Daemonization... "; if(fork()) { std::clog << "succeed, bye!" << std::endl; exit(0); } else std::clog << "failed, continuing." << std::endl; } #endif // silently append trailing slash std::string path = g_config.getString(ConfigManager::DATA_DIRECTORY); g_config.setString(ConfigManager::DATA_DIRECTORY, path.erase(path.find_last_not_of("/") + 1) + "/"); path = g_config.getString(ConfigManager::LOGS_DIRECTORY); g_config.setString(ConfigManager::LOGS_DIRECTORY, path.erase(path.find_last_not_of("/") + 1) + "/"); std::clog << ">> Opening logs" << std::endl; #if defined(WINDOWS) && !defined(_CONSOLE) SendMessage(GUI::getInstance()->m_statusBar, WM_SETTEXT, 0, (LPARAM)">> Opening logs"); #endif Logger::getInstance()->open(); IntegerVec cores = vectorAtoi(explodeString(g_config.getString(ConfigManager::CORES_USED), ",")); if(cores[0] != -1) { #ifdef WINDOWS int32_t mask = 0; for(IntegerVec::iterator it = cores.begin(); it != cores.end(); ++it) mask += 1 << (*it); SetProcessAffinityMask(GetCurrentProcess(), mask); } std::stringstream mutexName; mutexName << "otxserver_" << g_config.getNumber(ConfigManager::WORLD_ID); CreateMutex(NULL, FALSE, mutexName.str().c_str()); if(GetLastError() == ERROR_ALREADY_EXISTS) startupErrorMessage("Another instance of The OTX Server is already running with the same worldId.\nIf you want to run multiple servers, please change the worldId in configuration file."); std::string defaultPriority = asLowerCaseString(g_config.getString(ConfigManager::DEFAULT_PRIORITY)); if(defaultPriority == "realtime" || defaultPriority == "real") SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS); else if(defaultPriority == "high" || defaultPriority == "regular") SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); else if(defaultPriority == "higher" || defaultPriority == "above" || defaultPriority == "normal") SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS); #else #ifndef __APPLE__ cpu_set_t mask; CPU_ZERO(&mask); for(IntegerVec::iterator it = cores.begin(); it != cores.end(); ++it) CPU_SET((*it), &mask); sched_setaffinity(getpid(), (int32_t)sizeof(mask), &mask); }
void otserv(StringVec, ServiceManager* services) { srand((uint32_t)OTSYS_TIME()); #if defined(WINDOWS) SetConsoleTitle(SOFTWARE_NAME); #endif g_game.setGameState(GAMESTATE_STARTUP); #if !defined(WINDOWS) && !defined(__ROOT_PERMISSION__) if(!getuid() || !geteuid()) { std::clog << "> WARNING: " << SOFTWARE_NAME << " has been executed as super user! It is " << "recommended to run as a normal user." << std::endl << "Continue? (y/N)" << std::endl; char buffer = getch(); if(buffer != 121 && buffer != 89) startupErrorMessage("Aborted."); } #endif std::clog << SOFTWARE_NAME << " " << SOFTWARE_VERSION << std::endl << std::endl; std::stringstream ss; #ifdef __DEBUG__ ss << " GLOBAL"; #endif #ifdef __DEBUG_MOVESYS__ ss << " MOVESYS"; #endif #ifdef __DEBUG_CHAT__ ss << " CHAT"; #endif #ifdef __DEBUG_EXCEPTION_REPORT__ ss << " EXCEPTION-REPORT"; #endif #ifdef __DEBUG_HOUSES__ ss << " HOUSES"; #endif #ifdef __DEBUG_LUASCRIPTS__ ss << " LUA-SCRIPTS"; #endif #ifdef __DEBUG_MAILBOX__ ss << " MAILBOX"; #endif #ifdef __DEBUG_NET__ ss << " NET"; #endif #ifdef __DEBUG_NET_DETAIL__ ss << " NET-DETAIL"; #endif #ifdef __DEBUG_RAID__ ss << " RAIDS"; #endif #ifdef __DEBUG_SCHEDULER__ ss << " SCHEDULER"; #endif #ifdef __DEBUG_SPAWN__ ss << " SPAWNS"; #endif #ifdef __SQL_QUERY_DEBUG__ ss << " SQL-QUERIES"; #endif std::string debug = ss.str(); if(!debug.empty()) std::clog << ">> Debugging:" << debug << "." << std::endl; std::clog << ">> Loading config (" << g_config.getString(ConfigManager::CONFIG_FILE) << ")" << std::endl; if(!g_config.load()) startupErrorMessage("Unable to load " + g_config.getString(ConfigManager::CONFIG_FILE) + "!"); // silently append trailing slash std::string path = g_config.getString(ConfigManager::DATA_DIRECTORY); g_config.setString(ConfigManager::DATA_DIRECTORY, path.erase(path.find_last_not_of("/") + 1) + "/"); path = g_config.getString(ConfigManager::LOGS_DIRECTORY); g_config.setString(ConfigManager::LOGS_DIRECTORY, path.erase(path.find_last_not_of("/") + 1) + "/"); std::clog << ">> Opening logs" << std::endl; Logger::getInstance()->open(); IntegerVec cores = vectorAtoi(explodeString(g_config.getString(ConfigManager::CORES_USED), ",")); if(cores[0] != -1) { #ifdef WINDOWS int32_t mask = 0; for(IntegerVec::iterator it = cores.begin(); it != cores.end(); ++it) mask += 1 << (*it); SetProcessAffinityMask(GetCurrentProcess(), mask); } std::stringstream mutexName; mutexName << "forgottenserver_" << g_config.getNumber(ConfigManager::WORLD_ID); CreateMutex(NULL, FALSE, mutexName.str().c_str()); if(GetLastError() == ERROR_ALREADY_EXISTS) startupErrorMessage("Another instance of The Forgotten Server is already running with the same worldId.\nIf you want to run multiple servers, please change the worldId in configuration file."); std::string defaultPriority = asLowerCaseString(g_config.getString(ConfigManager::DEFAULT_PRIORITY)); if(defaultPriority == "realtime") SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS); else if(defaultPriority == "high") SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); else if(defaultPriority == "higher") SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS); #else #ifndef MACOS cpu_set_t mask; CPU_ZERO(&mask); for(IntegerVec::iterator it = cores.begin(); it != cores.end(); ++it) CPU_SET((*it), &mask); sched_setaffinity(getpid(), (int32_t)sizeof(mask), &mask); }