Changed whole project structure (split client and server into separat projects)
This commit is contained in:
67
ReallifeGamemode.Server/Events/Register.cs
Normal file
67
ReallifeGamemode.Server/Events/Register.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System.Linq;
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Models;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Event Register (Register.cs)
|
||||
* @author VegaZ
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
namespace reallife_gamemode.Server.Events
|
||||
{
|
||||
class Register : Script
|
||||
{
|
||||
[RemoteEvent("OnPlayerRegister")]
|
||||
public void OnPlayerRegister(Client player, string password)
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
var checkedUser = dbContext.Users.SingleOrDefault(b => b.Name == player.Name);
|
||||
if (checkedUser == null)
|
||||
{
|
||||
var user = new Entities.User
|
||||
{
|
||||
Name = player.Name,
|
||||
SocialClubName = player.SocialClubName,
|
||||
Password = NAPI.Util.GetHashSha256(password),
|
||||
PositionX = Main.DEFAULT_SPAWN_POSITION.X,
|
||||
PositionY = Main.DEFAULT_SPAWN_POSITION.Y,
|
||||
PositionZ = Main.DEFAULT_SPAWN_POSITION.Z
|
||||
};
|
||||
|
||||
dbContext.Users.Add(user);
|
||||
dbContext.SaveChanges();
|
||||
var userBankAccount = new Entities.UserBankAccount
|
||||
{
|
||||
UserId = user.Id,
|
||||
Balance = 5000,
|
||||
Active = true
|
||||
};
|
||||
|
||||
dbContext.UserBankAccounts.Add(userBankAccount);
|
||||
dbContext.SaveChanges();
|
||||
|
||||
player.TriggerEvent("registerSuccess");
|
||||
player.SetData("isLoggedIn", true);
|
||||
player.SetData("isDead", false);
|
||||
|
||||
var currentPlayerCreatorDimension = (uint) NAPI.Data.GetWorldData("playerCreatorDimension");
|
||||
currentPlayerCreatorDimension++;
|
||||
NAPI.Data.SetWorldData("playerCreatorDimension", currentPlayerCreatorDimension);
|
||||
player.Dimension = NAPI.Data.GetWorldData("playerCreatorDimension");
|
||||
player.TriggerEvent("toggleCreator");
|
||||
}
|
||||
|
||||
else if (player.SocialClubName == checkedUser.SocialClubName)
|
||||
{
|
||||
player.TriggerEvent("registerFail", "Dieser SocialClubAccount ist schon registriert!");
|
||||
}
|
||||
else if (checkedUser.Name == player.Name)
|
||||
{
|
||||
player.TriggerEvent("registerFail", "Benutzername existiert schon!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user