-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display rank information on ranked CSS #391
Draft
walz0
wants to merge
22
commits into
project-slippi:slippi
Choose a base branch
from
walz0:feature/rank_display
base: slippi
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
5380a33
initial commit
walz0 54ac91b
add rank icons to slpCSS
walz0 211df65
add ratingUpdateCount to RankInfo
walz0 a6773cf
resolve merge conflicts
walz0 ead04b6
remove wonky else if chain
walz0 e7d3c68
add rank icons to slpCSS
walz0 5670d1c
return unranked as a base case
walz0 3929bc1
Merge remote-tracking branch 'origin/slippi' into feature/rank_display
walz0 078b65f
rank notifications wip
walz0 d2b0575
Merge remote-tracking branch 'origin/slippi' into feature/rank_display
walz0 1a9acff
Merge branch 'project-slippi:slippi' into feature/rank_display
walz0 1266f9e
changes to RankInfo struct
walz0 01dc006
Merge branch 'feature/rank_display' of github.com:walz0/ishiiruka int…
walz0 2195b87
fix rank change calculation
walz0 3183361
fix icon scaling and refactor handleGetRank
walz0 19920e1
change type on rankChange from u8 to int
walz0 eb87343
convert gql query to multiline string
walz0 3fc84f8
Merge remote-tracking branch 'origin/slippi' into feature/rank_display
walz0 f219977
initialize user rank values
walz0 c4b28c2
Merge remote-tracking branch 'origin/slippi' into feature/rank_display
walz0 2b3a4a1
Merge branch 'project-slippi:slippi' into feature/rank_display
walz0 86550eb
Merge branch 'project-slippi:slippi' into feature/rank_display
walz0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,10 +25,208 @@ std::vector<std::string> ConvertChatMessagesFromRust(RustChatMessages *rsMessage | |
SlippiUser::SlippiUser(uintptr_t rs_exi_device_ptr) | ||
{ | ||
slprs_exi_device_ptr = rs_exi_device_ptr; | ||
|
||
InitUserRank(); | ||
} | ||
|
||
SlippiUser::~SlippiUser() {} | ||
|
||
void SlippiUser::InitUserRank() { | ||
userRank.rank = SlippiUser::SlippiRank (0); | ||
userRank.ratingOrdinal = 0.0f; | ||
userRank.globalPlacing = 0; | ||
userRank.regionalPlacing = 0; | ||
userRank.ratingUpdateCount = 0; | ||
userRank.ratingChange = 0.0f; | ||
userRank.rankChange = 0; | ||
} | ||
|
||
SlippiUser::RankInfo SlippiUser::GetRankInfo() { | ||
return userRank; | ||
} | ||
|
||
SlippiUser::SlippiRank SlippiUser::GetRank(float ratingOrdinal, int globalPlacing, int regionalPlacing, int ratingUpdateCount) | ||
{ | ||
if (ratingUpdateCount < 5) | ||
return RANK_UNRANKED; | ||
if (ratingOrdinal > 0 && ratingOrdinal <= 765.42) | ||
return RANK_BRONZE_1; | ||
if (ratingOrdinal > 765.43 && ratingOrdinal <= 913.71) | ||
return RANK_BRONZE_2; | ||
if (ratingOrdinal > 913.72 && ratingOrdinal <= 1054.86) | ||
return RANK_BRONZE_3; | ||
if (ratingOrdinal > 1054.87 && ratingOrdinal <= 1188.87) | ||
return RANK_SILVER_1; | ||
if (ratingOrdinal > 1188.88 && ratingOrdinal <= 1315.74) | ||
return RANK_SILVER_2; | ||
if (ratingOrdinal > 1315.75 && ratingOrdinal <= 1435.47) | ||
return RANK_SILVER_3; | ||
if (ratingOrdinal > 1435.48 && ratingOrdinal <= 1548.06) | ||
return RANK_GOLD_1; | ||
if (ratingOrdinal > 1548.07 && ratingOrdinal <= 1653.51) | ||
return RANK_GOLD_2; | ||
if (ratingOrdinal > 1653.52 && ratingOrdinal <= 1751.82) | ||
return RANK_GOLD_3; | ||
if (ratingOrdinal > 1751.83 && ratingOrdinal <= 1842.99) | ||
return RANK_PLATINUM_1; | ||
if (ratingOrdinal > 1843 && ratingOrdinal <= 1927.02) | ||
return RANK_PLATINUM_2; | ||
if (ratingOrdinal > 1927.03 && ratingOrdinal <= 2003.91) | ||
return RANK_PLATINUM_3; | ||
if (ratingOrdinal > 2003.92 && ratingOrdinal <= 2073.66) | ||
return RANK_DIAMOND_1; | ||
if (ratingOrdinal > 2073.67 && ratingOrdinal <= 2136.27) | ||
return RANK_DIAMOND_2; | ||
if (ratingOrdinal > 2136.28 && ratingOrdinal <= 2191.74) | ||
return RANK_DIAMOND_3; | ||
if (ratingOrdinal >= 2191.75 && globalPlacing && regionalPlacing) | ||
return RANK_GRANDMASTER; | ||
if (ratingOrdinal > 2191.75 && ratingOrdinal <= 2274.99) | ||
return RANK_MASTER_1; | ||
if (ratingOrdinal > 2275 && ratingOrdinal <= 2350) | ||
return RANK_MASTER_2; | ||
if (ratingOrdinal > 2350) | ||
return RANK_MASTER_3; | ||
return RANK_UNRANKED; | ||
} | ||
|
||
SlippiUser::RankInfo SlippiUser::FetchUserRank(std::string connectCode) | ||
{ | ||
RankInfo info; | ||
|
||
const char *query = | ||
"fragment profileFields on NetplayProfile {\n" | ||
" id\n" | ||
" ratingOrdinal\n" | ||
" ratingUpdateCount\n" | ||
" wins\n" | ||
" losses\n" | ||
" dailyGlobalPlacement\n" | ||
" dailyRegionalPlacement\n" | ||
" continent\n characters {\n" | ||
" id\n" | ||
" character\n" | ||
" gameCount\n" | ||
" __typename\n" | ||
" }\n" | ||
" __typename\n" | ||
"}\n" | ||
"\n" | ||
"fragment userProfilePage on User {\n" | ||
" fbUid\n" | ||
" displayName\n" | ||
" connectCode {\n" | ||
" code\n" | ||
" __typename\n" | ||
" }\n" | ||
" status\n" | ||
" activeSubscription {\n" | ||
" level\n" | ||
" hasGiftSub\n" | ||
" __typename\n" | ||
" }\n" | ||
" rankedNetplayProfile {\n" | ||
" ...profileFields\n" | ||
" __typename\n" | ||
" }\n" | ||
" netplayProfiles {\n" | ||
" ...profileFields\n" | ||
" season {\n" | ||
" id\n" | ||
" startedAt\n" | ||
" endedAt\n" | ||
" name\n" | ||
" status\n" | ||
" __typename\n" | ||
" }\n" | ||
" __typename\n" | ||
" }\n" | ||
" __typename\n" | ||
"}\n" | ||
"\n" | ||
"query AccountManagementPageQuery($cc: String!, $uid: String!) {\n" | ||
" getUser(fbUid: $uid) {\n" | ||
" ...userProfilePage\n" | ||
" __typename\n" | ||
" }\n" | ||
" getConnectCode(code: $cc) {\n" | ||
" user {\n" | ||
" ...userProfilePage\n" | ||
" __typename\n" | ||
" }\n" | ||
" __typename\n" | ||
" }\n" | ||
"}\n"; | ||
|
||
std::string url = "https://gql-gateway-dot-slippi.uc.r.appspot.com/graphql"; | ||
json body = {{"operationName", "AccountManagementPageQuery"}, | ||
{"variables", {{"cc", connectCode}, {"uid", connectCode}}}, | ||
{"query", query}}; | ||
|
||
// INFO_LOG(SLIPPI_ONLINE, "Preparing request..."); | ||
// Perform curl request | ||
std::string resp; | ||
curl_easy_setopt(m_curl, CURLOPT_URL, (url).c_str()); | ||
curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, &resp); | ||
curl_easy_setopt(m_curl, CURLOPT_POSTFIELDS, (body.dump()).c_str()); | ||
curl_easy_setopt(m_curl, CURLOPT_CUSTOMREQUEST, "POST"); | ||
|
||
CURLcode res = curl_easy_perform(m_curl); | ||
|
||
// INFO_LOG(SLIPPI_ONLINE, "Request sent"); | ||
if (res != 0) | ||
{ | ||
ERROR_LOG(SLIPPI, "[User] Error fetching user info from server, code: %d", res); | ||
//return info; | ||
} | ||
|
||
long responseCode; | ||
curl_easy_getinfo(m_curl, CURLINFO_RESPONSE_CODE, &responseCode); | ||
if (responseCode != 200) | ||
{ | ||
ERROR_LOG(SLIPPI, "[User] Server responded with non-success status: %d", responseCode); | ||
//return info; | ||
} | ||
|
||
auto r = json::parse(resp); | ||
auto rankedObject = r["data"]["getConnectCode"]["user"]["rankedNetplayProfile"]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should probably make sure |
||
|
||
float ratingOrdinal = rankedObject["ratingOrdinal"]; | ||
INFO_LOG(SLIPPI_ONLINE, "Rating: %0000.00f", ratingOrdinal); | ||
|
||
u8 global = (rankedObject["dailyGlobalPlacement"]).is_null() ? 0 : rankedObject["dailyGlobalPlacement"]; | ||
INFO_LOG(SLIPPI_ONLINE, "Global Placing: %d", global); | ||
|
||
u8 regional = (rankedObject["dailyRegionalPlacement"]).is_null() ? 0 : rankedObject["dailyRegionalPlacement"]; | ||
INFO_LOG(SLIPPI_ONLINE, "Regional Placing: %d", regional); | ||
|
||
u8 ratingUpdateCount = (rankedObject["ratingUpdateCount"]).is_null() ? 0 : rankedObject["ratingUpdateCount"]; | ||
INFO_LOG(SLIPPI_ONLINE, "Rating Update Count: %d", ratingUpdateCount); | ||
|
||
SlippiRank rank = GetRank(ratingOrdinal, global, regional, ratingUpdateCount); | ||
INFO_LOG(SLIPPI_ONLINE, "Rank: %d", rank); | ||
|
||
float ratingChange = (userRank.ratingOrdinal > 0.001f) ? ratingOrdinal - userRank.ratingOrdinal : 0; | ||
INFO_LOG(SLIPPI_ONLINE, "Rating Change: %0.1f", ratingChange); | ||
|
||
int rankChange = (userRank.rank > 0.001f) ? rank - userRank.rank : 0; | ||
INFO_LOG(SLIPPI_ONLINE, "userRank: %d", userRank.rank); | ||
INFO_LOG(SLIPPI_ONLINE, "Rank Change: %d", rankChange); | ||
|
||
info.rank = rank; | ||
info.ratingOrdinal = ratingOrdinal; | ||
info.globalPlacing = global; | ||
info.regionalPlacing = regional; | ||
info.ratingUpdateCount = ratingUpdateCount; | ||
info.ratingChange = ratingChange; | ||
info.rankChange = rankChange; | ||
|
||
// Set user rank | ||
userRank = info; | ||
|
||
return info; | ||
} | ||
|
||
bool SlippiUser::AttemptLogin() | ||
{ | ||
return slprs_user_attempt_login(slprs_exi_device_ptr); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if
ratingOrdinal == 2191.75
but!(globalPlacing && regionalPlacing)
?