mirror of
https://github.com/LCE-Hub/LCE-Emerald-Launcher.git
synced 2026-07-19 00:37:07 +00:00
feat: LCEOnline instead of LCELive
This commit is contained in:
parent
b2e3b2a322
commit
465bffd4a7
|
|
@ -23,8 +23,6 @@ const LceOnlineView = memo(function LceOnlineView({
|
|||
const [incomingReqs, setIncomingReqs] = useState<string[]>([]);
|
||||
const [outgoingReqs, setOutgoingReqs] = useState<string[]>([]);
|
||||
const [isHosting, setIsHosting] = useState(false);
|
||||
const [_hostStatus, setHostStatus] = useState("");
|
||||
const [isDiscovering, setIsDiscovering] = useState(false);
|
||||
const [isAddingFriend, setIsAddingFriend] = useState(false);
|
||||
const [addFriendUsername, setAddFriendUsername] = useState("");
|
||||
const addFriendInputRef = useRef<HTMLInputElement>(null);
|
||||
|
|
@ -80,14 +78,12 @@ const LceOnlineView = memo(function LceOnlineView({
|
|||
|
||||
const handleStartHosting = async () => {
|
||||
playPressSound();
|
||||
setIsDiscovering(true);
|
||||
setHostStatus("Starting relay...");
|
||||
try {
|
||||
await TauriService.stunDiscover();
|
||||
} catch {}
|
||||
setIsHosting(true);
|
||||
setHostStatus("Relay ready");
|
||||
setIsDiscovering(false);
|
||||
await TauriService.startHostRelay(lceOnlineService.accessToken ?? "", 25565);
|
||||
setIsHosting(true);
|
||||
} catch (e: unknown) {
|
||||
setErrorModal(e instanceof Error ? e.message : "Failed to start relay");
|
||||
}
|
||||
};
|
||||
|
||||
const handleStopHosting = async () => {
|
||||
|
|
@ -98,7 +94,6 @@ const LceOnlineView = memo(function LceOnlineView({
|
|||
console.warn("Stop hosting failed", e);
|
||||
}
|
||||
setIsHosting(false);
|
||||
setHostStatus("");
|
||||
};
|
||||
|
||||
const handleAuth = async () => {
|
||||
|
|
@ -129,22 +124,20 @@ const LceOnlineView = memo(function LceOnlineView({
|
|||
const menuItems = useMemo<MenuItem[]>(() => {
|
||||
const items: MenuItem[] = [];
|
||||
if (currentTab === "friends") {
|
||||
if (!isDiscovering) {
|
||||
if (!isHosting) {
|
||||
items.push({
|
||||
id: "host_game",
|
||||
type: "button",
|
||||
label: "Host Game",
|
||||
onClick: handleStartHosting,
|
||||
});
|
||||
} else {
|
||||
items.push({
|
||||
id: "stop_hosting",
|
||||
type: "button",
|
||||
label: "Stop Hosting",
|
||||
onClick: handleStopHosting,
|
||||
});
|
||||
}
|
||||
if (!isHosting) {
|
||||
items.push({
|
||||
id: "host_game",
|
||||
type: "button",
|
||||
label: "Host Game",
|
||||
onClick: handleStartHosting,
|
||||
});
|
||||
} else {
|
||||
items.push({
|
||||
id: "stop_hosting",
|
||||
type: "button",
|
||||
label: "Stop Hosting",
|
||||
onClick: handleStopHosting,
|
||||
});
|
||||
}
|
||||
items.push({
|
||||
id: "add_friend",
|
||||
|
|
@ -201,7 +194,6 @@ const LceOnlineView = memo(function LceOnlineView({
|
|||
outgoingReqs,
|
||||
playPressSound,
|
||||
isHosting,
|
||||
isDiscovering,
|
||||
]);
|
||||
|
||||
const tabs: ("friends" | "requests")[] = ["friends", "requests"];
|
||||
|
|
|
|||
|
|
@ -52,38 +52,32 @@ export class LceOnlineService {
|
|||
}
|
||||
|
||||
async login(username: string, password: string): Promise<void> {
|
||||
const res = await this.request<{ body: string }>(
|
||||
const res = await this.request<string>(
|
||||
"POST",
|
||||
"/login",
|
||||
`${username}:${password}`,
|
||||
AUTH_BASE_URL,
|
||||
);
|
||||
console.log("auth login response", res);
|
||||
const pretoken =
|
||||
res && typeof res === "object" && "body" in res
|
||||
? (res as any).body
|
||||
: typeof res === "string"
|
||||
? res
|
||||
: "";
|
||||
const token = pretoken.split(":")[1];
|
||||
const text = typeof res === "string" ? res : "";
|
||||
if (!text.startsWith("-")) {
|
||||
throw new Error(text || "Login failed");
|
||||
}
|
||||
const token = text.split(":")[1];
|
||||
this.loginWithToken(token, username);
|
||||
}
|
||||
|
||||
async register(username: string, password: string): Promise<void> {
|
||||
const res = await this.request<{ body: string }>(
|
||||
const res = await this.request<string>(
|
||||
"POST",
|
||||
"/register",
|
||||
`${username}:${password}`,
|
||||
AUTH_BASE_URL,
|
||||
);
|
||||
console.log("auth register response", res);
|
||||
const pretoken =
|
||||
res && typeof res === "object" && "body" in res
|
||||
? (res as any).body
|
||||
: typeof res === "string"
|
||||
? res
|
||||
: "";
|
||||
const token = pretoken.split(":")[1];
|
||||
const text = typeof res === "string" ? res : "";
|
||||
if (!text.startsWith("-")) {
|
||||
throw new Error(text || "Registration failed");
|
||||
}
|
||||
const token = text.split(":")[1];
|
||||
this.loginWithToken(token, username);
|
||||
}
|
||||
|
||||
|
|
@ -190,19 +184,31 @@ export class LceOnlineService {
|
|||
}
|
||||
|
||||
async sendFriendRequest(target: string): Promise<void> {
|
||||
await this.request("POST", "/sendrequest", target);
|
||||
const res = await this.request<string>("POST", "/sendrequest", target);
|
||||
if (typeof res === "string" && res !== "Successfully Sent Friend Request") {
|
||||
throw new Error(res);
|
||||
}
|
||||
}
|
||||
|
||||
async acceptFriendRequest(from: string): Promise<void> {
|
||||
await this.request("POST", "/acceptrequest", from);
|
||||
const res = await this.request<string>("POST", "/acceptrequest", from);
|
||||
if (typeof res === "string" && res !== "1") {
|
||||
throw new Error(res);
|
||||
}
|
||||
}
|
||||
|
||||
async declineFriendRequest(from: string): Promise<void> {
|
||||
await this.request("POST", "/declinerequest", from);
|
||||
const res = await this.request<string>("POST", "/declinerequest", from);
|
||||
if (typeof res === "string" && res !== "1") {
|
||||
throw new Error(res);
|
||||
}
|
||||
}
|
||||
|
||||
async removeFriend(from: string): Promise<void> {
|
||||
await this.request("POST", "/removefriend", from);
|
||||
const res = await this.request<string>("POST", "/removefriend", from);
|
||||
if (typeof res === "string") {
|
||||
throw new Error(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue