Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Some small initial release fixes
Browse files Browse the repository at this point in the history
- Reduced halplibe required version check to 2.1.6 (included by default in server babric instance)
- Some code cosmetic changes that were pointed out by IntelliJ IDEA language server
- Included bcrypt lib to be compiled in
  • Loading branch information
Myknakryu committed Sep 7, 2023
1 parent e585e15 commit e877272
Show file tree
Hide file tree
Showing 16 changed files with 25 additions and 34 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Simplified auth
This is serversided modification that allows for authorization using ingame commands, such as /register or /login

## Licenses:
Libraries used in this project are using:
- jBcrypt (MIT): https://github.com/jeremyh/jBCrypt
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ dependencies {
implementation("org.apache.logging.log4j:log4j-1.2-api:${log4jVersion}")
implementation("log4j:apache-log4j-extras:1.2.17")

implementation 'org.mindrot:jbcrypt:0.4'
implementation("org.mindrot:jbcrypt:${project.bcrypt_version}")
include("org.mindrot:jbcrypt:${project.bcrypt_version}")
}

java {
Expand Down
5 changes: 4 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ bta_version=1.7.7.0_02
loader_version=0.14.19-babric.1-bta

# HalpLibe
halplibe_version=2.2.0
halplibe_version=2.1.6

#bcrypt
bcrypt_version=0.4

# Mod
mod_version=0.0.1.1
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/pl/myku/simplifiedAuth/Player.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package pl.myku.simplifiedAuth;

import net.minecraft.core.entity.player.EntityPlayer;
import net.minecraft.server.entity.player.EntityPlayerMP;
public class Player {
private EntityPlayer player;
private final EntityPlayer player;
private boolean authorized = false;
public Player(EntityPlayer player){
this.player = player;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/pl/myku/simplifiedAuth/PlayerManager.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pl.myku.simplifiedAuth;

import net.minecraft.core.entity.player.EntityPlayer;
import net.minecraft.server.entity.player.EntityPlayerMP;
import java.util.HashMap;

public class PlayerManager extends HashMap<String, Player>{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public class ChangePasswordCommand extends Command {
public ChangePasswordCommand() {
super("changepassword", new String[0]);
super("changepassword");
}

public boolean execute(CommandHandler handler, CommandSender sender, String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pl.myku.simplifiedAuth.SimplifiedAuth;

public class LoginCommand extends Command{
public LoginCommand() {super("login", new String[0]);}
public LoginCommand() {super("login");}
public boolean execute(CommandHandler handler, CommandSender sender, String[] args) {
EntityPlayer player;
if(sender.getPlayer() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
import net.minecraft.core.net.command.CommandSender;
import pl.myku.simplifiedAuth.SimplifiedAuth;

import java.util.Arrays;

public class RegisterCommand extends Command {
public RegisterCommand() {
super("register", new String[0]);
super("register");
}

public boolean execute(CommandHandler handler, CommandSender sender, String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package pl.myku.simplifiedAuth.commands;
import net.minecraft.core.entity.player.EntityPlayer;
import net.minecraft.core.net.command.*;
import pl.myku.simplifiedAuth.SimplifiedAuth;

public class VersionCommand extends Command {
public VersionCommand() {super("version", new String[0]);}
public VersionCommand() {super("version");}

public boolean execute(CommandHandler handler, CommandSender sender, String[] args) {
EntityPlayer player;
if(sender.getPlayer() != null) {
sender.sendMessage("Version 0.0.1 ");
return true;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/pl/myku/simplifiedAuth/db/IDbManager.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package pl.myku.simplifiedAuth.db;

public interface IDbManager {
public Boolean loginPlayer(String username, String password);
public Boolean isPlayerRegistered(String username);
public void addPlayerToDatabase(String username, String password);
public void changePassword(String username, String password);
public void reloadDb();
Boolean loginPlayer(String username, String password);
Boolean isPlayerRegistered(String username);
void addPlayerToDatabase(String username, String password);
void changePassword(String username, String password);
void reloadDb();
}
8 changes: 4 additions & 4 deletions src/main/java/pl/myku/simplifiedAuth/db/JsonDbManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void saveDb(){
}
}
private JsonObject findPlayer(String username){
if (db.getAsJsonArray("Users").size() > 0) {
if (!db.getAsJsonArray("Users").isEmpty()) {
for(int i = 0; i < db.size(); i++){
JsonObject tmpUser = db.getAsJsonArray("Users").get(i).getAsJsonObject();
if(tmpUser.get("user").getAsString().equals(username)){
Expand All @@ -67,7 +67,7 @@ public Boolean loginPlayer(String username, String password){
return Utils.checkPassword(password, player.get("password").getAsString());
}
return false;
};
}

public void changePassword(String username, String password){
JsonObject player = findPlayer(username);
Expand All @@ -80,13 +80,13 @@ public void changePassword(String username, String password){

public Boolean isPlayerRegistered(String username){
return findPlayer(username) != null;
};
}

public void addPlayerToDatabase(String username, String password){
JsonObject player = new JsonObject();
player.addProperty("user", username);
player.addProperty("password", Utils.hashPassword(password));
db.getAsJsonArray("Users").add(player);
saveDb();
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
import net.minecraft.core.entity.Entity;
import net.minecraft.core.util.helper.DamageType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import pl.myku.simplifiedAuth.Player;
import pl.myku.simplifiedAuth.SimplifiedAuth;
import pl.myku.simplifiedAuth.commands.VersionCommand;
import net.minecraft.server.entity.player.EntityPlayerMP;
import net.minecraft.core.entity.player.EntityPlayer;

@Mixin(value = EntityPlayerMP.class, remap = false)
final class EntityPlayerMPMixin {
Expand All @@ -22,7 +18,6 @@ private void authorizationInvulnerability(Entity entity, int i, DamageType type,

if (player != null && !player.isAuthorized()) {
cir.setReturnValue(false);
return;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import net.minecraft.core.entity.player.EntityPlayer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(EntityPlayer.class)
public class EntityPlayerMixin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void handleChat(Packet3Chat packet, CallbackInfo ci) throws Exception {
return;
}
} catch (Exception e) {
throw new RuntimeException(e);
SimplifiedAuth.LOGGER.error(e.getMessage());
}
ci.cancel();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package pl.myku.simplifiedAuth.mixin;

import net.minecraft.server.player.*;
import org.spongepowered.asm.mixin.Mixin;


public class PlayerInstanceMixin {
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

"depends": {
"fabricloader": ">=0.13.3",
"halplibe": ">=2.2.0"
"halplibe": ">=2.1.6"
},
"suggests": {
}
Expand Down

0 comments on commit e877272

Please sign in to comment.