Add some Faction commands, Try EF error fix
This commit is contained in:
6
Main.cs
6
Main.cs
@@ -43,11 +43,5 @@ namespace reallife_gamemode
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ServerEvent(Event.ResourceStop)]
|
||||
public void OnResourceStop()
|
||||
{
|
||||
NAPI.Chat.SendChatMessageToAll("on stop");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Model;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Services;
|
||||
using reallife_gamemode.Server.Util;
|
||||
@@ -199,5 +201,57 @@ namespace reallife_gamemode.Server.Commands
|
||||
|
||||
target.GiveWeapon(wHash, ammo);
|
||||
}
|
||||
|
||||
[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)
|
||||
{
|
||||
player.SendChatMessage("~r~[FEHLER]~s~ Diese Fraktion existiert nicht (Liste: ~m~/factionlist).");
|
||||
return;
|
||||
}
|
||||
|
||||
target.GetUser(dbContext).Faction = f;
|
||||
dbContext.SaveChanges();
|
||||
|
||||
player.SendChatMessage("~b~[ADMIN]~y~ " + player.Name + "~s~ hat den Spieler ~y~" + target.Name + "~s~ administrativ in die Fraktion ~o~" + f.Name + "~s~ eingeladen.");
|
||||
target.SendChatMessage("~b~[ADMIN]~y~ Du wurdest von ~y~" + player.Name + "~s~ administrativ in die Fraktion ~o~" + f.Name + "~s~ eingeladen.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,10 +20,15 @@ namespace reallife_gamemode.Server.Commands
|
||||
public void CmdFactionF(Client player, string message)
|
||||
{
|
||||
User u = player.GetUser();
|
||||
if(u.Faction == null)
|
||||
{
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
string broadcastMessage = "** " + player.Name + ": " + message + " )) **";
|
||||
|
||||
ChatService.BroadcastFaction(broadcastMessage, player.GetFaction());
|
||||
ChatService.BroadcastFaction(broadcastMessage, u.Faction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using GTANetworkAPI;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using reallife_gamemode.Model;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using System;
|
||||
@@ -16,19 +17,33 @@ namespace reallife_gamemode.Server.Extensions
|
||||
{
|
||||
public static class ClientExtension
|
||||
{
|
||||
public static User GetUser(this Client client)
|
||||
public static User GetUser(this Client client, DatabaseContext context = null)
|
||||
{
|
||||
if(context == null)
|
||||
{
|
||||
using (DatabaseContext dbContext = new DatabaseContext())
|
||||
{
|
||||
return dbContext.Users.FirstOrDefault(u => u.Name == client.Name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return context.Users.FirstOrDefault(u => u.Name == client.Name);
|
||||
}
|
||||
}
|
||||
|
||||
public static Faction GetFaction(this Client client)
|
||||
public static Faction GetFaction(this Client client, DatabaseContext context = null)
|
||||
{
|
||||
if(context == null)
|
||||
{
|
||||
using (DatabaseContext dbContext = new DatabaseContext())
|
||||
{
|
||||
return dbContext.Factions.Find(client.GetUser().Faction);
|
||||
return dbContext.Factions.Find(client.GetUser(context).Faction);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return context.Factions.Find(client.GetUser(context).Faction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user