Push Files

- Uploaded Backend
- Uploaded Mod Code
- Started Documentation
This commit is contained in:
Pengu 2025-04-08 20:12:57 -05:00
parent 6c33c0b76a
commit b06a49e54d
18 changed files with 3344 additions and 0 deletions

14
Backend/package.json Normal file
View File

@ -0,0 +1,14 @@
{
"name": "gp-server",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "module"
}

39
Backend/server.js Normal file
View File

@ -0,0 +1,39 @@
import express from "express";
import client from "prom-client";
const registry = new client.Registry();
const app = express();
var active_users = 0;
const users = new client.Gauge({
name: "active_users",
help: "active_users",
async collect() {
this.set(active_users);
},
});
registry.registerMetric(users);
app.get("/", (req, res) => {
res.send("player-metrics");
});
app.post("/api/players", (req, res) => {
res.send("ok");
active_users++;
});
app.get("/metrics", async (req, res) => {
res.setHeader("Content-Type", client.contentType);
res.send(await registry.metrics());
res.end();
active_users = 0; // reset the active_users when prometheus gets metrics (aka reset every minute -- prometheus default poll time)
});
app.listen(5008, () => {
console.log("listening on :" + 5008);
});

1
Backend/start.sh Normal file
View File

@ -0,0 +1 @@
node server.js

View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Grafana", "Grafana.csproj", "{5208D570-5F22-4111-B506-06A0C0A6AE5E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5208D570-5F22-4111-B506-06A0C0A6AE5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5208D570-5F22-4111-B506-06A0C0A6AE5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5208D570-5F22-4111-B506-06A0C0A6AE5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5208D570-5F22-4111-B506-06A0C0A6AE5E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2517CDD3-F948-4559-935E-E2D8E3387E02}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<AssemblyName>GrafanaPostMod</AssemblyName>
<Version>1.0.1</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<!-- Reference to BepInEx -->
<Reference Include="BepInEx">
<HintPath>E:\SteamLibrary\steamapps\common\REPO\BepInEx\core\BepInEx.dll</HintPath>
</Reference>
<!-- Reference to UnityEngine -->
<Reference Include="UnityEngine">
<HintPath>E:\SteamLibrary\steamapps\common\REPO\REPO_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
<!-- Reference to UnityEngine.CoreModule -->
<Reference Include="UnityEngine.CoreModule">
<HintPath>E:\SteamLibrary\steamapps\common\REPO\REPO_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<!-- Reference to UnityEngine.UnityWebRequestModule -->
<Reference Include="UnityEngine.UnityWebRequestModule">
<HintPath>E:\SteamLibrary\steamapps\common\REPO\REPO_Data\Managed\UnityEngine.UnityWebRequestModule.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<!-- NuGet package for HTTP requests -->
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]

View File

