Skip to content

Commit 590e892

Browse files
authored
Merge pull request #74 from ggggg/v1.07-ready
v1.07 ready
2 parents ee88d24 + db734b2 commit 590e892

File tree

9 files changed

+41
-48
lines changed

9 files changed

+41
-48
lines changed

src/BPEssentials/BPEssentials.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
<Reference Include="EmbedIO">
4848
<HintPath>lib\Managed\EmbedIO.dll</HintPath>
4949
</Reference>
50+
<Reference Include="ENet-CSharp">
51+
<HintPath>lib\Managed\ENet-CSharp.dll</HintPath>
52+
</Reference>
5053
<Reference Include="LiteDB">
5154
<HintPath>lib\Managed\LiteDB.dll</HintPath>
5255
</Reference>

src/BPEssentials/Commands/Moderation/Info.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Linq;
88
using System.Text;
99

10-
1110
namespace BPEssentials.Commands
1211
{
1312
public class Info : Command
@@ -21,10 +20,12 @@ public void Invoke(ShPlayer player, string targetStr)
2120
if (target != null)
2221
{
2322
sb = GetOfflineInfo(target);
24-
}else if(EntityCollections.TryGetPlayerByNameOrID(targetStr, out ShPlayer shPlayer))
23+
}
24+
else if (EntityCollections.TryGetPlayerByNameOrID(targetStr, out ShPlayer shPlayer))
2525
{
2626
sb = GetOnlineInfo(shPlayer);
27-
}else
27+
}
28+
else
2829
{
2930
player.SendChatMessage($"No account found with the id '{targetStr}'.");
3031
return;
@@ -42,13 +43,8 @@ private StringBuilder GetOfflineInfo(User target)
4243
.Append("Last Updated: ").AppendLine(target.LastUpdated.ToString())
4344
.Append("Join Date: ").AppendLine(target.JoinDate.ToString())
4445

45-
.AppendLine("BanInfo: ")
46-
.Append(" - Is banned: ").AppendLine(target.BanInfo?.IsBanned.ToString())
47-
.Append(" - Reason: ").AppendLine(target.BanInfo?.Reason)
48-
.Append(" - Date: ").AppendLine(target.BanInfo?.Date.ToString())
49-
5046
.AppendLine("Character:")
51-
.Append(" - Username: ").Append(target.Character.Username.CleanerMessage()).AppendLine(" (Sanitized)")
47+
.Append(" - Username: ").Append(target.ID.CleanerMessage()).AppendLine(" (Sanitized)")
5248
.Append(" - Health: ").AppendLine(target.Character.Health.ToString())
5349
.Append(" - BankBalance: ").AppendLine(target.Character.BankBalance.ToString())
5450
.Append(" - Position: ").AppendLine(target.Character.Position.ToString())
@@ -81,15 +77,14 @@ private StringBuilder GetOnlineInfo(ShPlayer target)
8177
var sb = new StringBuilder();
8278
sb
8379
.Append("ID: ").AppendLine(target.ID.ToString())
84-
.Append("accountID64: ").AppendLine(target.accountID.ToString())
8580
.Append("Username: ").Append(target.username.CleanerMessage()).AppendLine(" (Sanitized)")
8681
.Append("Health: ").AppendLine(target.health.ToString())
8782
.Append("BankBalance: ").AppendLine(target.svPlayer.bankBalance.ToString())
8883
.Append("Position: ").AppendLine(target.GetPosition.ToString())
8984
.Append("Rotation: ").AppendLine(target.GetRotation.ToString())
9085
.Append("Stats: ").AppendLine(string.Join("\n - ", target.stats))
91-
.Append("Expecting more info? Type '/info ").Append(target.accountID.ToString()).AppendLine("'.");
86+
.Append("Expecting more info? Type '/info ").Append(target.username.ToString()).AppendLine("'.");
9287
return sb;
9388
}
9489
}
95-
}
90+
}

