save locations
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
|
||||
namespace ReallifeGamemode.DataService.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Produces("application/json")]
|
||||
[Route("DataService/[controller]")]
|
||||
public class LocationController : ControllerBase
|
||||
{
|
||||
private readonly DatabaseContext dbContext;
|
||||
|
||||
public LocationController(DatabaseContext dbContext)
|
||||
{
|
||||
this.dbContext = dbContext;
|
||||
}
|
||||
|
||||
[HttpGet("GetLocations")]
|
||||
public ActionResult<IEnumerable<string>> GetLocations()
|
||||
{
|
||||
var list = this.dbContext.Locations.OrderByDescending(l => l.Id);
|
||||
|
||||
List<string> locations = new List<string>();
|
||||
|
||||
foreach(var location in list)
|
||||
{
|
||||
locations.Add($"{location.Description.PadRight(20)} - {Math.Round(location.X, 2).ToString(CultureInfo.InvariantCulture)}, {Math.Round(location.Y, 2).ToString(CultureInfo.InvariantCulture)}, {Math.Round(location.Z, 2).ToString(CultureInfo.InvariantCulture)}");
|
||||
}
|
||||
|
||||
return locations;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ namespace ReallifeGamemode.DataService.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("DataService/User")]
|
||||
[Route("DataService/[controller]")]
|
||||
[Produces("application/json")]
|
||||
public class UserController : ControllerBase
|
||||
{
|
||||
|
||||
@@ -14,10 +14,6 @@
|
||||
<None Remove="logs\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="wwwroot\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="log4net" Version="2.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.11" />
|
||||
|
||||
@@ -131,6 +131,8 @@ namespace ReallifeGamemode.DataService
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseCors(c =>
|
||||
{
|
||||
c.AllowAnyOrigin()
|
||||
|
||||
73
ReallifeGamemode.DataService/wwwroot/locations.html
Normal file
73
ReallifeGamemode.DataService/wwwroot/locations.html
Normal file
@@ -0,0 +1,73 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Orte</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: sans-serif;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<label for="username">Username</label>
|
||||
<input type="text" id="username" />
|
||||
|
||||
<label for="password">Passwort</label>
|
||||
<input type="password" id="password" />
|
||||
|
||||
<input type="button" value="Anmelden" id="login-btn" />
|
||||
|
||||
<span id="login-status"></span>
|
||||
|
||||
<br />
|
||||
<input type="button" value="Gespeicherte Orte laden" id="fetch-locations-btn" />
|
||||
<br />
|
||||
|
||||
<ul id="location-list"></ul>
|
||||
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
|
||||
var token = null;
|
||||
var list = $("#location-list");
|
||||
|
||||
$("#login-btn").click(function () {
|
||||
var username = $("#username").val();
|
||||
var password = $("#password").val();
|
||||
|
||||
$.ajax({
|
||||
url: 'DataService/Auth/Login',
|
||||
type: 'post',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify({
|
||||
username: username,
|
||||
password: password
|
||||
})
|
||||
}).done(function (result) {
|
||||
token = result.token;
|
||||
$("#login-status").text("Erfolgreich angemeldet");
|
||||
}).fail(function () {
|
||||
$("#login-status").text("Login fehlgeschlagen");
|
||||
});
|
||||
});
|
||||
|
||||
$("#fetch-locations-btn").click(function () {
|
||||
list.empty();
|
||||
$.ajax({
|
||||
url: 'DataService/Location/GetLocations',
|
||||
type: 'get',
|
||||
headers: {
|
||||
Authorization: 'Bearer ' + token
|
||||
}
|
||||
}).done(function (result) {
|
||||
result.forEach(function (item) {
|
||||
list.append(`<li>${item}</li>`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
21
ReallifeGamemode.Database/Entities/Location.cs
Normal file
21
ReallifeGamemode.Database/Entities/Location.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
namespace ReallifeGamemode.Database.Entities
|
||||
{
|
||||
public class Location
|
||||
{
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public double X { get; set; }
|
||||
|
||||
public double Y { get; set; }
|
||||
|
||||
public double Z { get; set; }
|
||||
}
|
||||
}
|
||||
1335
ReallifeGamemode.Database/Migrations/20190929200617_SavedLocations.Designer.cs
generated
Normal file
1335
ReallifeGamemode.Database/Migrations/20190929200617_SavedLocations.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,33 @@
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace ReallifeGamemode.Database.Migrations
|
||||
{
|
||||
public partial class SavedLocations : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Locations",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
Description = table.Column<string>(nullable: true),
|
||||
X = table.Column<double>(nullable: false),
|
||||
Y = table.Column<double>(nullable: false),
|
||||
Z = table.Column<double>(nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Locations", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Locations");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ namespace ReallifeGamemode.Database.Migrations
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "2.2.6-servicing-10079")
|
||||
.HasAnnotation("ProductVersion", "2.1.11-servicing-32099")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Database.Entities.ATM", b =>
|
||||
@@ -61,6 +61,37 @@ namespace ReallifeGamemode.Database.Migrations
|
||||
b.ToTable("Bans");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Database.Entities.BusinessBankAccount", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<int>("Balance");
|
||||
|
||||
b.Property<int>("BusinessId");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BusinessId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("BusinessBankAccounts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Database.Entities.BusinessData", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<int>("BusinessId");
|
||||
|
||||
b.Property<int>("Price");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("BusinessData");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Database.Entities.BusRoute", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@@ -95,37 +126,6 @@ namespace ReallifeGamemode.Database.Migrations
|
||||
b.ToTable("BusRoutesPoints");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Database.Entities.BusinessBankAccount", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<int>("Balance");
|
||||
|
||||
b.Property<int>("BusinessId");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BusinessId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("BusinessBankAccounts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Database.Entities.BusinessData", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<int>("BusinessId");
|
||||
|
||||
b.Property<int>("Price");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("BusinessData");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Database.Entities.Character", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@@ -536,6 +536,24 @@ namespace ReallifeGamemode.Database.Migrations
|
||||
b.ToTable("Interiors");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Database.Entities.Location", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("Description");
|
||||
|
||||
b.Property<double>("X");
|
||||
|
||||
b.Property<double>("Y");
|
||||
|
||||
b.Property<double>("Z");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Locations");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ReallifeGamemode.Database.Entities.Logs.BankAccountTransactionHistory", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@@ -1064,6 +1082,8 @@ namespace ReallifeGamemode.Database.Migrations
|
||||
|
||||
b.HasIndex("GroupId");
|
||||
|
||||
b.ToTable("GroupVehicle");
|
||||
|
||||
b.HasDiscriminator().HasValue("GroupVehicle");
|
||||
});
|
||||
|
||||
@@ -1073,6 +1093,8 @@ namespace ReallifeGamemode.Database.Migrations
|
||||
|
||||
b.Property<int>("JobId");
|
||||
|
||||
b.ToTable("JobVehicle");
|
||||
|
||||
b.HasDiscriminator().HasValue("JobVehicle");
|
||||
});
|
||||
|
||||
@@ -1080,6 +1102,9 @@ namespace ReallifeGamemode.Database.Migrations
|
||||
{
|
||||
b.HasBaseType("ReallifeGamemode.Database.Entities.ServerVehicle");
|
||||
|
||||
|
||||
b.ToTable("SavedVehicle");
|
||||
|
||||
b.HasDiscriminator().HasValue("SavedVehicle");
|
||||
});
|
||||
|
||||
|
||||
@@ -87,6 +87,7 @@ namespace ReallifeGamemode.Database.Models
|
||||
|
||||
// Control Panel
|
||||
public DbSet<Entities.News> News { get; set; }
|
||||
public DbSet<Entities.Location> Locations { get; set; }
|
||||
|
||||
// Server Vehicles
|
||||
public DbSet<Entities.ServerVehicle> ServerVehicles { get; set; }
|
||||
|
||||
@@ -1737,7 +1737,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
}
|
||||
}
|
||||
|
||||
[Command("save", "~m~Benutzung: ~s~/save [Typ = ~g~Blip~s~, ~g~Goto (X)~s~, ~r~Marker~s~, ~r~Ped~s~, ~r~Pickup~s~, ~r~TextLabel~s~, ~g~Vehicle~s~, ~g~FVehicle~s~, ~g~SVehicle (X)~s~, ~g~JVehicle (X)~s~] (Weitere Angaben) = (X)")]
|
||||
[Command("save", "~m~Benutzung: ~s~/save [Typ = ~g~Blip~s~, ~g~Goto (X)~s~, ~r~Marker~s~, ~r~Ped~s~, ~r~Pickup~s~, ~r~TextLabel~s~, ~g~Vehicle~s~, ~g~FVehicle~s~, ~g~SVehicle (X)~s~, ~g~JVehicle (X)~s~, ~g~Location~s~] (Weitere Angaben) = (X)")]
|
||||
public void CmdAdminSave(Client player, string typ, string option1 = null, string option2 = null)
|
||||
{
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
|
||||
@@ -1745,6 +1745,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
ChatService.NotAuthorized(player);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (typ.ToLower())
|
||||
{
|
||||
case "blip":
|
||||
@@ -1849,6 +1850,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
}
|
||||
else ChatService.SendMessage(player, "~m~Du sitzt in keinem Fahrzeug!");
|
||||
break;
|
||||
|
||||
case "svehicle":
|
||||
if (player.IsInVehicle)
|
||||
{
|
||||
@@ -1888,6 +1890,28 @@ namespace ReallifeGamemode.Server.Commands
|
||||
else ChatService.SendMessage(player, "~m~Du sitzt in keinem Fahrzeug!");
|
||||
break;
|
||||
|
||||
case "location":
|
||||
if(option1 == null || option1.Length < 0)
|
||||
{
|
||||
ChatService.SendMessage(player, "~m~Benutzung: ~s~/save location [Beschreibung]");
|
||||
return;
|
||||
}
|
||||
|
||||
using(var dbContext = new DatabaseContext())
|
||||
{
|
||||
dbContext.Locations.Add(new Location
|
||||
{
|
||||
Description = option1,
|
||||
X = player.Position.X,
|
||||
Y = player.Position.Y,
|
||||
Z = player.Position.Z,
|
||||
});
|
||||
|
||||
dbContext.SaveChanges();
|
||||
|
||||
player.SendNotification("Die Position wurde gespeichert");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace ReallifeGamemode.Server.Events
|
||||
public class EnterVehicleAttempt : Script
|
||||
{
|
||||
[ServerEvent(Event.PlayerEnterVehicleAttempt)]
|
||||
public void OnPlayerEnterVehicleAttempt(Client player, Vehicle vehicle, sbyte seat)
|
||||
public void OnPlayerEnterVehicleAttempt(Client player, GTANetworkAPI.Vehicle vehicle, sbyte seat)
|
||||
{
|
||||
if ((VehicleHash)vehicle.Model == VehicleHash.Dune3)
|
||||
{
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace ReallifeGamemode.Server.Events
|
||||
{
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
foreach (Vehicle veh in NAPI.Pools.GetAllVehicles())
|
||||
foreach (GTANetworkAPI.Vehicle veh in NAPI.Pools.GetAllVehicles())
|
||||
{
|
||||
List<string> iName = new List<string>();
|
||||
List<int> iAmount = new List<int>();
|
||||
|
||||
@@ -382,7 +382,7 @@ namespace ReallifeGamemode.Server.Events
|
||||
if (!player.IsInVehicle) return;
|
||||
if (player.VehicleSeat != -1) return;
|
||||
|
||||
Vehicle v = player.Vehicle;
|
||||
GTANetworkAPI.Vehicle v = player.Vehicle;
|
||||
|
||||
User u = player.GetUser();
|
||||
if (u == null) return;
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace ReallifeGamemode.Server.Events
|
||||
public void ToggleSirenEvent(Client player)
|
||||
{
|
||||
if (!player.IsInVehicle || player.VehicleSeat != -1) return;
|
||||
Vehicle pV = player.Vehicle;
|
||||
GTANetworkAPI.Vehicle pV = player.Vehicle;
|
||||
bool oldValue = _sirenStates.ContainsKey(pV.Handle) ? _sirenStates[pV.Handle] : false;
|
||||
bool newValue = !oldValue;
|
||||
|
||||
|
||||
@@ -8,14 +8,14 @@ using System;
|
||||
|
||||
namespace ReallifeGamemode.Server.Events
|
||||
{
|
||||
public class VehicleMenu : Script
|
||||
public class Vehicle : Script
|
||||
{
|
||||
[RemoteEvent("VehicleMenu_ToggleEngine")]
|
||||
public void VehicleMenuToggleEngineEvent(Client player)
|
||||
{
|
||||
if (player.IsInVehicle && player.VehicleSeat == -1)
|
||||
{
|
||||
Vehicle v = player.Vehicle;
|
||||
GTANetworkAPI.Vehicle v = player.Vehicle;
|
||||
|
||||
User u = player.GetUser();
|
||||
if (u == null) return;
|
||||
@@ -69,7 +69,7 @@ namespace ReallifeGamemode.Server.Events
|
||||
{
|
||||
if (player.IsInVehicle && player.VehicleSeat == -1)
|
||||
{
|
||||
Vehicle v = player.Vehicle;
|
||||
GTANetworkAPI.Vehicle v = player.Vehicle;
|
||||
|
||||
User u = player.GetUser();
|
||||
if (u == null) return;
|
||||
@@ -112,7 +112,7 @@ namespace ReallifeGamemode.Server.Events
|
||||
{
|
||||
if (player.IsInVehicle && player.VehicleSeat == -1)
|
||||
{
|
||||
Vehicle v = player.Vehicle;
|
||||
GTANetworkAPI.Vehicle v = player.Vehicle;
|
||||
|
||||
User u = player.GetUser();
|
||||
if (u == null) return;
|
||||
@@ -166,7 +166,7 @@ namespace ReallifeGamemode.Server.Events
|
||||
public void VehicleMenuToggleSingleDoorEvent(Client player, int door)
|
||||
{
|
||||
if (!player.IsInVehicle) return;
|
||||
Vehicle veh = player.Vehicle;
|
||||
GTANetworkAPI.Vehicle veh = player.Vehicle;
|
||||
|
||||
DoorID doorId = (DoorID)door;
|
||||
|
||||
@@ -179,7 +179,7 @@ namespace ReallifeGamemode.Server.Events
|
||||
public void VehicleMenuOpenAllDoorsEvent(Client player)
|
||||
{
|
||||
if (!player.IsInVehicle) return;
|
||||
Vehicle veh = player.Vehicle;
|
||||
GTANetworkAPI.Vehicle veh = player.Vehicle;
|
||||
|
||||
foreach (DoorID doorId in Enum.GetValues(typeof(DoorID)))
|
||||
{
|
||||
@@ -191,12 +191,18 @@ namespace ReallifeGamemode.Server.Events
|
||||
public void VehicleMenuCloseAllDoorsEvent(Client player)
|
||||
{
|
||||
if (!player.IsInVehicle) return;
|
||||
Vehicle veh = player.Vehicle;
|
||||
GTANetworkAPI.Vehicle veh = player.Vehicle;
|
||||
|
||||
foreach (DoorID doorId in Enum.GetValues(typeof(DoorID)))
|
||||
{
|
||||
VehicleStreaming.SetDoorState(veh, doorId, DoorState.DoorClosed);
|
||||
}
|
||||
}
|
||||
|
||||
[ServerEvent(Event.VehicleDeath)]
|
||||
public void VehicleDeathEvent(GTANetworkAPI.Vehicle veh)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,9 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.11" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.11" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.1.11" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.10" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
|
||||
Reference in New Issue
Block a user