Skip to content

Commit

Permalink
refactor: migrate SlippiUser to be backed by a Rust layer (#403)
Browse files Browse the repository at this point in the history
* Modify SlippiUser to be a shim to the Rust user.

- Forwards calls in and out of the Rust User Manager held by the EXI
  device.
- Handles converting UserInfo into C++ types so that any existing logic
  relying on assumptions about the type doesn't need to be flagged just
  yet.

- Chat message importing for the current user, as well as the default
  chat list, now live over on the Rust side.
- Slight edits to Matchmaking to handle how chat messages are loaded,
  solely to avoid extra string allocations. Tested and no issues found,
  but someone with more context should test again.

* Remove the old webview login that macOS still had, and remove wxWidgets WebView functionality and linking on macOS

* Update to reflect condensed Rust log infrastructure

* linux now requires kebab case in target_link_libraries

---------

Co-authored-by: Nikhil Narayana <nikhil.narayana@live.com>
  • Loading branch information
ryanmcgrath and NikhilNarayana authored Sep 19, 2023
1 parent c8dd23c commit c83f775
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 571 deletions.
8 changes: 1 addition & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -934,13 +934,7 @@ endif()

if(NOT DISABLE_WX)
include(FindwxWidgets OPTIONAL)

# This is increasingly not touched, but the clarity is probably beneficial to keep around.
if(APPLE)
FIND_PACKAGE(wxWidgets COMPONENTS core aui adv webview)
else()
FIND_PACKAGE(wxWidgets COMPONENTS core aui adv)
endif()
FIND_PACKAGE(wxWidgets COMPONENTS core aui adv)

if(_ARCH_32)
add_definitions(-DwxSIZE_T_IS_UINT)
Expand Down
4 changes: 2 additions & 2 deletions Externals/wxWidgets3/wx/wxcocoa.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@

#define wxUSE_STC 0

#define wxUSE_WEBVIEW 1
#define wxUSE_WEBVIEW 0

#ifdef __WXMSW__
#define wxUSE_WEBVIEW_IE 0
Expand All @@ -349,7 +349,7 @@
#endif

#if defined(__WXGTK__) || defined(__WXOSX__)
#define wxUSE_WEBVIEW_WEBKIT 1
#define wxUSE_WEBVIEW_WEBKIT 0
#else
#define wxUSE_WEBVIEW_WEBKIT 0
#endif
Expand Down
3 changes: 1 addition & 2 deletions Source/Core/Common/Logging/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ enum LOG_TYPE
SLIPPI,
SLIPPI_ONLINE,
SLIPPI_RUST_DEPENDENCIES,
SLIPPI_RUST_EXI,
SLIPPI_RUST_GAME_REPORTER,
SLIPPI_RUST_ONLINE,
SLIPPI_RUST_JUKEBOX,
SP1,
VIDEO,
Expand Down
8 changes: 2 additions & 6 deletions Source/Core/Common/Logging/LogManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,8 @@ LogManager::LogManager()
"SLIPPI_RUST_DEPENDENCIES", "[Rust] Slippi Dependencies", LogTypes::SLIPPI_RUST_DEPENDENCIES, true);

// This LogContainer will register with the Rust side under the "SLIPPI_RUST_EXI" target.
m_Log[LogTypes::SLIPPI_RUST_EXI] =
new LogContainer("SLIPPI_RUST_EXI", "[Rust] Slippi EXI", LogTypes::SLIPPI_RUST_EXI, true);

// This LogContainer will register with the Rust side under the "SLIPPI_RUST_GAME_REPORTER" target.
m_Log[LogTypes::SLIPPI_RUST_GAME_REPORTER] = new LogContainer(
"SLIPPI_RUST_GAME_REPORTER", "[Rust] Slippi Game Reporter", LogTypes::SLIPPI_RUST_GAME_REPORTER, true);
m_Log[LogTypes::SLIPPI_RUST_ONLINE] =
new LogContainer("SLIPPI_RUST_ONLINE", "[Rust] Slippi Online", LogTypes::SLIPPI_RUST_ONLINE, true);

