add changepw

todo: cmd nicht in der konsole loggen @hydrant
This commit is contained in:
Luke
2021-07-03 00:11:01 +02:00
parent a35cae8bd2
commit fbf7aaedb4
4 changed files with 49 additions and 4 deletions

View File

@@ -22,6 +22,7 @@ namespace ReallifeGamemode.Server.Commands
{
private static readonly ILogger logger = LogManager.GetLogger<UserCommands>();
private const int PASSWORD_CHANGE_FEE = 5000;
private const int SMS_PRICE = 5;
[Command("rent", "~m~rent stop")]
@@ -114,6 +115,43 @@ namespace ReallifeGamemode.Server.Commands
player.SendChatMessage("~y~[EVENTPORT] ~s~Du hast dich zum Event teleportiert");
}
[Command("changepw", "~m~Benutzung: ~s~/changepw [Aktuelles Passwort] [Neues Passwort]", SensitiveInfo = true)]
public void CmdUserChangePw(Player player, string oldPassword, string newPassword)
{
if (!player.IsLoggedIn()) return;
if (oldPassword == newPassword)
{
ChatService.ErrorMessage(player, "Die eingegebenen Passwörter sind identisch");
return;
}
if (newPassword.Length < GlobalHelper.requiredPasswordLength)
{
ChatService.ErrorMessage(player, "Das neue Passwort muss aus mindestens sechs Zeichen bestehen");
return;
}
using (var dbContext = new DatabaseContext())
{
User user = player.GetUser(dbContext);
if (user.Password != NAPI.Util.GetHashSha256(oldPassword))
{
ChatService.ErrorMessage(player, "Du hast dein aktuelles Passwort falsch eingegeben");
return;
}
user.Password = NAPI.Util.GetHashSha256(newPassword);
logger.LogInformation("Player {0} changed their password for {1}", player.Name, PASSWORD_CHANGE_FEE.ToMoneyString());
user.BankAccount.Balance -= PASSWORD_CHANGE_FEE;
dbContext.SaveChanges();
}
ChatService.SendMessage(player, $"~y~[ACCOUNT] ~s~Du hast dein Passwort erfolgreich geändert. Dir wurden ~y~{ PASSWORD_CHANGE_FEE.ToMoneyString() } ~s~in Rechnung gestellt.");
}
[Command("sms", "~m~Benutzung: ~s~/sms [Spieler] [Nachricht]", GreedyArg = true)]
public void CmdUserSMS(Player player, string name, string msg)
{