server

Clone or download

Modified Files

package com.StreamPi.Server.Window.FirstTimeUse;
package com.StreamPi.Server.Window.FirstTimeUse;
import com.StreamPi.Server.Connection.ServerListener;
import com.StreamPi.Server.Connection.ServerListener;
import com.StreamPi.Server.IO.Config;
import com.StreamPi.Server.IO.Config;
import com.StreamPi.Server.Window.ExceptionAndAlertHandler;
import com.StreamPi.Server.Window.ExceptionAndAlertHandler;
import com.StreamPi.Util.Exception.SevereException;
import com.StreamPi.Util.Exception.SevereException;
import com.StreamPi.Util.FormHelper.HBoxInputBox;
import com.StreamPi.Util.FormHelper.HBoxInputBox;
import com.StreamPi.Util.FormHelper.SpaceFiller;
import com.StreamPi.Util.FormHelper.SpaceFiller;
import com.StreamPi.Util.FormHelper.SpaceFiller.FillerType;
import com.StreamPi.Util.FormHelper.SpaceFiller.FillerType;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.TextField;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.stage.Stage;
public class FinalConfigPane extends VBox
public class FinalConfigPane extends VBox
{
{
private TextField serverNicknameTextField;
private TextField serverNicknameTextField;
private TextField serverPortTextField;
private TextField serverPortTextField;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ServerListener serverListener;
private ServerListener serverListener;
public FinalConfigPane(ExceptionAndAlertHandler exceptionAndAlertHandler, ServerListener serverListener)
public FinalConfigPane(ExceptionAndAlertHandler exceptionAndAlertHandler, ServerListener serverListener)
{
{
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.serverListener = serverListener;
this.serverListener = serverListener;
getStyleClass().add("first_time_use_pane_final_config");
getStyleClass().add("first_time_use_pane_final_config");
Label label = new Label("Thats it. Now just name your Stream-Pi Server, and the port where the server will run on!\n" +
Label label = new Label("Thats it. Now just name your Stream-Pi Server, and the port where the server will run on!\n" +
"You can leave the default value of the port as it is.");
"You can leave the default value of the port as it is.");
label.setWrapText(true);
label.setWrapText(true);
label.getStyleClass().add("first_time_use_pane_final_config_label");
label.getStyleClass().add("first_time_use_pane_final_config_label");
serverNicknameTextField = new TextField();
serverNicknameTextField = new TextField();
serverPortTextField = new TextField("2004");
serverPortTextField = new TextField("2004");
HBoxInputBox serverNickNameInputBox = new HBoxInputBox("Server Nickname", serverNicknameTextField, 200);
HBoxInputBox serverNickNameInputBox = new HBoxInputBox("Server Nickname", serverNicknameTextField, 200);
HBoxInputBox serverPortInputBox = new HBoxInputBox("Server Nickname", serverPortTextField);
HBoxInputBox serverPortInputBox = new HBoxInputBox("Server Port", serverPortTextField);
Button confirmButton = new Button("Confirm");
Button confirmButton = new Button("Confirm");
confirmButton.setOnAction(event -> onConfirmButtonClicked());
confirmButton.setOnAction(event -> onConfirmButtonClicked());
HBox bBar = new HBox(confirmButton);
HBox bBar = new HBox(confirmButton);
bBar.setAlignment(Pos.CENTER_RIGHT);
bBar.setAlignment(Pos.CENTER_RIGHT);
getChildren().addAll(label, serverNickNameInputBox, serverPortInputBox, new SpaceFiller(FillerType.VBox), bBar);
getChildren().addAll(label, serverNickNameInputBox, serverPortInputBox, new SpaceFiller(FillerType.VBox), bBar);
setSpacing(10.0);
setSpacing(10.0);
setVisible(false);
setVisible(false);
}
}
private void onConfirmButtonClicked()
private void onConfirmButtonClicked()
{
{
StringBuilder errors = new StringBuilder();
StringBuilder errors = new StringBuilder();
String serverNameStr = serverNicknameTextField.getText();
String serverNameStr = serverNicknameTextField.getText();
String serverPortStr = serverPortTextField.getText();
String serverPortStr = serverPortTextField.getText();
if(serverNameStr.isBlank() || serverNameStr.isEmpty())
if(serverNameStr.isBlank() || serverNameStr.isEmpty())
{
{
errors.append("* Server Name cannot be blank.\n");
errors.append("* Server Name cannot be blank.\n");
}
}
int serverPort=-1;
int serverPort=-1;
try {
try {
serverPort = Integer.parseInt(serverPortStr);
serverPort = Integer.parseInt(serverPortStr);
if (serverPort < 1024)
if (serverPort < 1024)
errors.append("* Server Port must be more than 1024");
errors.append("* Server Port must be more than 1024");
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
errors.append("* Server Port must be integer.\n");
errors.append("* Server Port must be integer.\n");
}
}
if(errors.toString().isEmpty())
if(errors.toString().isEmpty())
{
{
try
try
{
{
Config.getInstance().setServerName(serverNameStr);
Config.getInstance().setServerName(serverNameStr);
Config.getInstance().setServerPort(serverPort);
Config.getInstance().setServerPort(serverPort);
Config.getInstance().setFirstTimeUse(false);
Config.getInstance().setFirstTimeUse(false);
Config.getInstance().save();
Config.getInstance().save();
serverListener.othInit();
serverListener.othInit();
((Stage) getScene().getWindow()).close();
((Stage) getScene().getWindow()).close();
}
}
catch(SevereException e)
catch(SevereException e)
{
{
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
}
}
else
else
{
{
Alert alert = new Alert(AlertType.ERROR);
Alert alert = new Alert(AlertType.ERROR);
alert.setContentText("Please rectify the following errors and try again:\n"+errors.toString());
alert.setContentText("Please rectify the following errors and try again:\n"+errors.toString());
alert.show();
alert.show();
}
}
}
}
}
}
package com.StreamPi.Server.Window.Settings;
package com.StreamPi.Server.Window.Settings;
import com.StreamPi.ActionAPI.ActionAPI;
import com.StreamPi.ActionAPI.ActionAPI;
import com.StreamPi.Server.Info.License;
import com.StreamPi.Server.Info.License;
import com.StreamPi.Server.Info.ServerInfo;
import com.StreamPi.Server.Info.ServerInfo;
import com.StreamPi.Server.Main;
import com.StreamPi.Server.Main;
import com.StreamPi.Util.Platform.Platform;
import com.StreamPi.Util.Platform.Platform;
import com.StreamPi.Util.Platform.ReleaseStatus;
import com.StreamPi.Util.Platform.ReleaseStatus;
import javafx.application.HostServices;
import javafx.application.HostServices;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
import java.io.IOException;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URL;
public class About extends VBox{
public class About extends VBox{
private HostServices hostServices;
private HostServices hostServices;
public About(HostServices hostServices)
public About(HostServices hostServices)
{
{
getStyleClass().add("about");
getStyleClass().add("about");
this.hostServices = hostServices;
this.hostServices = hostServices;
setAlignment(Pos.TOP_CENTER);
setAlignment(Pos.TOP_CENTER);
Image appIcon = new Image(Main.class.getResourceAsStream("app_icon.png"));
Image appIcon = new Image(Main.class.getResourceAsStream("app_icon.png"));
ImageView appIconImageView = new ImageView(appIcon);
ImageView appIconImageView = new ImageView(appIcon);
appIconImageView.setFitHeight(196);
appIconImageView.setFitHeight(196);
appIconImageView.setFitWidth(182);
appIconImageView.setFitWidth(182);
Label licenseLabel = new Label("License");
Label licenseLabel = new Label("License");
licenseLabel.getStyleClass().add("settings_about_license_label");
licenseLabel.getStyleClass().add("settings_about_license_label");
VBox.setMargin(licenseLabel, new Insets(20, 0 , 10 ,0));
VBox.setMargin(licenseLabel, new Insets(20, 0 , 10 ,0));
TextArea licenseTextArea = new TextArea(License.getLicense());
TextArea licenseTextArea = new TextArea(License.getLicense());
licenseTextArea.setWrapText(false);
licenseTextArea.setWrapText(false);
licenseTextArea.setEditable(false);
licenseTextArea.setEditable(false);
licenseTextArea.setMaxWidth(550);
licenseTextArea.setMaxWidth(550);
VBox.setVgrow(licenseTextArea, Priority.ALWAYS);
VBox.setVgrow(licenseTextArea, Priority.ALWAYS);
HBox links = new HBox();
HBox links = new HBox();
Hyperlink github = new Hyperlink("GitHub");
Hyperlink github = new Hyperlink("GitHub");
github.setOnAction(event -> {
github.setOnAction(event -> {
openWebpage("https://github.com/Stream-Pi");
openWebpage("https://github.com/Stream-Pi");
});
});
Hyperlink discord = new Hyperlink("Discord");
Hyperlink discord = new Hyperlink("Discord");
discord.setOnAction(event -> {
discord.setOnAction(event -> {
openWebpage("https://discord.gg/BExqGmk");
openWebpage("https://discord.gg/BExqGmk");
});
});
Hyperlink website = new Hyperlink("Website");
Hyperlink website = new Hyperlink("Website");
website.setOnAction(event -> {
website.setOnAction(event -> {
openWebpage("https://stream-pi.com");
openWebpage("https://stream-pi.com");
});
});
Hyperlink twitter = new Hyperlink("Twitter");
Hyperlink twitter = new Hyperlink("Twitter");
twitter.setOnAction(event -> {
twitter.setOnAction(event -> {
openWebpage("https://twitter.com/Stream_Pi");
openWebpage("https://twitter.com/Stream_Pi");
});
});
links.setSpacing(30);
links.setSpacing(30);
links.setAlignment(Pos.CENTER);
links.setAlignment(Pos.CENTER);
links.getChildren().addAll(github, discord, website, twitter);
links.getChildren().addAll(github, discord, website, twitter);
Hyperlink donateButton = new Hyperlink("DONATE");
Hyperlink donateButton = new Hyperlink("DONATE");
donateButton.setOnAction(event -> {
donateButton.setOnAction(event -> {
openWebpage("https://www.patreon.com/streampi");
openWebpage("https://www.patreon.com/streampi");
});
});
donateButton.getStyleClass().add("settings_about_donate_hyperlink");
donateButton.getStyleClass().add("settings_about_donate_hyperlink");
Region gap = new Region();
VBox.setVgrow(gap, Priority.ALWAYS);
ServerInfo serverInfo = ServerInfo.getInstance();
ServerInfo serverInfo = ServerInfo.getInstance();
Label versionText = new Label(serverInfo.getVersion().getText() + " - "+ serverInfo.getPlatformType().getUIName() + " - "+ serverInfo.getReleaseStatus().getUIName());
Label versionText = new Label(serverInfo.getVersion().getText() + " - "+ serverInfo.getPlatformType().getUIName() + " - "+ serverInfo.getReleaseStatus().getUIName());
Label commStandardLabel = new Label("Comm Standard "+serverInfo.getCommStandardVersion().getText());
Label commStandardLabel = new Label("Comm Standard "+serverInfo.getCommStandardVersion().getText());
Label minThemeAPILabel = new Label("Min ThemeAPI "+serverInfo.getMinThemeSupportVersion().getText());
Label minThemeAPILabel = new Label("Min ThemeAPI "+serverInfo.getMinThemeSupportVersion().getText());
Label minActionAPILabel = new Label("Min ActionAPI "+serverInfo.getMinPluginSupportVersion().getText());
Label minActionAPILabel = new Label("Min ActionAPI "+serverInfo.getMinPluginSupportVersion().getText());
Label currentActionAPILabel = new Label("ActionAPI "+ ActionAPI.API_VERSION.getText());
Label currentActionAPILabel = new Label("ActionAPI "+ ActionAPI.API_VERSION.getText());
setSpacing(3);
setSpacing(3);
getChildren().addAll(appIconImageView, licenseLabel, licenseTextArea, links, donateButton, gap, versionText, commStandardLabel, minThemeAPILabel, minActionAPILabel, currentActionAPILabel);
getChildren().addAll(appIconImageView, licenseLabel, licenseTextArea, links, donateButton, versionText, commStandardLabel, minThemeAPILabel, minActionAPILabel, currentActionAPILabel);
}
}
public void openWebpage(String url) {
public void openWebpage(String url) {
hostServices.showDocument(url);
hostServices.showDocument(url);
}
}
}
}