Event* Actions::getEvent(const std::string& nodeName) { if (asLowerCaseString(nodeName) == "action") { return new Action(&m_scriptInterface); } else { return nullptr; } }
uint32_t Monsters::getIdByName(const std::string& name) { auto it = monsterNames.find(asLowerCaseString(name)); if (it == monsterNames.end()) { return 0; } return it->second; }
Event* MoveEvents::getEvent(const std::string& nodeName) { if (asLowerCaseString(nodeName) == "movevent") { return new MoveEvent(&m_scriptInterface); } else { return nullptr; } }
Event* TalkActions::getEvent(const std::string& nodeName) { if (asLowerCaseString(nodeName) == "talkaction") { return new TalkAction(&m_scriptInterface); } return NULL; }
Event* MoveEvents::getEvent(const std::string& nodeName) { std::string tmpNodeName = asLowerCaseString(nodeName); if(tmpNodeName == "movevent" || tmpNodeName == "moveevent" || tmpNodeName == "movement") return new MoveEvent(&m_interface); return NULL; }
Event* CreatureEvents::getEvent(const std::string& nodeName) { if (asLowerCaseString(nodeName) == "event") { return new CreatureEvent(&m_scriptInterface); } return nullptr; }
Event* GlobalEvents::getEvent(const std::string& nodeName) { if (asLowerCaseString(nodeName) == "globalevent") { return new GlobalEvent(&m_scriptInterface); } return NULL; }
bool Groups::parseGroupNode(xmlNodePtr p) { if(xmlStrcmp(p->name, (const xmlChar*)"group")) return false; int32_t intValue; if(!readXMLInteger(p, "id", intValue)) { std::cout << "[Warning - Groups::parseGroupNode] Missing group id." << std::endl; return false; } std::string strValue; int64_t int64Value; Group* group = new Group(intValue); if(readXMLString(p, "name", strValue)) { group->setFullName(strValue); group->setName(asLowerCaseString(strValue)); } if(readXMLInteger64(p, "flags", int64Value)) group->setFlags(int64Value); if(readXMLInteger64(p, "customFlags", int64Value)) group->setCustomFlags(int64Value); if(readXMLInteger(p, "access", intValue)) group->setAccess(intValue); if(readXMLInteger(p, "ghostAccess", intValue)) group->setGhostAccess(intValue); else group->setGhostAccess(group->getAccess()); if(readXMLInteger(p, "violationReasons", intValue)) group->setViolationReasons(intValue); if(readXMLInteger(p, "nameViolationFlags", intValue)) group->setNameViolationFlags(intValue); if(readXMLInteger(p, "statementViolationFlags", intValue)) group->setStatementViolationFlags(intValue); if(readXMLInteger(p, "depotLimit", intValue)) group->setDepotLimit(intValue); if(readXMLInteger(p, "maxVips", intValue)) group->setMaxVips(intValue); if(readXMLInteger(p, "outfit", intValue)) group->setOutfit(intValue); groupsMap[group->getId()] = group; return true; }
MonsterType* Monsters::getMonsterType(const std::string& name) { auto it = monsters.find(asLowerCaseString(name)); if (it == monsters.end()) { return nullptr; } return &it->second; }
uint16_t Items::getItemIdByName(const std::string& name) { auto result = nameToItems.find(asLowerCaseString(name)); if (result == nameToItems.end()) return 0; return result->second; }
uint32_t Monsters::getIdByName(const std::string& name) { std::string tmp = name; MonsterNameMap::iterator it = monsterNames.find(asLowerCaseString(tmp)); if(it != monsterNames.end()) return it->second; return 0; }
void Commands::reloadInfo(Player* player, const std::string& cmd, const std::string& param) { std::string tmpParam = asLowerCaseString(param); if (tmpParam == "action" || tmpParam == "actions") { g_actions->reload(); player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Reloaded actions."); } else if (tmpParam == "config" || tmpParam == "configuration") { g_config.reload(); player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Reloaded config."); } else if (tmpParam == "command" || tmpParam == "commands") { reload(); player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Reloaded commands."); } else if (tmpParam == "creaturescript" || tmpParam == "creaturescripts") { g_creatureEvents->reload(); player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Reloaded creature scripts."); } else if (tmpParam == "monster" || tmpParam == "monsters") { g_monsters.reload(); player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Reloaded monsters."); } else if (tmpParam == "move" || tmpParam == "movement" || tmpParam == "movements" || tmpParam == "moveevents" || tmpParam == "moveevent") { g_moveEvents->reload(); player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Reloaded movements."); } else if (tmpParam == "npc" || tmpParam == "npcs") { g_npcs.reload(); player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Reloaded npcs."); } else if (tmpParam == "raid" || tmpParam == "raids") { Raids::getInstance()->reload(); Raids::getInstance()->startup(); player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Reloaded raids."); } else if (tmpParam == "spell" || tmpParam == "spells") { g_spells->reload(); g_monsters.reload(); player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Reloaded spells."); } else if (tmpParam == "talk" || tmpParam == "talkaction" || tmpParam == "talkactions") { g_talkActions->reload(); player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Reloaded talk actions."); } else if (tmpParam == "items") { Item::items.reload(); player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Reloaded items."); } else if (tmpParam == "weapon" || tmpParam == "weapons") { g_weapons->reload(); g_weapons->loadDefaults(); player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Reloaded weapons."); } else if (tmpParam == "quest" || tmpParam == "quests") { Quests::getInstance()->reload(); player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Reloaded quests."); } else if (tmpParam == "mount" || tmpParam == "mounts") { Mounts::getInstance()->reload(); player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Reloaded mounts."); } else if (tmpParam == "globalevents" || tmpParam == "globalevent") { g_globalEvents->reload(); player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Reloaded globalevents."); } else { player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Reload type not found."); } }
bool IOMapSerialize::saveMap(Map* map) { std::string config = asLowerCaseString(g_config.getString(ConfigManager::HOUSE_STORAGE)); if(config == "binary-tilebased") return saveMapBinaryTileBased(map); else if(config == "binary") return saveMapBinary(map); return saveMapRelational(map); }
Houses::Houses() { std::string strRentPeriod = g_config.getString(ConfigManager::HOUSE_RENT_PERIOD); rentPeriod = RENTPERIOD_MONTHLY; if(asLowerCaseString(strRentPeriod) == "yearly"){ rentPeriod = RENTPERIOD_YEARLY; } else if(asLowerCaseString(strRentPeriod) == "weekly"){ rentPeriod = RENTPERIOD_WEEKLY; } else if(asLowerCaseString(strRentPeriod) == "daily"){ rentPeriod = RENTPERIOD_DAILY; } else if(asLowerCaseString(strRentPeriod) == "never"){ rentPeriod = RENTPERIOD_NEVER; } }
bool AdminProtocolConfig::loadXMLConfig() { pugi::xml_document doc; pugi::xml_parse_result result = doc.load_file("data/XML/admin.xml"); if (!result) { std::cout << "[Error - AdminProtocolConfig::loadXMLConfig] Failed to load data/XML/admin.xml: " << result.description() << std::endl; return false; } pugi::xml_node otadminNode = doc.child("otadmin"); if (!otadminNode) { return false; } m_enabled = otadminNode.attribute("enabled").as_bool(); for (pugi::xml_node node = otadminNode.first_child(); node; node = node.next_sibling()) { if (strcasecmp(node.name(), "security") == 0) { m_onlyLocalHost = node.attribute("onlylocalhost").as_bool(); m_maxConnections = pugi::cast<int32_t>(node.attribute("maxconnections").value()); m_requireLogin = node.attribute("loginrequired").as_bool(); pugi::xml_attribute loginPasswordAttribute = node.attribute("loginpassword"); if (loginPasswordAttribute) { m_password = loginPasswordAttribute.as_string(); } else if (m_requireLogin) { std::cout << "[AdminProtocolConfig::loadXMLConfig - Security warning] Login required, but using default password." << std::endl; } } else if (strcasecmp(node.name(), "encryption") == 0) { m_requireEncryption = node.attribute("required").as_bool(); pugi::xml_node encryptionNode = node.child("key"); if (encryptionNode) { std::string encryptionType = encryptionNode.attribute("type").as_string(); if (asLowerCaseString(encryptionType) != "rsa1024xtea") { std::cout << "[AdminProtocolConfig::loadXMLConfig - Warning] " << encryptionType << " is not a valid key type." << std::endl; continue; } pugi::xml_attribute encryptionFile = encryptionNode.attribute("file"); if (!encryptionFile) { std::cout << "[AdminProtocolConfig::loadXMLConfig - Warning] Missing file for RSA1024XTEA key." << std::endl; continue; } m_key_RSA1024XTEA = new RSA(); if (!m_key_RSA1024XTEA->setKey("data/XML/" + std::string(encryptionFile.as_string()))) { delete m_key_RSA1024XTEA; m_key_RSA1024XTEA = nullptr; std::cout << "[AdminProtocolConfig::loadXMLConfig - Warning] Can not load key from data/XML/" << encryptionFile.as_string() << std::endl; } } } } return true; }
void Spectators::kick(StringVec list) { for(StringVec::const_iterator it = list.begin(); it != list.end(); ++it) { for(SpectatorList::iterator sit = spectators.begin(); sit != spectators.end(); ++sit) { if(asLowerCaseString(sit->second.first) == *it) sit->first->disconnect(); } } }
bool Events::load() { pugi::xml_document doc; pugi::xml_parse_result result = doc.load_file("data/events/events.xml"); if (!result) { std::cout << "[Error - Events::load] Failed to load data/events/events.xml: " << result.description() << std::endl; return false; } clear(); std::set<std::string> classes; for (pugi::xml_node eventNode = doc.child("events").first_child(); eventNode; eventNode = eventNode.next_sibling()) { if (eventNode.attribute("enabled").as_bool()) { const std::string& className = eventNode.attribute("class").as_string(); if (classes.count(className) == 0) { const std::string& lowercase = asLowerCaseString(className); if (scriptInterface.loadFile("data/events/scripts/" + lowercase + ".lua") != 0) { std::cout << "[Warning - Events::load] Can not load script: " << lowercase << ".lua" << std::endl; continue; } classes.insert(className); } const std::string& methodName = eventNode.attribute("method").as_string(); const int32_t event = scriptInterface.getMetaEvent(className, methodName); if (className == "Party") { if (methodName == "onJoin") { partyOnJoin = event; } else if (methodName == "onLeave") { partyOnLeave = event; } else if (methodName == "onDisband") { partyOnDisband = event; } else { std::cout << "[Warning - Events::load] Unknown party method: " << methodName << std::endl; } } else if (className == "Player") { if (methodName == "onLook") { playerOnLook = event; } else if (methodName == "onLookInTrade") { playerOnLookInTrade = event; } else if (methodName == "onLookInShop") { playerOnLookInShop = event; } else { std::cout << "[Warning - Events::load] Unknown player method: " << methodName << std::endl; } } else { std::cout << "[Warning - Events::load] Unknown class: " << className << std::endl; } } } return true; }
bool Weapon::loadFunction(const std::string& functionName) { std::string tmpFunctionName = asLowerCaseString(functionName); if (tmpFunctionName == "internalloadweapon" || tmpFunctionName == "default") { if (configureWeapon(Item::items[getID()])) { return true; } } else if (tmpFunctionName == "script") { m_scripted = true; } return false; }
bool CreatureEvent::configureEvent(const pugi::xml_node& node) { // Name that will be used in monster xml files and // lua function to register events to reference this event pugi::xml_attribute nameAttribute = node.attribute("name"); if (!nameAttribute) { std::cout << "[Error - CreatureEvent::configureEvent] Missing name for creature event" << std::endl; return false; } m_eventName = nameAttribute.as_string(); pugi::xml_attribute typeAttribute = node.attribute("type"); if (!typeAttribute) { std::cout << "[Error - CreatureEvent::configureEvent] Missing type for creature event: " << m_eventName << std::endl; return false; } std::string tmpStr = asLowerCaseString(typeAttribute.as_string()); if (tmpStr == "login") { m_type = CREATURE_EVENT_LOGIN; } else if (tmpStr == "logout") { m_type = CREATURE_EVENT_LOGOUT; } else if (tmpStr == "think") { m_type = CREATURE_EVENT_THINK; } else if (tmpStr == "preparedeath") { m_type = CREATURE_EVENT_PREPAREDEATH; } else if (tmpStr == "death") { m_type = CREATURE_EVENT_DEATH; } else if (tmpStr == "kill") { m_type = CREATURE_EVENT_KILL; } else if (tmpStr == "advance") { m_type = CREATURE_EVENT_ADVANCE; } else if (tmpStr == "modalwindow") { m_type = CREATURE_EVENT_MODALWINDOW; } else if (tmpStr == "textedit") { m_type = CREATURE_EVENT_TEXTEDIT; } else if (tmpStr == "healthchange") { m_type = CREATURE_EVENT_HEALTHCHANGE; } else if (tmpStr == "manachange") { m_type = CREATURE_EVENT_MANACHANGE; } else if (tmpStr == "extendedopcode") { m_type = CREATURE_EVENT_EXTENDED_OPCODE; } else if (tmpStr == "spawn") { m_type = CREATURE_EVENT_SPAWN; } else { std::cout << "[Error - CreatureEvent::configureEvent] Invalid type for creature event: " << m_eventName << std::endl; return false; } m_isLoaded = true; return true; }
Event* Weapons::getEvent(const std::string& nodeName) { std::string tmpNodeName = asLowerCaseString(nodeName); if(tmpNodeName == "melee") return new WeaponMelee(&m_scriptInterface); else if(tmpNodeName == "distance") return new WeaponDistance(&m_scriptInterface); else if(tmpNodeName == "wand" || tmpNodeName == "rod") return new WeaponWand(&m_scriptInterface); return NULL; }
bool MoveEvent::loadFunction(const std::string& functionName) { if(asLowerCaseString(functionName) == "onstepinfield"){ stepFunction = StepInField; } else if(asLowerCaseString(functionName) == "onstepoutfield"){ stepFunction = StepOutField; } else if(asLowerCaseString(functionName) == "onaddfield"){ moveFunction = AddItemField; } else if(asLowerCaseString(functionName) == "onremovefield"){ moveFunction = RemoveItemField; } else if(asLowerCaseString(functionName) == "onequipitem"){ equipFunction = EquipItem; } else if(asLowerCaseString(functionName) == "ondeequipitem"){ equipFunction = DeEquipItem; } else{ return false; } m_scripted = false; return true; }
int32_t reasonStringToInt(std::string reason) { reason = asLowerCaseString(reason); if (reason == "offensive name") { return 0; } else if (reason == "invalid name format") { return 1; } else if (reason == "unsuitable name") { return 2; } else if (reason == "name inciting rule violation") { return 3; } else if (reason == "offensive statement") { return 4; } else if (reason == "spamming") { return 5; } else if (reason == "illegal advertising") { return 6; } else if (reason == "off-topic public statement") { return 7; } else if (reason == "non-english public statement") { return 8; } else if (reason == "inciting rule violation") { return 9; } else if (reason == "bug abuse") { return 10; } else if (reason == "game weakness abuse") { return 11; } else if (reason == "using unofficial software to play") { return 12; } else if (reason == "hacking") { return 13; } else if (reason == "multi-clienting") { return 14; } else if (reason == "account trading or sharing") { return 15; } else if (reason == "threatening gamemaster") { return 16; } else if (reason == "pretending to have influence on rule enforcement") { return 17; } else if (reason == "false report to gamemaster") { return 18; } else if (reason == "destructive behaviour") { return 19; } else if (reason == "excessive unjustified player killing") { return 20; } else if (reason == "spoiling auction") { return 21; } else { return -1; } }
bool IOMapSerialize::saveHouseItems(Database* db, House* house) { std::string config = asLowerCaseString(g_config.getString(ConfigManager::HOUSE_STORAGE)); if(config == "binary-tilebased") { DBQuery query; query << "DELETE FROM `tile_store` WHERE `house_id` = " << house->getId() << " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID); if(!db->query(query.str())) return false; DBInsert stmt(db); stmt.setQuery("INSERT INTO `tile_store` (`house_id`, `world_id`, `data`) VALUES "); return saveHouseBinaryTileBased(db, stmt, house) && stmt.execute(); } else if(config == "binary") { DBQuery query; query << "DELETE FROM `house_data` WHERE `house_id` = "<< house->getId() << " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID); if(!db->query(query.str())) return false; DBInsert stmt(db); stmt.setQuery("INSERT INTO `house_data` (`house_id`, `world_id`, `data`) VALUES "); return saveHouseBinary(db, stmt, house) && stmt.execute(); } DBQuery query; query << "DELETE FROM `tile_items` WHERE `tile_id` IN (SELECT `id` FROM `tiles` WHERE `house_id` = " << house->getId() << " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << ") AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID); if(!db->query(query.str())) return false; query.str(""); query << "DELETE FROM `tiles` WHERE `house_id` = " << house->getId() << " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID); if(!db->query(query.str())) return false; query.str(""); query << "SELECT `id` FROM `tiles` WHERE `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " ORDER BY `id` DESC LIMIT 1;"; DBResult* result; if(!(result = db->storeQuery(query.str()))) return false; uint32_t tileId = result->getDataInt("id") + 1; result->free(); return saveHouseRelational(db, house, tileId); }
Houses::Houses() { rentPeriod = RENTPERIOD_NEVER; std::string strValue = asLowerCaseString(g_config.getString(ConfigManager::HOUSE_RENT_PERIOD)); if(strValue == "yearly") rentPeriod = RENTPERIOD_YEARLY; else if(strValue == "monthly") rentPeriod = RENTPERIOD_MONTHLY; else if(strValue == "weekly") rentPeriod = RENTPERIOD_WEEKLY; else if(strValue == "daily") rentPeriod = RENTPERIOD_DAILY; }
GuildEmblems_t getEmblems(std::string strValue) { std::string tmpStrValue = asLowerCaseString(strValue); if(tmpStrValue == "blue" || tmpStrValue == "3") return EMBLEM_BLUE; if(tmpStrValue == "red" || tmpStrValue == "2") return EMBLEM_RED; if(tmpStrValue == "green" || tmpStrValue == "1") return EMBLEM_GREEN; return EMBLEM_NONE; }
GuildEmblems_t getEmblems(std::string strValue) { std::string tmpStrValue = asLowerCaseString(strValue); if(tmpStrValue == "blue" || tmpStrValue == "neutral" || tmpStrValue == "3") return GUILDEMBLEM_NEUTRAL; if(tmpStrValue == "red" || tmpStrValue == "enemy" || tmpStrValue == "2") return GUILDEMBLEM_ENEMY; if(tmpStrValue == "green" || tmpStrValue == "ally" || tmpStrValue == "1") return GUILDEMBLEM_ALLY; return GUILDEMBLEM_NONE; }
Event* Spells::getEvent(const std::string& nodeName) { std::string tmpNodeName = asLowerCaseString(nodeName); if(tmpNodeName == "rune") return new RuneSpell(&m_interface); if(tmpNodeName == "instant") return new InstantSpell(&m_interface); if(tmpNodeName == "conjure") return new ConjureSpell(&m_interface); return NULL; }
void Creature::onAttackedCreatureDrainHealth(Creature* target, int32_t points) { target->addDamagePoints(this, points); if (!master) { return; } Player* masterPlayer = master->getPlayer(); if (masterPlayer) { std::ostringstream ss; ss << "Your " << asLowerCaseString(getName()) << " deals " << points << " to " << target->getNameDescription() << '.'; masterPlayer->sendTextMessage(MSG_EVENT_DEFAULT, ss.str()); } }
Skulls_t getSkull(std::string strValue) { std::string tmpStrValue = asLowerCaseString(strValue); if(tmpStrValue == "black" || tmpStrValue == "5") return SKULL_BLACK; else if(tmpStrValue == "red" || tmpStrValue == "4") return SKULL_RED; else if(tmpStrValue == "white" || tmpStrValue == "3") return SKULL_WHITE; else if(tmpStrValue == "green" || tmpStrValue == "2") return SKULL_GREEN; else if(tmpStrValue == "yellow" || tmpStrValue == "1") return SKULL_YELLOW; return SKULL_NONE; }
bool AnnounceEvent::configureRaidEvent(xmlNodePtr eventNode) { if(!RaidEvent::configureRaidEvent(eventNode)){ return false; } std::string strValue; if(readXMLString(eventNode, "message", strValue)){ m_message = strValue; } else{ std::cout << "[Error] Raid: message tag missing for announce event." << std::endl; return false; } if(readXMLString(eventNode, "type", strValue)){ if(asLowerCaseString(strValue) == "warning"){ m_messageType = MSG_STATUS_WARNING; } else if(asLowerCaseString(strValue) == "event"){ m_messageType = MSG_EVENT_ADVANCE; } else if(asLowerCaseString(strValue) == "default"){ m_messageType = MSG_EVENT_DEFAULT; } else if(asLowerCaseString(strValue) == "description"){ m_messageType = MSG_INFO_DESCR; } else if(asLowerCaseString(strValue) == "smallstatus"){ m_messageType = MSG_STATUS_SMALL; } else if(asLowerCaseString(strValue) == "blueconsole"){ m_messageType = MSG_STATUS_CONSOLE_BLUE; } else if(asLowerCaseString(strValue) == "redconsole"){ m_messageType = MSG_STATUS_CONSOLE_RED; } else{ m_messageType = MSG_EVENT_ADVANCE; std::cout << "[Notice] Raid: Unknown type tag missing for announce event. Using default: " << (int32_t)m_messageType << std::endl; } } else{ m_messageType = MSG_EVENT_ADVANCE; std::cout << "[Notice] Raid: type tag missing for announce event. Using default: " << (int32_t)m_messageType << std::endl; } return true; }