mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-30 17:10:20 -05:00
fixed misc issues and added stats page to webfront
This commit is contained in:
24
SharedLibrary/Helpers/ParseEnum.cs
Normal file
24
SharedLibrary/Helpers/ParseEnum.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary.Helpers
|
||||
{
|
||||
public class ParseEnum<T>
|
||||
{
|
||||
public static T Get(string e, Type type)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (T)Enum.Parse(type, e);
|
||||
}
|
||||
|
||||
catch (Exception)
|
||||
{
|
||||
return (T)(Enum.GetValues(type).GetValue(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
48
SharedLibrary/Helpers/ThreadSafe.cs
Normal file
48
SharedLibrary/Helpers/ThreadSafe.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Excuse this monstrosity
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class ThreadSafe<T>
|
||||
{
|
||||
private bool _lock;
|
||||
private T instance;
|
||||
|
||||
public ThreadSafe(T instance)
|
||||
{
|
||||
this.instance = instance;
|
||||
_lock = true;
|
||||
}
|
||||
|
||||
public T Value
|
||||
{
|
||||
get
|
||||
{
|
||||
// shush
|
||||
if (_lock)
|
||||
return Value;
|
||||
_lock = true;
|
||||
return instance;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_lock)
|
||||
{
|
||||
Value = Value;
|
||||
return;
|
||||
}
|
||||
instance = Value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
44
SharedLibrary/Helpers/Vector3.cs
Normal file
44
SharedLibrary/Helpers/Vector3.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary.Helpers
|
||||
{
|
||||
public class Vector3
|
||||
{
|
||||
public float X { get; private set; }
|
||||
public float Y { get; private set; }
|
||||
public float Z { get; private set; }
|
||||
|
||||
public Vector3(float x, float y, float z)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"({X}, {Y}, {Z})";
|
||||
}
|
||||
|
||||
public static Vector3 Parse(string s)
|
||||
{
|
||||
bool valid = Regex.Match(s, @"\(-?[0-9]+.?[0-9]*,\ -?[0-9]+.?[0-9]*,\ -?[0-9]+.?[0-9]*\)").Success;
|
||||
if (!valid)
|
||||
throw new FormatException("Vector3 is not in correct format");
|
||||
|
||||
string removeParenthesis = s.Substring(1, s.Length - 2);
|
||||
string[] eachPoint = removeParenthesis.Split(',');
|
||||
return new Vector3(float.Parse(eachPoint[0]), float.Parse(eachPoint[1]), float.Parse(eachPoint[2]));
|
||||
}
|
||||
|
||||
public static double Distance(Vector3 a, Vector3 b)
|
||||
{
|
||||
return Math.Round(Math.Sqrt(Math.Pow(b.X - a.X, 2) + Math.Pow(b.Y - a.Y, 2) + Math.Pow(b.Z - a.Z, 2)), 2);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user