Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
emcifuntik committed Sep 15, 2023
1 parent 0fb407c commit c255126
Show file tree
Hide file tree
Showing 9 changed files with 4,085 additions and 318 deletions.
3,580 changes: 3,580 additions & 0 deletions freeroam-extended/client/package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions freeroam-extended/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"main": "index.js",
"license": "MIT",
"devDependencies": {
"@altv/types-client": "^2.4.4",
"@altv/types-natives": "^1.4.8",
"@altv/types-server": "^2.5.7",
"@altv/types-shared": "^1.3.6",
"@altv/types-client": "^2.9.2",
"@altv/types-natives": "^1.5.4",
"@altv/types-server": "^2.9.5",
"@altv/types-shared": "^1.6.0",
"@typescript-eslint/eslint-plugin": "^5.50.0",
"@typescript-eslint/parser": "^5.50.0",
"altv-esbuild": "^0.4.3",
Expand Down
7 changes: 3 additions & 4 deletions freeroam-extended/client/resource.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ type = 'js'
main = 'dist/server.js'
client-main = 'dist/client.js'
client-files = [ 'dist/client.js', 'html/*' ]
# TODO: turn on after fixing: https://github.com/altmp/altv-issues/issues/1628
# optional-permissions = [
# 'Clipboard Access',
# ]
optional-permissions = [
'Clipboard Access',
]
2 changes: 1 addition & 1 deletion freeroam-extended/client/src/nametags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class PlayerNametags {
}

private draw(player: alt.Player, scale: number): void {
const fullName = `${player.name} <font family="3">~b~#${player.id}</font>`
const fullName = `${player.name} <font family="3">~b~#${player.remoteID}</font>`
scale *= this.fontSize

const yOffset = 0 - (player.armour > 0 ? 0.0015 : 0)
Expand Down
508 changes: 254 additions & 254 deletions freeroam-extended/client/yarn.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
using AltV.Net;
using AltV.Net.Elements.Entities;

namespace Freeroam_Extended.Clothes;

internal class IdGenerator
{
private Stack<long> idStack;

public IdGenerator()
{
this.idStack = new Stack<long>();
this.PushId(long.MinValue);
}

public long GetNextId()
{
if (this.idStack.Count == 0)
{
// If the stack is empty, push the next sequential ID.
this.PushId(this.idStack.Count + 1);
}

return this.idStack.Pop();
}

public void ReleaseId(long id)
{
this.idStack.Push(id);
}

private void PushId(long id)
{
this.idStack.Push(id);
}
}

internal static class ClothesFitService
{
private static readonly IdGenerator _idGen = new();
private static readonly Dictionary<long, TaskCompletionSource<object>> _tasks = new();

static ClothesFitService()
{
Alt.OnServer("clothes.resp", (long id, string type, object result) =>
{
if (!_tasks.TryGetValue(id, out var tcs))
{
return;
}

_tasks.Remove(id);

if (type == "error")
{
tcs.TrySetException(new Exception(result?.ToString()));
}
else
{
tcs.SetResult(result);
}
});
}

public static Task InitPlayer(IPlayer player)
{
return MakeReq(player, "initPlayer");
}

public static Task DestroyPlayer(IPlayer player)
{
return MakeReq(player, "destroyPlayer");
}

public static Task Equip(IPlayer player, string hash, bool force = true)
{
//TODO CLOTHES IMPLEMENT FORCE ON CLIENT
return MakeReq(player, "equip", hash, force);
}

public static Task Equip(IPlayer player, uint hash, bool force = true)
{
//TODO CLOTHES IMPLEMENT FORCE ON CLIENT
return MakeReq(player, "equip", hash, force);
}

public static Task UnEquip(IPlayer player, string hash)
{
return MakeReq(player, "unequip", hash);
}

public static Task UnEquip(IPlayer player, uint hash)
{
return MakeReq(player, "unequip", hash);
}

public static async Task<ulong[]> GetOutfitsBySex(uint sex)
{
var tcs = new TaskCompletionSource<object>();
var id = _idGen.GetNextId();
_tasks.Add(id, tcs);
Alt.Emit("clothes.req", null, "getoutfits", id, sex);
var result = await tcs.Task;
return ((object[]) result).Select(Convert.ToUInt64).ToArray();
}

private static Task MakeReq(IPlayer player, string eventName, params object[] args)
{
var tcs = new TaskCompletionSource<object>();
var id = _idGen.GetNextId();
_tasks.Add(id, tcs);
Alt.Emit("clothes.req", player, eventName, id, args);
return tcs.Task;
}
}
92 changes: 71 additions & 21 deletions freeroam-extended/server/freeroam-extended/Commands.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Numerics;
using System.Text.Json;
using AltV.Net;
using AltV.Net.Async;
using AltV.Net.Data;
using AltV.Net.Enums;
using AltV.Net.Resources.Chat.Api;
using Freeroam_Extended.Clothes;
using Freeroam_Extended.Factories;

namespace Freeroam_Extended
Expand Down Expand Up @@ -49,14 +51,14 @@ public void SpawnVeh(IAltPlayer player, string vehicleName)
{
var target = player.Vehicles.OrderBy(veh => veh.SpawnTime).First();
player.Vehicles.Remove(target);
target.Remove();
target.Destroy();
player.SendChatMessage("{FF0000} You can't have more than 3 vehicles. We removed your oldest one!");
}

if (player.IsInVehicle)
{
player.SendChatMessage("{FF0000} You are already in a vehicle we replaced it for you!");
player.Vehicle.Remove();
player.Vehicle.Destroy();
return;
}

Expand Down Expand Up @@ -103,12 +105,37 @@ public void GetWeapons(IAltPlayer player)
}
}

