Skip to content

Commit 7e59784

Browse files
authored
Merge pull request #96 from BPEssentials/patch-03
2 parents 300e620 + 4848a5b commit 7e59784

10 files changed

Lines changed: 54 additions & 70 deletions

File tree

dist/localization.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@
121121
"warn_expired": "expired warn",
122122
"active_warns_count": "Active Warns: {0} Warns",
123123
"expired_warns_count": "Expired Warns: {0} Warns",
124-
"kit_price_automatically_calculated": "Automatic Kit Price: {0}$"
124+
"kit_price_automatically_calculated": "Automatic Kit Price: {0}$",
125+
"player_giveammo_fail": "You do not have a weapon that needs ammo in your hands!"
125126
},
126127
"BR": {
127128
"arrested": "Preso {0}.",

dist/settings.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
// This does not change already Registerd ones
88
"LimitNames": false,
99
// This forbbids pressing Register when the Account already was registerd once.
10-
"DisableAccountOverwrite": false
10+
"DisableAccountOverwrite": false,
11+
"SaveInterval": 15
1112
},
1213
"KeptItemsOnDeath": {
1314
"KeepAllItemsOnDeath": false,
@@ -425,6 +426,13 @@
425426
"Commands": [
426427
"deletekit"
427428
]
429+
},
430+
{
431+
"CommandName": "GiveAmmo",
432+
"Commands": [
433+
"giveammo",
434+
"ga"
435+
]
428436
}
429437
]
430438
}

src/BPEssentials/BPEssentials.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@
295295
<Compile Include="Commands\Moderation\ToggleBypass.cs" />
296296
<Compile Include="Commands\Moderation\ToggleSpyChat.cs" />
297297
<Compile Include="Commands\Pay\Pay.cs" />
298+
<Compile Include="Commands\Player\Inventory\GiveAmmo.cs" />
298299
<Compile Include="Commands\Player\SetJob.cs" />
299300
<Compile Include="Commands\Player\ToggleGodmode.cs" />
300301
<Compile Include="Commands\Player\ToggleMute.cs" />

