Skip to content

Commit 8fa5ac3

Browse files
committed
change name UserProfile, UserUUID -> PlayerProfile, PlayerUUID
1 parent ef8ad55 commit 8fa5ac3

File tree

6 files changed

+44
-45
lines changed

6 files changed

+44
-45
lines changed

MojangAPI/Model/UserProfile.cs renamed to MojangAPI/Model/PlayerProfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace MojangAPI.Model
66
{
7-
public class UserProfile : MojangAPIResponse
7+
public class PlayerProfile : MojangAPIResponse
88
{
99
public string UUID { get; set; } = "";
1010
public string Name { get; set; } = "";

MojangAPI/Model/UserUUID.cs renamed to MojangAPI/Model/PlayerUUID.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace MojangAPI.Model
77
{
8-
public class UserUUID : MojangAPIResponse
8+
public class PlayerUUID : MojangAPIResponse
99
{
1010
public override bool IsSuccess
1111
=> base.IsSuccess

MojangAPI/Mojang.cs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ public Mojang(HttpClient client)
3737
this.client = client;
3838
}
3939

40-
public Task<UserUUID> GetUUID(string username) =>
41-
client.SendActionAsync(new HttpAction<UserUUID>
40+
public Task<PlayerUUID> GetUUID(string username) =>
41+
client.SendActionAsync(new HttpAction<PlayerUUID>
4242
{
4343
Method = HttpMethod.Get,
4444
Host = "https://api.mojang.com",
4545
Path = $"users/profiles/minecraft/{username ?? throw new ArgumentNullException(nameof(username))}"
4646
});
4747

48-
public Task<UserUUID> GetUUID(string username, DateTimeOffset timestamp) =>
48+
public Task<PlayerUUID> GetUUID(string username, DateTimeOffset timestamp) =>
4949
GetUUID(username, timestamp.ToUnixTimeSeconds());
5050

51-
public Task<UserUUID> GetUUID(string username, long timestamp) =>
52-
client.SendActionAsync(new HttpAction<UserUUID>
51+
public Task<PlayerUUID> GetUUID(string username, long timestamp) =>
52+
client.SendActionAsync(new HttpAction<PlayerUUID>
5353
{
5454
Method = HttpMethod.Get,
5555
Host = "https://api.mojang.com",
@@ -71,27 +71,27 @@ public Task<UserUUID> GetUUID(string username, long timestamp) =>
7171
ErrorHandler = (res, ex) => Task.FromResult<NameHistory[]?>(null)
7272
});
7373

74-
public Task<UserUUID[]?> GetUUIDs(string[] usernames) =>
75-
client.SendActionAsync(new HttpAction<UserUUID[]?>
74+
public Task<PlayerUUID[]?> GetUUIDs(string[] usernames) =>
75+
client.SendActionAsync(new HttpAction<PlayerUUID[]?>
7676
{
7777
Method = HttpMethod.Post,
7878
Host = "https://api.mojang.com",
7979
Path = "profiles/minecraft",
8080
Content = new JsonHttpContent(usernames ?? throw new ArgumentNullException()),
81-
ResponseHandler = HttpResponseHandlers.GetJsonArrayHandler<UserUUID>(),
82-
ErrorHandler = (res, ex) => Task.FromResult<UserUUID[]?>(null)
81+
ResponseHandler = HttpResponseHandlers.GetJsonArrayHandler<PlayerUUID>(),
82+
ErrorHandler = (res, ex) => Task.FromResult<PlayerUUID[]?>(null)
8383
});
8484

85-
public Task<UserProfile> GetProfileUsingUUID(string uuid) =>
86-
client.SendActionAsync(new HttpAction<UserProfile>
85+
public Task<PlayerProfile> GetProfileUsingUUID(string uuid) =>
86+
client.SendActionAsync(new HttpAction<PlayerProfile>
8787
{
8888
Method = HttpMethod.Get,
8989
Host = "https://sessionserver.mojang.com",
9090
Path = $"session/minecraft/profile/{uuid ?? throw new ArgumentNullException()}",
9191
ResponseHandler = uuidProfileResponseHandler
9292
});
9393

94-
private async Task<UserProfile> uuidProfileResponseHandler(HttpResponseMessage response)
94+
private async Task<PlayerProfile> uuidProfileResponseHandler(HttpResponseMessage response)
9595
{
9696
string responseContent = await response.Content.ReadAsStringAsync();
9797
JObject job = JObject.Parse(responseContent);
@@ -128,7 +128,7 @@ private async Task<UserProfile> uuidProfileResponseHandler(HttpResponseMessage r
128128
skin = new Skin(null, defaultSkinType);
129129
}
130130

131-
return new UserProfile
131+
return new PlayerProfile
132132
{
133133
UUID = uuid ?? "",
134134
Name = name,
@@ -137,8 +137,8 @@ private async Task<UserProfile> uuidProfileResponseHandler(HttpResponseMessage r
137137
};
138138
}
139139

140-
public Task<UserProfile> GetProfileUsingAccessToken(string accessToken) =>
141-
client.SendActionAsync(new HttpAction<UserProfile>
140+
public Task<PlayerProfile> GetProfileUsingAccessToken(string accessToken) =>
141+
client.SendActionAsync(new HttpAction<PlayerProfile>
142142
{
143143
Method = HttpMethod.Get,
144144
Host = "https://api.minecraftservices.com",
@@ -152,14 +152,14 @@ public Task<UserProfile> GetProfileUsingAccessToken(string accessToken) =>
152152
ResponseHandler = atProfileResponseHandler
153153
});
154154

155-
private async Task<UserProfile> atProfileResponseHandler(HttpResponseMessage response)
155+
private async Task<PlayerProfile> atProfileResponseHandler(HttpResponseMessage response)
156156
{
157157
string responseContent = await response.Content.ReadAsStringAsync();
158158
JObject job = JObject.Parse(responseContent);
159159

160160
var skinObj = job["skins"]?[0];
161161

162-
return new UserProfile
162+
return new PlayerProfile
163163
{
164164
UUID = job["id"]?.ToString() ?? "",
165165
Name = job["name"]?.ToString() ?? "",
@@ -172,12 +172,12 @@ private async Task<UserProfile> atProfileResponseHandler(HttpResponseMessage res
172172
};
173173
}
174174

175-
public Task<UserProfile> ChangeName(string accessToken, string newName) =>
176-
client.SendActionAsync(new HttpAction<UserProfile>
175+
public Task<PlayerProfile> ChangeName(string accessToken, string newName) =>
176+
client.SendActionAsync(new HttpAction<PlayerProfile>
177177
{
178178
Method = HttpMethod.Put,
179-
//Host = "https://api.minecraftservices.com",
180-
Host = "http://localhost:7777",
179+
Host = "https://api.minecraftservices.com",
180+
//Host = "http://localhost:7777",
181181
Path = $"minecraft/profile/name/{newName}",
182182

183183
RequestHeaders = new HttpHeaderCollection
@@ -186,7 +186,7 @@ public Task<UserProfile> ChangeName(string accessToken, string newName) =>
186186
},
187187

188188
ResponseHandler = atProfileResponseHandler,
189-
ErrorHandler = HttpResponseHandlers.GetJsonErrorHandler<UserProfile>(),
189+
ErrorHandler = HttpResponseHandlers.GetJsonErrorHandler<PlayerProfile>(),
190190

191191
CheckValidation = (h) =>
192192
{
@@ -200,8 +200,8 @@ public Task<MojangAPIResponse> ChangeSkin(string uuid, string accessToken, SkinT
200200
client.SendActionAsync(new HttpAction<MojangAPIResponse>
201201
{
202202
Method = HttpMethod.Post,
203-
//Host = "https://api.mojang.com",
204-
Host = "http://localhost:7777",
203+
Host = "https://api.mojang.com",
204+
//Host = "http://localhost:7777",
205205
Path = $"user/profile/{uuid}/skin",
206206

207207
RequestHeaders = new HttpHeaderCollection
@@ -237,13 +237,13 @@ public Task<MojangAPIResponse> UploadSkin(string accessToken, SkinType skinType,
237237
Stream fileStream = File.OpenRead(skinPath);
238238
return UploadSkin(accessToken, skinType, fileStream, filename);
239239
}
240-
240+
241241
public Task<MojangAPIResponse> UploadSkin(string accessToken, SkinType skinType, Stream skinStream, string filename) =>
242242
client.SendActionAsync(new HttpAction<MojangAPIResponse>
243243
{
244244
Method = HttpMethod.Put,
245-
//Host = "https://api.minecraftservices.com",
246-
Host = "http://localhost:7777",
245+
Host = "https://api.minecraftservices.com",
246+
//Host = "http://localhost:7777",
247247
Path = "minecraft/profile/skins",
248248

249249
RequestHeaders = new HttpHeaderCollection
@@ -277,8 +277,8 @@ public Task<MojangAPIResponse> ResetSkin(string uuid, string accessToken) =>
277277
client.SendActionAsync(new HttpAction<MojangAPIResponse>
278278
{
279279
Method = HttpMethod.Delete,
280-
//Host = "https://api.mojang.com",
281-
Host = "http://localhost:7777",
280+
Host = "https://api.mojang.com",
281+
//Host = "http://localhost:7777",
282282
Path = $"user/profile/{uuid}/skin",
283283

284284
RequestHeaders = new HttpHeaderCollection

MojangAPI/MojangAPI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<LangVersion>8.0</LangVersion>
77
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
88
<Description>Mojang API, Authenticate</Description>
9-
<PackageLicenseExpression>mit</PackageLicenseExpression>
9+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1010
<RepositoryUrl>https://github.com/AlphaBs/MojangAPI</RepositoryUrl>
1111
</PropertyGroup>
1212

MojangAPI/MojangAuth.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public Task<MojangAuthResponse> Signout(string email, string password) =>
256256
ErrorHandler = errorResponseHandler
257257
});
258258

259-
public Task<MojangAuthResponse> Invalidte()
259+
public Task<MojangAuthResponse> Invalidate()
260260
{
261261
Session? cachedSession = cacheManager?.ReadCache();
262262
if (cachedSession == null || string.IsNullOrEmpty(cachedSession.AccessToken))
@@ -326,7 +326,7 @@ public async Task<MojangAuthResponse> RequestSessionWithXbox(string uhs, string
326326
if (!await mojang.CheckGameOwnership(authResponse.AccessToken!))
327327
return new MojangAuthResponse(MojangAuthResult.NoProfile);
328328

329-
UserProfile profile = await mojang.GetProfileUsingAccessToken(authResponse.AccessToken!);
329+
PlayerProfile profile = await mojang.GetProfileUsingAccessToken(authResponse.AccessToken!);
330330
Session session = new Session
331331
{
332332
Username = profile.Name,

MojangAPISample/Program.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace MojangAPISample
99
{
1010
class Program
1111
{
12-
static HttpClient httpClient = new HttpClient();
12+
static readonly HttpClient httpClient = new HttpClient();
1313

1414
static async Task Main(string[] args)
1515
{
@@ -35,7 +35,7 @@ static async Task Main(string[] args)
3535
static async Task testMojangAPIs(Mojang mojang, Session session)
3636
{
3737
Console.WriteLine("GetUUID");
38-
UserUUID uuid = await mojang.GetUUID(session.Username);
38+
PlayerUUID uuid = await mojang.GetUUID(session.Username);
3939
printResponse(uuid);
4040
Console.WriteLine($"UUID: {uuid.UUID}, IsLegacy: {uuid.IsLegacy}, IsDemo: {uuid.IsDemo}\n");
4141

@@ -53,13 +53,13 @@ static async Task testMojangAPIs(Mojang mojang, Session session)
5353
Console.WriteLine();
5454

5555
Console.WriteLine("GetProfileUsingUUID");
56-
UserProfile uuidProfile = await mojang.GetProfileUsingUUID(session.UUID);
56+
PlayerProfile uuidProfile = await mojang.GetProfileUsingUUID(session.UUID);
5757
printResponse(uuidProfile);
5858
printProfile(uuidProfile);
5959
Console.WriteLine();
6060

6161
Console.WriteLine("GetProfileUsingAccessToken");
62-
UserProfile atProfile = await mojang.GetProfileUsingAccessToken(session.AccessToken);
62+
PlayerProfile atProfile = await mojang.GetProfileUsingAccessToken(session.AccessToken);
6363
printResponse(atProfile);
6464
printProfile(atProfile);
6565
Console.WriteLine();
@@ -145,15 +145,14 @@ static async Task testSecurityFlow(QuestionFlow q, Session session)
145145
throw new Exception("failed to get questions");
146146

147147
QuestionList questions = res.Questions;
148-
int qCount = 1;
149-
foreach (var item in questions)
148+
for (int i = 0; i < questions.Count; i++)
150149
{
151-
Console.WriteLine($"Q{qCount}. [{item.QuestionId}] {item.QuestionMessage}");
150+
Question question = questions[i];
151+
Console.WriteLine($"Q{i + 1}. [{question.QuestionId}] {question.QuestionMessage}");
152152
Console.Write("Answer? : ");
153153

154154
var answer = Console.ReadLine();
155-
item.Answer = answer;
156-
qCount++;
155+
question.Answer = answer;
157156
Console.WriteLine();
158157
}
159158

@@ -169,7 +168,7 @@ static async Task testSecurityFlow(QuestionFlow q, Session session)
169168
static async Task test_DANGEROUS_apis(Mojang mojang, Session session)
170169
{
171170
Console.WriteLine("ChangeName");
172-
UserProfile changeNameProfile = await mojang.ChangeName(session.AccessToken, "NEWNAME");
171+
PlayerProfile changeNameProfile = await mojang.ChangeName(session.AccessToken, "NEWNAME");
173172
printResponse(changeNameProfile);
174173
printProfile(changeNameProfile);
175174

@@ -196,7 +195,7 @@ static void printResponse(MojangAPIResponse res)
196195

197196
}
198197

199-
static void printProfile(UserProfile profile)
198+
static void printProfile(PlayerProfile profile)
200199
{
201200
if (!profile.IsSuccess)
202201
return;

0 commit comments

Comments
 (0)