feat(LCEOnline): JSON instead of colons (#176)

This commit is contained in:
str1k3r 2026-08-07 21:29:57 -04:00 committed by GitHub
parent 072f3f0cb6
commit d890f9b94a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 17 deletions

View file

@ -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)),
});

View file

@ -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 {}

View file

@ -83,7 +83,7 @@ export class LceOnlineService {
const res = await this.request<string>(
"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<string>(
"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<string>("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<T> {
const headers: Record<string, string> = {
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<string>("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<void> {
const res = await this.request<string>("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;
}
}