Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EP on first-character creation (instead of account create), check uniqueness on email only #52

Merged
merged 4 commits into from
Mar 27, 2018
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
9 changes: 3 additions & 6 deletions src/Perpetuum.RequestHandlers/AdminTools/AccountCreate.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Perpetuum.Accounting;
using Perpetuum.Data;
using Perpetuum.Host.Requests;
using System.Data;

namespace Perpetuum.RequestHandlers.AdminTools
{
Expand All @@ -26,19 +27,15 @@ public void HandleRequest(IRequest request)
CampaignId = "{\"host\":\"tooladmin\"}"
};

if (_accountRepository.Get(account.Email,account.Password) != null)
//If email exists - throw error
if (_accountRepository.Get(account.Email, account.Password) != null)
{
Message.Builder.FromRequest(request).WithError(ErrorCodes.AccountAlreadyExists).Send();
return;
}

_accountRepository.Insert(account);

Db.Query().CommandText("extensionPointsInject")
.SetParameter("@accountID", account.Id)
.SetParameter("@points", 40000)
.ExecuteNonQuery();

Message.Builder.FromRequest(request).SetData(k.account, account.ToDictionary()).Send();
}
}
Expand Down
11 changes: 3 additions & 8 deletions src/Perpetuum.RequestHandlers/AdminTools/AccountOpenCreate.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Perpetuum.Accounting;
using Perpetuum.Data;
using Perpetuum.Host.Requests;
using Perpetuum.Services.Relay;

Expand Down Expand Up @@ -29,7 +28,7 @@ public void HandleRequest(IRequest request)
// if an account was already created using this session, reject this creation attempt.
if (request.Session.AccountCreatedInSession)
{
throw new PerpetuumException(ErrorCodes.AccountAlreadyExists);
throw new PerpetuumException(ErrorCodes.MaxIterationsExceeded);
}

var account = new Account
Expand All @@ -40,7 +39,8 @@ public void HandleRequest(IRequest request)
CampaignId = "{\"host\":\"opencreate\"}"
};

if (_accountRepository.Get(account.Email,account.Password) != null)
//If email exists - throw error
if (_accountRepository.Get(account.Email, account.Password) != null)
{
Message.Builder.FromRequest(request).WithError(ErrorCodes.AccountAlreadyExists).Send();
return;
Expand All @@ -51,11 +51,6 @@ public void HandleRequest(IRequest request)
// if we get this far, make sure we can't sit here and make accounts.
request.Session.AccountCreatedInSession = true;

Db.Query().CommandText("extensionPointsInject")
.SetParameter("@accountID", account.Id)
.SetParameter("@points", 40000)
.ExecuteNonQuery();

Message.Builder.FromRequest(request).SetData(k.account, account.ToDictionary()).Send();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public void HandleRequest(IRequest request)
if (account.FirstCharacterDate == null)
{
account.FirstCharacterDate = DateTime.Now;
_accountManager.AddExtensionPoints(account, 40000); //TODO: starting EP - store in DB
_accountManager.Repository.Update(account);
}

Expand Down
9 changes: 9 additions & 0 deletions src/Perpetuum/Accounting/AccountRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ public Account Get(int accountId, string steamId)
return CreateAccountFromRecord(record);
}

public Account Get(string email)
{
var record = Db.Query("select * from accounts where email = @email")
.SetParameter("email", email)
.ExecuteSingleRow();

return CreateAccountFromRecord(record);
}

public Account Get(string email, string password)
{
var record = Db.Query("select * from accounts where email = @email and password = @password")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class TrainingExitStrategy : ITeleportStrategy

public delegate TrainingExitStrategy Factory(TeleportDescription description);

public TrainingExitStrategy(TeleportDescription description,ITrainingRewardRepository trainingRewardRepository,IChannelManager channelManager,CharacterCleaner characterCleaner,SparkHelper sparkHelper)
public TrainingExitStrategy(TeleportDescription description, ITrainingRewardRepository trainingRewardRepository, IChannelManager channelManager, CharacterCleaner characterCleaner, SparkHelper sparkHelper)
{
_description = description;
_trainingRewardRepository = trainingRewardRepository;
Expand All @@ -45,7 +45,7 @@ public void DoTeleport(Player player)
{
//Throw if email not confirmed
player.Character.GetAccount().EmailConfirmed.ThrowIfFalse(ErrorCodes.EmailNotConfirmed);

player.States.Dock = true;

var character = player.Character;
Expand All @@ -56,7 +56,7 @@ public void DoTeleport(Player player)

var info = GetCharacterWizardInfo();

var newCorporation = DefaultCorporation.GetBySchool(info.raceId,info.schoolId);
var newCorporation = DefaultCorporation.GetBySchool(info.raceId, info.schoolId);
oldCorporation.RemoveMember(character);
newCorporation.AddMember(character, CorporationRole.NotDefined, oldCorporation);

Expand Down Expand Up @@ -123,7 +123,7 @@ private struct CharacterWizardInfo
public int schoolId;
public int sparkId;

public CharacterWizardInfo(int raceId,int schoolId,int majorId,int sparkId) : this()
public CharacterWizardInfo(int raceId, int schoolId, int majorId, int sparkId) : this()
{
this.majorId = majorId;
this.raceId = raceId;
Expand Down