diff --git a/README.md b/README.md index 1909f0e..2efe5d4 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,16 @@ -![Logo](src/main/resources/images/kf2logo.png) +![Logo](src/main/resources/images/kf2banner.png) Application to easily customize and launch a Killing Floor 2 Server through a visual interface instead of edditing batch files or server's config files. It has been developed with Java, so the interface is compatible on Windows and Linux OS. ``` -Version: 2.0 alpha -Last modification date: 2019/06/29 -Supported OS: Microsoft Windows and Linux +Version: 2.0 beta +Last modification date: 2019/07/14 +Supported OS: Microsoft Windows and Linux (Ubuntu/Debian) Author: César Rodríguez González Language: English (Spanish soon) ``` -**Full documentation and binary files will be available soon.** +**Full documentation will be available soon.** ![Launcher screenshot](src/main/resources/images/capture1.png) diff --git a/scripts/sql/script.sql b/scripts/sql/script.sql index 1a69a29..4517201 100644 --- a/scripts/sql/script.sql +++ b/scripts/sql/script.sql @@ -69,7 +69,7 @@ INSERT INTO KF2DATABASE.MAX_PLAYERS VALUES (6, '1', 19); -- OFFICIAL MAPS ----------------------------------- INSERT INTO KF2DATABASE.DESCRIPTIONS VALUES (20, 'Burning Paris', 'París arde'); -INSERT INTO KF2DATABASE.DESCRIPTIONS VALUES (21, 'Bioticslab', 'Laboratorio biótico'); +INSERT INTO KF2DATABASE.DESCRIPTIONS VALUES (21, 'BioticsLab', 'Laboratorio biótico'); INSERT INTO KF2DATABASE.DESCRIPTIONS VALUES (22, 'Outpost', 'Avanzada'); INSERT INTO KF2DATABASE.DESCRIPTIONS VALUES (23, 'Volter Manor', 'Mansión Volter'); INSERT INTO KF2DATABASE.DESCRIPTIONS VALUES (24, 'Catacombs', 'Catacumbas'); @@ -87,7 +87,7 @@ INSERT INTO KF2DATABASE.DESCRIPTIONS VALUES (35, 'The Tragic Kingdom', 'El reino INSERT INTO KF2DATABASE.DESCRIPTIONS VALUES (36, 'Nightmare', 'Pesadilla'); INSERT INTO KF2DATABASE.DESCRIPTIONS VALUES (37, 'Krampus Lair', 'Guarida de Krampus'); INSERT INTO KF2DATABASE.DESCRIPTIONS VALUES (38, 'Die Sector', 'Sector mortal'); -INSERT INTO KF2DATABASE.DESCRIPTIONS VALUES (39, 'Powercore', 'Núcleo de poder'); +INSERT INTO KF2DATABASE.DESCRIPTIONS VALUES (39, 'PowerCore', 'Núcleo de poder'); INSERT INTO KF2DATABASE.DESCRIPTIONS VALUES (40, 'Airship', 'Aeronave'); INSERT INTO KF2DATABASE.DESCRIPTIONS VALUES (41, 'Lockdown', 'Bloqueo'); INSERT INTO KF2DATABASE.DESCRIPTIONS VALUES (42, 'Monster Ball', 'Baile de monstruos'); @@ -97,7 +97,7 @@ INSERT INTO KF2DATABASE.DESCRIPTIONS VALUES (45, 'Spillway', 'Desag INSERT INTO KF2DATABASE.DESCRIPTIONS VALUES (46, 'Steam Fortress', 'Steam Fortress'); INSERT INTO KF2DATABASE.MAPS(ID, CODE, ID_DESCRIPTION, OFFICIAL, URL_INFO, URL_PHOTO, DOWNLOADED) VALUES (1, 'KF-BurningParis', 20, TRUE, 'https://wiki.killingfloor2.com/index.php?title=Burning_Paris','/KFGame/Web/images/maps/KF-BurningParis.jpg', TRUE); -INSERT INTO KF2DATABASE.MAPS(ID, CODE, ID_DESCRIPTION, OFFICIAL, URL_INFO, URL_PHOTO, DOWNLOADED) VALUES (2, 'KF-Bioticslab', 21, TRUE, 'https://wiki.killingfloor2.com/index.php?title=Biotics_Lab_(Killing_Floor_2)','/KFGame/Web/images/maps/KF-Bioticslab.jpg', TRUE); +INSERT INTO KF2DATABASE.MAPS(ID, CODE, ID_DESCRIPTION, OFFICIAL, URL_INFO, URL_PHOTO, DOWNLOADED) VALUES (2, 'KF-BioticsLab', 21, TRUE, 'https://wiki.killingfloor2.com/index.php?title=Biotics_Lab_(Killing_Floor_2)','/KFGame/Web/images/maps/KF-BioticsLab.jpg', TRUE); INSERT INTO KF2DATABASE.MAPS(ID, CODE, ID_DESCRIPTION, OFFICIAL, URL_INFO, URL_PHOTO, DOWNLOADED) VALUES (3, 'KF-Outpost', 22, TRUE, 'https://wiki.killingfloor2.com/index.php?title=Outpost','/KFGame/Web/images/maps/KF-Outpost.jpg', TRUE); INSERT INTO KF2DATABASE.MAPS(ID, CODE, ID_DESCRIPTION, OFFICIAL, URL_INFO, URL_PHOTO, DOWNLOADED) VALUES (4, 'KF-VolterManor', 23, TRUE, 'https://wiki.killingfloor2.com/index.php?title=Volter_Manor','/KFGame/Web/images/maps/KF-VolterManor.jpg', TRUE); INSERT INTO KF2DATABASE.MAPS(ID, CODE, ID_DESCRIPTION, OFFICIAL, URL_INFO, URL_PHOTO, DOWNLOADED) VALUES (5, 'KF-Catacombs', 24, TRUE, 'https://wiki.killingfloor2.com/index.php?title=Catacombs','/KFGame/Web/images/maps/KF-Catacombs.jpg', TRUE); @@ -115,7 +115,7 @@ INSERT INTO KF2DATABASE.MAPS(ID, CODE, ID_DESCRIPTION, OFFICIAL, URL_INFO, URL_P INSERT INTO KF2DATABASE.MAPS(ID, CODE, ID_DESCRIPTION, OFFICIAL, URL_INFO, URL_PHOTO, DOWNLOADED) VALUES (17, 'KF-Nightmare', 36, TRUE, 'https://wiki.killingfloor2.com/index.php?title=Nightmare','/KFGame/Web/images/maps/KF-Nightmare.jpg', TRUE); INSERT INTO KF2DATABASE.MAPS(ID, CODE, ID_DESCRIPTION, OFFICIAL, URL_INFO, URL_PHOTO, DOWNLOADED) VALUES (18, 'KF-KrampusLair', 37, TRUE, 'https://wiki.killingfloor2.com/index.php?title=Krampus_Lair','/KFGame/Web/images/maps/KF-KrampusLair.jpg', TRUE); INSERT INTO KF2DATABASE.MAPS(ID, CODE, ID_DESCRIPTION, OFFICIAL, URL_INFO, URL_PHOTO, DOWNLOADED) VALUES (19, 'KF-DieSector', 38, TRUE, 'https://wiki.killingfloor2.com/index.php?title=DieSector','/KFGame/Web/images/maps/KF-DieSector.jpg', TRUE); -INSERT INTO KF2DATABASE.MAPS(ID, CODE, ID_DESCRIPTION, OFFICIAL, URL_INFO, URL_PHOTO, DOWNLOADED) VALUES (20, 'KF-Powercore_Holdout', 39, TRUE, 'https://wiki.killingfloor2.com/index.php?title=Powercore','/KFGame/Web/images/maps/KF-Powercore_Holdout.jpg', TRUE); +INSERT INTO KF2DATABASE.MAPS(ID, CODE, ID_DESCRIPTION, OFFICIAL, URL_INFO, URL_PHOTO, DOWNLOADED) VALUES (20, 'KF-PowerCore_Holdout', 39, TRUE, 'https://wiki.killingfloor2.com/index.php?title=Powercore','/KFGame/Web/images/maps/KF-PowerCore_Holdout.jpg', TRUE); INSERT INTO KF2DATABASE.MAPS(ID, CODE, ID_DESCRIPTION, OFFICIAL, URL_INFO, URL_PHOTO, DOWNLOADED) VALUES (21, 'KF-Airship', 40, TRUE, 'https://wiki.killingfloor2.com/index.php?title=Airship','/KFGame/Web/images/maps/KF-Airship.jpg', TRUE); INSERT INTO KF2DATABASE.MAPS(ID, CODE, ID_DESCRIPTION, OFFICIAL, URL_INFO, URL_PHOTO, DOWNLOADED) VALUES (22, 'KF-Lockdown', 41, TRUE, 'https://wiki.killingfloor2.com/index.php?title=Lockdown','/KFGame/Web/images/maps/KF-Lockdown.jpg', TRUE); INSERT INTO KF2DATABASE.MAPS(ID, CODE, ID_DESCRIPTION, OFFICIAL, URL_INFO, URL_PHOTO, DOWNLOADED) VALUES (23, 'KF-MonsterBall', 42, TRUE, 'https://wiki.killingfloor2.com/index.php?title=Monster_Ball','/KFGame/Web/images/maps/KF-MonsterBall.jpg', TRUE); @@ -133,11 +133,11 @@ INSERT INTO KF2DATABASE.PROFILES(ID, NAME, ID_LANGUAGE, ID_GAMETYPE, ID_MAP, ID_ ----------------------------------- -- PROPERTIES ----------------------------------- -INSERT INTO KF2DATABASE.PROPERTIES VALUES (1, 'prop.key.urlSteamcmd', 'https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip'); -INSERT INTO KF2DATABASE.PROPERTIES VALUES (2, 'prop.key.betaBrunch', 'preview'); -INSERT INTO KF2DATABASE.PROPERTIES VALUES (3, 'prop.key.downloadConnectionTimeout', '10000'); -INSERT INTO KF2DATABASE.PROPERTIES VALUES (4, 'prop.key.downloadReadTimeout', '30000'); -INSERT INTO KF2DATABASE.PROPERTIES VALUES (5, 'prop.key.defaultServername', 'Killing Floor 2 Server'); -INSERT INTO KF2DATABASE.PROPERTIES VALUES (6, 'prop.key.defaultWebPort', '8080'); -INSERT INTO KF2DATABASE.PROPERTIES VALUES (7, 'prop.key.defaultGamePort', '7777'); -INSERT INTO KF2DATABASE.PROPERTIES VALUES (8, 'prop.key.defaultQueryPort', '27015'); +INSERT INTO KF2DATABASE.PROPERTIES VALUES (101, 'prop.key.urlSteamcmd', 'https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip'); +INSERT INTO KF2DATABASE.PROPERTIES VALUES (102, 'prop.key.betaBrunch', 'preview'); +INSERT INTO KF2DATABASE.PROPERTIES VALUES (103, 'prop.key.downloadConnectionTimeout', '10000'); +INSERT INTO KF2DATABASE.PROPERTIES VALUES (104, 'prop.key.downloadReadTimeout', '30000'); +INSERT INTO KF2DATABASE.PROPERTIES VALUES (105, 'prop.key.defaultServername', 'Killing Floor 2 Server'); +INSERT INTO KF2DATABASE.PROPERTIES VALUES (106, 'prop.key.defaultWebPort', '8080'); +INSERT INTO KF2DATABASE.PROPERTIES VALUES (107, 'prop.key.defaultGamePort', '7777'); +INSERT INTO KF2DATABASE.PROPERTIES VALUES (108, 'prop.key.defaultQueryPort', '27015'); \ No newline at end of file diff --git a/src/main/java/constants/Constants.java b/src/main/java/constants/Constants.java index bf578df..a624dc7 100644 --- a/src/main/java/constants/Constants.java +++ b/src/main/java/constants/Constants.java @@ -7,7 +7,7 @@ public class Constants { // MENU public static final String MENU_MAIN_PAGE = "Main Page"; - public static final String MENU_INSTALL_UPDATE_SERVER = "Install/Update Server"; + public static final String MENU_INSTALL_UPDATE_SERVER = "Install/Update"; public static final String MENU_WEB_ADMIN = "WebAdmin"; public static final String MENU_PROFILES_EDITION = "Profiles"; public static final String MENU_GAMETYPES_EDITION = "Game types"; diff --git a/src/main/java/pojos/kf2factory/Kf2Common.java b/src/main/java/pojos/kf2factory/Kf2Common.java index fbe06ea..39b09c1 100644 --- a/src/main/java/pojos/kf2factory/Kf2Common.java +++ b/src/main/java/pojos/kf2factory/Kf2Common.java @@ -187,8 +187,6 @@ protected String replaceLinePcServerKFGameIni(String line, Profile profile) { modifiedLine = "ServerMOTD=" + profile.getWelcomeMessage(); modifiedLine = modifiedLine.replaceAll("\n","\\\\n"); } - // TODO: set GameMapCycle - return modifiedLine; } @@ -223,66 +221,78 @@ protected void joinToKf2Server(File steamExeFile, Profile profile) { } - protected void addCustomMapToKfEngineIni(Long idWorkShop, String installationFolder, String profileName, String filename) { - File kfEngineIni = new File(installationFolder + "/KFGame/Config/" + profileName + "/" + filename); - try (BufferedReader br = new BufferedReader(new FileReader(kfEngineIni))) { - String strTempFile = installationFolder + "/KFGame/Config/" + profileName + "/" + filename + ".tmp"; - File tempFile = new File(strTempFile); - PrintWriter pw = new PrintWriter(new FileWriter(strTempFile)); - String line; - boolean customMapAdded = false; - while ((line = br.readLine()) != null) { - pw.println(line); - if (StringUtils.isNotBlank(line) && line.contains("[OnlineSubsystemSteamworks.KFWorkshopSteamworks]")) { - pw.println("ServerSubscribedWorkshopItems=" + idWorkShop); - customMapAdded = true; + protected void addCustomMapToKfEngineIni(Long idWorkShop, String installationFolder, String filename) { + try { + List profileList = databaseService.listAllProfiles(); + if (profileList != null && !profileList.isEmpty()) { + for (Profile profile: profileList) { + File kfEngineIni = new File(installationFolder + "/KFGame/Config/" + profile.getName() + "/" + filename); + BufferedReader br = new BufferedReader(new FileReader(kfEngineIni)); + String strTempFile = installationFolder + "/KFGame/Config/" + profile.getName() + "/" + filename + ".tmp"; + File tempFile = new File(strTempFile); + PrintWriter pw = new PrintWriter(new FileWriter(strTempFile)); + String line; + boolean customMapAdded = false; + while ((line = br.readLine()) != null) { + pw.println(line); + if (StringUtils.isNotBlank(line) && line.contains("[OnlineSubsystemSteamworks.KFWorkshopSteamworks]")) { + pw.println("ServerSubscribedWorkshopItems=" + idWorkShop); + customMapAdded = true; + } + } + if (!customMapAdded) { + pw.println("\n[OnlineSubsystemSteamworks.KFWorkshopSteamworks]"); + pw.println("ServerSubscribedWorkshopItems=" + idWorkShop); + } + br.close(); + pw.close(); + kfEngineIni.delete(); + tempFile.renameTo(kfEngineIni); } } - if (!customMapAdded) { - pw.println("\n[OnlineSubsystemSteamworks.KFWorkshopSteamworks]"); - pw.println("ServerSubscribedWorkshopItems=" + idWorkShop); - } - br.close(); - pw.close(); - kfEngineIni.delete(); - tempFile.renameTo(kfEngineIni); } catch (Exception e) { Utils.errorDialog(e.getMessage(), "See stacktrace for more details", e); } } - public abstract void addCustomMapToKfEngineIni(Long idWorkShop, String installationFolder, String profileName); + public abstract void addCustomMapToKfEngineIni(Long idWorkShop, String installationFolder); - protected void removeCustomMapsFromKfEngineIni(List idWorkShopList, String installationFolder, String profileName, String filename) { - File kfEngineIni = new File(installationFolder + "/KFGame/Config/" + profileName + "/" + filename); - try (BufferedReader br = new BufferedReader(new FileReader(kfEngineIni))) { - String strTempFile = installationFolder + "/KFGame/Config/" + profileName + "/" + filename + ".tmp"; - File tempFile = new File(strTempFile); - PrintWriter pw = new PrintWriter(new FileWriter(strTempFile)); - String line; - while ((line = br.readLine()) != null) { - if (line.contains("ServerSubscribedWorkshopItems=")) { - String[] array = line.split("="); - Long idWorkshop = Long.parseLong(array[1]); - if (idWorkShopList.contains(idWorkshop)) { - idWorkShopList.remove(idWorkshop); - } else { - pw.println(line); + protected void removeCustomMapsFromKfEngineIni(List idWorkShopList, String installationFolder, String filename) { + try { + List profileList = databaseService.listAllProfiles(); + if (profileList != null && !profileList.isEmpty()) { + for (Profile profile : profileList) { + File kfEngineIni = new File(installationFolder + "/KFGame/Config/" + profile.getName() + "/" + filename); + BufferedReader br = new BufferedReader(new FileReader(kfEngineIni)); + String strTempFile = installationFolder + "/KFGame/Config/" + profile.getName() + "/" + filename + ".tmp"; + File tempFile = new File(strTempFile); + PrintWriter pw = new PrintWriter(new FileWriter(strTempFile)); + String line; + while ((line = br.readLine()) != null) { + if (line.contains("ServerSubscribedWorkshopItems=")) { + String[] array = line.split("="); + Long idWorkshop = Long.parseLong(array[1]); + if (idWorkShopList.contains(idWorkshop)) { + idWorkShopList.remove(idWorkshop); + } else { + pw.println(line); + } + } else { + pw.println(line); + } } - } else { - pw.println(line); + br.close(); + pw.close(); + kfEngineIni.delete(); + tempFile.renameTo(kfEngineIni); } } - br.close(); - pw.close(); - kfEngineIni.delete(); - tempFile.renameTo(kfEngineIni); } catch (Exception e) { Utils.errorDialog(e.getMessage(), "See stacktrace for more details", e); } } - public abstract void removeCustomMapsFromKfEngineIni(List idWorkShopList, String installationFolder, String profileName); + public abstract void removeCustomMapsFromKfEngineIni(List idWorkShopList, String installationFolder); private String generateMapCycleLine(List mapList) { StringBuffer sb = new StringBuffer("GameMapCycles=(Maps=("); @@ -298,74 +308,87 @@ private String generateMapCycleLine(List mapList) { return sb.toString(); } - protected void addCustomMapToKfGameIni(String mapName, String installationFolder, String profileName, List mapList, String filename) { - // TODO: Este método tiene que ser modificado para permitir añadir múltiples mapas al fichero - File kfGameIni = new File(installationFolder + "/KFGame/Config/" + profileName + "/" + filename); - try (BufferedReader br = new BufferedReader(new FileReader(kfGameIni))) { - String strTempFile = installationFolder + "/KFGame/Config/" + profileName + "/" + filename + ".tmp"; - File tempFile = new File(strTempFile); - PrintWriter pw = new PrintWriter(new FileWriter(strTempFile)); - String line; - while ((line = br.readLine()) != null) { - if (StringUtils.isNotBlank(line) && line.contains("GameMapCycles=(Maps=(")) { - pw.println(generateMapCycleLine(mapList)); - continue; + protected void addCustomMapsToKfGameIni(List mapNameList, String installationFolder, List mapList, String filename) { + try { + List profileList = databaseService.listAllProfiles(); + if (profileList != null && !profileList.isEmpty()) { + for (Profile profile : profileList) { + File kfGameIni = new File(installationFolder + "/KFGame/Config/" + profile.getName() + "/" + filename); + BufferedReader br = new BufferedReader(new FileReader(kfGameIni)); + String strTempFile = installationFolder + "/KFGame/Config/" + profile.getName() + "/" + filename + ".tmp"; + File tempFile = new File(strTempFile); + PrintWriter pw = new PrintWriter(new FileWriter(strTempFile)); + String line; + while ((line = br.readLine()) != null) { + if (StringUtils.isNotBlank(line) && line.contains("GameMapCycles=(Maps=(")) { + pw.println(generateMapCycleLine(mapList)); + continue; + } + pw.println(line); + } + for (String mapName: mapNameList) { + pw.println("[" + mapName + " KFMapSummary]"); + pw.println("MapName=" + mapName); + pw.println(""); + } + br.close(); + pw.close(); + kfGameIni.delete(); + tempFile.renameTo(kfGameIni); } - pw.println(line); } - pw.println("[" + mapName + " KFMapSummary]"); - pw.println("MapName=" + mapName); - pw.println(""); - br.close(); - pw.close(); - kfGameIni.delete(); - tempFile.renameTo(kfGameIni); } catch (Exception e) { Utils.errorDialog(e.getMessage(), "See stacktrace for more details", e); } } - public abstract void addCustomMapToKfGameIni(String mapName, String installationFolder, String profileName, List mapList); + public abstract void addCustomMapsToKfGameIni(List mapNameList, String installationFolder, List mapList); - protected void removeCustomMapsFromKfGameIni(List mapNameList, String installationFolder, String profileName, List mapList, String filename) { - File kfGameIni = new File(installationFolder + "/KFGame/Config/" + profileName + "/" + filename); - try (BufferedReader br = new BufferedReader(new FileReader(kfGameIni))) { - String strTempFile = installationFolder + "/KFGame/Config/" + profileName + "/" + filename + ".tmp"; - File tempFile = new File(strTempFile); - PrintWriter pw = new PrintWriter(new FileWriter(strTempFile)); - String line; - while ((line = br.readLine()) != null) { - if (StringUtils.isNotBlank(line)) { - if (line.contains("GameMapCycles=(Maps=(")) { - pw.println(generateMapCycleLine(mapList)); - continue; - } - if (line.contains(" KFMapSummary]")) { - String[] array = line.split(" "); - String mapName = array[0].replace("[",""); - if (mapNameList.contains(mapName)) { - continue; - } - } - if (line.contains("MapName=")) { - String[] array = line.split("="); - String mapName = array[1]; - if (mapNameList.contains(mapName)) { - continue; + protected void removeCustomMapsFromKfGameIni(List mapNameList, String installationFolder, List mapList, String filename) { + try { + List profileList = databaseService.listAllProfiles(); + if (profileList != null && !profileList.isEmpty()) { + for (Profile profile : profileList) { + File kfGameIni = new File(installationFolder + "/KFGame/Config/" + profile.getName() + "/" + filename); + BufferedReader br = new BufferedReader(new FileReader(kfGameIni)); + String strTempFile = installationFolder + "/KFGame/Config/" + profile.getName() + "/" + filename + ".tmp"; + File tempFile = new File(strTempFile); + PrintWriter pw = new PrintWriter(new FileWriter(strTempFile)); + String line; + while ((line = br.readLine()) != null) { + if (StringUtils.isNotBlank(line)) { + if (line.contains("GameMapCycles=(Maps=(")) { + pw.println(generateMapCycleLine(mapList)); + continue; + } + if (line.contains(" KFMapSummary]")) { + String[] array = line.split(" "); + String mapName = array[0].replace("[",""); + if (mapNameList.contains(mapName)) { + continue; + } + } + if (line.contains("MapName=")) { + String[] array = line.split("="); + String mapName = array[1]; + if (mapNameList.contains(mapName)) { + continue; + } + } } + pw.println(line); } + br.close(); + pw.close(); + kfGameIni.delete(); + tempFile.renameTo(kfGameIni); } - pw.println(line); } - br.close(); - pw.close(); - kfGameIni.delete(); - tempFile.renameTo(kfGameIni); } catch (Exception e) { Utils.errorDialog(e.getMessage(), "See stacktrace for more details", e); } } - public abstract void removeCustomMapsFromKfGameIni(List mapNameList, String installationFolder, String profileName, List mapList); + public abstract void removeCustomMapsFromKfGameIni(List mapNameList, String installationFolder, List mapList); } diff --git a/src/main/java/pojos/kf2factory/Kf2LinuxImpl.java b/src/main/java/pojos/kf2factory/Kf2LinuxImpl.java index 11b7349..e19d02d 100644 --- a/src/main/java/pojos/kf2factory/Kf2LinuxImpl.java +++ b/src/main/java/pojos/kf2factory/Kf2LinuxImpl.java @@ -7,17 +7,29 @@ import utils.Utils; import java.io.File; -import java.io.IOException; import java.util.List; +import java.util.concurrent.TimeUnit; public class Kf2LinuxImpl extends Kf2Common { @Override protected boolean prepareSteamCmd(String installationFolder) { try { + File xtermFile = new File("/usr/bin/xterm"); + if (!xtermFile.exists()) { + Runtime.getRuntime().exec(new String[]{"x-terminal-emulator","-e","echo Installing package xterm && sudo apt -y install xterm"}); + Utils.warningDialog("Install package xterm", "When installation is completed, press this button"); + } File steamcmdFile = new File("/usr/games/steamcmd"); if (!steamcmdFile.exists()) { - Runtime.getRuntime().exec(new String[]{"x-terminal-emulator","-e","sudo apt -y install steamcmd"}); + Process process = Runtime.getRuntime().exec(new String[]{"xterm", + "-T", "Installing SteamCmd", + "-fa", "DejaVu Sans Mono", + "-fs", "11", + "-geometry", "120x25+0-0", + "-xrm", "XTerm.vt100.allowTitleOps: false", + "-e","sudo apt -y install steamcmd"}); + process.waitFor(); } return true; } catch (Exception e) { @@ -29,8 +41,11 @@ protected boolean prepareSteamCmd(String installationFolder) { @Override protected void installUpdateKf2Server(String installationFolder, boolean validateFiles, boolean isBeta, String betaBrunch) { try { - StringBuffer command = new StringBuffer("x-terminal-emulator -e "); - command.append("/usr/games/steamcmd +login anonymous +force_install_dir "); + File cacheFolder = new File(installationFolder + "/KFGame/Cache"); + if (!cacheFolder.exists()) { + cacheFolder.mkdir(); + } + StringBuffer command = new StringBuffer("/usr/games/steamcmd +login anonymous +force_install_dir "); command.append(installationFolder); command.append(" +app_update 232130 "); if (validateFiles) { @@ -44,9 +59,36 @@ protected void installUpdateKf2Server(String installationFolder, boolean validat command.append(" +exit"); // Execute steamcmd and install / update the kf2 server - Runtime.getRuntime().exec(command.toString()); - } catch (IOException e) { - Utils.errorDialog("Error preparing SteamCmd to be able to install KF2 server", "See stacktrace for more details", e); + Process process = Runtime.getRuntime().exec(new String[]{"xterm", + "-T", "Installing/Updating the server", + "-fa", "DejaVu Sans Mono", + "-fs", "11", + "-geometry", "120x25+0-0", + "-xrm", "XTerm.vt100.allowTitleOps: false", + "-e", command.toString()}); + process.waitFor(); + + // If it's the first time, run the server to create needed config files + File kfEngineIni = new File(installationFolder + "/KFGame/Config/LinuxServer-KFEngine.ini"); + File kfGameIni = new File(installationFolder + "/KFGame/Config/LinuxServer-KFGame.ini"); + if (!kfEngineIni.exists() || !kfGameIni.exists()) { + process = Runtime.getRuntime().exec(new String[]{"xterm", + "-T", "Wait until config files are generated", + "-fa", "DejaVu Sans Mono", + "-fs", "11", + "-geometry", "120x25+0-0", + "-xrm", "XTerm.vt100.allowTitleOps: false", + "-e", installationFolder + "/Binaries/Win64/KFGameSteamServer.bin.x86_64 KF-BioticsLab"}, + null, new File(installationFolder)); + while (process.isAlive() && (!kfEngineIni.exists() || !kfGameIni.exists())) { + process.waitFor(5, TimeUnit.SECONDS); + } + if (process.isAlive()) { + process.destroy(); + } + } + } catch (Exception e) { + Utils.errorDialog("Error installing KF2 server", "See stacktrace for more details", e); } } @@ -73,7 +115,14 @@ protected String runKf2Server(String installationFolder, Profile profile) { replaceInFileKfWebIni(installationFolder, profile); replaceInFileKfGameIni("LinuxServer-KFGame.ini", installationFolder, profile); - Process proccess = Runtime.getRuntime().exec(new String[]{"x-terminal-emulator","-e",command.toString()},null, new File(installationFolder)); + Process proccess = Runtime.getRuntime().exec(new String[]{"xterm", + "-T", "Running the server", + "-fa", "DejaVu Sans Mono", + "-fs", "11", + "-geometry", "120x25+0-0", + "-xrm", "XTerm.vt100.allowTitleOps: false", + "-e",command.toString()}, + null, new File(installationFolder)); Session.getInstance().getProcessList().add(proccess); return command.toString(); @@ -93,22 +142,22 @@ protected File getSteamExeFile() { } @Override - public void addCustomMapToKfEngineIni(Long idWorkShop, String installationFolder, String profileName) { - addCustomMapToKfEngineIni(idWorkShop, installationFolder, profileName, "LinuxServer-KFEngine.ini"); + public void addCustomMapToKfEngineIni(Long idWorkShop, String installationFolder) { + addCustomMapToKfEngineIni(idWorkShop, installationFolder,"LinuxServer-KFEngine.ini"); } @Override - public void removeCustomMapsFromKfEngineIni(List idWorkShopList, String installationFolder, String profileName) { - removeCustomMapsFromKfEngineIni(idWorkShopList, installationFolder, profileName, "LinuxServer-KFEngine.ini"); + public void removeCustomMapsFromKfEngineIni(List idWorkShopList, String installationFolder) { + removeCustomMapsFromKfEngineIni(idWorkShopList, installationFolder,"LinuxServer-KFEngine.ini"); } @Override - public void addCustomMapToKfGameIni(String mapName, String installationFolder, String profileName, List mapList) { - addCustomMapToKfGameIni(mapName, installationFolder, profileName, mapList, "LinuxServer-KFGame.ini"); + public void addCustomMapsToKfGameIni(List mapNameList, String installationFolder, List mapList) { + addCustomMapsToKfGameIni(mapNameList, installationFolder, mapList, "LinuxServer-KFGame.ini"); } @Override - public void removeCustomMapsFromKfGameIni(List mapNameList, String installationFolder, String profileName, List mapList) { - removeCustomMapsFromKfGameIni(mapNameList, installationFolder, profileName, mapList, "LinuxServer-KFGame.ini"); + public void removeCustomMapsFromKfGameIni(List mapNameList, String installationFolder, List mapList) { + removeCustomMapsFromKfGameIni(mapNameList, installationFolder, mapList, "LinuxServer-KFGame.ini"); } } diff --git a/src/main/java/pojos/kf2factory/Kf2WindowsImpl.java b/src/main/java/pojos/kf2factory/Kf2WindowsImpl.java index 9eef515..df4effb 100644 --- a/src/main/java/pojos/kf2factory/Kf2WindowsImpl.java +++ b/src/main/java/pojos/kf2factory/Kf2WindowsImpl.java @@ -13,9 +13,9 @@ import utils.Utils; import java.io.File; -import java.io.IOException; import java.net.URL; import java.util.List; +import java.util.concurrent.TimeUnit; public class Kf2WindowsImpl extends Kf2Common { @@ -53,7 +53,7 @@ protected boolean prepareSteamCmd(String installationFolder) { @Override protected void installUpdateKf2Server(String installationFolder, boolean validateFiles, boolean isBeta, String betaBrunch) { try { - StringBuffer command = new StringBuffer("cmd /C start "); + StringBuffer command = new StringBuffer("cmd /C "); command.append(installationFolder); command.append("\\steamcmd\\steamcmd.exe +login anonymous +force_install_dir "); command.append(installationFolder); @@ -69,9 +69,26 @@ protected void installUpdateKf2Server(String installationFolder, boolean validat command.append(" +exit"); // Execute steamcmd and install / update the kf2 server - Runtime.getRuntime().exec(command.toString(),null, new File(installationFolder + "\\steamcmd\\")); - } catch (IOException e) { - Utils.errorDialog("Error preparing SteamCmd to be able to install KF2 server", "See stacktrace for more details", e); + Process process = Runtime.getRuntime().exec(command.toString(),null, new File(installationFolder + "\\steamcmd\\")); + process.waitFor(); + + // If it's the first time, run the server to create needed config files + File kfEngineIni = new File(installationFolder + "\\KFGame\\Config\\PCServer-KFEngine.ini"); + File kfGameIni = new File(installationFolder + "\\KFGame\\Config\\PCServer-KFGame.ini"); + if (!kfEngineIni.exists() || !kfGameIni.exists()) { + Process proccess = Runtime.getRuntime().exec("cmd /C " + installationFolder + "\\Binaries\\Win64\\KFServer.exe KF-BioticsLab", + null, + new File(installationFolder)); + while (process.isAlive() && (!kfEngineIni.exists() || !kfGameIni.exists())) { + process.waitFor(5, TimeUnit.SECONDS); + } + if (process.isAlive()) { + process.destroy(); + } + } + + } catch (Exception e) { + Utils.errorDialog("Error installing KF2 server", "See stacktrace for more details", e); } } @@ -124,23 +141,23 @@ protected File getSteamExeFile() { } @Override - public void addCustomMapToKfEngineIni(Long idWorkShop, String installationFolder, String profileName) { - addCustomMapToKfEngineIni(idWorkShop, installationFolder, profileName, "PCServer-KFEngine.ini"); + public void addCustomMapToKfEngineIni(Long idWorkShop, String installationFolder) { + addCustomMapToKfEngineIni(idWorkShop, installationFolder,"PCServer-KFEngine.ini"); } @Override - public void removeCustomMapsFromKfEngineIni(List idWorkShopList, String installationFolder, String profileName) { - removeCustomMapsFromKfEngineIni(idWorkShopList, installationFolder, profileName, "PCServer-KFEngine.ini"); + public void removeCustomMapsFromKfEngineIni(List idWorkShopList, String installationFolder) { + removeCustomMapsFromKfEngineIni(idWorkShopList, installationFolder,"PCServer-KFEngine.ini"); } @Override - public void addCustomMapToKfGameIni(String mapName, String installationFolder, String profileName, List mapList) { - addCustomMapToKfGameIni(mapName, installationFolder, profileName, mapList, "PCServer-KFGame.ini"); + public void addCustomMapsToKfGameIni(List mapNameList, String installationFolder, List mapList) { + addCustomMapsToKfGameIni(mapNameList, installationFolder, mapList, "PCServer-KFGame.ini"); } @Override - public void removeCustomMapsFromKfGameIni(List mapNameList, String installationFolder, String profileName, List mapList) { - removeCustomMapsFromKfGameIni(mapNameList, installationFolder, profileName, mapList, "PCServer-KFGame.ini"); + public void removeCustomMapsFromKfGameIni(List mapNameList, String installationFolder, List mapList) { + removeCustomMapsFromKfGameIni(mapNameList, installationFolder, mapList, "PCServer-KFGame.ini"); } } diff --git a/src/main/java/pojos/listener/TimeListener.java b/src/main/java/pojos/listener/TimeListener.java index 6c96a90..f5fc758 100644 --- a/src/main/java/pojos/listener/TimeListener.java +++ b/src/main/java/pojos/listener/TimeListener.java @@ -2,6 +2,8 @@ import constants.Constants; import entities.Map; +import pojos.kf2factory.Kf2Common; +import pojos.kf2factory.Kf2Factory; import pojos.session.Session; import services.DatabaseService; import services.DatabaseServiceImpl; @@ -12,6 +14,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; import java.util.TimerTask; import java.util.stream.Collectors; @@ -32,22 +35,30 @@ public void run() { List notDownloadedMapList = databaseService.listNotDownloadedMaps(); if (notDownloadedMapList != null && !notDownloadedMapList.isEmpty()) { String installationFolder = databaseService.findPropertyValue(Constants.KEY_INSTALLATION_FOLDER); + List mapNameListToAdd = new ArrayList(); for (Map map : notDownloadedMapList) { List kfmFilesPath = Files.walk(Paths.get(installationFolder + "/KFGame/Cache/" + map.getIdWorkShop())) .filter(Files::isRegularFile) - .filter(f -> f.toString().endsWith(".kfm")) + .filter(f -> f.getFileName().toString().startsWith("KF-")) + .filter(f -> f.getFileName().toString().endsWith(".kfm")) .collect(Collectors.toList()); if (kfmFilesPath != null && !kfmFilesPath.isEmpty()) { String filenameWithExtension = kfmFilesPath.get(0).getFileName().toString(); - System.out.println(filenameWithExtension); String[] array = filenameWithExtension.split(".kfm"); String filenameWithoutExtension = array[0]; map.setCode(filenameWithoutExtension); map.setDownloaded(true); databaseService.updateMap(map); + mapNameListToAdd.add(map.getCode()); } } + if (!mapNameListToAdd.isEmpty()) { + Kf2Common kf2Common = Kf2Factory.getInstance(); + kf2Common.addCustomMapsToKfGameIni(mapNameListToAdd, + installationFolder, + databaseService.listDownloadedMaps()); + } } } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/services/DatabaseService.java b/src/main/java/services/DatabaseService.java index 1f2ecf2..9fd1909 100644 --- a/src/main/java/services/DatabaseService.java +++ b/src/main/java/services/DatabaseService.java @@ -1,12 +1,15 @@ package services; import entities.Map; +import entities.Profile; import java.sql.SQLException; import java.util.List; public interface DatabaseService { String findPropertyValue(String key) throws SQLException; + List listDownloadedMaps() throws SQLException; List listNotDownloadedMaps() throws SQLException; boolean updateMap(Map map) throws SQLException; + List listAllProfiles() throws SQLException; } diff --git a/src/main/java/services/DatabaseServiceImpl.java b/src/main/java/services/DatabaseServiceImpl.java index dd1825f..ae517e7 100644 --- a/src/main/java/services/DatabaseServiceImpl.java +++ b/src/main/java/services/DatabaseServiceImpl.java @@ -1,8 +1,10 @@ package services; import daos.MapDao; +import daos.ProfileDao; import daos.PropertyDao; import entities.Map; +import entities.Profile; import entities.Property; import java.sql.SQLException; @@ -25,6 +27,11 @@ public String findPropertyValue(String key) throws SQLException { } } + @Override + public List listDownloadedMaps() throws SQLException { + return MapDao.getInstance().listDownloadedMaps(); + } + @Override public List listNotDownloadedMaps() throws SQLException { return MapDao.getInstance().listNotDownloadedMaps(); @@ -34,4 +41,9 @@ public List listNotDownloadedMaps() throws SQLException { public boolean updateMap(Map map) throws SQLException { return MapDao.getInstance().update(map); } + + @Override + public List listAllProfiles() throws SQLException { + return ProfileDao.getInstance().listAll(); + } } diff --git a/src/main/java/stories/mapsedition/MapsEditionController.java b/src/main/java/stories/mapsedition/MapsEditionController.java index ab7cc0c..e3127c5 100644 --- a/src/main/java/stories/mapsedition/MapsEditionController.java +++ b/src/main/java/stories/mapsedition/MapsEditionController.java @@ -18,6 +18,7 @@ import javafx.scene.input.MouseEvent; import javafx.scene.layout.FlowPane; import javafx.scene.layout.GridPane; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import pojos.kf2factory.Kf2Common; import pojos.kf2factory.Kf2Factory; @@ -254,7 +255,7 @@ private void addNewMapOnAction() { if (customMap != null) { mapList.add(customMap); Kf2Common kf2Common = Kf2Factory.getInstance(); - kf2Common.addCustomMapToKfEngineIni(customMap.getIdWorkShop(), installationFolder, Session.getInstance().getActualProfile().getName()); + kf2Common.addCustomMapToKfEngineIni(customMap.getIdWorkShop(), installationFolder); GridPane gridpane = createMapGridPane(facade.getDto(customMap)); customMapsFlowPane.getChildren().add(gridpane); } else { @@ -297,10 +298,12 @@ private void removeMapsOnAction() { customMapsFlowPane.getChildren().remove(gridpane); File photo = new File(installationFolder + customMap.getUrlPhoto()); photo.delete(); + File cacheFoler = new File(installationFolder + "/KFGame/Cache/" + customMap.getIdWorkShop()); + FileUtils.deleteDirectory(cacheFoler); } else { errors.append(mapNameLabel.getText()).append("\n"); } - } catch (SQLException e) { + } catch (Exception e) { Utils.errorDialog(e.getMessage(), "See stacktrace for more details", e); } } @@ -313,9 +316,9 @@ private void removeMapsOnAction() { } List idWorkShopListToRemove = mapsToRemove.stream().map(m -> m.getIdWorkShop()).collect(Collectors.toList()); Kf2Common kf2Common = Kf2Factory.getInstance(); - kf2Common.removeCustomMapsFromKfEngineIni(idWorkShopListToRemove, installationFolder, Session.getInstance().getActualProfile().getName()); + kf2Common.removeCustomMapsFromKfEngineIni(idWorkShopListToRemove, installationFolder); List mapNameListToRemove = mapsToRemove.stream().map(m -> m.getKey()).collect(Collectors.toList()); - kf2Common.removeCustomMapsFromKfGameIni(mapNameListToRemove, installationFolder, Session.getInstance().getActualProfile().getName(), mapList); + kf2Common.removeCustomMapsFromKfGameIni(mapNameListToRemove, installationFolder, mapList); } if (StringUtils.isNotBlank(errors.toString())) { Utils.errorDialog("Next maps could not be deleted", errors.toString(), null); diff --git a/src/main/java/stories/template/TemplateController.java b/src/main/java/stories/template/TemplateController.java index 7fe4bd8..8326598 100644 --- a/src/main/java/stories/template/TemplateController.java +++ b/src/main/java/stories/template/TemplateController.java @@ -20,12 +20,14 @@ public class TemplateController implements Initializable { @FXML private Menu mainPage; @FXML private Menu installUpdateServer; @FXML private Menu webAdmin; + @FXML private Menu mapsMenu; @Override public void initialize(URL location, ResourceBundle resources) { mainPage.setGraphic(getLabelWithHandler(Constants.MENU_MAIN_PAGE, "/views/mainContent.fxml")); installUpdateServer.setGraphic(getLabelWithHandler(Constants.MENU_INSTALL_UPDATE_SERVER, "/views/installUpdateServer.fxml")); webAdmin.setGraphic(getLabelWithHandler(Constants.MENU_WEB_ADMIN, "/views/webAdmin.fxml")); + mapsMenu.setGraphic(getLabelWithHandler(Constants.MENU_MAPS_EDITION, "/views/mapsEdition.fxml")); } private Label getLabelWithHandler(String title, String fxmlFilePath) { diff --git a/src/main/resources/css/custom.css b/src/main/resources/css/custom.css index 58ffc80..202ab72 100644 --- a/src/main/resources/css/custom.css +++ b/src/main/resources/css/custom.css @@ -139,3 +139,7 @@ .scroll-bar:vertical{ -fx-background-color: #c15d11; } + +#searchMaps, #viewPaneCombo { + -fx-background-color: #c15d11; +} \ No newline at end of file diff --git a/src/main/resources/images/find.png b/src/main/resources/images/find.png new file mode 100644 index 0000000..81c2af1 Binary files /dev/null and b/src/main/resources/images/find.png differ diff --git a/src/main/resources/images/kf2banner.png b/src/main/resources/images/kf2banner.png new file mode 100644 index 0000000..203f9a7 Binary files /dev/null and b/src/main/resources/images/kf2banner.png differ diff --git a/src/main/resources/views/mapsEdition.fxml b/src/main/resources/views/mapsEdition.fxml index 93c0644..bd8606b 100644 --- a/src/main/resources/views/mapsEdition.fxml +++ b/src/main/resources/views/mapsEdition.fxml @@ -7,6 +7,8 @@ + + @@ -14,15 +16,40 @@ - - + + + + + - + + + + + - - - - - + + + + + diff --git a/src/main/resources/views/template.fxml b/src/main/resources/views/template.fxml index dc4a762..e908095 100644 --- a/src/main/resources/views/template.fxml +++ b/src/main/resources/views/template.fxml @@ -10,14 +10,14 @@ + - - - - - - + + + + +