// [Command("model")]
// public void ChangeModel(IAltPlayer player, string modelName)
// {
// player.Model = Alt.Hash(modelName);
//
// }
[Command("model")]
public void ChangeModel(IAltPlayer player)
{
if (player.Model == Alt.Hash("mp_m_freemode_01"))
{
player.Model = Alt.Hash("mp_f_freemode_01");
}
else
{
player.Model = Alt.Hash("mp_m_freemode_01");
}

player.RefreshFace();

player.RefreshClothes();
player.SendChatMessage(
$"{{00FF00}}Your model changed");
}

[Command("outfit")]
public void Outfit(IAltPlayer player, string outfitUniqueName = "")
{
if (string.IsNullOrEmpty(outfitUniqueName))
{
player.RefreshClothes();
return;
}
player.EquipOutfit(Alt.Hash(outfitUniqueName));
player.SendChatMessage(
$"{{00FF00}}Your outfit updated");
}

[Command("tp")]
public void Teleport(IAltPlayer player, int id = 0)
Expand Down Expand Up @@ -139,46 +166,46 @@ public void Ban(IAltPlayer player, int id)
return;
}

var target = Alt.GetAllPlayers().FirstOrDefault(p => p.Id == id);
var target = (IAltPlayer)Alt.GetAllPlayers().FirstOrDefault(p => p.Id == id);
if (target == null)
{
player.SendChatMessage($"{{FF0000}}Player with id {id} not found!");
return;
}

target.Kick("You've been banned from this server!");
Misc.BannedPlayers.Add(new Tuple<ulong, ulong>(target.HardwareIdHash, target.HardwareIdExHash));
Misc.BannedPlayers.Add(target.CloudID);
string json = JsonSerializer.Serialize(Misc.BannedPlayers);
File.WriteAllText(@"BannedPlayers.json", json);

player.SendChatMessage($"{{00FF00}}Player with id {id} banned!");
}

[Command("unban")]
public void Unban(IAltPlayer player, ulong hwid)
public void Unban(IAltPlayer player, string rsid)
{
if (!player.IsAdmin)
{
player.SendChatMessage("{FF0000} No permission!");
return;
}

var target = Misc.BannedPlayers.FirstOrDefault(tuple => tuple.Item1 == hwid);
var target = Misc.BannedPlayers.FirstOrDefault(id => id == rsid);
if (target == null)
{
player.SendChatMessage($"{{FF0000}}Player with hwid {hwid} not found!");
player.SendChatMessage($"{{FF0000}}Player with rsid {rsid} not found!");
return;
}

if (Misc.BannedPlayers.All(tuple => tuple.Item1 != hwid))
if (Misc.BannedPlayers.All(id => id != rsid))
{
player.SendChatMessage($"{{FF0000}}Player with hwid {hwid} not banned!");
player.SendChatMessage($"{{FF0000}}Player with hwid {rsid} not banned!");
return;
}

// remove banned player from list
Misc.BannedPlayers.Remove(new Tuple<ulong, ulong>(player.HardwareIdHash, player.HardwareIdExHash));
player.SendChatMessage($"{{00FF00}}Player with hwid {hwid} unbanned!");
Misc.BannedPlayers.Remove(rsid);
player.SendChatMessage($"{{00FF00}}Player with hwid {rsid} unbanned!");
}

[Command("addcomponent")]
Expand Down Expand Up @@ -232,7 +259,7 @@ public void Dm(IAltPlayer player)
public void ToggleChat(IAltPlayer player, bool state)
{
// check if player is operator
if (!player.IsAdmin && !Misc.ChatState)
if (!player.IsAdmin)
{
player.SendChatMessage("{FF0000} No permission!");
return;
Expand Down Expand Up @@ -266,7 +293,7 @@ public void ClearVehicles(IAltPlayer player)
// get all vehicles owned by player
foreach (var veh in player.Vehicles)
{
veh.Remove();
veh.Destroy();
}
}

Expand Down Expand Up @@ -340,7 +367,7 @@ public void ClearAllVehicles(IAltPlayer player, int distance = 0)
{
foreach (var veh in Alt.GetAllVehicles())
{
veh.Remove();
veh.Destroy();
}

return;
Expand All @@ -350,7 +377,7 @@ public void ClearAllVehicles(IAltPlayer player, int distance = 0)
foreach (var veh in Alt.GetAllVehicles())
{
// compare squared distance between player and vehicle
if (Vector3.DistanceSquared(veh.Position, player.Position) <= distSqr) veh.Remove();
if (Vector3.DistanceSquared(veh.Position, player.Position) <= distSqr) veh.Destroy();
}
}

Expand Down Expand Up @@ -561,5 +588,28 @@ public void Esp(IAltPlayer player, bool mode)

player.Emit("esp", mode);
}

[Command("globalvoice")]
public void GlobalVoice(IAltPlayer player)
{
if (!player.IsAdmin)
{
player.SendChatMessage("{FF0000} No permission!");
return;
}

if (Voice.IsGlobalVoiceEnabled(player))
{
Voice.EnableGlobalVoice(player);
player.SendChatMessage("{00FF00} Global voice enabled!");
return;
}
else
{
Voice.DisableGlobalVoice(player);
player.SendChatMessage("{00FFFF} Global voice disabled!");
return;
}
}
}
}
Loading

0 comments on commit c255126

Please sign in to comment.