Skip to content

Commit

Permalink
Enable-disable takeover of the server
Browse files Browse the repository at this point in the history
  • Loading branch information
cesar-rgon committed Oct 24, 2019
1 parent e21d8b6 commit 13755d5
Show file tree
Hide file tree
Showing 25 changed files with 472 additions and 169 deletions.
2 changes: 1 addition & 1 deletion scripts/sql/script.sql
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ INSERT INTO KF2DATABASE.MAPS(ID, CODE, OFFICIAL, URL_INFO, URL_PHOTO, DOWNLOADED
-----------------------------------
-- PROFILES
-----------------------------------
INSERT INTO KF2DATABASE.PROFILES(ID, NAME, ID_LANGUAGE, ID_GAMETYPE, ID_MAP, ID_DIFFICULTY, ID_LENGTH, ID_MAXPLAYERS, SERVER_NAME, WEB_PORT, GAME_PORT, QUERY_PORT) VALUES(1000, 'Default', 1, 1000, 1000, 1000, 1000, 1006, 'Killing Floor 2 Server', 8080, 7777, 27015);
INSERT INTO KF2DATABASE.PROFILES(ID, NAME, ID_LANGUAGE, ID_GAMETYPE, ID_MAP, ID_DIFFICULTY, ID_LENGTH, ID_MAXPLAYERS, SERVER_NAME, WEB_PORT, GAME_PORT, QUERY_PORT, WEB_PAGE) VALUES(1000, 'Default', 1, 1000, 1000, 1000, 1000, 1006, 'Killing Floor 2 Server', 8080, 7777, 27015, true);

-----------------------------------
-- PROFILES_MAPS
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/daos/MapDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public static MapDao getInstance() {
return instance;
}

public List<Map> listNotDownloadedMapsAndMods() throws SQLException {
String query="select m from entities.Map m where m.downloaded=false";
public List<Map> listAllMaps() throws SQLException {
String query="select m from entities.Map m";
return list(query, null);
}

Expand Down
8 changes: 7 additions & 1 deletion src/main/java/dtos/ProfileDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ public class ProfileDto {
private final String welcomeMessage;
private final String customParameters;
private final ObservableList<MapDto> mapList;
private final Boolean takeover;

public ProfileDto(String name, SelectDto language, GameTypeDto gametype, MapDto map, SelectDto difficulty, SelectDto length, SelectDto maxPlayers,
String serverName, String serverPassword, Boolean webPage, String webPassword, Integer webPort, Integer gamePort, Integer queryPort,
String yourClan, String yourWebLink, String urlImageServer, String welcomeMessage, String customParameters, ObservableList<MapDto> mapList) {
String yourClan, String yourWebLink, String urlImageServer, String welcomeMessage, String customParameters, ObservableList<MapDto> mapList, Boolean takeover) {
super();
this.name = new SimpleStringProperty(name);
this.language = language;
Expand All @@ -53,6 +54,7 @@ public ProfileDto(String name, SelectDto language, GameTypeDto gametype, MapDto
this.welcomeMessage = welcomeMessage;
this.customParameters = customParameters;
this.mapList = mapList;
this.takeover = takeover;
}

public StringProperty getNameProperty() {
Expand Down Expand Up @@ -139,6 +141,10 @@ public ObservableList<MapDto> getMapList() {
return mapList;
}

public Boolean getTakeover() {
return takeover;
}

@Override
public String toString() {
return getName();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/dtos/factories/ProfileDtoFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public ProfileDto newDto(Profile profile) {
profile.getUrlImageServer(),
profile.getWelcomeMessage(),
profile.getCustomParameters(),
mapDtoFactory.newDtos(profile.getMapList()));
mapDtoFactory.newDtos(profile.getMapList()),
profile.getTakeover());
}

public ObservableList<ProfileDto> newDtos(List<Profile> profiles) {
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/entities/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class Profile extends CommonEntity {
@Column(name="WEB_PASSWORD", length=100)
private String webPassword;

@Column(name="TAKEOVER")
private Boolean takeover;

@Column(name="WEB_PORT")
private Integer webPort;

Expand Down Expand Up @@ -90,7 +93,7 @@ public Profile() {
}

public Profile(String name, Language language, GameType gametype, Map map, Difficulty difficulty, Length length, MaxPlayers maxPlayers,
String serverName, Integer webPort, Integer gamePort, Integer queryPort, List<Map> mapList) {
String serverName, Integer webPort, Integer gamePort, Integer queryPort, List<Map> mapList, Boolean webPage) {
super();
this.name = name;
this.language = language;
Expand All @@ -104,11 +107,12 @@ public Profile(String name, Language language, GameType gametype, Map map, Diffi
this.gamePort = gamePort;
this.queryPort = queryPort;
this.mapList = mapList;
this.webPage = webPage;
}

public Profile(String name, Language language, GameType gametype, Map map, Difficulty difficulty, Length length, MaxPlayers maxPlayers,
String serverName, String serverPassword, Boolean webPage, String webPassword, Integer webPort, Integer gamePort, Integer queryPort,
String yourClan, String yourWebLink, String urlImageServer, String welcomeMessage, String customParameters, List<Map> mapList) {
String yourClan, String yourWebLink, String urlImageServer, String welcomeMessage, String customParameters, List<Map> mapList, Boolean takeover) {
super();
this.name = name;
this.language = language;
Expand All @@ -130,6 +134,7 @@ public Profile(String name, Language language, GameType gametype, Map map, Diffi
this.welcomeMessage = welcomeMessage;
this.customParameters = customParameters;
this.mapList = mapList;
this.takeover = takeover;
}

@Override
Expand Down Expand Up @@ -301,4 +306,12 @@ public List<Map> getMapList() {
public void setMapList(List<Map> mapList) {
this.mapList = mapList;
}

public Boolean getTakeover() {
return takeover;
}

public void setTakeover(Boolean takeover) {
this.takeover = takeover;
}
}
20 changes: 14 additions & 6 deletions src/main/java/pojos/kf2factory/Kf2Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,22 @@ protected void replaceInFileKfEngineIni(String installationFolder, Profile profi
pw.println("DownloadManagers=OnlineSubsystemSteamworks.SteamWorkshopDownload");
}
}
if (StringUtils.isBlank(line) || (!line.contains("[OnlineSubsystemSteamworks.KFWorkshopSteamworks]") &&
!line.contains("ServerSubscribedWorkshopItems="))) {
pw.println(line);
if (StringUtils.isNotBlank(line) && line.contains("bUsedForTakeover=")) {
pw.println("bUsedForTakeover=" + (profile.getTakeover()!=null?profile.getTakeover():"FALSE"));
} else {
if (StringUtils.isBlank(line) || (!line.contains("[OnlineSubsystemSteamworks.KFWorkshopSteamworks]") &&
!line.contains("ServerSubscribedWorkshopItems="))) {
pw.println(line);
}
}
} else {
if (StringUtils.isBlank(line) || (!line.contains("DownloadManagers=OnlineSubsystemSteamworks.SteamWorkshopDownload") &&
!line.contains("[OnlineSubsystemSteamworks.KFWorkshopSteamworks]") && !line.contains("ServerSubscribedWorkshopItems="))) {
pw.println(line);
if (StringUtils.isNotBlank(line) && line.contains("bUsedForTakeover=")) {
pw.println("bUsedForTakeover=" + (profile.getTakeover()!=null?profile.getTakeover():"FALSE"));
} else {
if (StringUtils.isBlank(line) || (!line.contains("DownloadManagers=OnlineSubsystemSteamworks.SteamWorkshopDownload") &&
!line.contains("[OnlineSubsystemSteamworks.KFWorkshopSteamworks]") && !line.contains("ServerSubscribedWorkshopItems="))) {
pw.println(line);
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/pojos/listener/TimeListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public TimeListener() {
public void run() {
logger.info("Starting the process of checking downloaded custom maps and mods.");
try {
List<Map> notDownloadedMapList = databaseService.listNotDownloadedMapsAndMods();
if (notDownloadedMapList != null && !notDownloadedMapList.isEmpty()) {
List<Map> mapList = databaseService.listAllMaps();
if (mapList != null && !mapList.isEmpty()) {
PropertyService propertyService = new PropertyServiceImpl();
String installationFolder = propertyService.getPropertyValue("properties/config.properties", "prop.config.installationFolder");
for (Map map : notDownloadedMapList) {
for (Map map : mapList) {
try {
List<Path> kfmFilesPath = Files.walk(Paths.get(installationFolder + "/KFGame/Cache/" + map.getIdWorkShop()))
.filter(Files::isRegularFile)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/services/DatabaseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
import java.util.List;

public interface DatabaseService {
List<Map> listNotDownloadedMapsAndMods() throws SQLException;
List<Map> listAllMaps() throws SQLException;
boolean updateMap(Map map) throws SQLException;
}
7 changes: 2 additions & 5 deletions src/main/java/services/DatabaseServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package services;

import daos.MapDao;
import daos.ProfileDao;
import entities.Map;
import entities.Profile;

import java.sql.SQLException;
import java.util.List;
import java.util.Optional;

public class DatabaseServiceImpl implements DatabaseService {

Expand All @@ -16,8 +13,8 @@ public DatabaseServiceImpl() {
}

@Override
public List<Map> listNotDownloadedMapsAndMods() throws SQLException {
return MapDao.getInstance().listNotDownloadedMapsAndMods();
public List<Map> listAllMaps() throws SQLException {
return MapDao.getInstance().listAllMaps();
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/start/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public void start(Stage primaryStage) throws Exception {
mainContent.load();
primaryStage.getIcons().add(new Image(getClass().getClassLoader().getResourceAsStream("images/logo.png")));
String applicationTitle = propertyService.getPropertyValue("properties/config.properties", "prop.config.applicationTitle");
primaryStage.setTitle(applicationTitle);
String applicationVersion = propertyService.getPropertyValue("properties/config.properties", "prop.config.applicationVersion");
primaryStage.setTitle(applicationTitle + " " + applicationVersion);
primaryStage.setScene(scene);
primaryStage.setMinWidth(1280);
primaryStage.setMinHeight(800);
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/stories/console/ConsoleController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package stories.console;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TextArea;
import org.apache.commons.lang3.StringUtils;
import pojos.session.Session;

import java.net.URL;
import java.util.ResourceBundle;

public class ConsoleController implements Initializable {

@FXML private TextArea console;

public ConsoleController() {
super();
}

@Override
public void initialize(URL location, ResourceBundle resources) {
console.setText(StringUtils.isNotBlank(Session.getInstance().getConsole())? Session.getInstance().getConsole(): "");
}
}
Loading

0 comments on commit 13755d5

Please sign in to comment.