Skip to content

Commit

Permalink
Add config and handling for IsAutoRegister and IsFlippedUsername, res…
Browse files Browse the repository at this point in the history
…olves #75
  • Loading branch information
Kaioru committed Sep 29, 2023
1 parent 7d6b0f7 commit 72b770b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ namespace Edelstein.Application.Server.Configs;
public record ProgramConfigStageLogin : ProgramConfigStage, ILoginStageOptions
{
public byte[] Worlds { get; set; }

public bool IsAutoRegister { get; set; } = true;
public bool IsFlippedUsername { get; set; } = false;
}
4 changes: 3 additions & 1 deletion src/app/Edelstein.Application.Server/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"Worlds": [
0,
1
]
],
"IsAutoRegister": true,
"IsFlippedUsername": false
}
],
"GameStages": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@ public CheckPasswordHandler(IPipeline<UserOnPacketCheckPassword> pipeline) : bas
public override bool Check(ILoginStageUser user) => user.State == LoginState.CheckPassword;

public override UserOnPacketCheckPassword Serialize(ILoginStageUser user, IPacketReader reader)
=> new(
{
var username = reader.ReadString();
var password = reader.ReadString();

if (user.Context.Options.IsFlippedUsername)
(username, password) = (password, username);

return new(
user,
reader.ReadString(),
reader.ReadString()
username,
password
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task Handle(IPipelineContext ctx, UserOnPacketCheckPassword message
_ => LoginResult.Unknown
};

if (result == LoginResult.NotRegistered)
if (message.User.Context.Options.IsAutoRegister && result == LoginResult.NotRegistered)
{
// TODO: Move autoregister this to plugin
result = LoginResult.Success;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ namespace Edelstein.Protocol.Gameplay.Login;
public interface ILoginStageOptions : IIdentifiable<string>
{
byte[] Worlds { get; }

// TODO move this to plugins
bool IsAutoRegister { get; }
bool IsFlippedUsername { get; }
}

0 comments on commit 72b770b

Please sign in to comment.