void SpawnMobHandler::handle(InPacket& recv) const
	{
		int32_t oid = recv.readint();
		bool hascontrol = recv.readbyte() == 5;
		int32_t id = recv.readint();

		recv.skip(22);

		Point<int16_t> position = recv.readpoint();
		int8_t stance = recv.readbyte();

		recv.skip(2);

		uint16_t fh = recv.readshort();
		int8_t effect = recv.readbyte();

		if (effect > 0)
		{
			recv.readbyte();
			recv.readshort();
			if (effect == 15)
			{
				recv.readbyte();
			}
		}

		int8_t team = recv.readbyte();

		recv.skip(4);

		Stage::get().getmobs().addmob(oid, id, hascontrol, stance, fh, effect == -2, team, position);
	}
	void DropItemHandler::handle(InPacket& recv) const
	{
		int8_t mode = recv.readbyte();
		int32_t oid = recv.readint();
		bool meso = recv.readbool();
		int32_t itemid = recv.readint();
		int32_t owner = recv.readint();
		int8_t pickuptype = recv.readbyte();
		Point<int16_t> dropto = recv.readpoint();

		recv.skip(4);

		Point<int16_t> dropfrom;
		if (mode != 2)
		{
			dropfrom = recv.readpoint();

			recv.skip(2);
		}
		else
		{
			dropfrom = dropto;
		}

		if (!meso)
		{
			recv.skip(8);
		}
		bool playerdrop = !recv.readbool();

		Stage::get().getdrops().adddrop(oid, itemid, meso, owner, dropfrom, dropto, pickuptype, mode, playerdrop);
	}
	void SpawnPetHandler::handle(InPacket& recv) const
	{
		using Character::Char;
		Optional<Char> character = Stage::get().getcharacter(recv.readint());
		if (!character)
			return;

		uint8_t petindex = recv.readbyte();
		int8_t mode = recv.readbyte();

		if (mode == 1)
		{
			recv.skip(1);

			int32_t itemid = recv.readint();
			string name = recv.readascii();
			int32_t uniqueid = recv.readint();

			recv.skip(4);

			Point<int16_t> pos = recv.readpoint();
			uint8_t stance = recv.readbyte();
			int32_t fhid = recv.readint();

			character->addpet(petindex, itemid, name, uniqueid, pos, stance, fhid);
		}
		else if (mode == 0)
		{
			bool hunger = recv.readbool();

			character->removepet(petindex, hunger);
		}
	}
Esempio n. 4
0
	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);
	}
Esempio n. 5
0
	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);
	}
Esempio n. 6
0
	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 SpawnNpcHandler::handle(InPacket& recv) const
	{
		int32_t oid = recv.readint();
		int32_t id = recv.readint();
		Point<int16_t> position = recv.readpoint();
		bool flip = recv.readbool();
		uint16_t fh = recv.readshort();

		recv.readshort(); // 'rx'
		recv.readshort(); // 'ry'

		Stage::get().getnpcs().addnpc(id, oid, flip, fh, true, position);
	}
	void KillMobHandler::handle(InPacket& recv) const
	{
		int32_t oid = recv.readint();
		int8_t animation = recv.readbyte();

		Stage::get().getmobs().killmob(oid, animation);
	}
Esempio n. 9
0
	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);
		}
	}
Esempio n. 10
0
	void ServerIPHandler::handle(InPacket& recv) const
	{
		recv.skip(2);

		// Read the ipv4 adress in a string.
		string addrstr;
		for (int i = 0; i < 4; i++)
		{
			uint8_t num = static_cast<uint8_t>(recv.readbyte());
			addrstr.append(std::to_string(num));
			if (i < 3)
			{
				addrstr.push_back('.');
			}
		}

		// Read the port adress in a string.
		string portstr = std::to_string(recv.readshort());

		int32_t cid = recv.readint();

		// 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 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);
	}
Esempio n. 12
0
	Account::Account(InPacket& recv)
	{
		recv.readshort();
		accid = recv.readint();
		female = recv.readbool();
		recv.readbool(); //is admin
		gmlevel = recv.readbyte();
		recv.readbyte();
		name = recv.readascii();
		recv.readbyte();
		muted = recv.readbool();
		recv.readlong(); //muted until
		recv.readlong(); //creation date
		recv.readint();
		pin = recv.readshort();
		selected = 0;
	}