src/BPEssentials/Commands/Moderation/Unban.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@ public void Invoke(ShPlayer player, string targetAccount)
1616
player.TS("user_not_found", targetAccount.CleanerMessage());
1717
return;
1818
}
19-
if (!target.BanInfo.IsBanned)
20-
{
21-
player.TS("user_not_ban", targetAccount.CleanerMessage());
22-
return;
23-
}
24-
target.Unban();
25-
Core.Instance.SvManager.database.Users.Upsert(target);
19+
Core.Instance.SvManager.database.Bans.Delete(target.IP);
2620
player.TS("unbanned", targetAccount.CleanerMessage());
2721
}
2822
}

src/BPEssentials/Commands/Player/Restrain.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using BPEssentials.ExtensionMethods;
33
using BrokeProtocol.Entities;
44

5-
65
namespace BPEssentials.Commands
76
{
87
public class Restrain : Command
@@ -11,9 +10,9 @@ public void Invoke(ShPlayer player, ShPlayer target)
1110
{
1211
target.svPlayer.Restrain(target.manager.handcuffed);
1312
var shRetained = target.curEquipable as ShRestrained;
14-
target.svPlayer.SvSetEquipable(shRetained.otherRestrained.index);
13+
target.svPlayer.SvSetEquipable(shRetained.index);
1514
target.TS("target_restrained");
1615
player.TS("player_restrained", target.username.CleanerMessage());
1716
}
1817
}
19-
}
18+
}

