Merge develop into feature/inventory-system

This commit is contained in:
VegaZ
2018-11-26 17:53:25 +01:00
66 changed files with 4533 additions and 1302 deletions

View File

File diff suppressed because it is too large Load Diff

View File

@@ -78,7 +78,7 @@ namespace reallife_gamemode.Server.Commands
return;
}
Client target = ClientService.GetClientByName(name);
Client target = ClientService.GetClientByNameOrId(name);
if (target == null || !target.IsLoggedIn())
{
ChatService.PlayerNotFound(player);
@@ -109,7 +109,7 @@ namespace reallife_gamemode.Server.Commands
return;
}
Client target = ClientService.GetClientByName(name);
Client target = ClientService.GetClientByNameOrId(name);
if (target == null || !target.IsLoggedIn())
{
ChatService.PlayerNotFound(player);
@@ -149,7 +149,7 @@ namespace reallife_gamemode.Server.Commands
return;
}
Client target = ClientService.GetClientByName(name);
Client target = ClientService.GetClientByNameOrId(name);
if (target == null || !target.IsLoggedIn())
{
ChatService.PlayerNotFound(player);
@@ -239,27 +239,7 @@ namespace reallife_gamemode.Server.Commands
[Command("duty", "~m~Benutzung: ~s~/duty")]
public void CmdFactionDuty(Client player)
{
if (player.GetUser()?.FactionId == null)
{
ChatService.NotAuthorized(player);
return;
}
if(player.GetData("duty") != true)
{
player.SetData("duty", true);
player.SendNotification("Du bist nun ~g~im Dienst.");
if(player.GetUser().FactionId == 2)
{
NAPI.ClientEvent.TriggerClientEventForAll("updateDutyMedics", true);
}
}
else
{
player.SetData("duty", false);
player.SendNotification("Du bist nun ~r~außer Dienst.");
NAPI.ClientEvent.TriggerClientEventForAll("updateDutyMedics", false);
}
}
#endregion
}

View File

@@ -27,9 +27,18 @@ namespace reallife_gamemode.Server.Commands
return;
}
player.ResetData("accept_data");
using(var dbContext = new DatabaseContext())
{
Client leader = NAPI.Player.GetPlayerFromHandle((NetHandle)player.GetData("accept_invite"));
if(leader == null)
{
player.SendChatMessage("~r~[FEHLER]~s~ Die Einladung ist abgelaufen.");
return;
}
Entities.User u = leader.GetUser(dbContext);
Entities.User own = player.GetUser(dbContext);

View File

@@ -0,0 +1,28 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
/**
* @overview Life of German Reallife - Entities CharacterCloth CharacterCloth.cs
* @author VegaZ
* @copyright (c) 2008 - 2018 Life of German
*/
namespace reallife_gamemode.Server.Entities
{
public class CharacterCloth
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[ForeignKey("User")]
public int UserId { get; set; }
public User User { get; set; }
public bool Duty { get; set; }
public byte SlotType { get; set; }
public int SlotId { get; set; }
public int ClothId { get; set; }
}
}

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Numerics;
using System.Text;
/**
* @overview Life of German Reallife - Entities MaleCombination (MaleCombination.cs)
* @author VegaZ
* @copyright (c) 2008 - 2018 Life of German
*/
namespace reallife_gamemode.Server.Entities
{
public class ClothCombination
{
[Key]
public int Id { get; set; }
public bool Gender { get; set; }
public int Top { get; set; }
public int Torso { get; set; }
public int Undershirt { get; set; }
}
}

33
Server/Entities/Door.cs Normal file
View File

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Numerics;
using System.Text;
/**
* @overview Life of German Reallife - Entities Door (Door.cs)
* @author VegaZ
* @copyright (c) 2008 - 2018 Life of German
*/
namespace reallife_gamemode.Server.Entities
{
public class Door
{
[Key]
public int Id { get; set; }
public string Category { get; set; }
public string Name { get; set; }
public bool Locked { get; set; }
public int Model { get; set; }
public float X { get; set; }
public float Y { get; set; }
public float Z { get; set; }
public float Radius { get; set; }
[ForeignKey("FactionId")]
public int? FactionId { get; set; }
public Faction Faction { get; set; }
}
}

View File

@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
/**
* @overview Life of German Reallife - Entities DutyCloth DutyCloth.cs
* @author VegaZ
* @copyright (c) 2008 - 2018 Life of German
*/
namespace reallife_gamemode.Server.Entities
{
public class DutyCloth
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[ForeignKey("Faction")]
public int FactionId { get; set; }
public Faction Faction { get; set; }
public bool Gender { get; set; }
public byte SlotType { get; set; }
public int SlotId { get; set; }
public int ClothId { get; set; }
}
}

View File

@@ -1,8 +1,11 @@
using Microsoft.EntityFrameworkCore;
using reallife_gamemode.Model;
using reallife_gamemode.Server.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
/**
@@ -13,14 +16,28 @@ using System.Text;
namespace reallife_gamemode.Server.Entities
{
public class Faction
public class Faction : IBankAccountOwner
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[StringLength(32)]
public string Name { get; set; }
public int BankAccount { get; set; }
public bool StateOwned { get; set; }
public IBankAccount GetBankAccount(DatabaseContext databaseContext = null)
{
if (databaseContext == null)
{
using (databaseContext = new DatabaseContext())
{
return databaseContext.FactionBankAccounts.FirstOrDefault(u => u.FactionId == this.Id);
}
}
else
{
return databaseContext.FactionBankAccounts.FirstOrDefault(u => u.FactionId == this.Id);
}
}
}
}

View File

@@ -13,7 +13,7 @@ using System.Text;
*/
namespace reallife_gamemode.Server.Entities
{
public class FactionBankAccount
public class FactionBankAccount : IBankAccount
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]