src/BPEssentials/Commands/Misc/Launch.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ namespace BPEssentials.Commands
77
{
88
public class Launch : Command
99
{
10-
public void Invoke(ShPlayer player, ShPlayer target = null)
10+
public void Invoke(ShPlayer player, ShPlayer target = null, float thrust = 6500f)
1111
{
1212
target = target ?? player;
13-
target.svPlayer.SvForce(new UnityEngine.Vector3(0f, 6500f, 0f));
13+
target.svPlayer.SvForce(new UnityEngine.Vector3(0f, thrust, 0f));
1414
target.TS("target_launched");
1515
player.TS("player_launched", target.username.CleanerMessage());
1616
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using BPEssentials.Abstractions;
2+
using BPEssentials.ExtensionMethods;
3+
using BPEssentials.Utils;
4+
5+
using BrokeProtocol.Entities;
6+
using BrokeProtocol.Utility;
7+
using System.Linq;
8+
9+
namespace BPEssentials.Commands
10+
{
11+
public class GiveAmmo : Command
12+
{
13+
public void Invoke(ShPlayer player, int amount = 1, ShPlayer target = null)
14+
{
15+
target = target ?? player;
16+
17+
if (!target.curEquipable || !target.curEquipable.AmmoItem)
18+
{
19+
player.TS("player_giveammo_fail");
20+
}
21+
22+
var item = target.curEquipable.AmmoItem;
23+
target.TransferItem(DeltaInv.AddToMe, item.index, amount, true);
24+
player.TS("player_give", target.username.CleanerMessage(), item.itemName, amount.ToString());
25+
}
26+
}
27+
}

src/BPEssentials/Commands/Server/Save.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
11
using BPEssentials.Abstractions;
2-
using BPEssentials.ExtensionMethods;
3-
4-
using BrokeProtocol.Collections;
52
using BrokeProtocol.Entities;
6-
using Newtonsoft.Json;
7-
using System.Linq;
83

94
namespace BPEssentials.Commands
105
{
116
public class Save : Command
127
{
13-
public void StartSaveTimer()
14-
{
15-
16-
var Tmer = new System.Timers.Timer(); // TODO: Disposing the timer seems to break
17-
Tmer.Elapsed += (sender, e) => Run();
18-
Tmer.Interval = 15 * 60 * 1000;
19-
Tmer.Enabled = true;
20-
21-
}
22-
238
public void Invoke(ShPlayer player)
249
{
2510
Run();
2611
}
12+
2713
public void Run()
2814
{
2915
Core.Instance.Logger.Log("Saving Game Status");

src/BPEssentials/Configuration/Models/SettingsModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public class General
9191
{
9292
public string Version { get; set; }
9393

94-
public int AnnounceInterval { get; set; }
94+
public int SaveInterval { get; set; } = 15;
9595

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

src/BPEssentials/Core.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ public Core()
8282

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

src/BPEssentials/Events/OnRegister.cs

Lines changed: 8 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,60 +11,20 @@ namespace BPEssentials.RegisteredEvents
1111
public class OnRegiser : IScript
1212
{
1313

14-
[Target(GameSourceEvent.ManagerTryRegister, ExecutionMode.Override)]
15-
public void OnTryRegister(SvManager svManager, ConnectionData connectionData)
14+
[Target(GameSourceEvent.ManagerTryRegister, ExecutionMode.Test)]
15+
public bool OnTryRegister(SvManager svManager, ConnectionData connectionData)
1616
{
17-
if (ValidateUser(svManager, connectionData))
17+
if (Core.Instance.Settings.General.LimitNames && !Regex.IsMatch(connectionData.username, @"^[a-zA-Z0-9_-]+$"))
1818
{
19-
if (svManager.TryGetUserData(connectionData.username, out User playerData))
20-
{
21-
if(Core.Instance.Settings.General.DisableAccountOverwrite)
22-
{
23-
svManager.RegisterFail(connectionData.connection, "This Name has already been registerd and this Server has disabled overwriting Accounts!");
24-
return;
25-
}
26-
if (playerData.PasswordHash != connectionData.passwordHash)
27-
{
28-
svManager.RegisterFail(connectionData.connection, "Invalid credentials");
29-
return;
30-
}
31-
}
32-
33-
if (!connectionData.username.ValidCredential())
34-
{
35-
svManager.RegisterFail(connectionData.connection, $"Name cannot be registered (min: {Util.minCredential}, max: {Util.maxCredential})");
36-
return;
37-
}
38-
// -- BPE EXTEND
39-
if (Core.Instance.Settings.General.LimitNames && !Regex.IsMatch(connectionData.username, @"^[a-zA-Z0-9_-]+$"))
40-
{
41-
svManager.RegisterFail(connectionData.connection, $"Your Username can only contain letters: A-Z a-z 0-9 _ -");
42-
return;
43-
}
44-
// BPE EXTEND --
45-
svManager.AddNewPlayer(connectionData, playerData?.Persistent);
46-
}
47-
}
48-
49-
public bool ValidateUser(SvManager svManager, ConnectionData authData)
50-
{
51-
if (!svManager.HandleWhitelist(authData.username))
52-
{
53-
svManager.RegisterFail(authData.connection, "Account not whitelisted");
19+
svManager.RegisterFail(connectionData.connection, $"Your username can only contain the following characters: A-Z a-z 0-9 _ -");
5420
return false;
5521
}
56-
57-
// Don't allow multi-boxing, WebAPI doesn't prevent this
58-
foreach (ShPlayer p in EntityCollections.Humans)
22+
if (svManager.TryGetUserData(connectionData.username, out var user) && Core.Instance.Settings.General.DisableAccountOverwrite)
5923
{
60-
if (p.username == authData.username)
61-
{
62-
svManager.RegisterFail(authData.connection, "Account still logged in");
63-
return false;
64-
}
24+
svManager.RegisterFail(connectionData.connection, "This name has already been registered and this server has disabled overwriting accounts!");
25+
return false;
6526
}
66-
6727
return true;
6828
}
6929
}
70-
}
30+
}

src/BPEssentials/Events/OnStarted.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using BrokeProtocol.API;
1+
using BPCoreLib.Util;
2+
using BrokeProtocol.API;
23
using BrokeProtocol.Entities;
34
using BrokeProtocol.Managers;
45
using BrokeProtocol.Utility;
@@ -13,6 +14,7 @@ public class OnStarted : IScript
1314
public void OnEvent(SvManager svManager)
1415
{
1516
Core.Instance.SvManager = svManager;
17+
Core.Instance.SvManager.StartCoroutine(Interval.Start(Core.Instance.Settings.General.SaveInterval * 60 * 1000, new Commands.Save().Run));
1618
}
1719
}
1820
}

0 commit comments

Comments
 (0)