Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dist/localization.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@
"warn_expired": "expired warn",
"active_warns_count": "Active Warns: {0} Warns",
"expired_warns_count": "Expired Warns: {0} Warns",
"kit_price_automatically_calculated": "Automatic Kit Price: {0}$"
"kit_price_automatically_calculated": "Automatic Kit Price: {0}$",
"player_giveammo_fail": "You do not have a weapon that needs ammo in your hands!"
},
"BR": {
"arrested": "Preso {0}.",
Expand Down
10 changes: 9 additions & 1 deletion dist/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
// This does not change already Registerd ones
"LimitNames": false,
// This forbbids pressing Register when the Account already was registerd once.
"DisableAccountOverwrite": false
"DisableAccountOverwrite": false,
"SaveInterval": 15
},
"KeptItemsOnDeath": {
"KeepAllItemsOnDeath": false,
Expand Down Expand Up @@ -425,6 +426,13 @@
"Commands": [
"deletekit"
]
},
{
"CommandName": "GiveAmmo",
"Commands": [
"giveammo",
"ga"
]
}
]
}
1 change: 1 addition & 0 deletions src/BPEssentials/BPEssentials.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@
<Compile Include="Commands\Moderation\ToggleBypass.cs" />
<Compile Include="Commands\Moderation\ToggleSpyChat.cs" />
<Compile Include="Commands\Pay\Pay.cs" />
<Compile Include="Commands\Player\Inventory\GiveAmmo.cs" />
<Compile Include="Commands\Player\SetJob.cs" />
<Compile Include="Commands\Player\ToggleGodmode.cs" />
<Compile Include="Commands\Player\ToggleMute.cs" />
Expand Down
4 changes: 2 additions & 2 deletions src/BPEssentials/Commands/Misc/Launch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace BPEssentials.Commands
{
public class Launch : Command
{
public void Invoke(ShPlayer player, ShPlayer target = null)
public void Invoke(ShPlayer player, ShPlayer target = null, float thrust = 6500f)
{
target = target ?? player;
target.svPlayer.SvForce(new UnityEngine.Vector3(0f, 6500f, 0f));
target.svPlayer.SvForce(new UnityEngine.Vector3(0f, thrust, 0f));
target.TS("target_launched");
player.TS("player_launched", target.username.CleanerMessage());
}
Expand Down
27 changes: 27 additions & 0 deletions src/BPEssentials/Commands/Player/Inventory/GiveAmmo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using BPEssentials.Abstractions;
using BPEssentials.ExtensionMethods;
using BPEssentials.Utils;

using BrokeProtocol.Entities;
using BrokeProtocol.Utility;
using System.Linq;

namespace BPEssentials.Commands
{
public class GiveAmmo : Command
{
public void Invoke(ShPlayer player, int amount = 1, ShPlayer target = null)
{
target = target ?? player;

if (!target.curEquipable || !target.curEquipable.AmmoItem)
{
player.TS("player_giveammo_fail");
}

var item = target.curEquipable.AmmoItem;
target.TransferItem(DeltaInv.AddToMe, item.index, amount, true);
player.TS("player_give", target.username.CleanerMessage(), item.itemName, amount.ToString());
}
}
}
16 changes: 1 addition & 15 deletions src/BPEssentials/Commands/Server/Save.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
using BPEssentials.Abstractions;
using BPEssentials.ExtensionMethods;

using BrokeProtocol.Collections;
using BrokeProtocol.Entities;
using Newtonsoft.Json;
using System.Linq;

namespace BPEssentials.Commands
{
public class Save : Command
{
public void StartSaveTimer()
{

var Tmer = new System.Timers.Timer(); // TODO: Disposing the timer seems to break
Tmer.Elapsed += (sender, e) => Run();
Tmer.Interval = 15 * 60 * 1000;
Tmer.Enabled = true;

}

public void Invoke(ShPlayer player)
{
Run();
}

public void Run()
{
Core.Instance.Logger.Log("Saving Game Status");
Expand Down
2 changes: 1 addition & 1 deletion src/BPEssentials/Configuration/Models/SettingsModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class General
{
public string Version { get; set; }

public int AnnounceInterval { get; set; }
public int SaveInterval { get; set; } = 15;

public bool LocalChatOverHead { get; set; } = true;

Expand Down
1 change: 0 additions & 1 deletion src/BPEssentials/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public Core()

EventsHandler.Add("bpe:reload", new Action(OnReloadRequestAsync));
EventsHandler.Add("bpe:version", new Action<string>(OnVersionRequest));
new Commands.Save().StartSaveTimer();
Logger.LogInfo($"BP Essentials {(IsDevelopmentBuild() ? "[DEVELOPMENT-BUILD] " : "")}v{Version} loaded in successfully!");
}

Expand Down
56 changes: 8 additions & 48 deletions src/BPEssentials/Events/OnRegister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,60 +11,20 @@ namespace BPEssentials.RegisteredEvents
public class OnRegiser : IScript
{

[Target(GameSourceEvent.ManagerTryRegister, ExecutionMode.Override)]
public void OnTryRegister(SvManager svManager, ConnectionData connectionData)
[Target(GameSourceEvent.ManagerTryRegister, ExecutionMode.Test)]
public bool OnTryRegister(SvManager svManager, ConnectionData connectionData)
{
if (ValidateUser(svManager, connectionData))
if (Core.Instance.Settings.General.LimitNames && !Regex.IsMatch(connectionData.username, @"^[a-zA-Z0-9_-]+$"))
{
if (svManager.TryGetUserData(connectionData.username, out User playerData))
{
if(Core.Instance.Settings.General.DisableAccountOverwrite)
{
svManager.RegisterFail(connectionData.connection, "This Name has already been registerd and this Server has disabled overwriting Accounts!");
return;
}
if (playerData.PasswordHash != connectionData.passwordHash)
{
svManager.RegisterFail(connectionData.connection, "Invalid credentials");
return;
}
}

if (!connectionData.username.ValidCredential())
{
svManager.RegisterFail(connectionData.connection, $"Name cannot be registered (min: {Util.minCredential}, max: {Util.maxCredential})");
return;
}
// -- BPE EXTEND
if (Core.Instance.Settings.General.LimitNames && !Regex.IsMatch(connectionData.username, @"^[a-zA-Z0-9_-]+$"))
{
svManager.RegisterFail(connectionData.connection, $"Your Username can only contain letters: A-Z a-z 0-9 _ -");
return;
}
// BPE EXTEND --
svManager.AddNewPlayer(connectionData, playerData?.Persistent);
}
}

public bool ValidateUser(SvManager svManager, ConnectionData authData)
{
if (!svManager.HandleWhitelist(authData.username))
{
svManager.RegisterFail(authData.connection, "Account not whitelisted");
svManager.RegisterFail(connectionData.connection, $"Your username can only contain the following characters: A-Z a-z 0-9 _ -");
return false;
}

// Don't allow multi-boxing, WebAPI doesn't prevent this
foreach (ShPlayer p in EntityCollections.Humans)
if (svManager.TryGetUserData(connectionData.username, out var user) && Core.Instance.Settings.General.DisableAccountOverwrite)
{
if (p.username == authData.username)
{
svManager.RegisterFail(authData.connection, "Account still logged in");
return false;
}
svManager.RegisterFail(connectionData.connection, "This name has already been registered and this server has disabled overwriting accounts!");
return false;
}

return true;
}
}
}
}
4 changes: 3 additions & 1 deletion src/BPEssentials/Events/OnStarted.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BrokeProtocol.API;
using BPCoreLib.Util;
using BrokeProtocol.API;
using BrokeProtocol.Entities;
using BrokeProtocol.Managers;
using BrokeProtocol.Utility;
Expand All @@ -13,6 +14,7 @@ public class OnStarted : IScript
public void OnEvent(SvManager svManager)
{
Core.Instance.SvManager = svManager;
Core.Instance.SvManager.StartCoroutine(Interval.Start(Core.Instance.Settings.General.SaveInterval * 60 * 1000, new Commands.Save().Run));
}
}
}