24
Server/Entities/News.cs Normal file
View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
namespace reallife_gamemode.Server.Entities
{
public class News
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[ForeignKey("User")]
public int? UserId { get; set; }
public User User { get; set; }
public string Caption { get; set; }
public string Content { get; set; }
public bool Active { get; set; }
public int Timestamp { get; set; }
}
}

View File

@@ -1,5 +1,6 @@
using GTANetworkAPI;
using reallife_gamemode.Model;
using reallife_gamemode.Server.Extensions;
using reallife_gamemode.Server.Util;
using System;
using System.Collections.Generic;
@@ -16,7 +17,7 @@ using System.Text;
namespace reallife_gamemode.Server.Entities
{
public class User
public class User : IBankAccountOwner
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
@@ -28,8 +29,8 @@ namespace reallife_gamemode.Server.Entities
[StringLength(64)]
public string Password { get; set; }
public int LogUserId { get; set; }
[Timestamp]
public byte[] RegistrationDate { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public DateTime RegistrationDate { get; set; }
[EmailAddress]
[StringLength(64)]
@@ -122,12 +123,11 @@ namespace reallife_gamemode.Server.Entities
{
using (var unbanUser = new DatabaseContext())
{
var targetUser = unbanUser.Bans.FirstOrDefault(u => u.Id == BanId);
unbanUser.Bans.Remove(targetUser);
User user = admin.GetUser();
var targetUser = unbanUser.Users.FirstOrDefault(u => u.Id == user.Id);
targetUser.BanId = null;
unbanUser.SaveChanges();
}
admin.SendChatMessage(this.Name + " wurde entbannt.");
//TODO ***Admin Info: {ADMIN-NAME} hat {USER-NAME} entbannt.
}
public List<UserItem> GetItems()
@@ -138,5 +138,20 @@ namespace reallife_gamemode.Server.Entities
}
}
public bool IsAdmin(AdminLevel level) => AdminLevel >= level;
public IBankAccount GetBankAccount(DatabaseContext databaseContext = null)
{
if (databaseContext == null)
{
using (databaseContext = new DatabaseContext())
{
return databaseContext.UserBankAccounts.FirstOrDefault(u => u.UserId == this.Id);
}
}
else
{
return databaseContext.UserBankAccounts.FirstOrDefault(u => u.UserId == this.Id);
}
}
}
}

View File

@@ -17,8 +17,9 @@ using System.Linq;
namespace reallife_gamemode.Server.Entities
{
public class UserBankAccount
public class UserBankAccount : IBankAccount
{
[NotMapped]
private int _balance;
[Key]
@@ -38,7 +39,7 @@ namespace reallife_gamemode.Server.Entities
_balance = value;
using(var dbContext = new DatabaseContext())
{
ClientService.GetClientByName(dbContext.Users.First(u => u.Id == UserId).Name).TriggerEvent("updateMoney", value);
ClientService.GetClientByNameOrId(dbContext.Users.First(u => u.Id == UserId).Name).TriggerEvent("updateMoney", value);
}
}
}

13
Server/Events/Chat.cs Normal file
View File

@@ -0,0 +1,13 @@
using GTANetworkAPI;
namespace reallife_gamemode.Server.Events
{
public class Chat : Script
{
[ServerEvent(Event.ChatMessage)]
public void ChatEvent(Client player, string message)
{
NAPI.Player.GetPlayersInRadiusOfPlayer(10, player).ForEach(p => p.SendChatMessage($"{player.Name} sagt: {message}"));
}
}
}

View File

@@ -27,10 +27,7 @@ namespace reallife_gamemode.Server.Events
"datgame_",
"xSprite",
"xPrike",
"balboistderbeste",
"xNccPlay",
"Marvino01"
};
@@ -76,7 +73,7 @@ namespace reallife_gamemode.Server.Events
if (bannedUser.Applied == bannedUser.UntilDateTime)
{
player.SendChatMessage("!{#FF4040}Du wurdest permanent gebannt! [" + bannedUser.Reason + "]");
//player.Kick();
player.Kick();
}
else
{
@@ -86,14 +83,14 @@ namespace reallife_gamemode.Server.Events
if(timeStamp > unixTimestamp)
{
player.SendChatMessage("Du bist noch bis zum !{#FF4040}" + dt.AddSeconds(timeStamp).ToLocalTime() + " Uhr ~s~gebannt. [" + bannedUser.Reason + "]");
player.Kick();
}
else
{
player.GetUser().BanId = null;
user.BanId = null;
loginUser.SaveChanges();
player.TriggerEvent("showLogin");
}
//player.Kick();
}
}
}
else player.TriggerEvent("showLogin");

View File

