void LoginHandler::processUpdateHost2(Net::MessageIn &msg) { int len; len = msg.readInt16() - 4; std::string updateHost = msg.readString(len); splitToStringVector(loginData.updateHosts, updateHost, '|'); for (StringVectIter it = loginData.updateHosts.begin(), it_end = loginData.updateHosts.end(); it != it_end; ++ it) { if (!checkPath(*it)) { logger->log1("Warning: incorrect update server name"); loginData.updateHosts.clear(); break; } } logger->log("Received update hosts \"%s\" from login server.", updateHost.c_str()); if (Client::getState() == STATE_PRE_LOGIN) Client::setState(STATE_LOGIN); }
void BeingCommon::readWalkingAttributes(BeingInfo *const info, XmlNodePtrConst node, const int moreBlockFlags) { uint8_t block = 0; std::string walkStr = XML::getProperty( node, "walkType", "walk"); const uint8_t allFlags = CAST_U8( BlockMask::GROUND | BlockMask::WALL | BlockMask::WATER | BlockMask::AIR | moreBlockFlags); StringVect tokens; splitToStringVector(tokens, walkStr, ','); FOR_EACH (StringVectCIter, it, tokens) { if (walkStr == "walk" || walkStr == "ground") block |= BlockMask::GROUND; else if (walkStr == "fly" || walkStr == "air") block |= BlockMask::GROUND | BlockMask::WATER | BlockMask::AIR; else if (walkStr == "all") block |= allFlags; else if (walkStr == "wall") block |= BlockMask::WALL; else if (walkStr == "monsterwall") block |= BlockMask::MONSTERWALL; else if (walkStr == "swim" || walkStr == "water") block |= BlockMask::WATER; else if (walkStr == "walkswim" || walkStr == "swimwalk") // legacy block |= BlockMask::GROUND | BlockMask::WATER; } info->setBlockWalkMask(CAST_U8(block ^ allFlags)); }
void InputManager::retrieve() { for (int i = 0; i < InputAction::TOTAL; i++) { #ifdef USE_SDL2 const std::string cf = std::string("sdl2") + inputActionData[i].configField; #else const std::string cf = inputActionData[i].configField; #endif if (!cf.empty()) { mNameMap[cf] = i; InputFunction &kf = mKey[i]; const std::string keyStr = config.getValue(cf, ""); const size_t keyStrSize = keyStr.size(); if (keyStr.empty()) continue; StringVect keys; splitToStringVector(keys, keyStr, ','); unsigned int i2 = 0; for (StringVectCIter it = keys.begin(), it_end = keys.end(); it != it_end && i2 < inputFunctionSize; ++ it) { std::string keyStr2 = *it; if (keyStrSize < 2) continue; int type = InputType::KEYBOARD; if ((keyStr2[0] < '0' || keyStr2[0] > '9') && keyStr2[0] != '-') { switch (keyStr2[0]) { case 'm': type = InputType::MOUSE; break; case 'j': type = InputType::JOYSTICK; break; default: break; } keyStr2 = keyStr2.substr(1); } const int key = atoi(keyStr2.c_str()); if (key >= -255 && key < SDLK_LAST) { kf.values[i2] = InputItem(type, key); i2 ++; } } } } }
void BeingCommon::readBasicAttributes(BeingInfo *const info, XmlNodePtrConst node, const std::string &hoverCursor) { info->setTargetCursorSize(XML::getProperty(node, "targetCursor", "medium")); info->setHoverCursor(XML::getProperty(node, "hoverCursor", hoverCursor)); info->setTargetOffsetX(XML::getProperty(node, "targetOffsetX", 0)); info->setTargetOffsetY(XML::getProperty(node, "targetOffsetY", 0)); info->setNameOffsetX(XML::getProperty(node, "nameOffsetX", 0)); info->setNameOffsetY(XML::getProperty(node, "nameOffsetY", 0)); info->setSortOffsetY(XML::getProperty(node, "sortOffsetY", 0)); info->setHpBarOffsetX(XML::getProperty(node, "hpBarOffsetX", 0)); info->setHpBarOffsetY(XML::getProperty(node, "hpBarOffsetY", 0)); info->setQuickActionEffectId(XML::getProperty(node, "quickActionEffect", -1)); unsigned char block = 0; std::string walkStr = XML::getProperty( node, "walkType", "walk"); const int allFlags = BlockMask::GROUND | BlockMask::WALL | BlockMask::WATER | BlockMask::AIR; StringVect tokens; splitToStringVector(tokens, walkStr, ','); FOR_EACH (StringVectCIter, it, tokens) { if (walkStr == "walk" || walkStr == "ground") block |= BlockMask::GROUND; else if (walkStr == "fly" || walkStr == "air") block |= BlockMask::GROUND | BlockMask::WATER | BlockMask::AIR; else if (walkStr == "all") block |= allFlags; else if (walkStr == "wall") block |= BlockMask::WALL; else if (walkStr == "swim" || walkStr == "water") block |= BlockMask::WATER; else if (walkStr == "walkswim" || walkStr == "swimwalk") // legacy block |= BlockMask::GROUND | BlockMask::WATER; } info->setBlockWalkMask(CAST_U8(block ^ allFlags)); }
void InputManager::retrieve() { for (int i = 0; i < Input::KEY_TOTAL; i++) { if (*keyData[i].configField) { KeyFunction &kf = mKey[i]; std::string keyStr = config.getValue(keyData[i].configField, ""); if (keyStr.empty()) continue; StringVect keys; splitToStringVector(keys, keyStr, ','); int i2 = 0; for (StringVectCIter it = keys.begin(), it_end = keys.end(); it != it_end && i2 < KeyFunctionSize; ++ it) { std::string keyStr2 = *it; if (keyStr.size() < 2) continue; int type = INPUT_KEYBOARD; if ((keyStr2[0] < '0' || keyStr2[0] > '9') && keyStr2[0] != '-') { switch (keyStr2[0]) { case 'm': type = INPUT_MOUSE; break; case 'j': type = INPUT_JOYSTICK; break; default: break; } keyStr2 = keyStr2.substr(1); } int key = atoi(keyStr2.c_str()); if (key >= -255 && key < SDLK_LAST) { kf.values[i2] = KeyItem(type, key); i2 ++; } } } } }
void SpriteDef::loadAnimation(XmlNodePtr animationNode, Action *action, ImageSet *imageSet, int variant_offset) { if (!action || !imageSet) return; const std::string directionName = XML::getProperty(animationNode, "direction", ""); const SpriteDirection directionType = makeSpriteDirection(directionName); if (directionType == DIRECTION_INVALID) { logger->log("Warning: Unknown direction \"%s\" used in %s", directionName.c_str(), getIdPath().c_str()); return; } Animation *animation = new Animation; action->setAnimation(directionType, animation); // Get animation frames for_each_xml_child_node(frameNode, animationNode) { const int delay = XML::getIntProperty( frameNode, "delay", 0, 0, 100000); int offsetX = XML::getProperty(frameNode, "offsetX", 0) + imageSet->getOffsetX(); int offsetY = XML::getProperty(frameNode, "offsetY", 0) + imageSet->getOffsetY(); int rand = XML::getIntProperty(frameNode, "rand", 100, 0, 100); offsetY -= imageSet->getHeight() - 32; offsetX -= imageSet->getWidth() / 2 - 16; if (xmlNameEqual(frameNode, "frame")) { const int index = XML::getProperty(frameNode, "index", -1); if (index < 0) { logger->log1("No valid value for 'index'"); continue; } Image *img = imageSet->get(index + variant_offset); if (!img) { logger->log("No image at index %d", index + variant_offset); continue; } animation->addFrame(img, delay, offsetX, offsetY, rand); } else if (xmlNameEqual(frameNode, "sequence")) { const int start = XML::getProperty(frameNode, "start", -1); const int end = XML::getProperty(frameNode, "end", -1); const std::string value = XML::getProperty(frameNode, "value", ""); int repeat = XML::getIntProperty(frameNode, "repeat", 1, 0, 100); if (repeat < 1) { logger->log1("No valid value for 'repeat'"); continue; } if (value.empty()) { if (addSequence(start, end, delay, offsetX, offsetY, variant_offset, repeat, rand, imageSet, animation)) { continue; } } else { StringVect vals; splitToStringVector(vals, value, ','); for (StringVectCIter it = vals.begin(), it_end = vals.end(); it != it_end; ++ it) { std::string str = *it; size_t idx = str.find("-"); if (str == "p") { animation->addPause(delay, rand); } else if (idx != std::string::npos) { int v1 = atoi(str.substr(0, idx).c_str()); int v2 = atoi(str.substr(idx + 1).c_str()); addSequence(v1, v2, delay, offsetX, offsetY, variant_offset, repeat, rand, imageSet, animation); } else { Image *img = imageSet->get(atoi( str.c_str()) + variant_offset); if (img) { animation->addFrame(img, delay, offsetX, offsetY, rand); } } } } } else if (xmlNameEqual(frameNode, "pause")) { animation->addPause(delay, rand); } else if (xmlNameEqual(frameNode, "end")) { animation->addTerminator(rand); } else if (xmlNameEqual(frameNode, "jump")) { animation->addJump(XML::getProperty( frameNode, "action", ""), rand); } else if (xmlNameEqual(frameNode, "label")) { std::string name = XML::getProperty(frameNode, "name", ""); if (!name.empty()) animation->addLabel(name); } else if (xmlNameEqual(frameNode, "goto")) { std::string name = XML::getProperty(frameNode, "label", ""); if (!name.empty()) animation->addGoto(name, rand); } } // for frameNode }
bool GuildManager::process(std::string msg) { if (msg.size() > 4 && msg[0] == '#' && msg[1] == '#') msg = msg.substr(3); bool haveNick = (msg.find(": ") != std::string::npos); if (!haveNick && findCutLast(msg, " is now Offline.")) { Guild *guild = createGuild(); if (!guild) return false; if (msg.size() < 4) return false; if (msg[0] == '#' && msg[1] == '#') msg = msg.substr(3); GuildMember *m = guild->addMember(msg); if (m) m->setOnline(false); guild->sort(); mRequest = false; return true; } else if (!haveNick && findCutLast(msg, " is now Online.")) { Guild *guild = createGuild(); if (!guild) return false; if (msg.size() < 4) return false; if (msg[0] == '#' && msg[1] == '#') msg = msg.substr(3); GuildMember *m = guild->addMember(msg); if (m) m->setOnline(true); guild->sort(); mRequest = false; return true; } else if (findCutFirst(msg, "Welcome to the ")) { Guild *guild = createGuild(); if (!guild) return false; // logger->log("welcome message: %s", msg.c_str()); size_t pos = msg.find("! ("); if (pos == std::string::npos) return false; msg = msg.substr(0, pos); guild->setName(msg); if (player_node) player_node->setGuildName(msg); mGotName = true; mSentNameRequest = false; mRequest = false; return true; } else if (findCutFirst(msg, "Player name: ")) { Guild *guild = createGuild(); if (!guild) return false; size_t pos = msg.find("Access Level: "); if (pos == std::string::npos) return false; msg = msg.substr(pos); if (!findCutFirst(msg, "Access Level: ")) return false; pos = msg.find(", Guild:"); if (pos == std::string::npos) return false; int level = atoi(msg.substr(0, pos).c_str()); if (level >= 10) mHavePower = true; else mHavePower = false; msg = msg.substr(pos + strlen(", Guild:")); pos = msg.find(", No. Of Online Players: "); if (pos == std::string::npos) return false; msg = msg.substr(0, pos); // logger->log("guild name: %s", msg.c_str()); guild->setName(msg); if (player_node) player_node->setGuildName(msg); mGotName = true; mSentNameRequest = false; mRequest = false; return true; } else if (findCutFirst(msg, "OL#")) { // logger->log("OL"); mTempList.clear(); splitToStringVector(mTempList, msg, '#'); if (msg.size() < 1 || msg[msg.size() - 1] != '#') updateList(); mRequest = false; return true; } else if (findCutFirst(msg, "oL#")) { // logger->log("oL"); splitToStringVector(mTempList, msg, '#'); if (msg.size() < 1 || msg[msg.size() - 1] != '#') updateList(); mRequest = false; return true; } else if (msg == "You are currently not in a guild. For more information " "or to discuss the possibility of adding you own guild " "please contact Jero.") { mRequest = true; return true; } else if (findCutFirst(msg, "You have been invited to the ") && findCutLast(msg, " guild chat. If you would like to accept " "this invitation please reply \"yes\" and if not then \"no\" .")) { if (socialWindow) socialWindow->showGuildInvite(msg, 1, ""); return true; } else if (!haveNick && (findCutLast(msg, " has been removed " "from the Guild.") || findCutLast(msg, " has left the Guild."))) { Guild *guild = createGuild(); if (!guild) return false; if (msg.size() < 4) return false; if (msg[0] == '#' && msg[1] == '#') msg = msg.substr(3); if (actorSpriteManager) { Being *b = actorSpriteManager->findBeingByName( msg, Being::PLAYER); if (b) { b->clearGuilds(); b->setGuildName(""); b->updateColors(); } } guild->removeMember(msg); return true; } else if (msg == "You have been removed from the Guild" || msg == "You have left the Guild") { return afterRemove(); } else { Guild *guild = createGuild(); if (!guild) return false; if (!mTab) { createTab(guild); } if (mTab) { size_t pos = msg.find(": ", 0); if (pos != std::string::npos) { std::string sender_name = ((pos == std::string::npos) ? "" : msg.substr(0, pos)); if (!guild->getMember(sender_name)) { mTab->chatLog(msg); return true; } msg.erase(0, pos + 2); if (msg.size() > 3 && msg[0] == '#' && msg[1] == '#') msg.erase(0, 3); trim(msg); mTab->chatLog(sender_name, msg); } else { mTab->chatLog(msg); } return true; } } return false; }