Outfit ProtocolGame::internalGetOutfit(InputMessage& msg) { Outfit outfit; int id = msg.getU16(); if(id != 0) { outfit.setCategory(ThingsType::Creature); int head = msg.getU8(); int body = msg.getU8(); int legs = msg.getU8(); int feet = msg.getU8(); int addons = msg.getU8(); outfit.setId(id); outfit.setHead(head); outfit.setBody(body); outfit.setLegs(legs); outfit.setFeet(feet); outfit.setAddons(addons); } else { int id = msg.getU16(); if(id == 0) { outfit.setCategory(ThingsType::Effect); outfit.setId(13); } else { outfit.setCategory(ThingsType::Item); outfit.setId(id); } } return outfit; }
void ProtocolGame::parseOpenChannel(InputMessage& msg) { int channelId = msg.getU16(); std::string name = msg.getString(); g_lua.callGlobalField("Game", "onOpenChannel", channelId, name); }
void ProtocolGame::parseContainerUpdateItem(InputMessage& msg) { int containerId = msg.getU8(); int slot = msg.getU8(); ItemPtr item = internalGetItem(msg); g_lua.callGlobalField("Game", "onContainerUpdateItem", containerId, slot, item); }
void ProtocolLogin::onRecv(InputMessage& inputMessage) { try { while(!inputMessage.eof()) { int opt = inputMessage.getU8(); switch(opt) { case Proto::LoginServerError: parseError(inputMessage); break; case Proto::LoginServerMotd: parseMOTD(inputMessage); break; case Proto::LoginServerUpdateNeeded: callLuaField("onError", "Client needs update."); break; case Proto::LoginServerCharacterList: parseCharacterList(inputMessage); break; default: Fw::throwException("unknown opt byte ", opt); break; } } } catch(Exception& e) { logTraceError(e.what()); } disconnect(); }
void ProtocolGame::parseSafeTradeRequest(InputMessage& msg) { msg.getString(); // name int count = msg.getU8(); for(int i = 0; i < count; i++) internalGetItem(msg); }
void ProtocolGame::parseWorldLight(InputMessage& msg) { Light light; light.intensity = msg.getU8(); light.color = msg.getU8(); g_map.setLight(light); }
Position ProtocolGame::parsePosition(InputMessage& msg) { uint16 x = msg.getU16(); uint16 y = msg.getU16(); uint8 z = msg.getU8(); return Position(x, y, z); }
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::parseCreatureHealth(InputMessage& msg) { uint id = msg.getU32(); int healthPercent = msg.getU8(); CreaturePtr creature = g_map.getCreatureById(id); if(creature) creature->setHealthPercent(healthPercent); }
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::parseQuestList(InputMessage& msg) { int questsCount = msg.getU16(); for(int i = 0; i < questsCount; i++) { msg.getU16(); // quest id msg.getString(); // quest name msg.getU8(); // quest state } }
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::parseTextMessage(InputMessage& msg) { int type = msg.getU8(); std::string typeDesc = Proto::translateTextMessageType(type); std::string message = msg.getString(); g_game.processTextMessage(typeDesc, message); }
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::parseItemTextWindow(InputMessage& msg) { msg.getU32(); // windowId msg.getU16(); // itemid msg.getU16(); // max length msg.getString(); // text msg.getString(); // writter msg.getString(); // date }
void ProtocolGame::parseQuestPartList(InputMessage& msg) { msg.getU16(); // quest id int missionCount = msg.getU8(); for(int i = 0; i < missionCount; i++) { msg.getString(); // quest name msg.getString(); // quest description } }
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::parseCreatureSpeed(InputMessage& msg) { uint id = msg.getU32(); int speed = msg.getU16(); CreaturePtr creature = g_map.getCreatureById(id); if(creature) creature->setSpeed(speed); }
void ProtocolGame::parsePlayerCash(InputMessage& msg) { msg.getU32(); int size = msg.getU8(); for(int i = 0; i < size; i++) { msg.getU16(); // itemid msg.getU8(); // runecharges } }
ItemPtr ProtocolGame::internalGetItem(InputMessage& msg, int id) { if(id == 0) id = msg.getU16(); ItemPtr item = Item::create(id); if(item->isStackable() || item->isFluidContainer() || item->isFluid()) item->setData(msg.getU8()); return item; }
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::parseUpdateTile(InputMessage& msg) { Position tilePos = parsePosition(msg); int thingId = msg.getU16(true); if(thingId == 0xFF01) { msg.getU16(); } else { setTileDescription(msg, tilePos); msg.getU16(); } }
void ProtocolGame::parseChannelList(InputMessage& msg) { int count = msg.getU8(); std::vector<std::tuple<int, std::string> > channelList(count); for(int i = 0; i < count; i++) { int id = msg.getU16(); std::string name = msg.getString(); channelList.push_back(std::make_tuple(id, name)); } g_lua.callGlobalField("Game", "onChannelList", channelList); }
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 ProtocolGame::parseAnimatedText(InputMessage& msg) { Position position = parsePosition(msg); int color = msg.getU8(); std::string text = msg.getString(); AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText); animatedText->setColor(color); animatedText->setText(text); g_map.addThing(animatedText, position); }
void ProtocolGame::parseTileTransformThing(InputMessage& msg) { Position pos = parsePosition(msg); int stackPos = msg.getU8(); int thingId = msg.getU16(); assert(thingId != 0); if(thingId == 0x0061 || thingId == 0x0062 || thingId == 0x0063) { parseCreatureTurn(msg); } else { ThingPtr thing = internalGetItem(msg, thingId); g_map.removeThingByPos(pos, stackPos); g_map.addThing(thing, pos, stackPos); } }
void ProtocolGame::parseDeath(InputMessage& msg) { #if PROTOCOL==862 msg.getU8(); // 100 is a fair death. < 100 is a unfair death. #endif g_game.processDeath(); }
void Daemon::run( InputMessage &message, Channel channel ) { NOTE(); { OutputMessage response( MessageType::Control ); if ( _state != State::Grouped ) { Logger::log( "command Run came at bad moment" ); response.tag( Code::Refuse ); channel->send( response ); return; } response.tag( Code::OK ); channel->send( response ); channel->receive( message, [&,this] ( size_t length ) { char *arg = new char[ length + 1 ](); _arguments.emplace_back( arg ); return arg; } ); message.clear(); channel->receiveHeader( message ); if ( message.tag< Code >() != Code::Start ) { throw ResponseException( { Code::Start }, message.tag< Code >() ); } } _runMain = true; }
void ProtocolGame::parseTileRemoveThing(InputMessage& msg) { Position pos = parsePosition(msg); int stackPos = msg.getU8(); g_map.removeThingByPos(pos, stackPos); }
bool PlayerControllerSystem::init() { if(m_isInitialised) return false; if(!m_componentPool.init(100)) { LOG(ERROR, "Could not initialise m_componentPool with 10 ojects."); return false; } InputMessage inputMessage; m_inputMessageType = inputMessage.getType(); m_isInitialised = true; return true; }