@@ -1,8 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GTANetworkAPI;
using Newtonsoft.Json;
using reallife_gamemode.Model;
using reallife_gamemode.Server.Entities;
using reallife_gamemode.Server.Extensions;
using reallife_gamemode.Server.Managers;
using reallife_gamemode.Server.Saves;
using reallife_gamemode.Server.Services;
using reallife_gamemode.Server.Util;
/**
* @overview Life of German Reallife - Event Key (Key.cs)
@@ -14,6 +21,81 @@ namespace reallife_gamemode.Server.Events
{
public class Key : Script
{
[RemoteEvent("keyPress:NUM2")]
public void KeyPressNUM2(Client player)
{
if(player.GetData("editmode") == true && player.GetUser().IsAdmin(AdminLevel.HEADADMIN) == true)
{
TempBlip tempBlip = NAPI.Data.GetWorldData("blipTemplate");
SaveManager.OnSaveBlipData(player, tempBlip.Sprite.ToString(), tempBlip.Name, tempBlip.Scale.ToString(), tempBlip.Color.ToString(),
tempBlip.Transparency.ToString(), 200.ToString(), tempBlip.ShortRange.ToString(), 0.ToString(), 0.ToString());
player.SendNotification("~y~Blip~s~ erstellt!", false);
}
}
[RemoteEvent("keyPress:E")]
public void KeyPressE(Client player)
{
var user = player.GetUser();
if (user?.FactionId != null)
{
DutyPoint nearest = PositionManager.DutyPoints.Find(d => d.Position.DistanceTo(player.Position) <= 1.5);
if (nearest == null) return;
if (player.Position.DistanceTo(nearest.Position) <= 1.5 && nearest.FactionId == user.FactionId)
{
var nameTagColor = new Color(0, 0, 0);
var factionId = user.FactionId;
if (player.GetData("duty") == false)
{
player.SetData("duty", true);
player.SendNotification("Du bist nun ~g~im Dienst.");
if (player.GetUser().FactionId == 2) //Fire Department
{
NAPI.ClientEvent.TriggerClientEventForAll("updateDutyMedics", true);
}
switch (factionId)
{
//LSPD
case 1:
nameTagColor = new Color(28, 134, 238);
break;
}
player.NametagColor = nameTagColor;
using (var context = new DatabaseContext())
{
List<CharacterCloth> clothes = context.CharacterClothes.ToList().FindAll(u => u.UserId == user.Id && u.Duty == true);
foreach(var cloth in clothes)
{
if(cloth.SlotType == 0)
{
player.SetClothes(cloth.SlotId, cloth.ClothId, 0);
}
else
{
if(cloth.ClothId != -1)
{
player.SetAccessories(cloth.SlotId, cloth.ClothId, 0);
}
else
{
player.ClearAccessory(cloth.SlotId);
}
}
}
}
}
else
{
player.SetData("duty", false);
player.SendNotification("Du bist nun ~r~außer Dienst.");
NAPI.ClientEvent.TriggerClientEventForAll("updateDutyMedics", false);
player.NametagColor = new Color(255, 255, 255);
UpdateCharacterCloth.LoadCharacterDefaults(player);
}
}
}
}
[RemoteEvent("keyPress:I")]
public void KeyPressI(Client player)
{
@@ -31,36 +113,78 @@ namespace reallife_gamemode.Server.Events
}
player.TriggerEvent("fetchPlayerList", JsonConvert.SerializeObject(ListPlayers));
}
[RemoteEvent("keyPress:K")]
public void KeyPressK(Client player)
{
var user = player.GetUser();
if (user?.FactionId != null)
{
DutyPoint nearest = PositionManager.DutyPoints.Find(d => d.Position.DistanceTo(player.Position) <= 1.5);
if (nearest == null) return;
if (player.Position.DistanceTo(nearest.Position) <= 1.5 && nearest.FactionId == user.FactionId)
{
List<string> hats = new List<string>();
List<string> tops = new List<string>();
List<string> legs = new List<string>();
List<string> shoes = new List<string>();
using (var context = new DatabaseContext())
{
List<DutyCloth> clothes = context.DutyClothes.ToList().FindAll(c => c.FactionId == user.FactionId && c.Gender == user.GetCharacter().Gender);
foreach(var cloth in clothes)
{
if(cloth.SlotType == 1)
{
if (cloth.ClothId != -1)
{
hats.Add(cloth.ClothId.ToString());
}
else
{
hats.Add("Keinen");
}
continue;
}
switch (cloth.SlotId)
{
case 11:
tops.Add(cloth.ClothId.ToString());
break;
case 4:
legs.Add(cloth.ClothId.ToString());
break;
case 6:
shoes.Add(cloth.ClothId.ToString());
break;
}
}
}
player.TriggerEvent("showDutyClothMenu", hats.ToArray(), tops.ToArray(), legs.ToArray(), shoes.ToArray());
}
}
}
[RemoteEvent("keyPress:L")]
public void KeyPressL(Client player)
{
DoorManager.ChangeDoorState(player);
}
[RemoteEvent("keyPress:N")]
public void KeyPressN(Client player)
{
if (NAPI.Player.IsPlayerInAnyVehicle(player))
if (player.IsInVehicle && player.VehicleSeat == -1)
{
bool engineStatus = NAPI.Vehicle.GetVehicleEngineStatus(player.Vehicle);
if (engineStatus == false)
{
player.Vehicle.EngineStatus = true;
}
else
{
player.Vehicle.EngineStatus = false;
}
player.Vehicle.EngineStatus = !player.Vehicle.EngineStatus;
}
}
[RemoteEvent("keyPress:X")]
public void KeyPressX(Client player)
{
if (NAPI.Player.IsPlayerInAnyVehicle(player))
if (player.IsInVehicle)
{
if (player.Seatbelt == false)
{
player.Seatbelt = true;
}
else
{
player.Seatbelt = false;
}
player.Seatbelt = !player.Seatbelt;
}
}
}
}
}

View File

@@ -48,6 +48,11 @@ namespace reallife_gamemode.Server.Events
player.SetData("spec", true);
player.SetData("duty", false);
if(user.IsAdmin(AdminLevel.HEADADMIN) == true)
{
player.SetData("editmode", false);
}
var userBankAccount = loginUser.UserBankAccounts.SingleOrDefault(u => u.UserId == user.Id);
userBankAccount.Balance = userBankAccount.Balance;
@@ -66,8 +71,9 @@ namespace reallife_gamemode.Server.Events
else
{
CharacterCreator.ApplyCharacter(player);
UpdateCharacterCloth.LoadCharacterDefaults(player);
NAPI.Player.SpawnPlayer(player, new Vector3(user.PositionX, user.PositionY, user.PositionZ), 0);
player.TriggerEvent("draw", player.Name, player.Handle.Value);
player.TriggerEvent("draw", player.Name, player.Handle.Value);
}
if (user.Dead == true)
{

View File

@@ -0,0 +1,156 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GTANetworkAPI;
using Newtonsoft.Json;
using reallife_gamemode.Model;
using reallife_gamemode.Server.Entities;
using reallife_gamemode.Server.Extensions;
namespace reallife_gamemode.Server.Events
{
public class UpdateCharacterCloth : Script
{
[RemoteEvent("updateDutyProp")]
public void UpdateDutyProp(Client player, int componentId, int componentVariation)
{
if (componentId != -1)
{
player.SetAccessories(componentId, componentVariation, 0);
}
else
{
player.ClearAccessory(0);
}
}
[RemoteEvent("updateDutyCloth")]
public void UpdateDutyCloth(Client player, int componentId, int componentVariation)
{
if (componentId == 11)
{
//TODO Spezielle Duty Kleidung in Datenbank einpflegen (Ergibt bei Cop-Kleidung NULL)
using (var context = new DatabaseContext())
{
var character = player.GetUser().GetCharacter();
var combination = context.ClothCombinations.FirstOrDefault(c => c.Top == componentVariation && c.Gender == character.Gender);
player.SetClothes(11, componentVariation, 0);
if (combination != null)
{
player.SetClothes(3, combination.Torso, 0);
player.SetClothes(8, combination.Undershirt, 0);
}
}
}
else
{
player.SetClothes(componentId, componentVariation, 0);
}
}
[RemoteEvent("saveCharacterCloth")]
public void SaveDutyCloth(Client client, string JSlotType, string JSlotId, string JClothId)
{
using (var context = new DatabaseContext())
{
int[] slotType = JsonConvert.DeserializeObject<int[]>(JSlotType);
int[] slotId = JsonConvert.DeserializeObject<int[]>(JSlotId);
int[] clothId = JsonConvert.DeserializeObject<int[]>(JClothId);
User user = client.GetUser();
user = context.Users.FirstOrDefault(u => u.Id == user.Id);
var character = client.GetUser().GetCharacter();
var charClothes = context.CharacterClothes.FirstOrDefault(c => c.UserId == user.Id);
if (charClothes == null)
{
for (var x = 0; x < slotType.Length; x++)
{
CharacterCloth newCloth = new CharacterCloth
{
UserId = user.Id,
Duty = true,
SlotType = (byte)slotType[x],
SlotId = slotId[x],
ClothId = clothId[x]
};
context.CharacterClothes.Add(newCloth);
}
if (user.GetCharacter().Gender == false)
{
CharacterCloth newTorso = new CharacterCloth
{
UserId = user.Id,
Duty = true,
SlotType = 0,
SlotId = 3,
ClothId = context.ClothCombinations.FirstOrDefault(c => c.Top == clothId[1] && c.Gender == character.Gender).Torso
};
CharacterCloth newUndershirt = new CharacterCloth
{
UserId = user.Id,
Duty = true,
SlotType = 0,
SlotId = 8,
ClothId = context.ClothCombinations.FirstOrDefault(c => c.Top == clothId[1] && c.Gender == character.Gender).Undershirt
};
context.CharacterClothes.Add(newTorso);
context.CharacterClothes.Add(newUndershirt);
}
}
else
{
for (var x = 0; x < slotType.Length; x++)
{
var loopCloth = context.CharacterClothes.FirstOrDefault(u => u.UserId == user.Id && u.SlotType == slotType[x] && u.SlotId == slotId[x]);
loopCloth.ClothId = clothId[x];
}
CharacterCloth torso = context.CharacterClothes.FirstOrDefault(u => u.UserId == user.Id && u.SlotType == 0 && u.SlotId == 3);
CharacterCloth undershirt = context.CharacterClothes.FirstOrDefault(u => u.UserId == user.Id && u.SlotType == 0 && u.SlotId == 8);
torso.ClothId = context.ClothCombinations.FirstOrDefault(c => c.Top == clothId[1] && c.Gender == character.Gender).Torso;
undershirt.ClothId = context.ClothCombinations.FirstOrDefault(c => c.Top == clothId[1] && c.Gender == character.Gender).Undershirt;
}
context.SaveChanges();
}
LoadCharacterDefaults(client);
}
[RemoteEvent("defaultCharacterCloth")]
public static void LoadCharacterDefaults(Client player)
{
User user = player.GetUser();
using (var context = new DatabaseContext())
{
List<CharacterCloth> charClothes = context.CharacterClothes.ToList().FindAll(c => c.UserId == user.Id && c.Duty == false);
player.ClearAccessory(0);
player.ClearAccessory(1);
player.ClearAccessory(2);
player.ClearAccessory(6);
player.ClearAccessory(7);
foreach (var cloth in charClothes)
{
if(cloth.SlotType == 1)
{
player.SetAccessories(cloth.SlotId, cloth.ClothId, 0);
}
else
{
player.SetClothes(cloth.SlotId, cloth.ClothId, 0);
}
}
}
}
}
}

View 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";
}
}
}
}

View File

@@ -19,6 +19,13 @@ 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;
@@ -35,6 +42,26 @@ namespace reallife_gamemode.Server.Extensions
}
}
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;

View File

@@ -1,35 +0,0 @@
using GTANetworkAPI;
using Microsoft.EntityFrameworkCore;
using reallife_gamemode.Model;
using reallife_gamemode.Server.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/**
* @overview Life of German Reallife - Faction Extension (FactionExtension.cs)
* @author VegaZ
* @copyright (c) 2008 - 2018 Life of German
*/
namespace reallife_gamemode.Server.Extensions
{
public static class FactionExtension
{
public static FactionBankAccount GetFactionBankAccount(this Faction faction, DatabaseContext context = null)
{
if (context == null)
{
using (context = new DatabaseContext())
{
return context.FactionBankAccounts.FirstOrDefault(u => u.FactionId == faction.Id);
}
}
else
{
return context.FactionBankAccounts.FirstOrDefault(u => u.FactionId == faction.Id);
}
}
}
}