Esempio n. 13
0
	void Login::parseaccount(InPacket& recv)
	{
		recv.readshort();
		account.accid = recv.readint();
		account.female = recv.readbool();
		recv.readbool(); //is admin
		account.gmlevel = recv.readbyte();
		recv.readbyte();
		account.name = recv.readascii();
		recv.readbyte();
		account.muted = recv.readbool();
		recv.readlong(); //muted until
		recv.readlong(); //creation date
		recv.readint();
		account.pin = recv.readshort();
		account.selected = 0;
	}
Esempio n. 14
0
	void AttackHandler::handle(InPacket& recv) const
	{
		int32_t cid = recv.readint();
		uint8_t count = recv.readbyte();

		recv.skip(1);

		using Gameplay::AttackResult;
		AttackResult attack;
		attack.type = type;

		attack.level = recv.readbyte();
		attack.skill = (attack.level > 0) ? recv.readint() : 0;

		attack.display = recv.readbyte();
		attack.toleft = recv.readbool();
		attack.stance = recv.readbyte();
		attack.speed = recv.readbyte();

		recv.skip(1);

		attack.bullet = recv.readint();

		attack.mobcount = (count >> 4) & 0xF;
		attack.hitcount = count & 0xF;
		for (uint8_t i = 0; i < attack.mobcount; i++)
		{
			int32_t oid = recv.readint();

			recv.skip(1);

			using Gameplay::Skill;
			uint8_t length = (attack.skill == Skill::MESO_EXPLOSION) ? recv.readbyte() : attack.hitcount;
			for (uint8_t j = 0; j < length; j++)
			{
				int32_t damage = recv.readint();
				bool critical = false; // todo
				auto singledamage = std::make_pair(damage, critical);
				attack.damagelines[oid].push_back(singledamage);
			}
		}

		using Gameplay::Stage;
		Stage::get().showattack(cid, attack);
	}
Esempio n. 15
0
	void ChangeStatsHandler::handle(InPacket& recv) const
	{
		recv.readbool(); // 'itemreaction'

		int32_t updatemask = recv.readint();

		Player& player = Stage::get().getplayer();

		for (auto it = Maplestat::it(); it.hasnext(); it.increment())
		{
			Maplestat::Value stat = it.get();
			if (Maplestat::compare(stat, updatemask))
			{
				switch (stat)
				{
				case Maplestat::SKIN:
					player.changelook(stat, recv.readshort());
					break;
				case Maplestat::FACE:
				case Maplestat::HAIR:
					player.changelook(stat, recv.readint());
					break;
				case Maplestat::LEVEL:
					player.changelevel(recv.readbyte());
					break;
				case Maplestat::JOB:
					player.changejob(recv.readshort());
					break;
				case Maplestat::EXP:
					player.getstats().setexp(recv.readint());
					break;
				case Maplestat::MESO:
					player.getinvent().setmeso(recv.readint());
					break;
				default:
					player.getstats().setstat(stat, recv.readshort());
					player.recalcstats(false);
					break;
				}
			}

			UI::get().enable();
		}
	}
Esempio n. 16
0
	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());
	}
Esempio n. 17
0
	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);
		}
	}
Esempio n. 18
0
	LookEntry Login::parselook(InPacket& recv) const
	{
		LookEntry look;

		look.female = recv.readbool();
		look.skin = recv.readbyte();
		look.faceid = recv.readint();
		recv.readbool(); //megaphone
		look.hairid = recv.readint();
		uint8_t slot = recv.readbyte();
		while (slot != 0xFF)
		{
			look.equips[slot] = recv.readint();
			slot = recv.readbyte();
		}
		slot = recv.readbyte();
		while (slot != 0xFF)
		{
			look.maskedequips[slot] = recv.readint();
			slot = recv.readbyte();
		}
		look.maskedequips[-111] = recv.readint();
		for (uint8_t i = 0; i < 3; i++)
		{
			look.petids.push_back(recv.readint());
		}

		return look;
	}
