Decompiled source of REPO Reloaded v0.1.2

plugins/GrafanaPost/BepInExGrafana.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Net.Http;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Threading.Tasks;
using BepInEx;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BepInExGrafana")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d741c5ce966052f9c91a1f363b8d9259fc521d42")]
[assembly: AssemblyProduct("BepInExGrafana")]
[assembly: AssemblyTitle("BepInExGrafana")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace GrafanaPostMod
{
	[BepInPlugin("com.pengucc.grafanapostmod", "Grafana Post Mod", "1.0.1")]
	public class GrafanaPostMod : BaseUnityPlugin
	{
		private static HttpClient httpClient;

		private float postRequestInterval = 15f;

		private string apiUrl = "https://rrstats.lethal-extended.com/api/rrplayers";

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Grafana Post Mod is initializing...");
			httpClient = new HttpClient();
			((MonoBehaviour)this).StartCoroutine(PostRequestCoroutine());
		}

		private IEnumerator PostRequestCoroutine()
		{
			while (true)
			{
				yield return (object)new WaitForSeconds(postRequestInterval);
				((MonoBehaviour)this).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 (object)new WaitUntil((Func<bool>)(() => requestTask.IsCompleted));
			if (requestTask.Exception != null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Error sending POST request: " + requestTask.Exception.Message));
				yield break;
			}
			HttpResponseMessage response = requestTask.Result;
			if (!response.IsSuccessStatusCode)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)$"Error: Received HTTP {(int)response.StatusCode} {response.ReasonPhrase}");
				yield break;
			}
			Task<string> responseBodyTask = response.Content.ReadAsStringAsync();
			yield return (object)new WaitUntil((Func<bool>)(() => responseBodyTask.IsCompleted));
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Successfully sent POST request. Response: " + responseBodyTask.Result));
		}
	}
}