void ServerIPHandler::handle(InPacket& recv) const { recv.skip(2); // Read the ipv4 adress in a string. std::string addrstr; for (int i = 0; i < 4; i++) { uint8_t num = static_cast<uint8_t>(recv.read_byte()); addrstr.append(std::to_string(num)); if (i < 3) { addrstr.push_back('.'); } } // Read the port adress in a string. std::string portstr = std::to_string(recv.read_short()); int32_t cid = recv.read_int(); // Attempt to reconnect to the server and if successfull, login to the game. Session::get().reconnect(addrstr.c_str(), portstr.c_str()); PlayerLoginPacket(cid).dispatch(); }
void Login::parseworlds(InPacket& recv) { int8_t worldid = recv.readbyte(); if (worldid != -1) { World world; world.wid = worldid; world.name = recv.readascii(); world.flag = recv.readbyte(); world.message = recv.readascii(); recv.skip(5); world.channelcount = recv.readbyte(); for (uint8_t i = 0; i < world.channelcount; i++) { recv.readascii(); recv.skip(4); world.chloads.push_back(recv.readbyte()); recv.skip(2); } worlds.push_back(world); } }
Ladder::Ladder(InPacket& recv) { x = recv.readshort(); y1 = recv.readshort(); y2 = recv.readshort(); ladder = recv.readbool(); }
void DeleteCharResponseHandler::handle(InPacket& recv) const { // Read the character id and if deletion was successfull (pic was correct). int32_t cid = recv.read_int(); uint8_t state = recv.read_byte(); // Extract information from the state byte. if (state) { UILoginNotice::Message message; switch (state) { case 10: message = UILoginNotice::BIRTHDAY_INCORRECT; break; case 20: message = UILoginNotice::SECOND_PASSWORD_INCORRECT; break; default: message = UILoginNotice::UNKNOWN_ERROR; } UI::get().emplace<UILoginNotice>(message); } else { if (auto charselect = UI::get().get_element<UICharSelect>()) charselect->remove_char(cid); } UI::get().enable(); }
void BuffHandler::handle(InPacket& recv) const { int64_t firstmask = recv.read_long(); int64_t secondmask = recv.read_long(); switch (secondmask) { case Buff::BATTLESHIP: handlebuff(recv, Buff::BATTLESHIP); return; } for (Buff::Stat stat : Buff::FIRST_BUFFS) { if (firstmask & stat) { handlebuff(recv, stat); } } for (Buff::Stat stat : Buff::SECOND_BUFFS) { if (secondmask & stat) { handlebuff(recv, stat); } } Stage::get().getplayer().recalcstats(false); }
void KillMobHandler::handle(InPacket& recv) const { int32_t oid = recv.readint(); int8_t animation = recv.readbyte(); Stage::get().getmobs().killmob(oid, animation); }
MapInfo::MapInfo(InPacket& recv) { mapwalls.setfirst(recv.readshort()); mapwalls.setsecond(recv.readshort()); mapborders.setfirst(recv.readshort()); mapborders.setsecond(recv.readshort()); bgm = recv.read<string>(); cloud = recv.readbool(); fieldlimit = recv.readint(); hideminimap = recv.readbool(); mapmark = recv.read<string>(); swim = recv.readbool(); town = recv.readbool(); uint16_t numseats = recv.readshort(); for (uint16_t i = 0; i < numseats; i++) { seats.push_back(recv); } uint16_t numladders = recv.readshort(); for (uint16_t i = 0; i < numladders; i++) { ladders.push_back(recv); } }
InPacket::InPacket(const InPacket &rhs) : Packet(rhs) { bodyLength = rhs.getLength(); decryptedBuf = (unsigned char*)malloc(bodyLength * sizeof(unsigned char)); memcpy(decryptedBuf, rhs.getBody(), bodyLength); }
World LoginParser::parse_world(InPacket& recv) { int8_t wid = recv.read_byte(); if (wid == -1) return{ {}, {}, {}, 0, 0, wid }; std::string name = recv.read_string(); uint8_t flag = recv.read_byte(); std::string message = recv.read_string(); recv.skip(5); std::vector<int32_t> chloads; uint8_t channelcount = recv.read_byte(); for (uint8_t i = 0; i < channelcount; ++i) { recv.read_string(); // channel name chloads.push_back(recv.read_int()); recv.skip(1); recv.skip(2); } recv.skip(2); return{ name, message, chloads, channelcount, flag, wid }; }
void ShowMobHpHandler::handle(InPacket& recv) const { int32_t oid = recv.readint(); int8_t hppercent = recv.readbyte(); uint16_t playerlevel = Stage::get().getplayer().getstats().getstat(Maplestat::LEVEL); Stage::get().getmobs().sendmobhp(oid, hppercent, playerlevel); }
void AddCooldownHandler::handle(InPacket& recv) const { int32_t skillid = recv.read_int(); int16_t time = recv.read_short(); int32_t seconds = Timer::get().seconds() + time; Stage::get().getplayer().getskills().set_cd(skillid, seconds); }
void SetfieldHandler::change_map(InPacket& recv, int32_t) const { recv.skip(3); int32_t mapid = recv.read_int(); int8_t portalid = recv.read_byte(); stagetransition(portalid, mapid); }
Footholdtree::Footholdtree(InPacket& recv) { int16_t leftw = 30000; int16_t rightw = -30000; int16_t botb = -30000; int16_t topb = 30000; uint16_t numbase = recv.readshort(); for (uint16_t i = 0; i < numbase; i++) { uint8_t layer = recv.readbyte(); uint16_t nummid = recv.readshort(); for (uint16_t j = 0; j < nummid; j++) { uint16_t numlast = recv.readshort(); for (uint16_t k = 0; k < numlast; k++) { Foothold foothold = Foothold(recv, layer); if (foothold.getl() < leftw) { leftw = foothold.getl(); } else if (foothold.getr() > rightw) { rightw = foothold.getr(); } if (foothold.getb() > botb) { botb = foothold.getb(); } else if (foothold.gett() < topb) { topb = foothold.gett(); } uint16_t id = foothold.getid(); footholds[id] = foothold; if (abs(foothold.getslope()) < 0.5) { int16_t start = foothold.getl(); int16_t end = foothold.getr(); for (int16_t i = start; i <= end; i++) { footholdsbyx.insert(std::make_pair(i, id)); } } } } } walls = Range<int16_t>(leftw + 25, rightw - 25); borders = Range<int16_t>(topb - 400, botb + 400); }
void SetfieldHandler::parseareainfo(InPacket& recv) const { std::map<int16_t, std::string> areainfo; int16_t arsize = recv.read_short(); for (int16_t i = 0; i < arsize; i++) { int16_t area = recv.read_short(); areainfo[area] = recv.read_string(); } }
void ChangeStatsHandler::handle(InPacket& recv) const { recv.read_bool(); // 'itemreaction' int32_t updatemask = recv.read_int(); Player& player = Stage::get().getplayer(); bool recalculate = false; for (auto it = Maplestat::it(); it.hasnext(); it.increment()) { Maplestat::Value stat = it.get(); if (Maplestat::compare(stat, updatemask)) { bool updatesingle = false; switch (stat) { case Maplestat::SKIN: player.changelook(stat, recv.read_short()); break; case Maplestat::FACE: case Maplestat::HAIR: player.changelook(stat, recv.read_int()); break; case Maplestat::LEVEL: player.changelevel(recv.read_byte()); updatesingle = true; break; case Maplestat::JOB: player.changejob(recv.read_short()); updatesingle = true; break; case Maplestat::EXP: player.getstats().set_exp(recv.read_int()); break; case Maplestat::MESO: player.getinvent().setmeso(recv.read_int()); break; default: player.getstats().set_stat(stat, recv.read_short()); recalculate = true; break; } if (updatesingle) { UI::get().with_element<UIStatsinfo>([&stat](auto& si) { si.updatestat(stat); }); } } } if (recalculate) { player.recalcstats(false); } UI::get().enable(); }
void Login::parsecharlist(InPacket& recv) { size_t numchars = recv.readbyte(); for (size_t i = 0; i < numchars; i++) { addcharentry(recv); } account.pic = recv.readbyte(); account.slots = static_cast<int8_t>(recv.readint()); }
void ApplyBuffHandler::handlebuff(InPacket& recv, Buffstat::Value bs) const { int16_t value = recv.readshort(); int32_t skillid = recv.readint(); int32_t duration = recv.readint(); Buff buff = Buff(bs, value, skillid, duration); Stage::get().getplayer().givebuff(buff); UI::get().withelement(UIElement::BUFFLIST, &UIBuffList::addbuff, skillid, duration); }
void UpdateskillsHandler::handle(InPacket& recv) const { recv.skip(3); int32_t skillid = recv.readint(); int32_t level = recv.readint(); int32_t masterlevel = recv.readint(); int64_t expire = recv.readlong(); Stage::get().getplayer().getskills().setskill(skillid, level, masterlevel, expire); }
void SkillMacrosHandler::handle(InPacket& recv) const { uint8_t size = recv.readbyte(); for (uint8_t i = 0; i < size; i++) { recv.readascii(); // name recv.readbyte(); // 'shout' byte recv.readint(); // skill 1 recv.readint(); // skill 2 recv.readint(); // skill 3 } }
void KeymapHandler::handle(InPacket& recv) const { recv.skip(1); for (uint8_t i = 0; i < 90; i++) { uint8_t type = recv.readbyte(); int32_t action = recv.readint(); UI::get().addkeymapping(i, type, action); } }
void ApplyBuffHandler::handlebuff(InPacket& recv, Buff::Stat bs) const { int16_t value = recv.read_short(); int32_t skillid = recv.read_int(); int32_t duration = recv.read_int(); Stage::get().getplayer().givebuff({ bs, value, skillid, duration }); UI::get().with_element<UIBuffList>([&skillid, &duration](auto& bl) { bl.add_buff(skillid, duration); }); }
void SetfieldHandler::parsetelerock(InPacket& recv, Telerock& trock) const { for (size_t i = 0; i < 5; i++) { trock.addlocation(recv.read_int()); } for (size_t i = 0; i < 10; i++) { trock.addviplocation(recv.read_int()); } }
void PacketStorage::appendInPacket(char *inStr, int32 len) { mutex.lock(); InPacket *inPacket = new InPacket((uint8 *)inStr, len); //插入到收到队列里 inPacketList.insert(inPacket->getSequence(), inPacket); //唤醒线程 packetListEmpty.wakeOne(); mutex.unlock(); SAFE_DELETE_ARRAY(inStr); }
void SetfieldHandler::parsering1(InPacket& recv) const { int16_t rsize = recv.read_short(); for (int16_t i = 0; i < rsize; i++) { recv.read_int(); recv.read_padded_string(13); recv.read_int(); recv.read_int(); recv.read_int(); recv.read_int(); } }
void SetfieldHandler::handle(InPacket& recv) const { int32_t channel = recv.read_int(); int8_t mode1 = recv.read_byte(); int8_t mode2 = recv.read_byte(); if (mode1 == 0 && mode2 == 0) { change_map(recv, channel); } else { set_field(recv); } }
void SetfieldHandler::parsemonsterbook(InPacket& recv, Monsterbook& monsterbook) const { monsterbook.setcover(recv.read_int()); recv.skip(1); int16_t size = recv.read_short(); for (int16_t i = 0; i < size; i++) { int16_t cid = recv.read_short(); int8_t mblv = recv.read_byte(); monsterbook.addcard(cid, mblv); } }
void MoveCharHandler::handle(InPacket& recv) const { int32_t cid = recv.readint(); recv.skip(4); vector<Movement> movements; uint8_t nummoves = recv.readbyte(); for (uint8_t i = 0; i < nummoves; i++) { movements.push_back(parsemovement(recv)); } Stage::get().getchars().movechar(cid, movements); }
void SetfieldHandler::parsenewyear(InPacket& recv) const { int16_t nysize = recv.read_short(); for (int16_t i = 0; i < nysize; i++) { } }
void ServerlistHandler::handle(InPacket& recv) const { // Parse all worlds. std::vector<World> worlds; uint8_t worldcount = 0; while (recv.available()) { World world = LoginParser::parse_world(recv); if (world.wid != -1) { worlds.emplace_back(std::move(world)); worldcount++; } else { // "End of serverlist" packet. return; } } // Remove previous UIs. UI::get().remove(UIElement::LOGIN); UI::get().remove(UIElement::CHARSELECT); // Add the world selection screen to the ui. UI::get().emplace<UIWorldSelect>(worlds, worldcount); UI::get().enable(); }
void SessionManager::deliverPacket(InPacket &in) { ICQ_STR to, from; uint8 online; uint16 cmd; in >> to >> from >> online >> cmd; PACKET p; p.to = to.text; p.from = from.text; p.cmd = cmd; p.online = online; p.data = in.cursor; p.dataLen = in.getBytesLeft(); if (strchr(to.text, '@')) { s2s->deliver(&p); return; } Session *s = sessionHash.get(to.text); Client *client = NULL; if (s) client = s->client; else if (!online) { ICQ_LOG("%s is offline, bounce it\n", to.text); client = chooseClient(); } if (client) client->deliver(&p); }