mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-08-22 10:19:01 +00:00
Merge pull request #67 from bmarcott/nmarcott_format_manual
fix variable naming convention for SlippiUser
This commit is contained in:
commit
9d68db0100
4 changed files with 88 additions and 89 deletions
|
@ -1998,7 +1998,7 @@ void CEXISlippi::setMatchSelections(u8* payload)
|
||||||
s.rngOffset = generator() % 0xFFFF;
|
s.rngOffset = generator() % 0xFFFF;
|
||||||
|
|
||||||
// Get user name from file
|
// Get user name from file
|
||||||
std::string displayName = user->GetUserInfo().displayName;
|
std::string displayName = user->GetUserInfo().display_name;
|
||||||
|
|
||||||
// Just let the max length to transfer to opponent be potentially 16 worst-case utf-8 chars
|
// Just let the max length to transfer to opponent be potentially 16 worst-case utf-8 chars
|
||||||
// This string will get converted to the game format later
|
// This string will get converted to the game format later
|
||||||
|
@ -2011,7 +2011,7 @@ void CEXISlippi::setMatchSelections(u8* payload)
|
||||||
s.playerName = displayName;
|
s.playerName = displayName;
|
||||||
|
|
||||||
// Get user connect code from file
|
// Get user connect code from file
|
||||||
s.connectCode = user->GetUserInfo().connectCode;
|
s.connectCode = user->GetUserInfo().connect_code;
|
||||||
|
|
||||||
// Merge these selections
|
// Merge these selections
|
||||||
localSelections.Merge(s);
|
localSelections.Merge(s);
|
||||||
|
@ -2108,7 +2108,7 @@ void CEXISlippi::prepareOnlineStatus()
|
||||||
if (isLoggedIn)
|
if (isLoggedIn)
|
||||||
{
|
{
|
||||||
// Check if we have the latest version, and if not, indicate we need to update
|
// Check if we have the latest version, and if not, indicate we need to update
|
||||||
version::Semver200_version latestVersion(userInfo.latestVersion);
|
version::Semver200_version latestVersion(userInfo.latest_version);
|
||||||
version::Semver200_version currentVersion(Common::scm_slippi_semver_str);
|
version::Semver200_version currentVersion(Common::scm_slippi_semver_str);
|
||||||
|
|
||||||
appState = latestVersion > currentVersion ? 2 : 1;
|
appState = latestVersion > currentVersion ? 2 : 1;
|
||||||
|
@ -2117,11 +2117,11 @@ void CEXISlippi::prepareOnlineStatus()
|
||||||
m_read_queue.push_back(appState);
|
m_read_queue.push_back(appState);
|
||||||
|
|
||||||
// Write player name (31 bytes)
|
// Write player name (31 bytes)
|
||||||
std::string playerName = ConvertStringForGame(userInfo.displayName, MAX_NAME_LENGTH);
|
std::string playerName = ConvertStringForGame(userInfo.display_name, MAX_NAME_LENGTH);
|
||||||
m_read_queue.insert(m_read_queue.end(), playerName.begin(), playerName.end());
|
m_read_queue.insert(m_read_queue.end(), playerName.begin(), playerName.end());
|
||||||
|
|
||||||
// Write connect code (10 bytes)
|
// Write connect code (10 bytes)
|
||||||
std::string connectCode = userInfo.connectCode;
|
std::string connectCode = userInfo.connect_code;
|
||||||
char shiftJisHashtag[] = {'\x81', '\x94', '\x00'};
|
char shiftJisHashtag[] = {'\x81', '\x94', '\x00'};
|
||||||
connectCode.resize(CONNECT_CODE_LENGTH);
|
connectCode.resize(CONNECT_CODE_LENGTH);
|
||||||
connectCode = ReplaceAll(connectCode, "#", shiftJisHashtag);
|
connectCode = ReplaceAll(connectCode, "#", shiftJisHashtag);
|
||||||
|
|
|
@ -288,7 +288,7 @@ void SlippiMatchmaking::startMatchmaking()
|
||||||
// Send message to server to create ticket
|
// Send message to server to create ticket
|
||||||
json request;
|
json request;
|
||||||
request["type"] = MmMessageType::CREATE_TICKET;
|
request["type"] = MmMessageType::CREATE_TICKET;
|
||||||
request["user"] = {{"uid", userInfo.uid}, {"playKey", userInfo.playKey}};
|
request["user"] = {{"uid", userInfo.uid}, {"playKey", userInfo.play_key}};
|
||||||
request["search"] = {{"mode", m_searchSettings.mode}, {"connectCode", connectCodeBuf}};
|
request["search"] = {{"mode", m_searchSettings.mode}, {"connectCode", connectCodeBuf}};
|
||||||
request["appVersion"] = Common::scm_slippi_semver_str;
|
request["appVersion"] = Common::scm_slippi_semver_str;
|
||||||
sendMessage(request);
|
sendMessage(request);
|
||||||
|
|
|
@ -76,8 +76,8 @@ SlippiUser::SlippiUser()
|
||||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 5000);
|
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 5000);
|
||||||
|
|
||||||
// Set up HTTP Headers
|
// Set up HTTP Headers
|
||||||
m_curlHeaderList = curl_slist_append(m_curlHeaderList, "Content-Type: application/json");
|
m_curl_header_list = curl_slist_append(m_curl_header_list, "Content-Type: application/json");
|
||||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, m_curlHeaderList);
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, m_curl_header_list);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
// ALPN support is enabled by default but requires Windows >= 8.1.
|
// ALPN support is enabled by default but requires Windows >= 8.1.
|
||||||
|
@ -91,59 +91,58 @@ SlippiUser::SlippiUser()
|
||||||
SlippiUser::~SlippiUser()
|
SlippiUser::~SlippiUser()
|
||||||
{
|
{
|
||||||
// Wait for thread to terminate
|
// Wait for thread to terminate
|
||||||
runThread = false;
|
m_run_thread = false;
|
||||||
if (fileListenThread.joinable())
|
if (m_file_listen_thread.joinable())
|
||||||
fileListenThread.join();
|
m_file_listen_thread.join();
|
||||||
|
|
||||||
if (m_curl)
|
if (m_curl)
|
||||||
{
|
{
|
||||||
curl_slist_free_all(m_curlHeaderList);
|
curl_slist_free_all(m_curl_header_list);
|
||||||
curl_easy_cleanup(m_curl);
|
curl_easy_cleanup(m_curl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SlippiUser::AttemptLogin()
|
bool SlippiUser::AttemptLogin()
|
||||||
{
|
{
|
||||||
std::string userFilePath = getUserFilePath();
|
std::string user_file_path = getUserFilePath();
|
||||||
|
|
||||||
INFO_LOG(SLIPPI_ONLINE, "Looking for file at: %s", userFilePath.c_str());
|
INFO_LOG(SLIPPI_ONLINE, "Looking for file at: %s", user_file_path.c_str());
|
||||||
|
|
||||||
{
|
{
|
||||||
std::string userFilePathTxt =
|
// Put the filename here in its own scope because we don't really need it elsewhere
|
||||||
userFilePath +
|
std::string user_file_path_txt = user_file_path + ".txt";
|
||||||
".txt"; // Put the filename here in its own scope because we don't really need it elsewhere
|
if (File::Exists(user_file_path_txt))
|
||||||
if (File::Exists(userFilePathTxt))
|
|
||||||
{
|
{
|
||||||
// If both files exist we just log they exist and take no further action
|
// If both files exist we just log they exist and take no further action
|
||||||
if (File::Exists(userFilePath))
|
if (File::Exists(user_file_path))
|
||||||
{
|
{
|
||||||
INFO_LOG(SLIPPI_ONLINE, "Found both .json.txt and .json file for user data. Using .json "
|
INFO_LOG(SLIPPI_ONLINE, "Found both .json.txt and .json file for user data. Using .json "
|
||||||
"and ignoring the .json.txt");
|
"and ignoring the .json.txt");
|
||||||
}
|
}
|
||||||
// If only the .txt file exists move the contents to a json file and log if it fails
|
// If only the .txt file exists move the contents to a json file and log if it fails
|
||||||
else if (!File::Rename(userFilePathTxt, userFilePath))
|
else if (!File::Rename(user_file_path_txt, user_file_path))
|
||||||
{
|
{
|
||||||
WARN_LOG(SLIPPI_ONLINE, "Could not move file %s to %s", userFilePathTxt.c_str(),
|
WARN_LOG(SLIPPI_ONLINE, "Could not move file %s to %s", user_file_path_txt.c_str(),
|
||||||
userFilePath.c_str());
|
user_file_path.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get user file
|
// Get user file
|
||||||
std::string userFileContents;
|
std::string user_file_contents;
|
||||||
File::ReadFileToString(userFilePath, userFileContents);
|
File::ReadFileToString(user_file_path, user_file_contents);
|
||||||
|
|
||||||
userInfo = parseFile(userFileContents);
|
m_user_info = parseFile(user_file_contents);
|
||||||
|
|
||||||
isLoggedIn = !userInfo.uid.empty();
|
m_is_logged_in = !m_user_info.uid.empty();
|
||||||
if (isLoggedIn)
|
if (m_is_logged_in)
|
||||||
{
|
{
|
||||||
overwriteFromServer();
|
overwriteFromServer();
|
||||||
WARN_LOG(SLIPPI_ONLINE, "Found user %s (%s)", userInfo.displayName.c_str(),
|
WARN_LOG(SLIPPI_ONLINE, "Found user %s (%s)", m_user_info.display_name.c_str(),
|
||||||
userInfo.uid.c_str());
|
m_user_info.uid.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
return isLoggedIn;
|
return m_is_logged_in;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SlippiUser::OpenLogInPage()
|
void SlippiUser::OpenLogInPage()
|
||||||
|
@ -159,21 +158,21 @@ void SlippiUser::OpenLogInPage()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __APPLE__
|
#ifndef __APPLE__
|
||||||
char* escapedPath = curl_easy_escape(nullptr, path.c_str(), (int)path.length());
|
char* escaped_path = curl_easy_escape(nullptr, path.c_str(), (int)path.length());
|
||||||
path = std::string(escapedPath);
|
path = std::string(escaped_path);
|
||||||
curl_free(escapedPath);
|
curl_free(escaped_path);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::string fullUrl = url + "?path=" + path;
|
std::string full_url = url + "?path=" + path;
|
||||||
|
|
||||||
INFO_LOG(SLIPPI_ONLINE, "[User] Login at path: %s", fullUrl.c_str());
|
INFO_LOG(SLIPPI_ONLINE, "[User] Login at path: %s", full_url.c_str());
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
std::string command = "explorer \"" + fullUrl + "\"";
|
std::string command = "explorer \"" + full_url + "\"";
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
std::string command = "open \"" + fullUrl + "\"";
|
std::string command = "open \"" + full_url + "\"";
|
||||||
#else
|
#else
|
||||||
std::string command = "xdg-open \"" + fullUrl + "\""; // Linux
|
std::string command = "xdg-open \"" + full_url + "\""; // Linux
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RunSystemCommand(command);
|
RunSystemCommand(command);
|
||||||
|
@ -185,13 +184,13 @@ void SlippiUser::UpdateApp()
|
||||||
auto isoPath = SConfig::GetInstance().m_strIsoPath;
|
auto isoPath = SConfig::GetInstance().m_strIsoPath;
|
||||||
|
|
||||||
std::string path = File::GetExeDirectory() + "/dolphin-slippi-tools.exe";
|
std::string path = File::GetExeDirectory() + "/dolphin-slippi-tools.exe";
|
||||||
std::string echoMsg =
|
std::string echo_msg =
|
||||||
"echo Starting update process. If nothing happen after a few "
|
"echo Starting update process. If nothing happen after a few "
|
||||||
"minutes, you may need to update manually from https://slippi.gg/netplay ...";
|
"minutes, you may need to update manually from https://slippi.gg/netplay ...";
|
||||||
// std::string command =
|
// std::string command =
|
||||||
// "start /b cmd /c " + echoMsg + " && \"" + path + "\" app-update -launch -iso \"" + isoPath +
|
// "start /b cmd /c " + echo_msg + " && \"" + path + "\" app-update -launch -iso \"" + isoPath +
|
||||||
// "\"";
|
// "\"";
|
||||||
std::string command = "start /b cmd /c " + echoMsg + " && \"" + path +
|
std::string command = "start /b cmd /c " + echo_msg + " && \"" + path +
|
||||||
"\" app-update -launch -iso \"" + isoPath + "\" -version \"" +
|
"\" app-update -launch -iso \"" + isoPath + "\" -version \"" +
|
||||||
Common::scm_slippi_semver_str + "\"";
|
Common::scm_slippi_semver_str + "\"";
|
||||||
WARN_LOG(SLIPPI, "Executing app update command: %s", command.c_str());
|
WARN_LOG(SLIPPI, "Executing app update command: %s", command.c_str());
|
||||||
|
@ -215,48 +214,48 @@ void SlippiUser::UpdateApp()
|
||||||
|
|
||||||
void SlippiUser::ListenForLogIn()
|
void SlippiUser::ListenForLogIn()
|
||||||
{
|
{
|
||||||
if (runThread)
|
if (m_run_thread)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (fileListenThread.joinable())
|
if (m_file_listen_thread.joinable())
|
||||||
fileListenThread.join();
|
m_file_listen_thread.join();
|
||||||
|
|
||||||
runThread = true;
|
m_run_thread = true;
|
||||||
fileListenThread = std::thread(&SlippiUser::FileListenThread, this);
|
m_file_listen_thread = std::thread(&SlippiUser::FileListenThread, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SlippiUser::LogOut()
|
void SlippiUser::LogOut()
|
||||||
{
|
{
|
||||||
runThread = false;
|
m_run_thread = false;
|
||||||
deleteFile();
|
deleteFile();
|
||||||
|
|
||||||
UserInfo emptyUser;
|
UserInfo empty_user;
|
||||||
isLoggedIn = false;
|
m_is_logged_in = false;
|
||||||
userInfo = emptyUser;
|
m_user_info = empty_user;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SlippiUser::OverwriteLatestVersion(std::string version)
|
void SlippiUser::OverwriteLatestVersion(std::string version)
|
||||||
{
|
{
|
||||||
userInfo.latestVersion = version;
|
m_user_info.latest_version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
SlippiUser::UserInfo SlippiUser::GetUserInfo()
|
SlippiUser::UserInfo SlippiUser::GetUserInfo()
|
||||||
{
|
{
|
||||||
return userInfo;
|
return m_user_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SlippiUser::IsLoggedIn()
|
bool SlippiUser::IsLoggedIn()
|
||||||
{
|
{
|
||||||
return isLoggedIn;
|
return m_is_logged_in;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SlippiUser::FileListenThread()
|
void SlippiUser::FileListenThread()
|
||||||
{
|
{
|
||||||
while (runThread)
|
while (m_run_thread)
|
||||||
{
|
{
|
||||||
if (AttemptLogin())
|
if (AttemptLogin())
|
||||||
{
|
{
|
||||||
runThread = false;
|
m_run_thread = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,14 +269,14 @@ void SlippiUser::FileListenThread()
|
||||||
std::string SlippiUser::getUserFilePath()
|
std::string SlippiUser::getUserFilePath()
|
||||||
{
|
{
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
std::string userFilePath =
|
std::string user_file_path =
|
||||||
File::GetBundleDirectory() + "/Contents/Resources" + DIR_SEP + "user.json";
|
File::GetBundleDirectory() + "/Contents/Resources" + DIR_SEP + "user.json";
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
std::string userFilePath = File::GetExeDirectory() + DIR_SEP + "user.json";
|
std::string user_file_path = File::GetExeDirectory() + DIR_SEP + "user.json";
|
||||||
#else
|
#else
|
||||||
std::string userFilePath = File::GetUserPath(F_USERJSON_IDX);
|
std::string user_file_path = File::GetUserPath(F_USERJSON_IDX);
|
||||||
#endif
|
#endif
|
||||||
return userFilePath;
|
return user_file_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string readString(json obj, std::string key)
|
inline std::string readString(json obj, std::string key)
|
||||||
|
@ -291,30 +290,30 @@ inline std::string readString(json obj, std::string key)
|
||||||
return obj[key];
|
return obj[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
SlippiUser::UserInfo SlippiUser::parseFile(std::string fileContents)
|
SlippiUser::UserInfo SlippiUser::parseFile(std::string file_contents)
|
||||||
{
|
{
|
||||||
UserInfo info;
|
UserInfo info;
|
||||||
info.fileContents = fileContents;
|
info.file_contents = file_contents;
|
||||||
|
|
||||||
auto res = json::parse(fileContents, nullptr, false);
|
auto res = json::parse(file_contents, nullptr, false);
|
||||||
if (res.is_discarded() || !res.is_object())
|
if (res.is_discarded() || !res.is_object())
|
||||||
{
|
{
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
info.uid = readString(res, "uid");
|
info.uid = readString(res, "uid");
|
||||||
info.displayName = readString(res, "displayName");
|
info.display_name = readString(res, "displayName");
|
||||||
info.playKey = readString(res, "playKey");
|
info.play_key = readString(res, "playKey");
|
||||||
info.connectCode = readString(res, "connectCode");
|
info.connect_code = readString(res, "connectCode");
|
||||||
info.latestVersion = readString(res, "latestVersion");
|
info.latest_version = readString(res, "latestVersion");
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SlippiUser::deleteFile()
|
void SlippiUser::deleteFile()
|
||||||
{
|
{
|
||||||
std::string userFilePath = getUserFilePath();
|
std::string user_file_path = getUserFilePath();
|
||||||
File::Delete(userFilePath);
|
File::Delete(user_file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SlippiUser::overwriteFromServer()
|
void SlippiUser::overwriteFromServer()
|
||||||
|
@ -324,7 +323,7 @@ void SlippiUser::overwriteFromServer()
|
||||||
|
|
||||||
// Perform curl request
|
// Perform curl request
|
||||||
std::string resp;
|
std::string resp;
|
||||||
curl_easy_setopt(m_curl, CURLOPT_URL, (URL_START + "/" + userInfo.uid).c_str());
|
curl_easy_setopt(m_curl, CURLOPT_URL, (URL_START + "/" + m_user_info.uid).c_str());
|
||||||
curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, &resp);
|
curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, &resp);
|
||||||
CURLcode res = curl_easy_perform(m_curl);
|
CURLcode res = curl_easy_perform(m_curl);
|
||||||
|
|
||||||
|
@ -334,19 +333,19 @@ void SlippiUser::overwriteFromServer()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
long responseCode;
|
long response_code;
|
||||||
curl_easy_getinfo(m_curl, CURLINFO_RESPONSE_CODE, &responseCode);
|
curl_easy_getinfo(m_curl, CURLINFO_RESPONSE_CODE, &response_code);
|
||||||
if (responseCode != 200)
|
if (response_code != 200)
|
||||||
{
|
{
|
||||||
ERROR_LOG(SLIPPI, "[User] Server responded with non-success status: %d", responseCode);
|
ERROR_LOG(SLIPPI, "[User] Server responded with non-success status: %d", response_code);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overwrite userInfo with data from server
|
// Overwrite user info with data from server
|
||||||
auto r = json::parse(resp);
|
auto r = json::parse(resp);
|
||||||
userInfo.connectCode = r.value("connectCode", userInfo.connectCode);
|
m_user_info.connect_code = r.value("connectCode", m_user_info.connect_code);
|
||||||
userInfo.latestVersion = r.value("latestVersion", userInfo.latestVersion);
|
m_user_info.latest_version = r.value("latestVersion", m_user_info.latest_version);
|
||||||
|
|
||||||
// TODO: Once it's possible to change Display name from website, uncomment below
|
// TODO: Once it's possible to change Display name from website, uncomment below
|
||||||
// userInfo.displayName = r.value("displayName", userInfo.displayName);
|
// m_user_info.display_name = r.value("displayName", m_user_info.display_name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,11 +14,11 @@ public:
|
||||||
struct UserInfo
|
struct UserInfo
|
||||||
{
|
{
|
||||||
std::string uid = "";
|
std::string uid = "";
|
||||||
std::string playKey = "";
|
std::string play_key = "";
|
||||||
std::string displayName = "";
|
std::string display_name = "";
|
||||||
std::string connectCode = "";
|
std::string connect_code = "";
|
||||||
std::string latestVersion = "";
|
std::string latest_version = "";
|
||||||
std::string fileContents = "";
|
std::string file_contents = "";
|
||||||
};
|
};
|
||||||
|
|
||||||
SlippiUser();
|
SlippiUser();
|
||||||
|
@ -36,18 +36,18 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string getUserFilePath();
|
std::string getUserFilePath();
|
||||||
UserInfo parseFile(std::string fileContents);
|
UserInfo parseFile(std::string file_contents);
|
||||||
void deleteFile();
|
void deleteFile();
|
||||||
void overwriteFromServer();
|
void overwriteFromServer();
|
||||||
|
|
||||||
UserInfo userInfo;
|
UserInfo m_user_info;
|
||||||
bool isLoggedIn = false;
|
bool m_is_logged_in = false;
|
||||||
|
|
||||||
const std::string URL_START = "https://users-rest-dot-slippi.uc.r.appspot.com/user";
|
const std::string URL_START = "https://users-rest-dot-slippi.uc.r.appspot.com/user";
|
||||||
CURL* m_curl = nullptr;
|
CURL* m_curl = nullptr;
|
||||||
struct curl_slist* m_curlHeaderList = nullptr;
|
struct curl_slist* m_curl_header_list = nullptr;
|
||||||
std::vector<char> receiveBuf;
|
std::vector<char> m_receive_buf;
|
||||||
|
|
||||||
std::thread fileListenThread;
|
std::thread m_file_listen_thread;
|
||||||
std::atomic<bool> runThread;
|
std::atomic<bool> m_run_thread;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue