-
Notifications
You must be signed in to change notification settings - Fork 235
Description
There are two problems with handling the PlayerRealtimeChange packet.
- The server sends the packet to all clients without excluding the
receivingPeerwho 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.
mSocketwhich is redundant for remote multiplayers is passed toPlayerinPlayerConnectinMultiplayerGameState
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.