diff --git a/src/components/views/LceOnlineView.tsx b/src/components/views/LceOnlineView.tsx index 53a15f5..3df6ab0 100644 --- a/src/components/views/LceOnlineView.tsx +++ b/src/components/views/LceOnlineView.tsx @@ -191,7 +191,7 @@ const LceOnlineView = memo(function LceOnlineView({ items.push({ id: `friend_${f.username}`, type: "friend", - label: f.displayName, + label: f.displayName || f.username, onClick: () => handleAction(() => lceOnlineService.removeFriend(f.username)), onClickSecondary: isHosting ? () => handleAction(() => lceOnlineService.sendInvite(f.username)) @@ -203,7 +203,7 @@ const LceOnlineView = memo(function LceOnlineView({ items.push({ id: `req_in_${r.username}`, type: "request_in", - label: r.displayName, + label: r.displayName || r.username, onClick: () => handleAction(() => lceOnlineService.acceptFriendRequest(r.username)), onClickSecondary: () => @@ -214,7 +214,7 @@ const LceOnlineView = memo(function LceOnlineView({ items.push({ id: `req_out_${r.username}`, type: "request_out", - label: r.displayName, + label: r.displayName || r.username, onClick: () => handleAction(() => lceOnlineService.declineFriendRequest(r.username)), }); diff --git a/src/hooks/useLceOnlineNotifications.ts b/src/hooks/useLceOnlineNotifications.ts index 7f70dac..d37b6ca 100644 --- a/src/hooks/useLceOnlineNotifications.ts +++ b/src/hooks/useLceOnlineNotifications.ts @@ -20,7 +20,7 @@ export function useLceOnlineNotifications() { requestsData.requests.forEach((r) => { if (!seenRequests.current.has(r.username)) { seenRequests.current.add(r.username); - setFriendRequestMessage(`${r.displayName} wants to be friends!`); + setFriendRequestMessage(`${r.displayName || r.username} wants to be friends!`); } }); } catch (e) {} @@ -30,7 +30,7 @@ export function useLceOnlineNotifications() { invitesData.forEach((i) => { if (!seenInvites.current.has(i.inviteid)) { seenInvites.current.add(i.inviteid); - setInviteMessage(`${i.from.displayName} invited you to play!`); + setInviteMessage(`${i.from.displayName || i.from.username} invited you to play!`); } }); } catch {} @@ -53,7 +53,7 @@ export function useLceOnlineNotifications() { invitesData.forEach((i) => { if (!seenInvites.current.has(i.inviteid)) { seenInvites.current.add(i.inviteid); - setInviteMessage(`${i.from.displayName} invited you to play!`); + setInviteMessage(`${i.from.displayName || i.from.username} invited you to play!`); } }); } catch {} diff --git a/src/services/LceOnlineService.ts b/src/services/LceOnlineService.ts index 60d6ba7..30ebc0a 100644 --- a/src/services/LceOnlineService.ts +++ b/src/services/LceOnlineService.ts @@ -83,7 +83,7 @@ export class LceOnlineService { const res = await this.request( "POST", "/login", - `${username}:${password}`, + `${JSON.stringify({ username: username, password: password })}`, AUTH_BASE_URL, ); const text = typeof res === "string" ? res : ""; @@ -98,7 +98,7 @@ export class LceOnlineService { const res = await this.request( "POST", "/register", - `${username}:${password}`, + `${JSON.stringify({ username: username, password: password })}`, AUTH_BASE_URL, ); const text = typeof res === "string" ? res : ""; @@ -128,9 +128,10 @@ export class LceOnlineService { this._notify(); try { const raw: string = await this.request("POST", "/accountinfo"); - if (typeof raw === "string" && raw.startsWith("-")) { - const username = raw.slice(1); - this._session!.account = { username, displayName: username }; + if (typeof raw === "object" && raw !== null) { + const data = JSON.parse(raw); + const username = data.username; + this._session!.account = { username, displayName: data.displayName }; this.saveSession(); this._notify(); } @@ -166,7 +167,7 @@ export class LceOnlineService { ): Promise { const headers: Record = { Accept: "text/plain, application/json", - "User-Agent": "MCLCE-LCEOnline/1.0", + "User-Agent": "MCLCE-LCEOnline/1.1", // str1k3r - changed the user agent to use 1.1 so older versions use older apis & get older responses. }; if (body) { @@ -217,9 +218,9 @@ export class LceOnlineService { try { const res = await this.request("POST", "/refreshtoken", null, AUTH_BASE_URL); if (typeof res === "string" && res.startsWith("-")) { - const [username, token] = res.slice(1).split(":"); - this._session.accessToken = token; - this._session.account = { username, displayName: username }; + const data = JSON.parse(res); + this._session.accessToken = data.token; + this._session.account = { username: data.username, displayName: data.displayName }; this.saveSession(); this._notify(); return true; @@ -273,7 +274,7 @@ export class LceOnlineService { async sendInvite(target: string): Promise { const res = await this.request("POST", "/invite", target); - if (typeof res === "string" && res !== "Invite Sent") { + if (typeof res === "string" && res !== "Successfully Sent Invite") { throw new Error(res); } } @@ -289,7 +290,7 @@ export class LceOnlineService { await this.request("POST", "/declineinvite", from); } catch (e: unknown) { const msg = e instanceof Error ? e.message : ""; - if (msg !== "Declined Invite") throw e; + if (msg !== "Successfully Declined Invite") throw e; } }