Closed doshidak closed 1 year ago
Done!
The screenshot above shows a private gen8randombattle
, whose battle
object normally does not report each player's rating
.
Note that gen8unratedrandombattle
is mapped to gen8randombattle
, so you will see players' gen8randombattle
Elo ratings in gen8unratedrandombattle
.
Additionally, the tooltip that shows the additional GXE and Glicko-1 ratings are only available if the Calcdex had to fetch the player's rating.
Will close this via reference on the next PR.
Update:
Just tested this on smogtours.psim.us using Chrome and seems to pull the rating from https://play.pokemonshowdown.com/~~showdown/action.php
just fine, despite being on different domains (i.e., seems to be no CORS issues).
May have to separately test this on Firefox since fetch()
is called directly from the injected bundle, as opposed to the background service worker on Chrome (which could possibly evade CORS since the fetching URL is specified in host_permissions
of the manifest).
Update:
As expected, does not work from Firefox due to CORS. action.php
does not respond with the Access-Control-Allow-Origin
header, so it only works on play.pokemonshowdown.com.
Interestingly, app.user.getActionPHP()
on smogtours.psim.us returns:
/~~smogtours/action.php
resulting in the full URL:
https://smogtours.psim.us/~~smogtours/action.php
However, this redirects to:
https://play.pokemonshowdown.com/~~smogtours/action.php
which does not exist.
Fetching from:
/~~showdown/action.php
from smogtours.psim.us will result in the correct URL:
https://smogtours.psim.us/~~showdown/action.php
which redirects to:
https://play.pokemonshowdown.com/~~showdown/action.php
however, this results in an error due to Mixed Content, specifically active content due to this being used in a fetch()
call.
Unfortunately for now, Firefox users will not get this feature on other Showdown sites (other than the main one), like smogtours.psim.us. Thankfully, this does not crash the Calcdex as the fetch()
error is absorbed by RTK.
Workaround is to use some kind of CORS proxy, similar to how the fetch()
call in background script on Chrome works as a proxy. Will research more workarounds, but won't be able to fix this for the upcoming patch.
Unrated battles (e.g., tourneys, private matches via challenges, actually unrated battles like
gen8unratedrandombattle
) won't have therating
property populated in each player'sShowdown.Side
, e.g., inbattle.p1.rating
,battle.p2.rating
, etc.Apparently you can obtain any user's rating using the
/rank <name>
chat command in Showdown.For instance, running the following command in chat:
returns:
In Showdown's
ConsoleRoom
(defined in/js/client-chat.js
ofpokemon-showdown-client
), theparseCommand()
handles the user's command input.It appears that this fetches an API (via jQuery's
$.get()
) with the URL obtained from the following:and URL parameters:
We can see what this API returns via
curl
:resulting in:
At this point, it should be very straightforward to obtain the user's Elo by Arpad Elo for the current format.