Avoid orders given to tanks of wrong player.

master
Cyp 2012-03-31 20:34:15 +02:00
parent 359a035b39
commit 995d12479b
6 changed files with 57 additions and 0 deletions

View File

@ -217,6 +217,10 @@ bool recvDroidDisEmbark(NETQUEUE queue)
debug(LOG_WARNING, "player's %d transport droid %d wasn't found?", player, transporterID);
return false;
}
if (!canGiveOrdersFor(queue.index, psTransporterDroid->player))
{
return false;
}
// we need to find the droid *in* the transporter
psCheckDroid = psTransporterDroid ->psGroup->psList;
while (psCheckDroid)
@ -585,6 +589,12 @@ bool recvDroidInfo(NETQUEUE queue)
syncDebug("Droid %d missing", info.droidId);
continue; // Can't find the droid, so skip this droid.
}
if (!canGiveOrdersFor(queue.index, psDroid->player))
{
debug(LOG_WARNING, "Droid order for wrong player.");
syncDebug("Wrong player.");
continue;
}
CHECK_DROID(psDroid);

View File

@ -79,6 +79,13 @@ bool recvGift(NETQUEUE queue)
NETuint32_t(&droidID);
NETend();
if (!canGiveOrdersFor(queue.index, from))
{
debug(LOG_WARNING, "Gift from wrong player.");
syncDebug("Wrong player.");
return false;
}
// Handle the gift depending on what it is
switch (type)
{
@ -490,6 +497,11 @@ bool recvAlliance(NETQUEUE queue, bool allowAudio)
NETint32_t(&value);
NETend();
if (!canGiveOrdersFor(queue.index, from))
{
return false;
}
switch (state)
{
case ALLIANCE_NULL:

View File

@ -239,6 +239,10 @@ void recvPlayerLeft(NETQUEUE queue)
NETbeginDecode(queue, GAME_PLAYER_LEFT);
NETuint32_t(&playerIndex);
NETend();
if (queue.index == NET_HOST_ONLY || queue.index == playerIndex)
{
return;
}
turnOffMultiMsg(true);
clearPlayer(playerIndex, false); // don't do it quietly

View File

@ -500,6 +500,12 @@ bool responsibleFor(int player, int playerinquestion)
return whosResponsible(playerinquestion) == player;
}
bool canGiveOrdersFor(int player, int playerInQuestion)
{
return playerInQuestion >= 0 && playerInQuestion < MAX_PLAYERS &&
(player == playerInQuestion || responsibleFor(player, playerInQuestion) || getDebugMappingStatus());
}
int scavengerSlot()
{
// Scavengers used to always be in position 7, when scavengers were only supported in less than 8 player maps.
@ -935,6 +941,12 @@ bool recvResearchStatus(NETQUEUE queue)
debug(LOG_ERROR, "Bad GAME_RESEARCHSTATUS received, player is %d, index is %u", (int)player, index);
return false;
}
if (!canGiveOrdersFor(queue.index, player))
{
debug(LOG_WARNING, "Droid order for wrong player.");
syncDebug("Wrong player.");
return false;
}
int prevResearchState = 0;
if (aiCheckAlliances(selectedPlayer, player))
@ -1421,6 +1433,10 @@ bool recvTemplate(NETQUEUE queue)
NETtemplate(&t);
NETend();
if (!canGiveOrdersFor(queue.index, player))
{
return false;
}
t.prefab = false;
t.psNext = NULL;
@ -1474,6 +1490,10 @@ static bool recvDestroyTemplate(NETQUEUE queue)
NETuint8_t(&player);
NETuint32_t(&templateID);
NETend();
if (!canGiveOrdersFor(queue.index, player))
{
return false;
}
ASSERT_OR_RETURN(false, player < MAX_PLAYERS, "invalid player size: %d", player);

View File

@ -153,6 +153,7 @@ extern bool isHumanPlayer(int player); //to tell if the player is a computer
extern bool myResponsibility(int player);
extern bool responsibleFor(int player, int playerinquestion);
extern int whosResponsible(int player);
bool canGiveOrdersFor(int player, int playerInQuestion);
int scavengerSlot(); // Returns the player number that scavengers would have if they were enabled.
int scavengerPlayer(); // Returns the player number that the scavengers have, or -1 if disabled.
extern Vector3i cameraToHome (UDWORD player,bool scroll);

View File

@ -236,6 +236,11 @@ bool recvLasSat(NETQUEUE queue)
psStruct = IdToStruct (id, player);
psObj = IdToPointer(targetid, targetplayer);
if (psStruct && !canGiveOrdersFor(queue.index, psStruct->player))
{
syncDebug("Wrong player.");
return !"Meow"; // Return value meaningless and ignored.
}
if (psStruct && psObj && psStruct->pStructureType->psWeapStat[0]->weaponSubClass == WSC_LAS_SAT)
{
@ -321,6 +326,11 @@ void recvStructureInfo(NETQUEUE queue)
debug(LOG_SYNC, "Couldn't find structure %u to change production.", structId);
return;
}
if (!canGiveOrdersFor(queue.index, psStruct->player))
{
syncDebug("Wrong player.");
return;
}
CHECK_STRUCTURE(psStruct);