There are two problems with handling the PlayerRealtimeChange packet.
- The server sends the packet to all clients without excluding the
receivingPeer who already knows about the change.
After changing void notifyPlayerSpawn(int32_t aircraftIdentifier), void notifyPlayerRealtimeChange(int32_t aircraftIdentifier, int32_t action, bool actionEnabled), and void nofifyPlayerEvent(int32_t aircraftIdentifier, int32_t action) to private, add RemotePeer& changer to notifyPlayerRealtimeChange.
Send the packet to every client except the changer.
sf::Packet packet;
packet << static_cast<int32_t> (Server::PlayerRealtimeChange)
<< aircraftIdentifier << action << actionEnabled;
for (auto& peer : mPeers)
{
if (peer->ready && peer.get() != &changer)
{
peer->socket.send(packet);
}
}
Without this,
Player::handleNetworkRealtimeChange(Action action, bool actionEnabled)
{
mActionProxies[action] = actionEnabled;
}
would record the network changes to mActionProxies for the sender.
mSocket which is redundant for remote multiplayers is passed to Player in PlayerConnect in MultiplayerGameState
We pass the address of mSocket to remote players. However, this is redundant as the remote player cannot send the packet using mSocket as it belongs to a local aircraft. We should remove this to reduce unnecessary complexity in the code.
We don't even need mSocket for remote players.
For the three cases,
Case 1: Single-Player
Case 2: Multiplayer Local
Case 3: Multiplayer Remote
Case 3 is the only remote case, but !isLocal() already differentiates Case 3 from Cases 1 and 2. Cases 1 and 2 simply adds the command to the CommandQueue.
Therefore, handleRealtimeInput can use if (isLocal()) and handleRealtimeNetworkInput can use if (!isLocal()) instead of the complex expression with mSocket.
There are two problems with handling the
PlayerRealtimeChangepacket.receivingPeerwho already knows about the change.After changing void
notifyPlayerSpawn(int32_t aircraftIdentifier),void notifyPlayerRealtimeChange(int32_t aircraftIdentifier, int32_t action, bool actionEnabled), andvoid nofifyPlayerEvent(int32_t aircraftIdentifier, int32_t action)to private, addRemotePeer& changertonotifyPlayerRealtimeChange.Send the packet to every client except the changer.
Without this,
would record the network changes to
mActionProxiesfor the sender.mSocketwhich is redundant for remote multiplayers is passed toPlayerinPlayerConnectinMultiplayerGameStateWe pass the address of
mSocketto remote players. However, this is redundant as the remote player cannot send the packet usingmSocketas it belongs to a local aircraft. We should remove this to reduce unnecessary complexity in the code.We don't even need mSocket for remote players.
For the three cases,
Case 1: Single-Player
Case 2: Multiplayer Local
Case 3: Multiplayer Remote
Case 3 is the only remote case, but
!isLocal()already differentiates Case 3 from Cases 1 and 2. Cases 1 and 2 simply adds the command to theCommandQueue.Therefore,
handleRealtimeInputcan useif (isLocal())andhandleRealtimeNetworkInputcan useif (!isLocal())instead of the complex expression withmSocket.