mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE] More commands
This commit is contained in:
parent
80a7e1b593
commit
386239bfd7
6 changed files with 211 additions and 6 deletions
|
@ -7,10 +7,15 @@
|
|||
import pro.gravit.launcher.request.auth.AuthRequest;
|
||||
import pro.gravit.launcher.request.auth.details.AuthPasswordDetails;
|
||||
import pro.gravit.launcher.request.auth.password.AuthPlainPassword;
|
||||
import pro.gravit.launcher.request.secure.HardwareReportRequest;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.Reconfigurable;
|
||||
import pro.gravit.launchserver.auth.AuthException;
|
||||
import pro.gravit.launchserver.auth.core.interfaces.UserHardware;
|
||||
import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportGetAllUsers;
|
||||
import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportHardware;
|
||||
import pro.gravit.launchserver.auth.core.interfaces.user.UserSupportHardware;
|
||||
import pro.gravit.launchserver.auth.protect.hwid.HWIDProvider;
|
||||
import pro.gravit.launchserver.manangers.AuthManager;
|
||||
import pro.gravit.launchserver.socket.Client;
|
||||
import pro.gravit.launchserver.socket.response.auth.AuthResponse;
|
||||
|
@ -100,6 +105,56 @@ public void invoke(String... args) throws Exception {
|
|||
}
|
||||
}
|
||||
});
|
||||
map.put("getuserbyusername", new SubCommand("[username]", "get user by username") {
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
verifyArgs(args, 1);
|
||||
User user = getUserByUsername(args[0]);
|
||||
if (user == null) {
|
||||
logger.info("User {} not found", args[0]);
|
||||
} else {
|
||||
logger.info("User {}: {}", args[0], user.toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
map.put("getuserbyuuid", new SubCommand("[uuid]", "get user by uuid") {
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
verifyArgs(args, 1);
|
||||
User user = getUserByUUID(UUID.fromString(args[0]));
|
||||
if (user == null) {
|
||||
logger.info("User {} not found", args[0]);
|
||||
} else {
|
||||
logger.info("User {}: {}", args[0], user.toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
map.put("createsession", new SubCommand("[username] (true/false)", "create user session with/without minecraft access") {
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
verifyArgs(args, 1);
|
||||
User user = getUserByUsername(args[0]);
|
||||
if (user == null) {
|
||||
logger.info("User {} not found", args[0]);
|
||||
return;
|
||||
}
|
||||
boolean minecraftAccess = args.length > 1 && Boolean.parseBoolean(args[1]);
|
||||
AuthManager.AuthReport report = createOAuthSession(user, null, null, minecraftAccess);
|
||||
if (report == null) {
|
||||
logger.error("Method createOAuthSession return null");
|
||||
return;
|
||||
}
|
||||
if (report.isUsingOAuth()) {
|
||||
logger.info("OAuth: AccessToken: {} RefreshToken: {} MinecraftAccessToken: {}", report.oauthAccessToken, report.oauthRefreshToken, report.minecraftAccessToken);
|
||||
if (report.session != null) {
|
||||
logger.info("UserSession: id {} expire {} user {}", report.session.getID(), report.session.getExpireIn(), report.session.getUser() == null ? "null" : "found");
|
||||
logger.info(report.session.toString());
|
||||
}
|
||||
} else {
|
||||
logger.info("Basic: MinecraftAccessToken: {}", report.minecraftAccessToken);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (this instanceof AuthSupportGetAllUsers) {
|
||||
AuthSupportGetAllUsers instance = (AuthSupportGetAllUsers) this;
|
||||
map.put("getallusers", new SubCommand("(limit)", "print all users information") {
|
||||
|
@ -107,7 +162,7 @@ public void invoke(String... args) throws Exception {
|
|||
public void invoke(String... args) throws Exception {
|
||||
int max = Integer.MAX_VALUE;
|
||||
if (args.length > 0) max = Integer.parseInt(args[0]);
|
||||
List<User> users = instance.getAllUsers();
|
||||
Iterable<User> users = instance.getAllUsers();
|
||||
int counter = 0;
|
||||
for (User u : users) {
|
||||
logger.info("User {}", u.toString());
|
||||
|
@ -118,6 +173,110 @@ public void invoke(String... args) throws Exception {
|
|||
}
|
||||
});
|
||||
}
|
||||
if (this instanceof AuthSupportHardware) {
|
||||
AuthSupportHardware instance = (AuthSupportHardware) this;
|
||||
map.put("gethardwarebyid", new SubCommand("[id]", "get hardware by id") {
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
verifyArgs(args, 1);
|
||||
UserHardware hardware = instance.getHardwareInfoById(args[0]);
|
||||
if (hardware == null) {
|
||||
logger.info("UserHardware {} not found", args[0]);
|
||||
} else {
|
||||
logger.info("UserHardware: {}", hardware);
|
||||
}
|
||||
}
|
||||
});
|
||||
map.put("gethardwarebydata", new SubCommand("[json data]", "fulltext search hardware by json data(slow)") {
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
verifyArgs(args, 1);
|
||||
UserHardware hardware = instance.getHardwareInfoByData(Launcher.gsonManager.gson.fromJson(args[0], HardwareReportRequest.HardwareInfo.class));
|
||||
if (hardware == null) {
|
||||
logger.info("UserHardware {} not found", args[0]);
|
||||
} else {
|
||||
logger.info("UserHardware: {}", hardware);
|
||||
}
|
||||
}
|
||||
});
|
||||
map.put("getuserhardware", new SubCommand("[username]", "get hardware by username") {
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
verifyArgs(args, 1);
|
||||
User user = getUserByUUID(UUID.fromString(args[0]));
|
||||
if (user == null) {
|
||||
logger.info("User {} not found", args[0]);
|
||||
}
|
||||
UserSupportHardware hardware = instance.fetchUserHardware(user);
|
||||
if (hardware == null) {
|
||||
logger.error("Method fetchUserHardware return null");
|
||||
return;
|
||||
}
|
||||
UserHardware userHardware = hardware.getHardware();
|
||||
if (userHardware == null) {
|
||||
logger.info("User {} not contains hardware info", args[0]);
|
||||
} else {
|
||||
logger.info("UserHardware: {}", userHardware);
|
||||
logger.info("HardwareInfo(JSON): {}", Launcher.gsonManager.gson.toJson(userHardware.getHardwareInfo()));
|
||||
}
|
||||
}
|
||||
});
|
||||
map.put("findmulti", new SubCommand("[hardware id]", "get all users in one hardware id") {
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
verifyArgs(args, 1);
|
||||
UserHardware hardware = instance.getHardwareInfoById(args[0]);
|
||||
if (hardware == null) {
|
||||
logger.info("UserHardware {} not found", args[0]);
|
||||
return;
|
||||
}
|
||||
Iterable<User> users = instance.getUsersByHardwareInfo(hardware);
|
||||
for (User user : users) {
|
||||
logger.info("User {}", user.getUsername());
|
||||
}
|
||||
}
|
||||
});
|
||||
map.put("banhardware", new SubCommand("[hardware id]", "ban hardware by id") {
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
verifyArgs(args, 1);
|
||||
UserHardware hardware = instance.getHardwareInfoById(args[0]);
|
||||
if (hardware == null) {
|
||||
logger.info("UserHardware {} not found", args[0]);
|
||||
return;
|
||||
}
|
||||
instance.banHardware(hardware);
|
||||
logger.info("UserHardware {} banned", args[0]);
|
||||
}
|
||||
});
|
||||
map.put("unbanhardware", new SubCommand("[hardware id]", "ban hardware by id") {
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
verifyArgs(args, 1);
|
||||
UserHardware hardware = instance.getHardwareInfoById(args[0]);
|
||||
if (hardware == null) {
|
||||
logger.info("UserHardware {} not found", args[0]);
|
||||
return;
|
||||
}
|
||||
instance.unbanHardware(hardware);
|
||||
logger.info("UserHardware {} unbanned", args[0]);
|
||||
}
|
||||
});
|
||||
map.put("comparehardware", new SubCommand("[json data 1] [json data 2]", "compare hardware info") {
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
verifyArgs(args, 2);
|
||||
HardwareReportRequest.HardwareInfo hardware1 = Launcher.gsonManager.gson.fromJson(args[0], HardwareReportRequest.HardwareInfo.class);
|
||||
HardwareReportRequest.HardwareInfo hardware2 = Launcher.gsonManager.gson.fromJson(args[1], HardwareReportRequest.HardwareInfo.class);
|
||||
HWIDProvider.HardwareInfoCompareResult result = instance.compareHardwareInfo(hardware1, hardware2);
|
||||
if (result == null) {
|
||||
logger.error("Method compareHardwareInfo return null");
|
||||
return;
|
||||
}
|
||||
logger.info("Compare result: {} Spoof: {} first {} second", result.compareLevel, result.firstSpoofingLevel, result.secondSpoofingLevel);
|
||||
}
|
||||
});
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,4 +14,8 @@ public interface User {
|
|||
String getAccessToken();
|
||||
|
||||
ClientPermissions getPermissions();
|
||||
|
||||
default boolean isBanned() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,7 @@
|
|||
import pro.gravit.launchserver.auth.Feature;
|
||||
import pro.gravit.launchserver.auth.core.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Feature("users")
|
||||
public interface AuthSupportGetAllUsers {
|
||||
List<User> getAllUsers();
|
||||
Iterable<User> getAllUsers();
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
import pro.gravit.launchserver.helper.DamerauHelper;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public interface AuthSupportHardware {
|
||||
UserHardware getHardwareInfoByPublicKey(byte[] publicKey);
|
||||
|
@ -21,7 +20,7 @@ public interface AuthSupportHardware {
|
|||
|
||||
void addPublicKeyToHardwareInfo(UserHardware hardware, byte[] publicKey);
|
||||
|
||||
List<User> getUsersByHardwareInfo(UserHardware hardware);
|
||||
Iterable<User> getUsersByHardwareInfo(UserHardware hardware);
|
||||
|
||||
void banHardware(UserHardware hardware);
|
||||
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package pro.gravit.launchserver.auth.core.interfaces.provider;
|
||||
|
||||
import pro.gravit.launchserver.auth.core.User;
|
||||
import pro.gravit.launchserver.auth.core.interfaces.user.UserSupportBanInfo;
|
||||
|
||||
public interface AuthSupportUserBan {
|
||||
void banUser(User user, String reason);
|
||||
|
||||
default void banUser(User user) {
|
||||
banUser(user, null);
|
||||
}
|
||||
|
||||
void unbanUser(User user);
|
||||
|
||||
default UserSupportBanInfo fetchUserBanInfo(User user) {
|
||||
return (UserSupportBanInfo) user;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package pro.gravit.launchserver.auth.core.interfaces.user;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public interface UserSupportBanInfo {
|
||||
interface UserBanInfo {
|
||||
String getId();
|
||||
|
||||
default String getReason() {
|
||||
return null;
|
||||
}
|
||||
|
||||
default String getModerator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
default LocalDateTime getStartDate() {
|
||||
return null;
|
||||
}
|
||||
|
||||
default LocalDateTime getEndDate() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
UserBanInfo getBanInfo();
|
||||
}
|
Loading…
Reference in a new issue