View File

@@ -1,49 +0,0 @@
using GTANetworkAPI;
using Microsoft.EntityFrameworkCore;
using reallife_gamemode.Model;
using reallife_gamemode.Server.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/**
* @overview Life of German Reallife - User Extension (UserExtension.cs)
* @author VegaZ
* @copyright (c) 2008 - 2018 Life of German
*/
namespace reallife_gamemode.Server.Extensions
{
public static class UserExtension
{
public static UserBankAccount GetUserBankAccount(this User user, DatabaseContext context = null)
{
if (context == null)
{
using (context = new DatabaseContext())
{
return context.UserBankAccounts.FirstOrDefault(u => u.UserId == user.Id);
}
}
else
{
return context.UserBankAccounts.FirstOrDefault(u => u.UserId == user.Id);
}
}
public static Character GetUserCharacter(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);
}
}
}
}

View File

@@ -18,6 +18,11 @@ namespace reallife_gamemode.Server.Extensions
{
public static class VehicleExtension
{
/// <summary>
/// Gibt zurück, ob das Vehicle ein Fraktions-Fahrzeug ist
/// </summary>
/// <param name="vehicle">Das Vehicle, von dem man wissen möchte, ob es ein Fraktionsfahrzeug ist</param>
/// <returns></returns>
public static bool IsFactionVehicle(this Vehicle vehicle)
{
return LoadManager.FactionVehicleList.Contains(vehicle);

View File

@@ -30,7 +30,7 @@ namespace reallife_gamemode.Server.Logs
public int Fee { get; set; }
[StringLength(32)]
public string Origin { get; set; }
[Timestamp]
public byte[] Timestamp { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public DateTime Timestamp { get; set; }
}
}

View File

@@ -39,7 +39,7 @@ namespace reallife_gamemode.Server.Logs
[StringLength(64)]
public string CauseOfDeath { get; set; }
[Timestamp]
public byte[] Timestamp { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public DateTime Timestamp { get; set; }
}
}

View File

@@ -1 +0,0 @@


View File

@@ -5,6 +5,7 @@ using System.Text;
using GTANetworkAPI;
using reallife_gamemode.Server.Entities;
using reallife_gamemode.Server.Extensions;
using reallife_gamemode.Server.Util;
/**
* @overview Life of German Reallife - Managers BankManager (BankManager.cs)
@@ -17,99 +18,42 @@ namespace reallife_gamemode.Server.Managers
{
public class BankManager : Script
{
public static void TransferUserMoneyToUser(User sender, User receiver, int amount, string origin)
public static TransactionResult TransferMoney(IBankAccountOwner sender, IBankAccountOwner receiver, int amount, string origin)
{
using (var transferMoney = new Model.DatabaseContext())
{
if (amount < 0) return TransactionResult.NEGATIVE_MONEY_SENT;
IBankAccount senderAccount = sender.GetBankAccount(transferMoney);
IBankAccount receiverAccount = receiver.GetBankAccount(transferMoney);
if (senderAccount == null) return TransactionResult.SENDER_NO_BANKACCOUNT;
if (receiverAccount == null) return TransactionResult.RECEIVER_NO_BANKACCOUNT;
if (senderAccount.Balance < amount) return TransactionResult.SENDER_NOT_ENOUGH_MONEY;
var transactionLog = new Logs.BankAccountTransactionHistory
{
Sender = sender.Name,
SenderBalance = sender.GetUserBankAccount().Balance,
MoneySent = amount,
SenderBalance = senderAccount.Balance,
Receiver = receiver.Name,
ReceiverBalance = receiver.GetUserBankAccount().Balance,
NewReceiverBalance = receiver.GetUserBankAccount().Balance + amount,
NewSenderBalance = sender.GetUserBankAccount().Balance - amount,
ReceiverBalance = receiverAccount.Balance,
NewReceiverBalance = receiverAccount.Balance + amount,
NewSenderBalance = senderAccount.Balance - amount,
MoneySent = amount,
Fee = 0,
Origin = origin
};
// add log
transferMoney.BankAccountTransactionLogs.Add(transactionLog);
sender.GetUserBankAccount(transferMoney).Balance -= amount;
receiver.GetUserBankAccount(transferMoney).Balance += amount;
senderAccount.Balance -= amount;
receiverAccount.Balance += amount;
transferMoney.SaveChanges();
}
}
public static void TransferUserMoneyToFaction(User sender, Faction receiver, int amount, string origin)
{
using (var transferMoney = new Model.DatabaseContext())
{
var transactionLog = new Logs.BankAccountTransactionHistory
{
Sender = sender.Name,
SenderBalance = sender.GetUserBankAccount().Balance,
MoneySent = amount,
Receiver = receiver.Name,
ReceiverBalance = receiver.BankAccount,
NewReceiverBalance = receiver.BankAccount + amount,
NewSenderBalance = sender.GetUserBankAccount().Balance - amount,
Fee = 0,
Origin = origin
};
transferMoney.BankAccountTransactionLogs.Add(transactionLog);
sender.GetUserBankAccount(transferMoney).Balance -= amount;
receiver.BankAccount += amount;
transferMoney.SaveChanges();
}
}
public static void TransferFactionMoneyToUser(Faction sender, User receiver, int amount, string origin)
{
using (var transferMoney = new Model.DatabaseContext())
{
var transactionLog = new Logs.BankAccountTransactionHistory
{
Sender = sender.Name,
SenderBalance = sender.BankAccount,
MoneySent = amount,
Receiver = receiver.Name,
ReceiverBalance = receiver.GetUserBankAccount().Balance,
NewReceiverBalance = receiver.GetUserBankAccount().Balance + amount,
NewSenderBalance = sender.BankAccount - amount,
Fee = 0,
Origin = origin
};
transferMoney.BankAccountTransactionLogs.Add(transactionLog);
sender.BankAccount -= amount;
receiver.GetUserBankAccount(transferMoney).Balance += amount;
transferMoney.SaveChanges();
}
}
public static void TransferFactionMoneyToFaction(Faction sender, Faction receiver, int amount, string origin)
{
using (var transferMoney = new Model.DatabaseContext())
{
var transactionLog = new Logs.BankAccountTransactionHistory
{
Sender = sender.Name,
SenderBalance = sender.GetFactionBankAccount().Balance,
MoneySent = amount,
Receiver = receiver.Name,
ReceiverBalance = receiver.BankAccount,
NewReceiverBalance = receiver.BankAccount + amount,
NewSenderBalance = sender.BankAccount - amount,
Fee = 0,
Origin = origin
};
transferMoney.BankAccountTransactionLogs.Add(transactionLog);
sender.BankAccount -= amount;
receiver.BankAccount += amount;
transferMoney.SaveChanges();
return TransactionResult.SUCCESS;
}
}
}

View File

@@ -179,6 +179,10 @@ namespace reallife_gamemode.Server.Managers
player.Dimension = 0;
}
/// <summary>
/// Wendet den Character eines Spielers auf diesen an
/// </summary>
/// <param name="player">Der Client, dessen Aussehen man setzen will</param>
public static void ApplyCharacter(Client player)
{
var userId = player.GetUser().Id;

View File

@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GTANetworkAPI;
using reallife_gamemode.Model;
using reallife_gamemode.Server.Entities;
using reallife_gamemode.Server.Extensions;
using reallife_gamemode.Server.Util;
/**
* @overview Life of German Reallife - Managers BankManager (BankManager.cs)
* @author VegaZ
* @copyright (c) 2008 - 2018 Life of German
*/
namespace reallife_gamemode.Server.Managers
{
public class DoorManager : Script
{
public static void ChangeDoorState(Client player)
{
List<Door> NearDoors = new List<Door>();
var user = player.GetUser();
using (var saveDoor = new DatabaseContext())
{
NearDoors = saveDoor.Doors.ToList().FindAll(d => new Vector3(d.X, d.Y, d.Z).DistanceTo(player.Position) <= d.Radius);
foreach (Door d in NearDoors)
{
Door currentDoor = saveDoor.Doors.FirstOrDefault(c => c.Id == d.Id);
if(!user.IsAdmin(AdminLevel.ADMIN) && (d.FactionId != user.FactionId || d.FactionId == null))
{
string lockState = "~r~Du hast kein Recht diese T\u00fcr " + (d.Locked == true ? "auf" : "ab") + "zuschlie\u00dfen!";
player.SendNotification(lockState, true);
continue;
}
currentDoor.Locked = !currentDoor.Locked;
string notStr = d.Name + " " + (d.Locked == false ? "~g~auf" : "~r~ab") + "geschlossen";
player.SendNotification(notStr, true);
NAPI.Pools.GetAllPlayers().ForEach(p => p.TriggerEvent("changeDoorState", d.Model, d.X, d.Y, d.Z, (currentDoor.Locked ? 1 : 0), 0.0f, 0.0f, 0.0f));
}
saveDoor.SaveChanges();
}
}
}
}

View File

@@ -20,7 +20,6 @@ namespace reallife_gamemode.Server.Managers
public static List<Vehicle> ShopVehicleList = new List<Vehicle>();
public static List<Vehicle> UserVehicleList = new List<Vehicle>();
[ServerEvent(Event.ResourceStart)]
public void OnResourceStart()
{
@@ -69,7 +68,7 @@ namespace reallife_gamemode.Server.Managers
NAPI.Vehicle.SetVehicleEngineHealth(current, 0);
var tLabel = NAPI.TextLabel.CreateTextLabel(v.ModelName + " | " + v.Price + "~g~$", new Vector3(v.PositionX, v.PositionY, v.PositionZ + 1.5), 10, 1, 0, new Color(255, 255, 255), false, v.Dimension);
current.SetData("shopVehicleId", v.Id);
tLabel.AttachTo(current, "SKEL_ROOT", new Vector3(v.PositionX, v.PositionY, v.PositionZ + 1.5), new Vector3(0, 0, 0));
tLabel.AttachTo(current, "chassis", new Vector3(0, 0, 1.5), new Vector3(0, 0, 0));
}
}
foreach (UserVehicle v in loadData.UserVehicles)

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Text;
using GTANetworkAPI;
using reallife_gamemode.Server.Entities;
namespace reallife_gamemode.Server.Managers
{
public class PositionManager : Script
{
public static List<DutyPoint> DutyPoints = new List<DutyPoint>();
public static List<ColShape> DutyColShapes = new List<ColShape>();
[ServerEvent(Event.ResourceStart)]
public void OnResourceStart()
{
DutyPoint dutyPointLSPD = new DutyPoint()
{
Position = new Vector3(458.24, -990.86, 30.68),
FactionId = 1
};
DutyPoints.Add(dutyPointLSPD);
foreach (DutyPoint d in DutyPoints)
{
NAPI.Marker.CreateMarker(1, new Vector3(d.Position.X, d.Position.Y, d.Position.Z - 2), new Vector3(d.Position.X, d.Position.Y, d.Position.Z + 1),
new Vector3(0,0,0), 3, new Color(255, 255, 255, 50), false, 0);
NAPI.TextLabel.CreateTextLabel("Stempeluhr - Dr\u00fccke ~y~E\n~s~Dienstkleidung - Dr\u00fccke ~y~K", d.Position, 7, 1, 0, new Color(255, 255, 255), false, 0);
}
}
}
public class DutyPoint
{
public Vector3 Position { get; set; }
public int FactionId { get; set; }
}
}

