mirror of
https://github.com/elyby/chrly.git
synced 2024-11-26 16:51:59 +05:30
Resolves #23. Allow to spoof Mojang's API addresses
This commit is contained in:
parent
585318d307
commit
f43c1a9a37
@ -8,7 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Added
|
||||
- [#24](https://github.com/elyby/chrly/issues/24): Implemented a new strategy for the queue in the batch provider of
|
||||
Mojang UUIDs: `full-bus`.
|
||||
- A new configuration param `QUEUE_STRATEGY` with the default value `periodic`.
|
||||
- New configuration param `QUEUE_STRATEGY` with the default value `periodic`.
|
||||
- New configuration params: `MOJANG_API_BASE_URL` and `MOJANG_SESSION_SERVER_BASE_URL`, that allow you to spoof
|
||||
Mojang API base addresses.
|
||||
|
||||
### Changed
|
||||
- `ely.skinsystem.{hostname}.app.mojang_textures.usernames.round_time` timer will not be recorded if the iteration was
|
||||
|
14
README.md
14
README.md
@ -145,6 +145,20 @@ docker-compose up -d app
|
||||
</td>
|
||||
<td><code>http://remote-provider.com/api/worker/mojang-uuid</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>MOJANG_API_BASE_URL</td>
|
||||
<td>
|
||||
Allows you to spoof the Mojang's API server address.
|
||||
</td>
|
||||
<td><code>https://api.mojang.com</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>MOJANG_SESSION_SERVER_BASE_URL</td>
|
||||
<td>
|
||||
Allows you to spoof the Mojang's Session server address.
|
||||
</td>
|
||||
<td><code>https://sessionserver.mojang.com</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>TEXTURES_EXTRA_PARAM_NAME</td>
|
||||
<td>
|
||||
|
@ -58,11 +58,17 @@ type ProfileInfo struct {
|
||||
IsDemo bool `json:"demo,omitempty"`
|
||||
}
|
||||
|
||||
var ApiMojangDotComAddr = "https://api.mojang.com"
|
||||
var SessionServerMojangComAddr = "https://sessionserver.mojang.com"
|
||||
|
||||
// Exchanges usernames array to array of uuids
|
||||
// See https://wiki.vg/Mojang_API#Playernames_-.3E_UUIDs
|
||||
func UsernamesToUuids(usernames []string) ([]*ProfileInfo, error) {
|
||||
requestBody, _ := json.Marshal(usernames)
|
||||
request, _ := http.NewRequest("POST", "https://api.mojang.com/profiles/minecraft", bytes.NewBuffer(requestBody))
|
||||
request, err := http.NewRequest("POST", ApiMojangDotComAddr+"/profiles/minecraft", bytes.NewBuffer(requestBody))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
|
||||
@ -88,12 +94,15 @@ func UsernamesToUuids(usernames []string) ([]*ProfileInfo, error) {
|
||||
// See https://wiki.vg/Mojang_API#UUID_-.3E_Profile_.2B_Skin.2FCape
|
||||
func UuidToTextures(uuid string, signed bool) (*SignedTexturesResponse, error) {
|
||||
normalizedUuid := strings.ReplaceAll(uuid, "-", "")
|
||||
url := "https://sessionserver.mojang.com/session/minecraft/profile/" + normalizedUuid
|
||||
url := SessionServerMojangComAddr + "/session/minecraft/profile/" + normalizedUuid
|
||||
if signed {
|
||||
url += "?unsigned=false"
|
||||
}
|
||||
|
||||
request, _ := http.NewRequest("GET", url, nil)
|
||||
request, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response, err := HttpClient.Do(request)
|
||||
if err != nil {
|
||||
|
@ -9,12 +9,14 @@ import (
|
||||
"github.com/goava/di"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/elyby/chrly/api/mojang"
|
||||
es "github.com/elyby/chrly/eventsubscribers"
|
||||
"github.com/elyby/chrly/http"
|
||||
"github.com/elyby/chrly/mojangtextures"
|
||||
)
|
||||
|
||||
var mojangTextures = di.Options(
|
||||
di.Invoke(interceptMojangApiUrls),
|
||||
di.Provide(newMojangTexturesProviderFactory),
|
||||
di.Provide(newMojangTexturesProvider),
|
||||
di.Provide(newMojangTexturesUuidsProviderFactory),
|
||||
@ -27,6 +29,30 @@ var mojangTextures = di.Options(
|
||||
di.Provide(newMojangTexturesStorageFactory),
|
||||
)
|
||||
|
||||
func interceptMojangApiUrls(config *viper.Viper) error {
|
||||
apiUrl := config.GetString("mojang.api_base_url")
|
||||
if apiUrl != "" {
|
||||
u, err := url.ParseRequestURI(apiUrl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mojang.ApiMojangDotComAddr = u.String()
|
||||
}
|
||||
|
||||
sessionServerUrl := config.GetString("mojang.session_server_base_url")
|
||||
if sessionServerUrl != "" {
|
||||
u, err := url.ParseRequestURI(apiUrl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mojang.SessionServerMojangComAddr = u.String()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func newMojangTexturesProviderFactory(
|
||||
container *di.Container,
|
||||
config *viper.Viper,
|
||||
|
Loading…
Reference in New Issue
Block a user