mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-17 23:33:12 +09:00
Add version and connect button to player auth
This commit is contained in:
3 files changed
+111
-18
No files matched your search
@@ -3,6 +3,7 @@ import React, { useEffect, useState } from "react";
|
||||
import { BaseWebPlugin, notifyErrorHandler } from "@clusterio/web_ui";
|
||||
import { Button, Form, Input, Spin, Typography } from "antd";
|
||||
|
||||
import { PlayerAuthServer } from "../messages";
|
||||
import "./style.css";
|
||||
|
||||
const { Paragraph, Text } = Typography;
|
||||
@@ -12,21 +13,39 @@ interface LoginFormProps {
|
||||
}
|
||||
|
||||
function LoginForm(props: LoginFormProps) {
|
||||
let [servers, setServers] = useState<string[] | null>(null);
|
||||
const [servers, setServers] = useState<PlayerAuthServer[] | null>(null);
|
||||
let [playerCode, setPlayerCode] = useState<string | null>(null);
|
||||
let [playerCodeError, setPlayerCodeError] = useState<string | null>(null);
|
||||
let [verifyCode, setVerifyCode] = useState<string | undefined>();
|
||||
let [verifyToken, setVerifyToken] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
let cancelled = false;
|
||||
|
||||
async function load() {
|
||||
let response = await fetch(`${webRoot}api/player_auth/servers`);
|
||||
if (response.ok) {
|
||||
setServers(await response.json());
|
||||
} else {
|
||||
setServers([]);
|
||||
if (!response.ok) {
|
||||
if (!cancelled) {
|
||||
setServers([]);
|
||||
const err = new Error(await response.text());
|
||||
notifyErrorHandler("Error retrieving servers")(err);
|
||||
}
|
||||
return;
|
||||
}
|
||||
})();
|
||||
|
||||
const json = await response.json();
|
||||
if (!cancelled) {
|
||||
setServers(json.map((s: any) => PlayerAuthServer.fromJSON(s)));
|
||||
}
|
||||
}
|
||||
|
||||
load();
|
||||
const interval = setInterval(load, 15 * 1000);
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
clearInterval(interval);
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -61,7 +80,7 @@ function LoginForm(props: LoginFormProps) {
|
||||
clearInterval(checkLoop);
|
||||
notifyErrorHandler("Error verifying code")(err);
|
||||
});
|
||||
}, 2000);
|
||||
}, 2 * 1000);
|
||||
return () => { clearInterval(checkLoop); };
|
||||
}
|
||||
|
||||
@@ -74,8 +93,8 @@ function LoginForm(props: LoginFormProps) {
|
||||
|
||||
if (servers.length === 0) {
|
||||
return <Paragraph>
|
||||
There are no servers in the cluster currently running that can complete
|
||||
the login via Factorio. Please try again later.
|
||||
There are no running servers available for login via Factorio at the moment.
|
||||
Please try again later.
|
||||
</Paragraph>;
|
||||
}
|
||||
|
||||
@@ -89,9 +108,35 @@ function LoginForm(props: LoginFormProps) {
|
||||
Start Factorio, join one of the following multiplayer servers
|
||||
and type <Text keyboard>/web-login</Text> into the chat:
|
||||
</Paragraph>
|
||||
<div style={{ maxHeight: 160, overflowY: "auto", paddingLeft: 16 }}>
|
||||
<ul>
|
||||
{servers.map(text => <li key={text}>{text}</li>)}
|
||||
<div style={{ maxHeight: 160, overflowY: "auto", paddingLeft: 16, padding: "8px 0" }}>
|
||||
<ul style={{ margin: 0, paddingLeft: 16 }}>
|
||||
{servers.map(server => (
|
||||
<li key={server.address} style={{ marginBottom: 6 }}>
|
||||
<div style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "1fr auto",
|
||||
alignItems: "center",
|
||||
gap: 8,
|
||||
}}>
|
||||
<span>
|
||||
{server.name}
|
||||
{server.factorioVersion && (
|
||||
<Text type="secondary"> ({server.factorioVersion})</Text>
|
||||
)}
|
||||
</span>
|
||||
|
||||
<Button
|
||||
size="small"
|
||||
onClick={() => {
|
||||
window.location.href =
|
||||
`steam://run/427520//--mp-connect=${server.address}`;
|
||||
}}
|
||||
>
|
||||
Connect
|
||||
</Button>
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
Reference in new issue
Block a user