Esempio n. 19
0
	StatsEntry Login::parsestats(InPacket& recv) const
	{
		StatsEntry statsentry;

		statsentry.name = recv.readpadascii(13);

		recv.readbool(); //gender
		recv.readbyte(); //skin
		recv.readint(); //face
		recv.readint(); //hair

		for (size_t i = 0; i < 3; i++)
		{
			statsentry.petids.push_back(recv.readlong());
		}

		statsentry.stats[Maplestat::LEVEL] = recv.readbyte();
		statsentry.stats[Maplestat::JOB] = recv.readshort();
		statsentry.stats[Maplestat::STR] = recv.readshort();
		statsentry.stats[Maplestat::DEX] = recv.readshort();
		statsentry.stats[Maplestat::INT] = recv.readshort();
		statsentry.stats[Maplestat::LUK] = recv.readshort();
		statsentry.stats[Maplestat::HP] = recv.readshort();
		statsentry.stats[Maplestat::MAXHP] = recv.readshort();
		statsentry.stats[Maplestat::MP] = recv.readshort();
		statsentry.stats[Maplestat::MAXMP] = recv.readshort();
		statsentry.stats[Maplestat::AP] = recv.readshort();
		statsentry.stats[Maplestat::SP] = recv.readshort();
		statsentry.exp = recv.readint();
		statsentry.stats[Maplestat::FAME] = recv.readshort();

		recv.skip(4); //gachaexp
		statsentry.mapid = recv.readint();
		statsentry.portal = recv.readbyte();
		recv.skip(4); //timestamp

		statsentry.job = CharJob(statsentry.stats[Maplestat::JOB]);

		return statsentry;
	}
Esempio n. 20
0
	void LoginResultHandler::handle(InPacket& recv) const
	{
		// Remove login information.
		UI::get().remove(UIElement::LOGINNOTICE);
		UI::get().remove(UIElement::LOGINWAIT);

		// The packet should contain a 'reason' integer which can signify various things.
		int32_t reason = recv.readint();
		if (reason != 0)
		{
			// Login unsuccessfull. The LoginNotice displayed will contain the specific information.
			switch (reason)
			{
			case 2:
				UI::get().add(ElementLoginNotice(16));
				break;
			case 7:
				UI::get().add(ElementLoginNotice(17));
				break;
			case 23:
				// The server sends a request to accept the terms of service. For convenience, just auto-accept.
				TOSPacket().dispatch();
				break;
			default:
				// Other reasons.
				if (reason > 0)
				{
					auto reasonbyte = static_cast<int8_t>(reason - 1);
					UI::get().add(ElementLoginNotice(reasonbyte));
				}
			}

			UI::get().enable();
		}
		else
		{
			// Login successfull. The packet contains information on the account, so we initialise the account with it.
			Session::get().getlogin().parseaccount(recv);

			// Save the Login ID if the box for it on the login panel is checked.
			bool savelogin = Setting<SaveLogin>::get().load();
			if (savelogin)
			{
				string name = Session::get().getlogin().getaccount().name;
				Setting<DefaultAccount>::get().save(name);
			}

			// Request the list of worlds and channels online.
			ServerRequestPacket().dispatch();
		}
	}
	void SpawnMobControllerHandler::handle(InPacket& recv) const
	{
		int8_t aggro = recv.readbyte();
		if (aggro == 0)
			return;

		int32_t oid = recv.readint();

		recv.skip(1);

		int32_t id = recv.readint();

		recv.skip(22);

		Point<int16_t> position = recv.readpoint();
		int8_t stance = recv.readbyte();

		recv.skip(2);

		uint16_t fh = recv.readshort();
		int8_t effect = recv.readbyte();

		if (effect > 0)
		{
			recv.readbyte();
			recv.readshort();
			if (effect == 15)
			{
				recv.readbyte();
			}
		}

		int8_t team = recv.readbyte();

		recv.skip(4);

		Stage::get().getmobs().addmob(oid, id, true, stance, fh, effect == -2, team, position);
	}
