diff --git a/docs/advanced/tech-stack.mdx b/docs/advanced/tech-stack.mdx
index a8bb2b4..f8768cc 100644
--- a/docs/advanced/tech-stack.mdx
+++ b/docs/advanced/tech-stack.mdx
@@ -11,7 +11,7 @@ The tech stack of MHSF is relatively modern to ensure MHSF keeps up with standar
- **shadcn/ui** is the UI framework used to keep the whole website consistent.
- **Contentlayer** manages all the pages used for documentation
- **TailwindCSS** makes MHSF use (mostly) no CSS for better efficency
-- **react-hot-toast** provides the Toast used for MHSF
+- **Sonner** provides the Toast used for MHSF
## Back-end
- **Inngest** runs periodic tasks
diff --git a/docs/guides/owning-a-server.mdx b/docs/guides/owning-a-server.mdx
index a60eae5..702f0df 100644
--- a/docs/guides/owning-a-server.mdx
+++ b/docs/guides/owning-a-server.mdx
@@ -14,4 +14,8 @@ If they match, you should see a button named Click to own. Press that button, an
## I can't link my server, because my server doesn't have a author
-Your server must have an author in-order to be automagically linked, and if it doesn't have an author, that means you will have to manually link your server. To do that, make an issue on GitHub, showing that your server has no author, but needs to be linked. Show proof that you own the server, along with your account username, and your account will own the server you need.
\ No newline at end of file
+Your server must have an author in-order to be automagically linked, and if it doesn't have an author, that means you will have to manually link your server. To do that, make an issue on GitHub, showing that your server has no author, but needs to be linked. Show proof that you own the server, along with your account username, and your account will own the server you need.
+
+## There is an error while linking my server!
+This most likely is because the Minehut API is blocking the server-side request to verify your the owner of that server, or your server [has no author](#i-cant-link-my-server-because-my-server-doesnt-have-a-author).
+Try again in 30 minute intervals, or just make an issue on GitHub to link your server.
\ No newline at end of file
diff --git a/package.json b/package.json
index bd4c935..4b62add 100644
--- a/package.json
+++ b/package.json
@@ -33,6 +33,7 @@
"@unocss/postcss": "^0.61.5",
"@unocss/transformer-directives": "^0.61.5",
"@unocss/webpack": "^0.61.5",
+ "ag-grid-react": "^33.0.3",
"contentlayer": "^0.3.4",
"cron": "^3.1.7",
"discord.js": "^14.15.3",
diff --git a/src/app/(main)/server/[server]/layout.tsx b/src/app/(main)/server/[server]/layout.tsx
new file mode 100644
index 0000000..eabbd18
--- /dev/null
+++ b/src/app/(main)/server/[server]/layout.tsx
@@ -0,0 +1,51 @@
+/*
+ * MHSF, Minehut Server List
+ * All external content is rather licensed under the ECA Agreement
+ * located here: https://mhsf.app/docs/legal/external-content-agreement
+ *
+ * All code under MHSF is licensed under the MIT License
+ * by open source contributors
+ *
+ * Copyright (c) 2024 dvelo
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+"use client";
+
+import { LoadingSpinner } from "@/components/ui/loading-spinner";
+import { useServerExists } from "@/lib/hooks/use-server-exists";
+import { notFound } from "next/navigation";
+
+export default function ServerLayout({
+ params,
+ children,
+}: {
+ params: { server: string };
+ children: React.ReactNode;
+}) {
+ const { serverExists, loading } = useServerExists(params.server);
+
+ if (loading) return ;
+
+ if (!serverExists) notFound();
+
+ return children;
+}
diff --git a/src/app/(main)/server/[server]/statistics/page.tsx b/src/app/(main)/server/[server]/statistics/page.tsx
index a009481..6c80b7f 100644
--- a/src/app/(main)/server/[server]/statistics/page.tsx
+++ b/src/app/(main)/server/[server]/statistics/page.tsx
@@ -30,12 +30,12 @@
import Banner from "@/components/Banner";
import ColorProvider from "@/components/ColorProvider";
-import { NewChart } from "@/components/NewChart";
+import { NewChart } from "@/components/charts/NewChart";
import ServerView from "@/components/ServerView";
import TabServer from "@/components/misc/TabServer";
-import { Separator } from "@/components/ui/separator";
import type { Metadata, ResolvingMetadata } from "next";
import StickyTopbar from "@/components/misc/StickyTopbar";
+import { RelativeChart } from "@/components/charts/RelativeChart";
type Props = {
params: { server: string };
@@ -101,17 +101,18 @@ export default function ServerPage({ params }: { params: { server: string } }) {
-
-
- <>
- Meet MHSF, the modern
- server finder
- >
-
-
- MHSF is the next generation server list for Minehut, with
- interactive filters, {" "}
- intuitive keyboard shortcuts, and everything between.
-
+ return (
+
+
+ <>
+ {(!isSignedIn || hero) && (
+
+
+
+ <>
+ Meet MHSF, the modern
+ server finder
+ >
+
+
+ MHSF is the next generation server list for Minehut, with
+ interactive filters, {" "}
+ intuitive keyboard shortcuts, and everything between.
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
- For players
-
-
-
-
- Find what you want now, not later
-
-
- Use interactive filters and customization modes to find the
- server of your choice
- in less than 10 minutes.
-
-
-
-
-
+
+
+
+
+
+
+
+ For players
+
+
+
+
+ Find what you want now, not later
+
+
+ Use interactive filters and customization modes to find the
+ server of your choice
+ in less than 10 minutes.
+
+
+
+
+
-
-
-
-
- For server owners
-
-
-
-
- Make your server stand out
-
-
- Servers can have custom banners, Discord widgets, color schemes,
- and descriptions, making your server stand out with information
- that can be shown to players.
-
+ Servers can have custom banners, Discord widgets, color schemes,
+ and descriptions, making your server stand out with information
+ that can be shown to players.
+
- {serverList.getExtraData().total_servers >= 3200 && (
-
-
-
-
-
- The server amount is over 3.2k, meaning that new servers
- have to go into a queue before being able to be online.{" "}
-
- (the server count isn't entirely accurate, so sometimes
- you might not go into a queue even when the server count
- is at 3.2k)
-
-
- )}
-
+ {serverList.getExtraData().total_servers >= 3200 && (
+
+
+
+
+
+ The server amount is over 3.2k, meaning that new servers
+ have to go into a queue before being able to be online.{" "}
+
+ (the server count isn't entirely accurate, so sometimes
+ you might not go into a queue even when the server count
+ is at 3.2k)
+
+
+ )}
+
+ );
}
diff --git a/src/components/ServerView.tsx b/src/components/ServerView.tsx
index f78fa0a..f305283 100644
--- a/src/components/ServerView.tsx
+++ b/src/components/ServerView.tsx
@@ -58,8 +58,9 @@ import IconDisplay from "./IconDisplay";
import { useClerk, useUser } from "@clerk/nextjs";
import { LoaderIcon } from "react-hot-toast";
import { Separator } from "./ui/separator";
-import { convert } from "@/components/NewChart";
+import { convert } from "@/components/charts/NewChart";
import { LoadingSpinner } from "./ui/loading-spinner";
+import { BadgeOfAffiliation } from "./Icon";
export default function ServerView(props: { server: string }) {
const [single, setSingle] = useState(new ServerSingle(props.server));
@@ -169,6 +170,22 @@ export default function ServerView(props: { server: string }) {
/>
)}
{props.server}
+ {props.server === "CoreBoxx" && (
+
+
+
+
+
+
+
+
+ CoreBoxx is an official affiliate of MHSF. This server was
+ found to be a high-quality server and should be a
+ good join for any player!
+
+
+
+ )}
{/* 1704088800000 is the Unix time (in milliseconds) of (GMT) Monday, January 1, 2024 6:00:00 AM */}
diff --git a/src/components/NewChart.tsx b/src/components/charts/NewChart.tsx
similarity index 70%
rename from src/components/NewChart.tsx
rename to src/components/charts/NewChart.tsx
index dcd75b9..7e592bb 100644
--- a/src/components/NewChart.tsx
+++ b/src/components/charts/NewChart.tsx
@@ -31,7 +31,14 @@
"use client";
import * as React from "react";
-import { CartesianGrid, Line, LineChart, XAxis, YAxis } from "recharts";
+import {
+ CartesianGrid,
+ Line,
+ LineChart,
+ XAxis,
+ YAxis,
+ ReferenceLine,
+} from "recharts";
import {
Card,
@@ -49,8 +56,16 @@ import {
import { useEffectOnce } from "@/lib/useEffectOnce";
import { ServerResponse } from "@/lib/types/mh-server";
import { getCommunityServerFavorites, getShortTermData } from "@/lib/api";
-import { Skeleton } from "./ui/skeleton";
+import { Skeleton } from "../ui/skeleton";
import FadeIn from "react-fade-in/lib/FadeIn";
+import {
+ Select,
+ SelectContent,
+ SelectGroup,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select";
const chartConfig = {
player_count: {
@@ -68,15 +83,20 @@ export function NewChart({ server }: { server: string }) {
React.useState("player_count");
const [chartData, setChartData] = React.useState([]);
+ const [allData, setAllData] = React.useState([]);
const [joins, setJoins] = React.useState(0);
const [loading, setLoading] = React.useState(true);
+ const [dataMax, setDataMax] = React.useState(0);
const [favorites, setFavorites] = React.useState(0);
+ const [filter, setFilter] = React.useState("60");
const allNums = { player_count: joins, favorites };
useEffectOnce(() => {
getShortTermData(server, ["player_count", "favorites", "date"]).then(
(c) => {
- setChartData(c);
+ setAllData(c.data);
+ setChartData(c.data.slice(-60));
+ setDataMax(c.dataMax);
getCommunityServerFavorites(server).then((b) => setFavorites(b));
fetch("https://api.minehut.com/server/" + server + "?byName=true").then(
(k) => {
@@ -90,6 +110,14 @@ export function NewChart({ server }: { server: string }) {
);
});
+ React.useEffect(() => {
+ if (filter === "all") {
+ setChartData(allData);
+ } else {
+ setChartData(allData.slice(Number(filter) * -1));
+ }
+ }, [filter, allData]);
+
if (loading)
return (
<>
@@ -105,7 +133,29 @@ export function NewChart({ server }: { server: string }) {
{chartConfig[activeChart].label} Chart for {server}
- Showing the past 30 entries.
+
+ Showing {filter !== "all" && <>the last>}{" "}
+ {" "}
+ {filter === "all" && <>of the>} entries.
+
{["player_count", "favorites"].map((key) => {
@@ -149,9 +199,7 @@ export function NewChart({ server }: { server: string }) {
tickMargin={8}
minTickGap={32}
tickFormatter={(value) => {
- return new Date(value).toLocaleTimeString("en-US", {
- timeStyle: "short",
- });
+ return `${new Date(value).getMonth() + 1}/${new Date(value).getDate()}`;
}}
/>
{
- return new Date(value).toLocaleTimeString("en-US", {
+ return `${new Date(value).toLocaleDateString("en-US", {
+ day: "numeric",
+ month: "short",
+ })} ${new Date(value).toLocaleTimeString("en-US", {
timeStyle: "short",
- });
+ })}`;
}}
/>
}
/>
+ {activeChart === "player_count" && (
+
+ )}
+ >([]);
+ const [loading, setLoading] = useState(true);
+
+ useEffect(() => {
+ getRelativeServerData(server).then((d) => {
+ const newv: Array<{ relativePercentage: number; date: string }> = [];
+
+ d.forEach((c) =>
+ newv.push({
+ relativePercentage: c.relativePrecentage * 100,
+ date: c.date,
+ })
+ );
+ setChartData(newv);
+ setLoading(false);
+ });
+ }, [server]);
+
+ if (loading)
+ return (
+ <>
+
+ >
+ );
+
+ return (
+
+
+ Relative percentage of {server}
+
+ Shows the last 30 entries.{" "}
+
+
+
+
+
+ This is the percentage of players on your server
+ compared to the entire Minehut network.
+ Server players / Minehut players
+
+
+
+
+
+
+
+
+
+ `${new Date(value).toLocaleTimeString("en-US", {
+ timeStyle: "short",
+ })}`
+ }
+ />
+ `${value}%`}
+ />
+ {
+ return `${new Date(value).toLocaleDateString("en-US", {
+ day: "numeric",
+ month: "short",
+ })} ${new Date(value).toLocaleTimeString("en-US", {
+ timeStyle: "short",
+ })}`;
+ }}
+ />
+ }
+ />
+
+
+
+
+
+ );
+}
diff --git a/src/components/misc/AffiliatePopup.tsx b/src/components/misc/AffiliatePopup.tsx
new file mode 100644
index 0000000..e72a776
--- /dev/null
+++ b/src/components/misc/AffiliatePopup.tsx
@@ -0,0 +1,94 @@
+/*
+ * MHSF, Minehut Server List
+ * All external content is rather licensed under the ECA Agreement
+ * located here: https://mhsf.app/docs/legal/external-content-agreement
+ *
+ * All code under MHSF is licensed under the MIT License
+ * by open source contributors
+ *
+ * Copyright (c) 2024 dvelo
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+import {
+ DialogDescription,
+ DialogHeader,
+ DialogTitle,
+ DialogTrigger,
+} from "@/components/ui/dialog";
+import { useState } from "react";
+import useClipboard from "@/lib/useClipboard";
+import { Button } from "../ui/button";
+import { Check } from "lucide-react";
+
+export default function AffiliatePopup() {
+ const [textCopied, setTextCopied] = useState(false);
+ const clipboard = useClipboard();
+
+ return (
+
+ CoreBoxx
+
+ We won't claim to be a "unique server" or any of that. But we do aim to
+ give you the highest quality BoxPvP! Here's what we have: - 50
+ progression mines over 11 worlds, plus many more for events and other
+ items - Balanced gear sets - just because someone is a bit ahead
+ of you doesn't mean you deserve to die in one shot - We're
+ non-P2W, and we mean it! All perks are for convenience or benefit
+ everyone online! - A rapidly-growing, tight-knit community with
+ events and giveaways - Quests and storyline in development, in
+ case mining gets boring
+
+
+ CoreBoxx.minehut.gg{" "}
+
+
+ CoreBoxx is an official affiliate of MHSF. This server was found to be
+ a high-quality server and should be a good join for any player!
+
setOpen(true)} className="cursor-pointer">
+
+
+ CoreBoxx — an official affiliate of MHSF{" "}
+
+ Season 3 is out the doors for the best box server on Minehut
+
+
+
+ >
+ );
+}
+
export const bannerHooks: (() =>
| { bannerSpace: number; bannerContent: React.ReactNode }
| undefined)[] = [
() => {
- // if (process.env.NEXT_PUBLIC_VERCEL_ENV !== "production")
- // return {
- // bannerSpace: 1,
- // bannerContent: (
- //
- // Your not in production!{" "}
- //
- //
- //
- //
- // ),
- // };
+ if (process.env.NEXT_PUBLIC_VERCEL_ENV !== "production")
+ return {
+ bannerSpace: 1,
+ bannerContent: (
+
+ Your not in production!{" "}
+
+
+
+
+ ),
+ };
return undefined;
},
];
diff --git a/src/lib/api.ts b/src/lib/api.ts
index 49f4e8f..966cf20 100644
--- a/src/lib/api.ts
+++ b/src/lib/api.ts
@@ -38,452 +38,464 @@
import { Achievement } from "./types/achievement";
const connector = (
- endpoint: string,
- options: { version: number; starting?: string },
+ endpoint: string,
+ options: { version: number; starting?: string }
) =>
- `${options.starting == undefined ? "/" : `${options.starting}/`}api/v${options.version}${endpoint}`;
+ `${options.starting == undefined ? "/" : `${options.starting}/`}api/v${options.version}${endpoint}`;
async function apiConstructor(
- connector: string,
- requestInit: RequestInit,
- modifier: (data: any) => K,
+ connector: string,
+ requestInit: RequestInit,
+ modifier: (data: any) => K
): Promise {
- try {
- const response = await fetch(connector, requestInit);
+ try {
+ const response = await fetch(connector, requestInit);
- if (response.status >= 400) {
- throw Error("Error while running API");
- }
- return modifier(await response.json());
- } catch {
- throw Error("Error while running API");
- }
+ if (response.status >= 400) {
+ throw Error("Error while running API");
+ }
+ return modifier(await response.json());
+ } catch {
+ throw Error("Error while running API");
+ }
}
export async function getMOTDFromServer(
- list: Array<{ server: string; motd: string }>,
+ list: Array<{ server: string; motd: string }>
): Promise> {
- const result = await fetch(
- process.env.NEXT_PUBLIC_ALTERNATE_MOTD_ENDPOINT ??
- connector("/motd", { version: 1 }),
- {
- body: JSON.stringify({ motd: list }),
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- },
- );
+ const result = await fetch(
+ process.env.NEXT_PUBLIC_ALTERNATE_MOTD_ENDPOINT ??
+ connector("/motd", { version: 1 }),
+ {
+ body: JSON.stringify({ motd: list }),
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ }
+ );
- let json = await result.json();
- return json.result;
+ let json = await result.json();
+ return json.result;
+}
+
+export async function getRelativeServerData(
+ server: string
+): Promise> {
+ const result = await fetch(
+ connector("/history/" + server + "/get-relative-data", { version: 0 })
+ );
+
+ const json = await result.json();
+ return json.data;
}
export async function getCommunityServerFavorites(
- server: string,
+ server: string
): Promise {
- const result = await fetch(
- connector(`/favorites/${server}/community-favorites`, { version: 0 }),
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- },
- );
+ const result = await fetch(
+ connector(`/favorites/${server}/community-favorites`, { version: 0 }),
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ }
+ );
- let json = await result.json();
- return json.result;
+ let json = await result.json();
+ return json.result;
}
/** requires authentication */
export async function favoriteServer(server: string) {
- try {
- await fetch(
- connector(`/favorites/${server}/favorite-server`, { version: 0 }),
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- },
- );
- } catch {
- throw Error("Not authenticated with a user.");
- }
+ try {
+ await fetch(
+ connector(`/favorites/${server}/favorite-server`, { version: 0 }),
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ }
+ );
+ } catch {
+ throw Error("Not authenticated with a user.");
+ }
}
/** requires authentication */
export async function isFavorited(server: string): Promise {
- try {
- const response = await fetch(
- connector(`/favorites/${server}/favorited`, { version: 0 }),
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- },
- );
+ try {
+ const response = await fetch(
+ connector(`/favorites/${server}/favorited`, { version: 0 }),
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ }
+ );
- return (await response.json()).result;
- } catch {
- throw Error("Not authenticated with a user.");
- }
+ return (await response.json()).result;
+ } catch {
+ throw Error("Not authenticated with a user.");
+ }
}
/** requires authentication */
export async function getAccountFavorites(): Promise> {
- try {
- const response = await fetch(
- connector(`/favorites/account-favorites`, { version: 0 }),
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- },
- );
+ try {
+ const response = await fetch(
+ connector(`/favorites/account-favorites`, { version: 0 }),
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ }
+ );
- return (await response.json()).result;
- } catch {
- throw Error("Not authenticated with a user.");
- }
+ return (await response.json()).result;
+ } catch {
+ throw Error("Not authenticated with a user.");
+ }
}
/**
* currently not used in frontend yet
*/
export async function getHistoricalData(
- server: string,
- scopes: Array<"player_count" | "favorites" | "server" | "time">,
+ server: string,
+ scopes: Array<"player_count" | "favorites" | "server" | "time">
): Promise<
- Array<{
- player_count?: number;
- favorites?: number;
- server?: string;
- time?: number;
- }>
+ Array<{
+ player_count?: number;
+ favorites?: number;
+ server?: string;
+ time?: number;
+ }>
> {
- const response = await fetch(
- connector(`/history/${server}/get-historical-data`, { version: 0 }),
- {
- method: "POST",
- body: JSON.stringify({ scopes }),
- headers: {
- "Content-Type": "application/json",
- },
- },
- );
+ const response = await fetch(
+ connector(`/history/${server}/get-historical-data`, { version: 0 }),
+ {
+ method: "POST",
+ body: JSON.stringify({ scopes }),
+ headers: {
+ "Content-Type": "application/json",
+ },
+ }
+ );
- return (await response.json()).data;
+ return (await response.json()).data;
}
export async function getShortTermData(
- server: string,
- scopes: Array<"player_count" | "favorites" | "server" | "date">,
-): Promise<
- Array<{
- player_count?: number;
- favorites?: number;
- server?: string;
- time?: number;
- }>
-> {
- const response = await fetch(
- connector(`/history/${server}/get-short-term-data`, { version: 0 }),
- {
- method: "POST",
- body: JSON.stringify({ scopes }),
- headers: {
- "Content-Type": "application/json",
- },
- },
- );
+ server: string,
+ scopes: Array<"player_count" | "favorites" | "server" | "date">
+): Promise<{
+ data: Array<{
+ player_count?: number;
+ favorites?: number;
+ server?: string;
+ time?: number;
+ }>;
+ dataMax: number;
+}> {
+ const response = await fetch(
+ connector(`/history/${server}/get-short-term-data`, { version: 0 }),
+ {
+ method: "POST",
+ body: JSON.stringify({ scopes }),
+ headers: {
+ "Content-Type": "application/json",
+ },
+ }
+ );
- return (await response.json()).data;
+ return await response.json();
}
export async function getMetaShortTerm(
- scopes: Array<"total_players" | "total_servers" | "date">,
+ scopes: Array<"total_players" | "total_servers" | "date">
): Promise<
- Array<{
- total_players?: number;
- total_servers?: number;
- unix?: number;
- }>
+ Array<{
+ total_players?: number;
+ total_servers?: number;
+ unix?: number;
+ }>
> {
- const response = await fetch(
- connector(`/history/meta-short-term-data`, { version: 0 }),
- {
- method: "POST",
- body: JSON.stringify({ scopes }),
- headers: {
- "Content-Type": "application/json",
- },
- },
- );
+ const response = await fetch(
+ connector(`/history/meta-short-term-data`, { version: 0 }),
+ {
+ method: "POST",
+ body: JSON.stringify({ scopes }),
+ headers: {
+ "Content-Type": "application/json",
+ },
+ }
+ );
- return (await response.json()).data;
+ return (await response.json()).data;
}
/** requires authentication */
export async function linkMCAccount(code: string): Promise {
- try {
- const response = await fetch(
- connector(`/account-linking/claim-account-code`, { version: 0 }),
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({ code }),
- },
- );
+ try {
+ const response = await fetch(
+ connector(`/account-linking/claim-account-code`, { version: 0 }),
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({ code }),
+ }
+ );
- if (response.status == 400) {
- return undefined;
- }
+ if (response.status == 400) {
+ return undefined;
+ }
- return (await response.json()).player;
- } catch {
- throw Error("Incorrect code");
- }
+ return (await response.json()).player;
+ } catch {
+ throw Error("Incorrect code");
+ }
}
/** requires authentication */
export async function unlinkMCAccount(): Promise {
- try {
- const response = await fetch(
- connector(`/account-linking/unlink-account`, { version: 0 }),
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- },
- );
+ try {
+ const response = await fetch(
+ connector(`/account-linking/unlink-account`, { version: 0 }),
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ }
+ );
- return true;
- } catch {
- throw Error(
- "Not authenticated with a user or user already linked account.",
- );
- }
+ return true;
+ } catch {
+ throw Error(
+ "Not authenticated with a user or user already linked account."
+ );
+ }
}
export async function serverOwned(server: string): Promise {
- try {
- const response = await fetch(
- connector(`/account-linking/is-owned`, { version: 0 }),
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({ server }),
- },
- );
+ try {
+ const response = await fetch(
+ connector(`/account-linking/is-owned`, { version: 0 }),
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({ server }),
+ }
+ );
- return (await response.json()).owned;
- } catch {
- throw Error("Error while running API");
- }
+ return (await response.json()).owned;
+ } catch {
+ throw Error("Error while running API");
+ }
}
/** requires authentication */
export async function userOwnedServer(server: string): Promise {
- try {
- const response = await fetch(
- connector(`/account-linking/owned-user`, { version: 0 }),
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({ server }),
- },
- );
+ try {
+ const response = await fetch(
+ connector(`/account-linking/owned-user`, { version: 0 }),
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({ server }),
+ }
+ );
- return (await response.json()).result;
- } catch {
- throw Error("Error while running API");
- }
+ return (await response.json()).result;
+ } catch {
+ throw Error("Error while running API");
+ }
}
/** requires authentication */
export async function ownServer(server: string): Promise {
- try {
- const response = await fetch(
- connector(`/account-linking/own-server`, { version: 0 }),
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({ server }),
- },
- );
+ try {
+ const response = await fetch(
+ connector(`/account-linking/own-server`, { version: 0 }),
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({ server }),
+ }
+ );
- if (response.status >= 400) {
- return false;
- }
+ if (response.status >= 400) {
+ return false;
+ }
- return true;
- } catch {
- throw Error("Error while running API");
- }
+ return true;
+ } catch {
+ throw Error("Error while running API");
+ }
}
/** requires authentication */
export async function unownServer(server: string): Promise {
- try {
- const response = await fetch(
- connector(`/account-linking/unown-server`, { version: 0 }),
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({ server }),
- },
- );
+ try {
+ const response = await fetch(
+ connector(`/account-linking/unown-server`, { version: 0 }),
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({ server }),
+ }
+ );
- if (response.status == 400) {
- return false;
- }
+ if (response.status == 400) {
+ return false;
+ }
- return true;
- } catch {
- throw Error("Error while running API");
- }
+ return true;
+ } catch {
+ throw Error("Error while running API");
+ }
}
/** requires authentication */
export async function setCustomization(
- server: string,
- customization: any,
+ server: string,
+ customization: any
): Promise {
- try {
- const response = await fetch(
- connector(`/customization/${server}/set`, { version: 0 }),
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({ customization }),
- },
- );
+ try {
+ const response = await fetch(
+ connector(`/customization/${server}/set`, { version: 0 }),
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({ customization }),
+ }
+ );
- if (response.status == 400) {
- throw Error("Error while running API");
- return false;
- }
+ if (response.status == 400) {
+ throw Error("Error while running API");
+ return false;
+ }
- return true;
- } catch {
- throw Error("Error while running API");
- }
+ return true;
+ } catch {
+ throw Error("Error while running API");
+ }
}
export async function getCustomization(server: string): Promise {
- try {
- const response = await fetch(
- connector(`/customization/${server}/get`, { version: 0 }),
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- },
- );
+ try {
+ const response = await fetch(
+ connector(`/customization/${server}/get`, { version: 0 }),
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ }
+ );
- if (response.status == 400) {
- return false;
- }
+ if (response.status == 400) {
+ return false;
+ }
- return (await response.json()).results;
- } catch {
- throw Error("Error while running API");
- }
+ return (await response.json()).results;
+ } catch {
+ throw Error("Error while running API");
+ }
}
export async function sortedFavorites(): Promise<
- Array<{ server: string; favorites: number }> | boolean
+ Array<{ server: string; favorites: number }> | boolean
> {
- try {
- const response = await fetch(
- connector(`/sorting/favorites`, { version: 0 }),
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- },
- );
+ try {
+ const response = await fetch(
+ connector(`/sorting/favorites`, { version: 0 }),
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ }
+ );
- if (response.status == 400) {
- return false;
- }
+ if (response.status == 400) {
+ return false;
+ }
- return (await response.json()).results;
- } catch {
- throw Error("Error while running API");
- }
+ return (await response.json()).results;
+ } catch {
+ throw Error("Error while running API");
+ }
}
export async function reportServer(
- server: string,
- reason: string,
+ server: string,
+ reason: string
): Promise {
- try {
- const response = await fetch(connector(`/report-server`, { version: 1 }), {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({ server, reason }),
- });
+ try {
+ const response = await fetch(connector(`/report-server`, { version: 1 }), {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({ server, reason }),
+ });
- if (response.status == 400) {
- return false;
- }
+ if (response.status == 400) {
+ return false;
+ }
- return true;
- } catch {
- throw Error("Error while running API");
- }
+ return true;
+ } catch {
+ throw Error("Error while running API");
+ }
}
export async function setAccountSL(
- data: number | boolean | null,
- type: "srv" | "ipr" | "pad",
+ data: number | boolean | null,
+ type: "srv" | "ipr" | "pad"
): Promise {
- try {
- const response = await fetch(
- connector(`/account-sl/change`, { version: 0 }),
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({ data, type }),
- },
- );
+ try {
+ const response = await fetch(
+ connector(`/account-sl/change`, { version: 0 }),
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({ data, type }),
+ }
+ );
- if (response.status === 400) {
- return false;
- }
+ if (response.status === 400) {
+ return false;
+ }
- return true;
- } catch {
- throw Error("Error while running API");
- }
+ return true;
+ } catch {
+ throw Error("Error while running API");
+ }
}
export const getAchievements = async (server: string) =>
- apiConstructor<{ _id: string; name: string; achievements: Achievement[] }[]>(
- connector(`/achievements/${server}`, { version: 0 }),
- {},
- (data) => data.result,
- );
+ apiConstructor<{ _id: string; name: string; achievements: Achievement[] }[]>(
+ connector(`/achievements/${server}`, { version: 0 }),
+ {},
+ (data) => data.result
+ );
diff --git a/src/components/misc/AffilatePopup.tsx b/src/lib/hooks/use-server-exists.tsx
similarity index 74%
rename from src/components/misc/AffilatePopup.tsx
rename to src/lib/hooks/use-server-exists.tsx
index c54e8c9..bd385a4 100644
--- a/src/components/misc/AffilatePopup.tsx
+++ b/src/lib/hooks/use-server-exists.tsx
@@ -27,3 +27,24 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
+
+import { useEffect, useState } from "react";
+
+export function useServerExists(server: string) {
+ const [serverExists, setServerExists] = useState(true);
+ const [loading, setLoading] = useState(true);
+
+ useEffect(() => {
+ fetch("https://api.minehut.com/server/" + server + "?byName=true")
+ .then((c) => c.json())
+ .then((d) => {
+ setServerExists(d.server != null);
+ setLoading(false);
+ });
+ });
+
+ return {
+ serverExists,
+ loading,
+ };
+}
diff --git a/src/lib/list.ts b/src/lib/list.ts
index 8be16ea..714972a 100644
--- a/src/lib/list.ts
+++ b/src/lib/list.ts
@@ -5,7 +5,7 @@ import MiniMessage from "minimessage-js";
var numberOfItemsInView = 20;
export default class ServersList {
- private servers: Array = [];
+ servers: Array = [];
currentServers: Array = [];
private filters: Array<(server: OnlineServer) => Promise> = [];
extraData: any = { total_players: 0, total_servers: 0 };
diff --git a/src/pages/api/v0/history/[server]/get-relative-data.ts b/src/pages/api/v0/history/[server]/get-relative-data.ts
new file mode 100644
index 0000000..64d3447
--- /dev/null
+++ b/src/pages/api/v0/history/[server]/get-relative-data.ts
@@ -0,0 +1,97 @@
+/*
+ * MHSF, Minehut Server List
+ * All external content is rather licensed under the ECA Agreement
+ * located here: https://mhsf.app/docs/legal/external-content-agreement
+ *
+ * All code under MHSF is licensed under the MIT License
+ * by open source contributors
+ *
+ * Copyright (c) 2024 dvelo
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *//*
+ * MHSF, Minehut Server List
+ * All external content is rather licensed under the ECA Agreement
+ * located here: https://list.mlnehut.com/docs/legal/external-content-agreement
+ *
+ * All code under MHSF is licensed under the MIT License
+ * by open source contributors
+ *
+ * Copyright (c) 2024 dvelo
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+import { MongoClient } from "mongodb";
+import { NextApiRequest, NextApiResponse } from "next";
+
+export default async function handler(
+ req: NextApiRequest,
+ res: NextApiResponse
+) {
+ const client = new MongoClient(process.env.MONGO_DB as string);
+ const db = client.db("mhsf").collection("history");
+ const mh = client.db("mhsf").collection("mh");
+ const server = req.query.server as string;
+
+ const allData = await db.find({ server }).toArray();
+ const data: any[] = [];
+ if (server === "peww") console.log(allData.slice(-30));
+
+ for (const d of allData.slice(-30)) {
+ const dateOfEntry = new Date(d.date);
+ const result = await mh
+ .find({
+ date: {
+ $gte: new Date(dateOfEntry.getTime() - 1000 * 60 * 60),
+ $lt: new Date(dateOfEntry.getTime() + 1000 * 60 * 60),
+ },
+ })
+ .toArray();
+
+ if (result.length > 0) {
+ const resultedData = result[0];
+ data.push({
+ relativePrecentage: d.player_count / resultedData.total_players,
+ date: dateOfEntry,
+ });
+ }
+ }
+
+ client.close();
+ res.send({ data });
+}
diff --git a/src/pages/api/v0/history/[server]/get-short-term-data.ts b/src/pages/api/v0/history/[server]/get-short-term-data.ts
index a52b753..9d81cae 100644
--- a/src/pages/api/v0/history/[server]/get-short-term-data.ts
+++ b/src/pages/api/v0/history/[server]/get-short-term-data.ts
@@ -38,11 +38,16 @@ export default async function handler(
const client = new MongoClient(process.env.MONGO_DB as string);
const db = client.db("mhsf").collection("history");
const server = req.query.server as string;
+ let dataMax = 0;
const scopes: Array = checkForInfoOrLeave(res, req.body.scopes);
const allData = await db.find({ server }).toArray();
const data: any[] = [];
+ dataMax = (
+ await db.find({ server }).sort({ player_count: -1 }).limit(1).toArray()
+ )[0].player_count;
+
allData.forEach((d) => {
const result: any = {};
scopes.forEach((b) => {
@@ -52,7 +57,7 @@ export default async function handler(
});
client.close();
- res.send({ data });
+ res.send({ data, dataMax });
}
function checkForInfoOrLeave(res: NextApiResponse, info: any) {
diff --git a/yarn.lock b/yarn.lock
index fbc1388..5ab260d 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2639,6 +2639,26 @@ acorn@^8.9.0:
resolved "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz"
integrity sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==
+ag-charts-types@11.0.3:
+ version "11.0.3"
+ resolved "https://registry.yarnpkg.com/ag-charts-types/-/ag-charts-types-11.0.3.tgz#a4aa4825b298014c1323a1e5832dec0ef4e5e135"
+ integrity sha512-q7O2viQXPyO014QVH7KjFCUmQ/NvMBx9ReZtramQ44u+/aAa0ttLi/coK+V0Hse4/MG1eB/2XhgymdooQ0Kalg==
+
+ag-grid-community@33.0.3:
+ version "33.0.3"
+ resolved "https://registry.yarnpkg.com/ag-grid-community/-/ag-grid-community-33.0.3.tgz#51511d5b048eedf24b3de596967e74a3272bfe88"
+ integrity sha512-HZeVmVieZ5Gm9j09Itecqm+OIX8X6cU4TJToUbsXv3DxdO9SK5/s8aAJAwBHtNRXOhHrhqQYwrY2yc3OtzWwcQ==
+ dependencies:
+ ag-charts-types "11.0.3"
+
+ag-grid-react@^33.0.3:
+ version "33.0.3"
+ resolved "https://registry.yarnpkg.com/ag-grid-react/-/ag-grid-react-33.0.3.tgz#24f0c65ba48363e53db915aab13bb537b8e35025"
+ integrity sha512-6IcraSVqsUG/hzTeZ0D0dtddAcZKcWdN75ek/O+lCA6r22abJPe33nHBYVezkTV8k6D3JhA24mlTwduzn0GZLQ==
+ dependencies:
+ ag-grid-community "33.0.3"
+ prop-types "^15.8.1"
+
ajv@^6.12.4:
version "6.12.6"
resolved "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz"