From 23e732e8b29f1e4bb0d5d1c827cc5fc667fd2a58 Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Wed, 13 Feb 2019 12:43:17 +0300 Subject: [PATCH 1/4] =?UTF-8?q?[FIX]=20=D0=92=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20JFX=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81?= =?UTF-8?q?=D1=8B,=20=D0=BB=D0=B8=D1=88=D0=BD=D0=B8=D0=B5=20=D1=83=D0=B1?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D1=8B,=20=D1=82.=20=D0=BA.=20=D1=82=D0=B5?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D1=8C=20=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=20?= =?UTF-8?q?=D0=BB=D0=B5=D0=B3=D0=BA=D0=BE=20=D0=B4=D0=BE=D1=81=D1=82=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D1=82=D1=8C=20JFoenix=20=D0=B8=D0=BB=D0=B8=20?= =?UTF-8?q?=D0=B0=D0=BD=D0=B0=D0=BB=D0=BE=D0=B3=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../json/update/UpdateListResponse.java | 1 - Launcher/runtime/engine/api.js | 12 - .../guard/LauncherGuardInterface.java | 1 - .../launcher/guard/LauncherJavaGuard.java | 1 - .../launcher/guard/LauncherNoGuard.java | 1 - .../launcher/guard/LauncherWrapperGuard.java | 2 - .../launcher/gui/JSRuntimeProvider.java | 12 - .../gui/choosebox/CheckBitSetModelBase.java | 233 ------------------ .../launcher/gui/choosebox/CheckComboBox.java | 142 ----------- .../gui/choosebox/CheckComboBoxSkin.java | 172 ------------- .../launcher/gui/choosebox/CheckModel.java | 33 --- .../gui/choosebox/ControlsFXControl.java | 20 -- .../gui/choosebox/IndexedCheckModel.java | 31 --- .../indicator/ProgressCircleIndicator.java | 86 ------- .../gui/indicator/RingProgressIndicator.java | 95 ------- .../indicator/RingProgressIndicatorSkin.java | 124 ---------- .../request/update/LauncherRequest.java | 1 - .../request/update/ProfilesRequest.java | 1 - .../request/update/UpdateListRequest.java | 2 - .../request/UpdateListRequestEvent.java | 2 - 20 files changed, 972 deletions(-) delete mode 100644 Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckBitSetModelBase.java delete mode 100644 Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckComboBox.java delete mode 100644 Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckComboBoxSkin.java delete mode 100644 Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckModel.java delete mode 100644 Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/ControlsFXControl.java delete mode 100644 Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/IndexedCheckModel.java delete mode 100644 Launcher/src/main/java/ru/gravit/launcher/gui/indicator/ProgressCircleIndicator.java delete mode 100644 Launcher/src/main/java/ru/gravit/launcher/gui/indicator/RingProgressIndicator.java delete mode 100644 Launcher/src/main/java/ru/gravit/launcher/gui/indicator/RingProgressIndicatorSkin.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/UpdateListResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/UpdateListResponse.java index 7bffcf3a..743c71b4 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/UpdateListResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/UpdateListResponse.java @@ -12,7 +12,6 @@ import java.util.HashSet; import java.util.Map; -import java.util.Set; public class UpdateListResponse implements JsonResponseInterface { diff --git a/Launcher/runtime/engine/api.js b/Launcher/runtime/engine/api.js index d7cbcae5..a1bb7b7a 100644 --- a/Launcher/runtime/engine/api.js +++ b/Launcher/runtime/engine/api.js @@ -60,20 +60,8 @@ var LauncherSettings = LauncherSettingsClass.static; // Helper JS class API imports var JSApplication = null; -var CheckComboBox = null; -var CheckModel = null; -var IndexedCheckModel = null; -var CheckComboBoxSkin = null; -var RingProgressIndicator = null; -var RingProgressIndicatorSkin = null; if (typeof JSApplicationClass !== 'undefined') { JSApplication = JSApplicationClass.static; - CheckComboBox = CheckComboBoxClass.static; - CheckModel = CheckModelClass.static; - IndexedCheckModel = IndexedCheckModelClass.static; - CheckComboBoxSkin = CheckComboBoxSkinClass.static; - RingProgressIndicator = RingProgressIndicatorClass.static; - RingProgressIndicatorSkin = RingProgressIndicatorSkinClass.static; } // API wrapper diff --git a/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherGuardInterface.java b/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherGuardInterface.java index 7e793db0..3a994300 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherGuardInterface.java +++ b/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherGuardInterface.java @@ -3,7 +3,6 @@ import ru.gravit.launcher.client.ClientLauncherContext; import java.nio.file.Path; -import java.util.Collection; public interface LauncherGuardInterface { String getName(); diff --git a/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherJavaGuard.java b/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherJavaGuard.java index 0e2a0d18..9367f2f1 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherJavaGuard.java +++ b/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherJavaGuard.java @@ -7,7 +7,6 @@ import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Collection; import java.util.Collections; public class LauncherJavaGuard implements LauncherGuardInterface { diff --git a/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherNoGuard.java b/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherNoGuard.java index 7ff825f2..7a251b3b 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherNoGuard.java +++ b/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherNoGuard.java @@ -6,7 +6,6 @@ import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Collection; import java.util.Collections; public class LauncherNoGuard implements LauncherGuardInterface { diff --git a/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherWrapperGuard.java b/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherWrapperGuard.java index 5f55acfb..b5c59884 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherWrapperGuard.java +++ b/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherWrapperGuard.java @@ -9,8 +9,6 @@ import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Base64; -import java.util.Collection; import java.util.Collections; import java.util.Map; diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/JSRuntimeProvider.java b/Launcher/src/main/java/ru/gravit/launcher/gui/JSRuntimeProvider.java index fc99a3c0..a65c9330 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/JSRuntimeProvider.java +++ b/Launcher/src/main/java/ru/gravit/launcher/gui/JSRuntimeProvider.java @@ -5,12 +5,6 @@ import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherConfig; import ru.gravit.launcher.client.*; -import ru.gravit.launcher.gui.choosebox.CheckComboBox; -import ru.gravit.launcher.gui.choosebox.CheckComboBoxSkin; -import ru.gravit.launcher.gui.choosebox.CheckModel; -import ru.gravit.launcher.gui.choosebox.IndexedCheckModel; -import ru.gravit.launcher.gui.indicator.RingProgressIndicator; -import ru.gravit.launcher.gui.indicator.RingProgressIndicatorSkin; import ru.gravit.launcher.hasher.FileNameMatcher; import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hasher.HashedEntry; @@ -117,12 +111,6 @@ public static void addLauncherClassBindings(Map bindings) { try { Class.forName("javafx.application.Application"); bindings.put("JSApplicationClass", JSApplication.class); - bindings.put("RingProgressIndicatorClass", RingProgressIndicator.class); - bindings.put("RingProgressIndicatorSkinClass", RingProgressIndicatorSkin.class); - bindings.put("CheckComboBoxClass", CheckComboBox.class); - bindings.put("CheckModelClass", CheckModel.class); - bindings.put("IndexedCheckModelClass", IndexedCheckModel.class); - bindings.put("CheckComboBoxSkinClass", CheckComboBoxSkin.class); } catch (ClassNotFoundException ignored) { LogHelper.warning("JavaFX API isn't available"); } diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckBitSetModelBase.java b/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckBitSetModelBase.java deleted file mode 100644 index 58203cc6..00000000 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckBitSetModelBase.java +++ /dev/null @@ -1,233 +0,0 @@ -package ru.gravit.launcher.gui.choosebox; - -import com.sun.javafx.collections.MappingChange; -import com.sun.javafx.collections.NonIterableChange; -import com.sun.javafx.scene.control.ReadOnlyUnbackedObservableList; -import javafx.beans.property.BooleanProperty; -import javafx.beans.property.SimpleBooleanProperty; -import javafx.collections.ListChangeListener; -import javafx.collections.ObservableList; - -import java.util.BitSet; -import java.util.Map; - -abstract class CheckBitSetModelBase implements IndexedCheckModel { - private final Map itemBooleanMap; - - private final BitSet checkedIndices; - private final ReadOnlyUnbackedObservableList checkedIndicesList; - private final ReadOnlyUnbackedObservableList checkedItemsList; - - CheckBitSetModelBase(final Map itemBooleanMap) { - this.itemBooleanMap = itemBooleanMap; - - this.checkedIndices = new BitSet(); - - this.checkedIndicesList = new ReadOnlyUnbackedObservableList() { - @Override - public boolean contains(Object o) { - if (o instanceof Number) { - Number n = (Number) o; - int index = n.intValue(); - - return index >= 0 && index < checkedIndices.length() && checkedIndices.get(index); - } - - return false; - } - - @Override - public Integer get(int index) { - if (index < 0 || index >= getItemCount()) - return -1; - - for (int pos = 0, val = checkedIndices.nextSetBit(0); val >= 0 - || pos == index; pos++, val = checkedIndices.nextSetBit(val + 1)) - if (pos == index) - return val; - - return -1; - } - - @Override - public int size() { - return checkedIndices.cardinality(); - } - }; - - this.checkedItemsList = new ReadOnlyUnbackedObservableList() { - @Override - public T get(int i) { - int pos = checkedIndicesList.get(i); - if (pos < 0 || pos >= getItemCount()) - return null; - return getItem(pos); - } - - @Override - public int size() { - return checkedIndices.cardinality(); - } - }; - - final MappingChange.Map map = this::getItem; - - checkedIndicesList.addListener((ListChangeListener) c -> { - boolean hasRealChangeOccurred = false; - while (c.next() && !hasRealChangeOccurred) - hasRealChangeOccurred = c.wasAdded() || c.wasRemoved(); - - if (hasRealChangeOccurred) { - c.reset(); - checkedItemsList.callObservers(new MappingChange<>(c, map, checkedItemsList)); - } - c.reset(); - }); - getCheckedItems().addListener((ListChangeListener) c -> { - while (c.next()) { - if (c.wasAdded()) - for (T item : c.getAddedSubList()) { - BooleanProperty p = getItemBooleanProperty(item); - if (p != null) - p.set(true); - } - - if (c.wasRemoved()) - for (T item : c.getRemoved()) { - BooleanProperty p = getItemBooleanProperty(item); - if (p != null) - p.set(false); - } - } - }); - } - - @Override - public void check(int index) { - if (index < 0 || index >= getItemCount()) - return; - checkedIndices.set(index); - final int changeIndex = checkedIndicesList.indexOf(index); - checkedIndicesList.callObservers( - new NonIterableChange.SimpleAddChange<>(changeIndex, changeIndex + 1, checkedIndicesList)); - } - - @Override - public void check(T item) { - int index = getItemIndex(item); - check(index); - } - - @Override - public void checkAll() { - for (int i = 0; i < getItemCount(); i++) - check(i); - } - - @Override - public void checkIndices(int... indices) { - for (int indice : indices) - check(indice); - } - - @Override - public void clearCheck(int index) { - if (index < 0 || index >= getItemCount()) - return; - checkedIndices.clear(index); - - final int changeIndex = checkedIndicesList.indexOf(index); - checkedIndicesList.callObservers( - new NonIterableChange.SimpleRemovedChange<>(changeIndex, changeIndex, index, checkedIndicesList)); - } - - @Override - public void clearCheck(T item) { - int index = getItemIndex(item); - clearCheck(index); - } - - @Override - public void clearChecks() { - for (int index = 0; index < checkedIndices.length(); index++) - clearCheck(index); - } - - @Override - public ObservableList getCheckedIndices() { - return checkedIndicesList; - } - - @Override - public ObservableList getCheckedItems() { - return checkedItemsList; - } - - @Override - public abstract T getItem(int index); - - BooleanProperty getItemBooleanProperty(T item) { - return itemBooleanMap.get(item); - } - - @Override - public abstract int getItemCount(); - - @Override - public abstract int getItemIndex(T item); - - @Override - public boolean isChecked(int index) { - return checkedIndices.get(index); - } - - @Override - public boolean isChecked(T item) { - int index = getItemIndex(item); - return isChecked(index); - } - - @Override - public boolean isEmpty() { - return checkedIndices.isEmpty(); - } - - @Override - public void toggleCheckState(int index) { - if (isChecked(index)) - clearCheck(index); - else - check(index); - } - - @Override - public void toggleCheckState(T item) { - int index = getItemIndex(item); - toggleCheckState(index); - } - - protected void updateMap() { - itemBooleanMap.clear(); - for (int i = 0; i < getItemCount(); i++) { - final int index = i; - final T item = getItem(index); - - final BooleanProperty booleanProperty = new SimpleBooleanProperty(item, "selected", false); //$NON-NLS-1$ - itemBooleanMap.put(item, booleanProperty); - - booleanProperty.addListener(o -> { - if (booleanProperty.get()) { - checkedIndices.set(index); - final int changeIndex1 = checkedIndicesList.indexOf(index); - checkedIndicesList.callObservers(new NonIterableChange.SimpleAddChange<>(changeIndex1, - changeIndex1 + 1, checkedIndicesList)); - } else { - final int changeIndex2 = checkedIndicesList.indexOf(index); - checkedIndices.clear(index); - checkedIndicesList.callObservers(new NonIterableChange.SimpleRemovedChange<>(changeIndex2, - changeIndex2, index, checkedIndicesList)); - } - }); - } - } -} \ No newline at end of file diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckComboBox.java b/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckComboBox.java deleted file mode 100644 index 262d1fde..00000000 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckComboBox.java +++ /dev/null @@ -1,142 +0,0 @@ -package ru.gravit.launcher.gui.choosebox; - -import javafx.beans.property.*; -import javafx.collections.FXCollections; -import javafx.collections.ListChangeListener; -import javafx.collections.ObservableList; -import javafx.scene.control.Skin; -import javafx.util.StringConverter; -import ru.gravit.launcher.LauncherAPI; - -import java.util.HashMap; -import java.util.Map; - -public class CheckComboBox extends ControlsFXControl { - private static class CheckComboBoxBitSetCheckModel extends CheckBitSetModelBase { - private final ObservableList items; - - CheckComboBoxBitSetCheckModel(final ObservableList items, final Map itemBooleanMap) { - super(itemBooleanMap); - - this.items = items; - this.items.addListener((ListChangeListener) c -> updateMap()); - - updateMap(); - } - - @Override - public T getItem(int index) { - return items.get(index); - } - - @Override - public int getItemCount() { - return items.size(); - } - - @Override - public int getItemIndex(T item) { - return items.indexOf(item); - } - } - - private final ObservableList items; - private final Map itemBooleanMap; - private CheckComboBoxSkin checkComboBoxSkin; - private ObjectProperty> checkModel = new SimpleObjectProperty<>(this, "checkModel"); - private ObjectProperty> converter = new SimpleObjectProperty<>(this, - "converter"); - private StringProperty title = new SimpleStringProperty(null); - - public CheckComboBox() { - this(null); - } - - public CheckComboBox(final ObservableList items) { - final int initialSize = items == null ? 32 : items.size(); - - this.itemBooleanMap = new HashMap<>(initialSize); - this.items = items == null ? FXCollections.observableArrayList() : items; - setCheckModel(new CheckComboBoxBitSetCheckModel<>(this.items, itemBooleanMap)); - } - - @LauncherAPI - public final ObjectProperty> checkModelProperty() { - return checkModel; - } - - @LauncherAPI - public final ObjectProperty> converterProperty() { - return converter; - } - - @Override - protected Skin createDefaultSkin() { - checkComboBoxSkin = new CheckComboBoxSkin<>(this); - return checkComboBoxSkin; - } - - @LauncherAPI - public final IndexedCheckModel getCheckModel() { - return checkModel == null ? null : checkModel.get(); - } - - @LauncherAPI - public final StringConverter getConverter() { - return converterProperty().get(); - } - - @LauncherAPI - public BooleanProperty getItemBooleanProperty(int index) { - if (index < 0 || index >= items.size()) - return null; - return getItemBooleanProperty(getItems().get(index)); - } - - @LauncherAPI - public BooleanProperty getItemBooleanProperty(T item) { - return itemBooleanMap.get(item); - } - - @LauncherAPI - public ObservableList getItems() { - return items; - } - - @LauncherAPI - public final String getTitle() { - return title.getValue(); - } - - @LauncherAPI - public void hide() { - if (checkComboBoxSkin != null) - checkComboBoxSkin.hide(); - } - - @LauncherAPI - public final void setCheckModel(IndexedCheckModel value) { - checkModelProperty().set(value); - } - - @LauncherAPI - public final void setConverter(StringConverter value) { - converterProperty().set(value); - } - - @LauncherAPI - public final void setTitle(String value) { - title.setValue(value); - } - - @LauncherAPI - public void show() { - if (checkComboBoxSkin != null) - checkComboBoxSkin.show(); - } - - @LauncherAPI - public final StringProperty titleProperty() { - return title; - } -} diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckComboBoxSkin.java b/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckComboBoxSkin.java deleted file mode 100644 index 3a826a39..00000000 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckComboBoxSkin.java +++ /dev/null @@ -1,172 +0,0 @@ -package ru.gravit.launcher.gui.choosebox; - -import com.sun.javafx.scene.control.ReadOnlyUnbackedObservableList; -import com.sun.javafx.scene.control.behavior.BehaviorBase; -import com.sun.javafx.scene.control.skin.BehaviorSkinBase; -import com.sun.javafx.scene.control.skin.ComboBoxListViewSkin; -import javafx.collections.ListChangeListener; -import javafx.collections.ObservableList; -import javafx.scene.control.ComboBox; -import javafx.scene.control.ListCell; -import javafx.scene.control.ListView; -import javafx.scene.control.Skin; -import javafx.scene.control.cell.CheckBoxListCell; -import javafx.scene.input.KeyCode; -import ru.gravit.launcher.LauncherAPI; - -import java.util.Collections; - -public class CheckComboBoxSkin extends BehaviorSkinBase, BehaviorBase>> { - - private final ComboBox comboBox; - private final ListCell buttonCell; - - private final CheckComboBox control; - private final ReadOnlyUnbackedObservableList selectedItems; - - @SuppressWarnings("unchecked") - public CheckComboBoxSkin(final CheckComboBox control) { - super(control, new BehaviorBase<>(control, Collections.emptyList())); - - this.control = control; - ObservableList items = control.getItems(); - - ReadOnlyUnbackedObservableList selectedIndices = (ReadOnlyUnbackedObservableList) control.getCheckModel().getCheckedIndices(); - selectedItems = (ReadOnlyUnbackedObservableList) control.getCheckModel().getCheckedItems(); - - comboBox = new ComboBox(items) { - @Override - protected javafx.scene.control.Skin createDefaultSkin() { - return createComboBoxListViewSkin(this); - } - }; - comboBox.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE); - - comboBox.setCellFactory(listView -> { - CheckBoxListCell result = new CheckBoxListCell<>(control::getItemBooleanProperty); - result.focusedProperty().addListener((o, ov, nv) -> { - if (nv) - result.getParent().requestFocus(); - }); - result.setOnMouseClicked(e -> { - T item = result.getItem(); - if (control.getCheckModel().isChecked(item)) - control.getCheckModel().clearCheck(item); - else - control.getCheckModel().check(item); - }); - result.converterProperty().bind(control.converterProperty()); - return result; - }); - - buttonCell = new ListCell() { - @Override - protected void updateItem(T item, boolean empty) { - setText(getTextString()); - } - }; - comboBox.setButtonCell(buttonCell); - comboBox.setValue((T) getTextString()); - - selectedIndices.addListener((ListChangeListener) c -> buttonCell.updateIndex(0)); - - getChildren().add(comboBox); - } - - private String buildString() { - final StringBuilder sb = new StringBuilder(); - for (int i = 0, max = selectedItems.size(); i < max; i++) { - T item = selectedItems.get(i); - if (control.getConverter() == null) - sb.append(item); - else - sb.append(control.getConverter().toString(item)); - if (i < max - 1) - sb.append(", "); //$NON-NLS-1$ - } - return sb.toString(); - } - - @LauncherAPI - @Override - protected double computeMaxHeight(double width, double topInset, double rightInset, double bottomInset, - double leftInset) { - return getSkinnable().prefHeight(width); - } - - @LauncherAPI - @Override - protected double computeMaxWidth(double height, double topInset, double rightInset, double bottomInset, - double leftInset) { - return getSkinnable().prefWidth(height); - } - - @LauncherAPI - @Override - protected double computeMinHeight(double width, double topInset, double rightInset, double bottomInset, - double leftInset) { - return comboBox.minHeight(width); - } - - @LauncherAPI - @Override - protected double computeMinWidth(double height, double topInset, double rightInset, double bottomInset, - double leftInset) { - return comboBox.minWidth(height); - } - - @LauncherAPI - @Override - protected double computePrefHeight(double width, double topInset, double rightInset, double bottomInset, - double leftInset) { - return comboBox.prefHeight(width); - } - - @LauncherAPI - @Override - protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, - double leftInset) { - return comboBox.prefWidth(height); - } - - private Skin createComboBoxListViewSkin(ComboBox comboBox) { - final ComboBoxListViewSkin comboBoxListViewSkin = new ComboBoxListViewSkin(comboBox) { - @Override - protected boolean isHideOnClickEnabled() { - return false; - } - }; - @SuppressWarnings("unchecked") final ListView listView = (ListView) comboBoxListViewSkin.getPopupContent(); - listView.setOnKeyPressed(e -> { - if (e.getCode() == KeyCode.SPACE) { - T item = listView.getSelectionModel().getSelectedItem(); - if (item != null) { - final IndexedCheckModel checkModel = control.getCheckModel(); - if (checkModel != null) - checkModel.toggleCheckState(item); - } - } else if (e.getCode() == KeyCode.ESCAPE) - hide(); - }); - return comboBoxListViewSkin; - } - - @LauncherAPI - protected String getTextString() { - - if (control.getTitle() != null) - return control.getTitle(); - return buildString(); - - } - - @LauncherAPI - public void hide() { - comboBox.hide(); - } - - @LauncherAPI - public void show() { - comboBox.show(); - } -} diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckModel.java b/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckModel.java deleted file mode 100644 index 33a33e45..00000000 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckModel.java +++ /dev/null @@ -1,33 +0,0 @@ -package ru.gravit.launcher.gui.choosebox; - -import javafx.collections.ObservableList; -import ru.gravit.launcher.LauncherAPI; - -public interface CheckModel { - @LauncherAPI - void check(T item); - - @LauncherAPI - void checkAll(); - - @LauncherAPI - void clearCheck(T item); - - @LauncherAPI - void clearChecks(); - - @LauncherAPI - ObservableList getCheckedItems(); - - @LauncherAPI - int getItemCount(); - - @LauncherAPI - boolean isChecked(T item); - - @LauncherAPI - boolean isEmpty(); - - @LauncherAPI - void toggleCheckState(T item); -} diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/ControlsFXControl.java b/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/ControlsFXControl.java deleted file mode 100644 index 82353bba..00000000 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/ControlsFXControl.java +++ /dev/null @@ -1,20 +0,0 @@ -package ru.gravit.launcher.gui.choosebox; - -import javafx.scene.control.Control; - -abstract class ControlsFXControl extends Control { - - private String stylesheet; - - public ControlsFXControl() { - - } - - protected final String getUserAgentStylesheet(Class clazz, String fileName) { - - if (stylesheet == null) - stylesheet = clazz.getResource(fileName).toExternalForm(); - - return stylesheet; - } -} diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/IndexedCheckModel.java b/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/IndexedCheckModel.java deleted file mode 100644 index 5d661000..00000000 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/IndexedCheckModel.java +++ /dev/null @@ -1,31 +0,0 @@ -package ru.gravit.launcher.gui.choosebox; - -import javafx.collections.ObservableList; -import ru.gravit.launcher.LauncherAPI; - -public interface IndexedCheckModel extends CheckModel { - @LauncherAPI - void check(int index); - - @LauncherAPI - void checkIndices(int... indices); - - @LauncherAPI - void clearCheck(int index); - - @LauncherAPI - ObservableList getCheckedIndices(); - - @LauncherAPI - T getItem(int index); - - @LauncherAPI - int getItemIndex(T item); - - @LauncherAPI - boolean isChecked(int index); - - @LauncherAPI - void toggleCheckState(int index); - -} \ No newline at end of file diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/indicator/ProgressCircleIndicator.java b/Launcher/src/main/java/ru/gravit/launcher/gui/indicator/ProgressCircleIndicator.java deleted file mode 100644 index bf7d4a2e..00000000 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/indicator/ProgressCircleIndicator.java +++ /dev/null @@ -1,86 +0,0 @@ -package ru.gravit.launcher.gui.indicator; - -import com.sun.javafx.css.converters.SizeConverter; -import javafx.beans.property.DoubleProperty; -import javafx.css.CssMetaData; -import javafx.css.Styleable; -import javafx.css.StyleableDoubleProperty; -import javafx.css.StyleableProperty; -import javafx.scene.control.Control; -import javafx.scene.control.ProgressIndicator; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -abstract class ProgressCircleIndicator extends ProgressIndicator { - public ProgressCircleIndicator() { - this.getStylesheets().add(ProgressCircleIndicator.class.getResource("/runtime/launcher/overlay/update/circleprogress.css").toExternalForm()); - } - - public final void setInnerCircleRadius(int value) { - innerCircleRadiusProperty().set(value); - } - - public final DoubleProperty innerCircleRadiusProperty() { - return innerCircleRadius; - } - - public final double getInnerCircleRadius() { - return innerCircleRadiusProperty().get(); - } - - /** - * radius of the inner circle - */ - private DoubleProperty innerCircleRadius = new StyleableDoubleProperty(60) { - @Override - public Object getBean() { - return ProgressCircleIndicator.this; - } - - @Override - public String getName() { - return "innerCircleRadius"; - } - - @Override - public CssMetaData getCssMetaData() { - return StyleableProperties.INNER_CIRCLE_RADIUS; - } - }; - - private static class StyleableProperties { - private static final CssMetaData INNER_CIRCLE_RADIUS = new CssMetaData( - "-fx-inner-radius", SizeConverter.getInstance(), 60) { - - @Override - public boolean isSettable(ProgressCircleIndicator n) { - return n.innerCircleRadiusProperty() == null || !n.innerCircleRadiusProperty().isBound(); - } - - @SuppressWarnings("unchecked") - @Override - public StyleableProperty getStyleableProperty(ProgressCircleIndicator n) { - return (StyleableProperty) n.innerCircleRadiusProperty(); - } - }; - - public static final List> STYLEABLES; - - static { - final List> styleables = new ArrayList<>(Control.getClassCssMetaData()); - styleables.add(INNER_CIRCLE_RADIUS); - STYLEABLES = Collections.unmodifiableList(styleables); - } - } - - public static List> getClassCssMetaData() { - return StyleableProperties.STYLEABLES; - } - - @Override - public List> getControlCssMetaData() { - return StyleableProperties.STYLEABLES; - } -} diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/indicator/RingProgressIndicator.java b/Launcher/src/main/java/ru/gravit/launcher/gui/indicator/RingProgressIndicator.java deleted file mode 100644 index 11c04589..00000000 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/indicator/RingProgressIndicator.java +++ /dev/null @@ -1,95 +0,0 @@ -package ru.gravit.launcher.gui.indicator; - -import com.sun.javafx.css.converters.SizeConverter; -import javafx.beans.property.DoubleProperty; -import javafx.css.CssMetaData; -import javafx.css.Styleable; -import javafx.css.StyleableDoubleProperty; -import javafx.css.StyleableProperty; -import javafx.scene.control.Control; -import javafx.scene.control.Skin; -import ru.gravit.launcher.LauncherAPI; -import ru.gravit.utils.helper.LogHelper; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class RingProgressIndicator extends ProgressCircleIndicator { - public RingProgressIndicator() { - LogHelper.debug("Setting JVM dir name"); - this.getStylesheets().add(RingProgressIndicator.class.getResource("/runtime/launcher/overlay/update/ringprogress.css").toExternalForm()); - this.getStyleClass().add("ringindicator"); - } - - @Override - protected Skin createDefaultSkin() { - return new RingProgressIndicatorSkin(this); - } - - @LauncherAPI - public final void setRingWidth(int value) { - ringWidthProperty().set(value); - } - - @LauncherAPI - public final DoubleProperty ringWidthProperty() { - return ringWidth; - } - - @LauncherAPI - public final double getRingWidth() { - return ringWidthProperty().get(); - } - - /** - * thickness of the ring indicator. - */ - private DoubleProperty ringWidth = new StyleableDoubleProperty(22) { - @Override - public Object getBean() { - return RingProgressIndicator.this; - } - - @Override - public String getName() { - return "ringWidth"; - } - - @Override - public CssMetaData getCssMetaData() { - return StyleableProperties.RING_WIDTH; - } - }; - - private static class StyleableProperties { - private static final CssMetaData RING_WIDTH = new CssMetaData( - "-fx-ring-width", SizeConverter.getInstance(), 22) { - - @Override - public boolean isSettable(RingProgressIndicator n) { - return n.ringWidth == null || !n.ringWidth.isBound(); - } - - @SuppressWarnings("unchecked") - @Override - public StyleableProperty getStyleableProperty(RingProgressIndicator n) { - return (StyleableProperty) n.ringWidth; - } - }; - - public static final List> STYLEABLES; - - static { - final List> styleables = new ArrayList<>(Control.getClassCssMetaData()); - styleables.addAll(getClassCssMetaData()); - styleables.add(RING_WIDTH); - STYLEABLES = Collections.unmodifiableList(styleables); - } - } - - @Override - public List> getControlCssMetaData() { - return StyleableProperties.STYLEABLES; - } -} diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/indicator/RingProgressIndicatorSkin.java b/Launcher/src/main/java/ru/gravit/launcher/gui/indicator/RingProgressIndicatorSkin.java deleted file mode 100644 index 3367767e..00000000 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/indicator/RingProgressIndicatorSkin.java +++ /dev/null @@ -1,124 +0,0 @@ -package ru.gravit.launcher.gui.indicator; - -import javafx.animation.Animation; -import javafx.animation.Interpolator; -import javafx.animation.RotateTransition; -import javafx.scene.Node; -import javafx.scene.control.Label; -import javafx.scene.control.Skin; -import javafx.scene.layout.Region; -import javafx.scene.layout.StackPane; -import javafx.scene.shape.Arc; -import javafx.scene.shape.Circle; -import javafx.util.Duration; - -/** - * Skin of the ring progress indicator where an arc grows and by the progress value up to 100% where the arc becomes a ring. - * - * @author Andrea Vacondio - */ -public class RingProgressIndicatorSkin implements Skin { - - private final RingProgressIndicator indicator; - private final Label percentLabel = new Label(); - private final Circle innerCircle = new Circle(); - private final Circle outerCircle = new Circle(); - private final StackPane container = new StackPane(); - private final Arc fillerArc = new Arc(); - private final RotateTransition transition = new RotateTransition(Duration.millis(2000), fillerArc); - - public RingProgressIndicatorSkin(final RingProgressIndicator indicator) { - this.indicator = indicator; - initContainer(indicator); - initFillerArc(); - container.widthProperty().addListener((o, oldVal, newVal) -> fillerArc.setCenterX(newVal.intValue() / 2)); - container.heightProperty().addListener((o, oldVal, newVal) -> fillerArc.setCenterY(newVal.intValue() / 2)); - innerCircle.getStyleClass().add("ringindicator-inner-circle"); - outerCircle.getStyleClass().add("ringindicator-outer-circle-secondary"); - updateRadii(); - - this.indicator.indeterminateProperty().addListener((o, oldVal, newVal) -> initIndeterminate(newVal)); - this.indicator.progressProperty().addListener((o, oldVal, newVal) -> { - if (newVal.intValue() >= 0) { - fillerArc.setLength(newVal.doubleValue() * -360); - } - }); - this.indicator.ringWidthProperty().addListener((o, oldVal, newVal) -> updateRadii()); - innerCircle.strokeWidthProperty().addListener((e) -> updateRadii()); - innerCircle.radiusProperty().addListener((e) -> updateRadii()); - initTransition(); - initIndeterminate(indicator.isIndeterminate()); - indicator.visibleProperty().addListener((o, oldVal, newVal) -> { - if (newVal && this.indicator.isIndeterminate()) { - transition.play(); - } else { - transition.pause(); - } - }); - container.getChildren().addAll(fillerArc, outerCircle, innerCircle, percentLabel); - } - - private void initTransition() { - transition.setAutoReverse(false); - transition.setCycleCount(Animation.INDEFINITE); - transition.setDelay(Duration.ZERO); - transition.setInterpolator(Interpolator.LINEAR); - transition.setByAngle(360); - } - - private void initFillerArc() { - fillerArc.setManaged(false); - fillerArc.getStyleClass().add("ringindicator-filler"); - fillerArc.setStartAngle(90); - fillerArc.setLength(indicator.getProgress() * -360); - } - - private void initContainer(final RingProgressIndicator indicator) { - container.getStylesheets().addAll(indicator.getStylesheets()); - container.getStyleClass().addAll("circleindicator-container"); - container.setMaxHeight(Region.USE_PREF_SIZE); - container.setMaxWidth(Region.USE_PREF_SIZE); - } - - private void updateRadii() { - double ringWidth = indicator.getRingWidth(); - double innerCircleHalfStrokeWidth = innerCircle.getStrokeWidth() / 2; - double innerCircleRadius = indicator.getInnerCircleRadius(); - outerCircle.setRadius(innerCircleRadius + innerCircleHalfStrokeWidth + ringWidth); - fillerArc.setRadiusY(innerCircleRadius + innerCircleHalfStrokeWidth - 1 + (ringWidth / 2)); - fillerArc.setRadiusX(innerCircleRadius + innerCircleHalfStrokeWidth - 1 + (ringWidth / 2)); - fillerArc.setStrokeWidth(ringWidth); - innerCircle.setRadius(innerCircleRadius); - } - - private void initIndeterminate(boolean newVal) { - percentLabel.setVisible(!newVal); - if (newVal) { - fillerArc.setLength(360); - fillerArc.getStyleClass().add("indeterminate"); - if (indicator.isVisible()) { - transition.play(); - } - } else { - fillerArc.getStyleClass().remove("indeterminate"); - fillerArc.setRotate(0); - transition.stop(); - } - } - - @Override - public RingProgressIndicator getSkinnable() { - return indicator; - } - - @Override - public Node getNode() { - return container; - } - - @Override - public void dispose() { - transition.stop(); - } - -} diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LauncherRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LauncherRequest.java index b6f712c7..11777930 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LauncherRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LauncherRequest.java @@ -17,7 +17,6 @@ import ru.gravit.utils.helper.SecurityHelper; import java.io.IOException; -import java.io.InputStream; import java.io.OutputStream; import java.net.URL; import java.net.URLConnection; diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/ProfilesRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/ProfilesRequest.java index 4f58cbe2..c13eb7ec 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/ProfilesRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/ProfilesRequest.java @@ -13,7 +13,6 @@ import ru.gravit.launcher.serialize.HOutput; import java.util.ArrayList; -import java.util.Collections; import java.util.List; public final class ProfilesRequest extends Request implements RequestInterface { diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateListRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateListRequest.java index 342c6ed0..dfe9c1c1 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateListRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateListRequest.java @@ -12,9 +12,7 @@ import ru.gravit.utils.helper.IOHelper; import java.io.IOException; -import java.util.Collections; import java.util.HashSet; -import java.util.Set; public final class UpdateListRequest extends Request implements RequestInterface { @LauncherAPI diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/request/UpdateListRequestEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/request/UpdateListRequestEvent.java index fc2d5f67..6319a855 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/events/request/UpdateListRequestEvent.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/UpdateListRequestEvent.java @@ -1,11 +1,9 @@ package ru.gravit.launcher.events.request; import ru.gravit.launcher.LauncherNetworkAPI; -import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.request.ResultInterface; import ru.gravit.utils.event.EventInterface; -import java.util.ArrayList; import java.util.HashSet; import java.util.UUID; From feca582da028289dad77d367dbda8aaacd162773 Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Thu, 14 Feb 2019 13:28:02 +0300 Subject: [PATCH 2/4] =?UTF-8?q?[FIX]=20BinaryFileAuthHandler=20=D1=82?= =?UTF-8?q?=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=B5=D1=82.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/handler/BinaryFileAuthHandler.java | 228 ++++++++++++++++- .../auth/handler/FileAuthHandler.java | 233 ------------------ 2 files changed, 224 insertions(+), 237 deletions(-) delete mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/FileAuthHandler.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/BinaryFileAuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/BinaryFileAuthHandler.java index 820bfd0c..a68b71ea 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/BinaryFileAuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/BinaryFileAuthHandler.java @@ -1,19 +1,240 @@ package ru.gravit.launchserver.auth.handler; +import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; +import ru.gravit.launcher.serialize.stream.StreamObject; +import ru.gravit.launchserver.auth.provider.AuthProviderResult; +import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.LogHelper; +import ru.gravit.utils.helper.SecurityHelper; +import ru.gravit.utils.helper.VerifyHelper; +import java.io.File; import java.io.IOException; +import java.security.SecureRandom; +import java.util.Collections; +import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.concurrent.locks.ReentrantReadWriteLock; -public final class BinaryFileAuthHandler extends FileAuthHandler { +public final class BinaryFileAuthHandler extends AuthHandler { + public static final class Entry extends StreamObject { + private String username; + private String accessToken; + private String serverID; + + + public Entry(HInput input) throws IOException { + username = VerifyHelper.verifyUsername(input.readString(64)); + if (input.readBoolean()) { + accessToken = SecurityHelper.verifyToken(input.readASCII(-SecurityHelper.TOKEN_STRING_LENGTH)); + if (input.readBoolean()) + serverID = VerifyHelper.verifyServerID(input.readASCII(41)); + } + } + + + public Entry(String username) { + this.username = VerifyHelper.verifyUsername(username); + } + + + public Entry(String username, String accessToken, String serverID) { + this(username); + if (accessToken == null && serverID != null) + throw new IllegalArgumentException("Can't set access token while server ID is null"); + + // Set and verify access token + this.accessToken = accessToken == null ? null : SecurityHelper.verifyToken(accessToken); + this.serverID = serverID == null ? null : VerifyHelper.verifyServerID(serverID); + } + + private void auth(String username, String accessToken) { + this.username = username; // Update username case + this.accessToken = accessToken; + serverID = null; + } + + private boolean checkServer(String username, String serverID) { + return username.equals(this.username) && serverID.equals(this.serverID); + } + + + public String getAccessToken() { + return accessToken; + } + + + public String getServerID() { + return serverID; + } + + + public String getUsername() { + return username; + } + + private boolean joinServer(String username, String accessToken, String serverID) { + if (!username.equals(this.username) || !accessToken.equals(this.accessToken)) + return false; // Username or access token mismatch + + // Update server ID + this.serverID = serverID; + return true; + } + + @Override + public void write(HOutput output) throws IOException { + output.writeString(username, 64); + output.writeBoolean(accessToken != null); + if (accessToken != null) { + output.writeASCII(accessToken, -SecurityHelper.TOKEN_STRING_LENGTH); + output.writeBoolean(serverID != null); + if (serverID != null) + output.writeASCII(serverID, 41); + } + } + } + + + public String file; + + public String fileTmp; + + + public boolean offlineUUIDs; + // Instance + private final SecureRandom random = SecurityHelper.newRandom(); + + private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); + // Storage + private final Map entryMap = new HashMap<>(256); + + private final Map usernamesMap = new HashMap<>(256); + + + protected final void addAuth(UUID uuid, Entry entry) { + lock.writeLock().lock(); + try { + Entry previous = entryMap.put(uuid, entry); + if (previous != null) + usernamesMap.remove(CommonHelper.low(previous.username)); + usernamesMap.put(CommonHelper.low(entry.username), uuid); + } finally { + lock.writeLock().unlock(); + } + } @Override + public final UUID auth(AuthProviderResult authResult) { + lock.writeLock().lock(); + try { + UUID uuid = usernameToUUID(authResult.username); + Entry entry = entryMap.get(uuid); + + // Not registered? Fix it! + if (entry == null) { + entry = new Entry(authResult.username); + + // Generate UUID + uuid = genUUIDFor(authResult.username); + entryMap.put(uuid, entry); + usernamesMap.put(CommonHelper.low(authResult.username), uuid); + } + + // Authenticate + entry.auth(authResult.username, authResult.accessToken); + return uuid; + } finally { + lock.writeLock().unlock(); + } + } + + @Override + public final UUID checkServer(String username, String serverID) { + lock.readLock().lock(); + try { + UUID uuid = usernameToUUID(username); + Entry entry = entryMap.get(uuid); + + // Check server (if has such account of course) + return entry != null && entry.checkServer(username, serverID) ? uuid : null; + } finally { + lock.readLock().unlock(); + } + } + + @Override + public final void close() throws IOException { + lock.readLock().lock(); + try { + LogHelper.info("Writing auth handler file (%d entries)", entryMap.size()); + writeAuthFileTmp(); + IOHelper.move(new File(fileTmp).toPath(), new File(file).toPath()); + } finally { + lock.readLock().unlock(); + } + } + + + protected final Set> entrySet() { + return Collections.unmodifiableMap(entryMap).entrySet(); + } + + private UUID genUUIDFor(String username) { + if (offlineUUIDs) { + UUID md5UUID = PlayerProfile.offlineUUID(username); + if (!entryMap.containsKey(md5UUID)) + return md5UUID; + LogHelper.warning("Offline UUID collision, using random: '%s'", username); + } + + // Pick random UUID + UUID uuid; + do + uuid = new UUID(random.nextLong(), random.nextLong()); + while (entryMap.containsKey(uuid)); + return uuid; + } + + @Override + public final boolean joinServer(String username, String accessToken, String serverID) { + lock.writeLock().lock(); + try { + Entry entry = entryMap.get(usernameToUUID(username)); + return entry != null && entry.joinServer(username, accessToken, serverID); + } finally { + lock.writeLock().unlock(); + } + } + + @Override + public final UUID usernameToUUID(String username) { + lock.readLock().lock(); + try { + return usernamesMap.get(CommonHelper.low(username)); + } finally { + lock.readLock().unlock(); + } + } + + @Override + public final String uuidToUsername(UUID uuid) { + lock.readLock().lock(); + try { + Entry entry = entryMap.get(uuid); + return entry == null ? null : entry.username; + } finally { + lock.readLock().unlock(); + } + } + protected void readAuthFile() throws IOException { - try (HInput input = new HInput(IOHelper.newInput(file))) { + try (HInput input = new HInput(IOHelper.newInput(new File(file).toPath()))) { int count = input.readLength(0); for (int i = 0; i < count; i++) { UUID uuid = input.readUUID(); @@ -23,10 +244,9 @@ protected void readAuthFile() throws IOException { } } - @Override protected void writeAuthFileTmp() throws IOException { Set> entrySet = entrySet(); - try (HOutput output = new HOutput(IOHelper.newOutput(fileTmp))) { + try (HOutput output = new HOutput(IOHelper.newOutput(new File(fileTmp).toPath()))) { output.writeLength(entrySet.size(), 0); for (Map.Entry entry : entrySet) { output.writeUUID(entry.getKey()); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/FileAuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/FileAuthHandler.java deleted file mode 100644 index 90dd12bf..00000000 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/FileAuthHandler.java +++ /dev/null @@ -1,233 +0,0 @@ -package ru.gravit.launchserver.auth.handler; - -import ru.gravit.launcher.profiles.PlayerProfile; -import ru.gravit.launcher.serialize.HInput; -import ru.gravit.launcher.serialize.HOutput; -import ru.gravit.launcher.serialize.stream.StreamObject; -import ru.gravit.launchserver.auth.provider.AuthProviderResult; -import ru.gravit.utils.helper.*; - -import java.io.IOException; -import java.nio.file.Path; -import java.security.SecureRandom; -import java.util.*; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -public abstract class FileAuthHandler extends AuthHandler { - public static final class Entry extends StreamObject { - private String username; - private String accessToken; - private String serverID; - - - public Entry(HInput input) throws IOException { - username = VerifyHelper.verifyUsername(input.readString(64)); - if (input.readBoolean()) { - accessToken = SecurityHelper.verifyToken(input.readASCII(-SecurityHelper.TOKEN_STRING_LENGTH)); - if (input.readBoolean()) - serverID = VerifyHelper.verifyServerID(input.readASCII(41)); - } - } - - - public Entry(String username) { - this.username = VerifyHelper.verifyUsername(username); - } - - - public Entry(String username, String accessToken, String serverID) { - this(username); - if (accessToken == null && serverID != null) - throw new IllegalArgumentException("Can't set access token while server ID is null"); - - // Set and verify access token - this.accessToken = accessToken == null ? null : SecurityHelper.verifyToken(accessToken); - this.serverID = serverID == null ? null : VerifyHelper.verifyServerID(serverID); - } - - private void auth(String username, String accessToken) { - this.username = username; // Update username case - this.accessToken = accessToken; - serverID = null; - } - - private boolean checkServer(String username, String serverID) { - return username.equals(this.username) && serverID.equals(this.serverID); - } - - - public String getAccessToken() { - return accessToken; - } - - - public String getServerID() { - return serverID; - } - - - public String getUsername() { - return username; - } - - private boolean joinServer(String username, String accessToken, String serverID) { - if (!username.equals(this.username) || !accessToken.equals(this.accessToken)) - return false; // Username or access token mismatch - - // Update server ID - this.serverID = serverID; - return true; - } - - @Override - public void write(HOutput output) throws IOException { - output.writeString(username, 64); - output.writeBoolean(accessToken != null); - if (accessToken != null) { - output.writeASCII(accessToken, -SecurityHelper.TOKEN_STRING_LENGTH); - output.writeBoolean(serverID != null); - if (serverID != null) - output.writeASCII(serverID, 41); - } - } - } - - - public Path file; - - public Path fileTmp; - - - public boolean offlineUUIDs; - // Instance - private final SecureRandom random = SecurityHelper.newRandom(); - - private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); - // Storage - private final Map entryMap = new HashMap<>(256); - - private final Map usernamesMap = new HashMap<>(256); - - - protected final void addAuth(UUID uuid, Entry entry) { - lock.writeLock().lock(); - try { - Entry previous = entryMap.put(uuid, entry); - if (previous != null) - usernamesMap.remove(CommonHelper.low(previous.username)); - usernamesMap.put(CommonHelper.low(entry.username), uuid); - } finally { - lock.writeLock().unlock(); - } - } - - @Override - public final UUID auth(AuthProviderResult authResult) { - lock.writeLock().lock(); - try { - UUID uuid = usernameToUUID(authResult.username); - Entry entry = entryMap.get(uuid); - - // Not registered? Fix it! - if (entry == null) { - entry = new Entry(authResult.username); - - // Generate UUID - uuid = genUUIDFor(authResult.username); - entryMap.put(uuid, entry); - usernamesMap.put(CommonHelper.low(authResult.username), uuid); - } - - // Authenticate - entry.auth(authResult.username, authResult.accessToken); - return uuid; - } finally { - lock.writeLock().unlock(); - } - } - - @Override - public final UUID checkServer(String username, String serverID) { - lock.readLock().lock(); - try { - UUID uuid = usernameToUUID(username); - Entry entry = entryMap.get(uuid); - - // Check server (if has such account of course) - return entry != null && entry.checkServer(username, serverID) ? uuid : null; - } finally { - lock.readLock().unlock(); - } - } - - @Override - public final void close() throws IOException { - lock.readLock().lock(); - try { - LogHelper.info("Writing auth handler file (%d entries)", entryMap.size()); - writeAuthFileTmp(); - IOHelper.move(fileTmp, file); - } finally { - lock.readLock().unlock(); - } - } - - - protected final Set> entrySet() { - return Collections.unmodifiableMap(entryMap).entrySet(); - } - - private UUID genUUIDFor(String username) { - if (offlineUUIDs) { - UUID md5UUID = PlayerProfile.offlineUUID(username); - if (!entryMap.containsKey(md5UUID)) - return md5UUID; - LogHelper.warning("Offline UUID collision, using random: '%s'", username); - } - - // Pick random UUID - UUID uuid; - do - uuid = new UUID(random.nextLong(), random.nextLong()); - while (entryMap.containsKey(uuid)); - return uuid; - } - - @Override - public final boolean joinServer(String username, String accessToken, String serverID) { - lock.writeLock().lock(); - try { - Entry entry = entryMap.get(usernameToUUID(username)); - return entry != null && entry.joinServer(username, accessToken, serverID); - } finally { - lock.writeLock().unlock(); - } - } - - - protected abstract void readAuthFile() throws IOException; - - @Override - public final UUID usernameToUUID(String username) { - lock.readLock().lock(); - try { - return usernamesMap.get(CommonHelper.low(username)); - } finally { - lock.readLock().unlock(); - } - } - - @Override - public final String uuidToUsername(UUID uuid) { - lock.readLock().lock(); - try { - Entry entry = entryMap.get(uuid); - return entry == null ? null : entry.username; - } finally { - lock.readLock().unlock(); - } - } - - - protected abstract void writeAuthFileTmp() throws IOException; -} From 7c5c4faa75cc709db89a09c1e46b211fc4f04d1b Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Thu, 14 Feb 2019 13:45:36 +0300 Subject: [PATCH 3/4] =?UTF-8?q?[FIX]=20BinaryFileAuthHandler=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=BD=D0=B5=D1=81=D0=B5=D0=BD=20=D0=B2=20LegacySupport.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/handler/AuthHandler.java | 3 - .../auth/handler/BinaryFileAuthHandler.java | 257 ------------------ modules | 2 +- 3 files changed, 1 insertion(+), 261 deletions(-) delete mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/BinaryFileAuthHandler.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java index 1f3e9dba..5f30924f 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java @@ -41,9 +41,6 @@ public static void registerHandlers() { if (!registredHandl) { registerHandler("null", NullAuthHandler.class); registerHandler("memory", MemoryAuthHandler.class); - - // Auth handler that doesn't do nothing :D - registerHandler("binaryFile", BinaryFileAuthHandler.class); registerHandler("mysql", MySQLAuthHandler.class); registredHandl = true; } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/BinaryFileAuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/BinaryFileAuthHandler.java deleted file mode 100644 index a68b71ea..00000000 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/BinaryFileAuthHandler.java +++ /dev/null @@ -1,257 +0,0 @@ -package ru.gravit.launchserver.auth.handler; - -import ru.gravit.launcher.profiles.PlayerProfile; -import ru.gravit.launcher.serialize.HInput; -import ru.gravit.launcher.serialize.HOutput; -import ru.gravit.launcher.serialize.stream.StreamObject; -import ru.gravit.launchserver.auth.provider.AuthProviderResult; -import ru.gravit.utils.helper.CommonHelper; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.LogHelper; -import ru.gravit.utils.helper.SecurityHelper; -import ru.gravit.utils.helper.VerifyHelper; - -import java.io.File; -import java.io.IOException; -import java.security.SecureRandom; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -public final class BinaryFileAuthHandler extends AuthHandler { - public static final class Entry extends StreamObject { - private String username; - private String accessToken; - private String serverID; - - - public Entry(HInput input) throws IOException { - username = VerifyHelper.verifyUsername(input.readString(64)); - if (input.readBoolean()) { - accessToken = SecurityHelper.verifyToken(input.readASCII(-SecurityHelper.TOKEN_STRING_LENGTH)); - if (input.readBoolean()) - serverID = VerifyHelper.verifyServerID(input.readASCII(41)); - } - } - - - public Entry(String username) { - this.username = VerifyHelper.verifyUsername(username); - } - - - public Entry(String username, String accessToken, String serverID) { - this(username); - if (accessToken == null && serverID != null) - throw new IllegalArgumentException("Can't set access token while server ID is null"); - - // Set and verify access token - this.accessToken = accessToken == null ? null : SecurityHelper.verifyToken(accessToken); - this.serverID = serverID == null ? null : VerifyHelper.verifyServerID(serverID); - } - - private void auth(String username, String accessToken) { - this.username = username; // Update username case - this.accessToken = accessToken; - serverID = null; - } - - private boolean checkServer(String username, String serverID) { - return username.equals(this.username) && serverID.equals(this.serverID); - } - - - public String getAccessToken() { - return accessToken; - } - - - public String getServerID() { - return serverID; - } - - - public String getUsername() { - return username; - } - - private boolean joinServer(String username, String accessToken, String serverID) { - if (!username.equals(this.username) || !accessToken.equals(this.accessToken)) - return false; // Username or access token mismatch - - // Update server ID - this.serverID = serverID; - return true; - } - - @Override - public void write(HOutput output) throws IOException { - output.writeString(username, 64); - output.writeBoolean(accessToken != null); - if (accessToken != null) { - output.writeASCII(accessToken, -SecurityHelper.TOKEN_STRING_LENGTH); - output.writeBoolean(serverID != null); - if (serverID != null) - output.writeASCII(serverID, 41); - } - } - } - - - public String file; - - public String fileTmp; - - - public boolean offlineUUIDs; - // Instance - private final SecureRandom random = SecurityHelper.newRandom(); - - private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); - // Storage - private final Map entryMap = new HashMap<>(256); - - private final Map usernamesMap = new HashMap<>(256); - - - protected final void addAuth(UUID uuid, Entry entry) { - lock.writeLock().lock(); - try { - Entry previous = entryMap.put(uuid, entry); - if (previous != null) - usernamesMap.remove(CommonHelper.low(previous.username)); - usernamesMap.put(CommonHelper.low(entry.username), uuid); - } finally { - lock.writeLock().unlock(); - } - } - - @Override - public final UUID auth(AuthProviderResult authResult) { - lock.writeLock().lock(); - try { - UUID uuid = usernameToUUID(authResult.username); - Entry entry = entryMap.get(uuid); - - // Not registered? Fix it! - if (entry == null) { - entry = new Entry(authResult.username); - - // Generate UUID - uuid = genUUIDFor(authResult.username); - entryMap.put(uuid, entry); - usernamesMap.put(CommonHelper.low(authResult.username), uuid); - } - - // Authenticate - entry.auth(authResult.username, authResult.accessToken); - return uuid; - } finally { - lock.writeLock().unlock(); - } - } - - @Override - public final UUID checkServer(String username, String serverID) { - lock.readLock().lock(); - try { - UUID uuid = usernameToUUID(username); - Entry entry = entryMap.get(uuid); - - // Check server (if has such account of course) - return entry != null && entry.checkServer(username, serverID) ? uuid : null; - } finally { - lock.readLock().unlock(); - } - } - - @Override - public final void close() throws IOException { - lock.readLock().lock(); - try { - LogHelper.info("Writing auth handler file (%d entries)", entryMap.size()); - writeAuthFileTmp(); - IOHelper.move(new File(fileTmp).toPath(), new File(file).toPath()); - } finally { - lock.readLock().unlock(); - } - } - - - protected final Set> entrySet() { - return Collections.unmodifiableMap(entryMap).entrySet(); - } - - private UUID genUUIDFor(String username) { - if (offlineUUIDs) { - UUID md5UUID = PlayerProfile.offlineUUID(username); - if (!entryMap.containsKey(md5UUID)) - return md5UUID; - LogHelper.warning("Offline UUID collision, using random: '%s'", username); - } - - // Pick random UUID - UUID uuid; - do - uuid = new UUID(random.nextLong(), random.nextLong()); - while (entryMap.containsKey(uuid)); - return uuid; - } - - @Override - public final boolean joinServer(String username, String accessToken, String serverID) { - lock.writeLock().lock(); - try { - Entry entry = entryMap.get(usernameToUUID(username)); - return entry != null && entry.joinServer(username, accessToken, serverID); - } finally { - lock.writeLock().unlock(); - } - } - - @Override - public final UUID usernameToUUID(String username) { - lock.readLock().lock(); - try { - return usernamesMap.get(CommonHelper.low(username)); - } finally { - lock.readLock().unlock(); - } - } - - @Override - public final String uuidToUsername(UUID uuid) { - lock.readLock().lock(); - try { - Entry entry = entryMap.get(uuid); - return entry == null ? null : entry.username; - } finally { - lock.readLock().unlock(); - } - } - - protected void readAuthFile() throws IOException { - try (HInput input = new HInput(IOHelper.newInput(new File(file).toPath()))) { - int count = input.readLength(0); - for (int i = 0; i < count; i++) { - UUID uuid = input.readUUID(); - Entry entry = new Entry(input); - addAuth(uuid, entry); - } - } - } - - protected void writeAuthFileTmp() throws IOException { - Set> entrySet = entrySet(); - try (HOutput output = new HOutput(IOHelper.newOutput(new File(fileTmp).toPath()))) { - output.writeLength(entrySet.size(), 0); - for (Map.Entry entry : entrySet) { - output.writeUUID(entry.getKey()); - entry.getValue().write(output); - } - } - } -} diff --git a/modules b/modules index 9a7e59fb..14d93a04 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 9a7e59fb8df543305a2b708822a398dcabcac4b9 +Subproject commit 14d93a04d551ae36f68bd74d61445d8c7d7bd076 From 90b91a9635cde5a5ffc9ba87ba2ff50e4f418c6d Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Thu, 14 Feb 2019 14:03:50 +0300 Subject: [PATCH 4/4] =?UTF-8?q?[FEATURE]=20=D0=9F=D0=B5=D1=80=D0=B5=D1=85?= =?UTF-8?q?=D0=BE=D0=B4=20=D0=BD=D0=B0=20ThreadPool.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/gravit/launcher/LauncherEngine.java | 2 -- .../ru/gravit/launcher/RequestWorker.java | 30 ------------------- .../launcher/client/FunctionalBridge.java | 12 +++----- 3 files changed, 4 insertions(+), 40 deletions(-) delete mode 100644 Launcher/src/main/java/ru/gravit/launcher/RequestWorker.java diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index 273cc5a2..37a794fa 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -71,8 +71,6 @@ public void start(String... args) throws Throwable { throw new IllegalStateException("Launcher has been already started"); Launcher.modulesManager.initModules(); runtimeProvider.preLoad(); - FunctionalBridge.worker = new RequestWorker(); - CommonHelper.newThread("Task Worker", true, FunctionalBridge.worker).start(); FunctionalBridge.getHWID = CommonHelper.newThread("GetHWID Thread", true, FunctionalBridge::getHWID); FunctionalBridge.getHWID.start(); LogHelper.debug("Dir: %s", DirBridge.dir); diff --git a/Launcher/src/main/java/ru/gravit/launcher/RequestWorker.java b/Launcher/src/main/java/ru/gravit/launcher/RequestWorker.java deleted file mode 100644 index bbb44ead..00000000 --- a/Launcher/src/main/java/ru/gravit/launcher/RequestWorker.java +++ /dev/null @@ -1,30 +0,0 @@ -package ru.gravit.launcher; - -import ru.gravit.utils.helper.LogHelper; - -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; - -public class RequestWorker implements Runnable { - public RequestWorker() { - queue = new LinkedBlockingQueue<>(64); - } - - public BlockingQueue queue; - - @Override - public void run() { - LogHelper.debug("FX Task Thread start"); - while (!Thread.interrupted()) { - try { - Runnable task; - task = queue.take(); - task.run(); - } catch (InterruptedException e) { - LogHelper.error(e); - return; - } - } - LogHelper.debug("FX Task Thread done"); - } -} diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java b/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java index 882855e0..3b1acf9c 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java @@ -3,7 +3,6 @@ import javafx.concurrent.Task; import ru.gravit.launcher.HWID; import ru.gravit.launcher.LauncherAPI; -import ru.gravit.launcher.RequestWorker; import ru.gravit.launcher.hasher.FileNameMatcher; import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hwid.OshiHWIDProvider; @@ -13,17 +12,18 @@ import ru.gravit.launcher.request.update.LegacyLauncherRequest; import ru.gravit.launcher.request.websockets.RequestInterface; import ru.gravit.launcher.serialize.signed.SignedObjectHolder; -import ru.gravit.utils.helper.LogHelper; import java.io.IOException; import java.nio.file.Path; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicReference; public class FunctionalBridge { @LauncherAPI public static LauncherSettings settings; @LauncherAPI - public static RequestWorker worker; + public static ExecutorService worker = Executors.newWorkStealingPool(); @LauncherAPI public static OshiHWIDProvider hwidProvider = new OshiHWIDProvider(); @LauncherAPI @@ -64,11 +64,7 @@ public static void makeJsonRequest(RequestInterface request, Runnable callback) @LauncherAPI public static void startTask(@SuppressWarnings("rawtypes") Task task) { - try { - worker.queue.put(task); - } catch (InterruptedException e) { - LogHelper.error(e); - } + worker.execute(task); } @LauncherAPI