Ejemplo n.º 1
0
//=================================================================================================
bool QuestManager::Read(BitStream& stream)
{
	const int QUEST_MIN_SIZE = sizeof(int) + sizeof(byte) * 3;
	word quest_count;
	if(!stream.Read(quest_count)
		|| !EnsureSize(stream, QUEST_MIN_SIZE * quest_count))
	{
		Error("Read world: Broken packet for quests.");
		return false;
	}
	quests.resize(quest_count);

	int index = 0;
	for(Quest*& quest : quests)
	{
		quest = new PlaceholderQuest;
		quest->quest_index = index;
		if(!stream.Read(quest->refid) ||
			!stream.ReadCasted<byte>(quest->state) ||
			!ReadString1(stream, quest->name) ||
			!ReadStringArray<byte, word>(stream, quest->msgs))
		{
			Error("Read world: Broken packet for quest %d.", index);
			return false;
		}
		++index;
	}

	return true;
}
Ejemplo n.º 2
0
//=================================================================================================
void Explo::Load(HANDLE file)
{
	ReadFile(file, &pos, sizeof(pos), &tmp, nullptr);
	ReadFile(file, &size, sizeof(size), &tmp, nullptr);
	ReadFile(file, &sizemax, sizeof(sizemax), &tmp, nullptr);
	ReadFile(file, &dmg, sizeof(dmg), &tmp, nullptr);
	uint count;
	ReadFile(file, &count, sizeof(count), &tmp, nullptr);
	hitted.resize(count);
	int refid;
	for(uint i = 0; i < count; ++i)
	{
		ReadFile(file, &refid, sizeof(refid), &tmp, nullptr);
		hitted[i] = Unit::GetByRefid(refid);
	}
	ReadFile(file, &refid, sizeof(refid), &tmp, nullptr);
	owner = Unit::GetByRefid(refid);
	ReadString1(file);
	tex = ResourceManager::Get<Texture>().GetLoaded(BUF);
}
Ejemplo n.º 3
0
//=================================================================================================
void PickServerPanel::Update(float dt)
{
	// update gui
	for(int i=0; i<2; ++i)
	{
		bts[i].mouse_focus = focus;
		bts[i].Update(dt);
	}

	grid.focus = focus;
	grid.Update(dt);

	if(!focus)
		return;

	if(Key.Focus() && Key.PressedRelease(VK_ESCAPE))
	{
		Event((GuiEvent)(GuiEvent_Custom+BUTTON_CANCEL));
		return;
	}

	// ping servers
	ping_timer -= dt;
	if(ping_timer < 0.f)
	{
		ping_timer = 1.f;
		game->peer->Ping("255.255.255.255", (word)game->mp_port, true);
	}

	// listen for packets
	RakNet::Packet* packet;
	for(packet=game->peer->Receive(); packet; game->peer->DeallocatePacket(packet), packet=game->peer->Receive())
	{
		switch(packet->data[0])
		{
		case ID_UNCONNECTED_PONG:
			{
				BitStream s(packet->data+5, packet->length-5, false);
				char sign[2];
				if(!ReadStruct(s, sign))
				{
					WARN(Format("Unknown response from %s: %s.", packet->systemAddress.ToString(), PacketToString(packet)));
					break;
				}

				if(sign[0] != 'C' || sign[1] != 'A')
				{
					WARN(Format("Unknown response from %s, it's not CaRpg server: %s.", packet->systemAddress.ToString(), PacketToString(packet)));
					break;
				}

				uint wersja, build;
				byte gracze, gracze_max, flagi;
				string nazwa;

				if(	!s.Read(wersja) ||
					!s.Read(gracze) ||
					!s.Read(gracze_max) ||
					!s.Read(flagi) ||
					!ReadString1(s, nazwa))
				{
					WARN(Format("Broken response from %s: %s.", packet->systemAddress.ToString(), PacketToString(packet)));
					break;
				}

				if(!s.Read(build))
					build = 0;

				bool valid_version = (wersja == WERSJA && build == g_build);

				// szukaj serwera w bazie
				bool jest = false;
				int index = 0;
				for(vector<ServerData>::iterator it = servers.begin(), end = servers.end(); it != end; ++it, ++index)
				{
					if(it->adr == packet->systemAddress)
					{
						jest = true;
						// aktualizuj
						it->name = nazwa;
						it->players = gracze;
						it->max_players = gracze_max;
						it->flags = flagi;
						it->timer = 0.f;
						it->valid_version = valid_version;

						if(game->pick_autojoin && it->players != it->max_players && it->valid_version)
						{
							bts[0].state = Button::NONE;
							game->pick_autojoin = false;
							grid.selected = index;
							Event(GuiEvent(GuiEvent_Custom+BUTTON_OK));
						}

						break;
					}
				}

				if(!jest)
				{
					// nie ma, dodaj
					ServerData& sd = Add1(servers);
					sd.name = nazwa;
					sd.players = gracze;
					sd.max_players = gracze_max;
					sd.adr = packet->systemAddress;
					sd.flags = flagi;
					sd.timer = 0.f;
					sd.valid_version = valid_version;
					grid.AddItem();

					if(game->pick_autojoin && sd.players != sd.max_players && sd.valid_version)
					{
						bts[0].state = Button::NONE;
						game->pick_autojoin = false;
						grid.selected = servers.size()-1;
						Event(GuiEvent(GuiEvent_Custom+BUTTON_OK));
					}
				}
			}
			break;
		default:
			LOG(Format(txUnknownPacket, packet->data[0], packet->systemAddress.ToString(), PacketToString(packet)));
			break;
		}
	}

	// update servers
	int index = 0;
	for(vector<ServerData>::iterator it = servers.begin(), end = servers.end(); it != end;)
	{
		it->timer += dt;
		if(it->timer >= 2.f)
		{
			grid.RemoveItem(index);
			it = servers.erase(it);
			end = servers.end();
		}
		else
		{
			++it;
			++index;
		}
	}

	if(grid.selected == -1 || !servers[grid.selected].valid_version)
		bts[0].state = Button::DISABLED;
	else if(bts[0].state == Button::DISABLED)
		bts[0].state = Button::NONE;
}