// This LogContainer will register with the Rust side under the "SLIPPI_RUST_JUKEBOX" target.
m_Log[LogTypes::SLIPPI_RUST_JUKEBOX] =
Expand Down
38 changes: 24 additions & 14 deletions Source/Core/Core/HW/EXI_DeviceSlippi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,23 @@ CEXISlippi::CEXISlippi()
{
INFO_LOG(SLIPPI, "EXI SLIPPI Constructor called.");

// TODO: For mainline port, ISO file path can't be fetched this way. Look at the following:
// @TODO: For mainline port, ISO file path can't be fetched this way. Look at the following:
// https://github.com/dolphin-emu/dolphin/blob/7f450f1d7e7d37bd2300f3a2134cb443d07251f9/Source/Core/Core/Movie.cpp#L246-L249
std::string isoPath = SConfig::GetInstance().m_strFilename;
slprs_exi_device_ptr = slprs_exi_device_create(isoPath.c_str(), OSDMessageHandler);

// @TODO: Eventually we should move `GetSlippiUserJSONPath` out of the File module.
std::string userJSONPath = File::GetSlippiUserJSONPath();

SlippiRustEXIConfig slprs_exi_config;
slprs_exi_config.iso_path = isoPath.c_str();
slprs_exi_config.user_json_path = userJSONPath.c_str();
slprs_exi_config.scm_slippi_semver_str = scm_slippi_semver_str.c_str();
slprs_exi_config.osd_add_msg_fn = OSDMessageHandler;

slprs_exi_device_ptr = slprs_exi_device_create(slprs_exi_config);

m_slippiserver = SlippiSpectateServer::getInstance();
user = std::make_unique<SlippiUser>();
user = std::make_unique<SlippiUser>(slprs_exi_device_ptr);
g_playbackStatus = std::make_unique<SlippiPlaybackStatus>();
matchmaking = std::make_unique<SlippiMatchmaking>(user.get());
gameFileLoader = std::make_unique<SlippiGameFileLoader>();
Expand Down Expand Up @@ -306,10 +316,7 @@ CEXISlippi::~CEXISlippi()
{
ERROR_LOG(SLIPPI_ONLINE, "Exit during in-progress ranked game: %s", activeMatchId.c_str());

auto userInfo = user->GetUserInfo();

slprs_exi_device_report_match_abandonment(slprs_exi_device_ptr, userInfo.uid.c_str(), userInfo.playKey.c_str(),
activeMatchId.c_str());
slprs_exi_device_report_match_abandonment(slprs_exi_device_ptr, activeMatchId.c_str());
}
handleConnectionCleanup();

Expand Down Expand Up @@ -2758,7 +2765,6 @@ void CEXISlippi::handleChatMessage(u8 *payload)

if (slippi_netplay)
{
auto userInfo = user->GetUserInfo();
auto packet = std::make_unique<sf::Packet>();
// OSD::AddMessage("[Me]: "+ msg, OSD::Duration::VERY_LONG, OSD::Color::YELLOW);
slippi_netplay->remoteSentChatMessageId = messageId;
Expand Down Expand Up @@ -3065,8 +3071,7 @@ void CEXISlippi::handleCompleteSet(const SlippiExiTypes::ReportSetCompletionQuer

auto userInfo = user->GetUserInfo();

slprs_exi_device_report_match_completion(slprs_exi_device_ptr, userInfo.uid.c_str(), userInfo.playKey.c_str(),
lastMatchId.c_str(), query.endMode);
slprs_exi_device_report_match_completion(slprs_exi_device_ptr, lastMatchId.c_str(), query.endMode);
}
}

Expand All @@ -3076,12 +3081,10 @@ void CEXISlippi::handleGetPlayerSettings()

SlippiExiTypes::GetPlayerSettingsResponse resp = {};

std::vector<std::vector<std::string>> messagesByPlayer = {
SlippiUser::defaultChatMessages, SlippiUser::defaultChatMessages, SlippiUser::defaultChatMessages,
SlippiUser::defaultChatMessages};
std::vector<std::vector<std::string>> messagesByPlayer = {{}, {}, {}, {}};

// These chat messages will be used when previewing messages
auto userChatMessages = user->GetUserInfo().chatMessages;
auto userChatMessages = user->GetUserChatMessages();
if (userChatMessages.size() == 16)
{
messagesByPlayer[0] = userChatMessages;
Expand All @@ -3096,6 +3099,13 @@ void CEXISlippi::handleGetPlayerSettings()

for (int i = 0; i < 4; i++)
{
// If any of the users in the chat messages vector have a payload that is incorrect,
// force that player to the default chat messages. A valid payload is 16 entries.
if (messagesByPlayer[i].size() != 16)
{
messagesByPlayer[i] = user->GetDefaultChatMessages();
}

for (int j = 0; j < 16; j++)
{
auto str = ConvertStringForGame(messagesByPlayer[i][j], MAX_MESSAGE_LENGTH);
Expand Down
11 changes: 8 additions & 3 deletions Source/Core/Core/Slippi/SlippiMatchmaking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,15 +511,20 @@ void SlippiMatchmaking::handleMatchmaking()
playerInfo.displayName = el.value("displayName", "");
playerInfo.connectCode = el.value("connectCode", "");
playerInfo.port = el.value("port", 0);
playerInfo.chatMessages = SlippiUser::defaultChatMessages;

if (el["chatMessages"].is_array())
{
playerInfo.chatMessages = el.value("chatMessages", SlippiUser::defaultChatMessages);
playerInfo.chatMessages = el.value("chatMessages", m_user->GetDefaultChatMessages());

if (playerInfo.chatMessages.size() != 16)
{
playerInfo.chatMessages = SlippiUser::defaultChatMessages;
playerInfo.chatMessages = m_user->GetDefaultChatMessages();
}
}
else
{
playerInfo.chatMessages = m_user->GetDefaultChatMessages();
}

m_playerInfo.push_back(playerInfo);

Expand Down
Loading

0 comments on commit c83f775

Please sign in to comment.