Add Faction Ranks
This commit is contained in:
@@ -35,6 +35,7 @@ namespace reallife_gamemode.Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DbSet<Server.Entities.Faction> Factions { get; set; }
|
public DbSet<Server.Entities.Faction> Factions { get; set; }
|
||||||
|
public DbSet<Server.Entities.FactionRank> FactionRanks { get; set; }
|
||||||
public DbSet<Server.Entities.User> Users { get; set; }
|
public DbSet<Server.Entities.User> Users { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using GTANetworkAPI;
|
using GTANetworkAPI;
|
||||||
using reallife_gamemode.Model;
|
using reallife_gamemode.Model;
|
||||||
|
using reallife_gamemode.Server.Entities;
|
||||||
using reallife_gamemode.Server.Extensions;
|
using reallife_gamemode.Server.Extensions;
|
||||||
using reallife_gamemode.Server.Services;
|
using reallife_gamemode.Server.Services;
|
||||||
using reallife_gamemode.Server.Util;
|
using reallife_gamemode.Server.Util;
|
||||||
@@ -240,17 +241,33 @@ namespace reallife_gamemode.Server.Commands
|
|||||||
using (var dbContext = new DatabaseContext())
|
using (var dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
Entities.Faction f = dbContext.Factions.FirstOrDefault(x => x.Id == faction);
|
Entities.Faction f = dbContext.Factions.FirstOrDefault(x => x.Id == faction);
|
||||||
if(f == null)
|
if(f == null && faction != 0)
|
||||||
{
|
{
|
||||||
player.SendChatMessage("~r~[FEHLER]~s~ Diese Fraktion existiert nicht (Liste: ~m~/factionlist).");
|
player.SendChatMessage("~r~[FEHLER]~s~ Diese Fraktion existiert nicht (Liste: ~m~/factionlist).");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
target.GetUser(dbContext).FactionId = f.Id;
|
User u = dbContext.Users.SingleOrDefault(x => x.Name == target.Name);
|
||||||
dbContext.SaveChanges();
|
|
||||||
|
|
||||||
player.SendChatMessage("~b~[ADMIN]~s~ Du hast hast den Spieler ~y~" + target.Name + "~s~ administrativ in die Fraktion ~o~" + f.Name + "~s~ eingeladen.");
|
if(faction != 0)
|
||||||
target.SendChatMessage("~b~[ADMIN]~s~ Du wurdest von ~y~" + player.Name + "~s~ administrativ in die Fraktion ~o~" + f.Name + "~s~ eingeladen.");
|
{
|
||||||
|
u.FactionId = f.Id;
|
||||||
|
u.FactionRankId = dbContext.FactionRanks.
|
||||||
|
OrderBy(x => x.Order)
|
||||||
|
.FirstOrDefault(r => r.FactionId == f.Id)?.Id ?? null;
|
||||||
|
|
||||||
|
player.SendChatMessage("~b~[ADMIN]~s~ Du hast hast den Spieler ~y~" + target.Name + "~s~ administrativ in die Fraktion ~o~" + f.Name + "~s~ eingeladen.");
|
||||||
|
target.SendChatMessage("~b~[ADMIN]~s~ Du wurdest von ~y~" + player.Name + "~s~ administrativ in die Fraktion ~o~" + f.Name + "~s~ eingeladen.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
u.FactionId = null;
|
||||||
|
u.FactionRankId = null;
|
||||||
|
player.SendChatMessage("~b~[ADMIN]~s~ Du hast hast den Spieler ~y~" + target.Name + "~s~ administrativ aus seiner Fraktion geworfen.");
|
||||||
|
target.SendChatMessage("~b~[ADMIN]~s~ Du wurdest von ~y~" + player.Name + "~s~ administrativ aus deiner Fraktion geworfen.");
|
||||||
|
}
|
||||||
|
|
||||||
|
dbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|||||||
30
Server/Entities/FactionRank.cs
Normal file
30
Server/Entities/FactionRank.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using reallife_gamemode.Model;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace reallife_gamemode.Server.Entities
|
||||||
|
{
|
||||||
|
public class FactionRank
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string RankName { get; set; }
|
||||||
|
public int Order { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public int FactionId { get; set; }
|
||||||
|
public Faction Faction { get; set; }
|
||||||
|
|
||||||
|
public Faction GetFaction()
|
||||||
|
{
|
||||||
|
using (var context = new DatabaseContext())
|
||||||
|
{
|
||||||
|
return context.Factions.FirstOrDefault(f => f.Id == FactionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,21 +36,26 @@ namespace reallife_gamemode.Server.Entities
|
|||||||
|
|
||||||
public int? FactionId { get; set; }
|
public int? FactionId { get; set; }
|
||||||
public Faction Faction { get; set; }
|
public Faction Faction { get; set; }
|
||||||
|
|
||||||
|
public int? FactionRankId { get; set; }
|
||||||
|
public FactionRank FactionRank { get;set; }
|
||||||
|
|
||||||
public bool IsAdmin(AdminLevel level) => AdminLevel >= level;
|
public Faction GetFaction()
|
||||||
public Faction GetFaction(DatabaseContext context = null)
|
|
||||||
{
|
{
|
||||||
if(context == null)
|
using(var context = new DatabaseContext())
|
||||||
{
|
|
||||||
using(context = new DatabaseContext())
|
|
||||||
{
|
|
||||||
return context.Factions.FirstOrDefault(f => f.Id == FactionId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
return context.Factions.FirstOrDefault(f => f.Id == FactionId);
|
return context.Factions.FirstOrDefault(f => f.Id == FactionId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FactionRank GetFactionRank()
|
||||||
|
{
|
||||||
|
using (var context = new DatabaseContext())
|
||||||
|
{
|
||||||
|
return context.FactionRanks.FirstOrDefault(fR => fR.Id == FactionRankId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsAdmin(AdminLevel level) => AdminLevel >= level;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,14 +40,14 @@ namespace reallife_gamemode.Server.Extensions
|
|||||||
{
|
{
|
||||||
User u = client.GetUser();
|
User u = client.GetUser();
|
||||||
if (u == null) return null;
|
if (u == null) return null;
|
||||||
return context.Factions.FirstOrDefault(f => f.Id == u.FactionId);
|
return u.GetFaction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
User u = client.GetUser();
|
User u = client.GetUser();
|
||||||
if (u == null) return null;
|
if (u == null) return null;
|
||||||
return context.Factions.FirstOrDefault(f => f.Id == u.FactionId);
|
return u.GetFaction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user