mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-09-30 05:08:46 +00:00
pull in project-slippi/Ishiiruka/commit/11b0f4de469b3d9c1aa8424bc37b70ade4dc5718 and project-slippi/Ishiiruka/commit/df5e6190bc5162a5594cbc4b7b914c339c2feb14
This commit is contained in:
parent
5c19df9d3d
commit
8d4cd7d8e1
2 changed files with 108 additions and 26 deletions
|
@ -388,18 +388,26 @@ 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);
|
||||||
INFO_LOG_FMT(SLIPPI_ONLINE, "[Netplay] Received selections from opponent with player idx {}",
|
if (!s->error)
|
||||||
s->playerIdx);
|
{
|
||||||
u8 idx = PlayerIdxFromPort(s->playerIdx);
|
INFO_LOG_FMT(SLIPPI_ONLINE, "[Netplay] Received selections from opponent with player idx {}",
|
||||||
matchInfo.remotePlayerSelections[idx].Merge(*s);
|
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);
|
||||||
|
|
||||||
// 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;
|
||||||
|
|
||||||
|
@ -418,8 +426,11 @@ unsigned int SlippiNetplayClient::OnData(sf::Packet& packet, ENetPeer* peer)
|
||||||
remoteSentChatMessageId = 0;
|
remoteSentChatMessageId = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// set message id to netplay instance
|
if (!playerSelection->error)
|
||||||
remoteChatMessageSelection = std::move(playerSelection);
|
{
|
||||||
|
// set message id to netplay instance
|
||||||
|
remoteChatMessageSelection = std::move(playerSelection);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue