pull in project-slippi/Ishiiruka/commit/11b0f4de469b3d9c1aa8424bc37b70ade4dc5718 and project-slippi/Ishiiruka/commit/df5e6190bc5162a5594cbc4b7b914c339c2feb14

This commit is contained in:
Nikhil Narayana 2022-05-30 01:06:56 -07:00
commit 8d4cd7d8e1
2 changed files with 108 additions and 26 deletions

View file

@ -388,19 +388,27 @@ unsigned int SlippiNetplayClient::OnData(sf::Packet& packet, ENetPeer* peer)
case NetPlay::NP_MSG_SLIPPI_MATCH_SELECTIONS: case NetPlay::NP_MSG_SLIPPI_MATCH_SELECTIONS:
{ {
auto s = readSelectionsFromPacket(packet); auto s = readSelectionsFromPacket(packet);
if (!s->error)
{
INFO_LOG_FMT(SLIPPI_ONLINE, "[Netplay] Received selections from opponent with player idx {}", INFO_LOG_FMT(SLIPPI_ONLINE, "[Netplay] Received selections from opponent with player idx {}",
s->playerIdx); s->playerIdx);
u8 idx = PlayerIdxFromPort(s->playerIdx); u8 idx = PlayerIdxFromPort(s->playerIdx);
if (idx >= m_remotePlayerCount)
{
ERROR_LOG_FMT(SLIPPI_ONLINE, "Got match selection packet with invalid player idx {}", idx);
break;
}
matchInfo.remotePlayerSelections[idx].Merge(*s); matchInfo.remotePlayerSelections[idx].Merge(*s);
// This might be a good place to reset some logic? Game can't start until we receive this msg // This might be a good place to reset some logic? Game can't start until we receive this msg
// so this should ensure that everything is initialized before the game starts // so this should ensure that everything is initialized before the game starts
hasGameStarted = false; hasGameStarted = false;
// Reset remote pad queue such that next inputs that we get are not compared to inputs from last // Reset remote pad queue such that next inputs that we get are not compared to inputs from
// game // last game
remotePadQueue[idx].clear(); remotePadQueue[idx].clear();
} }
}
break; break;
case NetPlay::NP_MSG_SLIPPI_CHAT_MESSAGE: case NetPlay::NP_MSG_SLIPPI_CHAT_MESSAGE:
@ -418,9 +426,12 @@ unsigned int SlippiNetplayClient::OnData(sf::Packet& packet, ENetPeer* peer)
remoteSentChatMessageId = 0; remoteSentChatMessageId = 0;
break; break;
} }
if (!playerSelection->error)
{
// set message id to netplay instance // set message id to netplay instance
remoteChatMessageSelection = std::move(playerSelection); remoteChatMessageSelection = std::move(playerSelection);
} }
}
break; break;
case NetPlay::NP_MSG_SLIPPI_CONN_SELECTED: case NetPlay::NP_MSG_SLIPPI_CONN_SELECTED:
@ -461,8 +472,49 @@ SlippiNetplayClient::ReadChatMessageFromPacket(sf::Packet& packet)
{ {
auto s = std::make_unique<SlippiPlayerSelections>(); auto s = std::make_unique<SlippiPlayerSelections>();
packet >> s->messageId; if (!(packet >> s->messageId))
packet >> s->playerIdx; {
ERROR_LOG(SLIPPI_ONLINE, "Chat packet too small to read message ID");
s->error = true;
return std::move(s);
}
if (!(packet >> s->playerIdx))
{
ERROR_LOG(SLIPPI_ONLINE, "Chat packet too small to read player index");
s->error = true;
return std::move(s);
}
switch (s->messageId)
{
// Only these 16 message IDs are allowed
case 136:
case 129:
case 130:
case 132:
case 34:
case 40:
case 33:
case 36:
case 72:
case 66:
case 68:
case 65:
case 24:
case 18:
case 20:
case 17:
{
// Good message ID. Do nothing
break;
}
default:
{
ERROR_LOG_FMT(SLIPPI_ONLINE, "Received invalid chat message index: {}", s->messageId);
s->error = true;
break;
}
}
return std::move(s); return std::move(s);
} }
@ -472,17 +524,46 @@ SlippiNetplayClient::readSelectionsFromPacket(sf::Packet& packet)
{ {
auto s = std::make_unique<SlippiPlayerSelections>(); auto s = std::make_unique<SlippiPlayerSelections>();
packet >> s->characterId; if (!(packet >> s->characterId))
packet >> s->characterColor; {
packet >> s->isCharacterSelected; ERROR_LOG(SLIPPI_ONLINE, "Received invalid player selection");
s->error = true;
packet >> s->playerIdx; }
if (!(packet >> s->characterColor))
packet >> s->stageId; {
packet >> s->isStageSelected; ERROR_LOG(SLIPPI_ONLINE, "Received invalid player selection");
packet >> s->rngOffset; s->error = true;
}
packet >> s->teamId; if (!(packet >> s->isCharacterSelected))
{
ERROR_LOG(SLIPPI_ONLINE, "Received invalid player selection");
s->error = true;
}
if (!(packet >> s->playerIdx))
{
ERROR_LOG(SLIPPI_ONLINE, "Received invalid player selection");
s->error = true;
}
if (!(packet >> s->stageId))
{
ERROR_LOG(SLIPPI_ONLINE, "Received invalid player selection");
s->error = true;
}
if (!(packet >> s->isStageSelected))
{
ERROR_LOG(SLIPPI_ONLINE, "Received invalid player selection");
s->error = true;
}
if (!(packet >> s->rngOffset))
{
ERROR_LOG(SLIPPI_ONLINE, "Received invalid player selection");
s->error = true;
}
if (!(packet >> s->teamId))
{
ERROR_LOG(SLIPPI_ONLINE, "Received invalid player selection");
s->error = true;
}
return std::move(s); return std::move(s);
} }

View file

@ -54,7 +54,8 @@ public:
u32 rngOffset{}; u32 rngOffset{};
int messageId{}; int messageId = 0;
bool error = false;
void Merge(SlippiPlayerSelections& s) void Merge(SlippiPlayerSelections& s)
{ {