@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("GrafanaPostMod")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.1.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.1+6c33c0b76a29d6b5430bc18548d898ab0e115976")]
[assembly: System.Reflection.AssemblyProductAttribute("GrafanaPostMod")]
[assembly: System.Reflection.AssemblyTitleAttribute("GrafanaPostMod")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.1.0")]
// Generated by the MSBuild WriteCodeFragment class.

View File

@ -0,0 +1 @@
47645a2170d6a2b0b20966e84eef3968e69f2a32ae419f680b5ad2a81fd99afe

View File

@ -0,0 +1,5 @@
is_global = true
build_property.RootNamespace = Grafana
build_property.ProjectDir = D:\Github\Horizon-Studios\GrafanaPostMod\GrafanaPostMod\
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =

View File

@ -0,0 +1,72 @@
{
"format": 1,
"restore": {
"D:\\Github\\Horizon-Studios\\GrafanaPostMod\\GrafanaPostMod\\Grafana.csproj": {}
},
"projects": {
"D:\\Github\\Horizon-Studios\\GrafanaPostMod\\GrafanaPostMod\\Grafana.csproj": {
"version": "1.0.1",
"restore": {
"projectUniqueName": "D:\\Github\\Horizon-Studios\\GrafanaPostMod\\GrafanaPostMod\\Grafana.csproj",
"projectName": "GrafanaPostMod",
"projectPath": "D:\\Github\\Horizon-Studios\\GrafanaPostMod\\GrafanaPostMod\\Grafana.csproj",
"packagesPath": "C:\\Users\\Max\\.nuget\\packages\\",
"outputPath": "D:\\Github\\Horizon-Studios\\GrafanaPostMod\\GrafanaPostMod\\obj\\",
"projectStyle": "PackageReference",
"configFilePaths": [
"C:\\Users\\Max\\AppData\\Roaming\\NuGet\\NuGet.Config"
],
"originalTargetFrameworks": [
"netstandard2.1"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"netstandard2.1": {
"targetAlias": "netstandard2.1",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
}
},
"frameworks": {
"netstandard2.1": {
"targetAlias": "netstandard2.1",
"dependencies": {
"System.Net.Http": {
"target": "Package",
"version": "[4.3.4, )"
}
},
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"NETStandard.Library": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.406\\RuntimeIdentifierGraph.json"
}
}
}
}
}

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Max\.nuget\packages\</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.11.1</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\Max\.nuget\packages\" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,58 @@
{
"version": 2,
"dgSpecHash": "mo7TMmaJkIM=",
"success": true,
"projectFilePath": "D:\\Github\\Horizon-Studios\\GrafanaPostMod\\GrafanaPostMod\\Grafana.csproj",
"expectedPackageFiles": [
"C:\\Users\\Max\\.nuget\\packages\\microsoft.netcore.platforms\\1.1.1\\microsoft.netcore.platforms.1.1.1.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\microsoft.netcore.targets\\1.1.0\\microsoft.netcore.targets.1.1.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\runtime.debian.8-x64.runtime.native.system.security.cryptography.openssl\\4.3.2\\runtime.debian.8-x64.runtime.native.system.security.cryptography.openssl.4.3.2.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\runtime.fedora.23-x64.runtime.native.system.security.cryptography.openssl\\4.3.2\\runtime.fedora.23-x64.runtime.native.system.security.cryptography.openssl.4.3.2.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\runtime.fedora.24-x64.runtime.native.system.security.cryptography.openssl\\4.3.2\\runtime.fedora.24-x64.runtime.native.system.security.cryptography.openssl.4.3.2.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\runtime.native.system\\4.3.0\\runtime.native.system.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\runtime.native.system.net.http\\4.3.0\\runtime.native.system.net.http.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\runtime.native.system.security.cryptography.apple\\4.3.0\\runtime.native.system.security.cryptography.apple.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\runtime.native.system.security.cryptography.openssl\\4.3.2\\runtime.native.system.security.cryptography.openssl.4.3.2.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\runtime.opensuse.13.2-x64.runtime.native.system.security.cryptography.openssl\\4.3.2\\runtime.opensuse.13.2-x64.runtime.native.system.security.cryptography.openssl.4.3.2.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\runtime.opensuse.42.1-x64.runtime.native.system.security.cryptography.openssl\\4.3.2\\runtime.opensuse.42.1-x64.runtime.native.system.security.cryptography.openssl.4.3.2.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\runtime.osx.10.10-x64.runtime.native.system.security.cryptography.apple\\4.3.0\\runtime.osx.10.10-x64.runtime.native.system.security.cryptography.apple.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\runtime.osx.10.10-x64.runtime.native.system.security.cryptography.openssl\\4.3.2\\runtime.osx.10.10-x64.runtime.native.system.security.cryptography.openssl.4.3.2.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\runtime.rhel.7-x64.runtime.native.system.security.cryptography.openssl\\4.3.2\\runtime.rhel.7-x64.runtime.native.system.security.cryptography.openssl.4.3.2.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\runtime.ubuntu.14.04-x64.runtime.native.system.security.cryptography.openssl\\4.3.2\\runtime.ubuntu.14.04-x64.runtime.native.system.security.cryptography.openssl.4.3.2.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\runtime.ubuntu.16.04-x64.runtime.native.system.security.cryptography.openssl\\4.3.2\\runtime.ubuntu.16.04-x64.runtime.native.system.security.cryptography.openssl.4.3.2.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\runtime.ubuntu.16.10-x64.runtime.native.system.security.cryptography.openssl\\4.3.2\\runtime.ubuntu.16.10-x64.runtime.native.system.security.cryptography.openssl.4.3.2.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.collections\\4.3.0\\system.collections.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.collections.concurrent\\4.3.0\\system.collections.concurrent.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.diagnostics.debug\\4.3.0\\system.diagnostics.debug.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.diagnostics.diagnosticsource\\4.3.0\\system.diagnostics.diagnosticsource.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.diagnostics.tracing\\4.3.0\\system.diagnostics.tracing.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.globalization\\4.3.0\\system.globalization.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.globalization.calendars\\4.3.0\\system.globalization.calendars.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.globalization.extensions\\4.3.0\\system.globalization.extensions.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.io\\4.3.0\\system.io.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.io.filesystem\\4.3.0\\system.io.filesystem.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.io.filesystem.primitives\\4.3.0\\system.io.filesystem.primitives.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.linq\\4.3.0\\system.linq.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.net.http\\4.3.4\\system.net.http.4.3.4.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.net.primitives\\4.3.0\\system.net.primitives.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.reflection\\4.3.0\\system.reflection.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.reflection.primitives\\4.3.0\\system.reflection.primitives.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.resources.resourcemanager\\4.3.0\\system.resources.resourcemanager.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.runtime\\4.3.0\\system.runtime.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.runtime.extensions\\4.3.0\\system.runtime.extensions.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.runtime.handles\\4.3.0\\system.runtime.handles.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.runtime.interopservices\\4.3.0\\system.runtime.interopservices.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.runtime.numerics\\4.3.0\\system.runtime.numerics.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.security.cryptography.algorithms\\4.3.0\\system.security.cryptography.algorithms.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.security.cryptography.cng\\4.3.0\\system.security.cryptography.cng.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.security.cryptography.csp\\4.3.0\\system.security.cryptography.csp.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.security.cryptography.encoding\\4.3.0\\system.security.cryptography.encoding.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.security.cryptography.openssl\\4.3.0\\system.security.cryptography.openssl.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.security.cryptography.primitives\\4.3.0\\system.security.cryptography.primitives.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.security.cryptography.x509certificates\\4.3.0\\system.security.cryptography.x509certificates.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.text.encoding\\4.3.0\\system.text.encoding.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.threading\\4.3.0\\system.threading.4.3.0.nupkg.sha512",
"C:\\Users\\Max\\.nuget\\packages\\system.threading.tasks\\4.3.0\\system.threading.tasks.4.3.0.nupkg.sha512"
],
"logs": []
}

60
GrafanaPostMod/plugin.cs Normal file
View File

@ -0,0 +1,60 @@
using System;
using System.Collections;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using BepInEx;
using UnityEngine;
namespace GrafanaPostMod
{
[BepInPlugin("com.pengucc.grafanapostmod", "Grafana Post Mod", "1.0.1")]
public class GrafanaPostMod : BaseUnityPlugin
{
private static HttpClient httpClient;
private float postRequestInterval = 15f; // 15 seconds
private string apiUrl = "https://stats.yourdomain.com/api/players"; // Ensure this is the correct URL
void Awake()
{
Logger.LogInfo("Grafana Post Mod is initializing...");
httpClient = new HttpClient();
StartCoroutine(PostRequestCoroutine());
}
private IEnumerator PostRequestCoroutine()
{
while (true)
{
yield return new WaitForSeconds(postRequestInterval);
StartCoroutine(SendPostRequest());
}
}
private IEnumerator SendPostRequest()
{
string jsonData = "{ \"player_count\": 1 }";
StringContent content = new StringContent(jsonData, Encoding.UTF8, "application/json");
Task<HttpResponseMessage> requestTask = httpClient.PostAsync(apiUrl, content);
yield return new WaitUntil(() => requestTask.IsCompleted);
if (requestTask.Exception != null)
{
Logger.LogError($"Error sending POST request: {requestTask.Exception.Message}");
yield break;
}
HttpResponseMessage response = requestTask.Result;
if (!response.IsSuccessStatusCode)
{
Logger.LogError($"Error: Received HTTP {(int)response.StatusCode} {response.ReasonPhrase}");
yield break;
}
Task<string> responseBodyTask = response.Content.ReadAsStringAsync();
yield return new WaitUntil(() => responseBodyTask.IsCompleted);
Logger.LogInfo($"Successfully sent POST request. Response: {responseBodyTask.Result}");
}
}
}

View File

@ -1,2 +1,43 @@
# GrafanaPostMod # GrafanaPostMod
A simple mod that tracks live player counts for your BepInEx modpack.
# ⚠Please Read!⚠️
This mod is for those who run bigger projects, nobody is expected to use this mod unless they like seeing cool numbers go up.
You'll need the following things in order to begin:
- An exposed server for the backend (PLEASE DO NOT EXPOSE YOUR HOME IP)
- A web domain (I suppose it's not REQUIRED if you really want to do it over IP, but never recommended)
- A Grafana instance
- A Prometheus instance
- dotnet v8.0.406
I may be willing to host backends and maybe even grant a subdomain to some modpack developers, however I cannot do this for everyone.
# Building the mod
1. Modify `plugin.cs` on line 16. Replace `https://stats.yourdomain.com` with the subdomain you intend on using for your backend. (Keep `/api/players` there)
2. Modify `Grafana.csproj` and change the Reference paths to your correct directories. You can reference the following games in order to build this project:
- Lethal Company
- Content Warning
- R.E.P.O
There may be more, but those are the ones I know off the top of my head.
3. Open a terminal window in the directory of `Grafana.csproj` and run: `dotnet build .\Grafana.csproj`
The output .dll will be in `obj\Debug\netstandard2.1`
# Setting up the backend
Upload the backend files to a system you plan on running it on, keep in mind it needs to be public facing (I personally recommend a reverse proxy so that the IP isn't just sitting there)
1. Run `npm i` in the same directory as the backend files
2. Run `npm i pm2 -g` then run `pm2 run ./start.sh --name PostBackend` and finally run `pm2 startup`
3.