Update 29.10.2022
This commit is contained in:
15
C#/Mosleys/Mosleys.Server/ESX/Server/ESX.Config.Weapons.cs
Normal file
15
C#/Mosleys/Mosleys.Server/ESX/Server/ESX.Config.Weapons.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace Nexd.ESX.Server
|
||||
{
|
||||
public static partial class ESX
|
||||
{
|
||||
public static partial class Config
|
||||
{
|
||||
public static class Weapons
|
||||
{
|
||||
public static dynamic Raw => Config.Raw.Weapons;
|
||||
|
||||
public static string[] DefaultWeaponTints => Raw.DefaultWeaponTints;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
C#/Mosleys/Mosleys.Server/ESX/Server/ESX.Config.cs
Normal file
21
C#/Mosleys/Mosleys.Server/ESX/Server/ESX.Config.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace Nexd.ESX.Server
|
||||
{
|
||||
public static partial class ESX
|
||||
{
|
||||
public static partial class Config
|
||||
{
|
||||
public static dynamic Raw => ESX.Raw.Config ?? (ESX.Raw.Config);
|
||||
|
||||
public static string Locale => Raw.Locale;
|
||||
|
||||
public static string[] Accounts => new string[] { Raw.Accounts.bank, Raw.Accounts.money, Raw.Accounts.black_money };
|
||||
|
||||
public static dynamic StartingAccountMoney => Raw.StartingAccountMoney;
|
||||
public static bool EnableSocietyPayouts => Raw.EnableSocietyPayouts;
|
||||
public static bool EnableHud => Raw.EnableHud;
|
||||
public static int MaxWeight => Raw.MaxWeight;
|
||||
public static int PaycheckInterval => Raw.PaycheckInterval;
|
||||
public static bool EnableDebug => Raw.EnableDebug;
|
||||
}
|
||||
}
|
||||
}
|
||||
56
C#/Mosleys/Mosleys.Server/ESX/Server/ESX.cs
Normal file
56
C#/Mosleys/Mosleys.Server/ESX/Server/ESX.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
namespace Nexd.ESX.Server
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using CitizenFX.Core;
|
||||
|
||||
public static partial class ESX
|
||||
{
|
||||
public static dynamic Raw;
|
||||
|
||||
static ESX() => BaseScript.TriggerEvent("esx:getSharedObject", new object[] { new Action<dynamic>(esx => { Raw = esx; }) });
|
||||
|
||||
public static xPlayer GetPlayerFromId(int playerid) => new xPlayer(Raw.GetPlayerFromId(playerid));
|
||||
public static xPlayer GetPlayerFromIdentifier(string identifier) => new xPlayer(Raw.GetPlayerFromIdentifier(identifier));
|
||||
public static dynamic GetPlayerFromIdEx(int playerid) => Raw.GetPlayerFromId(playerid);
|
||||
public static dynamic GetPlayerFromIdentifierEx(string identifier) => Raw.GetPlayerFromIdentifier(identifier);
|
||||
public static bool DoesJobExist(string job, int grade) => Raw.DoesJobExist(job, grade);
|
||||
public static void SavePlayer(xPlayer xPlayer, Action callback = null) => Raw.SavePlayer(xPlayer.Raw, callback);
|
||||
public static void SavePlayers(Action callback = null) => Raw.SavePlayers(callback);
|
||||
public static void CreatePickup(
|
||||
string itemType,
|
||||
string itemName,
|
||||
int count,
|
||||
string label,
|
||||
int playerid,
|
||||
[Optional, DefaultParameterValue(null)]List<string> components,
|
||||
[Optional, DefaultParameterValue(0)]int tintIndex) =>
|
||||
Raw.CreatePickup(itemType, itemName, count, label, playerid, components, tintIndex);
|
||||
public static void UseItem(int playerid, string itemName) => Raw.UseItem(playerid, itemName);
|
||||
public static string GetItemLabel(string item) => Raw.GetItemLabel(item);
|
||||
public static void RegisterUsableItem(string item, Action<int> callback = null) => Raw.RegisterUsableItem(item, callback);
|
||||
public static void RegisterServerCallback(string name, Action<int, CallbackDelegate, dynamic> callback) => Raw.RegisterServerCallback(name, callback);
|
||||
public static void Trace(object args) => Raw.Trace(args);
|
||||
public static string GetRandomString(int length) => Raw.GetRandomString(length);
|
||||
public static dynamic GetConfig() => Raw.GetConfig();
|
||||
public static dynamic GetWeaponFromHash(long hash) => Raw.GetWeaponFromHash(hash);
|
||||
public static dynamic GetWeaponList() => Raw.GetWeaponList();
|
||||
public static dynamic GetWeaponComponent(string weaponName, string weaponComponent) => Raw.GetWeaponComponent(weaponName, weaponComponent);
|
||||
public static dynamic GetWeapon(string itemName) => Raw.GetWeapon(itemName);
|
||||
public static dynamic GetWeaponLabel(string weapon) => Raw.GetWeaponLabel(weapon);
|
||||
|
||||
public static List<xPlayer> GetPlayers()
|
||||
{
|
||||
List<xPlayer> temp = new List<xPlayer>();
|
||||
var rawdata = Raw.GetPlayers();
|
||||
foreach (var i in rawdata)
|
||||
{
|
||||
temp.Add(ESX.GetPlayerFromId(i));
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
160
C#/Mosleys/Mosleys.Server/ESX/Server/xPlayer.cs
Normal file
160
C#/Mosleys/Mosleys.Server/ESX/Server/xPlayer.cs
Normal file
@@ -0,0 +1,160 @@
|
||||
namespace Nexd.ESX.Server
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
using CitizenFX.Core;
|
||||
using Nexd.ESX.Shared;
|
||||
|
||||
public class xPlayer
|
||||
{
|
||||
public dynamic Raw;
|
||||
|
||||
public int Index => Raw.source;
|
||||
|
||||
public xPlayer() { }
|
||||
|
||||
public xPlayer(dynamic data) => Raw = data;
|
||||
|
||||
public bool IsOnline => Raw != null;
|
||||
public void TriggerEvent(string eventName, dynamic args = null) => Raw.triggerEvent(eventName, args);
|
||||
public float GetHeading() => Raw.getCoords(true).heading;
|
||||
public void Kick(string reason) => Raw.kick(reason);
|
||||
public void SetMoney(int money) => Raw.setMoney(money);
|
||||
public uint GetMoney() => Raw.getMoney();
|
||||
public void AddMoney(int amount) => Raw.addMoney(amount);
|
||||
public void RemoveMoney(int amount) => Raw.removeMoney(amount);
|
||||
public string GetIdentifier() => Raw.getIdentifier();
|
||||
public void SetGroup(string newgroup) => Raw.setGroup(newgroup);
|
||||
public string GetGroup() => Raw.getGroup();
|
||||
public void Set(dynamic key, dynamic value) => Raw.set(key, value);
|
||||
public dynamic Get(dynamic key) => Raw.get(key);
|
||||
public string GetName() => Raw.getName();
|
||||
public void SetName(string newname) => Raw.setName(newname);
|
||||
public void SetAccountMoney(string account, int money) => Raw.setAccountMoney(account, money);
|
||||
public void AddAccountMoney(string account, int amount) => Raw.addAccountMoney(account, amount);
|
||||
public void RemoveAccountMoney(string account, int amount) => Raw.removeAccountMoney(account, amount);
|
||||
public InventoryItem GetInventoryItem(string name) => new InventoryItem(Raw.getInventoryItem(name));
|
||||
public void AddInventoryItem(string name, int count) => Raw.addInventoryItem(name, count);
|
||||
public void RemoveInventoryItem(string name, int count) => Raw.removeInventoryItem(name, count);
|
||||
public void SetInventoryItem(string name, int count) => Raw.setInventoryItem(name, count);
|
||||
public double GetWeight() => Raw.getWeight();
|
||||
public double GetMaxWeight() => Raw.getMaxWeight();
|
||||
public bool CanCarryItem(string name, int count) => Raw.canCarryItem(name, count);
|
||||
public bool CanSwapItem(string firstitem, int firstitemcount, string testitem, int testitemcount) => Raw.canSwapItem(firstitem, firstitemcount, testitem, testitemcount);
|
||||
public void SetMaxWeight(double newWeight) => Raw.setMaxWeight(newWeight);
|
||||
public void SetJob(string job, int grade) => Raw.setJob(job, grade);
|
||||
public void AddWeapon(string weaponName, int ammo) => Raw.addWeapon(weaponName, ammo);
|
||||
public void AddWeaponComponent(string weaponName, string weaponComponent) => Raw.addWeaponComponent(weaponName, weaponComponent);
|
||||
public void AddWeaponAmmo(string weaponName, int ammoCount) => Raw.addWeaponAmmo(weaponName, ammoCount);
|
||||
public void UpdateWeaponAmmo(string weaponName, int ammoCount) => Raw.updateWeaponAmmo(weaponName, ammoCount);
|
||||
public void SetWeaponTint(string weaponName, int weaponTintIndex) => Raw.setWeaponTint(weaponName, weaponTintIndex);
|
||||
public int GetWeaponTint(string weaponName) => Raw.getWeaponTint(weaponName);
|
||||
public void RemoveWeapon(string weaponName) => Raw.removeWeapon(weaponName);
|
||||
public void RemoveWeaponComponent(string weaponName, string weaponComponent) => Raw.removeWeaponComponent(weaponName, weaponComponent);
|
||||
public void RemoveWeaponAmmo(string weaponName, int ammoCount) => Raw.removeWeaponAmmo(weaponName, ammoCount);
|
||||
public bool HasWeaponComponent(string weaponName, string weaponComponent) => Raw.hasWeaponComponent(weaponName, weaponComponent);
|
||||
public bool HasWeapon(string weaponName) => Raw.hasWeapon(weaponName);
|
||||
public Shared.Weapon GetWeapon(string weaponName) => GetLoadout().Find(x => x.name == weaponName);
|
||||
public int GetWeaponLoadoutNum(string weaponName) => GetLoadout().FindIndex(x => x.name == weaponName);
|
||||
public void ShowNotification(string message) => Raw.showNotification(message);
|
||||
public void ShowHelpNotification(string message, bool thisframe = false, bool beep = true, int duration = -1) => Raw.showHelpNotification(message, thisframe, beep, duration);
|
||||
public Job GetJob() => new Job(Raw.getJob());
|
||||
public Account GetAccount(string name) => new Account(Raw.getAccount(name));
|
||||
public Vector3 GetCoords(bool vector) => Raw.getCoords(vector);
|
||||
|
||||
public Vector3 GetCoords(bool vector, ref float heading)
|
||||
{
|
||||
dynamic data = Raw.getCoords(vector);
|
||||
Vector3 coords = new Vector3(data.X, data.Y, data.Z);
|
||||
heading = data.heading;
|
||||
return coords;
|
||||
}
|
||||
|
||||
public Account[] GetAccounts(bool minimal)
|
||||
{
|
||||
Account[] accounts = new Account[3];
|
||||
var raw = Raw.getAccounts(minimal);
|
||||
for (int i = 0; i < 3; i++)
|
||||
accounts[i] = new Account(raw[i]);
|
||||
|
||||
return accounts;
|
||||
}
|
||||
|
||||
public List<InventoryItem> GetInventory(bool minimal)
|
||||
{
|
||||
List<InventoryItem> inventory = new List<InventoryItem>();
|
||||
var rawdata = Raw.getInventory(minimal);
|
||||
foreach (var i in rawdata)
|
||||
{
|
||||
inventory.Add(new InventoryItem(i));
|
||||
}
|
||||
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public List<Shared.Weapon> GetLoadout()
|
||||
{
|
||||
List<Shared.Weapon> temp = new List<Shared.Weapon>();
|
||||
var loadout = Raw.getLoadout();
|
||||
|
||||
foreach (var i in loadout)
|
||||
{
|
||||
temp.Add(new Shared.Weapon(i));
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
public void SetCoords(Vector3 coords)
|
||||
{
|
||||
dynamic table = new
|
||||
{
|
||||
x = coords.X,
|
||||
y = coords.Y,
|
||||
z = coords.Z,
|
||||
heading = 0.0f
|
||||
};
|
||||
|
||||
Raw.setCoords(table);
|
||||
}
|
||||
|
||||
public void SetCoords(Vector3 coords, float heading)
|
||||
{
|
||||
dynamic table = new
|
||||
{
|
||||
x = coords.X,
|
||||
y = coords.Y,
|
||||
z = coords.Z,
|
||||
heading = heading
|
||||
};
|
||||
|
||||
Raw.setCoords(table);
|
||||
}
|
||||
|
||||
public void UpdateCoords(Vector3 coords)
|
||||
{
|
||||
dynamic table = new
|
||||
{
|
||||
x = coords.X,
|
||||
y = coords.Y,
|
||||
z = coords.Z,
|
||||
heading = 0.0f
|
||||
};
|
||||
|
||||
Raw.updateCoords(table);
|
||||
}
|
||||
|
||||
public void UpdateCoords(Vector3 coords, float heading)
|
||||
{
|
||||
dynamic table = new
|
||||
{
|
||||
x = coords.X,
|
||||
y = coords.Y,
|
||||
z = coords.Z,
|
||||
heading = heading
|
||||
};
|
||||
|
||||
Raw.updateCoords(table);
|
||||
}
|
||||
}
|
||||
}
|
||||
85
C#/Mosleys/Mosleys.Server/Mosleys.Server.csproj
Normal file
85
C#/Mosleys/Mosleys.Server/Mosleys.Server.csproj
Normal file
@@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{8DFEB53F-2F99-427F-96BF-2290697FB9B2}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Mosleys.Server</RootNamespace>
|
||||
<AssemblyName>Mosleys.Server.net</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>../Output</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>del Newtonsoft.Json.xml</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="CitizenFX.Core.Server">
|
||||
<HintPath>..\Librarys\CitizenFX.Core.Server.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp">
|
||||
<HintPath>..\Librarys\Microsoft.CSharp.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ESX\Server\ESX.Config.cs" />
|
||||
<Compile Include="ESX\Server\ESX.Config.Weapons.cs" />
|
||||
<Compile Include="ESX\Server\ESX.cs" />
|
||||
<Compile Include="ESX\Server\xPlayer.cs" />
|
||||
<Compile Include="MySql.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ServerScript.cs" />
|
||||
<Compile Include="Utils.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Mosleys.Shared\Mosleys.Shared.csproj">
|
||||
<Project>{95000252-da88-4a79-8958-ca70b42ce0f9}</Project>
|
||||
<Name>Mosleys.Shared</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="ESX" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
|
||||
</Project>
|
||||
38
C#/Mosleys/Mosleys.Server/MySql.cs
Normal file
38
C#/Mosleys/Mosleys.Server/MySql.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Mosleys.Server {
|
||||
public static class MySql {
|
||||
|
||||
public static dynamic MySqlObject;
|
||||
|
||||
public static Task Execute(string qry, IDictionary<string, object> parameters = null) {
|
||||
var source = new TaskCompletionSource<dynamic>();
|
||||
MySqlObject.query(qry, parameters, new Action<dynamic>(_ => {
|
||||
source.TrySetResult(null);
|
||||
}));
|
||||
return source.Task;
|
||||
}
|
||||
|
||||
public static Task<dynamic[]> FetchAll(string qry, IDictionary<string, object> parameters = null) {
|
||||
var source = new TaskCompletionSource<dynamic[]>();
|
||||
MySqlObject.query(qry, parameters, new Action<dynamic>(data => {
|
||||
source.TrySetResult((data as List<dynamic>).ToArray());
|
||||
}));
|
||||
return source.Task;
|
||||
}
|
||||
|
||||
public static async Task<dynamic> FetchOne(string qry, IDictionary<string, object> parameters = null) {
|
||||
var result = await FetchAll(qry, parameters);
|
||||
if (result.Length == 0) return null;
|
||||
return result[0];
|
||||
}
|
||||
|
||||
public static async void InitialSetup() {
|
||||
await Execute("CREATE TABLE IF NOT EXISTS cardealer (uuid VARCHAR(36) PRIMARY KEY, owner VARCHAR(46), description VARCHAR(60), price INT(7), slot INT(2), vehicle LONGTEXT, testdrive TINYINT(1))");
|
||||
await Execute("UPDATE cardealer SET testdrive = 0");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
35
C#/Mosleys/Mosleys.Server/Properties/AssemblyInfo.cs
Normal file
35
C#/Mosleys/Mosleys.Server/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Mosleys.Server")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Mosleys.Server")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2022")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("8DFEB53F-2F99-427F-96BF-2290697FB9B2")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
183
C#/Mosleys/Mosleys.Server/ServerScript.cs
Normal file
183
C#/Mosleys/Mosleys.Server/ServerScript.cs
Normal file
@@ -0,0 +1,183 @@
|
||||
using System;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CitizenFX.Core;
|
||||
using Mosleys.Shared;
|
||||
using Mosleys.Shared.Models;
|
||||
using Newtonsoft.Json;
|
||||
using Nexd.ESX.Server;
|
||||
using ESX = Nexd.ESX.Server.ESX;
|
||||
|
||||
namespace Mosleys.Server {
|
||||
public sealed class ServerScript : BaseScript {
|
||||
|
||||
public static ServerConfig Config;
|
||||
|
||||
public ServerScript() {
|
||||
Config = new ServerConfig();
|
||||
MySql.MySqlObject = Exports["oxmysql"];
|
||||
MySql.InitialSetup();
|
||||
|
||||
RegisterCallback<bool, string>("mosleys:server:checkVehicleOwnership", CheckVehicleOwnership);
|
||||
RegisterCallback<bool, int>("mosleys:server:checkMoney", CheckMoney);
|
||||
RegisterCallback<bool, SellData>("mosleys:server:sellVehicle", SellVehicle, true);
|
||||
RegisterCallback("mosleys:server:getExhibits", GetExhibits);
|
||||
RegisterCallback("mosleys:server:getPlayerExhibits", GetPlayerExhibits);
|
||||
RegisterCallback<ExhibitVehicle, int>("mosleys:server:getExhibitBySlot", GetExhibitBySlot);
|
||||
RegisterCallback<bool, BuyData>("mosleys:server:buyVehicle", BuyVehicle, true);
|
||||
RegisterCallback<bool, ExhibitUpdate>("mosleys:server:updateExhibit", UpdateVehicle, true);
|
||||
RegisterCallback<int, string>("mosleys:server:push", PushToExhibit);
|
||||
|
||||
EventHandlers["mosleys:server:testDrive"] += new Action<int, bool>(UpdateTestDrive);
|
||||
}
|
||||
|
||||
private static void RegisterCallback<TRes>(string name, Func<xPlayer, Task<TRes>> handler) {
|
||||
ESX.RegisterServerCallback(name, async (source, cb, args) => {
|
||||
try {
|
||||
var result = await handler.Invoke(ESX.GetPlayerFromId(source));
|
||||
cb(result);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.WriteLine(e.ToString());
|
||||
cb(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
private static void RegisterCallback<TRes, TArg>(string name, Func<xPlayer, TArg, Task<TRes>> handler, bool castViaJson = false) {
|
||||
ESX.RegisterServerCallback(name, async (source, cb, args) => {
|
||||
try {
|
||||
TArg arg;
|
||||
|
||||
if (castViaJson) {
|
||||
arg = JsonConvert.DeserializeObject<TArg>(JsonConvert.SerializeObject(args));
|
||||
}
|
||||
else {
|
||||
arg = Convert.ChangeType(args, typeof(TArg));
|
||||
}
|
||||
|
||||
var result = await handler.Invoke(ESX.GetPlayerFromId(source), arg);
|
||||
cb(result);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.WriteLine(e.ToString());
|
||||
cb(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async Task<bool> CheckVehicleOwnership(xPlayer source, string plate) {
|
||||
var result = await MySql.FetchAll($"SELECT * FROM owned_vehicles WHERE owner = '{source.GetIdentifier()}'");
|
||||
return result.Any(vehicle => vehicle.plate == plate);
|
||||
}
|
||||
|
||||
private async Task<bool> CheckMoney(xPlayer source, int price) {
|
||||
return source.GetAccount("bank").money >= price;
|
||||
}
|
||||
|
||||
private async Task<bool> SellVehicle(xPlayer source, SellData data) {
|
||||
var exhibit = new ExhibitVehicle {
|
||||
Uuid = Guid.NewGuid().ToString(),
|
||||
Owner = source.GetIdentifier(),
|
||||
Description = data.Description,
|
||||
Price = data.Price,
|
||||
Vehicle = data.VehicleProperties,
|
||||
TestDrive = false
|
||||
};
|
||||
|
||||
int slot = data.ParkingSpace == 0 ? await Utils.FindFreeSlot() : 0;
|
||||
if (slot >= Config.CarSlots.Length) slot = 0;
|
||||
|
||||
exhibit.Slot = slot;
|
||||
await Utils.SaveExhibit(exhibit);
|
||||
|
||||
if (data.ParkingSpace == 0) {
|
||||
source.RemoveAccountMoney("bank", Config.ExhibitPrice);
|
||||
Utils.UpdatePlayers(slot);
|
||||
}
|
||||
|
||||
return slot != 0;
|
||||
}
|
||||
|
||||
private async Task<dynamic> GetExhibits(xPlayer soruce) {
|
||||
var vehicles = await Utils.GetAllExhibits();
|
||||
dynamic data = new ExpandoObject();
|
||||
data.vehicles = vehicles;
|
||||
return data;
|
||||
}
|
||||
|
||||
private async Task<dynamic> GetPlayerExhibits(xPlayer source) {
|
||||
var vehicles = await Utils.GetAllExhibits();
|
||||
vehicles = vehicles.Where(vehicle => vehicle.Owner == source.GetIdentifier()).ToArray();
|
||||
dynamic data = new ExpandoObject();
|
||||
data.vehicles = vehicles;
|
||||
return data;
|
||||
}
|
||||
|
||||
private async Task<ExhibitVehicle> GetExhibitBySlot(xPlayer source, int slot) =>
|
||||
await Utils.GetExhibitBySlot(slot);
|
||||
|
||||
private async void UpdateTestDrive(int slot, bool toggle) {
|
||||
var exhibit = await Utils.GetExhibitBySlot(slot);
|
||||
if (exhibit == null) return;
|
||||
|
||||
exhibit.TestDrive = toggle;
|
||||
await Utils.SaveExhibit(exhibit);
|
||||
Utils.UpdatePlayers(slot);
|
||||
}
|
||||
|
||||
private async Task<bool> BuyVehicle(xPlayer source, BuyData data) {
|
||||
var exhibit = await Utils.GetExhibitByUuid(data.Uuid);
|
||||
if (exhibit == null) return false;
|
||||
|
||||
var hasMoney = await CheckMoney(source, exhibit.Price);
|
||||
if (!hasMoney) return false;
|
||||
|
||||
dynamic vehicle = exhibit.Vehicle;
|
||||
vehicle.plate = data.Plate;
|
||||
|
||||
source.RemoveAccountMoney("bank", exhibit.Price);
|
||||
Utils.PaySeller(exhibit.Owner, exhibit.Price);
|
||||
TriggerEvent("esx_vehicleshop:setVehicleOwnedPlayerId", source.Index, vehicle);
|
||||
await MySql.Execute($"DELETE FROM cardealer WHERE uuid = '{data.Uuid}'");
|
||||
|
||||
if (exhibit.Slot != 0) TriggerClientEvent("mosleys:client:onRemove", exhibit.Slot);
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task<bool> UpdateVehicle(xPlayer source, ExhibitUpdate update) {
|
||||
if (update.Exhibit.Owner != source.GetIdentifier()) return false;
|
||||
|
||||
if (update.Action == UpdateAction.Update) {
|
||||
await Utils.SaveExhibit(update.Exhibit);
|
||||
|
||||
if (update.Exhibit.Slot != 0 ) Utils.UpdatePlayers(update.Exhibit.Slot);
|
||||
}
|
||||
|
||||
if (update.Action == UpdateAction.Delete) {
|
||||
await MySql.Execute($"DELETE FROM cardealer WHERE uuid = '{update.Exhibit.Uuid}'");
|
||||
TriggerEvent("esx_vehicleshop:setVehicleOwnedPlayerId", source.Index, update.Exhibit.Vehicle);
|
||||
|
||||
if (update.Exhibit.Slot != 0) TriggerClientEvent("mosleys:client:onRemove", update.Exhibit.Slot);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task<int> PushToExhibit(xPlayer source, string uuid) {
|
||||
var exhibit = await Utils.GetExhibitByUuid(uuid);
|
||||
var slot = await Utils.FindFreeSlot();
|
||||
|
||||
if (slot >= Config.CarSlots.Length) return 0;
|
||||
|
||||
var hasMoney = await CheckMoney(source, Config.ExhibitPrice);
|
||||
if (!hasMoney) return 0;
|
||||
|
||||
source.RemoveAccountMoney("bank", Config.ExhibitPrice);
|
||||
exhibit.Slot = slot;
|
||||
await Utils.SaveExhibit(exhibit);
|
||||
Utils.UpdatePlayers(slot);
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
}
|
||||
101
C#/Mosleys/Mosleys.Server/Utils.cs
Normal file
101
C#/Mosleys/Mosleys.Server/Utils.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CitizenFX.Core;
|
||||
using Mosleys.Shared.Models;
|
||||
using Newtonsoft.Json;
|
||||
using Nexd.ESX.Server;
|
||||
|
||||
namespace Mosleys.Server {
|
||||
public static class Utils {
|
||||
|
||||
public static async Task<ExhibitVehicle[]> GetAllExhibits() {
|
||||
var vehicles = new List<ExhibitVehicle>();
|
||||
var data = await MySql.FetchAll("SELECT * FROM cardealer");
|
||||
|
||||
try {
|
||||
foreach (var exhibit in data) {
|
||||
exhibit.vehicle = JsonConvert.DeserializeObject<ExpandoObject>(exhibit.vehicle as string);
|
||||
var json = JsonConvert.SerializeObject(exhibit);
|
||||
vehicles.Add(JsonConvert.DeserializeObject<ExhibitVehicle>(json));
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.WriteLine(e.ToString());
|
||||
}
|
||||
|
||||
return vehicles.ToArray();
|
||||
}
|
||||
|
||||
public static async Task<ExhibitVehicle> GetExhibitBySlot(int slot) {
|
||||
var data = await MySql.FetchOne($"SELECT * FROM cardealer WHERE slot = {slot}");
|
||||
data.vehicle = JsonConvert.DeserializeObject<ExpandoObject>(data.vehicle as string);
|
||||
var json = JsonConvert.SerializeObject(data);
|
||||
return JsonConvert.DeserializeObject<ExhibitVehicle>(json);
|
||||
}
|
||||
|
||||
public static async Task<ExhibitVehicle> GetExhibitByUuid(string uuid) {
|
||||
var data = await MySql.FetchOne($"SELECT * FROM cardealer WHERE uuid = '{uuid}'");
|
||||
data.vehicle = JsonConvert.DeserializeObject<ExpandoObject>(data.vehicle as string);
|
||||
var json = JsonConvert.SerializeObject(data);
|
||||
return JsonConvert.DeserializeObject<ExhibitVehicle>(json);
|
||||
}
|
||||
|
||||
public static async Task<int> FindFreeSlot() {
|
||||
var vehicles = await GetAllExhibits();
|
||||
|
||||
int slot = 1;
|
||||
while (vehicles.Any(veh => veh.Slot == slot)) {
|
||||
slot++;
|
||||
}
|
||||
|
||||
return slot;
|
||||
}
|
||||
|
||||
public static async Task SaveExhibit(ExhibitVehicle exhibit) {
|
||||
if (string.IsNullOrEmpty(exhibit.Description))
|
||||
exhibit.Description = "Nicht angegeben";
|
||||
|
||||
await MySql.Execute($"DELETE FROM cardealer WHERE uuid = '{exhibit.Uuid}'");
|
||||
await MySql.Execute("INSERT INTO cardealer VALUES (@uuid, @owner, @description, @price, @slot, @vehicle, @testdrive)", new Dictionary<string, object>() {
|
||||
{"@uuid", exhibit.Uuid},
|
||||
{"@owner", exhibit.Owner},
|
||||
{"@description", exhibit.Description},
|
||||
{"@price", exhibit.Price},
|
||||
{"@slot", exhibit.Slot},
|
||||
{"@vehicle", JsonConvert.SerializeObject(exhibit.Vehicle)},
|
||||
{"@testdrive", Convert.ToInt32(exhibit.TestDrive)}
|
||||
});
|
||||
}
|
||||
|
||||
public static void UpdatePlayers(int slot) {
|
||||
BaseScript.TriggerClientEvent("mosleys:client:updateSlot", slot);
|
||||
}
|
||||
|
||||
public static async void PaySeller(string identifier, int amount) {
|
||||
try {
|
||||
var seller = ESX.GetPlayerFromIdentifier(identifier);
|
||||
if (seller.IsOnline) seller.AddAccountMoney("bank", (int)(amount * (1 - ServerScript.Config.SellBill)));
|
||||
else {
|
||||
var data = await MySql.FetchOne($"SELECT accounts FROM users WHERE identifier = '{identifier}'");
|
||||
var accounts = JsonConvert.DeserializeObject<ExpandoObject>(data.accounts);
|
||||
accounts.bank += amount;
|
||||
await MySql.Execute($"UPDATE users SET accounts = @accounts WHERE identifier = @identifier", new Dictionary<string, object>() {
|
||||
{"@accounts", JsonConvert.SerializeObject(accounts)},
|
||||
{"@identifier", identifier}
|
||||
});
|
||||
}
|
||||
|
||||
BaseScript.TriggerEvent("esx_addonaccount:getSharedAccount", $"society_{ServerScript.Config.TargetSociety}", new Action<dynamic>(society => {
|
||||
society.addMoney((int)(amount * ServerScript.Config.SellBill));
|
||||
}));
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
BIN
C#/Mosleys/Mosleys.Server/bin/Release/Mosleys.Server.dll
Normal file
BIN
C#/Mosleys/Mosleys.Server/bin/Release/Mosleys.Server.dll
Normal file
Binary file not shown.
BIN
C#/Mosleys/Mosleys.Server/bin/Release/Mosleys.Server.pdb
Normal file
BIN
C#/Mosleys/Mosleys.Server/bin/Release/Mosleys.Server.pdb
Normal file
Binary file not shown.
BIN
C#/Mosleys/Mosleys.Server/bin/Release/Mosleys.Shared.dll
Normal file
BIN
C#/Mosleys/Mosleys.Server/bin/Release/Mosleys.Shared.dll
Normal file
Binary file not shown.
BIN
C#/Mosleys/Mosleys.Server/bin/Release/Nexd.ESX.Server.dll
Normal file
BIN
C#/Mosleys/Mosleys.Server/bin/Release/Nexd.ESX.Server.dll
Normal file
Binary file not shown.
BIN
C#/Mosleys/Mosleys.Server/bin/Release/Nexd.ESX.Shared.dll
Normal file
BIN
C#/Mosleys/Mosleys.Server/bin/Release/Nexd.ESX.Shared.dll
Normal file
Binary file not shown.
23
C#/Mosleys/Mosleys.Server/bin/Release/fxmanifest.lua
Normal file
23
C#/Mosleys/Mosleys.Server/bin/Release/fxmanifest.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
fx_version 'cerulean'
|
||||
games { 'gta5' }
|
||||
|
||||
-- details
|
||||
author 'Leon Hoppe'
|
||||
description "Mosley's"
|
||||
version '2.0'
|
||||
|
||||
shared_scripts {
|
||||
'Nexd.ESX.Shared.dll',
|
||||
'Mosleys.Shared.dll',
|
||||
'settings.ini'
|
||||
}
|
||||
|
||||
client_scripts {
|
||||
'Newtonsoft.Json.dll',
|
||||
'Nexd.ESX.Client.dll',
|
||||
'Mosleys.Client.net.dll'
|
||||
}
|
||||
|
||||
server_scripts {
|
||||
'@mysql-async/lib/MySQL.lua',
|
||||
}
|
||||
39
C#/Mosleys/Mosleys.Server/bin/Release/settings.ini
Normal file
39
C#/Mosleys/Mosleys.Server/bin/Release/settings.ini
Normal file
@@ -0,0 +1,39 @@
|
||||
|
||||
{[Blip]
|
||||
Position [-41.5, -1676.1, 30]
|
||||
Sprite 380
|
||||
Color 44
|
||||
Scale 1.0
|
||||
}
|
||||
|
||||
{[General]
|
||||
MenuTitle Mosley's
|
||||
ExhibitPrice 500
|
||||
TestDriveTime 90000
|
||||
SpawnRadius 100.0
|
||||
MinSellPrice 1000
|
||||
|
||||
ForbiddenVehicleClasses [10, 13, 14, 15, 16, 18, 19, 20, 21]
|
||||
|
||||
SpawnLocation [3.556, -1652.677, 28.853, 229.645]
|
||||
TestDriveLocation [-48.724, -1645.301, 29.034, 318.446]
|
||||
DigitalShowPoint [-31.4151, -1663.9031, 29.5]
|
||||
DigitalCamera [-24.2456, -1643.7988, 33.1410, 186.6901]
|
||||
}
|
||||
|
||||
{[CarSlots]
|
||||
0 [-24.969, -1651.355, 28.35, 258.833]
|
||||
1 [-51.790, -1694.293, 28.35, 301.206]
|
||||
2 [-56.162, -1690.660, 28.35, 298.664]
|
||||
3 [-59.606, -1685.879, 28.35, 309.221]
|
||||
4 [-53.514, -1678.981, 28.35, 301.604]
|
||||
5 [-43.349, -1666.895, 28.35, 296.207]
|
||||
6 [-35.946, -1657.419, 28.35, 144.485]
|
||||
7 [-16.085, -1653.906, 28.35, 308.377]
|
||||
8 [-27.076, -1657.913, 28.35, 286.712]
|
||||
9 [-23.641, -1643.140, 28.35, 121.021]
|
||||
10 [-18.106, -1645.940, 28.35, 132.801]
|
||||
11 [-43.647, -1690.989, 28.35, 311.298]
|
||||
12 [-47.901, -1688.066, 28.35, 306.442]
|
||||
13 [-51.714, -1683.800, 28.35, 306.119]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// <autogenerated />
|
||||
using System;
|
||||
using System.Reflection;
|
||||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
534f4db9ea8ef7acfc1233e7413c6b4d36a209be
|
||||
@@ -0,0 +1,20 @@
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Server\bin\Release\fxmanifest.lua
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Server\bin\Release\settings.ini
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Server\bin\Release\Mosleys.Server.dll
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Server\bin\Release\Mosleys.Server.pdb
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Server\bin\Release\Mosleys.Shared.dll
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Server\bin\Release\Nexd.ESX.Server.dll
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Server\bin\Release\Nexd.ESX.Shared.dll
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Server\obj\Release\Mosleys.Server.csproj.AssemblyReference.cache
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Server\obj\Release\Mosleys.Server.csproj.CoreCompileInputs.cache
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Server\obj\Release\Mosleys.Server.csproj.CopyComplete
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Server\Output\fxmanifest.lua
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Server\Output\settings.ini
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Server\Output\Mosleys.Server.dll
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Server\Output\Mosleys.Shared.dll
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Server\Output\Nexd.ESX.Server.dll
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Server\Output\Nexd.ESX.Shared.dll
|
||||
D:\Programmierstuff\C#\Mosleys\Output\fxmanifest.lua
|
||||
D:\Programmierstuff\C#\Mosleys\Output\settings.ini
|
||||
D:\Programmierstuff\C#\Mosleys\Output\Mosleys.Server.net.dll
|
||||
D:\Programmierstuff\C#\Mosleys\Mosleys.Server\obj\Release\Mosleys.Server.net.dll
|
||||
BIN
C#/Mosleys/Mosleys.Server/obj/Release/Mosleys.Server.net.dll
Normal file
BIN
C#/Mosleys/Mosleys.Server/obj/Release/Mosleys.Server.net.dll
Normal file
Binary file not shown.
4
C#/Mosleys/Mosleys.Server/packages.config
Normal file
4
C#/Mosleys/Mosleys.Server/packages.config
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net481" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user