Esempio n. 22
0
	CharEntry Login::parsecharentry(InPacket& recv) const
	{
		CharEntry toparse;
		toparse.cid = recv.readint();
		toparse.stats = parsestats(recv);
		toparse.look = parselook(recv);

		recv.readbool(); // 'rankinfo' bool
		if (recv.readbool())
		{
			int32_t currank = recv.readint();
			int32_t rankmv = recv.readint();
			int32_t curjobrank = recv.readint();
			int32_t jobrankmv = recv.readint();
			int8_t rankmc = (rankmv > 0) ? '+' : (rankmv < 0) ? '-' : '=';
			int8_t jobrankmc = (jobrankmv > 0) ? '+' : (jobrankmv < 0) ? '-' : '=';

			toparse.stats.rank = std::make_pair(currank, rankmc);
			toparse.stats.jobrank = std::make_pair(curjobrank, jobrankmc);
		}

		return toparse;
	}
	void SpawnNpcControllerHandler::handle(InPacket& recv) const
	{
		int8_t mode = recv.readbyte();
		int32_t oid = recv.readint();

		if (mode == 0)
		{

		}
		else
		{
			int32_t id = recv.readint();
			Point<int16_t> position = recv.readpoint();
			bool f = recv.readbool();
			uint16_t fh = recv.readshort();

			recv.readshort(); // 'rx'
			recv.readshort(); // 'ry'
			recv.readbool(); // 'minimap'

			Stage::get().getnpcs().addnpc(id, oid, f, fh, true, position);
		}
	}
	void RemoveDropHandler::handle(InPacket& recv) const
	{
		int8_t mode = recv.readbyte();
		int32_t oid = recv.readint();

		using Gameplay::PhysicsObject;
		Optional<PhysicsObject> looter;
		if (mode > 1)
		{
			int32_t cid = recv.readint();
			if (recv.length() > 0)
			{
				recv.readbyte(); // pet
			}
			else
			{
				looter = Stage::get().getcharacter(cid)
					.transform(&Char::getphobj);
			}

			AudioPlayer::get().playsound(AudioPlayer::PICKUP);
		}
		Stage::get().getdrops().removedrop(oid, mode, looter.get());
	}
	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);
	}
Esempio n. 26
0
	void DeleteCharResponseHandler::handle(InPacket& recv) const
	{
		// Read the character id and if deletion was successfull (pic was correct).
		recv.readint(); // charid

		bool success = recv.readbool();

		// Show the result to the user.
		if (success)
		{
			UI::get().add(ElementLoginNotice(UILoginNotice::CASH_ITEMS_CONFIRM_DELETION));
		}
		else
		{
			UI::get().add(ElementLoginNotice(UILoginNotice::BIRTHDAY_INCORRECT));
		}
	}
Esempio n. 27
0
	World::World(uint8_t id, InPacket& recv)
	{
		wid = id;
		name = recv.readascii();
		flag = recv.readbyte();
		message = recv.readascii();
		recv.readbyte();
		recv.readbyte();
		recv.readbyte();
		recv.readbyte();
		recv.readbyte();
		channelcount = recv.readbyte();
		for (uint8_t i = 0; i < channelcount; i++)
		{
			recv.readascii();
			recv.readint();
			chloads.push_back(recv.readbyte());
			recv.readshort();
		}
	}
	void RemoveCharHandler::handle(InPacket& recv) const
	{
		int32_t cid = recv.readint();

		Stage::get().getchars().removechar(cid);
	}
	void SpawnCharHandler::handle(InPacket& recv) const
	{
		int32_t cid = recv.readint();
		uint8_t level = recv.readbyte();
		string name = recv.readascii();

		recv.readascii(); // guildname
		recv.readshort(); // guildlogobg
		recv.readbyte(); // guildlogobgcolor
		recv.readshort(); // guildlogo
		recv.readbyte(); // guildlogocolor

		recv.skip(8);

		bool morphed = recv.readint() == 2;
		int32_t buffmask1 = recv.readint();
		int16_t buffvalue = 0;
		if (buffmask1 != 0)
		{
			buffvalue = morphed ? recv.readshort() : recv.readbyte();
		}
		recv.readint(); // buffmask 2

		recv.skip(43);

		recv.readint(); // 'mount'

		recv.skip(61);

		int16_t job = recv.readshort();
		LookEntry look = Session::get().getlogin().parselook(recv);

		recv.readint(); //count of 5110000 
		recv.readint(); // 'itemeffect'
		recv.readint(); // 'chair'

		Point<int16_t> position = recv.readpoint();
		int8_t stance = recv.readbyte();

		recv.skip(3);

		for (size_t i = 0; i < 3; i++)
		{
			int8_t available = recv.readbyte();
			if (available == 1)
			{
				recv.readbyte(); // 'byte2'
				recv.readint(); // petid
				recv.readascii(); // name
				recv.readint(); // unique id
				recv.readint();
				recv.readpoint(); // pos
				recv.readbyte(); // stance
				recv.readint(); // fhid
			}
			else
			{
				break;
			}
		}

		recv.readint(); // mountlevel
		recv.readint(); // mountexp
		recv.readint(); // mounttiredness

		//shop stuff, TO DO
		recv.readbyte();
		//shop stuff end

		bool chalkboard = recv.readbool();
		string chalktext = chalkboard ? recv.readascii() : "";

		recv.skip(3);
		recv.readbyte(); // team

		Stage::get().getchars().addchar(cid, look, level, job, name, stance, position);
	}