Continued faction system
This commit is contained in:
1
Main.cs
1
Main.cs
@@ -25,6 +25,7 @@ namespace reallife_gamemode
|
|||||||
|
|
||||||
using (var context = new DatabaseContext())
|
using (var context = new DatabaseContext())
|
||||||
{
|
{
|
||||||
|
context.Factions.FirstOrDefault();
|
||||||
context.Users.FirstOrDefault();
|
context.Users.FirstOrDefault();
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace reallife_gamemode.Model
|
|||||||
base.OnModelCreating(modelBuilder);
|
base.OnModelCreating(modelBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DbSet<Server.Entities.User> Users { get; set; }
|
|
||||||
public DbSet<Server.Entities.Faction> Factions { get; set; }
|
public DbSet<Server.Entities.Faction> Factions { get; set; }
|
||||||
|
public DbSet<Server.Entities.User> Users { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
41
Server/Commands/Faction.cs
Normal file
41
Server/Commands/Faction.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using GTANetworkAPI;
|
||||||
|
using reallife_gamemode.Server.Entities;
|
||||||
|
using reallife_gamemode.Server.Extensions;
|
||||||
|
using reallife_gamemode.Server.Services;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @overview Life of German Reallife - Faction Commands (Faction.cs)
|
||||||
|
* @author VegaZ, hydrant
|
||||||
|
* @copyright (c) 2008 - 2018 Life of German
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace reallife_gamemode.Server.Commands
|
||||||
|
{
|
||||||
|
class Faction : Script
|
||||||
|
{
|
||||||
|
[Command("f", "~m~Benutzung: ~s~/f [Nachricht]", GreedyArg = true)]
|
||||||
|
public void CmdFactionF(Client player, string message)
|
||||||
|
{
|
||||||
|
User u = player.GetUser();
|
||||||
|
|
||||||
|
if(u == null)
|
||||||
|
{
|
||||||
|
NAPI.Util.ConsoleOutput("u is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Entities.Faction f = u.Faction;
|
||||||
|
if(f == null)
|
||||||
|
{
|
||||||
|
NAPI.Util.ConsoleOutput("f is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string broadcastMessage = "** " + player.Name + ": " + message + " )) **";
|
||||||
|
|
||||||
|
ChatService.BroadcastFaction(broadcastMessage, player.GetFaction());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,12 @@ using System.ComponentModel.DataAnnotations;
|
|||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @overview Life of German Reallife - Entities Faction (Faction.cs)
|
||||||
|
* @author VegaZ, hydrant
|
||||||
|
* @copyright (c) 2008 - 2018 Life of German
|
||||||
|
*/
|
||||||
|
|
||||||
namespace reallife_gamemode.Server.Entities
|
namespace reallife_gamemode.Server.Entities
|
||||||
{
|
{
|
||||||
public class Faction
|
public class Faction
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ using System.Text;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @overview Life of German Reallife - Client Extension (ClientExtension.cs)
|
* @overview Life of German Reallife - Client Extension (ClientExtension.cs)
|
||||||
* @author VegaZ, hydrant
|
* @author hydrant
|
||||||
* @copyright (c) 2008 - 2018 Life of German
|
* @copyright (c) 2008 - 2018 Life of German
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -23,5 +23,10 @@ namespace reallife_gamemode.Server.Extensions
|
|||||||
return dbContext.Users.FirstOrDefault(u => u.Name == client.Name);
|
return dbContext.Users.FirstOrDefault(u => u.Name == client.Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Faction GetFaction(this Client client)
|
||||||
|
{
|
||||||
|
return client.GetUser()?.Faction ?? null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using GTANetworkAPI;
|
using GTANetworkAPI;
|
||||||
|
using reallife_gamemode.Model;
|
||||||
|
using reallife_gamemode.Server.Entities;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -18,9 +20,26 @@ namespace reallife_gamemode.Server.Services
|
|||||||
player.SendChatMessage("~r~[FEHLER]~s~ Du kannst diesen Befehl nicht ausführen.");
|
player.SendChatMessage("~r~[FEHLER]~s~ Du kannst diesen Befehl nicht ausführen.");
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void PlayerNotFound(Client player)
|
public static void PlayerNotFound(Client player)
|
||||||
{
|
{
|
||||||
player.SendChatMessage("~r~[FEHLER]~s~ Der Spieler wurde nicht gefunden.");
|
player.SendChatMessage("~r~[FEHLER]~s~ Der Spieler wurde nicht gefunden.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void BroadcastFaction(string message, List<Faction> factions)
|
||||||
|
{
|
||||||
|
using(var dbCon = new DatabaseContext())
|
||||||
|
{
|
||||||
|
foreach(User u in dbCon.Users)
|
||||||
|
{
|
||||||
|
Client c = ClientService.GetClientByName(u.Name);
|
||||||
|
if (c != null && factions.Contains(u.Faction)) c.SendChatMessage(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void BroadcastFaction(string message, Faction faction)
|
||||||
|
{
|
||||||
|
BroadcastFaction(message, new List<Faction> { faction });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user