Skip to content

Commit e53262a

Browse files
committed
Store skins to better understand what goes wrong
1 parent 6994d2e commit e53262a

File tree

6 files changed

+66
-1
lines changed

6 files changed

+66
-1
lines changed

lib/global_api/application.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ defmodule GlobalApi.Application do
99
def start(_type, _args) do
1010
children = [
1111
GlobalApi.PromEx,
12-
{GlobalApi.DatabaseQueue, [pool_size: 7]},
12+
{GlobalApi.DatabaseQueue, [pool_size: 14]},
1313
GlobalApi.SocketManager,
1414
GlobalApi.SkinPreQueue,
1515
GlobalApi.SkinPreUploader,

lib/global_api/schema/skin_storage.ex

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule GlobalApi.Schema.SkinStorage do
2+
use Ecto.Schema
3+
4+
schema "skin_storage" do
5+
field :hash, :binary
6+
field :skin, :string
7+
field :code, :integer
8+
end
9+
end

lib/global_api/skins/skin_storage.ex

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
defmodule GlobalApi.Skins.SkinStorage do
2+
alias GlobalApi.DatabaseQueue
3+
alias GlobalApi.Repo
4+
alias GlobalApi.Schema.SkinStorage, as: Schema
5+
6+
def store(client_data, convert_code) do
7+
# Keep: SkinImageHeight, SkinImageWidth, SkinResourcePatch, SkinGeometryDataEngineVersion, SkinGeometryData, SkinData, SkinAnimationData,
8+
# PremiumSkin, PersonaSkin, CapeOnClassicSkin, CapeImageWidth, CapeImageHeight, CapeData, ArmSize, AnimatedImageData.
9+
# The other keys will only result in storing duplicate data
10+
final_data =
11+
client_data
12+
|> Jason.decode!()
13+
|> Map.drop([
14+
:CapeId,
15+
:ClientRandomId,
16+
:CurrentInputMode,
17+
:DefaultInputMode,
18+
:DeviceId,
19+
:DeviceModel,
20+
:DeviceOS,
21+
:GameVersion,
22+
:GuiScale,
23+
:IsEditorMode,
24+
:LanguageCode,
25+
:PersonaPieces,
26+
:PieceTintColors,
27+
:PlatformOfflineId,
28+
:PlatformOnlineId,
29+
:PlayFabId,
30+
:SelfSignedId,
31+
:ServerAddress,
32+
:SkinColor,
33+
:SkinId,
34+
:ThirdPartyName,
35+
:ThirdPartyNameOnly,
36+
:UIProfile
37+
])
38+
|> Jason.encode!()
39+
40+
identifier = Blake2.hash2b(final_data, 32)
41+
42+
DatabaseQueue.async_fn_call(fn ->
43+
Repo.insert(%Schema{hash: identifier, skin: final_data, code: convert_code}, on_conflict: :nothing)
44+
end)
45+
end
46+
end

lib/global_api_web/web_socket/web_socket.ex

+8
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ defmodule GlobalApiWeb.WebSocket do
106106
end
107107
end
108108

109+
def store(client_data, convert_code) do
110+
GlobalApi.Skins.SkinStorage.store(client_data)
111+
end
112+
109113
def websocket_handle({:json, %{"chain_data" => chain_data, "client_data" => client_data}}, state)
110114
when is_list(chain_data) and is_binary(client_data) do
111115
try do
@@ -114,24 +118,28 @@ defmodule GlobalApiWeb.WebSocket do
114118
{[{:close, @invalid_data}], state}
115119

116120
{:invalid_size, extra_data} ->
121+
store(client_data, 0)
117122
handle_extra_data(extra_data)
118123

119124
send_log_message(state, @info, "received a skin with an invalid skin size")
120125
{:ok, state}
121126

122127
{:invalid_geometry, extra_data} ->
128+
store(client_data, 1)
123129
handle_extra_data(extra_data)
124130

125131
send_log_message(state, @info, "received a skin with invalid geometry")
126132
{:ok, state}
127133

128134
{:invalid_geometry, reason, extra_data} ->
135+
store(client_data, 2)
129136
handle_extra_data(extra_data)
130137

131138
send_log_message(state, @info, "received a skin with invalid geometry: #{reason}")
132139
{:ok, state}
133140

134141
{is_steve, png, rgba_hash, minecraft_hash, {xuid, _, _} = extra_data} ->
142+
store(client_data, 3)
135143
handle_extra_data(extra_data)
136144

137145
# check for cached skin

mix.exs

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ defmodule GlobalApi.MixProject do
3939
# Type `mix help deps` for examples and options.
4040
defp deps do
4141
[
42+
{:blake2, "~> 1.0.4"},
4243
{:phoenix, "~> 1.6.13"},
4344
{:phoenix_live_reload, "~> 1.3.3", only: :dev},
4445
{:phoenix_live_view, "~> 0.18.1"},

mix.lock

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
%{
22
"artificery": {:hex, :artificery, "0.4.3", "0bc4260f988dcb9dda4b23f9fc3c6c8b99a6220a331534fdf5bf2fd0d4333b02", [:mix], [], "hexpm", "12e95333a30e20884e937abdbefa3e7f5e05609c2ba8cf37b33f000b9ffc0504"},
3+
"blake2": {:hex, :blake2, "1.0.4", "8263c69a191142922bc2510f1ffc0de0ae96e8c3bd5e2ad3fac7e87aed94c8b1", [:mix], [], "hexpm", "e9f4120d163ba14d86304195e50745fa18483e6ad2be94c864ae449bbdd6a189"},
34
"cachex": {:hex, :cachex, "3.4.0", "868b2959ea4aeb328c6b60ff66c8d5123c083466ad3c33d3d8b5f142e13101fb", [:mix], [{:eternal, "~> 1.2", [hex: :eternal, repo: "hexpm", optional: false]}, {:jumper, "~> 1.0", [hex: :jumper, repo: "hexpm", optional: false]}, {:sleeplocks, "~> 1.1", [hex: :sleeplocks, repo: "hexpm", optional: false]}, {:unsafe, "~> 1.0", [hex: :unsafe, repo: "hexpm", optional: false]}], "hexpm", "370123b1ab4fba4d2965fb18f87fd758325709787c8c5fce35b3fe80645ccbe5"},
45
"castore": {:hex, :castore, "0.1.18", "deb5b9ab02400561b6f5708f3e7660fc35ca2d51bfc6a940d2f513f89c2975fc", [:mix], [], "hexpm", "61bbaf6452b782ef80b33cdb45701afbcf0a918a45ebe7e73f1130d661e66a06"},
56
"certifi": {:hex, :certifi, "2.9.0", "6f2a475689dd47f19fb74334859d460a2dc4e3252a3324bd2111b8f0429e7e21", [:rebar3], [], "hexpm", "266da46bdb06d6c6d35fde799bcb28d36d985d424ad7c08b5bb48f5b5cdd4641"},

0 commit comments

Comments
 (0)