src/BPEssentials/CooldownHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void SaveCooldowns()
4141
{
4242
foreach (var cooldownPlayer in Cooldowns)
4343
{
44-
var onlinePlayer = EntityCollections.Humans.FirstOrDefault(x => x.accountID == cooldownPlayer.Key);
44+
var onlinePlayer = EntityCollections.Humans.FirstOrDefault(x => x.username == cooldownPlayer.Key);
4545
if (onlinePlayer)
4646
{
4747
onlinePlayer.svPlayer.CustomData.AddOrUpdate(CustomDataKey, cooldownPlayer.Value);

src/BPEssentials/Events/OnRegister.cs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,44 @@ namespace BPEssentials.RegisteredEvents
1313
public class OnRegiser : IScript
1414
{
1515
[Target(GameSourceEvent.ManagerTryRegister, ExecutionMode.Override)]
16-
public void OnTryRegister(SvManager svManager, AuthData authData, ConnectData connectData)
16+
public void OnTryRegister(SvManager svManager, ConnectionData connectData)
1717
{
18-
if (ValidateUser(svManager, authData))
18+
if (ValidateUser(svManager, connectData))
1919
{
20-
if (svManager.TryGetUserData(authData.accountID, out User playerData))
20+
if (svManager.TryGetUserData(connectData.username, out User playerData))
2121
{
22-
if (playerData.BanInfo.IsBanned)
22+
if (playerData.PasswordHash != connectData.passwordHash)
2323
{
24-
svManager.RegisterFail(authData.connection, $"Account banned: {playerData.BanInfo.Reason}");
25-
return;
26-
}
27-
28-
if (!svManager.settings.auth.steam && playerData.PasswordHash != connectData.passwordHash)
29-
{
30-
svManager.RegisterFail(authData.connection, $"Invalid credentials");
24+
svManager.RegisterFail(connectData.connection, "Invalid credentials");
3125
return;
3226
}
3327
}
3428

29+
if (!connectData.username.ValidCredential())
30+
{
31+
svManager.RegisterFail(connectData.connection, $"Name cannot be registered (min: {Util.minCredential}, max: {Util.maxCredential})");
32+
return;
33+
}
3534

3635
if (!connectData.username.ValidCredential())
3736
{
38-
svManager.RegisterFail(authData.connection, $"Name cannot be registered (min: {Util.minCredential}, max: {Util.maxCredential})");
37+
svManager.RegisterFail(connectData.connection, $"Name cannot be registered (min: {Util.minCredential}, max: {Util.maxCredential})");
3938
return;
4039
}
4140
// -- BPE EXTEND
4241
if (Core.Instance.Settings.General.LimitNames && !Regex.IsMatch(connectData.username, @"^[a-zA-Z0-9_]+$"))
4342
{
44-
svManager.RegisterFail(authData.connection, $"Your Username can only contain letters: A-Z a-z 0-9 _ -");
43+
svManager.RegisterFail(connectData.connection, $"Your Username can only contain letters: A-Z a-z 0-9 _ -");
4544
return;
4645
}
4746
// BPE EXTEND --
48-
svManager.AddNewPlayer(authData, connectData);
47+
svManager.AddNewPlayer(connectData);
4948
}
5049
}
5150

52-
public bool ValidateUser(SvManager svManager, AuthData authData)
51+
public bool ValidateUser(SvManager svManager, ConnectionData authData)
5352
{
54-
if (!svManager.HandleWhitelist(authData.accountID))
53+
if (!svManager.HandleWhitelist(authData.username))
5554
{
5655
svManager.RegisterFail(authData.connection, "Account not whitelisted");
5756
return false;
@@ -60,7 +59,7 @@ public bool ValidateUser(SvManager svManager, AuthData authData)
6059
// Don't allow multi-boxing, WebAPI doesn't prevent this
6160
foreach (ShPlayer p in EntityCollections.Humans)
6261
{
63-
if (p.accountID == authData.accountID)
62+
if (p.username == authData.username)
6463
{
6564
svManager.RegisterFail(authData.connection, "Account still logged in");
6665
return false;
@@ -70,4 +69,4 @@ public bool ValidateUser(SvManager svManager, AuthData authData)
7069
return true;
7170
}
7271
}
73-
}
72+
}

src/BPEssentials/Events/OnStarted.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using BrokeProtocol.API;
2+
using BrokeProtocol.Entities;
23
using BrokeProtocol.Managers;
4+
using BrokeProtocol.Utility;
35
using System;
6+
using System.Linq;
47

58
namespace BPEssentials.RegisteredEvents
69
{

src/BPEssentials/ExtensionMethods/PlayerCooldowns.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ public static class ExtensionPlayerCooldowns
66
{
77
public static bool HasCooldown(this ShPlayer player, string type, string key)
88
{
9-
return Core.Instance.CooldownHandler.IsCooldown(player.accountID, type, key);
9+
return Core.Instance.CooldownHandler.IsCooldown(player.username, type, key);
1010
}
1111

1212
public static void AddCooldown(this ShPlayer player, string type, string key, int time)
1313
{
14-
Core.Instance.CooldownHandler.AddCooldown(player.accountID, type, key, time);
14+
Core.Instance.CooldownHandler.AddCooldown(player.username, type, key, time);
1515
}
1616

1717
public static int GetCooldown(this ShPlayer player, string type, string key)
1818
{
19-
return Core.Instance.CooldownHandler.GetCooldown(player.accountID, type, key);
19+
return Core.Instance.CooldownHandler.GetCooldown(player.username, type, key);
2020
}
2121
}
22-
}
22+
}

src/BPEssentials/ExtensionMethods/PlayerWarns.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ public SerializableWarn(string issuer, string reason, DateTime dateTime)
2727
public string ToString(ShPlayer player)
2828
{
2929
var issuer = Core.Instance.SvManager.database.Users.FindById(IssueraccountID);
30-
return player.T("warn_toString", Reason, issuer != null ? issuer.Character.Username : IssueraccountID, Date.ToString(CultureInfo.InvariantCulture));
30+
return player.T("warn_toString", Reason, issuer != null ? issuer.ID : IssueraccountID, Date.ToString(CultureInfo.InvariantCulture));
3131
}
3232
}
3333

3434
public static void AddWarn(this ShPlayer player, ShPlayer issuer, string reason)
3535
{
3636
var warns = GetWarns(player);
37-
warns.Add(new SerializableWarn(issuer.accountID, reason, DateTime.Now));
37+
warns.Add(new SerializableWarn(issuer.username, reason, DateTime.Now));
3838
player.svPlayer.CustomData.AddOrUpdate(CustomDataKey, warns);
3939
}
4040

@@ -55,4 +55,4 @@ public static List<SerializableWarn> GetWarns(this ShPlayer player)
5555
return warns;
5656
}
5757
}
58-
}
58+
}

0 commit comments

Comments
 (0)