Fixed and simplified sendMessageToPeersChangingToken, avoiding
incorrect messages if more than one peer is connected.
This commit is contained in:
@@ -114,15 +114,23 @@ void Protocol::requestTerminate()
|
||||
} // requestTerminate
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void Protocol::sendMessageToPeersChangingToken(NetworkString prefix,
|
||||
NetworkString message)
|
||||
/** Sends a message to all peers, inserting the peer's token into the message.
|
||||
* The message is composed of a 1-byte message (usually the message type)
|
||||
* followed by the token of this client and then actual message).
|
||||
* \param type The first byte of the combined message.
|
||||
* \param message The actual message content.
|
||||
*/
|
||||
void Protocol::sendMessageToPeersChangingToken(uint8_t type,
|
||||
const NetworkString &message)
|
||||
{
|
||||
const std::vector<STKPeer*> &peers = STKHost::get()->getPeers();
|
||||
for (unsigned int i = 0; i < peers.size(); i++)
|
||||
{
|
||||
prefix.ai8(4).ai32(peers[i]->getClientServerToken());
|
||||
prefix += message;
|
||||
ProtocolManager::getInstance()->sendMessage(this, peers[i], prefix);
|
||||
NetworkString combined(1+4+message.size());
|
||||
combined.addUInt8(type).addUInt8(4)
|
||||
.addUInt32(peers[i]->getClientServerToken());
|
||||
combined+=message;
|
||||
ProtocolManager::getInstance()->sendMessage(this, peers[i], combined);
|
||||
}
|
||||
} // sendMessageToPeersChangingToken
|
||||
|
||||
|
||||
@@ -122,8 +122,8 @@ public:
|
||||
/// functions to check incoming data easily
|
||||
bool checkDataSizeAndToken(Event* event, int minimum_size);
|
||||
bool isByteCorrect(Event* event, int byte_nb, int value);
|
||||
void sendMessageToPeersChangingToken(NetworkString prefix,
|
||||
NetworkString message);
|
||||
void sendMessageToPeersChangingToken(uint8_t type,
|
||||
const NetworkString &message);
|
||||
void sendMessage(const NetworkString& message,
|
||||
bool reliable = true);
|
||||
void sendMessage(STKPeer* peer, const NetworkString& message,
|
||||
|
||||
@@ -595,9 +595,7 @@ void ServerLobbyRoomProtocol::playerMajorVote(Event* event)
|
||||
NetworkString other(5+data.size());
|
||||
other.ai8(1).ai8(player_id); // add the player id
|
||||
other += data; // add the data
|
||||
NetworkString prefix(1);
|
||||
prefix.ai8(LE_VOTE_MAJOR); // prefix the token with the type
|
||||
sendMessageToPeersChangingToken(prefix, other);
|
||||
sendMessageToPeersChangingToken(LE_VOTE_MAJOR, other);
|
||||
} // playerMajorVote
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -627,9 +625,7 @@ void ServerLobbyRoomProtocol::playerRaceCountVote(Event* event)
|
||||
NetworkString other(2+data.size());
|
||||
other.ai8(1).ai8(player_id); // add the player id
|
||||
other += data; // add the data
|
||||
NetworkString prefix(1);
|
||||
prefix.ai8(LE_VOTE_RACE_COUNT); // prefix the token with the type
|
||||
sendMessageToPeersChangingToken(prefix, other);
|
||||
sendMessageToPeersChangingToken(LE_VOTE_RACE_COUNT, other);
|
||||
} // playerRaceCountVote
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -660,9 +656,7 @@ void ServerLobbyRoomProtocol::playerMinorVote(Event* event)
|
||||
NetworkString other(2+data.size());
|
||||
other.ai8(1).ai8(player_id); // add the player id
|
||||
other += data; // add the data
|
||||
NetworkString prefix(1);
|
||||
prefix.ai8(LE_VOTE_MINOR); // prefix the token with the ype
|
||||
sendMessageToPeersChangingToken(prefix, other);
|
||||
sendMessageToPeersChangingToken(LE_VOTE_MINOR, other);
|
||||
} // playerMinorVote
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -694,9 +688,7 @@ void ServerLobbyRoomProtocol::playerTrackVote(Event* event)
|
||||
NetworkString other(2+data.size());
|
||||
other.ai8(1).ai8(player_id); // add the player id
|
||||
other += data; // add the data
|
||||
NetworkString prefix(1);
|
||||
prefix.ai8(LE_VOTE_TRACK); // prefix the token with the ype
|
||||
sendMessageToPeersChangingToken(prefix, other);
|
||||
sendMessageToPeersChangingToken(LE_VOTE_TRACK, other);
|
||||
if(m_setup->getRaceConfig()->getNumTrackVotes()==m_setup->getPlayerCount())
|
||||
startGame();
|
||||
} // playerTrackVote
|
||||
@@ -731,9 +723,7 @@ void ServerLobbyRoomProtocol::playerReversedVote(Event* event)
|
||||
NetworkString other(2+data.size());
|
||||
other.ai8(1).ai8(player_id); // add the player id
|
||||
other += data; // add the data
|
||||
NetworkString prefix(1);
|
||||
prefix.ai8(LE_VOTE_REVERSE); // prefix the token with the ype
|
||||
sendMessageToPeersChangingToken(prefix, other);
|
||||
sendMessageToPeersChangingToken(LE_VOTE_REVERSE, other);
|
||||
} // playerReversedVote
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -765,9 +755,7 @@ void ServerLobbyRoomProtocol::playerLapsVote(Event* event)
|
||||
NetworkString other(2+data.size());
|
||||
other.ai8(1).ai8(player_id); // add the player id
|
||||
other += data; // add the data
|
||||
NetworkString prefix(1);
|
||||
prefix.ai8(LE_VOTE_LAPS); // prefix the token with the ype
|
||||
sendMessageToPeersChangingToken(prefix, other);
|
||||
sendMessageToPeersChangingToken(LE_VOTE_LAPS, other);
|
||||
} // playerLapsVote
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user