add house entity
This commit is contained in:
36
ReallifeGamemode.Server/Entities/House.cs
Normal file
36
ReallifeGamemode.Server/Entities/House.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using GTANetworkAPI;
|
||||||
|
using ReallifeGamemode.Server.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace ReallifeGamemode.Server.Entities
|
||||||
|
{
|
||||||
|
public class House
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Type { get; set; }
|
||||||
|
|
||||||
|
public int Price { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey("User")]
|
||||||
|
public int? UserId { get; set; }
|
||||||
|
public User User { get; set; }
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public Client Owner
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
using (var dbContext = new DatabaseContext())
|
||||||
|
return dbContext.Users.Where(u => u.Id == this.UserId).FirstOrDefault()?.Client;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -55,6 +55,8 @@ namespace ReallifeGamemode.Server.Entities
|
|||||||
public int? BanId { get; set; }
|
public int? BanId { get; set; }
|
||||||
public Ban Ban { get; set; }
|
public Ban Ban { get; set; }
|
||||||
|
|
||||||
|
public int? BusinessId { get; set; }
|
||||||
|
|
||||||
public int? FactionId { get; set; }
|
public int? FactionId { get; set; }
|
||||||
public Faction Faction { get; set; }
|
public Faction Faction { get; set; }
|
||||||
|
|
||||||
@@ -67,6 +69,9 @@ namespace ReallifeGamemode.Server.Entities
|
|||||||
|
|
||||||
public GroupRank GroupRank { get; set; }
|
public GroupRank GroupRank { get; set; }
|
||||||
|
|
||||||
|
public House House { get; set; }
|
||||||
|
public int? HouseId { get; set; }
|
||||||
|
|
||||||
public int? JobId { get; set; }
|
public int? JobId { get; set; }
|
||||||
|
|
||||||
public int Wanteds
|
public int Wanteds
|
||||||
@@ -79,80 +84,6 @@ namespace ReallifeGamemode.Server.Entities
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public FactionRank GetFactionRank()
|
|
||||||
{
|
|
||||||
using (var dbContext = new DatabaseContext())
|
|
||||||
{
|
|
||||||
FactionRank toReturn = dbContext.FactionRanks.FirstOrDefault(fR => fR.Id == FactionRankId);
|
|
||||||
if (toReturn == null)
|
|
||||||
{
|
|
||||||
toReturn = dbContext.FactionRanks.OrderBy(f => f.Order).FirstOrDefault(f => f.FactionId == FactionId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (toReturn == null)
|
|
||||||
{
|
|
||||||
toReturn = new FactionRank
|
|
||||||
{
|
|
||||||
RankName = "Rang-Fehler"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return toReturn;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int? BusinessId { get; set; }
|
|
||||||
|
|
||||||
public void BanPlayer(Client admin, string reason, int mins)
|
|
||||||
{
|
|
||||||
using (var banUserContext = new DatabaseContext())
|
|
||||||
{
|
|
||||||
int unixTimestamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
|
||||||
Ban banUser;
|
|
||||||
|
|
||||||
if (mins == 0)
|
|
||||||
{
|
|
||||||
ChatService.Broadcast("!{#FF4040}[BAN] " + this.Name + " wurde von " + admin.Name + " permanent gebannt. [" + reason + "]");
|
|
||||||
banUser = new Ban { UserId = this.Id, Reason = reason, BannedBy = admin.Name, Applied = unixTimestamp, UntilDateTime = unixTimestamp };
|
|
||||||
|
|
||||||
this.Client?.Kick();
|
|
||||||
|
|
||||||
mins--;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ChatService.Broadcast("!{#FF4040}[BAN] " + this.Name + " wurde von " + admin.Name + " für " + mins + " Minuten gebannt. [" + reason + "]");
|
|
||||||
banUser = new Ban { UserId = this.Id, Reason = reason, BannedBy = admin.Name, Applied = unixTimestamp, UntilDateTime = unixTimestamp + mins * 60 };
|
|
||||||
this.Client?.Kick();
|
|
||||||
}
|
|
||||||
|
|
||||||
banUserContext.Bans.Add(banUser);
|
|
||||||
banUserContext.SaveChanges();
|
|
||||||
|
|
||||||
var targetUser = banUserContext.Users.FirstOrDefault(u => u.Name == this.Name);
|
|
||||||
targetUser.BanId = banUser.Id;
|
|
||||||
banUserContext.SaveChanges();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UnbanPlayer()
|
|
||||||
{
|
|
||||||
using (var unbanUser = new DatabaseContext())
|
|
||||||
{
|
|
||||||
var targetUser = unbanUser.Users.FirstOrDefault(u => u.Id == this.Id);
|
|
||||||
targetUser.BanId = null;
|
|
||||||
unbanUser.SaveChanges();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<UserItem> GetItems()
|
|
||||||
{
|
|
||||||
using (var dbContext = new DatabaseContext())
|
|
||||||
{
|
|
||||||
return dbContext.UserItems.ToList().FindAll(u => u.UserId == this.Id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsAdmin(AdminLevel level) => AdminLevel >= level;
|
public bool IsAdmin(AdminLevel level) => AdminLevel >= level;
|
||||||
|
|
||||||
public IBankAccount GetBankAccount(DatabaseContext databaseContext = null)
|
public IBankAccount GetBankAccount(DatabaseContext databaseContext = null)
|
||||||
@@ -176,34 +107,6 @@ namespace ReallifeGamemode.Server.Entities
|
|||||||
get => NAPI.Pools.GetAllPlayers().Where(c => c.Name.ToLower() == this.Name.ToLower()).FirstOrDefault();
|
get => NAPI.Pools.GetAllPlayers().Where(c => c.Name.ToLower() == this.Name.ToLower()).FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal T GetData<T>(string key, T nullValue)
|
|
||||||
{
|
|
||||||
key += "data_";
|
|
||||||
if (!Client.HasData(key)) return nullValue;
|
|
||||||
return JsonConvert.DeserializeObject<T>(Client.GetData(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
internal T GetData<T>(string key) => GetData<T>(key, default);
|
|
||||||
|
|
||||||
internal void SetData(string key, object value)
|
|
||||||
{
|
|
||||||
key += "data_";
|
|
||||||
Client.SetData(key, JsonConvert.SerializeObject(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void GiveWanteds(Client cop, int amount, string reason)
|
|
||||||
{
|
|
||||||
if (this.Wanteds + amount > 40)
|
|
||||||
{
|
|
||||||
ChatService.ErrorMessage(cop, "Die Wanteds dürfen ein Limit von 40 nicht überschreiten");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
using (var dbContext = new DatabaseContext())
|
|
||||||
{
|
|
||||||
User user = dbContext.Users.Where(u => u.Id == this.Id).FirstOrDefault();
|
|
||||||
user.Wanteds += amount;
|
|
||||||
dbContext.SaveChanges();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
using GTANetworkAPI;
|
using GTANetworkAPI;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using ReallifeGamemode.Server.Entities;
|
using ReallifeGamemode.Server.Entities;
|
||||||
using ReallifeGamemode.Server.Models;
|
using ReallifeGamemode.Server.Models;
|
||||||
|
using ReallifeGamemode.Server.Services;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,5 +74,105 @@ namespace ReallifeGamemode.Server.Extensions
|
|||||||
return newpos;
|
return newpos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static T GetData<T>(this User user, string key, T nullValue)
|
||||||
|
{
|
||||||
|
key += "data_";
|
||||||
|
if (!user.Client.HasData(key)) return nullValue;
|
||||||
|
return JsonConvert.DeserializeObject<T>(user.Client.GetData(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static T GetData<T>(this User user, string key) => user.GetData<T>(key, default);
|
||||||
|
|
||||||
|
internal static void SetData(this User user, string key, object value)
|
||||||
|
{
|
||||||
|
key += "data_";
|
||||||
|
user.Client.SetData(key, JsonConvert.SerializeObject(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void GiveWanteds(this User user, Client cop, int amount, string reason)
|
||||||
|
{
|
||||||
|
if (user.Wanteds + amount > 40)
|
||||||
|
{
|
||||||
|
ChatService.ErrorMessage(cop, "Die Wanteds dürfen ein Limit von 40 nicht überschreiten");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
using (var dbContext = new DatabaseContext())
|
||||||
|
{
|
||||||
|
User dbUser = dbContext.Users.Where(u => u.Id == user.Id).FirstOrDefault();
|
||||||
|
dbUser.Wanteds += amount;
|
||||||
|
dbContext.SaveChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static FactionRank GetFactionRank(this User user)
|
||||||
|
{
|
||||||
|
using (var dbContext = new DatabaseContext())
|
||||||
|
{
|
||||||
|
FactionRank toReturn = dbContext.FactionRanks.FirstOrDefault(fR => fR.Id == user.FactionRankId);
|
||||||
|
if (toReturn == null)
|
||||||
|
{
|
||||||
|
toReturn = dbContext.FactionRanks.OrderBy(f => f.Order).FirstOrDefault(f => f.FactionId == user.FactionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toReturn == null)
|
||||||
|
{
|
||||||
|
toReturn = new FactionRank
|
||||||
|
{
|
||||||
|
RankName = "Rang-Fehler"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void BanPlayer(this User user, Client admin, string reason, int mins)
|
||||||
|
{
|
||||||
|
using (var banUserContext = new DatabaseContext())
|
||||||
|
{
|
||||||
|
int unixTimestamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
||||||
|
Ban banUser;
|
||||||
|
|
||||||
|
if (mins == 0)
|
||||||
|
{
|
||||||
|
ChatService.Broadcast("!{#FF4040}[BAN] " + user.Name + " wurde von " + admin.Name + " permanent gebannt. [" + reason + "]");
|
||||||
|
banUser = new Ban { UserId = user.Id, Reason = reason, BannedBy = admin.Name, Applied = unixTimestamp, UntilDateTime = unixTimestamp };
|
||||||
|
|
||||||
|
user.Client?.Kick();
|
||||||
|
|
||||||
|
mins--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ChatService.Broadcast("!{#FF4040}[BAN] " + user.Name + " wurde von " + admin.Name + " für " + mins + " Minuten gebannt. [" + reason + "]");
|
||||||
|
banUser = new Ban { UserId = user.Id, Reason = reason, BannedBy = admin.Name, Applied = unixTimestamp, UntilDateTime = unixTimestamp + mins * 60 };
|
||||||
|
user.Client?.Kick();
|
||||||
|
}
|
||||||
|
|
||||||
|
banUserContext.Bans.Add(banUser);
|
||||||
|
banUserContext.SaveChanges();
|
||||||
|
|
||||||
|
var targetUser = banUserContext.Users.Where(u => u.Name == user.Name).FirstOrDefault();
|
||||||
|
targetUser.BanId = banUser.Id;
|
||||||
|
banUserContext.SaveChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void UnbanPlayer(this User user)
|
||||||
|
{
|
||||||
|
using (var unbanUser = new DatabaseContext())
|
||||||
|
{
|
||||||
|
var targetUser = unbanUser.Users.Where(u => u.Id == user.Id).FirstOrDefault();
|
||||||
|
targetUser.BanId = null;
|
||||||
|
unbanUser.SaveChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<UserItem> GetItems(this User user)
|
||||||
|
{
|
||||||
|
using (var dbContext = new DatabaseContext())
|
||||||
|
{
|
||||||
|
return dbContext.UserItems.Where(u => u.UserId == user.Id).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1148
ReallifeGamemode.Server/Migrations/20190626193631_House.Designer.cs
generated
Normal file
1148
ReallifeGamemode.Server/Migrations/20190626193631_House.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
53
ReallifeGamemode.Server/Migrations/20190626193631_House.cs
Normal file
53
ReallifeGamemode.Server/Migrations/20190626193631_House.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
namespace ReallifeGamemode.Migrations
|
||||||
|
{
|
||||||
|
public partial class House : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "HouseId",
|
||||||
|
table: "Users",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Houses",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(nullable: false)
|
||||||
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||||
|
Type = table.Column<string>(nullable: true),
|
||||||
|
Price = table.Column<int>(nullable: false),
|
||||||
|
UserId = table.Column<int>(nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Houses", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Houses_Users_UserId",
|
||||||
|
column: x => x.UserId,
|
||||||
|
principalTable: "Users",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Restrict);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Houses_UserId",
|
||||||
|
table: "Houses",
|
||||||
|
column: "UserId",
|
||||||
|
unique: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Houses");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "HouseId",
|
||||||
|
table: "Users");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -404,6 +404,25 @@ namespace ReallifeGamemode.Migrations
|
|||||||
b.ToTable("GroupBankAccounts");
|
b.ToTable("GroupBankAccounts");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ReallifeGamemode.Server.Entities.House", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<int>("Price");
|
||||||
|
|
||||||
|
b.Property<string>("Type");
|
||||||
|
|
||||||
|
b.Property<int?>("UserId");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("Houses");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("ReallifeGamemode.Server.Entities.Interior", b =>
|
modelBuilder.Entity("ReallifeGamemode.Server.Entities.Interior", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@@ -780,6 +799,8 @@ namespace ReallifeGamemode.Migrations
|
|||||||
|
|
||||||
b.Property<int>("Handmoney");
|
b.Property<int>("Handmoney");
|
||||||
|
|
||||||
|
b.Property<int?>("HouseId");
|
||||||
|
|
||||||
b.Property<int?>("JobId");
|
b.Property<int?>("JobId");
|
||||||
|
|
||||||
b.Property<int>("LogUserId");
|
b.Property<int>("LogUserId");
|
||||||
@@ -1025,6 +1046,13 @@ namespace ReallifeGamemode.Migrations
|
|||||||
.HasForeignKey("GroupId");
|
.HasForeignKey("GroupId");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ReallifeGamemode.Server.Entities.House", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("ReallifeGamemode.Server.Entities.User", "User")
|
||||||
|
.WithOne("House")
|
||||||
|
.HasForeignKey("ReallifeGamemode.Server.Entities.House", "UserId");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("ReallifeGamemode.Server.Entities.Logs.Death", b =>
|
modelBuilder.Entity("ReallifeGamemode.Server.Entities.Logs.Death", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("ReallifeGamemode.Server.Entities.User", "Killer")
|
b.HasOne("ReallifeGamemode.Server.Entities.User", "Killer")
|
||||||
|
|||||||
@@ -102,5 +102,8 @@ namespace ReallifeGamemode.Server.Models
|
|||||||
|
|
||||||
// Jobs
|
// Jobs
|
||||||
public DbSet<Entities.JobVehicle> JobVehicles { get; set; }
|
public DbSet<Entities.JobVehicle> JobVehicles { get; set; }
|
||||||
|
|
||||||
|
// Houses
|
||||||
|
public DbSet<Entities.House> Houses { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user