Changed whole project structure (split client and server into separat projects)
This commit is contained in:
35
ReallifeGamemode.Server/Extensions/AdminLevelExtension.cs
Normal file
35
ReallifeGamemode.Server/Extensions/AdminLevelExtension.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using reallife_gamemode.Server.Util;
|
||||
using static reallife_gamemode.Server.Util.AdminLevel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Extensions
|
||||
{
|
||||
public static class AdminLevelExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Gibt den richtigen Namen eines Admin Levels zurück
|
||||
/// </summary>
|
||||
/// <param name="level">Das Admin Level, dessen Namen man bekommen möchte</param>
|
||||
/// <returns></returns>
|
||||
public static string GetName(this AdminLevel level)
|
||||
{
|
||||
switch(level)
|
||||
{
|
||||
case SUPPORTER:
|
||||
return "Supporter";
|
||||
case ADMIN:
|
||||
case ADMIN2:
|
||||
case ADMIN3:
|
||||
return "Admin";
|
||||
case HEADADMIN:
|
||||
return "Headadmin";
|
||||
case PROJEKTLEITUNG:
|
||||
return "Projektleiter";
|
||||
default:
|
||||
return "Spieler";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
77
ReallifeGamemode.Server/Extensions/ClientExtension.cs
Normal file
77
ReallifeGamemode.Server/Extensions/ClientExtension.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Models;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Client Extension (ClientExtension.cs)
|
||||
* @author hydrant
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Extensions
|
||||
{
|
||||
public static class ClientExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Gibt das User-Objekt eines Client's zurück.
|
||||
/// Gibt nichts zurück, wenn der Client nicht eingeloggt ist
|
||||
/// </summary>
|
||||
/// <param name="client">Der Client, dessen User man bekommen möchte</param>
|
||||
/// <param name="context">Ein eventuell vorhandener Datenbank-Context, falls man Änderungen in der Datenbank vornehmen will</param>
|
||||
/// <returns></returns>
|
||||
public static User GetUser(this Client client, DatabaseContext context = null)
|
||||
{
|
||||
if (!client.IsLoggedIn()) return null;
|
||||
if(context == null)
|
||||
{
|
||||
using (context = new DatabaseContext())
|
||||
{
|
||||
return context.Users.FirstOrDefault(u => u.Name == client.Name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return context.Users.FirstOrDefault(u => u.Name == client.Name);
|
||||
}
|
||||
}
|
||||
|
||||
public static Character GetCharacter(this User user, DatabaseContext context = null)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
using (context = new DatabaseContext())
|
||||
{
|
||||
return context.Characters.FirstOrDefault(u => u.UserId == user.Id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return context.Characters.FirstOrDefault(u => u.UserId == user.Id);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gibt zurück, ob ein Client eingeloggt ist
|
||||
/// </summary>
|
||||
/// <param name="player">Der Client, dessen Login-Status man bekommen möchte</param>
|
||||
/// <returns></returns>
|
||||
public static bool IsLoggedIn(this Client player)
|
||||
{
|
||||
return player.HasData("isLoggedIn") ? player.GetData("isLoggedIn") : false;
|
||||
}
|
||||
|
||||
public static Vector3 GetPositionFromPlayer(Client player, float distance, int offset = 0)
|
||||
{
|
||||
var pos = player.Position;
|
||||
var a = player.Heading + offset;
|
||||
var rad = a * Math.PI / 180;
|
||||
var newpos = new Vector3(pos.X + (distance * Math.Sin(-rad)),
|
||||
pos.Y + (distance * Math.Cos(-rad)),
|
||||
pos.Z);
|
||||
return newpos;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
18
ReallifeGamemode.Server/Extensions/IntegerExtension.cs
Normal file
18
ReallifeGamemode.Server/Extensions/IntegerExtension.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Extensions
|
||||
{
|
||||
public static class IntegerExtension
|
||||
{
|
||||
public static string ToMoneyString(this int? money)
|
||||
{
|
||||
return ToMoneyString(money ?? 0);
|
||||
}
|
||||
public static string ToMoneyString(this int money)
|
||||
{
|
||||
return "$" + string.Format(Main.SERVER_CULTURE, "{0:C0}", money).Replace("€", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
17
ReallifeGamemode.Server/Extensions/VehicleExtension.cs
Normal file
17
ReallifeGamemode.Server/Extensions/VehicleExtension.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Managers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Extensions
|
||||
{
|
||||
public static class VehicleExtension
|
||||
{
|
||||
public static ServerVehicle GetServerVehicle(this Vehicle veh)
|
||||
{
|
||||
return VehicleManager.GetServerVehicleFromVehicle(veh);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user