Merge branch 'feature/faction-system' into develop
This commit is contained in:
@@ -4,12 +4,15 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using GTANetworkAPI;
|
||||
using Newtonsoft.Json;
|
||||
using reallife_gamemode.Model;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Events;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Services;
|
||||
using reallife_gamemode.Server.Util;
|
||||
using reallife_gamemode.Model;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Admin Commands (Admin.cs)
|
||||
@@ -529,6 +532,116 @@ namespace reallife_gamemode.Server.Commands
|
||||
player.SendChatMessage("~b~Du hast " + peopleInRange.Count + " Spielern eine " + weapon + " mit " + munition + " Munition gegeben");
|
||||
}
|
||||
|
||||
[Command("factionlist", "~m~Benutzung: ~s~/factionlist")]
|
||||
public void CmdAdminFactionlist(Client player)
|
||||
{
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
using(var dbContext = new DatabaseContext())
|
||||
{
|
||||
player.SendChatMessage("~m~__________ ~s~Fraktionen ~m~__________");
|
||||
foreach(Entities.Faction f in dbContext.Factions)
|
||||
{
|
||||
player.SendChatMessage(f.Id.ToString().PadRight(3) + " | " + f.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Command("ainvite", "~m~Benutzung: ~s~/ainvite [Name] [Fraktion]")]
|
||||
public void CmdAdminAinvite(Client player, string name, int faction)
|
||||
{
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
Client target = ClientService.GetClientByName(name);
|
||||
if (target == null)
|
||||
{
|
||||
ChatService.PlayerNotFound(player);
|
||||
return;
|
||||
}
|
||||
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
Entities.Faction f = dbContext.Factions.FirstOrDefault(x => x.Id == faction);
|
||||
if (f == null && faction != 0)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Diese Fraktion existiert nicht (Liste: ~m~/factionlist).");
|
||||
return;
|
||||
}
|
||||
|
||||
User u = dbContext.Users.SingleOrDefault(x => x.Name == target.Name);
|
||||
|
||||
if (faction != 0)
|
||||
{
|
||||
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.");
|
||||
}
|
||||
|
||||
u.FactionLeader = false;
|
||||
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
[Command("makeleader", "~m~Benutzung: ~s~/makeleader [Name] [Fraktion]")]
|
||||
public void CmdAdminMakeleader(Client player, string name, int faction)
|
||||
{
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
Client target = ClientService.GetClientByName(name);
|
||||
if (target == null)
|
||||
{
|
||||
ChatService.PlayerNotFound(player);
|
||||
return;
|
||||
}
|
||||
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
Entities.Faction f = dbContext.Factions.FirstOrDefault(x => x.Id == faction);
|
||||
if (f == null)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Diese Fraktion existiert nicht (Liste: ~m~/factionlist).");
|
||||
return;
|
||||
}
|
||||
|
||||
User u = dbContext.Users.SingleOrDefault(x => x.Name == target.Name);
|
||||
|
||||
u.FactionId = f.Id;
|
||||
u.FactionRankId = dbContext.FactionRanks.
|
||||
OrderByDescending(x => x.Order)
|
||||
.FirstOrDefault(r => r.FactionId == f.Id)?.Id ?? null;
|
||||
u.FactionLeader = true;
|
||||
|
||||
player.SendChatMessage("~b~[ADMIN]~s~ Du hast hast den Spieler ~y~" + target.Name + "~s~ zum Leader der Fraktion Fraktion ~o~" + f.Name + "~s~ ernannt.");
|
||||
target.SendChatMessage("~b~[ADMIN]~s~ Du wurdest von ~y~" + player.Name + "~s~ zum Leader der Fraktion ~o~" + f.Name + "~s~ ernannt.");
|
||||
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
[Command("save", "~m~Benutzung: ~s~/save [Typ = ~g~Blip, ~r~Marker, Ped, Pickup, TextLabel, ~g~Vehicle")]
|
||||
public void CmdAdminSave(Client player, string typ)
|
||||
{
|
||||
@@ -575,6 +688,7 @@ namespace reallife_gamemode.Server.Commands
|
||||
Client target = ClientService.GetClientByName(user);
|
||||
ClientExtension.BanPlayer(admin, target, reason, mins);
|
||||
}
|
||||
|
||||
[Command("unban", "~m~Benutzung: ~s~/unban [User] ", GreedyArg = true)]
|
||||
public void CmdAdminUnban(Client admin, string user)
|
||||
{
|
||||
@@ -592,6 +706,47 @@ namespace reallife_gamemode.Server.Commands
|
||||
ClientExtension.UnbanPlayer(admin, target);
|
||||
}
|
||||
|
||||
[Command("managefactionranks", "~m~Benutzung: ~s~/managefactionranks [Fraktions-ID]")]
|
||||
public void CmdFactionManageFactionRanks(Client player, int factionID)
|
||||
{
|
||||
if(!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
Entities.Faction f = context.Factions.FirstOrDefault(id => id.Id == factionID);
|
||||
if (f == null)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Diese Fraktion existiert nicht (Liste: ~m~/factionlist).");
|
||||
return;
|
||||
}
|
||||
|
||||
List<FactionRank> factionRanks = context.FactionRanks.ToList().FindAll(r => r.FactionId == f.Id).OrderByDescending(o => o.Order).ToList();
|
||||
List<Rank> rankList = new List<Rank>();
|
||||
|
||||
factionRanks.ForEach(r =>
|
||||
{
|
||||
rankList.Add(new Rank
|
||||
{
|
||||
Id = r.Id,
|
||||
Name = r.RankName
|
||||
});
|
||||
});
|
||||
|
||||
FactionRankHelper helper = new FactionRankHelper
|
||||
{
|
||||
FactionId = f.Id,
|
||||
Ranks = rankList
|
||||
};
|
||||
string json = JsonConvert.SerializeObject(helper, Formatting.None);
|
||||
Console.WriteLine(json);
|
||||
player.TriggerEvent("manageFactionRanks", json);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//TEST COMMAND
|
||||
[Command("own")]
|
||||
|
||||
Reference in New Issue
Block a user