void ProtocolGame::parseOpenShopWindow(InputMessage& msg) { int listCount = msg.getU8(); for(int i = 0; i < listCount; ++i) { msg.getU16(); // item id msg.getU8(); // runecharges msg.getString(); // item name msg.getU32(); // weight msg.getU32(); // buy price msg.getU32(); // sell price } }
void ProtocolGame::parseVipState(InputMessage& msg) { uint id = msg.getU32(); std::string name = msg.getString(); bool online = msg.getU8() != 0; g_lua.callGlobalField("Game", "onAddVip", id, name, online); }
void ProtocolGame::parseCreatureSkulls(InputMessage& msg) { uint id = msg.getU32(); int skull = msg.getU8(); CreaturePtr creature = g_map.getCreatureById(id); if(creature) creature->setSkull(skull); }
void ProtocolGame::onRead(uint8_t byte, InputMessage in) { if (byte < NET_GAME_START || byte > NET_GAME_PLAYER_DEAD) Protocol::onRead(byte, in); else if (m_byteHandler) m_byteHandler(in.getU32(), byte, in); recv(); }
void ProtocolGame::parseCreatureSpeed(InputMessage& msg) { uint id = msg.getU32(); int speed = msg.getU16(); CreaturePtr creature = g_map.getCreatureById(id); if(creature) creature->setSpeed(speed); }
void ProtocolGame::parseCreatureSquare(InputMessage& msg) { uint id = msg.getU32(); int color = msg.getU8(); CreaturePtr creature = g_map.getCreatureById(id); if(creature) creature->addVolatileSquare(color); }
void ProtocolGame::parseCreatureOutfit(InputMessage& msg) { uint id = msg.getU32(); Outfit outfit = internalGetOutfit(msg); CreaturePtr creature = g_map.getCreatureById(id); if(creature) creature->setOutfit(outfit); }
void ProtocolGame::parseItemTextWindow(InputMessage& msg) { msg.getU32(); // windowId msg.getU16(); // itemid msg.getU16(); // max length msg.getString(); // text msg.getString(); // writter msg.getString(); // date }
void ProtocolGame::parseCreatureHealth(InputMessage& msg) { uint id = msg.getU32(); int healthPercent = msg.getU8(); CreaturePtr creature = g_map.getCreatureById(id); if(creature) creature->setHealthPercent(healthPercent); }
void ProtocolGame::parseCreatureShields(InputMessage& msg) { uint id = msg.getU32(); int shield = msg.getU8(); CreaturePtr creature = g_map.getCreatureById(id); if(creature) creature->setShield(shield); }
void ProtocolGame::parseCreatureTurn(InputMessage& msg) { uint id = msg.getU32(); Otc::Direction direction = (Otc::Direction)msg.getU8(); CreaturePtr creature = g_map.getCreatureById(id); if(creature) creature->turn(direction); }
void ProtocolGame::parsePlayerCash(InputMessage& msg) { msg.getU32(); int size = msg.getU8(); for(int i = 0; i < size; i++) { msg.getU16(); // itemid msg.getU8(); // runecharges } }
void ProtocolGame::parseCreatureSpeak(InputMessage& msg) { msg.getU32(); // unkSpeak std::string name = msg.getString(); int level = msg.getU16(); int type = msg.getU8(); int channelId = 0; Position creaturePos; switch(type) { case Proto::SpeakSay: case Proto::SpeakWhisper: case Proto::SpeakYell: case Proto::SpeakMonsterSay: case Proto::SpeakMonsterYell: case Proto::SpeakPrivateNpcToPlayer: creaturePos = parsePosition(msg); break; case Proto::SpeakChannelYellow: case Proto::SpeakChannelWhite: case Proto::SpeakChannelRed: case Proto::SpeakChannelRed2: case Proto::SpeakChannelOrange: channelId = msg.getU16(); break; case Proto::SpeakPrivate: case Proto::SpeakPrivatePlayerToNpc: case Proto::SpeakBroadcast: case Proto::SpeakPrivateRed: break; case Proto::SpeakRVRChannel: msg.getU32(); break; default: logTraceError("unknown speak type ", type); break; } std::string message = msg.getString(); std::string typeDesc = Proto::translateSpeakType(type); g_game.processCreatureSpeak(name, level, typeDesc, message, channelId, creaturePos); }
void ProtocolGame::parsePlayerLogin(InputMessage& msg) { uint playerId = msg.getU32(); int serverBeat = msg.getU16(); int playerCanReportBugs = msg.getU8(); m_localPlayer = LocalPlayerPtr(new LocalPlayer); m_localPlayer->setId(playerId); m_localPlayer->setCanReportBugs(playerCanReportBugs); g_game.processLogin(m_localPlayer, serverBeat); }
void ProtocolGame::parseCreatureLight(InputMessage& msg) { uint id = msg.getU32(); Light light; light.intensity = msg.getU8(); light.color = msg.getU8(); CreaturePtr creature = g_map.getCreatureById(id); if(creature) creature->setLight(light); }
void ProtocolLogin::parseCharacterList(InputMessage& inputMessage) { typedef std::tuple<std::string, std::string, std::string, int> CharacterInfo; typedef std::vector<CharacterInfo> CharaterList; CharaterList charList; int numCharacters = inputMessage.getU8(); for(int i = 0; i < numCharacters; ++i) { std::string name = inputMessage.getString(); std::string world = inputMessage.getString(); uint32 ip = inputMessage.getU32(); uint16 port = inputMessage.getU16(); charList.push_back(CharacterInfo(name, world, Fw::ip2str(ip), port)); } int premDays = inputMessage.getU16(); callLuaField("onCharacterList", charList, premDays); }
void ProtocolGame::parseVipLogout(InputMessage& msg) { uint id = msg.getU32(); g_lua.callGlobalField("Game", "onVipStateChange", id, false); }
void ProtocolGame::parsePlayerCancelAttack(InputMessage& msg) { msg.getU32(); // unknown g_game.processAttackCancel(); }
void ProtocolGame::parsePlayerStats(InputMessage& msg) { double health = msg.getU16(); double maxHealth = msg.getU16(); double freeCapacity = msg.getU32() / 100.0; double experience = msg.getU32(); double level = msg.getU16(); double levelPercent = msg.getU8(); double mana = msg.getU16(); double maxMana = msg.getU16(); double magicLevel = msg.getU8(); double magicLevelPercent = msg.getU8(); double soul = msg.getU8(); double stamina = msg.getU16(); //TODO: move to game if(m_localPlayer->getStatistic(Otc::Health) != health || m_localPlayer->getStatistic(Otc::MaxHealth) != maxHealth) { m_localPlayer->setStatistic(Otc::Health, health); m_localPlayer->setStatistic(Otc::MaxHealth, maxHealth); g_lua.callGlobalField("Game", "onHealthChange", health, maxHealth); } if(m_localPlayer->getStatistic(Otc::FreeCapacity) != freeCapacity) { m_localPlayer->setStatistic(Otc::FreeCapacity, freeCapacity); g_lua.callGlobalField("Game", "onFreeCapacityChange", freeCapacity); } if(m_localPlayer->getStatistic(Otc::Experience) != experience) { m_localPlayer->setStatistic(Otc::Experience, experience); g_lua.callGlobalField("Game", "onExperienceChange", experience); } if(m_localPlayer->getStatistic(Otc::Level) != level || m_localPlayer->getStatistic(Otc::LevelPercent) != levelPercent) { m_localPlayer->setStatistic(Otc::Level, level); m_localPlayer->setStatistic(Otc::LevelPercent, levelPercent); g_lua.callGlobalField("Game", "onLevelChange", level, levelPercent); } if(m_localPlayer->getStatistic(Otc::Mana) != mana || m_localPlayer->getStatistic(Otc::MaxMana) != maxMana) { m_localPlayer->setStatistic(Otc::Mana, mana); m_localPlayer->setStatistic(Otc::MaxMana, maxMana); g_lua.callGlobalField("Game", "onManaChange", mana, maxMana); } if(m_localPlayer->getStatistic(Otc::MagicLevel) != magicLevel || m_localPlayer->getStatistic(Otc::MagicLevelPercent) != magicLevelPercent) { m_localPlayer->setStatistic(Otc::MagicLevel, magicLevel); m_localPlayer->setStatistic(Otc::MagicLevelPercent, magicLevelPercent); g_lua.callGlobalField("Game", "onMagicLevelChange", magicLevel, magicLevelPercent); } if(m_localPlayer->getStatistic(Otc::Soul) != soul) { m_localPlayer->setStatistic(Otc::Soul, soul); g_lua.callGlobalField("Game", "onSoulChange", soul); } if(m_localPlayer->getStatistic(Otc::Stamina) != stamina) { m_localPlayer->setStatistic(Otc::Stamina, stamina); g_lua.callGlobalField("Game", "onStaminaChange", stamina); } }
void ProtocolGame::parseHouseTextWindow(InputMessage& msg) { msg.getU8(); // unknown msg.getU32(); // windowId msg.getString(); // text }
ThingPtr ProtocolGame::internalGetThing(InputMessage& msg) { ThingPtr thing; int thingId = msg.getU16(); assert(thingId != 0); if(thingId == 0x0061 || thingId == 0x0062) { // add new creature CreaturePtr creature; if(thingId == 0x0062) { //creature is known uint id = msg.getU32(); CreaturePtr knownCreature = g_map.getCreatureById(id); if(knownCreature) creature = knownCreature; else logTraceError("server says creature is known, but its not on creatures list"); } else if(thingId == 0x0061) { //creature is not known uint removeId = msg.getU32(); uint id = msg.getU32(); std::string name = msg.getString(); if(name.length() > 0) // every creature name must start with a capital letter name[0] = toupper(name[0]); g_map.removeCreatureById(removeId); if(id == m_localPlayer->getId()) creature = m_localPlayer; else if(id >= Proto::PlayerStartId && id < Proto::PlayerEndId) creature = PlayerPtr(new Player); else if(id >= Proto::MonsterStartId && id < Proto::MonsterEndId) creature = MonsterPtr(new Monster); else if(id >= Proto::NpcStartId && id < Proto::NpcEndId) creature = NpcPtr(new Npc); else logTraceError("creature id is invalid"); creature->setId(id); creature->setName(name); } uint8 healthPercent = msg.getU8(); Otc::Direction direction = (Otc::Direction)msg.getU8(); Outfit outfit = internalGetOutfit(msg); Light light; light.intensity = msg.getU8(); light.color = msg.getU8(); int speed = msg.getU16(); int skull = msg.getU8(); int shield = msg.getU8(); int emblem = -1; if(thingId == 0x0061) // emblem is sent only in packet type 0x61 emblem = msg.getU8(); bool passable = (msg.getU8() == 0); if(creature) { creature->setHealthPercent(healthPercent); creature->setDirection(direction); creature->setOutfit(outfit); creature->setLight(light); creature->setSpeed(speed); creature->setSkull(skull); creature->setShield(shield); if(emblem != -1) creature->setEmblem(emblem); creature->setPassable(passable); creature->setDirection(direction); if(creature == m_localPlayer) { m_localPlayer->setKnown(true); } } thing = creature; } else if(thingId == 0x0063) { // creature turn parseCreatureTurn(msg); } else // item thing = internalGetItem(msg, thingId); return thing; }