mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +03:00
Merge branch 'dev' of github.com:GravitLauncher/Launcher into
dev
This commit is contained in:
commit
6b663c481c
14 changed files with 300 additions and 10 deletions
|
@ -68,6 +68,8 @@ public void reload() throws Exception {
|
|||
for (AuthProviderPair auth : config.auth) {
|
||||
auth.init();
|
||||
}
|
||||
config.permissionsHandler.init();
|
||||
config.hwidHandler.init();
|
||||
}
|
||||
|
||||
public static final class Config {
|
||||
|
@ -460,6 +462,8 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
|
|||
for (AuthProviderPair provider : config.auth) {
|
||||
provider.init();
|
||||
}
|
||||
config.permissionsHandler.init();
|
||||
config.hwidHandler.init();
|
||||
if(config.protectHandler != null)
|
||||
{
|
||||
config.protectHandler.checkLaunchServerLicense();
|
||||
|
|
|
@ -22,6 +22,11 @@ public void close() {
|
|||
//SKIP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HWID> getHwid(String username) {
|
||||
return new ArrayList<>();
|
||||
|
|
|
@ -24,6 +24,7 @@ public static void registerHandlers() {
|
|||
registerHandler("accept", AcceptHWIDHandler.class);
|
||||
registerHandler("mysql", MysqlHWIDHandler.class);
|
||||
registerHandler("json", JsonHWIDHandler.class);
|
||||
registerHandler("memory", MemoryHWIDHandler.class);
|
||||
registredHandl = true;
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +41,8 @@ public void check(HWID hwid, String username) throws HWIDException {
|
|||
@Override
|
||||
public abstract void close() throws Exception;
|
||||
|
||||
public abstract void init();
|
||||
|
||||
public abstract List<HWID> getHwid(String username) throws HWIDException;
|
||||
|
||||
public abstract void unban(List<HWID> hwid) throws HWIDException;
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
package ru.gravit.launchserver.auth.hwid;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import ru.gravit.launcher.ClientPermissions;
|
||||
import ru.gravit.launcher.HWID;
|
||||
import ru.gravit.launcher.Launcher;
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.utils.helper.IOHelper;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class JsonFileHWIDHandler extends HWIDHandler {
|
||||
public class Entry
|
||||
{
|
||||
public HWID hwid;
|
||||
public String username;
|
||||
public boolean isBanned = false;
|
||||
|
||||
public Entry(HWID hwid) {
|
||||
this.hwid = hwid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Entry entry = (Entry) o;
|
||||
return Objects.equals(hwid, entry.hwid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(hwid);
|
||||
}
|
||||
}
|
||||
public String filename = "hwids.json";
|
||||
public transient LinkedList<Entry> list = new LinkedList<>();
|
||||
public String banMessage = "You banned";
|
||||
@Override
|
||||
public void ban(List<HWID> hwid) throws HWIDException {
|
||||
for(Entry e : list)
|
||||
{
|
||||
for(HWID banHWID : hwid)
|
||||
{
|
||||
if(e.hwid.equals(banHWID)) e.isBanned = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
Path path = Paths.get(filename);
|
||||
Type type = new TypeToken<LinkedList<Entry>>() {
|
||||
}.getType();
|
||||
try (Reader reader = IOHelper.newReader(path)) {
|
||||
list = Launcher.gson.fromJson(reader, type);
|
||||
} catch (IOException e) {
|
||||
LogHelper.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void check0(HWID hwid, String username) throws HWIDException {
|
||||
boolean isOne = false;
|
||||
for(Entry e : list)
|
||||
{
|
||||
if(e.hwid.equals(hwid))
|
||||
{
|
||||
isOne = true;
|
||||
if(e.isBanned) throw new HWIDException(banMessage);
|
||||
}
|
||||
}
|
||||
if(!isOne)
|
||||
{
|
||||
list.add(new Entry(hwid));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
Path path = Paths.get(filename);
|
||||
try(Writer writer = IOHelper.newWriter(path))
|
||||
{
|
||||
LaunchServer.gson.toJson(list, writer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HWID> getHwid(String username) throws HWIDException {
|
||||
LinkedList<HWID> hwids = new LinkedList<>();
|
||||
for(Entry e : list)
|
||||
{
|
||||
if(e.username.equals(username)) hwids.add(e.hwid);
|
||||
}
|
||||
return hwids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unban(List<HWID> hwid) throws HWIDException {
|
||||
for(Entry e : list)
|
||||
{
|
||||
for(HWID banHWID : hwid)
|
||||
{
|
||||
if(e.hwid.equals(banHWID)) e.isBanned = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -111,6 +111,11 @@ public void close() {
|
|||
// pass
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HWID> getHwid(String username) throws HWIDException {
|
||||
ArrayList<HWID> hwids = new ArrayList<>();
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
package ru.gravit.launchserver.auth.hwid;
|
||||
|
||||
import ru.gravit.launcher.HWID;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class MemoryHWIDHandler extends HWIDHandler {
|
||||
public class Entry
|
||||
{
|
||||
public HWID hwid;
|
||||
public String username;
|
||||
public boolean isBanned = false;
|
||||
|
||||
public Entry(HWID hwid) {
|
||||
this.hwid = hwid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Entry entry = (Entry) o;
|
||||
return Objects.equals(hwid, entry.hwid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(hwid);
|
||||
}
|
||||
}
|
||||
public transient LinkedList<Entry> list = new LinkedList<>();
|
||||
public String banMessage = "You banned";
|
||||
@Override
|
||||
public void ban(List<HWID> hwid) throws HWIDException {
|
||||
for(Entry e : list)
|
||||
{
|
||||
for(HWID banHWID : hwid)
|
||||
{
|
||||
if(e.hwid.equals(banHWID)) e.isBanned = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void check0(HWID hwid, String username) throws HWIDException {
|
||||
boolean isOne = false;
|
||||
for(Entry e : list)
|
||||
{
|
||||
if(e.hwid.equals(hwid))
|
||||
{
|
||||
isOne = true;
|
||||
if(e.isBanned) throw new HWIDException(banMessage);
|
||||
}
|
||||
}
|
||||
if(!isOne)
|
||||
{
|
||||
list.add(new Entry(hwid));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HWID> getHwid(String username) throws HWIDException {
|
||||
LinkedList<HWID> hwids = new LinkedList<>();
|
||||
for(Entry e : list)
|
||||
{
|
||||
if(e.username.equals(username)) hwids.add(e.hwid);
|
||||
}
|
||||
return hwids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unban(List<HWID> hwid) throws HWIDException {
|
||||
for(Entry e : list)
|
||||
{
|
||||
for(HWID banHWID : hwid)
|
||||
{
|
||||
if(e.hwid.equals(banHWID)) e.isBanned = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -250,4 +250,9 @@ public List<HWID> getHwid(String username) {
|
|||
public void close() {
|
||||
mySQLHolder.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,11 @@ public class ConfigPermissionsHandler extends PermissionsHandler {
|
|||
public boolean isAdmin = false;
|
||||
public boolean isServer = false;
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientPermissions getPermissions(String username) {
|
||||
ClientPermissions permissions = new ClientPermissions();
|
||||
|
|
|
@ -3,6 +3,11 @@
|
|||
import ru.gravit.launcher.ClientPermissions;
|
||||
|
||||
public class DefaultPermissionsHandler extends PermissionsHandler {
|
||||
@Override
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientPermissions getPermissions(String username) {
|
||||
return ClientPermissions.DEFAULT;
|
||||
|
|
|
@ -44,11 +44,7 @@ public static class Enity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ClientPermissions getPermissions(String username) {
|
||||
return map.getOrDefault(username, ClientPermissions.DEFAULT);
|
||||
}
|
||||
|
||||
public JsonFilePermissionsHandler() {
|
||||
public void init() {
|
||||
Type type = new TypeToken<Map<String, ClientPermissions>>() {
|
||||
}.getType();
|
||||
Path path = Paths.get(filename);
|
||||
|
@ -66,4 +62,13 @@ public JsonFilePermissionsHandler() {
|
|||
LogHelper.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientPermissions getPermissions(String username) {
|
||||
return map.getOrDefault(username, ClientPermissions.DEFAULT);
|
||||
}
|
||||
|
||||
public JsonFilePermissionsHandler() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,11 +45,7 @@ public static class Enity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ClientPermissions getPermissions(String username) {
|
||||
return new ClientPermissions(map.getOrDefault(username, defaultPerms));
|
||||
}
|
||||
|
||||
public JsonLongFilePermissionsHandler() {
|
||||
public void init() {
|
||||
Type type = new TypeToken<Map<String, ClientPermissions>>() {
|
||||
}.getType();
|
||||
Path path = Paths.get(filename);
|
||||
|
@ -67,4 +63,13 @@ public JsonLongFilePermissionsHandler() {
|
|||
LogHelper.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientPermissions getPermissions(String username) {
|
||||
return new ClientPermissions(map.getOrDefault(username, defaultPerms));
|
||||
}
|
||||
|
||||
public JsonLongFilePermissionsHandler() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,5 +38,7 @@ public static void registerHandlers() {
|
|||
}
|
||||
}
|
||||
|
||||
public abstract void init();
|
||||
|
||||
public abstract ClientPermissions getPermissions(String username);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
public class OshiHWID implements HWID {
|
||||
public static Gson gson = new Gson();
|
||||
@LauncherAPI
|
||||
|
@ -53,4 +56,32 @@ public int compare(HWID hwid) {
|
|||
public boolean isNull() {
|
||||
return getLevel() < 15;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
OshiHWID oshiHWID = (OshiHWID) o;
|
||||
return totalMemory == oshiHWID.totalMemory &&
|
||||
Objects.equals(serialNumber, oshiHWID.serialNumber) &&
|
||||
Objects.equals(HWDiskSerial, oshiHWID.HWDiskSerial) &&
|
||||
Objects.equals(processorID, oshiHWID.processorID) &&
|
||||
Objects.equals(macAddr, oshiHWID.macAddr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(totalMemory, serialNumber, HWDiskSerial, processorID, macAddr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringJoiner(", ", OshiHWID.class.getSimpleName() + "[", "]")
|
||||
.add("totalMemory=" + totalMemory)
|
||||
.add("serialNumber='" + serialNumber + "'")
|
||||
.add("HWDiskSerial='" + HWDiskSerial + "'")
|
||||
.add("processorID='" + processorID + "'")
|
||||
.add("macAddr='" + macAddr + "'")
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,6 +76,10 @@ public void registerCommand(String name, Command command) {
|
|||
VerifyHelper.putIfAbsent(commands, name.toLowerCase(), Objects.requireNonNull(command, "command"),
|
||||
String.format("Command has been already registered: '%s'", name.toLowerCase()));
|
||||
}
|
||||
public void unregisterCommand(String name)
|
||||
{
|
||||
commands.remove(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
Loading…
Reference in a new issue