View File

@@ -11,7 +11,7 @@ namespace reallife_gamemode.Server.Events
public class SaveManager : Script
{
[RemoteEvent("OnSaveBlipData")]
public void OnSaveBlipData(Client player, string blipSprite, string blipName, string blipScale, string blipColor,
public static void OnSaveBlipData(Client player, string blipSprite, string blipName, string blipScale, string blipColor,
string blipAlpha, string blipDrawDistance, string blipShortRange, string blipRotation, string blipDimension)
{
float x = player.Position.X;
@@ -162,7 +162,7 @@ namespace reallife_gamemode.Server.Events
foreach (Vehicle v in LoadManager.FactionVehicleList)
{
int factionId = v.GetData("factionId");
Entities.UserVehicle factionVehicle = saveAll.UserVehicles.FirstOrDefault(u => u.UserId == factionId);
Entities.FactionVehicle factionVehicle = saveAll.FactionVehicles.FirstOrDefault(u => u.FactionId == factionId);
factionVehicle.PositionX = v.Position.X;
factionVehicle.PositionY = v.Position.Y;
factionVehicle.PositionZ = v.Position.Z;

View File

@@ -7,15 +7,19 @@ namespace reallife_gamemode.Server.Managers
{
private static List<ColShape> tuningGarages = new List<ColShape>();
public static void AddTuningGarage(Vector3 pos1, Vector3 pos2)
/// <summary>
/// Fügt eine Tuning-Garage zum Spiel hinzu
/// </summary>
/// <param name="pos">Die Position der Garage</param>
public static void AddTuningGarage(Vector3 pos)
{
ColShape colShape = NAPI.ColShape.CreateSphereColShape(pos1, 10, 0);
ColShape colShape = NAPI.ColShape.CreateSphereColShape(pos, 10, 0);
colShape.OnEntityEnterColShape += (cs, c) =>
{
if(c.IsInVehicle)
{
c.TriggerEvent("showTuningInfo");
c.TriggerEvent("showTuningInfo", c.GetData("duty"));
}
};

View File

@@ -35,4 +35,14 @@ namespace reallife_gamemode.Server.Saves
public byte Dimension { get; set; }
public bool Active { get; set; }
}
public class TempBlip
{
public byte Color { get; set; }
public string Name { get; set; }
public byte Transparency { get; set; }
public bool ShortRange { get; set; }
public uint Sprite { get; set; }
public float Scale { get; set; }
}
}

View File

@@ -37,6 +37,11 @@ namespace reallife_gamemode.Server.Services
player.SendChatMessage("~r~[FEHLER]~s~ Die Aktion wurde nicht ausgeführt.");
}
/// <summary>
/// Sendet eine Nachricht an eine Liste von Fraktionen
/// </summary>
/// <param name="message">Die Nachricht, die gesendet werden soll</param>
/// <param name="factions">Die Liste an Fraktionen, die diese Nachricht bekommen sollen</param>
public static void BroadcastFaction(string message, List<Faction> factions)
{
foreach (Client c in NAPI.Pools.GetAllPlayers())
@@ -52,11 +57,21 @@ namespace reallife_gamemode.Server.Services
}
}
/// <summary>
/// Sendet eine Nachricht an eine Fraktion
/// </summary>
/// <param name="message">Die Nachricht, die gesendet werden soll</param>
/// <param name="f">Die Fraktion, die diese Nachricht bekommen soll</param>
public static void BroadcastFaction(string message, Faction f)
{
BroadcastFaction(message, new List<Faction>() { f });
}
/// <summary>
/// Sendet eine Nachricht an alle Spieler mit einem bestimmten Admin Level
/// </summary>
/// <param name="message">Die Nachricht, die gesendet werden soll</param>
/// <param name="minLevel">Das mindest Admin Level, das für das Erhalten dieser Nachricht benötigt wird</param>
public static void BroadcastAdmin(string message, AdminLevel minLevel)
{
NAPI.Pools.GetAllPlayers().ForEach(p =>

View File

@@ -13,29 +13,29 @@ namespace reallife_gamemode.Server.Services
{
class ClientService
{
public static Client GetClientByName(string name)
/// <summary>
/// Gibt einen Client anhand seines Namens oder der ID zurück
/// </summary>
/// <param name="nameOrId">Die ID oder der Name, nach dem gesucht werden soll</param>
/// <returns></returns>
public static Client GetClientByNameOrId(string nameOrId)
{
/* Funktionsaufbau: Prüft erst, ob ein Spieler mit exakt diesem Namen online ist
* Wenn Ja: Wird dieser zurückgegeben
* Wenn Nein: Wird der erste Spieler zurückgegeben, dessen Namen mit dem eingegebenen Parameter übereinstimmt
* Gibt "null" zurück, falls kein Client gefunden wurde
*/
Client toReturn = null;
name = name.ToLower();
nameOrId = nameOrId.ToLower();
List<Client> playerList = NAPI.Pools.GetAllPlayers();
if(int.TryParse(name, out int id))
if(int.TryParse(nameOrId, out int id))
{
toReturn = playerList.Find(p => p.Handle.Value == id);
return toReturn;
}
toReturn = playerList.Find(p => p.Name.ToLower() == name);
toReturn = playerList.Find(p => p.Name.ToLower() == nameOrId);
if(toReturn == null)
{
toReturn = playerList.Find(p => p.Name.ToLower().StartsWith(name));
toReturn = playerList.Find(p => p.Name.ToLower().StartsWith(nameOrId));
}
return toReturn;

View File

@@ -12,8 +12,12 @@ namespace reallife_gamemode.Server.Util
{
public enum AdminLevel : int
{
PLAYER,
SUPPORTER,
ADMIN
PLAYER = 0,
SUPPORTER = 1,
ADMIN = 2,
ADMIN2 = 3,
ADMIN3 = 4,
HEADADMIN = 1337,
PROJEKTLEITUNG = 1338
}
}

40
Server/Util/Converter.cs Normal file
View File

@@ -0,0 +1,40 @@
using GTANetworkAPI;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
namespace reallife_gamemode.Server.Util
{
public class Converter
{
public static Color HexToColor(string hexColor)
{
//Remove # if present
if (hexColor.IndexOf('#') != -1)
hexColor = hexColor.Replace("#", "");
int red = 0;
int green = 0;
int blue = 0;
if (hexColor.Length == 6)
{
//#RRGGBB
red = int.Parse(hexColor.Substring(0, 2), NumberStyles.AllowHexSpecifier);
green = int.Parse(hexColor.Substring(2, 2), NumberStyles.AllowHexSpecifier);
blue = int.Parse(hexColor.Substring(4, 2), NumberStyles.AllowHexSpecifier);
}
else if (hexColor.Length == 3)
{
//#RGB
red = int.Parse(hexColor[0].ToString() + hexColor[0].ToString(), NumberStyles.AllowHexSpecifier);
green = int.Parse(hexColor[1].ToString() + hexColor[1].ToString(), NumberStyles.AllowHexSpecifier);
blue = int.Parse(hexColor[2].ToString() + hexColor[2].ToString(), NumberStyles.AllowHexSpecifier);
}
Color returnColor = new Color(red, green, blue);
return returnColor;
}
}
}

View File

@@ -0,0 +1,22 @@
using GTANetworkAPI;
using reallife_gamemode.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace reallife_gamemode.Server.Util
{
class DatabaseHelper
{
public static void InitDatabaseFirstTime()
{
NAPI.Util.ConsoleOutput("Initializing database...");
using(var dbContext = new DatabaseContext())
{
dbContext.Users.First();
dbContext.SaveChanges();
}
}
}
}

View File

@@ -0,0 +1,37 @@
using GTANetworkAPI;
using reallife_gamemode.Model;
using reallife_gamemode.Server.Entities;
using System;
using System.Collections.Generic;
using System.Text;
namespace reallife_gamemode.Server.Util
{
class FactionHelper
{
public static void CheckFactionBankAccounts()
{
NAPI.Util.ConsoleOutput("Checking faction bank accounts...");
using(var dbContext = new DatabaseContext())
{
foreach(Faction faction in dbContext.Factions)
{
if(faction.GetBankAccount(dbContext) == null)
{
NAPI.Util.ConsoleOutput("Adding bank account for faction: " + faction.Name);
FactionBankAccount factionBankAccount = new FactionBankAccount()
{
Balance = 0,
Bic = "",
Iban = "",
FactionId = faction.Id,
Active = true
};
dbContext.FactionBankAccounts.Add(factionBankAccount);
}
}
dbContext.SaveChanges();
}
}
}
}

View File

@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace reallife_gamemode.Server.Util
{
public interface IBankAccount
{
int Balance { get; set; }
}
}

View File

@@ -0,0 +1,14 @@
using reallife_gamemode.Model;
using System;
using System.Collections.Generic;
using System.Text;
namespace reallife_gamemode.Server.Util
{
public interface IBankAccountOwner
{
string Name { get; }
IBankAccount GetBankAccount(DatabaseContext databaseContext = null);
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace reallife_gamemode.Server.Util
{
public enum TransactionResult
{
SUCCESS,
SENDER_NO_BANKACCOUNT,
RECEIVER_NO_BANKACCOUNT,
SENDER_NOT_ENOUGH_MONEY,
NEGATIVE_MONEY_SENT
}
}