Skip to content

Commit

Permalink
Add Factorio player name listing
Browse files Browse the repository at this point in the history
  • Loading branch information
Nebual committed Dec 21, 2022
1 parent 6a9a696 commit dc17223
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
16 changes: 15 additions & 1 deletion game-api/src/games/factorio.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,21 @@ module.exports = class FactorioManager {
console.warn("unexpected playerList:", playerList);
return false;
}
return [...new Array(Number(matches[1]))].map((_) => ({}));
const playerCount = Number(matches[1]);
if (playerCount > 0) {
return playerList
.split("\n")
.slice(1)
.map((line) => {
const lineMatch = line.match(/ (.*) \(online\)/);
if (lineMatch) {
return { name: lineMatch[1] };
}
return false;
})
.filter(Boolean);
}
return [...new Array(playerCount)].map((_) => ({}));
}
async logs(requestedOffset) {
const { logs, offset } = await dockerLogRead(requestedOffset);
Expand Down
10 changes: 5 additions & 5 deletions ui/src/components/ServerCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ export default function ServerCard({
? "Updating"
: "Status Unknown";

const playerNamesString = players.map(({ name }) => name).join(", ");

return (
<Card
raised={["starting", "running", "stopping", "updating"].includes(status)}
Expand Down Expand Up @@ -220,10 +222,8 @@ export default function ServerCard({
`${smallScreen ? "" : " with"} ${
numPlayers !== undefined ? numPlayers : "?"
} players`}
{players.length > 0 && (
<Tooltip
title={players.map(({ name }) => name).join(", ")}
>
{playerNamesString.length > 0 && (
<Tooltip title={playerNamesString}>
<div
style={{
textAlign: "right",
Expand All @@ -234,7 +234,7 @@ export default function ServerCard({
fontSize: "0.8rem",
}}
>
{players.map(({ name }) => name).join(", ")}
{playerNamesString}
</div>
</Tooltip>
)}
Expand Down

0 comments on commit dc17223

Please sign in to comment.