Skip to content

Ch 10. Incorrect handPacket of MultiplayerGameState with Server::AcceptCoopPartner packet #22

@kyuhyunp

Description

@kyuhyunp

The client doesn't assign the received position from the server in handlePacket

case Server::AcceptCoopPartner:
		{
			sf::Int32 aircraftIdentifier;
			packet >> aircraftIdentifier;

			mWorld.addAircraft(aircraftIdentifier);
			mPlayers[aircraftIdentifier].reset(new Player(&mSocket, aircraftIdentifier, getContext().keys2));
			mLocalPlayerIdentifiers.push_back(aircraftIdentifier);
		} break;

The server sends the position of the aircraft to the client in handleIncomingPacket

case Client::RequestCoopPartner:
		{
			receivingPeer.aircraftIdentifiers.push_back(mAircraftIdentifierCounter);
			mAircraftInfo[mAircraftIdentifierCounter].position = sf::Vector2f(mBattleFieldRect.width / 2, mBattleFieldRect.top + mBattleFieldRect.height / 2);
			mAircraftInfo[mAircraftIdentifierCounter].hitpoints = 100;
			mAircraftInfo[mAircraftIdentifierCounter].missileAmmo = 2;

			sf::Packet requestPacket;
			requestPacket << static_cast<sf::Int32>(Server::AcceptCoopPartner);
			requestPacket << mAircraftIdentifierCounter;
			requestPacket << mAircraftInfo[mAircraftIdentifierCounter].position.x;
			requestPacket << mAircraftInfo[mAircraftIdentifierCounter].position.y;

			receivingPeer.socket.send(requestPacket);
			mAircraftCount++;

			// Inform every other peer about this new plane
			FOREACH(PeerPtr& peer, mPeers)
			{
				if (peer.get() != &receivingPeer && peer->ready)
				{
					sf::Packet notifyPacket;
					notifyPacket << static_cast<sf::Int32>(Server::PlayerConnect);
					notifyPacket << mAircraftIdentifierCounter;
					notifyPacket << mAircraftInfo[mAircraftIdentifierCounter].position.x;
					notifyPacket << mAircraftInfo[mAircraftIdentifierCounter].position.y;
					peer->socket.send(notifyPacket);
				}
			}
			mAircraftIdentifierCounter++;
		} break;

Although the World sets the position to the center of the map, the positions sent should be used.

Aircraft* World::addAircraft(int32_t identifier)
{ 
	std::unique_ptr <Aircraft> player(new Aircraft(Aircraft::Eagle, mFonts, mTextures));
	player->setPosition(mWorldView.getCenter());
	player->setIdentifier(identifier);

	mPlayerAircrafts.push_back(player.get());
	mSceneLayers[UpperAir]->attachChild(std::move(player));
	return mPlayerAircrafts.back();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions